Completed
Branch fix/primary-attendee-context (b83ab6)
by
unknown
12:36 queued 10:13
created
core/services/request/sanitizers/AllowedTags.php 1 patch
Indentation   +279 added lines, -279 removed lines patch added patch discarded remove patch
@@ -13,283 +13,283 @@
 block discarded – undo
13 13
 class AllowedTags
14 14
 {
15 15
 
16
-    /**
17
-     * @var array[]
18
-     */
19
-    private static $attributes = [
20
-        'accept-charset'    => 1,
21
-        'action'            => 1,
22
-        'alt'               => 1,
23
-        'allow'             => 1,
24
-        'allowfullscreen'   => 1,
25
-        'align'             => 1,
26
-        'aria-*'            => 1,
27
-        'autocomplete'      => 1,
28
-        'checked'           => 1,
29
-        'class'             => 1,
30
-        'cols'              => 1,
31
-        'content'           => 1,
32
-        'data-*'            => 1,
33
-        'dir'               => 1,
34
-        'disabled'          => 1,
35
-        'enctype'           => 1,
36
-        'for'               => 1,
37
-        'frameborder'       => 1,
38
-        'height'            => 1,
39
-        'href'              => 1,
40
-        'id'                => 1,
41
-        'itemprop'          => 1,
42
-        'itemscope'         => 1,
43
-        'itemtype'          => 1,
44
-        'label'             => 1,
45
-        'lang'              => 1,
46
-        'max'               => 1,
47
-        'maxlength'         => 1,
48
-        'method'            => 1,
49
-        'min'               => 1,
50
-        'multiple'          => 1,
51
-        'name'              => 1,
52
-        'novalidate'        => 1,
53
-        'placeholder'       => 1,
54
-        'readonly'          => 1,
55
-        'rel'               => 1,
56
-        'required'          => 1,
57
-        'rows'              => 1,
58
-        'selected'          => 1,
59
-        'src'               => 1,
60
-        'size'              => 1,
61
-        'style'             => 1,
62
-        'step'              => 1,
63
-        'tabindex'          => 1,
64
-        'target'            => 1,
65
-        'title'             => 1,
66
-        'type'              => 1,
67
-        'value'             => 1,
68
-        'width'             => 1,
69
-        'topmargin'         => 1,
70
-        'leftmargin'        => 1,
71
-        'marginheight'      => 1,
72
-        'marginwidth'       => 1,
73
-        'property'          => 1,
74
-        'bgcolor'           => 1,
75
-        'media'             => 1,
76
-        'cellpadding'       => 1,
77
-        'cellspacing'       => 1,
78
-        'border'            => 1,
79
-    ];
80
-
81
-
82
-    /**
83
-     * @var array
84
-     */
85
-    private static $tags = [
86
-        'a',
87
-        'abbr',
88
-        'b',
89
-        'br',
90
-        'code',
91
-        'div',
92
-        'em',
93
-        'h1',
94
-        'h2',
95
-        'h3',
96
-        'h4',
97
-        'h5',
98
-        'h6',
99
-        'hr',
100
-        'i',
101
-        'img',
102
-        'li',
103
-        'ol',
104
-        'p',
105
-        'pre',
106
-        'small',
107
-        'span',
108
-        'strong',
109
-        'table',
110
-        'td',
111
-        'tr',
112
-        'ul',
113
-    ];
114
-
115
-
116
-    /**
117
-     * @var array
118
-     */
119
-    private static $allowed_tags;
120
-
121
-
122
-    /**
123
-     * @var array
124
-     */
125
-    private static $allowed_with_embed_tags;
126
-
127
-
128
-    /**
129
-     * @var array
130
-     */
131
-    private static $allowed_with_form_tags;
132
-
133
-
134
-    /**
135
-     * @var array
136
-     */
137
-    private static $allowed_with_script_and_style_tags;
138
-
139
-    /**
140
-     * @var array
141
-     */
142
-    private static $allowed_with_full_tags;
143
-
144
-
145
-    /**
146
-     * merges additional tags and attributes into the WP post tags
147
-     */
148
-    private static function initializeAllowedTags()
149
-    {
150
-        $allowed_post_tags = wp_kses_allowed_html('post');
151
-        $allowed_tags = [];
152
-        foreach (AllowedTags::$tags as $tag) {
153
-            $allowed_tags[ $tag ] = AllowedTags::$attributes;
154
-        }
155
-        AllowedTags::$allowed_tags = array_merge_recursive($allowed_post_tags, $allowed_tags);
156
-    }
157
-
158
-
159
-    /**
160
-     * merges embed tags and attributes into the EE all tags
161
-     */
162
-    private static function initializeWithEmbedTags()
163
-    {
164
-        $all_tags = AllowedTags::getAllowedTags();
165
-        $embed_tags = [
166
-            'iframe' => AllowedTags::$attributes
167
-        ];
168
-        AllowedTags::$allowed_with_embed_tags = array_merge_recursive($all_tags, $embed_tags);
169
-    }
170
-
171
-
172
-    /**
173
-     * merges form tags and attributes into the EE all tags
174
-     */
175
-    private static function initializeWithFormTags()
176
-    {
177
-        $all_tags = AllowedTags::getAllowedTags();
178
-        $form_tags = [
179
-            'form'     => AllowedTags::$attributes,
180
-            'label'    => AllowedTags::$attributes,
181
-            'input'    => AllowedTags::$attributes,
182
-            'select'   => AllowedTags::$attributes,
183
-            'option'   => AllowedTags::$attributes,
184
-            'optgroup' => AllowedTags::$attributes,
185
-            'textarea' => AllowedTags::$attributes,
186
-            'button'   => AllowedTags::$attributes,
187
-            'fieldset' => AllowedTags::$attributes,
188
-            'output'   => AllowedTags::$attributes,
189
-        ];
190
-        AllowedTags::$allowed_with_form_tags = array_merge_recursive($all_tags, $form_tags);
191
-    }
192
-
193
-
194
-    /**
195
-     * merges form script and style tags and attributes into the EE all tags
196
-     */
197
-    private static function initializeWithScriptAndStyleTags()
198
-    {
199
-        $all_tags = AllowedTags::getAllowedTags();
200
-        $script_and_style_tags = [
201
-            'script'   => AllowedTags::$attributes,
202
-            'style'    => AllowedTags::$attributes,
203
-            'link'     => AllowedTags::$attributes,
204
-            'noscript' => AllowedTags::$attributes,
205
-        ];
206
-        AllowedTags::$allowed_with_script_and_style_tags = array_merge_recursive($all_tags, $script_and_style_tags);
207
-    }
208
-
209
-    /**
210
-     * merges all head and body tags and attributes into the EE all tags
211
-     */
212
-    private static function initializeWithFullTags()
213
-    {
214
-        $all_tags = AllowedTags::getAllowedTags();
215
-        $full_tags = [
216
-            'script'    => AllowedTags::$attributes,
217
-            'style'     => AllowedTags::$attributes,
218
-            'link'      => AllowedTags::$attributes,
219
-            'title'     => AllowedTags::$attributes,
220
-            'meta'      => AllowedTags::$attributes,
221
-            'iframe'    => AllowedTags::$attributes,
222
-            'form'      => AllowedTags::$attributes,
223
-            'label'     => AllowedTags::$attributes,
224
-            'input'     => AllowedTags::$attributes,
225
-            'select'    => AllowedTags::$attributes,
226
-            'option'    => AllowedTags::$attributes,
227
-            'optgroup'  => AllowedTags::$attributes,
228
-            'textarea'  => AllowedTags::$attributes,
229
-            'button'    => AllowedTags::$attributes,
230
-            'fieldset'  => AllowedTags::$attributes,
231
-            'output'    => AllowedTags::$attributes,
232
-            'noscript'  => AllowedTags::$attributes,
233
-        ];
234
-        AllowedTags::$allowed_with_full_tags = array_merge_recursive($all_tags, $full_tags);
235
-    }
236
-
237
-
238
-    /**
239
-     * @return array[]
240
-     */
241
-    public static function getAllowedTags()
242
-    {
243
-        if (empty(AllowedTags::$allowed_tags)) {
244
-            AllowedTags::initializeAllowedTags();
245
-        }
246
-        return AllowedTags::$allowed_tags;
247
-    }
248
-
249
-
250
-    /**
251
-     * @return array[]
252
-     */
253
-    public static function getWithEmbedTags()
254
-    {
255
-        if (empty(AllowedTags::$allowed_with_embed_tags)) {
256
-            AllowedTags::initializeWithEmbedTags();
257
-        }
258
-        return AllowedTags::$allowed_with_embed_tags;
259
-    }
260
-
261
-
262
-    /**
263
-     * @return array[]
264
-     */
265
-    public static function getWithFormTags()
266
-    {
267
-        if (empty(AllowedTags::$allowed_with_form_tags)) {
268
-            AllowedTags::initializeWithFormTags();
269
-        }
270
-        return AllowedTags::$allowed_with_form_tags;
271
-    }
272
-
273
-
274
-    /**
275
-     * @return array[]
276
-     */
277
-    public static function getWithScriptAndStyleTags()
278
-    {
279
-        if (empty(AllowedTags::$allowed_with_script_and_style_tags)) {
280
-            AllowedTags::initializeWithScriptAndStyleTags();
281
-        }
282
-        return AllowedTags::$allowed_with_script_and_style_tags;
283
-    }
284
-
285
-    /**
286
-     * @return array[]
287
-     */
288
-    public static function getWithFullTags()
289
-    {
290
-        if (empty(AllowedTags::$allowed_with_full_tags)) {
291
-            AllowedTags::initializeWithFullTags();
292
-        }
293
-        return AllowedTags::$allowed_with_full_tags;
294
-    }
16
+	/**
17
+	 * @var array[]
18
+	 */
19
+	private static $attributes = [
20
+		'accept-charset'    => 1,
21
+		'action'            => 1,
22
+		'alt'               => 1,
23
+		'allow'             => 1,
24
+		'allowfullscreen'   => 1,
25
+		'align'             => 1,
26
+		'aria-*'            => 1,
27
+		'autocomplete'      => 1,
28
+		'checked'           => 1,
29
+		'class'             => 1,
30
+		'cols'              => 1,
31
+		'content'           => 1,
32
+		'data-*'            => 1,
33
+		'dir'               => 1,
34
+		'disabled'          => 1,
35
+		'enctype'           => 1,
36
+		'for'               => 1,
37
+		'frameborder'       => 1,
38
+		'height'            => 1,
39
+		'href'              => 1,
40
+		'id'                => 1,
41
+		'itemprop'          => 1,
42
+		'itemscope'         => 1,
43
+		'itemtype'          => 1,
44
+		'label'             => 1,
45
+		'lang'              => 1,
46
+		'max'               => 1,
47
+		'maxlength'         => 1,
48
+		'method'            => 1,
49
+		'min'               => 1,
50
+		'multiple'          => 1,
51
+		'name'              => 1,
52
+		'novalidate'        => 1,
53
+		'placeholder'       => 1,
54
+		'readonly'          => 1,
55
+		'rel'               => 1,
56
+		'required'          => 1,
57
+		'rows'              => 1,
58
+		'selected'          => 1,
59
+		'src'               => 1,
60
+		'size'              => 1,
61
+		'style'             => 1,
62
+		'step'              => 1,
63
+		'tabindex'          => 1,
64
+		'target'            => 1,
65
+		'title'             => 1,
66
+		'type'              => 1,
67
+		'value'             => 1,
68
+		'width'             => 1,
69
+		'topmargin'         => 1,
70
+		'leftmargin'        => 1,
71
+		'marginheight'      => 1,
72
+		'marginwidth'       => 1,
73
+		'property'          => 1,
74
+		'bgcolor'           => 1,
75
+		'media'             => 1,
76
+		'cellpadding'       => 1,
77
+		'cellspacing'       => 1,
78
+		'border'            => 1,
79
+	];
80
+
81
+
82
+	/**
83
+	 * @var array
84
+	 */
85
+	private static $tags = [
86
+		'a',
87
+		'abbr',
88
+		'b',
89
+		'br',
90
+		'code',
91
+		'div',
92
+		'em',
93
+		'h1',
94
+		'h2',
95
+		'h3',
96
+		'h4',
97
+		'h5',
98
+		'h6',
99
+		'hr',
100
+		'i',
101
+		'img',
102
+		'li',
103
+		'ol',
104
+		'p',
105
+		'pre',
106
+		'small',
107
+		'span',
108
+		'strong',
109
+		'table',
110
+		'td',
111
+		'tr',
112
+		'ul',
113
+	];
114
+
115
+
116
+	/**
117
+	 * @var array
118
+	 */
119
+	private static $allowed_tags;
120
+
121
+
122
+	/**
123
+	 * @var array
124
+	 */
125
+	private static $allowed_with_embed_tags;
126
+
127
+
128
+	/**
129
+	 * @var array
130
+	 */
131
+	private static $allowed_with_form_tags;
132
+
133
+
134
+	/**
135
+	 * @var array
136
+	 */
137
+	private static $allowed_with_script_and_style_tags;
138
+
139
+	/**
140
+	 * @var array
141
+	 */
142
+	private static $allowed_with_full_tags;
143
+
144
+
145
+	/**
146
+	 * merges additional tags and attributes into the WP post tags
147
+	 */
148
+	private static function initializeAllowedTags()
149
+	{
150
+		$allowed_post_tags = wp_kses_allowed_html('post');
151
+		$allowed_tags = [];
152
+		foreach (AllowedTags::$tags as $tag) {
153
+			$allowed_tags[ $tag ] = AllowedTags::$attributes;
154
+		}
155
+		AllowedTags::$allowed_tags = array_merge_recursive($allowed_post_tags, $allowed_tags);
156
+	}
157
+
158
+
159
+	/**
160
+	 * merges embed tags and attributes into the EE all tags
161
+	 */
162
+	private static function initializeWithEmbedTags()
163
+	{
164
+		$all_tags = AllowedTags::getAllowedTags();
165
+		$embed_tags = [
166
+			'iframe' => AllowedTags::$attributes
167
+		];
168
+		AllowedTags::$allowed_with_embed_tags = array_merge_recursive($all_tags, $embed_tags);
169
+	}
170
+
171
+
172
+	/**
173
+	 * merges form tags and attributes into the EE all tags
174
+	 */
175
+	private static function initializeWithFormTags()
176
+	{
177
+		$all_tags = AllowedTags::getAllowedTags();
178
+		$form_tags = [
179
+			'form'     => AllowedTags::$attributes,
180
+			'label'    => AllowedTags::$attributes,
181
+			'input'    => AllowedTags::$attributes,
182
+			'select'   => AllowedTags::$attributes,
183
+			'option'   => AllowedTags::$attributes,
184
+			'optgroup' => AllowedTags::$attributes,
185
+			'textarea' => AllowedTags::$attributes,
186
+			'button'   => AllowedTags::$attributes,
187
+			'fieldset' => AllowedTags::$attributes,
188
+			'output'   => AllowedTags::$attributes,
189
+		];
190
+		AllowedTags::$allowed_with_form_tags = array_merge_recursive($all_tags, $form_tags);
191
+	}
192
+
193
+
194
+	/**
195
+	 * merges form script and style tags and attributes into the EE all tags
196
+	 */
197
+	private static function initializeWithScriptAndStyleTags()
198
+	{
199
+		$all_tags = AllowedTags::getAllowedTags();
200
+		$script_and_style_tags = [
201
+			'script'   => AllowedTags::$attributes,
202
+			'style'    => AllowedTags::$attributes,
203
+			'link'     => AllowedTags::$attributes,
204
+			'noscript' => AllowedTags::$attributes,
205
+		];
206
+		AllowedTags::$allowed_with_script_and_style_tags = array_merge_recursive($all_tags, $script_and_style_tags);
207
+	}
208
+
209
+	/**
210
+	 * merges all head and body tags and attributes into the EE all tags
211
+	 */
212
+	private static function initializeWithFullTags()
213
+	{
214
+		$all_tags = AllowedTags::getAllowedTags();
215
+		$full_tags = [
216
+			'script'    => AllowedTags::$attributes,
217
+			'style'     => AllowedTags::$attributes,
218
+			'link'      => AllowedTags::$attributes,
219
+			'title'     => AllowedTags::$attributes,
220
+			'meta'      => AllowedTags::$attributes,
221
+			'iframe'    => AllowedTags::$attributes,
222
+			'form'      => AllowedTags::$attributes,
223
+			'label'     => AllowedTags::$attributes,
224
+			'input'     => AllowedTags::$attributes,
225
+			'select'    => AllowedTags::$attributes,
226
+			'option'    => AllowedTags::$attributes,
227
+			'optgroup'  => AllowedTags::$attributes,
228
+			'textarea'  => AllowedTags::$attributes,
229
+			'button'    => AllowedTags::$attributes,
230
+			'fieldset'  => AllowedTags::$attributes,
231
+			'output'    => AllowedTags::$attributes,
232
+			'noscript'  => AllowedTags::$attributes,
233
+		];
234
+		AllowedTags::$allowed_with_full_tags = array_merge_recursive($all_tags, $full_tags);
235
+	}
236
+
237
+
238
+	/**
239
+	 * @return array[]
240
+	 */
241
+	public static function getAllowedTags()
242
+	{
243
+		if (empty(AllowedTags::$allowed_tags)) {
244
+			AllowedTags::initializeAllowedTags();
245
+		}
246
+		return AllowedTags::$allowed_tags;
247
+	}
248
+
249
+
250
+	/**
251
+	 * @return array[]
252
+	 */
253
+	public static function getWithEmbedTags()
254
+	{
255
+		if (empty(AllowedTags::$allowed_with_embed_tags)) {
256
+			AllowedTags::initializeWithEmbedTags();
257
+		}
258
+		return AllowedTags::$allowed_with_embed_tags;
259
+	}
260
+
261
+
262
+	/**
263
+	 * @return array[]
264
+	 */
265
+	public static function getWithFormTags()
266
+	{
267
+		if (empty(AllowedTags::$allowed_with_form_tags)) {
268
+			AllowedTags::initializeWithFormTags();
269
+		}
270
+		return AllowedTags::$allowed_with_form_tags;
271
+	}
272
+
273
+
274
+	/**
275
+	 * @return array[]
276
+	 */
277
+	public static function getWithScriptAndStyleTags()
278
+	{
279
+		if (empty(AllowedTags::$allowed_with_script_and_style_tags)) {
280
+			AllowedTags::initializeWithScriptAndStyleTags();
281
+		}
282
+		return AllowedTags::$allowed_with_script_and_style_tags;
283
+	}
284
+
285
+	/**
286
+	 * @return array[]
287
+	 */
288
+	public static function getWithFullTags()
289
+	{
290
+		if (empty(AllowedTags::$allowed_with_full_tags)) {
291
+			AllowedTags::initializeWithFullTags();
292
+		}
293
+		return AllowedTags::$allowed_with_full_tags;
294
+	}
295 295
 }
Please login to merge, or discard this patch.
core/EE_System.core.php 2 patches
Indentation   +1353 added lines, -1353 removed lines patch added patch discarded remove patch
@@ -27,1357 +27,1357 @@
 block discarded – undo
27 27
 final class EE_System implements ResettableInterface
28 28
 {
29 29
 
30
-    /**
31
-     * indicates this is a 'normal' request. Ie, not activation, nor upgrade, nor activation.
32
-     * So examples of this would be a normal GET request on the frontend or backend, or a POST, etc
33
-     */
34
-    const req_type_normal = 0;
35
-
36
-    /**
37
-     * Indicates this is a brand new installation of EE so we should install
38
-     * tables and default data etc
39
-     */
40
-    const req_type_new_activation = 1;
41
-
42
-    /**
43
-     * we've detected that EE has been reactivated (or EE was activated during maintenance mode,
44
-     * and we just exited maintenance mode). We MUST check the database is setup properly
45
-     * and that default data is setup too
46
-     */
47
-    const req_type_reactivation = 2;
48
-
49
-    /**
50
-     * indicates that EE has been upgraded since its previous request.
51
-     * We may have data migration scripts to call and will want to trigger maintenance mode
52
-     */
53
-    const req_type_upgrade = 3;
54
-
55
-    /**
56
-     * TODO  will detect that EE has been DOWNGRADED. We probably don't want to run in this case...
57
-     */
58
-    const req_type_downgrade = 4;
59
-
60
-    /**
61
-     * @deprecated since version 4.6.0.dev.006
62
-     * Now whenever a new_activation is detected the request type is still just
63
-     * new_activation (same for reactivation, upgrade, downgrade etc), but if we'r ein maintenance mode
64
-     * EE_System::initialize_db_if_no_migrations_required and EE_Addon::initialize_db_if_no_migrations_required
65
-     * will instead enqueue that EE plugin's db initialization for when we're taken out of maintenance mode.
66
-     * (Specifically, when the migration manager indicates migrations are finished
67
-     * EE_Data_Migration_Manager::initialize_db_for_enqueued_ee_plugins() will be called)
68
-     */
69
-    const req_type_activation_but_not_installed = 5;
70
-
71
-    /**
72
-     * option prefix for recording the activation history (like core's "espresso_db_update") of addons
73
-     */
74
-    const addon_activation_history_option_prefix = 'ee_addon_activation_history_';
75
-
76
-    /**
77
-     * @var EE_System $_instance
78
-     */
79
-    private static $_instance;
80
-
81
-    /**
82
-     * @var EE_Registry $registry
83
-     */
84
-    private $registry;
85
-
86
-    /**
87
-     * @var LoaderInterface $loader
88
-     */
89
-    private $loader;
90
-
91
-    /**
92
-     * @var EE_Capabilities $capabilities
93
-     */
94
-    private $capabilities;
95
-
96
-    /**
97
-     * @var RequestInterface $request
98
-     */
99
-    private $request;
100
-
101
-    /**
102
-     * @var EE_Maintenance_Mode $maintenance_mode
103
-     */
104
-    private $maintenance_mode;
105
-
106
-    /**
107
-     * Stores which type of request this is, options being one of the constants on EE_System starting with req_type_*.
108
-     * It can be a brand-new activation, a reactivation, an upgrade, a downgrade, or a normal request.
109
-     *
110
-     * @var int $_req_type
111
-     */
112
-    private $_req_type;
113
-
114
-    /**
115
-     * Whether or not there was a non-micro version change in EE core version during this request
116
-     *
117
-     * @var boolean $_major_version_change
118
-     */
119
-    private $_major_version_change = false;
120
-
121
-    /**
122
-     * A Context DTO dedicated solely to identifying the current request type.
123
-     *
124
-     * @var RequestTypeContextCheckerInterface $request_type
125
-     */
126
-    private $request_type;
127
-
128
-    /**
129
-     * @param EventEspresso\core\domain\services\custom_post_types\RegisterCustomPostTypes
130
-     */
131
-    private $register_custom_post_types;
132
-
133
-    /**
134
-     * @param EventEspresso\core\domain\services\custom_post_types\RegisterCustomTaxonomies
135
-     */
136
-    private $register_custom_taxonomies;
137
-
138
-    /**
139
-     * @param EventEspresso\core\domain\services\custom_post_types\RegisterCustomTaxonomyTerms
140
-     */
141
-    private $register_custom_taxonomy_terms;
142
-
143
-    /**
144
-     * @singleton method used to instantiate class object
145
-     * @param EE_Registry|null         $registry
146
-     * @param LoaderInterface|null     $loader
147
-     * @param RequestInterface|null    $request
148
-     * @param EE_Maintenance_Mode|null $maintenance_mode
149
-     * @return EE_System
150
-     */
151
-    public static function instance(
152
-        EE_Registry $registry = null,
153
-        LoaderInterface $loader = null,
154
-        RequestInterface $request = null,
155
-        EE_Maintenance_Mode $maintenance_mode = null
156
-    ) {
157
-        // check if class object is instantiated
158
-        if (! self::$_instance instanceof EE_System) {
159
-            self::$_instance = new self($registry, $loader, $request, $maintenance_mode);
160
-        }
161
-        return self::$_instance;
162
-    }
163
-
164
-
165
-    /**
166
-     * resets the instance and returns it
167
-     *
168
-     * @return EE_System
169
-     */
170
-    public static function reset()
171
-    {
172
-        self::$_instance->_req_type = null;
173
-        // make sure none of the old hooks are left hanging around
174
-        remove_all_actions('AHEE__EE_System__perform_activations_upgrades_and_migrations');
175
-        // we need to reset the migration manager in order for it to detect DMSs properly
176
-        EE_Data_Migration_Manager::reset();
177
-        self::instance()->detect_activations_or_upgrades();
178
-        self::instance()->perform_activations_upgrades_and_migrations();
179
-        return self::instance();
180
-    }
181
-
182
-
183
-    /**
184
-     * sets hooks for running rest of system
185
-     * provides "AHEE__EE_System__construct__complete" hook for EE Addons to use as their starting point
186
-     * starting EE Addons from any other point may lead to problems
187
-     *
188
-     * @param EE_Registry         $registry
189
-     * @param LoaderInterface     $loader
190
-     * @param RequestInterface    $request
191
-     * @param EE_Maintenance_Mode $maintenance_mode
192
-     */
193
-    private function __construct(
194
-        EE_Registry $registry,
195
-        LoaderInterface $loader,
196
-        RequestInterface $request,
197
-        EE_Maintenance_Mode $maintenance_mode
198
-    ) {
199
-        $this->registry = $registry;
200
-        $this->loader = $loader;
201
-        $this->request = $request;
202
-        $this->maintenance_mode = $maintenance_mode;
203
-        do_action('AHEE__EE_System__construct__begin', $this);
204
-        add_action(
205
-            'AHEE__EE_Bootstrap__load_espresso_addons',
206
-            array($this, 'loadCapabilities'),
207
-            5
208
-        );
209
-        add_action(
210
-            'AHEE__EE_Bootstrap__load_espresso_addons',
211
-            array($this, 'loadCommandBus'),
212
-            7
213
-        );
214
-        add_action(
215
-            'AHEE__EE_Bootstrap__load_espresso_addons',
216
-            array($this, 'loadPluginApi'),
217
-            9
218
-        );
219
-        // allow addons to load first so that they can register autoloaders, set hooks for running DMS's, etc
220
-        add_action(
221
-            'AHEE__EE_Bootstrap__load_espresso_addons',
222
-            array($this, 'load_espresso_addons')
223
-        );
224
-        // when an ee addon is activated, we want to call the core hook(s) again
225
-        // because the newly-activated addon didn't get a chance to run at all
226
-        add_action('activate_plugin', array($this, 'load_espresso_addons'), 1);
227
-        // detect whether install or upgrade
228
-        add_action(
229
-            'AHEE__EE_Bootstrap__detect_activations_or_upgrades',
230
-            array($this, 'detect_activations_or_upgrades'),
231
-            3
232
-        );
233
-        // load EE_Config, EE_Textdomain, etc
234
-        add_action(
235
-            'AHEE__EE_Bootstrap__load_core_configuration',
236
-            array($this, 'load_core_configuration'),
237
-            5
238
-        );
239
-        // load specifications for matching routes to current request
240
-        add_action(
241
-            'AHEE__EE_Bootstrap__load_core_configuration',
242
-            array($this, 'loadRouteMatchSpecifications')
243
-        );
244
-        // load specifications for custom post types
245
-        add_action(
246
-            'AHEE__EE_Bootstrap__load_core_configuration',
247
-            array($this, 'loadCustomPostTypes')
248
-        );
249
-        // load EE_Config, EE_Textdomain, etc
250
-        add_action(
251
-            'AHEE__EE_Bootstrap__register_shortcodes_modules_and_widgets',
252
-            array($this, 'register_shortcodes_modules_and_widgets'),
253
-            7
254
-        );
255
-        // you wanna get going? I wanna get going... let's get going!
256
-        add_action(
257
-            'AHEE__EE_Bootstrap__brew_espresso',
258
-            array($this, 'brew_espresso'),
259
-            9
260
-        );
261
-        // other housekeeping
262
-        // exclude EE critical pages from wp_list_pages
263
-        add_filter(
264
-            'wp_list_pages_excludes',
265
-            array($this, 'remove_pages_from_wp_list_pages'),
266
-            10
267
-        );
268
-        // ALL EE Addons should use the following hook point to attach their initial setup too
269
-        // it's extremely important for EE Addons to register any class autoloaders so that they can be available when the EE_Config loads
270
-        do_action('AHEE__EE_System__construct__complete', $this);
271
-    }
272
-
273
-
274
-    /**
275
-     * load and setup EE_Capabilities
276
-     *
277
-     * @return void
278
-     * @throws EE_Error
279
-     */
280
-    public function loadCapabilities()
281
-    {
282
-        $this->capabilities = $this->loader->getShared('EE_Capabilities');
283
-        add_action(
284
-            'AHEE__EE_Capabilities__init_caps__before_initialization',
285
-            function () {
286
-                LoaderFactory::getLoader()->getShared('EE_Payment_Method_Manager');
287
-            }
288
-        );
289
-    }
290
-
291
-
292
-    /**
293
-     * create and cache the CommandBus, and also add middleware
294
-     * The CapChecker middleware requires the use of EE_Capabilities
295
-     * which is why we need to load the CommandBus after Caps are set up
296
-     *
297
-     * @return void
298
-     * @throws EE_Error
299
-     */
300
-    public function loadCommandBus()
301
-    {
302
-        $this->loader->getShared(
303
-            'CommandBusInterface',
304
-            array(
305
-                null,
306
-                apply_filters(
307
-                    'FHEE__EE_Load_Espresso_Core__handle_request__CommandBus_middleware',
308
-                    array(
309
-                        $this->loader->getShared('EventEspresso\core\services\commands\middleware\CapChecker'),
310
-                        $this->loader->getShared('EventEspresso\core\services\commands\middleware\AddActionHook'),
311
-                    )
312
-                ),
313
-            )
314
-        );
315
-    }
316
-
317
-
318
-    /**
319
-     * @return void
320
-     * @throws EE_Error
321
-     */
322
-    public function loadPluginApi()
323
-    {
324
-        // set autoloaders for all of the classes implementing EEI_Plugin_API
325
-        // which provide helpers for EE plugin authors to more easily register certain components with EE.
326
-        EEH_Autoloader::instance()->register_autoloaders_for_each_file_in_folder(EE_LIBRARIES . 'plugin_api');
327
-    }
328
-
329
-
330
-    /**
331
-     * @param string $addon_name
332
-     * @param string $version_constant
333
-     * @param string $min_version_required
334
-     * @param string $load_callback
335
-     * @param string $plugin_file_constant
336
-     * @return void
337
-     */
338
-    private function deactivateIncompatibleAddon(
339
-        $addon_name,
340
-        $version_constant,
341
-        $min_version_required,
342
-        $load_callback,
343
-        $plugin_file_constant
344
-    ) {
345
-        if (! defined($version_constant)) {
346
-            return;
347
-        }
348
-        $addon_version = constant($version_constant);
349
-        if ($addon_version && version_compare($addon_version, $min_version_required, '<')) {
350
-            remove_action('AHEE__EE_System__load_espresso_addons', $load_callback);
351
-            if (! function_exists('deactivate_plugins')) {
352
-                require_once ABSPATH . 'wp-admin/includes/plugin.php';
353
-            }
354
-            deactivate_plugins(plugin_basename(constant($plugin_file_constant)));
355
-            $this->request->unSetRequestParams(['activate', 'activate-multi'], true);
356
-            EE_Error::add_error(
357
-                sprintf(
358
-                    esc_html__(
359
-                        'We\'re sorry, but the Event Espresso %1$s addon was deactivated because version %2$s or higher is required with this version of Event Espresso core.',
360
-                        'event_espresso'
361
-                    ),
362
-                    $addon_name,
363
-                    $min_version_required
364
-                ),
365
-                __FILE__,
366
-                __FUNCTION__ . "({$addon_name})",
367
-                __LINE__
368
-            );
369
-            EE_Error::get_notices(false, true);
370
-        }
371
-    }
372
-
373
-
374
-    /**
375
-     * load_espresso_addons
376
-     * allow addons to load first so that they can set hooks for running DMS's, etc
377
-     * this is hooked into both:
378
-     *    'AHEE__EE_Bootstrap__load_core_configuration'
379
-     *        which runs during the WP 'plugins_loaded' action at priority 5
380
-     *    and the WP 'activate_plugin' hook point
381
-     *
382
-     * @access public
383
-     * @return void
384
-     */
385
-    public function load_espresso_addons()
386
-    {
387
-        $this->deactivateIncompatibleAddon(
388
-            'Wait Lists',
389
-            'EE_WAIT_LISTS_VERSION',
390
-            '1.0.0.beta.074',
391
-            'load_espresso_wait_lists',
392
-            'EE_WAIT_LISTS_PLUGIN_FILE'
393
-        );
394
-        $this->deactivateIncompatibleAddon(
395
-            'Automated Upcoming Event Notifications',
396
-            'EE_AUTOMATED_UPCOMING_EVENT_NOTIFICATION_VERSION',
397
-            '1.0.0.beta.091',
398
-            'load_espresso_automated_upcoming_event_notification',
399
-            'EE_AUTOMATED_UPCOMING_EVENT_NOTIFICATION_PLUGIN_FILE'
400
-        );
401
-        do_action('AHEE__EE_System__load_espresso_addons');
402
-        // if the WP API basic auth plugin isn't already loaded, load it now.
403
-        // We want it for mobile apps. Just include the entire plugin
404
-        // also, don't load the basic auth when a plugin is getting activated, because
405
-        // it could be the basic auth plugin, and it doesn't check if its methods are already defined
406
-        // and causes a fatal error
407
-        if (
408
-            ($this->request->isWordPressApi() || $this->request->isApi())
409
-            && $this->request->getRequestParam('activate') !== 'true'
410
-            && ! function_exists('json_basic_auth_handler')
411
-            && ! function_exists('json_basic_auth_error')
412
-            && ! in_array(
413
-                $this->request->getRequestParam('action'),
414
-                array('activate', 'activate-selected'),
415
-                true
416
-            )
417
-        ) {
418
-            include_once EE_THIRD_PARTY . 'wp-api-basic-auth/basic-auth.php';
419
-        }
420
-        do_action('AHEE__EE_System__load_espresso_addons__complete');
421
-    }
422
-
423
-
424
-    /**
425
-     * detect_activations_or_upgrades
426
-     * Checks for activation or upgrade of core first;
427
-     * then also checks if any registered addons have been activated or upgraded
428
-     * This is hooked into 'AHEE__EE_Bootstrap__detect_activations_or_upgrades'
429
-     * which runs during the WP 'plugins_loaded' action at priority 3
430
-     *
431
-     * @access public
432
-     * @return void
433
-     */
434
-    public function detect_activations_or_upgrades()
435
-    {
436
-        // first off: let's make sure to handle core
437
-        $this->detect_if_activation_or_upgrade();
438
-        foreach ($this->registry->addons as $addon) {
439
-            if ($addon instanceof EE_Addon) {
440
-                // detect teh request type for that addon
441
-                $addon->detect_req_type();
442
-            }
443
-        }
444
-    }
445
-
446
-
447
-    /**
448
-     * detect_if_activation_or_upgrade
449
-     * Takes care of detecting whether this is a brand new install or code upgrade,
450
-     * and either setting up the DB or setting up maintenance mode etc.
451
-     *
452
-     * @access public
453
-     * @return void
454
-     */
455
-    public function detect_if_activation_or_upgrade()
456
-    {
457
-        do_action('AHEE__EE_System___detect_if_activation_or_upgrade__begin');
458
-        // check if db has been updated, or if its a brand-new installation
459
-        $espresso_db_update = $this->fix_espresso_db_upgrade_option();
460
-        $request_type = $this->detect_req_type($espresso_db_update);
461
-        // EEH_Debug_Tools::printr( $request_type, '$request_type', __FILE__, __LINE__ );
462
-        switch ($request_type) {
463
-            case EE_System::req_type_new_activation:
464
-                do_action('AHEE__EE_System__detect_if_activation_or_upgrade__new_activation');
465
-                $this->_handle_core_version_change($espresso_db_update);
466
-                break;
467
-            case EE_System::req_type_reactivation:
468
-                do_action('AHEE__EE_System__detect_if_activation_or_upgrade__reactivation');
469
-                $this->_handle_core_version_change($espresso_db_update);
470
-                break;
471
-            case EE_System::req_type_upgrade:
472
-                do_action('AHEE__EE_System__detect_if_activation_or_upgrade__upgrade');
473
-                // migrations may be required now that we've upgraded
474
-                $this->maintenance_mode->set_maintenance_mode_if_db_old();
475
-                $this->_handle_core_version_change($espresso_db_update);
476
-                break;
477
-            case EE_System::req_type_downgrade:
478
-                do_action('AHEE__EE_System__detect_if_activation_or_upgrade__downgrade');
479
-                // its possible migrations are no longer required
480
-                $this->maintenance_mode->set_maintenance_mode_if_db_old();
481
-                $this->_handle_core_version_change($espresso_db_update);
482
-                break;
483
-            case EE_System::req_type_normal:
484
-            default:
485
-                break;
486
-        }
487
-        do_action('AHEE__EE_System__detect_if_activation_or_upgrade__complete');
488
-    }
489
-
490
-
491
-    /**
492
-     * Updates the list of installed versions and sets hooks for
493
-     * initializing the database later during the request
494
-     *
495
-     * @param array $espresso_db_update
496
-     */
497
-    private function _handle_core_version_change($espresso_db_update)
498
-    {
499
-        $this->update_list_of_installed_versions($espresso_db_update);
500
-        // get ready to verify the DB is ok (provided we aren't in maintenance mode, of course)
501
-        add_action(
502
-            'AHEE__EE_System__perform_activations_upgrades_and_migrations',
503
-            array($this, 'initialize_db_if_no_migrations_required')
504
-        );
505
-    }
506
-
507
-
508
-    /**
509
-     * standardizes the wp option 'espresso_db_upgrade' which actually stores
510
-     * information about what versions of EE have been installed and activated,
511
-     * NOT necessarily the state of the database
512
-     *
513
-     * @param mixed $espresso_db_update           the value of the WordPress option.
514
-     *                                            If not supplied, fetches it from the options table
515
-     * @return array the correct value of 'espresso_db_upgrade', after saving it, if it needed correction
516
-     */
517
-    private function fix_espresso_db_upgrade_option($espresso_db_update = null)
518
-    {
519
-        do_action('FHEE__EE_System__manage_fix_espresso_db_upgrade_option__begin', $espresso_db_update);
520
-        if (! $espresso_db_update) {
521
-            $espresso_db_update = get_option('espresso_db_update');
522
-        }
523
-        // check that option is an array
524
-        if (! is_array($espresso_db_update)) {
525
-            // if option is FALSE, then it never existed
526
-            if ($espresso_db_update === false) {
527
-                // make $espresso_db_update an array and save option with autoload OFF
528
-                $espresso_db_update = array();
529
-                add_option('espresso_db_update', $espresso_db_update, '', 'no');
530
-            } else {
531
-                // option is NOT FALSE but also is NOT an array, so make it an array and save it
532
-                $espresso_db_update = array($espresso_db_update => array());
533
-                update_option('espresso_db_update', $espresso_db_update);
534
-            }
535
-        } else {
536
-            $corrected_db_update = array();
537
-            // if IS an array, but is it an array where KEYS are version numbers, and values are arrays?
538
-            foreach ($espresso_db_update as $should_be_version_string => $should_be_array) {
539
-                if (is_int($should_be_version_string) && ! is_array($should_be_array)) {
540
-                    // the key is an int, and the value IS NOT an array
541
-                    // so it must be numerically-indexed, where values are versions installed...
542
-                    // fix it!
543
-                    $version_string = $should_be_array;
544
-                    $corrected_db_update[ $version_string ] = array('unknown-date');
545
-                } else {
546
-                    // ok it checks out
547
-                    $corrected_db_update[ $should_be_version_string ] = $should_be_array;
548
-                }
549
-            }
550
-            $espresso_db_update = $corrected_db_update;
551
-            update_option('espresso_db_update', $espresso_db_update);
552
-        }
553
-        do_action('FHEE__EE_System__manage_fix_espresso_db_upgrade_option__complete', $espresso_db_update);
554
-        return $espresso_db_update;
555
-    }
556
-
557
-
558
-    /**
559
-     * Does the traditional work of setting up the plugin's database and adding default data.
560
-     * If migration script/process did not exist, this is what would happen on every activation/reactivation/upgrade.
561
-     * NOTE: if we're in maintenance mode (which would be the case if we detect there are data
562
-     * migration scripts that need to be run and a version change happens), enqueues core for database initialization,
563
-     * so that it will be done when migrations are finished
564
-     *
565
-     * @param boolean $initialize_addons_too if true, we double-check addons' database tables etc too;
566
-     * @param boolean $verify_schema         if true will re-check the database tables have the correct schema.
567
-     *                                       This is a resource-intensive job
568
-     *                                       so we prefer to only do it when necessary
569
-     * @return void
570
-     * @throws EE_Error
571
-     */
572
-    public function initialize_db_if_no_migrations_required($initialize_addons_too = false, $verify_schema = true)
573
-    {
574
-        $request_type = $this->detect_req_type();
575
-        // only initialize system if we're not in maintenance mode.
576
-        if ($this->maintenance_mode->level() !== EE_Maintenance_Mode::level_2_complete_maintenance) {
577
-            /** @var EventEspresso\core\domain\services\custom_post_types\RewriteRules $rewrite_rules */
578
-            $rewrite_rules = $this->loader->getShared(
579
-                'EventEspresso\core\domain\services\custom_post_types\RewriteRules'
580
-            );
581
-            $rewrite_rules->flush();
582
-            if ($verify_schema) {
583
-                EEH_Activation::initialize_db_and_folders();
584
-            }
585
-            EEH_Activation::initialize_db_content();
586
-            EEH_Activation::system_initialization();
587
-            if ($initialize_addons_too) {
588
-                $this->initialize_addons();
589
-            }
590
-        } else {
591
-            EE_Data_Migration_Manager::instance()->enqueue_db_initialization_for('Core');
592
-        }
593
-        if (
594
-            $request_type === EE_System::req_type_new_activation
595
-            || $request_type === EE_System::req_type_reactivation
596
-            || (
597
-                $request_type === EE_System::req_type_upgrade
598
-                && $this->is_major_version_change()
599
-            )
600
-        ) {
601
-            add_action('AHEE__EE_System__initialize_last', array($this, 'redirect_to_about_ee'), 9);
602
-        }
603
-    }
604
-
605
-
606
-    /**
607
-     * Initializes the db for all registered addons
608
-     *
609
-     * @throws EE_Error
610
-     */
611
-    public function initialize_addons()
612
-    {
613
-        // foreach registered addon, make sure its db is up-to-date too
614
-        foreach ($this->registry->addons as $addon) {
615
-            if ($addon instanceof EE_Addon) {
616
-                $addon->initialize_db_if_no_migrations_required();
617
-            }
618
-        }
619
-    }
620
-
621
-
622
-    /**
623
-     * Adds the current code version to the saved wp option which stores a list of all ee versions ever installed.
624
-     *
625
-     * @param    array  $version_history
626
-     * @param    string $current_version_to_add version to be added to the version history
627
-     * @return    boolean success as to whether or not this option was changed
628
-     */
629
-    public function update_list_of_installed_versions($version_history = null, $current_version_to_add = null)
630
-    {
631
-        if (! $version_history) {
632
-            $version_history = $this->fix_espresso_db_upgrade_option($version_history);
633
-        }
634
-        if ($current_version_to_add === null) {
635
-            $current_version_to_add = espresso_version();
636
-        }
637
-        $version_history[ $current_version_to_add ][] = date('Y-m-d H:i:s', time());
638
-        // re-save
639
-        return update_option('espresso_db_update', $version_history);
640
-    }
641
-
642
-
643
-    /**
644
-     * Detects if the current version indicated in the has existed in the list of
645
-     * previously-installed versions of EE (espresso_db_update). Does NOT modify it (ie, no side-effect)
646
-     *
647
-     * @param array $espresso_db_update array from the wp option stored under the name 'espresso_db_update'.
648
-     *                                  If not supplied, fetches it from the options table.
649
-     *                                  Also, caches its result so later parts of the code can also know whether
650
-     *                                  there's been an update or not. This way we can add the current version to
651
-     *                                  espresso_db_update, but still know if this is a new install or not
652
-     * @return int one of the constants on EE_System::req_type_
653
-     */
654
-    public function detect_req_type($espresso_db_update = null)
655
-    {
656
-        if ($this->_req_type === null) {
657
-            $espresso_db_update = ! empty($espresso_db_update)
658
-                ? $espresso_db_update
659
-                : $this->fix_espresso_db_upgrade_option();
660
-            $this->_req_type = EE_System::detect_req_type_given_activation_history(
661
-                $espresso_db_update,
662
-                'ee_espresso_activation',
663
-                espresso_version()
664
-            );
665
-            $this->_major_version_change = $this->_detect_major_version_change($espresso_db_update);
666
-            $this->request->setIsActivation($this->_req_type !== EE_System::req_type_normal);
667
-        }
668
-        return $this->_req_type;
669
-    }
670
-
671
-
672
-    /**
673
-     * Returns whether or not there was a non-micro version change (ie, change in either
674
-     * the first or second number in the version. Eg 4.9.0.rc.001 to 4.10.0.rc.000,
675
-     * but not 4.9.0.rc.0001 to 4.9.1.rc.0001
676
-     *
677
-     * @param $activation_history
678
-     * @return bool
679
-     */
680
-    private function _detect_major_version_change($activation_history)
681
-    {
682
-        $previous_version = EE_System::_get_most_recently_active_version_from_activation_history($activation_history);
683
-        $previous_version_parts = explode('.', $previous_version);
684
-        $current_version_parts = explode('.', espresso_version());
685
-        return isset($previous_version_parts[0], $previous_version_parts[1], $current_version_parts[0], $current_version_parts[1])
686
-               && ($previous_version_parts[0] !== $current_version_parts[0]
687
-                   || $previous_version_parts[1] !== $current_version_parts[1]
688
-               );
689
-    }
690
-
691
-
692
-    /**
693
-     * Returns true if either the major or minor version of EE changed during this request.
694
-     * Eg 4.9.0.rc.001 to 4.10.0.rc.000, but not 4.9.0.rc.0001 to 4.9.1.rc.0001
695
-     *
696
-     * @return bool
697
-     */
698
-    public function is_major_version_change()
699
-    {
700
-        return $this->_major_version_change;
701
-    }
702
-
703
-
704
-    /**
705
-     * Determines the request type for any ee addon, given three piece of info: the current array of activation
706
-     * histories (for core that' 'espresso_db_update' wp option); the name of the WordPress option which is temporarily
707
-     * set upon activation of the plugin (for core it's 'ee_espresso_activation'); and the version that this plugin was
708
-     * just activated to (for core that will always be espresso_version())
709
-     *
710
-     * @param array  $activation_history_for_addon     the option's value which stores the activation history for this
711
-     *                                                 ee plugin. for core that's 'espresso_db_update'
712
-     * @param string $activation_indicator_option_name the name of the WordPress option that is temporarily set to
713
-     *                                                 indicate that this plugin was just activated
714
-     * @param string $version_to_upgrade_to            the version that was just upgraded to (for core that will be
715
-     *                                                 espresso_version())
716
-     * @return int one of the constants on EE_System::req_type_*
717
-     */
718
-    public static function detect_req_type_given_activation_history(
719
-        $activation_history_for_addon,
720
-        $activation_indicator_option_name,
721
-        $version_to_upgrade_to
722
-    ) {
723
-        $version_is_higher = self::_new_version_is_higher($activation_history_for_addon, $version_to_upgrade_to);
724
-        if ($activation_history_for_addon) {
725
-            // it exists, so this isn't a completely new install
726
-            // check if this version already in that list of previously installed versions
727
-            if (! isset($activation_history_for_addon[ $version_to_upgrade_to ])) {
728
-                // it a version we haven't seen before
729
-                if ($version_is_higher === 1) {
730
-                    $req_type = EE_System::req_type_upgrade;
731
-                } else {
732
-                    $req_type = EE_System::req_type_downgrade;
733
-                }
734
-                delete_option($activation_indicator_option_name);
735
-            } else {
736
-                // its not an update. maybe a reactivation?
737
-                if (get_option($activation_indicator_option_name, false)) {
738
-                    if ($version_is_higher === -1) {
739
-                        $req_type = EE_System::req_type_downgrade;
740
-                    } elseif ($version_is_higher === 0) {
741
-                        // we've seen this version before, but it's an activation. must be a reactivation
742
-                        $req_type = EE_System::req_type_reactivation;
743
-                    } else {// $version_is_higher === 1
744
-                        $req_type = EE_System::req_type_upgrade;
745
-                    }
746
-                    delete_option($activation_indicator_option_name);
747
-                } else {
748
-                    // we've seen this version before and the activation indicate doesn't show it was just activated
749
-                    if ($version_is_higher === -1) {
750
-                        $req_type = EE_System::req_type_downgrade;
751
-                    } elseif ($version_is_higher === 0) {
752
-                        // we've seen this version before and it's not an activation. its normal request
753
-                        $req_type = EE_System::req_type_normal;
754
-                    } else {// $version_is_higher === 1
755
-                        $req_type = EE_System::req_type_upgrade;
756
-                    }
757
-                }
758
-            }
759
-        } else {
760
-            // brand new install
761
-            $req_type = EE_System::req_type_new_activation;
762
-            delete_option($activation_indicator_option_name);
763
-        }
764
-        return $req_type;
765
-    }
766
-
767
-
768
-    /**
769
-     * Detects if the $version_to_upgrade_to is higher than the most recent version in
770
-     * the $activation_history_for_addon
771
-     *
772
-     * @param array  $activation_history_for_addon (keys are versions, values are arrays of times activated,
773
-     *                                             sometimes containing 'unknown-date'
774
-     * @param string $version_to_upgrade_to        (current version)
775
-     * @return int results of version_compare( $version_to_upgrade_to, $most_recently_active_version ).
776
-     *                                             ie, -1 if $version_to_upgrade_to is LOWER (downgrade);
777
-     *                                             0 if $version_to_upgrade_to MATCHES (reactivation or normal request);
778
-     *                                             1 if $version_to_upgrade_to is HIGHER (upgrade) ;
779
-     */
780
-    private static function _new_version_is_higher($activation_history_for_addon, $version_to_upgrade_to)
781
-    {
782
-        // find the most recently-activated version
783
-        $most_recently_active_version =
784
-            EE_System::_get_most_recently_active_version_from_activation_history($activation_history_for_addon);
785
-        return version_compare($version_to_upgrade_to, $most_recently_active_version);
786
-    }
787
-
788
-
789
-    /**
790
-     * Gets the most recently active version listed in the activation history,
791
-     * and if none are found (ie, it's a brand new install) returns '0.0.0.dev.000'.
792
-     *
793
-     * @param array $activation_history  (keys are versions, values are arrays of times activated,
794
-     *                                   sometimes containing 'unknown-date'
795
-     * @return string
796
-     */
797
-    private static function _get_most_recently_active_version_from_activation_history($activation_history)
798
-    {
799
-        $most_recently_active_version_activation = '1970-01-01 00:00:00';
800
-        $most_recently_active_version = '0.0.0.dev.000';
801
-        if (is_array($activation_history)) {
802
-            foreach ($activation_history as $version => $times_activated) {
803
-                // check there is a record of when this version was activated. Otherwise,
804
-                // mark it as unknown
805
-                if (! $times_activated) {
806
-                    $times_activated = array('unknown-date');
807
-                }
808
-                if (is_string($times_activated)) {
809
-                    $times_activated = array($times_activated);
810
-                }
811
-                foreach ($times_activated as $an_activation) {
812
-                    if (
813
-                        $an_activation !== 'unknown-date'
814
-                        && $an_activation
815
-                           > $most_recently_active_version_activation
816
-                    ) {
817
-                        $most_recently_active_version = $version;
818
-                        $most_recently_active_version_activation = $an_activation === 'unknown-date'
819
-                            ? '1970-01-01 00:00:00'
820
-                            : $an_activation;
821
-                    }
822
-                }
823
-            }
824
-        }
825
-        return $most_recently_active_version;
826
-    }
827
-
828
-
829
-    /**
830
-     * This redirects to the about EE page after activation
831
-     *
832
-     * @return void
833
-     */
834
-    public function redirect_to_about_ee()
835
-    {
836
-        $notices = EE_Error::get_notices(false);
837
-        // if current user is an admin and it's not an ajax or rest request
838
-        if (
839
-            ! isset($notices['errors'])
840
-            && $this->request->isAdmin()
841
-            && apply_filters(
842
-                'FHEE__EE_System__redirect_to_about_ee__do_redirect',
843
-                $this->capabilities->current_user_can('manage_options', 'espresso_about_default')
844
-            )
845
-        ) {
846
-            $query_params = array('page' => 'espresso_about');
847
-            if (EE_System::instance()->detect_req_type() === EE_System::req_type_new_activation) {
848
-                $query_params['new_activation'] = true;
849
-            }
850
-            if (EE_System::instance()->detect_req_type() === EE_System::req_type_reactivation) {
851
-                $query_params['reactivation'] = true;
852
-            }
853
-            $url = add_query_arg($query_params, admin_url('admin.php'));
854
-            wp_safe_redirect($url);
855
-            exit();
856
-        }
857
-    }
858
-
859
-
860
-    /**
861
-     * load_core_configuration
862
-     * this is hooked into 'AHEE__EE_Bootstrap__load_core_configuration'
863
-     * which runs during the WP 'plugins_loaded' action at priority 5
864
-     *
865
-     * @return void
866
-     * @throws ReflectionException
867
-     * @throws Exception
868
-     */
869
-    public function load_core_configuration()
870
-    {
871
-        do_action('AHEE__EE_System__load_core_configuration__begin', $this);
872
-        $this->loader->getShared('EE_Load_Textdomain');
873
-        // load textdomain
874
-        EE_Load_Textdomain::load_textdomain();
875
-        // load caf stuff a chance to play during the activation process too.
876
-        $this->_maybe_brew_regular();
877
-        // load and setup EE_Config and EE_Network_Config
878
-        $config = $this->loader->getShared('EE_Config');
879
-        $this->loader->getShared('EE_Network_Config');
880
-        // setup autoloaders
881
-        // enable logging?
882
-        if ($config->admin->use_remote_logging) {
883
-            $this->loader->getShared('EE_Log');
884
-        }
885
-        // check for activation errors
886
-        $activation_errors = get_option('ee_plugin_activation_errors', false);
887
-        if ($activation_errors) {
888
-            EE_Error::add_error($activation_errors, __FILE__, __FUNCTION__, __LINE__);
889
-            update_option('ee_plugin_activation_errors', false);
890
-        }
891
-        // get model names
892
-        $this->_parse_model_names();
893
-        // configure custom post type definitions
894
-        $this->loader->getShared('EventEspresso\core\domain\entities\custom_post_types\CustomTaxonomyDefinitions');
895
-        $this->loader->getShared('EventEspresso\core\domain\entities\custom_post_types\CustomPostTypeDefinitions');
896
-        do_action('AHEE__EE_System__load_core_configuration__complete', $this);
897
-    }
898
-
899
-
900
-    /**
901
-     * cycles through all of the models/*.model.php files, and assembles an array of model names
902
-     *
903
-     * @return void
904
-     * @throws ReflectionException
905
-     */
906
-    private function _parse_model_names()
907
-    {
908
-        // get all the files in the EE_MODELS folder that end in .model.php
909
-        $models = glob(EE_MODELS . '*.model.php');
910
-        $model_names = array();
911
-        $non_abstract_db_models = array();
912
-        foreach ($models as $model) {
913
-            // get model classname
914
-            $classname = EEH_File::get_classname_from_filepath_with_standard_filename($model);
915
-            $short_name = str_replace('EEM_', '', $classname);
916
-            $reflectionClass = new ReflectionClass($classname);
917
-            if ($reflectionClass->isSubclassOf('EEM_Base') && ! $reflectionClass->isAbstract()) {
918
-                $non_abstract_db_models[ $short_name ] = $classname;
919
-            }
920
-            $model_names[ $short_name ] = $classname;
921
-        }
922
-        $this->registry->models = apply_filters('FHEE__EE_System__parse_model_names', $model_names);
923
-        $this->registry->non_abstract_db_models = apply_filters(
924
-            'FHEE__EE_System__parse_implemented_model_names',
925
-            $non_abstract_db_models
926
-        );
927
-    }
928
-
929
-
930
-    /**
931
-     * The purpose of this method is to simply check for a file named "caffeinated/brewing_regular.php" for any hooks
932
-     * that need to be setup before our EE_System launches.
933
-     *
934
-     * @return void
935
-     * @throws DomainException
936
-     * @throws InvalidArgumentException
937
-     * @throws InvalidDataTypeException
938
-     * @throws InvalidInterfaceException
939
-     * @throws InvalidClassException
940
-     * @throws InvalidFilePathException
941
-     */
942
-    private function _maybe_brew_regular()
943
-    {
944
-        /** @var Domain $domain */
945
-        $domain = DomainFactory::getShared(
946
-            new FullyQualifiedName(
947
-                'EventEspresso\core\domain\Domain'
948
-            ),
949
-            array(
950
-                new FilePath(EVENT_ESPRESSO_MAIN_FILE),
951
-                Version::fromString(espresso_version()),
952
-            )
953
-        );
954
-        if ($domain->isCaffeinated()) {
955
-            require_once EE_CAFF_PATH . 'brewing_regular.php';
956
-        }
957
-    }
958
-
959
-
960
-    /**
961
-     * @since 4.9.71.p
962
-     * @throws Exception
963
-     */
964
-    public function loadRouteMatchSpecifications()
965
-    {
966
-        try {
967
-            $this->loader->getShared(
968
-                'EventEspresso\core\services\route_match\RouteMatchSpecificationManager'
969
-            );
970
-        } catch (Exception $exception) {
971
-            new ExceptionStackTraceDisplay($exception);
972
-        }
973
-        do_action('AHEE__EE_System__loadRouteMatchSpecifications');
974
-    }
975
-
976
-
977
-    /**
978
-     * loading CPT related classes earlier so that their definitions are available
979
-     * but not performing any actual registration with WP core until load_CPTs_and_session() is called
980
-     *
981
-     * @since   4.10.21.p
982
-     */
983
-    public function loadCustomPostTypes()
984
-    {
985
-        $this->register_custom_taxonomies = $this->loader->getShared(
986
-            'EventEspresso\core\domain\services\custom_post_types\RegisterCustomTaxonomies'
987
-        );
988
-        $this->register_custom_post_types = $this->loader->getShared(
989
-            'EventEspresso\core\domain\services\custom_post_types\RegisterCustomPostTypes'
990
-        );
991
-        $this->register_custom_taxonomy_terms = $this->loader->getShared(
992
-            'EventEspresso\core\domain\services\custom_post_types\RegisterCustomTaxonomyTerms'
993
-        );
994
-        // integrate WP_Query with the EE models
995
-        $this->loader->getShared('EE_CPT_Strategy');
996
-        // load legacy EE_Request_Handler in case add-ons still need it
997
-        $this->loader->getShared('EE_Request_Handler');
998
-    }
999
-
1000
-
1001
-    /**
1002
-     * register_shortcodes_modules_and_widgets
1003
-     * generate lists of shortcodes and modules, then verify paths and classes
1004
-     * This is hooked into 'AHEE__EE_Bootstrap__register_shortcodes_modules_and_widgets'
1005
-     * which runs during the WP 'plugins_loaded' action at priority 7
1006
-     *
1007
-     * @access public
1008
-     * @return void
1009
-     * @throws Exception
1010
-     */
1011
-    public function register_shortcodes_modules_and_widgets()
1012
-    {
1013
-        if ($this->request->isFrontend() || $this->request->isIframe() || $this->request->isAjax()) {
1014
-            // load, register, and add shortcodes the new way
1015
-            $this->loader->getShared('EventEspresso\core\services\shortcodes\ShortcodesManager');
1016
-        }
1017
-        do_action('AHEE__EE_System__register_shortcodes_modules_and_widgets');
1018
-        // check for addons using old hook point
1019
-        if (has_action('AHEE__EE_System__register_shortcodes_modules_and_addons')) {
1020
-            $this->_incompatible_addon_error();
1021
-        }
1022
-    }
1023
-
1024
-
1025
-    /**
1026
-     * _incompatible_addon_error
1027
-     *
1028
-     * @access public
1029
-     * @return void
1030
-     */
1031
-    private function _incompatible_addon_error()
1032
-    {
1033
-        // get array of classes hooking into here
1034
-        $class_names = EEH_Class_Tools::get_class_names_for_all_callbacks_on_hook(
1035
-            'AHEE__EE_System__register_shortcodes_modules_and_addons'
1036
-        );
1037
-        if (! empty($class_names)) {
1038
-            $msg = esc_html__(
1039
-                'The following plugins, addons, or modules appear to be incompatible with this version of Event Espresso and were automatically deactivated to avoid fatal errors:',
1040
-                'event_espresso'
1041
-            );
1042
-            $msg .= '<ul>';
1043
-            foreach ($class_names as $class_name) {
1044
-                $msg .= '<li><b>Event Espresso - '
1045
-                        . str_replace(
1046
-                            array('EE_', 'EEM_', 'EED_', 'EES_', 'EEW_'),
1047
-                            '',
1048
-                            $class_name
1049
-                        ) . '</b></li>';
1050
-            }
1051
-            $msg .= '</ul>';
1052
-            $msg .= esc_html__(
1053
-                'Compatibility issues can be avoided and/or resolved by keeping addons and plugins updated to the latest version.',
1054
-                'event_espresso'
1055
-            );
1056
-            // save list of incompatible addons to wp-options for later use
1057
-            add_option('ee_incompatible_addons', $class_names, '', 'no');
1058
-            if (is_admin()) {
1059
-                EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
1060
-            }
1061
-        }
1062
-    }
1063
-
1064
-
1065
-    /**
1066
-     * brew_espresso
1067
-     * begins the process of setting hooks for initializing EE in the correct order
1068
-     * This is happening on the 'AHEE__EE_Bootstrap__brew_espresso' hook point
1069
-     * which runs during the WP 'plugins_loaded' action at priority 9
1070
-     *
1071
-     * @return void
1072
-     */
1073
-    public function brew_espresso()
1074
-    {
1075
-        do_action('AHEE__EE_System__brew_espresso__begin', $this);
1076
-        // load some final core systems
1077
-        add_action('init', array($this, 'set_hooks_for_core'), 1);
1078
-        add_action('init', array($this, 'perform_activations_upgrades_and_migrations'), 3);
1079
-        add_action('init', array($this, 'load_CPTs_and_session'), 5);
1080
-        add_action('init', array($this, 'load_controllers'), 7);
1081
-        add_action('init', array($this, 'core_loaded_and_ready'), 9);
1082
-        add_action('init', array($this, 'initialize'), 10);
1083
-        add_action('init', array($this, 'initialize_last'), 100);
1084
-        if (is_admin() && apply_filters('FHEE__EE_System__brew_espresso__load_pue', true)) {
1085
-            // pew pew pew
1086
-            $this->loader->getShared('EventEspresso\core\services\licensing\LicenseService');
1087
-            do_action('AHEE__EE_System__brew_espresso__after_pue_init');
1088
-        }
1089
-        do_action('AHEE__EE_System__brew_espresso__complete', $this);
1090
-    }
1091
-
1092
-
1093
-    /**
1094
-     *    set_hooks_for_core
1095
-     *
1096
-     * @access public
1097
-     * @return    void
1098
-     * @throws EE_Error
1099
-     */
1100
-    public function set_hooks_for_core()
1101
-    {
1102
-        $this->_deactivate_incompatible_addons();
1103
-        do_action('AHEE__EE_System__set_hooks_for_core');
1104
-        $this->loader->getShared('EventEspresso\core\domain\values\session\SessionLifespan');
1105
-        // caps need to be initialized on every request so that capability maps are set.
1106
-        // @see https://events.codebasehq.com/projects/event-espresso/tickets/8674
1107
-        $this->registry->CAP->init_caps();
1108
-    }
1109
-
1110
-
1111
-    /**
1112
-     * Using the information gathered in EE_System::_incompatible_addon_error,
1113
-     * deactivates any addons considered incompatible with the current version of EE
1114
-     */
1115
-    private function _deactivate_incompatible_addons()
1116
-    {
1117
-        $incompatible_addons = get_option('ee_incompatible_addons', array());
1118
-        if (! empty($incompatible_addons)) {
1119
-            $active_plugins = get_option('active_plugins', array());
1120
-            foreach ($active_plugins as $active_plugin) {
1121
-                foreach ($incompatible_addons as $incompatible_addon) {
1122
-                    if (strpos($active_plugin, $incompatible_addon) !== false) {
1123
-                        $this->request->unSetRequestParams(['activate'], true);
1124
-                        espresso_deactivate_plugin($active_plugin);
1125
-                    }
1126
-                }
1127
-            }
1128
-        }
1129
-    }
1130
-
1131
-
1132
-    /**
1133
-     *    perform_activations_upgrades_and_migrations
1134
-     *
1135
-     * @access public
1136
-     * @return    void
1137
-     */
1138
-    public function perform_activations_upgrades_and_migrations()
1139
-    {
1140
-        do_action('AHEE__EE_System__perform_activations_upgrades_and_migrations');
1141
-    }
1142
-
1143
-
1144
-    /**
1145
-     * @return void
1146
-     * @throws DomainException
1147
-     */
1148
-    public function load_CPTs_and_session()
1149
-    {
1150
-        do_action('AHEE__EE_System__load_CPTs_and_session__start');
1151
-        $this->register_custom_taxonomies->registerCustomTaxonomies();
1152
-        $this->register_custom_post_types->registerCustomPostTypes();
1153
-        $this->register_custom_taxonomy_terms->registerCustomTaxonomyTerms();
1154
-        // load legacy Custom Post Types and Taxonomies
1155
-        $this->loader->getShared('EE_Register_CPTs');
1156
-        do_action('AHEE__EE_System__load_CPTs_and_session__complete');
1157
-    }
1158
-
1159
-
1160
-    /**
1161
-     * load_controllers
1162
-     * this is the best place to load any additional controllers that needs access to EE core.
1163
-     * it is expected that all basic core EE systems, that are not dependant on the current request are loaded at this
1164
-     * time
1165
-     *
1166
-     * @access public
1167
-     * @return void
1168
-     */
1169
-    public function load_controllers()
1170
-    {
1171
-        do_action('AHEE__EE_System__load_controllers__start');
1172
-        // let's get it started
1173
-        if (
1174
-            ! $this->maintenance_mode->level()
1175
-            && ($this->request->isFrontend() || $this->request->isFrontAjax())
1176
-        ) {
1177
-            do_action('AHEE__EE_System__load_controllers__load_front_controllers');
1178
-            $this->loader->getShared('EE_Front_Controller');
1179
-        } elseif ($this->request->isAdmin() || $this->request->isAdminAjax()) {
1180
-            do_action('AHEE__EE_System__load_controllers__load_admin_controllers');
1181
-            $this->loader->getShared('EE_Admin');
1182
-        } elseif ($this->request->isWordPressHeartbeat()) {
1183
-            $this->loader->getShared('EventEspresso\core\domain\services\admin\ajax\WordpressHeartbeat');
1184
-        }
1185
-        do_action('AHEE__EE_System__load_controllers__complete');
1186
-    }
1187
-
1188
-
1189
-    /**
1190
-     * core_loaded_and_ready
1191
-     * all of the basic EE core should be loaded at this point and available regardless of M-Mode
1192
-     *
1193
-     * @access public
1194
-     * @return void
1195
-     * @throws Exception
1196
-     */
1197
-    public function core_loaded_and_ready()
1198
-    {
1199
-        if (
1200
-            $this->request->isAdmin()
1201
-            || $this->request->isFrontend()
1202
-            || $this->request->isIframe()
1203
-            || $this->request->isWordPressApi()
1204
-        ) {
1205
-            try {
1206
-                $this->loader->getShared('EventEspresso\core\services\assets\Registry');
1207
-                $this->loader->getShared('EventEspresso\core\domain\services\assets\CoreAssetManager');
1208
-                if ($this->canLoadBlocks()) {
1209
-                    $this->loader->getShared(
1210
-                        'EventEspresso\core\services\editor\BlockRegistrationManager'
1211
-                    );
1212
-                }
1213
-            } catch (Exception $exception) {
1214
-                new ExceptionStackTraceDisplay($exception);
1215
-            }
1216
-        }
1217
-        if (
1218
-            $this->request->isAdmin()
1219
-            || $this->request->isEeAjax()
1220
-            || $this->request->isFrontend()
1221
-        ) {
1222
-            $this->loader->getShared('EE_Session');
1223
-        }
1224
-        do_action('AHEE__EE_System__core_loaded_and_ready');
1225
-        // always load template tags, because it's faster than checking if it's a front-end request, and many page
1226
-        // builders require these even on the front-end
1227
-        require_once EE_PUBLIC . 'template_tags.php';
1228
-        do_action('AHEE__EE_System__set_hooks_for_shortcodes_modules_and_addons');
1229
-    }
1230
-
1231
-
1232
-    /**
1233
-     * initialize
1234
-     * this is the best place to begin initializing client code
1235
-     *
1236
-     * @access public
1237
-     * @return void
1238
-     */
1239
-    public function initialize()
1240
-    {
1241
-        do_action('AHEE__EE_System__initialize');
1242
-        add_filter(
1243
-            'safe_style_css',
1244
-            function ($styles) {
1245
-                $styles[] = 'display';
1246
-                $styles[] = 'visibility';
1247
-                $styles[] = 'position';
1248
-                $styles[] = 'top';
1249
-                $styles[] = 'right';
1250
-                $styles[] = 'bottom';
1251
-                $styles[] = 'left';
1252
-                $styles[] = 'resize';
1253
-                $styles[] = 'max-width';
1254
-                $styles[] = 'max-height';
1255
-                return $styles;
1256
-            }
1257
-        );
1258
-    }
1259
-
1260
-
1261
-    /**
1262
-     * initialize_last
1263
-     * this is run really late during the WP init hook point, and ensures that mostly everything else that needs to
1264
-     * initialize has done so
1265
-     *
1266
-     * @access public
1267
-     * @return void
1268
-     */
1269
-    public function initialize_last()
1270
-    {
1271
-        do_action('AHEE__EE_System__initialize_last');
1272
-        /** @var EventEspresso\core\domain\services\custom_post_types\RewriteRules $rewrite_rules */
1273
-        $rewrite_rules = $this->loader->getShared(
1274
-            'EventEspresso\core\domain\services\custom_post_types\RewriteRules'
1275
-        );
1276
-        $rewrite_rules->flushRewriteRules();
1277
-        add_action('admin_bar_init', array($this, 'addEspressoToolbar'));
1278
-        if (
1279
-            ($this->request->isAjax() || $this->request->isAdmin())
1280
-            && $this->maintenance_mode->models_can_query()
1281
-        ) {
1282
-            $this->loader->getShared('EventEspresso\core\services\privacy\export\PersonalDataExporterManager');
1283
-            $this->loader->getShared('EventEspresso\core\services\privacy\erasure\PersonalDataEraserManager');
1284
-        }
1285
-    }
1286
-
1287
-
1288
-    /**
1289
-     * @return void
1290
-     * @throws EE_Error
1291
-     */
1292
-    public function addEspressoToolbar()
1293
-    {
1294
-        $this->loader->getShared(
1295
-            'EventEspresso\core\domain\services\admin\AdminToolBar',
1296
-            array($this->registry->CAP)
1297
-        );
1298
-    }
1299
-
1300
-
1301
-    /**
1302
-     * do_not_cache
1303
-     * sets no cache headers and defines no cache constants for WP plugins
1304
-     *
1305
-     * @access public
1306
-     * @return void
1307
-     */
1308
-    public static function do_not_cache()
1309
-    {
1310
-        // set no cache constants
1311
-        if (! defined('DONOTCACHEPAGE')) {
1312
-            define('DONOTCACHEPAGE', true);
1313
-        }
1314
-        if (! defined('DONOTCACHCEOBJECT')) {
1315
-            define('DONOTCACHCEOBJECT', true);
1316
-        }
1317
-        if (! defined('DONOTCACHEDB')) {
1318
-            define('DONOTCACHEDB', true);
1319
-        }
1320
-        // add no cache headers
1321
-        add_action('send_headers', array('EE_System', 'nocache_headers'), 10);
1322
-        // plus a little extra for nginx and Google Chrome
1323
-        add_filter('nocache_headers', array('EE_System', 'extra_nocache_headers'), 10, 1);
1324
-        // prevent browsers from prefetching of the rel='next' link, because it may contain content that interferes with the registration process
1325
-        remove_action('wp_head', 'adjacent_posts_rel_link_wp_head');
1326
-    }
1327
-
1328
-
1329
-    /**
1330
-     *    extra_nocache_headers
1331
-     *
1332
-     * @access    public
1333
-     * @param $headers
1334
-     * @return    array
1335
-     */
1336
-    public static function extra_nocache_headers($headers)
1337
-    {
1338
-        // for NGINX
1339
-        $headers['X-Accel-Expires'] = 0;
1340
-        // plus extra for Google Chrome since it doesn't seem to respect "no-cache", but WILL respect "no-store"
1341
-        $headers['Cache-Control'] = 'no-store, no-cache, must-revalidate, max-age=0';
1342
-        return $headers;
1343
-    }
1344
-
1345
-
1346
-    /**
1347
-     *    nocache_headers
1348
-     *
1349
-     * @access    public
1350
-     * @return    void
1351
-     */
1352
-    public static function nocache_headers()
1353
-    {
1354
-        nocache_headers();
1355
-    }
1356
-
1357
-
1358
-    /**
1359
-     * simply hooks into "wp_list_pages_exclude" filter (for wp_list_pages method) and makes sure EE critical pages are
1360
-     * never returned with the function.
1361
-     *
1362
-     * @param  array $exclude_array any existing pages being excluded are in this array.
1363
-     * @return array
1364
-     */
1365
-    public function remove_pages_from_wp_list_pages($exclude_array)
1366
-    {
1367
-        return array_merge($exclude_array, $this->registry->CFG->core->get_critical_pages_array());
1368
-    }
1369
-
1370
-
1371
-    /**
1372
-     * Return whether blocks can be registered/loaded or not.
1373
-     * @return bool
1374
-     */
1375
-    private function canLoadBlocks()
1376
-    {
1377
-        return apply_filters('FHEE__EE_System__canLoadBlocks', true)
1378
-               && function_exists('register_block_type')
1379
-               // don't load blocks if in the Divi page builder editor context
1380
-               // @see https://github.com/eventespresso/event-espresso-core/issues/814
1381
-               && ! $this->request->getRequestParam('et_fb', false);
1382
-    }
30
+	/**
31
+	 * indicates this is a 'normal' request. Ie, not activation, nor upgrade, nor activation.
32
+	 * So examples of this would be a normal GET request on the frontend or backend, or a POST, etc
33
+	 */
34
+	const req_type_normal = 0;
35
+
36
+	/**
37
+	 * Indicates this is a brand new installation of EE so we should install
38
+	 * tables and default data etc
39
+	 */
40
+	const req_type_new_activation = 1;
41
+
42
+	/**
43
+	 * we've detected that EE has been reactivated (or EE was activated during maintenance mode,
44
+	 * and we just exited maintenance mode). We MUST check the database is setup properly
45
+	 * and that default data is setup too
46
+	 */
47
+	const req_type_reactivation = 2;
48
+
49
+	/**
50
+	 * indicates that EE has been upgraded since its previous request.
51
+	 * We may have data migration scripts to call and will want to trigger maintenance mode
52
+	 */
53
+	const req_type_upgrade = 3;
54
+
55
+	/**
56
+	 * TODO  will detect that EE has been DOWNGRADED. We probably don't want to run in this case...
57
+	 */
58
+	const req_type_downgrade = 4;
59
+
60
+	/**
61
+	 * @deprecated since version 4.6.0.dev.006
62
+	 * Now whenever a new_activation is detected the request type is still just
63
+	 * new_activation (same for reactivation, upgrade, downgrade etc), but if we'r ein maintenance mode
64
+	 * EE_System::initialize_db_if_no_migrations_required and EE_Addon::initialize_db_if_no_migrations_required
65
+	 * will instead enqueue that EE plugin's db initialization for when we're taken out of maintenance mode.
66
+	 * (Specifically, when the migration manager indicates migrations are finished
67
+	 * EE_Data_Migration_Manager::initialize_db_for_enqueued_ee_plugins() will be called)
68
+	 */
69
+	const req_type_activation_but_not_installed = 5;
70
+
71
+	/**
72
+	 * option prefix for recording the activation history (like core's "espresso_db_update") of addons
73
+	 */
74
+	const addon_activation_history_option_prefix = 'ee_addon_activation_history_';
75
+
76
+	/**
77
+	 * @var EE_System $_instance
78
+	 */
79
+	private static $_instance;
80
+
81
+	/**
82
+	 * @var EE_Registry $registry
83
+	 */
84
+	private $registry;
85
+
86
+	/**
87
+	 * @var LoaderInterface $loader
88
+	 */
89
+	private $loader;
90
+
91
+	/**
92
+	 * @var EE_Capabilities $capabilities
93
+	 */
94
+	private $capabilities;
95
+
96
+	/**
97
+	 * @var RequestInterface $request
98
+	 */
99
+	private $request;
100
+
101
+	/**
102
+	 * @var EE_Maintenance_Mode $maintenance_mode
103
+	 */
104
+	private $maintenance_mode;
105
+
106
+	/**
107
+	 * Stores which type of request this is, options being one of the constants on EE_System starting with req_type_*.
108
+	 * It can be a brand-new activation, a reactivation, an upgrade, a downgrade, or a normal request.
109
+	 *
110
+	 * @var int $_req_type
111
+	 */
112
+	private $_req_type;
113
+
114
+	/**
115
+	 * Whether or not there was a non-micro version change in EE core version during this request
116
+	 *
117
+	 * @var boolean $_major_version_change
118
+	 */
119
+	private $_major_version_change = false;
120
+
121
+	/**
122
+	 * A Context DTO dedicated solely to identifying the current request type.
123
+	 *
124
+	 * @var RequestTypeContextCheckerInterface $request_type
125
+	 */
126
+	private $request_type;
127
+
128
+	/**
129
+	 * @param EventEspresso\core\domain\services\custom_post_types\RegisterCustomPostTypes
130
+	 */
131
+	private $register_custom_post_types;
132
+
133
+	/**
134
+	 * @param EventEspresso\core\domain\services\custom_post_types\RegisterCustomTaxonomies
135
+	 */
136
+	private $register_custom_taxonomies;
137
+
138
+	/**
139
+	 * @param EventEspresso\core\domain\services\custom_post_types\RegisterCustomTaxonomyTerms
140
+	 */
141
+	private $register_custom_taxonomy_terms;
142
+
143
+	/**
144
+	 * @singleton method used to instantiate class object
145
+	 * @param EE_Registry|null         $registry
146
+	 * @param LoaderInterface|null     $loader
147
+	 * @param RequestInterface|null    $request
148
+	 * @param EE_Maintenance_Mode|null $maintenance_mode
149
+	 * @return EE_System
150
+	 */
151
+	public static function instance(
152
+		EE_Registry $registry = null,
153
+		LoaderInterface $loader = null,
154
+		RequestInterface $request = null,
155
+		EE_Maintenance_Mode $maintenance_mode = null
156
+	) {
157
+		// check if class object is instantiated
158
+		if (! self::$_instance instanceof EE_System) {
159
+			self::$_instance = new self($registry, $loader, $request, $maintenance_mode);
160
+		}
161
+		return self::$_instance;
162
+	}
163
+
164
+
165
+	/**
166
+	 * resets the instance and returns it
167
+	 *
168
+	 * @return EE_System
169
+	 */
170
+	public static function reset()
171
+	{
172
+		self::$_instance->_req_type = null;
173
+		// make sure none of the old hooks are left hanging around
174
+		remove_all_actions('AHEE__EE_System__perform_activations_upgrades_and_migrations');
175
+		// we need to reset the migration manager in order for it to detect DMSs properly
176
+		EE_Data_Migration_Manager::reset();
177
+		self::instance()->detect_activations_or_upgrades();
178
+		self::instance()->perform_activations_upgrades_and_migrations();
179
+		return self::instance();
180
+	}
181
+
182
+
183
+	/**
184
+	 * sets hooks for running rest of system
185
+	 * provides "AHEE__EE_System__construct__complete" hook for EE Addons to use as their starting point
186
+	 * starting EE Addons from any other point may lead to problems
187
+	 *
188
+	 * @param EE_Registry         $registry
189
+	 * @param LoaderInterface     $loader
190
+	 * @param RequestInterface    $request
191
+	 * @param EE_Maintenance_Mode $maintenance_mode
192
+	 */
193
+	private function __construct(
194
+		EE_Registry $registry,
195
+		LoaderInterface $loader,
196
+		RequestInterface $request,
197
+		EE_Maintenance_Mode $maintenance_mode
198
+	) {
199
+		$this->registry = $registry;
200
+		$this->loader = $loader;
201
+		$this->request = $request;
202
+		$this->maintenance_mode = $maintenance_mode;
203
+		do_action('AHEE__EE_System__construct__begin', $this);
204
+		add_action(
205
+			'AHEE__EE_Bootstrap__load_espresso_addons',
206
+			array($this, 'loadCapabilities'),
207
+			5
208
+		);
209
+		add_action(
210
+			'AHEE__EE_Bootstrap__load_espresso_addons',
211
+			array($this, 'loadCommandBus'),
212
+			7
213
+		);
214
+		add_action(
215
+			'AHEE__EE_Bootstrap__load_espresso_addons',
216
+			array($this, 'loadPluginApi'),
217
+			9
218
+		);
219
+		// allow addons to load first so that they can register autoloaders, set hooks for running DMS's, etc
220
+		add_action(
221
+			'AHEE__EE_Bootstrap__load_espresso_addons',
222
+			array($this, 'load_espresso_addons')
223
+		);
224
+		// when an ee addon is activated, we want to call the core hook(s) again
225
+		// because the newly-activated addon didn't get a chance to run at all
226
+		add_action('activate_plugin', array($this, 'load_espresso_addons'), 1);
227
+		// detect whether install or upgrade
228
+		add_action(
229
+			'AHEE__EE_Bootstrap__detect_activations_or_upgrades',
230
+			array($this, 'detect_activations_or_upgrades'),
231
+			3
232
+		);
233
+		// load EE_Config, EE_Textdomain, etc
234
+		add_action(
235
+			'AHEE__EE_Bootstrap__load_core_configuration',
236
+			array($this, 'load_core_configuration'),
237
+			5
238
+		);
239
+		// load specifications for matching routes to current request
240
+		add_action(
241
+			'AHEE__EE_Bootstrap__load_core_configuration',
242
+			array($this, 'loadRouteMatchSpecifications')
243
+		);
244
+		// load specifications for custom post types
245
+		add_action(
246
+			'AHEE__EE_Bootstrap__load_core_configuration',
247
+			array($this, 'loadCustomPostTypes')
248
+		);
249
+		// load EE_Config, EE_Textdomain, etc
250
+		add_action(
251
+			'AHEE__EE_Bootstrap__register_shortcodes_modules_and_widgets',
252
+			array($this, 'register_shortcodes_modules_and_widgets'),
253
+			7
254
+		);
255
+		// you wanna get going? I wanna get going... let's get going!
256
+		add_action(
257
+			'AHEE__EE_Bootstrap__brew_espresso',
258
+			array($this, 'brew_espresso'),
259
+			9
260
+		);
261
+		// other housekeeping
262
+		// exclude EE critical pages from wp_list_pages
263
+		add_filter(
264
+			'wp_list_pages_excludes',
265
+			array($this, 'remove_pages_from_wp_list_pages'),
266
+			10
267
+		);
268
+		// ALL EE Addons should use the following hook point to attach their initial setup too
269
+		// it's extremely important for EE Addons to register any class autoloaders so that they can be available when the EE_Config loads
270
+		do_action('AHEE__EE_System__construct__complete', $this);
271
+	}
272
+
273
+
274
+	/**
275
+	 * load and setup EE_Capabilities
276
+	 *
277
+	 * @return void
278
+	 * @throws EE_Error
279
+	 */
280
+	public function loadCapabilities()
281
+	{
282
+		$this->capabilities = $this->loader->getShared('EE_Capabilities');
283
+		add_action(
284
+			'AHEE__EE_Capabilities__init_caps__before_initialization',
285
+			function () {
286
+				LoaderFactory::getLoader()->getShared('EE_Payment_Method_Manager');
287
+			}
288
+		);
289
+	}
290
+
291
+
292
+	/**
293
+	 * create and cache the CommandBus, and also add middleware
294
+	 * The CapChecker middleware requires the use of EE_Capabilities
295
+	 * which is why we need to load the CommandBus after Caps are set up
296
+	 *
297
+	 * @return void
298
+	 * @throws EE_Error
299
+	 */
300
+	public function loadCommandBus()
301
+	{
302
+		$this->loader->getShared(
303
+			'CommandBusInterface',
304
+			array(
305
+				null,
306
+				apply_filters(
307
+					'FHEE__EE_Load_Espresso_Core__handle_request__CommandBus_middleware',
308
+					array(
309
+						$this->loader->getShared('EventEspresso\core\services\commands\middleware\CapChecker'),
310
+						$this->loader->getShared('EventEspresso\core\services\commands\middleware\AddActionHook'),
311
+					)
312
+				),
313
+			)
314
+		);
315
+	}
316
+
317
+
318
+	/**
319
+	 * @return void
320
+	 * @throws EE_Error
321
+	 */
322
+	public function loadPluginApi()
323
+	{
324
+		// set autoloaders for all of the classes implementing EEI_Plugin_API
325
+		// which provide helpers for EE plugin authors to more easily register certain components with EE.
326
+		EEH_Autoloader::instance()->register_autoloaders_for_each_file_in_folder(EE_LIBRARIES . 'plugin_api');
327
+	}
328
+
329
+
330
+	/**
331
+	 * @param string $addon_name
332
+	 * @param string $version_constant
333
+	 * @param string $min_version_required
334
+	 * @param string $load_callback
335
+	 * @param string $plugin_file_constant
336
+	 * @return void
337
+	 */
338
+	private function deactivateIncompatibleAddon(
339
+		$addon_name,
340
+		$version_constant,
341
+		$min_version_required,
342
+		$load_callback,
343
+		$plugin_file_constant
344
+	) {
345
+		if (! defined($version_constant)) {
346
+			return;
347
+		}
348
+		$addon_version = constant($version_constant);
349
+		if ($addon_version && version_compare($addon_version, $min_version_required, '<')) {
350
+			remove_action('AHEE__EE_System__load_espresso_addons', $load_callback);
351
+			if (! function_exists('deactivate_plugins')) {
352
+				require_once ABSPATH . 'wp-admin/includes/plugin.php';
353
+			}
354
+			deactivate_plugins(plugin_basename(constant($plugin_file_constant)));
355
+			$this->request->unSetRequestParams(['activate', 'activate-multi'], true);
356
+			EE_Error::add_error(
357
+				sprintf(
358
+					esc_html__(
359
+						'We\'re sorry, but the Event Espresso %1$s addon was deactivated because version %2$s or higher is required with this version of Event Espresso core.',
360
+						'event_espresso'
361
+					),
362
+					$addon_name,
363
+					$min_version_required
364
+				),
365
+				__FILE__,
366
+				__FUNCTION__ . "({$addon_name})",
367
+				__LINE__
368
+			);
369
+			EE_Error::get_notices(false, true);
370
+		}
371
+	}
372
+
373
+
374
+	/**
375
+	 * load_espresso_addons
376
+	 * allow addons to load first so that they can set hooks for running DMS's, etc
377
+	 * this is hooked into both:
378
+	 *    'AHEE__EE_Bootstrap__load_core_configuration'
379
+	 *        which runs during the WP 'plugins_loaded' action at priority 5
380
+	 *    and the WP 'activate_plugin' hook point
381
+	 *
382
+	 * @access public
383
+	 * @return void
384
+	 */
385
+	public function load_espresso_addons()
386
+	{
387
+		$this->deactivateIncompatibleAddon(
388
+			'Wait Lists',
389
+			'EE_WAIT_LISTS_VERSION',
390
+			'1.0.0.beta.074',
391
+			'load_espresso_wait_lists',
392
+			'EE_WAIT_LISTS_PLUGIN_FILE'
393
+		);
394
+		$this->deactivateIncompatibleAddon(
395
+			'Automated Upcoming Event Notifications',
396
+			'EE_AUTOMATED_UPCOMING_EVENT_NOTIFICATION_VERSION',
397
+			'1.0.0.beta.091',
398
+			'load_espresso_automated_upcoming_event_notification',
399
+			'EE_AUTOMATED_UPCOMING_EVENT_NOTIFICATION_PLUGIN_FILE'
400
+		);
401
+		do_action('AHEE__EE_System__load_espresso_addons');
402
+		// if the WP API basic auth plugin isn't already loaded, load it now.
403
+		// We want it for mobile apps. Just include the entire plugin
404
+		// also, don't load the basic auth when a plugin is getting activated, because
405
+		// it could be the basic auth plugin, and it doesn't check if its methods are already defined
406
+		// and causes a fatal error
407
+		if (
408
+			($this->request->isWordPressApi() || $this->request->isApi())
409
+			&& $this->request->getRequestParam('activate') !== 'true'
410
+			&& ! function_exists('json_basic_auth_handler')
411
+			&& ! function_exists('json_basic_auth_error')
412
+			&& ! in_array(
413
+				$this->request->getRequestParam('action'),
414
+				array('activate', 'activate-selected'),
415
+				true
416
+			)
417
+		) {
418
+			include_once EE_THIRD_PARTY . 'wp-api-basic-auth/basic-auth.php';
419
+		}
420
+		do_action('AHEE__EE_System__load_espresso_addons__complete');
421
+	}
422
+
423
+
424
+	/**
425
+	 * detect_activations_or_upgrades
426
+	 * Checks for activation or upgrade of core first;
427
+	 * then also checks if any registered addons have been activated or upgraded
428
+	 * This is hooked into 'AHEE__EE_Bootstrap__detect_activations_or_upgrades'
429
+	 * which runs during the WP 'plugins_loaded' action at priority 3
430
+	 *
431
+	 * @access public
432
+	 * @return void
433
+	 */
434
+	public function detect_activations_or_upgrades()
435
+	{
436
+		// first off: let's make sure to handle core
437
+		$this->detect_if_activation_or_upgrade();
438
+		foreach ($this->registry->addons as $addon) {
439
+			if ($addon instanceof EE_Addon) {
440
+				// detect teh request type for that addon
441
+				$addon->detect_req_type();
442
+			}
443
+		}
444
+	}
445
+
446
+
447
+	/**
448
+	 * detect_if_activation_or_upgrade
449
+	 * Takes care of detecting whether this is a brand new install or code upgrade,
450
+	 * and either setting up the DB or setting up maintenance mode etc.
451
+	 *
452
+	 * @access public
453
+	 * @return void
454
+	 */
455
+	public function detect_if_activation_or_upgrade()
456
+	{
457
+		do_action('AHEE__EE_System___detect_if_activation_or_upgrade__begin');
458
+		// check if db has been updated, or if its a brand-new installation
459
+		$espresso_db_update = $this->fix_espresso_db_upgrade_option();
460
+		$request_type = $this->detect_req_type($espresso_db_update);
461
+		// EEH_Debug_Tools::printr( $request_type, '$request_type', __FILE__, __LINE__ );
462
+		switch ($request_type) {
463
+			case EE_System::req_type_new_activation:
464
+				do_action('AHEE__EE_System__detect_if_activation_or_upgrade__new_activation');
465
+				$this->_handle_core_version_change($espresso_db_update);
466
+				break;
467
+			case EE_System::req_type_reactivation:
468
+				do_action('AHEE__EE_System__detect_if_activation_or_upgrade__reactivation');
469
+				$this->_handle_core_version_change($espresso_db_update);
470
+				break;
471
+			case EE_System::req_type_upgrade:
472
+				do_action('AHEE__EE_System__detect_if_activation_or_upgrade__upgrade');
473
+				// migrations may be required now that we've upgraded
474
+				$this->maintenance_mode->set_maintenance_mode_if_db_old();
475
+				$this->_handle_core_version_change($espresso_db_update);
476
+				break;
477
+			case EE_System::req_type_downgrade:
478
+				do_action('AHEE__EE_System__detect_if_activation_or_upgrade__downgrade');
479
+				// its possible migrations are no longer required
480
+				$this->maintenance_mode->set_maintenance_mode_if_db_old();
481
+				$this->_handle_core_version_change($espresso_db_update);
482
+				break;
483
+			case EE_System::req_type_normal:
484
+			default:
485
+				break;
486
+		}
487
+		do_action('AHEE__EE_System__detect_if_activation_or_upgrade__complete');
488
+	}
489
+
490
+
491
+	/**
492
+	 * Updates the list of installed versions and sets hooks for
493
+	 * initializing the database later during the request
494
+	 *
495
+	 * @param array $espresso_db_update
496
+	 */
497
+	private function _handle_core_version_change($espresso_db_update)
498
+	{
499
+		$this->update_list_of_installed_versions($espresso_db_update);
500
+		// get ready to verify the DB is ok (provided we aren't in maintenance mode, of course)
501
+		add_action(
502
+			'AHEE__EE_System__perform_activations_upgrades_and_migrations',
503
+			array($this, 'initialize_db_if_no_migrations_required')
504
+		);
505
+	}
506
+
507
+
508
+	/**
509
+	 * standardizes the wp option 'espresso_db_upgrade' which actually stores
510
+	 * information about what versions of EE have been installed and activated,
511
+	 * NOT necessarily the state of the database
512
+	 *
513
+	 * @param mixed $espresso_db_update           the value of the WordPress option.
514
+	 *                                            If not supplied, fetches it from the options table
515
+	 * @return array the correct value of 'espresso_db_upgrade', after saving it, if it needed correction
516
+	 */
517
+	private function fix_espresso_db_upgrade_option($espresso_db_update = null)
518
+	{
519
+		do_action('FHEE__EE_System__manage_fix_espresso_db_upgrade_option__begin', $espresso_db_update);
520
+		if (! $espresso_db_update) {
521
+			$espresso_db_update = get_option('espresso_db_update');
522
+		}
523
+		// check that option is an array
524
+		if (! is_array($espresso_db_update)) {
525
+			// if option is FALSE, then it never existed
526
+			if ($espresso_db_update === false) {
527
+				// make $espresso_db_update an array and save option with autoload OFF
528
+				$espresso_db_update = array();
529
+				add_option('espresso_db_update', $espresso_db_update, '', 'no');
530
+			} else {
531
+				// option is NOT FALSE but also is NOT an array, so make it an array and save it
532
+				$espresso_db_update = array($espresso_db_update => array());
533
+				update_option('espresso_db_update', $espresso_db_update);
534
+			}
535
+		} else {
536
+			$corrected_db_update = array();
537
+			// if IS an array, but is it an array where KEYS are version numbers, and values are arrays?
538
+			foreach ($espresso_db_update as $should_be_version_string => $should_be_array) {
539
+				if (is_int($should_be_version_string) && ! is_array($should_be_array)) {
540
+					// the key is an int, and the value IS NOT an array
541
+					// so it must be numerically-indexed, where values are versions installed...
542
+					// fix it!
543
+					$version_string = $should_be_array;
544
+					$corrected_db_update[ $version_string ] = array('unknown-date');
545
+				} else {
546
+					// ok it checks out
547
+					$corrected_db_update[ $should_be_version_string ] = $should_be_array;
548
+				}
549
+			}
550
+			$espresso_db_update = $corrected_db_update;
551
+			update_option('espresso_db_update', $espresso_db_update);
552
+		}
553
+		do_action('FHEE__EE_System__manage_fix_espresso_db_upgrade_option__complete', $espresso_db_update);
554
+		return $espresso_db_update;
555
+	}
556
+
557
+
558
+	/**
559
+	 * Does the traditional work of setting up the plugin's database and adding default data.
560
+	 * If migration script/process did not exist, this is what would happen on every activation/reactivation/upgrade.
561
+	 * NOTE: if we're in maintenance mode (which would be the case if we detect there are data
562
+	 * migration scripts that need to be run and a version change happens), enqueues core for database initialization,
563
+	 * so that it will be done when migrations are finished
564
+	 *
565
+	 * @param boolean $initialize_addons_too if true, we double-check addons' database tables etc too;
566
+	 * @param boolean $verify_schema         if true will re-check the database tables have the correct schema.
567
+	 *                                       This is a resource-intensive job
568
+	 *                                       so we prefer to only do it when necessary
569
+	 * @return void
570
+	 * @throws EE_Error
571
+	 */
572
+	public function initialize_db_if_no_migrations_required($initialize_addons_too = false, $verify_schema = true)
573
+	{
574
+		$request_type = $this->detect_req_type();
575
+		// only initialize system if we're not in maintenance mode.
576
+		if ($this->maintenance_mode->level() !== EE_Maintenance_Mode::level_2_complete_maintenance) {
577
+			/** @var EventEspresso\core\domain\services\custom_post_types\RewriteRules $rewrite_rules */
578
+			$rewrite_rules = $this->loader->getShared(
579
+				'EventEspresso\core\domain\services\custom_post_types\RewriteRules'
580
+			);
581
+			$rewrite_rules->flush();
582
+			if ($verify_schema) {
583
+				EEH_Activation::initialize_db_and_folders();
584
+			}
585
+			EEH_Activation::initialize_db_content();
586
+			EEH_Activation::system_initialization();
587
+			if ($initialize_addons_too) {
588
+				$this->initialize_addons();
589
+			}
590
+		} else {
591
+			EE_Data_Migration_Manager::instance()->enqueue_db_initialization_for('Core');
592
+		}
593
+		if (
594
+			$request_type === EE_System::req_type_new_activation
595
+			|| $request_type === EE_System::req_type_reactivation
596
+			|| (
597
+				$request_type === EE_System::req_type_upgrade
598
+				&& $this->is_major_version_change()
599
+			)
600
+		) {
601
+			add_action('AHEE__EE_System__initialize_last', array($this, 'redirect_to_about_ee'), 9);
602
+		}
603
+	}
604
+
605
+
606
+	/**
607
+	 * Initializes the db for all registered addons
608
+	 *
609
+	 * @throws EE_Error
610
+	 */
611
+	public function initialize_addons()
612
+	{
613
+		// foreach registered addon, make sure its db is up-to-date too
614
+		foreach ($this->registry->addons as $addon) {
615
+			if ($addon instanceof EE_Addon) {
616
+				$addon->initialize_db_if_no_migrations_required();
617
+			}
618
+		}
619
+	}
620
+
621
+
622
+	/**
623
+	 * Adds the current code version to the saved wp option which stores a list of all ee versions ever installed.
624
+	 *
625
+	 * @param    array  $version_history
626
+	 * @param    string $current_version_to_add version to be added to the version history
627
+	 * @return    boolean success as to whether or not this option was changed
628
+	 */
629
+	public function update_list_of_installed_versions($version_history = null, $current_version_to_add = null)
630
+	{
631
+		if (! $version_history) {
632
+			$version_history = $this->fix_espresso_db_upgrade_option($version_history);
633
+		}
634
+		if ($current_version_to_add === null) {
635
+			$current_version_to_add = espresso_version();
636
+		}
637
+		$version_history[ $current_version_to_add ][] = date('Y-m-d H:i:s', time());
638
+		// re-save
639
+		return update_option('espresso_db_update', $version_history);
640
+	}
641
+
642
+
643
+	/**
644
+	 * Detects if the current version indicated in the has existed in the list of
645
+	 * previously-installed versions of EE (espresso_db_update). Does NOT modify it (ie, no side-effect)
646
+	 *
647
+	 * @param array $espresso_db_update array from the wp option stored under the name 'espresso_db_update'.
648
+	 *                                  If not supplied, fetches it from the options table.
649
+	 *                                  Also, caches its result so later parts of the code can also know whether
650
+	 *                                  there's been an update or not. This way we can add the current version to
651
+	 *                                  espresso_db_update, but still know if this is a new install or not
652
+	 * @return int one of the constants on EE_System::req_type_
653
+	 */
654
+	public function detect_req_type($espresso_db_update = null)
655
+	{
656
+		if ($this->_req_type === null) {
657
+			$espresso_db_update = ! empty($espresso_db_update)
658
+				? $espresso_db_update
659
+				: $this->fix_espresso_db_upgrade_option();
660
+			$this->_req_type = EE_System::detect_req_type_given_activation_history(
661
+				$espresso_db_update,
662
+				'ee_espresso_activation',
663
+				espresso_version()
664
+			);
665
+			$this->_major_version_change = $this->_detect_major_version_change($espresso_db_update);
666
+			$this->request->setIsActivation($this->_req_type !== EE_System::req_type_normal);
667
+		}
668
+		return $this->_req_type;
669
+	}
670
+
671
+
672
+	/**
673
+	 * Returns whether or not there was a non-micro version change (ie, change in either
674
+	 * the first or second number in the version. Eg 4.9.0.rc.001 to 4.10.0.rc.000,
675
+	 * but not 4.9.0.rc.0001 to 4.9.1.rc.0001
676
+	 *
677
+	 * @param $activation_history
678
+	 * @return bool
679
+	 */
680
+	private function _detect_major_version_change($activation_history)
681
+	{
682
+		$previous_version = EE_System::_get_most_recently_active_version_from_activation_history($activation_history);
683
+		$previous_version_parts = explode('.', $previous_version);
684
+		$current_version_parts = explode('.', espresso_version());
685
+		return isset($previous_version_parts[0], $previous_version_parts[1], $current_version_parts[0], $current_version_parts[1])
686
+			   && ($previous_version_parts[0] !== $current_version_parts[0]
687
+				   || $previous_version_parts[1] !== $current_version_parts[1]
688
+			   );
689
+	}
690
+
691
+
692
+	/**
693
+	 * Returns true if either the major or minor version of EE changed during this request.
694
+	 * Eg 4.9.0.rc.001 to 4.10.0.rc.000, but not 4.9.0.rc.0001 to 4.9.1.rc.0001
695
+	 *
696
+	 * @return bool
697
+	 */
698
+	public function is_major_version_change()
699
+	{
700
+		return $this->_major_version_change;
701
+	}
702
+
703
+
704
+	/**
705
+	 * Determines the request type for any ee addon, given three piece of info: the current array of activation
706
+	 * histories (for core that' 'espresso_db_update' wp option); the name of the WordPress option which is temporarily
707
+	 * set upon activation of the plugin (for core it's 'ee_espresso_activation'); and the version that this plugin was
708
+	 * just activated to (for core that will always be espresso_version())
709
+	 *
710
+	 * @param array  $activation_history_for_addon     the option's value which stores the activation history for this
711
+	 *                                                 ee plugin. for core that's 'espresso_db_update'
712
+	 * @param string $activation_indicator_option_name the name of the WordPress option that is temporarily set to
713
+	 *                                                 indicate that this plugin was just activated
714
+	 * @param string $version_to_upgrade_to            the version that was just upgraded to (for core that will be
715
+	 *                                                 espresso_version())
716
+	 * @return int one of the constants on EE_System::req_type_*
717
+	 */
718
+	public static function detect_req_type_given_activation_history(
719
+		$activation_history_for_addon,
720
+		$activation_indicator_option_name,
721
+		$version_to_upgrade_to
722
+	) {
723
+		$version_is_higher = self::_new_version_is_higher($activation_history_for_addon, $version_to_upgrade_to);
724
+		if ($activation_history_for_addon) {
725
+			// it exists, so this isn't a completely new install
726
+			// check if this version already in that list of previously installed versions
727
+			if (! isset($activation_history_for_addon[ $version_to_upgrade_to ])) {
728
+				// it a version we haven't seen before
729
+				if ($version_is_higher === 1) {
730
+					$req_type = EE_System::req_type_upgrade;
731
+				} else {
732
+					$req_type = EE_System::req_type_downgrade;
733
+				}
734
+				delete_option($activation_indicator_option_name);
735
+			} else {
736
+				// its not an update. maybe a reactivation?
737
+				if (get_option($activation_indicator_option_name, false)) {
738
+					if ($version_is_higher === -1) {
739
+						$req_type = EE_System::req_type_downgrade;
740
+					} elseif ($version_is_higher === 0) {
741
+						// we've seen this version before, but it's an activation. must be a reactivation
742
+						$req_type = EE_System::req_type_reactivation;
743
+					} else {// $version_is_higher === 1
744
+						$req_type = EE_System::req_type_upgrade;
745
+					}
746
+					delete_option($activation_indicator_option_name);
747
+				} else {
748
+					// we've seen this version before and the activation indicate doesn't show it was just activated
749
+					if ($version_is_higher === -1) {
750
+						$req_type = EE_System::req_type_downgrade;
751
+					} elseif ($version_is_higher === 0) {
752
+						// we've seen this version before and it's not an activation. its normal request
753
+						$req_type = EE_System::req_type_normal;
754
+					} else {// $version_is_higher === 1
755
+						$req_type = EE_System::req_type_upgrade;
756
+					}
757
+				}
758
+			}
759
+		} else {
760
+			// brand new install
761
+			$req_type = EE_System::req_type_new_activation;
762
+			delete_option($activation_indicator_option_name);
763
+		}
764
+		return $req_type;
765
+	}
766
+
767
+
768
+	/**
769
+	 * Detects if the $version_to_upgrade_to is higher than the most recent version in
770
+	 * the $activation_history_for_addon
771
+	 *
772
+	 * @param array  $activation_history_for_addon (keys are versions, values are arrays of times activated,
773
+	 *                                             sometimes containing 'unknown-date'
774
+	 * @param string $version_to_upgrade_to        (current version)
775
+	 * @return int results of version_compare( $version_to_upgrade_to, $most_recently_active_version ).
776
+	 *                                             ie, -1 if $version_to_upgrade_to is LOWER (downgrade);
777
+	 *                                             0 if $version_to_upgrade_to MATCHES (reactivation or normal request);
778
+	 *                                             1 if $version_to_upgrade_to is HIGHER (upgrade) ;
779
+	 */
780
+	private static function _new_version_is_higher($activation_history_for_addon, $version_to_upgrade_to)
781
+	{
782
+		// find the most recently-activated version
783
+		$most_recently_active_version =
784
+			EE_System::_get_most_recently_active_version_from_activation_history($activation_history_for_addon);
785
+		return version_compare($version_to_upgrade_to, $most_recently_active_version);
786
+	}
787
+
788
+
789
+	/**
790
+	 * Gets the most recently active version listed in the activation history,
791
+	 * and if none are found (ie, it's a brand new install) returns '0.0.0.dev.000'.
792
+	 *
793
+	 * @param array $activation_history  (keys are versions, values are arrays of times activated,
794
+	 *                                   sometimes containing 'unknown-date'
795
+	 * @return string
796
+	 */
797
+	private static function _get_most_recently_active_version_from_activation_history($activation_history)
798
+	{
799
+		$most_recently_active_version_activation = '1970-01-01 00:00:00';
800
+		$most_recently_active_version = '0.0.0.dev.000';
801
+		if (is_array($activation_history)) {
802
+			foreach ($activation_history as $version => $times_activated) {
803
+				// check there is a record of when this version was activated. Otherwise,
804
+				// mark it as unknown
805
+				if (! $times_activated) {
806
+					$times_activated = array('unknown-date');
807
+				}
808
+				if (is_string($times_activated)) {
809
+					$times_activated = array($times_activated);
810
+				}
811
+				foreach ($times_activated as $an_activation) {
812
+					if (
813
+						$an_activation !== 'unknown-date'
814
+						&& $an_activation
815
+						   > $most_recently_active_version_activation
816
+					) {
817
+						$most_recently_active_version = $version;
818
+						$most_recently_active_version_activation = $an_activation === 'unknown-date'
819
+							? '1970-01-01 00:00:00'
820
+							: $an_activation;
821
+					}
822
+				}
823
+			}
824
+		}
825
+		return $most_recently_active_version;
826
+	}
827
+
828
+
829
+	/**
830
+	 * This redirects to the about EE page after activation
831
+	 *
832
+	 * @return void
833
+	 */
834
+	public function redirect_to_about_ee()
835
+	{
836
+		$notices = EE_Error::get_notices(false);
837
+		// if current user is an admin and it's not an ajax or rest request
838
+		if (
839
+			! isset($notices['errors'])
840
+			&& $this->request->isAdmin()
841
+			&& apply_filters(
842
+				'FHEE__EE_System__redirect_to_about_ee__do_redirect',
843
+				$this->capabilities->current_user_can('manage_options', 'espresso_about_default')
844
+			)
845
+		) {
846
+			$query_params = array('page' => 'espresso_about');
847
+			if (EE_System::instance()->detect_req_type() === EE_System::req_type_new_activation) {
848
+				$query_params['new_activation'] = true;
849
+			}
850
+			if (EE_System::instance()->detect_req_type() === EE_System::req_type_reactivation) {
851
+				$query_params['reactivation'] = true;
852
+			}
853
+			$url = add_query_arg($query_params, admin_url('admin.php'));
854
+			wp_safe_redirect($url);
855
+			exit();
856
+		}
857
+	}
858
+
859
+
860
+	/**
861
+	 * load_core_configuration
862
+	 * this is hooked into 'AHEE__EE_Bootstrap__load_core_configuration'
863
+	 * which runs during the WP 'plugins_loaded' action at priority 5
864
+	 *
865
+	 * @return void
866
+	 * @throws ReflectionException
867
+	 * @throws Exception
868
+	 */
869
+	public function load_core_configuration()
870
+	{
871
+		do_action('AHEE__EE_System__load_core_configuration__begin', $this);
872
+		$this->loader->getShared('EE_Load_Textdomain');
873
+		// load textdomain
874
+		EE_Load_Textdomain::load_textdomain();
875
+		// load caf stuff a chance to play during the activation process too.
876
+		$this->_maybe_brew_regular();
877
+		// load and setup EE_Config and EE_Network_Config
878
+		$config = $this->loader->getShared('EE_Config');
879
+		$this->loader->getShared('EE_Network_Config');
880
+		// setup autoloaders
881
+		// enable logging?
882
+		if ($config->admin->use_remote_logging) {
883
+			$this->loader->getShared('EE_Log');
884
+		}
885
+		// check for activation errors
886
+		$activation_errors = get_option('ee_plugin_activation_errors', false);
887
+		if ($activation_errors) {
888
+			EE_Error::add_error($activation_errors, __FILE__, __FUNCTION__, __LINE__);
889
+			update_option('ee_plugin_activation_errors', false);
890
+		}
891
+		// get model names
892
+		$this->_parse_model_names();
893
+		// configure custom post type definitions
894
+		$this->loader->getShared('EventEspresso\core\domain\entities\custom_post_types\CustomTaxonomyDefinitions');
895
+		$this->loader->getShared('EventEspresso\core\domain\entities\custom_post_types\CustomPostTypeDefinitions');
896
+		do_action('AHEE__EE_System__load_core_configuration__complete', $this);
897
+	}
898
+
899
+
900
+	/**
901
+	 * cycles through all of the models/*.model.php files, and assembles an array of model names
902
+	 *
903
+	 * @return void
904
+	 * @throws ReflectionException
905
+	 */
906
+	private function _parse_model_names()
907
+	{
908
+		// get all the files in the EE_MODELS folder that end in .model.php
909
+		$models = glob(EE_MODELS . '*.model.php');
910
+		$model_names = array();
911
+		$non_abstract_db_models = array();
912
+		foreach ($models as $model) {
913
+			// get model classname
914
+			$classname = EEH_File::get_classname_from_filepath_with_standard_filename($model);
915
+			$short_name = str_replace('EEM_', '', $classname);
916
+			$reflectionClass = new ReflectionClass($classname);
917
+			if ($reflectionClass->isSubclassOf('EEM_Base') && ! $reflectionClass->isAbstract()) {
918
+				$non_abstract_db_models[ $short_name ] = $classname;
919
+			}
920
+			$model_names[ $short_name ] = $classname;
921
+		}
922
+		$this->registry->models = apply_filters('FHEE__EE_System__parse_model_names', $model_names);
923
+		$this->registry->non_abstract_db_models = apply_filters(
924
+			'FHEE__EE_System__parse_implemented_model_names',
925
+			$non_abstract_db_models
926
+		);
927
+	}
928
+
929
+
930
+	/**
931
+	 * The purpose of this method is to simply check for a file named "caffeinated/brewing_regular.php" for any hooks
932
+	 * that need to be setup before our EE_System launches.
933
+	 *
934
+	 * @return void
935
+	 * @throws DomainException
936
+	 * @throws InvalidArgumentException
937
+	 * @throws InvalidDataTypeException
938
+	 * @throws InvalidInterfaceException
939
+	 * @throws InvalidClassException
940
+	 * @throws InvalidFilePathException
941
+	 */
942
+	private function _maybe_brew_regular()
943
+	{
944
+		/** @var Domain $domain */
945
+		$domain = DomainFactory::getShared(
946
+			new FullyQualifiedName(
947
+				'EventEspresso\core\domain\Domain'
948
+			),
949
+			array(
950
+				new FilePath(EVENT_ESPRESSO_MAIN_FILE),
951
+				Version::fromString(espresso_version()),
952
+			)
953
+		);
954
+		if ($domain->isCaffeinated()) {
955
+			require_once EE_CAFF_PATH . 'brewing_regular.php';
956
+		}
957
+	}
958
+
959
+
960
+	/**
961
+	 * @since 4.9.71.p
962
+	 * @throws Exception
963
+	 */
964
+	public function loadRouteMatchSpecifications()
965
+	{
966
+		try {
967
+			$this->loader->getShared(
968
+				'EventEspresso\core\services\route_match\RouteMatchSpecificationManager'
969
+			);
970
+		} catch (Exception $exception) {
971
+			new ExceptionStackTraceDisplay($exception);
972
+		}
973
+		do_action('AHEE__EE_System__loadRouteMatchSpecifications');
974
+	}
975
+
976
+
977
+	/**
978
+	 * loading CPT related classes earlier so that their definitions are available
979
+	 * but not performing any actual registration with WP core until load_CPTs_and_session() is called
980
+	 *
981
+	 * @since   4.10.21.p
982
+	 */
983
+	public function loadCustomPostTypes()
984
+	{
985
+		$this->register_custom_taxonomies = $this->loader->getShared(
986
+			'EventEspresso\core\domain\services\custom_post_types\RegisterCustomTaxonomies'
987
+		);
988
+		$this->register_custom_post_types = $this->loader->getShared(
989
+			'EventEspresso\core\domain\services\custom_post_types\RegisterCustomPostTypes'
990
+		);
991
+		$this->register_custom_taxonomy_terms = $this->loader->getShared(
992
+			'EventEspresso\core\domain\services\custom_post_types\RegisterCustomTaxonomyTerms'
993
+		);
994
+		// integrate WP_Query with the EE models
995
+		$this->loader->getShared('EE_CPT_Strategy');
996
+		// load legacy EE_Request_Handler in case add-ons still need it
997
+		$this->loader->getShared('EE_Request_Handler');
998
+	}
999
+
1000
+
1001
+	/**
1002
+	 * register_shortcodes_modules_and_widgets
1003
+	 * generate lists of shortcodes and modules, then verify paths and classes
1004
+	 * This is hooked into 'AHEE__EE_Bootstrap__register_shortcodes_modules_and_widgets'
1005
+	 * which runs during the WP 'plugins_loaded' action at priority 7
1006
+	 *
1007
+	 * @access public
1008
+	 * @return void
1009
+	 * @throws Exception
1010
+	 */
1011
+	public function register_shortcodes_modules_and_widgets()
1012
+	{
1013
+		if ($this->request->isFrontend() || $this->request->isIframe() || $this->request->isAjax()) {
1014
+			// load, register, and add shortcodes the new way
1015
+			$this->loader->getShared('EventEspresso\core\services\shortcodes\ShortcodesManager');
1016
+		}
1017
+		do_action('AHEE__EE_System__register_shortcodes_modules_and_widgets');
1018
+		// check for addons using old hook point
1019
+		if (has_action('AHEE__EE_System__register_shortcodes_modules_and_addons')) {
1020
+			$this->_incompatible_addon_error();
1021
+		}
1022
+	}
1023
+
1024
+
1025
+	/**
1026
+	 * _incompatible_addon_error
1027
+	 *
1028
+	 * @access public
1029
+	 * @return void
1030
+	 */
1031
+	private function _incompatible_addon_error()
1032
+	{
1033
+		// get array of classes hooking into here
1034
+		$class_names = EEH_Class_Tools::get_class_names_for_all_callbacks_on_hook(
1035
+			'AHEE__EE_System__register_shortcodes_modules_and_addons'
1036
+		);
1037
+		if (! empty($class_names)) {
1038
+			$msg = esc_html__(
1039
+				'The following plugins, addons, or modules appear to be incompatible with this version of Event Espresso and were automatically deactivated to avoid fatal errors:',
1040
+				'event_espresso'
1041
+			);
1042
+			$msg .= '<ul>';
1043
+			foreach ($class_names as $class_name) {
1044
+				$msg .= '<li><b>Event Espresso - '
1045
+						. str_replace(
1046
+							array('EE_', 'EEM_', 'EED_', 'EES_', 'EEW_'),
1047
+							'',
1048
+							$class_name
1049
+						) . '</b></li>';
1050
+			}
1051
+			$msg .= '</ul>';
1052
+			$msg .= esc_html__(
1053
+				'Compatibility issues can be avoided and/or resolved by keeping addons and plugins updated to the latest version.',
1054
+				'event_espresso'
1055
+			);
1056
+			// save list of incompatible addons to wp-options for later use
1057
+			add_option('ee_incompatible_addons', $class_names, '', 'no');
1058
+			if (is_admin()) {
1059
+				EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
1060
+			}
1061
+		}
1062
+	}
1063
+
1064
+
1065
+	/**
1066
+	 * brew_espresso
1067
+	 * begins the process of setting hooks for initializing EE in the correct order
1068
+	 * This is happening on the 'AHEE__EE_Bootstrap__brew_espresso' hook point
1069
+	 * which runs during the WP 'plugins_loaded' action at priority 9
1070
+	 *
1071
+	 * @return void
1072
+	 */
1073
+	public function brew_espresso()
1074
+	{
1075
+		do_action('AHEE__EE_System__brew_espresso__begin', $this);
1076
+		// load some final core systems
1077
+		add_action('init', array($this, 'set_hooks_for_core'), 1);
1078
+		add_action('init', array($this, 'perform_activations_upgrades_and_migrations'), 3);
1079
+		add_action('init', array($this, 'load_CPTs_and_session'), 5);
1080
+		add_action('init', array($this, 'load_controllers'), 7);
1081
+		add_action('init', array($this, 'core_loaded_and_ready'), 9);
1082
+		add_action('init', array($this, 'initialize'), 10);
1083
+		add_action('init', array($this, 'initialize_last'), 100);
1084
+		if (is_admin() && apply_filters('FHEE__EE_System__brew_espresso__load_pue', true)) {
1085
+			// pew pew pew
1086
+			$this->loader->getShared('EventEspresso\core\services\licensing\LicenseService');
1087
+			do_action('AHEE__EE_System__brew_espresso__after_pue_init');
1088
+		}
1089
+		do_action('AHEE__EE_System__brew_espresso__complete', $this);
1090
+	}
1091
+
1092
+
1093
+	/**
1094
+	 *    set_hooks_for_core
1095
+	 *
1096
+	 * @access public
1097
+	 * @return    void
1098
+	 * @throws EE_Error
1099
+	 */
1100
+	public function set_hooks_for_core()
1101
+	{
1102
+		$this->_deactivate_incompatible_addons();
1103
+		do_action('AHEE__EE_System__set_hooks_for_core');
1104
+		$this->loader->getShared('EventEspresso\core\domain\values\session\SessionLifespan');
1105
+		// caps need to be initialized on every request so that capability maps are set.
1106
+		// @see https://events.codebasehq.com/projects/event-espresso/tickets/8674
1107
+		$this->registry->CAP->init_caps();
1108
+	}
1109
+
1110
+
1111
+	/**
1112
+	 * Using the information gathered in EE_System::_incompatible_addon_error,
1113
+	 * deactivates any addons considered incompatible with the current version of EE
1114
+	 */
1115
+	private function _deactivate_incompatible_addons()
1116
+	{
1117
+		$incompatible_addons = get_option('ee_incompatible_addons', array());
1118
+		if (! empty($incompatible_addons)) {
1119
+			$active_plugins = get_option('active_plugins', array());
1120
+			foreach ($active_plugins as $active_plugin) {
1121
+				foreach ($incompatible_addons as $incompatible_addon) {
1122
+					if (strpos($active_plugin, $incompatible_addon) !== false) {
1123
+						$this->request->unSetRequestParams(['activate'], true);
1124
+						espresso_deactivate_plugin($active_plugin);
1125
+					}
1126
+				}
1127
+			}
1128
+		}
1129
+	}
1130
+
1131
+
1132
+	/**
1133
+	 *    perform_activations_upgrades_and_migrations
1134
+	 *
1135
+	 * @access public
1136
+	 * @return    void
1137
+	 */
1138
+	public function perform_activations_upgrades_and_migrations()
1139
+	{
1140
+		do_action('AHEE__EE_System__perform_activations_upgrades_and_migrations');
1141
+	}
1142
+
1143
+
1144
+	/**
1145
+	 * @return void
1146
+	 * @throws DomainException
1147
+	 */
1148
+	public function load_CPTs_and_session()
1149
+	{
1150
+		do_action('AHEE__EE_System__load_CPTs_and_session__start');
1151
+		$this->register_custom_taxonomies->registerCustomTaxonomies();
1152
+		$this->register_custom_post_types->registerCustomPostTypes();
1153
+		$this->register_custom_taxonomy_terms->registerCustomTaxonomyTerms();
1154
+		// load legacy Custom Post Types and Taxonomies
1155
+		$this->loader->getShared('EE_Register_CPTs');
1156
+		do_action('AHEE__EE_System__load_CPTs_and_session__complete');
1157
+	}
1158
+
1159
+
1160
+	/**
1161
+	 * load_controllers
1162
+	 * this is the best place to load any additional controllers that needs access to EE core.
1163
+	 * it is expected that all basic core EE systems, that are not dependant on the current request are loaded at this
1164
+	 * time
1165
+	 *
1166
+	 * @access public
1167
+	 * @return void
1168
+	 */
1169
+	public function load_controllers()
1170
+	{
1171
+		do_action('AHEE__EE_System__load_controllers__start');
1172
+		// let's get it started
1173
+		if (
1174
+			! $this->maintenance_mode->level()
1175
+			&& ($this->request->isFrontend() || $this->request->isFrontAjax())
1176
+		) {
1177
+			do_action('AHEE__EE_System__load_controllers__load_front_controllers');
1178
+			$this->loader->getShared('EE_Front_Controller');
1179
+		} elseif ($this->request->isAdmin() || $this->request->isAdminAjax()) {
1180
+			do_action('AHEE__EE_System__load_controllers__load_admin_controllers');
1181
+			$this->loader->getShared('EE_Admin');
1182
+		} elseif ($this->request->isWordPressHeartbeat()) {
1183
+			$this->loader->getShared('EventEspresso\core\domain\services\admin\ajax\WordpressHeartbeat');
1184
+		}
1185
+		do_action('AHEE__EE_System__load_controllers__complete');
1186
+	}
1187
+
1188
+
1189
+	/**
1190
+	 * core_loaded_and_ready
1191
+	 * all of the basic EE core should be loaded at this point and available regardless of M-Mode
1192
+	 *
1193
+	 * @access public
1194
+	 * @return void
1195
+	 * @throws Exception
1196
+	 */
1197
+	public function core_loaded_and_ready()
1198
+	{
1199
+		if (
1200
+			$this->request->isAdmin()
1201
+			|| $this->request->isFrontend()
1202
+			|| $this->request->isIframe()
1203
+			|| $this->request->isWordPressApi()
1204
+		) {
1205
+			try {
1206
+				$this->loader->getShared('EventEspresso\core\services\assets\Registry');
1207
+				$this->loader->getShared('EventEspresso\core\domain\services\assets\CoreAssetManager');
1208
+				if ($this->canLoadBlocks()) {
1209
+					$this->loader->getShared(
1210
+						'EventEspresso\core\services\editor\BlockRegistrationManager'
1211
+					);
1212
+				}
1213
+			} catch (Exception $exception) {
1214
+				new ExceptionStackTraceDisplay($exception);
1215
+			}
1216
+		}
1217
+		if (
1218
+			$this->request->isAdmin()
1219
+			|| $this->request->isEeAjax()
1220
+			|| $this->request->isFrontend()
1221
+		) {
1222
+			$this->loader->getShared('EE_Session');
1223
+		}
1224
+		do_action('AHEE__EE_System__core_loaded_and_ready');
1225
+		// always load template tags, because it's faster than checking if it's a front-end request, and many page
1226
+		// builders require these even on the front-end
1227
+		require_once EE_PUBLIC . 'template_tags.php';
1228
+		do_action('AHEE__EE_System__set_hooks_for_shortcodes_modules_and_addons');
1229
+	}
1230
+
1231
+
1232
+	/**
1233
+	 * initialize
1234
+	 * this is the best place to begin initializing client code
1235
+	 *
1236
+	 * @access public
1237
+	 * @return void
1238
+	 */
1239
+	public function initialize()
1240
+	{
1241
+		do_action('AHEE__EE_System__initialize');
1242
+		add_filter(
1243
+			'safe_style_css',
1244
+			function ($styles) {
1245
+				$styles[] = 'display';
1246
+				$styles[] = 'visibility';
1247
+				$styles[] = 'position';
1248
+				$styles[] = 'top';
1249
+				$styles[] = 'right';
1250
+				$styles[] = 'bottom';
1251
+				$styles[] = 'left';
1252
+				$styles[] = 'resize';
1253
+				$styles[] = 'max-width';
1254
+				$styles[] = 'max-height';
1255
+				return $styles;
1256
+			}
1257
+		);
1258
+	}
1259
+
1260
+
1261
+	/**
1262
+	 * initialize_last
1263
+	 * this is run really late during the WP init hook point, and ensures that mostly everything else that needs to
1264
+	 * initialize has done so
1265
+	 *
1266
+	 * @access public
1267
+	 * @return void
1268
+	 */
1269
+	public function initialize_last()
1270
+	{
1271
+		do_action('AHEE__EE_System__initialize_last');
1272
+		/** @var EventEspresso\core\domain\services\custom_post_types\RewriteRules $rewrite_rules */
1273
+		$rewrite_rules = $this->loader->getShared(
1274
+			'EventEspresso\core\domain\services\custom_post_types\RewriteRules'
1275
+		);
1276
+		$rewrite_rules->flushRewriteRules();
1277
+		add_action('admin_bar_init', array($this, 'addEspressoToolbar'));
1278
+		if (
1279
+			($this->request->isAjax() || $this->request->isAdmin())
1280
+			&& $this->maintenance_mode->models_can_query()
1281
+		) {
1282
+			$this->loader->getShared('EventEspresso\core\services\privacy\export\PersonalDataExporterManager');
1283
+			$this->loader->getShared('EventEspresso\core\services\privacy\erasure\PersonalDataEraserManager');
1284
+		}
1285
+	}
1286
+
1287
+
1288
+	/**
1289
+	 * @return void
1290
+	 * @throws EE_Error
1291
+	 */
1292
+	public function addEspressoToolbar()
1293
+	{
1294
+		$this->loader->getShared(
1295
+			'EventEspresso\core\domain\services\admin\AdminToolBar',
1296
+			array($this->registry->CAP)
1297
+		);
1298
+	}
1299
+
1300
+
1301
+	/**
1302
+	 * do_not_cache
1303
+	 * sets no cache headers and defines no cache constants for WP plugins
1304
+	 *
1305
+	 * @access public
1306
+	 * @return void
1307
+	 */
1308
+	public static function do_not_cache()
1309
+	{
1310
+		// set no cache constants
1311
+		if (! defined('DONOTCACHEPAGE')) {
1312
+			define('DONOTCACHEPAGE', true);
1313
+		}
1314
+		if (! defined('DONOTCACHCEOBJECT')) {
1315
+			define('DONOTCACHCEOBJECT', true);
1316
+		}
1317
+		if (! defined('DONOTCACHEDB')) {
1318
+			define('DONOTCACHEDB', true);
1319
+		}
1320
+		// add no cache headers
1321
+		add_action('send_headers', array('EE_System', 'nocache_headers'), 10);
1322
+		// plus a little extra for nginx and Google Chrome
1323
+		add_filter('nocache_headers', array('EE_System', 'extra_nocache_headers'), 10, 1);
1324
+		// prevent browsers from prefetching of the rel='next' link, because it may contain content that interferes with the registration process
1325
+		remove_action('wp_head', 'adjacent_posts_rel_link_wp_head');
1326
+	}
1327
+
1328
+
1329
+	/**
1330
+	 *    extra_nocache_headers
1331
+	 *
1332
+	 * @access    public
1333
+	 * @param $headers
1334
+	 * @return    array
1335
+	 */
1336
+	public static function extra_nocache_headers($headers)
1337
+	{
1338
+		// for NGINX
1339
+		$headers['X-Accel-Expires'] = 0;
1340
+		// plus extra for Google Chrome since it doesn't seem to respect "no-cache", but WILL respect "no-store"
1341
+		$headers['Cache-Control'] = 'no-store, no-cache, must-revalidate, max-age=0';
1342
+		return $headers;
1343
+	}
1344
+
1345
+
1346
+	/**
1347
+	 *    nocache_headers
1348
+	 *
1349
+	 * @access    public
1350
+	 * @return    void
1351
+	 */
1352
+	public static function nocache_headers()
1353
+	{
1354
+		nocache_headers();
1355
+	}
1356
+
1357
+
1358
+	/**
1359
+	 * simply hooks into "wp_list_pages_exclude" filter (for wp_list_pages method) and makes sure EE critical pages are
1360
+	 * never returned with the function.
1361
+	 *
1362
+	 * @param  array $exclude_array any existing pages being excluded are in this array.
1363
+	 * @return array
1364
+	 */
1365
+	public function remove_pages_from_wp_list_pages($exclude_array)
1366
+	{
1367
+		return array_merge($exclude_array, $this->registry->CFG->core->get_critical_pages_array());
1368
+	}
1369
+
1370
+
1371
+	/**
1372
+	 * Return whether blocks can be registered/loaded or not.
1373
+	 * @return bool
1374
+	 */
1375
+	private function canLoadBlocks()
1376
+	{
1377
+		return apply_filters('FHEE__EE_System__canLoadBlocks', true)
1378
+			   && function_exists('register_block_type')
1379
+			   // don't load blocks if in the Divi page builder editor context
1380
+			   // @see https://github.com/eventespresso/event-espresso-core/issues/814
1381
+			   && ! $this->request->getRequestParam('et_fb', false);
1382
+	}
1383 1383
 }
Please login to merge, or discard this patch.
Spacing   +28 added lines, -28 removed lines patch added patch discarded remove patch
@@ -155,7 +155,7 @@  discard block
 block discarded – undo
155 155
         EE_Maintenance_Mode $maintenance_mode = null
156 156
     ) {
157 157
         // check if class object is instantiated
158
-        if (! self::$_instance instanceof EE_System) {
158
+        if ( ! self::$_instance instanceof EE_System) {
159 159
             self::$_instance = new self($registry, $loader, $request, $maintenance_mode);
160 160
         }
161 161
         return self::$_instance;
@@ -282,7 +282,7 @@  discard block
 block discarded – undo
282 282
         $this->capabilities = $this->loader->getShared('EE_Capabilities');
283 283
         add_action(
284 284
             'AHEE__EE_Capabilities__init_caps__before_initialization',
285
-            function () {
285
+            function() {
286 286
                 LoaderFactory::getLoader()->getShared('EE_Payment_Method_Manager');
287 287
             }
288 288
         );
@@ -323,7 +323,7 @@  discard block
 block discarded – undo
323 323
     {
324 324
         // set autoloaders for all of the classes implementing EEI_Plugin_API
325 325
         // which provide helpers for EE plugin authors to more easily register certain components with EE.
326
-        EEH_Autoloader::instance()->register_autoloaders_for_each_file_in_folder(EE_LIBRARIES . 'plugin_api');
326
+        EEH_Autoloader::instance()->register_autoloaders_for_each_file_in_folder(EE_LIBRARIES.'plugin_api');
327 327
     }
328 328
 
329 329
 
@@ -342,14 +342,14 @@  discard block
 block discarded – undo
342 342
         $load_callback,
343 343
         $plugin_file_constant
344 344
     ) {
345
-        if (! defined($version_constant)) {
345
+        if ( ! defined($version_constant)) {
346 346
             return;
347 347
         }
348 348
         $addon_version = constant($version_constant);
349 349
         if ($addon_version && version_compare($addon_version, $min_version_required, '<')) {
350 350
             remove_action('AHEE__EE_System__load_espresso_addons', $load_callback);
351
-            if (! function_exists('deactivate_plugins')) {
352
-                require_once ABSPATH . 'wp-admin/includes/plugin.php';
351
+            if ( ! function_exists('deactivate_plugins')) {
352
+                require_once ABSPATH.'wp-admin/includes/plugin.php';
353 353
             }
354 354
             deactivate_plugins(plugin_basename(constant($plugin_file_constant)));
355 355
             $this->request->unSetRequestParams(['activate', 'activate-multi'], true);
@@ -363,7 +363,7 @@  discard block
 block discarded – undo
363 363
                     $min_version_required
364 364
                 ),
365 365
                 __FILE__,
366
-                __FUNCTION__ . "({$addon_name})",
366
+                __FUNCTION__."({$addon_name})",
367 367
                 __LINE__
368 368
             );
369 369
             EE_Error::get_notices(false, true);
@@ -415,7 +415,7 @@  discard block
 block discarded – undo
415 415
                 true
416 416
             )
417 417
         ) {
418
-            include_once EE_THIRD_PARTY . 'wp-api-basic-auth/basic-auth.php';
418
+            include_once EE_THIRD_PARTY.'wp-api-basic-auth/basic-auth.php';
419 419
         }
420 420
         do_action('AHEE__EE_System__load_espresso_addons__complete');
421 421
     }
@@ -517,11 +517,11 @@  discard block
 block discarded – undo
517 517
     private function fix_espresso_db_upgrade_option($espresso_db_update = null)
518 518
     {
519 519
         do_action('FHEE__EE_System__manage_fix_espresso_db_upgrade_option__begin', $espresso_db_update);
520
-        if (! $espresso_db_update) {
520
+        if ( ! $espresso_db_update) {
521 521
             $espresso_db_update = get_option('espresso_db_update');
522 522
         }
523 523
         // check that option is an array
524
-        if (! is_array($espresso_db_update)) {
524
+        if ( ! is_array($espresso_db_update)) {
525 525
             // if option is FALSE, then it never existed
526 526
             if ($espresso_db_update === false) {
527 527
                 // make $espresso_db_update an array and save option with autoload OFF
@@ -541,10 +541,10 @@  discard block
 block discarded – undo
541 541
                     // so it must be numerically-indexed, where values are versions installed...
542 542
                     // fix it!
543 543
                     $version_string = $should_be_array;
544
-                    $corrected_db_update[ $version_string ] = array('unknown-date');
544
+                    $corrected_db_update[$version_string] = array('unknown-date');
545 545
                 } else {
546 546
                     // ok it checks out
547
-                    $corrected_db_update[ $should_be_version_string ] = $should_be_array;
547
+                    $corrected_db_update[$should_be_version_string] = $should_be_array;
548 548
                 }
549 549
             }
550 550
             $espresso_db_update = $corrected_db_update;
@@ -628,13 +628,13 @@  discard block
 block discarded – undo
628 628
      */
629 629
     public function update_list_of_installed_versions($version_history = null, $current_version_to_add = null)
630 630
     {
631
-        if (! $version_history) {
631
+        if ( ! $version_history) {
632 632
             $version_history = $this->fix_espresso_db_upgrade_option($version_history);
633 633
         }
634 634
         if ($current_version_to_add === null) {
635 635
             $current_version_to_add = espresso_version();
636 636
         }
637
-        $version_history[ $current_version_to_add ][] = date('Y-m-d H:i:s', time());
637
+        $version_history[$current_version_to_add][] = date('Y-m-d H:i:s', time());
638 638
         // re-save
639 639
         return update_option('espresso_db_update', $version_history);
640 640
     }
@@ -724,7 +724,7 @@  discard block
 block discarded – undo
724 724
         if ($activation_history_for_addon) {
725 725
             // it exists, so this isn't a completely new install
726 726
             // check if this version already in that list of previously installed versions
727
-            if (! isset($activation_history_for_addon[ $version_to_upgrade_to ])) {
727
+            if ( ! isset($activation_history_for_addon[$version_to_upgrade_to])) {
728 728
                 // it a version we haven't seen before
729 729
                 if ($version_is_higher === 1) {
730 730
                     $req_type = EE_System::req_type_upgrade;
@@ -802,7 +802,7 @@  discard block
 block discarded – undo
802 802
             foreach ($activation_history as $version => $times_activated) {
803 803
                 // check there is a record of when this version was activated. Otherwise,
804 804
                 // mark it as unknown
805
-                if (! $times_activated) {
805
+                if ( ! $times_activated) {
806 806
                     $times_activated = array('unknown-date');
807 807
                 }
808 808
                 if (is_string($times_activated)) {
@@ -906,7 +906,7 @@  discard block
 block discarded – undo
906 906
     private function _parse_model_names()
907 907
     {
908 908
         // get all the files in the EE_MODELS folder that end in .model.php
909
-        $models = glob(EE_MODELS . '*.model.php');
909
+        $models = glob(EE_MODELS.'*.model.php');
910 910
         $model_names = array();
911 911
         $non_abstract_db_models = array();
912 912
         foreach ($models as $model) {
@@ -915,9 +915,9 @@  discard block
 block discarded – undo
915 915
             $short_name = str_replace('EEM_', '', $classname);
916 916
             $reflectionClass = new ReflectionClass($classname);
917 917
             if ($reflectionClass->isSubclassOf('EEM_Base') && ! $reflectionClass->isAbstract()) {
918
-                $non_abstract_db_models[ $short_name ] = $classname;
918
+                $non_abstract_db_models[$short_name] = $classname;
919 919
             }
920
-            $model_names[ $short_name ] = $classname;
920
+            $model_names[$short_name] = $classname;
921 921
         }
922 922
         $this->registry->models = apply_filters('FHEE__EE_System__parse_model_names', $model_names);
923 923
         $this->registry->non_abstract_db_models = apply_filters(
@@ -952,7 +952,7 @@  discard block
 block discarded – undo
952 952
             )
953 953
         );
954 954
         if ($domain->isCaffeinated()) {
955
-            require_once EE_CAFF_PATH . 'brewing_regular.php';
955
+            require_once EE_CAFF_PATH.'brewing_regular.php';
956 956
         }
957 957
     }
958 958
 
@@ -1034,7 +1034,7 @@  discard block
 block discarded – undo
1034 1034
         $class_names = EEH_Class_Tools::get_class_names_for_all_callbacks_on_hook(
1035 1035
             'AHEE__EE_System__register_shortcodes_modules_and_addons'
1036 1036
         );
1037
-        if (! empty($class_names)) {
1037
+        if ( ! empty($class_names)) {
1038 1038
             $msg = esc_html__(
1039 1039
                 'The following plugins, addons, or modules appear to be incompatible with this version of Event Espresso and were automatically deactivated to avoid fatal errors:',
1040 1040
                 'event_espresso'
@@ -1046,7 +1046,7 @@  discard block
 block discarded – undo
1046 1046
                             array('EE_', 'EEM_', 'EED_', 'EES_', 'EEW_'),
1047 1047
                             '',
1048 1048
                             $class_name
1049
-                        ) . '</b></li>';
1049
+                        ).'</b></li>';
1050 1050
             }
1051 1051
             $msg .= '</ul>';
1052 1052
             $msg .= esc_html__(
@@ -1115,7 +1115,7 @@  discard block
 block discarded – undo
1115 1115
     private function _deactivate_incompatible_addons()
1116 1116
     {
1117 1117
         $incompatible_addons = get_option('ee_incompatible_addons', array());
1118
-        if (! empty($incompatible_addons)) {
1118
+        if ( ! empty($incompatible_addons)) {
1119 1119
             $active_plugins = get_option('active_plugins', array());
1120 1120
             foreach ($active_plugins as $active_plugin) {
1121 1121
                 foreach ($incompatible_addons as $incompatible_addon) {
@@ -1224,7 +1224,7 @@  discard block
 block discarded – undo
1224 1224
         do_action('AHEE__EE_System__core_loaded_and_ready');
1225 1225
         // always load template tags, because it's faster than checking if it's a front-end request, and many page
1226 1226
         // builders require these even on the front-end
1227
-        require_once EE_PUBLIC . 'template_tags.php';
1227
+        require_once EE_PUBLIC.'template_tags.php';
1228 1228
         do_action('AHEE__EE_System__set_hooks_for_shortcodes_modules_and_addons');
1229 1229
     }
1230 1230
 
@@ -1241,7 +1241,7 @@  discard block
 block discarded – undo
1241 1241
         do_action('AHEE__EE_System__initialize');
1242 1242
         add_filter(
1243 1243
             'safe_style_css',
1244
-            function ($styles) {
1244
+            function($styles) {
1245 1245
                 $styles[] = 'display';
1246 1246
                 $styles[] = 'visibility';
1247 1247
                 $styles[] = 'position';
@@ -1308,13 +1308,13 @@  discard block
 block discarded – undo
1308 1308
     public static function do_not_cache()
1309 1309
     {
1310 1310
         // set no cache constants
1311
-        if (! defined('DONOTCACHEPAGE')) {
1311
+        if ( ! defined('DONOTCACHEPAGE')) {
1312 1312
             define('DONOTCACHEPAGE', true);
1313 1313
         }
1314
-        if (! defined('DONOTCACHCEOBJECT')) {
1314
+        if ( ! defined('DONOTCACHCEOBJECT')) {
1315 1315
             define('DONOTCACHCEOBJECT', true);
1316 1316
         }
1317
-        if (! defined('DONOTCACHEDB')) {
1317
+        if ( ! defined('DONOTCACHEDB')) {
1318 1318
             define('DONOTCACHEDB', true);
1319 1319
         }
1320 1320
         // add no cache headers
Please login to merge, or discard this patch.
espresso.php 1 patch
Indentation   +80 added lines, -80 removed lines patch added patch discarded remove patch
@@ -38,103 +38,103 @@
 block discarded – undo
38 38
  * @since           4.0
39 39
  */
40 40
 if (function_exists('espresso_version')) {
41
-    if (! function_exists('espresso_duplicate_plugin_error')) {
42
-        /**
43
-         *    espresso_duplicate_plugin_error
44
-         *    displays if more than one version of EE is activated at the same time
45
-         */
46
-        function espresso_duplicate_plugin_error()
47
-        {
48
-            ?>
41
+	if (! function_exists('espresso_duplicate_plugin_error')) {
42
+		/**
43
+		 *    espresso_duplicate_plugin_error
44
+		 *    displays if more than one version of EE is activated at the same time
45
+		 */
46
+		function espresso_duplicate_plugin_error()
47
+		{
48
+			?>
49 49
             <div class="error">
50 50
                 <p>
51 51
                     <?php
52
-                    echo esc_html__(
53
-                        'Can not run multiple versions of Event Espresso! One version has been automatically deactivated. Please verify that you have the correct version you want still active.',
54
-                        'event_espresso'
55
-                    ); ?>
52
+					echo esc_html__(
53
+						'Can not run multiple versions of Event Espresso! One version has been automatically deactivated. Please verify that you have the correct version you want still active.',
54
+						'event_espresso'
55
+					); ?>
56 56
                 </p>
57 57
             </div>
58 58
             <?php
59
-            espresso_deactivate_plugin(plugin_basename(__FILE__));
60
-        }
61
-    }
62
-    add_action('admin_notices', 'espresso_duplicate_plugin_error', 1);
59
+			espresso_deactivate_plugin(plugin_basename(__FILE__));
60
+		}
61
+	}
62
+	add_action('admin_notices', 'espresso_duplicate_plugin_error', 1);
63 63
 } else {
64
-    define('EE_MIN_PHP_VER_REQUIRED', '5.6.2');
65
-    if (! version_compare(PHP_VERSION, EE_MIN_PHP_VER_REQUIRED, '>=')) {
66
-        /**
67
-         * espresso_minimum_php_version_error
68
-         *
69
-         * @return void
70
-         */
71
-        function espresso_minimum_php_version_error()
72
-        {
73
-            ?>
64
+	define('EE_MIN_PHP_VER_REQUIRED', '5.6.2');
65
+	if (! version_compare(PHP_VERSION, EE_MIN_PHP_VER_REQUIRED, '>=')) {
66
+		/**
67
+		 * espresso_minimum_php_version_error
68
+		 *
69
+		 * @return void
70
+		 */
71
+		function espresso_minimum_php_version_error()
72
+		{
73
+			?>
74 74
             <div class="error">
75 75
                 <p>
76 76
                     <?php
77
-                    printf(
78
-                        esc_html__(
79
-                            'We\'re sorry, but Event Espresso requires PHP version %1$s or greater in order to operate. You are currently running version %2$s.%3$sIn order to update your version of PHP, you will need to contact your current hosting provider.%3$sFor information on stable PHP versions, please go to %4$s.',
80
-                            'event_espresso'
81
-                        ),
82
-                        EE_MIN_PHP_VER_REQUIRED,
83
-                        PHP_VERSION,
84
-                        '<br/>',
85
-                        '<a href="http://php.net/downloads.php">http://php.net/downloads.php</a>'
86
-                    );
87
-                    ?>
77
+					printf(
78
+						esc_html__(
79
+							'We\'re sorry, but Event Espresso requires PHP version %1$s or greater in order to operate. You are currently running version %2$s.%3$sIn order to update your version of PHP, you will need to contact your current hosting provider.%3$sFor information on stable PHP versions, please go to %4$s.',
80
+							'event_espresso'
81
+						),
82
+						EE_MIN_PHP_VER_REQUIRED,
83
+						PHP_VERSION,
84
+						'<br/>',
85
+						'<a href="http://php.net/downloads.php">http://php.net/downloads.php</a>'
86
+					);
87
+					?>
88 88
                 </p>
89 89
             </div>
90 90
             <?php
91
-            espresso_deactivate_plugin(plugin_basename(__FILE__));
92
-        }
91
+			espresso_deactivate_plugin(plugin_basename(__FILE__));
92
+		}
93 93
 
94
-        add_action('admin_notices', 'espresso_minimum_php_version_error', 1);
95
-    } else {
96
-        define('EVENT_ESPRESSO_MAIN_FILE', __FILE__);
97
-        /**
98
-         * espresso_version
99
-         * Returns the plugin version
100
-         *
101
-         * @return string
102
-         */
103
-        function espresso_version()
104
-        {
105
-            return apply_filters('FHEE__espresso__espresso_version', '4.10.33.rc.006');
106
-        }
94
+		add_action('admin_notices', 'espresso_minimum_php_version_error', 1);
95
+	} else {
96
+		define('EVENT_ESPRESSO_MAIN_FILE', __FILE__);
97
+		/**
98
+		 * espresso_version
99
+		 * Returns the plugin version
100
+		 *
101
+		 * @return string
102
+		 */
103
+		function espresso_version()
104
+		{
105
+			return apply_filters('FHEE__espresso__espresso_version', '4.10.33.rc.006');
106
+		}
107 107
 
108
-        /**
109
-         * espresso_plugin_activation
110
-         * adds a wp-option to indicate that EE has been activated via the WP admin plugins page
111
-         */
112
-        function espresso_plugin_activation()
113
-        {
114
-            update_option('ee_espresso_activation', true);
115
-        }
108
+		/**
109
+		 * espresso_plugin_activation
110
+		 * adds a wp-option to indicate that EE has been activated via the WP admin plugins page
111
+		 */
112
+		function espresso_plugin_activation()
113
+		{
114
+			update_option('ee_espresso_activation', true);
115
+		}
116 116
 
117
-        register_activation_hook(EVENT_ESPRESSO_MAIN_FILE, 'espresso_plugin_activation');
117
+		register_activation_hook(EVENT_ESPRESSO_MAIN_FILE, 'espresso_plugin_activation');
118 118
 
119
-        require_once __DIR__ . '/core/bootstrap_espresso.php';
120
-        bootstrap_espresso();
121
-    }
119
+		require_once __DIR__ . '/core/bootstrap_espresso.php';
120
+		bootstrap_espresso();
121
+	}
122 122
 }
123 123
 if (! function_exists('espresso_deactivate_plugin')) {
124
-    /**
125
-     *    deactivate_plugin
126
-     * usage:  espresso_deactivate_plugin( plugin_basename( __FILE__ ));
127
-     *
128
-     * @access public
129
-     * @param string $plugin_basename - the results of plugin_basename( __FILE__ ) for the plugin's main file
130
-     * @return    void
131
-     */
132
-    function espresso_deactivate_plugin($plugin_basename = '')
133
-    {
134
-        if (! function_exists('deactivate_plugins')) {
135
-            require_once ABSPATH . 'wp-admin/includes/plugin.php';
136
-        }
137
-        unset($_GET['activate'], $_REQUEST['activate']);
138
-        deactivate_plugins($plugin_basename);
139
-    }
124
+	/**
125
+	 *    deactivate_plugin
126
+	 * usage:  espresso_deactivate_plugin( plugin_basename( __FILE__ ));
127
+	 *
128
+	 * @access public
129
+	 * @param string $plugin_basename - the results of plugin_basename( __FILE__ ) for the plugin's main file
130
+	 * @return    void
131
+	 */
132
+	function espresso_deactivate_plugin($plugin_basename = '')
133
+	{
134
+		if (! function_exists('deactivate_plugins')) {
135
+			require_once ABSPATH . 'wp-admin/includes/plugin.php';
136
+		}
137
+		unset($_GET['activate'], $_REQUEST['activate']);
138
+		deactivate_plugins($plugin_basename);
139
+	}
140 140
 }
141 141
\ No newline at end of file
Please login to merge, or discard this patch.
admin_pages/general_settings/General_Settings_Admin_Page.core.php 1 patch
Indentation   +1422 added lines, -1422 removed lines patch added patch discarded remove patch
@@ -20,1437 +20,1437 @@
 block discarded – undo
20 20
 class General_Settings_Admin_Page extends EE_Admin_Page
21 21
 {
22 22
 
23
-    /**
24
-     * @var EE_Core_Config
25
-     */
26
-    public $core_config;
27
-
28
-
29
-    /**
30
-     * Initialize basic properties.
31
-     */
32
-    protected function _init_page_props()
33
-    {
34
-        $this->page_slug        = GEN_SET_PG_SLUG;
35
-        $this->page_label       = GEN_SET_LABEL;
36
-        $this->_admin_base_url  = GEN_SET_ADMIN_URL;
37
-        $this->_admin_base_path = GEN_SET_ADMIN;
38
-
39
-        $this->core_config = EE_Registry::instance()->CFG->core;
40
-    }
41
-
42
-
43
-    /**
44
-     * Set ajax hooks
45
-     */
46
-    protected function _ajax_hooks()
47
-    {
48
-        add_action('wp_ajax_espresso_display_country_settings', [$this, 'display_country_settings']);
49
-        add_action('wp_ajax_espresso_display_country_states', [$this, 'display_country_states']);
50
-        add_action('wp_ajax_espresso_delete_state', [$this, 'delete_state'], 10, 3);
51
-        add_action('wp_ajax_espresso_add_new_state', [$this, 'add_new_state']);
52
-    }
53
-
54
-
55
-    /**
56
-     * More page properties initialization.
57
-     */
58
-    protected function _define_page_props()
59
-    {
60
-        $this->_admin_page_title = GEN_SET_LABEL;
61
-        $this->_labels           = ['publishbox' => esc_html__('Update Settings', 'event_espresso')];
62
-    }
63
-
64
-
65
-    /**
66
-     * Set page routes property.
67
-     */
68
-    protected function _set_page_routes()
69
-    {
70
-        $this->_page_routes = [
71
-            'critical_pages'                => [
72
-                'func'       => '_espresso_page_settings',
73
-                'capability' => 'manage_options',
74
-            ],
75
-            'update_espresso_page_settings' => [
76
-                'func'       => '_update_espresso_page_settings',
77
-                'capability' => 'manage_options',
78
-                'noheader'   => true,
79
-            ],
80
-            'default'                       => [
81
-                'func'       => '_your_organization_settings',
82
-                'capability' => 'manage_options',
83
-            ],
84
-
85
-            'update_your_organization_settings' => [
86
-                'func'       => '_update_your_organization_settings',
87
-                'capability' => 'manage_options',
88
-                'noheader'   => true,
89
-            ],
90
-
91
-            'admin_option_settings' => [
92
-                'func'       => '_admin_option_settings',
93
-                'capability' => 'manage_options',
94
-            ],
95
-
96
-            'update_admin_option_settings' => [
97
-                'func'       => '_update_admin_option_settings',
98
-                'capability' => 'manage_options',
99
-                'noheader'   => true,
100
-            ],
101
-
102
-            'country_settings' => [
103
-                'func'       => '_country_settings',
104
-                'capability' => 'manage_options',
105
-            ],
106
-
107
-            'update_country_settings' => [
108
-                'func'       => '_update_country_settings',
109
-                'capability' => 'manage_options',
110
-                'noheader'   => true,
111
-            ],
112
-
113
-            'display_country_settings' => [
114
-                'func'       => 'display_country_settings',
115
-                'capability' => 'manage_options',
116
-                'noheader'   => true,
117
-            ],
118
-
119
-            'add_new_state' => [
120
-                'func'       => 'add_new_state',
121
-                'capability' => 'manage_options',
122
-                'noheader'   => true,
123
-            ],
124
-
125
-            'delete_state'            => [
126
-                'func'       => 'delete_state',
127
-                'capability' => 'manage_options',
128
-                'noheader'   => true,
129
-            ],
130
-            'privacy_settings'        => [
131
-                'func'       => 'privacySettings',
132
-                'capability' => 'manage_options',
133
-            ],
134
-            'update_privacy_settings' => [
135
-                'func'               => 'updatePrivacySettings',
136
-                'capability'         => 'manage_options',
137
-                'noheader'           => true,
138
-                'headers_sent_route' => 'privacy_settings',
139
-            ],
140
-        ];
141
-    }
142
-
143
-
144
-    /**
145
-     * Set page configuration property
146
-     */
147
-    protected function _set_page_config()
148
-    {
149
-        $this->_page_config = [
150
-            'critical_pages'        => [
151
-                'nav'           => [
152
-                    'label' => esc_html__('Critical Pages', 'event_espresso'),
153
-                    'order' => 50,
154
-                ],
155
-                'metaboxes'     => array_merge($this->_default_espresso_metaboxes, ['_publish_post_box']),
156
-                'help_tabs'     => [
157
-                    'general_settings_critical_pages_help_tab' => [
158
-                        'title'    => esc_html__('Critical Pages', 'event_espresso'),
159
-                        'filename' => 'general_settings_critical_pages',
160
-                    ],
161
-                ],
162
-                'require_nonce' => false,
163
-            ],
164
-            'default'               => [
165
-                'nav'           => [
166
-                    'label' => esc_html__('Your Organization', 'event_espresso'),
167
-                    'order' => 20,
168
-                ],
169
-                'help_tabs'     => [
170
-                    'general_settings_your_organization_help_tab' => [
171
-                        'title'    => esc_html__('Your Organization', 'event_espresso'),
172
-                        'filename' => 'general_settings_your_organization',
173
-                    ],
174
-                ],
175
-                'metaboxes'     => array_merge($this->_default_espresso_metaboxes, ['_publish_post_box']),
176
-                'require_nonce' => false,
177
-            ],
178
-            'admin_option_settings' => [
179
-                'nav'           => [
180
-                    'label' => esc_html__('Admin Options', 'event_espresso'),
181
-                    'order' => 60,
182
-                ],
183
-                'metaboxes'     => array_merge($this->_default_espresso_metaboxes, ['_publish_post_box']),
184
-                'help_tabs'     => [
185
-                    'general_settings_admin_options_help_tab' => [
186
-                        'title'    => esc_html__('Admin Options', 'event_espresso'),
187
-                        'filename' => 'general_settings_admin_options',
188
-                    ],
189
-                ],
190
-                'require_nonce' => false,
191
-            ],
192
-            'country_settings'      => [
193
-                'nav'           => [
194
-                    'label' => esc_html__('Countries', 'event_espresso'),
195
-                    'order' => 70,
196
-                ],
197
-                'help_tabs'     => [
198
-                    'general_settings_countries_help_tab' => [
199
-                        'title'    => esc_html__('Countries', 'event_espresso'),
200
-                        'filename' => 'general_settings_countries',
201
-                    ],
202
-                ],
203
-                'require_nonce' => false,
204
-            ],
205
-            'privacy_settings'      => [
206
-                'nav'           => [
207
-                    'label' => esc_html__('Privacy', 'event_espresso'),
208
-                    'order' => 80,
209
-                ],
210
-                'metaboxes'     => array_merge($this->_default_espresso_metaboxes, ['_publish_post_box']),
211
-                'require_nonce' => false,
212
-            ],
213
-        ];
214
-    }
215
-
216
-
217
-    protected function _add_screen_options()
218
-    {
219
-    }
220
-
221
-
222
-    protected function _add_feature_pointers()
223
-    {
224
-    }
225
-
226
-
227
-    /**
228
-     * Enqueue global scripts and styles for all routes in the General Settings Admin Pages.
229
-     */
230
-    public function load_scripts_styles()
231
-    {
232
-        // styles
233
-        wp_enqueue_style('espresso-ui-theme');
234
-        // scripts
235
-        wp_enqueue_script('ee_admin_js');
236
-    }
237
-
238
-
239
-    /**
240
-     * Execute logic running on `admin_init`
241
-     */
242
-    public function admin_init()
243
-    {
244
-        EE_Registry::$i18n_js_strings['invalid_server_response'] = wp_strip_all_tags(
245
-            esc_html__(
246
-                'An error occurred! Your request may have been processed, but a valid response from the server was not received. Please refresh the page and try again.',
247
-                'event_espresso'
248
-            )
249
-        );
250
-        EE_Registry::$i18n_js_strings['error_occurred']          = wp_strip_all_tags(
251
-            esc_html__(
252
-                'An error occurred! Please refresh the page and try again.',
253
-                'event_espresso'
254
-            )
255
-        );
256
-        EE_Registry::$i18n_js_strings['confirm_delete_state']    = wp_strip_all_tags(
257
-            esc_html__(
258
-                'Are you sure you want to delete this State / Province?',
259
-                'event_espresso'
260
-            )
261
-        );
262
-        EE_Registry::$i18n_js_strings['ajax_url']                = admin_url(
263
-            'admin-ajax.php?page=espresso_general_settings',
264
-            is_ssl() ? 'https://' : 'http://'
265
-        );
266
-    }
267
-
268
-
269
-    public function admin_notices()
270
-    {
271
-    }
272
-
273
-
274
-    public function admin_footer_scripts()
275
-    {
276
-    }
277
-
278
-
279
-    /**
280
-     * Enqueue scripts and styles for the default route.
281
-     */
282
-    public function load_scripts_styles_default()
283
-    {
284
-        // styles
285
-        wp_enqueue_style('thickbox');
286
-        // scripts
287
-        wp_enqueue_script('media-upload');
288
-        wp_enqueue_script('thickbox');
289
-        wp_register_script(
290
-            'organization_settings',
291
-            GEN_SET_ASSETS_URL . 'your_organization_settings.js',
292
-            ['jquery', 'media-upload', 'thickbox'],
293
-            EVENT_ESPRESSO_VERSION,
294
-            true
295
-        );
296
-        wp_register_style('organization-css', GEN_SET_ASSETS_URL . 'organization.css', [], EVENT_ESPRESSO_VERSION);
297
-        wp_enqueue_script('organization_settings');
298
-        wp_enqueue_style('organization-css');
299
-        $confirm_image_delete = [
300
-            'text' => wp_strip_all_tags(
301
-                esc_html__(
302
-                    'Do you really want to delete this image? Please remember to save your settings to complete the removal.',
303
-                    'event_espresso'
304
-                )
305
-            ),
306
-        ];
307
-        wp_localize_script('organization_settings', 'confirm_image_delete', $confirm_image_delete);
308
-    }
309
-
310
-
311
-    /**
312
-     * Enqueue scripts and styles for the country settings route.
313
-     */
314
-    public function load_scripts_styles_country_settings()
315
-    {
316
-        // scripts
317
-        wp_register_script(
318
-            'gen_settings_countries',
319
-            GEN_SET_ASSETS_URL . 'gen_settings_countries.js',
320
-            ['ee_admin_js'],
321
-            EVENT_ESPRESSO_VERSION,
322
-            true
323
-        );
324
-        wp_register_style('organization-css', GEN_SET_ASSETS_URL . 'organization.css', [], EVENT_ESPRESSO_VERSION);
325
-        wp_enqueue_script('gen_settings_countries');
326
-        wp_enqueue_style('organization-css');
327
-    }
328
-
329
-
330
-    /*************        Espresso Pages        *************/
331
-    /**
332
-     * _espresso_page_settings
333
-     *
334
-     * @throws EE_Error
335
-     * @throws DomainException
336
-     * @throws DomainException
337
-     * @throws InvalidDataTypeException
338
-     * @throws InvalidArgumentException
339
-     */
340
-    protected function _espresso_page_settings()
341
-    {
342
-        // Check to make sure all of the main pages are set up properly,
343
-        // if not create the default pages and display an admin notice
344
-        EEH_Activation::verify_default_pages_exist();
345
-        $this->_transient_garbage_collection();
346
-
347
-        $this->_template_args['values'] = $this->_yes_no_values;
348
-
349
-        $this->_template_args['reg_page_id']  = $this->core_config->reg_page_id ?? null;
350
-        $this->_template_args['reg_page_obj'] = isset($this->core_config->reg_page_id)
351
-            ? get_post($this->core_config->reg_page_id)
352
-            : false;
353
-
354
-        $this->_template_args['txn_page_id']  = $this->core_config->txn_page_id ?? null;
355
-        $this->_template_args['txn_page_obj'] = isset($this->core_config->txn_page_id)
356
-            ? get_post($this->core_config->txn_page_id)
357
-            : false;
358
-
359
-        $this->_template_args['thank_you_page_id']  = $this->core_config->thank_you_page_id ?? null;
360
-        $this->_template_args['thank_you_page_obj'] = isset($this->core_config->thank_you_page_id)
361
-            ? get_post($this->core_config->thank_you_page_id)
362
-            : false;
363
-
364
-        $this->_template_args['cancel_page_id']  = $this->core_config->cancel_page_id ?? null;
365
-        $this->_template_args['cancel_page_obj'] = isset($this->core_config->cancel_page_id)
366
-            ? get_post($this->core_config->cancel_page_id)
367
-            : false;
368
-
369
-        $this->_set_add_edit_form_tags('update_espresso_page_settings');
370
-        $this->_set_publish_post_box_vars(null, false, false, null, false);
371
-        $this->_template_args['admin_page_content'] = EEH_Template::display_template(
372
-            GEN_SET_TEMPLATE_PATH . 'espresso_page_settings.template.php',
373
-            $this->_template_args,
374
-            true
375
-        );
376
-        $this->display_admin_page_with_sidebar();
377
-    }
378
-
379
-
380
-    /**
381
-     * Handler for updating espresso page settings.
382
-     *
383
-     * @throws EE_Error
384
-     */
385
-    protected function _update_espresso_page_settings()
386
-    {
387
-        // capture incoming request data && set page IDs
388
-        $this->core_config->reg_page_id       = $this->request->getRequestParam(
389
-            'reg_page_id',
390
-            $this->core_config->reg_page_id,
391
-            DataType::INT
392
-        );
393
-        $this->core_config->txn_page_id       = $this->request->getRequestParam(
394
-            'txn_page_id',
395
-            $this->core_config->txn_page_id,
396
-            DataType::INT
397
-        );
398
-        $this->core_config->thank_you_page_id = $this->request->getRequestParam(
399
-            'thank_you_page_id',
400
-            $this->core_config->thank_you_page_id,
401
-            DataType::INT
402
-        );
403
-        $this->core_config->cancel_page_id    = $this->request->getRequestParam(
404
-            'cancel_page_id',
405
-            $this->core_config->cancel_page_id,
406
-            DataType::INT
407
-        );
408
-
409
-        $this->core_config = apply_filters(
410
-            'FHEE__General_Settings_Admin_Page___update_espresso_page_settings__CFG_core',
411
-            $this->core_config,
412
-            $this->request->requestParams()
413
-        );
414
-
415
-        $what = esc_html__('Critical Pages & Shortcodes', 'event_espresso');
416
-        $this->_redirect_after_action(
417
-            $this->_update_espresso_configuration(
418
-                $what,
419
-                $this->core_config,
420
-                __FILE__,
421
-                __FUNCTION__,
422
-                __LINE__
423
-            ),
424
-            $what,
425
-            '',
426
-            [
427
-                'action' => 'critical_pages',
428
-            ],
429
-            true
430
-        );
431
-    }
432
-
433
-
434
-    /*************        Your Organization        *************/
435
-
436
-
437
-    /**
438
-     * @throws DomainException
439
-     * @throws EE_Error
440
-     * @throws InvalidArgumentException
441
-     * @throws InvalidDataTypeException
442
-     * @throws InvalidInterfaceException
443
-     */
444
-    protected function _your_organization_settings()
445
-    {
446
-        $this->_template_args['admin_page_content'] = '';
447
-        try {
448
-            /** @var OrganizationSettings $organization_settings_form */
449
-            $organization_settings_form = $this->loader->getShared(OrganizationSettings::class);
450
-
451
-            $this->_template_args['admin_page_content'] = EEH_HTML::div(
452
-                $organization_settings_form->display(),
453
-                '',
454
-                'padding'
455
-            );
456
-        } catch (Exception $e) {
457
-            EE_Error::add_error($e->getMessage(), __FILE__, __FUNCTION__, __LINE__);
458
-        }
459
-        $this->_set_add_edit_form_tags('update_your_organization_settings');
460
-        $this->_set_publish_post_box_vars(null, false, false, null, false);
461
-        $this->display_admin_page_with_sidebar();
462
-    }
463
-
464
-
465
-    /**
466
-     * Handler for updating organization settings.
467
-     *
468
-     * @throws EE_Error
469
-     */
470
-    protected function _update_your_organization_settings()
471
-    {
472
-        try {
473
-            /** @var OrganizationSettings $organization_settings_form */
474
-            $organization_settings_form = $this->loader->getShared(OrganizationSettings::class);
475
-
476
-            $success = $organization_settings_form->process($this->request->requestParams());
477
-
478
-            EE_Registry::instance()->CFG = apply_filters(
479
-                'FHEE__General_Settings_Admin_Page___update_your_organization_settings__CFG',
480
-                EE_Registry::instance()->CFG
481
-            );
482
-        } catch (Exception $e) {
483
-            EE_Error::add_error($e->getMessage(), __FILE__, __FUNCTION__, __LINE__);
484
-            $success = false;
485
-        }
486
-
487
-        if ($success) {
488
-            $success = $this->_update_espresso_configuration(
489
-                esc_html__('Your Organization Settings', 'event_espresso'),
490
-                EE_Registry::instance()->CFG,
491
-                __FILE__,
492
-                __FUNCTION__,
493
-                __LINE__
494
-            );
495
-        }
496
-
497
-        $this->_redirect_after_action($success, '', '', ['action' => 'default'], true);
498
-    }
499
-
500
-
501
-
502
-    /*************        Admin Options        *************/
503
-
504
-
505
-    /**
506
-     * _admin_option_settings
507
-     *
508
-     * @throws EE_Error
509
-     * @throws LogicException
510
-     */
511
-    protected function _admin_option_settings()
512
-    {
513
-        $this->_template_args['admin_page_content'] = '';
514
-        try {
515
-            $admin_options_settings_form = new AdminOptionsSettings(EE_Registry::instance());
516
-            // still need this for the old school form in Extend_General_Settings_Admin_Page
517
-            $this->_template_args['values'] = $this->_yes_no_values;
518
-            // also need to account for the do_action that was in the old template
519
-            $admin_options_settings_form->setTemplateArgs($this->_template_args);
520
-            $this->_template_args['admin_page_content'] = $admin_options_settings_form->display();
521
-        } catch (Exception $e) {
522
-            EE_Error::add_error($e->getMessage(), __FILE__, __FUNCTION__, __LINE__);
523
-        }
524
-        $this->_set_add_edit_form_tags('update_admin_option_settings');
525
-        $this->_set_publish_post_box_vars(null, false, false, null, false);
526
-        $this->display_admin_page_with_sidebar();
527
-    }
528
-
529
-
530
-    /**
531
-     * _update_admin_option_settings
532
-     *
533
-     * @throws EE_Error
534
-     * @throws InvalidDataTypeException
535
-     * @throws InvalidFormSubmissionException
536
-     * @throws InvalidArgumentException
537
-     * @throws LogicException
538
-     */
539
-    protected function _update_admin_option_settings()
540
-    {
541
-        try {
542
-            $admin_options_settings_form = new AdminOptionsSettings(EE_Registry::instance());
543
-            $admin_options_settings_form->process(
544
-                $this->request->getRequestParam(
545
-                    $admin_options_settings_form->slug(),
546
-                    [],
547
-                    DataType::OBJECT // need to change this to ARRAY after min PHP version gets bumped to 7+
548
-                )
549
-            );
550
-            EE_Registry::instance()->CFG->admin = apply_filters(
551
-                'FHEE__General_Settings_Admin_Page___update_admin_option_settings__CFG_admin',
552
-                EE_Registry::instance()->CFG->admin
553
-            );
554
-        } catch (Exception $e) {
555
-            EE_Error::add_error($e->getMessage(), __FILE__, __FUNCTION__, __LINE__);
556
-        }
557
-        $this->_redirect_after_action(
558
-            apply_filters(
559
-                'FHEE__General_Settings_Admin_Page___update_admin_option_settings__success',
560
-                $this->_update_espresso_configuration(
561
-                    esc_html__('Admin Options', 'event_espresso'),
562
-                    EE_Registry::instance()->CFG->admin,
563
-                    __FILE__,
564
-                    __FUNCTION__,
565
-                    __LINE__
566
-                )
567
-            ),
568
-            esc_html__('Admin Options', 'event_espresso'),
569
-            'updated',
570
-            ['action' => 'admin_option_settings']
571
-        );
572
-    }
573
-
574
-
575
-    /*************        Countries        *************/
576
-
577
-
578
-    /**
579
-     * @param string|null $default
580
-     * @return string
581
-     */
582
-    protected function getCountryISO(?string $default = null): string
583
-    {
584
-        $default = $default ?? $this->getCountryIsoForSite();
585
-        $CNT_ISO = $this->request->getRequestParam('country', $default);
586
-        $CNT_ISO = $this->request->getRequestParam('CNT_ISO', $CNT_ISO);
587
-        return strtoupper($CNT_ISO);
588
-    }
589
-
590
-
591
-    /**
592
-     * @return string
593
-     */
594
-    protected function getCountryIsoForSite(): string
595
-    {
596
-        return ! empty(EE_Registry::instance()->CFG->organization->CNT_ISO)
597
-            ? EE_Registry::instance()->CFG->organization->CNT_ISO
598
-            : 'US';
599
-    }
600
-
601
-
602
-    /**
603
-     * @param string          $CNT_ISO
604
-     * @param EE_Country|null $country
605
-     * @return EE_Base_Class|EE_Country
606
-     * @throws EE_Error
607
-     * @throws InvalidArgumentException
608
-     * @throws InvalidDataTypeException
609
-     * @throws InvalidInterfaceException
610
-     * @throws ReflectionException
611
-     */
612
-    protected function verifyOrGetCountryFromIso(string $CNT_ISO, ?EE_Country $country = null)
613
-    {
614
-        /** @var EE_Country $country */
615
-        return $country instanceof EE_Country && $country->ID() === $CNT_ISO
616
-            ? $country
617
-            : EEM_Country::instance()->get_one_by_ID($CNT_ISO);
618
-    }
619
-
620
-
621
-    /**
622
-     * Output Country Settings view.
623
-     *
624
-     * @throws DomainException
625
-     * @throws EE_Error
626
-     * @throws InvalidArgumentException
627
-     * @throws InvalidDataTypeException
628
-     * @throws InvalidInterfaceException
629
-     * @throws ReflectionException
630
-     */
631
-    protected function _country_settings()
632
-    {
633
-        $CNT_ISO = $this->getCountryISO();
634
-
635
-        $this->_template_args['values']    = $this->_yes_no_values;
636
-        $this->_template_args['countries'] = new EE_Question_Form_Input(
637
-            EE_Question::new_instance(
638
-                [
639
-                    'QST_ID'           => 0,
640
-                    'QST_display_text' => esc_html__('Select Country', 'event_espresso'),
641
-                    'QST_system'       => 'admin-country',
642
-                ]
643
-            ),
644
-            EE_Answer::new_instance(
645
-                [
646
-                    'ANS_ID'    => 0,
647
-                    'ANS_value' => $CNT_ISO,
648
-                ]
649
-            ),
650
-            [
651
-                'input_id'       => 'country',
652
-                'input_name'     => 'country',
653
-                'input_prefix'   => '',
654
-                'append_qstn_id' => false,
655
-            ]
656
-        );
657
-
658
-        $country = $this->verifyOrGetCountryFromIso($CNT_ISO);
659
-        add_filter('FHEE__EEH_Form_Fields__label_html', [$this, 'country_form_field_label_wrap'], 10);
660
-        add_filter('FHEE__EEH_Form_Fields__input_html', [$this, 'country_form_field_input__wrap'], 10);
661
-        $this->_template_args['country_details_settings'] = $this->display_country_settings(
662
-            $country->ID(),
663
-            $country
664
-        );
665
-        $this->_template_args['country_states_settings']  = $this->display_country_states(
666
-            $country->ID(),
667
-            $country
668
-        );
669
-        $this->_template_args['CNT_name_for_site']        = $country->name();
670
-
671
-        $this->_set_add_edit_form_tags('update_country_settings');
672
-        $this->_set_publish_post_box_vars(null, false, false, null, false);
673
-        $this->_template_args['admin_page_content'] = EEH_Template::display_template(
674
-            GEN_SET_TEMPLATE_PATH . 'countries_settings.template.php',
675
-            $this->_template_args,
676
-            true
677
-        );
678
-        $this->display_admin_page_with_no_sidebar();
679
-    }
680
-
681
-
682
-    /**
683
-     * @param string          $CNT_ISO
684
-     * @param EE_Country|null $country
685
-     * @return string
686
-     * @throws DomainException
687
-     * @throws EE_Error
688
-     * @throws InvalidArgumentException
689
-     * @throws InvalidDataTypeException
690
-     * @throws InvalidInterfaceException
691
-     * @throws ReflectionException
692
-     */
693
-    public function display_country_settings(string $CNT_ISO = '', ?EE_Country $country = null): string
694
-    {
695
-        $CNT_ISO          = $this->getCountryISO($CNT_ISO);
696
-        $CNT_ISO_for_site = $this->getCountryIsoForSite();
697
-
698
-        if (! $CNT_ISO) {
699
-            return '';
700
-        }
701
-
702
-        // for ajax
703
-        remove_all_filters('FHEE__EEH_Form_Fields__label_html');
704
-        remove_all_filters('FHEE__EEH_Form_Fields__input_html');
705
-        add_filter('FHEE__EEH_Form_Fields__label_html', [$this, 'country_form_field_label_wrap'], 10, 2);
706
-        add_filter('FHEE__EEH_Form_Fields__input_html', [$this, 'country_form_field_input__wrap'], 10, 2);
707
-        $country                                  = $this->verifyOrGetCountryFromIso($CNT_ISO, $country);
708
-        $CNT_cur_disabled                         = $CNT_ISO !== $CNT_ISO_for_site;
709
-        $this->_template_args['CNT_cur_disabled'] = $CNT_cur_disabled;
710
-
711
-        $country_input_types            = [
712
-            'CNT_active'      => [
713
-                'type'             => 'RADIO_BTN',
714
-                'input_name'       => 'cntry[' . $CNT_ISO . ']',
715
-                'class'            => '',
716
-                'options'          => $this->_yes_no_values,
717
-                'use_desc_4_label' => true,
718
-            ],
719
-            'CNT_ISO'         => [
720
-                'type'       => 'TEXT',
721
-                'input_name' => 'cntry[' . $CNT_ISO . ']',
722
-                'class'      => 'small-text',
723
-            ],
724
-            'CNT_ISO3'        => [
725
-                'type'       => 'TEXT',
726
-                'input_name' => 'cntry[' . $CNT_ISO . ']',
727
-                'class'      => 'small-text',
728
-            ],
729
-            // 'RGN_ID'          => [
730
-            //     'type'       => 'TEXT',
731
-            //     'input_name' => 'cntry[' . $CNT_ISO . ']',
732
-            //     'class'      => 'ee-input-size--small',
733
-            // ],
734
-            'CNT_name'        => [
735
-                'type'       => 'TEXT',
736
-                'input_name' => 'cntry[' . $CNT_ISO . ']',
737
-                'class'      => 'regular-text',
738
-            ],
739
-            'CNT_cur_code'    => [
740
-                'type'       => 'TEXT',
741
-                'input_name' => 'cntry[' . $CNT_ISO . ']',
742
-                'class'      => 'small-text',
743
-                'disabled'   => $CNT_cur_disabled,
744
-            ],
745
-            'CNT_cur_single'  => [
746
-                'type'       => 'TEXT',
747
-                'input_name' => 'cntry[' . $CNT_ISO . ']',
748
-                'class'      => 'medium-text',
749
-                'disabled'   => $CNT_cur_disabled,
750
-            ],
751
-            'CNT_cur_plural'  => [
752
-                'type'       => 'TEXT',
753
-                'input_name' => 'cntry[' . $CNT_ISO . ']',
754
-                'class'      => 'medium-text',
755
-                'disabled'   => $CNT_cur_disabled,
756
-            ],
757
-            'CNT_cur_sign'    => [
758
-                'type'         => 'TEXT',
759
-                'input_name'   => 'cntry[' . $CNT_ISO . ']',
760
-                'class'        => 'small-text',
761
-                'htmlentities' => false,
762
-                'disabled'     => $CNT_cur_disabled,
763
-            ],
764
-            'CNT_cur_sign_b4' => [
765
-                'type'             => 'RADIO_BTN',
766
-                'input_name'       => 'cntry[' . $CNT_ISO . ']',
767
-                'class'            => '',
768
-                'options'          => $this->_yes_no_values,
769
-                'use_desc_4_label' => true,
770
-                'disabled'         => $CNT_cur_disabled,
771
-            ],
772
-            'CNT_cur_dec_plc' => [
773
-                'type'       => 'RADIO_BTN',
774
-                'input_name' => 'cntry[' . $CNT_ISO . ']',
775
-                'class'      => '',
776
-                'options'    => [
777
-                    ['id' => 0, 'text' => ''],
778
-                    ['id' => 1, 'text' => ''],
779
-                    ['id' => 2, 'text' => ''],
780
-                    ['id' => 3, 'text' => ''],
781
-                ],
782
-                'disabled'   => $CNT_cur_disabled,
783
-            ],
784
-            'CNT_cur_dec_mrk' => [
785
-                'type'             => 'RADIO_BTN',
786
-                'input_name'       => 'cntry[' . $CNT_ISO . ']',
787
-                'class'            => '',
788
-                'options'          => [
789
-                    [
790
-                        'id'   => ',',
791
-                        'text' => esc_html__(', (comma)', 'event_espresso'),
792
-                    ],
793
-                    ['id' => '.', 'text' => esc_html__('. (decimal)', 'event_espresso')],
794
-                ],
795
-                'use_desc_4_label' => true,
796
-                'disabled'         => $CNT_cur_disabled,
797
-            ],
798
-            'CNT_cur_thsnds'  => [
799
-                'type'             => 'RADIO_BTN',
800
-                'input_name'       => 'cntry[' . $CNT_ISO . ']',
801
-                'class'            => '',
802
-                'options'          => [
803
-                    [
804
-                        'id'   => ',',
805
-                        'text' => esc_html__(', (comma)', 'event_espresso'),
806
-                    ],
807
-                    [
808
-                        'id'   => '.',
809
-                        'text' => esc_html__('. (decimal)', 'event_espresso'),
810
-                    ],
811
-                    [
812
-                        'id'   => '&nbsp;',
813
-                        'text' => esc_html__('(space)', 'event_espresso'),
814
-                    ],
815
-                    [
816
-                        'id'   => '_',
817
-                        'text' => esc_html__('_ (underscore)', 'event_espresso'),
818
-                    ],
819
-                    [
820
-                        'id'   => "'",
821
-                        'text' => esc_html__("' (apostrophe)", 'event_espresso'),
822
-                    ],
823
-                ],
824
-                'use_desc_4_label' => true,
825
-                'disabled'         => $CNT_cur_disabled,
826
-            ],
827
-            'CNT_tel_code'    => [
828
-                'type'       => 'TEXT',
829
-                'input_name' => 'cntry[' . $CNT_ISO . ']',
830
-                'class'      => 'small-text',
831
-            ],
832
-            'CNT_is_EU'       => [
833
-                'type'             => 'RADIO_BTN',
834
-                'input_name'       => 'cntry[' . $CNT_ISO . ']',
835
-                'class'            => '',
836
-                'options'          => $this->_yes_no_values,
837
-                'use_desc_4_label' => true,
838
-            ],
839
-        ];
840
-        $this->_template_args['inputs'] = EE_Question_Form_Input::generate_question_form_inputs_for_object(
841
-            $country,
842
-            $country_input_types
843
-        );
844
-        $country_details_settings       = EEH_Template::display_template(
845
-            GEN_SET_TEMPLATE_PATH . 'country_details_settings.template.php',
846
-            $this->_template_args,
847
-            true
848
-        );
849
-
850
-        if (defined('DOING_AJAX')) {
851
-            $notices = EE_Error::get_notices(false, false, false);
852
-            echo wp_json_encode(
853
-                [
854
-                    'return_data' => $country_details_settings,
855
-                    'success'     => $notices['success'],
856
-                    'errors'      => $notices['errors'],
857
-                ]
858
-            );
859
-            die();
860
-        }
861
-        return $country_details_settings;
862
-    }
863
-
864
-
865
-    /**
866
-     * @param string          $CNT_ISO
867
-     * @param EE_Country|null $country
868
-     * @return string
869
-     * @throws DomainException
870
-     * @throws EE_Error
871
-     * @throws InvalidArgumentException
872
-     * @throws InvalidDataTypeException
873
-     * @throws InvalidInterfaceException
874
-     * @throws ReflectionException
875
-     */
876
-    public function display_country_states(string $CNT_ISO = '', ?EE_Country $country = null): string
877
-    {
878
-        $CNT_ISO = $this->getCountryISO($CNT_ISO);
879
-        if (! $CNT_ISO) {
880
-            return '';
881
-        }
882
-        // for ajax
883
-        remove_all_filters('FHEE__EEH_Form_Fields__label_html');
884
-        remove_all_filters('FHEE__EEH_Form_Fields__input_html');
885
-        add_filter('FHEE__EEH_Form_Fields__label_html', [$this, 'state_form_field_label_wrap'], 10, 2);
886
-        add_filter('FHEE__EEH_Form_Fields__input_html', [$this, 'state_form_field_input__wrap'], 10);
887
-        $states = EEM_State::instance()->get_all_states_for_these_countries([$CNT_ISO => $CNT_ISO]);
888
-        if (empty($states)) {
889
-            /** @var EventEspresso\core\services\address\CountrySubRegionDao $countrySubRegionDao */
890
-            $countrySubRegionDao = $this->loader->getShared(
891
-                'EventEspresso\core\services\address\CountrySubRegionDao'
892
-            );
893
-            if ($countrySubRegionDao instanceof EventEspresso\core\services\address\CountrySubRegionDao) {
894
-                $country = $this->verifyOrGetCountryFromIso($CNT_ISO, $country);
895
-                if ($countrySubRegionDao->saveCountrySubRegions($country)) {
896
-                    $states = EEM_State::instance()->get_all_states_for_these_countries([$CNT_ISO => $CNT_ISO]);
897
-                }
898
-            }
899
-        }
900
-        if (is_array($states)) {
901
-            foreach ($states as $STA_ID => $state) {
902
-                if ($state instanceof EE_State) {
903
-                    $inputs = EE_Question_Form_Input::generate_question_form_inputs_for_object(
904
-                        $state,
905
-                        [
906
-                            'STA_abbrev' => [
907
-                                'type'             => 'TEXT',
908
-                                'label'            => esc_html__('Code', 'event_espresso'),
909
-                                'input_name'       => 'states[' . $STA_ID . ']',
910
-                                'class'            => 'small-text',
911
-                                'add_mobile_label' => true,
912
-                            ],
913
-                            'STA_name'   => [
914
-                                'type'             => 'TEXT',
915
-                                'label'            => esc_html__('Name', 'event_espresso'),
916
-                                'input_name'       => 'states[' . $STA_ID . ']',
917
-                                'class'            => 'regular-text',
918
-                                'add_mobile_label' => true,
919
-                            ],
920
-                            'STA_active' => [
921
-                                'type'             => 'RADIO_BTN',
922
-                                'label'            => esc_html__(
923
-                                    'State Appears in Dropdown Select Lists',
924
-                                    'event_espresso'
925
-                                ),
926
-                                'input_name'       => 'states[' . $STA_ID . ']',
927
-                                'options'          => $this->_yes_no_values,
928
-                                'use_desc_4_label' => true,
929
-                                'add_mobile_label' => true,
930
-                            ],
931
-                        ]
932
-                    );
933
-
934
-                    $delete_state_url = EE_Admin_Page::add_query_args_and_nonce(
935
-                        [
936
-                            'action'     => 'delete_state',
937
-                            'STA_ID'     => $STA_ID,
938
-                            'CNT_ISO'    => $CNT_ISO,
939
-                            'STA_abbrev' => $state->abbrev(),
940
-                        ],
941
-                        GEN_SET_ADMIN_URL
942
-                    );
943
-
944
-                    $this->_template_args['states'][ $STA_ID ]['inputs']           = $inputs;
945
-                    $this->_template_args['states'][ $STA_ID ]['delete_state_url'] = $delete_state_url;
946
-                }
947
-            }
948
-        } else {
949
-            $this->_template_args['states'] = false;
950
-        }
951
-
952
-        $this->_template_args['add_new_state_url'] = EE_Admin_Page::add_query_args_and_nonce(
953
-            ['action' => 'add_new_state'],
954
-            GEN_SET_ADMIN_URL
955
-        );
956
-
957
-        $state_details_settings = EEH_Template::display_template(
958
-            GEN_SET_TEMPLATE_PATH . 'state_details_settings.template.php',
959
-            $this->_template_args,
960
-            true
961
-        );
962
-
963
-        if (defined('DOING_AJAX')) {
964
-            $notices = EE_Error::get_notices(false, false, false);
965
-            echo wp_json_encode(
966
-                [
967
-                    'return_data' => $state_details_settings,
968
-                    'success'     => $notices['success'],
969
-                    'errors'      => $notices['errors'],
970
-                ]
971
-            );
972
-            die();
973
-        }
974
-        return $state_details_settings;
975
-    }
976
-
977
-
978
-    /**
979
-     * @return void
980
-     * @throws EE_Error
981
-     * @throws InvalidArgumentException
982
-     * @throws InvalidDataTypeException
983
-     * @throws InvalidInterfaceException
984
-     * @throws ReflectionException
985
-     */
986
-    public function add_new_state()
987
-    {
988
-        $success = true;
989
-        $CNT_ISO = $this->getCountryISO('');
990
-        if (! $CNT_ISO) {
991
-            EE_Error::add_error(
992
-                esc_html__('No Country ISO code or an invalid Country ISO code was received.', 'event_espresso'),
993
-                __FILE__,
994
-                __FUNCTION__,
995
-                __LINE__
996
-            );
997
-            $success = false;
998
-        }
999
-        $STA_abbrev = $this->request->getRequestParam('STA_abbrev');
1000
-        if (! $STA_abbrev) {
1001
-            EE_Error::add_error(
1002
-                esc_html__('No State ISO code or an invalid State ISO code was received.', 'event_espresso'),
1003
-                __FILE__,
1004
-                __FUNCTION__,
1005
-                __LINE__
1006
-            );
1007
-            $success = false;
1008
-        }
1009
-        $STA_name = $this->request->getRequestParam('STA_name');
1010
-        if (! $STA_name) {
1011
-            EE_Error::add_error(
1012
-                esc_html__('No State name or an invalid State name was received.', 'event_espresso'),
1013
-                __FILE__,
1014
-                __FUNCTION__,
1015
-                __LINE__
1016
-            );
1017
-            $success = false;
1018
-        }
1019
-
1020
-        if ($success) {
1021
-            $cols_n_values = [
1022
-                'CNT_ISO'    => $CNT_ISO,
1023
-                'STA_abbrev' => $STA_abbrev,
1024
-                'STA_name'   => $STA_name,
1025
-                'STA_active' => true,
1026
-            ];
1027
-            $success       = EEM_State::instance()->insert($cols_n_values);
1028
-            EE_Error::add_success(esc_html__('The State was added successfully.', 'event_espresso'));
1029
-        }
1030
-
1031
-        if (defined('DOING_AJAX')) {
1032
-            $notices = EE_Error::get_notices(false, false, false);
1033
-            echo wp_json_encode(array_merge($notices, ['return_data' => $CNT_ISO]));
1034
-            die();
1035
-        } else {
1036
-            $this->_redirect_after_action(
1037
-                $success,
1038
-                esc_html__('State', 'event_espresso'),
1039
-                'added',
1040
-                ['action' => 'country_settings']
1041
-            );
1042
-        }
1043
-    }
1044
-
1045
-
1046
-    /**
1047
-     * @return void
1048
-     * @throws EE_Error
1049
-     * @throws InvalidArgumentException
1050
-     * @throws InvalidDataTypeException
1051
-     * @throws InvalidInterfaceException
1052
-     * @throws ReflectionException
1053
-     */
1054
-    public function delete_state()
1055
-    {
1056
-        $CNT_ISO    = $this->getCountryISO();
1057
-        $STA_ID     = $this->request->getRequestParam('STA_ID');
1058
-        $STA_abbrev = $this->request->getRequestParam('STA_abbrev');
1059
-
1060
-        if (! $STA_ID) {
1061
-            EE_Error::add_error(
1062
-                esc_html__('No State ID or an invalid State ID was received.', 'event_espresso'),
1063
-                __FILE__,
1064
-                __FUNCTION__,
1065
-                __LINE__
1066
-            );
1067
-            return;
1068
-        }
1069
-
1070
-        $success = EEM_State::instance()->delete_by_ID($STA_ID);
1071
-        if ($success !== false) {
1072
-            do_action(
1073
-                'AHEE__General_Settings_Admin_Page__delete_state__state_deleted',
1074
-                $CNT_ISO,
1075
-                $STA_ID,
1076
-                ['STA_abbrev' => $STA_abbrev]
1077
-            );
1078
-            EE_Error::add_success(esc_html__('The State was deleted successfully.', 'event_espresso'));
1079
-        }
1080
-        if (defined('DOING_AJAX')) {
1081
-            $notices                = EE_Error::get_notices(false);
1082
-            $notices['return_data'] = true;
1083
-            echo wp_json_encode($notices);
1084
-            die();
1085
-        } else {
1086
-            $this->_redirect_after_action(
1087
-                $success,
1088
-                esc_html__('State', 'event_espresso'),
1089
-                'deleted',
1090
-                ['action' => 'country_settings']
1091
-            );
1092
-        }
1093
-    }
1094
-
1095
-
1096
-    /**
1097
-     *        _update_country_settings
1098
-     *
1099
-     * @return void
1100
-     * @throws EE_Error
1101
-     * @throws InvalidArgumentException
1102
-     * @throws InvalidDataTypeException
1103
-     * @throws InvalidInterfaceException
1104
-     * @throws ReflectionException
1105
-     */
1106
-    protected function _update_country_settings()
1107
-    {
1108
-        $CNT_ISO = $this->getCountryISO();
1109
-        if (! $CNT_ISO) {
1110
-            EE_Error::add_error(
1111
-                esc_html__('No Country ISO code or an invalid Country ISO code was received.', 'event_espresso'),
1112
-                __FILE__,
1113
-                __FUNCTION__,
1114
-                __LINE__
1115
-            );
1116
-            return;
1117
-        }
1118
-
1119
-        $country = $this->verifyOrGetCountryFromIso($CNT_ISO);
1120
-
1121
-        $cols_n_values                    = [];
1122
-        $cols_n_values['CNT_ISO3']        = strtoupper(
1123
-            $this->request->getRequestParam('cntry', $country->ISO3())
1124
-        );
1125
-        $cols_n_values['CNT_name']        = $this->request->getRequestParam(
1126
-            "cntry[$CNT_ISO][CNT_name]",
1127
-            $country->name()
1128
-        );
1129
-        $cols_n_values['CNT_cur_code']    = strtoupper(
1130
-            $this->request->getRequestParam(
1131
-                "cntry[$CNT_ISO][CNT_cur_code]",
1132
-                $country->currency_code()
1133
-            )
1134
-        );
1135
-        $cols_n_values['CNT_cur_single']  = $this->request->getRequestParam(
1136
-            "cntry[$CNT_ISO][CNT_cur_single]",
1137
-            $country->currency_name_single()
1138
-        );
1139
-        $cols_n_values['CNT_cur_plural']  = $this->request->getRequestParam(
1140
-            "cntry[$CNT_ISO][CNT_cur_plural]",
1141
-            $country->currency_name_plural()
1142
-        );
1143
-        $cols_n_values['CNT_cur_sign']    = $this->request->getRequestParam(
1144
-            "cntry[$CNT_ISO][CNT_cur_sign]",
1145
-            $country->currency_sign()
1146
-        );
1147
-        $cols_n_values['CNT_cur_sign_b4'] = $this->request->getRequestParam(
1148
-            "cntry[$CNT_ISO][CNT_cur_sign_b4]",
1149
-            $country->currency_sign_before(),
1150
-            DataType::BOOL
1151
-        );
1152
-        $cols_n_values['CNT_cur_dec_plc'] = $this->request->getRequestParam(
1153
-            "cntry[$CNT_ISO][CNT_cur_dec_plc]",
1154
-            $country->currency_decimal_places()
1155
-        );
1156
-        $cols_n_values['CNT_cur_dec_mrk'] = $this->request->getRequestParam(
1157
-            "cntry[$CNT_ISO][CNT_cur_dec_mrk]",
1158
-            $country->currency_decimal_mark()
1159
-        );
1160
-        $cols_n_values['CNT_cur_thsnds']  = $this->request->getRequestParam(
1161
-            "cntry[$CNT_ISO][CNT_cur_thsnds]",
1162
-            $country->currency_thousands_separator()
1163
-        );
1164
-        $cols_n_values['CNT_tel_code']    = $this->request->getRequestParam(
1165
-            "cntry[$CNT_ISO][CNT_tel_code]",
1166
-            $country->telephoneCode()
1167
-        );
1168
-        $cols_n_values['CNT_active']      = $this->request->getRequestParam(
1169
-            "cntry[$CNT_ISO][CNT_active]",
1170
-            $country->isActive(),
1171
-            DataType::BOOL
1172
-        );
1173
-
1174
-        // allow filtering of country data
1175
-        $cols_n_values = apply_filters(
1176
-            'FHEE__General_Settings_Admin_Page___update_country_settings__cols_n_values',
1177
-            $cols_n_values
1178
-        );
1179
-
1180
-        // where values
1181
-        $where_cols_n_values = [['CNT_ISO' => $CNT_ISO]];
1182
-        // run the update
1183
-        $success = EEM_Country::instance()->update($cols_n_values, $where_cols_n_values);
1184
-
1185
-        // allow filtering of states data
1186
-        $states = apply_filters(
1187
-            'FHEE__General_Settings_Admin_Page___update_country_settings__states',
1188
-            $this->request->getRequestParam('states', [], DataType::STRING, true)
1189
-        );
1190
-
1191
-        if (! empty($states) && $success !== false) {
1192
-            // loop thru state data ( looks like : states[75][STA_name] )
1193
-            foreach ($states as $STA_ID => $state) {
1194
-                $cols_n_values = [
1195
-                    'CNT_ISO'    => $CNT_ISO,
1196
-                    'STA_abbrev' => sanitize_text_field($state['STA_abbrev']),
1197
-                    'STA_name'   => sanitize_text_field($state['STA_name']),
1198
-                    'STA_active' => filter_var($state['STA_active'], FILTER_VALIDATE_BOOLEAN),
1199
-                ];
1200
-                // where values
1201
-                $where_cols_n_values = [['STA_ID' => $STA_ID]];
1202
-                // run the update
1203
-                $success = EEM_State::instance()->update($cols_n_values, $where_cols_n_values);
1204
-                if ($success !== false) {
1205
-                    do_action(
1206
-                        'AHEE__General_Settings_Admin_Page__update_country_settings__state_saved',
1207
-                        $CNT_ISO,
1208
-                        $STA_ID,
1209
-                        $cols_n_values
1210
-                    );
1211
-                }
1212
-            }
1213
-        }
1214
-        // check if country being edited matches org option country, and if so, then  update EE_Config with new settings
1215
-        if (
1216
-            isset(EE_Registry::instance()->CFG->organization->CNT_ISO)
1217
-            && $CNT_ISO == EE_Registry::instance()->CFG->organization->CNT_ISO
1218
-        ) {
1219
-            EE_Registry::instance()->CFG->currency = new EE_Currency_Config($CNT_ISO);
1220
-            EE_Registry::instance()->CFG->update_espresso_config();
1221
-        }
1222
-
1223
-        if ($success !== false) {
1224
-            EE_Error::add_success(
1225
-                esc_html__('Country Settings updated successfully.', 'event_espresso')
1226
-            );
1227
-        }
1228
-        $this->_redirect_after_action(
1229
-            $success,
1230
-            '',
1231
-            '',
1232
-            ['action' => 'country_settings', 'country' => $CNT_ISO],
1233
-            true
1234
-        );
1235
-    }
1236
-
1237
-
1238
-    /**
1239
-     * form_form_field_label_wrap
1240
-     *
1241
-     * @param string $label
1242
-     * @return string
1243
-     */
1244
-    public function country_form_field_label_wrap(string $label): string
1245
-    {
1246
-        return '
23
+	/**
24
+	 * @var EE_Core_Config
25
+	 */
26
+	public $core_config;
27
+
28
+
29
+	/**
30
+	 * Initialize basic properties.
31
+	 */
32
+	protected function _init_page_props()
33
+	{
34
+		$this->page_slug        = GEN_SET_PG_SLUG;
35
+		$this->page_label       = GEN_SET_LABEL;
36
+		$this->_admin_base_url  = GEN_SET_ADMIN_URL;
37
+		$this->_admin_base_path = GEN_SET_ADMIN;
38
+
39
+		$this->core_config = EE_Registry::instance()->CFG->core;
40
+	}
41
+
42
+
43
+	/**
44
+	 * Set ajax hooks
45
+	 */
46
+	protected function _ajax_hooks()
47
+	{
48
+		add_action('wp_ajax_espresso_display_country_settings', [$this, 'display_country_settings']);
49
+		add_action('wp_ajax_espresso_display_country_states', [$this, 'display_country_states']);
50
+		add_action('wp_ajax_espresso_delete_state', [$this, 'delete_state'], 10, 3);
51
+		add_action('wp_ajax_espresso_add_new_state', [$this, 'add_new_state']);
52
+	}
53
+
54
+
55
+	/**
56
+	 * More page properties initialization.
57
+	 */
58
+	protected function _define_page_props()
59
+	{
60
+		$this->_admin_page_title = GEN_SET_LABEL;
61
+		$this->_labels           = ['publishbox' => esc_html__('Update Settings', 'event_espresso')];
62
+	}
63
+
64
+
65
+	/**
66
+	 * Set page routes property.
67
+	 */
68
+	protected function _set_page_routes()
69
+	{
70
+		$this->_page_routes = [
71
+			'critical_pages'                => [
72
+				'func'       => '_espresso_page_settings',
73
+				'capability' => 'manage_options',
74
+			],
75
+			'update_espresso_page_settings' => [
76
+				'func'       => '_update_espresso_page_settings',
77
+				'capability' => 'manage_options',
78
+				'noheader'   => true,
79
+			],
80
+			'default'                       => [
81
+				'func'       => '_your_organization_settings',
82
+				'capability' => 'manage_options',
83
+			],
84
+
85
+			'update_your_organization_settings' => [
86
+				'func'       => '_update_your_organization_settings',
87
+				'capability' => 'manage_options',
88
+				'noheader'   => true,
89
+			],
90
+
91
+			'admin_option_settings' => [
92
+				'func'       => '_admin_option_settings',
93
+				'capability' => 'manage_options',
94
+			],
95
+
96
+			'update_admin_option_settings' => [
97
+				'func'       => '_update_admin_option_settings',
98
+				'capability' => 'manage_options',
99
+				'noheader'   => true,
100
+			],
101
+
102
+			'country_settings' => [
103
+				'func'       => '_country_settings',
104
+				'capability' => 'manage_options',
105
+			],
106
+
107
+			'update_country_settings' => [
108
+				'func'       => '_update_country_settings',
109
+				'capability' => 'manage_options',
110
+				'noheader'   => true,
111
+			],
112
+
113
+			'display_country_settings' => [
114
+				'func'       => 'display_country_settings',
115
+				'capability' => 'manage_options',
116
+				'noheader'   => true,
117
+			],
118
+
119
+			'add_new_state' => [
120
+				'func'       => 'add_new_state',
121
+				'capability' => 'manage_options',
122
+				'noheader'   => true,
123
+			],
124
+
125
+			'delete_state'            => [
126
+				'func'       => 'delete_state',
127
+				'capability' => 'manage_options',
128
+				'noheader'   => true,
129
+			],
130
+			'privacy_settings'        => [
131
+				'func'       => 'privacySettings',
132
+				'capability' => 'manage_options',
133
+			],
134
+			'update_privacy_settings' => [
135
+				'func'               => 'updatePrivacySettings',
136
+				'capability'         => 'manage_options',
137
+				'noheader'           => true,
138
+				'headers_sent_route' => 'privacy_settings',
139
+			],
140
+		];
141
+	}
142
+
143
+
144
+	/**
145
+	 * Set page configuration property
146
+	 */
147
+	protected function _set_page_config()
148
+	{
149
+		$this->_page_config = [
150
+			'critical_pages'        => [
151
+				'nav'           => [
152
+					'label' => esc_html__('Critical Pages', 'event_espresso'),
153
+					'order' => 50,
154
+				],
155
+				'metaboxes'     => array_merge($this->_default_espresso_metaboxes, ['_publish_post_box']),
156
+				'help_tabs'     => [
157
+					'general_settings_critical_pages_help_tab' => [
158
+						'title'    => esc_html__('Critical Pages', 'event_espresso'),
159
+						'filename' => 'general_settings_critical_pages',
160
+					],
161
+				],
162
+				'require_nonce' => false,
163
+			],
164
+			'default'               => [
165
+				'nav'           => [
166
+					'label' => esc_html__('Your Organization', 'event_espresso'),
167
+					'order' => 20,
168
+				],
169
+				'help_tabs'     => [
170
+					'general_settings_your_organization_help_tab' => [
171
+						'title'    => esc_html__('Your Organization', 'event_espresso'),
172
+						'filename' => 'general_settings_your_organization',
173
+					],
174
+				],
175
+				'metaboxes'     => array_merge($this->_default_espresso_metaboxes, ['_publish_post_box']),
176
+				'require_nonce' => false,
177
+			],
178
+			'admin_option_settings' => [
179
+				'nav'           => [
180
+					'label' => esc_html__('Admin Options', 'event_espresso'),
181
+					'order' => 60,
182
+				],
183
+				'metaboxes'     => array_merge($this->_default_espresso_metaboxes, ['_publish_post_box']),
184
+				'help_tabs'     => [
185
+					'general_settings_admin_options_help_tab' => [
186
+						'title'    => esc_html__('Admin Options', 'event_espresso'),
187
+						'filename' => 'general_settings_admin_options',
188
+					],
189
+				],
190
+				'require_nonce' => false,
191
+			],
192
+			'country_settings'      => [
193
+				'nav'           => [
194
+					'label' => esc_html__('Countries', 'event_espresso'),
195
+					'order' => 70,
196
+				],
197
+				'help_tabs'     => [
198
+					'general_settings_countries_help_tab' => [
199
+						'title'    => esc_html__('Countries', 'event_espresso'),
200
+						'filename' => 'general_settings_countries',
201
+					],
202
+				],
203
+				'require_nonce' => false,
204
+			],
205
+			'privacy_settings'      => [
206
+				'nav'           => [
207
+					'label' => esc_html__('Privacy', 'event_espresso'),
208
+					'order' => 80,
209
+				],
210
+				'metaboxes'     => array_merge($this->_default_espresso_metaboxes, ['_publish_post_box']),
211
+				'require_nonce' => false,
212
+			],
213
+		];
214
+	}
215
+
216
+
217
+	protected function _add_screen_options()
218
+	{
219
+	}
220
+
221
+
222
+	protected function _add_feature_pointers()
223
+	{
224
+	}
225
+
226
+
227
+	/**
228
+	 * Enqueue global scripts and styles for all routes in the General Settings Admin Pages.
229
+	 */
230
+	public function load_scripts_styles()
231
+	{
232
+		// styles
233
+		wp_enqueue_style('espresso-ui-theme');
234
+		// scripts
235
+		wp_enqueue_script('ee_admin_js');
236
+	}
237
+
238
+
239
+	/**
240
+	 * Execute logic running on `admin_init`
241
+	 */
242
+	public function admin_init()
243
+	{
244
+		EE_Registry::$i18n_js_strings['invalid_server_response'] = wp_strip_all_tags(
245
+			esc_html__(
246
+				'An error occurred! Your request may have been processed, but a valid response from the server was not received. Please refresh the page and try again.',
247
+				'event_espresso'
248
+			)
249
+		);
250
+		EE_Registry::$i18n_js_strings['error_occurred']          = wp_strip_all_tags(
251
+			esc_html__(
252
+				'An error occurred! Please refresh the page and try again.',
253
+				'event_espresso'
254
+			)
255
+		);
256
+		EE_Registry::$i18n_js_strings['confirm_delete_state']    = wp_strip_all_tags(
257
+			esc_html__(
258
+				'Are you sure you want to delete this State / Province?',
259
+				'event_espresso'
260
+			)
261
+		);
262
+		EE_Registry::$i18n_js_strings['ajax_url']                = admin_url(
263
+			'admin-ajax.php?page=espresso_general_settings',
264
+			is_ssl() ? 'https://' : 'http://'
265
+		);
266
+	}
267
+
268
+
269
+	public function admin_notices()
270
+	{
271
+	}
272
+
273
+
274
+	public function admin_footer_scripts()
275
+	{
276
+	}
277
+
278
+
279
+	/**
280
+	 * Enqueue scripts and styles for the default route.
281
+	 */
282
+	public function load_scripts_styles_default()
283
+	{
284
+		// styles
285
+		wp_enqueue_style('thickbox');
286
+		// scripts
287
+		wp_enqueue_script('media-upload');
288
+		wp_enqueue_script('thickbox');
289
+		wp_register_script(
290
+			'organization_settings',
291
+			GEN_SET_ASSETS_URL . 'your_organization_settings.js',
292
+			['jquery', 'media-upload', 'thickbox'],
293
+			EVENT_ESPRESSO_VERSION,
294
+			true
295
+		);
296
+		wp_register_style('organization-css', GEN_SET_ASSETS_URL . 'organization.css', [], EVENT_ESPRESSO_VERSION);
297
+		wp_enqueue_script('organization_settings');
298
+		wp_enqueue_style('organization-css');
299
+		$confirm_image_delete = [
300
+			'text' => wp_strip_all_tags(
301
+				esc_html__(
302
+					'Do you really want to delete this image? Please remember to save your settings to complete the removal.',
303
+					'event_espresso'
304
+				)
305
+			),
306
+		];
307
+		wp_localize_script('organization_settings', 'confirm_image_delete', $confirm_image_delete);
308
+	}
309
+
310
+
311
+	/**
312
+	 * Enqueue scripts and styles for the country settings route.
313
+	 */
314
+	public function load_scripts_styles_country_settings()
315
+	{
316
+		// scripts
317
+		wp_register_script(
318
+			'gen_settings_countries',
319
+			GEN_SET_ASSETS_URL . 'gen_settings_countries.js',
320
+			['ee_admin_js'],
321
+			EVENT_ESPRESSO_VERSION,
322
+			true
323
+		);
324
+		wp_register_style('organization-css', GEN_SET_ASSETS_URL . 'organization.css', [], EVENT_ESPRESSO_VERSION);
325
+		wp_enqueue_script('gen_settings_countries');
326
+		wp_enqueue_style('organization-css');
327
+	}
328
+
329
+
330
+	/*************        Espresso Pages        *************/
331
+	/**
332
+	 * _espresso_page_settings
333
+	 *
334
+	 * @throws EE_Error
335
+	 * @throws DomainException
336
+	 * @throws DomainException
337
+	 * @throws InvalidDataTypeException
338
+	 * @throws InvalidArgumentException
339
+	 */
340
+	protected function _espresso_page_settings()
341
+	{
342
+		// Check to make sure all of the main pages are set up properly,
343
+		// if not create the default pages and display an admin notice
344
+		EEH_Activation::verify_default_pages_exist();
345
+		$this->_transient_garbage_collection();
346
+
347
+		$this->_template_args['values'] = $this->_yes_no_values;
348
+
349
+		$this->_template_args['reg_page_id']  = $this->core_config->reg_page_id ?? null;
350
+		$this->_template_args['reg_page_obj'] = isset($this->core_config->reg_page_id)
351
+			? get_post($this->core_config->reg_page_id)
352
+			: false;
353
+
354
+		$this->_template_args['txn_page_id']  = $this->core_config->txn_page_id ?? null;
355
+		$this->_template_args['txn_page_obj'] = isset($this->core_config->txn_page_id)
356
+			? get_post($this->core_config->txn_page_id)
357
+			: false;
358
+
359
+		$this->_template_args['thank_you_page_id']  = $this->core_config->thank_you_page_id ?? null;
360
+		$this->_template_args['thank_you_page_obj'] = isset($this->core_config->thank_you_page_id)
361
+			? get_post($this->core_config->thank_you_page_id)
362
+			: false;
363
+
364
+		$this->_template_args['cancel_page_id']  = $this->core_config->cancel_page_id ?? null;
365
+		$this->_template_args['cancel_page_obj'] = isset($this->core_config->cancel_page_id)
366
+			? get_post($this->core_config->cancel_page_id)
367
+			: false;
368
+
369
+		$this->_set_add_edit_form_tags('update_espresso_page_settings');
370
+		$this->_set_publish_post_box_vars(null, false, false, null, false);
371
+		$this->_template_args['admin_page_content'] = EEH_Template::display_template(
372
+			GEN_SET_TEMPLATE_PATH . 'espresso_page_settings.template.php',
373
+			$this->_template_args,
374
+			true
375
+		);
376
+		$this->display_admin_page_with_sidebar();
377
+	}
378
+
379
+
380
+	/**
381
+	 * Handler for updating espresso page settings.
382
+	 *
383
+	 * @throws EE_Error
384
+	 */
385
+	protected function _update_espresso_page_settings()
386
+	{
387
+		// capture incoming request data && set page IDs
388
+		$this->core_config->reg_page_id       = $this->request->getRequestParam(
389
+			'reg_page_id',
390
+			$this->core_config->reg_page_id,
391
+			DataType::INT
392
+		);
393
+		$this->core_config->txn_page_id       = $this->request->getRequestParam(
394
+			'txn_page_id',
395
+			$this->core_config->txn_page_id,
396
+			DataType::INT
397
+		);
398
+		$this->core_config->thank_you_page_id = $this->request->getRequestParam(
399
+			'thank_you_page_id',
400
+			$this->core_config->thank_you_page_id,
401
+			DataType::INT
402
+		);
403
+		$this->core_config->cancel_page_id    = $this->request->getRequestParam(
404
+			'cancel_page_id',
405
+			$this->core_config->cancel_page_id,
406
+			DataType::INT
407
+		);
408
+
409
+		$this->core_config = apply_filters(
410
+			'FHEE__General_Settings_Admin_Page___update_espresso_page_settings__CFG_core',
411
+			$this->core_config,
412
+			$this->request->requestParams()
413
+		);
414
+
415
+		$what = esc_html__('Critical Pages & Shortcodes', 'event_espresso');
416
+		$this->_redirect_after_action(
417
+			$this->_update_espresso_configuration(
418
+				$what,
419
+				$this->core_config,
420
+				__FILE__,
421
+				__FUNCTION__,
422
+				__LINE__
423
+			),
424
+			$what,
425
+			'',
426
+			[
427
+				'action' => 'critical_pages',
428
+			],
429
+			true
430
+		);
431
+	}
432
+
433
+
434
+	/*************        Your Organization        *************/
435
+
436
+
437
+	/**
438
+	 * @throws DomainException
439
+	 * @throws EE_Error
440
+	 * @throws InvalidArgumentException
441
+	 * @throws InvalidDataTypeException
442
+	 * @throws InvalidInterfaceException
443
+	 */
444
+	protected function _your_organization_settings()
445
+	{
446
+		$this->_template_args['admin_page_content'] = '';
447
+		try {
448
+			/** @var OrganizationSettings $organization_settings_form */
449
+			$organization_settings_form = $this->loader->getShared(OrganizationSettings::class);
450
+
451
+			$this->_template_args['admin_page_content'] = EEH_HTML::div(
452
+				$organization_settings_form->display(),
453
+				'',
454
+				'padding'
455
+			);
456
+		} catch (Exception $e) {
457
+			EE_Error::add_error($e->getMessage(), __FILE__, __FUNCTION__, __LINE__);
458
+		}
459
+		$this->_set_add_edit_form_tags('update_your_organization_settings');
460
+		$this->_set_publish_post_box_vars(null, false, false, null, false);
461
+		$this->display_admin_page_with_sidebar();
462
+	}
463
+
464
+
465
+	/**
466
+	 * Handler for updating organization settings.
467
+	 *
468
+	 * @throws EE_Error
469
+	 */
470
+	protected function _update_your_organization_settings()
471
+	{
472
+		try {
473
+			/** @var OrganizationSettings $organization_settings_form */
474
+			$organization_settings_form = $this->loader->getShared(OrganizationSettings::class);
475
+
476
+			$success = $organization_settings_form->process($this->request->requestParams());
477
+
478
+			EE_Registry::instance()->CFG = apply_filters(
479
+				'FHEE__General_Settings_Admin_Page___update_your_organization_settings__CFG',
480
+				EE_Registry::instance()->CFG
481
+			);
482
+		} catch (Exception $e) {
483
+			EE_Error::add_error($e->getMessage(), __FILE__, __FUNCTION__, __LINE__);
484
+			$success = false;
485
+		}
486
+
487
+		if ($success) {
488
+			$success = $this->_update_espresso_configuration(
489
+				esc_html__('Your Organization Settings', 'event_espresso'),
490
+				EE_Registry::instance()->CFG,
491
+				__FILE__,
492
+				__FUNCTION__,
493
+				__LINE__
494
+			);
495
+		}
496
+
497
+		$this->_redirect_after_action($success, '', '', ['action' => 'default'], true);
498
+	}
499
+
500
+
501
+
502
+	/*************        Admin Options        *************/
503
+
504
+
505
+	/**
506
+	 * _admin_option_settings
507
+	 *
508
+	 * @throws EE_Error
509
+	 * @throws LogicException
510
+	 */
511
+	protected function _admin_option_settings()
512
+	{
513
+		$this->_template_args['admin_page_content'] = '';
514
+		try {
515
+			$admin_options_settings_form = new AdminOptionsSettings(EE_Registry::instance());
516
+			// still need this for the old school form in Extend_General_Settings_Admin_Page
517
+			$this->_template_args['values'] = $this->_yes_no_values;
518
+			// also need to account for the do_action that was in the old template
519
+			$admin_options_settings_form->setTemplateArgs($this->_template_args);
520
+			$this->_template_args['admin_page_content'] = $admin_options_settings_form->display();
521
+		} catch (Exception $e) {
522
+			EE_Error::add_error($e->getMessage(), __FILE__, __FUNCTION__, __LINE__);
523
+		}
524
+		$this->_set_add_edit_form_tags('update_admin_option_settings');
525
+		$this->_set_publish_post_box_vars(null, false, false, null, false);
526
+		$this->display_admin_page_with_sidebar();
527
+	}
528
+
529
+
530
+	/**
531
+	 * _update_admin_option_settings
532
+	 *
533
+	 * @throws EE_Error
534
+	 * @throws InvalidDataTypeException
535
+	 * @throws InvalidFormSubmissionException
536
+	 * @throws InvalidArgumentException
537
+	 * @throws LogicException
538
+	 */
539
+	protected function _update_admin_option_settings()
540
+	{
541
+		try {
542
+			$admin_options_settings_form = new AdminOptionsSettings(EE_Registry::instance());
543
+			$admin_options_settings_form->process(
544
+				$this->request->getRequestParam(
545
+					$admin_options_settings_form->slug(),
546
+					[],
547
+					DataType::OBJECT // need to change this to ARRAY after min PHP version gets bumped to 7+
548
+				)
549
+			);
550
+			EE_Registry::instance()->CFG->admin = apply_filters(
551
+				'FHEE__General_Settings_Admin_Page___update_admin_option_settings__CFG_admin',
552
+				EE_Registry::instance()->CFG->admin
553
+			);
554
+		} catch (Exception $e) {
555
+			EE_Error::add_error($e->getMessage(), __FILE__, __FUNCTION__, __LINE__);
556
+		}
557
+		$this->_redirect_after_action(
558
+			apply_filters(
559
+				'FHEE__General_Settings_Admin_Page___update_admin_option_settings__success',
560
+				$this->_update_espresso_configuration(
561
+					esc_html__('Admin Options', 'event_espresso'),
562
+					EE_Registry::instance()->CFG->admin,
563
+					__FILE__,
564
+					__FUNCTION__,
565
+					__LINE__
566
+				)
567
+			),
568
+			esc_html__('Admin Options', 'event_espresso'),
569
+			'updated',
570
+			['action' => 'admin_option_settings']
571
+		);
572
+	}
573
+
574
+
575
+	/*************        Countries        *************/
576
+
577
+
578
+	/**
579
+	 * @param string|null $default
580
+	 * @return string
581
+	 */
582
+	protected function getCountryISO(?string $default = null): string
583
+	{
584
+		$default = $default ?? $this->getCountryIsoForSite();
585
+		$CNT_ISO = $this->request->getRequestParam('country', $default);
586
+		$CNT_ISO = $this->request->getRequestParam('CNT_ISO', $CNT_ISO);
587
+		return strtoupper($CNT_ISO);
588
+	}
589
+
590
+
591
+	/**
592
+	 * @return string
593
+	 */
594
+	protected function getCountryIsoForSite(): string
595
+	{
596
+		return ! empty(EE_Registry::instance()->CFG->organization->CNT_ISO)
597
+			? EE_Registry::instance()->CFG->organization->CNT_ISO
598
+			: 'US';
599
+	}
600
+
601
+
602
+	/**
603
+	 * @param string          $CNT_ISO
604
+	 * @param EE_Country|null $country
605
+	 * @return EE_Base_Class|EE_Country
606
+	 * @throws EE_Error
607
+	 * @throws InvalidArgumentException
608
+	 * @throws InvalidDataTypeException
609
+	 * @throws InvalidInterfaceException
610
+	 * @throws ReflectionException
611
+	 */
612
+	protected function verifyOrGetCountryFromIso(string $CNT_ISO, ?EE_Country $country = null)
613
+	{
614
+		/** @var EE_Country $country */
615
+		return $country instanceof EE_Country && $country->ID() === $CNT_ISO
616
+			? $country
617
+			: EEM_Country::instance()->get_one_by_ID($CNT_ISO);
618
+	}
619
+
620
+
621
+	/**
622
+	 * Output Country Settings view.
623
+	 *
624
+	 * @throws DomainException
625
+	 * @throws EE_Error
626
+	 * @throws InvalidArgumentException
627
+	 * @throws InvalidDataTypeException
628
+	 * @throws InvalidInterfaceException
629
+	 * @throws ReflectionException
630
+	 */
631
+	protected function _country_settings()
632
+	{
633
+		$CNT_ISO = $this->getCountryISO();
634
+
635
+		$this->_template_args['values']    = $this->_yes_no_values;
636
+		$this->_template_args['countries'] = new EE_Question_Form_Input(
637
+			EE_Question::new_instance(
638
+				[
639
+					'QST_ID'           => 0,
640
+					'QST_display_text' => esc_html__('Select Country', 'event_espresso'),
641
+					'QST_system'       => 'admin-country',
642
+				]
643
+			),
644
+			EE_Answer::new_instance(
645
+				[
646
+					'ANS_ID'    => 0,
647
+					'ANS_value' => $CNT_ISO,
648
+				]
649
+			),
650
+			[
651
+				'input_id'       => 'country',
652
+				'input_name'     => 'country',
653
+				'input_prefix'   => '',
654
+				'append_qstn_id' => false,
655
+			]
656
+		);
657
+
658
+		$country = $this->verifyOrGetCountryFromIso($CNT_ISO);
659
+		add_filter('FHEE__EEH_Form_Fields__label_html', [$this, 'country_form_field_label_wrap'], 10);
660
+		add_filter('FHEE__EEH_Form_Fields__input_html', [$this, 'country_form_field_input__wrap'], 10);
661
+		$this->_template_args['country_details_settings'] = $this->display_country_settings(
662
+			$country->ID(),
663
+			$country
664
+		);
665
+		$this->_template_args['country_states_settings']  = $this->display_country_states(
666
+			$country->ID(),
667
+			$country
668
+		);
669
+		$this->_template_args['CNT_name_for_site']        = $country->name();
670
+
671
+		$this->_set_add_edit_form_tags('update_country_settings');
672
+		$this->_set_publish_post_box_vars(null, false, false, null, false);
673
+		$this->_template_args['admin_page_content'] = EEH_Template::display_template(
674
+			GEN_SET_TEMPLATE_PATH . 'countries_settings.template.php',
675
+			$this->_template_args,
676
+			true
677
+		);
678
+		$this->display_admin_page_with_no_sidebar();
679
+	}
680
+
681
+
682
+	/**
683
+	 * @param string          $CNT_ISO
684
+	 * @param EE_Country|null $country
685
+	 * @return string
686
+	 * @throws DomainException
687
+	 * @throws EE_Error
688
+	 * @throws InvalidArgumentException
689
+	 * @throws InvalidDataTypeException
690
+	 * @throws InvalidInterfaceException
691
+	 * @throws ReflectionException
692
+	 */
693
+	public function display_country_settings(string $CNT_ISO = '', ?EE_Country $country = null): string
694
+	{
695
+		$CNT_ISO          = $this->getCountryISO($CNT_ISO);
696
+		$CNT_ISO_for_site = $this->getCountryIsoForSite();
697
+
698
+		if (! $CNT_ISO) {
699
+			return '';
700
+		}
701
+
702
+		// for ajax
703
+		remove_all_filters('FHEE__EEH_Form_Fields__label_html');
704
+		remove_all_filters('FHEE__EEH_Form_Fields__input_html');
705
+		add_filter('FHEE__EEH_Form_Fields__label_html', [$this, 'country_form_field_label_wrap'], 10, 2);
706
+		add_filter('FHEE__EEH_Form_Fields__input_html', [$this, 'country_form_field_input__wrap'], 10, 2);
707
+		$country                                  = $this->verifyOrGetCountryFromIso($CNT_ISO, $country);
708
+		$CNT_cur_disabled                         = $CNT_ISO !== $CNT_ISO_for_site;
709
+		$this->_template_args['CNT_cur_disabled'] = $CNT_cur_disabled;
710
+
711
+		$country_input_types            = [
712
+			'CNT_active'      => [
713
+				'type'             => 'RADIO_BTN',
714
+				'input_name'       => 'cntry[' . $CNT_ISO . ']',
715
+				'class'            => '',
716
+				'options'          => $this->_yes_no_values,
717
+				'use_desc_4_label' => true,
718
+			],
719
+			'CNT_ISO'         => [
720
+				'type'       => 'TEXT',
721
+				'input_name' => 'cntry[' . $CNT_ISO . ']',
722
+				'class'      => 'small-text',
723
+			],
724
+			'CNT_ISO3'        => [
725
+				'type'       => 'TEXT',
726
+				'input_name' => 'cntry[' . $CNT_ISO . ']',
727
+				'class'      => 'small-text',
728
+			],
729
+			// 'RGN_ID'          => [
730
+			//     'type'       => 'TEXT',
731
+			//     'input_name' => 'cntry[' . $CNT_ISO . ']',
732
+			//     'class'      => 'ee-input-size--small',
733
+			// ],
734
+			'CNT_name'        => [
735
+				'type'       => 'TEXT',
736
+				'input_name' => 'cntry[' . $CNT_ISO . ']',
737
+				'class'      => 'regular-text',
738
+			],
739
+			'CNT_cur_code'    => [
740
+				'type'       => 'TEXT',
741
+				'input_name' => 'cntry[' . $CNT_ISO . ']',
742
+				'class'      => 'small-text',
743
+				'disabled'   => $CNT_cur_disabled,
744
+			],
745
+			'CNT_cur_single'  => [
746
+				'type'       => 'TEXT',
747
+				'input_name' => 'cntry[' . $CNT_ISO . ']',
748
+				'class'      => 'medium-text',
749
+				'disabled'   => $CNT_cur_disabled,
750
+			],
751
+			'CNT_cur_plural'  => [
752
+				'type'       => 'TEXT',
753
+				'input_name' => 'cntry[' . $CNT_ISO . ']',
754
+				'class'      => 'medium-text',
755
+				'disabled'   => $CNT_cur_disabled,
756
+			],
757
+			'CNT_cur_sign'    => [
758
+				'type'         => 'TEXT',
759
+				'input_name'   => 'cntry[' . $CNT_ISO . ']',
760
+				'class'        => 'small-text',
761
+				'htmlentities' => false,
762
+				'disabled'     => $CNT_cur_disabled,
763
+			],
764
+			'CNT_cur_sign_b4' => [
765
+				'type'             => 'RADIO_BTN',
766
+				'input_name'       => 'cntry[' . $CNT_ISO . ']',
767
+				'class'            => '',
768
+				'options'          => $this->_yes_no_values,
769
+				'use_desc_4_label' => true,
770
+				'disabled'         => $CNT_cur_disabled,
771
+			],
772
+			'CNT_cur_dec_plc' => [
773
+				'type'       => 'RADIO_BTN',
774
+				'input_name' => 'cntry[' . $CNT_ISO . ']',
775
+				'class'      => '',
776
+				'options'    => [
777
+					['id' => 0, 'text' => ''],
778
+					['id' => 1, 'text' => ''],
779
+					['id' => 2, 'text' => ''],
780
+					['id' => 3, 'text' => ''],
781
+				],
782
+				'disabled'   => $CNT_cur_disabled,
783
+			],
784
+			'CNT_cur_dec_mrk' => [
785
+				'type'             => 'RADIO_BTN',
786
+				'input_name'       => 'cntry[' . $CNT_ISO . ']',
787
+				'class'            => '',
788
+				'options'          => [
789
+					[
790
+						'id'   => ',',
791
+						'text' => esc_html__(', (comma)', 'event_espresso'),
792
+					],
793
+					['id' => '.', 'text' => esc_html__('. (decimal)', 'event_espresso')],
794
+				],
795
+				'use_desc_4_label' => true,
796
+				'disabled'         => $CNT_cur_disabled,
797
+			],
798
+			'CNT_cur_thsnds'  => [
799
+				'type'             => 'RADIO_BTN',
800
+				'input_name'       => 'cntry[' . $CNT_ISO . ']',
801
+				'class'            => '',
802
+				'options'          => [
803
+					[
804
+						'id'   => ',',
805
+						'text' => esc_html__(', (comma)', 'event_espresso'),
806
+					],
807
+					[
808
+						'id'   => '.',
809
+						'text' => esc_html__('. (decimal)', 'event_espresso'),
810
+					],
811
+					[
812
+						'id'   => '&nbsp;',
813
+						'text' => esc_html__('(space)', 'event_espresso'),
814
+					],
815
+					[
816
+						'id'   => '_',
817
+						'text' => esc_html__('_ (underscore)', 'event_espresso'),
818
+					],
819
+					[
820
+						'id'   => "'",
821
+						'text' => esc_html__("' (apostrophe)", 'event_espresso'),
822
+					],
823
+				],
824
+				'use_desc_4_label' => true,
825
+				'disabled'         => $CNT_cur_disabled,
826
+			],
827
+			'CNT_tel_code'    => [
828
+				'type'       => 'TEXT',
829
+				'input_name' => 'cntry[' . $CNT_ISO . ']',
830
+				'class'      => 'small-text',
831
+			],
832
+			'CNT_is_EU'       => [
833
+				'type'             => 'RADIO_BTN',
834
+				'input_name'       => 'cntry[' . $CNT_ISO . ']',
835
+				'class'            => '',
836
+				'options'          => $this->_yes_no_values,
837
+				'use_desc_4_label' => true,
838
+			],
839
+		];
840
+		$this->_template_args['inputs'] = EE_Question_Form_Input::generate_question_form_inputs_for_object(
841
+			$country,
842
+			$country_input_types
843
+		);
844
+		$country_details_settings       = EEH_Template::display_template(
845
+			GEN_SET_TEMPLATE_PATH . 'country_details_settings.template.php',
846
+			$this->_template_args,
847
+			true
848
+		);
849
+
850
+		if (defined('DOING_AJAX')) {
851
+			$notices = EE_Error::get_notices(false, false, false);
852
+			echo wp_json_encode(
853
+				[
854
+					'return_data' => $country_details_settings,
855
+					'success'     => $notices['success'],
856
+					'errors'      => $notices['errors'],
857
+				]
858
+			);
859
+			die();
860
+		}
861
+		return $country_details_settings;
862
+	}
863
+
864
+
865
+	/**
866
+	 * @param string          $CNT_ISO
867
+	 * @param EE_Country|null $country
868
+	 * @return string
869
+	 * @throws DomainException
870
+	 * @throws EE_Error
871
+	 * @throws InvalidArgumentException
872
+	 * @throws InvalidDataTypeException
873
+	 * @throws InvalidInterfaceException
874
+	 * @throws ReflectionException
875
+	 */
876
+	public function display_country_states(string $CNT_ISO = '', ?EE_Country $country = null): string
877
+	{
878
+		$CNT_ISO = $this->getCountryISO($CNT_ISO);
879
+		if (! $CNT_ISO) {
880
+			return '';
881
+		}
882
+		// for ajax
883
+		remove_all_filters('FHEE__EEH_Form_Fields__label_html');
884
+		remove_all_filters('FHEE__EEH_Form_Fields__input_html');
885
+		add_filter('FHEE__EEH_Form_Fields__label_html', [$this, 'state_form_field_label_wrap'], 10, 2);
886
+		add_filter('FHEE__EEH_Form_Fields__input_html', [$this, 'state_form_field_input__wrap'], 10);
887
+		$states = EEM_State::instance()->get_all_states_for_these_countries([$CNT_ISO => $CNT_ISO]);
888
+		if (empty($states)) {
889
+			/** @var EventEspresso\core\services\address\CountrySubRegionDao $countrySubRegionDao */
890
+			$countrySubRegionDao = $this->loader->getShared(
891
+				'EventEspresso\core\services\address\CountrySubRegionDao'
892
+			);
893
+			if ($countrySubRegionDao instanceof EventEspresso\core\services\address\CountrySubRegionDao) {
894
+				$country = $this->verifyOrGetCountryFromIso($CNT_ISO, $country);
895
+				if ($countrySubRegionDao->saveCountrySubRegions($country)) {
896
+					$states = EEM_State::instance()->get_all_states_for_these_countries([$CNT_ISO => $CNT_ISO]);
897
+				}
898
+			}
899
+		}
900
+		if (is_array($states)) {
901
+			foreach ($states as $STA_ID => $state) {
902
+				if ($state instanceof EE_State) {
903
+					$inputs = EE_Question_Form_Input::generate_question_form_inputs_for_object(
904
+						$state,
905
+						[
906
+							'STA_abbrev' => [
907
+								'type'             => 'TEXT',
908
+								'label'            => esc_html__('Code', 'event_espresso'),
909
+								'input_name'       => 'states[' . $STA_ID . ']',
910
+								'class'            => 'small-text',
911
+								'add_mobile_label' => true,
912
+							],
913
+							'STA_name'   => [
914
+								'type'             => 'TEXT',
915
+								'label'            => esc_html__('Name', 'event_espresso'),
916
+								'input_name'       => 'states[' . $STA_ID . ']',
917
+								'class'            => 'regular-text',
918
+								'add_mobile_label' => true,
919
+							],
920
+							'STA_active' => [
921
+								'type'             => 'RADIO_BTN',
922
+								'label'            => esc_html__(
923
+									'State Appears in Dropdown Select Lists',
924
+									'event_espresso'
925
+								),
926
+								'input_name'       => 'states[' . $STA_ID . ']',
927
+								'options'          => $this->_yes_no_values,
928
+								'use_desc_4_label' => true,
929
+								'add_mobile_label' => true,
930
+							],
931
+						]
932
+					);
933
+
934
+					$delete_state_url = EE_Admin_Page::add_query_args_and_nonce(
935
+						[
936
+							'action'     => 'delete_state',
937
+							'STA_ID'     => $STA_ID,
938
+							'CNT_ISO'    => $CNT_ISO,
939
+							'STA_abbrev' => $state->abbrev(),
940
+						],
941
+						GEN_SET_ADMIN_URL
942
+					);
943
+
944
+					$this->_template_args['states'][ $STA_ID ]['inputs']           = $inputs;
945
+					$this->_template_args['states'][ $STA_ID ]['delete_state_url'] = $delete_state_url;
946
+				}
947
+			}
948
+		} else {
949
+			$this->_template_args['states'] = false;
950
+		}
951
+
952
+		$this->_template_args['add_new_state_url'] = EE_Admin_Page::add_query_args_and_nonce(
953
+			['action' => 'add_new_state'],
954
+			GEN_SET_ADMIN_URL
955
+		);
956
+
957
+		$state_details_settings = EEH_Template::display_template(
958
+			GEN_SET_TEMPLATE_PATH . 'state_details_settings.template.php',
959
+			$this->_template_args,
960
+			true
961
+		);
962
+
963
+		if (defined('DOING_AJAX')) {
964
+			$notices = EE_Error::get_notices(false, false, false);
965
+			echo wp_json_encode(
966
+				[
967
+					'return_data' => $state_details_settings,
968
+					'success'     => $notices['success'],
969
+					'errors'      => $notices['errors'],
970
+				]
971
+			);
972
+			die();
973
+		}
974
+		return $state_details_settings;
975
+	}
976
+
977
+
978
+	/**
979
+	 * @return void
980
+	 * @throws EE_Error
981
+	 * @throws InvalidArgumentException
982
+	 * @throws InvalidDataTypeException
983
+	 * @throws InvalidInterfaceException
984
+	 * @throws ReflectionException
985
+	 */
986
+	public function add_new_state()
987
+	{
988
+		$success = true;
989
+		$CNT_ISO = $this->getCountryISO('');
990
+		if (! $CNT_ISO) {
991
+			EE_Error::add_error(
992
+				esc_html__('No Country ISO code or an invalid Country ISO code was received.', 'event_espresso'),
993
+				__FILE__,
994
+				__FUNCTION__,
995
+				__LINE__
996
+			);
997
+			$success = false;
998
+		}
999
+		$STA_abbrev = $this->request->getRequestParam('STA_abbrev');
1000
+		if (! $STA_abbrev) {
1001
+			EE_Error::add_error(
1002
+				esc_html__('No State ISO code or an invalid State ISO code was received.', 'event_espresso'),
1003
+				__FILE__,
1004
+				__FUNCTION__,
1005
+				__LINE__
1006
+			);
1007
+			$success = false;
1008
+		}
1009
+		$STA_name = $this->request->getRequestParam('STA_name');
1010
+		if (! $STA_name) {
1011
+			EE_Error::add_error(
1012
+				esc_html__('No State name or an invalid State name was received.', 'event_espresso'),
1013
+				__FILE__,
1014
+				__FUNCTION__,
1015
+				__LINE__
1016
+			);
1017
+			$success = false;
1018
+		}
1019
+
1020
+		if ($success) {
1021
+			$cols_n_values = [
1022
+				'CNT_ISO'    => $CNT_ISO,
1023
+				'STA_abbrev' => $STA_abbrev,
1024
+				'STA_name'   => $STA_name,
1025
+				'STA_active' => true,
1026
+			];
1027
+			$success       = EEM_State::instance()->insert($cols_n_values);
1028
+			EE_Error::add_success(esc_html__('The State was added successfully.', 'event_espresso'));
1029
+		}
1030
+
1031
+		if (defined('DOING_AJAX')) {
1032
+			$notices = EE_Error::get_notices(false, false, false);
1033
+			echo wp_json_encode(array_merge($notices, ['return_data' => $CNT_ISO]));
1034
+			die();
1035
+		} else {
1036
+			$this->_redirect_after_action(
1037
+				$success,
1038
+				esc_html__('State', 'event_espresso'),
1039
+				'added',
1040
+				['action' => 'country_settings']
1041
+			);
1042
+		}
1043
+	}
1044
+
1045
+
1046
+	/**
1047
+	 * @return void
1048
+	 * @throws EE_Error
1049
+	 * @throws InvalidArgumentException
1050
+	 * @throws InvalidDataTypeException
1051
+	 * @throws InvalidInterfaceException
1052
+	 * @throws ReflectionException
1053
+	 */
1054
+	public function delete_state()
1055
+	{
1056
+		$CNT_ISO    = $this->getCountryISO();
1057
+		$STA_ID     = $this->request->getRequestParam('STA_ID');
1058
+		$STA_abbrev = $this->request->getRequestParam('STA_abbrev');
1059
+
1060
+		if (! $STA_ID) {
1061
+			EE_Error::add_error(
1062
+				esc_html__('No State ID or an invalid State ID was received.', 'event_espresso'),
1063
+				__FILE__,
1064
+				__FUNCTION__,
1065
+				__LINE__
1066
+			);
1067
+			return;
1068
+		}
1069
+
1070
+		$success = EEM_State::instance()->delete_by_ID($STA_ID);
1071
+		if ($success !== false) {
1072
+			do_action(
1073
+				'AHEE__General_Settings_Admin_Page__delete_state__state_deleted',
1074
+				$CNT_ISO,
1075
+				$STA_ID,
1076
+				['STA_abbrev' => $STA_abbrev]
1077
+			);
1078
+			EE_Error::add_success(esc_html__('The State was deleted successfully.', 'event_espresso'));
1079
+		}
1080
+		if (defined('DOING_AJAX')) {
1081
+			$notices                = EE_Error::get_notices(false);
1082
+			$notices['return_data'] = true;
1083
+			echo wp_json_encode($notices);
1084
+			die();
1085
+		} else {
1086
+			$this->_redirect_after_action(
1087
+				$success,
1088
+				esc_html__('State', 'event_espresso'),
1089
+				'deleted',
1090
+				['action' => 'country_settings']
1091
+			);
1092
+		}
1093
+	}
1094
+
1095
+
1096
+	/**
1097
+	 *        _update_country_settings
1098
+	 *
1099
+	 * @return void
1100
+	 * @throws EE_Error
1101
+	 * @throws InvalidArgumentException
1102
+	 * @throws InvalidDataTypeException
1103
+	 * @throws InvalidInterfaceException
1104
+	 * @throws ReflectionException
1105
+	 */
1106
+	protected function _update_country_settings()
1107
+	{
1108
+		$CNT_ISO = $this->getCountryISO();
1109
+		if (! $CNT_ISO) {
1110
+			EE_Error::add_error(
1111
+				esc_html__('No Country ISO code or an invalid Country ISO code was received.', 'event_espresso'),
1112
+				__FILE__,
1113
+				__FUNCTION__,
1114
+				__LINE__
1115
+			);
1116
+			return;
1117
+		}
1118
+
1119
+		$country = $this->verifyOrGetCountryFromIso($CNT_ISO);
1120
+
1121
+		$cols_n_values                    = [];
1122
+		$cols_n_values['CNT_ISO3']        = strtoupper(
1123
+			$this->request->getRequestParam('cntry', $country->ISO3())
1124
+		);
1125
+		$cols_n_values['CNT_name']        = $this->request->getRequestParam(
1126
+			"cntry[$CNT_ISO][CNT_name]",
1127
+			$country->name()
1128
+		);
1129
+		$cols_n_values['CNT_cur_code']    = strtoupper(
1130
+			$this->request->getRequestParam(
1131
+				"cntry[$CNT_ISO][CNT_cur_code]",
1132
+				$country->currency_code()
1133
+			)
1134
+		);
1135
+		$cols_n_values['CNT_cur_single']  = $this->request->getRequestParam(
1136
+			"cntry[$CNT_ISO][CNT_cur_single]",
1137
+			$country->currency_name_single()
1138
+		);
1139
+		$cols_n_values['CNT_cur_plural']  = $this->request->getRequestParam(
1140
+			"cntry[$CNT_ISO][CNT_cur_plural]",
1141
+			$country->currency_name_plural()
1142
+		);
1143
+		$cols_n_values['CNT_cur_sign']    = $this->request->getRequestParam(
1144
+			"cntry[$CNT_ISO][CNT_cur_sign]",
1145
+			$country->currency_sign()
1146
+		);
1147
+		$cols_n_values['CNT_cur_sign_b4'] = $this->request->getRequestParam(
1148
+			"cntry[$CNT_ISO][CNT_cur_sign_b4]",
1149
+			$country->currency_sign_before(),
1150
+			DataType::BOOL
1151
+		);
1152
+		$cols_n_values['CNT_cur_dec_plc'] = $this->request->getRequestParam(
1153
+			"cntry[$CNT_ISO][CNT_cur_dec_plc]",
1154
+			$country->currency_decimal_places()
1155
+		);
1156
+		$cols_n_values['CNT_cur_dec_mrk'] = $this->request->getRequestParam(
1157
+			"cntry[$CNT_ISO][CNT_cur_dec_mrk]",
1158
+			$country->currency_decimal_mark()
1159
+		);
1160
+		$cols_n_values['CNT_cur_thsnds']  = $this->request->getRequestParam(
1161
+			"cntry[$CNT_ISO][CNT_cur_thsnds]",
1162
+			$country->currency_thousands_separator()
1163
+		);
1164
+		$cols_n_values['CNT_tel_code']    = $this->request->getRequestParam(
1165
+			"cntry[$CNT_ISO][CNT_tel_code]",
1166
+			$country->telephoneCode()
1167
+		);
1168
+		$cols_n_values['CNT_active']      = $this->request->getRequestParam(
1169
+			"cntry[$CNT_ISO][CNT_active]",
1170
+			$country->isActive(),
1171
+			DataType::BOOL
1172
+		);
1173
+
1174
+		// allow filtering of country data
1175
+		$cols_n_values = apply_filters(
1176
+			'FHEE__General_Settings_Admin_Page___update_country_settings__cols_n_values',
1177
+			$cols_n_values
1178
+		);
1179
+
1180
+		// where values
1181
+		$where_cols_n_values = [['CNT_ISO' => $CNT_ISO]];
1182
+		// run the update
1183
+		$success = EEM_Country::instance()->update($cols_n_values, $where_cols_n_values);
1184
+
1185
+		// allow filtering of states data
1186
+		$states = apply_filters(
1187
+			'FHEE__General_Settings_Admin_Page___update_country_settings__states',
1188
+			$this->request->getRequestParam('states', [], DataType::STRING, true)
1189
+		);
1190
+
1191
+		if (! empty($states) && $success !== false) {
1192
+			// loop thru state data ( looks like : states[75][STA_name] )
1193
+			foreach ($states as $STA_ID => $state) {
1194
+				$cols_n_values = [
1195
+					'CNT_ISO'    => $CNT_ISO,
1196
+					'STA_abbrev' => sanitize_text_field($state['STA_abbrev']),
1197
+					'STA_name'   => sanitize_text_field($state['STA_name']),
1198
+					'STA_active' => filter_var($state['STA_active'], FILTER_VALIDATE_BOOLEAN),
1199
+				];
1200
+				// where values
1201
+				$where_cols_n_values = [['STA_ID' => $STA_ID]];
1202
+				// run the update
1203
+				$success = EEM_State::instance()->update($cols_n_values, $where_cols_n_values);
1204
+				if ($success !== false) {
1205
+					do_action(
1206
+						'AHEE__General_Settings_Admin_Page__update_country_settings__state_saved',
1207
+						$CNT_ISO,
1208
+						$STA_ID,
1209
+						$cols_n_values
1210
+					);
1211
+				}
1212
+			}
1213
+		}
1214
+		// check if country being edited matches org option country, and if so, then  update EE_Config with new settings
1215
+		if (
1216
+			isset(EE_Registry::instance()->CFG->organization->CNT_ISO)
1217
+			&& $CNT_ISO == EE_Registry::instance()->CFG->organization->CNT_ISO
1218
+		) {
1219
+			EE_Registry::instance()->CFG->currency = new EE_Currency_Config($CNT_ISO);
1220
+			EE_Registry::instance()->CFG->update_espresso_config();
1221
+		}
1222
+
1223
+		if ($success !== false) {
1224
+			EE_Error::add_success(
1225
+				esc_html__('Country Settings updated successfully.', 'event_espresso')
1226
+			);
1227
+		}
1228
+		$this->_redirect_after_action(
1229
+			$success,
1230
+			'',
1231
+			'',
1232
+			['action' => 'country_settings', 'country' => $CNT_ISO],
1233
+			true
1234
+		);
1235
+	}
1236
+
1237
+
1238
+	/**
1239
+	 * form_form_field_label_wrap
1240
+	 *
1241
+	 * @param string $label
1242
+	 * @return string
1243
+	 */
1244
+	public function country_form_field_label_wrap(string $label): string
1245
+	{
1246
+		return '
1247 1247
 			<tr>
1248 1248
 				<th>
1249 1249
 					' . $label . '
1250 1250
 				</th>';
1251
-    }
1252
-
1253
-
1254
-    /**
1255
-     * form_form_field_input__wrap
1256
-     *
1257
-     * @param string $input
1258
-     * @return string
1259
-     */
1260
-    public function country_form_field_input__wrap(string $input): string
1261
-    {
1262
-        return '
1251
+	}
1252
+
1253
+
1254
+	/**
1255
+	 * form_form_field_input__wrap
1256
+	 *
1257
+	 * @param string $input
1258
+	 * @return string
1259
+	 */
1260
+	public function country_form_field_input__wrap(string $input): string
1261
+	{
1262
+		return '
1263 1263
 				<td class="general-settings-country-input-td">
1264 1264
 					' . $input . '
1265 1265
 				</td>
1266 1266
 			</tr>';
1267
-    }
1268
-
1269
-
1270
-    /**
1271
-     * form_form_field_label_wrap
1272
-     *
1273
-     * @param string $label
1274
-     * @param string $required_text
1275
-     * @return string
1276
-     */
1277
-    public function state_form_field_label_wrap(string $label, string $required_text): string
1278
-    {
1279
-        return $required_text;
1280
-    }
1281
-
1282
-
1283
-    /**
1284
-     * form_form_field_input__wrap
1285
-     *
1286
-     * @param string $input
1287
-     * @return string
1288
-     */
1289
-    public function state_form_field_input__wrap(string $input): string
1290
-    {
1291
-        return '
1267
+	}
1268
+
1269
+
1270
+	/**
1271
+	 * form_form_field_label_wrap
1272
+	 *
1273
+	 * @param string $label
1274
+	 * @param string $required_text
1275
+	 * @return string
1276
+	 */
1277
+	public function state_form_field_label_wrap(string $label, string $required_text): string
1278
+	{
1279
+		return $required_text;
1280
+	}
1281
+
1282
+
1283
+	/**
1284
+	 * form_form_field_input__wrap
1285
+	 *
1286
+	 * @param string $input
1287
+	 * @return string
1288
+	 */
1289
+	public function state_form_field_input__wrap(string $input): string
1290
+	{
1291
+		return '
1292 1292
 				<td class="general-settings-country-state-input-td">
1293 1293
 					' . $input . '
1294 1294
 				</td>';
1295
-    }
1296
-
1297
-
1298
-    /***********/
1299
-
1300
-
1301
-    /**
1302
-     * displays edit and view links for critical EE pages
1303
-     *
1304
-     * @param int $ee_page_id
1305
-     * @return string
1306
-     */
1307
-    public static function edit_view_links(int $ee_page_id): string
1308
-    {
1309
-        $edit_url = add_query_arg(
1310
-            ['post' => $ee_page_id, 'action' => 'edit'],
1311
-            admin_url('post.php')
1312
-        );
1313
-        $links    = '<a href="' . esc_url_raw($edit_url) . '" >' . esc_html__('Edit', 'event_espresso') . '</a>';
1314
-        $links    .= ' &nbsp;|&nbsp; ';
1315
-        $links    .= '<a href="' . get_permalink($ee_page_id) . '" >' . esc_html__('View', 'event_espresso') . '</a>';
1316
-
1317
-        return $links;
1318
-    }
1319
-
1320
-
1321
-    /**
1322
-     * displays page and shortcode status for critical EE pages
1323
-     *
1324
-     * @param WP_Post $ee_page
1325
-     * @param string  $shortcode
1326
-     * @return string
1327
-     */
1328
-    public static function page_and_shortcode_status(WP_Post $ee_page, string $shortcode): string
1329
-    {
1330
-        // page status
1331
-        if (isset($ee_page->post_status) && $ee_page->post_status == 'publish') {
1332
-            $pg_colour = 'green';
1333
-            $pg_status = sprintf(esc_html__('Page%sStatus%sOK', 'event_espresso'), '&nbsp;', '&nbsp;');
1334
-        } else {
1335
-            $pg_colour = 'red';
1336
-            $pg_status = sprintf(esc_html__('Page%sVisibility%sProblem', 'event_espresso'), '&nbsp;', '&nbsp;');
1337
-        }
1338
-
1339
-        // shortcode status
1340
-        if (isset($ee_page->post_content) && strpos($ee_page->post_content, $shortcode) !== false) {
1341
-            $sc_colour = 'green';
1342
-            $sc_status = sprintf(esc_html__('Shortcode%sOK', 'event_espresso'), '&nbsp;');
1343
-        } else {
1344
-            $sc_colour = 'red';
1345
-            $sc_status = sprintf(esc_html__('Shortcode%sProblem', 'event_espresso'), '&nbsp;');
1346
-        }
1347
-
1348
-        return '<span style="color:' . $pg_colour . '; margin-right:2em;"><strong>'
1349
-               . $pg_status
1350
-               . '</strong></span><span style="color:' . $sc_colour . '"><strong>' . $sc_status . '</strong></span>';
1351
-    }
1352
-
1353
-
1354
-    /**
1355
-     * generates a dropdown of all parent pages - copied from WP core
1356
-     *
1357
-     * @param int  $default
1358
-     * @param int  $parent
1359
-     * @param int  $level
1360
-     * @param bool $echo
1361
-     * @return string;
1362
-     */
1363
-    public static function page_settings_dropdown(
1364
-        int $default = 0,
1365
-        int $parent = 0,
1366
-        int $level = 0,
1367
-        bool $echo = true
1368
-    ): string {
1369
-        global $wpdb;
1370
-        $items  = $wpdb->get_results(
1371
-            $wpdb->prepare(
1372
-                "SELECT ID, post_parent, post_title FROM $wpdb->posts WHERE post_parent = %d AND post_type = 'page' AND post_status != 'trash' ORDER BY menu_order",
1373
-                $parent
1374
-            )
1375
-        );
1376
-        $output = '';
1377
-
1378
-        if ($items) {
1379
-            $level = absint($level);
1380
-            foreach ($items as $item) {
1381
-                $ID         = absint($item->ID);
1382
-                $post_title = wp_strip_all_tags($item->post_title);
1383
-                $pad        = str_repeat('&nbsp;', $level * 3);
1384
-                $option     = "\n\t";
1385
-                $option     .= '<option class="level-' . $level . '" ';
1386
-                $option     .= 'value="' . $ID . '" ';
1387
-                $option     .= $ID === absint($default) ? ' selected' : '';
1388
-                $option     .= '>';
1389
-                $option     .= "$pad {$post_title}";
1390
-                $option     .= '</option>';
1391
-                $output     .= $option;
1392
-                ob_start();
1393
-                parent_dropdown($default, $item->ID, $level + 1);
1394
-                $output .= ob_get_clean();
1395
-            }
1396
-        }
1397
-        if ($echo) {
1398
-            echo wp_kses($output, AllowedTags::getWithFormTags());
1399
-            return '';
1400
-        }
1401
-        return $output;
1402
-    }
1403
-
1404
-
1405
-    /**
1406
-     * Loads the scripts for the privacy settings form
1407
-     */
1408
-    public function load_scripts_styles_privacy_settings()
1409
-    {
1410
-        $form_handler = $this->loader->getShared(
1411
-            'EventEspresso\core\domain\services\admin\privacy\forms\PrivacySettingsFormHandler'
1412
-        );
1413
-        $form_handler->enqueueStylesAndScripts();
1414
-    }
1415
-
1416
-
1417
-    /**
1418
-     * display the privacy settings form
1419
-     *
1420
-     * @throws EE_Error
1421
-     */
1422
-    public function privacySettings()
1423
-    {
1424
-        $this->_set_add_edit_form_tags('update_privacy_settings');
1425
-        $this->_set_publish_post_box_vars(null, false, false, null, false);
1426
-        $form_handler                               = $this->loader->getShared(
1427
-            'EventEspresso\core\domain\services\admin\privacy\forms\PrivacySettingsFormHandler'
1428
-        );
1429
-        $this->_template_args['admin_page_content'] = EEH_HTML::div(
1430
-            $form_handler->display(),
1431
-            '',
1432
-            'padding'
1433
-        );
1434
-        $this->display_admin_page_with_sidebar();
1435
-    }
1436
-
1437
-
1438
-    /**
1439
-     * Update the privacy settings from form data
1440
-     *
1441
-     * @throws EE_Error
1442
-     */
1443
-    public function updatePrivacySettings()
1444
-    {
1445
-        $form_handler = $this->loader->getShared(
1446
-            'EventEspresso\core\domain\services\admin\privacy\forms\PrivacySettingsFormHandler'
1447
-        );
1448
-        $success      = $form_handler->process($this->get_request_data());
1449
-        $this->_redirect_after_action(
1450
-            $success,
1451
-            esc_html__('Registration Form Options', 'event_espresso'),
1452
-            'updated',
1453
-            ['action' => 'privacy_settings']
1454
-        );
1455
-    }
1295
+	}
1296
+
1297
+
1298
+	/***********/
1299
+
1300
+
1301
+	/**
1302
+	 * displays edit and view links for critical EE pages
1303
+	 *
1304
+	 * @param int $ee_page_id
1305
+	 * @return string
1306
+	 */
1307
+	public static function edit_view_links(int $ee_page_id): string
1308
+	{
1309
+		$edit_url = add_query_arg(
1310
+			['post' => $ee_page_id, 'action' => 'edit'],
1311
+			admin_url('post.php')
1312
+		);
1313
+		$links    = '<a href="' . esc_url_raw($edit_url) . '" >' . esc_html__('Edit', 'event_espresso') . '</a>';
1314
+		$links    .= ' &nbsp;|&nbsp; ';
1315
+		$links    .= '<a href="' . get_permalink($ee_page_id) . '" >' . esc_html__('View', 'event_espresso') . '</a>';
1316
+
1317
+		return $links;
1318
+	}
1319
+
1320
+
1321
+	/**
1322
+	 * displays page and shortcode status for critical EE pages
1323
+	 *
1324
+	 * @param WP_Post $ee_page
1325
+	 * @param string  $shortcode
1326
+	 * @return string
1327
+	 */
1328
+	public static function page_and_shortcode_status(WP_Post $ee_page, string $shortcode): string
1329
+	{
1330
+		// page status
1331
+		if (isset($ee_page->post_status) && $ee_page->post_status == 'publish') {
1332
+			$pg_colour = 'green';
1333
+			$pg_status = sprintf(esc_html__('Page%sStatus%sOK', 'event_espresso'), '&nbsp;', '&nbsp;');
1334
+		} else {
1335
+			$pg_colour = 'red';
1336
+			$pg_status = sprintf(esc_html__('Page%sVisibility%sProblem', 'event_espresso'), '&nbsp;', '&nbsp;');
1337
+		}
1338
+
1339
+		// shortcode status
1340
+		if (isset($ee_page->post_content) && strpos($ee_page->post_content, $shortcode) !== false) {
1341
+			$sc_colour = 'green';
1342
+			$sc_status = sprintf(esc_html__('Shortcode%sOK', 'event_espresso'), '&nbsp;');
1343
+		} else {
1344
+			$sc_colour = 'red';
1345
+			$sc_status = sprintf(esc_html__('Shortcode%sProblem', 'event_espresso'), '&nbsp;');
1346
+		}
1347
+
1348
+		return '<span style="color:' . $pg_colour . '; margin-right:2em;"><strong>'
1349
+			   . $pg_status
1350
+			   . '</strong></span><span style="color:' . $sc_colour . '"><strong>' . $sc_status . '</strong></span>';
1351
+	}
1352
+
1353
+
1354
+	/**
1355
+	 * generates a dropdown of all parent pages - copied from WP core
1356
+	 *
1357
+	 * @param int  $default
1358
+	 * @param int  $parent
1359
+	 * @param int  $level
1360
+	 * @param bool $echo
1361
+	 * @return string;
1362
+	 */
1363
+	public static function page_settings_dropdown(
1364
+		int $default = 0,
1365
+		int $parent = 0,
1366
+		int $level = 0,
1367
+		bool $echo = true
1368
+	): string {
1369
+		global $wpdb;
1370
+		$items  = $wpdb->get_results(
1371
+			$wpdb->prepare(
1372
+				"SELECT ID, post_parent, post_title FROM $wpdb->posts WHERE post_parent = %d AND post_type = 'page' AND post_status != 'trash' ORDER BY menu_order",
1373
+				$parent
1374
+			)
1375
+		);
1376
+		$output = '';
1377
+
1378
+		if ($items) {
1379
+			$level = absint($level);
1380
+			foreach ($items as $item) {
1381
+				$ID         = absint($item->ID);
1382
+				$post_title = wp_strip_all_tags($item->post_title);
1383
+				$pad        = str_repeat('&nbsp;', $level * 3);
1384
+				$option     = "\n\t";
1385
+				$option     .= '<option class="level-' . $level . '" ';
1386
+				$option     .= 'value="' . $ID . '" ';
1387
+				$option     .= $ID === absint($default) ? ' selected' : '';
1388
+				$option     .= '>';
1389
+				$option     .= "$pad {$post_title}";
1390
+				$option     .= '</option>';
1391
+				$output     .= $option;
1392
+				ob_start();
1393
+				parent_dropdown($default, $item->ID, $level + 1);
1394
+				$output .= ob_get_clean();
1395
+			}
1396
+		}
1397
+		if ($echo) {
1398
+			echo wp_kses($output, AllowedTags::getWithFormTags());
1399
+			return '';
1400
+		}
1401
+		return $output;
1402
+	}
1403
+
1404
+
1405
+	/**
1406
+	 * Loads the scripts for the privacy settings form
1407
+	 */
1408
+	public function load_scripts_styles_privacy_settings()
1409
+	{
1410
+		$form_handler = $this->loader->getShared(
1411
+			'EventEspresso\core\domain\services\admin\privacy\forms\PrivacySettingsFormHandler'
1412
+		);
1413
+		$form_handler->enqueueStylesAndScripts();
1414
+	}
1415
+
1416
+
1417
+	/**
1418
+	 * display the privacy settings form
1419
+	 *
1420
+	 * @throws EE_Error
1421
+	 */
1422
+	public function privacySettings()
1423
+	{
1424
+		$this->_set_add_edit_form_tags('update_privacy_settings');
1425
+		$this->_set_publish_post_box_vars(null, false, false, null, false);
1426
+		$form_handler                               = $this->loader->getShared(
1427
+			'EventEspresso\core\domain\services\admin\privacy\forms\PrivacySettingsFormHandler'
1428
+		);
1429
+		$this->_template_args['admin_page_content'] = EEH_HTML::div(
1430
+			$form_handler->display(),
1431
+			'',
1432
+			'padding'
1433
+		);
1434
+		$this->display_admin_page_with_sidebar();
1435
+	}
1436
+
1437
+
1438
+	/**
1439
+	 * Update the privacy settings from form data
1440
+	 *
1441
+	 * @throws EE_Error
1442
+	 */
1443
+	public function updatePrivacySettings()
1444
+	{
1445
+		$form_handler = $this->loader->getShared(
1446
+			'EventEspresso\core\domain\services\admin\privacy\forms\PrivacySettingsFormHandler'
1447
+		);
1448
+		$success      = $form_handler->process($this->get_request_data());
1449
+		$this->_redirect_after_action(
1450
+			$success,
1451
+			esc_html__('Registration Form Options', 'event_espresso'),
1452
+			'updated',
1453
+			['action' => 'privacy_settings']
1454
+		);
1455
+	}
1456 1456
 }
Please login to merge, or discard this patch.
core/helpers/EEH_MSG_Template.helper.php 1 patch
Indentation   +1249 added lines, -1249 removed lines patch added patch discarded remove patch
@@ -15,1253 +15,1253 @@
 block discarded – undo
15 15
 {
16 16
 
17 17
 
18
-    /**
19
-     * Holds a collection of EE_Message_Template_Pack objects.
20
-     * @type EE_Messages_Template_Pack_Collection
21
-     */
22
-    protected static $_template_pack_collection;
23
-
24
-
25
-    /**
26
-     * @throws EE_Error
27
-     */
28
-    private static function _set_autoloader()
29
-    {
30
-        EED_Messages::set_autoloaders();
31
-    }
32
-
33
-
34
-    /**
35
-     * generate_new_templates
36
-     * This will handle the messenger, message_type selection when "adding a new custom template" for an event and will
37
-     * automatically create the defaults for the event.  The user would then be redirected to edit the default context
38
-     * for the event.
39
-     *
40
-     * @access protected
41
-     * @param string $messenger     the messenger we are generating templates for
42
-     * @param array  $message_types array of message types that the templates are generated for.
43
-     * @param int    $GRP_ID        If a non global template is being generated then it is expected we'll have a GRP_ID
44
-     *                              to use as the base for the new generated template.
45
-     * @param bool   $global        true indicates generating templates on messenger activation. false requires GRP_ID
46
-     *                              for event specific template generation.
47
-     * @return array  @see EEH_MSG_Template::_create_new_templates for the return value of each element in the array
48
-     *                for templates that are generated.  If this is an empty array then it means no templates were
49
-     *                generated which usually means there was an error.  Anything in the array with an empty value for
50
-     *                `MTP_context` means that it was not a new generated template but just reactivated (which only
51
-     *                happens for global templates that already exist in the database.
52
-     * @throws EE_Error
53
-     * @throws ReflectionException
54
-     */
55
-    public static function generate_new_templates($messenger, $message_types, $GRP_ID = 0, $global = false)
56
-    {
57
-        // make sure message_type is an array.
58
-        $message_types = (array) $message_types;
59
-        $templates = array();
60
-
61
-        if (empty($messenger)) {
62
-            throw new EE_Error(esc_html__('We need a messenger to generate templates!', 'event_espresso'));
63
-        }
64
-
65
-        // if we STILL have empty $message_types then we need to generate an error message b/c we NEED message types to do the template files.
66
-        if (empty($message_types)) {
67
-            throw new EE_Error(esc_html__('We need at least one message type to generate templates!', 'event_espresso'));
68
-        }
69
-
70
-        EEH_MSG_Template::_set_autoloader();
71
-        foreach ($message_types as $message_type) {
72
-            // if this is global template generation.
73
-            if ($global) {
74
-                // let's attempt to get the GRP_ID for this combo IF GRP_ID is empty.
75
-                if (empty($GRP_ID)) {
76
-                    $GRP_ID = EEM_Message_Template_Group::instance()->get_one(
77
-                        array(
78
-                            array(
79
-                                'MTP_messenger'    => $messenger,
80
-                                'MTP_message_type' => $message_type,
81
-                                'MTP_is_global'    => true,
82
-                            ),
83
-                        )
84
-                    );
85
-                    $GRP_ID = $GRP_ID instanceof EE_Message_Template_Group ? $GRP_ID->ID() : 0;
86
-                }
87
-                // First let's determine if we already HAVE global templates for this messenger and message_type combination.
88
-                //  If we do then NO generation!!
89
-                if (EEH_MSG_Template::already_generated($messenger, $message_type, $GRP_ID)) {
90
-                    $templates[] = array(
91
-                        'GRP_ID' => $GRP_ID,
92
-                        'MTP_context' => '',
93
-                    );
94
-                    // we already have generated templates for this so let's go to the next message type.
95
-                    continue;
96
-                }
97
-            }
98
-            $new_message_template_group = EEH_MSG_Template::create_new_templates($messenger, $message_type, $GRP_ID, $global);
99
-
100
-            if (! $new_message_template_group) {
101
-                continue;
102
-            }
103
-            $templates[] = $new_message_template_group;
104
-        }
105
-
106
-        return $templates;
107
-    }
108
-
109
-
110
-    /**
111
-     * The purpose of this method is to determine if there are already generated templates in the database for the
112
-     * given variables.
113
-     *
114
-     * @param string $messenger    messenger
115
-     * @param string $message_type message type
116
-     * @param int    $GRP_ID       GRP ID ( if a custom template) (if not provided then we're just doing global
117
-     *                             template check)
118
-     * @return bool                true = generated, false = hasn't been generated.
119
-     * @throws EE_Error
120
-     */
121
-    public static function already_generated($messenger, $message_type, $GRP_ID = 0)
122
-    {
123
-        EEH_MSG_Template::_set_autoloader();
124
-        // what method we use depends on whether we have an GRP_ID or not
125
-        $count = empty($GRP_ID)
126
-            ? EEM_Message_Template::instance()->count(
127
-                array(
128
-                    array(
129
-                        'Message_Template_Group.MTP_messenger'    => $messenger,
130
-                        'Message_Template_Group.MTP_message_type' => $message_type,
131
-                        'Message_Template_Group.MTP_is_global'    => true
132
-                    )
133
-                )
134
-            )
135
-            : EEM_Message_Template::instance()->count(array( array( 'GRP_ID' => $GRP_ID ) ));
136
-
137
-        return $count > 0;
138
-    }
139
-
140
-
141
-    /**
142
-     * Updates all message templates matching the incoming messengers and message types to active status.
143
-     *
144
-     * @static
145
-     * @param array $messenger_names    Messenger slug
146
-     * @param array $message_type_names Message type slug
147
-     * @return  int                         count of updated records.
148
-     * @throws EE_Error
149
-     */
150
-    public static function update_to_active($messenger_names, $message_type_names)
151
-    {
152
-        $messenger_names = is_array($messenger_names) ? $messenger_names : array( $messenger_names );
153
-        $message_type_names = is_array($message_type_names) ? $message_type_names : array( $message_type_names );
154
-        return EEM_Message_Template_Group::instance()->update(
155
-            array( 'MTP_is_active' => 1 ),
156
-            array(
157
-                array(
158
-                    'MTP_messenger'     => array( 'IN', $messenger_names ),
159
-                    'MTP_message_type'  => array( 'IN', $message_type_names )
160
-                )
161
-            )
162
-        );
163
-    }
164
-
165
-
166
-    /**
167
-     * Updates all message template groups matching the incoming arguments to inactive status.
168
-     *
169
-     * @static
170
-     * @param array $messenger_names    The messenger slugs.
171
-     *                                  If empty then all templates matching the message types are marked inactive.
172
-     *                                  Otherwise only templates matching the messengers and message types.
173
-     * @param array $message_type_names The message type slugs.
174
-     *                                  If empty then all templates matching the messengers are marked inactive.
175
-     *                                  Otherwise only templates matching the messengers and message types.
176
-     *
177
-     * @return int  count of updated records.
178
-     * @throws EE_Error
179
-     */
180
-    public static function update_to_inactive($messenger_names = array(), $message_type_names = array())
181
-    {
182
-        return EEM_Message_Template_Group::instance()->deactivate_message_template_groups_for(
183
-            $messenger_names,
184
-            $message_type_names
185
-        );
186
-    }
187
-
188
-
189
-    /**
190
-     * The purpose of this function is to return all installed message objects
191
-     * (messengers and message type regardless of whether they are ACTIVE or not)
192
-     *
193
-     * @param string $type
194
-     * @return array array consisting of installed messenger objects and installed message type objects.
195
-     * @throws EE_Error
196
-     * @throws ReflectionException
197
-     * @deprecated 4.9.0
198
-     * @static
199
-     */
200
-    public static function get_installed_message_objects($type = 'all')
201
-    {
202
-        self::_set_autoloader();
203
-        $message_resource_manager = EE_Registry::instance()->load_lib('Message_Resource_Manager');
204
-        return array(
205
-            'messenger' => $message_resource_manager->installed_messengers(),
206
-            'message_type' => $message_resource_manager->installed_message_types()
207
-        );
208
-    }
209
-
210
-
211
-    /**
212
-     * This will return an array of shortcodes => labels from the
213
-     * messenger and message_type objects associated with this
214
-     * template.
215
-     *
216
-     * @param string $message_type
217
-     * @param string $messenger
218
-     * @param array  $fields                        What fields we're returning valid shortcodes for.
219
-     *                                              If empty then we assume all fields are to be returned. Optional.
220
-     * @param string $context                       What context we're going to return shortcodes for. Optional.
221
-     * @param bool   $merged                        If TRUE then we don't return shortcodes indexed by field,
222
-     *                                              but instead an array of the unique shortcodes for all the given (
223
-     *                                              or all) fields. Optional.
224
-     * @return array                                an array of shortcodes in the format
225
-     *                                              array( '[shortcode] => 'label')
226
-     *                                              OR
227
-     *                                              FALSE if no shortcodes found.
228
-     * @throws ReflectionException
229
-     * @throws EE_Error*@since 4.3.0
230
-     *
231
-     */
232
-    public static function get_shortcodes(
233
-        $message_type,
234
-        $messenger,
235
-        $fields = array(),
236
-        $context = 'admin',
237
-        $merged = false
238
-    ) {
239
-        $messenger_name = str_replace(' ', '_', ucwords(str_replace('_', ' ', $messenger)));
240
-        $mt_name = str_replace(' ', '_', ucwords(str_replace('_', ' ', $message_type)));
241
-        /** @var EE_Message_Resource_Manager $message_resource_manager */
242
-        $message_resource_manager = EE_Registry::instance()->load_lib('Message_Resource_Manager');
243
-        // convert slug to object
244
-        $messenger = $message_resource_manager->get_messenger($messenger);
245
-
246
-        // if messenger isn't a EE_messenger resource then bail.
247
-        if (! $messenger instanceof EE_messenger) {
248
-            return array();
249
-        }
250
-
251
-        // validate class for getting our list of shortcodes
252
-        $classname = 'EE_Messages_' . $messenger_name . '_' . $mt_name . '_Validator';
253
-        if (! class_exists($classname)) {
254
-            $msg[] = esc_html__('The Validator class was unable to load', 'event_espresso');
255
-            $msg[] = sprintf(
256
-                esc_html__('The class name compiled was %s. Please check and make sure the spelling and case is correct for the class name and that there is an autoloader in place for this class', 'event_espresso'),
257
-                $classname
258
-            );
259
-            throw new EE_Error(implode('||', $msg));
260
-        }
261
-
262
-        /** @type EE_Messages_Validator $_VLD */
263
-        $_VLD = new $classname(array(), $context);
264
-        $valid_shortcodes = $_VLD->get_validators();
265
-
266
-        // let's make sure we're only getting the shortcode part of the validators
267
-        $shortcodes = array();
268
-        foreach ($valid_shortcodes as $field => $validators) {
269
-            $shortcodes[ $field ] = $validators['shortcodes'];
270
-        }
271
-        $valid_shortcodes = $shortcodes;
272
-
273
-        // if not all fields let's make sure we ONLY include the shortcodes for the specified fields.
274
-        if (! empty($fields)) {
275
-            $specified_shortcodes = array();
276
-            foreach ($fields as $field) {
277
-                if (isset($valid_shortcodes[ $field ])) {
278
-                    $specified_shortcodes[ $field ] = $valid_shortcodes[ $field ];
279
-                }
280
-            }
281
-            $valid_shortcodes = $specified_shortcodes;
282
-        }
283
-
284
-        // if not merged then let's replace the fields with the localized fields
285
-        if (! $merged) {
286
-            // let's get all the fields for the set messenger so that we can get the localized label and use that in the returned array.
287
-            $field_settings = $messenger->get_template_fields();
288
-            $localized = array();
289
-            foreach ($valid_shortcodes as $field => $shortcodes) {
290
-                // get localized field label
291
-                if (isset($field_settings[ $field ])) {
292
-                    // possible that this is used as a main field.
293
-                    if (empty($field_settings[ $field ])) {
294
-                        if (isset($field_settings['extra'][ $field ])) {
295
-                            $_field = $field_settings['extra'][ $field ]['main']['label'];
296
-                        } else {
297
-                            $_field = $field;
298
-                        }
299
-                    } else {
300
-                        $_field = $field_settings[ $field ]['label'];
301
-                    }
302
-                } elseif (isset($field_settings['extra'])) {
303
-                    // loop through extra "main fields" and see if any of their children have our field
304
-                    foreach ($field_settings['extra'] as $fields) {
305
-                        if (isset($fields[ $field ])) {
306
-                            $_field = $fields[ $field ]['label'];
307
-                        } else {
308
-                            $_field = $field;
309
-                        }
310
-                    }
311
-                } else {
312
-                    $_field = $field;
313
-                }
314
-                if (isset($_field)) {
315
-                    $localized[ (string) $_field ] = $shortcodes;
316
-                }
317
-            }
318
-            $valid_shortcodes = $localized;
319
-        }
320
-
321
-        // if $merged then let's merge all the shortcodes into one list NOT indexed by field.
322
-        if ($merged) {
323
-            $merged_codes = array();
324
-            foreach ($valid_shortcodes as $shortcode) {
325
-                foreach ($shortcode as $code => $label) {
326
-                    if (isset($merged_codes[ $code ])) {
327
-                        continue;
328
-                    } else {
329
-                        $merged_codes[ $code ] = $label;
330
-                    }
331
-                }
332
-            }
333
-            $valid_shortcodes = $merged_codes;
334
-        }
335
-
336
-        return $valid_shortcodes;
337
-    }
338
-
339
-
340
-    /**
341
-     * Get Messenger object.
342
-     *
343
-     * @param string $messenger messenger slug for the messenger object we want to retrieve.
344
-     * @return EE_messenger
345
-     * @throws ReflectionException
346
-     * @throws EE_Error*@since 4.3.0
347
-     * @deprecated 4.9.0
348
-     */
349
-    public static function messenger_obj($messenger)
350
-    {
351
-        /** @type EE_Message_Resource_Manager $Message_Resource_Manager */
352
-        $Message_Resource_Manager = EE_Registry::instance()->load_lib('Message_Resource_Manager');
353
-        return $Message_Resource_Manager->get_messenger($messenger);
354
-    }
355
-
356
-
357
-    /**
358
-     * get Message type object
359
-     *
360
-     * @param string $message_type the slug for the message type object to retrieve
361
-     * @return EE_message_type
362
-     * @throws ReflectionException
363
-     * @throws EE_Error*@since 4.3.0
364
-     * @deprecated 4.9.0
365
-     */
366
-    public static function message_type_obj($message_type)
367
-    {
368
-        /** @type EE_Message_Resource_Manager $Message_Resource_Manager */
369
-        $Message_Resource_Manager = EE_Registry::instance()->load_lib('Message_Resource_Manager');
370
-        return $Message_Resource_Manager->get_message_type($message_type);
371
-    }
372
-
373
-
374
-    /**
375
-     * Given a message_type slug, will return whether that message type is active in the system or not.
376
-     *
377
-     * @since    4.3.0
378
-     * @param string $message_type message type to check for.
379
-     * @return boolean
380
-     * @throws EE_Error
381
-     * @throws ReflectionException
382
-     */
383
-    public static function is_mt_active($message_type)
384
-    {
385
-        /** @type EE_Message_Resource_Manager $Message_Resource_Manager */
386
-        $Message_Resource_Manager = EE_Registry::instance()->load_lib('Message_Resource_Manager');
387
-        $active_mts = $Message_Resource_Manager->list_of_active_message_types();
388
-        return in_array($message_type, $active_mts);
389
-    }
390
-
391
-
392
-    /**
393
-     * Given a messenger slug, will return whether that messenger is active in the system or not.
394
-     *
395
-     * @since    4.3.0
396
-     *
397
-     * @param string $messenger slug for messenger to check.
398
-     * @return boolean
399
-     * @throws EE_Error
400
-     * @throws ReflectionException
401
-     */
402
-    public static function is_messenger_active($messenger)
403
-    {
404
-        /** @type EE_Message_Resource_Manager $Message_Resource_Manager */
405
-        $Message_Resource_Manager = EE_Registry::instance()->load_lib('Message_Resource_Manager');
406
-        $active_messenger = $Message_Resource_Manager->get_active_messenger($messenger);
407
-        return $active_messenger instanceof EE_messenger;
408
-    }
409
-
410
-
411
-    /**
412
-     * Used to return active messengers array stored in the wp options table.
413
-     * If no value is present in the option then an empty array is returned.
414
-     *
415
-     * @deprecated 4.9
416
-     * @since      4.3.1
417
-     *
418
-     * @return array
419
-     * @throws EE_Error
420
-     * @throws ReflectionException
421
-     */
422
-    public static function get_active_messengers_in_db()
423
-    {
424
-        EE_Error::doing_it_wrong(
425
-            __METHOD__,
426
-            esc_html__('Please use EE_Message_Resource_Manager::get_active_messengers_option() instead.', 'event_espresso'),
427
-            '4.9.0'
428
-        );
429
-        /** @var EE_Message_Resource_Manager $Message_Resource_Manager */
430
-        $Message_Resource_Manager = EE_Registry::instance()->load_lib('Message_Resource_Manager');
431
-        return $Message_Resource_Manager->get_active_messengers_option();
432
-    }
433
-
434
-
435
-    /**
436
-     * Used to update the active messengers array stored in the wp options table.
437
-     *
438
-     * @since      4.3.1
439
-     * @deprecated 4.9.0
440
-     *
441
-     * @param array $data_to_save Incoming data to save.
442
-     *
443
-     * @return bool FALSE if not updated, TRUE if updated.
444
-     * @throws EE_Error
445
-     * @throws ReflectionException
446
-     */
447
-    public static function update_active_messengers_in_db($data_to_save)
448
-    {
449
-        EE_Error::doing_it_wrong(
450
-            __METHOD__,
451
-            esc_html__('Please use EE_Message_Resource_Manager::update_active_messengers_option() instead.', 'event_espresso'),
452
-            '4.9.0'
453
-        );
454
-        /** @var EE_Message_Resource_Manager $Message_Resource_Manager */
455
-        $Message_Resource_Manager = EE_Registry::instance()->load_lib('Message_Resource_Manager');
456
-        return $Message_Resource_Manager->update_active_messengers_option($data_to_save);
457
-    }
458
-
459
-
460
-    /**
461
-     * This does some validation of incoming params, determines what type of url is being prepped and returns the
462
-     * appropriate url trigger
463
-     *
464
-     * @param EE_message_type $message_type
465
-     * @param EE_Message $message
466
-     * @param EE_Registration | null $registration  The registration object must be included if this
467
-     *                                              is going to be a registration trigger url.
468
-     * @param string $sending_messenger             The (optional) sending messenger for the url.
469
-     *
470
-     * @return string
471
-     * @throws EE_Error
472
-     */
473
-    public static function get_url_trigger(
474
-        EE_message_type $message_type,
475
-        EE_Message $message,
476
-        $registration = null,
477
-        $sending_messenger = ''
478
-    ) {
479
-        // first determine if the url can be to the EE_Message object.
480
-        if (! $message_type->always_generate()) {
481
-            return EEH_MSG_Template::generate_browser_trigger($message);
482
-        }
483
-
484
-        // if $registration object is not valid then exit early because there's nothing that can be generated.
485
-        if (! $registration instanceof EE_Registration) {
486
-            throw new EE_Error(
487
-                esc_html__('Incoming value for registration is not a valid EE_Registration object.', 'event_espresso')
488
-            );
489
-        }
490
-
491
-        // validate given context
492
-        $contexts = $message_type->get_contexts();
493
-        if ($message->context() !== '' && ! isset($contexts[ $message->context() ])) {
494
-            throw new EE_Error(
495
-                sprintf(
496
-                    esc_html__('The context %s is not a valid context for %s.', 'event_espresso'),
497
-                    $message->context(),
498
-                    get_class($message_type)
499
-                )
500
-            );
501
-        }
502
-
503
-        // valid sending messenger but only if sending messenger set.  Otherwise generating messenger is used.
504
-        if (! empty($sending_messenger)) {
505
-            $with_messengers = $message_type->with_messengers();
506
-            if (
507
-                ! isset($with_messengers[ $message->messenger() ])
508
-                 || ! in_array($sending_messenger, $with_messengers[ $message->messenger() ])
509
-            ) {
510
-                throw new EE_Error(
511
-                    sprintf(
512
-                        esc_html__(
513
-                            'The given sending messenger string (%1$s) does not match a valid sending messenger with the %2$s.  If this is incorrect, make sure that the message type has defined this messenger as a sending messenger in its $_with_messengers array.',
514
-                            'event_espresso'
515
-                        ),
516
-                        $sending_messenger,
517
-                        get_class($message_type)
518
-                    )
519
-                );
520
-            }
521
-        } else {
522
-            $sending_messenger = $message->messenger();
523
-        }
524
-        return EEH_MSG_Template::generate_url_trigger(
525
-            $sending_messenger,
526
-            $message->messenger(),
527
-            $message->context(),
528
-            $message->message_type(),
529
-            $registration,
530
-            $message->GRP_ID()
531
-        );
532
-    }
533
-
534
-
535
-    /**
536
-     * This returns the url for triggering a in browser view of a specific EE_Message object.
537
-     * @param EE_Message $message
538
-     * @return string.
539
-     */
540
-    public static function generate_browser_trigger(EE_Message $message)
541
-    {
542
-        $query_args = array(
543
-            'ee' => 'msg_browser_trigger',
544
-            'token' => $message->MSG_token()
545
-        );
546
-        return apply_filters(
547
-            'FHEE__EEH_MSG_Template__generate_browser_trigger',
548
-            add_query_arg($query_args, site_url()),
549
-            $message
550
-        );
551
-    }
552
-
553
-
554
-
555
-
556
-
557
-
558
-    /**
559
-     * This returns the url for triggering an in browser view of the error saved on the incoming message object.
560
-     * @param EE_Message $message
561
-     * @return string
562
-     */
563
-    public static function generate_error_display_trigger(EE_Message $message)
564
-    {
565
-        return apply_filters(
566
-            'FHEE__EEH_MSG_Template__generate_error_display_trigger',
567
-            add_query_arg(
568
-                array(
569
-                    'ee' => 'msg_browser_error_trigger',
570
-                    'token' => $message->MSG_token()
571
-                ),
572
-                site_url()
573
-            ),
574
-            $message
575
-        );
576
-    }
577
-
578
-
579
-    /**
580
-     * This generates a url trigger for the msg_url_trigger route using the given arguments
581
-     *
582
-     * @param string          $sending_messenger      The sending messenger slug.
583
-     * @param string          $generating_messenger   The generating messenger slug.
584
-     * @param string          $context                The context for the template.
585
-     * @param string          $message_type           The message type slug
586
-     * @param EE_Registration $registration
587
-     * @param integer         $message_template_group id   The EE_Message_Template_Group ID for the template.
588
-     * @param integer         $data_id                The id to the EE_Base_Class for getting the data used by the
589
-     *                                                trigger.
590
-     * @return string          The generated url.
591
-     * @throws EE_Error
592
-     */
593
-    public static function generate_url_trigger(
594
-        $sending_messenger,
595
-        $generating_messenger,
596
-        $context,
597
-        $message_type,
598
-        EE_Registration $registration,
599
-        $message_template_group,
600
-        $data_id = 0
601
-    ) {
602
-        $query_args = array(
603
-            'ee' => 'msg_url_trigger',
604
-            'snd_msgr' => $sending_messenger,
605
-            'gen_msgr' => $generating_messenger,
606
-            'message_type' => $message_type,
607
-            'context' => $context,
608
-            'token' => $registration->reg_url_link(),
609
-            'GRP_ID' => $message_template_group,
610
-            'id' => $data_id
611
-            );
612
-        $url = add_query_arg($query_args, get_home_url());
613
-
614
-        // made it here so now we can just get the url and filter it.  Filtered globally and by message type.
615
-        return apply_filters(
616
-            'FHEE__EEH_MSG_Template__generate_url_trigger',
617
-            $url,
618
-            $sending_messenger,
619
-            $generating_messenger,
620
-            $context,
621
-            $message_type,
622
-            $registration,
623
-            $message_template_group,
624
-            $data_id
625
-        );
626
-    }
627
-
628
-
629
-
630
-
631
-    /**
632
-     * Return the specific css for the action icon given.
633
-     *
634
-     * @param string $type  What action to return.
635
-     * @return string[]
636
-     * @since 4.9.0
637
-     */
638
-    public static function get_message_action_icon($type)
639
-    {
640
-        $action_icons = self::get_message_action_icons();
641
-        return isset($action_icons[ $type ]) ? $action_icons[ $type ] : [];
642
-    }
643
-
644
-
645
-    /**
646
-     * This is used for retrieving the css classes used for the icons representing message actions.
647
-     *
648
-     * @since 4.9.0
649
-     *
650
-     * @return array
651
-     */
652
-    public static function get_message_action_icons()
653
-    {
654
-        return apply_filters(
655
-            'FHEE__EEH_MSG_Template__message_action_icons',
656
-            array(
657
-                'view' => array(
658
-                    'label' => esc_html__('View Message', 'event_espresso'),
659
-                    'css_class' => 'dashicons dashicons-welcome-view-site',
660
-                ),
661
-                'error' => array(
662
-                    'label' => esc_html__('View Error Message', 'event_espresso'),
663
-                    'css_class' => 'dashicons dashicons-info',
664
-                ),
665
-                'see_notifications_for' => array(
666
-                    'label' => esc_html__('View Related Messages', 'event_espresso'),
667
-                    'css_class' => 'dashicons dashicons-megaphone',
668
-                ),
669
-                'generate_now' => array(
670
-                    'label' => esc_html__('Generate the message now.', 'event_espresso'),
671
-                    'css_class' => 'dashicons dashicons-admin-tools',
672
-                ),
673
-                'send_now' => array(
674
-                    'label' => esc_html__('Send Immediately', 'event_espresso'),
675
-                    'css_class' => 'dashicons dashicons-controls-forward',
676
-                ),
677
-                'queue_for_resending' => array(
678
-                    'label' => esc_html__('Queue for Resending', 'event_espresso'),
679
-                    'css_class' => 'dashicons dashicons-controls-repeat',
680
-                ),
681
-                'view_transaction' => array(
682
-                    'label' => esc_html__('View related Transaction', 'event_espresso'),
683
-                    'css_class' => 'dashicons dashicons-cart',
684
-                )
685
-            )
686
-        );
687
-    }
688
-
689
-
690
-    /**
691
-     * This returns the url for a given action related to EE_Message.
692
-     *
693
-     * @param string     $type         What type of action to return the url for.
694
-     * @param EE_Message $message      Required for generating the correct url for some types.
695
-     * @param array      $query_params Any additional query params to be included with the generated url.
696
-     *
697
-     * @return string
698
-     * @throws EE_Error
699
-     * @throws ReflectionException
700
-     * @since 4.9.0
701
-     *
702
-     */
703
-    public static function get_message_action_url($type, EE_Message $message = null, $query_params = array())
704
-    {
705
-        $action_urls = self::get_message_action_urls($message, $query_params);
706
-        return isset($action_urls[ $type ])  ? $action_urls[ $type ] : '';
707
-    }
708
-
709
-
710
-    /**
711
-     * This returns all the current urls for EE_Message actions.
712
-     *
713
-     * @since 4.9.0
714
-     *
715
-     * @param EE_Message $message      The EE_Message object required to generate correct urls for some types.
716
-     * @param array      $query_params Any additional query_params to be included with the generated url.
717
-     *
718
-     * @return array
719
-     * @throws EE_Error
720
-     * @throws ReflectionException
721
-     */
722
-    public static function get_message_action_urls(EE_Message $message = null, $query_params = array())
723
-    {
724
-        EE_Registry::instance()->load_helper('URL');
725
-        // if $message is not an instance of EE_Message then let's just do a dummy.
726
-        $message = empty($message) ? EE_Message_Factory::create() : $message;
727
-        $action_urls =  apply_filters(
728
-            'FHEE__EEH_MSG_Template__get_message_action_url',
729
-            array(
730
-                'view' => EEH_MSG_Template::generate_browser_trigger($message),
731
-                'error' => EEH_MSG_Template::generate_error_display_trigger($message),
732
-                'see_notifications_for' => EEH_URL::add_query_args_and_nonce(
733
-                    array_merge(
734
-                        array(
735
-                            'page' => 'espresso_messages',
736
-                            'action' => 'default',
737
-                            'filterby' => 1,
738
-                        ),
739
-                        $query_params
740
-                    ),
741
-                    admin_url('admin.php')
742
-                ),
743
-                'generate_now' => EEH_URL::add_query_args_and_nonce(
744
-                    array(
745
-                        'page' => 'espresso_messages',
746
-                        'action' => 'generate_now',
747
-                        'MSG_ID' => $message->ID()
748
-                    ),
749
-                    admin_url('admin.php')
750
-                ),
751
-                'send_now' => EEH_URL::add_query_args_and_nonce(
752
-                    array(
753
-                        'page' => 'espresso_messages',
754
-                        'action' => 'send_now',
755
-                        'MSG_ID' => $message->ID()
756
-                    ),
757
-                    admin_url('admin.php')
758
-                ),
759
-                'queue_for_resending' => EEH_URL::add_query_args_and_nonce(
760
-                    array(
761
-                        'page' => 'espresso_messages',
762
-                        'action' => 'queue_for_resending',
763
-                        'MSG_ID' => $message->ID()
764
-                    ),
765
-                    admin_url('admin.php')
766
-                ),
767
-            )
768
-        );
769
-        if (
770
-            $message->TXN_ID() > 0
771
-            && EE_Registry::instance()->CAP->current_user_can(
772
-                'ee_read_transaction',
773
-                'espresso_transactions_default',
774
-                $message->TXN_ID()
775
-            )
776
-        ) {
777
-            $action_urls['view_transaction'] = EEH_URL::add_query_args_and_nonce(
778
-                array(
779
-                    'page' => 'espresso_transactions',
780
-                    'action' => 'view_transaction',
781
-                    'TXN_ID' => $message->TXN_ID()
782
-                ),
783
-                admin_url('admin.php')
784
-            );
785
-        } else {
786
-            $action_urls['view_transaction'] = '';
787
-        }
788
-        return $action_urls;
789
-    }
790
-
791
-
792
-    /**
793
-     * This returns a generated link html including the icon used for the action link for EE_Message actions.
794
-     *
795
-     * @param string          $type         What type of action the link is for (if invalid type is passed in then an
796
-     *                                      empty string is returned)
797
-     * @param EE_Message|null $message      The EE_Message object (required for some actions to generate correctly)
798
-     * @param array           $query_params Any extra query params to include in the generated link.
799
-     *
800
-     * @return string
801
-     * @throws EE_Error
802
-     * @throws ReflectionException
803
-     * @since 4.9.0
804
-     *
805
-     */
806
-    public static function get_message_action_link($type, EE_Message $message = null, $query_params = array())
807
-    {
808
-        $url = EEH_MSG_Template::get_message_action_url($type, $message, $query_params);
809
-        $icon_css = EEH_MSG_Template::get_message_action_icon($type);
810
-        $title = isset($icon_css['label']) ? 'title="' . $icon_css['label'] . '"' : '';
811
-
812
-        if (empty($url) || empty($icon_css) || ! isset($icon_css['css_class'])) {
813
-            return '';
814
-        }
815
-
816
-        $icon_css['css_class'] .= esc_attr(
817
-            apply_filters(
818
-                'FHEE__EEH_MSG_Template__get_message_action_link__icon_css_class',
819
-                ' js-ee-message-action-link ee-message-action-link-' . $type,
820
-                $type,
821
-                $message,
822
-                $query_params
823
-            )
824
-        );
825
-
826
-        return '<a href="' . $url . '" ' . $title . '><span class="' . esc_attr($icon_css['css_class']) . '"></span></a>';
827
-    }
828
-
829
-
830
-
831
-
832
-
833
-    /**
834
-     * This returns an array with keys as reg statuses and values as the corresponding message type slug (filtered).
835
-     *
836
-     * @since 4.9.0
837
-     * @return array
838
-     */
839
-    public static function reg_status_to_message_type_array()
840
-    {
841
-        return (array) apply_filters(
842
-            'FHEE__EEH_MSG_Template__reg_status_to_message_type_array',
843
-            array(
844
-                EEM_Registration::status_id_approved => 'registration',
845
-                EEM_Registration::status_id_pending_payment => 'pending_approval',
846
-                EEM_Registration::status_id_not_approved => 'not_approved_registration',
847
-                EEM_Registration::status_id_cancelled => 'cancelled_registration',
848
-                EEM_Registration::status_id_declined => 'declined_registration'
849
-            )
850
-        );
851
-    }
852
-
853
-
854
-
855
-
856
-    /**
857
-     * This returns the corresponding registration message type slug to the given reg status. If there isn't a
858
-     * match, then returns an empty string.
859
-     *
860
-     * @since 4.9.0
861
-     * @param $reg_status
862
-     * @return string
863
-     */
864
-    public static function convert_reg_status_to_message_type($reg_status)
865
-    {
866
-        $reg_status_array = self::reg_status_to_message_type_array();
867
-        return isset($reg_status_array[ $reg_status ]) ? $reg_status_array[ $reg_status ] : '';
868
-    }
869
-
870
-
871
-    /**
872
-     * This returns an array with keys as payment stati and values as the corresponding message type slug (filtered).
873
-     *
874
-     * @since 4.9.0
875
-     * @return array
876
-     */
877
-    public static function payment_status_to_message_type_array()
878
-    {
879
-        return (array) apply_filters(
880
-            'FHEE__EEH_MSG_Template__payment_status_to_message_type_array',
881
-            array(
882
-                EEM_Payment::status_id_approved => 'payment',
883
-                EEM_Payment::status_id_pending => 'payment_pending',
884
-                EEM_Payment::status_id_cancelled => 'payment_cancelled',
885
-                EEM_Payment::status_id_declined => 'payment_declined',
886
-                EEM_Payment::status_id_failed => 'payment_failed'
887
-            )
888
-        );
889
-    }
890
-
891
-
892
-
893
-
894
-    /**
895
-     * This returns the corresponding payment message type slug to the given payment status. If there isn't a match then
896
-     * an empty string is returned
897
-     *
898
-     * @since 4.9.0
899
-     * @param $payment_status
900
-     * @return string
901
-     */
902
-    public static function convert_payment_status_to_message_type($payment_status)
903
-    {
904
-        $payment_status_array = self::payment_status_to_message_type_array();
905
-        return isset($payment_status_array[ $payment_status ]) ? $payment_status_array[ $payment_status ] : '';
906
-    }
907
-
908
-
909
-    /**
910
-     * This is used to retrieve the template pack for the given name.
911
-     *
912
-     * @param string $template_pack_name  should match the set `dbref` property value on the EE_Messages_Template_Pack.
913
-     *
914
-     * @return EE_Messages_Template_Pack
915
-     */
916
-    public static function get_template_pack($template_pack_name)
917
-    {
918
-        if (! self::$_template_pack_collection instanceof EE_Object_Collection) {
919
-            self::$_template_pack_collection = new EE_Messages_Template_Pack_Collection();
920
-        }
921
-
922
-        // first see if in collection already
923
-        $template_pack = self::$_template_pack_collection->get_by_name($template_pack_name);
924
-
925
-        if ($template_pack instanceof EE_Messages_Template_Pack) {
926
-            return $template_pack;
927
-        }
928
-
929
-        // nope...let's get it.
930
-        // not set yet so let's attempt to get it.
931
-        $pack_class_name = 'EE_Messages_Template_Pack_' . str_replace(
932
-            ' ',
933
-            '_',
934
-            ucwords(
935
-                str_replace('_', ' ', $template_pack_name)
936
-            )
937
-        );
938
-        if (! class_exists($pack_class_name) && $template_pack_name !== 'default') {
939
-            return self::get_template_pack('default');
940
-        } else {
941
-            $template_pack = new $pack_class_name();
942
-            self::$_template_pack_collection->add($template_pack);
943
-            return $template_pack;
944
-        }
945
-    }
946
-
947
-
948
-
949
-
950
-    /**
951
-     * Globs template packs installed in core and returns the template pack collection with all installed template packs
952
-     * in it.
953
-     *
954
-     * @since 4.9.0
955
-     *
956
-     * @return EE_Messages_Template_Pack_Collection
957
-     */
958
-    public static function get_template_pack_collection()
959
-    {
960
-        $new_collection = false;
961
-        if (! self::$_template_pack_collection instanceof EE_Messages_Template_Pack_Collection) {
962
-            self::$_template_pack_collection = new EE_Messages_Template_Pack_Collection();
963
-            $new_collection = true;
964
-        }
965
-
966
-        // glob the defaults directory for messages
967
-        $templates = glob(EE_LIBRARIES . 'messages/defaults/*', GLOB_ONLYDIR);
968
-        foreach ($templates as $template_path) {
969
-            // grab folder name
970
-            $template = basename($template_path);
971
-
972
-            if (! $new_collection) {
973
-                // already have it?
974
-                if (self::$_template_pack_collection->get_by_name($template) instanceof EE_Messages_Template_Pack) {
975
-                    continue;
976
-                }
977
-            }
978
-
979
-            // setup classname.
980
-            $template_pack_class_name = 'EE_Messages_Template_Pack_' . str_replace(
981
-                ' ',
982
-                '_',
983
-                ucwords(
984
-                    str_replace(
985
-                        '_',
986
-                        ' ',
987
-                        $template
988
-                    )
989
-                )
990
-            );
991
-            if (! class_exists($template_pack_class_name)) {
992
-                continue;
993
-            }
994
-            self::$_template_pack_collection->add(new $template_pack_class_name());
995
-        }
996
-
997
-        /**
998
-         * Filter for plugins to add in any additional template packs
999
-         * Note the filter name here is for backward compat, this used to be found in EED_Messages.
1000
-         */
1001
-        $additional_template_packs = apply_filters('FHEE__EED_Messages__get_template_packs__template_packs', array());
1002
-        foreach ((array) $additional_template_packs as $template_pack) {
1003
-            if (
1004
-                self::$_template_pack_collection->get_by_name(
1005
-                    $template_pack->dbref
1006
-                ) instanceof EE_Messages_Template_Pack
1007
-            ) {
1008
-                continue;
1009
-            }
1010
-            self::$_template_pack_collection->add($template_pack);
1011
-        }
1012
-        return self::$_template_pack_collection;
1013
-    }
1014
-
1015
-
1016
-    /**
1017
-     * This is a wrapper for the protected _create_new_templates function
1018
-     *
1019
-     * @param string $messenger_name
1020
-     * @param string $message_type_name message type that the templates are being created for
1021
-     * @param int    $GRP_ID
1022
-     * @param bool   $global
1023
-     * @return array
1024
-     * @throws EE_Error
1025
-     * @throws ReflectionException
1026
-     */
1027
-    public static function create_new_templates($messenger_name, $message_type_name, $GRP_ID = 0, $global = false)
1028
-    {
1029
-        /** @type EE_Message_Resource_Manager $Message_Resource_Manager */
1030
-        $Message_Resource_Manager = EE_Registry::instance()->load_lib('Message_Resource_Manager');
1031
-        $messenger = $Message_Resource_Manager->valid_messenger($messenger_name);
1032
-        $message_type = $Message_Resource_Manager->valid_message_type($message_type_name);
1033
-        if (! EEH_MSG_Template::message_type_has_active_templates_for_messenger($messenger, $message_type, $global)) {
1034
-            return array();
1035
-        }
1036
-        // whew made it this far!  Okay, let's go ahead and create the templates then
1037
-        return EEH_MSG_Template::_create_new_templates($messenger, $message_type, $GRP_ID, $global);
1038
-    }
1039
-
1040
-
1041
-    /**
1042
-     * @param EE_messenger     $messenger
1043
-     * @param EE_message_type  $message_type
1044
-     * @param                  $GRP_ID
1045
-     * @param                  $global
1046
-     * @return array|mixed
1047
-     * @throws EE_Error
1048
-     * @throws ReflectionException
1049
-     */
1050
-    protected static function _create_new_templates(EE_messenger $messenger, EE_message_type $message_type, $GRP_ID, $global)
1051
-    {
1052
-        // if we're creating a custom template then we don't need to use the defaults class
1053
-        if (! $global) {
1054
-            return EEH_MSG_Template::_create_custom_template_group($messenger, $message_type, $GRP_ID);
1055
-        }
1056
-        /** @type EE_Messages_Template_Defaults $Message_Template_Defaults */
1057
-        $Message_Template_Defaults = EE_Registry::factory(
1058
-            'EE_Messages_Template_Defaults',
1059
-            array( $messenger, $message_type, $GRP_ID )
1060
-        );
1061
-        // generate templates
1062
-        $success = $Message_Template_Defaults->create_new_templates();
1063
-
1064
-        // if creating the template failed.  Then we should deactivate the related message_type for the messenger because
1065
-        // its not active if it doesn't have a template.  Note this is only happening for GLOBAL template creation
1066
-        // attempts.
1067
-        if (! $success) {
1068
-            /** @var EE_Message_Resource_Manager $message_resource_manager */
1069
-            $message_resource_manager = EE_Registry::instance()->load_lib('Message_Resource_Manager');
1070
-            $message_resource_manager->deactivate_message_type_for_messenger($message_type->name, $messenger->name);
1071
-        }
1072
-
1073
-        /**
1074
-         * $success is in an array in the following format
1075
-         * array(
1076
-         *    'GRP_ID' => $new_grp_id,
1077
-         *    'MTP_context' => $first_context_in_new_templates,
1078
-         * )
1079
-         */
1080
-        return $success;
1081
-    }
1082
-
1083
-
1084
-    /**
1085
-     * This creates a custom template using the incoming GRP_ID
1086
-     *
1087
-     * @param EE_messenger    $messenger
1088
-     * @param EE_message_type $message_type
1089
-     * @param int             $GRP_ID           GRP_ID for the template_group being used as the base
1090
-     * @return  array $success              This will be an array in the format:
1091
-     *                                          array(
1092
-     *                                          'GRP_ID' => $new_grp_id,
1093
-     *                                          'MTP_context' => $first_context_in_created_template
1094
-     *                                          )
1095
-     * @throws EE_Error
1096
-     * @throws ReflectionException
1097
-     * @access private
1098
-     */
1099
-    private static function _create_custom_template_group(EE_messenger $messenger, EE_message_type $message_type, $GRP_ID)
1100
-    {
1101
-        // defaults
1102
-        $success = array( 'GRP_ID' => null, 'MTP_context' => '' );
1103
-        // get the template group to use as a template from the db.  If $GRP_ID is empty then we'll assume the base will be the global template matching the messenger and message type.
1104
-        $Message_Template_Group = empty($GRP_ID)
1105
-            ? EEM_Message_Template_Group::instance()->get_one(
1106
-                array(
1107
-                    array(
1108
-                        'MTP_messenger'    => $messenger->name,
1109
-                        'MTP_message_type' => $message_type->name,
1110
-                        'MTP_is_global'    => true
1111
-                    )
1112
-                )
1113
-            )
1114
-            : EEM_Message_Template_Group::instance()->get_one_by_ID($GRP_ID);
1115
-        // if we don't have a mtg at this point then we need to bail.
1116
-        if (! $Message_Template_Group instanceof EE_Message_Template_Group) {
1117
-            EE_Error::add_error(
1118
-                sprintf(
1119
-                    esc_html__(
1120
-                        'Something went wrong with generating the custom template from this group id: %s.  This usually happens when there is no matching message template group in the db.',
1121
-                        'event_espresso'
1122
-                    ),
1123
-                    $GRP_ID
1124
-                ),
1125
-                __FILE__,
1126
-                __FUNCTION__,
1127
-                __LINE__
1128
-            );
1129
-            return $success;
1130
-        }
1131
-        // let's get all the related message_template objects for this group.
1132
-        $message_templates = $Message_Template_Group->message_templates();
1133
-        // now we have what we need to setup the new template
1134
-        $new_mtg = clone $Message_Template_Group;
1135
-        $new_mtg->set('GRP_ID', 0);
1136
-        $new_mtg->set('MTP_is_global', false);
1137
-
1138
-        /** @var RequestInterface $request */
1139
-        $request = LoaderFactory::getLoader()->getShared(RequestInterface::class);
1140
-        $template_name = $request->isAjax() && $request->requestParamIsSet('templateName')
1141
-            ? $request->getRequestParam('templateName')
1142
-            : esc_html__('New Custom Template', 'event_espresso');
1143
-        $template_description = $request->isAjax() && $request->requestParamIsSet('templateDescription')
1144
-            ? $request->getRequestParam('templateDescription')
1145
-            : sprintf(
1146
-                esc_html__(
1147
-                    'This is a custom template that was created for the %s messenger and %s message type.',
1148
-                    'event_espresso'
1149
-                ),
1150
-                $new_mtg->messenger_obj()->label['singular'],
1151
-                $new_mtg->message_type_obj()->label['singular']
1152
-            );
1153
-        $new_mtg->set('MTP_name', $template_name);
1154
-        $new_mtg->set('MTP_description', $template_description);
1155
-        // remove ALL relations on this template group so they don't get saved!
1156
-        $new_mtg->_remove_relations('Message_Template');
1157
-        $new_mtg->save();
1158
-        $success['GRP_ID'] = $new_mtg->ID();
1159
-        $success['template_name'] = $template_name;
1160
-        // add new message templates and add relation to.
1161
-        foreach ($message_templates as $message_template) {
1162
-            if (! $message_template instanceof EE_Message_Template) {
1163
-                continue;
1164
-            }
1165
-            $new_message_template = clone $message_template;
1166
-            $new_message_template->set('MTP_ID', 0);
1167
-            $new_message_template->set('GRP_ID', $new_mtg->ID()); // relation
1168
-            $new_message_template->save();
1169
-            if (empty($success['MTP_context']) && $new_message_template->get('MTP_context') !== 'admin') {
1170
-                $success['MTP_context'] = $new_message_template->get('MTP_context');
1171
-            }
1172
-        }
1173
-        return $success;
1174
-    }
1175
-
1176
-
1177
-    /**
1178
-     * message_type_has_active_templates_for_messenger
1179
-     *
1180
-     * @param EE_messenger    $messenger
1181
-     * @param EE_message_type $message_type
1182
-     * @param bool            $global
1183
-     * @return bool
1184
-     * @throws EE_Error
1185
-     */
1186
-    public static function message_type_has_active_templates_for_messenger(
1187
-        EE_messenger $messenger,
1188
-        EE_message_type $message_type,
1189
-        $global = false
1190
-    ) {
1191
-        // is given message_type valid for given messenger (if this is not a global save)
1192
-        if ($global) {
1193
-            return true;
1194
-        }
1195
-        $active_templates = EEM_Message_Template_Group::instance()->count(
1196
-            array(
1197
-                array(
1198
-                    'MTP_is_active'    => true,
1199
-                    'MTP_messenger'    => $messenger->name,
1200
-                    'MTP_message_type' => $message_type->name
1201
-                )
1202
-            )
1203
-        );
1204
-        if ($active_templates > 0) {
1205
-            return true;
1206
-        }
1207
-        EE_Error::add_error(
1208
-            sprintf(
1209
-                esc_html__(
1210
-                    'The %1$s message type is not registered with the %2$s messenger. Please visit the Messenger activation page to assign this message type first if you want to use it.',
1211
-                    'event_espresso'
1212
-                ),
1213
-                $message_type->name,
1214
-                $messenger->name
1215
-            ),
1216
-            __FILE__,
1217
-            __FUNCTION__,
1218
-            __LINE__
1219
-        );
1220
-        return false;
1221
-    }
1222
-
1223
-
1224
-    /**
1225
-     * get_fields
1226
-     * This takes a given messenger and message type and returns all the template fields indexed by context (and with field type).
1227
-     *
1228
-     * @param string $messenger_name    name of EE_messenger
1229
-     * @param string $message_type_name name of EE_message_type
1230
-     * @return array
1231
-     * @throws EE_Error
1232
-     * @throws ReflectionException
1233
-     */
1234
-    public static function get_fields($messenger_name, $message_type_name)
1235
-    {
1236
-        $template_fields = array();
1237
-        /** @type EE_Message_Resource_Manager $Message_Resource_Manager */
1238
-        $Message_Resource_Manager = EE_Registry::instance()->load_lib('Message_Resource_Manager');
1239
-        $messenger = $Message_Resource_Manager->valid_messenger($messenger_name);
1240
-        $message_type = $Message_Resource_Manager->valid_message_type($message_type_name);
1241
-        if (! EEH_MSG_Template::message_type_has_active_templates_for_messenger($messenger, $message_type)) {
1242
-            return array();
1243
-        }
1244
-
1245
-        $excluded_fields_for_messenger = $message_type->excludedFieldsForMessenger($messenger_name);
1246
-
1247
-        // okay now let's assemble an array with the messenger template fields added to the message_type contexts.
1248
-        foreach ($message_type->get_contexts() as $context => $details) {
1249
-            foreach ($messenger->get_template_fields() as $field => $value) {
1250
-                if (in_array($field, $excluded_fields_for_messenger, true)) {
1251
-                    continue;
1252
-                }
1253
-                $template_fields[ $context ][ $field ] = $value;
1254
-            }
1255
-        }
1256
-        if (empty($template_fields)) {
1257
-            EE_Error::add_error(
1258
-                esc_html__('Something went wrong and we couldn\'t get any templates assembled', 'event_espresso'),
1259
-                __FILE__,
1260
-                __FUNCTION__,
1261
-                __LINE__
1262
-            );
1263
-            return array();
1264
-        }
1265
-        return $template_fields;
1266
-    }
18
+	/**
19
+	 * Holds a collection of EE_Message_Template_Pack objects.
20
+	 * @type EE_Messages_Template_Pack_Collection
21
+	 */
22
+	protected static $_template_pack_collection;
23
+
24
+
25
+	/**
26
+	 * @throws EE_Error
27
+	 */
28
+	private static function _set_autoloader()
29
+	{
30
+		EED_Messages::set_autoloaders();
31
+	}
32
+
33
+
34
+	/**
35
+	 * generate_new_templates
36
+	 * This will handle the messenger, message_type selection when "adding a new custom template" for an event and will
37
+	 * automatically create the defaults for the event.  The user would then be redirected to edit the default context
38
+	 * for the event.
39
+	 *
40
+	 * @access protected
41
+	 * @param string $messenger     the messenger we are generating templates for
42
+	 * @param array  $message_types array of message types that the templates are generated for.
43
+	 * @param int    $GRP_ID        If a non global template is being generated then it is expected we'll have a GRP_ID
44
+	 *                              to use as the base for the new generated template.
45
+	 * @param bool   $global        true indicates generating templates on messenger activation. false requires GRP_ID
46
+	 *                              for event specific template generation.
47
+	 * @return array  @see EEH_MSG_Template::_create_new_templates for the return value of each element in the array
48
+	 *                for templates that are generated.  If this is an empty array then it means no templates were
49
+	 *                generated which usually means there was an error.  Anything in the array with an empty value for
50
+	 *                `MTP_context` means that it was not a new generated template but just reactivated (which only
51
+	 *                happens for global templates that already exist in the database.
52
+	 * @throws EE_Error
53
+	 * @throws ReflectionException
54
+	 */
55
+	public static function generate_new_templates($messenger, $message_types, $GRP_ID = 0, $global = false)
56
+	{
57
+		// make sure message_type is an array.
58
+		$message_types = (array) $message_types;
59
+		$templates = array();
60
+
61
+		if (empty($messenger)) {
62
+			throw new EE_Error(esc_html__('We need a messenger to generate templates!', 'event_espresso'));
63
+		}
64
+
65
+		// if we STILL have empty $message_types then we need to generate an error message b/c we NEED message types to do the template files.
66
+		if (empty($message_types)) {
67
+			throw new EE_Error(esc_html__('We need at least one message type to generate templates!', 'event_espresso'));
68
+		}
69
+
70
+		EEH_MSG_Template::_set_autoloader();
71
+		foreach ($message_types as $message_type) {
72
+			// if this is global template generation.
73
+			if ($global) {
74
+				// let's attempt to get the GRP_ID for this combo IF GRP_ID is empty.
75
+				if (empty($GRP_ID)) {
76
+					$GRP_ID = EEM_Message_Template_Group::instance()->get_one(
77
+						array(
78
+							array(
79
+								'MTP_messenger'    => $messenger,
80
+								'MTP_message_type' => $message_type,
81
+								'MTP_is_global'    => true,
82
+							),
83
+						)
84
+					);
85
+					$GRP_ID = $GRP_ID instanceof EE_Message_Template_Group ? $GRP_ID->ID() : 0;
86
+				}
87
+				// First let's determine if we already HAVE global templates for this messenger and message_type combination.
88
+				//  If we do then NO generation!!
89
+				if (EEH_MSG_Template::already_generated($messenger, $message_type, $GRP_ID)) {
90
+					$templates[] = array(
91
+						'GRP_ID' => $GRP_ID,
92
+						'MTP_context' => '',
93
+					);
94
+					// we already have generated templates for this so let's go to the next message type.
95
+					continue;
96
+				}
97
+			}
98
+			$new_message_template_group = EEH_MSG_Template::create_new_templates($messenger, $message_type, $GRP_ID, $global);
99
+
100
+			if (! $new_message_template_group) {
101
+				continue;
102
+			}
103
+			$templates[] = $new_message_template_group;
104
+		}
105
+
106
+		return $templates;
107
+	}
108
+
109
+
110
+	/**
111
+	 * The purpose of this method is to determine if there are already generated templates in the database for the
112
+	 * given variables.
113
+	 *
114
+	 * @param string $messenger    messenger
115
+	 * @param string $message_type message type
116
+	 * @param int    $GRP_ID       GRP ID ( if a custom template) (if not provided then we're just doing global
117
+	 *                             template check)
118
+	 * @return bool                true = generated, false = hasn't been generated.
119
+	 * @throws EE_Error
120
+	 */
121
+	public static function already_generated($messenger, $message_type, $GRP_ID = 0)
122
+	{
123
+		EEH_MSG_Template::_set_autoloader();
124
+		// what method we use depends on whether we have an GRP_ID or not
125
+		$count = empty($GRP_ID)
126
+			? EEM_Message_Template::instance()->count(
127
+				array(
128
+					array(
129
+						'Message_Template_Group.MTP_messenger'    => $messenger,
130
+						'Message_Template_Group.MTP_message_type' => $message_type,
131
+						'Message_Template_Group.MTP_is_global'    => true
132
+					)
133
+				)
134
+			)
135
+			: EEM_Message_Template::instance()->count(array( array( 'GRP_ID' => $GRP_ID ) ));
136
+
137
+		return $count > 0;
138
+	}
139
+
140
+
141
+	/**
142
+	 * Updates all message templates matching the incoming messengers and message types to active status.
143
+	 *
144
+	 * @static
145
+	 * @param array $messenger_names    Messenger slug
146
+	 * @param array $message_type_names Message type slug
147
+	 * @return  int                         count of updated records.
148
+	 * @throws EE_Error
149
+	 */
150
+	public static function update_to_active($messenger_names, $message_type_names)
151
+	{
152
+		$messenger_names = is_array($messenger_names) ? $messenger_names : array( $messenger_names );
153
+		$message_type_names = is_array($message_type_names) ? $message_type_names : array( $message_type_names );
154
+		return EEM_Message_Template_Group::instance()->update(
155
+			array( 'MTP_is_active' => 1 ),
156
+			array(
157
+				array(
158
+					'MTP_messenger'     => array( 'IN', $messenger_names ),
159
+					'MTP_message_type'  => array( 'IN', $message_type_names )
160
+				)
161
+			)
162
+		);
163
+	}
164
+
165
+
166
+	/**
167
+	 * Updates all message template groups matching the incoming arguments to inactive status.
168
+	 *
169
+	 * @static
170
+	 * @param array $messenger_names    The messenger slugs.
171
+	 *                                  If empty then all templates matching the message types are marked inactive.
172
+	 *                                  Otherwise only templates matching the messengers and message types.
173
+	 * @param array $message_type_names The message type slugs.
174
+	 *                                  If empty then all templates matching the messengers are marked inactive.
175
+	 *                                  Otherwise only templates matching the messengers and message types.
176
+	 *
177
+	 * @return int  count of updated records.
178
+	 * @throws EE_Error
179
+	 */
180
+	public static function update_to_inactive($messenger_names = array(), $message_type_names = array())
181
+	{
182
+		return EEM_Message_Template_Group::instance()->deactivate_message_template_groups_for(
183
+			$messenger_names,
184
+			$message_type_names
185
+		);
186
+	}
187
+
188
+
189
+	/**
190
+	 * The purpose of this function is to return all installed message objects
191
+	 * (messengers and message type regardless of whether they are ACTIVE or not)
192
+	 *
193
+	 * @param string $type
194
+	 * @return array array consisting of installed messenger objects and installed message type objects.
195
+	 * @throws EE_Error
196
+	 * @throws ReflectionException
197
+	 * @deprecated 4.9.0
198
+	 * @static
199
+	 */
200
+	public static function get_installed_message_objects($type = 'all')
201
+	{
202
+		self::_set_autoloader();
203
+		$message_resource_manager = EE_Registry::instance()->load_lib('Message_Resource_Manager');
204
+		return array(
205
+			'messenger' => $message_resource_manager->installed_messengers(),
206
+			'message_type' => $message_resource_manager->installed_message_types()
207
+		);
208
+	}
209
+
210
+
211
+	/**
212
+	 * This will return an array of shortcodes => labels from the
213
+	 * messenger and message_type objects associated with this
214
+	 * template.
215
+	 *
216
+	 * @param string $message_type
217
+	 * @param string $messenger
218
+	 * @param array  $fields                        What fields we're returning valid shortcodes for.
219
+	 *                                              If empty then we assume all fields are to be returned. Optional.
220
+	 * @param string $context                       What context we're going to return shortcodes for. Optional.
221
+	 * @param bool   $merged                        If TRUE then we don't return shortcodes indexed by field,
222
+	 *                                              but instead an array of the unique shortcodes for all the given (
223
+	 *                                              or all) fields. Optional.
224
+	 * @return array                                an array of shortcodes in the format
225
+	 *                                              array( '[shortcode] => 'label')
226
+	 *                                              OR
227
+	 *                                              FALSE if no shortcodes found.
228
+	 * @throws ReflectionException
229
+	 * @throws EE_Error*@since 4.3.0
230
+	 *
231
+	 */
232
+	public static function get_shortcodes(
233
+		$message_type,
234
+		$messenger,
235
+		$fields = array(),
236
+		$context = 'admin',
237
+		$merged = false
238
+	) {
239
+		$messenger_name = str_replace(' ', '_', ucwords(str_replace('_', ' ', $messenger)));
240
+		$mt_name = str_replace(' ', '_', ucwords(str_replace('_', ' ', $message_type)));
241
+		/** @var EE_Message_Resource_Manager $message_resource_manager */
242
+		$message_resource_manager = EE_Registry::instance()->load_lib('Message_Resource_Manager');
243
+		// convert slug to object
244
+		$messenger = $message_resource_manager->get_messenger($messenger);
245
+
246
+		// if messenger isn't a EE_messenger resource then bail.
247
+		if (! $messenger instanceof EE_messenger) {
248
+			return array();
249
+		}
250
+
251
+		// validate class for getting our list of shortcodes
252
+		$classname = 'EE_Messages_' . $messenger_name . '_' . $mt_name . '_Validator';
253
+		if (! class_exists($classname)) {
254
+			$msg[] = esc_html__('The Validator class was unable to load', 'event_espresso');
255
+			$msg[] = sprintf(
256
+				esc_html__('The class name compiled was %s. Please check and make sure the spelling and case is correct for the class name and that there is an autoloader in place for this class', 'event_espresso'),
257
+				$classname
258
+			);
259
+			throw new EE_Error(implode('||', $msg));
260
+		}
261
+
262
+		/** @type EE_Messages_Validator $_VLD */
263
+		$_VLD = new $classname(array(), $context);
264
+		$valid_shortcodes = $_VLD->get_validators();
265
+
266
+		// let's make sure we're only getting the shortcode part of the validators
267
+		$shortcodes = array();
268
+		foreach ($valid_shortcodes as $field => $validators) {
269
+			$shortcodes[ $field ] = $validators['shortcodes'];
270
+		}
271
+		$valid_shortcodes = $shortcodes;
272
+
273
+		// if not all fields let's make sure we ONLY include the shortcodes for the specified fields.
274
+		if (! empty($fields)) {
275
+			$specified_shortcodes = array();
276
+			foreach ($fields as $field) {
277
+				if (isset($valid_shortcodes[ $field ])) {
278
+					$specified_shortcodes[ $field ] = $valid_shortcodes[ $field ];
279
+				}
280
+			}
281
+			$valid_shortcodes = $specified_shortcodes;
282
+		}
283
+
284
+		// if not merged then let's replace the fields with the localized fields
285
+		if (! $merged) {
286
+			// let's get all the fields for the set messenger so that we can get the localized label and use that in the returned array.
287
+			$field_settings = $messenger->get_template_fields();
288
+			$localized = array();
289
+			foreach ($valid_shortcodes as $field => $shortcodes) {
290
+				// get localized field label
291
+				if (isset($field_settings[ $field ])) {
292
+					// possible that this is used as a main field.
293
+					if (empty($field_settings[ $field ])) {
294
+						if (isset($field_settings['extra'][ $field ])) {
295
+							$_field = $field_settings['extra'][ $field ]['main']['label'];
296
+						} else {
297
+							$_field = $field;
298
+						}
299
+					} else {
300
+						$_field = $field_settings[ $field ]['label'];
301
+					}
302
+				} elseif (isset($field_settings['extra'])) {
303
+					// loop through extra "main fields" and see if any of their children have our field
304
+					foreach ($field_settings['extra'] as $fields) {
305
+						if (isset($fields[ $field ])) {
306
+							$_field = $fields[ $field ]['label'];
307
+						} else {
308
+							$_field = $field;
309
+						}
310
+					}
311
+				} else {
312
+					$_field = $field;
313
+				}
314
+				if (isset($_field)) {
315
+					$localized[ (string) $_field ] = $shortcodes;
316
+				}
317
+			}
318
+			$valid_shortcodes = $localized;
319
+		}
320
+
321
+		// if $merged then let's merge all the shortcodes into one list NOT indexed by field.
322
+		if ($merged) {
323
+			$merged_codes = array();
324
+			foreach ($valid_shortcodes as $shortcode) {
325
+				foreach ($shortcode as $code => $label) {
326
+					if (isset($merged_codes[ $code ])) {
327
+						continue;
328
+					} else {
329
+						$merged_codes[ $code ] = $label;
330
+					}
331
+				}
332
+			}
333
+			$valid_shortcodes = $merged_codes;
334
+		}
335
+
336
+		return $valid_shortcodes;
337
+	}
338
+
339
+
340
+	/**
341
+	 * Get Messenger object.
342
+	 *
343
+	 * @param string $messenger messenger slug for the messenger object we want to retrieve.
344
+	 * @return EE_messenger
345
+	 * @throws ReflectionException
346
+	 * @throws EE_Error*@since 4.3.0
347
+	 * @deprecated 4.9.0
348
+	 */
349
+	public static function messenger_obj($messenger)
350
+	{
351
+		/** @type EE_Message_Resource_Manager $Message_Resource_Manager */
352
+		$Message_Resource_Manager = EE_Registry::instance()->load_lib('Message_Resource_Manager');
353
+		return $Message_Resource_Manager->get_messenger($messenger);
354
+	}
355
+
356
+
357
+	/**
358
+	 * get Message type object
359
+	 *
360
+	 * @param string $message_type the slug for the message type object to retrieve
361
+	 * @return EE_message_type
362
+	 * @throws ReflectionException
363
+	 * @throws EE_Error*@since 4.3.0
364
+	 * @deprecated 4.9.0
365
+	 */
366
+	public static function message_type_obj($message_type)
367
+	{
368
+		/** @type EE_Message_Resource_Manager $Message_Resource_Manager */
369
+		$Message_Resource_Manager = EE_Registry::instance()->load_lib('Message_Resource_Manager');
370
+		return $Message_Resource_Manager->get_message_type($message_type);
371
+	}
372
+
373
+
374
+	/**
375
+	 * Given a message_type slug, will return whether that message type is active in the system or not.
376
+	 *
377
+	 * @since    4.3.0
378
+	 * @param string $message_type message type to check for.
379
+	 * @return boolean
380
+	 * @throws EE_Error
381
+	 * @throws ReflectionException
382
+	 */
383
+	public static function is_mt_active($message_type)
384
+	{
385
+		/** @type EE_Message_Resource_Manager $Message_Resource_Manager */
386
+		$Message_Resource_Manager = EE_Registry::instance()->load_lib('Message_Resource_Manager');
387
+		$active_mts = $Message_Resource_Manager->list_of_active_message_types();
388
+		return in_array($message_type, $active_mts);
389
+	}
390
+
391
+
392
+	/**
393
+	 * Given a messenger slug, will return whether that messenger is active in the system or not.
394
+	 *
395
+	 * @since    4.3.0
396
+	 *
397
+	 * @param string $messenger slug for messenger to check.
398
+	 * @return boolean
399
+	 * @throws EE_Error
400
+	 * @throws ReflectionException
401
+	 */
402
+	public static function is_messenger_active($messenger)
403
+	{
404
+		/** @type EE_Message_Resource_Manager $Message_Resource_Manager */
405
+		$Message_Resource_Manager = EE_Registry::instance()->load_lib('Message_Resource_Manager');
406
+		$active_messenger = $Message_Resource_Manager->get_active_messenger($messenger);
407
+		return $active_messenger instanceof EE_messenger;
408
+	}
409
+
410
+
411
+	/**
412
+	 * Used to return active messengers array stored in the wp options table.
413
+	 * If no value is present in the option then an empty array is returned.
414
+	 *
415
+	 * @deprecated 4.9
416
+	 * @since      4.3.1
417
+	 *
418
+	 * @return array
419
+	 * @throws EE_Error
420
+	 * @throws ReflectionException
421
+	 */
422
+	public static function get_active_messengers_in_db()
423
+	{
424
+		EE_Error::doing_it_wrong(
425
+			__METHOD__,
426
+			esc_html__('Please use EE_Message_Resource_Manager::get_active_messengers_option() instead.', 'event_espresso'),
427
+			'4.9.0'
428
+		);
429
+		/** @var EE_Message_Resource_Manager $Message_Resource_Manager */
430
+		$Message_Resource_Manager = EE_Registry::instance()->load_lib('Message_Resource_Manager');
431
+		return $Message_Resource_Manager->get_active_messengers_option();
432
+	}
433
+
434
+
435
+	/**
436
+	 * Used to update the active messengers array stored in the wp options table.
437
+	 *
438
+	 * @since      4.3.1
439
+	 * @deprecated 4.9.0
440
+	 *
441
+	 * @param array $data_to_save Incoming data to save.
442
+	 *
443
+	 * @return bool FALSE if not updated, TRUE if updated.
444
+	 * @throws EE_Error
445
+	 * @throws ReflectionException
446
+	 */
447
+	public static function update_active_messengers_in_db($data_to_save)
448
+	{
449
+		EE_Error::doing_it_wrong(
450
+			__METHOD__,
451
+			esc_html__('Please use EE_Message_Resource_Manager::update_active_messengers_option() instead.', 'event_espresso'),
452
+			'4.9.0'
453
+		);
454
+		/** @var EE_Message_Resource_Manager $Message_Resource_Manager */
455
+		$Message_Resource_Manager = EE_Registry::instance()->load_lib('Message_Resource_Manager');
456
+		return $Message_Resource_Manager->update_active_messengers_option($data_to_save);
457
+	}
458
+
459
+
460
+	/**
461
+	 * This does some validation of incoming params, determines what type of url is being prepped and returns the
462
+	 * appropriate url trigger
463
+	 *
464
+	 * @param EE_message_type $message_type
465
+	 * @param EE_Message $message
466
+	 * @param EE_Registration | null $registration  The registration object must be included if this
467
+	 *                                              is going to be a registration trigger url.
468
+	 * @param string $sending_messenger             The (optional) sending messenger for the url.
469
+	 *
470
+	 * @return string
471
+	 * @throws EE_Error
472
+	 */
473
+	public static function get_url_trigger(
474
+		EE_message_type $message_type,
475
+		EE_Message $message,
476
+		$registration = null,
477
+		$sending_messenger = ''
478
+	) {
479
+		// first determine if the url can be to the EE_Message object.
480
+		if (! $message_type->always_generate()) {
481
+			return EEH_MSG_Template::generate_browser_trigger($message);
482
+		}
483
+
484
+		// if $registration object is not valid then exit early because there's nothing that can be generated.
485
+		if (! $registration instanceof EE_Registration) {
486
+			throw new EE_Error(
487
+				esc_html__('Incoming value for registration is not a valid EE_Registration object.', 'event_espresso')
488
+			);
489
+		}
490
+
491
+		// validate given context
492
+		$contexts = $message_type->get_contexts();
493
+		if ($message->context() !== '' && ! isset($contexts[ $message->context() ])) {
494
+			throw new EE_Error(
495
+				sprintf(
496
+					esc_html__('The context %s is not a valid context for %s.', 'event_espresso'),
497
+					$message->context(),
498
+					get_class($message_type)
499
+				)
500
+			);
501
+		}
502
+
503
+		// valid sending messenger but only if sending messenger set.  Otherwise generating messenger is used.
504
+		if (! empty($sending_messenger)) {
505
+			$with_messengers = $message_type->with_messengers();
506
+			if (
507
+				! isset($with_messengers[ $message->messenger() ])
508
+				 || ! in_array($sending_messenger, $with_messengers[ $message->messenger() ])
509
+			) {
510
+				throw new EE_Error(
511
+					sprintf(
512
+						esc_html__(
513
+							'The given sending messenger string (%1$s) does not match a valid sending messenger with the %2$s.  If this is incorrect, make sure that the message type has defined this messenger as a sending messenger in its $_with_messengers array.',
514
+							'event_espresso'
515
+						),
516
+						$sending_messenger,
517
+						get_class($message_type)
518
+					)
519
+				);
520
+			}
521
+		} else {
522
+			$sending_messenger = $message->messenger();
523
+		}
524
+		return EEH_MSG_Template::generate_url_trigger(
525
+			$sending_messenger,
526
+			$message->messenger(),
527
+			$message->context(),
528
+			$message->message_type(),
529
+			$registration,
530
+			$message->GRP_ID()
531
+		);
532
+	}
533
+
534
+
535
+	/**
536
+	 * This returns the url for triggering a in browser view of a specific EE_Message object.
537
+	 * @param EE_Message $message
538
+	 * @return string.
539
+	 */
540
+	public static function generate_browser_trigger(EE_Message $message)
541
+	{
542
+		$query_args = array(
543
+			'ee' => 'msg_browser_trigger',
544
+			'token' => $message->MSG_token()
545
+		);
546
+		return apply_filters(
547
+			'FHEE__EEH_MSG_Template__generate_browser_trigger',
548
+			add_query_arg($query_args, site_url()),
549
+			$message
550
+		);
551
+	}
552
+
553
+
554
+
555
+
556
+
557
+
558
+	/**
559
+	 * This returns the url for triggering an in browser view of the error saved on the incoming message object.
560
+	 * @param EE_Message $message
561
+	 * @return string
562
+	 */
563
+	public static function generate_error_display_trigger(EE_Message $message)
564
+	{
565
+		return apply_filters(
566
+			'FHEE__EEH_MSG_Template__generate_error_display_trigger',
567
+			add_query_arg(
568
+				array(
569
+					'ee' => 'msg_browser_error_trigger',
570
+					'token' => $message->MSG_token()
571
+				),
572
+				site_url()
573
+			),
574
+			$message
575
+		);
576
+	}
577
+
578
+
579
+	/**
580
+	 * This generates a url trigger for the msg_url_trigger route using the given arguments
581
+	 *
582
+	 * @param string          $sending_messenger      The sending messenger slug.
583
+	 * @param string          $generating_messenger   The generating messenger slug.
584
+	 * @param string          $context                The context for the template.
585
+	 * @param string          $message_type           The message type slug
586
+	 * @param EE_Registration $registration
587
+	 * @param integer         $message_template_group id   The EE_Message_Template_Group ID for the template.
588
+	 * @param integer         $data_id                The id to the EE_Base_Class for getting the data used by the
589
+	 *                                                trigger.
590
+	 * @return string          The generated url.
591
+	 * @throws EE_Error
592
+	 */
593
+	public static function generate_url_trigger(
594
+		$sending_messenger,
595
+		$generating_messenger,
596
+		$context,
597
+		$message_type,
598
+		EE_Registration $registration,
599
+		$message_template_group,
600
+		$data_id = 0
601
+	) {
602
+		$query_args = array(
603
+			'ee' => 'msg_url_trigger',
604
+			'snd_msgr' => $sending_messenger,
605
+			'gen_msgr' => $generating_messenger,
606
+			'message_type' => $message_type,
607
+			'context' => $context,
608
+			'token' => $registration->reg_url_link(),
609
+			'GRP_ID' => $message_template_group,
610
+			'id' => $data_id
611
+			);
612
+		$url = add_query_arg($query_args, get_home_url());
613
+
614
+		// made it here so now we can just get the url and filter it.  Filtered globally and by message type.
615
+		return apply_filters(
616
+			'FHEE__EEH_MSG_Template__generate_url_trigger',
617
+			$url,
618
+			$sending_messenger,
619
+			$generating_messenger,
620
+			$context,
621
+			$message_type,
622
+			$registration,
623
+			$message_template_group,
624
+			$data_id
625
+		);
626
+	}
627
+
628
+
629
+
630
+
631
+	/**
632
+	 * Return the specific css for the action icon given.
633
+	 *
634
+	 * @param string $type  What action to return.
635
+	 * @return string[]
636
+	 * @since 4.9.0
637
+	 */
638
+	public static function get_message_action_icon($type)
639
+	{
640
+		$action_icons = self::get_message_action_icons();
641
+		return isset($action_icons[ $type ]) ? $action_icons[ $type ] : [];
642
+	}
643
+
644
+
645
+	/**
646
+	 * This is used for retrieving the css classes used for the icons representing message actions.
647
+	 *
648
+	 * @since 4.9.0
649
+	 *
650
+	 * @return array
651
+	 */
652
+	public static function get_message_action_icons()
653
+	{
654
+		return apply_filters(
655
+			'FHEE__EEH_MSG_Template__message_action_icons',
656
+			array(
657
+				'view' => array(
658
+					'label' => esc_html__('View Message', 'event_espresso'),
659
+					'css_class' => 'dashicons dashicons-welcome-view-site',
660
+				),
661
+				'error' => array(
662
+					'label' => esc_html__('View Error Message', 'event_espresso'),
663
+					'css_class' => 'dashicons dashicons-info',
664
+				),
665
+				'see_notifications_for' => array(
666
+					'label' => esc_html__('View Related Messages', 'event_espresso'),
667
+					'css_class' => 'dashicons dashicons-megaphone',
668
+				),
669
+				'generate_now' => array(
670
+					'label' => esc_html__('Generate the message now.', 'event_espresso'),
671
+					'css_class' => 'dashicons dashicons-admin-tools',
672
+				),
673
+				'send_now' => array(
674
+					'label' => esc_html__('Send Immediately', 'event_espresso'),
675
+					'css_class' => 'dashicons dashicons-controls-forward',
676
+				),
677
+				'queue_for_resending' => array(
678
+					'label' => esc_html__('Queue for Resending', 'event_espresso'),
679
+					'css_class' => 'dashicons dashicons-controls-repeat',
680
+				),
681
+				'view_transaction' => array(
682
+					'label' => esc_html__('View related Transaction', 'event_espresso'),
683
+					'css_class' => 'dashicons dashicons-cart',
684
+				)
685
+			)
686
+		);
687
+	}
688
+
689
+
690
+	/**
691
+	 * This returns the url for a given action related to EE_Message.
692
+	 *
693
+	 * @param string     $type         What type of action to return the url for.
694
+	 * @param EE_Message $message      Required for generating the correct url for some types.
695
+	 * @param array      $query_params Any additional query params to be included with the generated url.
696
+	 *
697
+	 * @return string
698
+	 * @throws EE_Error
699
+	 * @throws ReflectionException
700
+	 * @since 4.9.0
701
+	 *
702
+	 */
703
+	public static function get_message_action_url($type, EE_Message $message = null, $query_params = array())
704
+	{
705
+		$action_urls = self::get_message_action_urls($message, $query_params);
706
+		return isset($action_urls[ $type ])  ? $action_urls[ $type ] : '';
707
+	}
708
+
709
+
710
+	/**
711
+	 * This returns all the current urls for EE_Message actions.
712
+	 *
713
+	 * @since 4.9.0
714
+	 *
715
+	 * @param EE_Message $message      The EE_Message object required to generate correct urls for some types.
716
+	 * @param array      $query_params Any additional query_params to be included with the generated url.
717
+	 *
718
+	 * @return array
719
+	 * @throws EE_Error
720
+	 * @throws ReflectionException
721
+	 */
722
+	public static function get_message_action_urls(EE_Message $message = null, $query_params = array())
723
+	{
724
+		EE_Registry::instance()->load_helper('URL');
725
+		// if $message is not an instance of EE_Message then let's just do a dummy.
726
+		$message = empty($message) ? EE_Message_Factory::create() : $message;
727
+		$action_urls =  apply_filters(
728
+			'FHEE__EEH_MSG_Template__get_message_action_url',
729
+			array(
730
+				'view' => EEH_MSG_Template::generate_browser_trigger($message),
731
+				'error' => EEH_MSG_Template::generate_error_display_trigger($message),
732
+				'see_notifications_for' => EEH_URL::add_query_args_and_nonce(
733
+					array_merge(
734
+						array(
735
+							'page' => 'espresso_messages',
736
+							'action' => 'default',
737
+							'filterby' => 1,
738
+						),
739
+						$query_params
740
+					),
741
+					admin_url('admin.php')
742
+				),
743
+				'generate_now' => EEH_URL::add_query_args_and_nonce(
744
+					array(
745
+						'page' => 'espresso_messages',
746
+						'action' => 'generate_now',
747
+						'MSG_ID' => $message->ID()
748
+					),
749
+					admin_url('admin.php')
750
+				),
751
+				'send_now' => EEH_URL::add_query_args_and_nonce(
752
+					array(
753
+						'page' => 'espresso_messages',
754
+						'action' => 'send_now',
755
+						'MSG_ID' => $message->ID()
756
+					),
757
+					admin_url('admin.php')
758
+				),
759
+				'queue_for_resending' => EEH_URL::add_query_args_and_nonce(
760
+					array(
761
+						'page' => 'espresso_messages',
762
+						'action' => 'queue_for_resending',
763
+						'MSG_ID' => $message->ID()
764
+					),
765
+					admin_url('admin.php')
766
+				),
767
+			)
768
+		);
769
+		if (
770
+			$message->TXN_ID() > 0
771
+			&& EE_Registry::instance()->CAP->current_user_can(
772
+				'ee_read_transaction',
773
+				'espresso_transactions_default',
774
+				$message->TXN_ID()
775
+			)
776
+		) {
777
+			$action_urls['view_transaction'] = EEH_URL::add_query_args_and_nonce(
778
+				array(
779
+					'page' => 'espresso_transactions',
780
+					'action' => 'view_transaction',
781
+					'TXN_ID' => $message->TXN_ID()
782
+				),
783
+				admin_url('admin.php')
784
+			);
785
+		} else {
786
+			$action_urls['view_transaction'] = '';
787
+		}
788
+		return $action_urls;
789
+	}
790
+
791
+
792
+	/**
793
+	 * This returns a generated link html including the icon used for the action link for EE_Message actions.
794
+	 *
795
+	 * @param string          $type         What type of action the link is for (if invalid type is passed in then an
796
+	 *                                      empty string is returned)
797
+	 * @param EE_Message|null $message      The EE_Message object (required for some actions to generate correctly)
798
+	 * @param array           $query_params Any extra query params to include in the generated link.
799
+	 *
800
+	 * @return string
801
+	 * @throws EE_Error
802
+	 * @throws ReflectionException
803
+	 * @since 4.9.0
804
+	 *
805
+	 */
806
+	public static function get_message_action_link($type, EE_Message $message = null, $query_params = array())
807
+	{
808
+		$url = EEH_MSG_Template::get_message_action_url($type, $message, $query_params);
809
+		$icon_css = EEH_MSG_Template::get_message_action_icon($type);
810
+		$title = isset($icon_css['label']) ? 'title="' . $icon_css['label'] . '"' : '';
811
+
812
+		if (empty($url) || empty($icon_css) || ! isset($icon_css['css_class'])) {
813
+			return '';
814
+		}
815
+
816
+		$icon_css['css_class'] .= esc_attr(
817
+			apply_filters(
818
+				'FHEE__EEH_MSG_Template__get_message_action_link__icon_css_class',
819
+				' js-ee-message-action-link ee-message-action-link-' . $type,
820
+				$type,
821
+				$message,
822
+				$query_params
823
+			)
824
+		);
825
+
826
+		return '<a href="' . $url . '" ' . $title . '><span class="' . esc_attr($icon_css['css_class']) . '"></span></a>';
827
+	}
828
+
829
+
830
+
831
+
832
+
833
+	/**
834
+	 * This returns an array with keys as reg statuses and values as the corresponding message type slug (filtered).
835
+	 *
836
+	 * @since 4.9.0
837
+	 * @return array
838
+	 */
839
+	public static function reg_status_to_message_type_array()
840
+	{
841
+		return (array) apply_filters(
842
+			'FHEE__EEH_MSG_Template__reg_status_to_message_type_array',
843
+			array(
844
+				EEM_Registration::status_id_approved => 'registration',
845
+				EEM_Registration::status_id_pending_payment => 'pending_approval',
846
+				EEM_Registration::status_id_not_approved => 'not_approved_registration',
847
+				EEM_Registration::status_id_cancelled => 'cancelled_registration',
848
+				EEM_Registration::status_id_declined => 'declined_registration'
849
+			)
850
+		);
851
+	}
852
+
853
+
854
+
855
+
856
+	/**
857
+	 * This returns the corresponding registration message type slug to the given reg status. If there isn't a
858
+	 * match, then returns an empty string.
859
+	 *
860
+	 * @since 4.9.0
861
+	 * @param $reg_status
862
+	 * @return string
863
+	 */
864
+	public static function convert_reg_status_to_message_type($reg_status)
865
+	{
866
+		$reg_status_array = self::reg_status_to_message_type_array();
867
+		return isset($reg_status_array[ $reg_status ]) ? $reg_status_array[ $reg_status ] : '';
868
+	}
869
+
870
+
871
+	/**
872
+	 * This returns an array with keys as payment stati and values as the corresponding message type slug (filtered).
873
+	 *
874
+	 * @since 4.9.0
875
+	 * @return array
876
+	 */
877
+	public static function payment_status_to_message_type_array()
878
+	{
879
+		return (array) apply_filters(
880
+			'FHEE__EEH_MSG_Template__payment_status_to_message_type_array',
881
+			array(
882
+				EEM_Payment::status_id_approved => 'payment',
883
+				EEM_Payment::status_id_pending => 'payment_pending',
884
+				EEM_Payment::status_id_cancelled => 'payment_cancelled',
885
+				EEM_Payment::status_id_declined => 'payment_declined',
886
+				EEM_Payment::status_id_failed => 'payment_failed'
887
+			)
888
+		);
889
+	}
890
+
891
+
892
+
893
+
894
+	/**
895
+	 * This returns the corresponding payment message type slug to the given payment status. If there isn't a match then
896
+	 * an empty string is returned
897
+	 *
898
+	 * @since 4.9.0
899
+	 * @param $payment_status
900
+	 * @return string
901
+	 */
902
+	public static function convert_payment_status_to_message_type($payment_status)
903
+	{
904
+		$payment_status_array = self::payment_status_to_message_type_array();
905
+		return isset($payment_status_array[ $payment_status ]) ? $payment_status_array[ $payment_status ] : '';
906
+	}
907
+
908
+
909
+	/**
910
+	 * This is used to retrieve the template pack for the given name.
911
+	 *
912
+	 * @param string $template_pack_name  should match the set `dbref` property value on the EE_Messages_Template_Pack.
913
+	 *
914
+	 * @return EE_Messages_Template_Pack
915
+	 */
916
+	public static function get_template_pack($template_pack_name)
917
+	{
918
+		if (! self::$_template_pack_collection instanceof EE_Object_Collection) {
919
+			self::$_template_pack_collection = new EE_Messages_Template_Pack_Collection();
920
+		}
921
+
922
+		// first see if in collection already
923
+		$template_pack = self::$_template_pack_collection->get_by_name($template_pack_name);
924
+
925
+		if ($template_pack instanceof EE_Messages_Template_Pack) {
926
+			return $template_pack;
927
+		}
928
+
929
+		// nope...let's get it.
930
+		// not set yet so let's attempt to get it.
931
+		$pack_class_name = 'EE_Messages_Template_Pack_' . str_replace(
932
+			' ',
933
+			'_',
934
+			ucwords(
935
+				str_replace('_', ' ', $template_pack_name)
936
+			)
937
+		);
938
+		if (! class_exists($pack_class_name) && $template_pack_name !== 'default') {
939
+			return self::get_template_pack('default');
940
+		} else {
941
+			$template_pack = new $pack_class_name();
942
+			self::$_template_pack_collection->add($template_pack);
943
+			return $template_pack;
944
+		}
945
+	}
946
+
947
+
948
+
949
+
950
+	/**
951
+	 * Globs template packs installed in core and returns the template pack collection with all installed template packs
952
+	 * in it.
953
+	 *
954
+	 * @since 4.9.0
955
+	 *
956
+	 * @return EE_Messages_Template_Pack_Collection
957
+	 */
958
+	public static function get_template_pack_collection()
959
+	{
960
+		$new_collection = false;
961
+		if (! self::$_template_pack_collection instanceof EE_Messages_Template_Pack_Collection) {
962
+			self::$_template_pack_collection = new EE_Messages_Template_Pack_Collection();
963
+			$new_collection = true;
964
+		}
965
+
966
+		// glob the defaults directory for messages
967
+		$templates = glob(EE_LIBRARIES . 'messages/defaults/*', GLOB_ONLYDIR);
968
+		foreach ($templates as $template_path) {
969
+			// grab folder name
970
+			$template = basename($template_path);
971
+
972
+			if (! $new_collection) {
973
+				// already have it?
974
+				if (self::$_template_pack_collection->get_by_name($template) instanceof EE_Messages_Template_Pack) {
975
+					continue;
976
+				}
977
+			}
978
+
979
+			// setup classname.
980
+			$template_pack_class_name = 'EE_Messages_Template_Pack_' . str_replace(
981
+				' ',
982
+				'_',
983
+				ucwords(
984
+					str_replace(
985
+						'_',
986
+						' ',
987
+						$template
988
+					)
989
+				)
990
+			);
991
+			if (! class_exists($template_pack_class_name)) {
992
+				continue;
993
+			}
994
+			self::$_template_pack_collection->add(new $template_pack_class_name());
995
+		}
996
+
997
+		/**
998
+		 * Filter for plugins to add in any additional template packs
999
+		 * Note the filter name here is for backward compat, this used to be found in EED_Messages.
1000
+		 */
1001
+		$additional_template_packs = apply_filters('FHEE__EED_Messages__get_template_packs__template_packs', array());
1002
+		foreach ((array) $additional_template_packs as $template_pack) {
1003
+			if (
1004
+				self::$_template_pack_collection->get_by_name(
1005
+					$template_pack->dbref
1006
+				) instanceof EE_Messages_Template_Pack
1007
+			) {
1008
+				continue;
1009
+			}
1010
+			self::$_template_pack_collection->add($template_pack);
1011
+		}
1012
+		return self::$_template_pack_collection;
1013
+	}
1014
+
1015
+
1016
+	/**
1017
+	 * This is a wrapper for the protected _create_new_templates function
1018
+	 *
1019
+	 * @param string $messenger_name
1020
+	 * @param string $message_type_name message type that the templates are being created for
1021
+	 * @param int    $GRP_ID
1022
+	 * @param bool   $global
1023
+	 * @return array
1024
+	 * @throws EE_Error
1025
+	 * @throws ReflectionException
1026
+	 */
1027
+	public static function create_new_templates($messenger_name, $message_type_name, $GRP_ID = 0, $global = false)
1028
+	{
1029
+		/** @type EE_Message_Resource_Manager $Message_Resource_Manager */
1030
+		$Message_Resource_Manager = EE_Registry::instance()->load_lib('Message_Resource_Manager');
1031
+		$messenger = $Message_Resource_Manager->valid_messenger($messenger_name);
1032
+		$message_type = $Message_Resource_Manager->valid_message_type($message_type_name);
1033
+		if (! EEH_MSG_Template::message_type_has_active_templates_for_messenger($messenger, $message_type, $global)) {
1034
+			return array();
1035
+		}
1036
+		// whew made it this far!  Okay, let's go ahead and create the templates then
1037
+		return EEH_MSG_Template::_create_new_templates($messenger, $message_type, $GRP_ID, $global);
1038
+	}
1039
+
1040
+
1041
+	/**
1042
+	 * @param EE_messenger     $messenger
1043
+	 * @param EE_message_type  $message_type
1044
+	 * @param                  $GRP_ID
1045
+	 * @param                  $global
1046
+	 * @return array|mixed
1047
+	 * @throws EE_Error
1048
+	 * @throws ReflectionException
1049
+	 */
1050
+	protected static function _create_new_templates(EE_messenger $messenger, EE_message_type $message_type, $GRP_ID, $global)
1051
+	{
1052
+		// if we're creating a custom template then we don't need to use the defaults class
1053
+		if (! $global) {
1054
+			return EEH_MSG_Template::_create_custom_template_group($messenger, $message_type, $GRP_ID);
1055
+		}
1056
+		/** @type EE_Messages_Template_Defaults $Message_Template_Defaults */
1057
+		$Message_Template_Defaults = EE_Registry::factory(
1058
+			'EE_Messages_Template_Defaults',
1059
+			array( $messenger, $message_type, $GRP_ID )
1060
+		);
1061
+		// generate templates
1062
+		$success = $Message_Template_Defaults->create_new_templates();
1063
+
1064
+		// if creating the template failed.  Then we should deactivate the related message_type for the messenger because
1065
+		// its not active if it doesn't have a template.  Note this is only happening for GLOBAL template creation
1066
+		// attempts.
1067
+		if (! $success) {
1068
+			/** @var EE_Message_Resource_Manager $message_resource_manager */
1069
+			$message_resource_manager = EE_Registry::instance()->load_lib('Message_Resource_Manager');
1070
+			$message_resource_manager->deactivate_message_type_for_messenger($message_type->name, $messenger->name);
1071
+		}
1072
+
1073
+		/**
1074
+		 * $success is in an array in the following format
1075
+		 * array(
1076
+		 *    'GRP_ID' => $new_grp_id,
1077
+		 *    'MTP_context' => $first_context_in_new_templates,
1078
+		 * )
1079
+		 */
1080
+		return $success;
1081
+	}
1082
+
1083
+
1084
+	/**
1085
+	 * This creates a custom template using the incoming GRP_ID
1086
+	 *
1087
+	 * @param EE_messenger    $messenger
1088
+	 * @param EE_message_type $message_type
1089
+	 * @param int             $GRP_ID           GRP_ID for the template_group being used as the base
1090
+	 * @return  array $success              This will be an array in the format:
1091
+	 *                                          array(
1092
+	 *                                          'GRP_ID' => $new_grp_id,
1093
+	 *                                          'MTP_context' => $first_context_in_created_template
1094
+	 *                                          )
1095
+	 * @throws EE_Error
1096
+	 * @throws ReflectionException
1097
+	 * @access private
1098
+	 */
1099
+	private static function _create_custom_template_group(EE_messenger $messenger, EE_message_type $message_type, $GRP_ID)
1100
+	{
1101
+		// defaults
1102
+		$success = array( 'GRP_ID' => null, 'MTP_context' => '' );
1103
+		// get the template group to use as a template from the db.  If $GRP_ID is empty then we'll assume the base will be the global template matching the messenger and message type.
1104
+		$Message_Template_Group = empty($GRP_ID)
1105
+			? EEM_Message_Template_Group::instance()->get_one(
1106
+				array(
1107
+					array(
1108
+						'MTP_messenger'    => $messenger->name,
1109
+						'MTP_message_type' => $message_type->name,
1110
+						'MTP_is_global'    => true
1111
+					)
1112
+				)
1113
+			)
1114
+			: EEM_Message_Template_Group::instance()->get_one_by_ID($GRP_ID);
1115
+		// if we don't have a mtg at this point then we need to bail.
1116
+		if (! $Message_Template_Group instanceof EE_Message_Template_Group) {
1117
+			EE_Error::add_error(
1118
+				sprintf(
1119
+					esc_html__(
1120
+						'Something went wrong with generating the custom template from this group id: %s.  This usually happens when there is no matching message template group in the db.',
1121
+						'event_espresso'
1122
+					),
1123
+					$GRP_ID
1124
+				),
1125
+				__FILE__,
1126
+				__FUNCTION__,
1127
+				__LINE__
1128
+			);
1129
+			return $success;
1130
+		}
1131
+		// let's get all the related message_template objects for this group.
1132
+		$message_templates = $Message_Template_Group->message_templates();
1133
+		// now we have what we need to setup the new template
1134
+		$new_mtg = clone $Message_Template_Group;
1135
+		$new_mtg->set('GRP_ID', 0);
1136
+		$new_mtg->set('MTP_is_global', false);
1137
+
1138
+		/** @var RequestInterface $request */
1139
+		$request = LoaderFactory::getLoader()->getShared(RequestInterface::class);
1140
+		$template_name = $request->isAjax() && $request->requestParamIsSet('templateName')
1141
+			? $request->getRequestParam('templateName')
1142
+			: esc_html__('New Custom Template', 'event_espresso');
1143
+		$template_description = $request->isAjax() && $request->requestParamIsSet('templateDescription')
1144
+			? $request->getRequestParam('templateDescription')
1145
+			: sprintf(
1146
+				esc_html__(
1147
+					'This is a custom template that was created for the %s messenger and %s message type.',
1148
+					'event_espresso'
1149
+				),
1150
+				$new_mtg->messenger_obj()->label['singular'],
1151
+				$new_mtg->message_type_obj()->label['singular']
1152
+			);
1153
+		$new_mtg->set('MTP_name', $template_name);
1154
+		$new_mtg->set('MTP_description', $template_description);
1155
+		// remove ALL relations on this template group so they don't get saved!
1156
+		$new_mtg->_remove_relations('Message_Template');
1157
+		$new_mtg->save();
1158
+		$success['GRP_ID'] = $new_mtg->ID();
1159
+		$success['template_name'] = $template_name;
1160
+		// add new message templates and add relation to.
1161
+		foreach ($message_templates as $message_template) {
1162
+			if (! $message_template instanceof EE_Message_Template) {
1163
+				continue;
1164
+			}
1165
+			$new_message_template = clone $message_template;
1166
+			$new_message_template->set('MTP_ID', 0);
1167
+			$new_message_template->set('GRP_ID', $new_mtg->ID()); // relation
1168
+			$new_message_template->save();
1169
+			if (empty($success['MTP_context']) && $new_message_template->get('MTP_context') !== 'admin') {
1170
+				$success['MTP_context'] = $new_message_template->get('MTP_context');
1171
+			}
1172
+		}
1173
+		return $success;
1174
+	}
1175
+
1176
+
1177
+	/**
1178
+	 * message_type_has_active_templates_for_messenger
1179
+	 *
1180
+	 * @param EE_messenger    $messenger
1181
+	 * @param EE_message_type $message_type
1182
+	 * @param bool            $global
1183
+	 * @return bool
1184
+	 * @throws EE_Error
1185
+	 */
1186
+	public static function message_type_has_active_templates_for_messenger(
1187
+		EE_messenger $messenger,
1188
+		EE_message_type $message_type,
1189
+		$global = false
1190
+	) {
1191
+		// is given message_type valid for given messenger (if this is not a global save)
1192
+		if ($global) {
1193
+			return true;
1194
+		}
1195
+		$active_templates = EEM_Message_Template_Group::instance()->count(
1196
+			array(
1197
+				array(
1198
+					'MTP_is_active'    => true,
1199
+					'MTP_messenger'    => $messenger->name,
1200
+					'MTP_message_type' => $message_type->name
1201
+				)
1202
+			)
1203
+		);
1204
+		if ($active_templates > 0) {
1205
+			return true;
1206
+		}
1207
+		EE_Error::add_error(
1208
+			sprintf(
1209
+				esc_html__(
1210
+					'The %1$s message type is not registered with the %2$s messenger. Please visit the Messenger activation page to assign this message type first if you want to use it.',
1211
+					'event_espresso'
1212
+				),
1213
+				$message_type->name,
1214
+				$messenger->name
1215
+			),
1216
+			__FILE__,
1217
+			__FUNCTION__,
1218
+			__LINE__
1219
+		);
1220
+		return false;
1221
+	}
1222
+
1223
+
1224
+	/**
1225
+	 * get_fields
1226
+	 * This takes a given messenger and message type and returns all the template fields indexed by context (and with field type).
1227
+	 *
1228
+	 * @param string $messenger_name    name of EE_messenger
1229
+	 * @param string $message_type_name name of EE_message_type
1230
+	 * @return array
1231
+	 * @throws EE_Error
1232
+	 * @throws ReflectionException
1233
+	 */
1234
+	public static function get_fields($messenger_name, $message_type_name)
1235
+	{
1236
+		$template_fields = array();
1237
+		/** @type EE_Message_Resource_Manager $Message_Resource_Manager */
1238
+		$Message_Resource_Manager = EE_Registry::instance()->load_lib('Message_Resource_Manager');
1239
+		$messenger = $Message_Resource_Manager->valid_messenger($messenger_name);
1240
+		$message_type = $Message_Resource_Manager->valid_message_type($message_type_name);
1241
+		if (! EEH_MSG_Template::message_type_has_active_templates_for_messenger($messenger, $message_type)) {
1242
+			return array();
1243
+		}
1244
+
1245
+		$excluded_fields_for_messenger = $message_type->excludedFieldsForMessenger($messenger_name);
1246
+
1247
+		// okay now let's assemble an array with the messenger template fields added to the message_type contexts.
1248
+		foreach ($message_type->get_contexts() as $context => $details) {
1249
+			foreach ($messenger->get_template_fields() as $field => $value) {
1250
+				if (in_array($field, $excluded_fields_for_messenger, true)) {
1251
+					continue;
1252
+				}
1253
+				$template_fields[ $context ][ $field ] = $value;
1254
+			}
1255
+		}
1256
+		if (empty($template_fields)) {
1257
+			EE_Error::add_error(
1258
+				esc_html__('Something went wrong and we couldn\'t get any templates assembled', 'event_espresso'),
1259
+				__FILE__,
1260
+				__FUNCTION__,
1261
+				__LINE__
1262
+			);
1263
+			return array();
1264
+		}
1265
+		return $template_fields;
1266
+	}
1267 1267
 }
Please login to merge, or discard this patch.