Completed
Branch master (7421d0)
by
unknown
11:25 queued 06:55
created
core/CPTs/EE_CPT_Strategy.core.php 2 patches
Indentation   +343 added lines, -343 removed lines patch added patch discarded remove patch
@@ -16,347 +16,347 @@
 block discarded – undo
16 16
  */
17 17
 class EE_CPT_Strategy extends EE_Base
18 18
 {
19
-    private static ?EE_CPT_Strategy $_instance = null;
20
-
21
-    protected ?EEM_CPT_Base $CPT_model = null;
22
-
23
-    /**
24
-     * @var CptQueryModifier[]
25
-     */
26
-    protected array $query_modifier = [];
27
-
28
-    /**
29
-     * the current page, if it utilizes CPTs
30
-     */
31
-    protected array $CPT = [];
32
-
33
-    /**
34
-     * return value from CustomPostTypeDefinitions::getDefinitions()
35
-     */
36
-    protected array $_CPTs = [];
37
-
38
-    protected array $_CPT_taxonomies = [];
39
-
40
-    protected array $_CPT_terms = [];
41
-
42
-    protected array $_CPT_endpoints = [];
43
-
44
-
45
-    /**
46
-     * @singleton method used to instantiate class object
47
-     * @param CustomPostTypeDefinitions|null $custom_post_types
48
-     * @param CustomTaxonomyDefinitions|null $taxonomies
49
-     * @return EE_CPT_Strategy
50
-     */
51
-    public static function instance(
52
-        CustomPostTypeDefinitions $custom_post_types = null,
53
-        CustomTaxonomyDefinitions $taxonomies = null
54
-    ): EE_CPT_Strategy {
55
-        // check if class object is instantiated
56
-        if (
57
-            ! self::$_instance instanceof EE_CPT_Strategy
58
-            && $custom_post_types instanceof CustomPostTypeDefinitions
59
-            && $taxonomies instanceof CustomTaxonomyDefinitions
60
-        ) {
61
-            self::$_instance = new self($custom_post_types, $taxonomies);
62
-        }
63
-        return self::$_instance;
64
-    }
65
-
66
-
67
-    /**
68
-     * @param CustomPostTypeDefinitions $custom_post_types
69
-     * @param CustomTaxonomyDefinitions $taxonomies
70
-     */
71
-    protected function __construct(
72
-        CustomPostTypeDefinitions $custom_post_types,
73
-        CustomTaxonomyDefinitions $taxonomies
74
-    ) {
75
-        // get CPT data
76
-        $this->_CPTs           = $custom_post_types->getDefinitions();
77
-        $this->_CPT_endpoints  = $this->_set_CPT_endpoints();
78
-        $this->_CPT_taxonomies = $taxonomies->getCustomTaxonomyDefinitions();
79
-        add_action('pre_get_posts', [$this, 'pre_get_posts'], 5);
80
-    }
81
-
82
-
83
-    /**
84
-     * @return array
85
-     */
86
-    public function get_CPT_endpoints(): array
87
-    {
88
-        return $this->_CPT_endpoints;
89
-    }
90
-
91
-
92
-    /**
93
-     * @return array
94
-     */
95
-    public function get_CPT_taxonomies(): array
96
-    {
97
-        return $this->_CPT_taxonomies;
98
-    }
99
-
100
-
101
-    /**
102
-     * add CPT "slugs" to array of default espresso "pages"
103
-     *
104
-     * @return array
105
-     */
106
-    private function _set_CPT_endpoints(): array
107
-    {
108
-        $_CPT_endpoints = [];
109
-        foreach ($this->_CPTs as $CPT_type => $CPT) {
110
-            if (isset($CPT['plural_slug'])) {
111
-                $_CPT_endpoints [ (string) $CPT['plural_slug'] ] = $CPT_type;
112
-            }
113
-        }
114
-        return $_CPT_endpoints;
115
-    }
116
-
117
-
118
-    public function wpQueryPostType(?WP_Query $wp_query): string
119
-    {
120
-        if (! $wp_query instanceof WP_Query) {
121
-            return '';
122
-        }
123
-        // cuz WP_Query is a mess and doesn't always have the post_type set in the same place
124
-        $post_type = $wp_query->query->post_type ?? '';
125
-        $post_type = $wp_query->query['post_type'] ?? $post_type;
126
-        $post_type = $wp_query->query_vars['post_type'] ?? $post_type;
127
-        return is_array($post_type) ? (string) reset($post_type) : (string) $post_type;
128
-    }
129
-
130
-
131
-    public function isEspressoPostType(WP_Query $wp_query): bool
132
-    {
133
-        $post_type = $this->wpQueryPostType($wp_query);
134
-        return isset($this->_CPTs[ $post_type ]);
135
-    }
136
-
137
-
138
-    /**
139
-     * If this query (not just "main" queries (ie, for WP's infamous "loop")) is for an EE CPT, then we want to
140
-     * supercharge the get_posts query to add our EE stuff (like joining to our tables, selecting extra columns, and
141
-     * adding EE objects to the post to facilitate further querying of related data etc)
142
-     *
143
-     * @param WP_Query $wp_query
144
-     * @return void
145
-     * @throws EE_Error
146
-     * @throws ReflectionException
147
-     */
148
-    public function pre_get_posts(WP_Query $wp_query)
149
-    {
150
-        // add our conditionals
151
-        $this->_set_EE_tags_on_WP_Query($wp_query);
152
-        // check for terms
153
-        $this->_set_post_type_for_terms($wp_query);
154
-        // make sure paging is always set
155
-        $this->_set_paging($wp_query);
156
-        // is a taxonomy set ?
157
-        $this->_set_CPT_taxonomies_on_WP_Query($wp_query);
158
-        // loop thru post_types if set
159
-        $this->_process_WP_Query_post_types($wp_query);
160
-    }
161
-
162
-
163
-    /**
164
-     * @param WP_Query $wp_query
165
-     * @return void
166
-     */
167
-    private function _set_EE_tags_on_WP_Query(WP_Query $wp_query)
168
-    {
169
-        $wp_query->is_espresso_event_single   = false;
170
-        $wp_query->is_espresso_event_archive  = false;
171
-        $wp_query->is_espresso_event_taxonomy = false;
172
-        $wp_query->is_espresso_venue_single   = false;
173
-        $wp_query->is_espresso_venue_archive  = false;
174
-        $wp_query->is_espresso_venue_taxonomy = false;
175
-    }
176
-
177
-
178
-    /**
179
-     * @return void
180
-     * @throws EE_Error
181
-     * @throws ReflectionException
182
-     */
183
-    private function _set_CPT_terms()
184
-    {
185
-        if (empty($this->_CPT_terms)) {
186
-            $terms = EEM_Term::instance()->get_all_CPT_post_tags();
187
-            foreach ($terms as $term) {
188
-                if ($term instanceof EE_Term) {
189
-                    $this->_CPT_terms[ $term->slug() ] = $term;
190
-                }
191
-            }
192
-        }
193
-    }
194
-
195
-
196
-    /**
197
-     * @param WP_Query $wp_query
198
-     * @return void
199
-     * @throws EE_Error
200
-     * @throws ReflectionException
201
-     */
202
-    private function _set_post_type_for_terms(WP_Query $wp_query)
203
-    {
204
-        // is a tag set ?
205
-        if (! isset($wp_query->query['tag'])) {
206
-            return;
207
-        }
208
-        // get term for tag
209
-        $term = EEM_Term::instance()->get_post_tag_for_event_or_venue($wp_query->query['tag']);
210
-        // verify the term
211
-        if (! $term instanceof EE_Term) {
212
-            return;
213
-        }
214
-        // set post_type from term
215
-        $term->post_type = (array) apply_filters(
216
-            'FHEE__EE_CPT_Strategy___set_post_type_for_terms__term_post_type',
217
-            array_merge(['post', 'page'], $term->post_type),
218
-            $term
219
-        );
220
-        // if a post type is already set
221
-        if (isset($wp_query->query_vars['post_type'])) {
222
-            // add to existing array
223
-            $term->post_type = array_merge((array) $wp_query->query_vars['post_type'], $term->post_type);
224
-        }
225
-        // just set post_type to our CPT
226
-        $wp_query->set('post_type', array_unique($term->post_type));
227
-    }
228
-
229
-
230
-    /**
231
-     * @param WP_Query $wp_query
232
-     * @return void
233
-     */
234
-    public function _set_paging(WP_Query $wp_query)
235
-    {
236
-        if ($wp_query->is_main_query() && apply_filters('FHEE__EE_CPT_Strategy___set_paging', true)) {
237
-            $page  = get_query_var('page') ? get_query_var('page') : null;
238
-            $paged = get_query_var('paged') ? get_query_var('paged') : $page;
239
-            $wp_query->set('paged', $paged);
240
-        }
241
-    }
242
-
243
-
244
-    /**
245
-     * @param WP_Query $wp_query
246
-     */
247
-    protected function _set_CPT_taxonomies_on_WP_Query(WP_Query $wp_query)
248
-    {
249
-        // is a taxonomy set ?
250
-        if (! $wp_query->is_tax) {
251
-            return;
252
-        }
253
-        // loop thru our taxonomies
254
-        foreach ($this->_CPT_taxonomies as $CPT_taxonomy => $CPT_taxonomy_details) {
255
-            // check if one of our taxonomies is set as a query var
256
-            if (! isset($wp_query->query[ $CPT_taxonomy ])) {
257
-                continue;
258
-            }
259
-            // but which CPT does that correspond to??? hmmm... guess we gotta go looping
260
-            foreach ($this->_CPTs as $post_type => $CPT) {
261
-                // verify our CPT has args, is public and has taxonomies set
262
-                if (
263
-                    ! isset($CPT['args']['public'])
264
-                    || ! $CPT['args']['public']
265
-                    || empty($CPT['args']['taxonomies'])
266
-                    || ! in_array($CPT_taxonomy, $CPT['args']['taxonomies'], true)
267
-                ) {
268
-                    continue;
269
-                }
270
-                // if so, then add this CPT post_type to the current query's array of post_types'
271
-                $wp_query->query_vars['post_type']   = isset($wp_query->query_vars['post_type'])
272
-                    ? (array) $wp_query->query_vars['post_type']
273
-                    : [];
274
-                $wp_query->query_vars['post_type'][] = $post_type;
275
-                switch ($post_type) {
276
-                    case EspressoPostType::EVENTS:
277
-                        $wp_query->is_espresso_event_taxonomy = true;
278
-                        break;
279
-
280
-                    case EspressoPostType::VENUES:
281
-                        $wp_query->is_espresso_venue_taxonomy = true;
282
-                        break;
283
-
284
-                    default:
285
-                        do_action(
286
-                            'AHEE__EE_CPT_Strategy___set_CPT_taxonomies_on_WP_Query__for_' . $post_type . '_post_type',
287
-                            $wp_query,
288
-                            $this
289
-                        );
290
-                }
291
-            }
292
-        }
293
-    }
294
-
295
-
296
-    /**
297
-     * @param WP_Query $wp_query
298
-     */
299
-    protected function _process_WP_Query_post_types(WP_Query $wp_query)
300
-    {
301
-        if (! isset($wp_query->query_vars['post_type'])) {
302
-            return;
303
-        }
304
-        // loop thru post_types as array
305
-        foreach ((array) $wp_query->query_vars['post_type'] as $post_type) {
306
-            // is current query for an EE CPT ?
307
-            if (! isset($this->_CPTs[ $post_type ])) {
308
-                continue;
309
-            }
310
-            // is EE on or off ?
311
-            if (MaintenanceStatus::isNotDisabled()) {
312
-                // reroute CPT template view to maintenance_mode.template.php
313
-                if (! has_filter('template_include', ['EE_Maintenance_Mode', 'template_include'])) {
314
-                    add_filter('template_include', ['EE_Maintenance_Mode', 'template_include'], 99999);
315
-                }
316
-                if (has_filter('the_content', [EE_Maintenance_Mode::instance(), 'the_content'])) {
317
-                    add_filter('the_content', [$this, 'inject_EE_shortcode_placeholder'], 1);
318
-                }
319
-                return;
320
-            }
321
-            $this->_generate_CptQueryModifier($wp_query, $post_type);
322
-        }
323
-    }
324
-
325
-
326
-    /**
327
-     * @param WP_Query $wp_query
328
-     * @param string   $post_type
329
-     */
330
-    protected function _generate_CptQueryModifier(WP_Query $wp_query, string $post_type)
331
-    {
332
-        if (
333
-            isset($this->query_modifier[ $post_type ])
334
-            && $this->query_modifier[ $post_type ] instanceof CptQueryModifier
335
-        ) {
336
-            return;
337
-        }
338
-        $this->query_modifier[ $post_type ] = LoaderFactory::getLoader()->getShared(
339
-            CptQueryModifier::class,
340
-            [
341
-                $post_type,
342
-                $this->_CPTs[ $post_type ],
343
-                $wp_query,
344
-            ]
345
-        );
346
-        $this->_CPT_taxonomies              = $this->query_modifier[ $post_type ]->taxonomies();
347
-    }
348
-
349
-
350
-    /**
351
-     * inject_EE_shortcode_placeholder
352
-     * in order to display the M-Mode notice on our CPT routes,
353
-     * we need to first inject what looks like one of our shortcodes,
354
-     * so that it can be replaced with the actual M-Mode notice
355
-     *
356
-     * @return string
357
-     */
358
-    public function inject_EE_shortcode_placeholder(): string
359
-    {
360
-        return '[ESPRESSO_';
361
-    }
19
+	private static ?EE_CPT_Strategy $_instance = null;
20
+
21
+	protected ?EEM_CPT_Base $CPT_model = null;
22
+
23
+	/**
24
+	 * @var CptQueryModifier[]
25
+	 */
26
+	protected array $query_modifier = [];
27
+
28
+	/**
29
+	 * the current page, if it utilizes CPTs
30
+	 */
31
+	protected array $CPT = [];
32
+
33
+	/**
34
+	 * return value from CustomPostTypeDefinitions::getDefinitions()
35
+	 */
36
+	protected array $_CPTs = [];
37
+
38
+	protected array $_CPT_taxonomies = [];
39
+
40
+	protected array $_CPT_terms = [];
41
+
42
+	protected array $_CPT_endpoints = [];
43
+
44
+
45
+	/**
46
+	 * @singleton method used to instantiate class object
47
+	 * @param CustomPostTypeDefinitions|null $custom_post_types
48
+	 * @param CustomTaxonomyDefinitions|null $taxonomies
49
+	 * @return EE_CPT_Strategy
50
+	 */
51
+	public static function instance(
52
+		CustomPostTypeDefinitions $custom_post_types = null,
53
+		CustomTaxonomyDefinitions $taxonomies = null
54
+	): EE_CPT_Strategy {
55
+		// check if class object is instantiated
56
+		if (
57
+			! self::$_instance instanceof EE_CPT_Strategy
58
+			&& $custom_post_types instanceof CustomPostTypeDefinitions
59
+			&& $taxonomies instanceof CustomTaxonomyDefinitions
60
+		) {
61
+			self::$_instance = new self($custom_post_types, $taxonomies);
62
+		}
63
+		return self::$_instance;
64
+	}
65
+
66
+
67
+	/**
68
+	 * @param CustomPostTypeDefinitions $custom_post_types
69
+	 * @param CustomTaxonomyDefinitions $taxonomies
70
+	 */
71
+	protected function __construct(
72
+		CustomPostTypeDefinitions $custom_post_types,
73
+		CustomTaxonomyDefinitions $taxonomies
74
+	) {
75
+		// get CPT data
76
+		$this->_CPTs           = $custom_post_types->getDefinitions();
77
+		$this->_CPT_endpoints  = $this->_set_CPT_endpoints();
78
+		$this->_CPT_taxonomies = $taxonomies->getCustomTaxonomyDefinitions();
79
+		add_action('pre_get_posts', [$this, 'pre_get_posts'], 5);
80
+	}
81
+
82
+
83
+	/**
84
+	 * @return array
85
+	 */
86
+	public function get_CPT_endpoints(): array
87
+	{
88
+		return $this->_CPT_endpoints;
89
+	}
90
+
91
+
92
+	/**
93
+	 * @return array
94
+	 */
95
+	public function get_CPT_taxonomies(): array
96
+	{
97
+		return $this->_CPT_taxonomies;
98
+	}
99
+
100
+
101
+	/**
102
+	 * add CPT "slugs" to array of default espresso "pages"
103
+	 *
104
+	 * @return array
105
+	 */
106
+	private function _set_CPT_endpoints(): array
107
+	{
108
+		$_CPT_endpoints = [];
109
+		foreach ($this->_CPTs as $CPT_type => $CPT) {
110
+			if (isset($CPT['plural_slug'])) {
111
+				$_CPT_endpoints [ (string) $CPT['plural_slug'] ] = $CPT_type;
112
+			}
113
+		}
114
+		return $_CPT_endpoints;
115
+	}
116
+
117
+
118
+	public function wpQueryPostType(?WP_Query $wp_query): string
119
+	{
120
+		if (! $wp_query instanceof WP_Query) {
121
+			return '';
122
+		}
123
+		// cuz WP_Query is a mess and doesn't always have the post_type set in the same place
124
+		$post_type = $wp_query->query->post_type ?? '';
125
+		$post_type = $wp_query->query['post_type'] ?? $post_type;
126
+		$post_type = $wp_query->query_vars['post_type'] ?? $post_type;
127
+		return is_array($post_type) ? (string) reset($post_type) : (string) $post_type;
128
+	}
129
+
130
+
131
+	public function isEspressoPostType(WP_Query $wp_query): bool
132
+	{
133
+		$post_type = $this->wpQueryPostType($wp_query);
134
+		return isset($this->_CPTs[ $post_type ]);
135
+	}
136
+
137
+
138
+	/**
139
+	 * If this query (not just "main" queries (ie, for WP's infamous "loop")) is for an EE CPT, then we want to
140
+	 * supercharge the get_posts query to add our EE stuff (like joining to our tables, selecting extra columns, and
141
+	 * adding EE objects to the post to facilitate further querying of related data etc)
142
+	 *
143
+	 * @param WP_Query $wp_query
144
+	 * @return void
145
+	 * @throws EE_Error
146
+	 * @throws ReflectionException
147
+	 */
148
+	public function pre_get_posts(WP_Query $wp_query)
149
+	{
150
+		// add our conditionals
151
+		$this->_set_EE_tags_on_WP_Query($wp_query);
152
+		// check for terms
153
+		$this->_set_post_type_for_terms($wp_query);
154
+		// make sure paging is always set
155
+		$this->_set_paging($wp_query);
156
+		// is a taxonomy set ?
157
+		$this->_set_CPT_taxonomies_on_WP_Query($wp_query);
158
+		// loop thru post_types if set
159
+		$this->_process_WP_Query_post_types($wp_query);
160
+	}
161
+
162
+
163
+	/**
164
+	 * @param WP_Query $wp_query
165
+	 * @return void
166
+	 */
167
+	private function _set_EE_tags_on_WP_Query(WP_Query $wp_query)
168
+	{
169
+		$wp_query->is_espresso_event_single   = false;
170
+		$wp_query->is_espresso_event_archive  = false;
171
+		$wp_query->is_espresso_event_taxonomy = false;
172
+		$wp_query->is_espresso_venue_single   = false;
173
+		$wp_query->is_espresso_venue_archive  = false;
174
+		$wp_query->is_espresso_venue_taxonomy = false;
175
+	}
176
+
177
+
178
+	/**
179
+	 * @return void
180
+	 * @throws EE_Error
181
+	 * @throws ReflectionException
182
+	 */
183
+	private function _set_CPT_terms()
184
+	{
185
+		if (empty($this->_CPT_terms)) {
186
+			$terms = EEM_Term::instance()->get_all_CPT_post_tags();
187
+			foreach ($terms as $term) {
188
+				if ($term instanceof EE_Term) {
189
+					$this->_CPT_terms[ $term->slug() ] = $term;
190
+				}
191
+			}
192
+		}
193
+	}
194
+
195
+
196
+	/**
197
+	 * @param WP_Query $wp_query
198
+	 * @return void
199
+	 * @throws EE_Error
200
+	 * @throws ReflectionException
201
+	 */
202
+	private function _set_post_type_for_terms(WP_Query $wp_query)
203
+	{
204
+		// is a tag set ?
205
+		if (! isset($wp_query->query['tag'])) {
206
+			return;
207
+		}
208
+		// get term for tag
209
+		$term = EEM_Term::instance()->get_post_tag_for_event_or_venue($wp_query->query['tag']);
210
+		// verify the term
211
+		if (! $term instanceof EE_Term) {
212
+			return;
213
+		}
214
+		// set post_type from term
215
+		$term->post_type = (array) apply_filters(
216
+			'FHEE__EE_CPT_Strategy___set_post_type_for_terms__term_post_type',
217
+			array_merge(['post', 'page'], $term->post_type),
218
+			$term
219
+		);
220
+		// if a post type is already set
221
+		if (isset($wp_query->query_vars['post_type'])) {
222
+			// add to existing array
223
+			$term->post_type = array_merge((array) $wp_query->query_vars['post_type'], $term->post_type);
224
+		}
225
+		// just set post_type to our CPT
226
+		$wp_query->set('post_type', array_unique($term->post_type));
227
+	}
228
+
229
+
230
+	/**
231
+	 * @param WP_Query $wp_query
232
+	 * @return void
233
+	 */
234
+	public function _set_paging(WP_Query $wp_query)
235
+	{
236
+		if ($wp_query->is_main_query() && apply_filters('FHEE__EE_CPT_Strategy___set_paging', true)) {
237
+			$page  = get_query_var('page') ? get_query_var('page') : null;
238
+			$paged = get_query_var('paged') ? get_query_var('paged') : $page;
239
+			$wp_query->set('paged', $paged);
240
+		}
241
+	}
242
+
243
+
244
+	/**
245
+	 * @param WP_Query $wp_query
246
+	 */
247
+	protected function _set_CPT_taxonomies_on_WP_Query(WP_Query $wp_query)
248
+	{
249
+		// is a taxonomy set ?
250
+		if (! $wp_query->is_tax) {
251
+			return;
252
+		}
253
+		// loop thru our taxonomies
254
+		foreach ($this->_CPT_taxonomies as $CPT_taxonomy => $CPT_taxonomy_details) {
255
+			// check if one of our taxonomies is set as a query var
256
+			if (! isset($wp_query->query[ $CPT_taxonomy ])) {
257
+				continue;
258
+			}
259
+			// but which CPT does that correspond to??? hmmm... guess we gotta go looping
260
+			foreach ($this->_CPTs as $post_type => $CPT) {
261
+				// verify our CPT has args, is public and has taxonomies set
262
+				if (
263
+					! isset($CPT['args']['public'])
264
+					|| ! $CPT['args']['public']
265
+					|| empty($CPT['args']['taxonomies'])
266
+					|| ! in_array($CPT_taxonomy, $CPT['args']['taxonomies'], true)
267
+				) {
268
+					continue;
269
+				}
270
+				// if so, then add this CPT post_type to the current query's array of post_types'
271
+				$wp_query->query_vars['post_type']   = isset($wp_query->query_vars['post_type'])
272
+					? (array) $wp_query->query_vars['post_type']
273
+					: [];
274
+				$wp_query->query_vars['post_type'][] = $post_type;
275
+				switch ($post_type) {
276
+					case EspressoPostType::EVENTS:
277
+						$wp_query->is_espresso_event_taxonomy = true;
278
+						break;
279
+
280
+					case EspressoPostType::VENUES:
281
+						$wp_query->is_espresso_venue_taxonomy = true;
282
+						break;
283
+
284
+					default:
285
+						do_action(
286
+							'AHEE__EE_CPT_Strategy___set_CPT_taxonomies_on_WP_Query__for_' . $post_type . '_post_type',
287
+							$wp_query,
288
+							$this
289
+						);
290
+				}
291
+			}
292
+		}
293
+	}
294
+
295
+
296
+	/**
297
+	 * @param WP_Query $wp_query
298
+	 */
299
+	protected function _process_WP_Query_post_types(WP_Query $wp_query)
300
+	{
301
+		if (! isset($wp_query->query_vars['post_type'])) {
302
+			return;
303
+		}
304
+		// loop thru post_types as array
305
+		foreach ((array) $wp_query->query_vars['post_type'] as $post_type) {
306
+			// is current query for an EE CPT ?
307
+			if (! isset($this->_CPTs[ $post_type ])) {
308
+				continue;
309
+			}
310
+			// is EE on or off ?
311
+			if (MaintenanceStatus::isNotDisabled()) {
312
+				// reroute CPT template view to maintenance_mode.template.php
313
+				if (! has_filter('template_include', ['EE_Maintenance_Mode', 'template_include'])) {
314
+					add_filter('template_include', ['EE_Maintenance_Mode', 'template_include'], 99999);
315
+				}
316
+				if (has_filter('the_content', [EE_Maintenance_Mode::instance(), 'the_content'])) {
317
+					add_filter('the_content', [$this, 'inject_EE_shortcode_placeholder'], 1);
318
+				}
319
+				return;
320
+			}
321
+			$this->_generate_CptQueryModifier($wp_query, $post_type);
322
+		}
323
+	}
324
+
325
+
326
+	/**
327
+	 * @param WP_Query $wp_query
328
+	 * @param string   $post_type
329
+	 */
330
+	protected function _generate_CptQueryModifier(WP_Query $wp_query, string $post_type)
331
+	{
332
+		if (
333
+			isset($this->query_modifier[ $post_type ])
334
+			&& $this->query_modifier[ $post_type ] instanceof CptQueryModifier
335
+		) {
336
+			return;
337
+		}
338
+		$this->query_modifier[ $post_type ] = LoaderFactory::getLoader()->getShared(
339
+			CptQueryModifier::class,
340
+			[
341
+				$post_type,
342
+				$this->_CPTs[ $post_type ],
343
+				$wp_query,
344
+			]
345
+		);
346
+		$this->_CPT_taxonomies              = $this->query_modifier[ $post_type ]->taxonomies();
347
+	}
348
+
349
+
350
+	/**
351
+	 * inject_EE_shortcode_placeholder
352
+	 * in order to display the M-Mode notice on our CPT routes,
353
+	 * we need to first inject what looks like one of our shortcodes,
354
+	 * so that it can be replaced with the actual M-Mode notice
355
+	 *
356
+	 * @return string
357
+	 */
358
+	public function inject_EE_shortcode_placeholder(): string
359
+	{
360
+		return '[ESPRESSO_';
361
+	}
362 362
 }
Please login to merge, or discard this patch.
Spacing   +17 added lines, -17 removed lines patch added patch discarded remove patch
@@ -108,7 +108,7 @@  discard block
 block discarded – undo
108 108
         $_CPT_endpoints = [];
109 109
         foreach ($this->_CPTs as $CPT_type => $CPT) {
110 110
             if (isset($CPT['plural_slug'])) {
111
-                $_CPT_endpoints [ (string) $CPT['plural_slug'] ] = $CPT_type;
111
+                $_CPT_endpoints [(string) $CPT['plural_slug']] = $CPT_type;
112 112
             }
113 113
         }
114 114
         return $_CPT_endpoints;
@@ -117,7 +117,7 @@  discard block
 block discarded – undo
117 117
 
118 118
     public function wpQueryPostType(?WP_Query $wp_query): string
119 119
     {
120
-        if (! $wp_query instanceof WP_Query) {
120
+        if ( ! $wp_query instanceof WP_Query) {
121 121
             return '';
122 122
         }
123 123
         // cuz WP_Query is a mess and doesn't always have the post_type set in the same place
@@ -131,7 +131,7 @@  discard block
 block discarded – undo
131 131
     public function isEspressoPostType(WP_Query $wp_query): bool
132 132
     {
133 133
         $post_type = $this->wpQueryPostType($wp_query);
134
-        return isset($this->_CPTs[ $post_type ]);
134
+        return isset($this->_CPTs[$post_type]);
135 135
     }
136 136
 
137 137
 
@@ -186,7 +186,7 @@  discard block
 block discarded – undo
186 186
             $terms = EEM_Term::instance()->get_all_CPT_post_tags();
187 187
             foreach ($terms as $term) {
188 188
                 if ($term instanceof EE_Term) {
189
-                    $this->_CPT_terms[ $term->slug() ] = $term;
189
+                    $this->_CPT_terms[$term->slug()] = $term;
190 190
                 }
191 191
             }
192 192
         }
@@ -202,13 +202,13 @@  discard block
 block discarded – undo
202 202
     private function _set_post_type_for_terms(WP_Query $wp_query)
203 203
     {
204 204
         // is a tag set ?
205
-        if (! isset($wp_query->query['tag'])) {
205
+        if ( ! isset($wp_query->query['tag'])) {
206 206
             return;
207 207
         }
208 208
         // get term for tag
209 209
         $term = EEM_Term::instance()->get_post_tag_for_event_or_venue($wp_query->query['tag']);
210 210
         // verify the term
211
-        if (! $term instanceof EE_Term) {
211
+        if ( ! $term instanceof EE_Term) {
212 212
             return;
213 213
         }
214 214
         // set post_type from term
@@ -247,13 +247,13 @@  discard block
 block discarded – undo
247 247
     protected function _set_CPT_taxonomies_on_WP_Query(WP_Query $wp_query)
248 248
     {
249 249
         // is a taxonomy set ?
250
-        if (! $wp_query->is_tax) {
250
+        if ( ! $wp_query->is_tax) {
251 251
             return;
252 252
         }
253 253
         // loop thru our taxonomies
254 254
         foreach ($this->_CPT_taxonomies as $CPT_taxonomy => $CPT_taxonomy_details) {
255 255
             // check if one of our taxonomies is set as a query var
256
-            if (! isset($wp_query->query[ $CPT_taxonomy ])) {
256
+            if ( ! isset($wp_query->query[$CPT_taxonomy])) {
257 257
                 continue;
258 258
             }
259 259
             // but which CPT does that correspond to??? hmmm... guess we gotta go looping
@@ -283,7 +283,7 @@  discard block
 block discarded – undo
283 283
 
284 284
                     default:
285 285
                         do_action(
286
-                            'AHEE__EE_CPT_Strategy___set_CPT_taxonomies_on_WP_Query__for_' . $post_type . '_post_type',
286
+                            'AHEE__EE_CPT_Strategy___set_CPT_taxonomies_on_WP_Query__for_'.$post_type.'_post_type',
287 287
                             $wp_query,
288 288
                             $this
289 289
                         );
@@ -298,19 +298,19 @@  discard block
 block discarded – undo
298 298
      */
299 299
     protected function _process_WP_Query_post_types(WP_Query $wp_query)
300 300
     {
301
-        if (! isset($wp_query->query_vars['post_type'])) {
301
+        if ( ! isset($wp_query->query_vars['post_type'])) {
302 302
             return;
303 303
         }
304 304
         // loop thru post_types as array
305 305
         foreach ((array) $wp_query->query_vars['post_type'] as $post_type) {
306 306
             // is current query for an EE CPT ?
307
-            if (! isset($this->_CPTs[ $post_type ])) {
307
+            if ( ! isset($this->_CPTs[$post_type])) {
308 308
                 continue;
309 309
             }
310 310
             // is EE on or off ?
311 311
             if (MaintenanceStatus::isNotDisabled()) {
312 312
                 // reroute CPT template view to maintenance_mode.template.php
313
-                if (! has_filter('template_include', ['EE_Maintenance_Mode', 'template_include'])) {
313
+                if ( ! has_filter('template_include', ['EE_Maintenance_Mode', 'template_include'])) {
314 314
                     add_filter('template_include', ['EE_Maintenance_Mode', 'template_include'], 99999);
315 315
                 }
316 316
                 if (has_filter('the_content', [EE_Maintenance_Mode::instance(), 'the_content'])) {
@@ -330,20 +330,20 @@  discard block
 block discarded – undo
330 330
     protected function _generate_CptQueryModifier(WP_Query $wp_query, string $post_type)
331 331
     {
332 332
         if (
333
-            isset($this->query_modifier[ $post_type ])
334
-            && $this->query_modifier[ $post_type ] instanceof CptQueryModifier
333
+            isset($this->query_modifier[$post_type])
334
+            && $this->query_modifier[$post_type] instanceof CptQueryModifier
335 335
         ) {
336 336
             return;
337 337
         }
338
-        $this->query_modifier[ $post_type ] = LoaderFactory::getLoader()->getShared(
338
+        $this->query_modifier[$post_type] = LoaderFactory::getLoader()->getShared(
339 339
             CptQueryModifier::class,
340 340
             [
341 341
                 $post_type,
342
-                $this->_CPTs[ $post_type ],
342
+                $this->_CPTs[$post_type],
343 343
                 $wp_query,
344 344
             ]
345 345
         );
346
-        $this->_CPT_taxonomies              = $this->query_modifier[ $post_type ]->taxonomies();
346
+        $this->_CPT_taxonomies = $this->query_modifier[$post_type]->taxonomies();
347 347
     }
348 348
 
349 349
 
Please login to merge, or discard this patch.
core/EE_Cron_Tasks.core.php 1 patch
Indentation   +581 added lines, -581 removed lines patch added patch discarded remove patch
@@ -15,588 +15,588 @@
 block discarded – undo
15 15
  */
16 16
 class EE_Cron_Tasks extends EE_Base
17 17
 {
18
-    /**
19
-     * WordPress doesn't allow duplicate crons within 10 minutes of the original,
20
-     * so we'll set our retry time for just over 10 minutes to avoid that
21
-     */
22
-    const reschedule_timeout = 605;
23
-
24
-
25
-    private static ?EE_Cron_Tasks $_instance = null;
26
-
27
-
28
-    public static function instance(): ?EE_Cron_Tasks
29
-    {
30
-        if (! self::$_instance instanceof EE_Cron_Tasks) {
31
-            self::$_instance = new self();
32
-        }
33
-        return self::$_instance;
34
-    }
35
-
36
-
37
-    /**
38
-     * @throws InvalidDataTypeException
39
-     * @throws InvalidInterfaceException
40
-     * @throws InvalidArgumentException
41
-     * @throws EE_Error
42
-     * @throws ReflectionException
43
-     */
44
-    private function __construct()
45
-    {
46
-        do_action('AHEE_log', __CLASS__, __FUNCTION__);
47
-        // verify that WP Cron is enabled
48
-        if (
49
-            defined('DISABLE_WP_CRON')
50
-            && DISABLE_WP_CRON
51
-            && is_admin()
52
-            && ! get_option('ee_disabled_wp_cron_check')
53
-        ) {
54
-            /**
55
-             * This needs to be delayed until after the config is loaded because EE_Cron_Tasks is constructed before
56
-             * config is loaded.
57
-             * This is intentionally using a anonymous function so that its not easily de-registered.  Client code
58
-             * wanting to not have this functionality can just register its own action at a priority after this one to
59
-             * reverse any changes.
60
-             */
61
-            add_action(
62
-                'AHEE__EE_System__load_core_configuration__complete',
63
-                function () {
64
-                    EE_Registry::instance()->NET_CFG->core->do_messages_on_same_request = true;
65
-                    EE_Registry::instance()->NET_CFG->update_config(true, false);
66
-                    add_option('ee_disabled_wp_cron_check', 1, '', false);
67
-                }
68
-            );
69
-        }
70
-        // UPDATE TRANSACTION WITH PAYMENT
71
-        add_action(
72
-            'AHEE__EE_Cron_Tasks__update_transaction_with_payment_2',
73
-            array('EE_Cron_Tasks', 'setup_update_for_transaction_with_payment'),
74
-            10,
75
-            2
76
-        );
77
-        // ABANDONED / EXPIRED TRANSACTION CHECK
78
-        add_action(
79
-            'AHEE__EE_Cron_Tasks__expired_transaction_check',
80
-            array('EE_Cron_Tasks', 'expired_transaction_check')
81
-        );
82
-        // CLEAN OUT JUNK TRANSACTIONS AND RELATED DATA
83
-        add_action(
84
-            'AHEE__EE_Cron_Tasks__clean_up_junk_transactions',
85
-            array('EE_Cron_Tasks', 'clean_out_junk_transactions')
86
-        );
87
-        // logging
88
-        add_action(
89
-            'AHEE__EE_System__load_core_configuration__complete',
90
-            array('EE_Cron_Tasks', 'log_scheduled_ee_crons')
91
-        );
92
-        EE_Registry::instance()->load_lib('Messages_Scheduler');
93
-        // clean out old gateway logs
94
-        add_action(
95
-            'AHEE_EE_Cron_Tasks__clean_out_old_gateway_logs',
96
-            array('EE_Cron_Tasks', 'clean_out_old_gateway_logs')
97
-        );
98
-    }
99
-
100
-    public static function log_scheduled_ee_crons(): void
101
-    {
102
-        $ee_crons = array(
103
-            'AHEE__EE_Cron_Tasks__update_transaction_with_payment',
104
-            'AHEE__EE_Cron_Tasks__finalize_abandoned_transactions',
105
-            'AHEE__EE_Cron_Tasks__clean_up_junk_transactions',
106
-        );
107
-        $crons = (array) get_option('cron');
108
-        foreach ($crons as $cron) {
109
-            /** @var array[] $cron */
110
-            foreach ($ee_crons as $ee_cron) {
111
-                if (isset($cron[ $ee_cron ]) && is_array($cron[ $ee_cron ])) {
112
-                    do_action('AHEE_log', __CLASS__, __FUNCTION__, $ee_cron, 'scheduled EE cron');
113
-                    foreach ($cron[ $ee_cron ] as $ee_cron_details) {
114
-                        if (! empty($ee_cron_details['args'])) {
115
-                            do_action(
116
-                                'AHEE_log',
117
-                                __CLASS__,
118
-                                __FUNCTION__,
119
-                                print_r($ee_cron_details['args'], true),
120
-                                "$ee_cron args"
121
-                            );
122
-                        }
123
-                    }
124
-                }
125
-            }
126
-        }
127
-    }
128
-
129
-
130
-    /**
131
-     * reschedule_cron_for_transactions_if_maintenance_mode
132
-     * if Maintenance Mode is active, this will reschedule a cron to run again in 10 minutes
133
-     *
134
-     * @param string $cron_task
135
-     * @param array  $TXN_IDs
136
-     * @return bool
137
-     * @throws DomainException
138
-     */
139
-    public static function reschedule_cron_for_transactions_if_maintenance_mode(string $cron_task, array $TXN_IDs): bool
140
-    {
141
-        if (! method_exists('EE_Cron_Tasks', $cron_task)) {
142
-            throw new DomainException(
143
-                sprintf(
144
-                    esc_html__('"%1$s" is not valid method on EE_Cron_Tasks.', 'event_espresso'),
145
-                    $cron_task
146
-                )
147
-            );
148
-        }
149
-        // reschedule the cron if we can't hit the db right now
150
-        if (DbStatus::isOffline()) {
151
-            foreach ($TXN_IDs as $TXN_ID => $additional_vars) {
152
-                // ensure $additional_vars is an array
153
-                $additional_vars = is_array($additional_vars) ? $additional_vars : array($additional_vars);
154
-                // reset cron job for the TXN
155
-                call_user_func_array(
156
-                    array('EE_Cron_Tasks', $cron_task),
157
-                    array_merge(
158
-                        array(
159
-                            time() + (10 * MINUTE_IN_SECONDS),
160
-                            $TXN_ID,
161
-                        ),
162
-                        $additional_vars
163
-                    )
164
-                );
165
-            }
166
-            return true;
167
-        }
168
-        return false;
169
-    }
170
-
171
-
172
-
173
-
174
-    /****************  UPDATE TRANSACTION WITH PAYMENT ****************/
175
-
176
-
177
-    /**
178
-     * array of TXN IDs and the payment
179
-     *
180
-     * @var array
181
-     */
182
-    protected static array $_update_transactions_with_payment = array();
183
-
184
-
185
-    /**
186
-     * schedule_update_transaction_with_payment
187
-     * sets a wp_schedule_single_event() for updating any TXNs that may
188
-     * require updating due to recently received payments
189
-     *
190
-     * @param int $timestamp
191
-     * @param int $TXN_ID
192
-     * @param int $PAY_ID
193
-     */
194
-    public static function schedule_update_transaction_with_payment(
195
-        int $timestamp,
196
-        int $TXN_ID,
197
-        int $PAY_ID
198
-    ): void {
199
-        do_action('AHEE_log', __CLASS__, __FUNCTION__);
200
-        // validate $TXN_ID and $timestamp
201
-        $TXN_ID = absint($TXN_ID);
202
-        $timestamp = absint($timestamp);
203
-        if ($TXN_ID && $timestamp) {
204
-            wp_schedule_single_event(
205
-                $timestamp,
206
-                'AHEE__EE_Cron_Tasks__update_transaction_with_payment_2',
207
-                array($TXN_ID, $PAY_ID)
208
-            );
209
-        }
210
-    }
211
-
212
-
213
-    /**
214
-     * setup_update_for_transaction_with_payment
215
-     * this is the callback for the action hook:
216
-     * 'AHEE__EE_Cron_Tasks__update_transaction_with_payment'
217
-     * which is setup by EE_Cron_Tasks::schedule_update_transaction_with_payment().
218
-     * The passed TXN_ID and associated payment gets added to an array, and then
219
-     * the EE_Cron_Tasks::update_transaction_with_payment() function is hooked into
220
-     * 'shutdown' which will actually handle the processing of any
221
-     * transactions requiring updating, because doing so now would be too early
222
-     * and the required resources may not be available
223
-     *
224
-     * @param int $TXN_ID
225
-     * @param int $PAY_ID
226
-     */
227
-    public static function setup_update_for_transaction_with_payment(int $TXN_ID = 0, int $PAY_ID = 0): void
228
-    {
229
-        do_action('AHEE_log', __CLASS__, __FUNCTION__, $TXN_ID, '$TXN_ID');
230
-        if (absint($TXN_ID)) {
231
-            self::$_update_transactions_with_payment[ $TXN_ID ] = $PAY_ID;
232
-            add_action(
233
-                'shutdown',
234
-                array('EE_Cron_Tasks', 'update_transaction_with_payment'),
235
-                5
236
-            );
237
-        }
238
-    }
239
-
240
-
241
-    /**
242
-     * update_transaction_with_payment
243
-     * loops through the self::$_abandoned_transactions array
244
-     * and attempts to finalize any TXNs that have not been completed
245
-     * but have had their sessions expired, most likely due to a user not
246
-     * returning from an off-site payment gateway
247
-     *
248
-     * @throws EE_Error
249
-     * @throws DomainException
250
-     * @throws InvalidDataTypeException
251
-     * @throws InvalidInterfaceException
252
-     * @throws InvalidArgumentException
253
-     * @throws ReflectionException
254
-     * @throws RuntimeException
255
-     */
256
-    public static function update_transaction_with_payment(): void
257
-    {
258
-        do_action('AHEE_log', __CLASS__, __FUNCTION__);
259
-        if (
18
+	/**
19
+	 * WordPress doesn't allow duplicate crons within 10 minutes of the original,
20
+	 * so we'll set our retry time for just over 10 minutes to avoid that
21
+	 */
22
+	const reschedule_timeout = 605;
23
+
24
+
25
+	private static ?EE_Cron_Tasks $_instance = null;
26
+
27
+
28
+	public static function instance(): ?EE_Cron_Tasks
29
+	{
30
+		if (! self::$_instance instanceof EE_Cron_Tasks) {
31
+			self::$_instance = new self();
32
+		}
33
+		return self::$_instance;
34
+	}
35
+
36
+
37
+	/**
38
+	 * @throws InvalidDataTypeException
39
+	 * @throws InvalidInterfaceException
40
+	 * @throws InvalidArgumentException
41
+	 * @throws EE_Error
42
+	 * @throws ReflectionException
43
+	 */
44
+	private function __construct()
45
+	{
46
+		do_action('AHEE_log', __CLASS__, __FUNCTION__);
47
+		// verify that WP Cron is enabled
48
+		if (
49
+			defined('DISABLE_WP_CRON')
50
+			&& DISABLE_WP_CRON
51
+			&& is_admin()
52
+			&& ! get_option('ee_disabled_wp_cron_check')
53
+		) {
54
+			/**
55
+			 * This needs to be delayed until after the config is loaded because EE_Cron_Tasks is constructed before
56
+			 * config is loaded.
57
+			 * This is intentionally using a anonymous function so that its not easily de-registered.  Client code
58
+			 * wanting to not have this functionality can just register its own action at a priority after this one to
59
+			 * reverse any changes.
60
+			 */
61
+			add_action(
62
+				'AHEE__EE_System__load_core_configuration__complete',
63
+				function () {
64
+					EE_Registry::instance()->NET_CFG->core->do_messages_on_same_request = true;
65
+					EE_Registry::instance()->NET_CFG->update_config(true, false);
66
+					add_option('ee_disabled_wp_cron_check', 1, '', false);
67
+				}
68
+			);
69
+		}
70
+		// UPDATE TRANSACTION WITH PAYMENT
71
+		add_action(
72
+			'AHEE__EE_Cron_Tasks__update_transaction_with_payment_2',
73
+			array('EE_Cron_Tasks', 'setup_update_for_transaction_with_payment'),
74
+			10,
75
+			2
76
+		);
77
+		// ABANDONED / EXPIRED TRANSACTION CHECK
78
+		add_action(
79
+			'AHEE__EE_Cron_Tasks__expired_transaction_check',
80
+			array('EE_Cron_Tasks', 'expired_transaction_check')
81
+		);
82
+		// CLEAN OUT JUNK TRANSACTIONS AND RELATED DATA
83
+		add_action(
84
+			'AHEE__EE_Cron_Tasks__clean_up_junk_transactions',
85
+			array('EE_Cron_Tasks', 'clean_out_junk_transactions')
86
+		);
87
+		// logging
88
+		add_action(
89
+			'AHEE__EE_System__load_core_configuration__complete',
90
+			array('EE_Cron_Tasks', 'log_scheduled_ee_crons')
91
+		);
92
+		EE_Registry::instance()->load_lib('Messages_Scheduler');
93
+		// clean out old gateway logs
94
+		add_action(
95
+			'AHEE_EE_Cron_Tasks__clean_out_old_gateway_logs',
96
+			array('EE_Cron_Tasks', 'clean_out_old_gateway_logs')
97
+		);
98
+	}
99
+
100
+	public static function log_scheduled_ee_crons(): void
101
+	{
102
+		$ee_crons = array(
103
+			'AHEE__EE_Cron_Tasks__update_transaction_with_payment',
104
+			'AHEE__EE_Cron_Tasks__finalize_abandoned_transactions',
105
+			'AHEE__EE_Cron_Tasks__clean_up_junk_transactions',
106
+		);
107
+		$crons = (array) get_option('cron');
108
+		foreach ($crons as $cron) {
109
+			/** @var array[] $cron */
110
+			foreach ($ee_crons as $ee_cron) {
111
+				if (isset($cron[ $ee_cron ]) && is_array($cron[ $ee_cron ])) {
112
+					do_action('AHEE_log', __CLASS__, __FUNCTION__, $ee_cron, 'scheduled EE cron');
113
+					foreach ($cron[ $ee_cron ] as $ee_cron_details) {
114
+						if (! empty($ee_cron_details['args'])) {
115
+							do_action(
116
+								'AHEE_log',
117
+								__CLASS__,
118
+								__FUNCTION__,
119
+								print_r($ee_cron_details['args'], true),
120
+								"$ee_cron args"
121
+							);
122
+						}
123
+					}
124
+				}
125
+			}
126
+		}
127
+	}
128
+
129
+
130
+	/**
131
+	 * reschedule_cron_for_transactions_if_maintenance_mode
132
+	 * if Maintenance Mode is active, this will reschedule a cron to run again in 10 minutes
133
+	 *
134
+	 * @param string $cron_task
135
+	 * @param array  $TXN_IDs
136
+	 * @return bool
137
+	 * @throws DomainException
138
+	 */
139
+	public static function reschedule_cron_for_transactions_if_maintenance_mode(string $cron_task, array $TXN_IDs): bool
140
+	{
141
+		if (! method_exists('EE_Cron_Tasks', $cron_task)) {
142
+			throw new DomainException(
143
+				sprintf(
144
+					esc_html__('"%1$s" is not valid method on EE_Cron_Tasks.', 'event_espresso'),
145
+					$cron_task
146
+				)
147
+			);
148
+		}
149
+		// reschedule the cron if we can't hit the db right now
150
+		if (DbStatus::isOffline()) {
151
+			foreach ($TXN_IDs as $TXN_ID => $additional_vars) {
152
+				// ensure $additional_vars is an array
153
+				$additional_vars = is_array($additional_vars) ? $additional_vars : array($additional_vars);
154
+				// reset cron job for the TXN
155
+				call_user_func_array(
156
+					array('EE_Cron_Tasks', $cron_task),
157
+					array_merge(
158
+						array(
159
+							time() + (10 * MINUTE_IN_SECONDS),
160
+							$TXN_ID,
161
+						),
162
+						$additional_vars
163
+					)
164
+				);
165
+			}
166
+			return true;
167
+		}
168
+		return false;
169
+	}
170
+
171
+
172
+
173
+
174
+	/****************  UPDATE TRANSACTION WITH PAYMENT ****************/
175
+
176
+
177
+	/**
178
+	 * array of TXN IDs and the payment
179
+	 *
180
+	 * @var array
181
+	 */
182
+	protected static array $_update_transactions_with_payment = array();
183
+
184
+
185
+	/**
186
+	 * schedule_update_transaction_with_payment
187
+	 * sets a wp_schedule_single_event() for updating any TXNs that may
188
+	 * require updating due to recently received payments
189
+	 *
190
+	 * @param int $timestamp
191
+	 * @param int $TXN_ID
192
+	 * @param int $PAY_ID
193
+	 */
194
+	public static function schedule_update_transaction_with_payment(
195
+		int $timestamp,
196
+		int $TXN_ID,
197
+		int $PAY_ID
198
+	): void {
199
+		do_action('AHEE_log', __CLASS__, __FUNCTION__);
200
+		// validate $TXN_ID and $timestamp
201
+		$TXN_ID = absint($TXN_ID);
202
+		$timestamp = absint($timestamp);
203
+		if ($TXN_ID && $timestamp) {
204
+			wp_schedule_single_event(
205
+				$timestamp,
206
+				'AHEE__EE_Cron_Tasks__update_transaction_with_payment_2',
207
+				array($TXN_ID, $PAY_ID)
208
+			);
209
+		}
210
+	}
211
+
212
+
213
+	/**
214
+	 * setup_update_for_transaction_with_payment
215
+	 * this is the callback for the action hook:
216
+	 * 'AHEE__EE_Cron_Tasks__update_transaction_with_payment'
217
+	 * which is setup by EE_Cron_Tasks::schedule_update_transaction_with_payment().
218
+	 * The passed TXN_ID and associated payment gets added to an array, and then
219
+	 * the EE_Cron_Tasks::update_transaction_with_payment() function is hooked into
220
+	 * 'shutdown' which will actually handle the processing of any
221
+	 * transactions requiring updating, because doing so now would be too early
222
+	 * and the required resources may not be available
223
+	 *
224
+	 * @param int $TXN_ID
225
+	 * @param int $PAY_ID
226
+	 */
227
+	public static function setup_update_for_transaction_with_payment(int $TXN_ID = 0, int $PAY_ID = 0): void
228
+	{
229
+		do_action('AHEE_log', __CLASS__, __FUNCTION__, $TXN_ID, '$TXN_ID');
230
+		if (absint($TXN_ID)) {
231
+			self::$_update_transactions_with_payment[ $TXN_ID ] = $PAY_ID;
232
+			add_action(
233
+				'shutdown',
234
+				array('EE_Cron_Tasks', 'update_transaction_with_payment'),
235
+				5
236
+			);
237
+		}
238
+	}
239
+
240
+
241
+	/**
242
+	 * update_transaction_with_payment
243
+	 * loops through the self::$_abandoned_transactions array
244
+	 * and attempts to finalize any TXNs that have not been completed
245
+	 * but have had their sessions expired, most likely due to a user not
246
+	 * returning from an off-site payment gateway
247
+	 *
248
+	 * @throws EE_Error
249
+	 * @throws DomainException
250
+	 * @throws InvalidDataTypeException
251
+	 * @throws InvalidInterfaceException
252
+	 * @throws InvalidArgumentException
253
+	 * @throws ReflectionException
254
+	 * @throws RuntimeException
255
+	 */
256
+	public static function update_transaction_with_payment(): void
257
+	{
258
+		do_action('AHEE_log', __CLASS__, __FUNCTION__);
259
+		if (
260 260
 // are there any TXNs that need cleaning up ?
261
-            empty(self::$_update_transactions_with_payment)
262
-            // reschedule the cron if we can't hit the db right now
263
-            || EE_Cron_Tasks::reschedule_cron_for_transactions_if_maintenance_mode(
264
-                'schedule_update_transaction_with_payment',
265
-                self::$_update_transactions_with_payment
266
-            )
267
-        ) {
268
-            return;
269
-        }
270
-        /** @type EE_Payment_Processor $payment_processor */
271
-        $payment_processor = EE_Registry::instance()->load_core('Payment_Processor');
272
-        // set revisit flag for payment processor
273
-        $payment_processor->set_revisit();
274
-        // load EEM_Transaction
275
-        EE_Registry::instance()->load_model('Transaction');
276
-        foreach (self::$_update_transactions_with_payment as $TXN_ID => $PAY_ID) {
277
-            // reschedule the cron if we can't hit the db right now
278
-            if (DbStatus::isOffline()) {
279
-                // reset cron job for updating the TXN
280
-                EE_Cron_Tasks::schedule_update_transaction_with_payment(
281
-                    time() + EE_Cron_Tasks::reschedule_timeout,
282
-                    $TXN_ID,
283
-                    $PAY_ID
284
-                );
285
-                continue;
286
-            }
287
-            $transaction = EEM_Transaction::instance()->get_one_by_ID($TXN_ID);
288
-            $payment = EEM_Payment::instance()->get_one_by_ID($PAY_ID);
289
-            // verify transaction
290
-            if ($transaction instanceof EE_Transaction && $payment instanceof EE_Payment) {
291
-                // now try to update the TXN with any payments
292
-                $payment_processor->update_txn_based_on_payment($transaction, $payment, true, true);
293
-            }
294
-            unset(self::$_update_transactions_with_payment[ $TXN_ID ]);
295
-        }
296
-    }
297
-
298
-
299
-
300
-    /************  END OF UPDATE TRANSACTION WITH PAYMENT  ************/
301
-
302
-
303
-    /*****************  EXPIRED TRANSACTION CHECK *****************/
304
-
305
-
306
-    /**
307
-     * array of TXN IDs
308
-     *
309
-     * @var array
310
-     */
311
-    protected static array $_expired_transactions = array();
312
-
313
-
314
-    /**
315
-     * schedule_expired_transaction_check
316
-     * sets a wp_schedule_single_event() for following up on TXNs after their session has expired
317
-     *
318
-     * @param int $timestamp
319
-     * @param int $TXN_ID
320
-     */
321
-    public static function schedule_expired_transaction_check(
322
-        int $timestamp,
323
-        int $TXN_ID
324
-    ): void {
325
-        // validate $TXN_ID and $timestamp
326
-        $TXN_ID = absint($TXN_ID);
327
-        $timestamp = absint($timestamp);
328
-        if ($TXN_ID && $timestamp) {
329
-            wp_schedule_single_event(
330
-                $timestamp,
331
-                'AHEE__EE_Cron_Tasks__expired_transaction_check',
332
-                array($TXN_ID)
333
-            );
334
-        }
335
-    }
336
-
337
-
338
-    /**
339
-     * expired_transaction_check
340
-     * this is the callback for the action hook:
341
-     * 'AHEE__EE_Cron_Tasks__transaction_session_expiration_check'
342
-     * which is utilized by wp_schedule_single_event()
343
-     * in \EED_Single_Page_Checkout::_initialize_transaction().
344
-     * The passed TXN_ID gets added to an array, and then the
345
-     * process_expired_transactions() function is hooked into
346
-     * 'AHEE__EE_System__core_loaded_and_ready' which will actually handle the
347
-     * processing of any failed transactions, because doing so now would be
348
-     * too early and the required resources may not be available
349
-     *
350
-     * @param int $TXN_ID
351
-     */
352
-    public static function expired_transaction_check(int $TXN_ID = 0): void
353
-    {
354
-        if (absint($TXN_ID)) {
355
-            self::$_expired_transactions[ $TXN_ID ] = $TXN_ID;
356
-            add_action(
357
-                'shutdown',
358
-                array('EE_Cron_Tasks', 'process_expired_transactions'),
359
-                5
360
-            );
361
-        }
362
-    }
363
-
364
-
365
-    /**
366
-     * process_expired_transactions
367
-     * loops through the self::$_expired_transactions array and processes any failed TXNs
368
-     *
369
-     * @throws EE_Error
370
-     * @throws InvalidDataTypeException
371
-     * @throws InvalidInterfaceException
372
-     * @throws InvalidArgumentException
373
-     * @throws ReflectionException
374
-     * @throws DomainException
375
-     * @throws RuntimeException
376
-     */
377
-    public static function process_expired_transactions(): void
378
-    {
379
-        if (
261
+			empty(self::$_update_transactions_with_payment)
262
+			// reschedule the cron if we can't hit the db right now
263
+			|| EE_Cron_Tasks::reschedule_cron_for_transactions_if_maintenance_mode(
264
+				'schedule_update_transaction_with_payment',
265
+				self::$_update_transactions_with_payment
266
+			)
267
+		) {
268
+			return;
269
+		}
270
+		/** @type EE_Payment_Processor $payment_processor */
271
+		$payment_processor = EE_Registry::instance()->load_core('Payment_Processor');
272
+		// set revisit flag for payment processor
273
+		$payment_processor->set_revisit();
274
+		// load EEM_Transaction
275
+		EE_Registry::instance()->load_model('Transaction');
276
+		foreach (self::$_update_transactions_with_payment as $TXN_ID => $PAY_ID) {
277
+			// reschedule the cron if we can't hit the db right now
278
+			if (DbStatus::isOffline()) {
279
+				// reset cron job for updating the TXN
280
+				EE_Cron_Tasks::schedule_update_transaction_with_payment(
281
+					time() + EE_Cron_Tasks::reschedule_timeout,
282
+					$TXN_ID,
283
+					$PAY_ID
284
+				);
285
+				continue;
286
+			}
287
+			$transaction = EEM_Transaction::instance()->get_one_by_ID($TXN_ID);
288
+			$payment = EEM_Payment::instance()->get_one_by_ID($PAY_ID);
289
+			// verify transaction
290
+			if ($transaction instanceof EE_Transaction && $payment instanceof EE_Payment) {
291
+				// now try to update the TXN with any payments
292
+				$payment_processor->update_txn_based_on_payment($transaction, $payment, true, true);
293
+			}
294
+			unset(self::$_update_transactions_with_payment[ $TXN_ID ]);
295
+		}
296
+	}
297
+
298
+
299
+
300
+	/************  END OF UPDATE TRANSACTION WITH PAYMENT  ************/
301
+
302
+
303
+	/*****************  EXPIRED TRANSACTION CHECK *****************/
304
+
305
+
306
+	/**
307
+	 * array of TXN IDs
308
+	 *
309
+	 * @var array
310
+	 */
311
+	protected static array $_expired_transactions = array();
312
+
313
+
314
+	/**
315
+	 * schedule_expired_transaction_check
316
+	 * sets a wp_schedule_single_event() for following up on TXNs after their session has expired
317
+	 *
318
+	 * @param int $timestamp
319
+	 * @param int $TXN_ID
320
+	 */
321
+	public static function schedule_expired_transaction_check(
322
+		int $timestamp,
323
+		int $TXN_ID
324
+	): void {
325
+		// validate $TXN_ID and $timestamp
326
+		$TXN_ID = absint($TXN_ID);
327
+		$timestamp = absint($timestamp);
328
+		if ($TXN_ID && $timestamp) {
329
+			wp_schedule_single_event(
330
+				$timestamp,
331
+				'AHEE__EE_Cron_Tasks__expired_transaction_check',
332
+				array($TXN_ID)
333
+			);
334
+		}
335
+	}
336
+
337
+
338
+	/**
339
+	 * expired_transaction_check
340
+	 * this is the callback for the action hook:
341
+	 * 'AHEE__EE_Cron_Tasks__transaction_session_expiration_check'
342
+	 * which is utilized by wp_schedule_single_event()
343
+	 * in \EED_Single_Page_Checkout::_initialize_transaction().
344
+	 * The passed TXN_ID gets added to an array, and then the
345
+	 * process_expired_transactions() function is hooked into
346
+	 * 'AHEE__EE_System__core_loaded_and_ready' which will actually handle the
347
+	 * processing of any failed transactions, because doing so now would be
348
+	 * too early and the required resources may not be available
349
+	 *
350
+	 * @param int $TXN_ID
351
+	 */
352
+	public static function expired_transaction_check(int $TXN_ID = 0): void
353
+	{
354
+		if (absint($TXN_ID)) {
355
+			self::$_expired_transactions[ $TXN_ID ] = $TXN_ID;
356
+			add_action(
357
+				'shutdown',
358
+				array('EE_Cron_Tasks', 'process_expired_transactions'),
359
+				5
360
+			);
361
+		}
362
+	}
363
+
364
+
365
+	/**
366
+	 * process_expired_transactions
367
+	 * loops through the self::$_expired_transactions array and processes any failed TXNs
368
+	 *
369
+	 * @throws EE_Error
370
+	 * @throws InvalidDataTypeException
371
+	 * @throws InvalidInterfaceException
372
+	 * @throws InvalidArgumentException
373
+	 * @throws ReflectionException
374
+	 * @throws DomainException
375
+	 * @throws RuntimeException
376
+	 */
377
+	public static function process_expired_transactions(): void
378
+	{
379
+		if (
380 380
 // are there any TXNs that need cleaning up ?
381
-            empty(self::$_expired_transactions)
382
-            // reschedule the cron if we can't hit the db right now
383
-            || EE_Cron_Tasks::reschedule_cron_for_transactions_if_maintenance_mode(
384
-                'schedule_expired_transaction_check',
385
-                self::$_expired_transactions
386
-            )
387
-        ) {
388
-            return;
389
-        }
390
-        /** @type EE_Transaction_Processor $transaction_processor */
391
-        $transaction_processor = EE_Registry::instance()->load_class('Transaction_Processor');
392
-        // set revisit flag for txn processor
393
-        $transaction_processor->set_revisit();
394
-        // load EEM_Transaction
395
-        EE_Registry::instance()->load_model('Transaction');
396
-        foreach (self::$_expired_transactions as $TXN_ID) {
397
-            $transaction = EEM_Transaction::instance()->get_one_by_ID($TXN_ID);
398
-            // verify transaction and whether it is failed or not
399
-            if ($transaction instanceof EE_Transaction) {
400
-                switch ($transaction->status_ID()) {
401
-                    // Completed TXNs
402
-                    case EEM_Transaction::complete_status_code:
403
-                        // Don't update the transaction/registrations if the Primary Registration is Not Approved.
404
-                        $primary_registration = $transaction->primary_registration();
405
-                        if (
406
-                            $primary_registration instanceof EE_Registration
407
-                            && $primary_registration->status_ID() !== RegStatus::AWAITING_REVIEW
408
-                        ) {
409
-                            /** @type EE_Transaction_Processor $transaction_processor */
410
-                            $transaction_processor = EE_Registry::instance()->load_class('Transaction_Processor');
411
-                            $transaction_processor->update_transaction_and_registrations_after_checkout_or_payment(
412
-                                $transaction,
413
-                                $transaction->last_payment()
414
-                            );
415
-                            do_action(
416
-                                'AHEE__EE_Cron_Tasks__process_expired_transactions__completed_transaction',
417
-                                $transaction
418
-                            );
419
-                        }
420
-                        break;
421
-                    // Overpaid TXNs
422
-                    case EEM_Transaction::overpaid_status_code:
423
-                        do_action(
424
-                            'AHEE__EE_Cron_Tasks__process_expired_transactions__overpaid_transaction',
425
-                            $transaction
426
-                        );
427
-                        break;
428
-                    // Incomplete TXNs
429
-                    case EEM_Transaction::incomplete_status_code:
430
-                        do_action(
431
-                            'AHEE__EE_Cron_Tasks__process_expired_transactions__incomplete_transaction',
432
-                            $transaction
433
-                        );
434
-                        // todo : move business logic into EE_Transaction_Processor for finalizing abandoned transactions
435
-                        break;
436
-                    // Abandoned TXNs
437
-                    case EEM_Transaction::abandoned_status_code:
438
-                        // run hook before updating transaction, primarily so
439
-                        // EED_Ticket_Sales_Monitor::process_abandoned_transactions() can release reserved tickets
440
-                        do_action(
441
-                            'AHEE__EE_Cron_Tasks__process_expired_transactions__abandoned_transaction',
442
-                            $transaction
443
-                        );
444
-                        // don't finalize the TXN if it has already been completed
445
-                        if ($transaction->all_reg_steps_completed() !== true) {
446
-                            /** @type EE_Payment_Processor $payment_processor */
447
-                            $payment_processor = EE_Registry::instance()->load_core('Payment_Processor');
448
-                            // let's simulate an IPN here which will trigger any notifications that need to go out
449
-                            $payment_processor->update_txn_based_on_payment(
450
-                                $transaction,
451
-                                $transaction->last_payment(),
452
-                                true,
453
-                                true
454
-                            );
455
-                        }
456
-                        break;
457
-                    // Failed TXNs
458
-                    case EEM_Transaction::failed_status_code:
459
-                        do_action(
460
-                            'AHEE__EE_Cron_Tasks__process_expired_transactions__failed_transaction',
461
-                            $transaction
462
-                        );
463
-                        // todo :
464
-                        // perform garbage collection here and remove clean_out_junk_transactions()
465
-                        // $registrations = $transaction->registrations();
466
-                        // if (! empty($registrations)) {
467
-                        //     foreach ($registrations as $registration) {
468
-                        //         if ($registration instanceof EE_Registration) {
469
-                        //             $delete_registration = true;
470
-                        //             if ($registration->attendee() instanceof EE_Attendee) {
471
-                        //                 $delete_registration = false;
472
-                        //             }
473
-                        //             if ($delete_registration) {
474
-                        //                 $registration->delete_permanently();
475
-                        //                 $registration->delete_related_permanently();
476
-                        //             }
477
-                        //         }
478
-                        //     }
479
-                        // }
480
-                        break;
481
-                }
482
-            }
483
-            unset(self::$_expired_transactions[ $TXN_ID ]);
484
-        }
485
-    }
486
-
487
-
488
-
489
-    /*************  END OF EXPIRED TRANSACTION CHECK  *************/
490
-
491
-
492
-    /************* START CLEAN UP BOT TRANSACTIONS **********************/
493
-
494
-
495
-    /**
496
-     * callback for 'AHEE__EE_Cron_Tasks__clean_up_junk_transactions'
497
-     * which is setup during activation to run on an hourly cron
498
-     *
499
-     * @throws EE_Error
500
-     * @throws InvalidArgumentException
501
-     * @throws InvalidDataTypeException
502
-     * @throws InvalidInterfaceException
503
-     * @throws DomainException
504
-     * @throws ReflectionException
505
-     */
506
-    public static function clean_out_junk_transactions(): void
507
-    {
508
-        if (DbStatus::isOnline()) {
509
-            EED_Ticket_Sales_Monitor::reset_reservation_counts();
510
-            EEM_Transaction::instance()->delete_junk_transactions();
511
-            EEM_Registration::instance()->delete_registrations_with_no_transaction();
512
-            EEM_Line_Item::instance()->delete_line_items_with_no_transaction();
513
-        }
514
-    }
515
-
516
-
517
-    /**
518
-     * Deletes old gateway logs. After about a week we usually don't need them for debugging. But folks can filter that.
519
-     *
520
-     * @throws EE_Error
521
-     * @throws InvalidDataTypeException
522
-     * @throws InvalidInterfaceException
523
-     * @throws InvalidArgumentException
524
-     * @throws ReflectionException
525
-     * @throws Exception
526
-     */
527
-    public static function clean_out_old_gateway_logs(): void
528
-    {
529
-        if (DbStatus::isOnline()) {
530
-            $reg_config = LoaderFactory::getLoader()->load('EE_Registration_Config');
531
-            $time_diff_for_comparison = apply_filters(
532
-                'FHEE__EE_Cron_Tasks__clean_out_old_gateway_logs__time_diff_for_comparison',
533
-                '-' . $reg_config->gateway_log_lifespan
534
-            );
535
-            EEM_Change_Log::instance()->delete_gateway_logs_older_than(new DateTime($time_diff_for_comparison));
536
-        }
537
-    }
538
-
539
-
540
-    /*****************  FINALIZE ABANDONED TRANSACTIONS *****************/
541
-
542
-
543
-    /**
544
-     * @var array
545
-     */
546
-    protected static array $_abandoned_transactions = array();
547
-
548
-
549
-    /**
550
-     * @param int $timestamp
551
-     * @param int $TXN_ID
552
-     *@deprecated
553
-     */
554
-    public static function schedule_finalize_abandoned_transactions_check(int $timestamp, int $TXN_ID): void
555
-    {
556
-        EE_Cron_Tasks::schedule_expired_transaction_check($timestamp, $TXN_ID);
557
-    }
558
-
559
-
560
-    /**
561
-     * @param int $TXN_ID
562
-     *@deprecated
563
-     */
564
-    public static function check_for_abandoned_transactions(int $TXN_ID = 0): void
565
-    {
566
-        EE_Cron_Tasks::expired_transaction_check($TXN_ID);
567
-    }
568
-
569
-
570
-    /**
571
-     * @deprecated
572
-     * @throws EE_Error
573
-     * @throws DomainException
574
-     * @throws InvalidDataTypeException
575
-     * @throws InvalidInterfaceException
576
-     * @throws InvalidArgumentException
577
-     * @throws ReflectionException
578
-     * @throws RuntimeException
579
-     */
580
-    public static function finalize_abandoned_transactions(): void
581
-    {
582
-        do_action('AHEE_log', __CLASS__, __FUNCTION__);
583
-        if (
381
+			empty(self::$_expired_transactions)
382
+			// reschedule the cron if we can't hit the db right now
383
+			|| EE_Cron_Tasks::reschedule_cron_for_transactions_if_maintenance_mode(
384
+				'schedule_expired_transaction_check',
385
+				self::$_expired_transactions
386
+			)
387
+		) {
388
+			return;
389
+		}
390
+		/** @type EE_Transaction_Processor $transaction_processor */
391
+		$transaction_processor = EE_Registry::instance()->load_class('Transaction_Processor');
392
+		// set revisit flag for txn processor
393
+		$transaction_processor->set_revisit();
394
+		// load EEM_Transaction
395
+		EE_Registry::instance()->load_model('Transaction');
396
+		foreach (self::$_expired_transactions as $TXN_ID) {
397
+			$transaction = EEM_Transaction::instance()->get_one_by_ID($TXN_ID);
398
+			// verify transaction and whether it is failed or not
399
+			if ($transaction instanceof EE_Transaction) {
400
+				switch ($transaction->status_ID()) {
401
+					// Completed TXNs
402
+					case EEM_Transaction::complete_status_code:
403
+						// Don't update the transaction/registrations if the Primary Registration is Not Approved.
404
+						$primary_registration = $transaction->primary_registration();
405
+						if (
406
+							$primary_registration instanceof EE_Registration
407
+							&& $primary_registration->status_ID() !== RegStatus::AWAITING_REVIEW
408
+						) {
409
+							/** @type EE_Transaction_Processor $transaction_processor */
410
+							$transaction_processor = EE_Registry::instance()->load_class('Transaction_Processor');
411
+							$transaction_processor->update_transaction_and_registrations_after_checkout_or_payment(
412
+								$transaction,
413
+								$transaction->last_payment()
414
+							);
415
+							do_action(
416
+								'AHEE__EE_Cron_Tasks__process_expired_transactions__completed_transaction',
417
+								$transaction
418
+							);
419
+						}
420
+						break;
421
+					// Overpaid TXNs
422
+					case EEM_Transaction::overpaid_status_code:
423
+						do_action(
424
+							'AHEE__EE_Cron_Tasks__process_expired_transactions__overpaid_transaction',
425
+							$transaction
426
+						);
427
+						break;
428
+					// Incomplete TXNs
429
+					case EEM_Transaction::incomplete_status_code:
430
+						do_action(
431
+							'AHEE__EE_Cron_Tasks__process_expired_transactions__incomplete_transaction',
432
+							$transaction
433
+						);
434
+						// todo : move business logic into EE_Transaction_Processor for finalizing abandoned transactions
435
+						break;
436
+					// Abandoned TXNs
437
+					case EEM_Transaction::abandoned_status_code:
438
+						// run hook before updating transaction, primarily so
439
+						// EED_Ticket_Sales_Monitor::process_abandoned_transactions() can release reserved tickets
440
+						do_action(
441
+							'AHEE__EE_Cron_Tasks__process_expired_transactions__abandoned_transaction',
442
+							$transaction
443
+						);
444
+						// don't finalize the TXN if it has already been completed
445
+						if ($transaction->all_reg_steps_completed() !== true) {
446
+							/** @type EE_Payment_Processor $payment_processor */
447
+							$payment_processor = EE_Registry::instance()->load_core('Payment_Processor');
448
+							// let's simulate an IPN here which will trigger any notifications that need to go out
449
+							$payment_processor->update_txn_based_on_payment(
450
+								$transaction,
451
+								$transaction->last_payment(),
452
+								true,
453
+								true
454
+							);
455
+						}
456
+						break;
457
+					// Failed TXNs
458
+					case EEM_Transaction::failed_status_code:
459
+						do_action(
460
+							'AHEE__EE_Cron_Tasks__process_expired_transactions__failed_transaction',
461
+							$transaction
462
+						);
463
+						// todo :
464
+						// perform garbage collection here and remove clean_out_junk_transactions()
465
+						// $registrations = $transaction->registrations();
466
+						// if (! empty($registrations)) {
467
+						//     foreach ($registrations as $registration) {
468
+						//         if ($registration instanceof EE_Registration) {
469
+						//             $delete_registration = true;
470
+						//             if ($registration->attendee() instanceof EE_Attendee) {
471
+						//                 $delete_registration = false;
472
+						//             }
473
+						//             if ($delete_registration) {
474
+						//                 $registration->delete_permanently();
475
+						//                 $registration->delete_related_permanently();
476
+						//             }
477
+						//         }
478
+						//     }
479
+						// }
480
+						break;
481
+				}
482
+			}
483
+			unset(self::$_expired_transactions[ $TXN_ID ]);
484
+		}
485
+	}
486
+
487
+
488
+
489
+	/*************  END OF EXPIRED TRANSACTION CHECK  *************/
490
+
491
+
492
+	/************* START CLEAN UP BOT TRANSACTIONS **********************/
493
+
494
+
495
+	/**
496
+	 * callback for 'AHEE__EE_Cron_Tasks__clean_up_junk_transactions'
497
+	 * which is setup during activation to run on an hourly cron
498
+	 *
499
+	 * @throws EE_Error
500
+	 * @throws InvalidArgumentException
501
+	 * @throws InvalidDataTypeException
502
+	 * @throws InvalidInterfaceException
503
+	 * @throws DomainException
504
+	 * @throws ReflectionException
505
+	 */
506
+	public static function clean_out_junk_transactions(): void
507
+	{
508
+		if (DbStatus::isOnline()) {
509
+			EED_Ticket_Sales_Monitor::reset_reservation_counts();
510
+			EEM_Transaction::instance()->delete_junk_transactions();
511
+			EEM_Registration::instance()->delete_registrations_with_no_transaction();
512
+			EEM_Line_Item::instance()->delete_line_items_with_no_transaction();
513
+		}
514
+	}
515
+
516
+
517
+	/**
518
+	 * Deletes old gateway logs. After about a week we usually don't need them for debugging. But folks can filter that.
519
+	 *
520
+	 * @throws EE_Error
521
+	 * @throws InvalidDataTypeException
522
+	 * @throws InvalidInterfaceException
523
+	 * @throws InvalidArgumentException
524
+	 * @throws ReflectionException
525
+	 * @throws Exception
526
+	 */
527
+	public static function clean_out_old_gateway_logs(): void
528
+	{
529
+		if (DbStatus::isOnline()) {
530
+			$reg_config = LoaderFactory::getLoader()->load('EE_Registration_Config');
531
+			$time_diff_for_comparison = apply_filters(
532
+				'FHEE__EE_Cron_Tasks__clean_out_old_gateway_logs__time_diff_for_comparison',
533
+				'-' . $reg_config->gateway_log_lifespan
534
+			);
535
+			EEM_Change_Log::instance()->delete_gateway_logs_older_than(new DateTime($time_diff_for_comparison));
536
+		}
537
+	}
538
+
539
+
540
+	/*****************  FINALIZE ABANDONED TRANSACTIONS *****************/
541
+
542
+
543
+	/**
544
+	 * @var array
545
+	 */
546
+	protected static array $_abandoned_transactions = array();
547
+
548
+
549
+	/**
550
+	 * @param int $timestamp
551
+	 * @param int $TXN_ID
552
+	 *@deprecated
553
+	 */
554
+	public static function schedule_finalize_abandoned_transactions_check(int $timestamp, int $TXN_ID): void
555
+	{
556
+		EE_Cron_Tasks::schedule_expired_transaction_check($timestamp, $TXN_ID);
557
+	}
558
+
559
+
560
+	/**
561
+	 * @param int $TXN_ID
562
+	 *@deprecated
563
+	 */
564
+	public static function check_for_abandoned_transactions(int $TXN_ID = 0): void
565
+	{
566
+		EE_Cron_Tasks::expired_transaction_check($TXN_ID);
567
+	}
568
+
569
+
570
+	/**
571
+	 * @deprecated
572
+	 * @throws EE_Error
573
+	 * @throws DomainException
574
+	 * @throws InvalidDataTypeException
575
+	 * @throws InvalidInterfaceException
576
+	 * @throws InvalidArgumentException
577
+	 * @throws ReflectionException
578
+	 * @throws RuntimeException
579
+	 */
580
+	public static function finalize_abandoned_transactions(): void
581
+	{
582
+		do_action('AHEE_log', __CLASS__, __FUNCTION__);
583
+		if (
584 584
 // are there any TXNs that need cleaning up ?
585
-            empty(self::$_abandoned_transactions)
586
-            // reschedule the cron if we can't hit the db right now
587
-            || EE_Cron_Tasks::reschedule_cron_for_transactions_if_maintenance_mode(
588
-                'schedule_expired_transaction_check',
589
-                self::$_abandoned_transactions
590
-            )
591
-        ) {
592
-            return;
593
-        }
594
-        // combine our arrays of transaction IDs
595
-        self::$_expired_transactions = self::$_abandoned_transactions + self::$_expired_transactions;
596
-        // and deal with abandoned transactions here now...
597
-        EE_Cron_Tasks::process_expired_transactions();
598
-    }
599
-
600
-
601
-    /*************  END OF FINALIZE ABANDONED TRANSACTIONS  *************/
585
+			empty(self::$_abandoned_transactions)
586
+			// reschedule the cron if we can't hit the db right now
587
+			|| EE_Cron_Tasks::reschedule_cron_for_transactions_if_maintenance_mode(
588
+				'schedule_expired_transaction_check',
589
+				self::$_abandoned_transactions
590
+			)
591
+		) {
592
+			return;
593
+		}
594
+		// combine our arrays of transaction IDs
595
+		self::$_expired_transactions = self::$_abandoned_transactions + self::$_expired_transactions;
596
+		// and deal with abandoned transactions here now...
597
+		EE_Cron_Tasks::process_expired_transactions();
598
+	}
599
+
600
+
601
+	/*************  END OF FINALIZE ABANDONED TRANSACTIONS  *************/
602 602
 }
Please login to merge, or discard this patch.
core/domain/services/capabilities/FeatureFlag.php 1 patch
Indentation   +176 added lines, -176 removed lines patch added patch discarded remove patch
@@ -11,192 +11,192 @@
 block discarded – undo
11 11
 class FeatureFlag
12 12
 {
13 13
 
14
-    /**
15
-     * Whether to use the New Event Editor (EDTR) or continue using the legacy Event Editor
16
-     * deafult: Enabled for Caffeinated sites, disabled for Decaf or Multisite installs
17
-     */
18
-    public const  USE_ADVANCED_EVENT_EDITOR = 'ee_advanced_event_editor';
14
+	/**
15
+	 * Whether to use the New Event Editor (EDTR) or continue using the legacy Event Editor
16
+	 * deafult: Enabled for Caffeinated sites, disabled for Decaf or Multisite installs
17
+	 */
18
+	public const  USE_ADVANCED_EVENT_EDITOR = 'ee_advanced_event_editor';
19 19
 
20
-    /**
21
-     * Whether to enable the Bulk Edit feature in the Advanced Event Editor (EDTR)
22
-     * default: Enabled for Caffeinated sites, disabled for Decaf or Multisite installs
23
-     */
24
-    public const  USE_EVENT_EDITOR_BULK_EDIT = 'ee_event_editor_bulk_edit';
20
+	/**
21
+	 * Whether to enable the Bulk Edit feature in the Advanced Event Editor (EDTR)
22
+	 * default: Enabled for Caffeinated sites, disabled for Decaf or Multisite installs
23
+	 */
24
+	public const  USE_EVENT_EDITOR_BULK_EDIT = 'ee_event_editor_bulk_edit';
25 25
 
26
-    /**
27
-     * Whether to enable the new Default Ticket Manager in the EDTR
28
-     * default: Enabled
29
-     */
30
-    public const  USE_DEFAULT_TICKET_MANAGER = 'use_default_ticket_manager';
26
+	/**
27
+	 * Whether to enable the new Default Ticket Manager in the EDTR
28
+	 * default: Enabled
29
+	 */
30
+	public const  USE_DEFAULT_TICKET_MANAGER = 'use_default_ticket_manager';
31 31
 
32
-    /**
33
-     * Whether to enable the Rich Text Editor for the Event Description field in the EDTR or use tinymce
34
-     * default: Disabled
35
-     */
36
-    public const  USE_EVENT_DESCRIPTION_RTE = 'use_event_description_rte';
32
+	/**
33
+	 * Whether to enable the Rich Text Editor for the Event Description field in the EDTR or use tinymce
34
+	 * default: Disabled
35
+	 */
36
+	public const  USE_EVENT_DESCRIPTION_RTE = 'use_event_description_rte';
37 37
 
38
-    /**
39
-     * Whether to enable the Rich Text Editor for all other RTE fields in the EDTR
40
-     * default: Disabled
41
-     */
42
-    public const  USE_EXPERIMENTAL_RTE = 'use_experimental_rte';
38
+	/**
39
+	 * Whether to enable the Rich Text Editor for all other RTE fields in the EDTR
40
+	 * default: Disabled
41
+	 */
42
+	public const  USE_EXPERIMENTAL_RTE = 'use_experimental_rte';
43 43
 
44
-    /**
45
-     * Whether to enable the new Registration Form Builder in the EDTR
46
-     * or continue using the legacy Question Groups and Registration Form admin pages
47
-     * default: Disabled
48
-     */
49
-    public const  USE_REG_FORM_BUILDER = 'use_reg_form_builder';
44
+	/**
45
+	 * Whether to enable the new Registration Form Builder in the EDTR
46
+	 * or continue using the legacy Question Groups and Registration Form admin pages
47
+	 * default: Disabled
48
+	 */
49
+	public const  USE_REG_FORM_BUILDER = 'use_reg_form_builder';
50 50
 
51
-    /**
52
-     * Whether to enable the new Registration Options meta box in the EDTR
53
-     * or continue using the legacy Event Registration Options
54
-     * default: Disabled
55
-     */
56
-    public const  USE_REG_OPTIONS_META_BOX = 'use_reg_options_meta_box';
51
+	/**
52
+	 * Whether to enable the new Registration Options meta box in the EDTR
53
+	 * or continue using the legacy Event Registration Options
54
+	 * default: Disabled
55
+	 */
56
+	public const  USE_REG_OPTIONS_META_BOX = 'use_reg_options_meta_box';
57 57
 
58
-    /**
59
-     * Whether to enable the new Single Page Checkout form refactor changes
60
-     * default: Disabled
61
-     *
62
-     * @since 5.0.18.p
63
-     */
64
-    public const  USE_SPCO_FORM_REFACTOR = 'use_spco_form_refactor';
58
+	/**
59
+	 * Whether to enable the new Single Page Checkout form refactor changes
60
+	 * default: Disabled
61
+	 *
62
+	 * @since 5.0.18.p
63
+	 */
64
+	public const  USE_SPCO_FORM_REFACTOR = 'use_spco_form_refactor';
65 65
 
66
-    /**
67
-     * Whether to enable the new Reg Form Ticket Questions functionality
68
-     * default: Disabled
69
-     */
70
-    public const  USE_REG_FORM_TICKET_QUESTIONS = 'use_reg_form_ticket_questions';
66
+	/**
67
+	 * Whether to enable the new Reg Form Ticket Questions functionality
68
+	 * default: Disabled
69
+	 */
70
+	public const  USE_REG_FORM_TICKET_QUESTIONS = 'use_reg_form_ticket_questions';
71 71
 
72
-    /**
73
-     * Whether to use the EDD Plugin Licensing system to manage licenses for the EE plugins
74
-     * default: Disabled
75
-     */
76
-    public const USE_EDD_PLUGIN_LICENSING = 'use_edd_plugin_licensing';
72
+	/**
73
+	 * Whether to use the EDD Plugin Licensing system to manage licenses for the EE plugins
74
+	 * default: Disabled
75
+	 */
76
+	public const USE_EDD_PLUGIN_LICENSING = 'use_edd_plugin_licensing';
77 77
 
78
-    /**
79
-     * Whether to use the new Datetime Status Controls in the EDTR
80
-     * default: Disabled
81
-     */
82
-    public const USE_DATETIME_STATUS_CONTROLS = 'use_datetime_status_controls';
78
+	/**
79
+	 * Whether to use the new Datetime Status Controls in the EDTR
80
+	 * default: Disabled
81
+	 */
82
+	public const USE_DATETIME_STATUS_CONTROLS = 'use_datetime_status_controls';
83 83
 
84 84
 
85
-    public static function getFormOptions(): array
86
-    {
87
-        return [
88
-            FeatureFlag::USE_EVENT_EDITOR_BULK_EDIT    => [
89
-                'name'            => esc_html__('Event Editor Bulk Edit', 'event_espresso'),
90
-                'html_label_text' => esc_html__('Use Event Editor Bulk Edit', 'event_espresso'),
91
-                'help_text'       => sprintf(
92
-                    esc_html__(
93
-                        'Whether to enable the Bulk Edit feature in the Advanced Event Editor (EDTR).%1$s%2$sPLEASE NOTE: Bulk Editing is ALWAYS enabled if the Recurring Events Manager add-on is active.%3$s%1$s default: Enabled for Caffeinated sites, disabled for Decaf or Multisite installs',
94
-                        'event_espresso'
95
-                    ),
96
-                    '<br/>',
97
-                    '<strong>',
98
-                    '</strong>'
99
-                ),
100
-                'overridden'      => false,
101
-                'overridden_by'   => '',
102
-            ],
103
-            FeatureFlag::USE_DEFAULT_TICKET_MANAGER    => [
104
-                'name'            => esc_html__('Default Ticket Manager', 'event_espresso'),
105
-                'html_label_text' => esc_html__('Use Default Ticket Manager', 'event_espresso'),
106
-                'help_text'       => esc_html__(
107
-                    'Whether to enable the new Default Ticket Manager in the EDTR. default: Enabled',
108
-                    'event_espresso'
109
-                ),
110
-                'overridden'      => false,
111
-                'overridden_by'   => '',
112
-            ],
113
-            FeatureFlag::USE_EVENT_DESCRIPTION_RTE     => [
114
-                'name'            => esc_html__('Event Description RTE', 'event_espresso'),
115
-                'html_label_text' => esc_html__('Use Rich Text Editor for Event Description', 'event_espresso'),
116
-                'help_text'       => esc_html__(
117
-                    'Whether to enable the Rich Text Editor for the Event Description field in the EDTR or use tinymce. default: Disabled',
118
-                    'event_espresso'
119
-                ),
120
-                'overridden'      => false,
121
-                'overridden_by'   => '',
122
-            ],
123
-            FeatureFlag::USE_EXPERIMENTAL_RTE          => [
124
-                'name'            => esc_html__('Rich Text Editor', 'event_espresso'),
125
-                'html_label_text' => esc_html__('Use Rich Text Editor for other RTE fields', 'event_espresso'),
126
-                'help_text'       => esc_html__(
127
-                    'Whether to enable the Rich Text Editor for all other RTE fields in the EDTR. default: Disabled',
128
-                    'event_espresso'
129
-                ),
130
-                'overridden'      => false,
131
-                'overridden_by'   => '',
132
-            ],
133
-            FeatureFlag::USE_REG_FORM_BUILDER          => [
134
-                'name'            => esc_html__('Registration Form Builder', 'event_espresso'),
135
-                'html_label_text' => esc_html__('Use Registration Form Builder', 'event_espresso'),
136
-                'help_text'       => esc_html__(
137
-                    'Whether to enable the new Registration Form Builder in the EDTR or continue using the legacy Question Groups and Registration Form admin pages. default: Disabled',
138
-                    'event_espresso'
139
-                ),
140
-                'overridden'      => false,
141
-                'overridden_by'   => '',
142
-            ],
143
-            FeatureFlag::USE_REG_OPTIONS_META_BOX      => [
144
-                'name'            => esc_html__('Registration Options', 'event_espresso'),
145
-                'html_label_text' => esc_html__('Use Registration Options', 'event_espresso'),
146
-                'help_text'       => esc_html__(
147
-                    'Whether to enable the new Registration Options meta box in the EDTR or continue using the legacy Event Registration Options. default: Disabled',
148
-                    'event_espresso'
149
-                ),
150
-                'overridden'      => false,
151
-                'overridden_by'   => '',
152
-            ],
153
-            FeatureFlag::USE_SPCO_FORM_REFACTOR        => [
154
-                'name'            => esc_html__('SPCO Form Refactor', 'event_espresso'),
155
-                'html_label_text' => esc_html__('Use SPCO Form Refactor', 'event_espresso'),
156
-                'help_text'       => esc_html__(
157
-                    'Whether to enable the new Single Page Checkout form refactor changes or continue using the legacy Single Page Checkout form. default: Disabled',
158
-                    'event_espresso'
159
-                ),
160
-                'overridden'      => false,
161
-                'overridden_by'   => '',
162
-            ],
163
-            FeatureFlag::USE_REG_FORM_TICKET_QUESTIONS => [
164
-                'name'            => esc_html__('Reg Form Ticket Questions', 'event_espresso'),
165
-                'html_label_text' => esc_html__('Use Reg Form Ticket Questions', 'event_espresso'),
166
-                'help_text'       => esc_html__(
167
-                    'Whether to enable the new Reg Form Ticket Questions functionality. default: Disabled',
168
-                    'event_espresso'
169
-                ),
170
-                'overridden'      => false,
171
-                'overridden_by'   => '',
172
-            ],
173
-            FeatureFlag::USE_EDD_PLUGIN_LICENSING      => [
174
-                'name'            => esc_html__('EDD Plugin Licensing', 'event_espresso'),
175
-                'html_label_text' => esc_html__('Use EDD Plugin Licensing', 'event_espresso'),
176
-                'help_text'       => esc_html__(
177
-                    'Whether to use the EDD Plugin Licensing system to manage licenses for the EE plugins. default: Disabled',
178
-                    'event_espresso'
179
-                ),
180
-                'overridden'      => defined('EE_USE_EDD_PLUGIN_LICENSING') && EE_USE_EDD_PLUGIN_LICENSING,
181
-                'overridden_by'      => defined('EE_USE_EDD_PLUGIN_LICENSING') && EE_USE_EDD_PLUGIN_LICENSING
182
-                    ? sprintf(
183
-                        esc_html__('%1$sCurrently overriden by the %2$s constant in wp-config.php%3$s', 'event_espresso'),
184
-                        '<br><span class="ee-status--warning">',
185
-                        'EE_USE_EDD_PLUGIN_LICENSING',
186
-                        '</span>'
187
-                    )
188
-                    : '',
189
-            ],
190
-            FeatureFlag::USE_DATETIME_STATUS_CONTROLS  => [
191
-                'name'            => esc_html__('Datetime Status Controls', 'event_espresso'),
192
-                'html_label_text' => esc_html__('Use Datetime Status Controls', 'event_espresso'),
193
-                'help_text'       => esc_html__(
194
-                    'Whether to use the new Datetime Status Controls in the EDTR. default: Disabled',
195
-                    'event_espresso'
196
-                ),
197
-                'overridden'      => false,
198
-                'overridden_by'   => '',
199
-            ],
200
-        ];
201
-    }
85
+	public static function getFormOptions(): array
86
+	{
87
+		return [
88
+			FeatureFlag::USE_EVENT_EDITOR_BULK_EDIT    => [
89
+				'name'            => esc_html__('Event Editor Bulk Edit', 'event_espresso'),
90
+				'html_label_text' => esc_html__('Use Event Editor Bulk Edit', 'event_espresso'),
91
+				'help_text'       => sprintf(
92
+					esc_html__(
93
+						'Whether to enable the Bulk Edit feature in the Advanced Event Editor (EDTR).%1$s%2$sPLEASE NOTE: Bulk Editing is ALWAYS enabled if the Recurring Events Manager add-on is active.%3$s%1$s default: Enabled for Caffeinated sites, disabled for Decaf or Multisite installs',
94
+						'event_espresso'
95
+					),
96
+					'<br/>',
97
+					'<strong>',
98
+					'</strong>'
99
+				),
100
+				'overridden'      => false,
101
+				'overridden_by'   => '',
102
+			],
103
+			FeatureFlag::USE_DEFAULT_TICKET_MANAGER    => [
104
+				'name'            => esc_html__('Default Ticket Manager', 'event_espresso'),
105
+				'html_label_text' => esc_html__('Use Default Ticket Manager', 'event_espresso'),
106
+				'help_text'       => esc_html__(
107
+					'Whether to enable the new Default Ticket Manager in the EDTR. default: Enabled',
108
+					'event_espresso'
109
+				),
110
+				'overridden'      => false,
111
+				'overridden_by'   => '',
112
+			],
113
+			FeatureFlag::USE_EVENT_DESCRIPTION_RTE     => [
114
+				'name'            => esc_html__('Event Description RTE', 'event_espresso'),
115
+				'html_label_text' => esc_html__('Use Rich Text Editor for Event Description', 'event_espresso'),
116
+				'help_text'       => esc_html__(
117
+					'Whether to enable the Rich Text Editor for the Event Description field in the EDTR or use tinymce. default: Disabled',
118
+					'event_espresso'
119
+				),
120
+				'overridden'      => false,
121
+				'overridden_by'   => '',
122
+			],
123
+			FeatureFlag::USE_EXPERIMENTAL_RTE          => [
124
+				'name'            => esc_html__('Rich Text Editor', 'event_espresso'),
125
+				'html_label_text' => esc_html__('Use Rich Text Editor for other RTE fields', 'event_espresso'),
126
+				'help_text'       => esc_html__(
127
+					'Whether to enable the Rich Text Editor for all other RTE fields in the EDTR. default: Disabled',
128
+					'event_espresso'
129
+				),
130
+				'overridden'      => false,
131
+				'overridden_by'   => '',
132
+			],
133
+			FeatureFlag::USE_REG_FORM_BUILDER          => [
134
+				'name'            => esc_html__('Registration Form Builder', 'event_espresso'),
135
+				'html_label_text' => esc_html__('Use Registration Form Builder', 'event_espresso'),
136
+				'help_text'       => esc_html__(
137
+					'Whether to enable the new Registration Form Builder in the EDTR or continue using the legacy Question Groups and Registration Form admin pages. default: Disabled',
138
+					'event_espresso'
139
+				),
140
+				'overridden'      => false,
141
+				'overridden_by'   => '',
142
+			],
143
+			FeatureFlag::USE_REG_OPTIONS_META_BOX      => [
144
+				'name'            => esc_html__('Registration Options', 'event_espresso'),
145
+				'html_label_text' => esc_html__('Use Registration Options', 'event_espresso'),
146
+				'help_text'       => esc_html__(
147
+					'Whether to enable the new Registration Options meta box in the EDTR or continue using the legacy Event Registration Options. default: Disabled',
148
+					'event_espresso'
149
+				),
150
+				'overridden'      => false,
151
+				'overridden_by'   => '',
152
+			],
153
+			FeatureFlag::USE_SPCO_FORM_REFACTOR        => [
154
+				'name'            => esc_html__('SPCO Form Refactor', 'event_espresso'),
155
+				'html_label_text' => esc_html__('Use SPCO Form Refactor', 'event_espresso'),
156
+				'help_text'       => esc_html__(
157
+					'Whether to enable the new Single Page Checkout form refactor changes or continue using the legacy Single Page Checkout form. default: Disabled',
158
+					'event_espresso'
159
+				),
160
+				'overridden'      => false,
161
+				'overridden_by'   => '',
162
+			],
163
+			FeatureFlag::USE_REG_FORM_TICKET_QUESTIONS => [
164
+				'name'            => esc_html__('Reg Form Ticket Questions', 'event_espresso'),
165
+				'html_label_text' => esc_html__('Use Reg Form Ticket Questions', 'event_espresso'),
166
+				'help_text'       => esc_html__(
167
+					'Whether to enable the new Reg Form Ticket Questions functionality. default: Disabled',
168
+					'event_espresso'
169
+				),
170
+				'overridden'      => false,
171
+				'overridden_by'   => '',
172
+			],
173
+			FeatureFlag::USE_EDD_PLUGIN_LICENSING      => [
174
+				'name'            => esc_html__('EDD Plugin Licensing', 'event_espresso'),
175
+				'html_label_text' => esc_html__('Use EDD Plugin Licensing', 'event_espresso'),
176
+				'help_text'       => esc_html__(
177
+					'Whether to use the EDD Plugin Licensing system to manage licenses for the EE plugins. default: Disabled',
178
+					'event_espresso'
179
+				),
180
+				'overridden'      => defined('EE_USE_EDD_PLUGIN_LICENSING') && EE_USE_EDD_PLUGIN_LICENSING,
181
+				'overridden_by'      => defined('EE_USE_EDD_PLUGIN_LICENSING') && EE_USE_EDD_PLUGIN_LICENSING
182
+					? sprintf(
183
+						esc_html__('%1$sCurrently overriden by the %2$s constant in wp-config.php%3$s', 'event_espresso'),
184
+						'<br><span class="ee-status--warning">',
185
+						'EE_USE_EDD_PLUGIN_LICENSING',
186
+						'</span>'
187
+					)
188
+					: '',
189
+			],
190
+			FeatureFlag::USE_DATETIME_STATUS_CONTROLS  => [
191
+				'name'            => esc_html__('Datetime Status Controls', 'event_espresso'),
192
+				'html_label_text' => esc_html__('Use Datetime Status Controls', 'event_espresso'),
193
+				'help_text'       => esc_html__(
194
+					'Whether to use the new Datetime Status Controls in the EDTR. default: Disabled',
195
+					'event_espresso'
196
+				),
197
+				'overridden'      => false,
198
+				'overridden_by'   => '',
199
+			],
200
+		];
201
+	}
202 202
 }
Please login to merge, or discard this patch.
core/domain/services/capabilities/FeatureFlagsConfig.php 2 patches
Indentation   +163 added lines, -163 removed lines patch added patch discarded remove patch
@@ -17,167 +17,167 @@
 block discarded – undo
17 17
  */
18 18
 class FeatureFlagsConfig extends JsonDataWordpressOption
19 19
 {
20
-    /**
21
-     * WP option name for saving the Feature Flags configuration
22
-     */
23
-    private const OPTION_NAME = 'ee_feature_flags';
24
-
25
-    /**
26
-     * use FeatureFlag::USE_EVENT_EDITOR_BULK_EDIT instead
27
-     * this hasn't been deleted because it's used in the REM add-on
28
-     *
29
-     * @deprecated 5.0.18.p
30
-     */
31
-    public const  USE_EVENT_EDITOR_BULK_EDIT = FeatureFlag::USE_EVENT_EDITOR_BULK_EDIT;
32
-
33
-
34
-
35
-    protected Domain $domain;
36
-
37
-    private ?stdClass $feature_flags = null;
38
-
39
-
40
-    public function __construct(Domain $domain, JsonDataHandler $json_data_handler)
41
-    {
42
-        $this->domain = $domain;
43
-        parent::__construct($json_data_handler, FeatureFlagsConfig::OPTION_NAME, $this->getDefaultFeatureFlagOptions());
44
-    }
45
-
46
-
47
-    /**
48
-     * see the FeatureFlag::USE_* constants for descriptions of each feature flag and their default values
49
-     *
50
-     * @return stdClass
51
-     */
52
-    public function getDefaultFeatureFlagOptions(): stdClass
53
-    {
54
-        return (object) [
55
-            FeatureFlag::USE_ADVANCED_EVENT_EDITOR     => $this->domain->isCaffeinated() && ! $this->domain->isMultiSite(),
56
-            FeatureFlag::USE_DEFAULT_TICKET_MANAGER    => true,
57
-            FeatureFlag::USE_EDD_PLUGIN_LICENSING      => defined('EE_USE_EDD_PLUGIN_LICENSING') && EE_USE_EDD_PLUGIN_LICENSING,
58
-            FeatureFlag::USE_EVENT_DESCRIPTION_RTE     => false,
59
-            FeatureFlag::USE_EVENT_EDITOR_BULK_EDIT    => $this->domain->isCaffeinated() && ! $this->domain->isMultiSite(),
60
-            FeatureFlag::USE_EXPERIMENTAL_RTE          => false,
61
-            FeatureFlag::USE_REG_FORM_BUILDER          => false,
62
-            FeatureFlag::USE_REG_FORM_TICKET_QUESTIONS => false,
63
-            FeatureFlag::USE_REG_OPTIONS_META_BOX      => false,
64
-            FeatureFlag::USE_SPCO_FORM_REFACTOR        => false,
65
-        ];
66
-    }
67
-
68
-
69
-    /**
70
-     * feature flags that absolutely must be enabled/disabled based on hard-coded conditions
71
-     *
72
-     * @return stdClass
73
-     * @since 5.0.20.p
74
-     */
75
-    public function getOverrides(): stdClass
76
-    {
77
-        $overrides = [];
78
-        if (defined('EE_USE_EDD_PLUGIN_LICENSING')) {
79
-            $overrides[FeatureFlag::USE_EDD_PLUGIN_LICENSING] = EE_USE_EDD_PLUGIN_LICENSING;
80
-        }
81
-        return (object) $overrides;
82
-    }
83
-
84
-
85
-    /**
86
-     * @return stdClass
87
-     */
88
-    public function getFeatureFlags(): stdClass
89
-    {
90
-        if ($this->feature_flags) {
91
-            return $this->feature_flags;
92
-        }
93
-        $default_options = $this->getDefaultFeatureFlagOptions();
94
-        if (apply_filters('FHEE__FeatureFlagsConfig__getFeatureFlags__use_default_feature_flags', true)) {
95
-            $this->feature_flags = $default_options;
96
-            return $this->feature_flags;
97
-        }
98
-        $this->feature_flags = $this->getAll();
99
-        $overrides = $this->getOverrides();
100
-        // ensure that all feature flags are set
101
-        foreach ($default_options as $key => $value) {
102
-            // if the feature flag is not set, use the default value
103
-            if (!isset($this->feature_flags->$key)) {
104
-                $this->feature_flags->$key = $value;
105
-            }
106
-            // ensure that all overrides are set
107
-            if (isset($overrides->$key)) {
108
-                $this->feature_flags->$key = $overrides->$key;
109
-            }
110
-        }
111
-        return $this->feature_flags;
112
-    }
113
-
114
-
115
-    public function saveFeatureFlagsConfig(?stdClass $feature_flags = null): int
116
-    {
117
-        $feature_flags = $feature_flags ?? $this->feature_flags;
118
-        return $this->updateOption($feature_flags);
119
-    }
120
-
121
-
122
-    /**
123
-     * enables a feature flag, ex:
124
-     * $this->enableFeatureFlag(FeatureFlag::USE_ADVANCED_EVENT_EDITOR);
125
-     *
126
-     * @param string $feature_flag the feature flag to enable. One of the FeatureFlag::USE_* constants
127
-     * @param bool   $add_if_missing
128
-     * @param bool   $save
129
-     * @return int
130
-     */
131
-    public function enableFeatureFlag(string $feature_flag, bool $add_if_missing = false, bool $save = true): int
132
-    {
133
-        if (! $this->feature_flags) {
134
-            $this->getFeatureFlags();
135
-        }
136
-        if (! property_exists($this->feature_flags, $feature_flag) && ! $add_if_missing) {
137
-                return WordPressOption::UPDATE_ERROR;
138
-        }
139
-        $this->feature_flags->{$feature_flag} = true;
140
-        // if feature flag is the advanced event editor or bulk edit options
141
-        // then only enabled if the site is Caffeinated and not MultiSite
142
-        if (
143
-            $feature_flag === FeatureFlag::USE_ADVANCED_EVENT_EDITOR
144
-            || $feature_flag === FeatureFlag::USE_EVENT_EDITOR_BULK_EDIT
145
-        ) {
146
-            $this->feature_flags->{$feature_flag} = $this->domain->isCaffeinated() && ! $this->domain->isMultiSite();
147
-        }
148
-        if ($save) {
149
-            return $this->saveFeatureFlagsConfig($this->feature_flags);
150
-        }
151
-        return WordPressOption::UPDATE_NONE;
152
-    }
153
-
154
-
155
-    /**
156
-     * disables a feature flag, ex:
157
-     * $this->disableFeatureFlag(FeatureFlag::USE_ADVANCED_EVENT_EDITOR);
158
-     *
159
-     * @param string $feature_flag the feature flag to disable. One of the FeatureFlag::USE_* constants
160
-     * @param bool   $save
161
-     * @return int
162
-     */
163
-    public function disableFeatureFlag(string $feature_flag, bool $save = true): int
164
-    {
165
-        if (! $this->feature_flags) {
166
-            $this->getFeatureFlags();
167
-        }
168
-        if (! property_exists($this->feature_flags, $feature_flag)) {
169
-            return WordPressOption::UPDATE_ERROR;
170
-        }
171
-        $this->feature_flags->{$feature_flag} = false;
172
-        if ($save) {
173
-            return $this->saveFeatureFlagsConfig($this->feature_flags);
174
-        }
175
-        return WordPressOption::UPDATE_NONE;
176
-    }
177
-
178
-
179
-    public function getFeatureFlagsFormOptions(): ?array
180
-    {
181
-        return FeatureFlag::getFormOptions();
182
-    }
20
+	/**
21
+	 * WP option name for saving the Feature Flags configuration
22
+	 */
23
+	private const OPTION_NAME = 'ee_feature_flags';
24
+
25
+	/**
26
+	 * use FeatureFlag::USE_EVENT_EDITOR_BULK_EDIT instead
27
+	 * this hasn't been deleted because it's used in the REM add-on
28
+	 *
29
+	 * @deprecated 5.0.18.p
30
+	 */
31
+	public const  USE_EVENT_EDITOR_BULK_EDIT = FeatureFlag::USE_EVENT_EDITOR_BULK_EDIT;
32
+
33
+
34
+
35
+	protected Domain $domain;
36
+
37
+	private ?stdClass $feature_flags = null;
38
+
39
+
40
+	public function __construct(Domain $domain, JsonDataHandler $json_data_handler)
41
+	{
42
+		$this->domain = $domain;
43
+		parent::__construct($json_data_handler, FeatureFlagsConfig::OPTION_NAME, $this->getDefaultFeatureFlagOptions());
44
+	}
45
+
46
+
47
+	/**
48
+	 * see the FeatureFlag::USE_* constants for descriptions of each feature flag and their default values
49
+	 *
50
+	 * @return stdClass
51
+	 */
52
+	public function getDefaultFeatureFlagOptions(): stdClass
53
+	{
54
+		return (object) [
55
+			FeatureFlag::USE_ADVANCED_EVENT_EDITOR     => $this->domain->isCaffeinated() && ! $this->domain->isMultiSite(),
56
+			FeatureFlag::USE_DEFAULT_TICKET_MANAGER    => true,
57
+			FeatureFlag::USE_EDD_PLUGIN_LICENSING      => defined('EE_USE_EDD_PLUGIN_LICENSING') && EE_USE_EDD_PLUGIN_LICENSING,
58
+			FeatureFlag::USE_EVENT_DESCRIPTION_RTE     => false,
59
+			FeatureFlag::USE_EVENT_EDITOR_BULK_EDIT    => $this->domain->isCaffeinated() && ! $this->domain->isMultiSite(),
60
+			FeatureFlag::USE_EXPERIMENTAL_RTE          => false,
61
+			FeatureFlag::USE_REG_FORM_BUILDER          => false,
62
+			FeatureFlag::USE_REG_FORM_TICKET_QUESTIONS => false,
63
+			FeatureFlag::USE_REG_OPTIONS_META_BOX      => false,
64
+			FeatureFlag::USE_SPCO_FORM_REFACTOR        => false,
65
+		];
66
+	}
67
+
68
+
69
+	/**
70
+	 * feature flags that absolutely must be enabled/disabled based on hard-coded conditions
71
+	 *
72
+	 * @return stdClass
73
+	 * @since 5.0.20.p
74
+	 */
75
+	public function getOverrides(): stdClass
76
+	{
77
+		$overrides = [];
78
+		if (defined('EE_USE_EDD_PLUGIN_LICENSING')) {
79
+			$overrides[FeatureFlag::USE_EDD_PLUGIN_LICENSING] = EE_USE_EDD_PLUGIN_LICENSING;
80
+		}
81
+		return (object) $overrides;
82
+	}
83
+
84
+
85
+	/**
86
+	 * @return stdClass
87
+	 */
88
+	public function getFeatureFlags(): stdClass
89
+	{
90
+		if ($this->feature_flags) {
91
+			return $this->feature_flags;
92
+		}
93
+		$default_options = $this->getDefaultFeatureFlagOptions();
94
+		if (apply_filters('FHEE__FeatureFlagsConfig__getFeatureFlags__use_default_feature_flags', true)) {
95
+			$this->feature_flags = $default_options;
96
+			return $this->feature_flags;
97
+		}
98
+		$this->feature_flags = $this->getAll();
99
+		$overrides = $this->getOverrides();
100
+		// ensure that all feature flags are set
101
+		foreach ($default_options as $key => $value) {
102
+			// if the feature flag is not set, use the default value
103
+			if (!isset($this->feature_flags->$key)) {
104
+				$this->feature_flags->$key = $value;
105
+			}
106
+			// ensure that all overrides are set
107
+			if (isset($overrides->$key)) {
108
+				$this->feature_flags->$key = $overrides->$key;
109
+			}
110
+		}
111
+		return $this->feature_flags;
112
+	}
113
+
114
+
115
+	public function saveFeatureFlagsConfig(?stdClass $feature_flags = null): int
116
+	{
117
+		$feature_flags = $feature_flags ?? $this->feature_flags;
118
+		return $this->updateOption($feature_flags);
119
+	}
120
+
121
+
122
+	/**
123
+	 * enables a feature flag, ex:
124
+	 * $this->enableFeatureFlag(FeatureFlag::USE_ADVANCED_EVENT_EDITOR);
125
+	 *
126
+	 * @param string $feature_flag the feature flag to enable. One of the FeatureFlag::USE_* constants
127
+	 * @param bool   $add_if_missing
128
+	 * @param bool   $save
129
+	 * @return int
130
+	 */
131
+	public function enableFeatureFlag(string $feature_flag, bool $add_if_missing = false, bool $save = true): int
132
+	{
133
+		if (! $this->feature_flags) {
134
+			$this->getFeatureFlags();
135
+		}
136
+		if (! property_exists($this->feature_flags, $feature_flag) && ! $add_if_missing) {
137
+				return WordPressOption::UPDATE_ERROR;
138
+		}
139
+		$this->feature_flags->{$feature_flag} = true;
140
+		// if feature flag is the advanced event editor or bulk edit options
141
+		// then only enabled if the site is Caffeinated and not MultiSite
142
+		if (
143
+			$feature_flag === FeatureFlag::USE_ADVANCED_EVENT_EDITOR
144
+			|| $feature_flag === FeatureFlag::USE_EVENT_EDITOR_BULK_EDIT
145
+		) {
146
+			$this->feature_flags->{$feature_flag} = $this->domain->isCaffeinated() && ! $this->domain->isMultiSite();
147
+		}
148
+		if ($save) {
149
+			return $this->saveFeatureFlagsConfig($this->feature_flags);
150
+		}
151
+		return WordPressOption::UPDATE_NONE;
152
+	}
153
+
154
+
155
+	/**
156
+	 * disables a feature flag, ex:
157
+	 * $this->disableFeatureFlag(FeatureFlag::USE_ADVANCED_EVENT_EDITOR);
158
+	 *
159
+	 * @param string $feature_flag the feature flag to disable. One of the FeatureFlag::USE_* constants
160
+	 * @param bool   $save
161
+	 * @return int
162
+	 */
163
+	public function disableFeatureFlag(string $feature_flag, bool $save = true): int
164
+	{
165
+		if (! $this->feature_flags) {
166
+			$this->getFeatureFlags();
167
+		}
168
+		if (! property_exists($this->feature_flags, $feature_flag)) {
169
+			return WordPressOption::UPDATE_ERROR;
170
+		}
171
+		$this->feature_flags->{$feature_flag} = false;
172
+		if ($save) {
173
+			return $this->saveFeatureFlagsConfig($this->feature_flags);
174
+		}
175
+		return WordPressOption::UPDATE_NONE;
176
+	}
177
+
178
+
179
+	public function getFeatureFlagsFormOptions(): ?array
180
+	{
181
+		return FeatureFlag::getFormOptions();
182
+	}
183 183
 }
Please login to merge, or discard this patch.
Spacing   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -100,7 +100,7 @@  discard block
 block discarded – undo
100 100
         // ensure that all feature flags are set
101 101
         foreach ($default_options as $key => $value) {
102 102
             // if the feature flag is not set, use the default value
103
-            if (!isset($this->feature_flags->$key)) {
103
+            if ( ! isset($this->feature_flags->$key)) {
104 104
                 $this->feature_flags->$key = $value;
105 105
             }
106 106
             // ensure that all overrides are set
@@ -130,10 +130,10 @@  discard block
 block discarded – undo
130 130
      */
131 131
     public function enableFeatureFlag(string $feature_flag, bool $add_if_missing = false, bool $save = true): int
132 132
     {
133
-        if (! $this->feature_flags) {
133
+        if ( ! $this->feature_flags) {
134 134
             $this->getFeatureFlags();
135 135
         }
136
-        if (! property_exists($this->feature_flags, $feature_flag) && ! $add_if_missing) {
136
+        if ( ! property_exists($this->feature_flags, $feature_flag) && ! $add_if_missing) {
137 137
                 return WordPressOption::UPDATE_ERROR;
138 138
         }
139 139
         $this->feature_flags->{$feature_flag} = true;
@@ -162,10 +162,10 @@  discard block
 block discarded – undo
162 162
      */
163 163
     public function disableFeatureFlag(string $feature_flag, bool $save = true): int
164 164
     {
165
-        if (! $this->feature_flags) {
165
+        if ( ! $this->feature_flags) {
166 166
             $this->getFeatureFlags();
167 167
         }
168
-        if (! property_exists($this->feature_flags, $feature_flag)) {
168
+        if ( ! property_exists($this->feature_flags, $feature_flag)) {
169 169
             return WordPressOption::UPDATE_ERROR;
170 170
         }
171 171
         $this->feature_flags->{$feature_flag} = false;
Please login to merge, or discard this patch.
services/admin/events/default_settings/AdvancedEditorAdminFormSection.php 1 patch
Indentation   +72 added lines, -72 removed lines patch added patch discarded remove patch
@@ -37,82 +37,82 @@
 block discarded – undo
37 37
  */
38 38
 class AdvancedEditorAdminFormSection
39 39
 {
40
-    protected  EE_Admin_Config $admin_config;
40
+	protected  EE_Admin_Config $admin_config;
41 41
 
42 42
 
43
-    /**
44
-     * AdvancedEditorAdminForm constructor.
45
-     *
46
-     * @param EE_Admin_Config $admin_config
47
-     */
48
-    public function __construct(EE_Admin_Config $admin_config)
49
-    {
50
-        $this->admin_config = $admin_config;
51
-        add_filter(
52
-            'FHEE__Events_Admin_Page___default_event_settings_form__form_subsections',
53
-            [$this, 'mergeFormSubsections']
54
-        );
55
-        add_action(
56
-            'AHEE__Events_Admin_Page___update_default_event_settings',
57
-            [$this, 'updateAdminFormSettings'],
58
-            10,
59
-            2
60
-        );
61
-    }
43
+	/**
44
+	 * AdvancedEditorAdminForm constructor.
45
+	 *
46
+	 * @param EE_Admin_Config $admin_config
47
+	 */
48
+	public function __construct(EE_Admin_Config $admin_config)
49
+	{
50
+		$this->admin_config = $admin_config;
51
+		add_filter(
52
+			'FHEE__Events_Admin_Page___default_event_settings_form__form_subsections',
53
+			[$this, 'mergeFormSubsections']
54
+		);
55
+		add_action(
56
+			'AHEE__Events_Admin_Page___update_default_event_settings',
57
+			[$this, 'updateAdminFormSettings'],
58
+			10,
59
+			2
60
+		);
61
+	}
62 62
 
63 63
 
64
-    /**
65
-     * @param array $default_event_settings_form_subsections
66
-     * @return array
67
-     * @since 5.0.0.p
68
-     */
69
-    public function mergeFormSubsections(array $default_event_settings_form_subsections): array
70
-    {
71
-        return [
72
-                   'new_features_section_header' => new EE_Form_Section_HTML(
73
-                       EEH_HTML::h2(
74
-                           esc_html__('New Feature', 'event_espresso'),
75
-                           '',
76
-                           'ee-admin-settings-hdr ee-admin-settings-hdr--new-feature'
77
-                       )
78
-                   ),
79
-                   'use_advanced_editor'     => new EE_Select_Input(
80
-                       apply_filters(
81
-                           'FHEE__Events_Admin_Page___default_event_settings_form__advanced_editor_input_answer_options',
82
-                           [
83
-                               esc_html__('Legacy Editor', 'event_espresso'),
84
-                               esc_html__('Advanced Editor', 'event_espresso'),
85
-                           ]
86
-                       ),
87
-                       apply_filters(
88
-                           'FHEE__Events_Admin_Page___default_event_settings_form__advanced_editor_input_settings',
89
-                           [
90
-                               'default'         => $this->admin_config->useAdvancedEditor(),
91
-                               'html_label_text' => esc_html__('Activate Advanced Editor?', 'event_espresso'),
92
-                               'html_help_text'  => sprintf(
93
-                                   esc_html__(
94
-                                       'Controls whether the Event Espresso Event Editor continues to use the existing legacy editor that functions like the typical older WordPress admin you are used to,%1$sor uses the new Advanced Editor with a more powerful and easier to use interface. This may be automatically turned on in order to utilize advanced features from new addons.',
95
-                                       'event_espresso'
96
-                                   ),
97
-                                   '<br />'
98
-                               ),
99
-                               'html_class'      => 'ee-input-width--small',
100
-                           ]
101
-                       )
102
-                   ),
103
-               ] + $default_event_settings_form_subsections;
104
-    }
64
+	/**
65
+	 * @param array $default_event_settings_form_subsections
66
+	 * @return array
67
+	 * @since 5.0.0.p
68
+	 */
69
+	public function mergeFormSubsections(array $default_event_settings_form_subsections): array
70
+	{
71
+		return [
72
+				   'new_features_section_header' => new EE_Form_Section_HTML(
73
+					   EEH_HTML::h2(
74
+						   esc_html__('New Feature', 'event_espresso'),
75
+						   '',
76
+						   'ee-admin-settings-hdr ee-admin-settings-hdr--new-feature'
77
+					   )
78
+				   ),
79
+				   'use_advanced_editor'     => new EE_Select_Input(
80
+					   apply_filters(
81
+						   'FHEE__Events_Admin_Page___default_event_settings_form__advanced_editor_input_answer_options',
82
+						   [
83
+							   esc_html__('Legacy Editor', 'event_espresso'),
84
+							   esc_html__('Advanced Editor', 'event_espresso'),
85
+						   ]
86
+					   ),
87
+					   apply_filters(
88
+						   'FHEE__Events_Admin_Page___default_event_settings_form__advanced_editor_input_settings',
89
+						   [
90
+							   'default'         => $this->admin_config->useAdvancedEditor(),
91
+							   'html_label_text' => esc_html__('Activate Advanced Editor?', 'event_espresso'),
92
+							   'html_help_text'  => sprintf(
93
+								   esc_html__(
94
+									   'Controls whether the Event Espresso Event Editor continues to use the existing legacy editor that functions like the typical older WordPress admin you are used to,%1$sor uses the new Advanced Editor with a more powerful and easier to use interface. This may be automatically turned on in order to utilize advanced features from new addons.',
95
+									   'event_espresso'
96
+								   ),
97
+								   '<br />'
98
+							   ),
99
+							   'html_class'      => 'ee-input-width--small',
100
+						   ]
101
+					   )
102
+				   ),
103
+			   ] + $default_event_settings_form_subsections;
104
+	}
105 105
 
106 106
 
107
-    /**
108
-     * @param array     $valid_data
109
-     * @param EE_Config $config
110
-     * @since 5.0.0.p
111
-     */
112
-    public function updateAdminFormSettings(array $valid_data, EE_Config $config)
113
-    {
114
-        $config->admin->setUseAdvancedEditor(
115
-            $valid_data['use_advanced_editor'] ?? false
116
-        );
117
-    }
107
+	/**
108
+	 * @param array     $valid_data
109
+	 * @param EE_Config $config
110
+	 * @since 5.0.0.p
111
+	 */
112
+	public function updateAdminFormSettings(array $valid_data, EE_Config $config)
113
+	{
114
+		$config->admin->setUseAdvancedEditor(
115
+			$valid_data['use_advanced_editor'] ?? false
116
+		);
117
+	}
118 118
 }
Please login to merge, or discard this patch.
core/domain/services/admin/registrations/list_table/QueryBuilder.php 1 patch
Indentation   +412 added lines, -412 removed lines patch added patch discarded remove patch
@@ -23,416 +23,416 @@
 block discarded – undo
23 23
  */
24 24
 class QueryBuilder
25 25
 {
26
-    protected RequestInterface $request;
27
-
28
-    protected EEM_Registration $registration_model;
29
-
30
-    protected array $filters;
31
-
32
-    protected string $view;
33
-
34
-    protected array $where_params;
35
-
36
-
37
-    /**
38
-     * QueryBuilder constructor.
39
-     *
40
-     * @param RequestInterface $request
41
-     * @param EEM_Registration $registration_model
42
-     * @param array            $extra_request_params
43
-     */
44
-    public function __construct(
45
-        RequestInterface $request,
46
-        EEM_Registration $registration_model,
47
-        array $extra_request_params = []
48
-    ) {
49
-        $this->request = $request;
50
-        $this->filters = $this->request->getRequestParam('filters', [], DataType::STRING, true);
51
-        $this->registration_model = $registration_model;
52
-        foreach ($extra_request_params as $key => $value) {
53
-            if (! $this->request->requestParamIsSet($key)) {
54
-                $this->request->setRequestParam($key, $value);
55
-            }
56
-        }
57
-        $this->view = $this->request->getRequestParam('status', '');
58
-        $this->where_params = [];
59
-    }
60
-
61
-
62
-    /**
63
-     * Sets up the where conditions for the registrations query.
64
-     *
65
-     * @param int  $per_page
66
-     * @param bool $count_query
67
-     * @return array
68
-     * @throws EE_Error
69
-     * @throws InvalidArgumentException
70
-     * @throws InvalidDataTypeException
71
-     * @throws InvalidInterfaceException
72
-     */
73
-    public function getQueryParams(int $per_page = 10, bool $count_query = false): array
74
-    {
75
-        $query_params = [
76
-            0                          => $this->getWhereClause(),
77
-            'caps'                     => EEM_Base::caps_read_admin,
78
-            'default_where_conditions' => 'this_model_only',
79
-        ];
80
-        if (! $count_query) {
81
-            $query_params = array_merge(
82
-                $query_params,
83
-                $this->getOrderbyClause(),
84
-                $this->getLimitClause($per_page)
85
-            );
86
-        }
87
-
88
-        return $query_params;
89
-    }
90
-
91
-
92
-    /**
93
-     * Sets up the where conditions for the registrations query.
94
-     *
95
-     * @return array
96
-     * @throws EE_Error
97
-     * @throws InvalidArgumentException
98
-     * @throws InvalidDataTypeException
99
-     * @throws InvalidInterfaceException
100
-     */
101
-    protected function getWhereClause(): array
102
-    {
103
-        $this->addAttendeeIdToWhereConditions();
104
-        $this->addEventIdToWhereConditions();
105
-        $this->addCategoryIdToWhereConditions();
106
-        $this->addDatetimeIdToWhereConditions();
107
-        $this->addTicketIdToWhereConditions();
108
-        $this->addRegistrationStatusToWhereConditions();
109
-        $this->addDateToWhereConditions();
110
-        $this->addSearchToWhereConditions();
111
-        return apply_filters(
112
-            'FHEE__Registrations_Admin_Page___get_where_conditions_for_registrations_query',
113
-            $this->where_params,
114
-            $this->request->requestParams()
115
-        );
116
-    }
117
-
118
-
119
-    /**
120
-     * This will add ATT_ID to the provided $this->where_clause array for EE model query parameters.
121
-     */
122
-    protected function addAttendeeIdToWhereConditions()
123
-    {
124
-        $ATT_ID = $this->request->getRequestParam('attendee_id');
125
-        $ATT_ID = $this->request->getRequestParam('ATT_ID', $ATT_ID, 'int');
126
-        if ($ATT_ID) {
127
-            $this->where_params['ATT_ID'] = $ATT_ID;
128
-        }
129
-    }
130
-
131
-
132
-    /**
133
-     * This will add EVT_ID to the provided $this->where_clause array for EE model query parameters.
134
-     */
135
-    protected function addEventIdToWhereConditions()
136
-    {
137
-        $EVT_ID = $this->request->getRequestParam('event_id');
138
-        $EVT_ID = $this->request->getRequestParam('EVT_ID', $EVT_ID, 'int');
139
-        if ($EVT_ID) {
140
-            $this->where_params['EVT_ID'] = $EVT_ID;
141
-        }
142
-    }
143
-
144
-
145
-    /**
146
-     * Adds category ID if it exists in the request to the where conditions for the registrations query.
147
-     */
148
-    protected function addCategoryIdToWhereConditions()
149
-    {
150
-        $EVT_CAT = $this->request->getRequestParam('EVT_CAT', 0, DataType::INTEGER);
151
-        $EVT_CAT = $this->filters['EVT_CAT'] ?? $EVT_CAT;
152
-        $EVT_CAT = (int) $EVT_CAT;
153
-        if ($EVT_CAT > 0) {
154
-            $this->where_params['Event.Term_Taxonomy.term_id'] = $EVT_CAT;
155
-        }
156
-    }
157
-
158
-
159
-    /**
160
-     * Adds the datetime ID if it exists in the request to the where conditions for the registrations query.
161
-     */
162
-    protected function addDatetimeIdToWhereConditions()
163
-    {
164
-        // first look for 'datetime_id' then 'DTT_ID' using first result as fallback default value
165
-        $DTT_ID = $this->request->getRequestParam('datetime_id');
166
-        $DTT_ID = $this->request->getRequestParam('DTT_ID', $DTT_ID, DataType::INTEGER);
167
-        $DTT_ID = $this->filters['datetime_id'] ?? $DTT_ID;
168
-        $DTT_ID = (int) $DTT_ID;
169
-
170
-        if ($DTT_ID) {
171
-            $this->where_params['Ticket.Datetime.DTT_ID'] = $DTT_ID;
172
-        }
173
-    }
174
-
175
-
176
-    /**
177
-     * Adds the ticket ID if it exists in the request to the where conditions for the registrations query.
178
-     */
179
-    protected function addTicketIdToWhereConditions()
180
-    {
181
-        // first look for 'ticket_id' then 'TKT_ID' using first result as fallback default value
182
-        $TKT_ID = $this->request->getRequestParam('ticket_id');
183
-        $TKT_ID = $this->request->getRequestParam('TKT_ID', $TKT_ID, DataType::INTEGER);
184
-        $TKT_ID = $this->filters['ticket_id'] ?? $TKT_ID;
185
-        $TKT_ID = (int) $TKT_ID;
186
-
187
-        if ($TKT_ID) {
188
-            $this->where_params['TKT_ID'] = $TKT_ID;
189
-        }
190
-    }
191
-
192
-
193
-    /**
194
-     * Adds the correct registration status to the where conditions for the registrations query.
195
-     * If filtering by registration status, then we show registrations matching that status.
196
-     * If not filtering by specified status, then we show all registrations excluding incomplete registrations
197
-     * UNLESS viewing trashed registrations.
198
-     */
199
-    protected function addRegistrationStatusToWhereConditions()
200
-    {
201
-        $registration_status = $this->request->getRequestParam('_reg_status');
202
-        $registration_status = $this->filters['_reg_status'] ?? $registration_status;
203
-        if ($registration_status) {
204
-            $this->where_params['STS_ID'] = sanitize_text_field($registration_status);
205
-            return;
206
-        }
207
-        // make sure we exclude incomplete registrations, but only if not trashed.
208
-        if ($this->view === 'trash') {
209
-            $this->where_params['REG_deleted'] = true;
210
-            return;
211
-        }
212
-        $this->where_params['STS_ID'] = $this->view === 'incomplete'
213
-            ? RegStatus::INCOMPLETE
214
-            : ['!=', RegStatus::INCOMPLETE];
215
-    }
216
-
217
-
218
-    /**
219
-     * Adds any provided date restraints to the where conditions for the registrations query.
220
-     *
221
-     * @throws EE_Error
222
-     * @throws InvalidArgumentException
223
-     * @throws InvalidDataTypeException
224
-     * @throws InvalidInterfaceException
225
-     */
226
-    protected function addDateToWhereConditions()
227
-    {
228
-        $current_time = current_time('timestamp');
229
-        $timezone_string = EEH_DTT_Helper::get_timezone();
230
-        if ($this->view === 'today') {
231
-            $now = date('Y-m-d', $current_time);
232
-            $this->where_params['REG_date'] = [
233
-                'BETWEEN',
234
-                [
235
-                    $this->registration_model->convert_datetime_for_query(
236
-                        'REG_date',
237
-                        $now . ' 00:00:00',
238
-                        'Y-m-d H:i:s',
239
-                        $timezone_string
240
-                    ),
241
-                    $this->registration_model->convert_datetime_for_query(
242
-                        'REG_date',
243
-                        $now . ' 23:59:59',
244
-                        'Y-m-d H:i:s',
245
-                        $timezone_string
246
-                    ),
247
-                ],
248
-            ];
249
-            return;
250
-        }
251
-        if ($this->view === 'yesterday') {
252
-            $yesterday = date('Y-m-d', $current_time - DAY_IN_SECONDS);
253
-            $this->where_params['REG_date'] = [
254
-                'BETWEEN',
255
-                [
256
-                    $this->registration_model->convert_datetime_for_query(
257
-                        'REG_date',
258
-                        $yesterday . ' 00:00:00',
259
-                        'Y-m-d H:i:s',
260
-                        $timezone_string
261
-                    ),
262
-                    $this->registration_model->convert_datetime_for_query(
263
-                        'REG_date',
264
-                        $yesterday . ' 23:59:59',
265
-                        'Y-m-d H:i:s',
266
-                        $timezone_string
267
-                    ),
268
-                ],
269
-            ];
270
-            return;
271
-        }
272
-        if ($this->view === 'month') {
273
-            $current_year_and_month = date('Y-m', $current_time);
274
-            $days_this_month = date('t', $current_time);
275
-            $this->where_params['REG_date'] = [
276
-                'BETWEEN',
277
-                [
278
-                    $this->registration_model->convert_datetime_for_query(
279
-                        'REG_date',
280
-                        $current_year_and_month . '-01 00:00:00',
281
-                        'Y-m-d H:i:s',
282
-                        $timezone_string
283
-                    ),
284
-                    $this->registration_model->convert_datetime_for_query(
285
-                        'REG_date',
286
-                        $current_year_and_month . '-' . $days_this_month . ' 23:59:59',
287
-                        'Y-m-d H:i:s',
288
-                        $timezone_string
289
-                    ),
290
-                ],
291
-            ];
292
-            return;
293
-        }
294
-        $month_range = $this->request->getRequestParam('month_range');
295
-        $month_range = $this->filters['month_range'] ?? $month_range;
296
-        if ($month_range) {
297
-            $month_range = sanitize_text_field($month_range);
298
-            $pieces = explode(' ', $month_range, 3);
299
-            $month_requested = ! empty($pieces[0])
300
-                ? date('m', EEH_DTT_Helper::first_of_month_timestamp($pieces[0]))
301
-                : '';
302
-            $year_requested = ! empty($pieces[1])
303
-                ? $pieces[1]
304
-                : '';
305
-            // if there is not a month or year then we can't go further
306
-            if ($month_requested && $year_requested) {
307
-                $days_in_month = date('t', strtotime($year_requested . '-' . $month_requested . '-' . '01'));
308
-                $this->where_params['REG_date'] = [
309
-                    'BETWEEN',
310
-                    [
311
-                        $this->registration_model->convert_datetime_for_query(
312
-                            'REG_date',
313
-                            $year_requested . '-' . $month_requested . '-01 00:00:00',
314
-                            'Y-m-d H:i:s',
315
-                            $timezone_string
316
-                        ),
317
-                        $this->registration_model->convert_datetime_for_query(
318
-                            'REG_date',
319
-                            $year_requested . '-' . $month_requested . '-' . $days_in_month . ' 23:59:59',
320
-                            'Y-m-d H:i:s',
321
-                            $timezone_string
322
-                        ),
323
-                    ],
324
-                ];
325
-            }
326
-        }
327
-    }
328
-
329
-
330
-    /**
331
-     * Adds any provided search restraints to the where conditions for the registrations query
332
-     */
333
-    protected function addSearchToWhereConditions()
334
-    {
335
-        $search = $this->request->getRequestParam('s');
336
-        if ($search) {
337
-            $search_string = '%' . sanitize_text_field($search) . '%';
338
-            $this->where_params['OR*search_conditions'] = [
339
-                'Event.EVT_name'                          => ['LIKE', $search_string],
340
-                'Event.EVT_desc'                          => ['LIKE', $search_string],
341
-                'Event.EVT_short_desc'                    => ['LIKE', $search_string],
342
-                'Attendee.ATT_full_name'                  => ['LIKE', $search_string],
343
-                'Attendee.ATT_fname'                      => ['LIKE', $search_string],
344
-                'Attendee.ATT_lname'                      => ['LIKE', $search_string],
345
-                'Attendee.ATT_short_bio'                  => ['LIKE', $search_string],
346
-                'Attendee.ATT_email'                      => ['LIKE', $search_string],
347
-                'Attendee.ATT_address'                    => ['LIKE', $search_string],
348
-                'Attendee.ATT_address2'                   => ['LIKE', $search_string],
349
-                'Attendee.ATT_city'                       => ['LIKE', $search_string],
350
-                'REG_final_price'                         => ['LIKE', $search_string],
351
-                'REG_code'                                => ['LIKE', $search_string],
352
-                'REG_count'                               => ['LIKE', $search_string],
353
-                'REG_group_size'                          => ['LIKE', $search_string],
354
-                'Ticket.TKT_name'                         => ['LIKE', $search_string],
355
-                'Ticket.TKT_description'                  => ['LIKE', $search_string],
356
-                'Transaction.Payment.PAY_txn_id_chq_nmbr' => ['LIKE', $search_string],
357
-            ];
358
-        }
359
-    }
360
-
361
-
362
-    /**
363
-     * Sets up the orderby for the registrations query.
364
-     *
365
-     * @return array
366
-     */
367
-    protected function getOrderbyClause(): array
368
-    {
369
-        $orderby_field = $this->request->getRequestParam('orderby');
370
-        $orderby_field = $orderby_field ? sanitize_text_field($orderby_field) : '_REG_date';
371
-        switch ($orderby_field) {
372
-            case '_REG_ID':
373
-                $orderby = ['REG_ID'];
374
-                break;
375
-            case '_Reg_status':
376
-                $orderby = ['STS_ID'];
377
-                break;
378
-            case 'ATT_fname':
379
-                $orderby = ['Attendee.ATT_fname', 'Attendee.ATT_lname'];
380
-                break;
381
-            case 'ATT_lname':
382
-                $orderby = ['Attendee.ATT_lname', 'Attendee.ATT_fname'];
383
-                break;
384
-            case 'event_name':
385
-                $orderby = ['Event.EVT_name'];
386
-                break;
387
-            case 'DTT_EVT_start':
388
-                $orderby = ['Event.Datetime.DTT_EVT_start'];
389
-                break;
390
-            case '_REG_date':
391
-                $orderby = ['REG_date'];
392
-                break;
393
-            default:
394
-                $orderby = [$orderby_field];
395
-                break;
396
-        }
397
-        $order = $this->request->getRequestParam('order');
398
-        $order = $order ? sanitize_text_field($order) : 'DESC';
399
-
400
-        $orderby = array_combine(
401
-            $orderby,
402
-            array_fill(0, count($orderby), $order)
403
-        );
404
-        // always add REG_count to the orderby array
405
-        $orderby['REG_count'] = 'ASC';
406
-        // because there are many registrations with the same date, define
407
-        // a secondary way to order them, otherwise MySQL seems to be a bit random
408
-        if (empty($orderby['REG_ID'])) {
409
-            $orderby['REG_ID'] = $order;
410
-        }
411
-
412
-        $orderby = apply_filters(
413
-            'FHEE__Registrations_Admin_Page___get_orderby_for_registrations_query',
414
-            $orderby,
415
-            $this->request->requestParams()
416
-        );
417
-        return ['order_by' => $orderby];
418
-    }
419
-
420
-
421
-    /**
422
-     * Sets up the limit for the registrations query.
423
-     *
424
-     * @param int $per_page
425
-     * @return array
426
-     */
427
-    protected function getLimitClause(int $per_page): array
428
-    {
429
-        $current_page = $this->request->getRequestParam('paged', 1, 'int');
430
-        $per_page = $this->request->getRequestParam('perpage', $per_page, 'int');
431
-        // -1 means return all results so get out if that's set.
432
-        if ($per_page === -1) {
433
-            return [];
434
-        }
435
-        $offset = ($current_page - 1) * $per_page;
436
-        return ['limit' => [$offset, $per_page]];
437
-    }
26
+	protected RequestInterface $request;
27
+
28
+	protected EEM_Registration $registration_model;
29
+
30
+	protected array $filters;
31
+
32
+	protected string $view;
33
+
34
+	protected array $where_params;
35
+
36
+
37
+	/**
38
+	 * QueryBuilder constructor.
39
+	 *
40
+	 * @param RequestInterface $request
41
+	 * @param EEM_Registration $registration_model
42
+	 * @param array            $extra_request_params
43
+	 */
44
+	public function __construct(
45
+		RequestInterface $request,
46
+		EEM_Registration $registration_model,
47
+		array $extra_request_params = []
48
+	) {
49
+		$this->request = $request;
50
+		$this->filters = $this->request->getRequestParam('filters', [], DataType::STRING, true);
51
+		$this->registration_model = $registration_model;
52
+		foreach ($extra_request_params as $key => $value) {
53
+			if (! $this->request->requestParamIsSet($key)) {
54
+				$this->request->setRequestParam($key, $value);
55
+			}
56
+		}
57
+		$this->view = $this->request->getRequestParam('status', '');
58
+		$this->where_params = [];
59
+	}
60
+
61
+
62
+	/**
63
+	 * Sets up the where conditions for the registrations query.
64
+	 *
65
+	 * @param int  $per_page
66
+	 * @param bool $count_query
67
+	 * @return array
68
+	 * @throws EE_Error
69
+	 * @throws InvalidArgumentException
70
+	 * @throws InvalidDataTypeException
71
+	 * @throws InvalidInterfaceException
72
+	 */
73
+	public function getQueryParams(int $per_page = 10, bool $count_query = false): array
74
+	{
75
+		$query_params = [
76
+			0                          => $this->getWhereClause(),
77
+			'caps'                     => EEM_Base::caps_read_admin,
78
+			'default_where_conditions' => 'this_model_only',
79
+		];
80
+		if (! $count_query) {
81
+			$query_params = array_merge(
82
+				$query_params,
83
+				$this->getOrderbyClause(),
84
+				$this->getLimitClause($per_page)
85
+			);
86
+		}
87
+
88
+		return $query_params;
89
+	}
90
+
91
+
92
+	/**
93
+	 * Sets up the where conditions for the registrations query.
94
+	 *
95
+	 * @return array
96
+	 * @throws EE_Error
97
+	 * @throws InvalidArgumentException
98
+	 * @throws InvalidDataTypeException
99
+	 * @throws InvalidInterfaceException
100
+	 */
101
+	protected function getWhereClause(): array
102
+	{
103
+		$this->addAttendeeIdToWhereConditions();
104
+		$this->addEventIdToWhereConditions();
105
+		$this->addCategoryIdToWhereConditions();
106
+		$this->addDatetimeIdToWhereConditions();
107
+		$this->addTicketIdToWhereConditions();
108
+		$this->addRegistrationStatusToWhereConditions();
109
+		$this->addDateToWhereConditions();
110
+		$this->addSearchToWhereConditions();
111
+		return apply_filters(
112
+			'FHEE__Registrations_Admin_Page___get_where_conditions_for_registrations_query',
113
+			$this->where_params,
114
+			$this->request->requestParams()
115
+		);
116
+	}
117
+
118
+
119
+	/**
120
+	 * This will add ATT_ID to the provided $this->where_clause array for EE model query parameters.
121
+	 */
122
+	protected function addAttendeeIdToWhereConditions()
123
+	{
124
+		$ATT_ID = $this->request->getRequestParam('attendee_id');
125
+		$ATT_ID = $this->request->getRequestParam('ATT_ID', $ATT_ID, 'int');
126
+		if ($ATT_ID) {
127
+			$this->where_params['ATT_ID'] = $ATT_ID;
128
+		}
129
+	}
130
+
131
+
132
+	/**
133
+	 * This will add EVT_ID to the provided $this->where_clause array for EE model query parameters.
134
+	 */
135
+	protected function addEventIdToWhereConditions()
136
+	{
137
+		$EVT_ID = $this->request->getRequestParam('event_id');
138
+		$EVT_ID = $this->request->getRequestParam('EVT_ID', $EVT_ID, 'int');
139
+		if ($EVT_ID) {
140
+			$this->where_params['EVT_ID'] = $EVT_ID;
141
+		}
142
+	}
143
+
144
+
145
+	/**
146
+	 * Adds category ID if it exists in the request to the where conditions for the registrations query.
147
+	 */
148
+	protected function addCategoryIdToWhereConditions()
149
+	{
150
+		$EVT_CAT = $this->request->getRequestParam('EVT_CAT', 0, DataType::INTEGER);
151
+		$EVT_CAT = $this->filters['EVT_CAT'] ?? $EVT_CAT;
152
+		$EVT_CAT = (int) $EVT_CAT;
153
+		if ($EVT_CAT > 0) {
154
+			$this->where_params['Event.Term_Taxonomy.term_id'] = $EVT_CAT;
155
+		}
156
+	}
157
+
158
+
159
+	/**
160
+	 * Adds the datetime ID if it exists in the request to the where conditions for the registrations query.
161
+	 */
162
+	protected function addDatetimeIdToWhereConditions()
163
+	{
164
+		// first look for 'datetime_id' then 'DTT_ID' using first result as fallback default value
165
+		$DTT_ID = $this->request->getRequestParam('datetime_id');
166
+		$DTT_ID = $this->request->getRequestParam('DTT_ID', $DTT_ID, DataType::INTEGER);
167
+		$DTT_ID = $this->filters['datetime_id'] ?? $DTT_ID;
168
+		$DTT_ID = (int) $DTT_ID;
169
+
170
+		if ($DTT_ID) {
171
+			$this->where_params['Ticket.Datetime.DTT_ID'] = $DTT_ID;
172
+		}
173
+	}
174
+
175
+
176
+	/**
177
+	 * Adds the ticket ID if it exists in the request to the where conditions for the registrations query.
178
+	 */
179
+	protected function addTicketIdToWhereConditions()
180
+	{
181
+		// first look for 'ticket_id' then 'TKT_ID' using first result as fallback default value
182
+		$TKT_ID = $this->request->getRequestParam('ticket_id');
183
+		$TKT_ID = $this->request->getRequestParam('TKT_ID', $TKT_ID, DataType::INTEGER);
184
+		$TKT_ID = $this->filters['ticket_id'] ?? $TKT_ID;
185
+		$TKT_ID = (int) $TKT_ID;
186
+
187
+		if ($TKT_ID) {
188
+			$this->where_params['TKT_ID'] = $TKT_ID;
189
+		}
190
+	}
191
+
192
+
193
+	/**
194
+	 * Adds the correct registration status to the where conditions for the registrations query.
195
+	 * If filtering by registration status, then we show registrations matching that status.
196
+	 * If not filtering by specified status, then we show all registrations excluding incomplete registrations
197
+	 * UNLESS viewing trashed registrations.
198
+	 */
199
+	protected function addRegistrationStatusToWhereConditions()
200
+	{
201
+		$registration_status = $this->request->getRequestParam('_reg_status');
202
+		$registration_status = $this->filters['_reg_status'] ?? $registration_status;
203
+		if ($registration_status) {
204
+			$this->where_params['STS_ID'] = sanitize_text_field($registration_status);
205
+			return;
206
+		}
207
+		// make sure we exclude incomplete registrations, but only if not trashed.
208
+		if ($this->view === 'trash') {
209
+			$this->where_params['REG_deleted'] = true;
210
+			return;
211
+		}
212
+		$this->where_params['STS_ID'] = $this->view === 'incomplete'
213
+			? RegStatus::INCOMPLETE
214
+			: ['!=', RegStatus::INCOMPLETE];
215
+	}
216
+
217
+
218
+	/**
219
+	 * Adds any provided date restraints to the where conditions for the registrations query.
220
+	 *
221
+	 * @throws EE_Error
222
+	 * @throws InvalidArgumentException
223
+	 * @throws InvalidDataTypeException
224
+	 * @throws InvalidInterfaceException
225
+	 */
226
+	protected function addDateToWhereConditions()
227
+	{
228
+		$current_time = current_time('timestamp');
229
+		$timezone_string = EEH_DTT_Helper::get_timezone();
230
+		if ($this->view === 'today') {
231
+			$now = date('Y-m-d', $current_time);
232
+			$this->where_params['REG_date'] = [
233
+				'BETWEEN',
234
+				[
235
+					$this->registration_model->convert_datetime_for_query(
236
+						'REG_date',
237
+						$now . ' 00:00:00',
238
+						'Y-m-d H:i:s',
239
+						$timezone_string
240
+					),
241
+					$this->registration_model->convert_datetime_for_query(
242
+						'REG_date',
243
+						$now . ' 23:59:59',
244
+						'Y-m-d H:i:s',
245
+						$timezone_string
246
+					),
247
+				],
248
+			];
249
+			return;
250
+		}
251
+		if ($this->view === 'yesterday') {
252
+			$yesterday = date('Y-m-d', $current_time - DAY_IN_SECONDS);
253
+			$this->where_params['REG_date'] = [
254
+				'BETWEEN',
255
+				[
256
+					$this->registration_model->convert_datetime_for_query(
257
+						'REG_date',
258
+						$yesterday . ' 00:00:00',
259
+						'Y-m-d H:i:s',
260
+						$timezone_string
261
+					),
262
+					$this->registration_model->convert_datetime_for_query(
263
+						'REG_date',
264
+						$yesterday . ' 23:59:59',
265
+						'Y-m-d H:i:s',
266
+						$timezone_string
267
+					),
268
+				],
269
+			];
270
+			return;
271
+		}
272
+		if ($this->view === 'month') {
273
+			$current_year_and_month = date('Y-m', $current_time);
274
+			$days_this_month = date('t', $current_time);
275
+			$this->where_params['REG_date'] = [
276
+				'BETWEEN',
277
+				[
278
+					$this->registration_model->convert_datetime_for_query(
279
+						'REG_date',
280
+						$current_year_and_month . '-01 00:00:00',
281
+						'Y-m-d H:i:s',
282
+						$timezone_string
283
+					),
284
+					$this->registration_model->convert_datetime_for_query(
285
+						'REG_date',
286
+						$current_year_and_month . '-' . $days_this_month . ' 23:59:59',
287
+						'Y-m-d H:i:s',
288
+						$timezone_string
289
+					),
290
+				],
291
+			];
292
+			return;
293
+		}
294
+		$month_range = $this->request->getRequestParam('month_range');
295
+		$month_range = $this->filters['month_range'] ?? $month_range;
296
+		if ($month_range) {
297
+			$month_range = sanitize_text_field($month_range);
298
+			$pieces = explode(' ', $month_range, 3);
299
+			$month_requested = ! empty($pieces[0])
300
+				? date('m', EEH_DTT_Helper::first_of_month_timestamp($pieces[0]))
301
+				: '';
302
+			$year_requested = ! empty($pieces[1])
303
+				? $pieces[1]
304
+				: '';
305
+			// if there is not a month or year then we can't go further
306
+			if ($month_requested && $year_requested) {
307
+				$days_in_month = date('t', strtotime($year_requested . '-' . $month_requested . '-' . '01'));
308
+				$this->where_params['REG_date'] = [
309
+					'BETWEEN',
310
+					[
311
+						$this->registration_model->convert_datetime_for_query(
312
+							'REG_date',
313
+							$year_requested . '-' . $month_requested . '-01 00:00:00',
314
+							'Y-m-d H:i:s',
315
+							$timezone_string
316
+						),
317
+						$this->registration_model->convert_datetime_for_query(
318
+							'REG_date',
319
+							$year_requested . '-' . $month_requested . '-' . $days_in_month . ' 23:59:59',
320
+							'Y-m-d H:i:s',
321
+							$timezone_string
322
+						),
323
+					],
324
+				];
325
+			}
326
+		}
327
+	}
328
+
329
+
330
+	/**
331
+	 * Adds any provided search restraints to the where conditions for the registrations query
332
+	 */
333
+	protected function addSearchToWhereConditions()
334
+	{
335
+		$search = $this->request->getRequestParam('s');
336
+		if ($search) {
337
+			$search_string = '%' . sanitize_text_field($search) . '%';
338
+			$this->where_params['OR*search_conditions'] = [
339
+				'Event.EVT_name'                          => ['LIKE', $search_string],
340
+				'Event.EVT_desc'                          => ['LIKE', $search_string],
341
+				'Event.EVT_short_desc'                    => ['LIKE', $search_string],
342
+				'Attendee.ATT_full_name'                  => ['LIKE', $search_string],
343
+				'Attendee.ATT_fname'                      => ['LIKE', $search_string],
344
+				'Attendee.ATT_lname'                      => ['LIKE', $search_string],
345
+				'Attendee.ATT_short_bio'                  => ['LIKE', $search_string],
346
+				'Attendee.ATT_email'                      => ['LIKE', $search_string],
347
+				'Attendee.ATT_address'                    => ['LIKE', $search_string],
348
+				'Attendee.ATT_address2'                   => ['LIKE', $search_string],
349
+				'Attendee.ATT_city'                       => ['LIKE', $search_string],
350
+				'REG_final_price'                         => ['LIKE', $search_string],
351
+				'REG_code'                                => ['LIKE', $search_string],
352
+				'REG_count'                               => ['LIKE', $search_string],
353
+				'REG_group_size'                          => ['LIKE', $search_string],
354
+				'Ticket.TKT_name'                         => ['LIKE', $search_string],
355
+				'Ticket.TKT_description'                  => ['LIKE', $search_string],
356
+				'Transaction.Payment.PAY_txn_id_chq_nmbr' => ['LIKE', $search_string],
357
+			];
358
+		}
359
+	}
360
+
361
+
362
+	/**
363
+	 * Sets up the orderby for the registrations query.
364
+	 *
365
+	 * @return array
366
+	 */
367
+	protected function getOrderbyClause(): array
368
+	{
369
+		$orderby_field = $this->request->getRequestParam('orderby');
370
+		$orderby_field = $orderby_field ? sanitize_text_field($orderby_field) : '_REG_date';
371
+		switch ($orderby_field) {
372
+			case '_REG_ID':
373
+				$orderby = ['REG_ID'];
374
+				break;
375
+			case '_Reg_status':
376
+				$orderby = ['STS_ID'];
377
+				break;
378
+			case 'ATT_fname':
379
+				$orderby = ['Attendee.ATT_fname', 'Attendee.ATT_lname'];
380
+				break;
381
+			case 'ATT_lname':
382
+				$orderby = ['Attendee.ATT_lname', 'Attendee.ATT_fname'];
383
+				break;
384
+			case 'event_name':
385
+				$orderby = ['Event.EVT_name'];
386
+				break;
387
+			case 'DTT_EVT_start':
388
+				$orderby = ['Event.Datetime.DTT_EVT_start'];
389
+				break;
390
+			case '_REG_date':
391
+				$orderby = ['REG_date'];
392
+				break;
393
+			default:
394
+				$orderby = [$orderby_field];
395
+				break;
396
+		}
397
+		$order = $this->request->getRequestParam('order');
398
+		$order = $order ? sanitize_text_field($order) : 'DESC';
399
+
400
+		$orderby = array_combine(
401
+			$orderby,
402
+			array_fill(0, count($orderby), $order)
403
+		);
404
+		// always add REG_count to the orderby array
405
+		$orderby['REG_count'] = 'ASC';
406
+		// because there are many registrations with the same date, define
407
+		// a secondary way to order them, otherwise MySQL seems to be a bit random
408
+		if (empty($orderby['REG_ID'])) {
409
+			$orderby['REG_ID'] = $order;
410
+		}
411
+
412
+		$orderby = apply_filters(
413
+			'FHEE__Registrations_Admin_Page___get_orderby_for_registrations_query',
414
+			$orderby,
415
+			$this->request->requestParams()
416
+		);
417
+		return ['order_by' => $orderby];
418
+	}
419
+
420
+
421
+	/**
422
+	 * Sets up the limit for the registrations query.
423
+	 *
424
+	 * @param int $per_page
425
+	 * @return array
426
+	 */
427
+	protected function getLimitClause(int $per_page): array
428
+	{
429
+		$current_page = $this->request->getRequestParam('paged', 1, 'int');
430
+		$per_page = $this->request->getRequestParam('perpage', $per_page, 'int');
431
+		// -1 means return all results so get out if that's set.
432
+		if ($per_page === -1) {
433
+			return [];
434
+		}
435
+		$offset = ($current_page - 1) * $per_page;
436
+		return ['limit' => [$offset, $per_page]];
437
+	}
438 438
 }
Please login to merge, or discard this patch.
core/domain/services/admin/AdminToolBar.php 2 patches
Indentation   +821 added lines, -821 removed lines patch added patch discarded remove patch
@@ -20,825 +20,825 @@
 block discarded – undo
20 20
  */
21 21
 class AdminToolBar
22 22
 {
23
-    private ?WP_Admin_Bar   $admin_bar        = null;
24
-
25
-    private EE_Capabilities $capabilities;
26
-
27
-    private string          $events_admin_url = '';
28
-
29
-    private string          $menu_class       = 'espresso_menu_item_class';
30
-
31
-    private string          $reg_admin_url    = '';
32
-
33
-
34
-    /**
35
-     * AdminToolBar constructor.
36
-     *
37
-     * @param EE_Capabilities $capabilities
38
-     */
39
-    public function __construct(EE_Capabilities $capabilities)
40
-    {
41
-        $this->capabilities = $capabilities;
42
-        add_action('admin_bar_menu', [$this, 'espressoToolbarItems'], 100);
43
-        $this->enqueueAssets();
44
-    }
45
-
46
-
47
-    /**
48
-     *    espresso_toolbar_items
49
-     *
50
-     * @access public
51
-     * @param WP_Admin_Bar $admin_bar
52
-     * @return void
53
-     */
54
-    public function espressoToolbarItems(WP_Admin_Bar $admin_bar)
55
-    {
56
-        // if it's an AJAX request, or user is NOT an admin, or in full M-Mode
57
-        if (
58
-            (defined('DOING_AJAX') && DOING_AJAX)
59
-            || ! $this->capabilities->current_user_can('ee_read_ee', 'ee_admin_bar_menu_top_level')
60
-            || MaintenanceStatus::isFullSite()
61
-        ) {
62
-            return;
63
-        }
64
-        $this->admin_bar = $admin_bar;
65
-        // we don't use the constants EVENTS_ADMIN_URL or REG_ADMIN_URL
66
-        // because they're only defined in each of their respective constructors
67
-        // and this might be a frontend request, in which case they aren't available
68
-        $this->events_admin_url = admin_url('admin.php?page=espresso_events');
69
-        $this->reg_admin_url    = admin_url('admin.php?page=espresso_registrations');
70
-        // now let's add all the menu items
71
-        $this->addTopLevelMenu();
72
-        $this->addEventsSubMenu();
73
-        $this->addEventsAddEditHeader();
74
-        $this->addEventsAddNew();
75
-        $this->addEventsEditCurrentEvent();
76
-        $this->addEventsViewHeader();
77
-        $this->addEventsViewAll();
78
-        $this->addEventsViewToday();
79
-        $this->addEventsViewThisMonth();
80
-        $this->addRegistrationSubMenu();
81
-        $this->addRegistrationOverviewToday();
82
-        $this->addRegistrationOverviewTodayApproved();
83
-        $this->addRegistrationOverviewTodayPendingPayment();
84
-        $this->addRegistrationOverviewTodayNotApproved();
85
-        $this->addRegistrationOverviewTodayCancelled();
86
-        $this->addRegistrationOverviewThisMonth();
87
-        $this->addRegistrationOverviewThisMonthApproved();
88
-        $this->addRegistrationOverviewThisMonthPending();
89
-        $this->addRegistrationOverviewThisMonthNotApproved();
90
-        $this->addRegistrationOverviewThisMonthCancelled();
91
-        $this->addExtensionsAndServices();
92
-        $this->addFontSizeSubMenu();
93
-    }
94
-
95
-
96
-    /**
97
-     * @return void
98
-     */
99
-    private function enqueueAssets()
100
-    {
101
-        wp_register_style(
102
-            'espresso-admin-toolbar',
103
-            EE_GLOBAL_ASSETS_URL . 'css/espresso-admin-toolbar.css',
104
-            ['dashicons'],
105
-            EVENT_ESPRESSO_VERSION
106
-        );
107
-        wp_enqueue_style('espresso-admin-toolbar');
108
-    }
109
-
110
-
111
-    /**
112
-     * @return void
113
-     */
114
-    private function addTopLevelMenu()
115
-    {
116
-        $this->admin_bar->add_menu(
117
-            [
118
-                'id'    => 'espresso-toolbar',
119
-                'title' => '<span class="ab-icon ee-icon ee-icon-ee-cup-thick ee-icon-size-20"></span><span class="ab-label">'
120
-                           . esc_html_x('Event Espresso', 'admin bar menu group label', 'event_espresso')
121
-                           . '</span>',
122
-                'href'  => $this->events_admin_url,
123
-                'meta'  => [
124
-                    'title' => esc_html__('Event Espresso', 'event_espresso'),
125
-                    'class' => $this->menu_class . 'first',
126
-                ],
127
-            ]
128
-        );
129
-    }
130
-
131
-
132
-    /**
133
-     * @return void
134
-     */
135
-    private function addEventsSubMenu()
136
-    {
137
-        if (
138
-            $this->capabilities->current_user_can(
139
-                'ee_read_events',
140
-                'ee_admin_bar_menu_espresso-toolbar-events'
141
-            )
142
-        ) {
143
-            $this->admin_bar->add_menu(
144
-                [
145
-                    'id'     => 'espresso-toolbar-events',
146
-                    'parent' => 'espresso-toolbar',
147
-                    'title'  => '<span class="ee-toolbar-icon"></span>'
148
-                                . esc_html__('Events', 'event_espresso'),
149
-                    'href'   => $this->events_admin_url,
150
-                    'meta'   => [
151
-                        'title'  => esc_html__('Events', 'event_espresso'),
152
-                        'target' => '',
153
-                        'class'  => $this->menu_class,
154
-                    ],
155
-                ]
156
-            );
157
-        }
158
-    }
159
-
160
-
161
-    /**
162
-     * @return void
163
-     */
164
-    private function addEventsAddEditHeader()
165
-    {
166
-        if (
167
-            $this->capabilities->current_user_can(
168
-                'ee_read_events',
169
-                'ee_admin_bar_menu_espresso-toolbar-events-view'
170
-            )
171
-        ) {
172
-            $this->admin_bar->add_menu(
173
-                [
174
-                    'id'     => 'espresso-toolbar-events-add-edit',
175
-                    'parent' => 'espresso-toolbar-events',
176
-                    'title'  => esc_html__('Add / Edit', 'event_espresso'),
177
-                    'href'   => '',
178
-                ]
179
-            );
180
-        }
181
-    }
182
-
183
-
184
-    /**
185
-     * @return void
186
-     */
187
-    private function addEventsAddNew()
188
-    {
189
-        if (
190
-            $this->capabilities->current_user_can(
191
-                'ee_edit_events',
192
-                'ee_admin_bar_menu_espresso-toolbar-events-new'
193
-            )
194
-        ) {
195
-            $this->admin_bar->add_menu(
196
-                [
197
-                    'id'     => 'espresso-toolbar-events-new',
198
-                    'parent' => 'espresso-toolbar-events',
199
-                    'title'  => '<span class="ee-toolbar-icon"></span>'
200
-                                . esc_html__('Add New', 'event_espresso'),
201
-                    'href'   => EEH_URL::add_query_args_and_nonce(
202
-                        ['action' => 'create_new'],
203
-                        $this->events_admin_url
204
-                    ),
205
-                    'meta'   => [
206
-                        'title'  => esc_html__('Add New', 'event_espresso'),
207
-                        'target' => '',
208
-                        'class'  => $this->menu_class,
209
-                    ],
210
-                ]
211
-            );
212
-        }
213
-    }
214
-
215
-
216
-    /**
217
-     * @return void
218
-     */
219
-    private function addEventsEditCurrentEvent()
220
-    {
221
-        if (is_single() && (get_post_type() === EspressoPostType::EVENTS)) {
222
-            // Current post
223
-            global $post;
224
-            if (
225
-                $this->capabilities->current_user_can(
226
-                    'ee_edit_event',
227
-                    'ee_admin_bar_menu_espresso-toolbar-events-edit',
228
-                    $post->ID
229
-                )
230
-            ) {
231
-                $this->admin_bar->add_menu(
232
-                    [
233
-                        'id'     => 'espresso-toolbar-events-edit',
234
-                        'parent' => 'espresso-toolbar-events',
235
-                        'title'  => '<span class="ee-toolbar-icon"></span>'
236
-                                    . esc_html__('Edit Event', 'event_espresso'),
237
-                        'href'   => EEH_URL::add_query_args_and_nonce(
238
-                            [
239
-                                'action' => 'edit',
240
-                                'post'   => $post->ID,
241
-                            ],
242
-                            $this->events_admin_url
243
-                        ),
244
-                        'meta'   => [
245
-                            'title'  => esc_html__('Edit Event', 'event_espresso'),
246
-                            'target' => '',
247
-                            'class'  => $this->menu_class,
248
-                        ],
249
-                    ]
250
-                );
251
-            }
252
-        }
253
-    }
254
-
255
-
256
-    /**
257
-     * @return void
258
-     */
259
-    private function addEventsViewHeader()
260
-    {
261
-        if (
262
-            $this->capabilities->current_user_can(
263
-                'ee_read_events',
264
-                'ee_admin_bar_menu_espresso-toolbar-events-view'
265
-            )
266
-        ) {
267
-            $this->admin_bar->add_menu(
268
-                [
269
-                    'id'     => 'espresso-toolbar-events-view',
270
-                    'parent' => 'espresso-toolbar-events',
271
-                    'title'  => esc_html__('View', 'event_espresso'),
272
-                    'href'   => '',
273
-                ]
274
-            );
275
-        }
276
-    }
277
-
278
-
279
-    /**
280
-     * @return void
281
-     */
282
-    private function addEventsViewAll()
283
-    {
284
-        if (
285
-            $this->capabilities->current_user_can(
286
-                'ee_read_events',
287
-                'ee_admin_bar_menu_espresso-toolbar-events-all'
288
-            )
289
-        ) {
290
-            $this->admin_bar->add_menu(
291
-                [
292
-                    'id'     => 'espresso-toolbar-events-all',
293
-                    'parent' => 'espresso-toolbar-events',
294
-                    'title'  => '<span class="ee-toolbar-icon"></span>'
295
-                                . esc_html__('All', 'event_espresso'),
296
-                    'href'   => $this->events_admin_url,
297
-                    'meta'   => [
298
-                        'title'  => esc_html__('All', 'event_espresso'),
299
-                        'target' => '',
300
-                        'class'  => $this->menu_class,
301
-                    ],
302
-                ]
303
-            );
304
-        }
305
-    }
306
-
307
-
308
-    /**
309
-     * @return void
310
-     */
311
-    private function addEventsViewToday()
312
-    {
313
-        if (
314
-            $this->capabilities->current_user_can(
315
-                'ee_read_events',
316
-                'ee_admin_bar_menu_espresso-toolbar-events-today'
317
-            )
318
-        ) {
319
-            $this->admin_bar->add_menu(
320
-                [
321
-                    'id'     => 'espresso-toolbar-events-today',
322
-                    'parent' => 'espresso-toolbar-events',
323
-                    'title'  => '<span class="ee-toolbar-icon"></span>'
324
-                                . esc_html__('Today', 'event_espresso'),
325
-                    'href'   => EEH_URL::add_query_args_and_nonce(
326
-                        [
327
-                            'action' => 'default',
328
-                            'status' => 'today',
329
-                        ],
330
-                        $this->events_admin_url
331
-                    ),
332
-                    'meta'   => [
333
-                        'title'  => esc_html__('Today', 'event_espresso'),
334
-                        'target' => '',
335
-                        'class'  => $this->menu_class,
336
-                    ],
337
-                ]
338
-            );
339
-        }
340
-    }
341
-
342
-
343
-    /**
344
-     * @return void
345
-     */
346
-    private function addEventsViewThisMonth()
347
-    {
348
-        if (
349
-            $this->capabilities->current_user_can(
350
-                'ee_read_events',
351
-                'ee_admin_bar_menu_espresso-toolbar-events-month'
352
-            )
353
-        ) {
354
-            $this->admin_bar->add_menu(
355
-                [
356
-                    'id'     => 'espresso-toolbar-events-month',
357
-                    'parent' => 'espresso-toolbar-events',
358
-                    'title'  => '<span class="ee-toolbar-icon"></span>'
359
-                                . esc_html__('This Month', 'event_espresso'),
360
-                    'href'   => EEH_URL::add_query_args_and_nonce(
361
-                        [
362
-                            'action' => 'default',
363
-                            'status' => 'month',
364
-                        ],
365
-                        $this->events_admin_url
366
-                    ),
367
-                    'meta'   => [
368
-                        'title'  => esc_html__('This Month', 'event_espresso'),
369
-                        'target' => '',
370
-                        'class'  => $this->menu_class,
371
-                    ],
372
-                ]
373
-            );
374
-        }
375
-    }
376
-
377
-
378
-    /**
379
-     * @return void
380
-     */
381
-    private function addRegistrationSubMenu()
382
-    {
383
-        if (
384
-            $this->capabilities->current_user_can(
385
-                'ee_read_registrations',
386
-                'ee_admin_bar_menu_espresso-toolbar-registrations'
387
-            )
388
-        ) {
389
-            $this->admin_bar->add_menu(
390
-                [
391
-                    'id'     => 'espresso-toolbar-registrations',
392
-                    'parent' => 'espresso-toolbar',
393
-                    'title'  => '<span class="ee-toolbar-icon"></span>'
394
-                                . esc_html__('Registrations', 'event_espresso'),
395
-                    'href'   => $this->reg_admin_url,
396
-                    'meta'   => [
397
-                        'title'  => esc_html__('Registrations', 'event_espresso'),
398
-                        'target' => '',
399
-                        'class'  => $this->menu_class,
400
-                    ],
401
-                ]
402
-            );
403
-        }
404
-    }
405
-
406
-
407
-    /**
408
-     * @return void
409
-     */
410
-    private function addRegistrationOverviewToday()
411
-    {
412
-        if (
413
-            $this->capabilities->current_user_can(
414
-                'ee_read_registrations',
415
-                'ee_admin_bar_menu_espresso-toolbar-registrations-today'
416
-            )
417
-        ) {
418
-            $this->admin_bar->add_menu(
419
-                [
420
-                    'id'     => 'espresso-toolbar-registrations-today',
421
-                    'parent' => 'espresso-toolbar-registrations',
422
-                    'title'  => esc_html__('Today', 'event_espresso'),
423
-                    'href'   => '',
424
-                    'meta'   => [
425
-                        'title'  => esc_html__('Today', 'event_espresso'),
426
-                        'target' => '',
427
-                        'class'  => $this->menu_class,
428
-                    ],
429
-                ]
430
-            );
431
-        }
432
-    }
433
-
434
-
435
-    /**
436
-     * @return void
437
-     */
438
-    private function addRegistrationOverviewTodayApproved()
439
-    {
440
-        if (
441
-            $this->capabilities->current_user_can(
442
-                'ee_read_registrations',
443
-                'ee_admin_bar_menu_espresso-toolbar-registrations-today-approved'
444
-            )
445
-        ) {
446
-            $this->admin_bar->add_menu(
447
-                [
448
-                    'id'     => 'espresso-toolbar-registrations-today-approved',
449
-                    'parent' => 'espresso-toolbar-registrations',
450
-                    'title'  => '<span class="ee-toolbar-icon"></span>'
451
-                                . esc_html__('Approved', 'event_espresso'),
452
-                    'href'   => EEH_URL::add_query_args_and_nonce(
453
-                        [
454
-                            'action'      => 'default',
455
-                            'status'      => 'today',
456
-                            '_reg_status' => RegStatus::APPROVED,
457
-                        ],
458
-                        $this->reg_admin_url
459
-                    ),
460
-                    'meta'   => [
461
-                        'title'  => esc_html__('Approved', 'event_espresso'),
462
-                        'target' => '',
463
-                        'class'  => $this->menu_class . ' ee-toolbar-icon-approved',
464
-                    ],
465
-                ]
466
-            );
467
-        }
468
-    }
469
-
470
-
471
-    /**
472
-     * @return void
473
-     */
474
-    private function addRegistrationOverviewTodayPendingPayment()
475
-    {
476
-        if (
477
-            $this->capabilities->current_user_can(
478
-                'ee_read_registrations',
479
-                'ee_admin_bar_menu_espresso-toolbar-registrations-today-pending'
480
-            )
481
-        ) {
482
-            $this->admin_bar->add_menu(
483
-                [
484
-                    'id'     => 'espresso-toolbar-registrations-today-pending',
485
-                    'parent' => 'espresso-toolbar-registrations',
486
-                    'title'  => '<span class="ee-toolbar-icon"></span>'
487
-                                . esc_html__('Pending', 'event_espresso'),
488
-                    'href'   => EEH_URL::add_query_args_and_nonce(
489
-                        [
490
-                            'action'      => 'default',
491
-                            'status'      => 'today',
492
-                            '_reg_status' => RegStatus::PENDING_PAYMENT,
493
-                        ],
494
-                        $this->reg_admin_url
495
-                    ),
496
-                    'meta'   => [
497
-                        'title'  => esc_html__('Pending Payment', 'event_espresso'),
498
-                        'target' => '',
499
-                        'class'  => $this->menu_class . ' ee-toolbar-icon-pending',
500
-                    ],
501
-                ]
502
-            );
503
-        }
504
-    }
505
-
506
-
507
-    /**
508
-     * @return void
509
-     */
510
-    private function addRegistrationOverviewTodayNotApproved()
511
-    {
512
-        if (
513
-            $this->capabilities->current_user_can(
514
-                'ee_read_registrations',
515
-                'ee_admin_bar_menu_espresso-toolbar-registrations-today-not-approved'
516
-            )
517
-        ) {
518
-            $this->admin_bar->add_menu(
519
-                [
520
-                    'id'     => 'espresso-toolbar-registrations-today-not-approved',
521
-                    'parent' => 'espresso-toolbar-registrations',
522
-                    'title'  => '<span class="ee-toolbar-icon"></span>'
523
-                                . esc_html__('Not Approved / Awaiting Review', 'event_espresso'),
524
-                    'href'   => EEH_URL::add_query_args_and_nonce(
525
-                        [
526
-                            'action'      => 'default',
527
-                            'status'      => 'today',
528
-                            '_reg_status' => RegStatus::AWAITING_REVIEW,
529
-                        ],
530
-                        $this->reg_admin_url
531
-                    ),
532
-                    'meta'   => [
533
-                        'title'  => esc_html__('Not Approved / Awaiting Review', 'event_espresso'),
534
-                        'target' => '',
535
-                        'class'  => $this->menu_class . ' ee-toolbar-icon-not-approved',
536
-                    ],
537
-                ]
538
-            );
539
-        }
540
-    }
541
-
542
-
543
-    /**
544
-     * @return void
545
-     */
546
-    private function addRegistrationOverviewTodayCancelled()
547
-    {
548
-        if (
549
-            $this->capabilities->current_user_can(
550
-                'ee_read_registrations',
551
-                'ee_admin_bar_menu_espresso-toolbar-registrations-today-cancelled'
552
-            )
553
-        ) {
554
-            $this->admin_bar->add_menu(
555
-                [
556
-                    'id'     => 'espresso-toolbar-registrations-today-cancelled',
557
-                    'parent' => 'espresso-toolbar-registrations',
558
-                    'title'  => '<span class="ee-toolbar-icon"></span>'
559
-                                . esc_html__('Cancelled', 'event_espresso'),
560
-                    'href'   => EEH_URL::add_query_args_and_nonce(
561
-                        [
562
-                            'action'      => 'default',
563
-                            'status'      => 'today',
564
-                            '_reg_status' => RegStatus::CANCELLED,
565
-                        ],
566
-                        $this->reg_admin_url
567
-                    ),
568
-                    'meta'   => [
569
-                        'title'  => esc_html__('Cancelled', 'event_espresso'),
570
-                        'target' => '',
571
-                        'class'  => $this->menu_class . ' ee-toolbar-icon-cancelled',
572
-                    ],
573
-                ]
574
-            );
575
-        }
576
-    }
577
-
578
-
579
-    /**
580
-     * @return void
581
-     */
582
-    private function addRegistrationOverviewThisMonth()
583
-    {
584
-        if (
585
-            $this->capabilities->current_user_can(
586
-                'ee_read_registrations',
587
-                'ee_admin_bar_menu_espresso-toolbar-registrations-month'
588
-            )
589
-        ) {
590
-            $this->admin_bar->add_menu(
591
-                [
592
-                    'id'     => 'espresso-toolbar-registrations-month',
593
-                    'parent' => 'espresso-toolbar-registrations',
594
-                    'title'  => esc_html__('This Month', 'event_espresso'),
595
-                    'href'   => '', // EEH_URL::add_query_args_and_nonce(
596
-                    //     array(
597
-                    //         'action' => 'default',
598
-                    //         'status' => 'month'
599
-                    //     ),
600
-                    //     $this->reg_admin_url
601
-                    // ),
602
-                    'meta'   => [
603
-                        'title'  => esc_html__('This Month', 'event_espresso'),
604
-                        'target' => '',
605
-                        'class'  => $this->menu_class,
606
-                    ],
607
-                ]
608
-            );
609
-        }
610
-    }
611
-
612
-
613
-    /**
614
-     * @return void
615
-     */
616
-    private function addRegistrationOverviewThisMonthApproved()
617
-    {
618
-        if (
619
-            $this->capabilities->current_user_can(
620
-                'ee_read_registrations',
621
-                'ee_admin_bar_menu_espresso-toolbar-registrations-month-approved'
622
-            )
623
-        ) {
624
-            $this->admin_bar->add_menu(
625
-                [
626
-                    'id'     => 'espresso-toolbar-registrations-month-approved',
627
-                    'parent' => 'espresso-toolbar-registrations',
628
-                    'title'  => '<span class="ee-toolbar-icon"></span>'
629
-                                . esc_html__('Approved', 'event_espresso'),
630
-                    'href'   => EEH_URL::add_query_args_and_nonce(
631
-                        [
632
-                            'action'      => 'default',
633
-                            'status'      => 'month',
634
-                            '_reg_status' => RegStatus::APPROVED,
635
-                        ],
636
-                        $this->reg_admin_url
637
-                    ),
638
-                    'meta'   => [
639
-                        'title'  => esc_html__('Approved', 'event_espresso'),
640
-                        'target' => '',
641
-                        'class'  => $this->menu_class . ' ee-toolbar-icon-approved',
642
-                    ],
643
-                ]
644
-            );
645
-        }
646
-    }
647
-
648
-
649
-    /**
650
-     * @return void
651
-     */
652
-    private function addRegistrationOverviewThisMonthPending()
653
-    {
654
-        if (
655
-            $this->capabilities->current_user_can(
656
-                'ee_read_registrations',
657
-                'ee_admin_bar_menu_espresso-toolbar-registrations-month-pending'
658
-            )
659
-        ) {
660
-            $this->admin_bar->add_menu(
661
-                [
662
-                    'id'     => 'espresso-toolbar-registrations-month-pending',
663
-                    'parent' => 'espresso-toolbar-registrations',
664
-                    'title'  => '<span class="ee-toolbar-icon"></span>'
665
-                                . esc_html__('Pending', 'event_espresso'),
666
-                    'href'   => EEH_URL::add_query_args_and_nonce(
667
-                        [
668
-                            'action'      => 'default',
669
-                            'status'      => 'month',
670
-                            '_reg_status' => RegStatus::PENDING_PAYMENT,
671
-                        ],
672
-                        $this->reg_admin_url
673
-                    ),
674
-                    'meta'   => [
675
-                        'title'  => esc_html__('Pending', 'event_espresso'),
676
-                        'target' => '',
677
-                        'class'  => $this->menu_class . ' ee-toolbar-icon-pending',
678
-                    ],
679
-                ]
680
-            );
681
-        }
682
-    }
683
-
684
-
685
-    /**
686
-     * @return void
687
-     */
688
-    private function addRegistrationOverviewThisMonthNotApproved()
689
-    {
690
-        if (
691
-            $this->capabilities->current_user_can(
692
-                'ee_read_registrations',
693
-                'ee_admin_bar_menu_espresso-toolbar-registrations-month-not-approved'
694
-            )
695
-        ) {
696
-            $this->admin_bar->add_menu(
697
-                [
698
-                    'id'     => 'espresso-toolbar-registrations-month-not-approved',
699
-                    'parent' => 'espresso-toolbar-registrations',
700
-                    'title'  => '<span class="ee-toolbar-icon"></span>'
701
-                                . esc_html__('Not Approved / Awaiting Review', 'event_espresso'),
702
-                    'href'   => EEH_URL::add_query_args_and_nonce(
703
-                        [
704
-                            'action'      => 'default',
705
-                            'status'      => 'month',
706
-                            '_reg_status' => RegStatus::AWAITING_REVIEW,
707
-                        ],
708
-                        $this->reg_admin_url
709
-                    ),
710
-                    'meta'   => [
711
-                        'title'  => esc_html__('Not Approved / Awaiting Review', 'event_espresso'),
712
-                        'target' => '',
713
-                        'class'  => $this->menu_class . ' ee-toolbar-icon-not-approved',
714
-                    ],
715
-                ]
716
-            );
717
-        }
718
-    }
719
-
720
-
721
-    /**
722
-     * @return void
723
-     */
724
-    private function addRegistrationOverviewThisMonthCancelled()
725
-    {
726
-        if (
727
-            $this->capabilities->current_user_can(
728
-                'ee_read_registrations',
729
-                'ee_admin_bar_menu_espresso-toolbar-registrations-month-cancelled'
730
-            )
731
-        ) {
732
-            $this->admin_bar->add_menu(
733
-                [
734
-                    'id'     => 'espresso-toolbar-registrations-month-cancelled',
735
-                    'parent' => 'espresso-toolbar-registrations',
736
-                    'title'  => '<span class="ee-toolbar-icon"></span>'
737
-                                . esc_html__('Cancelled', 'event_espresso'),
738
-                    'href'   => EEH_URL::add_query_args_and_nonce(
739
-                        [
740
-                            'action'      => 'default',
741
-                            'status'      => 'month',
742
-                            '_reg_status' => RegStatus::CANCELLED,
743
-                        ],
744
-                        $this->reg_admin_url
745
-                    ),
746
-                    'meta'   => [
747
-                        'title'  => esc_html__('Cancelled', 'event_espresso'),
748
-                        'target' => '',
749
-                        'class'  => $this->menu_class . ' ee-toolbar-icon-cancelled',
750
-                    ],
751
-                ]
752
-            );
753
-        }
754
-    }
755
-
756
-
757
-    /**
758
-     * @return void
759
-     */
760
-    private function addExtensionsAndServices()
761
-    {
762
-        if (
763
-            $this->capabilities->current_user_can(
764
-                'ee_read_ee',
765
-                'ee_admin_bar_menu_espresso-toolbar-extensions-and-services'
766
-            )
767
-        ) {
768
-            $this->admin_bar->add_menu(
769
-                [
770
-                    'id'     => 'espresso-toolbar-extensions-and-services',
771
-                    'parent' => 'espresso-toolbar',
772
-                    'title'  => '<span class="ee-toolbar-icon"></span>'
773
-                                . esc_html__('Extensions & Services', 'event_espresso'),
774
-                    'href'   => admin_url('admin.php?page=espresso_packages'),
775
-                    'meta'   => [
776
-                        'title'  => esc_html__('Extensions & Services', 'event_espresso'),
777
-                        'target' => '',
778
-                        'class'  => $this->menu_class,
779
-                    ],
780
-                ]
781
-            );
782
-        }
783
-    }
784
-
785
-
786
-    /**
787
-     * @return void
788
-     */
789
-    private function addFontSizeSubMenu()
790
-    {
791
-        if (! is_admin()) {
792
-            return;
793
-        }
794
-        $this->admin_bar->add_menu(
795
-            [
796
-                'id'     => 'espresso-toolbar-font-size',
797
-                'parent' => 'espresso-toolbar',
798
-                'title'  => '<span class="ee-toolbar-icon"></span>'
799
-                            . esc_html__('Set Font Size', 'event_espresso'),
800
-                'href'   => '',
801
-                'meta'   => [
802
-                    'title'  => esc_html__('Set Font Size', 'event_espresso'),
803
-                    'target' => '',
804
-                    'class'  => $this->menu_class,
805
-                ],
806
-            ]
807
-        );
808
-
809
-        $settings_admin_url = admin_url('admin.php?page=espresso_general_settings');
810
-
811
-        $font_sizes = [
812
-            'tiny'    => AdminFontSize::FONT_SIZE_TINY,
813
-            'smaller' => AdminFontSize::FONT_SIZE_SMALLER,
814
-            'small'   => AdminFontSize::FONT_SIZE_SMALL,
815
-            'default' => AdminFontSize::FONT_SIZE_DEFAULT,
816
-            'big'     => AdminFontSize::FONT_SIZE_BIG,
817
-            'bigger'  => AdminFontSize::FONT_SIZE_BIGGER,
818
-        ];
819
-
820
-        foreach ($font_sizes as $font_size => $value) {
821
-            $this->admin_bar->add_menu(
822
-                [
823
-                    'id'     => "espresso-toolbar-set-font-size-$font_size",
824
-                    'parent' => 'espresso-toolbar-font-size',
825
-                    'title'  => '<span class="ee-toolbar-icon"></span>'
826
-                                . sprintf(
827
-                                    /* translators: Font Size Small */
828
-                                    esc_html__('Font Size %1$s', 'event_espresso'),
829
-                                    ucwords($font_size)
830
-                                ),
831
-                    'href'   => EEH_URL::add_query_args_and_nonce(
832
-                        ['action' => 'set_font_size', 'font_size' => $value],
833
-                        $settings_admin_url
834
-                    ),
835
-                    'meta'   => [
836
-                        'title'  => esc_html__('increases or decreases the Event Espresso admin font size', 'event_espresso'),
837
-                        'target' => '',
838
-                        'class'  => $this->menu_class,
839
-                    ],
840
-                ]
841
-            );
842
-        }
843
-    }
23
+	private ?WP_Admin_Bar   $admin_bar        = null;
24
+
25
+	private EE_Capabilities $capabilities;
26
+
27
+	private string          $events_admin_url = '';
28
+
29
+	private string          $menu_class       = 'espresso_menu_item_class';
30
+
31
+	private string          $reg_admin_url    = '';
32
+
33
+
34
+	/**
35
+	 * AdminToolBar constructor.
36
+	 *
37
+	 * @param EE_Capabilities $capabilities
38
+	 */
39
+	public function __construct(EE_Capabilities $capabilities)
40
+	{
41
+		$this->capabilities = $capabilities;
42
+		add_action('admin_bar_menu', [$this, 'espressoToolbarItems'], 100);
43
+		$this->enqueueAssets();
44
+	}
45
+
46
+
47
+	/**
48
+	 *    espresso_toolbar_items
49
+	 *
50
+	 * @access public
51
+	 * @param WP_Admin_Bar $admin_bar
52
+	 * @return void
53
+	 */
54
+	public function espressoToolbarItems(WP_Admin_Bar $admin_bar)
55
+	{
56
+		// if it's an AJAX request, or user is NOT an admin, or in full M-Mode
57
+		if (
58
+			(defined('DOING_AJAX') && DOING_AJAX)
59
+			|| ! $this->capabilities->current_user_can('ee_read_ee', 'ee_admin_bar_menu_top_level')
60
+			|| MaintenanceStatus::isFullSite()
61
+		) {
62
+			return;
63
+		}
64
+		$this->admin_bar = $admin_bar;
65
+		// we don't use the constants EVENTS_ADMIN_URL or REG_ADMIN_URL
66
+		// because they're only defined in each of their respective constructors
67
+		// and this might be a frontend request, in which case they aren't available
68
+		$this->events_admin_url = admin_url('admin.php?page=espresso_events');
69
+		$this->reg_admin_url    = admin_url('admin.php?page=espresso_registrations');
70
+		// now let's add all the menu items
71
+		$this->addTopLevelMenu();
72
+		$this->addEventsSubMenu();
73
+		$this->addEventsAddEditHeader();
74
+		$this->addEventsAddNew();
75
+		$this->addEventsEditCurrentEvent();
76
+		$this->addEventsViewHeader();
77
+		$this->addEventsViewAll();
78
+		$this->addEventsViewToday();
79
+		$this->addEventsViewThisMonth();
80
+		$this->addRegistrationSubMenu();
81
+		$this->addRegistrationOverviewToday();
82
+		$this->addRegistrationOverviewTodayApproved();
83
+		$this->addRegistrationOverviewTodayPendingPayment();
84
+		$this->addRegistrationOverviewTodayNotApproved();
85
+		$this->addRegistrationOverviewTodayCancelled();
86
+		$this->addRegistrationOverviewThisMonth();
87
+		$this->addRegistrationOverviewThisMonthApproved();
88
+		$this->addRegistrationOverviewThisMonthPending();
89
+		$this->addRegistrationOverviewThisMonthNotApproved();
90
+		$this->addRegistrationOverviewThisMonthCancelled();
91
+		$this->addExtensionsAndServices();
92
+		$this->addFontSizeSubMenu();
93
+	}
94
+
95
+
96
+	/**
97
+	 * @return void
98
+	 */
99
+	private function enqueueAssets()
100
+	{
101
+		wp_register_style(
102
+			'espresso-admin-toolbar',
103
+			EE_GLOBAL_ASSETS_URL . 'css/espresso-admin-toolbar.css',
104
+			['dashicons'],
105
+			EVENT_ESPRESSO_VERSION
106
+		);
107
+		wp_enqueue_style('espresso-admin-toolbar');
108
+	}
109
+
110
+
111
+	/**
112
+	 * @return void
113
+	 */
114
+	private function addTopLevelMenu()
115
+	{
116
+		$this->admin_bar->add_menu(
117
+			[
118
+				'id'    => 'espresso-toolbar',
119
+				'title' => '<span class="ab-icon ee-icon ee-icon-ee-cup-thick ee-icon-size-20"></span><span class="ab-label">'
120
+						   . esc_html_x('Event Espresso', 'admin bar menu group label', 'event_espresso')
121
+						   . '</span>',
122
+				'href'  => $this->events_admin_url,
123
+				'meta'  => [
124
+					'title' => esc_html__('Event Espresso', 'event_espresso'),
125
+					'class' => $this->menu_class . 'first',
126
+				],
127
+			]
128
+		);
129
+	}
130
+
131
+
132
+	/**
133
+	 * @return void
134
+	 */
135
+	private function addEventsSubMenu()
136
+	{
137
+		if (
138
+			$this->capabilities->current_user_can(
139
+				'ee_read_events',
140
+				'ee_admin_bar_menu_espresso-toolbar-events'
141
+			)
142
+		) {
143
+			$this->admin_bar->add_menu(
144
+				[
145
+					'id'     => 'espresso-toolbar-events',
146
+					'parent' => 'espresso-toolbar',
147
+					'title'  => '<span class="ee-toolbar-icon"></span>'
148
+								. esc_html__('Events', 'event_espresso'),
149
+					'href'   => $this->events_admin_url,
150
+					'meta'   => [
151
+						'title'  => esc_html__('Events', 'event_espresso'),
152
+						'target' => '',
153
+						'class'  => $this->menu_class,
154
+					],
155
+				]
156
+			);
157
+		}
158
+	}
159
+
160
+
161
+	/**
162
+	 * @return void
163
+	 */
164
+	private function addEventsAddEditHeader()
165
+	{
166
+		if (
167
+			$this->capabilities->current_user_can(
168
+				'ee_read_events',
169
+				'ee_admin_bar_menu_espresso-toolbar-events-view'
170
+			)
171
+		) {
172
+			$this->admin_bar->add_menu(
173
+				[
174
+					'id'     => 'espresso-toolbar-events-add-edit',
175
+					'parent' => 'espresso-toolbar-events',
176
+					'title'  => esc_html__('Add / Edit', 'event_espresso'),
177
+					'href'   => '',
178
+				]
179
+			);
180
+		}
181
+	}
182
+
183
+
184
+	/**
185
+	 * @return void
186
+	 */
187
+	private function addEventsAddNew()
188
+	{
189
+		if (
190
+			$this->capabilities->current_user_can(
191
+				'ee_edit_events',
192
+				'ee_admin_bar_menu_espresso-toolbar-events-new'
193
+			)
194
+		) {
195
+			$this->admin_bar->add_menu(
196
+				[
197
+					'id'     => 'espresso-toolbar-events-new',
198
+					'parent' => 'espresso-toolbar-events',
199
+					'title'  => '<span class="ee-toolbar-icon"></span>'
200
+								. esc_html__('Add New', 'event_espresso'),
201
+					'href'   => EEH_URL::add_query_args_and_nonce(
202
+						['action' => 'create_new'],
203
+						$this->events_admin_url
204
+					),
205
+					'meta'   => [
206
+						'title'  => esc_html__('Add New', 'event_espresso'),
207
+						'target' => '',
208
+						'class'  => $this->menu_class,
209
+					],
210
+				]
211
+			);
212
+		}
213
+	}
214
+
215
+
216
+	/**
217
+	 * @return void
218
+	 */
219
+	private function addEventsEditCurrentEvent()
220
+	{
221
+		if (is_single() && (get_post_type() === EspressoPostType::EVENTS)) {
222
+			// Current post
223
+			global $post;
224
+			if (
225
+				$this->capabilities->current_user_can(
226
+					'ee_edit_event',
227
+					'ee_admin_bar_menu_espresso-toolbar-events-edit',
228
+					$post->ID
229
+				)
230
+			) {
231
+				$this->admin_bar->add_menu(
232
+					[
233
+						'id'     => 'espresso-toolbar-events-edit',
234
+						'parent' => 'espresso-toolbar-events',
235
+						'title'  => '<span class="ee-toolbar-icon"></span>'
236
+									. esc_html__('Edit Event', 'event_espresso'),
237
+						'href'   => EEH_URL::add_query_args_and_nonce(
238
+							[
239
+								'action' => 'edit',
240
+								'post'   => $post->ID,
241
+							],
242
+							$this->events_admin_url
243
+						),
244
+						'meta'   => [
245
+							'title'  => esc_html__('Edit Event', 'event_espresso'),
246
+							'target' => '',
247
+							'class'  => $this->menu_class,
248
+						],
249
+					]
250
+				);
251
+			}
252
+		}
253
+	}
254
+
255
+
256
+	/**
257
+	 * @return void
258
+	 */
259
+	private function addEventsViewHeader()
260
+	{
261
+		if (
262
+			$this->capabilities->current_user_can(
263
+				'ee_read_events',
264
+				'ee_admin_bar_menu_espresso-toolbar-events-view'
265
+			)
266
+		) {
267
+			$this->admin_bar->add_menu(
268
+				[
269
+					'id'     => 'espresso-toolbar-events-view',
270
+					'parent' => 'espresso-toolbar-events',
271
+					'title'  => esc_html__('View', 'event_espresso'),
272
+					'href'   => '',
273
+				]
274
+			);
275
+		}
276
+	}
277
+
278
+
279
+	/**
280
+	 * @return void
281
+	 */
282
+	private function addEventsViewAll()
283
+	{
284
+		if (
285
+			$this->capabilities->current_user_can(
286
+				'ee_read_events',
287
+				'ee_admin_bar_menu_espresso-toolbar-events-all'
288
+			)
289
+		) {
290
+			$this->admin_bar->add_menu(
291
+				[
292
+					'id'     => 'espresso-toolbar-events-all',
293
+					'parent' => 'espresso-toolbar-events',
294
+					'title'  => '<span class="ee-toolbar-icon"></span>'
295
+								. esc_html__('All', 'event_espresso'),
296
+					'href'   => $this->events_admin_url,
297
+					'meta'   => [
298
+						'title'  => esc_html__('All', 'event_espresso'),
299
+						'target' => '',
300
+						'class'  => $this->menu_class,
301
+					],
302
+				]
303
+			);
304
+		}
305
+	}
306
+
307
+
308
+	/**
309
+	 * @return void
310
+	 */
311
+	private function addEventsViewToday()
312
+	{
313
+		if (
314
+			$this->capabilities->current_user_can(
315
+				'ee_read_events',
316
+				'ee_admin_bar_menu_espresso-toolbar-events-today'
317
+			)
318
+		) {
319
+			$this->admin_bar->add_menu(
320
+				[
321
+					'id'     => 'espresso-toolbar-events-today',
322
+					'parent' => 'espresso-toolbar-events',
323
+					'title'  => '<span class="ee-toolbar-icon"></span>'
324
+								. esc_html__('Today', 'event_espresso'),
325
+					'href'   => EEH_URL::add_query_args_and_nonce(
326
+						[
327
+							'action' => 'default',
328
+							'status' => 'today',
329
+						],
330
+						$this->events_admin_url
331
+					),
332
+					'meta'   => [
333
+						'title'  => esc_html__('Today', 'event_espresso'),
334
+						'target' => '',
335
+						'class'  => $this->menu_class,
336
+					],
337
+				]
338
+			);
339
+		}
340
+	}
341
+
342
+
343
+	/**
344
+	 * @return void
345
+	 */
346
+	private function addEventsViewThisMonth()
347
+	{
348
+		if (
349
+			$this->capabilities->current_user_can(
350
+				'ee_read_events',
351
+				'ee_admin_bar_menu_espresso-toolbar-events-month'
352
+			)
353
+		) {
354
+			$this->admin_bar->add_menu(
355
+				[
356
+					'id'     => 'espresso-toolbar-events-month',
357
+					'parent' => 'espresso-toolbar-events',
358
+					'title'  => '<span class="ee-toolbar-icon"></span>'
359
+								. esc_html__('This Month', 'event_espresso'),
360
+					'href'   => EEH_URL::add_query_args_and_nonce(
361
+						[
362
+							'action' => 'default',
363
+							'status' => 'month',
364
+						],
365
+						$this->events_admin_url
366
+					),
367
+					'meta'   => [
368
+						'title'  => esc_html__('This Month', 'event_espresso'),
369
+						'target' => '',
370
+						'class'  => $this->menu_class,
371
+					],
372
+				]
373
+			);
374
+		}
375
+	}
376
+
377
+
378
+	/**
379
+	 * @return void
380
+	 */
381
+	private function addRegistrationSubMenu()
382
+	{
383
+		if (
384
+			$this->capabilities->current_user_can(
385
+				'ee_read_registrations',
386
+				'ee_admin_bar_menu_espresso-toolbar-registrations'
387
+			)
388
+		) {
389
+			$this->admin_bar->add_menu(
390
+				[
391
+					'id'     => 'espresso-toolbar-registrations',
392
+					'parent' => 'espresso-toolbar',
393
+					'title'  => '<span class="ee-toolbar-icon"></span>'
394
+								. esc_html__('Registrations', 'event_espresso'),
395
+					'href'   => $this->reg_admin_url,
396
+					'meta'   => [
397
+						'title'  => esc_html__('Registrations', 'event_espresso'),
398
+						'target' => '',
399
+						'class'  => $this->menu_class,
400
+					],
401
+				]
402
+			);
403
+		}
404
+	}
405
+
406
+
407
+	/**
408
+	 * @return void
409
+	 */
410
+	private function addRegistrationOverviewToday()
411
+	{
412
+		if (
413
+			$this->capabilities->current_user_can(
414
+				'ee_read_registrations',
415
+				'ee_admin_bar_menu_espresso-toolbar-registrations-today'
416
+			)
417
+		) {
418
+			$this->admin_bar->add_menu(
419
+				[
420
+					'id'     => 'espresso-toolbar-registrations-today',
421
+					'parent' => 'espresso-toolbar-registrations',
422
+					'title'  => esc_html__('Today', 'event_espresso'),
423
+					'href'   => '',
424
+					'meta'   => [
425
+						'title'  => esc_html__('Today', 'event_espresso'),
426
+						'target' => '',
427
+						'class'  => $this->menu_class,
428
+					],
429
+				]
430
+			);
431
+		}
432
+	}
433
+
434
+
435
+	/**
436
+	 * @return void
437
+	 */
438
+	private function addRegistrationOverviewTodayApproved()
439
+	{
440
+		if (
441
+			$this->capabilities->current_user_can(
442
+				'ee_read_registrations',
443
+				'ee_admin_bar_menu_espresso-toolbar-registrations-today-approved'
444
+			)
445
+		) {
446
+			$this->admin_bar->add_menu(
447
+				[
448
+					'id'     => 'espresso-toolbar-registrations-today-approved',
449
+					'parent' => 'espresso-toolbar-registrations',
450
+					'title'  => '<span class="ee-toolbar-icon"></span>'
451
+								. esc_html__('Approved', 'event_espresso'),
452
+					'href'   => EEH_URL::add_query_args_and_nonce(
453
+						[
454
+							'action'      => 'default',
455
+							'status'      => 'today',
456
+							'_reg_status' => RegStatus::APPROVED,
457
+						],
458
+						$this->reg_admin_url
459
+					),
460
+					'meta'   => [
461
+						'title'  => esc_html__('Approved', 'event_espresso'),
462
+						'target' => '',
463
+						'class'  => $this->menu_class . ' ee-toolbar-icon-approved',
464
+					],
465
+				]
466
+			);
467
+		}
468
+	}
469
+
470
+
471
+	/**
472
+	 * @return void
473
+	 */
474
+	private function addRegistrationOverviewTodayPendingPayment()
475
+	{
476
+		if (
477
+			$this->capabilities->current_user_can(
478
+				'ee_read_registrations',
479
+				'ee_admin_bar_menu_espresso-toolbar-registrations-today-pending'
480
+			)
481
+		) {
482
+			$this->admin_bar->add_menu(
483
+				[
484
+					'id'     => 'espresso-toolbar-registrations-today-pending',
485
+					'parent' => 'espresso-toolbar-registrations',
486
+					'title'  => '<span class="ee-toolbar-icon"></span>'
487
+								. esc_html__('Pending', 'event_espresso'),
488
+					'href'   => EEH_URL::add_query_args_and_nonce(
489
+						[
490
+							'action'      => 'default',
491
+							'status'      => 'today',
492
+							'_reg_status' => RegStatus::PENDING_PAYMENT,
493
+						],
494
+						$this->reg_admin_url
495
+					),
496
+					'meta'   => [
497
+						'title'  => esc_html__('Pending Payment', 'event_espresso'),
498
+						'target' => '',
499
+						'class'  => $this->menu_class . ' ee-toolbar-icon-pending',
500
+					],
501
+				]
502
+			);
503
+		}
504
+	}
505
+
506
+
507
+	/**
508
+	 * @return void
509
+	 */
510
+	private function addRegistrationOverviewTodayNotApproved()
511
+	{
512
+		if (
513
+			$this->capabilities->current_user_can(
514
+				'ee_read_registrations',
515
+				'ee_admin_bar_menu_espresso-toolbar-registrations-today-not-approved'
516
+			)
517
+		) {
518
+			$this->admin_bar->add_menu(
519
+				[
520
+					'id'     => 'espresso-toolbar-registrations-today-not-approved',
521
+					'parent' => 'espresso-toolbar-registrations',
522
+					'title'  => '<span class="ee-toolbar-icon"></span>'
523
+								. esc_html__('Not Approved / Awaiting Review', 'event_espresso'),
524
+					'href'   => EEH_URL::add_query_args_and_nonce(
525
+						[
526
+							'action'      => 'default',
527
+							'status'      => 'today',
528
+							'_reg_status' => RegStatus::AWAITING_REVIEW,
529
+						],
530
+						$this->reg_admin_url
531
+					),
532
+					'meta'   => [
533
+						'title'  => esc_html__('Not Approved / Awaiting Review', 'event_espresso'),
534
+						'target' => '',
535
+						'class'  => $this->menu_class . ' ee-toolbar-icon-not-approved',
536
+					],
537
+				]
538
+			);
539
+		}
540
+	}
541
+
542
+
543
+	/**
544
+	 * @return void
545
+	 */
546
+	private function addRegistrationOverviewTodayCancelled()
547
+	{
548
+		if (
549
+			$this->capabilities->current_user_can(
550
+				'ee_read_registrations',
551
+				'ee_admin_bar_menu_espresso-toolbar-registrations-today-cancelled'
552
+			)
553
+		) {
554
+			$this->admin_bar->add_menu(
555
+				[
556
+					'id'     => 'espresso-toolbar-registrations-today-cancelled',
557
+					'parent' => 'espresso-toolbar-registrations',
558
+					'title'  => '<span class="ee-toolbar-icon"></span>'
559
+								. esc_html__('Cancelled', 'event_espresso'),
560
+					'href'   => EEH_URL::add_query_args_and_nonce(
561
+						[
562
+							'action'      => 'default',
563
+							'status'      => 'today',
564
+							'_reg_status' => RegStatus::CANCELLED,
565
+						],
566
+						$this->reg_admin_url
567
+					),
568
+					'meta'   => [
569
+						'title'  => esc_html__('Cancelled', 'event_espresso'),
570
+						'target' => '',
571
+						'class'  => $this->menu_class . ' ee-toolbar-icon-cancelled',
572
+					],
573
+				]
574
+			);
575
+		}
576
+	}
577
+
578
+
579
+	/**
580
+	 * @return void
581
+	 */
582
+	private function addRegistrationOverviewThisMonth()
583
+	{
584
+		if (
585
+			$this->capabilities->current_user_can(
586
+				'ee_read_registrations',
587
+				'ee_admin_bar_menu_espresso-toolbar-registrations-month'
588
+			)
589
+		) {
590
+			$this->admin_bar->add_menu(
591
+				[
592
+					'id'     => 'espresso-toolbar-registrations-month',
593
+					'parent' => 'espresso-toolbar-registrations',
594
+					'title'  => esc_html__('This Month', 'event_espresso'),
595
+					'href'   => '', // EEH_URL::add_query_args_and_nonce(
596
+					//     array(
597
+					//         'action' => 'default',
598
+					//         'status' => 'month'
599
+					//     ),
600
+					//     $this->reg_admin_url
601
+					// ),
602
+					'meta'   => [
603
+						'title'  => esc_html__('This Month', 'event_espresso'),
604
+						'target' => '',
605
+						'class'  => $this->menu_class,
606
+					],
607
+				]
608
+			);
609
+		}
610
+	}
611
+
612
+
613
+	/**
614
+	 * @return void
615
+	 */
616
+	private function addRegistrationOverviewThisMonthApproved()
617
+	{
618
+		if (
619
+			$this->capabilities->current_user_can(
620
+				'ee_read_registrations',
621
+				'ee_admin_bar_menu_espresso-toolbar-registrations-month-approved'
622
+			)
623
+		) {
624
+			$this->admin_bar->add_menu(
625
+				[
626
+					'id'     => 'espresso-toolbar-registrations-month-approved',
627
+					'parent' => 'espresso-toolbar-registrations',
628
+					'title'  => '<span class="ee-toolbar-icon"></span>'
629
+								. esc_html__('Approved', 'event_espresso'),
630
+					'href'   => EEH_URL::add_query_args_and_nonce(
631
+						[
632
+							'action'      => 'default',
633
+							'status'      => 'month',
634
+							'_reg_status' => RegStatus::APPROVED,
635
+						],
636
+						$this->reg_admin_url
637
+					),
638
+					'meta'   => [
639
+						'title'  => esc_html__('Approved', 'event_espresso'),
640
+						'target' => '',
641
+						'class'  => $this->menu_class . ' ee-toolbar-icon-approved',
642
+					],
643
+				]
644
+			);
645
+		}
646
+	}
647
+
648
+
649
+	/**
650
+	 * @return void
651
+	 */
652
+	private function addRegistrationOverviewThisMonthPending()
653
+	{
654
+		if (
655
+			$this->capabilities->current_user_can(
656
+				'ee_read_registrations',
657
+				'ee_admin_bar_menu_espresso-toolbar-registrations-month-pending'
658
+			)
659
+		) {
660
+			$this->admin_bar->add_menu(
661
+				[
662
+					'id'     => 'espresso-toolbar-registrations-month-pending',
663
+					'parent' => 'espresso-toolbar-registrations',
664
+					'title'  => '<span class="ee-toolbar-icon"></span>'
665
+								. esc_html__('Pending', 'event_espresso'),
666
+					'href'   => EEH_URL::add_query_args_and_nonce(
667
+						[
668
+							'action'      => 'default',
669
+							'status'      => 'month',
670
+							'_reg_status' => RegStatus::PENDING_PAYMENT,
671
+						],
672
+						$this->reg_admin_url
673
+					),
674
+					'meta'   => [
675
+						'title'  => esc_html__('Pending', 'event_espresso'),
676
+						'target' => '',
677
+						'class'  => $this->menu_class . ' ee-toolbar-icon-pending',
678
+					],
679
+				]
680
+			);
681
+		}
682
+	}
683
+
684
+
685
+	/**
686
+	 * @return void
687
+	 */
688
+	private function addRegistrationOverviewThisMonthNotApproved()
689
+	{
690
+		if (
691
+			$this->capabilities->current_user_can(
692
+				'ee_read_registrations',
693
+				'ee_admin_bar_menu_espresso-toolbar-registrations-month-not-approved'
694
+			)
695
+		) {
696
+			$this->admin_bar->add_menu(
697
+				[
698
+					'id'     => 'espresso-toolbar-registrations-month-not-approved',
699
+					'parent' => 'espresso-toolbar-registrations',
700
+					'title'  => '<span class="ee-toolbar-icon"></span>'
701
+								. esc_html__('Not Approved / Awaiting Review', 'event_espresso'),
702
+					'href'   => EEH_URL::add_query_args_and_nonce(
703
+						[
704
+							'action'      => 'default',
705
+							'status'      => 'month',
706
+							'_reg_status' => RegStatus::AWAITING_REVIEW,
707
+						],
708
+						$this->reg_admin_url
709
+					),
710
+					'meta'   => [
711
+						'title'  => esc_html__('Not Approved / Awaiting Review', 'event_espresso'),
712
+						'target' => '',
713
+						'class'  => $this->menu_class . ' ee-toolbar-icon-not-approved',
714
+					],
715
+				]
716
+			);
717
+		}
718
+	}
719
+
720
+
721
+	/**
722
+	 * @return void
723
+	 */
724
+	private function addRegistrationOverviewThisMonthCancelled()
725
+	{
726
+		if (
727
+			$this->capabilities->current_user_can(
728
+				'ee_read_registrations',
729
+				'ee_admin_bar_menu_espresso-toolbar-registrations-month-cancelled'
730
+			)
731
+		) {
732
+			$this->admin_bar->add_menu(
733
+				[
734
+					'id'     => 'espresso-toolbar-registrations-month-cancelled',
735
+					'parent' => 'espresso-toolbar-registrations',
736
+					'title'  => '<span class="ee-toolbar-icon"></span>'
737
+								. esc_html__('Cancelled', 'event_espresso'),
738
+					'href'   => EEH_URL::add_query_args_and_nonce(
739
+						[
740
+							'action'      => 'default',
741
+							'status'      => 'month',
742
+							'_reg_status' => RegStatus::CANCELLED,
743
+						],
744
+						$this->reg_admin_url
745
+					),
746
+					'meta'   => [
747
+						'title'  => esc_html__('Cancelled', 'event_espresso'),
748
+						'target' => '',
749
+						'class'  => $this->menu_class . ' ee-toolbar-icon-cancelled',
750
+					],
751
+				]
752
+			);
753
+		}
754
+	}
755
+
756
+
757
+	/**
758
+	 * @return void
759
+	 */
760
+	private function addExtensionsAndServices()
761
+	{
762
+		if (
763
+			$this->capabilities->current_user_can(
764
+				'ee_read_ee',
765
+				'ee_admin_bar_menu_espresso-toolbar-extensions-and-services'
766
+			)
767
+		) {
768
+			$this->admin_bar->add_menu(
769
+				[
770
+					'id'     => 'espresso-toolbar-extensions-and-services',
771
+					'parent' => 'espresso-toolbar',
772
+					'title'  => '<span class="ee-toolbar-icon"></span>'
773
+								. esc_html__('Extensions & Services', 'event_espresso'),
774
+					'href'   => admin_url('admin.php?page=espresso_packages'),
775
+					'meta'   => [
776
+						'title'  => esc_html__('Extensions & Services', 'event_espresso'),
777
+						'target' => '',
778
+						'class'  => $this->menu_class,
779
+					],
780
+				]
781
+			);
782
+		}
783
+	}
784
+
785
+
786
+	/**
787
+	 * @return void
788
+	 */
789
+	private function addFontSizeSubMenu()
790
+	{
791
+		if (! is_admin()) {
792
+			return;
793
+		}
794
+		$this->admin_bar->add_menu(
795
+			[
796
+				'id'     => 'espresso-toolbar-font-size',
797
+				'parent' => 'espresso-toolbar',
798
+				'title'  => '<span class="ee-toolbar-icon"></span>'
799
+							. esc_html__('Set Font Size', 'event_espresso'),
800
+				'href'   => '',
801
+				'meta'   => [
802
+					'title'  => esc_html__('Set Font Size', 'event_espresso'),
803
+					'target' => '',
804
+					'class'  => $this->menu_class,
805
+				],
806
+			]
807
+		);
808
+
809
+		$settings_admin_url = admin_url('admin.php?page=espresso_general_settings');
810
+
811
+		$font_sizes = [
812
+			'tiny'    => AdminFontSize::FONT_SIZE_TINY,
813
+			'smaller' => AdminFontSize::FONT_SIZE_SMALLER,
814
+			'small'   => AdminFontSize::FONT_SIZE_SMALL,
815
+			'default' => AdminFontSize::FONT_SIZE_DEFAULT,
816
+			'big'     => AdminFontSize::FONT_SIZE_BIG,
817
+			'bigger'  => AdminFontSize::FONT_SIZE_BIGGER,
818
+		];
819
+
820
+		foreach ($font_sizes as $font_size => $value) {
821
+			$this->admin_bar->add_menu(
822
+				[
823
+					'id'     => "espresso-toolbar-set-font-size-$font_size",
824
+					'parent' => 'espresso-toolbar-font-size',
825
+					'title'  => '<span class="ee-toolbar-icon"></span>'
826
+								. sprintf(
827
+									/* translators: Font Size Small */
828
+									esc_html__('Font Size %1$s', 'event_espresso'),
829
+									ucwords($font_size)
830
+								),
831
+					'href'   => EEH_URL::add_query_args_and_nonce(
832
+						['action' => 'set_font_size', 'font_size' => $value],
833
+						$settings_admin_url
834
+					),
835
+					'meta'   => [
836
+						'title'  => esc_html__('increases or decreases the Event Espresso admin font size', 'event_espresso'),
837
+						'target' => '',
838
+						'class'  => $this->menu_class,
839
+					],
840
+				]
841
+			);
842
+		}
843
+	}
844 844
 }
Please login to merge, or discard this patch.
Spacing   +12 added lines, -12 removed lines patch added patch discarded remove patch
@@ -20,7 +20,7 @@  discard block
 block discarded – undo
20 20
  */
21 21
 class AdminToolBar
22 22
 {
23
-    private ?WP_Admin_Bar   $admin_bar        = null;
23
+    private ?WP_Admin_Bar   $admin_bar = null;
24 24
 
25 25
     private EE_Capabilities $capabilities;
26 26
 
@@ -100,7 +100,7 @@  discard block
 block discarded – undo
100 100
     {
101 101
         wp_register_style(
102 102
             'espresso-admin-toolbar',
103
-            EE_GLOBAL_ASSETS_URL . 'css/espresso-admin-toolbar.css',
103
+            EE_GLOBAL_ASSETS_URL.'css/espresso-admin-toolbar.css',
104 104
             ['dashicons'],
105 105
             EVENT_ESPRESSO_VERSION
106 106
         );
@@ -122,7 +122,7 @@  discard block
 block discarded – undo
122 122
                 'href'  => $this->events_admin_url,
123 123
                 'meta'  => [
124 124
                     'title' => esc_html__('Event Espresso', 'event_espresso'),
125
-                    'class' => $this->menu_class . 'first',
125
+                    'class' => $this->menu_class.'first',
126 126
                 ],
127 127
             ]
128 128
         );
@@ -460,7 +460,7 @@  discard block
 block discarded – undo
460 460
                     'meta'   => [
461 461
                         'title'  => esc_html__('Approved', 'event_espresso'),
462 462
                         'target' => '',
463
-                        'class'  => $this->menu_class . ' ee-toolbar-icon-approved',
463
+                        'class'  => $this->menu_class.' ee-toolbar-icon-approved',
464 464
                     ],
465 465
                 ]
466 466
             );
@@ -496,7 +496,7 @@  discard block
 block discarded – undo
496 496
                     'meta'   => [
497 497
                         'title'  => esc_html__('Pending Payment', 'event_espresso'),
498 498
                         'target' => '',
499
-                        'class'  => $this->menu_class . ' ee-toolbar-icon-pending',
499
+                        'class'  => $this->menu_class.' ee-toolbar-icon-pending',
500 500
                     ],
501 501
                 ]
502 502
             );
@@ -532,7 +532,7 @@  discard block
 block discarded – undo
532 532
                     'meta'   => [
533 533
                         'title'  => esc_html__('Not Approved / Awaiting Review', 'event_espresso'),
534 534
                         'target' => '',
535
-                        'class'  => $this->menu_class . ' ee-toolbar-icon-not-approved',
535
+                        'class'  => $this->menu_class.' ee-toolbar-icon-not-approved',
536 536
                     ],
537 537
                 ]
538 538
             );
@@ -568,7 +568,7 @@  discard block
 block discarded – undo
568 568
                     'meta'   => [
569 569
                         'title'  => esc_html__('Cancelled', 'event_espresso'),
570 570
                         'target' => '',
571
-                        'class'  => $this->menu_class . ' ee-toolbar-icon-cancelled',
571
+                        'class'  => $this->menu_class.' ee-toolbar-icon-cancelled',
572 572
                     ],
573 573
                 ]
574 574
             );
@@ -638,7 +638,7 @@  discard block
 block discarded – undo
638 638
                     'meta'   => [
639 639
                         'title'  => esc_html__('Approved', 'event_espresso'),
640 640
                         'target' => '',
641
-                        'class'  => $this->menu_class . ' ee-toolbar-icon-approved',
641
+                        'class'  => $this->menu_class.' ee-toolbar-icon-approved',
642 642
                     ],
643 643
                 ]
644 644
             );
@@ -674,7 +674,7 @@  discard block
 block discarded – undo
674 674
                     'meta'   => [
675 675
                         'title'  => esc_html__('Pending', 'event_espresso'),
676 676
                         'target' => '',
677
-                        'class'  => $this->menu_class . ' ee-toolbar-icon-pending',
677
+                        'class'  => $this->menu_class.' ee-toolbar-icon-pending',
678 678
                     ],
679 679
                 ]
680 680
             );
@@ -710,7 +710,7 @@  discard block
 block discarded – undo
710 710
                     'meta'   => [
711 711
                         'title'  => esc_html__('Not Approved / Awaiting Review', 'event_espresso'),
712 712
                         'target' => '',
713
-                        'class'  => $this->menu_class . ' ee-toolbar-icon-not-approved',
713
+                        'class'  => $this->menu_class.' ee-toolbar-icon-not-approved',
714 714
                     ],
715 715
                 ]
716 716
             );
@@ -746,7 +746,7 @@  discard block
 block discarded – undo
746 746
                     'meta'   => [
747 747
                         'title'  => esc_html__('Cancelled', 'event_espresso'),
748 748
                         'target' => '',
749
-                        'class'  => $this->menu_class . ' ee-toolbar-icon-cancelled',
749
+                        'class'  => $this->menu_class.' ee-toolbar-icon-cancelled',
750 750
                     ],
751 751
                 ]
752 752
             );
@@ -788,7 +788,7 @@  discard block
 block discarded – undo
788 788
      */
789 789
     private function addFontSizeSubMenu()
790 790
     {
791
-        if (! is_admin()) {
791
+        if ( ! is_admin()) {
792 792
             return;
793 793
         }
794 794
         $this->admin_bar->add_menu(
Please login to merge, or discard this patch.
core/domain/services/admin/menu/AdminMenuManager.php 1 patch
Indentation   +430 added lines, -430 removed lines patch added patch discarded remove patch
@@ -15,434 +15,434 @@
 block discarded – undo
15 15
 
16 16
 class AdminMenuManager
17 17
 {
18
-    /**
19
-     * Default: null - defaults to below Comments
20
-     *
21
-     * 5 - below Posts
22
-     * 10 - below Media
23
-     * 15 - below Links
24
-     * 20 - below Pages
25
-     * 25 - below comments
26
-     * 60 - below first separator
27
-     * 65 - below Plugins
28
-     * 70 - below Users
29
-     * 75 - below Tools
30
-     * 80 - below Settings
31
-     * 100 - below second separator
32
-     */
33
-    const DEFAULT_MENU_POSITION = 100;
34
-
35
-
36
-    /**
37
-     * @var AdminMenuItem[]
38
-     */
39
-    private array $menu_items = [];
40
-
41
-    /**
42
-     * objects for page_init objects detected and loaded
43
-     *
44
-     * @var EE_Admin_Page_Init[]
45
-     */
46
-    private array $installed_pages = [];
47
-
48
-    /**
49
-     * set to TRUE if site is currently in maintenance mode level 2
50
-     *
51
-     * @var bool
52
-     */
53
-    protected bool $maintenance_mode = false;
54
-
55
-    /**
56
-     * same values used by AdminMenuManager::DEFAULT_MENU_POSITION
57
-     *
58
-     * @var int
59
-     */
60
-    private int $menu_position;
61
-
62
-    /**
63
-     * @var AdminMenuItem
64
-     */
65
-    private AdminMenuItem $top_level_menu_item;
66
-
67
-
68
-    public function __construct()
69
-    {
70
-    }
71
-
72
-
73
-    public function initialize()
74
-    {
75
-        $this->maintenance_mode = MaintenanceStatus::isFullSite();
76
-        $this->menu_position = apply_filters(
77
-            'FHEE__EventEspresso_core_domain_services_admin_menu_AdminMenuManager__initialize__menu_position',
78
-            AdminMenuManager::DEFAULT_MENU_POSITION,
79
-            $this->maintenance_mode
80
-        );
81
-        $this->addTopLevelMenuItem();
82
-        $this->initializeMenuGroups();
83
-        add_action('admin_menu', [$this, 'generateAdminMenu']);
84
-        add_action('network_admin_menu', [$this, 'generateNetworkAdminMenu']);
85
-        add_filter('custom_menu_order', '__return_true');
86
-        add_filter('menu_order', [$this, 'reorderAdminMenu']);
87
-    }
88
-
89
-
90
-    /**
91
-     * adds the top level menu item that everything else descends from.
92
-     * changes depending on whether site is in full maintenance mode or not
93
-     *
94
-     * @return void
95
-     */
96
-    private function addTopLevelMenuItem()
97
-    {
98
-        $this->top_level_menu_item = $this->maintenance_mode
99
-            ? $this->instantiateAdminMenu(
100
-                [
101
-                    'menu_slug'    => 'espresso_maintenance_settings',
102
-                    'menu_label'   => esc_html__('Event Espresso', 'event_espresso'),
103
-                    'capability'   => 'manage_options',
104
-                    'menu_group'   => 'main',
105
-                    'menu_order'   => 10,
106
-                    'menu_type'    => AdminMenuItem::TYPE_MENU_TOP,
107
-                    'parent_slug'  => 'espresso_maintenance_settings',
108
-                    'show_on_menu' => AdminMenuItem::DISPLAY_BLOG_ONLY,
109
-                ]
110
-            )
111
-            : $this->instantiateAdminMenu(
112
-                [
113
-                    'menu_slug'    => 'espresso_events',
114
-                    'menu_label'   => esc_html__('Event Espresso', 'event_espresso'),
115
-                    'capability'   => 'ee_read_events',
116
-                    'menu_group'   => 'main',
117
-                    'menu_order'   => 10,
118
-                    'menu_type'    => AdminMenuItem::TYPE_MENU_TOP,
119
-                    'parent_slug'  => 'espresso_events',
120
-                    'show_on_menu' => AdminMenuItem::DISPLAY_BLOG_ONLY,
121
-                ]
122
-            );
123
-    }
124
-
125
-
126
-    /**
127
-     * sets the filterable _admin_menu_groups property (list of various "groupings" within the EE admin menu array)
128
-     *
129
-     * @return void
130
-     */
131
-    private function initializeMenuGroups()
132
-    {
133
-        $this->menu_items = apply_filters(
134
-            'FHEE__EE_Admin_Page_Loader___set_menu_groups__admin_menu_groups',
135
-            [
136
-                'main'       => $this->instantiateAdminMenu(
137
-                    [
138
-                        'menu_slug'               => 'main',
139
-                        'menu_label'              => esc_html__('Main', 'event_espresso'),
140
-                        'capability'              => $this->maintenance_mode ? 'manage_options' : 'ee_read_ee',
141
-                        'maintenance_mode_parent' => 'espresso_maintenance_settings',
142
-                        'menu_order'              => 0,
143
-                        'parent_slug'             => 'espresso_events',
144
-                        'show_on_menu'            => AdminMenuItem::DISPLAY_NONE,
145
-                    ]
146
-                ),
147
-                'management' => $this->instantiateAdminMenu(
148
-                    [
149
-                        'menu_slug'    => 'management',
150
-                        'menu_label'   => esc_html__('Management', 'event_espresso'),
151
-                        'capability'   => 'ee_read_ee',
152
-                        'menu_order'   => 10,
153
-                        'parent_slug'  => 'espresso_events',
154
-                        'show_on_menu' => AdminMenuItem::DISPLAY_BLOG_ONLY,
155
-                    ]
156
-                ),
157
-                'addons'     => $this->instantiateAdminMenu(
158
-                    [
159
-                        'menu_slug'    => 'addons',
160
-                        'menu_label'   => esc_html__('Add-ons', 'event_espresso'),
161
-                        'capability'   => 'ee_read_ee',
162
-                        'menu_order'   => 20,
163
-                        'parent_slug'  => 'espresso_events',
164
-                        'show_on_menu' => AdminMenuItem::DISPLAY_BLOG_AND_NETWORK,
165
-                    ]
166
-                ),
167
-                'settings'   => $this->instantiateAdminMenu(
168
-                    [
169
-                        'menu_slug'    => 'settings',
170
-                        'menu_label'   => esc_html__('Settings', 'event_espresso'),
171
-                        'capability'   => 'ee_read_ee',
172
-                        'menu_order'   => 30,
173
-                        'parent_slug'  => 'espresso_events',
174
-                        'show_on_menu' => AdminMenuItem::DISPLAY_BLOG_ONLY,
175
-                    ]
176
-                ),
177
-                'templates'  => $this->instantiateAdminMenu(
178
-                    [
179
-                        'menu_slug'    => 'templates',
180
-                        'menu_label'   => esc_html__('Templates', 'event_espresso'),
181
-                        'capability'   => 'ee_read_ee',
182
-                        'menu_order'   => 40,
183
-                        'parent_slug'  => 'espresso_events',
184
-                        'show_on_menu' => AdminMenuItem::DISPLAY_BLOG_ONLY,
185
-                    ]
186
-                ),
187
-                'extras'     => $this->instantiateAdminMenu(
188
-                    [
189
-                        'menu_slug'               => 'extras',
190
-                        'menu_label'              => esc_html__('Extras', 'event_espresso'),
191
-                        'capability'              => 'ee_read_ee',
192
-                        'maintenance_mode_parent' => 'espresso_maintenance_settings',
193
-                        'menu_order'              => 50,
194
-                        'parent_slug'             => 'espresso_events',
195
-                        'show_on_menu'            => AdminMenuItem::DISPLAY_BLOG_AND_NETWORK,
196
-                    ]
197
-                ),
198
-                'tools'      => $this->instantiateAdminMenu(
199
-                    [
200
-                        'menu_slug'    => 'tools',
201
-                        'menu_label'   => esc_html__('Tools', 'event_espresso'),
202
-                        'capability'   => 'ee_read_ee',
203
-                        'menu_order'   => 60,
204
-                        'parent_slug'  => 'espresso_events',
205
-                        'show_on_menu' => AdminMenuItem::DISPLAY_BLOG_ONLY,
206
-                    ]
207
-                ),
208
-            ]
209
-        );
210
-    }
211
-
212
-
213
-    /**
214
-     * adds an AdminMenuItem
215
-     *
216
-     * @param AdminMenuItem $admin_menu_item
217
-     * @return AdminMenuItem
218
-     */
219
-    public function addAdminMenuItem(AdminMenuItem $admin_menu_item): AdminMenuItem
220
-    {
221
-        // get the menu group that this menu item belongs to and then add it
222
-        $admin_group = $this->getMenuGroup($admin_menu_item);
223
-        $admin_group->addMenuItem($admin_menu_item);
224
-        return $admin_menu_item;
225
-    }
226
-
227
-
228
-    /**
229
-     * instantiates and returns the appropriate AdminMenuItem for the provided EE_Admin_Page_Init
230
-     *
231
-     * @param EE_Admin_Page_Init $admin_page_init
232
-     * @return AdminMenuItem
233
-     */
234
-    public function getAdminMenu(EE_Admin_Page_Init $admin_page_init): AdminMenuItem
235
-    {
236
-        // see if admin page init is using new classes
237
-        $menu_properties = $admin_page_init->getMenuProperties();
238
-        if (empty($menu_properties)) {
239
-            // no? ok setup the admin menu item the old way
240
-            $admin_page_init->setupLegacyAdminMenuItem();
241
-        } else {
242
-            // adding the admin page init callback here means the menu doesn't have to cart that object around
243
-            $menu_properties['menu_callback'] = [$admin_page_init, 'initialize_admin_page'];
244
-            $admin_page_init->setAdminMenu($this->instantiateAdminMenu($menu_properties));
245
-        }
246
-        $admin_menu = $admin_page_init->adminMenu();
247
-        if (! $admin_menu instanceof AdminMenuItem) {
248
-            throw new DomainException(esc_html__('Invalid AdminMenuItem', 'event_espresso'));
249
-        }
250
-        if (! is_callable($admin_menu->menuCallback())) {
251
-            $admin_menu->setMenuCallback([$admin_page_init, 'initialize_admin_page']);
252
-        }
253
-        // get the menu group that this menu item belongs to and then add it
254
-        $admin_group = $this->getMenuGroup($admin_menu);
255
-        $admin_group->addMenuItem($admin_menu);
256
-        return $admin_menu;
257
-    }
258
-
259
-
260
-    /**
261
-     * @param array $menu_properties
262
-     * @return AdminMenuItem|null
263
-     */
264
-    private function instantiateAdminMenu(array $menu_properties): ?AdminMenuItem
265
-    {
266
-        $type = $menu_properties['menu_type'] ?? AdminMenuItem::TYPE_MENU_GROUP;
267
-        unset($menu_properties['menu_type']);
268
-        switch ($type) {
269
-            case AdminMenuItem::TYPE_MENU_GROUP:
270
-                unset($menu_properties['menu_callback']);
271
-                return new AdminMenuGroup($menu_properties);
272
-            case AdminMenuItem::TYPE_MENU_TOP:
273
-                return new AdminMenuTopLevel($menu_properties);
274
-            case AdminMenuItem::TYPE_MENU_SUB_ITEM:
275
-                return new AdminMenuSubItem($menu_properties);
276
-        }
277
-        return null;
278
-    }
279
-
280
-
281
-    /**
282
-     * @param AdminMenuItem $admin_menu
283
-     * @return AdminMenuGroup
284
-     * @throws DomainException
285
-     * @throws OutOfRangeException
286
-     */
287
-    private function getMenuGroup(AdminMenuItem $admin_menu): AdminMenuGroup
288
-    {
289
-        if (! isset($this->menu_items[ $admin_menu->menuGroup() ])) {
290
-            throw new OutOfRangeException(esc_html__('AdminMenuGroup does not exist', 'event_espresso'));
291
-        }
292
-        $admin_group = $this->menu_items[ $admin_menu->menuGroup() ];
293
-        if (! $admin_group instanceof AdminMenuGroup) {
294
-            throw new DomainException(esc_html__('Invalid AdminMenuGroup found', 'event_espresso'));
295
-        }
296
-        return $admin_group;
297
-    }
298
-
299
-
300
-    /**
301
-     * set_network_menus
302
-     * This method sets up the menus for network EE Admin Pages.
303
-     * Almost identical to EE_Admin_Page_Loader::set_menus() except pages
304
-     * are only added to the menu map if they are intended for the admin menu
305
-     *
306
-     * @return void
307
-     * @throws DomainException
308
-     */
309
-    public function generateNetworkAdminMenu()
310
-    {
311
-        $this->generateAdminMenu(true);
312
-    }
313
-
314
-
315
-    /**
316
-     * This method sets up the menus for EE Admin Pages
317
-     *
318
-     * @return void
319
-     * @throws DomainException
320
-     */
321
-    public function generateAdminMenu(bool $network_admin = false)
322
-    {
323
-        $admin_menu = $this->sortMenu($this->menu_items);
324
-        $this->top_level_menu_item->registerAdminMenuItem($network_admin);
325
-        $this->registerAdminMenu($admin_menu, $network_admin);
326
-    }
327
-
328
-
329
-    /**
330
-     * @param array $admin_menu
331
-     * @param bool  $network_admin
332
-     */
333
-    private function registerAdminMenu(array $admin_menu, bool $network_admin)
334
-    {
335
-        foreach ($admin_menu as $menu_item) {
336
-            if ($this->skipMenuItem($menu_item)) {
337
-                continue;
338
-            }
339
-            try {
340
-                $wp_page_slug    = $menu_item->registerAdminMenuItem($network_admin);
341
-                $admin_init_page = $this->installed_pages[ $menu_item->menuSlug() ] ?? null;
342
-                if ($wp_page_slug && $admin_init_page instanceof EE_Admin_Page_Init) {
343
-                    $admin_init_page->setWpPageSlug($wp_page_slug);
344
-                    $admin_init_page->set_page_dependencies($wp_page_slug);
345
-                }
346
-                if ($menu_item instanceof AdminMenuGroup) {
347
-                    $this->registerAdminMenu($menu_item->getMenuItems(), $network_admin);
348
-                }
349
-            } catch (Exception $e) {
350
-                EE_Error::add_error($e->getMessage(), $e->getFile(), __FUNCTION__, $e->getLine());
351
-            }
352
-        }
353
-    }
354
-
355
-
356
-    /**
357
-     * returns TRUE if any of the following conditions is met:
358
-     * - menu item is NOT an instanceof AdminMenuItem
359
-     * - menu item has already been registered
360
-     * - menu item should not be shown when site is in full maintenance mode
361
-     * - current user does not have the required access permission
362
-     * - menu item is a group but has no sub items
363
-     *
364
-     * @param AdminMenuItem|null $menu_item
365
-     * @return bool
366
-     */
367
-    private function skipMenuItem(?AdminMenuItem $menu_item): bool
368
-    {
369
-        return ! $menu_item instanceof AdminMenuItem
370
-               || $menu_item->isRegistered()
371
-               || ! $menu_item->showOnMaintenanceModeMenu()
372
-               || ! $menu_item->currentUserHasAccess()
373
-               || (
374
-                   $menu_item instanceof AdminMenuGroup
375
-                   && $menu_item->hasNoMenuItems()
376
-               );
377
-    }
378
-
379
-
380
-    /**
381
-     * @param EE_Admin_Page_Init[] $installed_pages
382
-     */
383
-    public function setInstalledPages(array $installed_pages): void
384
-    {
385
-        $this->installed_pages = $installed_pages;
386
-    }
387
-
388
-
389
-    /**
390
-     * Recursively sort menu groups and their sub items
391
-     *
392
-     * @return AdminMenuItem[]
393
-     * @throws DomainException
394
-     */
395
-    public function sortMenu(array $admin_menu): array
396
-    {
397
-        foreach ($admin_menu as $menu_group) {
398
-            if (! $menu_group instanceof AdminMenuItem) {
399
-                throw new DomainException(esc_html__('Invalid AdminMenuItem', 'event_espresso'));
400
-            }
401
-            if ($menu_group instanceof AdminMenuGroup) {
402
-                // sort sub items
403
-                $menu_items = $this->sortMenu($menu_group->getMenuItems());
404
-                $menu_group->setMenuItems($menu_items);
405
-            }
406
-        }
407
-        // sort incoming array AFTER it's been looped through and elements have been validated
408
-        usort($admin_menu, [$this, 'sortMenuItems']);
409
-        return $admin_menu;
410
-    }
411
-
412
-
413
-    /**
414
-     *  sort sub menu items
415
-     *
416
-     * @param AdminMenuItem $a menu_item
417
-     * @param AdminMenuItem $b being compared to
418
-     * @return int    sort order
419
-     */
420
-    private function sortMenuItems(AdminMenuItem $a, AdminMenuItem $b): int
421
-    {
422
-        if ($a->menuOrder() === $b->menuOrder()) {
423
-            return 0;
424
-        }
425
-        return $a->menuOrder() < $b->menuOrder() ? -1 : 1;
426
-    }
427
-
428
-
429
-    /**
430
-     * Moves the Event Espresso admin menu to the position set by $this->menu_position
431
-     *
432
-     * @param array $menu_order
433
-     * @return array
434
-     */
435
-    public function reorderAdminMenu(array $menu_order): array
436
-    {
437
-        $menu_slug     = $this->maintenance_mode ? 'espresso_maintenance_settings' : 'espresso_events';
438
-        $current_index = array_search($menu_slug, $menu_order);
439
-        if ($current_index === false) {
440
-            return $menu_order;
441
-        }
442
-        // chop out the espresso admin menu if found
443
-        $espresso_menu = array_splice($menu_order, $current_index, 1);
444
-        // reinsert at position set by $this->menu_position
445
-        array_splice($menu_order, $this->menu_position, 0, $espresso_menu);
446
-        return $menu_order;
447
-    }
18
+	/**
19
+	 * Default: null - defaults to below Comments
20
+	 *
21
+	 * 5 - below Posts
22
+	 * 10 - below Media
23
+	 * 15 - below Links
24
+	 * 20 - below Pages
25
+	 * 25 - below comments
26
+	 * 60 - below first separator
27
+	 * 65 - below Plugins
28
+	 * 70 - below Users
29
+	 * 75 - below Tools
30
+	 * 80 - below Settings
31
+	 * 100 - below second separator
32
+	 */
33
+	const DEFAULT_MENU_POSITION = 100;
34
+
35
+
36
+	/**
37
+	 * @var AdminMenuItem[]
38
+	 */
39
+	private array $menu_items = [];
40
+
41
+	/**
42
+	 * objects for page_init objects detected and loaded
43
+	 *
44
+	 * @var EE_Admin_Page_Init[]
45
+	 */
46
+	private array $installed_pages = [];
47
+
48
+	/**
49
+	 * set to TRUE if site is currently in maintenance mode level 2
50
+	 *
51
+	 * @var bool
52
+	 */
53
+	protected bool $maintenance_mode = false;
54
+
55
+	/**
56
+	 * same values used by AdminMenuManager::DEFAULT_MENU_POSITION
57
+	 *
58
+	 * @var int
59
+	 */
60
+	private int $menu_position;
61
+
62
+	/**
63
+	 * @var AdminMenuItem
64
+	 */
65
+	private AdminMenuItem $top_level_menu_item;
66
+
67
+
68
+	public function __construct()
69
+	{
70
+	}
71
+
72
+
73
+	public function initialize()
74
+	{
75
+		$this->maintenance_mode = MaintenanceStatus::isFullSite();
76
+		$this->menu_position = apply_filters(
77
+			'FHEE__EventEspresso_core_domain_services_admin_menu_AdminMenuManager__initialize__menu_position',
78
+			AdminMenuManager::DEFAULT_MENU_POSITION,
79
+			$this->maintenance_mode
80
+		);
81
+		$this->addTopLevelMenuItem();
82
+		$this->initializeMenuGroups();
83
+		add_action('admin_menu', [$this, 'generateAdminMenu']);
84
+		add_action('network_admin_menu', [$this, 'generateNetworkAdminMenu']);
85
+		add_filter('custom_menu_order', '__return_true');
86
+		add_filter('menu_order', [$this, 'reorderAdminMenu']);
87
+	}
88
+
89
+
90
+	/**
91
+	 * adds the top level menu item that everything else descends from.
92
+	 * changes depending on whether site is in full maintenance mode or not
93
+	 *
94
+	 * @return void
95
+	 */
96
+	private function addTopLevelMenuItem()
97
+	{
98
+		$this->top_level_menu_item = $this->maintenance_mode
99
+			? $this->instantiateAdminMenu(
100
+				[
101
+					'menu_slug'    => 'espresso_maintenance_settings',
102
+					'menu_label'   => esc_html__('Event Espresso', 'event_espresso'),
103
+					'capability'   => 'manage_options',
104
+					'menu_group'   => 'main',
105
+					'menu_order'   => 10,
106
+					'menu_type'    => AdminMenuItem::TYPE_MENU_TOP,
107
+					'parent_slug'  => 'espresso_maintenance_settings',
108
+					'show_on_menu' => AdminMenuItem::DISPLAY_BLOG_ONLY,
109
+				]
110
+			)
111
+			: $this->instantiateAdminMenu(
112
+				[
113
+					'menu_slug'    => 'espresso_events',
114
+					'menu_label'   => esc_html__('Event Espresso', 'event_espresso'),
115
+					'capability'   => 'ee_read_events',
116
+					'menu_group'   => 'main',
117
+					'menu_order'   => 10,
118
+					'menu_type'    => AdminMenuItem::TYPE_MENU_TOP,
119
+					'parent_slug'  => 'espresso_events',
120
+					'show_on_menu' => AdminMenuItem::DISPLAY_BLOG_ONLY,
121
+				]
122
+			);
123
+	}
124
+
125
+
126
+	/**
127
+	 * sets the filterable _admin_menu_groups property (list of various "groupings" within the EE admin menu array)
128
+	 *
129
+	 * @return void
130
+	 */
131
+	private function initializeMenuGroups()
132
+	{
133
+		$this->menu_items = apply_filters(
134
+			'FHEE__EE_Admin_Page_Loader___set_menu_groups__admin_menu_groups',
135
+			[
136
+				'main'       => $this->instantiateAdminMenu(
137
+					[
138
+						'menu_slug'               => 'main',
139
+						'menu_label'              => esc_html__('Main', 'event_espresso'),
140
+						'capability'              => $this->maintenance_mode ? 'manage_options' : 'ee_read_ee',
141
+						'maintenance_mode_parent' => 'espresso_maintenance_settings',
142
+						'menu_order'              => 0,
143
+						'parent_slug'             => 'espresso_events',
144
+						'show_on_menu'            => AdminMenuItem::DISPLAY_NONE,
145
+					]
146
+				),
147
+				'management' => $this->instantiateAdminMenu(
148
+					[
149
+						'menu_slug'    => 'management',
150
+						'menu_label'   => esc_html__('Management', 'event_espresso'),
151
+						'capability'   => 'ee_read_ee',
152
+						'menu_order'   => 10,
153
+						'parent_slug'  => 'espresso_events',
154
+						'show_on_menu' => AdminMenuItem::DISPLAY_BLOG_ONLY,
155
+					]
156
+				),
157
+				'addons'     => $this->instantiateAdminMenu(
158
+					[
159
+						'menu_slug'    => 'addons',
160
+						'menu_label'   => esc_html__('Add-ons', 'event_espresso'),
161
+						'capability'   => 'ee_read_ee',
162
+						'menu_order'   => 20,
163
+						'parent_slug'  => 'espresso_events',
164
+						'show_on_menu' => AdminMenuItem::DISPLAY_BLOG_AND_NETWORK,
165
+					]
166
+				),
167
+				'settings'   => $this->instantiateAdminMenu(
168
+					[
169
+						'menu_slug'    => 'settings',
170
+						'menu_label'   => esc_html__('Settings', 'event_espresso'),
171
+						'capability'   => 'ee_read_ee',
172
+						'menu_order'   => 30,
173
+						'parent_slug'  => 'espresso_events',
174
+						'show_on_menu' => AdminMenuItem::DISPLAY_BLOG_ONLY,
175
+					]
176
+				),
177
+				'templates'  => $this->instantiateAdminMenu(
178
+					[
179
+						'menu_slug'    => 'templates',
180
+						'menu_label'   => esc_html__('Templates', 'event_espresso'),
181
+						'capability'   => 'ee_read_ee',
182
+						'menu_order'   => 40,
183
+						'parent_slug'  => 'espresso_events',
184
+						'show_on_menu' => AdminMenuItem::DISPLAY_BLOG_ONLY,
185
+					]
186
+				),
187
+				'extras'     => $this->instantiateAdminMenu(
188
+					[
189
+						'menu_slug'               => 'extras',
190
+						'menu_label'              => esc_html__('Extras', 'event_espresso'),
191
+						'capability'              => 'ee_read_ee',
192
+						'maintenance_mode_parent' => 'espresso_maintenance_settings',
193
+						'menu_order'              => 50,
194
+						'parent_slug'             => 'espresso_events',
195
+						'show_on_menu'            => AdminMenuItem::DISPLAY_BLOG_AND_NETWORK,
196
+					]
197
+				),
198
+				'tools'      => $this->instantiateAdminMenu(
199
+					[
200
+						'menu_slug'    => 'tools',
201
+						'menu_label'   => esc_html__('Tools', 'event_espresso'),
202
+						'capability'   => 'ee_read_ee',
203
+						'menu_order'   => 60,
204
+						'parent_slug'  => 'espresso_events',
205
+						'show_on_menu' => AdminMenuItem::DISPLAY_BLOG_ONLY,
206
+					]
207
+				),
208
+			]
209
+		);
210
+	}
211
+
212
+
213
+	/**
214
+	 * adds an AdminMenuItem
215
+	 *
216
+	 * @param AdminMenuItem $admin_menu_item
217
+	 * @return AdminMenuItem
218
+	 */
219
+	public function addAdminMenuItem(AdminMenuItem $admin_menu_item): AdminMenuItem
220
+	{
221
+		// get the menu group that this menu item belongs to and then add it
222
+		$admin_group = $this->getMenuGroup($admin_menu_item);
223
+		$admin_group->addMenuItem($admin_menu_item);
224
+		return $admin_menu_item;
225
+	}
226
+
227
+
228
+	/**
229
+	 * instantiates and returns the appropriate AdminMenuItem for the provided EE_Admin_Page_Init
230
+	 *
231
+	 * @param EE_Admin_Page_Init $admin_page_init
232
+	 * @return AdminMenuItem
233
+	 */
234
+	public function getAdminMenu(EE_Admin_Page_Init $admin_page_init): AdminMenuItem
235
+	{
236
+		// see if admin page init is using new classes
237
+		$menu_properties = $admin_page_init->getMenuProperties();
238
+		if (empty($menu_properties)) {
239
+			// no? ok setup the admin menu item the old way
240
+			$admin_page_init->setupLegacyAdminMenuItem();
241
+		} else {
242
+			// adding the admin page init callback here means the menu doesn't have to cart that object around
243
+			$menu_properties['menu_callback'] = [$admin_page_init, 'initialize_admin_page'];
244
+			$admin_page_init->setAdminMenu($this->instantiateAdminMenu($menu_properties));
245
+		}
246
+		$admin_menu = $admin_page_init->adminMenu();
247
+		if (! $admin_menu instanceof AdminMenuItem) {
248
+			throw new DomainException(esc_html__('Invalid AdminMenuItem', 'event_espresso'));
249
+		}
250
+		if (! is_callable($admin_menu->menuCallback())) {
251
+			$admin_menu->setMenuCallback([$admin_page_init, 'initialize_admin_page']);
252
+		}
253
+		// get the menu group that this menu item belongs to and then add it
254
+		$admin_group = $this->getMenuGroup($admin_menu);
255
+		$admin_group->addMenuItem($admin_menu);
256
+		return $admin_menu;
257
+	}
258
+
259
+
260
+	/**
261
+	 * @param array $menu_properties
262
+	 * @return AdminMenuItem|null
263
+	 */
264
+	private function instantiateAdminMenu(array $menu_properties): ?AdminMenuItem
265
+	{
266
+		$type = $menu_properties['menu_type'] ?? AdminMenuItem::TYPE_MENU_GROUP;
267
+		unset($menu_properties['menu_type']);
268
+		switch ($type) {
269
+			case AdminMenuItem::TYPE_MENU_GROUP:
270
+				unset($menu_properties['menu_callback']);
271
+				return new AdminMenuGroup($menu_properties);
272
+			case AdminMenuItem::TYPE_MENU_TOP:
273
+				return new AdminMenuTopLevel($menu_properties);
274
+			case AdminMenuItem::TYPE_MENU_SUB_ITEM:
275
+				return new AdminMenuSubItem($menu_properties);
276
+		}
277
+		return null;
278
+	}
279
+
280
+
281
+	/**
282
+	 * @param AdminMenuItem $admin_menu
283
+	 * @return AdminMenuGroup
284
+	 * @throws DomainException
285
+	 * @throws OutOfRangeException
286
+	 */
287
+	private function getMenuGroup(AdminMenuItem $admin_menu): AdminMenuGroup
288
+	{
289
+		if (! isset($this->menu_items[ $admin_menu->menuGroup() ])) {
290
+			throw new OutOfRangeException(esc_html__('AdminMenuGroup does not exist', 'event_espresso'));
291
+		}
292
+		$admin_group = $this->menu_items[ $admin_menu->menuGroup() ];
293
+		if (! $admin_group instanceof AdminMenuGroup) {
294
+			throw new DomainException(esc_html__('Invalid AdminMenuGroup found', 'event_espresso'));
295
+		}
296
+		return $admin_group;
297
+	}
298
+
299
+
300
+	/**
301
+	 * set_network_menus
302
+	 * This method sets up the menus for network EE Admin Pages.
303
+	 * Almost identical to EE_Admin_Page_Loader::set_menus() except pages
304
+	 * are only added to the menu map if they are intended for the admin menu
305
+	 *
306
+	 * @return void
307
+	 * @throws DomainException
308
+	 */
309
+	public function generateNetworkAdminMenu()
310
+	{
311
+		$this->generateAdminMenu(true);
312
+	}
313
+
314
+
315
+	/**
316
+	 * This method sets up the menus for EE Admin Pages
317
+	 *
318
+	 * @return void
319
+	 * @throws DomainException
320
+	 */
321
+	public function generateAdminMenu(bool $network_admin = false)
322
+	{
323
+		$admin_menu = $this->sortMenu($this->menu_items);
324
+		$this->top_level_menu_item->registerAdminMenuItem($network_admin);
325
+		$this->registerAdminMenu($admin_menu, $network_admin);
326
+	}
327
+
328
+
329
+	/**
330
+	 * @param array $admin_menu
331
+	 * @param bool  $network_admin
332
+	 */
333
+	private function registerAdminMenu(array $admin_menu, bool $network_admin)
334
+	{
335
+		foreach ($admin_menu as $menu_item) {
336
+			if ($this->skipMenuItem($menu_item)) {
337
+				continue;
338
+			}
339
+			try {
340
+				$wp_page_slug    = $menu_item->registerAdminMenuItem($network_admin);
341
+				$admin_init_page = $this->installed_pages[ $menu_item->menuSlug() ] ?? null;
342
+				if ($wp_page_slug && $admin_init_page instanceof EE_Admin_Page_Init) {
343
+					$admin_init_page->setWpPageSlug($wp_page_slug);
344
+					$admin_init_page->set_page_dependencies($wp_page_slug);
345
+				}
346
+				if ($menu_item instanceof AdminMenuGroup) {
347
+					$this->registerAdminMenu($menu_item->getMenuItems(), $network_admin);
348
+				}
349
+			} catch (Exception $e) {
350
+				EE_Error::add_error($e->getMessage(), $e->getFile(), __FUNCTION__, $e->getLine());
351
+			}
352
+		}
353
+	}
354
+
355
+
356
+	/**
357
+	 * returns TRUE if any of the following conditions is met:
358
+	 * - menu item is NOT an instanceof AdminMenuItem
359
+	 * - menu item has already been registered
360
+	 * - menu item should not be shown when site is in full maintenance mode
361
+	 * - current user does not have the required access permission
362
+	 * - menu item is a group but has no sub items
363
+	 *
364
+	 * @param AdminMenuItem|null $menu_item
365
+	 * @return bool
366
+	 */
367
+	private function skipMenuItem(?AdminMenuItem $menu_item): bool
368
+	{
369
+		return ! $menu_item instanceof AdminMenuItem
370
+			   || $menu_item->isRegistered()
371
+			   || ! $menu_item->showOnMaintenanceModeMenu()
372
+			   || ! $menu_item->currentUserHasAccess()
373
+			   || (
374
+				   $menu_item instanceof AdminMenuGroup
375
+				   && $menu_item->hasNoMenuItems()
376
+			   );
377
+	}
378
+
379
+
380
+	/**
381
+	 * @param EE_Admin_Page_Init[] $installed_pages
382
+	 */
383
+	public function setInstalledPages(array $installed_pages): void
384
+	{
385
+		$this->installed_pages = $installed_pages;
386
+	}
387
+
388
+
389
+	/**
390
+	 * Recursively sort menu groups and their sub items
391
+	 *
392
+	 * @return AdminMenuItem[]
393
+	 * @throws DomainException
394
+	 */
395
+	public function sortMenu(array $admin_menu): array
396
+	{
397
+		foreach ($admin_menu as $menu_group) {
398
+			if (! $menu_group instanceof AdminMenuItem) {
399
+				throw new DomainException(esc_html__('Invalid AdminMenuItem', 'event_espresso'));
400
+			}
401
+			if ($menu_group instanceof AdminMenuGroup) {
402
+				// sort sub items
403
+				$menu_items = $this->sortMenu($menu_group->getMenuItems());
404
+				$menu_group->setMenuItems($menu_items);
405
+			}
406
+		}
407
+		// sort incoming array AFTER it's been looped through and elements have been validated
408
+		usort($admin_menu, [$this, 'sortMenuItems']);
409
+		return $admin_menu;
410
+	}
411
+
412
+
413
+	/**
414
+	 *  sort sub menu items
415
+	 *
416
+	 * @param AdminMenuItem $a menu_item
417
+	 * @param AdminMenuItem $b being compared to
418
+	 * @return int    sort order
419
+	 */
420
+	private function sortMenuItems(AdminMenuItem $a, AdminMenuItem $b): int
421
+	{
422
+		if ($a->menuOrder() === $b->menuOrder()) {
423
+			return 0;
424
+		}
425
+		return $a->menuOrder() < $b->menuOrder() ? -1 : 1;
426
+	}
427
+
428
+
429
+	/**
430
+	 * Moves the Event Espresso admin menu to the position set by $this->menu_position
431
+	 *
432
+	 * @param array $menu_order
433
+	 * @return array
434
+	 */
435
+	public function reorderAdminMenu(array $menu_order): array
436
+	{
437
+		$menu_slug     = $this->maintenance_mode ? 'espresso_maintenance_settings' : 'espresso_events';
438
+		$current_index = array_search($menu_slug, $menu_order);
439
+		if ($current_index === false) {
440
+			return $menu_order;
441
+		}
442
+		// chop out the espresso admin menu if found
443
+		$espresso_menu = array_splice($menu_order, $current_index, 1);
444
+		// reinsert at position set by $this->menu_position
445
+		array_splice($menu_order, $this->menu_position, 0, $espresso_menu);
446
+		return $menu_order;
447
+	}
448 448
 }
Please login to merge, or discard this patch.
core/domain/services/wp_queries/EventListQuery.php 2 patches
Indentation   +164 added lines, -164 removed lines patch added patch discarded remove patch
@@ -16,168 +16,168 @@
 block discarded – undo
16 16
  */
17 17
 class EventListQuery extends WP_Query
18 18
 {
19
-    private ?string $title = '';
20
-
21
-    private int $limit = 10;
22
-
23
-    private ?string $css_class = '';
24
-
25
-    private bool $show_expired = false;
26
-
27
-    private ?string $month = '';
28
-
29
-    private ?string $category_slug = '';
30
-
31
-    /**
32
-     * @var array|string|null
33
-     */
34
-    private $order_by =[];
35
-
36
-    private ?string $sort = '';
37
-
38
-    private bool $show_title = true;
39
-
40
-
41
-    /**
42
-     * EE_Event_List_Query Constructor     *
43
-     *
44
-     * @param array $args
45
-     */
46
-    public function __construct($args = [])
47
-    {
48
-        $args = $this->parseArgs((array) $args);
49
-        $this->setupEventQueryHelper();
50
-        $this->setupFilters();
51
-        $args = $this->getQueryArgs($args);
52
-        // run the query
53
-        parent::__construct($args);
54
-    }
55
-
56
-
57
-    /**
58
-     * @param array $args
59
-     * @return array
60
-     */
61
-    private function parseArgs(array $args): array
62
-    {
63
-        // incoming args could be a mix of WP query args + EE shortcode args
64
-        foreach ($args as $property => $value) {
65
-            // if the arg is a property of this class, then it's an EE shortcode arg
66
-            if (property_exists($this, $property) && ! property_exists('WP_Query', $property)) {
67
-                // set the property value
68
-                $this->{$property} = $value;
69
-                // then remove it from the array of args that will later be passed to WP_Query()
70
-                unset($args[ $property ]);
71
-            }
72
-        }
73
-        return $args;
74
-    }
75
-
76
-
77
-    private function setupEventQueryHelper()
78
-    {
79
-        // add query filters
80
-        EEH_Event_Query::add_query_filters();
81
-        // set params that will get used by the filters
82
-        EEH_Event_Query::set_query_params(
83
-            $this->month,
84
-            $this->category_slug,
85
-            $this->show_expired,
86
-            $this->order_by,
87
-            $this->sort
88
-        );
89
-    }
90
-
91
-
92
-    private function setupFilters()
93
-    {
94
-        // first off, let's remove any filters from previous queries
95
-        remove_filter(
96
-            'FHEE__archive_espresso_events_template__show_header',
97
-            [$this, 'show_event_list_title']
98
-        );
99
-        remove_filter(
100
-            'FHEE__archive_espresso_events_template__upcoming_events_h1',
101
-            [$this, 'event_list_title']
102
-        );
103
-        remove_all_filters('FHEE__content_espresso_events__event_class');
104
-        // Event List Title ?
105
-        add_filter(
106
-            'FHEE__archive_espresso_events_template__show_header',
107
-            [$this, 'show_event_list_title']
108
-        );
109
-        add_filter(
110
-            'FHEE__archive_espresso_events_template__upcoming_events_h1',
111
-            [$this, 'event_list_title']
112
-        );
113
-        // add the css class
114
-        add_filter(
115
-            'FHEE__content_espresso_events__event_class',
116
-            [$this, 'event_list_css']
117
-        );
118
-    }
119
-
120
-
121
-    private function getQueryArgs(array $args): array
122
-    {
123
-        // the current "page" we are viewing
124
-        $paged = max(1, get_query_var('paged'));
125
-        // Force these args
126
-        return array_merge(
127
-            $args,
128
-            [
129
-                'post_type'              => EspressoPostType::EVENTS,
130
-                'posts_per_page'         => $this->limit,
131
-                'update_post_term_cache' => false,
132
-                'update_post_meta_cache' => false,
133
-                'paged'                  => $paged,
134
-                'offset'                 => ($paged - 1) * $this->limit,
135
-            ]
136
-        );
137
-    }
138
-
139
-    // phpcs:disable PSR1.Methods.CamelCapsMethodName.NotCamelCaps
140
-
141
-
142
-    /**
143
-     * show_event_list_title
144
-     *
145
-     * @return boolean
146
-     */
147
-    public function show_event_list_title(): bool
148
-    {
149
-        return filter_var($this->show_title, FILTER_VALIDATE_BOOLEAN);
150
-    }
151
-
152
-
153
-    /**
154
-     * callback for FHEE__archive_espresso_events_template__upcoming_events_h1 filter
155
-     *
156
-     * @param string $event_list_title
157
-     * @return    string
158
-     */
159
-    public function event_list_title(string $event_list_title = ''): string
160
-    {
161
-        if (! empty($this->title)) {
162
-            return $this->title;
163
-        }
164
-        return $event_list_title;
165
-    }
166
-
167
-
168
-    /**
169
-     * callback for FHEE__content_espresso_events__event_class filter
170
-     *
171
-     * @param string $event_list_css
172
-     * @return string
173
-     */
174
-    public function event_list_css(string $event_list_css = ''): string
175
-    {
176
-        $event_list_css .= ! empty($event_list_css) ? ' ' : '';
177
-        $event_list_css .= ! empty($this->css_class) ? $this->css_class : '';
178
-        $event_list_css .= ! empty($event_list_css) ? ' ' : '';
179
-        $event_list_css .= ! empty($this->category_slug) ? $this->category_slug : '';
180
-        return $event_list_css;
181
-    }
182
-    // phpcs:enable
19
+	private ?string $title = '';
20
+
21
+	private int $limit = 10;
22
+
23
+	private ?string $css_class = '';
24
+
25
+	private bool $show_expired = false;
26
+
27
+	private ?string $month = '';
28
+
29
+	private ?string $category_slug = '';
30
+
31
+	/**
32
+	 * @var array|string|null
33
+	 */
34
+	private $order_by =[];
35
+
36
+	private ?string $sort = '';
37
+
38
+	private bool $show_title = true;
39
+
40
+
41
+	/**
42
+	 * EE_Event_List_Query Constructor     *
43
+	 *
44
+	 * @param array $args
45
+	 */
46
+	public function __construct($args = [])
47
+	{
48
+		$args = $this->parseArgs((array) $args);
49
+		$this->setupEventQueryHelper();
50
+		$this->setupFilters();
51
+		$args = $this->getQueryArgs($args);
52
+		// run the query
53
+		parent::__construct($args);
54
+	}
55
+
56
+
57
+	/**
58
+	 * @param array $args
59
+	 * @return array
60
+	 */
61
+	private function parseArgs(array $args): array
62
+	{
63
+		// incoming args could be a mix of WP query args + EE shortcode args
64
+		foreach ($args as $property => $value) {
65
+			// if the arg is a property of this class, then it's an EE shortcode arg
66
+			if (property_exists($this, $property) && ! property_exists('WP_Query', $property)) {
67
+				// set the property value
68
+				$this->{$property} = $value;
69
+				// then remove it from the array of args that will later be passed to WP_Query()
70
+				unset($args[ $property ]);
71
+			}
72
+		}
73
+		return $args;
74
+	}
75
+
76
+
77
+	private function setupEventQueryHelper()
78
+	{
79
+		// add query filters
80
+		EEH_Event_Query::add_query_filters();
81
+		// set params that will get used by the filters
82
+		EEH_Event_Query::set_query_params(
83
+			$this->month,
84
+			$this->category_slug,
85
+			$this->show_expired,
86
+			$this->order_by,
87
+			$this->sort
88
+		);
89
+	}
90
+
91
+
92
+	private function setupFilters()
93
+	{
94
+		// first off, let's remove any filters from previous queries
95
+		remove_filter(
96
+			'FHEE__archive_espresso_events_template__show_header',
97
+			[$this, 'show_event_list_title']
98
+		);
99
+		remove_filter(
100
+			'FHEE__archive_espresso_events_template__upcoming_events_h1',
101
+			[$this, 'event_list_title']
102
+		);
103
+		remove_all_filters('FHEE__content_espresso_events__event_class');
104
+		// Event List Title ?
105
+		add_filter(
106
+			'FHEE__archive_espresso_events_template__show_header',
107
+			[$this, 'show_event_list_title']
108
+		);
109
+		add_filter(
110
+			'FHEE__archive_espresso_events_template__upcoming_events_h1',
111
+			[$this, 'event_list_title']
112
+		);
113
+		// add the css class
114
+		add_filter(
115
+			'FHEE__content_espresso_events__event_class',
116
+			[$this, 'event_list_css']
117
+		);
118
+	}
119
+
120
+
121
+	private function getQueryArgs(array $args): array
122
+	{
123
+		// the current "page" we are viewing
124
+		$paged = max(1, get_query_var('paged'));
125
+		// Force these args
126
+		return array_merge(
127
+			$args,
128
+			[
129
+				'post_type'              => EspressoPostType::EVENTS,
130
+				'posts_per_page'         => $this->limit,
131
+				'update_post_term_cache' => false,
132
+				'update_post_meta_cache' => false,
133
+				'paged'                  => $paged,
134
+				'offset'                 => ($paged - 1) * $this->limit,
135
+			]
136
+		);
137
+	}
138
+
139
+	// phpcs:disable PSR1.Methods.CamelCapsMethodName.NotCamelCaps
140
+
141
+
142
+	/**
143
+	 * show_event_list_title
144
+	 *
145
+	 * @return boolean
146
+	 */
147
+	public function show_event_list_title(): bool
148
+	{
149
+		return filter_var($this->show_title, FILTER_VALIDATE_BOOLEAN);
150
+	}
151
+
152
+
153
+	/**
154
+	 * callback for FHEE__archive_espresso_events_template__upcoming_events_h1 filter
155
+	 *
156
+	 * @param string $event_list_title
157
+	 * @return    string
158
+	 */
159
+	public function event_list_title(string $event_list_title = ''): string
160
+	{
161
+		if (! empty($this->title)) {
162
+			return $this->title;
163
+		}
164
+		return $event_list_title;
165
+	}
166
+
167
+
168
+	/**
169
+	 * callback for FHEE__content_espresso_events__event_class filter
170
+	 *
171
+	 * @param string $event_list_css
172
+	 * @return string
173
+	 */
174
+	public function event_list_css(string $event_list_css = ''): string
175
+	{
176
+		$event_list_css .= ! empty($event_list_css) ? ' ' : '';
177
+		$event_list_css .= ! empty($this->css_class) ? $this->css_class : '';
178
+		$event_list_css .= ! empty($event_list_css) ? ' ' : '';
179
+		$event_list_css .= ! empty($this->category_slug) ? $this->category_slug : '';
180
+		return $event_list_css;
181
+	}
182
+	// phpcs:enable
183 183
 }
Please login to merge, or discard this patch.
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -31,7 +31,7 @@  discard block
 block discarded – undo
31 31
     /**
32 32
      * @var array|string|null
33 33
      */
34
-    private $order_by =[];
34
+    private $order_by = [];
35 35
 
36 36
     private ?string $sort = '';
37 37
 
@@ -67,7 +67,7 @@  discard block
 block discarded – undo
67 67
                 // set the property value
68 68
                 $this->{$property} = $value;
69 69
                 // then remove it from the array of args that will later be passed to WP_Query()
70
-                unset($args[ $property ]);
70
+                unset($args[$property]);
71 71
             }
72 72
         }
73 73
         return $args;
@@ -158,7 +158,7 @@  discard block
 block discarded – undo
158 158
      */
159 159
     public function event_list_title(string $event_list_title = ''): string
160 160
     {
161
-        if (! empty($this->title)) {
161
+        if ( ! empty($this->title)) {
162 162
             return $this->title;
163 163
         }
164 164
         return $event_list_title;
Please login to merge, or discard this patch.