Completed
Branch back-compat-edtr-taxes (752e0e)
by
unknown
12:08 queued 09:43
created
core/EE_Addon.core.php 2 patches
Indentation   +844 added lines, -844 removed lines patch added patch discarded remove patch
@@ -19,798 +19,798 @@  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 = array();
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 $dependency_map [optional]
113
-     * @param DomainInterface   $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', array($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()
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
-     * @return DomainInterface
155
-     */
156
-    public function domain()
157
-    {
158
-        return $this->domain;
159
-    }
160
-
161
-
162
-    /**
163
-     * @param mixed $version
164
-     */
165
-    public function set_version($version = null)
166
-    {
167
-        $this->_version = $version;
168
-    }
169
-
170
-
171
-    /**
172
-     * get__version
173
-     *
174
-     * @return string
175
-     */
176
-    public function version()
177
-    {
178
-        return $this->_version;
179
-    }
180
-
181
-
182
-    /**
183
-     * @param mixed $min_core_version
184
-     */
185
-    public function set_min_core_version($min_core_version = null)
186
-    {
187
-        $this->_min_core_version = $min_core_version;
188
-    }
189
-
190
-
191
-    /**
192
-     * get__min_core_version
193
-     *
194
-     * @return string
195
-     */
196
-    public function min_core_version()
197
-    {
198
-        return $this->_min_core_version;
199
-    }
200
-
201
-
202
-    /**
203
-     * Sets addon_name
204
-     *
205
-     * @param string $addon_name
206
-     * @return boolean
207
-     */
208
-    public function set_name($addon_name)
209
-    {
210
-        return $this->_addon_name = $addon_name;
211
-    }
212
-
213
-
214
-    /**
215
-     * Gets addon_name
216
-     *
217
-     * @return string
218
-     */
219
-    public function name()
220
-    {
221
-        return $this->_addon_name;
222
-    }
223
-
224
-
225
-    /**
226
-     * @return string
227
-     */
228
-    public function plugin_basename()
229
-    {
230
-
231
-        return $this->_plugin_basename;
232
-    }
233
-
234
-
235
-    /**
236
-     * @param string $plugin_basename
237
-     */
238
-    public function set_plugin_basename($plugin_basename)
239
-    {
240
-
241
-        $this->_plugin_basename = $plugin_basename;
242
-    }
243
-
244
-
245
-    /**
246
-     * @return string
247
-     */
248
-    public function plugin_slug()
249
-    {
250
-
251
-        return $this->_plugin_slug;
252
-    }
253
-
254
-
255
-    /**
256
-     * @param string $plugin_slug
257
-     */
258
-    public function set_plugin_slug($plugin_slug)
259
-    {
260
-
261
-        $this->_plugin_slug = $plugin_slug;
262
-    }
263
-
264
-
265
-    /**
266
-     * @return string
267
-     */
268
-    public function plugin_action_slug()
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($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()
289
-    {
290
-
291
-        return $this->_plugins_page_row;
292
-    }
293
-
294
-
295
-    /**
296
-     * @param array $plugins_page_row
297
-     */
298
-    public function set_plugins_page_row($plugins_page_row = array())
299
-    {
300
-        // sigh.... check for example content that I stupidly merged to master and remove it if found
301
-        if (
302
-            ! is_array($plugins_page_row)
303
-            && strpos($plugins_page_row, '<h3>Promotions Addon Upsell Info</h3>') !== false
304
-        ) {
305
-            $plugins_page_row = array();
306
-        }
307
-        $this->_plugins_page_row = (array) $plugins_page_row;
308
-    }
309
-
310
-
311
-    /**
312
-     * Called when EE core detects this addon has been activated for the first time.
313
-     * If the site isn't in maintenance mode, should setup the addon's database
314
-     *
315
-     * @return void
316
-     */
317
-    public function new_install()
318
-    {
319
-        $classname = get_class($this);
320
-        do_action("AHEE__{$classname}__new_install");
321
-        do_action('AHEE__EE_Addon__new_install', $this);
322
-        EE_Maintenance_Mode::instance()->set_maintenance_mode_if_db_old();
323
-        add_action(
324
-            'AHEE__EE_System__perform_activations_upgrades_and_migrations',
325
-            array($this, 'initialize_db_if_no_migrations_required')
326
-        );
327
-    }
328
-
329
-
330
-    /**
331
-     * Called when EE core detects this addon has been reactivated. When this happens,
332
-     * it's good to just check that your data is still intact
333
-     *
334
-     * @return void
335
-     */
336
-    public function reactivation()
337
-    {
338
-        $classname = get_class($this);
339
-        do_action("AHEE__{$classname}__reactivation");
340
-        do_action('AHEE__EE_Addon__reactivation', $this);
341
-        EE_Maintenance_Mode::instance()->set_maintenance_mode_if_db_old();
342
-        add_action(
343
-            'AHEE__EE_System__perform_activations_upgrades_and_migrations',
344
-            array($this, 'initialize_db_if_no_migrations_required')
345
-        );
346
-    }
347
-
348
-
349
-    /**
350
-     * Called when the registered deactivation hook for this addon fires.
351
-     *
352
-     * @throws EE_Error
353
-     */
354
-    public function deactivation()
355
-    {
356
-        $classname = get_class($this);
357
-        do_action("AHEE__{$classname}__deactivation");
358
-        do_action('AHEE__EE_Addon__deactivation', $this);
359
-        // check if the site no longer needs to be in maintenance mode
360
-        EE_Register_Addon::deregister($this->name());
361
-        EE_Maintenance_Mode::instance()->set_maintenance_mode_if_db_old();
362
-    }
363
-
364
-
365
-    /**
366
-     * Takes care of double-checking that we're not in maintenance mode, and then
367
-     * initializing this addon's necessary initial data. This is called by default on new activations
368
-     * and reactivations.
369
-     *
370
-     * @param boolean $verify_schema whether to verify the database's schema for this addon, or just its data.
371
-     *                               This is a resource-intensive job so we prefer to only do it when necessary
372
-     * @return void
373
-     * @throws \EE_Error
374
-     * @throws InvalidInterfaceException
375
-     * @throws InvalidDataTypeException
376
-     * @throws InvalidArgumentException
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
-                array(
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 = array();
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 $dependency_map [optional]
113
+	 * @param DomainInterface   $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', array($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()
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
+	 * @return DomainInterface
155
+	 */
156
+	public function domain()
157
+	{
158
+		return $this->domain;
159
+	}
160
+
161
+
162
+	/**
163
+	 * @param mixed $version
164
+	 */
165
+	public function set_version($version = null)
166
+	{
167
+		$this->_version = $version;
168
+	}
169
+
170
+
171
+	/**
172
+	 * get__version
173
+	 *
174
+	 * @return string
175
+	 */
176
+	public function version()
177
+	{
178
+		return $this->_version;
179
+	}
180
+
181
+
182
+	/**
183
+	 * @param mixed $min_core_version
184
+	 */
185
+	public function set_min_core_version($min_core_version = null)
186
+	{
187
+		$this->_min_core_version = $min_core_version;
188
+	}
189
+
190
+
191
+	/**
192
+	 * get__min_core_version
193
+	 *
194
+	 * @return string
195
+	 */
196
+	public function min_core_version()
197
+	{
198
+		return $this->_min_core_version;
199
+	}
200
+
201
+
202
+	/**
203
+	 * Sets addon_name
204
+	 *
205
+	 * @param string $addon_name
206
+	 * @return boolean
207
+	 */
208
+	public function set_name($addon_name)
209
+	{
210
+		return $this->_addon_name = $addon_name;
211
+	}
212
+
213
+
214
+	/**
215
+	 * Gets addon_name
216
+	 *
217
+	 * @return string
218
+	 */
219
+	public function name()
220
+	{
221
+		return $this->_addon_name;
222
+	}
223
+
224
+
225
+	/**
226
+	 * @return string
227
+	 */
228
+	public function plugin_basename()
229
+	{
230
+
231
+		return $this->_plugin_basename;
232
+	}
233
+
234
+
235
+	/**
236
+	 * @param string $plugin_basename
237
+	 */
238
+	public function set_plugin_basename($plugin_basename)
239
+	{
240
+
241
+		$this->_plugin_basename = $plugin_basename;
242
+	}
243
+
244
+
245
+	/**
246
+	 * @return string
247
+	 */
248
+	public function plugin_slug()
249
+	{
250
+
251
+		return $this->_plugin_slug;
252
+	}
253
+
254
+
255
+	/**
256
+	 * @param string $plugin_slug
257
+	 */
258
+	public function set_plugin_slug($plugin_slug)
259
+	{
260
+
261
+		$this->_plugin_slug = $plugin_slug;
262
+	}
263
+
264
+
265
+	/**
266
+	 * @return string
267
+	 */
268
+	public function plugin_action_slug()
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($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()
289
+	{
290
+
291
+		return $this->_plugins_page_row;
292
+	}
293
+
294
+
295
+	/**
296
+	 * @param array $plugins_page_row
297
+	 */
298
+	public function set_plugins_page_row($plugins_page_row = array())
299
+	{
300
+		// sigh.... check for example content that I stupidly merged to master and remove it if found
301
+		if (
302
+			! is_array($plugins_page_row)
303
+			&& strpos($plugins_page_row, '<h3>Promotions Addon Upsell Info</h3>') !== false
304
+		) {
305
+			$plugins_page_row = array();
306
+		}
307
+		$this->_plugins_page_row = (array) $plugins_page_row;
308
+	}
309
+
310
+
311
+	/**
312
+	 * Called when EE core detects this addon has been activated for the first time.
313
+	 * If the site isn't in maintenance mode, should setup the addon's database
314
+	 *
315
+	 * @return void
316
+	 */
317
+	public function new_install()
318
+	{
319
+		$classname = get_class($this);
320
+		do_action("AHEE__{$classname}__new_install");
321
+		do_action('AHEE__EE_Addon__new_install', $this);
322
+		EE_Maintenance_Mode::instance()->set_maintenance_mode_if_db_old();
323
+		add_action(
324
+			'AHEE__EE_System__perform_activations_upgrades_and_migrations',
325
+			array($this, 'initialize_db_if_no_migrations_required')
326
+		);
327
+	}
328
+
329
+
330
+	/**
331
+	 * Called when EE core detects this addon has been reactivated. When this happens,
332
+	 * it's good to just check that your data is still intact
333
+	 *
334
+	 * @return void
335
+	 */
336
+	public function reactivation()
337
+	{
338
+		$classname = get_class($this);
339
+		do_action("AHEE__{$classname}__reactivation");
340
+		do_action('AHEE__EE_Addon__reactivation', $this);
341
+		EE_Maintenance_Mode::instance()->set_maintenance_mode_if_db_old();
342
+		add_action(
343
+			'AHEE__EE_System__perform_activations_upgrades_and_migrations',
344
+			array($this, 'initialize_db_if_no_migrations_required')
345
+		);
346
+	}
347
+
348
+
349
+	/**
350
+	 * Called when the registered deactivation hook for this addon fires.
351
+	 *
352
+	 * @throws EE_Error
353
+	 */
354
+	public function deactivation()
355
+	{
356
+		$classname = get_class($this);
357
+		do_action("AHEE__{$classname}__deactivation");
358
+		do_action('AHEE__EE_Addon__deactivation', $this);
359
+		// check if the site no longer needs to be in maintenance mode
360
+		EE_Register_Addon::deregister($this->name());
361
+		EE_Maintenance_Mode::instance()->set_maintenance_mode_if_db_old();
362
+	}
363
+
364
+
365
+	/**
366
+	 * Takes care of double-checking that we're not in maintenance mode, and then
367
+	 * initializing this addon's necessary initial data. This is called by default on new activations
368
+	 * and reactivations.
369
+	 *
370
+	 * @param boolean $verify_schema whether to verify the database's schema for this addon, or just its data.
371
+	 *                               This is a resource-intensive job so we prefer to only do it when necessary
372
+	 * @return void
373
+	 * @throws \EE_Error
374
+	 * @throws InvalidInterfaceException
375
+	 * @throws InvalidDataTypeException
376
+	 * @throws InvalidArgumentException
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
+				array(
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
-    public function initialize_db()
430
-    {
431
-        // find the migration script that sets the database to be compatible with the code
432
-        $current_dms_name = EE_Data_Migration_Manager::instance()->get_most_up_to_date_dms($this->name());
433
-        if ($current_dms_name) {
434
-            $current_data_migration_script = EE_Registry::instance()->load_dms($current_dms_name);
435
-            $current_data_migration_script->set_migrating(false);
436
-            $current_data_migration_script->schema_changes_before_migration();
437
-            $current_data_migration_script->schema_changes_after_migration();
438
-            if ($current_data_migration_script->get_errors()) {
439
-                foreach ($current_data_migration_script->get_errors() as $error) {
440
-                    EE_Error::add_error($error, __FILE__, __FUNCTION__, __LINE__);
441
-                }
442
-            }
443
-        }
444
-        // if not DMS was found that should be ok. This addon just doesn't require any database changes
445
-        EE_Data_Migration_Manager::instance()->update_current_database_state_to(
446
-            array(
447
-                'slug'    => $this->name(),
448
-                'version' => $this->version(),
449
-            )
450
-        );
451
-    }
452
-
453
-
454
-    /**
455
-     * If you want to setup default data for the addon, override this method, and call
456
-     * parent::initialize_default_data() from within it. This is normally called
457
-     * from EE_Addon::initialize_db_if_no_migrations_required(), just after EE_Addon::initialize_db()
458
-     * and should verify default data is present (but this is also called
459
-     * on reactivations and just after migrations, so please verify you actually want
460
-     * to ADD default data, because it may already be present).
461
-     * However, please call this parent (currently it just fires a hook which other
462
-     * addons may be depending on)
463
-     */
464
-    public function initialize_default_data()
465
-    {
466
-        /**
467
-         * Called when an addon is ensuring its default data is set (possibly called
468
-         * on a reactivation, so first check for the absence of other data before setting
469
-         * default data)
470
-         *
471
-         * @param EE_Addon $addon the addon that called this
472
-         */
473
-        do_action('AHEE__EE_Addon__initialize_default_data__begin', $this);
474
-        // override to insert default data. It is safe to use the models here
475
-        // because the site should not be in maintenance mode
476
-    }
477
-
478
-
479
-    /**
480
-     * EE Core detected that this addon has been upgraded. We should check if there
481
-     * are any new migration scripts, and if so put the site into maintenance mode until
482
-     * they're ran
483
-     *
484
-     * @return void
485
-     */
486
-    public function upgrade()
487
-    {
488
-        $classname = get_class($this);
489
-        do_action("AHEE__{$classname}__upgrade");
490
-        do_action('AHEE__EE_Addon__upgrade', $this);
491
-        EE_Maintenance_Mode::instance()->set_maintenance_mode_if_db_old();
492
-        // also it's possible there is new default data that needs to be added
493
-        add_action(
494
-            'AHEE__EE_System__perform_activations_upgrades_and_migrations',
495
-            array($this, 'initialize_db_if_no_migrations_required')
496
-        );
497
-    }
498
-
499
-
500
-    /**
501
-     * If Core detects this addon has been downgraded, you may want to invoke some special logic here.
502
-     */
503
-    public function downgrade()
504
-    {
505
-        $classname = get_class($this);
506
-        do_action("AHEE__{$classname}__downgrade");
507
-        do_action('AHEE__EE_Addon__downgrade', $this);
508
-        // it's possible there's old default data that needs to be double-checked
509
-        add_action(
510
-            'AHEE__EE_System__perform_activations_upgrades_and_migrations',
511
-            array($this, 'initialize_db_if_no_migrations_required')
512
-        );
513
-    }
514
-
515
-
516
-    /**
517
-     * set_db_update_option_name
518
-     * Until we do something better, we'll just check for migration scripts upon
519
-     * plugin activation only. In the future, we'll want to do it on plugin updates too
520
-     *
521
-     * @return bool
522
-     */
523
-    public function set_db_update_option_name()
524
-    {
525
-        EE_Error::doing_it_wrong(
526
-            __FUNCTION__,
527
-            esc_html__(
528
-                'EE_Addon::set_db_update_option_name was renamed to EE_Addon::set_activation_indicator_option',
529
-                'event_espresso'
530
-            ),
531
-            '4.3.0.alpha.016'
532
-        );
533
-        // let's just handle this on the next request, ok? right now we're just not really ready
534
-        return $this->set_activation_indicator_option();
535
-    }
536
-
537
-
538
-    /**
539
-     * Returns the name of the activation indicator option
540
-     * (an option which is set temporarily to indicate that this addon was just activated)
541
-     *
542
-     * @deprecated since version 4.3.0.alpha.016
543
-     * @return string
544
-     */
545
-    public function get_db_update_option_name()
546
-    {
547
-        EE_Error::doing_it_wrong(
548
-            __FUNCTION__,
549
-            esc_html__(
550
-                'EE_Addon::get_db_update_option was renamed to EE_Addon::get_activation_indicator_option_name',
551
-                'event_espresso'
552
-            ),
553
-            '4.3.0.alpha.016'
554
-        );
555
-        return $this->get_activation_indicator_option_name();
556
-    }
557
-
558
-
559
-    /**
560
-     * When the addon is activated, this should be called to set a wordpress option that
561
-     * indicates it was activated. This is especially useful for detecting reactivations.
562
-     *
563
-     * @return bool
564
-     */
565
-    public function set_activation_indicator_option()
566
-    {
567
-        // let's just handle this on the next request, ok? right now we're just not really ready
568
-        return update_option($this->get_activation_indicator_option_name(), true);
569
-    }
570
-
571
-
572
-    /**
573
-     * Gets the name of the wp option which is used to temporarily indicate that this addon was activated
574
-     *
575
-     * @return string
576
-     */
577
-    public function get_activation_indicator_option_name()
578
-    {
579
-        return 'ee_activation_' . $this->name();
580
-    }
581
-
582
-
583
-    /**
584
-     * Used by EE_System to set the request type of this addon. Should not be used by addon developers
585
-     *
586
-     * @param int $req_type
587
-     */
588
-    public function set_req_type($req_type)
589
-    {
590
-        $this->_req_type = $req_type;
591
-    }
592
-
593
-
594
-    /**
595
-     * Returns the request type of this addon (ie, EE_System::req_type_normal, EE_System::req_type_new_activation,
596
-     * EE_System::req_type_reactivation, EE_System::req_type_upgrade, or EE_System::req_type_downgrade). This is set by
597
-     * EE_System when it is checking for new install or upgrades of addons
598
-     */
599
-    public function detect_req_type($redetect = false)
600
-    {
601
-        if ($this->_req_type === null || $redetect) {
602
-            $this->detect_activation_or_upgrade();
603
-        }
604
-        return $this->_req_type;
605
-    }
606
-
607
-
608
-    /**
609
-     * Detects the request type for this addon (whether it was just activated, upgrades, a normal request, etc.)
610
-     * Should only be called once per request
611
-     *
612
-     * @return void
613
-     */
614
-    public function detect_activation_or_upgrade()
615
-    {
616
-        $activation_history_for_addon = $this->get_activation_history();
617
-        $request_type = EE_System::detect_req_type_given_activation_history(
618
-            $activation_history_for_addon,
619
-            $this->get_activation_indicator_option_name(),
620
-            $this->version()
621
-        );
622
-        $this->set_req_type($request_type);
623
-        $classname = get_class($this);
624
-        switch ($request_type) {
625
-            case EE_System::req_type_new_activation:
626
-                do_action("AHEE__{$classname}__detect_activations_or_upgrades__new_activation");
627
-                do_action('AHEE__EE_Addon__detect_activations_or_upgrades__new_activation', $this);
628
-                $this->new_install();
629
-                $this->update_list_of_installed_versions($activation_history_for_addon);
630
-                break;
631
-            case EE_System::req_type_reactivation:
632
-                do_action("AHEE__{$classname}__detect_activations_or_upgrades__reactivation");
633
-                do_action('AHEE__EE_Addon__detect_activations_or_upgrades__reactivation', $this);
634
-                $this->reactivation();
635
-                $this->update_list_of_installed_versions($activation_history_for_addon);
636
-                break;
637
-            case EE_System::req_type_upgrade:
638
-                do_action("AHEE__{$classname}__detect_activations_or_upgrades__upgrade");
639
-                do_action('AHEE__EE_Addon__detect_activations_or_upgrades__upgrade', $this);
640
-                $this->upgrade();
641
-                $this->update_list_of_installed_versions($activation_history_for_addon);
642
-                break;
643
-            case EE_System::req_type_downgrade:
644
-                do_action("AHEE__{$classname}__detect_activations_or_upgrades__downgrade");
645
-                do_action('AHEE__EE_Addon__detect_activations_or_upgrades__downgrade', $this);
646
-                $this->downgrade();
647
-                $this->update_list_of_installed_versions($activation_history_for_addon);
648
-                break;
649
-            case EE_System::req_type_normal:
650
-            default:
651
-                break;
652
-        }
653
-
654
-        do_action("AHEE__{$classname}__detect_if_activation_or_upgrade__complete");
655
-    }
656
-
657
-    /**
658
-     * Updates the version history for this addon
659
-     *
660
-     * @param array  $version_history
661
-     * @param string $current_version_to_add
662
-     * @return boolean success
663
-     */
664
-    public function update_list_of_installed_versions($version_history = null, $current_version_to_add = null)
665
-    {
666
-        if (! $version_history) {
667
-            $version_history = $this->get_activation_history();
668
-        }
669
-        if ($current_version_to_add === null) {
670
-            $current_version_to_add = $this->version();
671
-        }
672
-        $version_history[ $current_version_to_add ][] = date('Y-m-d H:i:s', time());
673
-        // resave
674
-        return update_option($this->get_activation_history_option_name(), $version_history);
675
-    }
676
-
677
-    /**
678
-     * Gets the name of the wp option that stores the activation history
679
-     * of this addon
680
-     *
681
-     * @return string
682
-     */
683
-    public function get_activation_history_option_name()
684
-    {
685
-        return self::ee_addon_version_history_option_prefix . $this->name();
686
-    }
687
-
688
-
689
-    /**
690
-     * Gets the wp option which stores the activation history for this addon
691
-     *
692
-     * @return array
693
-     */
694
-    public function get_activation_history()
695
-    {
696
-        return get_option($this->get_activation_history_option_name(), null);
697
-    }
698
-
699
-
700
-    /**
701
-     * @param string $config_section
702
-     */
703
-    public function set_config_section($config_section = '')
704
-    {
705
-        $this->_config_section = ! empty($config_section) ? $config_section : 'addons';
706
-    }
707
-
708
-    /**
709
-     * Sets the filepath to the main plugin file
710
-     *
711
-     * @param string $filepath
712
-     */
713
-    public function set_main_plugin_file($filepath)
714
-    {
715
-        $this->_main_plugin_file = $filepath;
716
-    }
717
-
718
-    /**
719
-     * gets the filepath to teh main file
720
-     *
721
-     * @return string
722
-     */
723
-    public function get_main_plugin_file()
724
-    {
725
-        return $this->_main_plugin_file;
726
-    }
727
-
728
-    /**
729
-     * Gets the filename (no path) of the main file (the main file loaded
730
-     * by WP)
731
-     *
732
-     * @return string
733
-     */
734
-    public function get_main_plugin_file_basename()
735
-    {
736
-        return plugin_basename($this->get_main_plugin_file());
737
-    }
738
-
739
-    /**
740
-     * Gets the folder name which contains the main plugin file
741
-     *
742
-     * @return string
743
-     */
744
-    public function get_main_plugin_file_dirname()
745
-    {
746
-        return dirname($this->get_main_plugin_file());
747
-    }
748
-
749
-
750
-    /**
751
-     * sets hooks used in the admin
752
-     *
753
-     * @return void
754
-     */
755
-    public function admin_init()
756
-    {
757
-        // is admin and not in M-Mode ?
758
-        if (is_admin() && ! EE_Maintenance_Mode::instance()->level()) {
759
-            add_filter('plugin_action_links', array($this, 'plugin_action_links'), 10, 2);
760
-            add_filter('after_plugin_row_' . $this->_plugin_basename, array($this, 'after_plugin_row'), 10, 3);
761
-        }
762
-    }
763
-
764
-
765
-    /**
766
-     * plugin_actions
767
-     * Add a settings link to the Plugins page, so people can go straight from the plugin page to the settings page.
768
-     *
769
-     * @param $links
770
-     * @param $file
771
-     * @return array
772
-     */
773
-    public function plugin_action_links($links, $file)
774
-    {
775
-        if ($file === $this->plugin_basename() && $this->plugin_action_slug() !== '') {
776
-            // before other links
777
-            array_unshift(
778
-                $links,
779
-                '<a href="admin.php?page=' . $this->plugin_action_slug() . '">'
780
-                . esc_html__('Settings', 'event_espresso')
781
-                . '</a>'
782
-            );
783
-        }
784
-        return $links;
785
-    }
786
-
787
-
788
-    /**
789
-     * after_plugin_row
790
-     * Add additional content to the plugins page plugin row
791
-     * Inserts another row
792
-     *
793
-     * @param $plugin_file
794
-     * @param $plugin_data
795
-     * @param $status
796
-     * @return void
797
-     */
798
-    public function after_plugin_row($plugin_file, $plugin_data, $status)
799
-    {
800
-        $after_plugin_row = '';
801
-        $plugins_page_row = $this->get_plugins_page_row();
802
-        if (! empty($plugins_page_row) && $plugin_file === $this->plugin_basename()) {
803
-            $class = $status ? 'active' : 'inactive';
804
-            $link_text = isset($plugins_page_row['link_text']) ? $plugins_page_row['link_text'] : '';
805
-            $link_url = isset($plugins_page_row['link_url']) ? $plugins_page_row['link_url'] : '';
806
-            $description = isset($plugins_page_row['description'])
807
-                ? $plugins_page_row['description']
808
-                : '';
809
-            if (! empty($link_text) && ! empty($link_url) && ! empty($description)) {
810
-                $after_plugin_row .= '<tr id="' . sanitize_title($plugin_file) . '-ee-addon" class="' . $class . '">';
811
-                $after_plugin_row .= '<th class="check-column" scope="row"></th>';
812
-                $after_plugin_row .= '<td class="ee-addon-upsell-info-title-td plugin-title column-primary">';
813
-                $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
+	public function initialize_db()
430
+	{
431
+		// find the migration script that sets the database to be compatible with the code
432
+		$current_dms_name = EE_Data_Migration_Manager::instance()->get_most_up_to_date_dms($this->name());
433
+		if ($current_dms_name) {
434
+			$current_data_migration_script = EE_Registry::instance()->load_dms($current_dms_name);
435
+			$current_data_migration_script->set_migrating(false);
436
+			$current_data_migration_script->schema_changes_before_migration();
437
+			$current_data_migration_script->schema_changes_after_migration();
438
+			if ($current_data_migration_script->get_errors()) {
439
+				foreach ($current_data_migration_script->get_errors() as $error) {
440
+					EE_Error::add_error($error, __FILE__, __FUNCTION__, __LINE__);
441
+				}
442
+			}
443
+		}
444
+		// if not DMS was found that should be ok. This addon just doesn't require any database changes
445
+		EE_Data_Migration_Manager::instance()->update_current_database_state_to(
446
+			array(
447
+				'slug'    => $this->name(),
448
+				'version' => $this->version(),
449
+			)
450
+		);
451
+	}
452
+
453
+
454
+	/**
455
+	 * If you want to setup default data for the addon, override this method, and call
456
+	 * parent::initialize_default_data() from within it. This is normally called
457
+	 * from EE_Addon::initialize_db_if_no_migrations_required(), just after EE_Addon::initialize_db()
458
+	 * and should verify default data is present (but this is also called
459
+	 * on reactivations and just after migrations, so please verify you actually want
460
+	 * to ADD default data, because it may already be present).
461
+	 * However, please call this parent (currently it just fires a hook which other
462
+	 * addons may be depending on)
463
+	 */
464
+	public function initialize_default_data()
465
+	{
466
+		/**
467
+		 * Called when an addon is ensuring its default data is set (possibly called
468
+		 * on a reactivation, so first check for the absence of other data before setting
469
+		 * default data)
470
+		 *
471
+		 * @param EE_Addon $addon the addon that called this
472
+		 */
473
+		do_action('AHEE__EE_Addon__initialize_default_data__begin', $this);
474
+		// override to insert default data. It is safe to use the models here
475
+		// because the site should not be in maintenance mode
476
+	}
477
+
478
+
479
+	/**
480
+	 * EE Core detected that this addon has been upgraded. We should check if there
481
+	 * are any new migration scripts, and if so put the site into maintenance mode until
482
+	 * they're ran
483
+	 *
484
+	 * @return void
485
+	 */
486
+	public function upgrade()
487
+	{
488
+		$classname = get_class($this);
489
+		do_action("AHEE__{$classname}__upgrade");
490
+		do_action('AHEE__EE_Addon__upgrade', $this);
491
+		EE_Maintenance_Mode::instance()->set_maintenance_mode_if_db_old();
492
+		// also it's possible there is new default data that needs to be added
493
+		add_action(
494
+			'AHEE__EE_System__perform_activations_upgrades_and_migrations',
495
+			array($this, 'initialize_db_if_no_migrations_required')
496
+		);
497
+	}
498
+
499
+
500
+	/**
501
+	 * If Core detects this addon has been downgraded, you may want to invoke some special logic here.
502
+	 */
503
+	public function downgrade()
504
+	{
505
+		$classname = get_class($this);
506
+		do_action("AHEE__{$classname}__downgrade");
507
+		do_action('AHEE__EE_Addon__downgrade', $this);
508
+		// it's possible there's old default data that needs to be double-checked
509
+		add_action(
510
+			'AHEE__EE_System__perform_activations_upgrades_and_migrations',
511
+			array($this, 'initialize_db_if_no_migrations_required')
512
+		);
513
+	}
514
+
515
+
516
+	/**
517
+	 * set_db_update_option_name
518
+	 * Until we do something better, we'll just check for migration scripts upon
519
+	 * plugin activation only. In the future, we'll want to do it on plugin updates too
520
+	 *
521
+	 * @return bool
522
+	 */
523
+	public function set_db_update_option_name()
524
+	{
525
+		EE_Error::doing_it_wrong(
526
+			__FUNCTION__,
527
+			esc_html__(
528
+				'EE_Addon::set_db_update_option_name was renamed to EE_Addon::set_activation_indicator_option',
529
+				'event_espresso'
530
+			),
531
+			'4.3.0.alpha.016'
532
+		);
533
+		// let's just handle this on the next request, ok? right now we're just not really ready
534
+		return $this->set_activation_indicator_option();
535
+	}
536
+
537
+
538
+	/**
539
+	 * Returns the name of the activation indicator option
540
+	 * (an option which is set temporarily to indicate that this addon was just activated)
541
+	 *
542
+	 * @deprecated since version 4.3.0.alpha.016
543
+	 * @return string
544
+	 */
545
+	public function get_db_update_option_name()
546
+	{
547
+		EE_Error::doing_it_wrong(
548
+			__FUNCTION__,
549
+			esc_html__(
550
+				'EE_Addon::get_db_update_option was renamed to EE_Addon::get_activation_indicator_option_name',
551
+				'event_espresso'
552
+			),
553
+			'4.3.0.alpha.016'
554
+		);
555
+		return $this->get_activation_indicator_option_name();
556
+	}
557
+
558
+
559
+	/**
560
+	 * When the addon is activated, this should be called to set a wordpress option that
561
+	 * indicates it was activated. This is especially useful for detecting reactivations.
562
+	 *
563
+	 * @return bool
564
+	 */
565
+	public function set_activation_indicator_option()
566
+	{
567
+		// let's just handle this on the next request, ok? right now we're just not really ready
568
+		return update_option($this->get_activation_indicator_option_name(), true);
569
+	}
570
+
571
+
572
+	/**
573
+	 * Gets the name of the wp option which is used to temporarily indicate that this addon was activated
574
+	 *
575
+	 * @return string
576
+	 */
577
+	public function get_activation_indicator_option_name()
578
+	{
579
+		return 'ee_activation_' . $this->name();
580
+	}
581
+
582
+
583
+	/**
584
+	 * Used by EE_System to set the request type of this addon. Should not be used by addon developers
585
+	 *
586
+	 * @param int $req_type
587
+	 */
588
+	public function set_req_type($req_type)
589
+	{
590
+		$this->_req_type = $req_type;
591
+	}
592
+
593
+
594
+	/**
595
+	 * Returns the request type of this addon (ie, EE_System::req_type_normal, EE_System::req_type_new_activation,
596
+	 * EE_System::req_type_reactivation, EE_System::req_type_upgrade, or EE_System::req_type_downgrade). This is set by
597
+	 * EE_System when it is checking for new install or upgrades of addons
598
+	 */
599
+	public function detect_req_type($redetect = false)
600
+	{
601
+		if ($this->_req_type === null || $redetect) {
602
+			$this->detect_activation_or_upgrade();
603
+		}
604
+		return $this->_req_type;
605
+	}
606
+
607
+
608
+	/**
609
+	 * Detects the request type for this addon (whether it was just activated, upgrades, a normal request, etc.)
610
+	 * Should only be called once per request
611
+	 *
612
+	 * @return void
613
+	 */
614
+	public function detect_activation_or_upgrade()
615
+	{
616
+		$activation_history_for_addon = $this->get_activation_history();
617
+		$request_type = EE_System::detect_req_type_given_activation_history(
618
+			$activation_history_for_addon,
619
+			$this->get_activation_indicator_option_name(),
620
+			$this->version()
621
+		);
622
+		$this->set_req_type($request_type);
623
+		$classname = get_class($this);
624
+		switch ($request_type) {
625
+			case EE_System::req_type_new_activation:
626
+				do_action("AHEE__{$classname}__detect_activations_or_upgrades__new_activation");
627
+				do_action('AHEE__EE_Addon__detect_activations_or_upgrades__new_activation', $this);
628
+				$this->new_install();
629
+				$this->update_list_of_installed_versions($activation_history_for_addon);
630
+				break;
631
+			case EE_System::req_type_reactivation:
632
+				do_action("AHEE__{$classname}__detect_activations_or_upgrades__reactivation");
633
+				do_action('AHEE__EE_Addon__detect_activations_or_upgrades__reactivation', $this);
634
+				$this->reactivation();
635
+				$this->update_list_of_installed_versions($activation_history_for_addon);
636
+				break;
637
+			case EE_System::req_type_upgrade:
638
+				do_action("AHEE__{$classname}__detect_activations_or_upgrades__upgrade");
639
+				do_action('AHEE__EE_Addon__detect_activations_or_upgrades__upgrade', $this);
640
+				$this->upgrade();
641
+				$this->update_list_of_installed_versions($activation_history_for_addon);
642
+				break;
643
+			case EE_System::req_type_downgrade:
644
+				do_action("AHEE__{$classname}__detect_activations_or_upgrades__downgrade");
645
+				do_action('AHEE__EE_Addon__detect_activations_or_upgrades__downgrade', $this);
646
+				$this->downgrade();
647
+				$this->update_list_of_installed_versions($activation_history_for_addon);
648
+				break;
649
+			case EE_System::req_type_normal:
650
+			default:
651
+				break;
652
+		}
653
+
654
+		do_action("AHEE__{$classname}__detect_if_activation_or_upgrade__complete");
655
+	}
656
+
657
+	/**
658
+	 * Updates the version history for this addon
659
+	 *
660
+	 * @param array  $version_history
661
+	 * @param string $current_version_to_add
662
+	 * @return boolean success
663
+	 */
664
+	public function update_list_of_installed_versions($version_history = null, $current_version_to_add = null)
665
+	{
666
+		if (! $version_history) {
667
+			$version_history = $this->get_activation_history();
668
+		}
669
+		if ($current_version_to_add === null) {
670
+			$current_version_to_add = $this->version();
671
+		}
672
+		$version_history[ $current_version_to_add ][] = date('Y-m-d H:i:s', time());
673
+		// resave
674
+		return update_option($this->get_activation_history_option_name(), $version_history);
675
+	}
676
+
677
+	/**
678
+	 * Gets the name of the wp option that stores the activation history
679
+	 * of this addon
680
+	 *
681
+	 * @return string
682
+	 */
683
+	public function get_activation_history_option_name()
684
+	{
685
+		return self::ee_addon_version_history_option_prefix . $this->name();
686
+	}
687
+
688
+
689
+	/**
690
+	 * Gets the wp option which stores the activation history for this addon
691
+	 *
692
+	 * @return array
693
+	 */
694
+	public function get_activation_history()
695
+	{
696
+		return get_option($this->get_activation_history_option_name(), null);
697
+	}
698
+
699
+
700
+	/**
701
+	 * @param string $config_section
702
+	 */
703
+	public function set_config_section($config_section = '')
704
+	{
705
+		$this->_config_section = ! empty($config_section) ? $config_section : 'addons';
706
+	}
707
+
708
+	/**
709
+	 * Sets the filepath to the main plugin file
710
+	 *
711
+	 * @param string $filepath
712
+	 */
713
+	public function set_main_plugin_file($filepath)
714
+	{
715
+		$this->_main_plugin_file = $filepath;
716
+	}
717
+
718
+	/**
719
+	 * gets the filepath to teh main file
720
+	 *
721
+	 * @return string
722
+	 */
723
+	public function get_main_plugin_file()
724
+	{
725
+		return $this->_main_plugin_file;
726
+	}
727
+
728
+	/**
729
+	 * Gets the filename (no path) of the main file (the main file loaded
730
+	 * by WP)
731
+	 *
732
+	 * @return string
733
+	 */
734
+	public function get_main_plugin_file_basename()
735
+	{
736
+		return plugin_basename($this->get_main_plugin_file());
737
+	}
738
+
739
+	/**
740
+	 * Gets the folder name which contains the main plugin file
741
+	 *
742
+	 * @return string
743
+	 */
744
+	public function get_main_plugin_file_dirname()
745
+	{
746
+		return dirname($this->get_main_plugin_file());
747
+	}
748
+
749
+
750
+	/**
751
+	 * sets hooks used in the admin
752
+	 *
753
+	 * @return void
754
+	 */
755
+	public function admin_init()
756
+	{
757
+		// is admin and not in M-Mode ?
758
+		if (is_admin() && ! EE_Maintenance_Mode::instance()->level()) {
759
+			add_filter('plugin_action_links', array($this, 'plugin_action_links'), 10, 2);
760
+			add_filter('after_plugin_row_' . $this->_plugin_basename, array($this, 'after_plugin_row'), 10, 3);
761
+		}
762
+	}
763
+
764
+
765
+	/**
766
+	 * plugin_actions
767
+	 * Add a settings link to the Plugins page, so people can go straight from the plugin page to the settings page.
768
+	 *
769
+	 * @param $links
770
+	 * @param $file
771
+	 * @return array
772
+	 */
773
+	public function plugin_action_links($links, $file)
774
+	{
775
+		if ($file === $this->plugin_basename() && $this->plugin_action_slug() !== '') {
776
+			// before other links
777
+			array_unshift(
778
+				$links,
779
+				'<a href="admin.php?page=' . $this->plugin_action_slug() . '">'
780
+				. esc_html__('Settings', 'event_espresso')
781
+				. '</a>'
782
+			);
783
+		}
784
+		return $links;
785
+	}
786
+
787
+
788
+	/**
789
+	 * after_plugin_row
790
+	 * Add additional content to the plugins page plugin row
791
+	 * Inserts another row
792
+	 *
793
+	 * @param $plugin_file
794
+	 * @param $plugin_data
795
+	 * @param $status
796
+	 * @return void
797
+	 */
798
+	public function after_plugin_row($plugin_file, $plugin_data, $status)
799
+	{
800
+		$after_plugin_row = '';
801
+		$plugins_page_row = $this->get_plugins_page_row();
802
+		if (! empty($plugins_page_row) && $plugin_file === $this->plugin_basename()) {
803
+			$class = $status ? 'active' : 'inactive';
804
+			$link_text = isset($plugins_page_row['link_text']) ? $plugins_page_row['link_text'] : '';
805
+			$link_url = isset($plugins_page_row['link_url']) ? $plugins_page_row['link_url'] : '';
806
+			$description = isset($plugins_page_row['description'])
807
+				? $plugins_page_row['description']
808
+				: '';
809
+			if (! empty($link_text) && ! empty($link_url) && ! empty($description)) {
810
+				$after_plugin_row .= '<tr id="' . sanitize_title($plugin_file) . '-ee-addon" class="' . $class . '">';
811
+				$after_plugin_row .= '<th class="check-column" scope="row"></th>';
812
+				$after_plugin_row .= '<td class="ee-addon-upsell-info-title-td plugin-title column-primary">';
813
+				$after_plugin_row .= '<style>
814 814
 .ee-button,
815 815
 .ee-button:active,
816 816
 .ee-button:visited {
@@ -847,64 +847,64 @@  discard block
 block discarded – undo
847 847
 }
848 848
 .ee-button:active { top:0; }
849 849
 </style>';
850
-                $after_plugin_row .= '
850
+				$after_plugin_row .= '
851 851
 <p class="ee-addon-upsell-info-dv">
852 852
 	<a class="ee-button" href="' . $link_url . '">'
853
-                                     . $link_text
854
-                                     . ' &nbsp;<span class="dashicons dashicons-arrow-right-alt2" style="margin:0;"></span>'
855
-                                     . '</a>
853
+									 . $link_text
854
+									 . ' &nbsp;<span class="dashicons dashicons-arrow-right-alt2" style="margin:0;"></span>'
855
+									 . '</a>
856 856
 </p>';
857
-                $after_plugin_row .= '</td>';
858
-                $after_plugin_row .= '<td class="ee-addon-upsell-info-desc-td column-description desc">';
859
-                $after_plugin_row .= $description;
860
-                $after_plugin_row .= '</td>';
861
-                $after_plugin_row .= '</tr>';
862
-            } else {
863
-                $after_plugin_row .= $description;
864
-            }
865
-        }
866
-
867
-        echo $after_plugin_row;
868
-    }
869
-
870
-
871
-    /**
872
-     * A safe space for addons to add additional logic like setting hooks that need to be set early in the request.
873
-     * Child classes that have logic like that to run can override this method declaration.  This was not made abstract
874
-     * for back compat reasons.
875
-     *
876
-     * This will fire on the `AHEE__EE_System__load_espresso_addons__complete` hook at priority 999.
877
-     *
878
-     * It is recommended, if client code is `de-registering` an add-on, then do it on the
879
-     * `AHEE__EE_System__load_espresso_addons__complete` hook before priority 999 so as to ensure any code logic in this
880
-     * callback does not get run/set in that request.
881
-     *
882
-     * Also, keep in mind that if a registered add-on happens to be deactivated via
883
-     * EE_System::_deactivate_incompatible_addons() because its incompatible, any code executed in this method
884
-     * (including setting hooks etc) will have executed before the plugin was deactivated.  If you use
885
-     * `after_registration` to set any filter and/or action hooks and want to ensure they are removed on this add-on's
886
-     * deactivation, you can override `EE_Addon::deactivation` and unset your hooks and filters there.  Just remember
887
-     * to call `parent::deactivation`.
888
-     *
889
-     * @since 4.9.26
890
-     */
891
-    public function after_registration()
892
-    {
893
-        // cricket chirp... cricket chirp...
894
-    }
895
-
896
-    /**
897
-     * @return string
898
-     */
899
-    public function getPueSlug()
900
-    {
901
-        return $this->pue_slug;
902
-    }
903
-    /**
904
-     * @param string $pue_slug
905
-     */
906
-    public function setPueSlug($pue_slug)
907
-    {
908
-        $this->pue_slug = $pue_slug;
909
-    }
857
+				$after_plugin_row .= '</td>';
858
+				$after_plugin_row .= '<td class="ee-addon-upsell-info-desc-td column-description desc">';
859
+				$after_plugin_row .= $description;
860
+				$after_plugin_row .= '</td>';
861
+				$after_plugin_row .= '</tr>';
862
+			} else {
863
+				$after_plugin_row .= $description;
864
+			}
865
+		}
866
+
867
+		echo $after_plugin_row;
868
+	}
869
+
870
+
871
+	/**
872
+	 * A safe space for addons to add additional logic like setting hooks that need to be set early in the request.
873
+	 * Child classes that have logic like that to run can override this method declaration.  This was not made abstract
874
+	 * for back compat reasons.
875
+	 *
876
+	 * This will fire on the `AHEE__EE_System__load_espresso_addons__complete` hook at priority 999.
877
+	 *
878
+	 * It is recommended, if client code is `de-registering` an add-on, then do it on the
879
+	 * `AHEE__EE_System__load_espresso_addons__complete` hook before priority 999 so as to ensure any code logic in this
880
+	 * callback does not get run/set in that request.
881
+	 *
882
+	 * Also, keep in mind that if a registered add-on happens to be deactivated via
883
+	 * EE_System::_deactivate_incompatible_addons() because its incompatible, any code executed in this method
884
+	 * (including setting hooks etc) will have executed before the plugin was deactivated.  If you use
885
+	 * `after_registration` to set any filter and/or action hooks and want to ensure they are removed on this add-on's
886
+	 * deactivation, you can override `EE_Addon::deactivation` and unset your hooks and filters there.  Just remember
887
+	 * to call `parent::deactivation`.
888
+	 *
889
+	 * @since 4.9.26
890
+	 */
891
+	public function after_registration()
892
+	{
893
+		// cricket chirp... cricket chirp...
894
+	}
895
+
896
+	/**
897
+	 * @return string
898
+	 */
899
+	public function getPueSlug()
900
+	{
901
+		return $this->pue_slug;
902
+	}
903
+	/**
904
+	 * @param string $pue_slug
905
+	 */
906
+	public function setPueSlug($pue_slug)
907
+	{
908
+		$this->pue_slug = $pue_slug;
909
+	}
910 910
 }
Please login to merge, or discard this patch.
Spacing   +10 added lines, -10 removed lines patch added patch discarded remove patch
@@ -576,7 +576,7 @@  discard block
 block discarded – undo
576 576
      */
577 577
     public function get_activation_indicator_option_name()
578 578
     {
579
-        return 'ee_activation_' . $this->name();
579
+        return 'ee_activation_'.$this->name();
580 580
     }
581 581
 
582 582
 
@@ -663,13 +663,13 @@  discard block
 block discarded – undo
663 663
      */
664 664
     public function update_list_of_installed_versions($version_history = null, $current_version_to_add = null)
665 665
     {
666
-        if (! $version_history) {
666
+        if ( ! $version_history) {
667 667
             $version_history = $this->get_activation_history();
668 668
         }
669 669
         if ($current_version_to_add === null) {
670 670
             $current_version_to_add = $this->version();
671 671
         }
672
-        $version_history[ $current_version_to_add ][] = date('Y-m-d H:i:s', time());
672
+        $version_history[$current_version_to_add][] = date('Y-m-d H:i:s', time());
673 673
         // resave
674 674
         return update_option($this->get_activation_history_option_name(), $version_history);
675 675
     }
@@ -682,7 +682,7 @@  discard block
 block discarded – undo
682 682
      */
683 683
     public function get_activation_history_option_name()
684 684
     {
685
-        return self::ee_addon_version_history_option_prefix . $this->name();
685
+        return self::ee_addon_version_history_option_prefix.$this->name();
686 686
     }
687 687
 
688 688
 
@@ -757,7 +757,7 @@  discard block
 block discarded – undo
757 757
         // is admin and not in M-Mode ?
758 758
         if (is_admin() && ! EE_Maintenance_Mode::instance()->level()) {
759 759
             add_filter('plugin_action_links', array($this, 'plugin_action_links'), 10, 2);
760
-            add_filter('after_plugin_row_' . $this->_plugin_basename, array($this, 'after_plugin_row'), 10, 3);
760
+            add_filter('after_plugin_row_'.$this->_plugin_basename, array($this, 'after_plugin_row'), 10, 3);
761 761
         }
762 762
     }
763 763
 
@@ -776,7 +776,7 @@  discard block
 block discarded – undo
776 776
             // before other links
777 777
             array_unshift(
778 778
                 $links,
779
-                '<a href="admin.php?page=' . $this->plugin_action_slug() . '">'
779
+                '<a href="admin.php?page='.$this->plugin_action_slug().'">'
780 780
                 . esc_html__('Settings', 'event_espresso')
781 781
                 . '</a>'
782 782
             );
@@ -799,15 +799,15 @@  discard block
 block discarded – undo
799 799
     {
800 800
         $after_plugin_row = '';
801 801
         $plugins_page_row = $this->get_plugins_page_row();
802
-        if (! empty($plugins_page_row) && $plugin_file === $this->plugin_basename()) {
802
+        if ( ! empty($plugins_page_row) && $plugin_file === $this->plugin_basename()) {
803 803
             $class = $status ? 'active' : 'inactive';
804 804
             $link_text = isset($plugins_page_row['link_text']) ? $plugins_page_row['link_text'] : '';
805 805
             $link_url = isset($plugins_page_row['link_url']) ? $plugins_page_row['link_url'] : '';
806 806
             $description = isset($plugins_page_row['description'])
807 807
                 ? $plugins_page_row['description']
808 808
                 : '';
809
-            if (! empty($link_text) && ! empty($link_url) && ! empty($description)) {
810
-                $after_plugin_row .= '<tr id="' . sanitize_title($plugin_file) . '-ee-addon" class="' . $class . '">';
809
+            if ( ! empty($link_text) && ! empty($link_url) && ! empty($description)) {
810
+                $after_plugin_row .= '<tr id="'.sanitize_title($plugin_file).'-ee-addon" class="'.$class.'">';
811 811
                 $after_plugin_row .= '<th class="check-column" scope="row"></th>';
812 812
                 $after_plugin_row .= '<td class="ee-addon-upsell-info-title-td plugin-title column-primary">';
813 813
                 $after_plugin_row .= '<style>
@@ -849,7 +849,7 @@  discard block
 block discarded – undo
849 849
 </style>';
850 850
                 $after_plugin_row .= '
851 851
 <p class="ee-addon-upsell-info-dv">
852
-	<a class="ee-button" href="' . $link_url . '">'
852
+	<a class="ee-button" href="' . $link_url.'">'
853 853
                                      . $link_text
854 854
                                      . ' &nbsp;<span class="dashicons dashicons-arrow-right-alt2" style="margin:0;"></span>'
855 855
                                      . '</a>
Please login to merge, or discard this patch.
core/services/orm/tree_traversal/ModelObjNode.php 2 patches
Indentation   +188 added lines, -188 removed lines patch added patch discarded remove patch
@@ -22,206 +22,206 @@
 block discarded – undo
22 22
  */
23 23
 class ModelObjNode extends BaseNode
24 24
 {
25
-    /**
26
-     * @var int|string
27
-     */
28
-    protected $id;
25
+	/**
26
+	 * @var int|string
27
+	 */
28
+	protected $id;
29 29
 
30
-    /**
31
-     * @var EEM_Base
32
-     */
33
-    protected $model;
30
+	/**
31
+	 * @var EEM_Base
32
+	 */
33
+	protected $model;
34 34
 
35
-    /**
36
-     * @var RelationNode[]
37
-     */
38
-    protected $nodes;
35
+	/**
36
+	 * @var RelationNode[]
37
+	 */
38
+	protected $nodes;
39 39
 
40
-    /**
41
-     * We don't pass the model objects because this needs to serialize to something tiny for effiency.
42
-     * @param $model_obj_id
43
-     * @param EEM_Base $model
44
-     * @param array $dont_traverse_models array of model names we DON'T want to traverse.
45
-     */
46
-    public function __construct($model_obj_id, EEM_Base $model, array $dont_traverse_models = [])
47
-    {
48
-        $this->id = $model_obj_id;
49
-        $this->model = $model;
50
-        $this->dont_traverse_models = $dont_traverse_models;
51
-    }
40
+	/**
41
+	 * We don't pass the model objects because this needs to serialize to something tiny for effiency.
42
+	 * @param $model_obj_id
43
+	 * @param EEM_Base $model
44
+	 * @param array $dont_traverse_models array of model names we DON'T want to traverse.
45
+	 */
46
+	public function __construct($model_obj_id, EEM_Base $model, array $dont_traverse_models = [])
47
+	{
48
+		$this->id = $model_obj_id;
49
+		$this->model = $model;
50
+		$this->dont_traverse_models = $dont_traverse_models;
51
+	}
52 52
 
53
-    /**
54
-     * Creates a relation node for each relation of this model's relations.
55
-     * Does NOT call `discover` on them yet though.
56
-     * @since 4.10.12.p
57
-     * @throws \EE_Error
58
-     * @throws InvalidDataTypeException
59
-     * @throws InvalidInterfaceException
60
-     * @throws InvalidArgumentException
61
-     * @throws ReflectionException
62
-     */
63
-    protected function discover()
64
-    {
65
-        $this->nodes = [];
66
-        foreach ($this->model->relation_settings() as $relationName => $relation) {
67
-            // Make sure this isn't one of the models we were told to not traverse into.
68
-            if (in_array($relationName, $this->dont_traverse_models)) {
69
-                continue;
70
-            }
71
-            if ($relation instanceof EE_Has_Many_Relation) {
72
-                $this->nodes[ $relationName ] = new RelationNode(
73
-                    $this->id,
74
-                    $this->model,
75
-                    $relation->get_other_model(),
76
-                    $this->dont_traverse_models
77
-                );
78
-            } elseif (
79
-                $relation instanceof EE_HABTM_Relation &&
80
-                ! in_array(
81
-                    $relation->get_join_model()->get_this_model_name(),
82
-                    $this->dont_traverse_models
83
-                )
84
-            ) {
85
-                $this->nodes[ $relation->get_join_model()->get_this_model_name() ] = new RelationNode(
86
-                    $this->id,
87
-                    $this->model,
88
-                    $relation->get_join_model(),
89
-                    $this->dont_traverse_models
90
-                );
91
-            }
92
-        }
93
-        ksort($this->nodes);
94
-    }
53
+	/**
54
+	 * Creates a relation node for each relation of this model's relations.
55
+	 * Does NOT call `discover` on them yet though.
56
+	 * @since 4.10.12.p
57
+	 * @throws \EE_Error
58
+	 * @throws InvalidDataTypeException
59
+	 * @throws InvalidInterfaceException
60
+	 * @throws InvalidArgumentException
61
+	 * @throws ReflectionException
62
+	 */
63
+	protected function discover()
64
+	{
65
+		$this->nodes = [];
66
+		foreach ($this->model->relation_settings() as $relationName => $relation) {
67
+			// Make sure this isn't one of the models we were told to not traverse into.
68
+			if (in_array($relationName, $this->dont_traverse_models)) {
69
+				continue;
70
+			}
71
+			if ($relation instanceof EE_Has_Many_Relation) {
72
+				$this->nodes[ $relationName ] = new RelationNode(
73
+					$this->id,
74
+					$this->model,
75
+					$relation->get_other_model(),
76
+					$this->dont_traverse_models
77
+				);
78
+			} elseif (
79
+				$relation instanceof EE_HABTM_Relation &&
80
+				! in_array(
81
+					$relation->get_join_model()->get_this_model_name(),
82
+					$this->dont_traverse_models
83
+				)
84
+			) {
85
+				$this->nodes[ $relation->get_join_model()->get_this_model_name() ] = new RelationNode(
86
+					$this->id,
87
+					$this->model,
88
+					$relation->get_join_model(),
89
+					$this->dont_traverse_models
90
+				);
91
+			}
92
+		}
93
+		ksort($this->nodes);
94
+	}
95 95
 
96 96
 
97
-    /**
98
-     * Whether this item has already been initialized
99
-     */
100
-    protected function isDiscovered()
101
-    {
102
-        return $this->nodes !== null && is_array($this->nodes);
103
-    }
97
+	/**
98
+	 * Whether this item has already been initialized
99
+	 */
100
+	protected function isDiscovered()
101
+	{
102
+		return $this->nodes !== null && is_array($this->nodes);
103
+	}
104 104
 
105
-    /**
106
-     * @since 4.10.12.p
107
-     * @return boolean
108
-     */
109
-    public function isComplete()
110
-    {
111
-        if ($this->complete === null) {
112
-            $this->complete = false;
113
-        }
114
-        return $this->complete;
115
-    }
105
+	/**
106
+	 * @since 4.10.12.p
107
+	 * @return boolean
108
+	 */
109
+	public function isComplete()
110
+	{
111
+		if ($this->complete === null) {
112
+			$this->complete = false;
113
+		}
114
+		return $this->complete;
115
+	}
116 116
 
117
-    /**
118
-     * Triggers working on each child relation node that has work to do.
119
-     * @since 4.10.12.p
120
-     * @param $model_objects_to_identify
121
-     * @return int units of work done
122
-     */
123
-    protected function work($model_objects_to_identify)
124
-    {
125
-        $num_identified = 0;
126
-        // Begin assuming we'll finish all the work on this node and its children...
127
-        $this->complete = true;
128
-        foreach ($this->nodes as $model_name => $relation_node) {
129
-            $num_identified += $relation_node->visit($model_objects_to_identify - $num_identified);
130
-            // To save on space when serializing, only bother keeping a record of relation nodes that actually found
131
-            // related model objects.
132
-            if ($relation_node->isComplete() && $relation_node->countSubNodes() === 0) {
133
-                unset($this->nodes[ $model_name ]);
134
-            }
135
-            if ($num_identified >= $model_objects_to_identify) {
136
-                // ...but admit we're wrong if the work exceeded the budget.
137
-                $this->complete = false;
138
-                break;
139
-            }
140
-        }
141
-        return $num_identified;
142
-    }
117
+	/**
118
+	 * Triggers working on each child relation node that has work to do.
119
+	 * @since 4.10.12.p
120
+	 * @param $model_objects_to_identify
121
+	 * @return int units of work done
122
+	 */
123
+	protected function work($model_objects_to_identify)
124
+	{
125
+		$num_identified = 0;
126
+		// Begin assuming we'll finish all the work on this node and its children...
127
+		$this->complete = true;
128
+		foreach ($this->nodes as $model_name => $relation_node) {
129
+			$num_identified += $relation_node->visit($model_objects_to_identify - $num_identified);
130
+			// To save on space when serializing, only bother keeping a record of relation nodes that actually found
131
+			// related model objects.
132
+			if ($relation_node->isComplete() && $relation_node->countSubNodes() === 0) {
133
+				unset($this->nodes[ $model_name ]);
134
+			}
135
+			if ($num_identified >= $model_objects_to_identify) {
136
+				// ...but admit we're wrong if the work exceeded the budget.
137
+				$this->complete = false;
138
+				break;
139
+			}
140
+		}
141
+		return $num_identified;
142
+	}
143 143
 
144
-    /**
145
-     * @since 4.10.12.p
146
-     * @return array
147
-     * @throws \EE_Error
148
-     * @throws InvalidDataTypeException
149
-     * @throws InvalidInterfaceException
150
-     * @throws InvalidArgumentException
151
-     * @throws ReflectionException
152
-     */
153
-    public function toArray()
154
-    {
155
-        $tree = [
156
-            'id' => $this->id,
157
-            'complete' => $this->isComplete(),
158
-            'rels' => []
159
-        ];
160
-        if ($this->nodes === null) {
161
-            $tree['rels'] = null;
162
-        } else {
163
-            foreach ($this->nodes as $relation_name => $relation_node) {
164
-                $tree['rels'][ $relation_name ] = $relation_node->toArray();
165
-            }
166
-        }
167
-        return $tree;
168
-    }
144
+	/**
145
+	 * @since 4.10.12.p
146
+	 * @return array
147
+	 * @throws \EE_Error
148
+	 * @throws InvalidDataTypeException
149
+	 * @throws InvalidInterfaceException
150
+	 * @throws InvalidArgumentException
151
+	 * @throws ReflectionException
152
+	 */
153
+	public function toArray()
154
+	{
155
+		$tree = [
156
+			'id' => $this->id,
157
+			'complete' => $this->isComplete(),
158
+			'rels' => []
159
+		];
160
+		if ($this->nodes === null) {
161
+			$tree['rels'] = null;
162
+		} else {
163
+			foreach ($this->nodes as $relation_name => $relation_node) {
164
+				$tree['rels'][ $relation_name ] = $relation_node->toArray();
165
+			}
166
+		}
167
+		return $tree;
168
+	}
169 169
 
170
-    /**
171
-     * @since 4.10.12.p
172
-     * @return array|mixed
173
-     * @throws InvalidArgumentException
174
-     * @throws InvalidDataTypeException
175
-     * @throws InvalidInterfaceException
176
-     * @throws ReflectionException
177
-     * @throws \EE_Error
178
-     */
179
-    public function getIds()
180
-    {
181
-        $ids = [
182
-            $this->model->get_this_model_name() => [
183
-                $this->id => $this->id
184
-            ]
185
-        ];
186
-        if ($this->nodes && is_array($this->nodes)) {
187
-            foreach ($this->nodes as $relation_node) {
188
-                $ids = array_replace_recursive($ids, $relation_node->getIds());
189
-            }
190
-        }
191
-        return $ids;
192
-    }
170
+	/**
171
+	 * @since 4.10.12.p
172
+	 * @return array|mixed
173
+	 * @throws InvalidArgumentException
174
+	 * @throws InvalidDataTypeException
175
+	 * @throws InvalidInterfaceException
176
+	 * @throws ReflectionException
177
+	 * @throws \EE_Error
178
+	 */
179
+	public function getIds()
180
+	{
181
+		$ids = [
182
+			$this->model->get_this_model_name() => [
183
+				$this->id => $this->id
184
+			]
185
+		];
186
+		if ($this->nodes && is_array($this->nodes)) {
187
+			foreach ($this->nodes as $relation_node) {
188
+				$ids = array_replace_recursive($ids, $relation_node->getIds());
189
+			}
190
+		}
191
+		return $ids;
192
+	}
193 193
 
194
-    /**
195
-     * Don't serialize the models. Just record their names on some dynamic properties.
196
-     * @since 4.10.12.p
197
-     */
198
-    public function __sleep()
199
-    {
200
-        $this->m = $this->model->get_this_model_name();
201
-        return array_merge(
202
-            [
203
-                'm',
204
-                'id',
205
-                'nodes',
206
-            ],
207
-            parent::__sleep()
208
-        );
209
-    }
194
+	/**
195
+	 * Don't serialize the models. Just record their names on some dynamic properties.
196
+	 * @since 4.10.12.p
197
+	 */
198
+	public function __sleep()
199
+	{
200
+		$this->m = $this->model->get_this_model_name();
201
+		return array_merge(
202
+			[
203
+				'm',
204
+				'id',
205
+				'nodes',
206
+			],
207
+			parent::__sleep()
208
+		);
209
+	}
210 210
 
211
-    /**
212
-     * Use the dynamic properties to instantiate the models we use.
213
-     * @since 4.10.12.p
214
-     * @throws EE_Error
215
-     * @throws InvalidArgumentException
216
-     * @throws InvalidDataTypeException
217
-     * @throws InvalidInterfaceException
218
-     * @throws ReflectionException
219
-     */
220
-    public function __wakeup()
221
-    {
222
-        $this->model = EE_Registry::instance()->load_model($this->m);
223
-        parent::__wakeup();
224
-    }
211
+	/**
212
+	 * Use the dynamic properties to instantiate the models we use.
213
+	 * @since 4.10.12.p
214
+	 * @throws EE_Error
215
+	 * @throws InvalidArgumentException
216
+	 * @throws InvalidDataTypeException
217
+	 * @throws InvalidInterfaceException
218
+	 * @throws ReflectionException
219
+	 */
220
+	public function __wakeup()
221
+	{
222
+		$this->model = EE_Registry::instance()->load_model($this->m);
223
+		parent::__wakeup();
224
+	}
225 225
 }
226 226
 // End of file Visitor.php
227 227
 // Location: EventEspresso\core\services\orm\tree_traversal/Visitor.php
Please login to merge, or discard this patch.
Spacing   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -69,7 +69,7 @@  discard block
 block discarded – undo
69 69
                 continue;
70 70
             }
71 71
             if ($relation instanceof EE_Has_Many_Relation) {
72
-                $this->nodes[ $relationName ] = new RelationNode(
72
+                $this->nodes[$relationName] = new RelationNode(
73 73
                     $this->id,
74 74
                     $this->model,
75 75
                     $relation->get_other_model(),
@@ -82,7 +82,7 @@  discard block
 block discarded – undo
82 82
                     $this->dont_traverse_models
83 83
                 )
84 84
             ) {
85
-                $this->nodes[ $relation->get_join_model()->get_this_model_name() ] = new RelationNode(
85
+                $this->nodes[$relation->get_join_model()->get_this_model_name()] = new RelationNode(
86 86
                     $this->id,
87 87
                     $this->model,
88 88
                     $relation->get_join_model(),
@@ -130,7 +130,7 @@  discard block
 block discarded – undo
130 130
             // To save on space when serializing, only bother keeping a record of relation nodes that actually found
131 131
             // related model objects.
132 132
             if ($relation_node->isComplete() && $relation_node->countSubNodes() === 0) {
133
-                unset($this->nodes[ $model_name ]);
133
+                unset($this->nodes[$model_name]);
134 134
             }
135 135
             if ($num_identified >= $model_objects_to_identify) {
136 136
                 // ...but admit we're wrong if the work exceeded the budget.
@@ -161,7 +161,7 @@  discard block
 block discarded – undo
161 161
             $tree['rels'] = null;
162 162
         } else {
163 163
             foreach ($this->nodes as $relation_name => $relation_node) {
164
-                $tree['rels'][ $relation_name ] = $relation_node->toArray();
164
+                $tree['rels'][$relation_name] = $relation_node->toArray();
165 165
             }
166 166
         }
167 167
         return $tree;
Please login to merge, or discard this patch.
core/business/EE_Registration_Processor.class.php 2 patches
Indentation   +770 added lines, -770 removed lines patch added patch discarded remove patch
@@ -26,775 +26,775 @@
 block discarded – undo
26 26
 class EE_Registration_Processor extends EE_Processor_Base
27 27
 {
28 28
 
29
-    /**
30
-     * @var EE_Registration_Processor $_instance
31
-     * @access    private
32
-     */
33
-    private static $_instance;
34
-
35
-    /**
36
-     * initial reg status at the beginning of this request.
37
-     * indexed by registration ID
38
-     *
39
-     * @var array
40
-     */
41
-    protected $_old_reg_status = [];
42
-
43
-    /**
44
-     * reg status at the end of the request after all processing.
45
-     * indexed by registration ID
46
-     *
47
-     * @var array
48
-     */
49
-    protected $_new_reg_status = [];
50
-
51
-    /**
52
-     * amounts paid at the end of the request after all processing.
53
-     * indexed by registration ID
54
-     *
55
-     * @var array
56
-     */
57
-    protected static $_amount_paid = [];
58
-
59
-    /**
60
-     * Cache of the reg final price for registrations corresponding to a ticket line item
61
-     *
62
-     * @deprecated
63
-     * @var array @see EEH_Line_Item::calculate_reg_final_prices_per_line_item()'s return value
64
-     */
65
-    protected $_reg_final_price_per_tkt_line_item;
66
-
67
-    /**
68
-     * @var RequestInterface $request
69
-     */
70
-    protected $request;
71
-
72
-
73
-    /**
74
-     * @singleton method used to instantiate class object
75
-     * @param RequestInterface|null $request
76
-     * @return EE_Registration_Processor instance
77
-     * @throws InvalidArgumentException
78
-     * @throws InvalidInterfaceException
79
-     * @throws InvalidDataTypeException
80
-     */
81
-    public static function instance(RequestInterface $request = null)
82
-    {
83
-        // check if class object is instantiated
84
-        if (! self::$_instance instanceof EE_Registration_Processor) {
85
-            if (! $request instanceof RequestInterface) {
86
-                $request = LoaderFactory::getLoader()->getShared('EventEspresso\core\services\request\Request');
87
-            }
88
-            self::$_instance = new self($request);
89
-        }
90
-        return self::$_instance;
91
-    }
92
-
93
-
94
-    /**
95
-     * EE_Registration_Processor constructor.
96
-     *
97
-     * @param RequestInterface $request
98
-     */
99
-    public function __construct(RequestInterface $request)
100
-    {
101
-        $this->request = $request;
102
-    }
103
-
104
-
105
-    /**
106
-     * @param int $REG_ID
107
-     * @return string
108
-     */
109
-    public function old_reg_status($REG_ID)
110
-    {
111
-        return isset($this->_old_reg_status[ $REG_ID ]) ? $this->_old_reg_status[ $REG_ID ] : null;
112
-    }
113
-
114
-
115
-    /**
116
-     * @param int    $REG_ID
117
-     * @param string $old_reg_status
118
-     */
119
-    public function set_old_reg_status($REG_ID, $old_reg_status)
120
-    {
121
-        // only set the first time
122
-        if (! isset($this->_old_reg_status[ $REG_ID ])) {
123
-            $this->_old_reg_status[ $REG_ID ] = $old_reg_status;
124
-        }
125
-    }
126
-
127
-
128
-    /**
129
-     * @param int $REG_ID
130
-     * @return string
131
-     */
132
-    public function new_reg_status($REG_ID)
133
-    {
134
-        return isset($this->_new_reg_status[ $REG_ID ]) ? $this->_new_reg_status[ $REG_ID ] : null;
135
-    }
136
-
137
-
138
-    /**
139
-     * @param int    $REG_ID
140
-     * @param string $new_reg_status
141
-     */
142
-    public function set_new_reg_status($REG_ID, $new_reg_status)
143
-    {
144
-        $this->_new_reg_status[ $REG_ID ] = $new_reg_status;
145
-    }
146
-
147
-
148
-    /**
149
-     * reg_status_updated
150
-     *
151
-     * @param int $REG_ID
152
-     * @return bool
153
-     */
154
-    public function reg_status_updated($REG_ID)
155
-    {
156
-        return $this->new_reg_status($REG_ID) !== $this->old_reg_status($REG_ID);
157
-    }
158
-
159
-
160
-    /**
161
-     * @param EE_Registration $registration
162
-     * @throws EE_Error
163
-     * @throws EntityNotFoundException
164
-     * @throws InvalidArgumentException
165
-     * @throws InvalidDataTypeException
166
-     * @throws InvalidInterfaceException
167
-     * @throws ReflectionException
168
-     * @throws RuntimeException
169
-     */
170
-    public function update_registration_status_and_trigger_notifications(EE_Registration $registration)
171
-    {
172
-        $this->toggle_incomplete_registration_status_to_default($registration, false);
173
-        $this->toggle_registration_status_for_default_approved_events($registration, false);
174
-        $this->toggle_registration_status_if_no_monies_owing($registration, false);
175
-        $registration->save();
176
-        // trigger notifications
177
-        $this->trigger_registration_update_notifications($registration);
178
-    }
179
-
180
-
181
-    /**
182
-     *    manually_update_registration_status
183
-     *
184
-     * @access public
185
-     * @param EE_Registration $registration
186
-     * @param string          $new_reg_status
187
-     * @param bool            $save TRUE will save the registration if the status is updated, FALSE will leave that up
188
-     *                              to client code
189
-     * @return bool
190
-     * @throws EE_Error
191
-     * @throws EntityNotFoundException
192
-     * @throws InvalidArgumentException
193
-     * @throws InvalidDataTypeException
194
-     * @throws InvalidInterfaceException
195
-     * @throws ReflectionException
196
-     * @throws RuntimeException
197
-     */
198
-    public function manually_update_registration_status(
199
-        EE_Registration $registration,
200
-        $new_reg_status = '',
201
-        $save = true
202
-    ) {
203
-        // set initial REG_Status
204
-        $this->set_old_reg_status($registration->ID(), $registration->status_ID());
205
-        // set incoming REG_Status
206
-        $this->set_new_reg_status($registration->ID(), $new_reg_status);
207
-        // toggle reg status but only if it has changed and the user can do so
208
-        if (
209
-            $this->reg_status_updated($registration->ID())
210
-            && (
211
-                (! $this->request->isAdmin() || $this->request->isFrontAjax())
212
-                || EE_Registry::instance()->CAP->current_user_can(
213
-                    'ee_edit_registration',
214
-                    'toggle_registration_status',
215
-                    $registration->ID()
216
-                )
217
-            )
218
-        ) {
219
-            // change status to new value
220
-            $updated = $registration->set_status($this->new_reg_status($registration->ID()));
221
-            if ($updated && $save) {
222
-                $registration->save();
223
-            }
224
-            return true;
225
-        }
226
-        return false;
227
-    }
228
-
229
-
230
-    /**
231
-     *    toggle_incomplete_registration_status_to_default
232
-     *        changes any incomplete registrations to either the event or global default registration status
233
-     *
234
-     * @access public
235
-     * @param EE_Registration       $registration
236
-     * @param bool                  $save TRUE will save the registration if the status is updated, FALSE will leave
237
-     *                                    that up to client code
238
-     * @param ContextInterface|null $context
239
-     * @return void
240
-     * @throws EE_Error
241
-     * @throws InvalidArgumentException
242
-     * @throws ReflectionException
243
-     * @throws RuntimeException
244
-     * @throws EntityNotFoundException
245
-     * @throws InvalidDataTypeException
246
-     * @throws InvalidInterfaceException
247
-     */
248
-    public function toggle_incomplete_registration_status_to_default(
249
-        EE_Registration $registration,
250
-        $save = true,
251
-        ContextInterface $context = null
252
-    ) {
253
-        $existing_reg_status = $registration->status_ID();
254
-        // set initial REG_Status
255
-        $this->set_old_reg_status($registration->ID(), $existing_reg_status);
256
-        // is the registration currently incomplete ?
257
-        if ($registration->status_ID() === EEM_Registration::status_id_incomplete) {
258
-            // grab default reg status for the event, if set
259
-            $event_default_registration_status = $registration->event()->default_registration_status();
260
-            // if no default reg status is set for the event, then use the global value
261
-            $STS_ID = ! empty($event_default_registration_status)
262
-                ? $event_default_registration_status
263
-                : EE_Registry::instance()->CFG->registration->default_STS_ID;
264
-            // if the event default reg status is approved, then downgrade temporarily to payment pending to ensure that payments are triggered
265
-            $STS_ID = $STS_ID === EEM_Registration::status_id_approved ? EEM_Registration::status_id_pending_payment
266
-                : $STS_ID;
267
-            // set incoming REG_Status
268
-            $this->set_new_reg_status($registration->ID(), $STS_ID);
269
-            $registration->set_status($STS_ID, false, $context);
270
-            if ($save) {
271
-                $registration->save();
272
-            }
273
-            // don't trigger notifications during IPNs because they will get triggered by EE_Payment_Processor
274
-            if (! EE_Processor_Base::$IPN) {
275
-                // otherwise, send out notifications
276
-                add_filter('FHEE__EED_Messages___maybe_registration__deliver_notifications', '__return_true', 10);
277
-            }
278
-            // DEBUG LOG
279
-            // $this->log(
280
-            //     __CLASS__,
281
-            //     __FUNCTION__,
282
-            //     __LINE__,
283
-            //     $registration->transaction(),
284
-            //     array(
285
-            //         'IPN' => EE_Processor_Base::$IPN,
286
-            //         'deliver_notifications' => has_filter(
287
-            //             'FHEE__EED_Messages___maybe_registration__deliver_notifications'
288
-            //         ),
289
-            //     )
290
-            // );
291
-        }
292
-    }
293
-
294
-
295
-    /**
296
-     *    toggle_registration_status_for_default_approved_events
297
-     *
298
-     * @access public
299
-     * @param EE_Registration $registration
300
-     * @param bool            $save TRUE will save the registration if the status is updated, FALSE will leave that up
301
-     *                              to client code
302
-     * @return bool
303
-     * @throws EE_Error
304
-     * @throws EntityNotFoundException
305
-     * @throws InvalidArgumentException
306
-     * @throws InvalidDataTypeException
307
-     * @throws InvalidInterfaceException
308
-     * @throws ReflectionException
309
-     * @throws RuntimeException
310
-     */
311
-    public function toggle_registration_status_for_default_approved_events(EE_Registration $registration, $save = true)
312
-    {
313
-        $reg_status = $registration->status_ID();
314
-        // set initial REG_Status
315
-        $this->set_old_reg_status($registration->ID(), $reg_status);
316
-        // if not already, toggle reg status to approved IF the event default reg status is approved
317
-        // ( as long as the registration wasn't cancelled or declined at some point )
318
-        if (
319
-            $reg_status !== EEM_Registration::status_id_cancelled
320
-            && $reg_status
321
-               !== EEM_Registration::status_id_declined
322
-            && $reg_status !== EEM_Registration::status_id_approved
323
-            && $registration->event()->default_registration_status() === EEM_Registration::status_id_approved
324
-        ) {
325
-            // set incoming REG_Status
326
-            $this->set_new_reg_status($registration->ID(), EEM_Registration::status_id_approved);
327
-            // toggle status to approved
328
-            $registration->set_status(EEM_Registration::status_id_approved);
329
-            if ($save) {
330
-                $registration->save();
331
-            }
332
-            // don't trigger notifications during IPNs because they will get triggered by EE_Payment_Processor
333
-            if (! EE_Processor_Base::$IPN) {
334
-                // otherwise, send out notifications
335
-                add_filter('FHEE__EED_Messages___maybe_registration__deliver_notifications', '__return_true', 10);
336
-            }
337
-            // DEBUG LOG
338
-            // $this->log(
339
-            //     __CLASS__,
340
-            //     __FUNCTION__,
341
-            //     __LINE__,
342
-            //     $registration->transaction(),
343
-            //     array(
344
-            //         'IPN' => EE_Processor_Base::$IPN,
345
-            //         'deliver_notifications' => has_filter(
346
-            //             'FHEE__EED_Messages___maybe_registration__deliver_notifications'
347
-            //         ),
348
-            //     )
349
-            // );
350
-            return true;
351
-        }
352
-        return false;
353
-    }
354
-
355
-
356
-    /**
357
-     *    toggle_registration_statuses_if_no_monies_owing
358
-     *
359
-     * @access public
360
-     * @param EE_Registration $registration
361
-     * @param bool            $save TRUE will save the registration if the status is updated, FALSE will leave that up
362
-     *                              to client code
363
-     * @param array           $additional_details
364
-     * @return bool
365
-     * @throws EE_Error
366
-     * @throws EntityNotFoundException
367
-     * @throws InvalidArgumentException
368
-     * @throws InvalidDataTypeException
369
-     * @throws InvalidInterfaceException
370
-     * @throws ReflectionException
371
-     * @throws RuntimeException
372
-     */
373
-    public function toggle_registration_status_if_no_monies_owing(
374
-        EE_Registration $registration,
375
-        $save = true,
376
-        array $additional_details = []
377
-    ) {
378
-        // set initial REG_Status
379
-        $this->set_old_reg_status($registration->ID(), $registration->status_ID());
380
-        // was a payment just made ?
381
-        $payment    = isset($additional_details['payment_updates'], $additional_details['last_payment'])
382
-                      && $additional_details['payment_updates']
383
-                      && $additional_details['last_payment'] instanceof EE_Payment
384
-            ? $additional_details['last_payment']
385
-            : null;
386
-        $total_paid = array_sum(self::$_amount_paid);
387
-        // toggle reg status to approved IF
388
-        if (
29
+	/**
30
+	 * @var EE_Registration_Processor $_instance
31
+	 * @access    private
32
+	 */
33
+	private static $_instance;
34
+
35
+	/**
36
+	 * initial reg status at the beginning of this request.
37
+	 * indexed by registration ID
38
+	 *
39
+	 * @var array
40
+	 */
41
+	protected $_old_reg_status = [];
42
+
43
+	/**
44
+	 * reg status at the end of the request after all processing.
45
+	 * indexed by registration ID
46
+	 *
47
+	 * @var array
48
+	 */
49
+	protected $_new_reg_status = [];
50
+
51
+	/**
52
+	 * amounts paid at the end of the request after all processing.
53
+	 * indexed by registration ID
54
+	 *
55
+	 * @var array
56
+	 */
57
+	protected static $_amount_paid = [];
58
+
59
+	/**
60
+	 * Cache of the reg final price for registrations corresponding to a ticket line item
61
+	 *
62
+	 * @deprecated
63
+	 * @var array @see EEH_Line_Item::calculate_reg_final_prices_per_line_item()'s return value
64
+	 */
65
+	protected $_reg_final_price_per_tkt_line_item;
66
+
67
+	/**
68
+	 * @var RequestInterface $request
69
+	 */
70
+	protected $request;
71
+
72
+
73
+	/**
74
+	 * @singleton method used to instantiate class object
75
+	 * @param RequestInterface|null $request
76
+	 * @return EE_Registration_Processor instance
77
+	 * @throws InvalidArgumentException
78
+	 * @throws InvalidInterfaceException
79
+	 * @throws InvalidDataTypeException
80
+	 */
81
+	public static function instance(RequestInterface $request = null)
82
+	{
83
+		// check if class object is instantiated
84
+		if (! self::$_instance instanceof EE_Registration_Processor) {
85
+			if (! $request instanceof RequestInterface) {
86
+				$request = LoaderFactory::getLoader()->getShared('EventEspresso\core\services\request\Request');
87
+			}
88
+			self::$_instance = new self($request);
89
+		}
90
+		return self::$_instance;
91
+	}
92
+
93
+
94
+	/**
95
+	 * EE_Registration_Processor constructor.
96
+	 *
97
+	 * @param RequestInterface $request
98
+	 */
99
+	public function __construct(RequestInterface $request)
100
+	{
101
+		$this->request = $request;
102
+	}
103
+
104
+
105
+	/**
106
+	 * @param int $REG_ID
107
+	 * @return string
108
+	 */
109
+	public function old_reg_status($REG_ID)
110
+	{
111
+		return isset($this->_old_reg_status[ $REG_ID ]) ? $this->_old_reg_status[ $REG_ID ] : null;
112
+	}
113
+
114
+
115
+	/**
116
+	 * @param int    $REG_ID
117
+	 * @param string $old_reg_status
118
+	 */
119
+	public function set_old_reg_status($REG_ID, $old_reg_status)
120
+	{
121
+		// only set the first time
122
+		if (! isset($this->_old_reg_status[ $REG_ID ])) {
123
+			$this->_old_reg_status[ $REG_ID ] = $old_reg_status;
124
+		}
125
+	}
126
+
127
+
128
+	/**
129
+	 * @param int $REG_ID
130
+	 * @return string
131
+	 */
132
+	public function new_reg_status($REG_ID)
133
+	{
134
+		return isset($this->_new_reg_status[ $REG_ID ]) ? $this->_new_reg_status[ $REG_ID ] : null;
135
+	}
136
+
137
+
138
+	/**
139
+	 * @param int    $REG_ID
140
+	 * @param string $new_reg_status
141
+	 */
142
+	public function set_new_reg_status($REG_ID, $new_reg_status)
143
+	{
144
+		$this->_new_reg_status[ $REG_ID ] = $new_reg_status;
145
+	}
146
+
147
+
148
+	/**
149
+	 * reg_status_updated
150
+	 *
151
+	 * @param int $REG_ID
152
+	 * @return bool
153
+	 */
154
+	public function reg_status_updated($REG_ID)
155
+	{
156
+		return $this->new_reg_status($REG_ID) !== $this->old_reg_status($REG_ID);
157
+	}
158
+
159
+
160
+	/**
161
+	 * @param EE_Registration $registration
162
+	 * @throws EE_Error
163
+	 * @throws EntityNotFoundException
164
+	 * @throws InvalidArgumentException
165
+	 * @throws InvalidDataTypeException
166
+	 * @throws InvalidInterfaceException
167
+	 * @throws ReflectionException
168
+	 * @throws RuntimeException
169
+	 */
170
+	public function update_registration_status_and_trigger_notifications(EE_Registration $registration)
171
+	{
172
+		$this->toggle_incomplete_registration_status_to_default($registration, false);
173
+		$this->toggle_registration_status_for_default_approved_events($registration, false);
174
+		$this->toggle_registration_status_if_no_monies_owing($registration, false);
175
+		$registration->save();
176
+		// trigger notifications
177
+		$this->trigger_registration_update_notifications($registration);
178
+	}
179
+
180
+
181
+	/**
182
+	 *    manually_update_registration_status
183
+	 *
184
+	 * @access public
185
+	 * @param EE_Registration $registration
186
+	 * @param string          $new_reg_status
187
+	 * @param bool            $save TRUE will save the registration if the status is updated, FALSE will leave that up
188
+	 *                              to client code
189
+	 * @return bool
190
+	 * @throws EE_Error
191
+	 * @throws EntityNotFoundException
192
+	 * @throws InvalidArgumentException
193
+	 * @throws InvalidDataTypeException
194
+	 * @throws InvalidInterfaceException
195
+	 * @throws ReflectionException
196
+	 * @throws RuntimeException
197
+	 */
198
+	public function manually_update_registration_status(
199
+		EE_Registration $registration,
200
+		$new_reg_status = '',
201
+		$save = true
202
+	) {
203
+		// set initial REG_Status
204
+		$this->set_old_reg_status($registration->ID(), $registration->status_ID());
205
+		// set incoming REG_Status
206
+		$this->set_new_reg_status($registration->ID(), $new_reg_status);
207
+		// toggle reg status but only if it has changed and the user can do so
208
+		if (
209
+			$this->reg_status_updated($registration->ID())
210
+			&& (
211
+				(! $this->request->isAdmin() || $this->request->isFrontAjax())
212
+				|| EE_Registry::instance()->CAP->current_user_can(
213
+					'ee_edit_registration',
214
+					'toggle_registration_status',
215
+					$registration->ID()
216
+				)
217
+			)
218
+		) {
219
+			// change status to new value
220
+			$updated = $registration->set_status($this->new_reg_status($registration->ID()));
221
+			if ($updated && $save) {
222
+				$registration->save();
223
+			}
224
+			return true;
225
+		}
226
+		return false;
227
+	}
228
+
229
+
230
+	/**
231
+	 *    toggle_incomplete_registration_status_to_default
232
+	 *        changes any incomplete registrations to either the event or global default registration status
233
+	 *
234
+	 * @access public
235
+	 * @param EE_Registration       $registration
236
+	 * @param bool                  $save TRUE will save the registration if the status is updated, FALSE will leave
237
+	 *                                    that up to client code
238
+	 * @param ContextInterface|null $context
239
+	 * @return void
240
+	 * @throws EE_Error
241
+	 * @throws InvalidArgumentException
242
+	 * @throws ReflectionException
243
+	 * @throws RuntimeException
244
+	 * @throws EntityNotFoundException
245
+	 * @throws InvalidDataTypeException
246
+	 * @throws InvalidInterfaceException
247
+	 */
248
+	public function toggle_incomplete_registration_status_to_default(
249
+		EE_Registration $registration,
250
+		$save = true,
251
+		ContextInterface $context = null
252
+	) {
253
+		$existing_reg_status = $registration->status_ID();
254
+		// set initial REG_Status
255
+		$this->set_old_reg_status($registration->ID(), $existing_reg_status);
256
+		// is the registration currently incomplete ?
257
+		if ($registration->status_ID() === EEM_Registration::status_id_incomplete) {
258
+			// grab default reg status for the event, if set
259
+			$event_default_registration_status = $registration->event()->default_registration_status();
260
+			// if no default reg status is set for the event, then use the global value
261
+			$STS_ID = ! empty($event_default_registration_status)
262
+				? $event_default_registration_status
263
+				: EE_Registry::instance()->CFG->registration->default_STS_ID;
264
+			// if the event default reg status is approved, then downgrade temporarily to payment pending to ensure that payments are triggered
265
+			$STS_ID = $STS_ID === EEM_Registration::status_id_approved ? EEM_Registration::status_id_pending_payment
266
+				: $STS_ID;
267
+			// set incoming REG_Status
268
+			$this->set_new_reg_status($registration->ID(), $STS_ID);
269
+			$registration->set_status($STS_ID, false, $context);
270
+			if ($save) {
271
+				$registration->save();
272
+			}
273
+			// don't trigger notifications during IPNs because they will get triggered by EE_Payment_Processor
274
+			if (! EE_Processor_Base::$IPN) {
275
+				// otherwise, send out notifications
276
+				add_filter('FHEE__EED_Messages___maybe_registration__deliver_notifications', '__return_true', 10);
277
+			}
278
+			// DEBUG LOG
279
+			// $this->log(
280
+			//     __CLASS__,
281
+			//     __FUNCTION__,
282
+			//     __LINE__,
283
+			//     $registration->transaction(),
284
+			//     array(
285
+			//         'IPN' => EE_Processor_Base::$IPN,
286
+			//         'deliver_notifications' => has_filter(
287
+			//             'FHEE__EED_Messages___maybe_registration__deliver_notifications'
288
+			//         ),
289
+			//     )
290
+			// );
291
+		}
292
+	}
293
+
294
+
295
+	/**
296
+	 *    toggle_registration_status_for_default_approved_events
297
+	 *
298
+	 * @access public
299
+	 * @param EE_Registration $registration
300
+	 * @param bool            $save TRUE will save the registration if the status is updated, FALSE will leave that up
301
+	 *                              to client code
302
+	 * @return bool
303
+	 * @throws EE_Error
304
+	 * @throws EntityNotFoundException
305
+	 * @throws InvalidArgumentException
306
+	 * @throws InvalidDataTypeException
307
+	 * @throws InvalidInterfaceException
308
+	 * @throws ReflectionException
309
+	 * @throws RuntimeException
310
+	 */
311
+	public function toggle_registration_status_for_default_approved_events(EE_Registration $registration, $save = true)
312
+	{
313
+		$reg_status = $registration->status_ID();
314
+		// set initial REG_Status
315
+		$this->set_old_reg_status($registration->ID(), $reg_status);
316
+		// if not already, toggle reg status to approved IF the event default reg status is approved
317
+		// ( as long as the registration wasn't cancelled or declined at some point )
318
+		if (
319
+			$reg_status !== EEM_Registration::status_id_cancelled
320
+			&& $reg_status
321
+			   !== EEM_Registration::status_id_declined
322
+			&& $reg_status !== EEM_Registration::status_id_approved
323
+			&& $registration->event()->default_registration_status() === EEM_Registration::status_id_approved
324
+		) {
325
+			// set incoming REG_Status
326
+			$this->set_new_reg_status($registration->ID(), EEM_Registration::status_id_approved);
327
+			// toggle status to approved
328
+			$registration->set_status(EEM_Registration::status_id_approved);
329
+			if ($save) {
330
+				$registration->save();
331
+			}
332
+			// don't trigger notifications during IPNs because they will get triggered by EE_Payment_Processor
333
+			if (! EE_Processor_Base::$IPN) {
334
+				// otherwise, send out notifications
335
+				add_filter('FHEE__EED_Messages___maybe_registration__deliver_notifications', '__return_true', 10);
336
+			}
337
+			// DEBUG LOG
338
+			// $this->log(
339
+			//     __CLASS__,
340
+			//     __FUNCTION__,
341
+			//     __LINE__,
342
+			//     $registration->transaction(),
343
+			//     array(
344
+			//         'IPN' => EE_Processor_Base::$IPN,
345
+			//         'deliver_notifications' => has_filter(
346
+			//             'FHEE__EED_Messages___maybe_registration__deliver_notifications'
347
+			//         ),
348
+			//     )
349
+			// );
350
+			return true;
351
+		}
352
+		return false;
353
+	}
354
+
355
+
356
+	/**
357
+	 *    toggle_registration_statuses_if_no_monies_owing
358
+	 *
359
+	 * @access public
360
+	 * @param EE_Registration $registration
361
+	 * @param bool            $save TRUE will save the registration if the status is updated, FALSE will leave that up
362
+	 *                              to client code
363
+	 * @param array           $additional_details
364
+	 * @return bool
365
+	 * @throws EE_Error
366
+	 * @throws EntityNotFoundException
367
+	 * @throws InvalidArgumentException
368
+	 * @throws InvalidDataTypeException
369
+	 * @throws InvalidInterfaceException
370
+	 * @throws ReflectionException
371
+	 * @throws RuntimeException
372
+	 */
373
+	public function toggle_registration_status_if_no_monies_owing(
374
+		EE_Registration $registration,
375
+		$save = true,
376
+		array $additional_details = []
377
+	) {
378
+		// set initial REG_Status
379
+		$this->set_old_reg_status($registration->ID(), $registration->status_ID());
380
+		// was a payment just made ?
381
+		$payment    = isset($additional_details['payment_updates'], $additional_details['last_payment'])
382
+					  && $additional_details['payment_updates']
383
+					  && $additional_details['last_payment'] instanceof EE_Payment
384
+			? $additional_details['last_payment']
385
+			: null;
386
+		$total_paid = array_sum(self::$_amount_paid);
387
+		// toggle reg status to approved IF
388
+		if (
389 389
 // REG status is pending payment
390
-            $registration->status_ID() === EEM_Registration::status_id_pending_payment
391
-            // AND no monies are owing
392
-            && (
393
-                (
394
-                    $registration->transaction()->is_completed()
395
-                    || $registration->transaction()->is_overpaid()
396
-                    || $registration->transaction()->is_free()
397
-                    || apply_filters(
398
-                        'FHEE__EE_Registration_Processor__toggle_registration_status_if_no_monies_owing',
399
-                        false,
400
-                        $registration
401
-                    )
402
-                )
403
-                || (
404
-                    $payment instanceof EE_Payment && $payment->is_approved()
405
-                    && // this specific registration has not yet been paid for
406
-                    ! isset(self::$_amount_paid[ $registration->ID() ])
407
-                    && // payment amount, less what we have already attributed to other registrations, is greater than this reg's final price
408
-                    $payment->amount() - $total_paid >= $registration->final_price()
409
-                )
410
-            )
411
-        ) {
412
-            // mark as paid
413
-            self::$_amount_paid[ $registration->ID() ] = $registration->final_price();
414
-            // track new REG_Status
415
-            $this->set_new_reg_status($registration->ID(), EEM_Registration::status_id_approved);
416
-            // toggle status to approved
417
-            $registration->set_status(EEM_Registration::status_id_approved);
418
-            if ($save) {
419
-                $registration->save();
420
-            }
421
-            // don't trigger notifications during IPNs because they will get triggered by EE_Payment_Processor
422
-            if (! EE_Processor_Base::$IPN) {
423
-                // otherwise, send out notifications
424
-                add_filter('FHEE__EED_Messages___maybe_registration__deliver_notifications', '__return_true', 10);
425
-            }
426
-            // DEBUG LOG
427
-            // $this->log(
428
-            //     __CLASS__,
429
-            //     __FUNCTION__,
430
-            //     __LINE__,
431
-            //     $registration->transaction(),
432
-            //     array(
433
-            //         'IPN' => EE_Processor_Base::$IPN,
434
-            //         'deliver_notifications' => has_filter(
435
-            //             'FHEE__EED_Messages___maybe_registration__deliver_notifications'
436
-            //         ),
437
-            //     )
438
-            // );
439
-            return true;
440
-        }
441
-        return false;
442
-    }
443
-
444
-
445
-    /**
446
-     *    registration_status_changed
447
-     *
448
-     * @access public
449
-     * @param EE_Registration $registration
450
-     * @param array           $additional_details
451
-     * @return void
452
-     */
453
-    public function trigger_registration_update_notifications($registration, array $additional_details = [])
454
-    {
455
-        try {
456
-            if (! $registration instanceof EE_Registration) {
457
-                throw new EE_Error(
458
-                    esc_html__('An invalid registration was received.', 'event_espresso')
459
-                );
460
-            }
461
-            // EE_Registry::instance()->load_helper('Debug_Tools');
462
-            // EEH_Debug_Tools::log(
463
-            //     __CLASS__,
464
-            //     __FUNCTION__,
465
-            //     __LINE__,
466
-            //     array($registration->transaction(), $additional_details),
467
-            //     false,
468
-            //     'EE_Transaction: ' . $registration->transaction()->ID()
469
-            // );
470
-            if (! $registration->is_primary_registrant()) {
471
-                return;
472
-            }
473
-            do_action(
474
-                'AHEE__EE_Registration_Processor__trigger_registration_update_notifications',
475
-                $registration,
476
-                $additional_details
477
-            );
478
-        } catch (Exception $e) {
479
-            EE_Error::add_error($e->getMessage(), $e->getFile(), 'unknown_function_from_exception', $e->getLine());
480
-        }
481
-    }
482
-
483
-
484
-    /**
485
-     * sets reg status based either on passed param or on transaction status and event pre-approval setting
486
-     *
487
-     * @param EE_Registration $registration
488
-     * @param array           $additional_details
489
-     * @return bool
490
-     * @throws EE_Error
491
-     * @throws EntityNotFoundException
492
-     * @throws InvalidArgumentException
493
-     * @throws InvalidDataTypeException
494
-     * @throws InvalidInterfaceException
495
-     * @throws ReflectionException
496
-     * @throws RuntimeException
497
-     */
498
-    public function update_registration_after_checkout_or_payment(
499
-        EE_Registration $registration,
500
-        array $additional_details = []
501
-    ) {
502
-        // set initial REG_Status
503
-        $this->set_old_reg_status($registration->ID(), $registration->status_ID());
504
-        // if the registration status gets updated, then save the registration
505
-        if (
506
-            $this->toggle_registration_status_for_default_approved_events($registration, false)
507
-            || $this->toggle_registration_status_if_no_monies_owing(
508
-                $registration,
509
-                false,
510
-                $additional_details
511
-            )
512
-        ) {
513
-            $registration->save();
514
-        }
515
-        // set new  REG_Status
516
-        $this->set_new_reg_status($registration->ID(), $registration->status_ID());
517
-        return $this->reg_status_updated($registration->ID())
518
-               && $this->new_reg_status($registration->ID()) === EEM_Registration::status_id_approved;
519
-    }
520
-
521
-
522
-    /**
523
-     * Updates the registration' final prices based on the current line item tree (taking into account
524
-     * discounts, taxes, and other line items unrelated to tickets.)
525
-     *
526
-     * @param EE_Transaction $transaction
527
-     * @param boolean        $save_regs whether to immediately save registrations in this function or not
528
-     * @return void
529
-     * @throws EE_Error
530
-     * @throws InvalidArgumentException
531
-     * @throws InvalidDataTypeException
532
-     * @throws InvalidInterfaceException
533
-     * @throws RuntimeException
534
-     * @throws ReflectionException
535
-     */
536
-    public function update_registration_final_prices($transaction, $save_regs = true)
537
-    {
538
-        $reg_final_price_per_ticket_line_item = EEH_Line_Item::calculate_reg_final_prices_per_line_item(
539
-            $transaction->total_line_item()
540
-        );
541
-        foreach ($transaction->registrations() as $registration) {
542
-            /** @var EE_Line_Item $line_item */
543
-            $line_item = EEM_Line_Item::instance()->get_line_item_for_registration($registration);
544
-            if (isset($reg_final_price_per_ticket_line_item[ $line_item->ID() ])) {
545
-                $registration->set_final_price($reg_final_price_per_ticket_line_item[ $line_item->ID() ]);
546
-                if ($save_regs) {
547
-                    $registration->save();
548
-                }
549
-            }
550
-        }
551
-        // and make sure there's no rounding problem
552
-        $this->fix_reg_final_price_rounding_issue($transaction);
553
-    }
554
-
555
-
556
-    /**
557
-     * Makes sure there is no rounding errors for the REG_final_prices.
558
-     * Eg, if we have 3 registrations for $1, and there is a $0.01 discount between the three of them,
559
-     * they will each be for $0.99333333, which gets rounded to $1 again.
560
-     * So the transaction total will be $2.99, but each registration will be for $1,
561
-     * so if each registrant paid individually they will have overpaid by $0.01.
562
-     * So in order to overcome this, we check for any difference, and if there is a difference
563
-     * we just grab one registrant at random and make them responsible for it.
564
-     * This should be used after setting REG_final_prices (it's done automatically as part of
565
-     * EE_Registration_Processor::update_registration_final_prices())
566
-     *
567
-     * @param EE_Transaction $transaction
568
-     * @return bool success verifying that there is NO difference after this method is done
569
-     * @throws EE_Error
570
-     * @throws InvalidArgumentException
571
-     * @throws InvalidDataTypeException
572
-     * @throws InvalidInterfaceException
573
-     * @throws ReflectionException
574
-     */
575
-    public function fix_reg_final_price_rounding_issue($transaction)
576
-    {
577
-        $reg_final_price_sum = EEM_Registration::instance()->sum(
578
-            [
579
-                [
580
-                    'TXN_ID' => $transaction->ID(),
581
-                ],
582
-            ],
583
-            'REG_final_price'
584
-        );
585
-        $diff                = $transaction->total() - $reg_final_price_sum;
586
-        // ok then, just grab one of the registrations
587
-        if ($diff !== (float) 0) {
588
-            $a_reg = EEM_Registration::instance()->get_one(
589
-                [
590
-                    [
591
-                        'TXN_ID' => $transaction->ID(),
592
-                    ],
593
-                ]
594
-            );
595
-            return $a_reg instanceof EE_Registration
596
-                   && $a_reg->save(['REG_final_price' => $a_reg->final_price() + $diff]);
597
-        }
598
-        return true;
599
-    }
600
-
601
-
602
-    /**
603
-     * update_registration_after_being_canceled_or_declined
604
-     *
605
-     * @param EE_Registration $registration
606
-     * @param array           $closed_reg_statuses
607
-     * @param bool            $update_reg
608
-     * @return bool
609
-     * @throws EE_Error
610
-     * @throws RuntimeException
611
-     * @throws ReflectionException
612
-     */
613
-    public function update_registration_after_being_canceled_or_declined(
614
-        EE_Registration $registration,
615
-        array $closed_reg_statuses = [],
616
-        $update_reg = true
617
-    ) {
618
-        // these reg statuses should not be considered in any calculations involving monies owing
619
-        $closed_reg_statuses = ! empty($closed_reg_statuses)
620
-            ? $closed_reg_statuses
621
-            : EEM_Registration::closed_reg_statuses();
622
-        if (! in_array($registration->status_ID(), $closed_reg_statuses, true)) {
623
-            return false;
624
-        }
625
-        // release a reserved ticket by decrementing ticket and datetime reserved values
626
-        $registration->release_reserved_ticket(true, 'RegProcessor:' . __LINE__);
627
-        $registration->set_final_price(0);
628
-        if ($update_reg) {
629
-            $registration->save();
630
-        }
631
-        return true;
632
-    }
633
-
634
-
635
-    /**
636
-     * update_canceled_or_declined_registration_after_being_reinstated
637
-     *
638
-     * @param EE_Registration $registration
639
-     * @param array           $closed_reg_statuses
640
-     * @param bool            $update_reg
641
-     * @return bool
642
-     * @throws EE_Error
643
-     * @throws RuntimeException
644
-     * @throws ReflectionException
645
-     */
646
-    public function update_canceled_or_declined_registration_after_being_reinstated(
647
-        EE_Registration $registration,
648
-        array $closed_reg_statuses = [],
649
-        $update_reg = true
650
-    ) {
651
-        // these reg statuses should not be considered in any calculations involving monies owing
652
-        $closed_reg_statuses = ! empty($closed_reg_statuses) ? $closed_reg_statuses
653
-            : EEM_Registration::closed_reg_statuses();
654
-        if (in_array($registration->status_ID(), $closed_reg_statuses, true)) {
655
-            return false;
656
-        }
657
-        $ticket = $registration->ticket();
658
-        if (! $ticket instanceof EE_Ticket) {
659
-            throw new EE_Error(
660
-                sprintf(
661
-                    esc_html__(
662
-                        'The Ticket for Registration %1$d was not found or is invalid.',
663
-                        'event_espresso'
664
-                    ),
665
-                    $registration->ticket_ID()
666
-                )
667
-            );
668
-        }
669
-        $registration->set_final_price($ticket->price());
670
-        if ($update_reg) {
671
-            $registration->save();
672
-        }
673
-        return true;
674
-    }
675
-
676
-
677
-    /**
678
-     * generate_ONE_registration_from_line_item
679
-     * Although a ticket line item may have a quantity greater than 1,
680
-     * this method will ONLY CREATE ONE REGISTRATION !!!
681
-     * Regardless of the ticket line item quantity.
682
-     * This means that any code calling this method is responsible for ensuring
683
-     * that the final registration count matches the ticket line item quantity.
684
-     * This was done to make it easier to match the number of registrations
685
-     * to the number of tickets in the cart, when the cart has been edited
686
-     * after SPCO has already been initialized. So if an additional ticket was added to the cart, you can simply pass
687
-     * the line item to this method to add a second ticket, and in this case, you would not want to add 2 tickets.
688
-     *
689
-     * @param EE_Line_Item   $line_item
690
-     * @param EE_Transaction $transaction
691
-     * @param int            $att_nmbr
692
-     * @param int            $total_ticket_count
693
-     * @return EE_Registration | null
694
-     * @throws OutOfRangeException
695
-     * @throws UnexpectedEntityException
696
-     * @throws EE_Error
697
-     * @throws ReflectionException
698
-     * @deprecated
699
-     * @since 4.9.1
700
-     */
701
-    public function generate_ONE_registration_from_line_item(
702
-        EE_Line_Item $line_item,
703
-        EE_Transaction $transaction,
704
-        $att_nmbr = 1,
705
-        $total_ticket_count = 1
706
-    ) {
707
-        EE_Error::doing_it_wrong(
708
-            __CLASS__ . '::' . __FUNCTION__,
709
-            sprintf(
710
-                esc_html__('This method is deprecated. Please use "%s" instead', 'event_espresso'),
711
-                '\EventEspresso\core\domain\services\registration\CreateRegistrationService::create()'
712
-            ),
713
-            '4.9.1',
714
-            '5.0.0'
715
-        );
716
-        // grab the related ticket object for this line_item
717
-        $ticket = $line_item->ticket();
718
-        if (! $ticket instanceof EE_Ticket) {
719
-            EE_Error::add_error(
720
-                sprintf(
721
-                    esc_html__('Line item %s did not contain a valid ticket', 'event_espresso'),
722
-                    $line_item->ID()
723
-                ),
724
-                __FILE__,
725
-                __FUNCTION__,
726
-                __LINE__
727
-            );
728
-            return null;
729
-        }
730
-        $registration_service = new CreateRegistrationService();
731
-        // then generate a new registration from that
732
-        return $registration_service->create(
733
-            $ticket->get_related_event(),
734
-            $transaction,
735
-            $ticket,
736
-            $line_item,
737
-            $att_nmbr,
738
-            $total_ticket_count
739
-        );
740
-    }
741
-
742
-
743
-    /**
744
-     * generates reg_url_link
745
-     *
746
-     * @param int                   $att_nmbr
747
-     * @param EE_Line_Item | string $item
748
-     * @return RegUrlLink
749
-     * @throws InvalidArgumentException
750
-     * @deprecated
751
-     * @since 4.9.1
752
-     */
753
-    public function generate_reg_url_link($att_nmbr, $item)
754
-    {
755
-        EE_Error::doing_it_wrong(
756
-            __CLASS__ . '::' . __FUNCTION__,
757
-            sprintf(
758
-                esc_html__('This method is deprecated. Please use "%s" instead', 'event_espresso'),
759
-                'EventEspresso\core\domain\entities\RegUrlLink'
760
-            ),
761
-            '4.9.1',
762
-            '5.0.0'
763
-        );
764
-        return new RegUrlLink($att_nmbr, $item);
765
-    }
766
-
767
-
768
-    /**
769
-     * generates reg code
770
-     *
771
-     * @param EE_Registration $registration
772
-     * @return RegCode
773
-     * @throws EE_Error
774
-     * @throws EntityNotFoundException
775
-     * @throws InvalidArgumentException
776
-     * @since 4.9.1
777
-     * @deprecated
778
-     */
779
-    public function generate_reg_code(EE_Registration $registration)
780
-    {
781
-        EE_Error::doing_it_wrong(
782
-            __CLASS__ . '::' . __FUNCTION__,
783
-            sprintf(
784
-                esc_html__('This method is deprecated. Please use "%s" instead', 'event_espresso'),
785
-                'EventEspresso\core\domain\entities\RegCode'
786
-            ),
787
-            '4.9.1',
788
-            '5.0.0'
789
-        );
790
-        return apply_filters(
791
-            'FHEE__EE_Registration_Processor___generate_reg_code__new_reg_code',
792
-            new RegCode(
793
-                RegUrlLink::fromRegistration($registration),
794
-                $registration->transaction(),
795
-                $registration->ticket()
796
-            ),
797
-            $registration
798
-        );
799
-    }
390
+			$registration->status_ID() === EEM_Registration::status_id_pending_payment
391
+			// AND no monies are owing
392
+			&& (
393
+				(
394
+					$registration->transaction()->is_completed()
395
+					|| $registration->transaction()->is_overpaid()
396
+					|| $registration->transaction()->is_free()
397
+					|| apply_filters(
398
+						'FHEE__EE_Registration_Processor__toggle_registration_status_if_no_monies_owing',
399
+						false,
400
+						$registration
401
+					)
402
+				)
403
+				|| (
404
+					$payment instanceof EE_Payment && $payment->is_approved()
405
+					&& // this specific registration has not yet been paid for
406
+					! isset(self::$_amount_paid[ $registration->ID() ])
407
+					&& // payment amount, less what we have already attributed to other registrations, is greater than this reg's final price
408
+					$payment->amount() - $total_paid >= $registration->final_price()
409
+				)
410
+			)
411
+		) {
412
+			// mark as paid
413
+			self::$_amount_paid[ $registration->ID() ] = $registration->final_price();
414
+			// track new REG_Status
415
+			$this->set_new_reg_status($registration->ID(), EEM_Registration::status_id_approved);
416
+			// toggle status to approved
417
+			$registration->set_status(EEM_Registration::status_id_approved);
418
+			if ($save) {
419
+				$registration->save();
420
+			}
421
+			// don't trigger notifications during IPNs because they will get triggered by EE_Payment_Processor
422
+			if (! EE_Processor_Base::$IPN) {
423
+				// otherwise, send out notifications
424
+				add_filter('FHEE__EED_Messages___maybe_registration__deliver_notifications', '__return_true', 10);
425
+			}
426
+			// DEBUG LOG
427
+			// $this->log(
428
+			//     __CLASS__,
429
+			//     __FUNCTION__,
430
+			//     __LINE__,
431
+			//     $registration->transaction(),
432
+			//     array(
433
+			//         'IPN' => EE_Processor_Base::$IPN,
434
+			//         'deliver_notifications' => has_filter(
435
+			//             'FHEE__EED_Messages___maybe_registration__deliver_notifications'
436
+			//         ),
437
+			//     )
438
+			// );
439
+			return true;
440
+		}
441
+		return false;
442
+	}
443
+
444
+
445
+	/**
446
+	 *    registration_status_changed
447
+	 *
448
+	 * @access public
449
+	 * @param EE_Registration $registration
450
+	 * @param array           $additional_details
451
+	 * @return void
452
+	 */
453
+	public function trigger_registration_update_notifications($registration, array $additional_details = [])
454
+	{
455
+		try {
456
+			if (! $registration instanceof EE_Registration) {
457
+				throw new EE_Error(
458
+					esc_html__('An invalid registration was received.', 'event_espresso')
459
+				);
460
+			}
461
+			// EE_Registry::instance()->load_helper('Debug_Tools');
462
+			// EEH_Debug_Tools::log(
463
+			//     __CLASS__,
464
+			//     __FUNCTION__,
465
+			//     __LINE__,
466
+			//     array($registration->transaction(), $additional_details),
467
+			//     false,
468
+			//     'EE_Transaction: ' . $registration->transaction()->ID()
469
+			// );
470
+			if (! $registration->is_primary_registrant()) {
471
+				return;
472
+			}
473
+			do_action(
474
+				'AHEE__EE_Registration_Processor__trigger_registration_update_notifications',
475
+				$registration,
476
+				$additional_details
477
+			);
478
+		} catch (Exception $e) {
479
+			EE_Error::add_error($e->getMessage(), $e->getFile(), 'unknown_function_from_exception', $e->getLine());
480
+		}
481
+	}
482
+
483
+
484
+	/**
485
+	 * sets reg status based either on passed param or on transaction status and event pre-approval setting
486
+	 *
487
+	 * @param EE_Registration $registration
488
+	 * @param array           $additional_details
489
+	 * @return bool
490
+	 * @throws EE_Error
491
+	 * @throws EntityNotFoundException
492
+	 * @throws InvalidArgumentException
493
+	 * @throws InvalidDataTypeException
494
+	 * @throws InvalidInterfaceException
495
+	 * @throws ReflectionException
496
+	 * @throws RuntimeException
497
+	 */
498
+	public function update_registration_after_checkout_or_payment(
499
+		EE_Registration $registration,
500
+		array $additional_details = []
501
+	) {
502
+		// set initial REG_Status
503
+		$this->set_old_reg_status($registration->ID(), $registration->status_ID());
504
+		// if the registration status gets updated, then save the registration
505
+		if (
506
+			$this->toggle_registration_status_for_default_approved_events($registration, false)
507
+			|| $this->toggle_registration_status_if_no_monies_owing(
508
+				$registration,
509
+				false,
510
+				$additional_details
511
+			)
512
+		) {
513
+			$registration->save();
514
+		}
515
+		// set new  REG_Status
516
+		$this->set_new_reg_status($registration->ID(), $registration->status_ID());
517
+		return $this->reg_status_updated($registration->ID())
518
+			   && $this->new_reg_status($registration->ID()) === EEM_Registration::status_id_approved;
519
+	}
520
+
521
+
522
+	/**
523
+	 * Updates the registration' final prices based on the current line item tree (taking into account
524
+	 * discounts, taxes, and other line items unrelated to tickets.)
525
+	 *
526
+	 * @param EE_Transaction $transaction
527
+	 * @param boolean        $save_regs whether to immediately save registrations in this function or not
528
+	 * @return void
529
+	 * @throws EE_Error
530
+	 * @throws InvalidArgumentException
531
+	 * @throws InvalidDataTypeException
532
+	 * @throws InvalidInterfaceException
533
+	 * @throws RuntimeException
534
+	 * @throws ReflectionException
535
+	 */
536
+	public function update_registration_final_prices($transaction, $save_regs = true)
537
+	{
538
+		$reg_final_price_per_ticket_line_item = EEH_Line_Item::calculate_reg_final_prices_per_line_item(
539
+			$transaction->total_line_item()
540
+		);
541
+		foreach ($transaction->registrations() as $registration) {
542
+			/** @var EE_Line_Item $line_item */
543
+			$line_item = EEM_Line_Item::instance()->get_line_item_for_registration($registration);
544
+			if (isset($reg_final_price_per_ticket_line_item[ $line_item->ID() ])) {
545
+				$registration->set_final_price($reg_final_price_per_ticket_line_item[ $line_item->ID() ]);
546
+				if ($save_regs) {
547
+					$registration->save();
548
+				}
549
+			}
550
+		}
551
+		// and make sure there's no rounding problem
552
+		$this->fix_reg_final_price_rounding_issue($transaction);
553
+	}
554
+
555
+
556
+	/**
557
+	 * Makes sure there is no rounding errors for the REG_final_prices.
558
+	 * Eg, if we have 3 registrations for $1, and there is a $0.01 discount between the three of them,
559
+	 * they will each be for $0.99333333, which gets rounded to $1 again.
560
+	 * So the transaction total will be $2.99, but each registration will be for $1,
561
+	 * so if each registrant paid individually they will have overpaid by $0.01.
562
+	 * So in order to overcome this, we check for any difference, and if there is a difference
563
+	 * we just grab one registrant at random and make them responsible for it.
564
+	 * This should be used after setting REG_final_prices (it's done automatically as part of
565
+	 * EE_Registration_Processor::update_registration_final_prices())
566
+	 *
567
+	 * @param EE_Transaction $transaction
568
+	 * @return bool success verifying that there is NO difference after this method is done
569
+	 * @throws EE_Error
570
+	 * @throws InvalidArgumentException
571
+	 * @throws InvalidDataTypeException
572
+	 * @throws InvalidInterfaceException
573
+	 * @throws ReflectionException
574
+	 */
575
+	public function fix_reg_final_price_rounding_issue($transaction)
576
+	{
577
+		$reg_final_price_sum = EEM_Registration::instance()->sum(
578
+			[
579
+				[
580
+					'TXN_ID' => $transaction->ID(),
581
+				],
582
+			],
583
+			'REG_final_price'
584
+		);
585
+		$diff                = $transaction->total() - $reg_final_price_sum;
586
+		// ok then, just grab one of the registrations
587
+		if ($diff !== (float) 0) {
588
+			$a_reg = EEM_Registration::instance()->get_one(
589
+				[
590
+					[
591
+						'TXN_ID' => $transaction->ID(),
592
+					],
593
+				]
594
+			);
595
+			return $a_reg instanceof EE_Registration
596
+				   && $a_reg->save(['REG_final_price' => $a_reg->final_price() + $diff]);
597
+		}
598
+		return true;
599
+	}
600
+
601
+
602
+	/**
603
+	 * update_registration_after_being_canceled_or_declined
604
+	 *
605
+	 * @param EE_Registration $registration
606
+	 * @param array           $closed_reg_statuses
607
+	 * @param bool            $update_reg
608
+	 * @return bool
609
+	 * @throws EE_Error
610
+	 * @throws RuntimeException
611
+	 * @throws ReflectionException
612
+	 */
613
+	public function update_registration_after_being_canceled_or_declined(
614
+		EE_Registration $registration,
615
+		array $closed_reg_statuses = [],
616
+		$update_reg = true
617
+	) {
618
+		// these reg statuses should not be considered in any calculations involving monies owing
619
+		$closed_reg_statuses = ! empty($closed_reg_statuses)
620
+			? $closed_reg_statuses
621
+			: EEM_Registration::closed_reg_statuses();
622
+		if (! in_array($registration->status_ID(), $closed_reg_statuses, true)) {
623
+			return false;
624
+		}
625
+		// release a reserved ticket by decrementing ticket and datetime reserved values
626
+		$registration->release_reserved_ticket(true, 'RegProcessor:' . __LINE__);
627
+		$registration->set_final_price(0);
628
+		if ($update_reg) {
629
+			$registration->save();
630
+		}
631
+		return true;
632
+	}
633
+
634
+
635
+	/**
636
+	 * update_canceled_or_declined_registration_after_being_reinstated
637
+	 *
638
+	 * @param EE_Registration $registration
639
+	 * @param array           $closed_reg_statuses
640
+	 * @param bool            $update_reg
641
+	 * @return bool
642
+	 * @throws EE_Error
643
+	 * @throws RuntimeException
644
+	 * @throws ReflectionException
645
+	 */
646
+	public function update_canceled_or_declined_registration_after_being_reinstated(
647
+		EE_Registration $registration,
648
+		array $closed_reg_statuses = [],
649
+		$update_reg = true
650
+	) {
651
+		// these reg statuses should not be considered in any calculations involving monies owing
652
+		$closed_reg_statuses = ! empty($closed_reg_statuses) ? $closed_reg_statuses
653
+			: EEM_Registration::closed_reg_statuses();
654
+		if (in_array($registration->status_ID(), $closed_reg_statuses, true)) {
655
+			return false;
656
+		}
657
+		$ticket = $registration->ticket();
658
+		if (! $ticket instanceof EE_Ticket) {
659
+			throw new EE_Error(
660
+				sprintf(
661
+					esc_html__(
662
+						'The Ticket for Registration %1$d was not found or is invalid.',
663
+						'event_espresso'
664
+					),
665
+					$registration->ticket_ID()
666
+				)
667
+			);
668
+		}
669
+		$registration->set_final_price($ticket->price());
670
+		if ($update_reg) {
671
+			$registration->save();
672
+		}
673
+		return true;
674
+	}
675
+
676
+
677
+	/**
678
+	 * generate_ONE_registration_from_line_item
679
+	 * Although a ticket line item may have a quantity greater than 1,
680
+	 * this method will ONLY CREATE ONE REGISTRATION !!!
681
+	 * Regardless of the ticket line item quantity.
682
+	 * This means that any code calling this method is responsible for ensuring
683
+	 * that the final registration count matches the ticket line item quantity.
684
+	 * This was done to make it easier to match the number of registrations
685
+	 * to the number of tickets in the cart, when the cart has been edited
686
+	 * after SPCO has already been initialized. So if an additional ticket was added to the cart, you can simply pass
687
+	 * the line item to this method to add a second ticket, and in this case, you would not want to add 2 tickets.
688
+	 *
689
+	 * @param EE_Line_Item   $line_item
690
+	 * @param EE_Transaction $transaction
691
+	 * @param int            $att_nmbr
692
+	 * @param int            $total_ticket_count
693
+	 * @return EE_Registration | null
694
+	 * @throws OutOfRangeException
695
+	 * @throws UnexpectedEntityException
696
+	 * @throws EE_Error
697
+	 * @throws ReflectionException
698
+	 * @deprecated
699
+	 * @since 4.9.1
700
+	 */
701
+	public function generate_ONE_registration_from_line_item(
702
+		EE_Line_Item $line_item,
703
+		EE_Transaction $transaction,
704
+		$att_nmbr = 1,
705
+		$total_ticket_count = 1
706
+	) {
707
+		EE_Error::doing_it_wrong(
708
+			__CLASS__ . '::' . __FUNCTION__,
709
+			sprintf(
710
+				esc_html__('This method is deprecated. Please use "%s" instead', 'event_espresso'),
711
+				'\EventEspresso\core\domain\services\registration\CreateRegistrationService::create()'
712
+			),
713
+			'4.9.1',
714
+			'5.0.0'
715
+		);
716
+		// grab the related ticket object for this line_item
717
+		$ticket = $line_item->ticket();
718
+		if (! $ticket instanceof EE_Ticket) {
719
+			EE_Error::add_error(
720
+				sprintf(
721
+					esc_html__('Line item %s did not contain a valid ticket', 'event_espresso'),
722
+					$line_item->ID()
723
+				),
724
+				__FILE__,
725
+				__FUNCTION__,
726
+				__LINE__
727
+			);
728
+			return null;
729
+		}
730
+		$registration_service = new CreateRegistrationService();
731
+		// then generate a new registration from that
732
+		return $registration_service->create(
733
+			$ticket->get_related_event(),
734
+			$transaction,
735
+			$ticket,
736
+			$line_item,
737
+			$att_nmbr,
738
+			$total_ticket_count
739
+		);
740
+	}
741
+
742
+
743
+	/**
744
+	 * generates reg_url_link
745
+	 *
746
+	 * @param int                   $att_nmbr
747
+	 * @param EE_Line_Item | string $item
748
+	 * @return RegUrlLink
749
+	 * @throws InvalidArgumentException
750
+	 * @deprecated
751
+	 * @since 4.9.1
752
+	 */
753
+	public function generate_reg_url_link($att_nmbr, $item)
754
+	{
755
+		EE_Error::doing_it_wrong(
756
+			__CLASS__ . '::' . __FUNCTION__,
757
+			sprintf(
758
+				esc_html__('This method is deprecated. Please use "%s" instead', 'event_espresso'),
759
+				'EventEspresso\core\domain\entities\RegUrlLink'
760
+			),
761
+			'4.9.1',
762
+			'5.0.0'
763
+		);
764
+		return new RegUrlLink($att_nmbr, $item);
765
+	}
766
+
767
+
768
+	/**
769
+	 * generates reg code
770
+	 *
771
+	 * @param EE_Registration $registration
772
+	 * @return RegCode
773
+	 * @throws EE_Error
774
+	 * @throws EntityNotFoundException
775
+	 * @throws InvalidArgumentException
776
+	 * @since 4.9.1
777
+	 * @deprecated
778
+	 */
779
+	public function generate_reg_code(EE_Registration $registration)
780
+	{
781
+		EE_Error::doing_it_wrong(
782
+			__CLASS__ . '::' . __FUNCTION__,
783
+			sprintf(
784
+				esc_html__('This method is deprecated. Please use "%s" instead', 'event_espresso'),
785
+				'EventEspresso\core\domain\entities\RegCode'
786
+			),
787
+			'4.9.1',
788
+			'5.0.0'
789
+		);
790
+		return apply_filters(
791
+			'FHEE__EE_Registration_Processor___generate_reg_code__new_reg_code',
792
+			new RegCode(
793
+				RegUrlLink::fromRegistration($registration),
794
+				$registration->transaction(),
795
+				$registration->ticket()
796
+			),
797
+			$registration
798
+		);
799
+	}
800 800
 }
Please login to merge, or discard this patch.
Spacing   +26 added lines, -26 removed lines patch added patch discarded remove patch
@@ -81,8 +81,8 @@  discard block
 block discarded – undo
81 81
     public static function instance(RequestInterface $request = null)
82 82
     {
83 83
         // check if class object is instantiated
84
-        if (! self::$_instance instanceof EE_Registration_Processor) {
85
-            if (! $request instanceof RequestInterface) {
84
+        if ( ! self::$_instance instanceof EE_Registration_Processor) {
85
+            if ( ! $request instanceof RequestInterface) {
86 86
                 $request = LoaderFactory::getLoader()->getShared('EventEspresso\core\services\request\Request');
87 87
             }
88 88
             self::$_instance = new self($request);
@@ -108,7 +108,7 @@  discard block
 block discarded – undo
108 108
      */
109 109
     public function old_reg_status($REG_ID)
110 110
     {
111
-        return isset($this->_old_reg_status[ $REG_ID ]) ? $this->_old_reg_status[ $REG_ID ] : null;
111
+        return isset($this->_old_reg_status[$REG_ID]) ? $this->_old_reg_status[$REG_ID] : null;
112 112
     }
113 113
 
114 114
 
@@ -119,8 +119,8 @@  discard block
 block discarded – undo
119 119
     public function set_old_reg_status($REG_ID, $old_reg_status)
120 120
     {
121 121
         // only set the first time
122
-        if (! isset($this->_old_reg_status[ $REG_ID ])) {
123
-            $this->_old_reg_status[ $REG_ID ] = $old_reg_status;
122
+        if ( ! isset($this->_old_reg_status[$REG_ID])) {
123
+            $this->_old_reg_status[$REG_ID] = $old_reg_status;
124 124
         }
125 125
     }
126 126
 
@@ -131,7 +131,7 @@  discard block
 block discarded – undo
131 131
      */
132 132
     public function new_reg_status($REG_ID)
133 133
     {
134
-        return isset($this->_new_reg_status[ $REG_ID ]) ? $this->_new_reg_status[ $REG_ID ] : null;
134
+        return isset($this->_new_reg_status[$REG_ID]) ? $this->_new_reg_status[$REG_ID] : null;
135 135
     }
136 136
 
137 137
 
@@ -141,7 +141,7 @@  discard block
 block discarded – undo
141 141
      */
142 142
     public function set_new_reg_status($REG_ID, $new_reg_status)
143 143
     {
144
-        $this->_new_reg_status[ $REG_ID ] = $new_reg_status;
144
+        $this->_new_reg_status[$REG_ID] = $new_reg_status;
145 145
     }
146 146
 
147 147
 
@@ -208,7 +208,7 @@  discard block
 block discarded – undo
208 208
         if (
209 209
             $this->reg_status_updated($registration->ID())
210 210
             && (
211
-                (! $this->request->isAdmin() || $this->request->isFrontAjax())
211
+                ( ! $this->request->isAdmin() || $this->request->isFrontAjax())
212 212
                 || EE_Registry::instance()->CAP->current_user_can(
213 213
                     'ee_edit_registration',
214 214
                     'toggle_registration_status',
@@ -271,7 +271,7 @@  discard block
 block discarded – undo
271 271
                 $registration->save();
272 272
             }
273 273
             // don't trigger notifications during IPNs because they will get triggered by EE_Payment_Processor
274
-            if (! EE_Processor_Base::$IPN) {
274
+            if ( ! EE_Processor_Base::$IPN) {
275 275
                 // otherwise, send out notifications
276 276
                 add_filter('FHEE__EED_Messages___maybe_registration__deliver_notifications', '__return_true', 10);
277 277
             }
@@ -330,7 +330,7 @@  discard block
 block discarded – undo
330 330
                 $registration->save();
331 331
             }
332 332
             // don't trigger notifications during IPNs because they will get triggered by EE_Payment_Processor
333
-            if (! EE_Processor_Base::$IPN) {
333
+            if ( ! EE_Processor_Base::$IPN) {
334 334
                 // otherwise, send out notifications
335 335
                 add_filter('FHEE__EED_Messages___maybe_registration__deliver_notifications', '__return_true', 10);
336 336
             }
@@ -378,7 +378,7 @@  discard block
 block discarded – undo
378 378
         // set initial REG_Status
379 379
         $this->set_old_reg_status($registration->ID(), $registration->status_ID());
380 380
         // was a payment just made ?
381
-        $payment    = isset($additional_details['payment_updates'], $additional_details['last_payment'])
381
+        $payment = isset($additional_details['payment_updates'], $additional_details['last_payment'])
382 382
                       && $additional_details['payment_updates']
383 383
                       && $additional_details['last_payment'] instanceof EE_Payment
384 384
             ? $additional_details['last_payment']
@@ -403,14 +403,14 @@  discard block
 block discarded – undo
403 403
                 || (
404 404
                     $payment instanceof EE_Payment && $payment->is_approved()
405 405
                     && // this specific registration has not yet been paid for
406
-                    ! isset(self::$_amount_paid[ $registration->ID() ])
406
+                    ! isset(self::$_amount_paid[$registration->ID()])
407 407
                     && // payment amount, less what we have already attributed to other registrations, is greater than this reg's final price
408 408
                     $payment->amount() - $total_paid >= $registration->final_price()
409 409
                 )
410 410
             )
411 411
         ) {
412 412
             // mark as paid
413
-            self::$_amount_paid[ $registration->ID() ] = $registration->final_price();
413
+            self::$_amount_paid[$registration->ID()] = $registration->final_price();
414 414
             // track new REG_Status
415 415
             $this->set_new_reg_status($registration->ID(), EEM_Registration::status_id_approved);
416 416
             // toggle status to approved
@@ -419,7 +419,7 @@  discard block
 block discarded – undo
419 419
                 $registration->save();
420 420
             }
421 421
             // don't trigger notifications during IPNs because they will get triggered by EE_Payment_Processor
422
-            if (! EE_Processor_Base::$IPN) {
422
+            if ( ! EE_Processor_Base::$IPN) {
423 423
                 // otherwise, send out notifications
424 424
                 add_filter('FHEE__EED_Messages___maybe_registration__deliver_notifications', '__return_true', 10);
425 425
             }
@@ -453,7 +453,7 @@  discard block
 block discarded – undo
453 453
     public function trigger_registration_update_notifications($registration, array $additional_details = [])
454 454
     {
455 455
         try {
456
-            if (! $registration instanceof EE_Registration) {
456
+            if ( ! $registration instanceof EE_Registration) {
457 457
                 throw new EE_Error(
458 458
                     esc_html__('An invalid registration was received.', 'event_espresso')
459 459
                 );
@@ -467,7 +467,7 @@  discard block
 block discarded – undo
467 467
             //     false,
468 468
             //     'EE_Transaction: ' . $registration->transaction()->ID()
469 469
             // );
470
-            if (! $registration->is_primary_registrant()) {
470
+            if ( ! $registration->is_primary_registrant()) {
471 471
                 return;
472 472
             }
473 473
             do_action(
@@ -541,8 +541,8 @@  discard block
 block discarded – undo
541 541
         foreach ($transaction->registrations() as $registration) {
542 542
             /** @var EE_Line_Item $line_item */
543 543
             $line_item = EEM_Line_Item::instance()->get_line_item_for_registration($registration);
544
-            if (isset($reg_final_price_per_ticket_line_item[ $line_item->ID() ])) {
545
-                $registration->set_final_price($reg_final_price_per_ticket_line_item[ $line_item->ID() ]);
544
+            if (isset($reg_final_price_per_ticket_line_item[$line_item->ID()])) {
545
+                $registration->set_final_price($reg_final_price_per_ticket_line_item[$line_item->ID()]);
546 546
                 if ($save_regs) {
547 547
                     $registration->save();
548 548
                 }
@@ -582,7 +582,7 @@  discard block
 block discarded – undo
582 582
             ],
583 583
             'REG_final_price'
584 584
         );
585
-        $diff                = $transaction->total() - $reg_final_price_sum;
585
+        $diff = $transaction->total() - $reg_final_price_sum;
586 586
         // ok then, just grab one of the registrations
587 587
         if ($diff !== (float) 0) {
588 588
             $a_reg = EEM_Registration::instance()->get_one(
@@ -619,11 +619,11 @@  discard block
 block discarded – undo
619 619
         $closed_reg_statuses = ! empty($closed_reg_statuses)
620 620
             ? $closed_reg_statuses
621 621
             : EEM_Registration::closed_reg_statuses();
622
-        if (! in_array($registration->status_ID(), $closed_reg_statuses, true)) {
622
+        if ( ! in_array($registration->status_ID(), $closed_reg_statuses, true)) {
623 623
             return false;
624 624
         }
625 625
         // release a reserved ticket by decrementing ticket and datetime reserved values
626
-        $registration->release_reserved_ticket(true, 'RegProcessor:' . __LINE__);
626
+        $registration->release_reserved_ticket(true, 'RegProcessor:'.__LINE__);
627 627
         $registration->set_final_price(0);
628 628
         if ($update_reg) {
629 629
             $registration->save();
@@ -655,7 +655,7 @@  discard block
 block discarded – undo
655 655
             return false;
656 656
         }
657 657
         $ticket = $registration->ticket();
658
-        if (! $ticket instanceof EE_Ticket) {
658
+        if ( ! $ticket instanceof EE_Ticket) {
659 659
             throw new EE_Error(
660 660
                 sprintf(
661 661
                     esc_html__(
@@ -705,7 +705,7 @@  discard block
 block discarded – undo
705 705
         $total_ticket_count = 1
706 706
     ) {
707 707
         EE_Error::doing_it_wrong(
708
-            __CLASS__ . '::' . __FUNCTION__,
708
+            __CLASS__.'::'.__FUNCTION__,
709 709
             sprintf(
710 710
                 esc_html__('This method is deprecated. Please use "%s" instead', 'event_espresso'),
711 711
                 '\EventEspresso\core\domain\services\registration\CreateRegistrationService::create()'
@@ -715,7 +715,7 @@  discard block
 block discarded – undo
715 715
         );
716 716
         // grab the related ticket object for this line_item
717 717
         $ticket = $line_item->ticket();
718
-        if (! $ticket instanceof EE_Ticket) {
718
+        if ( ! $ticket instanceof EE_Ticket) {
719 719
             EE_Error::add_error(
720 720
                 sprintf(
721 721
                     esc_html__('Line item %s did not contain a valid ticket', 'event_espresso'),
@@ -753,7 +753,7 @@  discard block
 block discarded – undo
753 753
     public function generate_reg_url_link($att_nmbr, $item)
754 754
     {
755 755
         EE_Error::doing_it_wrong(
756
-            __CLASS__ . '::' . __FUNCTION__,
756
+            __CLASS__.'::'.__FUNCTION__,
757 757
             sprintf(
758 758
                 esc_html__('This method is deprecated. Please use "%s" instead', 'event_espresso'),
759 759
                 'EventEspresso\core\domain\entities\RegUrlLink'
@@ -779,7 +779,7 @@  discard block
 block discarded – undo
779 779
     public function generate_reg_code(EE_Registration $registration)
780 780
     {
781 781
         EE_Error::doing_it_wrong(
782
-            __CLASS__ . '::' . __FUNCTION__,
782
+            __CLASS__.'::'.__FUNCTION__,
783 783
             sprintf(
784 784
                 esc_html__('This method is deprecated. Please use "%s" instead', 'event_espresso'),
785 785
                 'EventEspresso\core\domain\entities\RegCode'
Please login to merge, or discard this patch.
core/libraries/plugin_api/EE_Register_Model_Extensions.lib.php 2 patches
Spacing   +12 added lines, -12 removed lines patch added patch discarded remove patch
@@ -68,11 +68,11 @@  discard block
 block discarded – undo
68 68
         }
69 69
 
70 70
         // make sure we don't register twice
71
-        if (isset(self::$_registry[ $identifier ])) {
71
+        if (isset(self::$_registry[$identifier])) {
72 72
             return;
73 73
         }
74 74
         // check correct loading
75
-        if (! did_action('AHEE__EE_System__load_espresso_addons') || did_action('AHEE__EE_Admin__loaded')) {
75
+        if ( ! did_action('AHEE__EE_System__load_espresso_addons') || did_action('AHEE__EE_Admin__loaded')) {
76 76
             EE_Error::doing_it_wrong(
77 77
                 __METHOD__,
78 78
                 sprintf(
@@ -89,30 +89,30 @@  discard block
 block discarded – undo
89 89
             );
90 90
         }
91 91
 
92
-        self::$_registry[ $identifier ]   = $setup_args;
93
-        self::$_extensions[ $identifier ] = [];
92
+        self::$_registry[$identifier]   = $setup_args;
93
+        self::$_extensions[$identifier] = [];
94 94
 
95 95
         if (isset($setup_args['model_extension_paths'])) {
96
-            require_once(EE_LIBRARIES . 'plugin_api/db/EEME_Base.lib.php');
96
+            require_once(EE_LIBRARIES.'plugin_api/db/EEME_Base.lib.php');
97 97
             $class_to_filepath_map = EEH_File::get_contents_of_folders($setup_args['model_extension_paths']);
98 98
             // remove all files that are not PHP
99 99
             foreach ($class_to_filepath_map as $class => $path) {
100 100
                 if (substr($path, strlen($path) - 3) !== 'php') {
101
-                    unset($class_to_filepath_map[ $class ]);
101
+                    unset($class_to_filepath_map[$class]);
102 102
                 }
103 103
             }
104 104
             EEH_Autoloader::register_autoloader($class_to_filepath_map);
105 105
             foreach (array_keys($class_to_filepath_map) as $classname) {
106
-                self::$_extensions[ $identifier ]['models'][ $classname ] = new $classname();
106
+                self::$_extensions[$identifier]['models'][$classname] = new $classname();
107 107
             }
108 108
             unset($setup_args['model_extension_paths']);
109 109
         }
110 110
         if (isset($setup_args['class_extension_paths'])) {
111
-            require_once(EE_LIBRARIES . 'plugin_api/db/EEE_Base_Class.lib.php');
111
+            require_once(EE_LIBRARIES.'plugin_api/db/EEE_Base_Class.lib.php');
112 112
             $class_to_filepath_map = EEH_File::get_contents_of_folders($setup_args['class_extension_paths']);
113 113
             EEH_Autoloader::register_autoloader($class_to_filepath_map);
114 114
             foreach (array_keys($class_to_filepath_map) as $classname) {
115
-                self::$_extensions[ $identifier ]['classes'][ $classname ] = new $classname();
115
+                self::$_extensions[$identifier]['classes'][$classname] = new $classname();
116 116
             }
117 117
             unset($setup_args['class_extension_paths']);
118 118
         }
@@ -131,9 +131,9 @@  discard block
 block discarded – undo
131 131
      */
132 132
     public static function deregister($identifier = '')
133 133
     {
134
-        if (isset(self::$_registry[ $identifier ])) {
135
-            unset(self::$_registry[ $identifier ]);
136
-            foreach (self::$_extensions[ $identifier ] as $extension_of_type) {
134
+        if (isset(self::$_registry[$identifier])) {
135
+            unset(self::$_registry[$identifier]);
136
+            foreach (self::$_extensions[$identifier] as $extension_of_type) {
137 137
                 foreach ($extension_of_type as $extension) {
138 138
                     $extension->deregister();
139 139
                 }
Please login to merge, or discard this patch.
Indentation   +120 added lines, -120 removed lines patch added patch discarded remove patch
@@ -12,132 +12,132 @@
 block discarded – undo
12 12
 class EE_Register_Model_Extensions implements EEI_Plugin_API
13 13
 {
14 14
 
15
-    protected static $_registry;
15
+	protected static $_registry;
16 16
 
17
-    protected static $_extensions = [];
17
+	protected static $_extensions = [];
18 18
 
19 19
 
20
-    /**
21
-     * register method for setting up model extensions
22
-     *
23
-     * @param string $identifier            unique id for the extensions being setup
24
-     * @param array  $setup_args            {
25
-     * @return void
26
-     * @throws EE_Error
27
-     * @type  array  $model_extension_paths array of folders containing DB model extensions, where each file follows
28
-     *                                      the models naming convention, which is:
29
-     *                                      EEME_{your_plugin_slug}_model_name_extended}.model_ext.php.
30
-     *                                      Where {your_plugin_slug} is really anything you want (but something having
31
-     *                                      to do with your addon, like 'Calendar' or '3D_View') and
32
-     *                                      model_name_extended} is the model extended.
33
-     *                                      The class contained in teh file should extend
34
-     *                                      EEME_Base_{model_name_extended}.model_ext.php.
35
-     *                                      Where {your_plugin_slug} is really anything you want (but something
36
-     *                                      having to do with your addon, like 'Calendar' or '3D_View') and
37
-     *                                      {model_name_extended} is the model extended. The class contained in teh
38
-     *                                      file should extend EEME_Base
39
-     * @type array   $class_extension_paths array of folders containing DB class extensions, where each file follows
40
-     *                                      the model class extension naming convention, which is:
41
-     *                                      EEE_{your_plugin_slug}_model_name_extended}.class_ext.php.
42
-     *                                      Where {your_plugin_slug} is something like 'Calendar','MailChimp',etc,
43
-     *                                      and model_name_extended} is the name of the model extended, eg
44
-     *                                      'Attendee','Event',etc.
45
-     *                                      The class contained in the file should extend EEE_Base_Class
46
-     *                                      ._{model_name_extended}.class_ext.php.
47
-     *                                      Where {your_plugin_slug} is something like 'Calendar','MailChimp',etc,
48
-     *                                      and {model_name_extended} is the name of the model extended, eg
49
-     *                                      'Attendee','Event',etc. The class contained in the file should extend
50
-     *                                      EEE_Base_Class.
51
-     *                                      }
52
-     *
53
-     */
54
-    public static function register($identifier = '', array $setup_args = [])
55
-    {
56
-        // required fields MUST be present, so let's make sure they are.
57
-        if (
58
-            empty($identifier)
59
-            || ! is_array($setup_args)
60
-            || (empty($setup_args['model_extension_paths']) && empty($setup_args['class_extension_paths']))
61
-        ) {
62
-            throw new EE_Error(
63
-                esc_html__(
64
-                    'In order to register Model extensions with EE_Register_Model_Extensions::register(), you must include a "model_id" (a unique identifier for this set of models), and an array containing the following keys: "model_extension_paths" (an array of full server paths to folders that contain model extensions), and "class_extension_paths" (an array of full server paths to folders that contain class extensions)',
65
-                    'event_espresso'
66
-                )
67
-            );
68
-        }
20
+	/**
21
+	 * register method for setting up model extensions
22
+	 *
23
+	 * @param string $identifier            unique id for the extensions being setup
24
+	 * @param array  $setup_args            {
25
+	 * @return void
26
+	 * @throws EE_Error
27
+	 * @type  array  $model_extension_paths array of folders containing DB model extensions, where each file follows
28
+	 *                                      the models naming convention, which is:
29
+	 *                                      EEME_{your_plugin_slug}_model_name_extended}.model_ext.php.
30
+	 *                                      Where {your_plugin_slug} is really anything you want (but something having
31
+	 *                                      to do with your addon, like 'Calendar' or '3D_View') and
32
+	 *                                      model_name_extended} is the model extended.
33
+	 *                                      The class contained in teh file should extend
34
+	 *                                      EEME_Base_{model_name_extended}.model_ext.php.
35
+	 *                                      Where {your_plugin_slug} is really anything you want (but something
36
+	 *                                      having to do with your addon, like 'Calendar' or '3D_View') and
37
+	 *                                      {model_name_extended} is the model extended. The class contained in teh
38
+	 *                                      file should extend EEME_Base
39
+	 * @type array   $class_extension_paths array of folders containing DB class extensions, where each file follows
40
+	 *                                      the model class extension naming convention, which is:
41
+	 *                                      EEE_{your_plugin_slug}_model_name_extended}.class_ext.php.
42
+	 *                                      Where {your_plugin_slug} is something like 'Calendar','MailChimp',etc,
43
+	 *                                      and model_name_extended} is the name of the model extended, eg
44
+	 *                                      'Attendee','Event',etc.
45
+	 *                                      The class contained in the file should extend EEE_Base_Class
46
+	 *                                      ._{model_name_extended}.class_ext.php.
47
+	 *                                      Where {your_plugin_slug} is something like 'Calendar','MailChimp',etc,
48
+	 *                                      and {model_name_extended} is the name of the model extended, eg
49
+	 *                                      'Attendee','Event',etc. The class contained in the file should extend
50
+	 *                                      EEE_Base_Class.
51
+	 *                                      }
52
+	 *
53
+	 */
54
+	public static function register($identifier = '', array $setup_args = [])
55
+	{
56
+		// required fields MUST be present, so let's make sure they are.
57
+		if (
58
+			empty($identifier)
59
+			|| ! is_array($setup_args)
60
+			|| (empty($setup_args['model_extension_paths']) && empty($setup_args['class_extension_paths']))
61
+		) {
62
+			throw new EE_Error(
63
+				esc_html__(
64
+					'In order to register Model extensions with EE_Register_Model_Extensions::register(), you must include a "model_id" (a unique identifier for this set of models), and an array containing the following keys: "model_extension_paths" (an array of full server paths to folders that contain model extensions), and "class_extension_paths" (an array of full server paths to folders that contain class extensions)',
65
+					'event_espresso'
66
+				)
67
+			);
68
+		}
69 69
 
70
-        // make sure we don't register twice
71
-        if (isset(self::$_registry[ $identifier ])) {
72
-            return;
73
-        }
74
-        // check correct loading
75
-        if (! did_action('AHEE__EE_System__load_espresso_addons') || did_action('AHEE__EE_Admin__loaded')) {
76
-            EE_Error::doing_it_wrong(
77
-                __METHOD__,
78
-                sprintf(
79
-                    esc_html__(
80
-                        'An attempt was made to register "%1$s" as a Model extension has failed because it was not registered at the correct time.  Please use the "AHEE__EE_System__load_espresso_addons" hook to register models.%2$s Hook Status: %2$s "AHEE__EE_System__load_espresso_addons" : %3$s %2$s "AHEE__EE_Admin__loaded" : %4$s%2$s',
81
-                        'event_espresso'
82
-                    ),
83
-                    $identifier,
84
-                    '<br />',
85
-                    did_action('AHEE__EE_System__load_espresso_addons') ? 'action done' : 'action NOT done',
86
-                    did_action('AHEE__EE_Admin__loaded') ? 'action done' : 'action NOT done'
87
-                ),
88
-                '4.3'
89
-            );
90
-        }
70
+		// make sure we don't register twice
71
+		if (isset(self::$_registry[ $identifier ])) {
72
+			return;
73
+		}
74
+		// check correct loading
75
+		if (! did_action('AHEE__EE_System__load_espresso_addons') || did_action('AHEE__EE_Admin__loaded')) {
76
+			EE_Error::doing_it_wrong(
77
+				__METHOD__,
78
+				sprintf(
79
+					esc_html__(
80
+						'An attempt was made to register "%1$s" as a Model extension has failed because it was not registered at the correct time.  Please use the "AHEE__EE_System__load_espresso_addons" hook to register models.%2$s Hook Status: %2$s "AHEE__EE_System__load_espresso_addons" : %3$s %2$s "AHEE__EE_Admin__loaded" : %4$s%2$s',
81
+						'event_espresso'
82
+					),
83
+					$identifier,
84
+					'<br />',
85
+					did_action('AHEE__EE_System__load_espresso_addons') ? 'action done' : 'action NOT done',
86
+					did_action('AHEE__EE_Admin__loaded') ? 'action done' : 'action NOT done'
87
+				),
88
+				'4.3'
89
+			);
90
+		}
91 91
 
92
-        self::$_registry[ $identifier ]   = $setup_args;
93
-        self::$_extensions[ $identifier ] = [];
92
+		self::$_registry[ $identifier ]   = $setup_args;
93
+		self::$_extensions[ $identifier ] = [];
94 94
 
95
-        if (isset($setup_args['model_extension_paths'])) {
96
-            require_once(EE_LIBRARIES . 'plugin_api/db/EEME_Base.lib.php');
97
-            $class_to_filepath_map = EEH_File::get_contents_of_folders($setup_args['model_extension_paths']);
98
-            // remove all files that are not PHP
99
-            foreach ($class_to_filepath_map as $class => $path) {
100
-                if (substr($path, strlen($path) - 3) !== 'php') {
101
-                    unset($class_to_filepath_map[ $class ]);
102
-                }
103
-            }
104
-            EEH_Autoloader::register_autoloader($class_to_filepath_map);
105
-            foreach (array_keys($class_to_filepath_map) as $classname) {
106
-                self::$_extensions[ $identifier ]['models'][ $classname ] = new $classname();
107
-            }
108
-            unset($setup_args['model_extension_paths']);
109
-        }
110
-        if (isset($setup_args['class_extension_paths'])) {
111
-            require_once(EE_LIBRARIES . 'plugin_api/db/EEE_Base_Class.lib.php');
112
-            $class_to_filepath_map = EEH_File::get_contents_of_folders($setup_args['class_extension_paths']);
113
-            EEH_Autoloader::register_autoloader($class_to_filepath_map);
114
-            foreach (array_keys($class_to_filepath_map) as $classname) {
115
-                self::$_extensions[ $identifier ]['classes'][ $classname ] = new $classname();
116
-            }
117
-            unset($setup_args['class_extension_paths']);
118
-        }
119
-        foreach ($setup_args as $unknown_key => $unknown_config) {
120
-            throw new EE_Error(
121
-                sprintf(esc_html__("The key '%s' is not a known key for registering a model", "event_espresso"), $unknown_key)
122
-            );
123
-        }
124
-    }
95
+		if (isset($setup_args['model_extension_paths'])) {
96
+			require_once(EE_LIBRARIES . 'plugin_api/db/EEME_Base.lib.php');
97
+			$class_to_filepath_map = EEH_File::get_contents_of_folders($setup_args['model_extension_paths']);
98
+			// remove all files that are not PHP
99
+			foreach ($class_to_filepath_map as $class => $path) {
100
+				if (substr($path, strlen($path) - 3) !== 'php') {
101
+					unset($class_to_filepath_map[ $class ]);
102
+				}
103
+			}
104
+			EEH_Autoloader::register_autoloader($class_to_filepath_map);
105
+			foreach (array_keys($class_to_filepath_map) as $classname) {
106
+				self::$_extensions[ $identifier ]['models'][ $classname ] = new $classname();
107
+			}
108
+			unset($setup_args['model_extension_paths']);
109
+		}
110
+		if (isset($setup_args['class_extension_paths'])) {
111
+			require_once(EE_LIBRARIES . 'plugin_api/db/EEE_Base_Class.lib.php');
112
+			$class_to_filepath_map = EEH_File::get_contents_of_folders($setup_args['class_extension_paths']);
113
+			EEH_Autoloader::register_autoloader($class_to_filepath_map);
114
+			foreach (array_keys($class_to_filepath_map) as $classname) {
115
+				self::$_extensions[ $identifier ]['classes'][ $classname ] = new $classname();
116
+			}
117
+			unset($setup_args['class_extension_paths']);
118
+		}
119
+		foreach ($setup_args as $unknown_key => $unknown_config) {
120
+			throw new EE_Error(
121
+				sprintf(esc_html__("The key '%s' is not a known key for registering a model", "event_espresso"), $unknown_key)
122
+			);
123
+		}
124
+	}
125 125
 
126 126
 
127
-    /**
128
-     * deregister
129
-     *
130
-     * @param string $identifier
131
-     */
132
-    public static function deregister($identifier = '')
133
-    {
134
-        if (isset(self::$_registry[ $identifier ])) {
135
-            unset(self::$_registry[ $identifier ]);
136
-            foreach (self::$_extensions[ $identifier ] as $extension_of_type) {
137
-                foreach ($extension_of_type as $extension) {
138
-                    $extension->deregister();
139
-                }
140
-            }
141
-        }
142
-    }
127
+	/**
128
+	 * deregister
129
+	 *
130
+	 * @param string $identifier
131
+	 */
132
+	public static function deregister($identifier = '')
133
+	{
134
+		if (isset(self::$_registry[ $identifier ])) {
135
+			unset(self::$_registry[ $identifier ]);
136
+			foreach (self::$_extensions[ $identifier ] as $extension_of_type) {
137
+				foreach ($extension_of_type as $extension) {
138
+					$extension->deregister();
139
+				}
140
+			}
141
+		}
142
+	}
143 143
 }
Please login to merge, or discard this patch.
core/libraries/plugin_api/EE_Register_Payment_Method.lib.php 2 patches
Indentation   +151 added lines, -151 removed lines patch added patch discarded remove patch
@@ -19,163 +19,163 @@
 block discarded – undo
19 19
 class EE_Register_Payment_Method implements EEI_Plugin_API
20 20
 {
21 21
 
22
-    /**
23
-     * Holds values for registered payment methods
24
-     *
25
-     * @var array
26
-     */
27
-    protected static $_settings = [];
22
+	/**
23
+	 * Holds values for registered payment methods
24
+	 *
25
+	 * @var array
26
+	 */
27
+	protected static $_settings = [];
28 28
 
29 29
 
30
-    /**
31
-     * Method for registering new EE_PMT_Base children
32
-     *
33
-     * @param string  $identifier           a unique identifier for this set of modules Required.
34
-     * @param array   $setup_args           an array of arguments provided for registering modules Required.{
35
-     * @type string[] $payment_method_paths each element is the folder containing the EE_PMT_Base child class
36
-     *                                      (eg, 'public_html/wp-content/plugins/my_plugin/Payomatic/' which contains
37
-     *                                      the files EE_PMT_Payomatic.pm.php)
38
-     *                                      }
39
-     * @return void
40
-     * @throws EE_Error
41
-     * @type array payment_method_paths    an array of full server paths to folders containing any EE_PMT_Base
42
-     *                                      children, or to the EED_Module files themselves
43
-     * @throws InvalidDataTypeException
44
-     * @throws DomainException
45
-     * @throws InvalidArgumentException
46
-     * @throws InvalidInterfaceException
47
-     * @throws InvalidDataTypeException
48
-     * @since    4.5.0
49
-     */
50
-    public static function register($identifier = '', array $setup_args = [])
51
-    {
52
-        // required fields MUST be present, so let's make sure they are.
53
-        if (empty($identifier) || ! is_array($setup_args) || empty($setup_args['payment_method_paths'])) {
54
-            throw new EE_Error(
55
-                esc_html__(
56
-                    'In order to register Payment Methods with EE_Register_Payment_Method::register(), you must include a "payment_method_id" (a unique identifier for this set of modules), and an array containing the following keys: "payment_method_paths" (an array of full server paths to folders that contain modules, or to the module files themselves)',
57
-                    'event_espresso'
58
-                )
59
-            );
60
-        }
61
-        // make sure we don't register twice
62
-        if (isset(self::$_settings[ $identifier ])) {
63
-            return;
64
-        }
65
-        // make sure this was called in the right place!
66
-        if (
67
-            ! did_action('AHEE__EE_System__load_espresso_addons')
68
-            || did_action('AHEE__EE_System__register_shortcodes_modules_and_widgets')
69
-        ) {
70
-            EE_Error::doing_it_wrong(
71
-                __METHOD__,
72
-                esc_html__(
73
-                    'An attempt to register modules has failed because it was not registered at the correct time.  Please use the "AHEE__EE_System__register_shortcodes_modules_and_widgets" hook to register modules.',
74
-                    'event_espresso'
75
-                ),
76
-                '4.3.0'
77
-            );
78
-        }
79
-        // setup $_settings array from incoming values.
80
-        self::$_settings[ $identifier ] = [
81
-            // array of full server paths to any EE_PMT_Base children used
82
-            'payment_method_paths' => isset($setup_args['payment_method_paths'])
83
-                ? (array) $setup_args['payment_method_paths']
84
-                : [],
85
-        ];
86
-        // add to list of modules to be registered
87
-        add_filter(
88
-            'FHEE__EE_Payment_Method_Manager__register_payment_methods__payment_methods_to_register',
89
-            ['EE_Register_Payment_Method', 'add_payment_methods']
90
-        );
91
-        // If EE_Payment_Method_Manager::register_payment_methods has already been called,
92
-        // then we need to add our caps for this payment method manually
93
-        if (did_action('FHEE__EE_Payment_Method_Manager__register_payment_methods__registered_payment_methods')) {
94
-            $payment_method_manager = LoaderFactory::getLoader()->getShared('EE_Payment_Method_Manager');
95
-            // register payment methods directly
96
-            foreach (self::$_settings[ $identifier ]['payment_method_paths'] as $payment_method_path) {
97
-                $payment_method_manager->register_payment_method($payment_method_path);
98
-            }
99
-            $capabilities = LoaderFactory::getLoader()->getShared('EE_Capabilities');
100
-            $capabilities->addCaps(
101
-                self::getPaymentMethodCapabilities(self::$_settings[ $identifier ])
102
-            );
103
-        }
104
-    }
30
+	/**
31
+	 * Method for registering new EE_PMT_Base children
32
+	 *
33
+	 * @param string  $identifier           a unique identifier for this set of modules Required.
34
+	 * @param array   $setup_args           an array of arguments provided for registering modules Required.{
35
+	 * @type string[] $payment_method_paths each element is the folder containing the EE_PMT_Base child class
36
+	 *                                      (eg, 'public_html/wp-content/plugins/my_plugin/Payomatic/' which contains
37
+	 *                                      the files EE_PMT_Payomatic.pm.php)
38
+	 *                                      }
39
+	 * @return void
40
+	 * @throws EE_Error
41
+	 * @type array payment_method_paths    an array of full server paths to folders containing any EE_PMT_Base
42
+	 *                                      children, or to the EED_Module files themselves
43
+	 * @throws InvalidDataTypeException
44
+	 * @throws DomainException
45
+	 * @throws InvalidArgumentException
46
+	 * @throws InvalidInterfaceException
47
+	 * @throws InvalidDataTypeException
48
+	 * @since    4.5.0
49
+	 */
50
+	public static function register($identifier = '', array $setup_args = [])
51
+	{
52
+		// required fields MUST be present, so let's make sure they are.
53
+		if (empty($identifier) || ! is_array($setup_args) || empty($setup_args['payment_method_paths'])) {
54
+			throw new EE_Error(
55
+				esc_html__(
56
+					'In order to register Payment Methods with EE_Register_Payment_Method::register(), you must include a "payment_method_id" (a unique identifier for this set of modules), and an array containing the following keys: "payment_method_paths" (an array of full server paths to folders that contain modules, or to the module files themselves)',
57
+					'event_espresso'
58
+				)
59
+			);
60
+		}
61
+		// make sure we don't register twice
62
+		if (isset(self::$_settings[ $identifier ])) {
63
+			return;
64
+		}
65
+		// make sure this was called in the right place!
66
+		if (
67
+			! did_action('AHEE__EE_System__load_espresso_addons')
68
+			|| did_action('AHEE__EE_System__register_shortcodes_modules_and_widgets')
69
+		) {
70
+			EE_Error::doing_it_wrong(
71
+				__METHOD__,
72
+				esc_html__(
73
+					'An attempt to register modules has failed because it was not registered at the correct time.  Please use the "AHEE__EE_System__register_shortcodes_modules_and_widgets" hook to register modules.',
74
+					'event_espresso'
75
+				),
76
+				'4.3.0'
77
+			);
78
+		}
79
+		// setup $_settings array from incoming values.
80
+		self::$_settings[ $identifier ] = [
81
+			// array of full server paths to any EE_PMT_Base children used
82
+			'payment_method_paths' => isset($setup_args['payment_method_paths'])
83
+				? (array) $setup_args['payment_method_paths']
84
+				: [],
85
+		];
86
+		// add to list of modules to be registered
87
+		add_filter(
88
+			'FHEE__EE_Payment_Method_Manager__register_payment_methods__payment_methods_to_register',
89
+			['EE_Register_Payment_Method', 'add_payment_methods']
90
+		);
91
+		// If EE_Payment_Method_Manager::register_payment_methods has already been called,
92
+		// then we need to add our caps for this payment method manually
93
+		if (did_action('FHEE__EE_Payment_Method_Manager__register_payment_methods__registered_payment_methods')) {
94
+			$payment_method_manager = LoaderFactory::getLoader()->getShared('EE_Payment_Method_Manager');
95
+			// register payment methods directly
96
+			foreach (self::$_settings[ $identifier ]['payment_method_paths'] as $payment_method_path) {
97
+				$payment_method_manager->register_payment_method($payment_method_path);
98
+			}
99
+			$capabilities = LoaderFactory::getLoader()->getShared('EE_Capabilities');
100
+			$capabilities->addCaps(
101
+				self::getPaymentMethodCapabilities(self::$_settings[ $identifier ])
102
+			);
103
+		}
104
+	}
105 105
 
106 106
 
107
-    /**
108
-     * Filters the list of payment methods to add ours.
109
-     * and they're just full filepaths to FOLDERS containing a payment method class file. Eg.
110
-     *
111
-     * @param array $payment_method_folders array of paths to all payment methods that require registering
112
-     * @return array
113
-     */
114
-    public static function add_payment_methods(array $payment_method_folders)
115
-    {
116
-        foreach (self::$_settings as $settings) {
117
-            foreach ($settings['payment_method_paths'] as $payment_method_path) {
118
-                $payment_method_folders[] = $payment_method_path;
119
-            }
120
-        }
121
-        return $payment_method_folders;
122
-    }
107
+	/**
108
+	 * Filters the list of payment methods to add ours.
109
+	 * and they're just full filepaths to FOLDERS containing a payment method class file. Eg.
110
+	 *
111
+	 * @param array $payment_method_folders array of paths to all payment methods that require registering
112
+	 * @return array
113
+	 */
114
+	public static function add_payment_methods(array $payment_method_folders)
115
+	{
116
+		foreach (self::$_settings as $settings) {
117
+			foreach ($settings['payment_method_paths'] as $payment_method_path) {
118
+				$payment_method_folders[] = $payment_method_path;
119
+			}
120
+		}
121
+		return $payment_method_folders;
122
+	}
123 123
 
124 124
 
125
-    /**
126
-     * This deregisters a module that was previously registered with a specific $identifier.
127
-     *
128
-     * @param string $identifier the name for the module that was previously registered
129
-     * @return void
130
-     * @throws DomainException
131
-     * @throws InvalidArgumentException
132
-     * @throws InvalidInterfaceException
133
-     * @throws InvalidDataTypeException
134
-     * @since    4.3.0
135
-     */
136
-    public static function deregister($identifier = '')
137
-    {
138
-        if (isset(self::$_settings[ $identifier ])) {
139
-            // set action for just this module id to delay deregistration until core is loaded and ready.
140
-            $module_settings = self::$_settings[ $identifier ];
141
-            unset(self::$_settings[ $identifier ]);
142
-            add_action(
143
-                'AHEE__EE_System__core_loaded_and_ready',
144
-                function () use ($module_settings) {
145
-                    $capabilities = LoaderFactory::getLoader()->getShared('EE_Capabilities');
146
-                    $capabilities->removeCaps(
147
-                        EE_Register_Payment_Method::getPaymentMethodCapabilities($module_settings)
148
-                    );
149
-                }
150
-            );
151
-        }
152
-    }
125
+	/**
126
+	 * This deregisters a module that was previously registered with a specific $identifier.
127
+	 *
128
+	 * @param string $identifier the name for the module that was previously registered
129
+	 * @return void
130
+	 * @throws DomainException
131
+	 * @throws InvalidArgumentException
132
+	 * @throws InvalidInterfaceException
133
+	 * @throws InvalidDataTypeException
134
+	 * @since    4.3.0
135
+	 */
136
+	public static function deregister($identifier = '')
137
+	{
138
+		if (isset(self::$_settings[ $identifier ])) {
139
+			// set action for just this module id to delay deregistration until core is loaded and ready.
140
+			$module_settings = self::$_settings[ $identifier ];
141
+			unset(self::$_settings[ $identifier ]);
142
+			add_action(
143
+				'AHEE__EE_System__core_loaded_and_ready',
144
+				function () use ($module_settings) {
145
+					$capabilities = LoaderFactory::getLoader()->getShared('EE_Capabilities');
146
+					$capabilities->removeCaps(
147
+						EE_Register_Payment_Method::getPaymentMethodCapabilities($module_settings)
148
+					);
149
+				}
150
+			);
151
+		}
152
+	}
153 153
 
154 154
 
155
-    /**
156
-     * returns an array of the caps that get added when a Payment Method is registered
157
-     *
158
-     * @param array $settings
159
-     * @return array
160
-     * @throws DomainException
161
-     * @throws InvalidArgumentException
162
-     * @throws InvalidInterfaceException
163
-     * @throws InvalidDataTypeException
164
-     * @access private  Developers do NOT use this method.  It's only public for PHP5.3 closure support (see deregister)
165
-     *                  When we drop support for PHP5.3 this will be made private again.  You have been warned.
166
-     */
167
-    public static function getPaymentMethodCapabilities(array $settings)
168
-    {
169
-        $payment_method_manager = LoaderFactory::getLoader()->getShared('EE_Payment_Method_Manager');
170
-        $payment_method_caps    = ['administrator' => []];
171
-        if (isset($settings['payment_method_paths'])) {
172
-            foreach ($settings['payment_method_paths'] as $payment_method_path) {
173
-                $payment_method_caps = $payment_method_manager->addPaymentMethodCap(
174
-                    strtolower(basename($payment_method_path)),
175
-                    $payment_method_caps
176
-                );
177
-            }
178
-        }
179
-        return $payment_method_caps;
180
-    }
155
+	/**
156
+	 * returns an array of the caps that get added when a Payment Method is registered
157
+	 *
158
+	 * @param array $settings
159
+	 * @return array
160
+	 * @throws DomainException
161
+	 * @throws InvalidArgumentException
162
+	 * @throws InvalidInterfaceException
163
+	 * @throws InvalidDataTypeException
164
+	 * @access private  Developers do NOT use this method.  It's only public for PHP5.3 closure support (see deregister)
165
+	 *                  When we drop support for PHP5.3 this will be made private again.  You have been warned.
166
+	 */
167
+	public static function getPaymentMethodCapabilities(array $settings)
168
+	{
169
+		$payment_method_manager = LoaderFactory::getLoader()->getShared('EE_Payment_Method_Manager');
170
+		$payment_method_caps    = ['administrator' => []];
171
+		if (isset($settings['payment_method_paths'])) {
172
+			foreach ($settings['payment_method_paths'] as $payment_method_path) {
173
+				$payment_method_caps = $payment_method_manager->addPaymentMethodCap(
174
+					strtolower(basename($payment_method_path)),
175
+					$payment_method_caps
176
+				);
177
+			}
178
+		}
179
+		return $payment_method_caps;
180
+	}
181 181
 }
Please login to merge, or discard this patch.
Spacing   +8 added lines, -8 removed lines patch added patch discarded remove patch
@@ -59,7 +59,7 @@  discard block
 block discarded – undo
59 59
             );
60 60
         }
61 61
         // make sure we don't register twice
62
-        if (isset(self::$_settings[ $identifier ])) {
62
+        if (isset(self::$_settings[$identifier])) {
63 63
             return;
64 64
         }
65 65
         // make sure this was called in the right place!
@@ -77,7 +77,7 @@  discard block
 block discarded – undo
77 77
             );
78 78
         }
79 79
         // setup $_settings array from incoming values.
80
-        self::$_settings[ $identifier ] = [
80
+        self::$_settings[$identifier] = [
81 81
             // array of full server paths to any EE_PMT_Base children used
82 82
             'payment_method_paths' => isset($setup_args['payment_method_paths'])
83 83
                 ? (array) $setup_args['payment_method_paths']
@@ -93,12 +93,12 @@  discard block
 block discarded – undo
93 93
         if (did_action('FHEE__EE_Payment_Method_Manager__register_payment_methods__registered_payment_methods')) {
94 94
             $payment_method_manager = LoaderFactory::getLoader()->getShared('EE_Payment_Method_Manager');
95 95
             // register payment methods directly
96
-            foreach (self::$_settings[ $identifier ]['payment_method_paths'] as $payment_method_path) {
96
+            foreach (self::$_settings[$identifier]['payment_method_paths'] as $payment_method_path) {
97 97
                 $payment_method_manager->register_payment_method($payment_method_path);
98 98
             }
99 99
             $capabilities = LoaderFactory::getLoader()->getShared('EE_Capabilities');
100 100
             $capabilities->addCaps(
101
-                self::getPaymentMethodCapabilities(self::$_settings[ $identifier ])
101
+                self::getPaymentMethodCapabilities(self::$_settings[$identifier])
102 102
             );
103 103
         }
104 104
     }
@@ -135,13 +135,13 @@  discard block
 block discarded – undo
135 135
      */
136 136
     public static function deregister($identifier = '')
137 137
     {
138
-        if (isset(self::$_settings[ $identifier ])) {
138
+        if (isset(self::$_settings[$identifier])) {
139 139
             // set action for just this module id to delay deregistration until core is loaded and ready.
140
-            $module_settings = self::$_settings[ $identifier ];
141
-            unset(self::$_settings[ $identifier ]);
140
+            $module_settings = self::$_settings[$identifier];
141
+            unset(self::$_settings[$identifier]);
142 142
             add_action(
143 143
                 'AHEE__EE_System__core_loaded_and_ready',
144
-                function () use ($module_settings) {
144
+                function() use ($module_settings) {
145 145
                     $capabilities = LoaderFactory::getLoader()->getShared('EE_Capabilities');
146 146
                     $capabilities->removeCaps(
147 147
                         EE_Register_Payment_Method::getPaymentMethodCapabilities($module_settings)
Please login to merge, or discard this patch.
core/libraries/plugin_api/EE_Register_Messages_Template_Pack.lib.php 2 patches
Spacing   +8 added lines, -8 removed lines patch added patch discarded remove patch
@@ -70,13 +70,13 @@  discard block
 block discarded – undo
70 70
         }
71 71
 
72 72
         // make sure we don't register twice
73
-        if (isset(self::$_registry[ $identifier ])) {
73
+        if (isset(self::$_registry[$identifier])) {
74 74
             return;
75 75
         }
76 76
 
77 77
         // check that incoming $identifier doesn't already exist. If it does then we'll create a unique reference for this template pack.
78
-        if (isset(self::$_registry[ $identifier ])) {
79
-            $identifier = uniqid() . '_' . $identifier;
78
+        if (isset(self::$_registry[$identifier])) {
79
+            $identifier = uniqid().'_'.$identifier;
80 80
         }
81 81
 
82 82
 
@@ -99,7 +99,7 @@  discard block
 block discarded – undo
99 99
         }
100 100
 
101 101
         if (self::_verify_class_not_exist($setup_args['classname'])) {
102
-            self::$_registry[ $identifier ] = [
102
+            self::$_registry[$identifier] = [
103 103
                 'path'      => (string) $setup_args['path'],
104 104
                 'classname' => (string) $setup_args['classname'],
105 105
             ];
@@ -151,14 +151,14 @@  discard block
 block discarded – undo
151 151
     {
152 152
         foreach (self::$_registry as $args) {
153 153
             // verify class_exists
154
-            if (! class_exists($args['classname'])) {
155
-                require_once($args['path'] . '/' . $args['classname'] . '.class.php');
154
+            if ( ! class_exists($args['classname'])) {
155
+                require_once($args['path'].'/'.$args['classname'].'.class.php');
156 156
             }
157 157
 
158 158
             // check again!
159 159
             if (class_exists($args['classname'])) {
160 160
                 $template_pack                           = new $args['classname']();
161
-                $template_packs[ $template_pack->dbref ] = $template_pack;
161
+                $template_packs[$template_pack->dbref] = $template_pack;
162 162
             }
163 163
         }
164 164
 
@@ -208,6 +208,6 @@  discard block
 block discarded – undo
208 208
      */
209 209
     public static function deregister($identifier = '')
210 210
     {
211
-        unset(self::$_registry[ $identifier ]);
211
+        unset(self::$_registry[$identifier]);
212 212
     }
213 213
 }
Please login to merge, or discard this patch.
Indentation   +198 added lines, -198 removed lines patch added patch discarded remove patch
@@ -12,202 +12,202 @@
 block discarded – undo
12 12
 {
13 13
 
14 14
 
15
-    /**
16
-     * Holds values for registered template pack
17
-     *
18
-     * @since 4.5.0
19
-     *
20
-     * @var array
21
-     */
22
-    protected static $_registry = [];
23
-
24
-
25
-    /**
26
-     * Used to register a new template pack with the messages system.
27
-     *
28
-     * Template packs are primarily defined via class extending EE_Messages_Template_Pack and are typically used to
29
-     * change entire layouts for a set of message templates.  This method is used to register the new template pack and
30
-     * automatically have it loaded in the appropriate places.
31
-     *
32
-     * This registry also verifies that there isn't already a template pack registered with the same name and if there
33
-     * is then it will add an EE_Error notice.
34
-     *
35
-     * Note that this only handles registering the your Template Pack class with the message template pack system.
36
-     * However, there is also a naming schema you must follow for templates you are providing with your template pack.
37
-     *
38
-     * @param string $identifier The internal reference used to refer to this template pack.  Note, this is first come,
39
-     *                           first serve.  If there is already a template pack registered with this name then the
40
-     *                           registry will assign a unique reference for it so it can still be activated (but this
41
-     *                           makes it harder to deregister as it will be unique per load - so its best to try to
42
-     *                           make this a unique string!)
43
-     * @param array  $setup_args array {
44
-     *                           An array of required values for registering the template pack.
45
-     * @type string  $path       The path for the new template pack class.
46
-     * @type string  $classname  The name of the new Template Pack Class.
47
-     *                           }
48
-     *
49
-     * @return void
50
-     * @throws EE_Error
51
-     *
52
-     * @see    core/libraries/messages/defaults/default/* for all the example templates the default template pack
53
-     *         supports.
54
-     *
55
-     *
56
-     * @since  4.5.0
57
-     * @see    EE_Messages_Template_Pack_Default for an example class
58
-     */
59
-    public static function register($identifier = '', array $setup_args = [])
60
-    {
61
-
62
-        // check for required params
63
-        if (empty($identifier) || empty($setup_args['path']) || empty($setup_args['classname'])) {
64
-            throw new EE_Error(
65
-                esc_html__(
66
-                    'In order to register a new template pack for the EE Messages system, you must include a value to reference the template pack being registered and the setup_args must have the path for the new template pack class as well as the classname for the new Template Pack Class. ',
67
-                    'event_espresso'
68
-                )
69
-            );
70
-        }
71
-
72
-        // make sure we don't register twice
73
-        if (isset(self::$_registry[ $identifier ])) {
74
-            return;
75
-        }
76
-
77
-        // check that incoming $identifier doesn't already exist. If it does then we'll create a unique reference for this template pack.
78
-        if (isset(self::$_registry[ $identifier ])) {
79
-            $identifier = uniqid() . '_' . $identifier;
80
-        }
81
-
82
-
83
-        // make sure this was called in the right place!
84
-        if (
85
-            ! did_action('EE_Brewing_Regular___messages_caf')
86
-            || did_action('AHEE__EE_System__perform_activations_upgrades_and_migrations')
87
-        ) {
88
-            EE_Error::doing_it_wrong(
89
-                __METHOD__,
90
-                sprintf(
91
-                    esc_html__(
92
-                        'A EE Messages Template Pack given the reference "%s" has been attempted to be registered with the EE Messages System.  It may or may not work because it should be only called on the "EE_Brewing_Regular__messages_caf" hook.',
93
-                        'event_espresso'
94
-                    ),
95
-                    $identifier
96
-                ),
97
-                '4.5.0'
98
-            );
99
-        }
100
-
101
-        if (self::_verify_class_not_exist($setup_args['classname'])) {
102
-            self::$_registry[ $identifier ] = [
103
-                'path'      => (string) $setup_args['path'],
104
-                'classname' => (string) $setup_args['classname'],
105
-            ];
106
-        }
107
-
108
-        // hook into the system
109
-        add_filter(
110
-            'FHEE__EED_Messages___set_messages_paths___MSG_PATHS',
111
-            ['EE_Register_Messages_Template_Pack', 'set_template_pack_path'],
112
-            10
113
-        );
114
-        add_filter(
115
-            'FHEE__EED_Messages__get_template_packs__template_packs',
116
-            ['EE_Register_Messages_Template_Pack', 'set_template_pack'],
117
-            10
118
-        );
119
-    }
120
-
121
-
122
-    /**
123
-     * Callback for the FHEE__EED_Messages___set_messages_paths___MSG_PATHS filter.  This adds this template packs path
124
-     * to the messages autoloader paths.
125
-     *
126
-     * @param array $paths Array of paths already registered with the messages autoloader
127
-     *
128
-     * @return array
129
-     * @since  4.5.0
130
-     *
131
-     */
132
-    public static function set_template_pack_path(array $paths)
133
-    {
134
-        foreach (self::$_registry as $args) {
135
-            $paths[] = $args['path'];
136
-        }
137
-        return $paths;
138
-    }
139
-
140
-
141
-    /**
142
-     * Callback for the FHEE__EED_Messages__get_template_packs__template_packs filter. This adds the instantiated,
143
-     * registered template pack to the template packs array when requested by client code.
144
-     *
145
-     * @param EE_Messages_Template_Pack[] $template_packs
146
-     * @return EE_Messages_Template_Pack[]
147
-     * @since 4.5.0
148
-     *
149
-     */
150
-    public static function set_template_pack(array $template_packs)
151
-    {
152
-        foreach (self::$_registry as $args) {
153
-            // verify class_exists
154
-            if (! class_exists($args['classname'])) {
155
-                require_once($args['path'] . '/' . $args['classname'] . '.class.php');
156
-            }
157
-
158
-            // check again!
159
-            if (class_exists($args['classname'])) {
160
-                $template_pack                           = new $args['classname']();
161
-                $template_packs[ $template_pack->dbref ] = $template_pack;
162
-            }
163
-        }
164
-
165
-        return $template_packs;
166
-    }
167
-
168
-
169
-    /**
170
-     * This verifies that the classes for each registered template pack are unique  names.
171
-     *
172
-     * @param string $classname The classname being checked
173
-     *
174
-     * @return bool
175
-     */
176
-    private static function _verify_class_not_exist($classname)
177
-    {
178
-        // loop through the existing registry and see if the classname is already present.
179
-        foreach (self::$_registry as $args) {
180
-            if ($args['classname'] == $classname) {
181
-                EE_Error::add_error(
182
-                    sprintf(
183
-                        esc_html__(
184
-                            'The %s template pack that you just activated cannot be registered with the messages system because there is already a template pack active using the same classname.  Contact the author of this template pack to let them know of the conflict.  To stop seeing this message you will need to deactivate this template pack.',
185
-                            'event_espresso'
186
-                        ),
187
-                        $classname
188
-                    ),
189
-                    __FILE__,
190
-                    __LINE__,
191
-                    __FUNCTION__
192
-                );
193
-                return false;
194
-            }
195
-        }
196
-        return true;
197
-    }
198
-
199
-
200
-    /**
201
-     * This deregisters a variation set that was previously registered with the given slug.
202
-     *
203
-     * @param string $identifier The name for the variation set that was previously registered.
204
-     *
205
-     * @return void
206
-     * @since 4.5.0
207
-     *
208
-     */
209
-    public static function deregister($identifier = '')
210
-    {
211
-        unset(self::$_registry[ $identifier ]);
212
-    }
15
+	/**
16
+	 * Holds values for registered template pack
17
+	 *
18
+	 * @since 4.5.0
19
+	 *
20
+	 * @var array
21
+	 */
22
+	protected static $_registry = [];
23
+
24
+
25
+	/**
26
+	 * Used to register a new template pack with the messages system.
27
+	 *
28
+	 * Template packs are primarily defined via class extending EE_Messages_Template_Pack and are typically used to
29
+	 * change entire layouts for a set of message templates.  This method is used to register the new template pack and
30
+	 * automatically have it loaded in the appropriate places.
31
+	 *
32
+	 * This registry also verifies that there isn't already a template pack registered with the same name and if there
33
+	 * is then it will add an EE_Error notice.
34
+	 *
35
+	 * Note that this only handles registering the your Template Pack class with the message template pack system.
36
+	 * However, there is also a naming schema you must follow for templates you are providing with your template pack.
37
+	 *
38
+	 * @param string $identifier The internal reference used to refer to this template pack.  Note, this is first come,
39
+	 *                           first serve.  If there is already a template pack registered with this name then the
40
+	 *                           registry will assign a unique reference for it so it can still be activated (but this
41
+	 *                           makes it harder to deregister as it will be unique per load - so its best to try to
42
+	 *                           make this a unique string!)
43
+	 * @param array  $setup_args array {
44
+	 *                           An array of required values for registering the template pack.
45
+	 * @type string  $path       The path for the new template pack class.
46
+	 * @type string  $classname  The name of the new Template Pack Class.
47
+	 *                           }
48
+	 *
49
+	 * @return void
50
+	 * @throws EE_Error
51
+	 *
52
+	 * @see    core/libraries/messages/defaults/default/* for all the example templates the default template pack
53
+	 *         supports.
54
+	 *
55
+	 *
56
+	 * @since  4.5.0
57
+	 * @see    EE_Messages_Template_Pack_Default for an example class
58
+	 */
59
+	public static function register($identifier = '', array $setup_args = [])
60
+	{
61
+
62
+		// check for required params
63
+		if (empty($identifier) || empty($setup_args['path']) || empty($setup_args['classname'])) {
64
+			throw new EE_Error(
65
+				esc_html__(
66
+					'In order to register a new template pack for the EE Messages system, you must include a value to reference the template pack being registered and the setup_args must have the path for the new template pack class as well as the classname for the new Template Pack Class. ',
67
+					'event_espresso'
68
+				)
69
+			);
70
+		}
71
+
72
+		// make sure we don't register twice
73
+		if (isset(self::$_registry[ $identifier ])) {
74
+			return;
75
+		}
76
+
77
+		// check that incoming $identifier doesn't already exist. If it does then we'll create a unique reference for this template pack.
78
+		if (isset(self::$_registry[ $identifier ])) {
79
+			$identifier = uniqid() . '_' . $identifier;
80
+		}
81
+
82
+
83
+		// make sure this was called in the right place!
84
+		if (
85
+			! did_action('EE_Brewing_Regular___messages_caf')
86
+			|| did_action('AHEE__EE_System__perform_activations_upgrades_and_migrations')
87
+		) {
88
+			EE_Error::doing_it_wrong(
89
+				__METHOD__,
90
+				sprintf(
91
+					esc_html__(
92
+						'A EE Messages Template Pack given the reference "%s" has been attempted to be registered with the EE Messages System.  It may or may not work because it should be only called on the "EE_Brewing_Regular__messages_caf" hook.',
93
+						'event_espresso'
94
+					),
95
+					$identifier
96
+				),
97
+				'4.5.0'
98
+			);
99
+		}
100
+
101
+		if (self::_verify_class_not_exist($setup_args['classname'])) {
102
+			self::$_registry[ $identifier ] = [
103
+				'path'      => (string) $setup_args['path'],
104
+				'classname' => (string) $setup_args['classname'],
105
+			];
106
+		}
107
+
108
+		// hook into the system
109
+		add_filter(
110
+			'FHEE__EED_Messages___set_messages_paths___MSG_PATHS',
111
+			['EE_Register_Messages_Template_Pack', 'set_template_pack_path'],
112
+			10
113
+		);
114
+		add_filter(
115
+			'FHEE__EED_Messages__get_template_packs__template_packs',
116
+			['EE_Register_Messages_Template_Pack', 'set_template_pack'],
117
+			10
118
+		);
119
+	}
120
+
121
+
122
+	/**
123
+	 * Callback for the FHEE__EED_Messages___set_messages_paths___MSG_PATHS filter.  This adds this template packs path
124
+	 * to the messages autoloader paths.
125
+	 *
126
+	 * @param array $paths Array of paths already registered with the messages autoloader
127
+	 *
128
+	 * @return array
129
+	 * @since  4.5.0
130
+	 *
131
+	 */
132
+	public static function set_template_pack_path(array $paths)
133
+	{
134
+		foreach (self::$_registry as $args) {
135
+			$paths[] = $args['path'];
136
+		}
137
+		return $paths;
138
+	}
139
+
140
+
141
+	/**
142
+	 * Callback for the FHEE__EED_Messages__get_template_packs__template_packs filter. This adds the instantiated,
143
+	 * registered template pack to the template packs array when requested by client code.
144
+	 *
145
+	 * @param EE_Messages_Template_Pack[] $template_packs
146
+	 * @return EE_Messages_Template_Pack[]
147
+	 * @since 4.5.0
148
+	 *
149
+	 */
150
+	public static function set_template_pack(array $template_packs)
151
+	{
152
+		foreach (self::$_registry as $args) {
153
+			// verify class_exists
154
+			if (! class_exists($args['classname'])) {
155
+				require_once($args['path'] . '/' . $args['classname'] . '.class.php');
156
+			}
157
+
158
+			// check again!
159
+			if (class_exists($args['classname'])) {
160
+				$template_pack                           = new $args['classname']();
161
+				$template_packs[ $template_pack->dbref ] = $template_pack;
162
+			}
163
+		}
164
+
165
+		return $template_packs;
166
+	}
167
+
168
+
169
+	/**
170
+	 * This verifies that the classes for each registered template pack are unique  names.
171
+	 *
172
+	 * @param string $classname The classname being checked
173
+	 *
174
+	 * @return bool
175
+	 */
176
+	private static function _verify_class_not_exist($classname)
177
+	{
178
+		// loop through the existing registry and see if the classname is already present.
179
+		foreach (self::$_registry as $args) {
180
+			if ($args['classname'] == $classname) {
181
+				EE_Error::add_error(
182
+					sprintf(
183
+						esc_html__(
184
+							'The %s template pack that you just activated cannot be registered with the messages system because there is already a template pack active using the same classname.  Contact the author of this template pack to let them know of the conflict.  To stop seeing this message you will need to deactivate this template pack.',
185
+							'event_espresso'
186
+						),
187
+						$classname
188
+					),
189
+					__FILE__,
190
+					__LINE__,
191
+					__FUNCTION__
192
+				);
193
+				return false;
194
+			}
195
+		}
196
+		return true;
197
+	}
198
+
199
+
200
+	/**
201
+	 * This deregisters a variation set that was previously registered with the given slug.
202
+	 *
203
+	 * @param string $identifier The name for the variation set that was previously registered.
204
+	 *
205
+	 * @return void
206
+	 * @since 4.5.0
207
+	 *
208
+	 */
209
+	public static function deregister($identifier = '')
210
+	{
211
+		unset(self::$_registry[ $identifier ]);
212
+	}
213 213
 }
Please login to merge, or discard this patch.
core/libraries/plugin_api/EE_Register_Message_Type.lib.php 2 patches
Spacing   +7 added lines, -7 removed lines patch added patch discarded remove patch
@@ -60,7 +60,7 @@  discard block
 block discarded – undo
60 60
         }
61 61
 
62 62
         // make sure we don't register twice
63
-        if (isset(self::$_ee_message_type_registry[ $identifier ])) {
63
+        if (isset(self::$_ee_message_type_registry[$identifier])) {
64 64
             return;
65 65
         }
66 66
 
@@ -82,7 +82,7 @@  discard block
 block discarded – undo
82 82
             );
83 83
         }
84 84
         // setup $__ee_message_type_registry array from incoming values.
85
-        self::$_ee_message_type_registry[ $identifier ] = [
85
+        self::$_ee_message_type_registry[$identifier] = [
86 86
             /**
87 87
              * The file name for the message type being registered.
88 88
              * Required.
@@ -265,7 +265,7 @@  discard block
 block discarded – undo
265 265
      */
266 266
     public static function deregister($identifier = '')
267 267
     {
268
-        if (! empty(self::$_ee_message_type_registry[ $identifier ])) {
268
+        if ( ! empty(self::$_ee_message_type_registry[$identifier])) {
269 269
             // let's make sure that we remove any place this message type was made active
270 270
             /** @var EE_Message_Resource_Manager $Message_Resource_Manager */
271 271
             $Message_Resource_Manager = EE_Registry::instance()->load_lib('Message_Resource_Manager');
@@ -277,7 +277,7 @@  discard block
 block discarded – undo
277 277
             );
278 278
             $Message_Resource_Manager->deactivate_message_type($identifier, false);
279 279
         }
280
-        unset(self::$_ee_message_type_registry[ $identifier ]);
280
+        unset(self::$_ee_message_type_registry[$identifier]);
281 281
     }
282 282
 
283 283
 
@@ -312,7 +312,7 @@  discard block
 block discarded – undo
312 312
      */
313 313
     public static function register_msgs_autoload_paths(array $paths)
314 314
     {
315
-        if (! empty(self::$_ee_message_type_registry)) {
315
+        if ( ! empty(self::$_ee_message_type_registry)) {
316 316
             foreach (self::$_ee_message_type_registry as $mt_reg) {
317 317
                 if (empty($mt_reg['autoloadpaths'])) {
318 318
                     continue;
@@ -401,7 +401,7 @@  discard block
 block discarded – undo
401 401
                 continue;
402 402
             }
403 403
             foreach ($mt_reg['messengers_supporting_default_template_pack_with'] as $messenger_slug) {
404
-                $supports[ $messenger_slug ][] = $identifier;
404
+                $supports[$messenger_slug][] = $identifier;
405 405
             }
406 406
         }
407 407
         return $supports;
@@ -473,7 +473,7 @@  discard block
 block discarded – undo
473 473
         $file_extension,
474 474
         EE_Messages_Template_Pack $template_pack
475 475
     ) {
476
-        if (! $template_pack instanceof EE_Messages_Template_Pack_Default) {
476
+        if ( ! $template_pack instanceof EE_Messages_Template_Pack_Default) {
477 477
             return $base_path_or_url;
478 478
         }
479 479
         foreach (self::$_ee_message_type_registry as $identifier => $mt_reg) {
Please login to merge, or discard this patch.
Indentation   +457 added lines, -457 removed lines patch added patch discarded remove patch
@@ -12,487 +12,487 @@
 block discarded – undo
12 12
 {
13 13
 
14 14
 
15
-    /**
16
-     * Holds values for registered message types
17
-     *
18
-     * @var array
19
-     */
20
-    protected static $_ee_message_type_registry = [];
15
+	/**
16
+	 * Holds values for registered message types
17
+	 *
18
+	 * @var array
19
+	 */
20
+	protected static $_ee_message_type_registry = [];
21 21
 
22 22
 
23
-    /**
24
-     * Method for registering new message types in the EE_messages system.
25
-     * Note:  All message types must have the following files in order to work:
26
-     * Template files for default templates getting setup.
27
-     * See /core/libraries/messages/defaults/default/ for examples
28
-     * (note that template files match a specific naming schema).
29
-     * These templates will need to be registered with the default template pack.
30
-     * - EE_Messages_Validator extended class(es).  See /core/libraries/messages/validators/email/
31
-     *      for examples.  Note for any new message types, there will need to be a validator for each
32
-     *      messenger combo this message type can activate with.
33
-     * - And of course the main EE_{Message_Type_Name}_message_type class that defines the new
34
-     *      message type and its properties.
35
-     *
36
-     * @param string $identifier    Whatever is defined for the $name property of
37
-     *                              the message type you are registering (eg.
38
-     *                              declined_registration). Required.
39
-     * @param array  $setup_args    An array of arguments provided for registering the message type.
40
-     * @throws EE_Error
41
-     *                              }
42
-     * @see      inline docs in the register method for what can be passed in as arguments.
43
-     * @since    4.3.0
44
-     */
45
-    public static function register($identifier = '', array $setup_args = [])
46
-    {
47
-        // required fields MUST be present, so let's make sure they are.
48
-        if (
49
-            ! isset($identifier)
50
-            || ! is_array($setup_args)
51
-            || empty($setup_args['mtfilename'])
52
-            || empty($setup_args['autoloadpaths'])
53
-        ) {
54
-            throw new EE_Error(
55
-                esc_html__(
56
-                    'In order to register a message type with EE_Register_Message_Type::register, you must include a unique name for the message type, plus an array containing the following keys: "mtfilename", "autoloadpaths"',
57
-                    'event_espresso'
58
-                )
59
-            );
60
-        }
23
+	/**
24
+	 * Method for registering new message types in the EE_messages system.
25
+	 * Note:  All message types must have the following files in order to work:
26
+	 * Template files for default templates getting setup.
27
+	 * See /core/libraries/messages/defaults/default/ for examples
28
+	 * (note that template files match a specific naming schema).
29
+	 * These templates will need to be registered with the default template pack.
30
+	 * - EE_Messages_Validator extended class(es).  See /core/libraries/messages/validators/email/
31
+	 *      for examples.  Note for any new message types, there will need to be a validator for each
32
+	 *      messenger combo this message type can activate with.
33
+	 * - And of course the main EE_{Message_Type_Name}_message_type class that defines the new
34
+	 *      message type and its properties.
35
+	 *
36
+	 * @param string $identifier    Whatever is defined for the $name property of
37
+	 *                              the message type you are registering (eg.
38
+	 *                              declined_registration). Required.
39
+	 * @param array  $setup_args    An array of arguments provided for registering the message type.
40
+	 * @throws EE_Error
41
+	 *                              }
42
+	 * @see      inline docs in the register method for what can be passed in as arguments.
43
+	 * @since    4.3.0
44
+	 */
45
+	public static function register($identifier = '', array $setup_args = [])
46
+	{
47
+		// required fields MUST be present, so let's make sure they are.
48
+		if (
49
+			! isset($identifier)
50
+			|| ! is_array($setup_args)
51
+			|| empty($setup_args['mtfilename'])
52
+			|| empty($setup_args['autoloadpaths'])
53
+		) {
54
+			throw new EE_Error(
55
+				esc_html__(
56
+					'In order to register a message type with EE_Register_Message_Type::register, you must include a unique name for the message type, plus an array containing the following keys: "mtfilename", "autoloadpaths"',
57
+					'event_espresso'
58
+				)
59
+			);
60
+		}
61 61
 
62
-        // make sure we don't register twice
63
-        if (isset(self::$_ee_message_type_registry[ $identifier ])) {
64
-            return;
65
-        }
62
+		// make sure we don't register twice
63
+		if (isset(self::$_ee_message_type_registry[ $identifier ])) {
64
+			return;
65
+		}
66 66
 
67
-        // make sure this was called in the right place!
68
-        if (
69
-            ! did_action('EE_Brewing_Regular___messages_caf')
70
-            || did_action('AHEE__EE_System__perform_activations_upgrades_and_migrations')
71
-        ) {
72
-            EE_Error::doing_it_wrong(
73
-                __METHOD__,
74
-                sprintf(
75
-                    esc_html__(
76
-                        'A message type named "%s" has been attempted to be registered with the EE Messages System.  It may or may not work because it should be only called on the "EE_Brewing_Regular___messages_caf" hook.',
77
-                        'event_espresso'
78
-                    ),
79
-                    $identifier
80
-                ),
81
-                '4.3.0'
82
-            );
83
-        }
84
-        // setup $__ee_message_type_registry array from incoming values.
85
-        self::$_ee_message_type_registry[ $identifier ] = [
86
-            /**
87
-             * The file name for the message type being registered.
88
-             * Required.
89
-             *
90
-             * @type string
91
-             */
92
-            'mtfilename'                                       => (string) $setup_args['mtfilename'],
93
-            /**
94
-             * Autoload paths for classes used by the message type.
95
-             * Required.
96
-             *
97
-             * @type array
98
-             */
99
-            'autoloadpaths'                                    => (array) $setup_args['autoloadpaths'],
100
-            /**
101
-             * Messengers that the message type should be able to activate with.
102
-             * Use messenger slugs.
103
-             *
104
-             * @type array
105
-             */
106
-            'messengers_to_activate_with'                      => ! empty($setup_args['messengers_to_activate_with'])
107
-                ? (array) $setup_args['messengers_to_activate_with']
108
-                : [],
109
-            /**
110
-             * Messengers that the message type should validate with.
111
-             * Use messenger slugs.
112
-             *
113
-             * @type array
114
-             */
115
-            'messengers_to_validate_with'                      => ! empty($setup_args['messengers_to_validate_with'])
116
-                ? (array) $setup_args['messengers_to_validate_with']
117
-                : [],
118
-            /**
119
-             * Whether to force activate this message type the first time it is registered.
120
-             *
121
-             * @type bool   False means its not activated by default and left up to the end user to activate.
122
-             */
123
-            'force_activation'                                 => ! empty($setup_args['force_activation'])
124
-                                                                  && $setup_args['force_activation'],
125
-            /**
126
-             * What messengers this message type supports the default template pack for.
127
-             * Note: If you do not set this (or any of the following template pack/variation related arguments) to true,
128
-             * then it is expected that the message type being registered is doing its own custom default template
129
-             * pack/variation registration.
130
-             *
131
-             * If this is set and has values, then it is expected that the following arguments are also set in the incoming options
132
-             * $setup_arguments array as well:
133
-             * - 'base_path_for_default_templates'
134
-             *
135
-             * @type array   Expect an array of messengers this supports default template packs for.
136
-             */
137
-            'messengers_supporting_default_template_pack_with' => isset($setup_args['messengers_supporting_default_template_pack_with'])
138
-                ? (array) $setup_args['messengers_supporting_default_template_pack_with']
139
-                : [],
140
-            /**
141
-             * The base path where the default templates for this message type can be found.
142
-             *
143
-             * @type string
144
-             */
145
-            'base_path_for_default_templates'                  => isset($setup_args['base_path_for_default_templates'])
146
-                ? $setup_args['base_path_for_default_templates'] : '',
147
-            /**
148
-             * The base path where the default variations for this message type can be found.
149
-             *
150
-             * @type string
151
-             */
152
-            'base_path_for_default_variation'                  => isset($setup_args['base_path_for_default_variation'])
153
-                ? $setup_args['base_path_for_default_variation'] : '',
154
-            /**
155
-             * The base url for the default variations for this message type.
156
-             *
157
-             * @type string
158
-             */
159
-            'base_url_for_default_variation'                   => isset($setup_args['base_url_for_default_variation'])
160
-                ? $setup_args['base_url_for_default_variation'] : '',
161
-        ];
162
-        // add filters but only if they haven't already been set (these filters only need to be registered ONCE because
163
-        // the callback handles all registered message types.
164
-        if (
165
-            false === has_filter(
166
-                'FHEE__EED_Messages___set_messages_paths___MSG_PATHS',
167
-                ['EE_Register_Message_Type', 'register_msgs_autoload_paths']
168
-            )
169
-        ) {
170
-            add_filter(
171
-                'FHEE__EED_Messages___set_messages_paths___MSG_PATHS',
172
-                ['EE_Register_Message_Type', 'register_msgs_autoload_paths'],
173
-                10
174
-            );
175
-            add_filter(
176
-                'FHEE__EE_messages__get_installed__messagetype_files',
177
-                ['EE_Register_Message_Type', 'register_messagetype_files'],
178
-                10,
179
-                1
180
-            );
181
-            add_filter(
182
-                'FHEE__EE_messenger__get_default_message_types__default_types',
183
-                ['EE_Register_Message_Type', 'register_messengers_to_activate_mt_with'],
184
-                10,
185
-                2
186
-            );
187
-            add_filter(
188
-                'FHEE__EE_messenger__get_valid_message_types__valid_types',
189
-                ['EE_Register_Message_Type', 'register_messengers_to_validate_mt_with'],
190
-                10,
191
-                2
192
-            );
193
-            // actions
194
-            add_action(
195
-                'AHEE__EE_Addon__initialize_default_data__begin',
196
-                ['EE_Register_Message_Type', 'set_defaults']
197
-            );
67
+		// make sure this was called in the right place!
68
+		if (
69
+			! did_action('EE_Brewing_Regular___messages_caf')
70
+			|| did_action('AHEE__EE_System__perform_activations_upgrades_and_migrations')
71
+		) {
72
+			EE_Error::doing_it_wrong(
73
+				__METHOD__,
74
+				sprintf(
75
+					esc_html__(
76
+						'A message type named "%s" has been attempted to be registered with the EE Messages System.  It may or may not work because it should be only called on the "EE_Brewing_Regular___messages_caf" hook.',
77
+						'event_espresso'
78
+					),
79
+					$identifier
80
+				),
81
+				'4.3.0'
82
+			);
83
+		}
84
+		// setup $__ee_message_type_registry array from incoming values.
85
+		self::$_ee_message_type_registry[ $identifier ] = [
86
+			/**
87
+			 * The file name for the message type being registered.
88
+			 * Required.
89
+			 *
90
+			 * @type string
91
+			 */
92
+			'mtfilename'                                       => (string) $setup_args['mtfilename'],
93
+			/**
94
+			 * Autoload paths for classes used by the message type.
95
+			 * Required.
96
+			 *
97
+			 * @type array
98
+			 */
99
+			'autoloadpaths'                                    => (array) $setup_args['autoloadpaths'],
100
+			/**
101
+			 * Messengers that the message type should be able to activate with.
102
+			 * Use messenger slugs.
103
+			 *
104
+			 * @type array
105
+			 */
106
+			'messengers_to_activate_with'                      => ! empty($setup_args['messengers_to_activate_with'])
107
+				? (array) $setup_args['messengers_to_activate_with']
108
+				: [],
109
+			/**
110
+			 * Messengers that the message type should validate with.
111
+			 * Use messenger slugs.
112
+			 *
113
+			 * @type array
114
+			 */
115
+			'messengers_to_validate_with'                      => ! empty($setup_args['messengers_to_validate_with'])
116
+				? (array) $setup_args['messengers_to_validate_with']
117
+				: [],
118
+			/**
119
+			 * Whether to force activate this message type the first time it is registered.
120
+			 *
121
+			 * @type bool   False means its not activated by default and left up to the end user to activate.
122
+			 */
123
+			'force_activation'                                 => ! empty($setup_args['force_activation'])
124
+																  && $setup_args['force_activation'],
125
+			/**
126
+			 * What messengers this message type supports the default template pack for.
127
+			 * Note: If you do not set this (or any of the following template pack/variation related arguments) to true,
128
+			 * then it is expected that the message type being registered is doing its own custom default template
129
+			 * pack/variation registration.
130
+			 *
131
+			 * If this is set and has values, then it is expected that the following arguments are also set in the incoming options
132
+			 * $setup_arguments array as well:
133
+			 * - 'base_path_for_default_templates'
134
+			 *
135
+			 * @type array   Expect an array of messengers this supports default template packs for.
136
+			 */
137
+			'messengers_supporting_default_template_pack_with' => isset($setup_args['messengers_supporting_default_template_pack_with'])
138
+				? (array) $setup_args['messengers_supporting_default_template_pack_with']
139
+				: [],
140
+			/**
141
+			 * The base path where the default templates for this message type can be found.
142
+			 *
143
+			 * @type string
144
+			 */
145
+			'base_path_for_default_templates'                  => isset($setup_args['base_path_for_default_templates'])
146
+				? $setup_args['base_path_for_default_templates'] : '',
147
+			/**
148
+			 * The base path where the default variations for this message type can be found.
149
+			 *
150
+			 * @type string
151
+			 */
152
+			'base_path_for_default_variation'                  => isset($setup_args['base_path_for_default_variation'])
153
+				? $setup_args['base_path_for_default_variation'] : '',
154
+			/**
155
+			 * The base url for the default variations for this message type.
156
+			 *
157
+			 * @type string
158
+			 */
159
+			'base_url_for_default_variation'                   => isset($setup_args['base_url_for_default_variation'])
160
+				? $setup_args['base_url_for_default_variation'] : '',
161
+		];
162
+		// add filters but only if they haven't already been set (these filters only need to be registered ONCE because
163
+		// the callback handles all registered message types.
164
+		if (
165
+			false === has_filter(
166
+				'FHEE__EED_Messages___set_messages_paths___MSG_PATHS',
167
+				['EE_Register_Message_Type', 'register_msgs_autoload_paths']
168
+			)
169
+		) {
170
+			add_filter(
171
+				'FHEE__EED_Messages___set_messages_paths___MSG_PATHS',
172
+				['EE_Register_Message_Type', 'register_msgs_autoload_paths'],
173
+				10
174
+			);
175
+			add_filter(
176
+				'FHEE__EE_messages__get_installed__messagetype_files',
177
+				['EE_Register_Message_Type', 'register_messagetype_files'],
178
+				10,
179
+				1
180
+			);
181
+			add_filter(
182
+				'FHEE__EE_messenger__get_default_message_types__default_types',
183
+				['EE_Register_Message_Type', 'register_messengers_to_activate_mt_with'],
184
+				10,
185
+				2
186
+			);
187
+			add_filter(
188
+				'FHEE__EE_messenger__get_valid_message_types__valid_types',
189
+				['EE_Register_Message_Type', 'register_messengers_to_validate_mt_with'],
190
+				10,
191
+				2
192
+			);
193
+			// actions
194
+			add_action(
195
+				'AHEE__EE_Addon__initialize_default_data__begin',
196
+				['EE_Register_Message_Type', 'set_defaults']
197
+			);
198 198
 
199
-            // default template packs and variations related
200
-            add_filter(
201
-                'FHEE__EE_Messages_Template_Pack_Default__get_supports',
202
-                ['EE_Register_Message_Type', 'register_default_template_pack_supports']
203
-            );
204
-            add_filter(
205
-                'FHEE__EE_Template_Pack___get_specific_template__filtered_base_path',
206
-                ['EE_Register_Message_Type', 'register_base_template_path'],
207
-                10,
208
-                6
209
-            );
210
-            add_filter(
211
-                'FHEE__EE_Messages_Template_Pack__get_variation__base_path_or_url',
212
-                ['EE_Register_Message_Type', 'register_variation_base_path_or_url'],
213
-                10,
214
-                8
215
-            );
216
-            add_filter(
217
-                'FHEE__EE_Messages_Template_Pack__get_variation__base_path',
218
-                ['EE_Register_Message_Type', 'register_variation_base_path_or_url'],
219
-                10,
220
-                8
221
-            );
222
-        }
223
-    }
199
+			// default template packs and variations related
200
+			add_filter(
201
+				'FHEE__EE_Messages_Template_Pack_Default__get_supports',
202
+				['EE_Register_Message_Type', 'register_default_template_pack_supports']
203
+			);
204
+			add_filter(
205
+				'FHEE__EE_Template_Pack___get_specific_template__filtered_base_path',
206
+				['EE_Register_Message_Type', 'register_base_template_path'],
207
+				10,
208
+				6
209
+			);
210
+			add_filter(
211
+				'FHEE__EE_Messages_Template_Pack__get_variation__base_path_or_url',
212
+				['EE_Register_Message_Type', 'register_variation_base_path_or_url'],
213
+				10,
214
+				8
215
+			);
216
+			add_filter(
217
+				'FHEE__EE_Messages_Template_Pack__get_variation__base_path',
218
+				['EE_Register_Message_Type', 'register_variation_base_path_or_url'],
219
+				10,
220
+				8
221
+			);
222
+		}
223
+	}
224 224
 
225 225
 
226
-    /**
227
-     * This just ensures that when an addon registers a message type that on initial activation/reactivation the
228
-     * defaults the addon sets are taken care of.
229
-     *
230
-     * @throws EE_Error
231
-     * @throws ReflectionException
232
-     */
233
-    public static function set_defaults()
234
-    {
235
-        /** @type EE_Message_Resource_Manager $message_resource_manager */
236
-        $message_resource_manager = EE_Registry::instance()->load_lib('Message_Resource_Manager');
226
+	/**
227
+	 * This just ensures that when an addon registers a message type that on initial activation/reactivation the
228
+	 * defaults the addon sets are taken care of.
229
+	 *
230
+	 * @throws EE_Error
231
+	 * @throws ReflectionException
232
+	 */
233
+	public static function set_defaults()
234
+	{
235
+		/** @type EE_Message_Resource_Manager $message_resource_manager */
236
+		$message_resource_manager = EE_Registry::instance()->load_lib('Message_Resource_Manager');
237 237
 
238
-        // for any message types with force activation, let's ensure they are activated
239
-        foreach (self::$_ee_message_type_registry as $identifier => $settings) {
240
-            if ($settings['force_activation']) {
241
-                foreach ($settings['messengers_to_activate_with'] as $messenger) {
242
-                    // DO not force activation if this message type has already been activated in the system
243
-                    if (
244
-                        ! $message_resource_manager->has_message_type_been_activated_for_messenger(
245
-                            $identifier,
246
-                            $messenger
247
-                        )
248
-                    ) {
249
-                        $message_resource_manager->ensure_message_type_is_active($identifier, $messenger);
250
-                    }
251
-                }
252
-            }
253
-        }
254
-    }
238
+		// for any message types with force activation, let's ensure they are activated
239
+		foreach (self::$_ee_message_type_registry as $identifier => $settings) {
240
+			if ($settings['force_activation']) {
241
+				foreach ($settings['messengers_to_activate_with'] as $messenger) {
242
+					// DO not force activation if this message type has already been activated in the system
243
+					if (
244
+						! $message_resource_manager->has_message_type_been_activated_for_messenger(
245
+							$identifier,
246
+							$messenger
247
+						)
248
+					) {
249
+						$message_resource_manager->ensure_message_type_is_active($identifier, $messenger);
250
+					}
251
+				}
252
+			}
253
+		}
254
+	}
255 255
 
256 256
 
257
-    /**
258
-     * This deregisters a message type that was previously registered with a specific message_type_name.
259
-     *
260
-     * @param string $identifier the name for the message type that was previously registered
261
-     * @return void
262
-     * @throws EE_Error
263
-     * @throws ReflectionException
264
-     * @since    4.3.0
265
-     */
266
-    public static function deregister($identifier = '')
267
-    {
268
-        if (! empty(self::$_ee_message_type_registry[ $identifier ])) {
269
-            // let's make sure that we remove any place this message type was made active
270
-            /** @var EE_Message_Resource_Manager $Message_Resource_Manager */
271
-            $Message_Resource_Manager = EE_Registry::instance()->load_lib('Message_Resource_Manager');
272
-            // ensures that if this message type is registered again that it retains its previous active state vs
273
-            // remaining inactive.
274
-            $Message_Resource_Manager->remove_message_type_has_been_activated_from_all_messengers(
275
-                $identifier,
276
-                true
277
-            );
278
-            $Message_Resource_Manager->deactivate_message_type($identifier, false);
279
-        }
280
-        unset(self::$_ee_message_type_registry[ $identifier ]);
281
-    }
257
+	/**
258
+	 * This deregisters a message type that was previously registered with a specific message_type_name.
259
+	 *
260
+	 * @param string $identifier the name for the message type that was previously registered
261
+	 * @return void
262
+	 * @throws EE_Error
263
+	 * @throws ReflectionException
264
+	 * @since    4.3.0
265
+	 */
266
+	public static function deregister($identifier = '')
267
+	{
268
+		if (! empty(self::$_ee_message_type_registry[ $identifier ])) {
269
+			// let's make sure that we remove any place this message type was made active
270
+			/** @var EE_Message_Resource_Manager $Message_Resource_Manager */
271
+			$Message_Resource_Manager = EE_Registry::instance()->load_lib('Message_Resource_Manager');
272
+			// ensures that if this message type is registered again that it retains its previous active state vs
273
+			// remaining inactive.
274
+			$Message_Resource_Manager->remove_message_type_has_been_activated_from_all_messengers(
275
+				$identifier,
276
+				true
277
+			);
278
+			$Message_Resource_Manager->deactivate_message_type($identifier, false);
279
+		}
280
+		unset(self::$_ee_message_type_registry[ $identifier ]);
281
+	}
282 282
 
283 283
 
284
-    /**
285
-     * callback for FHEE__EE_messages__get_installed__messagetype_files filter.
286
-     *
287
-     * @param array $messagetype_files The current array of message type file names
288
-     * @return  array                                 Array of message type file names
289
-     * @since   4.3.0
290
-     */
291
-    public static function register_messagetype_files(array $messagetype_files)
292
-    {
293
-        if (empty(self::$_ee_message_type_registry)) {
294
-            return $messagetype_files;
295
-        }
296
-        foreach (self::$_ee_message_type_registry as $mt_reg) {
297
-            if (empty($mt_reg['mtfilename'])) {
298
-                continue;
299
-            }
300
-            $messagetype_files[] = $mt_reg['mtfilename'];
301
-        }
302
-        return $messagetype_files;
303
-    }
284
+	/**
285
+	 * callback for FHEE__EE_messages__get_installed__messagetype_files filter.
286
+	 *
287
+	 * @param array $messagetype_files The current array of message type file names
288
+	 * @return  array                                 Array of message type file names
289
+	 * @since   4.3.0
290
+	 */
291
+	public static function register_messagetype_files(array $messagetype_files)
292
+	{
293
+		if (empty(self::$_ee_message_type_registry)) {
294
+			return $messagetype_files;
295
+		}
296
+		foreach (self::$_ee_message_type_registry as $mt_reg) {
297
+			if (empty($mt_reg['mtfilename'])) {
298
+				continue;
299
+			}
300
+			$messagetype_files[] = $mt_reg['mtfilename'];
301
+		}
302
+		return $messagetype_files;
303
+	}
304 304
 
305 305
 
306
-    /**
307
-     * callback for FHEE__EED_Messages___set_messages_paths___MSG_PATHS filter.
308
-     *
309
-     * @param array $paths array of paths to be checked by EE_messages autoloader.
310
-     * @return array
311
-     * @since    4.3.0
312
-     */
313
-    public static function register_msgs_autoload_paths(array $paths)
314
-    {
315
-        if (! empty(self::$_ee_message_type_registry)) {
316
-            foreach (self::$_ee_message_type_registry as $mt_reg) {
317
-                if (empty($mt_reg['autoloadpaths'])) {
318
-                    continue;
319
-                }
320
-                $paths = array_merge($paths, $mt_reg['autoloadpaths']);
321
-            }
322
-        }
323
-        return $paths;
324
-    }
306
+	/**
307
+	 * callback for FHEE__EED_Messages___set_messages_paths___MSG_PATHS filter.
308
+	 *
309
+	 * @param array $paths array of paths to be checked by EE_messages autoloader.
310
+	 * @return array
311
+	 * @since    4.3.0
312
+	 */
313
+	public static function register_msgs_autoload_paths(array $paths)
314
+	{
315
+		if (! empty(self::$_ee_message_type_registry)) {
316
+			foreach (self::$_ee_message_type_registry as $mt_reg) {
317
+				if (empty($mt_reg['autoloadpaths'])) {
318
+					continue;
319
+				}
320
+				$paths = array_merge($paths, $mt_reg['autoloadpaths']);
321
+			}
322
+		}
323
+		return $paths;
324
+	}
325 325
 
326 326
 
327
-    /**
328
-     * callback for FHEE__EE_messenger__get_default_message_types__default_types filter.
329
-     *
330
-     * @param array        $default_types   array of message types activated with messenger (
331
-     *                                      corresponds to the $name property of message type)
332
-     * @param EE_messenger $messenger       The EE_messenger the filter is called from.
333
-     * @return array
334
-     * @since  4.3.0
335
-     */
336
-    public static function register_messengers_to_activate_mt_with(array $default_types, EE_messenger $messenger)
337
-    {
338
-        if (empty(self::$_ee_message_type_registry)) {
339
-            return $default_types;
340
-        }
341
-        foreach (self::$_ee_message_type_registry as $identifier => $mt_reg) {
342
-            if (empty($mt_reg['messengers_to_activate_with']) || empty($mt_reg['mtfilename'])) {
343
-                continue;
344
-            }
345
-            // loop through each of the messengers and if it matches the loaded class
346
-            // then we add this message type to the
347
-            foreach ($mt_reg['messengers_to_activate_with'] as $msgr) {
348
-                if ($messenger->name == $msgr) {
349
-                    $default_types[] = $identifier;
350
-                }
351
-            }
352
-        }
327
+	/**
328
+	 * callback for FHEE__EE_messenger__get_default_message_types__default_types filter.
329
+	 *
330
+	 * @param array        $default_types   array of message types activated with messenger (
331
+	 *                                      corresponds to the $name property of message type)
332
+	 * @param EE_messenger $messenger       The EE_messenger the filter is called from.
333
+	 * @return array
334
+	 * @since  4.3.0
335
+	 */
336
+	public static function register_messengers_to_activate_mt_with(array $default_types, EE_messenger $messenger)
337
+	{
338
+		if (empty(self::$_ee_message_type_registry)) {
339
+			return $default_types;
340
+		}
341
+		foreach (self::$_ee_message_type_registry as $identifier => $mt_reg) {
342
+			if (empty($mt_reg['messengers_to_activate_with']) || empty($mt_reg['mtfilename'])) {
343
+				continue;
344
+			}
345
+			// loop through each of the messengers and if it matches the loaded class
346
+			// then we add this message type to the
347
+			foreach ($mt_reg['messengers_to_activate_with'] as $msgr) {
348
+				if ($messenger->name == $msgr) {
349
+					$default_types[] = $identifier;
350
+				}
351
+			}
352
+		}
353 353
 
354
-        return $default_types;
355
-    }
354
+		return $default_types;
355
+	}
356 356
 
357 357
 
358
-    /**
359
-     * callback for FHEE__EE_messenger__get_valid_message_types__default_types filter.
360
-     *
361
-     * @param array        $valid_types     array of message types valid with messenger (
362
-     *                                      corresponds to the $name property of message type)
363
-     * @param EE_messenger $messenger       The EE_messenger the filter is called from.
364
-     * @return  array
365
-     * @since   4.3.0
366
-     */
367
-    public static function register_messengers_to_validate_mt_with(array $valid_types, EE_messenger $messenger)
368
-    {
369
-        if (empty(self::$_ee_message_type_registry)) {
370
-            return $valid_types;
371
-        }
372
-        foreach (self::$_ee_message_type_registry as $identifier => $mt_reg) {
373
-            if (empty($mt_reg['messengers_to_validate_with']) || empty($mt_reg['mtfilename'])) {
374
-                continue;
375
-            }
376
-            // loop through each of the messengers and if it matches the loaded class
377
-            // then we add this message type to the
378
-            foreach ($mt_reg['messengers_to_validate_with'] as $msgr) {
379
-                if ($messenger->name == $msgr) {
380
-                    $valid_types[] = $identifier;
381
-                }
382
-            }
383
-        }
358
+	/**
359
+	 * callback for FHEE__EE_messenger__get_valid_message_types__default_types filter.
360
+	 *
361
+	 * @param array        $valid_types     array of message types valid with messenger (
362
+	 *                                      corresponds to the $name property of message type)
363
+	 * @param EE_messenger $messenger       The EE_messenger the filter is called from.
364
+	 * @return  array
365
+	 * @since   4.3.0
366
+	 */
367
+	public static function register_messengers_to_validate_mt_with(array $valid_types, EE_messenger $messenger)
368
+	{
369
+		if (empty(self::$_ee_message_type_registry)) {
370
+			return $valid_types;
371
+		}
372
+		foreach (self::$_ee_message_type_registry as $identifier => $mt_reg) {
373
+			if (empty($mt_reg['messengers_to_validate_with']) || empty($mt_reg['mtfilename'])) {
374
+				continue;
375
+			}
376
+			// loop through each of the messengers and if it matches the loaded class
377
+			// then we add this message type to the
378
+			foreach ($mt_reg['messengers_to_validate_with'] as $msgr) {
379
+				if ($messenger->name == $msgr) {
380
+					$valid_types[] = $identifier;
381
+				}
382
+			}
383
+		}
384 384
 
385
-        return $valid_types;
386
-    }
385
+		return $valid_types;
386
+	}
387 387
 
388 388
 
389
-    /**
390
-     * Callback for `FHEE__EE_Messages_Template_Pack_Default__get_supports` filter to register this message type as
391
-     * supporting the default template pack
392
-     *
393
-     * @param array $supports
394
-     *
395
-     * @return array
396
-     */
397
-    public static function register_default_template_pack_supports(array $supports)
398
-    {
399
-        foreach (self::$_ee_message_type_registry as $identifier => $mt_reg) {
400
-            if (empty($mt_reg['messengers_supporting_default_template_pack_with'])) {
401
-                continue;
402
-            }
403
-            foreach ($mt_reg['messengers_supporting_default_template_pack_with'] as $messenger_slug) {
404
-                $supports[ $messenger_slug ][] = $identifier;
405
-            }
406
-        }
407
-        return $supports;
408
-    }
389
+	/**
390
+	 * Callback for `FHEE__EE_Messages_Template_Pack_Default__get_supports` filter to register this message type as
391
+	 * supporting the default template pack
392
+	 *
393
+	 * @param array $supports
394
+	 *
395
+	 * @return array
396
+	 */
397
+	public static function register_default_template_pack_supports(array $supports)
398
+	{
399
+		foreach (self::$_ee_message_type_registry as $identifier => $mt_reg) {
400
+			if (empty($mt_reg['messengers_supporting_default_template_pack_with'])) {
401
+				continue;
402
+			}
403
+			foreach ($mt_reg['messengers_supporting_default_template_pack_with'] as $messenger_slug) {
404
+				$supports[ $messenger_slug ][] = $identifier;
405
+			}
406
+		}
407
+		return $supports;
408
+	}
409 409
 
410 410
 
411
-    /**
412
-     * Callback for FHEE__EE_Template_Pack___get_specific_template__filtered_base_path
413
-     *
414
-     * @param string                    $base_path The original base path for message templates
415
-     * @param EE_messenger              $messenger
416
-     * @param EE_message_type           $message_type
417
-     * @param string                    $field     The field requesting a template
418
-     * @param string                    $context   The context requesting a template
419
-     * @param EE_Messages_Template_Pack $template_pack
420
-     *
421
-     * @return string
422
-     */
423
-    public static function register_base_template_path(
424
-        $base_path,
425
-        EE_messenger $messenger,
426
-        EE_message_type $message_type,
427
-        $field,
428
-        $context,
429
-        EE_Messages_Template_Pack $template_pack
430
-    ) {
431
-        if (
432
-            ! $template_pack instanceof EE_Messages_Template_Pack_Default
433
-            || ! $message_type instanceof EE_message_type
434
-        ) {
435
-            return $base_path;
436
-        }
437
-        foreach (self::$_ee_message_type_registry as $identifier => $mt_reg) {
438
-            if (
439
-                $message_type->name === $identifier
440
-                && ! empty($mt_reg['base_path_for_default_templates'])
441
-            ) {
442
-                return $mt_reg['base_path_for_default_templates'];
443
-            }
444
-        }
445
-        return $base_path;
446
-    }
411
+	/**
412
+	 * Callback for FHEE__EE_Template_Pack___get_specific_template__filtered_base_path
413
+	 *
414
+	 * @param string                    $base_path The original base path for message templates
415
+	 * @param EE_messenger              $messenger
416
+	 * @param EE_message_type           $message_type
417
+	 * @param string                    $field     The field requesting a template
418
+	 * @param string                    $context   The context requesting a template
419
+	 * @param EE_Messages_Template_Pack $template_pack
420
+	 *
421
+	 * @return string
422
+	 */
423
+	public static function register_base_template_path(
424
+		$base_path,
425
+		EE_messenger $messenger,
426
+		EE_message_type $message_type,
427
+		$field,
428
+		$context,
429
+		EE_Messages_Template_Pack $template_pack
430
+	) {
431
+		if (
432
+			! $template_pack instanceof EE_Messages_Template_Pack_Default
433
+			|| ! $message_type instanceof EE_message_type
434
+		) {
435
+			return $base_path;
436
+		}
437
+		foreach (self::$_ee_message_type_registry as $identifier => $mt_reg) {
438
+			if (
439
+				$message_type->name === $identifier
440
+				&& ! empty($mt_reg['base_path_for_default_templates'])
441
+			) {
442
+				return $mt_reg['base_path_for_default_templates'];
443
+			}
444
+		}
445
+		return $base_path;
446
+	}
447 447
 
448 448
 
449
-    /**
450
-     * Callback for FHEE__EE_Messages_Template_Pack__get_variation__base_path and
451
-     * FHEE__EE_Messages_Template_Pack__get_variation__base_path_or_url hooks
452
-     *
453
-     * @param string                    $base_path_or_url  The original incoming base url or path
454
-     * @param string                    $messenger_slug    The slug of the messenger the template is being generated
455
-     *                                                     for.
456
-     * @param string                    $message_type_slug The slug of the message type the template is being generated
457
-     *                                                     for.
458
-     * @param string                    $type              The "type" of css being requested.
459
-     * @param string                    $variation         The variation being requested.
460
-     * @param bool                      $url               whether a url or path is being requested.
461
-     * @param string                    $file_extension    What file extension is expected for the variation file.
462
-     * @param EE_Messages_Template_Pack $template_pack
463
-     *
464
-     * @return string
465
-     */
466
-    public static function register_variation_base_path_or_url(
467
-        $base_path_or_url,
468
-        $messenger_slug,
469
-        $message_type_slug,
470
-        $type,
471
-        $variation,
472
-        $url,
473
-        $file_extension,
474
-        EE_Messages_Template_Pack $template_pack
475
-    ) {
476
-        if (! $template_pack instanceof EE_Messages_Template_Pack_Default) {
477
-            return $base_path_or_url;
478
-        }
479
-        foreach (self::$_ee_message_type_registry as $identifier => $mt_reg) {
480
-            if (
481
-                $identifier === $message_type_slug
482
-            ) {
483
-                if (
484
-                    $url
485
-                    && ! empty($mt_reg['base_url_for_default_variation'])
486
-                ) {
487
-                    return $mt_reg['base_url_for_default_variation'];
488
-                } elseif (
489
-                    ! $url
490
-                          && ! empty($mt_reg['base_path_for_default_variation'])
491
-                ) {
492
-                    return $mt_reg['base_path_for_default_variation'];
493
-                }
494
-            }
495
-        }
496
-        return $base_path_or_url;
497
-    }
449
+	/**
450
+	 * Callback for FHEE__EE_Messages_Template_Pack__get_variation__base_path and
451
+	 * FHEE__EE_Messages_Template_Pack__get_variation__base_path_or_url hooks
452
+	 *
453
+	 * @param string                    $base_path_or_url  The original incoming base url or path
454
+	 * @param string                    $messenger_slug    The slug of the messenger the template is being generated
455
+	 *                                                     for.
456
+	 * @param string                    $message_type_slug The slug of the message type the template is being generated
457
+	 *                                                     for.
458
+	 * @param string                    $type              The "type" of css being requested.
459
+	 * @param string                    $variation         The variation being requested.
460
+	 * @param bool                      $url               whether a url or path is being requested.
461
+	 * @param string                    $file_extension    What file extension is expected for the variation file.
462
+	 * @param EE_Messages_Template_Pack $template_pack
463
+	 *
464
+	 * @return string
465
+	 */
466
+	public static function register_variation_base_path_or_url(
467
+		$base_path_or_url,
468
+		$messenger_slug,
469
+		$message_type_slug,
470
+		$type,
471
+		$variation,
472
+		$url,
473
+		$file_extension,
474
+		EE_Messages_Template_Pack $template_pack
475
+	) {
476
+		if (! $template_pack instanceof EE_Messages_Template_Pack_Default) {
477
+			return $base_path_or_url;
478
+		}
479
+		foreach (self::$_ee_message_type_registry as $identifier => $mt_reg) {
480
+			if (
481
+				$identifier === $message_type_slug
482
+			) {
483
+				if (
484
+					$url
485
+					&& ! empty($mt_reg['base_url_for_default_variation'])
486
+				) {
487
+					return $mt_reg['base_url_for_default_variation'];
488
+				} elseif (
489
+					! $url
490
+						  && ! empty($mt_reg['base_path_for_default_variation'])
491
+				) {
492
+					return $mt_reg['base_path_for_default_variation'];
493
+				}
494
+			}
495
+		}
496
+		return $base_path_or_url;
497
+	}
498 498
 }
Please login to merge, or discard this patch.
core/libraries/plugin_api/EE_Register_Module.lib.php 2 patches
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -48,7 +48,7 @@  discard block
 block discarded – undo
48 48
         }
49 49
 
50 50
         // make sure we don't register twice
51
-        if (isset(self::$_settings[ $identifier ])) {
51
+        if (isset(self::$_settings[$identifier])) {
52 52
             return;
53 53
         }
54 54
 
@@ -67,7 +67,7 @@  discard block
 block discarded – undo
67 67
             );
68 68
         }
69 69
         // setup $_settings array from incoming values.
70
-        self::$_settings[ $identifier ] = [
70
+        self::$_settings[$identifier] = [
71 71
             // array of full server paths to any EED_Modules used by the module
72 72
             'module_paths' => isset($setup_args['module_paths']) ? (array) $setup_args['module_paths'] : [],
73 73
         ];
@@ -105,6 +105,6 @@  discard block
 block discarded – undo
105 105
      */
106 106
     public static function deregister($identifier = '')
107 107
     {
108
-        unset(self::$_settings[ $identifier ]);
108
+        unset(self::$_settings[$identifier]);
109 109
     }
110 110
 }
Please login to merge, or discard this patch.
Indentation   +84 added lines, -84 removed lines patch added patch discarded remove patch
@@ -15,96 +15,96 @@
 block discarded – undo
15 15
 class EE_Register_Module implements EEI_Plugin_API
16 16
 {
17 17
 
18
-    /**
19
-     * Holds values for registered modules
20
-     *
21
-     * @var array
22
-     */
23
-    protected static $_settings = [];
18
+	/**
19
+	 * Holds values for registered modules
20
+	 *
21
+	 * @var array
22
+	 */
23
+	protected static $_settings = [];
24 24
 
25 25
 
26
-    /**
27
-     *    Method for registering new EED_Modules
28
-     *
29
-     * @param string $identifier a unique identifier for this set of modules Required.
30
-     * @param array  $setup_args an array of full server paths to folders containing any EED_Modules, or to the
31
-     *                           EED_Module files themselves Required.
32
-     * @type    array module_paths    an array of full server paths to folders containing any EED_Modules, or to the
33
-     *                           EED_Module files themselves
34
-     * @return void
35
-     * @throws EE_Error
36
-     * @since    4.3.0
37
-     */
38
-    public static function register($identifier = '', array $setup_args = [])
39
-    {
40
-        // required fields MUST be present, so let's make sure they are.
41
-        if (empty($identifier) || ! is_array($setup_args) || empty($setup_args['module_paths'])) {
42
-            throw new EE_Error(
43
-                esc_html__(
44
-                    'In order to register Modules with EE_Register_Module::register(), you must include a "module_id" (a unique identifier for this set of modules), and an array containing the following keys: "module_paths" (an array of full server paths to folders that contain modules, or to the module files themselves)',
45
-                    'event_espresso'
46
-                )
47
-            );
48
-        }
26
+	/**
27
+	 *    Method for registering new EED_Modules
28
+	 *
29
+	 * @param string $identifier a unique identifier for this set of modules Required.
30
+	 * @param array  $setup_args an array of full server paths to folders containing any EED_Modules, or to the
31
+	 *                           EED_Module files themselves Required.
32
+	 * @type    array module_paths    an array of full server paths to folders containing any EED_Modules, or to the
33
+	 *                           EED_Module files themselves
34
+	 * @return void
35
+	 * @throws EE_Error
36
+	 * @since    4.3.0
37
+	 */
38
+	public static function register($identifier = '', array $setup_args = [])
39
+	{
40
+		// required fields MUST be present, so let's make sure they are.
41
+		if (empty($identifier) || ! is_array($setup_args) || empty($setup_args['module_paths'])) {
42
+			throw new EE_Error(
43
+				esc_html__(
44
+					'In order to register Modules with EE_Register_Module::register(), you must include a "module_id" (a unique identifier for this set of modules), and an array containing the following keys: "module_paths" (an array of full server paths to folders that contain modules, or to the module files themselves)',
45
+					'event_espresso'
46
+				)
47
+			);
48
+		}
49 49
 
50
-        // make sure we don't register twice
51
-        if (isset(self::$_settings[ $identifier ])) {
52
-            return;
53
-        }
50
+		// make sure we don't register twice
51
+		if (isset(self::$_settings[ $identifier ])) {
52
+			return;
53
+		}
54 54
 
55
-        // make sure this was called in the right place!
56
-        if (
57
-            ! did_action('AHEE__EE_System__load_espresso_addons')
58
-            || did_action('AHEE__EE_System__register_shortcodes_modules_and_widgets')
59
-        ) {
60
-            EE_Error::doing_it_wrong(
61
-                __METHOD__,
62
-                esc_html__(
63
-                    'An attempt to register modules has failed because it was not registered at the correct time.  Please use the "AHEE__EE_System__register_shortcodes_modules_and_widgets" hook to register modules.',
64
-                    'event_espresso'
65
-                ),
66
-                '4.3.0'
67
-            );
68
-        }
69
-        // setup $_settings array from incoming values.
70
-        self::$_settings[ $identifier ] = [
71
-            // array of full server paths to any EED_Modules used by the module
72
-            'module_paths' => isset($setup_args['module_paths']) ? (array) $setup_args['module_paths'] : [],
73
-        ];
74
-        // add to list of modules to be registered
75
-        add_filter(
76
-            'FHEE__EE_Config__register_modules__modules_to_register',
77
-            ['EE_Register_Module', 'add_modules']
78
-        );
79
-    }
55
+		// make sure this was called in the right place!
56
+		if (
57
+			! did_action('AHEE__EE_System__load_espresso_addons')
58
+			|| did_action('AHEE__EE_System__register_shortcodes_modules_and_widgets')
59
+		) {
60
+			EE_Error::doing_it_wrong(
61
+				__METHOD__,
62
+				esc_html__(
63
+					'An attempt to register modules has failed because it was not registered at the correct time.  Please use the "AHEE__EE_System__register_shortcodes_modules_and_widgets" hook to register modules.',
64
+					'event_espresso'
65
+				),
66
+				'4.3.0'
67
+			);
68
+		}
69
+		// setup $_settings array from incoming values.
70
+		self::$_settings[ $identifier ] = [
71
+			// array of full server paths to any EED_Modules used by the module
72
+			'module_paths' => isset($setup_args['module_paths']) ? (array) $setup_args['module_paths'] : [],
73
+		];
74
+		// add to list of modules to be registered
75
+		add_filter(
76
+			'FHEE__EE_Config__register_modules__modules_to_register',
77
+			['EE_Register_Module', 'add_modules']
78
+		);
79
+	}
80 80
 
81 81
 
82
-    /**
83
-     * Filters the list of modules to add ours.
84
-     * and they're just full filepaths to FOLDERS containing a module class file. Eg.
85
-     * array('espresso_monkey'=>'/public_html/wonder-site/wp-content/plugins/ee4/shortcodes/espresso_monkey'...)
86
-     *
87
-     * @param array $modules_to_register array of paths to all modules that require registering
88
-     * @return array
89
-     */
90
-    public static function add_modules(array $modules_to_register)
91
-    {
92
-        foreach (self::$_settings as $settings) {
93
-            $modules_to_register = array_merge($modules_to_register, $settings['module_paths']);
94
-        }
95
-        return $modules_to_register;
96
-    }
82
+	/**
83
+	 * Filters the list of modules to add ours.
84
+	 * and they're just full filepaths to FOLDERS containing a module class file. Eg.
85
+	 * array('espresso_monkey'=>'/public_html/wonder-site/wp-content/plugins/ee4/shortcodes/espresso_monkey'...)
86
+	 *
87
+	 * @param array $modules_to_register array of paths to all modules that require registering
88
+	 * @return array
89
+	 */
90
+	public static function add_modules(array $modules_to_register)
91
+	{
92
+		foreach (self::$_settings as $settings) {
93
+			$modules_to_register = array_merge($modules_to_register, $settings['module_paths']);
94
+		}
95
+		return $modules_to_register;
96
+	}
97 97
 
98 98
 
99
-    /**
100
-     * This deregisters a module that was previously registered with a specific $identifier.
101
-     *
102
-     * @param string $identifier the name for the module that was previously registered
103
-     * @return void
104
-     * @since    4.3.0
105
-     */
106
-    public static function deregister($identifier = '')
107
-    {
108
-        unset(self::$_settings[ $identifier ]);
109
-    }
99
+	/**
100
+	 * This deregisters a module that was previously registered with a specific $identifier.
101
+	 *
102
+	 * @param string $identifier the name for the module that was previously registered
103
+	 * @return void
104
+	 * @since    4.3.0
105
+	 */
106
+	public static function deregister($identifier = '')
107
+	{
108
+		unset(self::$_settings[ $identifier ]);
109
+	}
110 110
 }
Please login to merge, or discard this patch.
core/libraries/plugin_api/EE_Register_Model.lib.php 2 patches
Spacing   +8 added lines, -8 removed lines patch added patch discarded remove patch
@@ -58,7 +58,7 @@  discard block
 block discarded – undo
58 58
         }
59 59
 
60 60
         // make sure we don't register twice
61
-        if (isset(self::$_model_registry[ $identifier ])) {
61
+        if (isset(self::$_model_registry[$identifier])) {
62 62
             return;
63 63
         }
64 64
 
@@ -79,11 +79,11 @@  discard block
 block discarded – undo
79 79
                 '4.5'
80 80
             );
81 81
         }
82
-        self::$_model_registry[ $identifier ] = $setup_args;
82
+        self::$_model_registry[$identifier] = $setup_args;
83 83
 
84 84
         if (
85 85
             (isset($setup_args['model_paths']) && ! isset($setup_args['class_paths']))
86
-            || (! isset($setup_args['model_paths']) && isset($setup_args['class_paths']))
86
+            || ( ! isset($setup_args['model_paths']) && isset($setup_args['class_paths']))
87 87
         ) {
88 88
             throw new EE_Error(
89 89
                 sprintf(
@@ -97,7 +97,7 @@  discard block
 block discarded – undo
97 97
         }
98 98
         if (isset($setup_args['model_paths'])) {
99 99
             // make sure they passed in an array
100
-            if (! is_array($setup_args['model_paths'])) {
100
+            if ( ! is_array($setup_args['model_paths'])) {
101 101
                 $setup_args['model_paths'] = [$setup_args['model_paths']];
102 102
             }
103 103
             // we want to add this as a model folder
@@ -106,9 +106,9 @@  discard block
 block discarded – undo
106 106
             EEH_Autoloader::register_autoloader($class_to_filepath_map);
107 107
             $model_name_to_classname_map = [];
108 108
             foreach (array_keys($class_to_filepath_map) as $classname) {
109
-                $model_name_to_classname_map[ str_replace("EEM_", "", $classname) ] = $classname;
109
+                $model_name_to_classname_map[str_replace("EEM_", "", $classname)] = $classname;
110 110
             }
111
-            self::$_model_name_to_classname_map[ $identifier ] = $model_name_to_classname_map;
111
+            self::$_model_name_to_classname_map[$identifier] = $model_name_to_classname_map;
112 112
             add_filter('FHEE__EE_System__parse_model_names', ['EE_Register_Model', 'add_addon_models']);
113 113
             add_filter(
114 114
                 'FHEE__EE_System__parse_implemented_model_names',
@@ -119,7 +119,7 @@  discard block
 block discarded – undo
119 119
         }
120 120
         if (isset($setup_args['class_paths'])) {
121 121
             // make sure they passed in an array
122
-            if (! is_array($setup_args['class_paths'])) {
122
+            if ( ! is_array($setup_args['class_paths'])) {
123 123
                 $setup_args['class_paths'] = [$setup_args['class_paths']];
124 124
             }
125 125
             $class_to_filepath_map = EEH_File::get_contents_of_folders($setup_args['class_paths']);
@@ -192,6 +192,6 @@  discard block
 block discarded – undo
192 192
      */
193 193
     public static function deregister($identifier = '')
194 194
     {
195
-        unset(self::$_model_registry[ $identifier ], self::$_model_name_to_classname_map[ $identifier ]);
195
+        unset(self::$_model_registry[$identifier], self::$_model_name_to_classname_map[$identifier]);
196 196
     }
197 197
 }
Please login to merge, or discard this patch.
Indentation   +169 added lines, -169 removed lines patch added patch discarded remove patch
@@ -11,187 +11,187 @@
 block discarded – undo
11 11
  */
12 12
 class EE_Register_Model implements EEI_Plugin_API
13 13
 {
14
-    /**
15
-     *
16
-     * @var array keys are the model_id used to register with, values are the array provided to register them, exactly
17
-     *      like EE_Register_Model::register()'s 2nd arg
18
-     */
19
-    protected static $_model_registry;
14
+	/**
15
+	 *
16
+	 * @var array keys are the model_id used to register with, values are the array provided to register them, exactly
17
+	 *      like EE_Register_Model::register()'s 2nd arg
18
+	 */
19
+	protected static $_model_registry;
20 20
 
21
-    /**
22
-     *
23
-     * @var array keys are model names, values are their class names. Stored on registration and used
24
-     * on a hook
25
-     */
26
-    protected static $_model_name_to_classname_map;
21
+	/**
22
+	 *
23
+	 * @var array keys are model names, values are their class names. Stored on registration and used
24
+	 * on a hook
25
+	 */
26
+	protected static $_model_name_to_classname_map;
27 27
 
28 28
 
29
-    /**
30
-     * @param string $identifier  unique id for it
31
-     * @param array  $setup_args  {
32
-     * @type array   $model_paths array of folders containing DB models, where each file follows the models naming
33
-     *                            convention, which is: EEM_{model_name}.model.php which contains a single class called
34
-     *                            EEM_{model_name}. Eg. you could pass
35
-     *                            "public_html/wp-content/plugins/my_addon/db_models" (with or without trailing slash)
36
-     *                            and in that folder put each of your model files, like "EEM_Food.model.php" which
37
-     *                            contains the class "EEM_Food" and
38
-     *                            "EEM_Monkey.model.php" which contains the class "EEM_Monkey". These will be
39
-     *                            autoloaded and added to the EE registry so they can be used like ordinary models. The
40
-     *                            class contained in each file should extend EEM_Base.
41
-     * @type array   $class_paths array of folders containing DB classes, where each file follows the model class
42
-     *                            naming convention, which is EE_{model_name}.class.php. The class contained in each
43
-     *                            file should extend EE_Base_Class
44
-     *
45
-     * }
46
-     * @throws EE_Error
47
-     */
48
-    public static function register($identifier = '', array $setup_args = [])
49
-    {
50
-        // required fields MUST be present, so let's make sure they are.
51
-        if (empty($identifier) || ! is_array($setup_args) || empty($setup_args['model_paths'])) {
52
-            throw new EE_Error(
53
-                esc_html__(
54
-                    'In order to register Models with EE_Register_Model::register(), you must include a "model_id" (a unique identifier for this set of models), and an array containing the following keys: "model_paths" (an array of full server paths to folders that contain models)',
55
-                    'event_espresso'
56
-                )
57
-            );
58
-        }
29
+	/**
30
+	 * @param string $identifier  unique id for it
31
+	 * @param array  $setup_args  {
32
+	 * @type array   $model_paths array of folders containing DB models, where each file follows the models naming
33
+	 *                            convention, which is: EEM_{model_name}.model.php which contains a single class called
34
+	 *                            EEM_{model_name}. Eg. you could pass
35
+	 *                            "public_html/wp-content/plugins/my_addon/db_models" (with or without trailing slash)
36
+	 *                            and in that folder put each of your model files, like "EEM_Food.model.php" which
37
+	 *                            contains the class "EEM_Food" and
38
+	 *                            "EEM_Monkey.model.php" which contains the class "EEM_Monkey". These will be
39
+	 *                            autoloaded and added to the EE registry so they can be used like ordinary models. The
40
+	 *                            class contained in each file should extend EEM_Base.
41
+	 * @type array   $class_paths array of folders containing DB classes, where each file follows the model class
42
+	 *                            naming convention, which is EE_{model_name}.class.php. The class contained in each
43
+	 *                            file should extend EE_Base_Class
44
+	 *
45
+	 * }
46
+	 * @throws EE_Error
47
+	 */
48
+	public static function register($identifier = '', array $setup_args = [])
49
+	{
50
+		// required fields MUST be present, so let's make sure they are.
51
+		if (empty($identifier) || ! is_array($setup_args) || empty($setup_args['model_paths'])) {
52
+			throw new EE_Error(
53
+				esc_html__(
54
+					'In order to register Models with EE_Register_Model::register(), you must include a "model_id" (a unique identifier for this set of models), and an array containing the following keys: "model_paths" (an array of full server paths to folders that contain models)',
55
+					'event_espresso'
56
+				)
57
+			);
58
+		}
59 59
 
60
-        // make sure we don't register twice
61
-        if (isset(self::$_model_registry[ $identifier ])) {
62
-            return;
63
-        }
60
+		// make sure we don't register twice
61
+		if (isset(self::$_model_registry[ $identifier ])) {
62
+			return;
63
+		}
64 64
 
65
-        if (
66
-            ! did_action('AHEE__EE_System__load_espresso_addons')
67
-            || did_action('FHEE__EE_System__parse_model_names')
68
-            || did_action('FHEE__EE_System__parse_implemented_model_names')
69
-        ) {
70
-            EE_Error::doing_it_wrong(
71
-                __METHOD__,
72
-                sprintf(
73
-                    esc_html__(
74
-                        'An attempt was made to register "%s" as a group models has failed because it was not registered at the correct time.  Please use the "AHEE__EE_System__load_espresso_addons" hook to register models.',
75
-                        'event_espresso'
76
-                    ),
77
-                    $identifier
78
-                ),
79
-                '4.5'
80
-            );
81
-        }
82
-        self::$_model_registry[ $identifier ] = $setup_args;
65
+		if (
66
+			! did_action('AHEE__EE_System__load_espresso_addons')
67
+			|| did_action('FHEE__EE_System__parse_model_names')
68
+			|| did_action('FHEE__EE_System__parse_implemented_model_names')
69
+		) {
70
+			EE_Error::doing_it_wrong(
71
+				__METHOD__,
72
+				sprintf(
73
+					esc_html__(
74
+						'An attempt was made to register "%s" as a group models has failed because it was not registered at the correct time.  Please use the "AHEE__EE_System__load_espresso_addons" hook to register models.',
75
+						'event_espresso'
76
+					),
77
+					$identifier
78
+				),
79
+				'4.5'
80
+			);
81
+		}
82
+		self::$_model_registry[ $identifier ] = $setup_args;
83 83
 
84
-        if (
85
-            (isset($setup_args['model_paths']) && ! isset($setup_args['class_paths']))
86
-            || (! isset($setup_args['model_paths']) && isset($setup_args['class_paths']))
87
-        ) {
88
-            throw new EE_Error(
89
-                sprintf(
90
-                    esc_html__(
91
-                        'You must register both "model_paths" AND "class_paths", not just one or the other You provided %s',
92
-                        'event_espresso'
93
-                    ),
94
-                    implode(", ", array_keys($setup_args))
95
-                )
96
-            );
97
-        }
98
-        if (isset($setup_args['model_paths'])) {
99
-            // make sure they passed in an array
100
-            if (! is_array($setup_args['model_paths'])) {
101
-                $setup_args['model_paths'] = [$setup_args['model_paths']];
102
-            }
103
-            // we want to add this as a model folder
104
-            // and autoload them all
105
-            $class_to_filepath_map = EEH_File::get_contents_of_folders($setup_args['model_paths']);
106
-            EEH_Autoloader::register_autoloader($class_to_filepath_map);
107
-            $model_name_to_classname_map = [];
108
-            foreach (array_keys($class_to_filepath_map) as $classname) {
109
-                $model_name_to_classname_map[ str_replace("EEM_", "", $classname) ] = $classname;
110
-            }
111
-            self::$_model_name_to_classname_map[ $identifier ] = $model_name_to_classname_map;
112
-            add_filter('FHEE__EE_System__parse_model_names', ['EE_Register_Model', 'add_addon_models']);
113
-            add_filter(
114
-                'FHEE__EE_System__parse_implemented_model_names',
115
-                ['EE_Register_Model', 'add_addon_models']
116
-            );
117
-            add_filter('FHEE__EE_Registry__load_model__paths', ['EE_Register_Model', 'add_model_folders']);
118
-            unset($setup_args['model_paths']);
119
-        }
120
-        if (isset($setup_args['class_paths'])) {
121
-            // make sure they passed in an array
122
-            if (! is_array($setup_args['class_paths'])) {
123
-                $setup_args['class_paths'] = [$setup_args['class_paths']];
124
-            }
125
-            $class_to_filepath_map = EEH_File::get_contents_of_folders($setup_args['class_paths']);
126
-            EEH_Autoloader::register_autoloader($class_to_filepath_map);
127
-            add_filter('FHEE__EE_Registry__load_class__paths', ['EE_Register_Model', 'add_class_folders']);
128
-            unset($setup_args['class_paths']);
129
-        }
130
-        foreach ($setup_args as $unknown_key => $unknown_config) {
131
-            self::deregister($identifier);
132
-            throw new EE_Error(
133
-                sprintf(esc_html__("The key '%s' is not a known key for registering a model", "event_espresso"), $unknown_key)
134
-            );
135
-        }
136
-    }
84
+		if (
85
+			(isset($setup_args['model_paths']) && ! isset($setup_args['class_paths']))
86
+			|| (! isset($setup_args['model_paths']) && isset($setup_args['class_paths']))
87
+		) {
88
+			throw new EE_Error(
89
+				sprintf(
90
+					esc_html__(
91
+						'You must register both "model_paths" AND "class_paths", not just one or the other You provided %s',
92
+						'event_espresso'
93
+					),
94
+					implode(", ", array_keys($setup_args))
95
+				)
96
+			);
97
+		}
98
+		if (isset($setup_args['model_paths'])) {
99
+			// make sure they passed in an array
100
+			if (! is_array($setup_args['model_paths'])) {
101
+				$setup_args['model_paths'] = [$setup_args['model_paths']];
102
+			}
103
+			// we want to add this as a model folder
104
+			// and autoload them all
105
+			$class_to_filepath_map = EEH_File::get_contents_of_folders($setup_args['model_paths']);
106
+			EEH_Autoloader::register_autoloader($class_to_filepath_map);
107
+			$model_name_to_classname_map = [];
108
+			foreach (array_keys($class_to_filepath_map) as $classname) {
109
+				$model_name_to_classname_map[ str_replace("EEM_", "", $classname) ] = $classname;
110
+			}
111
+			self::$_model_name_to_classname_map[ $identifier ] = $model_name_to_classname_map;
112
+			add_filter('FHEE__EE_System__parse_model_names', ['EE_Register_Model', 'add_addon_models']);
113
+			add_filter(
114
+				'FHEE__EE_System__parse_implemented_model_names',
115
+				['EE_Register_Model', 'add_addon_models']
116
+			);
117
+			add_filter('FHEE__EE_Registry__load_model__paths', ['EE_Register_Model', 'add_model_folders']);
118
+			unset($setup_args['model_paths']);
119
+		}
120
+		if (isset($setup_args['class_paths'])) {
121
+			// make sure they passed in an array
122
+			if (! is_array($setup_args['class_paths'])) {
123
+				$setup_args['class_paths'] = [$setup_args['class_paths']];
124
+			}
125
+			$class_to_filepath_map = EEH_File::get_contents_of_folders($setup_args['class_paths']);
126
+			EEH_Autoloader::register_autoloader($class_to_filepath_map);
127
+			add_filter('FHEE__EE_Registry__load_class__paths', ['EE_Register_Model', 'add_class_folders']);
128
+			unset($setup_args['class_paths']);
129
+		}
130
+		foreach ($setup_args as $unknown_key => $unknown_config) {
131
+			self::deregister($identifier);
132
+			throw new EE_Error(
133
+				sprintf(esc_html__("The key '%s' is not a known key for registering a model", "event_espresso"), $unknown_key)
134
+			);
135
+		}
136
+	}
137 137
 
138 138
 
139
-    /**
140
-     * Filters the core list of models
141
-     *
142
-     * @param array $core_models
143
-     * @return array keys are model names (eg 'Event') and values are their classes (eg 'EE_Event')
144
-     */
145
-    public static function add_addon_models(array $core_models = [])
146
-    {
147
-        foreach (self::$_model_name_to_classname_map as $model_name_to_class_map) {
148
-            $core_models = array_merge($core_models, $model_name_to_class_map);
149
-        }
150
-        return $core_models;
151
-    }
139
+	/**
140
+	 * Filters the core list of models
141
+	 *
142
+	 * @param array $core_models
143
+	 * @return array keys are model names (eg 'Event') and values are their classes (eg 'EE_Event')
144
+	 */
145
+	public static function add_addon_models(array $core_models = [])
146
+	{
147
+		foreach (self::$_model_name_to_classname_map as $model_name_to_class_map) {
148
+			$core_models = array_merge($core_models, $model_name_to_class_map);
149
+		}
150
+		return $core_models;
151
+	}
152 152
 
153 153
 
154
-    /**
155
-     * Filters the list of model folders
156
-     *
157
-     * @param array $folders
158
-     * @return array of folder paths
159
-     */
160
-    public static function add_model_folders(array $folders = [])
161
-    {
162
-        foreach (self::$_model_registry as $setup_args) {
163
-            if (isset($setup_args['model_paths'])) {
164
-                $folders = array_merge($folders, $setup_args['model_paths']);
165
-            }
166
-        }
167
-        return $folders;
168
-    }
154
+	/**
155
+	 * Filters the list of model folders
156
+	 *
157
+	 * @param array $folders
158
+	 * @return array of folder paths
159
+	 */
160
+	public static function add_model_folders(array $folders = [])
161
+	{
162
+		foreach (self::$_model_registry as $setup_args) {
163
+			if (isset($setup_args['model_paths'])) {
164
+				$folders = array_merge($folders, $setup_args['model_paths']);
165
+			}
166
+		}
167
+		return $folders;
168
+	}
169 169
 
170 170
 
171
-    /**
172
-     * Filters the array of model class paths
173
-     *
174
-     * @param array $folders
175
-     * @return array of folder paths
176
-     */
177
-    public static function add_class_folders(array $folders = [])
178
-    {
179
-        foreach (self::$_model_registry as $setup_args) {
180
-            if (isset($setup_args['class_paths'])) {
181
-                $folders = array_merge($folders, $setup_args['class_paths']);
182
-            }
183
-        }
184
-        return $folders;
185
-    }
171
+	/**
172
+	 * Filters the array of model class paths
173
+	 *
174
+	 * @param array $folders
175
+	 * @return array of folder paths
176
+	 */
177
+	public static function add_class_folders(array $folders = [])
178
+	{
179
+		foreach (self::$_model_registry as $setup_args) {
180
+			if (isset($setup_args['class_paths'])) {
181
+				$folders = array_merge($folders, $setup_args['class_paths']);
182
+			}
183
+		}
184
+		return $folders;
185
+	}
186 186
 
187 187
 
188
-    /**
189
-     * deregister
190
-     *
191
-     * @param string $identifier
192
-     */
193
-    public static function deregister($identifier = '')
194
-    {
195
-        unset(self::$_model_registry[ $identifier ], self::$_model_name_to_classname_map[ $identifier ]);
196
-    }
188
+	/**
189
+	 * deregister
190
+	 *
191
+	 * @param string $identifier
192
+	 */
193
+	public static function deregister($identifier = '')
194
+	{
195
+		unset(self::$_model_registry[ $identifier ], self::$_model_name_to_classname_map[ $identifier ]);
196
+	}
197 197
 }
Please login to merge, or discard this patch.