Completed
Branch Gutenberg/master (ab08bc)
by
unknown
78:42 queued 61:53
created
core/db_models/EEM_CPT_Base.model.php 1 patch
Indentation   +558 added lines, -558 removed lines patch added patch discarded remove patch
@@ -16,562 +16,562 @@
 block discarded – undo
16 16
 abstract class EEM_CPT_Base extends EEM_Soft_Delete_Base
17 17
 {
18 18
 
19
-    const EVENT_CATEGORY_TAXONOMY = 'espresso_event_categories';
20
-
21
-    /**
22
-     * @var string post_status_publish - the wp post status for published cpts
23
-     */
24
-    const post_status_publish = 'publish';
25
-
26
-    /**
27
-     * @var string post_status_future - the wp post status for scheduled cpts
28
-     */
29
-    const post_status_future = 'future';
30
-
31
-    /**
32
-     * @var string post_status_draft - the wp post status for draft cpts
33
-     */
34
-    const post_status_draft = 'draft';
35
-
36
-    /**
37
-     * @var string post_status_pending - the wp post status for pending cpts
38
-     */
39
-    const post_status_pending = 'pending';
40
-
41
-    /**
42
-     * @var string post_status_private - the wp post status for private cpts
43
-     */
44
-    const post_status_private = 'private';
45
-
46
-    /**
47
-     * @var string post_status_trashed - the wp post status for trashed cpts
48
-     */
49
-    const post_status_trashed = 'trash';
50
-
51
-    /**
52
-     * This is an array of custom statuses for the given CPT model (modified by children)
53
-     * format:
54
-     * array(
55
-     *        'status_name' => array(
56
-     *            'label' => __('Status Name', 'event_espresso'),
57
-     *            'public' => TRUE //whether a public status or not.
58
-     *        )
59
-     * )
60
-     *
61
-     * @var array
62
-     */
63
-    protected $_custom_stati = array();
64
-
65
-
66
-    /**
67
-     * Adds a relationship to Term_Taxonomy for each CPT_Base
68
-     *
69
-     * @param string $timezone
70
-     * @throws \EE_Error
71
-     */
72
-    protected function __construct($timezone = null)
73
-    {
74
-        // adds a relationship to Term_Taxonomy for all these models. For this to work
75
-        // Term_Relationship must have a relation to each model subclassing EE_CPT_Base explicitly
76
-        // eg, in EEM_Term_Relationship, inside the _model_relations array, there must be an entry
77
-        // with key equalling the subclassing model's model name (eg 'Event' or 'Venue'), and the value
78
-        // must also be new EE_HABTM_Relation('Term_Relationship');
79
-        $this->_model_relations['Term_Taxonomy'] = new EE_HABTM_Relation('Term_Relationship');
80
-        $primary_table_name = null;
81
-        // add  the common _status field to all CPT primary tables.
82
-        foreach ($this->_tables as $alias => $table_obj) {
83
-            if ($table_obj instanceof EE_Primary_Table) {
84
-                $primary_table_name = $alias;
85
-            }
86
-        }
87
-        // set default wp post statuses if child has not already set.
88
-        if (! isset($this->_fields[ $primary_table_name ]['status'])) {
89
-            $this->_fields[ $primary_table_name ]['status'] = new EE_WP_Post_Status_Field(
90
-                'post_status',
91
-                __("Event Status", "event_espresso"),
92
-                false,
93
-                'draft'
94
-            );
95
-        }
96
-        if (! isset($this->_fields[ $primary_table_name ]['to_ping'])) {
97
-            $this->_fields[ $primary_table_name ]['to_ping'] = new EE_DB_Only_Text_Field(
98
-                'to_ping',
99
-                __('To Ping', 'event_espresso'),
100
-                false,
101
-                ''
102
-            );
103
-        }
104
-        if (! isset($this->_fields[ $primary_table_name ]['pinged'])) {
105
-            $this->_fields[ $primary_table_name ]['pinged'] = new EE_DB_Only_Text_Field(
106
-                'pinged',
107
-                __('Pinged', 'event_espresso'),
108
-                false,
109
-                ''
110
-            );
111
-        }
112
-        if (! isset($this->_fields[ $primary_table_name ]['comment_status'])) {
113
-            $this->_fields[ $primary_table_name ]['comment_status'] = new EE_Plain_Text_Field(
114
-                'comment_status',
115
-                __('Comment Status', 'event_espresso'),
116
-                false,
117
-                'open'
118
-            );
119
-        }
120
-        if (! isset($this->_fields[ $primary_table_name ]['ping_status'])) {
121
-            $this->_fields[ $primary_table_name ]['ping_status'] = new EE_Plain_Text_Field(
122
-                'ping_status',
123
-                __('Ping Status', 'event_espresso'),
124
-                false,
125
-                'open'
126
-            );
127
-        }
128
-        if (! isset($this->_fields[ $primary_table_name ]['post_content_filtered'])) {
129
-            $this->_fields[ $primary_table_name ]['post_content_filtered'] = new EE_DB_Only_Text_Field(
130
-                'post_content_filtered',
131
-                __('Post Content Filtered', 'event_espresso'),
132
-                false,
133
-                ''
134
-            );
135
-        }
136
-        if (! isset($this->_model_relations['Post_Meta'])) {
137
-            // don't block deletes though because we want to maintain the current behaviour
138
-            $this->_model_relations['Post_Meta'] = new EE_Has_Many_Relation(false);
139
-        }
140
-        if (! $this->_minimum_where_conditions_strategy instanceof EE_Default_Where_Conditions) {
141
-            // nothing was set during child constructor, so set default
142
-            $this->_minimum_where_conditions_strategy = new EE_CPT_Minimum_Where_Conditions($this->post_type());
143
-        }
144
-        if (! $this->_default_where_conditions_strategy instanceof EE_Default_Where_Conditions) {
145
-            // nothing was set during child constructor, so set default
146
-            // it's ok for child classes to specify this, but generally this is more DRY
147
-            $this->_default_where_conditions_strategy = new EE_CPT_Where_Conditions($this->post_type());
148
-        }
149
-        parent::__construct($timezone);
150
-    }
151
-
152
-
153
-    /**
154
-     * @return array
155
-     */
156
-    public function public_event_stati()
157
-    {
158
-        // @see wp-includes/post.php
159
-        return get_post_stati(array('public' => true));
160
-    }
161
-
162
-
163
-    /**
164
-     * Searches for field on this model of type 'deleted_flag'. if it is found,
165
-     * returns it's name. BUT That doesn't apply to CPTs. We should instead use post_status_field_name
166
-     *
167
-     * @return string
168
-     * @throws EE_Error
169
-     */
170
-    public function deleted_field_name()
171
-    {
172
-        throw new EE_Error(
173
-            sprintf(
174
-                __(
175
-                    "EEM_CPT_Base should nto call deleted_field_name! It should instead use post_status_field_name",
176
-                    "event_espresso"
177
-                )
178
-            )
179
-        );
180
-    }
181
-
182
-
183
-    /**
184
-     * Gets the field's name that sets the post status
185
-     *
186
-     * @return string
187
-     * @throws EE_Error
188
-     */
189
-    public function post_status_field_name()
190
-    {
191
-        $field = $this->get_a_field_of_type('EE_WP_Post_Status_Field');
192
-        if ($field) {
193
-            return $field->get_name();
194
-        } else {
195
-            throw new EE_Error(
196
-                sprintf(
197
-                    __(
198
-                        'We are trying to find the post status flag field on %s, but none was found. Are you sure there is a field of type EE_Trashed_Flag_Field in %s constructor?',
199
-                        'event_espresso'
200
-                    ),
201
-                    get_class($this),
202
-                    get_class($this)
203
-                )
204
-            );
205
-        }
206
-    }
207
-
208
-
209
-    /**
210
-     * Alters the query params so that only trashed/soft-deleted items are considered
211
-     *
212
-     * @param array $query_params like EEM_Base::get_all's $query_params
213
-     * @return array like EEM_Base::get_all's $query_params
214
-     */
215
-    protected function _alter_query_params_so_only_trashed_items_included($query_params)
216
-    {
217
-        $post_status_field_name = $this->post_status_field_name();
218
-        $query_params[0][ $post_status_field_name ] = self::post_status_trashed;
219
-        return $query_params;
220
-    }
221
-
222
-
223
-    /**
224
-     * Alters the query params so each item's deleted status is ignored.
225
-     *
226
-     * @param array $query_params
227
-     * @return array
228
-     */
229
-    protected function _alter_query_params_so_deleted_and_undeleted_items_included($query_params)
230
-    {
231
-        $query_params['default_where_conditions'] = 'minimum';
232
-        return $query_params;
233
-    }
234
-
235
-
236
-    /**
237
-     * Performs deletes or restores on items. Both soft-deleted and non-soft-deleted items considered.
238
-     *
239
-     * @param boolean $delete       true to indicate deletion, false to indicate restoration
240
-     * @param array   $query_params like EEM_Base::get_all
241
-     * @return boolean success
242
-     */
243
-    public function delete_or_restore($delete = true, $query_params = array())
244
-    {
245
-        $post_status_field_name = $this->post_status_field_name();
246
-        $query_params = $this->_alter_query_params_so_deleted_and_undeleted_items_included($query_params);
247
-        $new_status = $delete ? self::post_status_trashed : 'draft';
248
-        if ($this->update(array($post_status_field_name => $new_status), $query_params)) {
249
-            return true;
250
-        } else {
251
-            return false;
252
-        }
253
-    }
254
-
255
-
256
-    /**
257
-     * meta_table
258
-     * returns first EE_Secondary_Table table name
259
-     *
260
-     * @access public
261
-     * @return string
262
-     */
263
-    public function meta_table()
264
-    {
265
-        $meta_table = $this->_get_other_tables();
266
-        $meta_table = reset($meta_table);
267
-        return $meta_table instanceof EE_Secondary_Table ? $meta_table->get_table_name() : null;
268
-    }
269
-
270
-
271
-    /**
272
-     * This simply returns an array of the meta table fields (useful for when we just need to update those fields)
273
-     *
274
-     * @param  bool $all triggers whether we include DB_Only fields or JUST non DB_Only fields.  Defaults to false (no
275
-     *                   db only fields)
276
-     * @return array
277
-     */
278
-    public function get_meta_table_fields($all = false)
279
-    {
280
-        $all_fields = $fields_to_return = array();
281
-        foreach ($this->_tables as $alias => $table_obj) {
282
-            if ($table_obj instanceof EE_Secondary_Table) {
283
-                $all_fields = array_merge($this->_get_fields_for_table($alias), $all_fields);
284
-            }
285
-        }
286
-        if (! $all) {
287
-            foreach ($all_fields as $name => $obj) {
288
-                if ($obj instanceof EE_DB_Only_Field_Base) {
289
-                    continue;
290
-                }
291
-                $fields_to_return[] = $name;
292
-            }
293
-        } else {
294
-            $fields_to_return = array_keys($all_fields);
295
-        }
296
-        return $fields_to_return;
297
-    }
298
-
299
-
300
-    /**
301
-     * Adds an event category with the specified name and description to the specified
302
-     * $cpt_model_object. Intelligently adds a term if necessary, and adds a term_taxonomy if necessary,
303
-     * and adds an entry in the term_relationship if necessary.
304
-     *
305
-     * @param EE_CPT_Base $cpt_model_object
306
-     * @param string      $category_name (used to derive the term slug too)
307
-     * @param string      $category_description
308
-     * @param int         $parent_term_taxonomy_id
309
-     * @return EE_Term_Taxonomy
310
-     */
311
-    public function add_event_category(
312
-        EE_CPT_Base $cpt_model_object,
313
-        $category_name,
314
-        $category_description = '',
315
-        $parent_term_taxonomy_id = null
316
-    ) {
317
-        // create term
318
-        require_once(EE_MODELS . 'EEM_Term.model.php');
319
-        // first, check for a term by the same name or slug
320
-        $category_slug = sanitize_title($category_name);
321
-        $term = EEM_Term::instance()->get_one(
322
-            array(
323
-                array(
324
-                    'OR' => array(
325
-                        'name' => $category_name,
326
-                        'slug' => $category_slug,
327
-                    ),
328
-                    'Term_Taxonomy.taxonomy' => self::EVENT_CATEGORY_TAXONOMY
329
-                ),
330
-            )
331
-        );
332
-        if (! $term) {
333
-            $term = EE_Term::new_instance(
334
-                array(
335
-                    'name' => $category_name,
336
-                    'slug' => $category_slug,
337
-                )
338
-            );
339
-            $term->save();
340
-        }
341
-        // make sure there's a term-taxonomy entry too
342
-        require_once(EE_MODELS . 'EEM_Term_Taxonomy.model.php');
343
-        $term_taxonomy = EEM_Term_Taxonomy::instance()->get_one(
344
-            array(
345
-                array(
346
-                    'term_id'  => $term->ID(),
347
-                    'taxonomy' => self::EVENT_CATEGORY_TAXONOMY,
348
-                ),
349
-            )
350
-        );
351
-        /** @var $term_taxonomy EE_Term_Taxonomy */
352
-        if (! $term_taxonomy) {
353
-            $term_taxonomy = EE_Term_Taxonomy::new_instance(
354
-                array(
355
-                    'term_id'     => $term->ID(),
356
-                    'taxonomy'    => self::EVENT_CATEGORY_TAXONOMY,
357
-                    'description' => $category_description,
358
-                    'term_count'       => 1,
359
-                    'parent'      => $parent_term_taxonomy_id,
360
-                )
361
-            );
362
-            $term_taxonomy->save();
363
-        } else {
364
-            $term_taxonomy->set_count($term_taxonomy->count() + 1);
365
-            $term_taxonomy->save();
366
-        }
367
-        return $this->add_relationship_to($cpt_model_object, $term_taxonomy, 'Term_Taxonomy');
368
-    }
369
-
370
-
371
-    /**
372
-     * Removed the category specified by name as having a relation to this event.
373
-     * Does not remove the term or term_taxonomy.
374
-     *
375
-     * @param EE_CPT_Base $cpt_model_object_event
376
-     * @param string      $category_name name of the event category (term)
377
-     * @return bool
378
-     */
379
-    public function remove_event_category(EE_CPT_Base $cpt_model_object_event, $category_name)
380
-    {
381
-        // find the term_taxonomy by that name
382
-        $term_taxonomy = $this->get_first_related(
383
-            $cpt_model_object_event,
384
-            'Term_Taxonomy',
385
-            array(array('Term.name' => $category_name, 'taxonomy' => self::EVENT_CATEGORY_TAXONOMY))
386
-        );
387
-        /** @var $term_taxonomy EE_Term_Taxonomy */
388
-        if ($term_taxonomy) {
389
-            $term_taxonomy->set_count($term_taxonomy->count() - 1);
390
-            $term_taxonomy->save();
391
-        }
392
-        return $this->remove_relationship_to($cpt_model_object_event, $term_taxonomy, 'Term_Taxonomy');
393
-    }
394
-
395
-
396
-    /**
397
-     * This is a wrapper for the WordPress get_the_post_thumbnail() function that returns the feature image for the
398
-     * given CPT ID.  It accepts the same params as what get_the_post_thumbnail() accepts.
399
-     *
400
-     * @link   http://codex.wordpress.org/Function_Reference/get_the_post_thumbnail
401
-     * @access public
402
-     * @param int          $id   the ID for the cpt we want the feature image for
403
-     * @param string|array $size (optional) Image size. Defaults to 'post-thumbnail' but can also be a 2-item array
404
-     *                           representing width and height in pixels (i.e. array(32,32) ).
405
-     * @param string|array $attr Optional. Query string or array of attributes.
406
-     * @return string HTML image element
407
-     */
408
-    public function get_feature_image($id, $size = 'thumbnail', $attr = '')
409
-    {
410
-        return get_the_post_thumbnail($id, $size, $attr);
411
-    }
412
-
413
-
414
-    /**
415
-     * Just a handy way to get the list of post statuses currently registered with WP.
416
-     *
417
-     * @global array $wp_post_statuses set in wp core for storing all the post stati
418
-     * @return array
419
-     */
420
-    public function get_post_statuses()
421
-    {
422
-        global $wp_post_statuses;
423
-        $statuses = array();
424
-        foreach ($wp_post_statuses as $post_status => $args_object) {
425
-            $statuses[ $post_status ] = $args_object->label;
426
-        }
427
-        return $statuses;
428
-    }
429
-
430
-
431
-    /**
432
-     * public method that can be used to retrieve the protected status array on the instantiated cpt model
433
-     *
434
-     * @return array array of statuses.
435
-     */
436
-    public function get_status_array()
437
-    {
438
-        $statuses = $this->get_post_statuses();
439
-        // first the global filter
440
-        $statuses = apply_filters('FHEE_EEM_CPT_Base__get_status_array', $statuses);
441
-        // now the class specific filter
442
-        $statuses = apply_filters('FHEE_EEM_' . get_class($this) . '__get_status_array', $statuses);
443
-        return $statuses;
444
-    }
445
-
446
-
447
-    /**
448
-     * this returns the post statuses that are NOT the default wordpress status
449
-     *
450
-     * @return array
451
-     */
452
-    public function get_custom_post_statuses()
453
-    {
454
-        $new_stati = array();
455
-        foreach ($this->_custom_stati as $status => $props) {
456
-            $new_stati[ $status ] = $props['label'];
457
-        }
458
-        return $new_stati;
459
-    }
460
-
461
-
462
-    /**
463
-     * Creates a child of EE_CPT_Base given a WP_Post or array of wpdb results which
464
-     * are a row from the posts table. If we're missing any fields required for the model,
465
-     * we just fetch the entire entry from the DB (ie, if you want to use this to save DB queries,
466
-     * make sure you are attaching all the model's fields onto the post)
467
-     *
468
-     * @param WP_Post|array $post
469
-     * @return EE_Base_Class|EE_Soft_Delete_Base_Class
470
-     */
471
-    public function instantiate_class_from_post_object_orig($post)
472
-    {
473
-        $post = (array) $post;
474
-        $has_all_necessary_fields_for_table = true;
475
-        // check if the post has fields on the meta table already
476
-        foreach ($this->_get_other_tables() as $table_obj) {
477
-            $fields_for_that_table = $this->_get_fields_for_table($table_obj->get_table_alias());
478
-            foreach ($fields_for_that_table as $field_obj) {
479
-                if (! isset($post[ $field_obj->get_table_column() ])
480
-                    && ! isset($post[ $field_obj->get_qualified_column() ])
481
-                ) {
482
-                    $has_all_necessary_fields_for_table = false;
483
-                }
484
-            }
485
-        }
486
-        // if we don't have all the fields we need, then just fetch the proper model from the DB
487
-        if (! $has_all_necessary_fields_for_table) {
488
-            return $this->get_one_by_ID($post['ID']);
489
-        } else {
490
-            return $this->instantiate_class_from_array_or_object($post);
491
-        }
492
-    }
493
-
494
-
495
-    /**
496
-     * @param null $post
497
-     * @return EE_Base_Class|EE_Soft_Delete_Base_Class
498
-     */
499
-    public function instantiate_class_from_post_object($post = null)
500
-    {
501
-        if (empty($post)) {
502
-            global $post;
503
-        }
504
-        $post = (array) $post;
505
-        $tables_needing_to_be_queried = array();
506
-        // check if the post has fields on the meta table already
507
-        foreach ($this->get_tables() as $table_obj) {
508
-            $fields_for_that_table = $this->_get_fields_for_table($table_obj->get_table_alias());
509
-            foreach ($fields_for_that_table as $field_obj) {
510
-                if (! isset($post[ $field_obj->get_table_column() ])
511
-                    && ! isset($post[ $field_obj->get_qualified_column() ])
512
-                ) {
513
-                    $tables_needing_to_be_queried[ $table_obj->get_table_alias() ] = $table_obj;
514
-                }
515
-            }
516
-        }
517
-        // if we don't have all the fields we need, then just fetch the proper model from the DB
518
-        if ($tables_needing_to_be_queried) {
519
-            if (count($tables_needing_to_be_queried) == 1
520
-                && reset($tables_needing_to_be_queried)
521
-                   instanceof
522
-                   EE_Secondary_Table
523
-            ) {
524
-                // so we're only missing data from a secondary table. Well that's not too hard to query for
525
-                $table_to_query = reset($tables_needing_to_be_queried);
526
-                $missing_data = $this->_do_wpdb_query(
527
-                    'get_row',
528
-                    array(
529
-                        'SELECT * FROM '
530
-                        . $table_to_query->get_table_name()
531
-                        . ' WHERE '
532
-                        . $table_to_query->get_fk_on_table()
533
-                        . ' = '
534
-                        . $post['ID'],
535
-                        ARRAY_A,
536
-                    )
537
-                );
538
-                if (! empty($missing_data)) {
539
-                    $post = array_merge($post, $missing_data);
540
-                }
541
-            } else {
542
-                return $this->get_one_by_ID($post['ID']);
543
-            }
544
-        }
545
-        return $this->instantiate_class_from_array_or_object($post);
546
-    }
547
-
548
-
549
-    /**
550
-     * Gets the post type associated with this
551
-     *
552
-     * @throws EE_Error
553
-     * @return string
554
-     */
555
-    public function post_type()
556
-    {
557
-        $post_type_field = null;
558
-        foreach ($this->field_settings(true) as $field_obj) {
559
-            if ($field_obj instanceof EE_WP_Post_Type_Field) {
560
-                $post_type_field = $field_obj;
561
-                break;
562
-            }
563
-        }
564
-        if ($post_type_field == null) {
565
-            throw new EE_Error(
566
-                sprintf(
567
-                    __(
568
-                        "CPT Model %s should have a field of type EE_WP_Post_Type, but doesnt",
569
-                        "event_espresso"
570
-                    ),
571
-                    get_class($this)
572
-                )
573
-            );
574
-        }
575
-        return $post_type_field->get_default_value();
576
-    }
19
+	const EVENT_CATEGORY_TAXONOMY = 'espresso_event_categories';
20
+
21
+	/**
22
+	 * @var string post_status_publish - the wp post status for published cpts
23
+	 */
24
+	const post_status_publish = 'publish';
25
+
26
+	/**
27
+	 * @var string post_status_future - the wp post status for scheduled cpts
28
+	 */
29
+	const post_status_future = 'future';
30
+
31
+	/**
32
+	 * @var string post_status_draft - the wp post status for draft cpts
33
+	 */
34
+	const post_status_draft = 'draft';
35
+
36
+	/**
37
+	 * @var string post_status_pending - the wp post status for pending cpts
38
+	 */
39
+	const post_status_pending = 'pending';
40
+
41
+	/**
42
+	 * @var string post_status_private - the wp post status for private cpts
43
+	 */
44
+	const post_status_private = 'private';
45
+
46
+	/**
47
+	 * @var string post_status_trashed - the wp post status for trashed cpts
48
+	 */
49
+	const post_status_trashed = 'trash';
50
+
51
+	/**
52
+	 * This is an array of custom statuses for the given CPT model (modified by children)
53
+	 * format:
54
+	 * array(
55
+	 *        'status_name' => array(
56
+	 *            'label' => __('Status Name', 'event_espresso'),
57
+	 *            'public' => TRUE //whether a public status or not.
58
+	 *        )
59
+	 * )
60
+	 *
61
+	 * @var array
62
+	 */
63
+	protected $_custom_stati = array();
64
+
65
+
66
+	/**
67
+	 * Adds a relationship to Term_Taxonomy for each CPT_Base
68
+	 *
69
+	 * @param string $timezone
70
+	 * @throws \EE_Error
71
+	 */
72
+	protected function __construct($timezone = null)
73
+	{
74
+		// adds a relationship to Term_Taxonomy for all these models. For this to work
75
+		// Term_Relationship must have a relation to each model subclassing EE_CPT_Base explicitly
76
+		// eg, in EEM_Term_Relationship, inside the _model_relations array, there must be an entry
77
+		// with key equalling the subclassing model's model name (eg 'Event' or 'Venue'), and the value
78
+		// must also be new EE_HABTM_Relation('Term_Relationship');
79
+		$this->_model_relations['Term_Taxonomy'] = new EE_HABTM_Relation('Term_Relationship');
80
+		$primary_table_name = null;
81
+		// add  the common _status field to all CPT primary tables.
82
+		foreach ($this->_tables as $alias => $table_obj) {
83
+			if ($table_obj instanceof EE_Primary_Table) {
84
+				$primary_table_name = $alias;
85
+			}
86
+		}
87
+		// set default wp post statuses if child has not already set.
88
+		if (! isset($this->_fields[ $primary_table_name ]['status'])) {
89
+			$this->_fields[ $primary_table_name ]['status'] = new EE_WP_Post_Status_Field(
90
+				'post_status',
91
+				__("Event Status", "event_espresso"),
92
+				false,
93
+				'draft'
94
+			);
95
+		}
96
+		if (! isset($this->_fields[ $primary_table_name ]['to_ping'])) {
97
+			$this->_fields[ $primary_table_name ]['to_ping'] = new EE_DB_Only_Text_Field(
98
+				'to_ping',
99
+				__('To Ping', 'event_espresso'),
100
+				false,
101
+				''
102
+			);
103
+		}
104
+		if (! isset($this->_fields[ $primary_table_name ]['pinged'])) {
105
+			$this->_fields[ $primary_table_name ]['pinged'] = new EE_DB_Only_Text_Field(
106
+				'pinged',
107
+				__('Pinged', 'event_espresso'),
108
+				false,
109
+				''
110
+			);
111
+		}
112
+		if (! isset($this->_fields[ $primary_table_name ]['comment_status'])) {
113
+			$this->_fields[ $primary_table_name ]['comment_status'] = new EE_Plain_Text_Field(
114
+				'comment_status',
115
+				__('Comment Status', 'event_espresso'),
116
+				false,
117
+				'open'
118
+			);
119
+		}
120
+		if (! isset($this->_fields[ $primary_table_name ]['ping_status'])) {
121
+			$this->_fields[ $primary_table_name ]['ping_status'] = new EE_Plain_Text_Field(
122
+				'ping_status',
123
+				__('Ping Status', 'event_espresso'),
124
+				false,
125
+				'open'
126
+			);
127
+		}
128
+		if (! isset($this->_fields[ $primary_table_name ]['post_content_filtered'])) {
129
+			$this->_fields[ $primary_table_name ]['post_content_filtered'] = new EE_DB_Only_Text_Field(
130
+				'post_content_filtered',
131
+				__('Post Content Filtered', 'event_espresso'),
132
+				false,
133
+				''
134
+			);
135
+		}
136
+		if (! isset($this->_model_relations['Post_Meta'])) {
137
+			// don't block deletes though because we want to maintain the current behaviour
138
+			$this->_model_relations['Post_Meta'] = new EE_Has_Many_Relation(false);
139
+		}
140
+		if (! $this->_minimum_where_conditions_strategy instanceof EE_Default_Where_Conditions) {
141
+			// nothing was set during child constructor, so set default
142
+			$this->_minimum_where_conditions_strategy = new EE_CPT_Minimum_Where_Conditions($this->post_type());
143
+		}
144
+		if (! $this->_default_where_conditions_strategy instanceof EE_Default_Where_Conditions) {
145
+			// nothing was set during child constructor, so set default
146
+			// it's ok for child classes to specify this, but generally this is more DRY
147
+			$this->_default_where_conditions_strategy = new EE_CPT_Where_Conditions($this->post_type());
148
+		}
149
+		parent::__construct($timezone);
150
+	}
151
+
152
+
153
+	/**
154
+	 * @return array
155
+	 */
156
+	public function public_event_stati()
157
+	{
158
+		// @see wp-includes/post.php
159
+		return get_post_stati(array('public' => true));
160
+	}
161
+
162
+
163
+	/**
164
+	 * Searches for field on this model of type 'deleted_flag'. if it is found,
165
+	 * returns it's name. BUT That doesn't apply to CPTs. We should instead use post_status_field_name
166
+	 *
167
+	 * @return string
168
+	 * @throws EE_Error
169
+	 */
170
+	public function deleted_field_name()
171
+	{
172
+		throw new EE_Error(
173
+			sprintf(
174
+				__(
175
+					"EEM_CPT_Base should nto call deleted_field_name! It should instead use post_status_field_name",
176
+					"event_espresso"
177
+				)
178
+			)
179
+		);
180
+	}
181
+
182
+
183
+	/**
184
+	 * Gets the field's name that sets the post status
185
+	 *
186
+	 * @return string
187
+	 * @throws EE_Error
188
+	 */
189
+	public function post_status_field_name()
190
+	{
191
+		$field = $this->get_a_field_of_type('EE_WP_Post_Status_Field');
192
+		if ($field) {
193
+			return $field->get_name();
194
+		} else {
195
+			throw new EE_Error(
196
+				sprintf(
197
+					__(
198
+						'We are trying to find the post status flag field on %s, but none was found. Are you sure there is a field of type EE_Trashed_Flag_Field in %s constructor?',
199
+						'event_espresso'
200
+					),
201
+					get_class($this),
202
+					get_class($this)
203
+				)
204
+			);
205
+		}
206
+	}
207
+
208
+
209
+	/**
210
+	 * Alters the query params so that only trashed/soft-deleted items are considered
211
+	 *
212
+	 * @param array $query_params like EEM_Base::get_all's $query_params
213
+	 * @return array like EEM_Base::get_all's $query_params
214
+	 */
215
+	protected function _alter_query_params_so_only_trashed_items_included($query_params)
216
+	{
217
+		$post_status_field_name = $this->post_status_field_name();
218
+		$query_params[0][ $post_status_field_name ] = self::post_status_trashed;
219
+		return $query_params;
220
+	}
221
+
222
+
223
+	/**
224
+	 * Alters the query params so each item's deleted status is ignored.
225
+	 *
226
+	 * @param array $query_params
227
+	 * @return array
228
+	 */
229
+	protected function _alter_query_params_so_deleted_and_undeleted_items_included($query_params)
230
+	{
231
+		$query_params['default_where_conditions'] = 'minimum';
232
+		return $query_params;
233
+	}
234
+
235
+
236
+	/**
237
+	 * Performs deletes or restores on items. Both soft-deleted and non-soft-deleted items considered.
238
+	 *
239
+	 * @param boolean $delete       true to indicate deletion, false to indicate restoration
240
+	 * @param array   $query_params like EEM_Base::get_all
241
+	 * @return boolean success
242
+	 */
243
+	public function delete_or_restore($delete = true, $query_params = array())
244
+	{
245
+		$post_status_field_name = $this->post_status_field_name();
246
+		$query_params = $this->_alter_query_params_so_deleted_and_undeleted_items_included($query_params);
247
+		$new_status = $delete ? self::post_status_trashed : 'draft';
248
+		if ($this->update(array($post_status_field_name => $new_status), $query_params)) {
249
+			return true;
250
+		} else {
251
+			return false;
252
+		}
253
+	}
254
+
255
+
256
+	/**
257
+	 * meta_table
258
+	 * returns first EE_Secondary_Table table name
259
+	 *
260
+	 * @access public
261
+	 * @return string
262
+	 */
263
+	public function meta_table()
264
+	{
265
+		$meta_table = $this->_get_other_tables();
266
+		$meta_table = reset($meta_table);
267
+		return $meta_table instanceof EE_Secondary_Table ? $meta_table->get_table_name() : null;
268
+	}
269
+
270
+
271
+	/**
272
+	 * This simply returns an array of the meta table fields (useful for when we just need to update those fields)
273
+	 *
274
+	 * @param  bool $all triggers whether we include DB_Only fields or JUST non DB_Only fields.  Defaults to false (no
275
+	 *                   db only fields)
276
+	 * @return array
277
+	 */
278
+	public function get_meta_table_fields($all = false)
279
+	{
280
+		$all_fields = $fields_to_return = array();
281
+		foreach ($this->_tables as $alias => $table_obj) {
282
+			if ($table_obj instanceof EE_Secondary_Table) {
283
+				$all_fields = array_merge($this->_get_fields_for_table($alias), $all_fields);
284
+			}
285
+		}
286
+		if (! $all) {
287
+			foreach ($all_fields as $name => $obj) {
288
+				if ($obj instanceof EE_DB_Only_Field_Base) {
289
+					continue;
290
+				}
291
+				$fields_to_return[] = $name;
292
+			}
293
+		} else {
294
+			$fields_to_return = array_keys($all_fields);
295
+		}
296
+		return $fields_to_return;
297
+	}
298
+
299
+
300
+	/**
301
+	 * Adds an event category with the specified name and description to the specified
302
+	 * $cpt_model_object. Intelligently adds a term if necessary, and adds a term_taxonomy if necessary,
303
+	 * and adds an entry in the term_relationship if necessary.
304
+	 *
305
+	 * @param EE_CPT_Base $cpt_model_object
306
+	 * @param string      $category_name (used to derive the term slug too)
307
+	 * @param string      $category_description
308
+	 * @param int         $parent_term_taxonomy_id
309
+	 * @return EE_Term_Taxonomy
310
+	 */
311
+	public function add_event_category(
312
+		EE_CPT_Base $cpt_model_object,
313
+		$category_name,
314
+		$category_description = '',
315
+		$parent_term_taxonomy_id = null
316
+	) {
317
+		// create term
318
+		require_once(EE_MODELS . 'EEM_Term.model.php');
319
+		// first, check for a term by the same name or slug
320
+		$category_slug = sanitize_title($category_name);
321
+		$term = EEM_Term::instance()->get_one(
322
+			array(
323
+				array(
324
+					'OR' => array(
325
+						'name' => $category_name,
326
+						'slug' => $category_slug,
327
+					),
328
+					'Term_Taxonomy.taxonomy' => self::EVENT_CATEGORY_TAXONOMY
329
+				),
330
+			)
331
+		);
332
+		if (! $term) {
333
+			$term = EE_Term::new_instance(
334
+				array(
335
+					'name' => $category_name,
336
+					'slug' => $category_slug,
337
+				)
338
+			);
339
+			$term->save();
340
+		}
341
+		// make sure there's a term-taxonomy entry too
342
+		require_once(EE_MODELS . 'EEM_Term_Taxonomy.model.php');
343
+		$term_taxonomy = EEM_Term_Taxonomy::instance()->get_one(
344
+			array(
345
+				array(
346
+					'term_id'  => $term->ID(),
347
+					'taxonomy' => self::EVENT_CATEGORY_TAXONOMY,
348
+				),
349
+			)
350
+		);
351
+		/** @var $term_taxonomy EE_Term_Taxonomy */
352
+		if (! $term_taxonomy) {
353
+			$term_taxonomy = EE_Term_Taxonomy::new_instance(
354
+				array(
355
+					'term_id'     => $term->ID(),
356
+					'taxonomy'    => self::EVENT_CATEGORY_TAXONOMY,
357
+					'description' => $category_description,
358
+					'term_count'       => 1,
359
+					'parent'      => $parent_term_taxonomy_id,
360
+				)
361
+			);
362
+			$term_taxonomy->save();
363
+		} else {
364
+			$term_taxonomy->set_count($term_taxonomy->count() + 1);
365
+			$term_taxonomy->save();
366
+		}
367
+		return $this->add_relationship_to($cpt_model_object, $term_taxonomy, 'Term_Taxonomy');
368
+	}
369
+
370
+
371
+	/**
372
+	 * Removed the category specified by name as having a relation to this event.
373
+	 * Does not remove the term or term_taxonomy.
374
+	 *
375
+	 * @param EE_CPT_Base $cpt_model_object_event
376
+	 * @param string      $category_name name of the event category (term)
377
+	 * @return bool
378
+	 */
379
+	public function remove_event_category(EE_CPT_Base $cpt_model_object_event, $category_name)
380
+	{
381
+		// find the term_taxonomy by that name
382
+		$term_taxonomy = $this->get_first_related(
383
+			$cpt_model_object_event,
384
+			'Term_Taxonomy',
385
+			array(array('Term.name' => $category_name, 'taxonomy' => self::EVENT_CATEGORY_TAXONOMY))
386
+		);
387
+		/** @var $term_taxonomy EE_Term_Taxonomy */
388
+		if ($term_taxonomy) {
389
+			$term_taxonomy->set_count($term_taxonomy->count() - 1);
390
+			$term_taxonomy->save();
391
+		}
392
+		return $this->remove_relationship_to($cpt_model_object_event, $term_taxonomy, 'Term_Taxonomy');
393
+	}
394
+
395
+
396
+	/**
397
+	 * This is a wrapper for the WordPress get_the_post_thumbnail() function that returns the feature image for the
398
+	 * given CPT ID.  It accepts the same params as what get_the_post_thumbnail() accepts.
399
+	 *
400
+	 * @link   http://codex.wordpress.org/Function_Reference/get_the_post_thumbnail
401
+	 * @access public
402
+	 * @param int          $id   the ID for the cpt we want the feature image for
403
+	 * @param string|array $size (optional) Image size. Defaults to 'post-thumbnail' but can also be a 2-item array
404
+	 *                           representing width and height in pixels (i.e. array(32,32) ).
405
+	 * @param string|array $attr Optional. Query string or array of attributes.
406
+	 * @return string HTML image element
407
+	 */
408
+	public function get_feature_image($id, $size = 'thumbnail', $attr = '')
409
+	{
410
+		return get_the_post_thumbnail($id, $size, $attr);
411
+	}
412
+
413
+
414
+	/**
415
+	 * Just a handy way to get the list of post statuses currently registered with WP.
416
+	 *
417
+	 * @global array $wp_post_statuses set in wp core for storing all the post stati
418
+	 * @return array
419
+	 */
420
+	public function get_post_statuses()
421
+	{
422
+		global $wp_post_statuses;
423
+		$statuses = array();
424
+		foreach ($wp_post_statuses as $post_status => $args_object) {
425
+			$statuses[ $post_status ] = $args_object->label;
426
+		}
427
+		return $statuses;
428
+	}
429
+
430
+
431
+	/**
432
+	 * public method that can be used to retrieve the protected status array on the instantiated cpt model
433
+	 *
434
+	 * @return array array of statuses.
435
+	 */
436
+	public function get_status_array()
437
+	{
438
+		$statuses = $this->get_post_statuses();
439
+		// first the global filter
440
+		$statuses = apply_filters('FHEE_EEM_CPT_Base__get_status_array', $statuses);
441
+		// now the class specific filter
442
+		$statuses = apply_filters('FHEE_EEM_' . get_class($this) . '__get_status_array', $statuses);
443
+		return $statuses;
444
+	}
445
+
446
+
447
+	/**
448
+	 * this returns the post statuses that are NOT the default wordpress status
449
+	 *
450
+	 * @return array
451
+	 */
452
+	public function get_custom_post_statuses()
453
+	{
454
+		$new_stati = array();
455
+		foreach ($this->_custom_stati as $status => $props) {
456
+			$new_stati[ $status ] = $props['label'];
457
+		}
458
+		return $new_stati;
459
+	}
460
+
461
+
462
+	/**
463
+	 * Creates a child of EE_CPT_Base given a WP_Post or array of wpdb results which
464
+	 * are a row from the posts table. If we're missing any fields required for the model,
465
+	 * we just fetch the entire entry from the DB (ie, if you want to use this to save DB queries,
466
+	 * make sure you are attaching all the model's fields onto the post)
467
+	 *
468
+	 * @param WP_Post|array $post
469
+	 * @return EE_Base_Class|EE_Soft_Delete_Base_Class
470
+	 */
471
+	public function instantiate_class_from_post_object_orig($post)
472
+	{
473
+		$post = (array) $post;
474
+		$has_all_necessary_fields_for_table = true;
475
+		// check if the post has fields on the meta table already
476
+		foreach ($this->_get_other_tables() as $table_obj) {
477
+			$fields_for_that_table = $this->_get_fields_for_table($table_obj->get_table_alias());
478
+			foreach ($fields_for_that_table as $field_obj) {
479
+				if (! isset($post[ $field_obj->get_table_column() ])
480
+					&& ! isset($post[ $field_obj->get_qualified_column() ])
481
+				) {
482
+					$has_all_necessary_fields_for_table = false;
483
+				}
484
+			}
485
+		}
486
+		// if we don't have all the fields we need, then just fetch the proper model from the DB
487
+		if (! $has_all_necessary_fields_for_table) {
488
+			return $this->get_one_by_ID($post['ID']);
489
+		} else {
490
+			return $this->instantiate_class_from_array_or_object($post);
491
+		}
492
+	}
493
+
494
+
495
+	/**
496
+	 * @param null $post
497
+	 * @return EE_Base_Class|EE_Soft_Delete_Base_Class
498
+	 */
499
+	public function instantiate_class_from_post_object($post = null)
500
+	{
501
+		if (empty($post)) {
502
+			global $post;
503
+		}
504
+		$post = (array) $post;
505
+		$tables_needing_to_be_queried = array();
506
+		// check if the post has fields on the meta table already
507
+		foreach ($this->get_tables() as $table_obj) {
508
+			$fields_for_that_table = $this->_get_fields_for_table($table_obj->get_table_alias());
509
+			foreach ($fields_for_that_table as $field_obj) {
510
+				if (! isset($post[ $field_obj->get_table_column() ])
511
+					&& ! isset($post[ $field_obj->get_qualified_column() ])
512
+				) {
513
+					$tables_needing_to_be_queried[ $table_obj->get_table_alias() ] = $table_obj;
514
+				}
515
+			}
516
+		}
517
+		// if we don't have all the fields we need, then just fetch the proper model from the DB
518
+		if ($tables_needing_to_be_queried) {
519
+			if (count($tables_needing_to_be_queried) == 1
520
+				&& reset($tables_needing_to_be_queried)
521
+				   instanceof
522
+				   EE_Secondary_Table
523
+			) {
524
+				// so we're only missing data from a secondary table. Well that's not too hard to query for
525
+				$table_to_query = reset($tables_needing_to_be_queried);
526
+				$missing_data = $this->_do_wpdb_query(
527
+					'get_row',
528
+					array(
529
+						'SELECT * FROM '
530
+						. $table_to_query->get_table_name()
531
+						. ' WHERE '
532
+						. $table_to_query->get_fk_on_table()
533
+						. ' = '
534
+						. $post['ID'],
535
+						ARRAY_A,
536
+					)
537
+				);
538
+				if (! empty($missing_data)) {
539
+					$post = array_merge($post, $missing_data);
540
+				}
541
+			} else {
542
+				return $this->get_one_by_ID($post['ID']);
543
+			}
544
+		}
545
+		return $this->instantiate_class_from_array_or_object($post);
546
+	}
547
+
548
+
549
+	/**
550
+	 * Gets the post type associated with this
551
+	 *
552
+	 * @throws EE_Error
553
+	 * @return string
554
+	 */
555
+	public function post_type()
556
+	{
557
+		$post_type_field = null;
558
+		foreach ($this->field_settings(true) as $field_obj) {
559
+			if ($field_obj instanceof EE_WP_Post_Type_Field) {
560
+				$post_type_field = $field_obj;
561
+				break;
562
+			}
563
+		}
564
+		if ($post_type_field == null) {
565
+			throw new EE_Error(
566
+				sprintf(
567
+					__(
568
+						"CPT Model %s should have a field of type EE_WP_Post_Type, but doesnt",
569
+						"event_espresso"
570
+					),
571
+					get_class($this)
572
+				)
573
+			);
574
+		}
575
+		return $post_type_field->get_default_value();
576
+	}
577 577
 }
Please login to merge, or discard this patch.
core/EE_Cron_Tasks.core.php 3 patches
Unused Use Statements   -1 removed lines patch added patch discarded remove patch
@@ -2,7 +2,6 @@
 block discarded – undo
2 2
 
3 3
 use EventEspresso\core\exceptions\InvalidDataTypeException;
4 4
 use EventEspresso\core\exceptions\InvalidInterfaceException;
5
-use EventEspresso\core\services\loaders\Loader;
6 5
 use EventEspresso\core\services\loaders\LoaderFactory;
7 6
 
8 7
 /**
Please login to merge, or discard this patch.
Indentation   +586 added lines, -586 removed lines patch added patch discarded remove patch
@@ -15,590 +15,590 @@
 block discarded – undo
15 15
 class EE_Cron_Tasks extends EE_Base
16 16
 {
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
-    /**
26
-     * @var EE_Cron_Tasks
27
-     */
28
-    private static $_instance;
29
-
30
-
31
-    /**
32
-     * @return EE_Cron_Tasks
33
-     * @throws ReflectionException
34
-     * @throws EE_Error
35
-     * @throws InvalidArgumentException
36
-     * @throws InvalidInterfaceException
37
-     * @throws InvalidDataTypeException
38
-     */
39
-    public static function instance()
40
-    {
41
-        if (! self::$_instance instanceof EE_Cron_Tasks) {
42
-            self::$_instance = new self();
43
-        }
44
-        return self::$_instance;
45
-    }
46
-
47
-
48
-    /**
49
-     * @access private
50
-     * @throws InvalidDataTypeException
51
-     * @throws InvalidInterfaceException
52
-     * @throws InvalidArgumentException
53
-     * @throws EE_Error
54
-     * @throws ReflectionException
55
-     */
56
-    private function __construct()
57
-    {
58
-        do_action('AHEE_log', __CLASS__, __FUNCTION__);
59
-        // verify that WP Cron is enabled
60
-        if (defined('DISABLE_WP_CRON')
61
-            && DISABLE_WP_CRON
62
-            && is_admin()
63
-            && ! get_option('ee_disabled_wp_cron_check')
64
-        ) {
65
-            /**
66
-             * This needs to be delayed until after the config is loaded because EE_Cron_Tasks is constructed before
67
-             * config is loaded.
68
-             * This is intentionally using a anonymous function so that its not easily de-registered.  Client code
69
-             * wanting to not have this functionality can just register its own action at a priority after this one to
70
-             * reverse any changes.
71
-             */
72
-            add_action(
73
-                'AHEE__EE_System__load_core_configuration__complete',
74
-                function () {
75
-                    EE_Registry::instance()->NET_CFG->core->do_messages_on_same_request = true;
76
-                    EE_Registry::instance()->NET_CFG->update_config(true, false);
77
-                    add_option('ee_disabled_wp_cron_check', 1, '', false);
78
-                }
79
-            );
80
-        }
81
-        // UPDATE TRANSACTION WITH PAYMENT
82
-        add_action(
83
-            'AHEE__EE_Cron_Tasks__update_transaction_with_payment_2',
84
-            array('EE_Cron_Tasks', 'setup_update_for_transaction_with_payment'),
85
-            10,
86
-            2
87
-        );
88
-        // ABANDONED / EXPIRED TRANSACTION CHECK
89
-        add_action(
90
-            'AHEE__EE_Cron_Tasks__expired_transaction_check',
91
-            array('EE_Cron_Tasks', 'expired_transaction_check'),
92
-            10,
93
-            1
94
-        );
95
-        // CLEAN OUT JUNK TRANSACTIONS AND RELATED DATA
96
-        add_action(
97
-            'AHEE__EE_Cron_Tasks__clean_up_junk_transactions',
98
-            array('EE_Cron_Tasks', 'clean_out_junk_transactions')
99
-        );
100
-        // logging
101
-        add_action(
102
-            'AHEE__EE_System__load_core_configuration__complete',
103
-            array('EE_Cron_Tasks', 'log_scheduled_ee_crons')
104
-        );
105
-        EE_Registry::instance()->load_lib('Messages_Scheduler');
106
-        // clean out old gateway logs
107
-        add_action(
108
-            'AHEE_EE_Cron_Tasks__clean_out_old_gateway_logs',
109
-            array('EE_Cron_Tasks', 'clean_out_old_gateway_logs')
110
-        );
111
-    }
112
-
113
-
114
-    /**
115
-     * @access protected
116
-     * @return void
117
-     */
118
-    public static function log_scheduled_ee_crons()
119
-    {
120
-        $ee_crons = array(
121
-            'AHEE__EE_Cron_Tasks__update_transaction_with_payment',
122
-            'AHEE__EE_Cron_Tasks__finalize_abandoned_transactions',
123
-            'AHEE__EE_Cron_Tasks__clean_up_junk_transactions',
124
-        );
125
-        $crons = (array) get_option('cron');
126
-        if (! is_array($crons)) {
127
-            return;
128
-        }
129
-        foreach ($crons as $timestamp => $cron) {
130
-            /** @var array[] $cron */
131
-            foreach ($ee_crons as $ee_cron) {
132
-                if (isset($cron[ $ee_cron ]) && is_array($cron[ $ee_cron ])) {
133
-                    do_action('AHEE_log', __CLASS__, __FUNCTION__, $ee_cron, 'scheduled EE cron');
134
-                    foreach ($cron[ $ee_cron ] as $ee_cron_details) {
135
-                        if (! empty($ee_cron_details['args'])) {
136
-                            do_action(
137
-                                'AHEE_log',
138
-                                __CLASS__,
139
-                                __FUNCTION__,
140
-                                print_r($ee_cron_details['args'], true),
141
-                                "{$ee_cron} args"
142
-                            );
143
-                        }
144
-                    }
145
-                }
146
-            }
147
-        }
148
-    }
149
-
150
-
151
-    /**
152
-     * reschedule_cron_for_transactions_if_maintenance_mode
153
-     * if Maintenance Mode is active, this will reschedule a cron to run again in 10 minutes
154
-     *
155
-     * @param string $cron_task
156
-     * @param array  $TXN_IDs
157
-     * @return bool
158
-     * @throws DomainException
159
-     */
160
-    public static function reschedule_cron_for_transactions_if_maintenance_mode($cron_task, array $TXN_IDs)
161
-    {
162
-        if (! method_exists('EE_Cron_Tasks', $cron_task)) {
163
-            throw new DomainException(
164
-                sprintf(
165
-                    __('"%1$s" is not valid method on EE_Cron_Tasks.', 'event_espresso'),
166
-                    $cron_task
167
-                )
168
-            );
169
-        }
170
-        // reschedule the cron if we can't hit the db right now
171
-        if (! EE_Maintenance_Mode::instance()->models_can_query()) {
172
-            foreach ($TXN_IDs as $TXN_ID => $additional_vars) {
173
-                // ensure $additional_vars is an array
174
-                $additional_vars = is_array($additional_vars) ? $additional_vars : array($additional_vars);
175
-                // reset cron job for the TXN
176
-                call_user_func_array(
177
-                    array('EE_Cron_Tasks', $cron_task),
178
-                    array_merge(
179
-                        array(
180
-                            time() + (10 * MINUTE_IN_SECONDS),
181
-                            $TXN_ID,
182
-                        ),
183
-                        $additional_vars
184
-                    )
185
-                );
186
-            }
187
-            return true;
188
-        }
189
-        return false;
190
-    }
191
-
192
-
193
-
194
-
195
-    /****************  UPDATE TRANSACTION WITH PAYMENT ****************/
196
-
197
-
198
-    /**
199
-     * array of TXN IDs and the payment
200
-     *
201
-     * @var array
202
-     */
203
-    protected static $_update_transactions_with_payment = array();
204
-
205
-
206
-    /**
207
-     * schedule_update_transaction_with_payment
208
-     * sets a wp_schedule_single_event() for updating any TXNs that may
209
-     * require updating due to recently received payments
210
-     *
211
-     * @param int $timestamp
212
-     * @param int $TXN_ID
213
-     * @param int $PAY_ID
214
-     */
215
-    public static function schedule_update_transaction_with_payment(
216
-        $timestamp,
217
-        $TXN_ID,
218
-        $PAY_ID
219
-    ) {
220
-        do_action('AHEE_log', __CLASS__, __FUNCTION__);
221
-        // validate $TXN_ID and $timestamp
222
-        $TXN_ID = absint($TXN_ID);
223
-        $timestamp = absint($timestamp);
224
-        if ($TXN_ID && $timestamp) {
225
-            wp_schedule_single_event(
226
-                $timestamp,
227
-                'AHEE__EE_Cron_Tasks__update_transaction_with_payment_2',
228
-                array($TXN_ID, $PAY_ID)
229
-            );
230
-        }
231
-    }
232
-
233
-
234
-    /**
235
-     * setup_update_for_transaction_with_payment
236
-     * this is the callback for the action hook:
237
-     * 'AHEE__EE_Cron_Tasks__update_transaction_with_payment'
238
-     * which is setup by EE_Cron_Tasks::schedule_update_transaction_with_payment().
239
-     * The passed TXN_ID and associated payment gets added to an array, and then
240
-     * the EE_Cron_Tasks::update_transaction_with_payment() function is hooked into
241
-     * 'shutdown' which will actually handle the processing of any
242
-     * transactions requiring updating, because doing so now would be too early
243
-     * and the required resources may not be available
244
-     *
245
-     * @param int $TXN_ID
246
-     * @param int $PAY_ID
247
-     */
248
-    public static function setup_update_for_transaction_with_payment($TXN_ID = 0, $PAY_ID = 0)
249
-    {
250
-        do_action('AHEE_log', __CLASS__, __FUNCTION__, $TXN_ID, '$TXN_ID');
251
-        if (absint($TXN_ID)) {
252
-            self::$_update_transactions_with_payment[ $TXN_ID ] = $PAY_ID;
253
-            add_action(
254
-                'shutdown',
255
-                array('EE_Cron_Tasks', 'update_transaction_with_payment'),
256
-                5
257
-            );
258
-        }
259
-    }
260
-
261
-
262
-    /**
263
-     * update_transaction_with_payment
264
-     * loops through the self::$_abandoned_transactions array
265
-     * and attempts to finalize any TXNs that have not been completed
266
-     * but have had their sessions expired, most likely due to a user not
267
-     * returning from an off-site payment gateway
268
-     *
269
-     * @throws EE_Error
270
-     * @throws DomainException
271
-     * @throws InvalidDataTypeException
272
-     * @throws InvalidInterfaceException
273
-     * @throws InvalidArgumentException
274
-     * @throws ReflectionException
275
-     * @throws RuntimeException
276
-     */
277
-    public static function update_transaction_with_payment()
278
-    {
279
-        do_action('AHEE_log', __CLASS__, __FUNCTION__);
280
-        if (// are there any TXNs that need cleaning up ?
281
-            empty(self::$_update_transactions_with_payment)
282
-            // reschedule the cron if we can't hit the db right now
283
-            || EE_Cron_Tasks::reschedule_cron_for_transactions_if_maintenance_mode(
284
-                'schedule_update_transaction_with_payment',
285
-                self::$_update_transactions_with_payment
286
-            )
287
-        ) {
288
-            return;
289
-        }
290
-        /** @type EE_Payment_Processor $payment_processor */
291
-        $payment_processor = EE_Registry::instance()->load_core('Payment_Processor');
292
-        // set revisit flag for payment processor
293
-        $payment_processor->set_revisit();
294
-        // load EEM_Transaction
295
-        EE_Registry::instance()->load_model('Transaction');
296
-        foreach (self::$_update_transactions_with_payment as $TXN_ID => $PAY_ID) {
297
-            // reschedule the cron if we can't hit the db right now
298
-            if (! EE_Maintenance_Mode::instance()->models_can_query()) {
299
-                // reset cron job for updating the TXN
300
-                EE_Cron_Tasks::schedule_update_transaction_with_payment(
301
-                    time() + EE_Cron_Tasks::reschedule_timeout,
302
-                    $TXN_ID,
303
-                    $PAY_ID
304
-                );
305
-                continue;
306
-            }
307
-            $transaction = EEM_Transaction::instance()->get_one_by_ID($TXN_ID);
308
-            $payment = EEM_Payment::instance()->get_one_by_ID($PAY_ID);
309
-            // verify transaction
310
-            if ($transaction instanceof EE_Transaction && $payment instanceof EE_Payment) {
311
-                // now try to update the TXN with any payments
312
-                $payment_processor->update_txn_based_on_payment($transaction, $payment, true, true);
313
-            }
314
-            unset(self::$_update_transactions_with_payment[ $TXN_ID ]);
315
-        }
316
-    }
317
-
318
-
319
-
320
-    /************  END OF UPDATE TRANSACTION WITH PAYMENT  ************/
321
-
322
-
323
-    /*****************  EXPIRED TRANSACTION CHECK *****************/
324
-
325
-
326
-    /**
327
-     * array of TXN IDs
328
-     *
329
-     * @var array
330
-     */
331
-    protected static $_expired_transactions = array();
332
-
333
-
334
-    /**
335
-     * schedule_expired_transaction_check
336
-     * sets a wp_schedule_single_event() for following up on TXNs after their session has expired
337
-     *
338
-     * @param int $timestamp
339
-     * @param int $TXN_ID
340
-     */
341
-    public static function schedule_expired_transaction_check(
342
-        $timestamp,
343
-        $TXN_ID
344
-    ) {
345
-        // validate $TXN_ID and $timestamp
346
-        $TXN_ID = absint($TXN_ID);
347
-        $timestamp = absint($timestamp);
348
-        if ($TXN_ID && $timestamp) {
349
-            wp_schedule_single_event(
350
-                $timestamp,
351
-                'AHEE__EE_Cron_Tasks__expired_transaction_check',
352
-                array($TXN_ID)
353
-            );
354
-        }
355
-    }
356
-
357
-
358
-    /**
359
-     * expired_transaction_check
360
-     * this is the callback for the action hook:
361
-     * 'AHEE__EE_Cron_Tasks__transaction_session_expiration_check'
362
-     * which is utilized by wp_schedule_single_event()
363
-     * in \EED_Single_Page_Checkout::_initialize_transaction().
364
-     * The passed TXN_ID gets added to an array, and then the
365
-     * process_expired_transactions() function is hooked into
366
-     * 'AHEE__EE_System__core_loaded_and_ready' which will actually handle the
367
-     * processing of any failed transactions, because doing so now would be
368
-     * too early and the required resources may not be available
369
-     *
370
-     * @param int $TXN_ID
371
-     */
372
-    public static function expired_transaction_check($TXN_ID = 0)
373
-    {
374
-        if (absint($TXN_ID)) {
375
-            self::$_expired_transactions[ $TXN_ID ] = $TXN_ID;
376
-            add_action(
377
-                'shutdown',
378
-                array('EE_Cron_Tasks', 'process_expired_transactions'),
379
-                5
380
-            );
381
-        }
382
-    }
383
-
384
-
385
-    /**
386
-     * process_expired_transactions
387
-     * loops through the self::$_expired_transactions array and processes any failed TXNs
388
-     *
389
-     * @throws EE_Error
390
-     * @throws InvalidDataTypeException
391
-     * @throws InvalidInterfaceException
392
-     * @throws InvalidArgumentException
393
-     * @throws ReflectionException
394
-     * @throws DomainException
395
-     * @throws RuntimeException
396
-     */
397
-    public static function process_expired_transactions()
398
-    {
399
-        if (// are there any TXNs that need cleaning up ?
400
-            empty(self::$_expired_transactions)
401
-            // reschedule the cron if we can't hit the db right now
402
-            || EE_Cron_Tasks::reschedule_cron_for_transactions_if_maintenance_mode(
403
-                'schedule_expired_transaction_check',
404
-                self::$_expired_transactions
405
-            )
406
-        ) {
407
-            return;
408
-        }
409
-        /** @type EE_Transaction_Processor $transaction_processor */
410
-        $transaction_processor = EE_Registry::instance()->load_class('Transaction_Processor');
411
-        // set revisit flag for txn processor
412
-        $transaction_processor->set_revisit();
413
-        // load EEM_Transaction
414
-        EE_Registry::instance()->load_model('Transaction');
415
-        foreach (self::$_expired_transactions as $TXN_ID) {
416
-            $transaction = EEM_Transaction::instance()->get_one_by_ID($TXN_ID);
417
-            // verify transaction and whether it is failed or not
418
-            if ($transaction instanceof EE_Transaction) {
419
-                switch ($transaction->status_ID()) {
420
-                    // Completed TXNs
421
-                    case EEM_Transaction::complete_status_code:
422
-                        do_action(
423
-                            'AHEE__EE_Cron_Tasks__process_expired_transactions__completed_transaction',
424
-                            $transaction
425
-                        );
426
-                        break;
427
-                    // Overpaid TXNs
428
-                    case EEM_Transaction::overpaid_status_code:
429
-                        do_action(
430
-                            'AHEE__EE_Cron_Tasks__process_expired_transactions__overpaid_transaction',
431
-                            $transaction
432
-                        );
433
-                        break;
434
-                    // Incomplete TXNs
435
-                    case EEM_Transaction::incomplete_status_code:
436
-                        do_action(
437
-                            'AHEE__EE_Cron_Tasks__process_expired_transactions__incomplete_transaction',
438
-                            $transaction
439
-                        );
440
-                        // todo : move business logic into EE_Transaction_Processor for finalizing abandoned transactions
441
-                        break;
442
-                    // Abandoned TXNs
443
-                    case EEM_Transaction::abandoned_status_code:
444
-                        // run hook before updating transaction, primarily so
445
-                        // EED_Ticket_Sales_Monitor::process_abandoned_transactions() can release reserved tickets
446
-                        do_action(
447
-                            'AHEE__EE_Cron_Tasks__process_expired_transactions__abandoned_transaction',
448
-                            $transaction
449
-                        );
450
-                        // don't finalize the TXN if it has already been completed
451
-                        if ($transaction->all_reg_steps_completed() !== true) {
452
-                            /** @type EE_Payment_Processor $payment_processor */
453
-                            $payment_processor = EE_Registry::instance()->load_core('Payment_Processor');
454
-                            // let's simulate an IPN here which will trigger any notifications that need to go out
455
-                            $payment_processor->update_txn_based_on_payment(
456
-                                $transaction,
457
-                                $transaction->last_payment(),
458
-                                true,
459
-                                true
460
-                            );
461
-                        }
462
-                        break;
463
-                    // Failed TXNs
464
-                    case EEM_Transaction::failed_status_code:
465
-                        do_action(
466
-                            'AHEE__EE_Cron_Tasks__process_expired_transactions__failed_transaction',
467
-                            $transaction
468
-                        );
469
-                        // todo :
470
-                        // perform garbage collection here and remove clean_out_junk_transactions()
471
-                        // $registrations = $transaction->registrations();
472
-                        // if (! empty($registrations)) {
473
-                        //     foreach ($registrations as $registration) {
474
-                        //         if ($registration instanceof EE_Registration) {
475
-                        //             $delete_registration = true;
476
-                        //             if ($registration->attendee() instanceof EE_Attendee) {
477
-                        //                 $delete_registration = false;
478
-                        //             }
479
-                        //             if ($delete_registration) {
480
-                        //                 $registration->delete_permanently();
481
-                        //                 $registration->delete_related_permanently();
482
-                        //             }
483
-                        //         }
484
-                        //     }
485
-                        // }
486
-                        break;
487
-                }
488
-            }
489
-            unset(self::$_expired_transactions[ $TXN_ID ]);
490
-        }
491
-    }
492
-
493
-
494
-
495
-    /*************  END OF EXPIRED TRANSACTION CHECK  *************/
496
-
497
-
498
-    /************* START CLEAN UP BOT TRANSACTIONS **********************/
499
-
500
-
501
-    /**
502
-     * callback for 'AHEE__EE_Cron_Tasks__clean_up_junk_transactions'
503
-     * which is setup during activation to run on an hourly cron
504
-     *
505
-     * @throws EE_Error
506
-     * @throws InvalidArgumentException
507
-     * @throws InvalidDataTypeException
508
-     * @throws InvalidInterfaceException
509
-     * @throws DomainException
510
-     */
511
-    public static function clean_out_junk_transactions()
512
-    {
513
-        if (EE_Maintenance_Mode::instance()->models_can_query()) {
514
-            EED_Ticket_Sales_Monitor::reset_reservation_counts();
515
-            EEM_Transaction::instance('')->delete_junk_transactions();
516
-            EEM_Registration::instance('')->delete_registrations_with_no_transaction();
517
-            EEM_Line_Item::instance('')->delete_line_items_with_no_transaction();
518
-        }
519
-    }
520
-
521
-
522
-    /**
523
-     * Deletes old gateway logs. After about a week we usually don't need them for debugging. But folks can filter that.
524
-     *
525
-     * @throws EE_Error
526
-     * @throws InvalidDataTypeException
527
-     * @throws InvalidInterfaceException
528
-     * @throws InvalidArgumentException
529
-     */
530
-    public static function clean_out_old_gateway_logs()
531
-    {
532
-        if (EE_Maintenance_Mode::instance()->models_can_query()) {
533
-            $reg_config = LoaderFactory::getLoader()->load('EE_Registration_Config');
534
-            $time_diff_for_comparison = apply_filters(
535
-                'FHEE__EE_Cron_Tasks__clean_out_old_gateway_logs__time_diff_for_comparison',
536
-                '-' . $reg_config->gateway_log_lifespan
537
-            );
538
-            EEM_Change_Log::instance()->delete_gateway_logs_older_than(new DateTime($time_diff_for_comparison));
539
-        }
540
-    }
541
-
542
-
543
-    /*****************  FINALIZE ABANDONED TRANSACTIONS *****************/
544
-
545
-
546
-    /**
547
-     * @var array
548
-     */
549
-    protected static $_abandoned_transactions = array();
550
-
551
-
552
-    /**
553
-     * @deprecated
554
-     * @param int $timestamp
555
-     * @param int $TXN_ID
556
-     */
557
-    public static function schedule_finalize_abandoned_transactions_check($timestamp, $TXN_ID)
558
-    {
559
-        EE_Cron_Tasks::schedule_expired_transaction_check($timestamp, $TXN_ID);
560
-    }
561
-
562
-
563
-    /**
564
-     * @deprecated
565
-     * @param int $TXN_ID
566
-     */
567
-    public static function check_for_abandoned_transactions($TXN_ID = 0)
568
-    {
569
-        EE_Cron_Tasks::expired_transaction_check($TXN_ID);
570
-    }
571
-
572
-
573
-    /**
574
-     * @deprecated
575
-     * @throws EE_Error
576
-     * @throws DomainException
577
-     * @throws InvalidDataTypeException
578
-     * @throws InvalidInterfaceException
579
-     * @throws InvalidArgumentException
580
-     * @throws ReflectionException
581
-     * @throws RuntimeException
582
-     */
583
-    public static function finalize_abandoned_transactions()
584
-    {
585
-        do_action('AHEE_log', __CLASS__, __FUNCTION__);
586
-        if (// are there any TXNs that need cleaning up ?
587
-            empty(self::$_abandoned_transactions)
588
-            // reschedule the cron if we can't hit the db right now
589
-            || EE_Cron_Tasks::reschedule_cron_for_transactions_if_maintenance_mode(
590
-                'schedule_expired_transaction_check',
591
-                self::$_abandoned_transactions
592
-            )
593
-        ) {
594
-            return;
595
-        }
596
-        // combine our arrays of transaction IDs
597
-        self::$_expired_transactions = self::$_abandoned_transactions + self::$_expired_transactions;
598
-        // and deal with abandoned transactions here now...
599
-        EE_Cron_Tasks::process_expired_transactions();
600
-    }
601
-
602
-
603
-    /*************  END OF FINALIZE ABANDONED TRANSACTIONS  *************/
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
+	/**
26
+	 * @var EE_Cron_Tasks
27
+	 */
28
+	private static $_instance;
29
+
30
+
31
+	/**
32
+	 * @return EE_Cron_Tasks
33
+	 * @throws ReflectionException
34
+	 * @throws EE_Error
35
+	 * @throws InvalidArgumentException
36
+	 * @throws InvalidInterfaceException
37
+	 * @throws InvalidDataTypeException
38
+	 */
39
+	public static function instance()
40
+	{
41
+		if (! self::$_instance instanceof EE_Cron_Tasks) {
42
+			self::$_instance = new self();
43
+		}
44
+		return self::$_instance;
45
+	}
46
+
47
+
48
+	/**
49
+	 * @access private
50
+	 * @throws InvalidDataTypeException
51
+	 * @throws InvalidInterfaceException
52
+	 * @throws InvalidArgumentException
53
+	 * @throws EE_Error
54
+	 * @throws ReflectionException
55
+	 */
56
+	private function __construct()
57
+	{
58
+		do_action('AHEE_log', __CLASS__, __FUNCTION__);
59
+		// verify that WP Cron is enabled
60
+		if (defined('DISABLE_WP_CRON')
61
+			&& DISABLE_WP_CRON
62
+			&& is_admin()
63
+			&& ! get_option('ee_disabled_wp_cron_check')
64
+		) {
65
+			/**
66
+			 * This needs to be delayed until after the config is loaded because EE_Cron_Tasks is constructed before
67
+			 * config is loaded.
68
+			 * This is intentionally using a anonymous function so that its not easily de-registered.  Client code
69
+			 * wanting to not have this functionality can just register its own action at a priority after this one to
70
+			 * reverse any changes.
71
+			 */
72
+			add_action(
73
+				'AHEE__EE_System__load_core_configuration__complete',
74
+				function () {
75
+					EE_Registry::instance()->NET_CFG->core->do_messages_on_same_request = true;
76
+					EE_Registry::instance()->NET_CFG->update_config(true, false);
77
+					add_option('ee_disabled_wp_cron_check', 1, '', false);
78
+				}
79
+			);
80
+		}
81
+		// UPDATE TRANSACTION WITH PAYMENT
82
+		add_action(
83
+			'AHEE__EE_Cron_Tasks__update_transaction_with_payment_2',
84
+			array('EE_Cron_Tasks', 'setup_update_for_transaction_with_payment'),
85
+			10,
86
+			2
87
+		);
88
+		// ABANDONED / EXPIRED TRANSACTION CHECK
89
+		add_action(
90
+			'AHEE__EE_Cron_Tasks__expired_transaction_check',
91
+			array('EE_Cron_Tasks', 'expired_transaction_check'),
92
+			10,
93
+			1
94
+		);
95
+		// CLEAN OUT JUNK TRANSACTIONS AND RELATED DATA
96
+		add_action(
97
+			'AHEE__EE_Cron_Tasks__clean_up_junk_transactions',
98
+			array('EE_Cron_Tasks', 'clean_out_junk_transactions')
99
+		);
100
+		// logging
101
+		add_action(
102
+			'AHEE__EE_System__load_core_configuration__complete',
103
+			array('EE_Cron_Tasks', 'log_scheduled_ee_crons')
104
+		);
105
+		EE_Registry::instance()->load_lib('Messages_Scheduler');
106
+		// clean out old gateway logs
107
+		add_action(
108
+			'AHEE_EE_Cron_Tasks__clean_out_old_gateway_logs',
109
+			array('EE_Cron_Tasks', 'clean_out_old_gateway_logs')
110
+		);
111
+	}
112
+
113
+
114
+	/**
115
+	 * @access protected
116
+	 * @return void
117
+	 */
118
+	public static function log_scheduled_ee_crons()
119
+	{
120
+		$ee_crons = array(
121
+			'AHEE__EE_Cron_Tasks__update_transaction_with_payment',
122
+			'AHEE__EE_Cron_Tasks__finalize_abandoned_transactions',
123
+			'AHEE__EE_Cron_Tasks__clean_up_junk_transactions',
124
+		);
125
+		$crons = (array) get_option('cron');
126
+		if (! is_array($crons)) {
127
+			return;
128
+		}
129
+		foreach ($crons as $timestamp => $cron) {
130
+			/** @var array[] $cron */
131
+			foreach ($ee_crons as $ee_cron) {
132
+				if (isset($cron[ $ee_cron ]) && is_array($cron[ $ee_cron ])) {
133
+					do_action('AHEE_log', __CLASS__, __FUNCTION__, $ee_cron, 'scheduled EE cron');
134
+					foreach ($cron[ $ee_cron ] as $ee_cron_details) {
135
+						if (! empty($ee_cron_details['args'])) {
136
+							do_action(
137
+								'AHEE_log',
138
+								__CLASS__,
139
+								__FUNCTION__,
140
+								print_r($ee_cron_details['args'], true),
141
+								"{$ee_cron} args"
142
+							);
143
+						}
144
+					}
145
+				}
146
+			}
147
+		}
148
+	}
149
+
150
+
151
+	/**
152
+	 * reschedule_cron_for_transactions_if_maintenance_mode
153
+	 * if Maintenance Mode is active, this will reschedule a cron to run again in 10 minutes
154
+	 *
155
+	 * @param string $cron_task
156
+	 * @param array  $TXN_IDs
157
+	 * @return bool
158
+	 * @throws DomainException
159
+	 */
160
+	public static function reschedule_cron_for_transactions_if_maintenance_mode($cron_task, array $TXN_IDs)
161
+	{
162
+		if (! method_exists('EE_Cron_Tasks', $cron_task)) {
163
+			throw new DomainException(
164
+				sprintf(
165
+					__('"%1$s" is not valid method on EE_Cron_Tasks.', 'event_espresso'),
166
+					$cron_task
167
+				)
168
+			);
169
+		}
170
+		// reschedule the cron if we can't hit the db right now
171
+		if (! EE_Maintenance_Mode::instance()->models_can_query()) {
172
+			foreach ($TXN_IDs as $TXN_ID => $additional_vars) {
173
+				// ensure $additional_vars is an array
174
+				$additional_vars = is_array($additional_vars) ? $additional_vars : array($additional_vars);
175
+				// reset cron job for the TXN
176
+				call_user_func_array(
177
+					array('EE_Cron_Tasks', $cron_task),
178
+					array_merge(
179
+						array(
180
+							time() + (10 * MINUTE_IN_SECONDS),
181
+							$TXN_ID,
182
+						),
183
+						$additional_vars
184
+					)
185
+				);
186
+			}
187
+			return true;
188
+		}
189
+		return false;
190
+	}
191
+
192
+
193
+
194
+
195
+	/****************  UPDATE TRANSACTION WITH PAYMENT ****************/
196
+
197
+
198
+	/**
199
+	 * array of TXN IDs and the payment
200
+	 *
201
+	 * @var array
202
+	 */
203
+	protected static $_update_transactions_with_payment = array();
204
+
205
+
206
+	/**
207
+	 * schedule_update_transaction_with_payment
208
+	 * sets a wp_schedule_single_event() for updating any TXNs that may
209
+	 * require updating due to recently received payments
210
+	 *
211
+	 * @param int $timestamp
212
+	 * @param int $TXN_ID
213
+	 * @param int $PAY_ID
214
+	 */
215
+	public static function schedule_update_transaction_with_payment(
216
+		$timestamp,
217
+		$TXN_ID,
218
+		$PAY_ID
219
+	) {
220
+		do_action('AHEE_log', __CLASS__, __FUNCTION__);
221
+		// validate $TXN_ID and $timestamp
222
+		$TXN_ID = absint($TXN_ID);
223
+		$timestamp = absint($timestamp);
224
+		if ($TXN_ID && $timestamp) {
225
+			wp_schedule_single_event(
226
+				$timestamp,
227
+				'AHEE__EE_Cron_Tasks__update_transaction_with_payment_2',
228
+				array($TXN_ID, $PAY_ID)
229
+			);
230
+		}
231
+	}
232
+
233
+
234
+	/**
235
+	 * setup_update_for_transaction_with_payment
236
+	 * this is the callback for the action hook:
237
+	 * 'AHEE__EE_Cron_Tasks__update_transaction_with_payment'
238
+	 * which is setup by EE_Cron_Tasks::schedule_update_transaction_with_payment().
239
+	 * The passed TXN_ID and associated payment gets added to an array, and then
240
+	 * the EE_Cron_Tasks::update_transaction_with_payment() function is hooked into
241
+	 * 'shutdown' which will actually handle the processing of any
242
+	 * transactions requiring updating, because doing so now would be too early
243
+	 * and the required resources may not be available
244
+	 *
245
+	 * @param int $TXN_ID
246
+	 * @param int $PAY_ID
247
+	 */
248
+	public static function setup_update_for_transaction_with_payment($TXN_ID = 0, $PAY_ID = 0)
249
+	{
250
+		do_action('AHEE_log', __CLASS__, __FUNCTION__, $TXN_ID, '$TXN_ID');
251
+		if (absint($TXN_ID)) {
252
+			self::$_update_transactions_with_payment[ $TXN_ID ] = $PAY_ID;
253
+			add_action(
254
+				'shutdown',
255
+				array('EE_Cron_Tasks', 'update_transaction_with_payment'),
256
+				5
257
+			);
258
+		}
259
+	}
260
+
261
+
262
+	/**
263
+	 * update_transaction_with_payment
264
+	 * loops through the self::$_abandoned_transactions array
265
+	 * and attempts to finalize any TXNs that have not been completed
266
+	 * but have had their sessions expired, most likely due to a user not
267
+	 * returning from an off-site payment gateway
268
+	 *
269
+	 * @throws EE_Error
270
+	 * @throws DomainException
271
+	 * @throws InvalidDataTypeException
272
+	 * @throws InvalidInterfaceException
273
+	 * @throws InvalidArgumentException
274
+	 * @throws ReflectionException
275
+	 * @throws RuntimeException
276
+	 */
277
+	public static function update_transaction_with_payment()
278
+	{
279
+		do_action('AHEE_log', __CLASS__, __FUNCTION__);
280
+		if (// are there any TXNs that need cleaning up ?
281
+			empty(self::$_update_transactions_with_payment)
282
+			// reschedule the cron if we can't hit the db right now
283
+			|| EE_Cron_Tasks::reschedule_cron_for_transactions_if_maintenance_mode(
284
+				'schedule_update_transaction_with_payment',
285
+				self::$_update_transactions_with_payment
286
+			)
287
+		) {
288
+			return;
289
+		}
290
+		/** @type EE_Payment_Processor $payment_processor */
291
+		$payment_processor = EE_Registry::instance()->load_core('Payment_Processor');
292
+		// set revisit flag for payment processor
293
+		$payment_processor->set_revisit();
294
+		// load EEM_Transaction
295
+		EE_Registry::instance()->load_model('Transaction');
296
+		foreach (self::$_update_transactions_with_payment as $TXN_ID => $PAY_ID) {
297
+			// reschedule the cron if we can't hit the db right now
298
+			if (! EE_Maintenance_Mode::instance()->models_can_query()) {
299
+				// reset cron job for updating the TXN
300
+				EE_Cron_Tasks::schedule_update_transaction_with_payment(
301
+					time() + EE_Cron_Tasks::reschedule_timeout,
302
+					$TXN_ID,
303
+					$PAY_ID
304
+				);
305
+				continue;
306
+			}
307
+			$transaction = EEM_Transaction::instance()->get_one_by_ID($TXN_ID);
308
+			$payment = EEM_Payment::instance()->get_one_by_ID($PAY_ID);
309
+			// verify transaction
310
+			if ($transaction instanceof EE_Transaction && $payment instanceof EE_Payment) {
311
+				// now try to update the TXN with any payments
312
+				$payment_processor->update_txn_based_on_payment($transaction, $payment, true, true);
313
+			}
314
+			unset(self::$_update_transactions_with_payment[ $TXN_ID ]);
315
+		}
316
+	}
317
+
318
+
319
+
320
+	/************  END OF UPDATE TRANSACTION WITH PAYMENT  ************/
321
+
322
+
323
+	/*****************  EXPIRED TRANSACTION CHECK *****************/
324
+
325
+
326
+	/**
327
+	 * array of TXN IDs
328
+	 *
329
+	 * @var array
330
+	 */
331
+	protected static $_expired_transactions = array();
332
+
333
+
334
+	/**
335
+	 * schedule_expired_transaction_check
336
+	 * sets a wp_schedule_single_event() for following up on TXNs after their session has expired
337
+	 *
338
+	 * @param int $timestamp
339
+	 * @param int $TXN_ID
340
+	 */
341
+	public static function schedule_expired_transaction_check(
342
+		$timestamp,
343
+		$TXN_ID
344
+	) {
345
+		// validate $TXN_ID and $timestamp
346
+		$TXN_ID = absint($TXN_ID);
347
+		$timestamp = absint($timestamp);
348
+		if ($TXN_ID && $timestamp) {
349
+			wp_schedule_single_event(
350
+				$timestamp,
351
+				'AHEE__EE_Cron_Tasks__expired_transaction_check',
352
+				array($TXN_ID)
353
+			);
354
+		}
355
+	}
356
+
357
+
358
+	/**
359
+	 * expired_transaction_check
360
+	 * this is the callback for the action hook:
361
+	 * 'AHEE__EE_Cron_Tasks__transaction_session_expiration_check'
362
+	 * which is utilized by wp_schedule_single_event()
363
+	 * in \EED_Single_Page_Checkout::_initialize_transaction().
364
+	 * The passed TXN_ID gets added to an array, and then the
365
+	 * process_expired_transactions() function is hooked into
366
+	 * 'AHEE__EE_System__core_loaded_and_ready' which will actually handle the
367
+	 * processing of any failed transactions, because doing so now would be
368
+	 * too early and the required resources may not be available
369
+	 *
370
+	 * @param int $TXN_ID
371
+	 */
372
+	public static function expired_transaction_check($TXN_ID = 0)
373
+	{
374
+		if (absint($TXN_ID)) {
375
+			self::$_expired_transactions[ $TXN_ID ] = $TXN_ID;
376
+			add_action(
377
+				'shutdown',
378
+				array('EE_Cron_Tasks', 'process_expired_transactions'),
379
+				5
380
+			);
381
+		}
382
+	}
383
+
384
+
385
+	/**
386
+	 * process_expired_transactions
387
+	 * loops through the self::$_expired_transactions array and processes any failed TXNs
388
+	 *
389
+	 * @throws EE_Error
390
+	 * @throws InvalidDataTypeException
391
+	 * @throws InvalidInterfaceException
392
+	 * @throws InvalidArgumentException
393
+	 * @throws ReflectionException
394
+	 * @throws DomainException
395
+	 * @throws RuntimeException
396
+	 */
397
+	public static function process_expired_transactions()
398
+	{
399
+		if (// are there any TXNs that need cleaning up ?
400
+			empty(self::$_expired_transactions)
401
+			// reschedule the cron if we can't hit the db right now
402
+			|| EE_Cron_Tasks::reschedule_cron_for_transactions_if_maintenance_mode(
403
+				'schedule_expired_transaction_check',
404
+				self::$_expired_transactions
405
+			)
406
+		) {
407
+			return;
408
+		}
409
+		/** @type EE_Transaction_Processor $transaction_processor */
410
+		$transaction_processor = EE_Registry::instance()->load_class('Transaction_Processor');
411
+		// set revisit flag for txn processor
412
+		$transaction_processor->set_revisit();
413
+		// load EEM_Transaction
414
+		EE_Registry::instance()->load_model('Transaction');
415
+		foreach (self::$_expired_transactions as $TXN_ID) {
416
+			$transaction = EEM_Transaction::instance()->get_one_by_ID($TXN_ID);
417
+			// verify transaction and whether it is failed or not
418
+			if ($transaction instanceof EE_Transaction) {
419
+				switch ($transaction->status_ID()) {
420
+					// Completed TXNs
421
+					case EEM_Transaction::complete_status_code:
422
+						do_action(
423
+							'AHEE__EE_Cron_Tasks__process_expired_transactions__completed_transaction',
424
+							$transaction
425
+						);
426
+						break;
427
+					// Overpaid TXNs
428
+					case EEM_Transaction::overpaid_status_code:
429
+						do_action(
430
+							'AHEE__EE_Cron_Tasks__process_expired_transactions__overpaid_transaction',
431
+							$transaction
432
+						);
433
+						break;
434
+					// Incomplete TXNs
435
+					case EEM_Transaction::incomplete_status_code:
436
+						do_action(
437
+							'AHEE__EE_Cron_Tasks__process_expired_transactions__incomplete_transaction',
438
+							$transaction
439
+						);
440
+						// todo : move business logic into EE_Transaction_Processor for finalizing abandoned transactions
441
+						break;
442
+					// Abandoned TXNs
443
+					case EEM_Transaction::abandoned_status_code:
444
+						// run hook before updating transaction, primarily so
445
+						// EED_Ticket_Sales_Monitor::process_abandoned_transactions() can release reserved tickets
446
+						do_action(
447
+							'AHEE__EE_Cron_Tasks__process_expired_transactions__abandoned_transaction',
448
+							$transaction
449
+						);
450
+						// don't finalize the TXN if it has already been completed
451
+						if ($transaction->all_reg_steps_completed() !== true) {
452
+							/** @type EE_Payment_Processor $payment_processor */
453
+							$payment_processor = EE_Registry::instance()->load_core('Payment_Processor');
454
+							// let's simulate an IPN here which will trigger any notifications that need to go out
455
+							$payment_processor->update_txn_based_on_payment(
456
+								$transaction,
457
+								$transaction->last_payment(),
458
+								true,
459
+								true
460
+							);
461
+						}
462
+						break;
463
+					// Failed TXNs
464
+					case EEM_Transaction::failed_status_code:
465
+						do_action(
466
+							'AHEE__EE_Cron_Tasks__process_expired_transactions__failed_transaction',
467
+							$transaction
468
+						);
469
+						// todo :
470
+						// perform garbage collection here and remove clean_out_junk_transactions()
471
+						// $registrations = $transaction->registrations();
472
+						// if (! empty($registrations)) {
473
+						//     foreach ($registrations as $registration) {
474
+						//         if ($registration instanceof EE_Registration) {
475
+						//             $delete_registration = true;
476
+						//             if ($registration->attendee() instanceof EE_Attendee) {
477
+						//                 $delete_registration = false;
478
+						//             }
479
+						//             if ($delete_registration) {
480
+						//                 $registration->delete_permanently();
481
+						//                 $registration->delete_related_permanently();
482
+						//             }
483
+						//         }
484
+						//     }
485
+						// }
486
+						break;
487
+				}
488
+			}
489
+			unset(self::$_expired_transactions[ $TXN_ID ]);
490
+		}
491
+	}
492
+
493
+
494
+
495
+	/*************  END OF EXPIRED TRANSACTION CHECK  *************/
496
+
497
+
498
+	/************* START CLEAN UP BOT TRANSACTIONS **********************/
499
+
500
+
501
+	/**
502
+	 * callback for 'AHEE__EE_Cron_Tasks__clean_up_junk_transactions'
503
+	 * which is setup during activation to run on an hourly cron
504
+	 *
505
+	 * @throws EE_Error
506
+	 * @throws InvalidArgumentException
507
+	 * @throws InvalidDataTypeException
508
+	 * @throws InvalidInterfaceException
509
+	 * @throws DomainException
510
+	 */
511
+	public static function clean_out_junk_transactions()
512
+	{
513
+		if (EE_Maintenance_Mode::instance()->models_can_query()) {
514
+			EED_Ticket_Sales_Monitor::reset_reservation_counts();
515
+			EEM_Transaction::instance('')->delete_junk_transactions();
516
+			EEM_Registration::instance('')->delete_registrations_with_no_transaction();
517
+			EEM_Line_Item::instance('')->delete_line_items_with_no_transaction();
518
+		}
519
+	}
520
+
521
+
522
+	/**
523
+	 * Deletes old gateway logs. After about a week we usually don't need them for debugging. But folks can filter that.
524
+	 *
525
+	 * @throws EE_Error
526
+	 * @throws InvalidDataTypeException
527
+	 * @throws InvalidInterfaceException
528
+	 * @throws InvalidArgumentException
529
+	 */
530
+	public static function clean_out_old_gateway_logs()
531
+	{
532
+		if (EE_Maintenance_Mode::instance()->models_can_query()) {
533
+			$reg_config = LoaderFactory::getLoader()->load('EE_Registration_Config');
534
+			$time_diff_for_comparison = apply_filters(
535
+				'FHEE__EE_Cron_Tasks__clean_out_old_gateway_logs__time_diff_for_comparison',
536
+				'-' . $reg_config->gateway_log_lifespan
537
+			);
538
+			EEM_Change_Log::instance()->delete_gateway_logs_older_than(new DateTime($time_diff_for_comparison));
539
+		}
540
+	}
541
+
542
+
543
+	/*****************  FINALIZE ABANDONED TRANSACTIONS *****************/
544
+
545
+
546
+	/**
547
+	 * @var array
548
+	 */
549
+	protected static $_abandoned_transactions = array();
550
+
551
+
552
+	/**
553
+	 * @deprecated
554
+	 * @param int $timestamp
555
+	 * @param int $TXN_ID
556
+	 */
557
+	public static function schedule_finalize_abandoned_transactions_check($timestamp, $TXN_ID)
558
+	{
559
+		EE_Cron_Tasks::schedule_expired_transaction_check($timestamp, $TXN_ID);
560
+	}
561
+
562
+
563
+	/**
564
+	 * @deprecated
565
+	 * @param int $TXN_ID
566
+	 */
567
+	public static function check_for_abandoned_transactions($TXN_ID = 0)
568
+	{
569
+		EE_Cron_Tasks::expired_transaction_check($TXN_ID);
570
+	}
571
+
572
+
573
+	/**
574
+	 * @deprecated
575
+	 * @throws EE_Error
576
+	 * @throws DomainException
577
+	 * @throws InvalidDataTypeException
578
+	 * @throws InvalidInterfaceException
579
+	 * @throws InvalidArgumentException
580
+	 * @throws ReflectionException
581
+	 * @throws RuntimeException
582
+	 */
583
+	public static function finalize_abandoned_transactions()
584
+	{
585
+		do_action('AHEE_log', __CLASS__, __FUNCTION__);
586
+		if (// are there any TXNs that need cleaning up ?
587
+			empty(self::$_abandoned_transactions)
588
+			// reschedule the cron if we can't hit the db right now
589
+			|| EE_Cron_Tasks::reschedule_cron_for_transactions_if_maintenance_mode(
590
+				'schedule_expired_transaction_check',
591
+				self::$_abandoned_transactions
592
+			)
593
+		) {
594
+			return;
595
+		}
596
+		// combine our arrays of transaction IDs
597
+		self::$_expired_transactions = self::$_abandoned_transactions + self::$_expired_transactions;
598
+		// and deal with abandoned transactions here now...
599
+		EE_Cron_Tasks::process_expired_transactions();
600
+	}
601
+
602
+
603
+	/*************  END OF FINALIZE ABANDONED TRANSACTIONS  *************/
604 604
 }
Please login to merge, or discard this patch.
Spacing   +14 added lines, -14 removed lines patch added patch discarded remove patch
@@ -38,7 +38,7 @@  discard block
 block discarded – undo
38 38
      */
39 39
     public static function instance()
40 40
     {
41
-        if (! self::$_instance instanceof EE_Cron_Tasks) {
41
+        if ( ! self::$_instance instanceof EE_Cron_Tasks) {
42 42
             self::$_instance = new self();
43 43
         }
44 44
         return self::$_instance;
@@ -71,7 +71,7 @@  discard block
 block discarded – undo
71 71
              */
72 72
             add_action(
73 73
                 'AHEE__EE_System__load_core_configuration__complete',
74
-                function () {
74
+                function() {
75 75
                     EE_Registry::instance()->NET_CFG->core->do_messages_on_same_request = true;
76 76
                     EE_Registry::instance()->NET_CFG->update_config(true, false);
77 77
                     add_option('ee_disabled_wp_cron_check', 1, '', false);
@@ -123,16 +123,16 @@  discard block
 block discarded – undo
123 123
             'AHEE__EE_Cron_Tasks__clean_up_junk_transactions',
124 124
         );
125 125
         $crons = (array) get_option('cron');
126
-        if (! is_array($crons)) {
126
+        if ( ! is_array($crons)) {
127 127
             return;
128 128
         }
129 129
         foreach ($crons as $timestamp => $cron) {
130 130
             /** @var array[] $cron */
131 131
             foreach ($ee_crons as $ee_cron) {
132
-                if (isset($cron[ $ee_cron ]) && is_array($cron[ $ee_cron ])) {
132
+                if (isset($cron[$ee_cron]) && is_array($cron[$ee_cron])) {
133 133
                     do_action('AHEE_log', __CLASS__, __FUNCTION__, $ee_cron, 'scheduled EE cron');
134
-                    foreach ($cron[ $ee_cron ] as $ee_cron_details) {
135
-                        if (! empty($ee_cron_details['args'])) {
134
+                    foreach ($cron[$ee_cron] as $ee_cron_details) {
135
+                        if ( ! empty($ee_cron_details['args'])) {
136 136
                             do_action(
137 137
                                 'AHEE_log',
138 138
                                 __CLASS__,
@@ -159,7 +159,7 @@  discard block
 block discarded – undo
159 159
      */
160 160
     public static function reschedule_cron_for_transactions_if_maintenance_mode($cron_task, array $TXN_IDs)
161 161
     {
162
-        if (! method_exists('EE_Cron_Tasks', $cron_task)) {
162
+        if ( ! method_exists('EE_Cron_Tasks', $cron_task)) {
163 163
             throw new DomainException(
164 164
                 sprintf(
165 165
                     __('"%1$s" is not valid method on EE_Cron_Tasks.', 'event_espresso'),
@@ -168,7 +168,7 @@  discard block
 block discarded – undo
168 168
             );
169 169
         }
170 170
         // reschedule the cron if we can't hit the db right now
171
-        if (! EE_Maintenance_Mode::instance()->models_can_query()) {
171
+        if ( ! EE_Maintenance_Mode::instance()->models_can_query()) {
172 172
             foreach ($TXN_IDs as $TXN_ID => $additional_vars) {
173 173
                 // ensure $additional_vars is an array
174 174
                 $additional_vars = is_array($additional_vars) ? $additional_vars : array($additional_vars);
@@ -249,7 +249,7 @@  discard block
 block discarded – undo
249 249
     {
250 250
         do_action('AHEE_log', __CLASS__, __FUNCTION__, $TXN_ID, '$TXN_ID');
251 251
         if (absint($TXN_ID)) {
252
-            self::$_update_transactions_with_payment[ $TXN_ID ] = $PAY_ID;
252
+            self::$_update_transactions_with_payment[$TXN_ID] = $PAY_ID;
253 253
             add_action(
254 254
                 'shutdown',
255 255
                 array('EE_Cron_Tasks', 'update_transaction_with_payment'),
@@ -295,7 +295,7 @@  discard block
 block discarded – undo
295 295
         EE_Registry::instance()->load_model('Transaction');
296 296
         foreach (self::$_update_transactions_with_payment as $TXN_ID => $PAY_ID) {
297 297
             // reschedule the cron if we can't hit the db right now
298
-            if (! EE_Maintenance_Mode::instance()->models_can_query()) {
298
+            if ( ! EE_Maintenance_Mode::instance()->models_can_query()) {
299 299
                 // reset cron job for updating the TXN
300 300
                 EE_Cron_Tasks::schedule_update_transaction_with_payment(
301 301
                     time() + EE_Cron_Tasks::reschedule_timeout,
@@ -311,7 +311,7 @@  discard block
 block discarded – undo
311 311
                 // now try to update the TXN with any payments
312 312
                 $payment_processor->update_txn_based_on_payment($transaction, $payment, true, true);
313 313
             }
314
-            unset(self::$_update_transactions_with_payment[ $TXN_ID ]);
314
+            unset(self::$_update_transactions_with_payment[$TXN_ID]);
315 315
         }
316 316
     }
317 317
 
@@ -372,7 +372,7 @@  discard block
 block discarded – undo
372 372
     public static function expired_transaction_check($TXN_ID = 0)
373 373
     {
374 374
         if (absint($TXN_ID)) {
375
-            self::$_expired_transactions[ $TXN_ID ] = $TXN_ID;
375
+            self::$_expired_transactions[$TXN_ID] = $TXN_ID;
376 376
             add_action(
377 377
                 'shutdown',
378 378
                 array('EE_Cron_Tasks', 'process_expired_transactions'),
@@ -486,7 +486,7 @@  discard block
 block discarded – undo
486 486
                         break;
487 487
                 }
488 488
             }
489
-            unset(self::$_expired_transactions[ $TXN_ID ]);
489
+            unset(self::$_expired_transactions[$TXN_ID]);
490 490
         }
491 491
     }
492 492
 
@@ -533,7 +533,7 @@  discard block
 block discarded – undo
533 533
             $reg_config = LoaderFactory::getLoader()->load('EE_Registration_Config');
534 534
             $time_diff_for_comparison = apply_filters(
535 535
                 'FHEE__EE_Cron_Tasks__clean_out_old_gateway_logs__time_diff_for_comparison',
536
-                '-' . $reg_config->gateway_log_lifespan
536
+                '-'.$reg_config->gateway_log_lifespan
537 537
             );
538 538
             EEM_Change_Log::instance()->delete_gateway_logs_older_than(new DateTime($time_diff_for_comparison));
539 539
         }
Please login to merge, or discard this patch.
core/EE_Dependency_Map.core.php 2 patches
Spacing   +33 added lines, -33 removed lines patch added patch discarded remove patch
@@ -122,7 +122,7 @@  discard block
 block discarded – undo
122 122
     public static function instance(ClassInterfaceCache $class_cache = null)
123 123
     {
124 124
         // check if class object is instantiated, and instantiated properly
125
-        if (! self::$_instance instanceof EE_Dependency_Map
125
+        if ( ! self::$_instance instanceof EE_Dependency_Map
126 126
             && $class_cache instanceof ClassInterfaceCache
127 127
         ) {
128 128
             self::$_instance = new EE_Dependency_Map($class_cache);
@@ -203,18 +203,18 @@  discard block
 block discarded – undo
203 203
     ) {
204 204
         $class = trim($class, '\\');
205 205
         $registered = false;
206
-        if (empty(self::$_instance->_dependency_map[ $class ])) {
207
-            self::$_instance->_dependency_map[ $class ] = array();
206
+        if (empty(self::$_instance->_dependency_map[$class])) {
207
+            self::$_instance->_dependency_map[$class] = array();
208 208
         }
209 209
         // we need to make sure that any aliases used when registering a dependency
210 210
         // get resolved to the correct class name
211 211
         foreach ($dependencies as $dependency => $load_source) {
212 212
             $alias = self::$_instance->getFqnForAlias($dependency);
213 213
             if ($overwrite === EE_Dependency_Map::OVERWRITE_DEPENDENCIES
214
-                || ! isset(self::$_instance->_dependency_map[ $class ][ $alias ])
214
+                || ! isset(self::$_instance->_dependency_map[$class][$alias])
215 215
             ) {
216
-                unset($dependencies[ $dependency ]);
217
-                $dependencies[ $alias ] = $load_source;
216
+                unset($dependencies[$dependency]);
217
+                $dependencies[$alias] = $load_source;
218 218
                 $registered = true;
219 219
             }
220 220
         }
@@ -224,13 +224,13 @@  discard block
 block discarded – undo
224 224
         // ie: with A = B + C, entries in B take precedence over duplicate entries in C
225 225
         // Union is way faster than array_merge() but should be used with caution...
226 226
         // especially with numerically indexed arrays
227
-        $dependencies += self::$_instance->_dependency_map[ $class ];
227
+        $dependencies += self::$_instance->_dependency_map[$class];
228 228
         // now we need to ensure that the resulting dependencies
229 229
         // array only has the entries that are required for the class
230 230
         // so first count how many dependencies were originally registered for the class
231
-        $dependency_count = count(self::$_instance->_dependency_map[ $class ]);
231
+        $dependency_count = count(self::$_instance->_dependency_map[$class]);
232 232
         // if that count is non-zero (meaning dependencies were already registered)
233
-        self::$_instance->_dependency_map[ $class ] = $dependency_count
233
+        self::$_instance->_dependency_map[$class] = $dependency_count
234 234
             // then truncate the  final array to match that count
235 235
             ? array_slice($dependencies, 0, $dependency_count)
236 236
             // otherwise just take the incoming array because nothing previously existed
@@ -247,13 +247,13 @@  discard block
 block discarded – undo
247 247
      */
248 248
     public static function register_class_loader($class_name, $loader = 'load_core')
249 249
     {
250
-        if (! $loader instanceof Closure && strpos($class_name, '\\') !== false) {
250
+        if ( ! $loader instanceof Closure && strpos($class_name, '\\') !== false) {
251 251
             throw new DomainException(
252 252
                 esc_html__('Don\'t use class loaders for FQCNs.', 'event_espresso')
253 253
             );
254 254
         }
255 255
         // check that loader is callable or method starts with "load_" and exists in EE_Registry
256
-        if (! is_callable($loader)
256
+        if ( ! is_callable($loader)
257 257
             && (
258 258
                 strpos($loader, 'load_') !== 0
259 259
                 || ! method_exists('EE_Registry', $loader)
@@ -270,8 +270,8 @@  discard block
 block discarded – undo
270 270
             );
271 271
         }
272 272
         $class_name = self::$_instance->getFqnForAlias($class_name);
273
-        if (! isset(self::$_instance->_class_loaders[ $class_name ])) {
274
-            self::$_instance->_class_loaders[ $class_name ] = $loader;
273
+        if ( ! isset(self::$_instance->_class_loaders[$class_name])) {
274
+            self::$_instance->_class_loaders[$class_name] = $loader;
275 275
             return true;
276 276
         }
277 277
         return false;
@@ -299,7 +299,7 @@  discard block
 block discarded – undo
299 299
         if (strpos($class_name, 'EEM_') === 0) {
300 300
             $class_name = 'LEGACY_MODELS';
301 301
         }
302
-        return isset($this->_dependency_map[ $class_name ]) ? true : false;
302
+        return isset($this->_dependency_map[$class_name]) ? true : false;
303 303
     }
304 304
 
305 305
 
@@ -317,7 +317,7 @@  discard block
 block discarded – undo
317 317
             $class_name = 'LEGACY_MODELS';
318 318
         }
319 319
         $dependency = $this->getFqnForAlias($dependency, $class_name);
320
-        return isset($this->_dependency_map[ $class_name ][ $dependency ])
320
+        return isset($this->_dependency_map[$class_name][$dependency])
321 321
             ? true
322 322
             : false;
323 323
     }
@@ -338,7 +338,7 @@  discard block
 block discarded – undo
338 338
         }
339 339
         $dependency = $this->getFqnForAlias($dependency);
340 340
         return $this->has_dependency_for_class($class_name, $dependency)
341
-            ? $this->_dependency_map[ $class_name ][ $dependency ]
341
+            ? $this->_dependency_map[$class_name][$dependency]
342 342
             : EE_Dependency_Map::not_registered;
343 343
     }
344 344
 
@@ -354,7 +354,7 @@  discard block
 block discarded – undo
354 354
             return 'load_model';
355 355
         }
356 356
         $class_name = $this->getFqnForAlias($class_name);
357
-        return isset($this->_class_loaders[ $class_name ]) ? $this->_class_loaders[ $class_name ] : '';
357
+        return isset($this->_class_loaders[$class_name]) ? $this->_class_loaders[$class_name] : '';
358 358
     }
359 359
 
360 360
 
@@ -788,13 +788,13 @@  discard block
 block discarded – undo
788 788
             'EE_Front_Controller'                          => 'load_core',
789 789
             'EE_Module_Request_Router'                     => 'load_core',
790 790
             'EE_Registry'                                  => 'load_core',
791
-            'EE_Request'                                   => function () use (&$legacy_request) {
791
+            'EE_Request'                                   => function() use (&$legacy_request) {
792 792
                 return $legacy_request;
793 793
             },
794
-            'EventEspresso\core\services\request\Request'  => function () use (&$request) {
794
+            'EventEspresso\core\services\request\Request'  => function() use (&$request) {
795 795
                 return $request;
796 796
             },
797
-            'EventEspresso\core\services\request\Response' => function () use (&$response) {
797
+            'EventEspresso\core\services\request\Response' => function() use (&$response) {
798 798
                 return $response;
799 799
             },
800 800
             'EE_Base'                                      => 'load_core',
@@ -818,7 +818,7 @@  discard block
 block discarded – undo
818 818
             'EE_Messages_Data_Handler_Collection'          => 'load_lib',
819 819
             'EE_Message_Template_Group_Collection'         => 'load_lib',
820 820
             'EE_Payment_Method_Manager'                    => 'load_lib',
821
-            'EE_Messages_Generator'                        => function () {
821
+            'EE_Messages_Generator'                        => function() {
822 822
                 return EE_Registry::instance()->load_lib(
823 823
                     'Messages_Generator',
824 824
                     array(),
@@ -826,7 +826,7 @@  discard block
 block discarded – undo
826 826
                     false
827 827
                 );
828 828
             },
829
-            'EE_Messages_Template_Defaults'                => function ($arguments = array()) {
829
+            'EE_Messages_Template_Defaults'                => function($arguments = array()) {
830 830
                 return EE_Registry::instance()->load_lib(
831 831
                     'Messages_Template_Defaults',
832 832
                     $arguments,
@@ -835,37 +835,37 @@  discard block
 block discarded – undo
835 835
                 );
836 836
             },
837 837
             // load_helper
838
-            'EEH_Parse_Shortcodes'                         => function () {
838
+            'EEH_Parse_Shortcodes'                         => function() {
839 839
                 if (EE_Registry::instance()->load_helper('Parse_Shortcodes')) {
840 840
                     return new EEH_Parse_Shortcodes();
841 841
                 }
842 842
                 return null;
843 843
             },
844
-            'EE_Template_Config'                           => function () {
844
+            'EE_Template_Config'                           => function() {
845 845
                 return EE_Config::instance()->template_settings;
846 846
             },
847
-            'EE_Currency_Config'                           => function () {
847
+            'EE_Currency_Config'                           => function() {
848 848
                 return EE_Config::instance()->currency;
849 849
             },
850
-            'EE_Registration_Config'                       => function () {
850
+            'EE_Registration_Config'                       => function() {
851 851
                 return EE_Config::instance()->registration;
852 852
             },
853
-            'EE_Core_Config'                               => function () {
853
+            'EE_Core_Config'                               => function() {
854 854
                 return EE_Config::instance()->core;
855 855
             },
856
-            'EventEspresso\core\services\loaders\Loader'   => function () {
856
+            'EventEspresso\core\services\loaders\Loader'   => function() {
857 857
                 return LoaderFactory::getLoader();
858 858
             },
859
-            'EE_Network_Config'                            => function () {
859
+            'EE_Network_Config'                            => function() {
860 860
                 return EE_Network_Config::instance();
861 861
             },
862
-            'EE_Config'                                    => function () {
862
+            'EE_Config'                                    => function() {
863 863
                 return EE_Config::instance();
864 864
             },
865
-            'EventEspresso\core\domain\Domain'             => function () {
865
+            'EventEspresso\core\domain\Domain'             => function() {
866 866
                 return DomainFactory::getEventEspressoCoreDomain();
867 867
             },
868
-            'EE_Admin_Config'                              => function () {
868
+            'EE_Admin_Config'                              => function() {
869 869
                 return EE_Config::instance()->admin;
870 870
             }
871 871
         );
@@ -927,7 +927,7 @@  discard block
 block discarded – undo
927 927
             }
928 928
             $this->class_cache->addAlias($fqn, $alias);
929 929
         }
930
-        if (! (defined('DOING_AJAX') && DOING_AJAX) && is_admin()) {
930
+        if ( ! (defined('DOING_AJAX') && DOING_AJAX) && is_admin()) {
931 931
             $this->class_cache->addAlias(
932 932
                 'EventEspresso\core\services\notices\ConvertNoticesToAdminNotices',
933 933
                 'EventEspresso\core\services\notices\NoticeConverterInterface'
Please login to merge, or discard this patch.
Indentation   +988 added lines, -988 removed lines patch added patch discarded remove patch
@@ -20,992 +20,992 @@
 block discarded – undo
20 20
 class EE_Dependency_Map
21 21
 {
22 22
 
23
-    /**
24
-     * This means that the requested class dependency is not present in the dependency map
25
-     */
26
-    const not_registered = 0;
27
-
28
-    /**
29
-     * This instructs class loaders to ALWAYS return a newly instantiated object for the requested class.
30
-     */
31
-    const load_new_object = 1;
32
-
33
-    /**
34
-     * This instructs class loaders to return a previously instantiated and cached object for the requested class.
35
-     * IF a previously instantiated object does not exist, a new one will be created and added to the cache.
36
-     */
37
-    const load_from_cache = 2;
38
-
39
-    /**
40
-     * When registering a dependency,
41
-     * this indicates to keep any existing dependencies that already exist,
42
-     * and simply discard any new dependencies declared in the incoming data
43
-     */
44
-    const KEEP_EXISTING_DEPENDENCIES = 0;
45
-
46
-    /**
47
-     * When registering a dependency,
48
-     * this indicates to overwrite any existing dependencies that already exist using the incoming data
49
-     */
50
-    const OVERWRITE_DEPENDENCIES = 1;
51
-
52
-
53
-    /**
54
-     * @type EE_Dependency_Map $_instance
55
-     */
56
-    protected static $_instance;
57
-
58
-    /**
59
-     * @var ClassInterfaceCache $class_cache
60
-     */
61
-    private $class_cache;
62
-
63
-    /**
64
-     * @type RequestInterface $request
65
-     */
66
-    protected $request;
67
-
68
-    /**
69
-     * @type LegacyRequestInterface $legacy_request
70
-     */
71
-    protected $legacy_request;
72
-
73
-    /**
74
-     * @type ResponseInterface $response
75
-     */
76
-    protected $response;
77
-
78
-    /**
79
-     * @type LoaderInterface $loader
80
-     */
81
-    protected $loader;
82
-
83
-    /**
84
-     * @type array $_dependency_map
85
-     */
86
-    protected $_dependency_map = array();
87
-
88
-    /**
89
-     * @type array $_class_loaders
90
-     */
91
-    protected $_class_loaders = array();
92
-
93
-
94
-    /**
95
-     * EE_Dependency_Map constructor.
96
-     *
97
-     * @param ClassInterfaceCache $class_cache
98
-     */
99
-    protected function __construct(ClassInterfaceCache $class_cache)
100
-    {
101
-        $this->class_cache = $class_cache;
102
-        do_action('EE_Dependency_Map____construct', $this);
103
-    }
104
-
105
-
106
-    /**
107
-     * @return void
108
-     */
109
-    public function initialize()
110
-    {
111
-        $this->_register_core_dependencies();
112
-        $this->_register_core_class_loaders();
113
-        $this->_register_core_aliases();
114
-    }
115
-
116
-
117
-    /**
118
-     * @singleton method used to instantiate class object
119
-     * @param ClassInterfaceCache|null $class_cache
120
-     * @return EE_Dependency_Map
121
-     */
122
-    public static function instance(ClassInterfaceCache $class_cache = null)
123
-    {
124
-        // check if class object is instantiated, and instantiated properly
125
-        if (! self::$_instance instanceof EE_Dependency_Map
126
-            && $class_cache instanceof ClassInterfaceCache
127
-        ) {
128
-            self::$_instance = new EE_Dependency_Map($class_cache);
129
-        }
130
-        return self::$_instance;
131
-    }
132
-
133
-
134
-    /**
135
-     * @param RequestInterface $request
136
-     */
137
-    public function setRequest(RequestInterface $request)
138
-    {
139
-        $this->request = $request;
140
-    }
141
-
142
-
143
-    /**
144
-     * @param LegacyRequestInterface $legacy_request
145
-     */
146
-    public function setLegacyRequest(LegacyRequestInterface $legacy_request)
147
-    {
148
-        $this->legacy_request = $legacy_request;
149
-    }
150
-
151
-
152
-    /**
153
-     * @param ResponseInterface $response
154
-     */
155
-    public function setResponse(ResponseInterface $response)
156
-    {
157
-        $this->response = $response;
158
-    }
159
-
160
-
161
-    /**
162
-     * @param LoaderInterface $loader
163
-     */
164
-    public function setLoader(LoaderInterface $loader)
165
-    {
166
-        $this->loader = $loader;
167
-    }
168
-
169
-
170
-    /**
171
-     * @param string $class
172
-     * @param array  $dependencies
173
-     * @param int    $overwrite
174
-     * @return bool
175
-     */
176
-    public static function register_dependencies(
177
-        $class,
178
-        array $dependencies,
179
-        $overwrite = EE_Dependency_Map::KEEP_EXISTING_DEPENDENCIES
180
-    ) {
181
-        return self::$_instance->registerDependencies($class, $dependencies, $overwrite);
182
-    }
183
-
184
-
185
-    /**
186
-     * Assigns an array of class names and corresponding load sources (new or cached)
187
-     * to the class specified by the first parameter.
188
-     * IMPORTANT !!!
189
-     * The order of elements in the incoming $dependencies array MUST match
190
-     * the order of the constructor parameters for the class in question.
191
-     * This is especially important when overriding any existing dependencies that are registered.
192
-     * the third parameter controls whether any duplicate dependencies are overwritten or not.
193
-     *
194
-     * @param string $class
195
-     * @param array  $dependencies
196
-     * @param int    $overwrite
197
-     * @return bool
198
-     */
199
-    public function registerDependencies(
200
-        $class,
201
-        array $dependencies,
202
-        $overwrite = EE_Dependency_Map::KEEP_EXISTING_DEPENDENCIES
203
-    ) {
204
-        $class = trim($class, '\\');
205
-        $registered = false;
206
-        if (empty(self::$_instance->_dependency_map[ $class ])) {
207
-            self::$_instance->_dependency_map[ $class ] = array();
208
-        }
209
-        // we need to make sure that any aliases used when registering a dependency
210
-        // get resolved to the correct class name
211
-        foreach ($dependencies as $dependency => $load_source) {
212
-            $alias = self::$_instance->getFqnForAlias($dependency);
213
-            if ($overwrite === EE_Dependency_Map::OVERWRITE_DEPENDENCIES
214
-                || ! isset(self::$_instance->_dependency_map[ $class ][ $alias ])
215
-            ) {
216
-                unset($dependencies[ $dependency ]);
217
-                $dependencies[ $alias ] = $load_source;
218
-                $registered = true;
219
-            }
220
-        }
221
-        // now add our two lists of dependencies together.
222
-        // using Union (+=) favours the arrays in precedence from left to right,
223
-        // so $dependencies is NOT overwritten because it is listed first
224
-        // ie: with A = B + C, entries in B take precedence over duplicate entries in C
225
-        // Union is way faster than array_merge() but should be used with caution...
226
-        // especially with numerically indexed arrays
227
-        $dependencies += self::$_instance->_dependency_map[ $class ];
228
-        // now we need to ensure that the resulting dependencies
229
-        // array only has the entries that are required for the class
230
-        // so first count how many dependencies were originally registered for the class
231
-        $dependency_count = count(self::$_instance->_dependency_map[ $class ]);
232
-        // if that count is non-zero (meaning dependencies were already registered)
233
-        self::$_instance->_dependency_map[ $class ] = $dependency_count
234
-            // then truncate the  final array to match that count
235
-            ? array_slice($dependencies, 0, $dependency_count)
236
-            // otherwise just take the incoming array because nothing previously existed
237
-            : $dependencies;
238
-        return $registered;
239
-    }
240
-
241
-
242
-    /**
243
-     * @param string $class_name
244
-     * @param string $loader
245
-     * @return bool
246
-     * @throws DomainException
247
-     */
248
-    public static function register_class_loader($class_name, $loader = 'load_core')
249
-    {
250
-        if (! $loader instanceof Closure && strpos($class_name, '\\') !== false) {
251
-            throw new DomainException(
252
-                esc_html__('Don\'t use class loaders for FQCNs.', 'event_espresso')
253
-            );
254
-        }
255
-        // check that loader is callable or method starts with "load_" and exists in EE_Registry
256
-        if (! is_callable($loader)
257
-            && (
258
-                strpos($loader, 'load_') !== 0
259
-                || ! method_exists('EE_Registry', $loader)
260
-            )
261
-        ) {
262
-            throw new DomainException(
263
-                sprintf(
264
-                    esc_html__(
265
-                        '"%1$s" is not a valid loader method on EE_Registry.',
266
-                        'event_espresso'
267
-                    ),
268
-                    $loader
269
-                )
270
-            );
271
-        }
272
-        $class_name = self::$_instance->getFqnForAlias($class_name);
273
-        if (! isset(self::$_instance->_class_loaders[ $class_name ])) {
274
-            self::$_instance->_class_loaders[ $class_name ] = $loader;
275
-            return true;
276
-        }
277
-        return false;
278
-    }
279
-
280
-
281
-    /**
282
-     * @return array
283
-     */
284
-    public function dependency_map()
285
-    {
286
-        return $this->_dependency_map;
287
-    }
288
-
289
-
290
-    /**
291
-     * returns TRUE if dependency map contains a listing for the provided class name
292
-     *
293
-     * @param string $class_name
294
-     * @return boolean
295
-     */
296
-    public function has($class_name = '')
297
-    {
298
-        // all legacy models have the same dependencies
299
-        if (strpos($class_name, 'EEM_') === 0) {
300
-            $class_name = 'LEGACY_MODELS';
301
-        }
302
-        return isset($this->_dependency_map[ $class_name ]) ? true : false;
303
-    }
304
-
305
-
306
-    /**
307
-     * returns TRUE if dependency map contains a listing for the provided class name AND dependency
308
-     *
309
-     * @param string $class_name
310
-     * @param string $dependency
311
-     * @return bool
312
-     */
313
-    public function has_dependency_for_class($class_name = '', $dependency = '')
314
-    {
315
-        // all legacy models have the same dependencies
316
-        if (strpos($class_name, 'EEM_') === 0) {
317
-            $class_name = 'LEGACY_MODELS';
318
-        }
319
-        $dependency = $this->getFqnForAlias($dependency, $class_name);
320
-        return isset($this->_dependency_map[ $class_name ][ $dependency ])
321
-            ? true
322
-            : false;
323
-    }
324
-
325
-
326
-    /**
327
-     * returns loading strategy for whether a previously cached dependency should be loaded or a new instance returned
328
-     *
329
-     * @param string $class_name
330
-     * @param string $dependency
331
-     * @return int
332
-     */
333
-    public function loading_strategy_for_class_dependency($class_name = '', $dependency = '')
334
-    {
335
-        // all legacy models have the same dependencies
336
-        if (strpos($class_name, 'EEM_') === 0) {
337
-            $class_name = 'LEGACY_MODELS';
338
-        }
339
-        $dependency = $this->getFqnForAlias($dependency);
340
-        return $this->has_dependency_for_class($class_name, $dependency)
341
-            ? $this->_dependency_map[ $class_name ][ $dependency ]
342
-            : EE_Dependency_Map::not_registered;
343
-    }
344
-
345
-
346
-    /**
347
-     * @param string $class_name
348
-     * @return string | Closure
349
-     */
350
-    public function class_loader($class_name)
351
-    {
352
-        // all legacy models use load_model()
353
-        if (strpos($class_name, 'EEM_') === 0) {
354
-            return 'load_model';
355
-        }
356
-        $class_name = $this->getFqnForAlias($class_name);
357
-        return isset($this->_class_loaders[ $class_name ]) ? $this->_class_loaders[ $class_name ] : '';
358
-    }
359
-
360
-
361
-    /**
362
-     * @return array
363
-     */
364
-    public function class_loaders()
365
-    {
366
-        return $this->_class_loaders;
367
-    }
368
-
369
-
370
-    /**
371
-     * adds an alias for a classname
372
-     *
373
-     * @param string $fqcn      the class name that should be used (concrete class to replace interface)
374
-     * @param string $alias     the class name that would be type hinted for (abstract parent or interface)
375
-     * @param string $for_class the class that has the dependency (is type hinting for the interface)
376
-     */
377
-    public function add_alias($fqcn, $alias, $for_class = '')
378
-    {
379
-        $this->class_cache->addAlias($fqcn, $alias, $for_class);
380
-    }
381
-
382
-
383
-    /**
384
-     * Returns TRUE if the provided fully qualified name IS an alias
385
-     * WHY?
386
-     * Because if a class is type hinting for a concretion,
387
-     * then why would we need to find another class to supply it?
388
-     * ie: if a class asks for `Fully/Qualified/Namespace/SpecificClassName`,
389
-     * then give it an instance of `Fully/Qualified/Namespace/SpecificClassName`.
390
-     * Don't go looking for some substitute.
391
-     * Whereas if a class is type hinting for an interface...
392
-     * then we need to find an actual class to use.
393
-     * So the interface IS the alias for some other FQN,
394
-     * and we need to find out if `Fully/Qualified/Namespace/SomeInterface`
395
-     * represents some other class.
396
-     *
397
-     * @param string $fqn
398
-     * @param string $for_class
399
-     * @return bool
400
-     */
401
-    public function isAlias($fqn = '', $for_class = '')
402
-    {
403
-        return $this->class_cache->isAlias($fqn, $for_class);
404
-    }
405
-
406
-
407
-    /**
408
-     * Returns a FQN for provided alias if one exists, otherwise returns the original $alias
409
-     * functions recursively, so that multiple aliases can be used to drill down to a FQN
410
-     *  for example:
411
-     *      if the following two entries were added to the _aliases array:
412
-     *          array(
413
-     *              'interface_alias'           => 'some\namespace\interface'
414
-     *              'some\namespace\interface'  => 'some\namespace\classname'
415
-     *          )
416
-     *      then one could use EE_Registry::instance()->create( 'interface_alias' )
417
-     *      to load an instance of 'some\namespace\classname'
418
-     *
419
-     * @param string $alias
420
-     * @param string $for_class
421
-     * @return string
422
-     */
423
-    public function getFqnForAlias($alias = '', $for_class = '')
424
-    {
425
-        return (string) $this->class_cache->getFqnForAlias($alias, $for_class);
426
-    }
427
-
428
-
429
-    /**
430
-     * Registers the core dependencies and whether a previously instantiated object should be loaded from the cache,
431
-     * if one exists, or whether a new object should be generated every time the requested class is loaded.
432
-     * This is done by using the following class constants:
433
-     *        EE_Dependency_Map::load_from_cache - loads previously instantiated object
434
-     *        EE_Dependency_Map::load_new_object - generates a new object every time
435
-     */
436
-    protected function _register_core_dependencies()
437
-    {
438
-        $this->_dependency_map = array(
439
-            'EE_Request_Handler'                                                                                          => array(
440
-                'EE_Request' => EE_Dependency_Map::load_from_cache,
441
-            ),
442
-            'EE_System'                                                                                                   => array(
443
-                'EE_Registry'                                 => EE_Dependency_Map::load_from_cache,
444
-                'EventEspresso\core\services\loaders\Loader'  => EE_Dependency_Map::load_from_cache,
445
-                'EventEspresso\core\services\request\Request' => EE_Dependency_Map::load_from_cache,
446
-                'EE_Maintenance_Mode'                         => EE_Dependency_Map::load_from_cache,
447
-            ),
448
-            'EE_Session'                                                                                                  => array(
449
-                'EventEspresso\core\services\cache\TransientCacheStorage'  => EE_Dependency_Map::load_from_cache,
450
-                'EventEspresso\core\domain\values\session\SessionLifespan' => EE_Dependency_Map::load_from_cache,
451
-                'EventEspresso\core\services\request\Request'              => EE_Dependency_Map::load_from_cache,
452
-                'EE_Encryption'                                            => EE_Dependency_Map::load_from_cache,
453
-            ),
454
-            'EE_Cart'                                                                                                     => array(
455
-                'EE_Session' => EE_Dependency_Map::load_from_cache,
456
-            ),
457
-            'EE_Front_Controller'                                                                                         => array(
458
-                'EE_Registry'              => EE_Dependency_Map::load_from_cache,
459
-                'EE_Request_Handler'       => EE_Dependency_Map::load_from_cache,
460
-                'EE_Module_Request_Router' => EE_Dependency_Map::load_from_cache,
461
-            ),
462
-            'EE_Messenger_Collection_Loader'                                                                              => array(
463
-                'EE_Messenger_Collection' => EE_Dependency_Map::load_new_object,
464
-            ),
465
-            'EE_Message_Type_Collection_Loader'                                                                           => array(
466
-                'EE_Message_Type_Collection' => EE_Dependency_Map::load_new_object,
467
-            ),
468
-            'EE_Message_Resource_Manager'                                                                                 => array(
469
-                'EE_Messenger_Collection_Loader'    => EE_Dependency_Map::load_new_object,
470
-                'EE_Message_Type_Collection_Loader' => EE_Dependency_Map::load_new_object,
471
-                'EEM_Message_Template_Group'        => EE_Dependency_Map::load_from_cache,
472
-            ),
473
-            'EE_Message_Factory'                                                                                          => array(
474
-                'EE_Message_Resource_Manager' => EE_Dependency_Map::load_from_cache,
475
-            ),
476
-            'EE_messages'                                                                                                 => array(
477
-                'EE_Message_Resource_Manager' => EE_Dependency_Map::load_from_cache,
478
-            ),
479
-            'EE_Messages_Generator'                                                                                       => array(
480
-                'EE_Messages_Queue'                    => EE_Dependency_Map::load_new_object,
481
-                'EE_Messages_Data_Handler_Collection'  => EE_Dependency_Map::load_new_object,
482
-                'EE_Message_Template_Group_Collection' => EE_Dependency_Map::load_new_object,
483
-                'EEH_Parse_Shortcodes'                 => EE_Dependency_Map::load_from_cache,
484
-            ),
485
-            'EE_Messages_Processor'                                                                                       => array(
486
-                'EE_Message_Resource_Manager' => EE_Dependency_Map::load_from_cache,
487
-            ),
488
-            'EE_Messages_Queue'                                                                                           => array(
489
-                'EE_Message_Repository' => EE_Dependency_Map::load_new_object,
490
-            ),
491
-            'EE_Messages_Template_Defaults'                                                                               => array(
492
-                'EEM_Message_Template_Group' => EE_Dependency_Map::load_from_cache,
493
-                'EEM_Message_Template'       => EE_Dependency_Map::load_from_cache,
494
-            ),
495
-            'EE_Message_To_Generate_From_Request'                                                                         => array(
496
-                'EE_Message_Resource_Manager' => EE_Dependency_Map::load_from_cache,
497
-                'EE_Request_Handler'          => EE_Dependency_Map::load_from_cache,
498
-            ),
499
-            'EventEspresso\core\services\commands\CommandBus'                                                             => array(
500
-                'EventEspresso\core\services\commands\CommandHandlerManager' => EE_Dependency_Map::load_from_cache,
501
-            ),
502
-            'EventEspresso\services\commands\CommandHandler'                                                              => array(
503
-                'EE_Registry'         => EE_Dependency_Map::load_from_cache,
504
-                'CommandBusInterface' => EE_Dependency_Map::load_from_cache,
505
-            ),
506
-            'EventEspresso\core\services\commands\CommandHandlerManager'                                                  => array(
507
-                'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache,
508
-            ),
509
-            'EventEspresso\core\services\commands\CompositeCommandHandler'                                                => array(
510
-                'EventEspresso\core\services\commands\CommandBus'     => EE_Dependency_Map::load_from_cache,
511
-                'EventEspresso\core\services\commands\CommandFactory' => EE_Dependency_Map::load_from_cache,
512
-            ),
513
-            'EventEspresso\core\services\commands\CommandFactory'                                                         => array(
514
-                'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache,
515
-            ),
516
-            'EventEspresso\core\services\commands\middleware\CapChecker'                                                  => array(
517
-                'EventEspresso\core\domain\services\capabilities\CapabilitiesChecker' => EE_Dependency_Map::load_from_cache,
518
-            ),
519
-            'EventEspresso\core\domain\services\capabilities\CapabilitiesChecker'                                         => array(
520
-                'EE_Capabilities' => EE_Dependency_Map::load_from_cache,
521
-            ),
522
-            'EventEspresso\core\domain\services\capabilities\RegistrationsCapChecker'                                     => array(
523
-                'EE_Capabilities' => EE_Dependency_Map::load_from_cache,
524
-            ),
525
-            'EventEspresso\core\services\commands\registration\CreateRegistrationCommandHandler'                          => array(
526
-                'EventEspresso\core\domain\services\registration\CreateRegistrationService' => EE_Dependency_Map::load_from_cache,
527
-            ),
528
-            'EventEspresso\core\services\commands\registration\CopyRegistrationDetailsCommandHandler'                     => array(
529
-                'EventEspresso\core\domain\services\registration\CopyRegistrationService' => EE_Dependency_Map::load_from_cache,
530
-            ),
531
-            'EventEspresso\core\services\commands\registration\CopyRegistrationPaymentsCommandHandler'                    => array(
532
-                'EventEspresso\core\domain\services\registration\CopyRegistrationService' => EE_Dependency_Map::load_from_cache,
533
-            ),
534
-            'EventEspresso\core\services\commands\registration\CancelRegistrationAndTicketLineItemCommandHandler'         => array(
535
-                'EventEspresso\core\domain\services\registration\CancelTicketLineItemService' => EE_Dependency_Map::load_from_cache,
536
-            ),
537
-            'EventEspresso\core\services\commands\registration\UpdateRegistrationAndTransactionAfterChangeCommandHandler' => array(
538
-                'EventEspresso\core\domain\services\registration\UpdateRegistrationService' => EE_Dependency_Map::load_from_cache,
539
-            ),
540
-            'EventEspresso\core\services\commands\ticket\CreateTicketLineItemCommandHandler'                              => array(
541
-                'EventEspresso\core\domain\services\ticket\CreateTicketLineItemService' => EE_Dependency_Map::load_from_cache,
542
-            ),
543
-            'EventEspresso\core\services\commands\ticket\CancelTicketLineItemCommandHandler'                              => array(
544
-                'EventEspresso\core\domain\services\ticket\CancelTicketLineItemService' => EE_Dependency_Map::load_from_cache,
545
-            ),
546
-            'EventEspresso\core\domain\services\registration\CancelRegistrationService'                                   => array(
547
-                'EventEspresso\core\domain\services\ticket\CancelTicketLineItemService' => EE_Dependency_Map::load_from_cache,
548
-            ),
549
-            'EventEspresso\core\services\commands\attendee\CreateAttendeeCommandHandler'                                  => array(
550
-                'EEM_Attendee' => EE_Dependency_Map::load_from_cache,
551
-            ),
552
-            'EventEspresso\core\services\database\TableManager'                                                           => array(
553
-                'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache,
554
-            ),
555
-            'EE_Data_Migration_Class_Base'                                                                                => array(
556
-                'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache,
557
-                'EventEspresso\core\services\database\TableManager'  => EE_Dependency_Map::load_from_cache,
558
-            ),
559
-            'EE_DMS_Core_4_1_0'                                                                                           => array(
560
-                'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache,
561
-                'EventEspresso\core\services\database\TableManager'  => EE_Dependency_Map::load_from_cache,
562
-            ),
563
-            'EE_DMS_Core_4_2_0'                                                                                           => array(
564
-                'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache,
565
-                'EventEspresso\core\services\database\TableManager'  => EE_Dependency_Map::load_from_cache,
566
-            ),
567
-            'EE_DMS_Core_4_3_0'                                                                                           => array(
568
-                'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache,
569
-                'EventEspresso\core\services\database\TableManager'  => EE_Dependency_Map::load_from_cache,
570
-            ),
571
-            'EE_DMS_Core_4_4_0'                                                                                           => array(
572
-                'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache,
573
-                'EventEspresso\core\services\database\TableManager'  => EE_Dependency_Map::load_from_cache,
574
-            ),
575
-            'EE_DMS_Core_4_5_0'                                                                                           => array(
576
-                'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache,
577
-                'EventEspresso\core\services\database\TableManager'  => EE_Dependency_Map::load_from_cache,
578
-            ),
579
-            'EE_DMS_Core_4_6_0'                                                                                           => array(
580
-                'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache,
581
-                'EventEspresso\core\services\database\TableManager'  => EE_Dependency_Map::load_from_cache,
582
-            ),
583
-            'EE_DMS_Core_4_7_0'                                                                                           => array(
584
-                'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache,
585
-                'EventEspresso\core\services\database\TableManager'  => EE_Dependency_Map::load_from_cache,
586
-            ),
587
-            'EE_DMS_Core_4_8_0'                                                                                           => array(
588
-                'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache,
589
-                'EventEspresso\core\services\database\TableManager'  => EE_Dependency_Map::load_from_cache,
590
-            ),
591
-            'EE_DMS_Core_4_9_0'                                                                                           => array(
592
-                'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache,
593
-                'EventEspresso\core\services\database\TableManager'  => EE_Dependency_Map::load_from_cache,
594
-            ),
595
-            'EventEspresso\core\services\assets\I18nRegistry'                                                             => array(
596
-                array(),
597
-                'EventEspresso\core\domain\Domain' => EE_Dependency_Map::load_from_cache,
598
-            ),
599
-            'EventEspresso\core\services\assets\Registry'                                                                 => array(
600
-                'EventEspresso\core\services\assets\AssetCollection' => EE_Dependency_Map::load_from_cache,
601
-                'EventEspresso\core\services\assets\I18nRegistry'    => EE_Dependency_Map::load_from_cache,
602
-            ),
603
-            'EventEspresso\core\domain\entities\shortcodes\EspressoCancelled'                                             => array(
604
-                'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache,
605
-            ),
606
-            'EventEspresso\core\domain\entities\shortcodes\EspressoCheckout'                                              => array(
607
-                'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache,
608
-            ),
609
-            'EventEspresso\core\domain\entities\shortcodes\EspressoEventAttendees'                                        => array(
610
-                'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache,
611
-            ),
612
-            'EventEspresso\core\domain\entities\shortcodes\EspressoEvents'                                                => array(
613
-                'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache,
614
-            ),
615
-            'EventEspresso\core\domain\entities\shortcodes\EspressoThankYou'                                              => array(
616
-                'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache,
617
-            ),
618
-            'EventEspresso\core\domain\entities\shortcodes\EspressoTicketSelector'                                        => array(
619
-                'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache,
620
-            ),
621
-            'EventEspresso\core\domain\entities\shortcodes\EspressoTxnPage'                                               => array(
622
-                'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache,
623
-            ),
624
-            'EventEspresso\core\services\cache\BasicCacheManager'                                                         => array(
625
-                'EventEspresso\core\services\cache\TransientCacheStorage' => EE_Dependency_Map::load_from_cache,
626
-            ),
627
-            'EventEspresso\core\services\cache\PostRelatedCacheManager'                                                   => array(
628
-                'EventEspresso\core\services\cache\TransientCacheStorage' => EE_Dependency_Map::load_from_cache,
629
-            ),
630
-            'EventEspresso\core\domain\services\validation\email\EmailValidationService'                                  => array(
631
-                'EE_Registration_Config'                     => EE_Dependency_Map::load_from_cache,
632
-                'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache,
633
-            ),
634
-            'EventEspresso\core\domain\values\EmailAddress'                                                               => array(
635
-                null,
636
-                'EventEspresso\core\domain\services\validation\email\EmailValidationService' => EE_Dependency_Map::load_from_cache,
637
-            ),
638
-            'EventEspresso\core\services\orm\ModelFieldFactory'                                                           => array(
639
-                'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache,
640
-            ),
641
-            'LEGACY_MODELS'                                                                                               => array(
642
-                null,
643
-                'EventEspresso\core\services\database\ModelFieldFactory' => EE_Dependency_Map::load_from_cache,
644
-            ),
645
-            'EE_Module_Request_Router'                                                                                    => array(
646
-                'EE_Request' => EE_Dependency_Map::load_from_cache,
647
-            ),
648
-            'EE_Registration_Processor'                                                                                   => array(
649
-                'EE_Request' => EE_Dependency_Map::load_from_cache,
650
-            ),
651
-            'EventEspresso\core\services\notifications\PersistentAdminNoticeManager'                                      => array(
652
-                null,
653
-                'EventEspresso\core\domain\services\capabilities\CapabilitiesChecker' => EE_Dependency_Map::load_from_cache,
654
-                'EE_Request'                                                          => EE_Dependency_Map::load_from_cache,
655
-            ),
656
-            'EventEspresso\core\services\licensing\LicenseService'                                                        => array(
657
-                'EventEspresso\core\domain\services\pue\Stats'  => EE_Dependency_Map::load_from_cache,
658
-                'EventEspresso\core\domain\services\pue\Config' => EE_Dependency_Map::load_from_cache,
659
-            ),
660
-            'EE_Admin_Transactions_List_Table'                                                                            => array(
661
-                null,
662
-                'EventEspresso\core\domain\values\session\SessionLifespan' => EE_Dependency_Map::load_from_cache,
663
-            ),
664
-            'EventEspresso\core\domain\services\pue\Stats'                                                                => array(
665
-                'EventEspresso\core\domain\services\pue\Config'        => EE_Dependency_Map::load_from_cache,
666
-                'EE_Maintenance_Mode'                                  => EE_Dependency_Map::load_from_cache,
667
-                'EventEspresso\core\domain\services\pue\StatsGatherer' => EE_Dependency_Map::load_from_cache,
668
-            ),
669
-            'EventEspresso\core\domain\services\pue\Config'                                                               => array(
670
-                'EE_Network_Config' => EE_Dependency_Map::load_from_cache,
671
-                'EE_Config'         => EE_Dependency_Map::load_from_cache,
672
-            ),
673
-            'EventEspresso\core\domain\services\pue\StatsGatherer'                                                        => array(
674
-                'EEM_Payment_Method' => EE_Dependency_Map::load_from_cache,
675
-                'EEM_Event'          => EE_Dependency_Map::load_from_cache,
676
-                'EEM_Datetime'       => EE_Dependency_Map::load_from_cache,
677
-                'EEM_Ticket'         => EE_Dependency_Map::load_from_cache,
678
-                'EEM_Registration'   => EE_Dependency_Map::load_from_cache,
679
-                'EEM_Transaction'    => EE_Dependency_Map::load_from_cache,
680
-                'EE_Config'          => EE_Dependency_Map::load_from_cache,
681
-            ),
682
-            'EventEspresso\core\domain\services\admin\ExitModal'                                                          => array(
683
-                'EventEspresso\core\services\assets\Registry' => EE_Dependency_Map::load_from_cache,
684
-            ),
685
-            'EventEspresso\core\domain\services\admin\PluginUpsells'                                                      => array(
686
-                'EventEspresso\core\domain\Domain' => EE_Dependency_Map::load_from_cache,
687
-            ),
688
-            'EventEspresso\caffeinated\modules\recaptcha_invisible\InvisibleRecaptcha'                                    => array(
689
-                'EE_Registration_Config' => EE_Dependency_Map::load_from_cache,
690
-                'EE_Session'             => EE_Dependency_Map::load_from_cache,
691
-            ),
692
-            'EventEspresso\caffeinated\modules\recaptcha_invisible\RecaptchaAdminSettings'                                => array(
693
-                'EE_Registration_Config' => EE_Dependency_Map::load_from_cache,
694
-            ),
695
-            'EventEspresso\modules\ticket_selector\ProcessTicketSelector'                                                 => array(
696
-                'EE_Core_Config'                                                          => EE_Dependency_Map::load_from_cache,
697
-                'EventEspresso\core\services\request\Request'                             => EE_Dependency_Map::load_from_cache,
698
-                'EE_Session'                                                              => EE_Dependency_Map::load_from_cache,
699
-                'EEM_Ticket'                                                              => EE_Dependency_Map::load_from_cache,
700
-                'EventEspresso\modules\ticket_selector\TicketDatetimeAvailabilityTracker' => EE_Dependency_Map::load_from_cache,
701
-            ),
702
-            'EventEspresso\modules\ticket_selector\TicketDatetimeAvailabilityTracker'                                     => array(
703
-                'EEM_Datetime' => EE_Dependency_Map::load_from_cache,
704
-            ),
705
-            'EventEspresso\core\domain\entities\custom_post_types\CustomPostTypeDefinitions'                              => array(
706
-                'EE_Core_Config'                             => EE_Dependency_Map::load_from_cache,
707
-                'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache,
708
-            ),
709
-            'EventEspresso\core\domain\services\custom_post_types\RegisterCustomPostTypes'                                => array(
710
-                'EventEspresso\core\domain\entities\custom_post_types\CustomPostTypeDefinitions' => EE_Dependency_Map::load_from_cache,
711
-            ),
712
-            'EventEspresso\core\domain\services\custom_post_types\RegisterCustomTaxonomies'                               => array(
713
-                'EventEspresso\core\domain\entities\custom_post_types\CustomTaxonomyDefinitions' => EE_Dependency_Map::load_from_cache,
714
-            ),
715
-            'EE_CPT_Strategy'                                                                                             => array(
716
-                'EventEspresso\core\domain\entities\custom_post_types\CustomPostTypeDefinitions' => EE_Dependency_Map::load_from_cache,
717
-                'EventEspresso\core\domain\entities\custom_post_types\CustomTaxonomyDefinitions' => EE_Dependency_Map::load_from_cache,
718
-            ),
719
-            'EventEspresso\core\services\loaders\ObjectIdentifier'                                                        => array(
720
-                'EventEspresso\core\services\loaders\ClassInterfaceCache' => EE_Dependency_Map::load_from_cache,
721
-            ),
722
-            'EventEspresso\core\domain\services\assets\CoreAssetManager'                                                  => array(
723
-                'EventEspresso\core\services\assets\AssetCollection' => EE_Dependency_Map::load_from_cache,
724
-                'EE_Currency_Config'                                 => EE_Dependency_Map::load_from_cache,
725
-                'EE_Template_Config'                                 => EE_Dependency_Map::load_from_cache,
726
-                'EventEspresso\core\domain\Domain'                   => EE_Dependency_Map::load_from_cache,
727
-                'EventEspresso\core\services\assets\Registry'        => EE_Dependency_Map::load_from_cache,
728
-            ),
729
-            'EventEspresso\core\domain\services\admin\privacy\policy\PrivacyPolicy' => array(
730
-                'EEM_Payment_Method' => EE_Dependency_Map::load_from_cache,
731
-                'EventEspresso\core\domain\values\session\SessionLifespan' => EE_Dependency_Map::load_from_cache
732
-            ),
733
-            'EventEspresso\core\domain\services\admin\privacy\export\ExportAttendee' => array(
734
-                'EEM_Attendee' => EE_Dependency_Map::load_from_cache,
735
-            ),
736
-            'EventEspresso\core\domain\services\admin\privacy\export\ExportAttendeeBillingData' => array(
737
-                'EEM_Attendee' => EE_Dependency_Map::load_from_cache,
738
-                'EEM_Payment_Method' => EE_Dependency_Map::load_from_cache
739
-            ),
740
-            'EventEspresso\core\domain\services\admin\privacy\export\ExportCheckins' => array(
741
-                'EEM_Checkin' => EE_Dependency_Map::load_from_cache,
742
-            ),
743
-            'EventEspresso\core\domain\services\admin\privacy\export\ExportRegistration' => array(
744
-                'EEM_Registration' => EE_Dependency_Map::load_from_cache,
745
-            ),
746
-            'EventEspresso\core\domain\services\admin\privacy\export\ExportTransaction' => array(
747
-                'EEM_Transaction' => EE_Dependency_Map::load_from_cache,
748
-            ),
749
-            'EventEspresso\core\domain\services\admin\privacy\erasure\EraseAttendeeData' => array(
750
-                'EEM_Attendee' => EE_Dependency_Map::load_from_cache,
751
-            ),
752
-            'EventEspresso\core\domain\services\admin\privacy\erasure\EraseAnswers' => array(
753
-                'EEM_Answer' => EE_Dependency_Map::load_from_cache,
754
-                'EEM_Question' => EE_Dependency_Map::load_from_cache,
755
-            ),
756
-            'EventEspresso\core\services\editor\BlockRegistrationManager'                                                 => array(
757
-                'EventEspresso\core\services\assets\BlockAssetManagerCollection' => EE_Dependency_Map::load_from_cache,
758
-                'EventEspresso\core\domain\entities\editor\BlockCollection'      => EE_Dependency_Map::load_from_cache,
759
-                'EventEspresso\core\services\request\Request'                    => EE_Dependency_Map::load_from_cache,
760
-            ),
761
-            'EventEspresso\core\domain\entities\editor\blocks\CoreBlocksAssetManager' => array(
762
-                'EventEspresso\core\domain\Domain'                   => EE_Dependency_Map::load_from_cache,
763
-                'EventEspresso\core\services\assets\AssetCollection' => EE_Dependency_Map::load_from_cache,
764
-                'EventEspresso\core\services\assets\Registry'        => EE_Dependency_Map::load_from_cache,
765
-            ),
766
-            'EventEspresso\core\domain\entities\editor\blocks\widgets\EventAttendees' => array(
767
-                'EventEspresso\core\domain\entities\editor\blocks\CoreBlocksAssetManager' => self::load_from_cache,
768
-            ),
769
-        );
770
-    }
771
-
772
-
773
-    /**
774
-     * Registers how core classes are loaded.
775
-     * This can either be done by simply providing the name of one of the EE_Registry loader methods such as:
776
-     *        'EE_Request_Handler' => 'load_core'
777
-     *        'EE_Messages_Queue'  => 'load_lib'
778
-     *        'EEH_Debug_Tools'    => 'load_helper'
779
-     * or, if greater control is required, by providing a custom closure. For example:
780
-     *        'Some_Class' => function () {
781
-     *            return new Some_Class();
782
-     *        },
783
-     * This is required for instantiating dependencies
784
-     * where an interface has been type hinted in a class constructor. For example:
785
-     *        'Required_Interface' => function () {
786
-     *            return new A_Class_That_Implements_Required_Interface();
787
-     *        },
788
-     */
789
-    protected function _register_core_class_loaders()
790
-    {
791
-        // for PHP5.3 compat, we need to register any properties called here in a variable because `$this` cannot
792
-        // be used in a closure.
793
-        $request = &$this->request;
794
-        $response = &$this->response;
795
-        $legacy_request = &$this->legacy_request;
796
-        // $loader = &$this->loader;
797
-        $this->_class_loaders = array(
798
-            // load_core
799
-            'EE_Capabilities'                              => 'load_core',
800
-            'EE_Encryption'                                => 'load_core',
801
-            'EE_Front_Controller'                          => 'load_core',
802
-            'EE_Module_Request_Router'                     => 'load_core',
803
-            'EE_Registry'                                  => 'load_core',
804
-            'EE_Request'                                   => function () use (&$legacy_request) {
805
-                return $legacy_request;
806
-            },
807
-            'EventEspresso\core\services\request\Request'  => function () use (&$request) {
808
-                return $request;
809
-            },
810
-            'EventEspresso\core\services\request\Response' => function () use (&$response) {
811
-                return $response;
812
-            },
813
-            'EE_Base'                                      => 'load_core',
814
-            'EE_Request_Handler'                           => 'load_core',
815
-            'EE_Session'                                   => 'load_core',
816
-            'EE_Cron_Tasks'                                => 'load_core',
817
-            'EE_System'                                    => 'load_core',
818
-            'EE_Maintenance_Mode'                          => 'load_core',
819
-            'EE_Register_CPTs'                             => 'load_core',
820
-            'EE_Admin'                                     => 'load_core',
821
-            'EE_CPT_Strategy'                              => 'load_core',
822
-            // load_lib
823
-            'EE_Message_Resource_Manager'                  => 'load_lib',
824
-            'EE_Message_Type_Collection'                   => 'load_lib',
825
-            'EE_Message_Type_Collection_Loader'            => 'load_lib',
826
-            'EE_Messenger_Collection'                      => 'load_lib',
827
-            'EE_Messenger_Collection_Loader'               => 'load_lib',
828
-            'EE_Messages_Processor'                        => 'load_lib',
829
-            'EE_Message_Repository'                        => 'load_lib',
830
-            'EE_Messages_Queue'                            => 'load_lib',
831
-            'EE_Messages_Data_Handler_Collection'          => 'load_lib',
832
-            'EE_Message_Template_Group_Collection'         => 'load_lib',
833
-            'EE_Payment_Method_Manager'                    => 'load_lib',
834
-            'EE_Messages_Generator'                        => function () {
835
-                return EE_Registry::instance()->load_lib(
836
-                    'Messages_Generator',
837
-                    array(),
838
-                    false,
839
-                    false
840
-                );
841
-            },
842
-            'EE_Messages_Template_Defaults'                => function ($arguments = array()) {
843
-                return EE_Registry::instance()->load_lib(
844
-                    'Messages_Template_Defaults',
845
-                    $arguments,
846
-                    false,
847
-                    false
848
-                );
849
-            },
850
-            // load_helper
851
-            'EEH_Parse_Shortcodes'                         => function () {
852
-                if (EE_Registry::instance()->load_helper('Parse_Shortcodes')) {
853
-                    return new EEH_Parse_Shortcodes();
854
-                }
855
-                return null;
856
-            },
857
-            'EE_Template_Config'                           => function () {
858
-                return EE_Config::instance()->template_settings;
859
-            },
860
-            'EE_Currency_Config'                           => function () {
861
-                return EE_Config::instance()->currency;
862
-            },
863
-            'EE_Registration_Config'                       => function () {
864
-                return EE_Config::instance()->registration;
865
-            },
866
-            'EE_Core_Config'                               => function () {
867
-                return EE_Config::instance()->core;
868
-            },
869
-            'EventEspresso\core\services\loaders\Loader'   => function () {
870
-                return LoaderFactory::getLoader();
871
-            },
872
-            'EE_Network_Config'                            => function () {
873
-                return EE_Network_Config::instance();
874
-            },
875
-            'EE_Config'                                    => function () {
876
-                return EE_Config::instance();
877
-            },
878
-            'EventEspresso\core\domain\Domain'             => function () {
879
-                return DomainFactory::getEventEspressoCoreDomain();
880
-            },
881
-            'EE_Admin_Config'                              => function () {
882
-                return EE_Config::instance()->admin;
883
-            }
884
-        );
885
-    }
886
-
887
-
888
-    /**
889
-     * can be used for supplying alternate names for classes,
890
-     * or for connecting interface names to instantiable classes
891
-     */
892
-    protected function _register_core_aliases()
893
-    {
894
-        $aliases = array(
895
-            'CommandBusInterface'                                                          => 'EventEspresso\core\services\commands\CommandBusInterface',
896
-            'EventEspresso\core\services\commands\CommandBusInterface'                     => 'EventEspresso\core\services\commands\CommandBus',
897
-            'CommandHandlerManagerInterface'                                               => 'EventEspresso\core\services\commands\CommandHandlerManagerInterface',
898
-            'EventEspresso\core\services\commands\CommandHandlerManagerInterface'          => 'EventEspresso\core\services\commands\CommandHandlerManager',
899
-            'CapChecker'                                                                   => 'EventEspresso\core\services\commands\middleware\CapChecker',
900
-            'AddActionHook'                                                                => 'EventEspresso\core\services\commands\middleware\AddActionHook',
901
-            'CapabilitiesChecker'                                                          => 'EventEspresso\core\domain\services\capabilities\CapabilitiesChecker',
902
-            'CapabilitiesCheckerInterface'                                                 => 'EventEspresso\core\domain\services\capabilities\CapabilitiesCheckerInterface',
903
-            'EventEspresso\core\domain\services\capabilities\CapabilitiesCheckerInterface' => 'EventEspresso\core\domain\services\capabilities\CapabilitiesChecker',
904
-            'CreateRegistrationService'                                                    => 'EventEspresso\core\domain\services\registration\CreateRegistrationService',
905
-            'CreateRegistrationCommandHandler'                                             => 'EventEspresso\core\services\commands\registration\CreateRegistrationCommand',
906
-            'CopyRegistrationDetailsCommandHandler'                                        => 'EventEspresso\core\services\commands\registration\CopyRegistrationDetailsCommand',
907
-            'CopyRegistrationPaymentsCommandHandler'                                       => 'EventEspresso\core\services\commands\registration\CopyRegistrationPaymentsCommand',
908
-            'CancelRegistrationAndTicketLineItemCommandHandler'                            => 'EventEspresso\core\services\commands\registration\CancelRegistrationAndTicketLineItemCommandHandler',
909
-            'UpdateRegistrationAndTransactionAfterChangeCommandHandler'                    => 'EventEspresso\core\services\commands\registration\UpdateRegistrationAndTransactionAfterChangeCommandHandler',
910
-            'CreateTicketLineItemCommandHandler'                                           => 'EventEspresso\core\services\commands\ticket\CreateTicketLineItemCommand',
911
-            'CreateTransactionCommandHandler'                                              => 'EventEspresso\core\services\commands\transaction\CreateTransactionCommandHandler',
912
-            'CreateAttendeeCommandHandler'                                                 => 'EventEspresso\core\services\commands\attendee\CreateAttendeeCommandHandler',
913
-            'TableManager'                                                                 => 'EventEspresso\core\services\database\TableManager',
914
-            'TableAnalysis'                                                                => 'EventEspresso\core\services\database\TableAnalysis',
915
-            'EspressoShortcode'                                                            => 'EventEspresso\core\services\shortcodes\EspressoShortcode',
916
-            'ShortcodeInterface'                                                           => 'EventEspresso\core\services\shortcodes\ShortcodeInterface',
917
-            'EventEspresso\core\services\shortcodes\ShortcodeInterface'                    => 'EventEspresso\core\services\shortcodes\EspressoShortcode',
918
-            'EventEspresso\core\services\cache\CacheStorageInterface'                      => 'EventEspresso\core\services\cache\TransientCacheStorage',
919
-            'LoaderInterface'                                                              => 'EventEspresso\core\services\loaders\LoaderInterface',
920
-            'EventEspresso\core\services\loaders\LoaderInterface'                          => 'EventEspresso\core\services\loaders\Loader',
921
-            'CommandFactoryInterface'                                                      => 'EventEspresso\core\services\commands\CommandFactoryInterface',
922
-            'EventEspresso\core\services\commands\CommandFactoryInterface'                 => 'EventEspresso\core\services\commands\CommandFactory',
923
-            'EventEspresso\core\domain\services\session\SessionIdentifierInterface'        => 'EE_Session',
924
-            'EmailValidatorInterface'                                                      => 'EventEspresso\core\domain\services\validation\email\EmailValidatorInterface',
925
-            'EventEspresso\core\domain\services\validation\email\EmailValidatorInterface'  => 'EventEspresso\core\domain\services\validation\email\EmailValidationService',
926
-            'NoticeConverterInterface'                                                     => 'EventEspresso\core\services\notices\NoticeConverterInterface',
927
-            'EventEspresso\core\services\notices\NoticeConverterInterface'                 => 'EventEspresso\core\services\notices\ConvertNoticesToEeErrors',
928
-            'NoticesContainerInterface'                                                    => 'EventEspresso\core\services\notices\NoticesContainerInterface',
929
-            'EventEspresso\core\services\notices\NoticesContainerInterface'                => 'EventEspresso\core\services\notices\NoticesContainer',
930
-            'EventEspresso\core\services\request\RequestInterface'                         => 'EventEspresso\core\services\request\Request',
931
-            'EventEspresso\core\services\request\ResponseInterface'                        => 'EventEspresso\core\services\request\Response',
932
-            'EventEspresso\core\domain\DomainInterface'                                    => 'EventEspresso\core\domain\Domain',
933
-        );
934
-        foreach ($aliases as $alias => $fqn) {
935
-            if (is_array($fqn)) {
936
-                foreach ($fqn as $class => $for_class) {
937
-                    $this->class_cache->addAlias($class, $alias, $for_class);
938
-                }
939
-                continue;
940
-            }
941
-            $this->class_cache->addAlias($fqn, $alias);
942
-        }
943
-        if (! (defined('DOING_AJAX') && DOING_AJAX) && is_admin()) {
944
-            $this->class_cache->addAlias(
945
-                'EventEspresso\core\services\notices\ConvertNoticesToAdminNotices',
946
-                'EventEspresso\core\services\notices\NoticeConverterInterface'
947
-            );
948
-        }
949
-    }
950
-
951
-
952
-    /**
953
-     * This is used to reset the internal map and class_loaders to their original default state at the beginning of the
954
-     * request Primarily used by unit tests.
955
-     */
956
-    public function reset()
957
-    {
958
-        $this->_register_core_class_loaders();
959
-        $this->_register_core_dependencies();
960
-    }
961
-
962
-
963
-    /**
964
-     * PLZ NOTE: a better name for this method would be is_alias()
965
-     * because it returns TRUE if the provided fully qualified name IS an alias
966
-     * WHY?
967
-     * Because if a class is type hinting for a concretion,
968
-     * then why would we need to find another class to supply it?
969
-     * ie: if a class asks for `Fully/Qualified/Namespace/SpecificClassName`,
970
-     * then give it an instance of `Fully/Qualified/Namespace/SpecificClassName`.
971
-     * Don't go looking for some substitute.
972
-     * Whereas if a class is type hinting for an interface...
973
-     * then we need to find an actual class to use.
974
-     * So the interface IS the alias for some other FQN,
975
-     * and we need to find out if `Fully/Qualified/Namespace/SomeInterface`
976
-     * represents some other class.
977
-     *
978
-     * @deprecated 4.9.62.p
979
-     * @param string $fqn
980
-     * @param string $for_class
981
-     * @return bool
982
-     */
983
-    public function has_alias($fqn = '', $for_class = '')
984
-    {
985
-        return $this->isAlias($fqn, $for_class);
986
-    }
987
-
988
-
989
-    /**
990
-     * PLZ NOTE: a better name for this method would be get_fqn_for_alias()
991
-     * because it returns a FQN for provided alias if one exists, otherwise returns the original $alias
992
-     * functions recursively, so that multiple aliases can be used to drill down to a FQN
993
-     *  for example:
994
-     *      if the following two entries were added to the _aliases array:
995
-     *          array(
996
-     *              'interface_alias'           => 'some\namespace\interface'
997
-     *              'some\namespace\interface'  => 'some\namespace\classname'
998
-     *          )
999
-     *      then one could use EE_Registry::instance()->create( 'interface_alias' )
1000
-     *      to load an instance of 'some\namespace\classname'
1001
-     *
1002
-     * @deprecated 4.9.62.p
1003
-     * @param string $alias
1004
-     * @param string $for_class
1005
-     * @return string
1006
-     */
1007
-    public function get_alias($alias = '', $for_class = '')
1008
-    {
1009
-        return $this->getFqnForAlias($alias, $for_class);
1010
-    }
23
+	/**
24
+	 * This means that the requested class dependency is not present in the dependency map
25
+	 */
26
+	const not_registered = 0;
27
+
28
+	/**
29
+	 * This instructs class loaders to ALWAYS return a newly instantiated object for the requested class.
30
+	 */
31
+	const load_new_object = 1;
32
+
33
+	/**
34
+	 * This instructs class loaders to return a previously instantiated and cached object for the requested class.
35
+	 * IF a previously instantiated object does not exist, a new one will be created and added to the cache.
36
+	 */
37
+	const load_from_cache = 2;
38
+
39
+	/**
40
+	 * When registering a dependency,
41
+	 * this indicates to keep any existing dependencies that already exist,
42
+	 * and simply discard any new dependencies declared in the incoming data
43
+	 */
44
+	const KEEP_EXISTING_DEPENDENCIES = 0;
45
+
46
+	/**
47
+	 * When registering a dependency,
48
+	 * this indicates to overwrite any existing dependencies that already exist using the incoming data
49
+	 */
50
+	const OVERWRITE_DEPENDENCIES = 1;
51
+
52
+
53
+	/**
54
+	 * @type EE_Dependency_Map $_instance
55
+	 */
56
+	protected static $_instance;
57
+
58
+	/**
59
+	 * @var ClassInterfaceCache $class_cache
60
+	 */
61
+	private $class_cache;
62
+
63
+	/**
64
+	 * @type RequestInterface $request
65
+	 */
66
+	protected $request;
67
+
68
+	/**
69
+	 * @type LegacyRequestInterface $legacy_request
70
+	 */
71
+	protected $legacy_request;
72
+
73
+	/**
74
+	 * @type ResponseInterface $response
75
+	 */
76
+	protected $response;
77
+
78
+	/**
79
+	 * @type LoaderInterface $loader
80
+	 */
81
+	protected $loader;
82
+
83
+	/**
84
+	 * @type array $_dependency_map
85
+	 */
86
+	protected $_dependency_map = array();
87
+
88
+	/**
89
+	 * @type array $_class_loaders
90
+	 */
91
+	protected $_class_loaders = array();
92
+
93
+
94
+	/**
95
+	 * EE_Dependency_Map constructor.
96
+	 *
97
+	 * @param ClassInterfaceCache $class_cache
98
+	 */
99
+	protected function __construct(ClassInterfaceCache $class_cache)
100
+	{
101
+		$this->class_cache = $class_cache;
102
+		do_action('EE_Dependency_Map____construct', $this);
103
+	}
104
+
105
+
106
+	/**
107
+	 * @return void
108
+	 */
109
+	public function initialize()
110
+	{
111
+		$this->_register_core_dependencies();
112
+		$this->_register_core_class_loaders();
113
+		$this->_register_core_aliases();
114
+	}
115
+
116
+
117
+	/**
118
+	 * @singleton method used to instantiate class object
119
+	 * @param ClassInterfaceCache|null $class_cache
120
+	 * @return EE_Dependency_Map
121
+	 */
122
+	public static function instance(ClassInterfaceCache $class_cache = null)
123
+	{
124
+		// check if class object is instantiated, and instantiated properly
125
+		if (! self::$_instance instanceof EE_Dependency_Map
126
+			&& $class_cache instanceof ClassInterfaceCache
127
+		) {
128
+			self::$_instance = new EE_Dependency_Map($class_cache);
129
+		}
130
+		return self::$_instance;
131
+	}
132
+
133
+
134
+	/**
135
+	 * @param RequestInterface $request
136
+	 */
137
+	public function setRequest(RequestInterface $request)
138
+	{
139
+		$this->request = $request;
140
+	}
141
+
142
+
143
+	/**
144
+	 * @param LegacyRequestInterface $legacy_request
145
+	 */
146
+	public function setLegacyRequest(LegacyRequestInterface $legacy_request)
147
+	{
148
+		$this->legacy_request = $legacy_request;
149
+	}
150
+
151
+
152
+	/**
153
+	 * @param ResponseInterface $response
154
+	 */
155
+	public function setResponse(ResponseInterface $response)
156
+	{
157
+		$this->response = $response;
158
+	}
159
+
160
+
161
+	/**
162
+	 * @param LoaderInterface $loader
163
+	 */
164
+	public function setLoader(LoaderInterface $loader)
165
+	{
166
+		$this->loader = $loader;
167
+	}
168
+
169
+
170
+	/**
171
+	 * @param string $class
172
+	 * @param array  $dependencies
173
+	 * @param int    $overwrite
174
+	 * @return bool
175
+	 */
176
+	public static function register_dependencies(
177
+		$class,
178
+		array $dependencies,
179
+		$overwrite = EE_Dependency_Map::KEEP_EXISTING_DEPENDENCIES
180
+	) {
181
+		return self::$_instance->registerDependencies($class, $dependencies, $overwrite);
182
+	}
183
+
184
+
185
+	/**
186
+	 * Assigns an array of class names and corresponding load sources (new or cached)
187
+	 * to the class specified by the first parameter.
188
+	 * IMPORTANT !!!
189
+	 * The order of elements in the incoming $dependencies array MUST match
190
+	 * the order of the constructor parameters for the class in question.
191
+	 * This is especially important when overriding any existing dependencies that are registered.
192
+	 * the third parameter controls whether any duplicate dependencies are overwritten or not.
193
+	 *
194
+	 * @param string $class
195
+	 * @param array  $dependencies
196
+	 * @param int    $overwrite
197
+	 * @return bool
198
+	 */
199
+	public function registerDependencies(
200
+		$class,
201
+		array $dependencies,
202
+		$overwrite = EE_Dependency_Map::KEEP_EXISTING_DEPENDENCIES
203
+	) {
204
+		$class = trim($class, '\\');
205
+		$registered = false;
206
+		if (empty(self::$_instance->_dependency_map[ $class ])) {
207
+			self::$_instance->_dependency_map[ $class ] = array();
208
+		}
209
+		// we need to make sure that any aliases used when registering a dependency
210
+		// get resolved to the correct class name
211
+		foreach ($dependencies as $dependency => $load_source) {
212
+			$alias = self::$_instance->getFqnForAlias($dependency);
213
+			if ($overwrite === EE_Dependency_Map::OVERWRITE_DEPENDENCIES
214
+				|| ! isset(self::$_instance->_dependency_map[ $class ][ $alias ])
215
+			) {
216
+				unset($dependencies[ $dependency ]);
217
+				$dependencies[ $alias ] = $load_source;
218
+				$registered = true;
219
+			}
220
+		}
221
+		// now add our two lists of dependencies together.
222
+		// using Union (+=) favours the arrays in precedence from left to right,
223
+		// so $dependencies is NOT overwritten because it is listed first
224
+		// ie: with A = B + C, entries in B take precedence over duplicate entries in C
225
+		// Union is way faster than array_merge() but should be used with caution...
226
+		// especially with numerically indexed arrays
227
+		$dependencies += self::$_instance->_dependency_map[ $class ];
228
+		// now we need to ensure that the resulting dependencies
229
+		// array only has the entries that are required for the class
230
+		// so first count how many dependencies were originally registered for the class
231
+		$dependency_count = count(self::$_instance->_dependency_map[ $class ]);
232
+		// if that count is non-zero (meaning dependencies were already registered)
233
+		self::$_instance->_dependency_map[ $class ] = $dependency_count
234
+			// then truncate the  final array to match that count
235
+			? array_slice($dependencies, 0, $dependency_count)
236
+			// otherwise just take the incoming array because nothing previously existed
237
+			: $dependencies;
238
+		return $registered;
239
+	}
240
+
241
+
242
+	/**
243
+	 * @param string $class_name
244
+	 * @param string $loader
245
+	 * @return bool
246
+	 * @throws DomainException
247
+	 */
248
+	public static function register_class_loader($class_name, $loader = 'load_core')
249
+	{
250
+		if (! $loader instanceof Closure && strpos($class_name, '\\') !== false) {
251
+			throw new DomainException(
252
+				esc_html__('Don\'t use class loaders for FQCNs.', 'event_espresso')
253
+			);
254
+		}
255
+		// check that loader is callable or method starts with "load_" and exists in EE_Registry
256
+		if (! is_callable($loader)
257
+			&& (
258
+				strpos($loader, 'load_') !== 0
259
+				|| ! method_exists('EE_Registry', $loader)
260
+			)
261
+		) {
262
+			throw new DomainException(
263
+				sprintf(
264
+					esc_html__(
265
+						'"%1$s" is not a valid loader method on EE_Registry.',
266
+						'event_espresso'
267
+					),
268
+					$loader
269
+				)
270
+			);
271
+		}
272
+		$class_name = self::$_instance->getFqnForAlias($class_name);
273
+		if (! isset(self::$_instance->_class_loaders[ $class_name ])) {
274
+			self::$_instance->_class_loaders[ $class_name ] = $loader;
275
+			return true;
276
+		}
277
+		return false;
278
+	}
279
+
280
+
281
+	/**
282
+	 * @return array
283
+	 */
284
+	public function dependency_map()
285
+	{
286
+		return $this->_dependency_map;
287
+	}
288
+
289
+
290
+	/**
291
+	 * returns TRUE if dependency map contains a listing for the provided class name
292
+	 *
293
+	 * @param string $class_name
294
+	 * @return boolean
295
+	 */
296
+	public function has($class_name = '')
297
+	{
298
+		// all legacy models have the same dependencies
299
+		if (strpos($class_name, 'EEM_') === 0) {
300
+			$class_name = 'LEGACY_MODELS';
301
+		}
302
+		return isset($this->_dependency_map[ $class_name ]) ? true : false;
303
+	}
304
+
305
+
306
+	/**
307
+	 * returns TRUE if dependency map contains a listing for the provided class name AND dependency
308
+	 *
309
+	 * @param string $class_name
310
+	 * @param string $dependency
311
+	 * @return bool
312
+	 */
313
+	public function has_dependency_for_class($class_name = '', $dependency = '')
314
+	{
315
+		// all legacy models have the same dependencies
316
+		if (strpos($class_name, 'EEM_') === 0) {
317
+			$class_name = 'LEGACY_MODELS';
318
+		}
319
+		$dependency = $this->getFqnForAlias($dependency, $class_name);
320
+		return isset($this->_dependency_map[ $class_name ][ $dependency ])
321
+			? true
322
+			: false;
323
+	}
324
+
325
+
326
+	/**
327
+	 * returns loading strategy for whether a previously cached dependency should be loaded or a new instance returned
328
+	 *
329
+	 * @param string $class_name
330
+	 * @param string $dependency
331
+	 * @return int
332
+	 */
333
+	public function loading_strategy_for_class_dependency($class_name = '', $dependency = '')
334
+	{
335
+		// all legacy models have the same dependencies
336
+		if (strpos($class_name, 'EEM_') === 0) {
337
+			$class_name = 'LEGACY_MODELS';
338
+		}
339
+		$dependency = $this->getFqnForAlias($dependency);
340
+		return $this->has_dependency_for_class($class_name, $dependency)
341
+			? $this->_dependency_map[ $class_name ][ $dependency ]
342
+			: EE_Dependency_Map::not_registered;
343
+	}
344
+
345
+
346
+	/**
347
+	 * @param string $class_name
348
+	 * @return string | Closure
349
+	 */
350
+	public function class_loader($class_name)
351
+	{
352
+		// all legacy models use load_model()
353
+		if (strpos($class_name, 'EEM_') === 0) {
354
+			return 'load_model';
355
+		}
356
+		$class_name = $this->getFqnForAlias($class_name);
357
+		return isset($this->_class_loaders[ $class_name ]) ? $this->_class_loaders[ $class_name ] : '';
358
+	}
359
+
360
+
361
+	/**
362
+	 * @return array
363
+	 */
364
+	public function class_loaders()
365
+	{
366
+		return $this->_class_loaders;
367
+	}
368
+
369
+
370
+	/**
371
+	 * adds an alias for a classname
372
+	 *
373
+	 * @param string $fqcn      the class name that should be used (concrete class to replace interface)
374
+	 * @param string $alias     the class name that would be type hinted for (abstract parent or interface)
375
+	 * @param string $for_class the class that has the dependency (is type hinting for the interface)
376
+	 */
377
+	public function add_alias($fqcn, $alias, $for_class = '')
378
+	{
379
+		$this->class_cache->addAlias($fqcn, $alias, $for_class);
380
+	}
381
+
382
+
383
+	/**
384
+	 * Returns TRUE if the provided fully qualified name IS an alias
385
+	 * WHY?
386
+	 * Because if a class is type hinting for a concretion,
387
+	 * then why would we need to find another class to supply it?
388
+	 * ie: if a class asks for `Fully/Qualified/Namespace/SpecificClassName`,
389
+	 * then give it an instance of `Fully/Qualified/Namespace/SpecificClassName`.
390
+	 * Don't go looking for some substitute.
391
+	 * Whereas if a class is type hinting for an interface...
392
+	 * then we need to find an actual class to use.
393
+	 * So the interface IS the alias for some other FQN,
394
+	 * and we need to find out if `Fully/Qualified/Namespace/SomeInterface`
395
+	 * represents some other class.
396
+	 *
397
+	 * @param string $fqn
398
+	 * @param string $for_class
399
+	 * @return bool
400
+	 */
401
+	public function isAlias($fqn = '', $for_class = '')
402
+	{
403
+		return $this->class_cache->isAlias($fqn, $for_class);
404
+	}
405
+
406
+
407
+	/**
408
+	 * Returns a FQN for provided alias if one exists, otherwise returns the original $alias
409
+	 * functions recursively, so that multiple aliases can be used to drill down to a FQN
410
+	 *  for example:
411
+	 *      if the following two entries were added to the _aliases array:
412
+	 *          array(
413
+	 *              'interface_alias'           => 'some\namespace\interface'
414
+	 *              'some\namespace\interface'  => 'some\namespace\classname'
415
+	 *          )
416
+	 *      then one could use EE_Registry::instance()->create( 'interface_alias' )
417
+	 *      to load an instance of 'some\namespace\classname'
418
+	 *
419
+	 * @param string $alias
420
+	 * @param string $for_class
421
+	 * @return string
422
+	 */
423
+	public function getFqnForAlias($alias = '', $for_class = '')
424
+	{
425
+		return (string) $this->class_cache->getFqnForAlias($alias, $for_class);
426
+	}
427
+
428
+
429
+	/**
430
+	 * Registers the core dependencies and whether a previously instantiated object should be loaded from the cache,
431
+	 * if one exists, or whether a new object should be generated every time the requested class is loaded.
432
+	 * This is done by using the following class constants:
433
+	 *        EE_Dependency_Map::load_from_cache - loads previously instantiated object
434
+	 *        EE_Dependency_Map::load_new_object - generates a new object every time
435
+	 */
436
+	protected function _register_core_dependencies()
437
+	{
438
+		$this->_dependency_map = array(
439
+			'EE_Request_Handler'                                                                                          => array(
440
+				'EE_Request' => EE_Dependency_Map::load_from_cache,
441
+			),
442
+			'EE_System'                                                                                                   => array(
443
+				'EE_Registry'                                 => EE_Dependency_Map::load_from_cache,
444
+				'EventEspresso\core\services\loaders\Loader'  => EE_Dependency_Map::load_from_cache,
445
+				'EventEspresso\core\services\request\Request' => EE_Dependency_Map::load_from_cache,
446
+				'EE_Maintenance_Mode'                         => EE_Dependency_Map::load_from_cache,
447
+			),
448
+			'EE_Session'                                                                                                  => array(
449
+				'EventEspresso\core\services\cache\TransientCacheStorage'  => EE_Dependency_Map::load_from_cache,
450
+				'EventEspresso\core\domain\values\session\SessionLifespan' => EE_Dependency_Map::load_from_cache,
451
+				'EventEspresso\core\services\request\Request'              => EE_Dependency_Map::load_from_cache,
452
+				'EE_Encryption'                                            => EE_Dependency_Map::load_from_cache,
453
+			),
454
+			'EE_Cart'                                                                                                     => array(
455
+				'EE_Session' => EE_Dependency_Map::load_from_cache,
456
+			),
457
+			'EE_Front_Controller'                                                                                         => array(
458
+				'EE_Registry'              => EE_Dependency_Map::load_from_cache,
459
+				'EE_Request_Handler'       => EE_Dependency_Map::load_from_cache,
460
+				'EE_Module_Request_Router' => EE_Dependency_Map::load_from_cache,
461
+			),
462
+			'EE_Messenger_Collection_Loader'                                                                              => array(
463
+				'EE_Messenger_Collection' => EE_Dependency_Map::load_new_object,
464
+			),
465
+			'EE_Message_Type_Collection_Loader'                                                                           => array(
466
+				'EE_Message_Type_Collection' => EE_Dependency_Map::load_new_object,
467
+			),
468
+			'EE_Message_Resource_Manager'                                                                                 => array(
469
+				'EE_Messenger_Collection_Loader'    => EE_Dependency_Map::load_new_object,
470
+				'EE_Message_Type_Collection_Loader' => EE_Dependency_Map::load_new_object,
471
+				'EEM_Message_Template_Group'        => EE_Dependency_Map::load_from_cache,
472
+			),
473
+			'EE_Message_Factory'                                                                                          => array(
474
+				'EE_Message_Resource_Manager' => EE_Dependency_Map::load_from_cache,
475
+			),
476
+			'EE_messages'                                                                                                 => array(
477
+				'EE_Message_Resource_Manager' => EE_Dependency_Map::load_from_cache,
478
+			),
479
+			'EE_Messages_Generator'                                                                                       => array(
480
+				'EE_Messages_Queue'                    => EE_Dependency_Map::load_new_object,
481
+				'EE_Messages_Data_Handler_Collection'  => EE_Dependency_Map::load_new_object,
482
+				'EE_Message_Template_Group_Collection' => EE_Dependency_Map::load_new_object,
483
+				'EEH_Parse_Shortcodes'                 => EE_Dependency_Map::load_from_cache,
484
+			),
485
+			'EE_Messages_Processor'                                                                                       => array(
486
+				'EE_Message_Resource_Manager' => EE_Dependency_Map::load_from_cache,
487
+			),
488
+			'EE_Messages_Queue'                                                                                           => array(
489
+				'EE_Message_Repository' => EE_Dependency_Map::load_new_object,
490
+			),
491
+			'EE_Messages_Template_Defaults'                                                                               => array(
492
+				'EEM_Message_Template_Group' => EE_Dependency_Map::load_from_cache,
493
+				'EEM_Message_Template'       => EE_Dependency_Map::load_from_cache,
494
+			),
495
+			'EE_Message_To_Generate_From_Request'                                                                         => array(
496
+				'EE_Message_Resource_Manager' => EE_Dependency_Map::load_from_cache,
497
+				'EE_Request_Handler'          => EE_Dependency_Map::load_from_cache,
498
+			),
499
+			'EventEspresso\core\services\commands\CommandBus'                                                             => array(
500
+				'EventEspresso\core\services\commands\CommandHandlerManager' => EE_Dependency_Map::load_from_cache,
501
+			),
502
+			'EventEspresso\services\commands\CommandHandler'                                                              => array(
503
+				'EE_Registry'         => EE_Dependency_Map::load_from_cache,
504
+				'CommandBusInterface' => EE_Dependency_Map::load_from_cache,
505
+			),
506
+			'EventEspresso\core\services\commands\CommandHandlerManager'                                                  => array(
507
+				'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache,
508
+			),
509
+			'EventEspresso\core\services\commands\CompositeCommandHandler'                                                => array(
510
+				'EventEspresso\core\services\commands\CommandBus'     => EE_Dependency_Map::load_from_cache,
511
+				'EventEspresso\core\services\commands\CommandFactory' => EE_Dependency_Map::load_from_cache,
512
+			),
513
+			'EventEspresso\core\services\commands\CommandFactory'                                                         => array(
514
+				'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache,
515
+			),
516
+			'EventEspresso\core\services\commands\middleware\CapChecker'                                                  => array(
517
+				'EventEspresso\core\domain\services\capabilities\CapabilitiesChecker' => EE_Dependency_Map::load_from_cache,
518
+			),
519
+			'EventEspresso\core\domain\services\capabilities\CapabilitiesChecker'                                         => array(
520
+				'EE_Capabilities' => EE_Dependency_Map::load_from_cache,
521
+			),
522
+			'EventEspresso\core\domain\services\capabilities\RegistrationsCapChecker'                                     => array(
523
+				'EE_Capabilities' => EE_Dependency_Map::load_from_cache,
524
+			),
525
+			'EventEspresso\core\services\commands\registration\CreateRegistrationCommandHandler'                          => array(
526
+				'EventEspresso\core\domain\services\registration\CreateRegistrationService' => EE_Dependency_Map::load_from_cache,
527
+			),
528
+			'EventEspresso\core\services\commands\registration\CopyRegistrationDetailsCommandHandler'                     => array(
529
+				'EventEspresso\core\domain\services\registration\CopyRegistrationService' => EE_Dependency_Map::load_from_cache,
530
+			),
531
+			'EventEspresso\core\services\commands\registration\CopyRegistrationPaymentsCommandHandler'                    => array(
532
+				'EventEspresso\core\domain\services\registration\CopyRegistrationService' => EE_Dependency_Map::load_from_cache,
533
+			),
534
+			'EventEspresso\core\services\commands\registration\CancelRegistrationAndTicketLineItemCommandHandler'         => array(
535
+				'EventEspresso\core\domain\services\registration\CancelTicketLineItemService' => EE_Dependency_Map::load_from_cache,
536
+			),
537
+			'EventEspresso\core\services\commands\registration\UpdateRegistrationAndTransactionAfterChangeCommandHandler' => array(
538
+				'EventEspresso\core\domain\services\registration\UpdateRegistrationService' => EE_Dependency_Map::load_from_cache,
539
+			),
540
+			'EventEspresso\core\services\commands\ticket\CreateTicketLineItemCommandHandler'                              => array(
541
+				'EventEspresso\core\domain\services\ticket\CreateTicketLineItemService' => EE_Dependency_Map::load_from_cache,
542
+			),
543
+			'EventEspresso\core\services\commands\ticket\CancelTicketLineItemCommandHandler'                              => array(
544
+				'EventEspresso\core\domain\services\ticket\CancelTicketLineItemService' => EE_Dependency_Map::load_from_cache,
545
+			),
546
+			'EventEspresso\core\domain\services\registration\CancelRegistrationService'                                   => array(
547
+				'EventEspresso\core\domain\services\ticket\CancelTicketLineItemService' => EE_Dependency_Map::load_from_cache,
548
+			),
549
+			'EventEspresso\core\services\commands\attendee\CreateAttendeeCommandHandler'                                  => array(
550
+				'EEM_Attendee' => EE_Dependency_Map::load_from_cache,
551
+			),
552
+			'EventEspresso\core\services\database\TableManager'                                                           => array(
553
+				'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache,
554
+			),
555
+			'EE_Data_Migration_Class_Base'                                                                                => array(
556
+				'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache,
557
+				'EventEspresso\core\services\database\TableManager'  => EE_Dependency_Map::load_from_cache,
558
+			),
559
+			'EE_DMS_Core_4_1_0'                                                                                           => array(
560
+				'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache,
561
+				'EventEspresso\core\services\database\TableManager'  => EE_Dependency_Map::load_from_cache,
562
+			),
563
+			'EE_DMS_Core_4_2_0'                                                                                           => array(
564
+				'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache,
565
+				'EventEspresso\core\services\database\TableManager'  => EE_Dependency_Map::load_from_cache,
566
+			),
567
+			'EE_DMS_Core_4_3_0'                                                                                           => array(
568
+				'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache,
569
+				'EventEspresso\core\services\database\TableManager'  => EE_Dependency_Map::load_from_cache,
570
+			),
571
+			'EE_DMS_Core_4_4_0'                                                                                           => array(
572
+				'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache,
573
+				'EventEspresso\core\services\database\TableManager'  => EE_Dependency_Map::load_from_cache,
574
+			),
575
+			'EE_DMS_Core_4_5_0'                                                                                           => array(
576
+				'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache,
577
+				'EventEspresso\core\services\database\TableManager'  => EE_Dependency_Map::load_from_cache,
578
+			),
579
+			'EE_DMS_Core_4_6_0'                                                                                           => array(
580
+				'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache,
581
+				'EventEspresso\core\services\database\TableManager'  => EE_Dependency_Map::load_from_cache,
582
+			),
583
+			'EE_DMS_Core_4_7_0'                                                                                           => array(
584
+				'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache,
585
+				'EventEspresso\core\services\database\TableManager'  => EE_Dependency_Map::load_from_cache,
586
+			),
587
+			'EE_DMS_Core_4_8_0'                                                                                           => array(
588
+				'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache,
589
+				'EventEspresso\core\services\database\TableManager'  => EE_Dependency_Map::load_from_cache,
590
+			),
591
+			'EE_DMS_Core_4_9_0'                                                                                           => array(
592
+				'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache,
593
+				'EventEspresso\core\services\database\TableManager'  => EE_Dependency_Map::load_from_cache,
594
+			),
595
+			'EventEspresso\core\services\assets\I18nRegistry'                                                             => array(
596
+				array(),
597
+				'EventEspresso\core\domain\Domain' => EE_Dependency_Map::load_from_cache,
598
+			),
599
+			'EventEspresso\core\services\assets\Registry'                                                                 => array(
600
+				'EventEspresso\core\services\assets\AssetCollection' => EE_Dependency_Map::load_from_cache,
601
+				'EventEspresso\core\services\assets\I18nRegistry'    => EE_Dependency_Map::load_from_cache,
602
+			),
603
+			'EventEspresso\core\domain\entities\shortcodes\EspressoCancelled'                                             => array(
604
+				'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache,
605
+			),
606
+			'EventEspresso\core\domain\entities\shortcodes\EspressoCheckout'                                              => array(
607
+				'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache,
608
+			),
609
+			'EventEspresso\core\domain\entities\shortcodes\EspressoEventAttendees'                                        => array(
610
+				'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache,
611
+			),
612
+			'EventEspresso\core\domain\entities\shortcodes\EspressoEvents'                                                => array(
613
+				'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache,
614
+			),
615
+			'EventEspresso\core\domain\entities\shortcodes\EspressoThankYou'                                              => array(
616
+				'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache,
617
+			),
618
+			'EventEspresso\core\domain\entities\shortcodes\EspressoTicketSelector'                                        => array(
619
+				'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache,
620
+			),
621
+			'EventEspresso\core\domain\entities\shortcodes\EspressoTxnPage'                                               => array(
622
+				'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache,
623
+			),
624
+			'EventEspresso\core\services\cache\BasicCacheManager'                                                         => array(
625
+				'EventEspresso\core\services\cache\TransientCacheStorage' => EE_Dependency_Map::load_from_cache,
626
+			),
627
+			'EventEspresso\core\services\cache\PostRelatedCacheManager'                                                   => array(
628
+				'EventEspresso\core\services\cache\TransientCacheStorage' => EE_Dependency_Map::load_from_cache,
629
+			),
630
+			'EventEspresso\core\domain\services\validation\email\EmailValidationService'                                  => array(
631
+				'EE_Registration_Config'                     => EE_Dependency_Map::load_from_cache,
632
+				'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache,
633
+			),
634
+			'EventEspresso\core\domain\values\EmailAddress'                                                               => array(
635
+				null,
636
+				'EventEspresso\core\domain\services\validation\email\EmailValidationService' => EE_Dependency_Map::load_from_cache,
637
+			),
638
+			'EventEspresso\core\services\orm\ModelFieldFactory'                                                           => array(
639
+				'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache,
640
+			),
641
+			'LEGACY_MODELS'                                                                                               => array(
642
+				null,
643
+				'EventEspresso\core\services\database\ModelFieldFactory' => EE_Dependency_Map::load_from_cache,
644
+			),
645
+			'EE_Module_Request_Router'                                                                                    => array(
646
+				'EE_Request' => EE_Dependency_Map::load_from_cache,
647
+			),
648
+			'EE_Registration_Processor'                                                                                   => array(
649
+				'EE_Request' => EE_Dependency_Map::load_from_cache,
650
+			),
651
+			'EventEspresso\core\services\notifications\PersistentAdminNoticeManager'                                      => array(
652
+				null,
653
+				'EventEspresso\core\domain\services\capabilities\CapabilitiesChecker' => EE_Dependency_Map::load_from_cache,
654
+				'EE_Request'                                                          => EE_Dependency_Map::load_from_cache,
655
+			),
656
+			'EventEspresso\core\services\licensing\LicenseService'                                                        => array(
657
+				'EventEspresso\core\domain\services\pue\Stats'  => EE_Dependency_Map::load_from_cache,
658
+				'EventEspresso\core\domain\services\pue\Config' => EE_Dependency_Map::load_from_cache,
659
+			),
660
+			'EE_Admin_Transactions_List_Table'                                                                            => array(
661
+				null,
662
+				'EventEspresso\core\domain\values\session\SessionLifespan' => EE_Dependency_Map::load_from_cache,
663
+			),
664
+			'EventEspresso\core\domain\services\pue\Stats'                                                                => array(
665
+				'EventEspresso\core\domain\services\pue\Config'        => EE_Dependency_Map::load_from_cache,
666
+				'EE_Maintenance_Mode'                                  => EE_Dependency_Map::load_from_cache,
667
+				'EventEspresso\core\domain\services\pue\StatsGatherer' => EE_Dependency_Map::load_from_cache,
668
+			),
669
+			'EventEspresso\core\domain\services\pue\Config'                                                               => array(
670
+				'EE_Network_Config' => EE_Dependency_Map::load_from_cache,
671
+				'EE_Config'         => EE_Dependency_Map::load_from_cache,
672
+			),
673
+			'EventEspresso\core\domain\services\pue\StatsGatherer'                                                        => array(
674
+				'EEM_Payment_Method' => EE_Dependency_Map::load_from_cache,
675
+				'EEM_Event'          => EE_Dependency_Map::load_from_cache,
676
+				'EEM_Datetime'       => EE_Dependency_Map::load_from_cache,
677
+				'EEM_Ticket'         => EE_Dependency_Map::load_from_cache,
678
+				'EEM_Registration'   => EE_Dependency_Map::load_from_cache,
679
+				'EEM_Transaction'    => EE_Dependency_Map::load_from_cache,
680
+				'EE_Config'          => EE_Dependency_Map::load_from_cache,
681
+			),
682
+			'EventEspresso\core\domain\services\admin\ExitModal'                                                          => array(
683
+				'EventEspresso\core\services\assets\Registry' => EE_Dependency_Map::load_from_cache,
684
+			),
685
+			'EventEspresso\core\domain\services\admin\PluginUpsells'                                                      => array(
686
+				'EventEspresso\core\domain\Domain' => EE_Dependency_Map::load_from_cache,
687
+			),
688
+			'EventEspresso\caffeinated\modules\recaptcha_invisible\InvisibleRecaptcha'                                    => array(
689
+				'EE_Registration_Config' => EE_Dependency_Map::load_from_cache,
690
+				'EE_Session'             => EE_Dependency_Map::load_from_cache,
691
+			),
692
+			'EventEspresso\caffeinated\modules\recaptcha_invisible\RecaptchaAdminSettings'                                => array(
693
+				'EE_Registration_Config' => EE_Dependency_Map::load_from_cache,
694
+			),
695
+			'EventEspresso\modules\ticket_selector\ProcessTicketSelector'                                                 => array(
696
+				'EE_Core_Config'                                                          => EE_Dependency_Map::load_from_cache,
697
+				'EventEspresso\core\services\request\Request'                             => EE_Dependency_Map::load_from_cache,
698
+				'EE_Session'                                                              => EE_Dependency_Map::load_from_cache,
699
+				'EEM_Ticket'                                                              => EE_Dependency_Map::load_from_cache,
700
+				'EventEspresso\modules\ticket_selector\TicketDatetimeAvailabilityTracker' => EE_Dependency_Map::load_from_cache,
701
+			),
702
+			'EventEspresso\modules\ticket_selector\TicketDatetimeAvailabilityTracker'                                     => array(
703
+				'EEM_Datetime' => EE_Dependency_Map::load_from_cache,
704
+			),
705
+			'EventEspresso\core\domain\entities\custom_post_types\CustomPostTypeDefinitions'                              => array(
706
+				'EE_Core_Config'                             => EE_Dependency_Map::load_from_cache,
707
+				'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache,
708
+			),
709
+			'EventEspresso\core\domain\services\custom_post_types\RegisterCustomPostTypes'                                => array(
710
+				'EventEspresso\core\domain\entities\custom_post_types\CustomPostTypeDefinitions' => EE_Dependency_Map::load_from_cache,
711
+			),
712
+			'EventEspresso\core\domain\services\custom_post_types\RegisterCustomTaxonomies'                               => array(
713
+				'EventEspresso\core\domain\entities\custom_post_types\CustomTaxonomyDefinitions' => EE_Dependency_Map::load_from_cache,
714
+			),
715
+			'EE_CPT_Strategy'                                                                                             => array(
716
+				'EventEspresso\core\domain\entities\custom_post_types\CustomPostTypeDefinitions' => EE_Dependency_Map::load_from_cache,
717
+				'EventEspresso\core\domain\entities\custom_post_types\CustomTaxonomyDefinitions' => EE_Dependency_Map::load_from_cache,
718
+			),
719
+			'EventEspresso\core\services\loaders\ObjectIdentifier'                                                        => array(
720
+				'EventEspresso\core\services\loaders\ClassInterfaceCache' => EE_Dependency_Map::load_from_cache,
721
+			),
722
+			'EventEspresso\core\domain\services\assets\CoreAssetManager'                                                  => array(
723
+				'EventEspresso\core\services\assets\AssetCollection' => EE_Dependency_Map::load_from_cache,
724
+				'EE_Currency_Config'                                 => EE_Dependency_Map::load_from_cache,
725
+				'EE_Template_Config'                                 => EE_Dependency_Map::load_from_cache,
726
+				'EventEspresso\core\domain\Domain'                   => EE_Dependency_Map::load_from_cache,
727
+				'EventEspresso\core\services\assets\Registry'        => EE_Dependency_Map::load_from_cache,
728
+			),
729
+			'EventEspresso\core\domain\services\admin\privacy\policy\PrivacyPolicy' => array(
730
+				'EEM_Payment_Method' => EE_Dependency_Map::load_from_cache,
731
+				'EventEspresso\core\domain\values\session\SessionLifespan' => EE_Dependency_Map::load_from_cache
732
+			),
733
+			'EventEspresso\core\domain\services\admin\privacy\export\ExportAttendee' => array(
734
+				'EEM_Attendee' => EE_Dependency_Map::load_from_cache,
735
+			),
736
+			'EventEspresso\core\domain\services\admin\privacy\export\ExportAttendeeBillingData' => array(
737
+				'EEM_Attendee' => EE_Dependency_Map::load_from_cache,
738
+				'EEM_Payment_Method' => EE_Dependency_Map::load_from_cache
739
+			),
740
+			'EventEspresso\core\domain\services\admin\privacy\export\ExportCheckins' => array(
741
+				'EEM_Checkin' => EE_Dependency_Map::load_from_cache,
742
+			),
743
+			'EventEspresso\core\domain\services\admin\privacy\export\ExportRegistration' => array(
744
+				'EEM_Registration' => EE_Dependency_Map::load_from_cache,
745
+			),
746
+			'EventEspresso\core\domain\services\admin\privacy\export\ExportTransaction' => array(
747
+				'EEM_Transaction' => EE_Dependency_Map::load_from_cache,
748
+			),
749
+			'EventEspresso\core\domain\services\admin\privacy\erasure\EraseAttendeeData' => array(
750
+				'EEM_Attendee' => EE_Dependency_Map::load_from_cache,
751
+			),
752
+			'EventEspresso\core\domain\services\admin\privacy\erasure\EraseAnswers' => array(
753
+				'EEM_Answer' => EE_Dependency_Map::load_from_cache,
754
+				'EEM_Question' => EE_Dependency_Map::load_from_cache,
755
+			),
756
+			'EventEspresso\core\services\editor\BlockRegistrationManager'                                                 => array(
757
+				'EventEspresso\core\services\assets\BlockAssetManagerCollection' => EE_Dependency_Map::load_from_cache,
758
+				'EventEspresso\core\domain\entities\editor\BlockCollection'      => EE_Dependency_Map::load_from_cache,
759
+				'EventEspresso\core\services\request\Request'                    => EE_Dependency_Map::load_from_cache,
760
+			),
761
+			'EventEspresso\core\domain\entities\editor\blocks\CoreBlocksAssetManager' => array(
762
+				'EventEspresso\core\domain\Domain'                   => EE_Dependency_Map::load_from_cache,
763
+				'EventEspresso\core\services\assets\AssetCollection' => EE_Dependency_Map::load_from_cache,
764
+				'EventEspresso\core\services\assets\Registry'        => EE_Dependency_Map::load_from_cache,
765
+			),
766
+			'EventEspresso\core\domain\entities\editor\blocks\widgets\EventAttendees' => array(
767
+				'EventEspresso\core\domain\entities\editor\blocks\CoreBlocksAssetManager' => self::load_from_cache,
768
+			),
769
+		);
770
+	}
771
+
772
+
773
+	/**
774
+	 * Registers how core classes are loaded.
775
+	 * This can either be done by simply providing the name of one of the EE_Registry loader methods such as:
776
+	 *        'EE_Request_Handler' => 'load_core'
777
+	 *        'EE_Messages_Queue'  => 'load_lib'
778
+	 *        'EEH_Debug_Tools'    => 'load_helper'
779
+	 * or, if greater control is required, by providing a custom closure. For example:
780
+	 *        'Some_Class' => function () {
781
+	 *            return new Some_Class();
782
+	 *        },
783
+	 * This is required for instantiating dependencies
784
+	 * where an interface has been type hinted in a class constructor. For example:
785
+	 *        'Required_Interface' => function () {
786
+	 *            return new A_Class_That_Implements_Required_Interface();
787
+	 *        },
788
+	 */
789
+	protected function _register_core_class_loaders()
790
+	{
791
+		// for PHP5.3 compat, we need to register any properties called here in a variable because `$this` cannot
792
+		// be used in a closure.
793
+		$request = &$this->request;
794
+		$response = &$this->response;
795
+		$legacy_request = &$this->legacy_request;
796
+		// $loader = &$this->loader;
797
+		$this->_class_loaders = array(
798
+			// load_core
799
+			'EE_Capabilities'                              => 'load_core',
800
+			'EE_Encryption'                                => 'load_core',
801
+			'EE_Front_Controller'                          => 'load_core',
802
+			'EE_Module_Request_Router'                     => 'load_core',
803
+			'EE_Registry'                                  => 'load_core',
804
+			'EE_Request'                                   => function () use (&$legacy_request) {
805
+				return $legacy_request;
806
+			},
807
+			'EventEspresso\core\services\request\Request'  => function () use (&$request) {
808
+				return $request;
809
+			},
810
+			'EventEspresso\core\services\request\Response' => function () use (&$response) {
811
+				return $response;
812
+			},
813
+			'EE_Base'                                      => 'load_core',
814
+			'EE_Request_Handler'                           => 'load_core',
815
+			'EE_Session'                                   => 'load_core',
816
+			'EE_Cron_Tasks'                                => 'load_core',
817
+			'EE_System'                                    => 'load_core',
818
+			'EE_Maintenance_Mode'                          => 'load_core',
819
+			'EE_Register_CPTs'                             => 'load_core',
820
+			'EE_Admin'                                     => 'load_core',
821
+			'EE_CPT_Strategy'                              => 'load_core',
822
+			// load_lib
823
+			'EE_Message_Resource_Manager'                  => 'load_lib',
824
+			'EE_Message_Type_Collection'                   => 'load_lib',
825
+			'EE_Message_Type_Collection_Loader'            => 'load_lib',
826
+			'EE_Messenger_Collection'                      => 'load_lib',
827
+			'EE_Messenger_Collection_Loader'               => 'load_lib',
828
+			'EE_Messages_Processor'                        => 'load_lib',
829
+			'EE_Message_Repository'                        => 'load_lib',
830
+			'EE_Messages_Queue'                            => 'load_lib',
831
+			'EE_Messages_Data_Handler_Collection'          => 'load_lib',
832
+			'EE_Message_Template_Group_Collection'         => 'load_lib',
833
+			'EE_Payment_Method_Manager'                    => 'load_lib',
834
+			'EE_Messages_Generator'                        => function () {
835
+				return EE_Registry::instance()->load_lib(
836
+					'Messages_Generator',
837
+					array(),
838
+					false,
839
+					false
840
+				);
841
+			},
842
+			'EE_Messages_Template_Defaults'                => function ($arguments = array()) {
843
+				return EE_Registry::instance()->load_lib(
844
+					'Messages_Template_Defaults',
845
+					$arguments,
846
+					false,
847
+					false
848
+				);
849
+			},
850
+			// load_helper
851
+			'EEH_Parse_Shortcodes'                         => function () {
852
+				if (EE_Registry::instance()->load_helper('Parse_Shortcodes')) {
853
+					return new EEH_Parse_Shortcodes();
854
+				}
855
+				return null;
856
+			},
857
+			'EE_Template_Config'                           => function () {
858
+				return EE_Config::instance()->template_settings;
859
+			},
860
+			'EE_Currency_Config'                           => function () {
861
+				return EE_Config::instance()->currency;
862
+			},
863
+			'EE_Registration_Config'                       => function () {
864
+				return EE_Config::instance()->registration;
865
+			},
866
+			'EE_Core_Config'                               => function () {
867
+				return EE_Config::instance()->core;
868
+			},
869
+			'EventEspresso\core\services\loaders\Loader'   => function () {
870
+				return LoaderFactory::getLoader();
871
+			},
872
+			'EE_Network_Config'                            => function () {
873
+				return EE_Network_Config::instance();
874
+			},
875
+			'EE_Config'                                    => function () {
876
+				return EE_Config::instance();
877
+			},
878
+			'EventEspresso\core\domain\Domain'             => function () {
879
+				return DomainFactory::getEventEspressoCoreDomain();
880
+			},
881
+			'EE_Admin_Config'                              => function () {
882
+				return EE_Config::instance()->admin;
883
+			}
884
+		);
885
+	}
886
+
887
+
888
+	/**
889
+	 * can be used for supplying alternate names for classes,
890
+	 * or for connecting interface names to instantiable classes
891
+	 */
892
+	protected function _register_core_aliases()
893
+	{
894
+		$aliases = array(
895
+			'CommandBusInterface'                                                          => 'EventEspresso\core\services\commands\CommandBusInterface',
896
+			'EventEspresso\core\services\commands\CommandBusInterface'                     => 'EventEspresso\core\services\commands\CommandBus',
897
+			'CommandHandlerManagerInterface'                                               => 'EventEspresso\core\services\commands\CommandHandlerManagerInterface',
898
+			'EventEspresso\core\services\commands\CommandHandlerManagerInterface'          => 'EventEspresso\core\services\commands\CommandHandlerManager',
899
+			'CapChecker'                                                                   => 'EventEspresso\core\services\commands\middleware\CapChecker',
900
+			'AddActionHook'                                                                => 'EventEspresso\core\services\commands\middleware\AddActionHook',
901
+			'CapabilitiesChecker'                                                          => 'EventEspresso\core\domain\services\capabilities\CapabilitiesChecker',
902
+			'CapabilitiesCheckerInterface'                                                 => 'EventEspresso\core\domain\services\capabilities\CapabilitiesCheckerInterface',
903
+			'EventEspresso\core\domain\services\capabilities\CapabilitiesCheckerInterface' => 'EventEspresso\core\domain\services\capabilities\CapabilitiesChecker',
904
+			'CreateRegistrationService'                                                    => 'EventEspresso\core\domain\services\registration\CreateRegistrationService',
905
+			'CreateRegistrationCommandHandler'                                             => 'EventEspresso\core\services\commands\registration\CreateRegistrationCommand',
906
+			'CopyRegistrationDetailsCommandHandler'                                        => 'EventEspresso\core\services\commands\registration\CopyRegistrationDetailsCommand',
907
+			'CopyRegistrationPaymentsCommandHandler'                                       => 'EventEspresso\core\services\commands\registration\CopyRegistrationPaymentsCommand',
908
+			'CancelRegistrationAndTicketLineItemCommandHandler'                            => 'EventEspresso\core\services\commands\registration\CancelRegistrationAndTicketLineItemCommandHandler',
909
+			'UpdateRegistrationAndTransactionAfterChangeCommandHandler'                    => 'EventEspresso\core\services\commands\registration\UpdateRegistrationAndTransactionAfterChangeCommandHandler',
910
+			'CreateTicketLineItemCommandHandler'                                           => 'EventEspresso\core\services\commands\ticket\CreateTicketLineItemCommand',
911
+			'CreateTransactionCommandHandler'                                              => 'EventEspresso\core\services\commands\transaction\CreateTransactionCommandHandler',
912
+			'CreateAttendeeCommandHandler'                                                 => 'EventEspresso\core\services\commands\attendee\CreateAttendeeCommandHandler',
913
+			'TableManager'                                                                 => 'EventEspresso\core\services\database\TableManager',
914
+			'TableAnalysis'                                                                => 'EventEspresso\core\services\database\TableAnalysis',
915
+			'EspressoShortcode'                                                            => 'EventEspresso\core\services\shortcodes\EspressoShortcode',
916
+			'ShortcodeInterface'                                                           => 'EventEspresso\core\services\shortcodes\ShortcodeInterface',
917
+			'EventEspresso\core\services\shortcodes\ShortcodeInterface'                    => 'EventEspresso\core\services\shortcodes\EspressoShortcode',
918
+			'EventEspresso\core\services\cache\CacheStorageInterface'                      => 'EventEspresso\core\services\cache\TransientCacheStorage',
919
+			'LoaderInterface'                                                              => 'EventEspresso\core\services\loaders\LoaderInterface',
920
+			'EventEspresso\core\services\loaders\LoaderInterface'                          => 'EventEspresso\core\services\loaders\Loader',
921
+			'CommandFactoryInterface'                                                      => 'EventEspresso\core\services\commands\CommandFactoryInterface',
922
+			'EventEspresso\core\services\commands\CommandFactoryInterface'                 => 'EventEspresso\core\services\commands\CommandFactory',
923
+			'EventEspresso\core\domain\services\session\SessionIdentifierInterface'        => 'EE_Session',
924
+			'EmailValidatorInterface'                                                      => 'EventEspresso\core\domain\services\validation\email\EmailValidatorInterface',
925
+			'EventEspresso\core\domain\services\validation\email\EmailValidatorInterface'  => 'EventEspresso\core\domain\services\validation\email\EmailValidationService',
926
+			'NoticeConverterInterface'                                                     => 'EventEspresso\core\services\notices\NoticeConverterInterface',
927
+			'EventEspresso\core\services\notices\NoticeConverterInterface'                 => 'EventEspresso\core\services\notices\ConvertNoticesToEeErrors',
928
+			'NoticesContainerInterface'                                                    => 'EventEspresso\core\services\notices\NoticesContainerInterface',
929
+			'EventEspresso\core\services\notices\NoticesContainerInterface'                => 'EventEspresso\core\services\notices\NoticesContainer',
930
+			'EventEspresso\core\services\request\RequestInterface'                         => 'EventEspresso\core\services\request\Request',
931
+			'EventEspresso\core\services\request\ResponseInterface'                        => 'EventEspresso\core\services\request\Response',
932
+			'EventEspresso\core\domain\DomainInterface'                                    => 'EventEspresso\core\domain\Domain',
933
+		);
934
+		foreach ($aliases as $alias => $fqn) {
935
+			if (is_array($fqn)) {
936
+				foreach ($fqn as $class => $for_class) {
937
+					$this->class_cache->addAlias($class, $alias, $for_class);
938
+				}
939
+				continue;
940
+			}
941
+			$this->class_cache->addAlias($fqn, $alias);
942
+		}
943
+		if (! (defined('DOING_AJAX') && DOING_AJAX) && is_admin()) {
944
+			$this->class_cache->addAlias(
945
+				'EventEspresso\core\services\notices\ConvertNoticesToAdminNotices',
946
+				'EventEspresso\core\services\notices\NoticeConverterInterface'
947
+			);
948
+		}
949
+	}
950
+
951
+
952
+	/**
953
+	 * This is used to reset the internal map and class_loaders to their original default state at the beginning of the
954
+	 * request Primarily used by unit tests.
955
+	 */
956
+	public function reset()
957
+	{
958
+		$this->_register_core_class_loaders();
959
+		$this->_register_core_dependencies();
960
+	}
961
+
962
+
963
+	/**
964
+	 * PLZ NOTE: a better name for this method would be is_alias()
965
+	 * because it returns TRUE if the provided fully qualified name IS an alias
966
+	 * WHY?
967
+	 * Because if a class is type hinting for a concretion,
968
+	 * then why would we need to find another class to supply it?
969
+	 * ie: if a class asks for `Fully/Qualified/Namespace/SpecificClassName`,
970
+	 * then give it an instance of `Fully/Qualified/Namespace/SpecificClassName`.
971
+	 * Don't go looking for some substitute.
972
+	 * Whereas if a class is type hinting for an interface...
973
+	 * then we need to find an actual class to use.
974
+	 * So the interface IS the alias for some other FQN,
975
+	 * and we need to find out if `Fully/Qualified/Namespace/SomeInterface`
976
+	 * represents some other class.
977
+	 *
978
+	 * @deprecated 4.9.62.p
979
+	 * @param string $fqn
980
+	 * @param string $for_class
981
+	 * @return bool
982
+	 */
983
+	public function has_alias($fqn = '', $for_class = '')
984
+	{
985
+		return $this->isAlias($fqn, $for_class);
986
+	}
987
+
988
+
989
+	/**
990
+	 * PLZ NOTE: a better name for this method would be get_fqn_for_alias()
991
+	 * because it returns a FQN for provided alias if one exists, otherwise returns the original $alias
992
+	 * functions recursively, so that multiple aliases can be used to drill down to a FQN
993
+	 *  for example:
994
+	 *      if the following two entries were added to the _aliases array:
995
+	 *          array(
996
+	 *              'interface_alias'           => 'some\namespace\interface'
997
+	 *              'some\namespace\interface'  => 'some\namespace\classname'
998
+	 *          )
999
+	 *      then one could use EE_Registry::instance()->create( 'interface_alias' )
1000
+	 *      to load an instance of 'some\namespace\classname'
1001
+	 *
1002
+	 * @deprecated 4.9.62.p
1003
+	 * @param string $alias
1004
+	 * @param string $for_class
1005
+	 * @return string
1006
+	 */
1007
+	public function get_alias($alias = '', $for_class = '')
1008
+	{
1009
+		return $this->getFqnForAlias($alias, $for_class);
1010
+	}
1011 1011
 }
Please login to merge, or discard this patch.
core/libraries/payment_methods/EE_Gateway.lib.php 1 patch
Indentation   +488 added lines, -488 removed lines patch added patch discarded remove patch
@@ -23,492 +23,492 @@
 block discarded – undo
23 23
  */
24 24
 abstract class EE_Gateway
25 25
 {
26
-    /**
27
-     * a constant used as a possible value for $_currencies_supported to indicate
28
-     * that ALL currencies are supported by this gateway
29
-     */
30
-    const all_currencies_supported = 'all_currencies_supported';
31
-    /**
32
-     * Where values are 3-letter currency codes
33
-     *
34
-     * @var array
35
-     */
36
-    protected $_currencies_supported = array();
37
-    /**
38
-     * Whether or not this gateway can support SENDING a refund request (ie, initiated by
39
-     * admin in EE's wp-admin page)
40
-     *
41
-     * @var boolean
42
-     */
43
-    protected $_supports_sending_refunds = false;
44
-
45
-    /**
46
-     * Whether or not this gateway can support RECEIVING a refund request from the payment
47
-     * provider (ie, initiated by admin on the payment prover's website who sends an IPN to EE)
48
-     *
49
-     * @var boolean
50
-     */
51
-    protected $_supports_receiving_refunds = false;
52
-    /**
53
-     * Model for querying for existing payments
54
-     *
55
-     * @var EEMI_Payment
56
-     */
57
-    protected $_pay_model;
58
-
59
-    /**
60
-     * Model used for adding to the payments log
61
-     *
62
-     * @var EEMI_Payment_Log
63
-     */
64
-    protected $_pay_log;
65
-
66
-    /**
67
-     * Used for formatting some input to gateways
68
-     *
69
-     * @var EEHI_Template
70
-     */
71
-    protected $_template;
72
-
73
-    /**
74
-     * Concrete class that implements EEHI_Money, used by most gateways
75
-     *
76
-     * @var EEHI_Money
77
-     */
78
-    protected $_money;
79
-
80
-    /**
81
-     * Concrete class that implements EEHI_Line_Item, used for manipulating the line item tree
82
-     *
83
-     * @var EEHI_Line_Item
84
-     */
85
-    protected $_line_item;
86
-
87
-    /**
88
-     * @var GatewayDataFormatterInterface
89
-     */
90
-    protected $_gateway_data_formatter;
91
-
92
-    /**
93
-     * @var FormatterInterface
94
-     */
95
-    protected $_unsupported_character_remover;
96
-
97
-    /**
98
-     * The ID of the payment method using this gateway
99
-     *
100
-     * @var int
101
-     */
102
-    protected $_ID;
103
-
104
-    /**
105
-     * @var $_debug_mode boolean whether to send requests to teh sandbox site or not
106
-     */
107
-    protected $_debug_mode;
108
-    /**
109
-     *
110
-     * @var string $_name name to show for this payment method
111
-     */
112
-    protected $_name;
113
-    /**
114
-     *
115
-     * @var string name to show fir this payment method to admin-type users
116
-     */
117
-    protected $_admin_name;
118
-
119
-    /**
120
-     * @return EE_Gateway
121
-     */
122
-    public function __construct()
123
-    {
124
-    }
125
-
126
-    /**
127
-     * We don't want to serialize models as they often have circular structures
128
-     * (eg a payment model has a reference to each payment model object; and most
129
-     * payments have a transaction, most transactions have a payment method;
130
-     * most payment methods have a payment method type; most payment method types
131
-     * have a gateway. And if a gateway serializes its models, we start at the
132
-     * beginning again)
133
-     *
134
-     * @return array
135
-     */
136
-    public function __sleep()
137
-    {
138
-        $properties = get_object_vars($this);
139
-        unset($properties['_pay_model'], $properties['_pay_log']);
140
-        return array_keys($properties);
141
-    }
142
-
143
-    /**
144
-     * Returns whether or not this gateway should support SENDING refunds
145
-     * see $_supports_sending_refunds
146
-     *
147
-     * @return boolean
148
-     */
149
-    public function supports_sending_refunds()
150
-    {
151
-        return $this->_supports_sending_refunds;
152
-    }
153
-
154
-    /**
155
-     * Returns whether or not this gateway should support RECEIVING refunds
156
-     * see $_supports_receiving_refunds
157
-     *
158
-     * @return boolean
159
-     */
160
-    public function supports_receiving_refunds()
161
-    {
162
-        return $this->_supports_receiving_refunds;
163
-    }
164
-
165
-
166
-    /**
167
-     * Tries to refund the payment specified, taking into account the extra
168
-     * refund info. Note that if the gateway's _supports_sending_refunds is false,
169
-     * this should just throw an exception.
170
-     *
171
-     * @param EE_Payment $payment
172
-     * @param array      $refund_info
173
-     * @return EE_Payment for the refund
174
-     * @throws EE_Error
175
-     */
176
-    public function do_direct_refund(EE_Payment $payment, $refund_info = null)
177
-    {
178
-        return null;
179
-    }
180
-
181
-
182
-    /**
183
-     * Sets the payment method's settings so the gateway knows where to send the request
184
-     * etc
185
-     *
186
-     * @param array $settings_array
187
-     */
188
-    public function set_settings($settings_array)
189
-    {
190
-        foreach ($settings_array as $name => $value) {
191
-            $property_name = "_" . $name;
192
-            $this->{$property_name} = $value;
193
-        }
194
-    }
195
-
196
-    /**
197
-     * See this class description
198
-     *
199
-     * @param EEMI_Payment $payment_model
200
-     */
201
-    public function set_payment_model($payment_model)
202
-    {
203
-        $this->_pay_model = $payment_model;
204
-    }
205
-
206
-    /**
207
-     * See this class description
208
-     *
209
-     * @param EEMI_Payment_Log $payment_log_model
210
-     */
211
-    public function set_payment_log($payment_log_model)
212
-    {
213
-        $this->_pay_log = $payment_log_model;
214
-    }
215
-
216
-    /**
217
-     * See this class description
218
-     *
219
-     * @param EEHI_Template $template_helper
220
-     */
221
-    public function set_template_helper($template_helper)
222
-    {
223
-        $this->_template = $template_helper;
224
-    }
225
-
226
-    /**
227
-     * See this class description
228
-     *
229
-     * @param EEHI_Line_Item $line_item_helper
230
-     */
231
-    public function set_line_item_helper($line_item_helper)
232
-    {
233
-        $this->_line_item = $line_item_helper;
234
-    }
235
-
236
-    /**
237
-     * See this class description
238
-     *
239
-     * @param EEHI_Money $money_helper
240
-     */
241
-    public function set_money_helper($money_helper)
242
-    {
243
-        $this->_money = $money_helper;
244
-    }
245
-
246
-
247
-    /**
248
-     * Sets the gateway data formatter helper
249
-     *
250
-     * @param GatewayDataFormatterInterface $gateway_data_formatter
251
-     * @throws InvalidEntityException if it's not set properly
252
-     */
253
-    public function set_gateway_data_formatter(GatewayDataFormatterInterface $gateway_data_formatter)
254
-    {
255
-        if (! $gateway_data_formatter instanceof GatewayDataFormatterInterface) {
256
-            throw new InvalidEntityException(
257
-                is_object($gateway_data_formatter)
258
-                    ? get_class($gateway_data_formatter)
259
-                    : esc_html__('Not an object', 'event_espresso'),
260
-                '\\EventEspresso\\core\\services\\payment_methods\\gateways\\GatewayDataFormatterInterface'
261
-            );
262
-        }
263
-        $this->_gateway_data_formatter = $gateway_data_formatter;
264
-    }
265
-
266
-    /**
267
-     * Gets the gateway data formatter
268
-     *
269
-     * @return GatewayDataFormatterInterface
270
-     * @throws InvalidEntityException if it's not set properly
271
-     */
272
-    protected function _get_gateway_formatter()
273
-    {
274
-        if (! $this->_gateway_data_formatter instanceof GatewayDataFormatterInterface) {
275
-            throw new InvalidEntityException(
276
-                is_object($this->_gateway_data_formatter)
277
-                    ? get_class($this->_gateway_data_formatter)
278
-                    : esc_html__('Not an object', 'event_espresso'),
279
-                '\\EventEspresso\\core\\services\\payment_methods\\gateways\\GatewayDataFormatterInterface'
280
-            );
281
-        }
282
-        return $this->_gateway_data_formatter;
283
-    }
284
-
285
-
286
-    /**
287
-     * Sets the helper which will remove unsupported characters for most gateways
288
-     *
289
-     * @param FormatterInterface $formatter
290
-     * @return FormatterInterface
291
-     * @throws InvalidEntityException
292
-     */
293
-    public function set_unsupported_character_remover(FormatterInterface $formatter)
294
-    {
295
-        if (! $formatter instanceof FormatterInterface) {
296
-            throw new InvalidEntityException(
297
-                is_object($formatter)
298
-                    ? get_class($formatter)
299
-                    : esc_html__('Not an object', 'event_espresso'),
300
-                '\\EventEspresso\\core\\services\\formatters\\FormatterInterface'
301
-            );
302
-        }
303
-        $this->_unsupported_character_remover = $formatter;
304
-    }
305
-
306
-    /**
307
-     * Gets the helper which removes characters which gateways might not support, like emojis etc.
308
-     *
309
-     * @return FormatterInterface
310
-     * @throws InvalidEntityException
311
-     */
312
-    protected function _get_unsupported_character_remover()
313
-    {
314
-        if (! $this->_unsupported_character_remover instanceof FormatterInterface) {
315
-            throw new InvalidEntityException(
316
-                is_object($this->_unsupported_character_remover)
317
-                    ? get_class($this->_unsupported_character_remover)
318
-                    : esc_html__('Not an object', 'event_espresso'),
319
-                '\\EventEspresso\\core\\services\\formatters\\FormatterInterface'
320
-            );
321
-        }
322
-        return $this->_unsupported_character_remover;
323
-    }
324
-
325
-
326
-    /**
327
-     * @param $message
328
-     * @param $payment
329
-     */
330
-    public function log($message, $payment)
331
-    {
332
-        if ($payment instanceof EEI_Payment) {
333
-            $type = 'Payment';
334
-            $id = $payment->ID();
335
-        } else {
336
-            $type = 'Payment_Method';
337
-            $id = $this->_ID;
338
-        }
339
-        // only log if we're going to store it for longer than the minimum time
340
-        $reg_config = LoaderFactory::getLoader()->load('EE_Registration_Config');
341
-        if ($reg_config->gateway_log_lifespan !== '1 second') {
342
-            $this->_pay_log->gateway_log($message, $id, $type);
343
-        }
344
-    }
345
-
346
-    /**
347
-     * Formats the amount so it can generally be sent to gateways
348
-     *
349
-     * @param float $amount
350
-     * @return string
351
-     * @deprecated since 4.9.31 insetad use
352
-     *             EventEspresso\core\services\payment_methods\gateways\GatewayDataFormatter::format_currency()
353
-     */
354
-    public function format_currency($amount)
355
-    {
356
-        return $this->_get_gateway_formatter()->formatCurrency($amount);
357
-    }
358
-
359
-    /**
360
-     * Returns either an array of all the currency codes supported,
361
-     * or a string indicating they're all supported (EE_gateway::all_currencies_supported)
362
-     *
363
-     * @return mixed array or string
364
-     */
365
-    public function currencies_supported()
366
-    {
367
-        return $this->_currencies_supported;
368
-    }
369
-
370
-    /**
371
-     * Returns what a simple summing of items and taxes for this transaction. This
372
-     * can be used to determine if some more complex line items, like promotions,
373
-     * surcharges, or cancellations occurred (in which case we might want to forget
374
-     * about creating an itemized list of purchases and instead only send the total due)
375
-     *
376
-     * @param EE_Transaction $transaction
377
-     * @return float
378
-     */
379
-    protected function _sum_items_and_taxes(EE_Transaction $transaction)
380
-    {
381
-        $total_line_item = $transaction->total_line_item();
382
-        $total = 0;
383
-        foreach ($total_line_item->get_items() as $item_line_item) {
384
-            $total += max($item_line_item->total(), 0);
385
-        }
386
-        foreach ($total_line_item->tax_descendants() as $tax_line_item) {
387
-            $total += max($tax_line_item->total(), 0);
388
-        }
389
-        return $total;
390
-    }
391
-
392
-    /**
393
-     * Determines whether or not we can easily itemize the transaction using only
394
-     * items and taxes (ie, no promotions or surcharges or cancellations needed)
395
-     *
396
-     * @param EEI_Payment $payment
397
-     * @return boolean
398
-     */
399
-    protected function _can_easily_itemize_transaction_for(EEI_Payment $payment)
400
-    {
401
-        return $this->_money->compare_floats(
402
-            $this->_sum_items_and_taxes($payment->transaction()),
403
-            $payment->transaction()->total()
404
-        )
405
-               && $this->_money->compare_floats(
406
-                   $payment->amount(),
407
-                   $payment->transaction()->total()
408
-               );
409
-    }
410
-
411
-    /**
412
-     * Handles updating the transaction and any other related data based on the payment.
413
-     * You may be tempted to do this as part of do_direct_payment or handle_payment_update,
414
-     * but doing so on those functions might be too early. It's possible that the changes
415
-     * you make to teh transaction or registration or line items may just get overwritten
416
-     * at that point. Instead, you should store any info you need on the payment during those
417
-     * functions, and use that information at this step, which client code will decide
418
-     * for you when it should be called.
419
-     *
420
-     * @param EE_Payment $payment
421
-     * @return void
422
-     */
423
-    public function update_txn_based_on_payment($payment)
424
-    {
425
-        // maybe update the transaction or line items or registrations
426
-        // but most gateways don't need to do this, because they only update the payment
427
-    }
428
-
429
-    /**
430
-     * Gets the first event for this payment (it's possible that it could be for multiple)
431
-     *
432
-     * @param EEI_Payment $payment
433
-     * @return EEI_Event|null
434
-     * @deprecated since 4.9.31 instead use EEI_Payment::get_first_event()
435
-     */
436
-    protected function _get_first_event_for_payment(EEI_Payment $payment)
437
-    {
438
-        return $payment->get_first_event();
439
-    }
440
-
441
-    /**
442
-     * Gets the name of the first event for which is being paid
443
-     *
444
-     * @param EEI_Payment $payment
445
-     * @return string
446
-     * @deprecated since 4.9.31 instead use EEI_Payment::get_first_event_name()
447
-     */
448
-    protected function _get_first_event_name_for_payment(EEI_Payment $payment)
449
-    {
450
-        return $payment->get_first_event_name();
451
-    }
452
-
453
-    /**
454
-     * Gets the text to use for a gateway's line item name when this is a partial payment
455
-     *
456
-     * @deprecated since 4.9.31 instead use $this->_get_gateway_formatter()->formatPartialPaymentLineItemName($payment)
457
-     * @param EE_Payment $payment
458
-     * @return string
459
-     */
460
-    protected function _format_partial_payment_line_item_name(EEI_Payment $payment)
461
-    {
462
-        return $this->_get_gateway_formatter()->formatPartialPaymentLineItemName($payment);
463
-    }
464
-
465
-    /**
466
-     * Gets the text to use for a gateway's line item description when this is a partial payment
467
-     *
468
-     * @deprecated since 4.9.31 instead use $this->_get_gateway_formatter()->formatPartialPaymentLineItemDesc()
469
-     * @param EEI_Payment $payment
470
-     * @return string
471
-     */
472
-    protected function _format_partial_payment_line_item_desc(EEI_Payment $payment)
473
-    {
474
-        return $this->_get_gateway_formatter()->formatPartialPaymentLineItemDesc($payment);
475
-    }
476
-
477
-    /**
478
-     * Gets the name to use for a line item when sending line items to the gateway
479
-     *
480
-     * @deprecated since 4.9.31 instead use $this->_get_gateway_formatter()->formatLineItemName($line_item,$payment)
481
-     * @param EEI_Line_Item $line_item
482
-     * @param EEI_Payment   $payment
483
-     * @return string
484
-     */
485
-    protected function _format_line_item_name(EEI_Line_Item $line_item, EEI_Payment $payment)
486
-    {
487
-        return $this->_get_gateway_formatter()->formatLineItemName($line_item, $payment);
488
-    }
489
-
490
-    /**
491
-     * Gets the description to use for a line item when sending line items to the gateway
492
-     *
493
-     * @deprecated since 4.9.31 instead use $this->_get_gateway_formatter()->formatLineItemDesc($line_item, $payment))
494
-     * @param EEI_Line_Item $line_item
495
-     * @param EEI_Payment   $payment
496
-     * @return string
497
-     */
498
-    protected function _format_line_item_desc(EEI_Line_Item $line_item, EEI_Payment $payment)
499
-    {
500
-        return $this->_get_gateway_formatter()->formatLineItemDesc($line_item, $payment);
501
-    }
502
-
503
-    /**
504
-     * Gets the order description that should generlly be sent to gateways
505
-     *
506
-     * @deprecated since 4.9.31 instead use $this->_get_gateway_formatter()->formatOrderDescription($payment)
507
-     * @param EEI_Payment $payment
508
-     * @return type
509
-     */
510
-    protected function _format_order_description(EEI_Payment $payment)
511
-    {
512
-        return $this->_get_gateway_formatter()->formatOrderDescription($payment);
513
-    }
26
+	/**
27
+	 * a constant used as a possible value for $_currencies_supported to indicate
28
+	 * that ALL currencies are supported by this gateway
29
+	 */
30
+	const all_currencies_supported = 'all_currencies_supported';
31
+	/**
32
+	 * Where values are 3-letter currency codes
33
+	 *
34
+	 * @var array
35
+	 */
36
+	protected $_currencies_supported = array();
37
+	/**
38
+	 * Whether or not this gateway can support SENDING a refund request (ie, initiated by
39
+	 * admin in EE's wp-admin page)
40
+	 *
41
+	 * @var boolean
42
+	 */
43
+	protected $_supports_sending_refunds = false;
44
+
45
+	/**
46
+	 * Whether or not this gateway can support RECEIVING a refund request from the payment
47
+	 * provider (ie, initiated by admin on the payment prover's website who sends an IPN to EE)
48
+	 *
49
+	 * @var boolean
50
+	 */
51
+	protected $_supports_receiving_refunds = false;
52
+	/**
53
+	 * Model for querying for existing payments
54
+	 *
55
+	 * @var EEMI_Payment
56
+	 */
57
+	protected $_pay_model;
58
+
59
+	/**
60
+	 * Model used for adding to the payments log
61
+	 *
62
+	 * @var EEMI_Payment_Log
63
+	 */
64
+	protected $_pay_log;
65
+
66
+	/**
67
+	 * Used for formatting some input to gateways
68
+	 *
69
+	 * @var EEHI_Template
70
+	 */
71
+	protected $_template;
72
+
73
+	/**
74
+	 * Concrete class that implements EEHI_Money, used by most gateways
75
+	 *
76
+	 * @var EEHI_Money
77
+	 */
78
+	protected $_money;
79
+
80
+	/**
81
+	 * Concrete class that implements EEHI_Line_Item, used for manipulating the line item tree
82
+	 *
83
+	 * @var EEHI_Line_Item
84
+	 */
85
+	protected $_line_item;
86
+
87
+	/**
88
+	 * @var GatewayDataFormatterInterface
89
+	 */
90
+	protected $_gateway_data_formatter;
91
+
92
+	/**
93
+	 * @var FormatterInterface
94
+	 */
95
+	protected $_unsupported_character_remover;
96
+
97
+	/**
98
+	 * The ID of the payment method using this gateway
99
+	 *
100
+	 * @var int
101
+	 */
102
+	protected $_ID;
103
+
104
+	/**
105
+	 * @var $_debug_mode boolean whether to send requests to teh sandbox site or not
106
+	 */
107
+	protected $_debug_mode;
108
+	/**
109
+	 *
110
+	 * @var string $_name name to show for this payment method
111
+	 */
112
+	protected $_name;
113
+	/**
114
+	 *
115
+	 * @var string name to show fir this payment method to admin-type users
116
+	 */
117
+	protected $_admin_name;
118
+
119
+	/**
120
+	 * @return EE_Gateway
121
+	 */
122
+	public function __construct()
123
+	{
124
+	}
125
+
126
+	/**
127
+	 * We don't want to serialize models as they often have circular structures
128
+	 * (eg a payment model has a reference to each payment model object; and most
129
+	 * payments have a transaction, most transactions have a payment method;
130
+	 * most payment methods have a payment method type; most payment method types
131
+	 * have a gateway. And if a gateway serializes its models, we start at the
132
+	 * beginning again)
133
+	 *
134
+	 * @return array
135
+	 */
136
+	public function __sleep()
137
+	{
138
+		$properties = get_object_vars($this);
139
+		unset($properties['_pay_model'], $properties['_pay_log']);
140
+		return array_keys($properties);
141
+	}
142
+
143
+	/**
144
+	 * Returns whether or not this gateway should support SENDING refunds
145
+	 * see $_supports_sending_refunds
146
+	 *
147
+	 * @return boolean
148
+	 */
149
+	public function supports_sending_refunds()
150
+	{
151
+		return $this->_supports_sending_refunds;
152
+	}
153
+
154
+	/**
155
+	 * Returns whether or not this gateway should support RECEIVING refunds
156
+	 * see $_supports_receiving_refunds
157
+	 *
158
+	 * @return boolean
159
+	 */
160
+	public function supports_receiving_refunds()
161
+	{
162
+		return $this->_supports_receiving_refunds;
163
+	}
164
+
165
+
166
+	/**
167
+	 * Tries to refund the payment specified, taking into account the extra
168
+	 * refund info. Note that if the gateway's _supports_sending_refunds is false,
169
+	 * this should just throw an exception.
170
+	 *
171
+	 * @param EE_Payment $payment
172
+	 * @param array      $refund_info
173
+	 * @return EE_Payment for the refund
174
+	 * @throws EE_Error
175
+	 */
176
+	public function do_direct_refund(EE_Payment $payment, $refund_info = null)
177
+	{
178
+		return null;
179
+	}
180
+
181
+
182
+	/**
183
+	 * Sets the payment method's settings so the gateway knows where to send the request
184
+	 * etc
185
+	 *
186
+	 * @param array $settings_array
187
+	 */
188
+	public function set_settings($settings_array)
189
+	{
190
+		foreach ($settings_array as $name => $value) {
191
+			$property_name = "_" . $name;
192
+			$this->{$property_name} = $value;
193
+		}
194
+	}
195
+
196
+	/**
197
+	 * See this class description
198
+	 *
199
+	 * @param EEMI_Payment $payment_model
200
+	 */
201
+	public function set_payment_model($payment_model)
202
+	{
203
+		$this->_pay_model = $payment_model;
204
+	}
205
+
206
+	/**
207
+	 * See this class description
208
+	 *
209
+	 * @param EEMI_Payment_Log $payment_log_model
210
+	 */
211
+	public function set_payment_log($payment_log_model)
212
+	{
213
+		$this->_pay_log = $payment_log_model;
214
+	}
215
+
216
+	/**
217
+	 * See this class description
218
+	 *
219
+	 * @param EEHI_Template $template_helper
220
+	 */
221
+	public function set_template_helper($template_helper)
222
+	{
223
+		$this->_template = $template_helper;
224
+	}
225
+
226
+	/**
227
+	 * See this class description
228
+	 *
229
+	 * @param EEHI_Line_Item $line_item_helper
230
+	 */
231
+	public function set_line_item_helper($line_item_helper)
232
+	{
233
+		$this->_line_item = $line_item_helper;
234
+	}
235
+
236
+	/**
237
+	 * See this class description
238
+	 *
239
+	 * @param EEHI_Money $money_helper
240
+	 */
241
+	public function set_money_helper($money_helper)
242
+	{
243
+		$this->_money = $money_helper;
244
+	}
245
+
246
+
247
+	/**
248
+	 * Sets the gateway data formatter helper
249
+	 *
250
+	 * @param GatewayDataFormatterInterface $gateway_data_formatter
251
+	 * @throws InvalidEntityException if it's not set properly
252
+	 */
253
+	public function set_gateway_data_formatter(GatewayDataFormatterInterface $gateway_data_formatter)
254
+	{
255
+		if (! $gateway_data_formatter instanceof GatewayDataFormatterInterface) {
256
+			throw new InvalidEntityException(
257
+				is_object($gateway_data_formatter)
258
+					? get_class($gateway_data_formatter)
259
+					: esc_html__('Not an object', 'event_espresso'),
260
+				'\\EventEspresso\\core\\services\\payment_methods\\gateways\\GatewayDataFormatterInterface'
261
+			);
262
+		}
263
+		$this->_gateway_data_formatter = $gateway_data_formatter;
264
+	}
265
+
266
+	/**
267
+	 * Gets the gateway data formatter
268
+	 *
269
+	 * @return GatewayDataFormatterInterface
270
+	 * @throws InvalidEntityException if it's not set properly
271
+	 */
272
+	protected function _get_gateway_formatter()
273
+	{
274
+		if (! $this->_gateway_data_formatter instanceof GatewayDataFormatterInterface) {
275
+			throw new InvalidEntityException(
276
+				is_object($this->_gateway_data_formatter)
277
+					? get_class($this->_gateway_data_formatter)
278
+					: esc_html__('Not an object', 'event_espresso'),
279
+				'\\EventEspresso\\core\\services\\payment_methods\\gateways\\GatewayDataFormatterInterface'
280
+			);
281
+		}
282
+		return $this->_gateway_data_formatter;
283
+	}
284
+
285
+
286
+	/**
287
+	 * Sets the helper which will remove unsupported characters for most gateways
288
+	 *
289
+	 * @param FormatterInterface $formatter
290
+	 * @return FormatterInterface
291
+	 * @throws InvalidEntityException
292
+	 */
293
+	public function set_unsupported_character_remover(FormatterInterface $formatter)
294
+	{
295
+		if (! $formatter instanceof FormatterInterface) {
296
+			throw new InvalidEntityException(
297
+				is_object($formatter)
298
+					? get_class($formatter)
299
+					: esc_html__('Not an object', 'event_espresso'),
300
+				'\\EventEspresso\\core\\services\\formatters\\FormatterInterface'
301
+			);
302
+		}
303
+		$this->_unsupported_character_remover = $formatter;
304
+	}
305
+
306
+	/**
307
+	 * Gets the helper which removes characters which gateways might not support, like emojis etc.
308
+	 *
309
+	 * @return FormatterInterface
310
+	 * @throws InvalidEntityException
311
+	 */
312
+	protected function _get_unsupported_character_remover()
313
+	{
314
+		if (! $this->_unsupported_character_remover instanceof FormatterInterface) {
315
+			throw new InvalidEntityException(
316
+				is_object($this->_unsupported_character_remover)
317
+					? get_class($this->_unsupported_character_remover)
318
+					: esc_html__('Not an object', 'event_espresso'),
319
+				'\\EventEspresso\\core\\services\\formatters\\FormatterInterface'
320
+			);
321
+		}
322
+		return $this->_unsupported_character_remover;
323
+	}
324
+
325
+
326
+	/**
327
+	 * @param $message
328
+	 * @param $payment
329
+	 */
330
+	public function log($message, $payment)
331
+	{
332
+		if ($payment instanceof EEI_Payment) {
333
+			$type = 'Payment';
334
+			$id = $payment->ID();
335
+		} else {
336
+			$type = 'Payment_Method';
337
+			$id = $this->_ID;
338
+		}
339
+		// only log if we're going to store it for longer than the minimum time
340
+		$reg_config = LoaderFactory::getLoader()->load('EE_Registration_Config');
341
+		if ($reg_config->gateway_log_lifespan !== '1 second') {
342
+			$this->_pay_log->gateway_log($message, $id, $type);
343
+		}
344
+	}
345
+
346
+	/**
347
+	 * Formats the amount so it can generally be sent to gateways
348
+	 *
349
+	 * @param float $amount
350
+	 * @return string
351
+	 * @deprecated since 4.9.31 insetad use
352
+	 *             EventEspresso\core\services\payment_methods\gateways\GatewayDataFormatter::format_currency()
353
+	 */
354
+	public function format_currency($amount)
355
+	{
356
+		return $this->_get_gateway_formatter()->formatCurrency($amount);
357
+	}
358
+
359
+	/**
360
+	 * Returns either an array of all the currency codes supported,
361
+	 * or a string indicating they're all supported (EE_gateway::all_currencies_supported)
362
+	 *
363
+	 * @return mixed array or string
364
+	 */
365
+	public function currencies_supported()
366
+	{
367
+		return $this->_currencies_supported;
368
+	}
369
+
370
+	/**
371
+	 * Returns what a simple summing of items and taxes for this transaction. This
372
+	 * can be used to determine if some more complex line items, like promotions,
373
+	 * surcharges, or cancellations occurred (in which case we might want to forget
374
+	 * about creating an itemized list of purchases and instead only send the total due)
375
+	 *
376
+	 * @param EE_Transaction $transaction
377
+	 * @return float
378
+	 */
379
+	protected function _sum_items_and_taxes(EE_Transaction $transaction)
380
+	{
381
+		$total_line_item = $transaction->total_line_item();
382
+		$total = 0;
383
+		foreach ($total_line_item->get_items() as $item_line_item) {
384
+			$total += max($item_line_item->total(), 0);
385
+		}
386
+		foreach ($total_line_item->tax_descendants() as $tax_line_item) {
387
+			$total += max($tax_line_item->total(), 0);
388
+		}
389
+		return $total;
390
+	}
391
+
392
+	/**
393
+	 * Determines whether or not we can easily itemize the transaction using only
394
+	 * items and taxes (ie, no promotions or surcharges or cancellations needed)
395
+	 *
396
+	 * @param EEI_Payment $payment
397
+	 * @return boolean
398
+	 */
399
+	protected function _can_easily_itemize_transaction_for(EEI_Payment $payment)
400
+	{
401
+		return $this->_money->compare_floats(
402
+			$this->_sum_items_and_taxes($payment->transaction()),
403
+			$payment->transaction()->total()
404
+		)
405
+			   && $this->_money->compare_floats(
406
+				   $payment->amount(),
407
+				   $payment->transaction()->total()
408
+			   );
409
+	}
410
+
411
+	/**
412
+	 * Handles updating the transaction and any other related data based on the payment.
413
+	 * You may be tempted to do this as part of do_direct_payment or handle_payment_update,
414
+	 * but doing so on those functions might be too early. It's possible that the changes
415
+	 * you make to teh transaction or registration or line items may just get overwritten
416
+	 * at that point. Instead, you should store any info you need on the payment during those
417
+	 * functions, and use that information at this step, which client code will decide
418
+	 * for you when it should be called.
419
+	 *
420
+	 * @param EE_Payment $payment
421
+	 * @return void
422
+	 */
423
+	public function update_txn_based_on_payment($payment)
424
+	{
425
+		// maybe update the transaction or line items or registrations
426
+		// but most gateways don't need to do this, because they only update the payment
427
+	}
428
+
429
+	/**
430
+	 * Gets the first event for this payment (it's possible that it could be for multiple)
431
+	 *
432
+	 * @param EEI_Payment $payment
433
+	 * @return EEI_Event|null
434
+	 * @deprecated since 4.9.31 instead use EEI_Payment::get_first_event()
435
+	 */
436
+	protected function _get_first_event_for_payment(EEI_Payment $payment)
437
+	{
438
+		return $payment->get_first_event();
439
+	}
440
+
441
+	/**
442
+	 * Gets the name of the first event for which is being paid
443
+	 *
444
+	 * @param EEI_Payment $payment
445
+	 * @return string
446
+	 * @deprecated since 4.9.31 instead use EEI_Payment::get_first_event_name()
447
+	 */
448
+	protected function _get_first_event_name_for_payment(EEI_Payment $payment)
449
+	{
450
+		return $payment->get_first_event_name();
451
+	}
452
+
453
+	/**
454
+	 * Gets the text to use for a gateway's line item name when this is a partial payment
455
+	 *
456
+	 * @deprecated since 4.9.31 instead use $this->_get_gateway_formatter()->formatPartialPaymentLineItemName($payment)
457
+	 * @param EE_Payment $payment
458
+	 * @return string
459
+	 */
460
+	protected function _format_partial_payment_line_item_name(EEI_Payment $payment)
461
+	{
462
+		return $this->_get_gateway_formatter()->formatPartialPaymentLineItemName($payment);
463
+	}
464
+
465
+	/**
466
+	 * Gets the text to use for a gateway's line item description when this is a partial payment
467
+	 *
468
+	 * @deprecated since 4.9.31 instead use $this->_get_gateway_formatter()->formatPartialPaymentLineItemDesc()
469
+	 * @param EEI_Payment $payment
470
+	 * @return string
471
+	 */
472
+	protected function _format_partial_payment_line_item_desc(EEI_Payment $payment)
473
+	{
474
+		return $this->_get_gateway_formatter()->formatPartialPaymentLineItemDesc($payment);
475
+	}
476
+
477
+	/**
478
+	 * Gets the name to use for a line item when sending line items to the gateway
479
+	 *
480
+	 * @deprecated since 4.9.31 instead use $this->_get_gateway_formatter()->formatLineItemName($line_item,$payment)
481
+	 * @param EEI_Line_Item $line_item
482
+	 * @param EEI_Payment   $payment
483
+	 * @return string
484
+	 */
485
+	protected function _format_line_item_name(EEI_Line_Item $line_item, EEI_Payment $payment)
486
+	{
487
+		return $this->_get_gateway_formatter()->formatLineItemName($line_item, $payment);
488
+	}
489
+
490
+	/**
491
+	 * Gets the description to use for a line item when sending line items to the gateway
492
+	 *
493
+	 * @deprecated since 4.9.31 instead use $this->_get_gateway_formatter()->formatLineItemDesc($line_item, $payment))
494
+	 * @param EEI_Line_Item $line_item
495
+	 * @param EEI_Payment   $payment
496
+	 * @return string
497
+	 */
498
+	protected function _format_line_item_desc(EEI_Line_Item $line_item, EEI_Payment $payment)
499
+	{
500
+		return $this->_get_gateway_formatter()->formatLineItemDesc($line_item, $payment);
501
+	}
502
+
503
+	/**
504
+	 * Gets the order description that should generlly be sent to gateways
505
+	 *
506
+	 * @deprecated since 4.9.31 instead use $this->_get_gateway_formatter()->formatOrderDescription($payment)
507
+	 * @param EEI_Payment $payment
508
+	 * @return type
509
+	 */
510
+	protected function _format_order_description(EEI_Payment $payment)
511
+	{
512
+		return $this->_get_gateway_formatter()->formatOrderDescription($payment);
513
+	}
514 514
 }
Please login to merge, or discard this patch.
admin_pages/payments/Payments_Admin_Page.core.php 2 patches
Indentation   +1121 added lines, -1121 removed lines patch added patch discarded remove patch
@@ -14,1125 +14,1125 @@
 block discarded – undo
14 14
 class Payments_Admin_Page extends EE_Admin_Page
15 15
 {
16 16
 
17
-    /**
18
-     * Variables used for when we're re-sorting the logs results, in case
19
-     * we needed to do two queries and we need to resort
20
-     *
21
-     * @var string
22
-     */
23
-    private $_sort_logs_again_direction;
24
-
25
-
26
-    /**
27
-     * @Constructor
28
-     * @access public
29
-     * @param bool $routing indicate whether we want to just load the object and handle routing or just load the object.
30
-     * @return \Payments_Admin_Page
31
-     */
32
-    public function __construct($routing = true)
33
-    {
34
-        parent::__construct($routing);
35
-    }
36
-
37
-
38
-    protected function _init_page_props()
39
-    {
40
-        $this->page_slug = EE_PAYMENTS_PG_SLUG;
41
-        $this->page_label = __('Payment Methods', 'event_espresso');
42
-        $this->_admin_base_url = EE_PAYMENTS_ADMIN_URL;
43
-        $this->_admin_base_path = EE_PAYMENTS_ADMIN;
44
-    }
45
-
46
-
47
-    protected function _ajax_hooks()
48
-    {
49
-        // todo: all hooks for ajax goes here.
50
-    }
51
-
52
-
53
-    protected function _define_page_props()
54
-    {
55
-        $this->_admin_page_title = $this->page_label;
56
-        $this->_labels = array(
57
-            'publishbox' => __('Update Settings', 'event_espresso'),
58
-        );
59
-    }
60
-
61
-
62
-    protected function _set_page_routes()
63
-    {
64
-        /**
65
-         * note that with payment method capabilities, although we've implemented
66
-         * capability mapping which will be used for accessing payment methods owned by
67
-         * other users.  This is not fully implemented yet in the payment method ui.
68
-         * Currently only the "plural" caps are in active use.
69
-         * When cap mapping is implemented, some routes will need to use the singular form of
70
-         * capability method and also include the $id of the payment method for the route.
71
-         **/
72
-        $this->_page_routes = array(
73
-            'default'                   => array(
74
-                'func'       => '_payment_methods_list',
75
-                'capability' => 'ee_edit_payment_methods',
76
-            ),
77
-            'payment_settings'          => array(
78
-                'func'       => '_payment_settings',
79
-                'capability' => 'ee_manage_gateways',
80
-            ),
81
-            'activate_payment_method'   => array(
82
-                'func'       => '_activate_payment_method',
83
-                'noheader'   => true,
84
-                'capability' => 'ee_edit_payment_methods',
85
-            ),
86
-            'deactivate_payment_method' => array(
87
-                'func'       => '_deactivate_payment_method',
88
-                'noheader'   => true,
89
-                'capability' => 'ee_delete_payment_methods',
90
-            ),
91
-            'update_payment_method'     => array(
92
-                'func'               => '_update_payment_method',
93
-                'noheader'           => true,
94
-                'headers_sent_route' => 'default',
95
-                'capability'         => 'ee_edit_payment_methods',
96
-            ),
97
-            'update_payment_settings'   => array(
98
-                'func'       => '_update_payment_settings',
99
-                'noheader'   => true,
100
-                'capability' => 'ee_manage_gateways',
101
-            ),
102
-            'payment_log'               => array(
103
-                'func'       => '_payment_log_overview_list_table',
104
-                'capability' => 'ee_read_payment_methods',
105
-            ),
106
-            'payment_log_details'       => array(
107
-                'func'       => '_payment_log_details',
108
-                'capability' => 'ee_read_payment_methods',
109
-            ),
110
-        );
111
-    }
112
-
113
-
114
-    protected function _set_page_config()
115
-    {
116
-        $payment_method_list_config = array(
117
-            'nav'           => array(
118
-                'label' => __('Payment Methods', 'event_espresso'),
119
-                'order' => 10,
120
-            ),
121
-            'metaboxes'     => $this->_default_espresso_metaboxes,
122
-            'help_tabs'     => array_merge(
123
-                array(
124
-                    'payment_methods_overview_help_tab' => array(
125
-                        'title'    => __('Payment Methods Overview', 'event_espresso'),
126
-                        'filename' => 'payment_methods_overview',
127
-                    ),
128
-                ),
129
-                $this->_add_payment_method_help_tabs()
130
-            ),
131
-            'help_tour'     => array('Payment_Methods_Selection_Help_Tour'),
132
-            'require_nonce' => false,
133
-        );
134
-        $this->_page_config = array(
135
-            'default'          => $payment_method_list_config,
136
-            'payment_settings' => array(
137
-                'nav'           => array(
138
-                    'label' => __('Settings', 'event_espresso'),
139
-                    'order' => 20,
140
-                ),
141
-                'help_tabs'     => array(
142
-                    'payment_methods_settings_help_tab' => array(
143
-                        'title'    => __('Payment Method Settings', 'event_espresso'),
144
-                        'filename' => 'payment_methods_settings',
145
-                    ),
146
-                ),
147
-                // 'help_tour' => array( 'Payment_Methods_Settings_Help_Tour' ),
148
-                'metaboxes'     => array_merge($this->_default_espresso_metaboxes, array('_publish_post_box')),
149
-                'require_nonce' => false,
150
-            ),
151
-            'payment_log'      => array(
152
-                'nav'           => array(
153
-                    'label' => __("Logs", 'event_espresso'),
154
-                    'order' => 30,
155
-                ),
156
-                'list_table'    => 'Payment_Log_Admin_List_Table',
157
-                'metaboxes'     => $this->_default_espresso_metaboxes,
158
-                'require_nonce' => false,
159
-            ),
160
-        );
161
-    }
162
-
163
-
164
-    /**
165
-     * @return array
166
-     */
167
-    protected function _add_payment_method_help_tabs()
168
-    {
169
-        EE_Registry::instance()->load_lib('Payment_Method_Manager');
170
-        $payment_method_types = EE_Payment_Method_Manager::instance()->payment_method_types();
171
-        $all_pmt_help_tabs_config = array();
172
-        foreach ($payment_method_types as $payment_method_type) {
173
-            if (! EE_Registry::instance()->CAP->current_user_can(
174
-                $payment_method_type->cap_name(),
175
-                'specific_payment_method_type_access'
176
-            )
177
-            ) {
178
-                continue;
179
-            }
180
-            foreach ($payment_method_type->help_tabs_config() as $help_tab_name => $config) {
181
-                $template_args = isset($config['template_args']) ? $config['template_args'] : array();
182
-                $template_args['admin_page_obj'] = $this;
183
-                $all_pmt_help_tabs_config[ $help_tab_name ] = array(
184
-                    'title'   => $config['title'],
185
-                    'content' => EEH_Template::display_template(
186
-                        $payment_method_type->file_folder() . 'help_tabs' . DS . $config['filename'] . '.help_tab.php',
187
-                        $template_args,
188
-                        true
189
-                    ),
190
-                );
191
-            }
192
-        }
193
-        return $all_pmt_help_tabs_config;
194
-    }
195
-
196
-
197
-    // none of the below group are currently used for Gateway Settings
198
-    protected function _add_screen_options()
199
-    {
200
-    }
201
-
202
-
203
-    protected function _add_feature_pointers()
204
-    {
205
-    }
206
-
207
-
208
-    public function admin_init()
209
-    {
210
-    }
211
-
212
-
213
-    public function admin_notices()
214
-    {
215
-    }
216
-
217
-
218
-    public function admin_footer_scripts()
219
-    {
220
-    }
221
-
222
-
223
-    public function load_scripts_styles()
224
-    {
225
-        wp_enqueue_script('ee_admin_js');
226
-        wp_enqueue_script('ee-text-links');
227
-        wp_enqueue_script(
228
-            'espresso_payments',
229
-            EE_PAYMENTS_ASSETS_URL . 'espresso_payments_admin.js',
230
-            array('espresso-ui-theme', 'ee-datepicker'),
231
-            EVENT_ESPRESSO_VERSION,
232
-            true
233
-        );
234
-    }
235
-
236
-
237
-    public function load_scripts_styles_default()
238
-    {
239
-        // styles
240
-        wp_register_style(
241
-            'espresso_payments',
242
-            EE_PAYMENTS_ASSETS_URL . 'ee-payments.css',
243
-            array(),
244
-            EVENT_ESPRESSO_VERSION
245
-        );
246
-        wp_enqueue_style('espresso_payments');
247
-        wp_enqueue_style('ee-text-links');
248
-        // scripts
249
-    }
250
-
251
-
252
-    protected function _payment_methods_list()
253
-    {
254
-        /**
255
-         * first let's ensure payment methods have been setup. We do this here because when people activate a
256
-         * payment method for the first time (as an addon), it may not setup its capabilities or get registered correctly due
257
-         * to the loading process.  However, people MUST setup the details for the payment method so its safe to do a
258
-         * recheck here.
259
-         */
260
-        EE_Registry::instance()->load_lib('Payment_Method_Manager');
261
-        EEM_Payment_Method::instance()->verify_button_urls();
262
-        // setup tabs, one for each payment method type
263
-        $tabs = array();
264
-        $payment_methods = array();
265
-        foreach (EE_Payment_Method_Manager::instance()->payment_method_types() as $pmt_obj) {
266
-            // we don't want to show admin-only PMTs for now
267
-            if ($pmt_obj instanceof EE_PMT_Admin_Only) {
268
-                continue;
269
-            }
270
-            // check access
271
-            if (! EE_Registry::instance()->CAP->current_user_can(
272
-                $pmt_obj->cap_name(),
273
-                'specific_payment_method_type_access'
274
-            )
275
-            ) {
276
-                continue;
277
-            }
278
-            // check for any active pms of that type
279
-            $payment_method = EEM_Payment_Method::instance()->get_one_of_type($pmt_obj->system_name());
280
-            if (! $payment_method instanceof EE_Payment_Method) {
281
-                $payment_method = EE_Payment_Method::new_instance(
282
-                    array(
283
-                        'PMD_slug'       => sanitize_key($pmt_obj->system_name()),
284
-                        'PMD_type'       => $pmt_obj->system_name(),
285
-                        'PMD_name'       => $pmt_obj->pretty_name(),
286
-                        'PMD_admin_name' => $pmt_obj->pretty_name(),
287
-                    )
288
-                );
289
-            }
290
-            $payment_methods[ $payment_method->slug() ] = $payment_method;
291
-        }
292
-        $payment_methods = apply_filters(
293
-            'FHEE__Payments_Admin_Page___payment_methods_list__payment_methods',
294
-            $payment_methods
295
-        );
296
-        foreach ($payment_methods as $payment_method) {
297
-            if ($payment_method instanceof EE_Payment_Method) {
298
-                add_meta_box(
299
-                    // html id
300
-                    'espresso_' . $payment_method->slug() . '_payment_settings',
301
-                    // title
302
-                    sprintf(__('%s Settings', 'event_espresso'), $payment_method->admin_name()),
303
-                    // callback
304
-                    array($this, 'payment_method_settings_meta_box'),
305
-                    // post type
306
-                    null,
307
-                    // context
308
-                    'normal',
309
-                    // priority
310
-                    'default',
311
-                    // callback args
312
-                    array('payment_method' => $payment_method)
313
-                );
314
-                // setup for tabbed content
315
-                $tabs[ $payment_method->slug() ] = array(
316
-                    'label' => $payment_method->admin_name(),
317
-                    'class' => $payment_method->active() ? 'gateway-active' : '',
318
-                    'href'  => 'espresso_' . $payment_method->slug() . '_payment_settings',
319
-                    'title' => __('Modify this Payment Method', 'event_espresso'),
320
-                    'slug'  => $payment_method->slug(),
321
-                );
322
-            }
323
-        }
324
-        $this->_template_args['admin_page_header'] = EEH_Tabbed_Content::tab_text_links(
325
-            $tabs,
326
-            'payment_method_links',
327
-            '|',
328
-            $this->_get_active_payment_method_slug()
329
-        );
330
-        $this->display_admin_page_with_sidebar();
331
-    }
332
-
333
-
334
-    /**
335
-     *   _get_active_payment_method_slug
336
-     *
337
-     * @return string
338
-     */
339
-    protected function _get_active_payment_method_slug()
340
-    {
341
-        $payment_method_slug = false;
342
-        // decide which payment method tab to open first, as dictated by the request's 'payment_method'
343
-        if (isset($this->_req_data['payment_method'])) {
344
-            // if they provided the current payment method, use it
345
-            $payment_method_slug = sanitize_key($this->_req_data['payment_method']);
346
-        }
347
-        $payment_method = EEM_Payment_Method::instance()->get_one(array(array('PMD_slug' => $payment_method_slug)));
348
-        // if that didn't work or wasn't provided, find another way to select the current pm
349
-        if (! $this->_verify_payment_method($payment_method)) {
350
-            // like, looking for an active one
351
-            $payment_method = EEM_Payment_Method::instance()->get_one_active('CART');
352
-            // test that one as well
353
-            if ($this->_verify_payment_method($payment_method)) {
354
-                $payment_method_slug = $payment_method->slug();
355
-            } else {
356
-                $payment_method_slug = 'paypal_standard';
357
-            }
358
-        }
359
-        return $payment_method_slug;
360
-    }
361
-
362
-
363
-    /**
364
-     *    payment_method_settings_meta_box
365
-     *    returns TRUE if the passed payment method is properly constructed and the logged in user has the correct
366
-     *    capabilities to access it
367
-     *
368
-     * @param \EE_Payment_Method $payment_method
369
-     * @return boolean
370
-     */
371
-    protected function _verify_payment_method($payment_method)
372
-    {
373
-        if ($payment_method instanceof EE_Payment_Method && $payment_method->type_obj() instanceof EE_PMT_Base
374
-            && EE_Registry::instance()->CAP->current_user_can(
375
-                $payment_method->type_obj()->cap_name(),
376
-                'specific_payment_method_type_access'
377
-            )
378
-        ) {
379
-            return true;
380
-        }
381
-        return false;
382
-    }
383
-
384
-
385
-    /**
386
-     *    payment_method_settings_meta_box
387
-     *
388
-     * @param NULL  $post_obj_which_is_null is an object containing the current post (as a $post object)
389
-     * @param array $metabox                is an array with metabox id, title, callback, and args elements. the value
390
-     *                                      at 'args' has key 'payment_method', as set within _payment_methods_list
391
-     * @return string
392
-     * @throws EE_Error
393
-     */
394
-    public function payment_method_settings_meta_box($post_obj_which_is_null, $metabox)
395
-    {
396
-        $payment_method = isset($metabox['args'], $metabox['args']['payment_method'])
397
-            ? $metabox['args']['payment_method'] : null;
398
-        if (! $payment_method instanceof EE_Payment_Method) {
399
-            throw new EE_Error(
400
-                sprintf(
401
-                    __(
402
-                        'Payment method metabox setup incorrectly. No Payment method object was supplied',
403
-                        'event_espresso'
404
-                    )
405
-                )
406
-            );
407
-        }
408
-        $payment_method_scopes = $payment_method->active();
409
-        // if the payment method really exists show its form, otherwise the activation template
410
-        if ($payment_method->ID() && ! empty($payment_method_scopes)) {
411
-            $form = $this->_generate_payment_method_settings_form($payment_method);
412
-            if ($form->form_data_present_in($this->_req_data)) {
413
-                $form->receive_form_submission($this->_req_data);
414
-            }
415
-            echo $form->form_open() . $form->get_html_and_js() . $form->form_close();
416
-        } else {
417
-            echo $this->_activate_payment_method_button($payment_method)->get_html_and_js();
418
-        }
419
-    }
420
-
421
-
422
-    /**
423
-     * Gets the form for all the settings related to this payment method type
424
-     *
425
-     * @access protected
426
-     * @param \EE_Payment_Method $payment_method
427
-     * @return \EE_Form_Section_Proper
428
-     */
429
-    protected function _generate_payment_method_settings_form(EE_Payment_Method $payment_method)
430
-    {
431
-        if (! $payment_method instanceof EE_Payment_Method) {
432
-            return new EE_Form_Section_Proper();
433
-        }
434
-        return new EE_Form_Section_Proper(
435
-            array(
436
-                'name'            => $payment_method->slug() . '_settings_form',
437
-                'html_id'         => $payment_method->slug() . '_settings_form',
438
-                'action'          => EE_Admin_Page::add_query_args_and_nonce(
439
-                    array(
440
-                        'action'         => 'update_payment_method',
441
-                        'payment_method' => $payment_method->slug(),
442
-                    ),
443
-                    EE_PAYMENTS_ADMIN_URL
444
-                ),
445
-                'layout_strategy' => new EE_Admin_Two_Column_Layout(),
446
-                'subsections'     => apply_filters(
447
-                    'FHEE__Payments_Admin_Page___generate_payment_method_settings_form__form_subsections',
448
-                    array(
449
-                        'pci_dss_compliance'      => $this->_pci_dss_compliance($payment_method),
450
-                        'currency_support'        => $this->_currency_support($payment_method),
451
-                        'payment_method_settings' => $this->_payment_method_settings($payment_method),
452
-                        'update'                  => $this->_update_payment_method_button($payment_method),
453
-                        'deactivate'              => $this->_deactivate_payment_method_button($payment_method),
454
-                        'fine_print'              => $this->_fine_print(),
455
-                    ),
456
-                    $payment_method
457
-                ),
458
-            )
459
-        );
460
-    }
461
-
462
-
463
-    /**
464
-     * _pci_dss_compliance
465
-     *
466
-     * @access protected
467
-     * @param \EE_Payment_Method $payment_method
468
-     * @return \EE_Form_Section_Proper
469
-     */
470
-    protected function _pci_dss_compliance(EE_Payment_Method $payment_method)
471
-    {
472
-        if ($payment_method->type_obj()->requires_https()) {
473
-            return new EE_Form_Section_HTML(
474
-                EEH_HTML::tr(
475
-                    EEH_HTML::th(
476
-                        EEH_HTML::label(
477
-                            EEH_HTML::strong(__('IMPORTANT', 'event_espresso'), '', 'important-notice')
478
-                        )
479
-                    ) .
480
-                    EEH_HTML::td(
481
-                        EEH_HTML::strong(
482
-                            __(
483
-                                'You are responsible for your own website security and Payment Card Industry Data Security Standards (PCI DSS) compliance.',
484
-                                'event_espresso'
485
-                            )
486
-                        )
487
-                        .
488
-                        EEH_HTML::br()
489
-                        .
490
-                        __('Learn more about ', 'event_espresso')
491
-                        . EEH_HTML::link(
492
-                            'https://www.pcisecuritystandards.org/merchants/index.php',
493
-                            __('PCI DSS compliance', 'event_espresso')
494
-                        )
495
-                    )
496
-                )
497
-            );
498
-        } else {
499
-            return new EE_Form_Section_HTML('');
500
-        }
501
-    }
502
-
503
-
504
-    /**
505
-     * _currency_support
506
-     *
507
-     * @access protected
508
-     * @param \EE_Payment_Method $payment_method
509
-     * @return \EE_Form_Section_Proper
510
-     */
511
-    protected function _currency_support(EE_Payment_Method $payment_method)
512
-    {
513
-        if (! $payment_method->usable_for_currency(EE_Config::instance()->currency->code)) {
514
-            return new EE_Form_Section_HTML(
515
-                EEH_HTML::tr(
516
-                    EEH_HTML::th(
517
-                        EEH_HTML::label(
518
-                            EEH_HTML::strong(__('IMPORTANT', 'event_espresso'), '', 'important-notice')
519
-                        )
520
-                    ) .
521
-                    EEH_HTML::td(
522
-                        EEH_HTML::strong(
523
-                            sprintf(
524
-                                __(
525
-                                    'This payment method does not support the currency set on your site (%1$s). Please activate a different payment method or change your site\'s country and associated currency.',
526
-                                    'event_espresso'
527
-                                ),
528
-                                EE_Config::instance()->currency->code
529
-                            )
530
-                        )
531
-                    )
532
-                )
533
-            );
534
-        } else {
535
-            return new EE_Form_Section_HTML('');
536
-        }
537
-    }
538
-
539
-
540
-    /**
541
-     * _update_payment_method_button
542
-     *
543
-     * @access protected
544
-     * @param \EE_Payment_Method $payment_method
545
-     * @return \EE_Form_Section_HTML
546
-     */
547
-    protected function _payment_method_settings(EE_Payment_Method $payment_method)
548
-    {
549
-        // modify the form so we only have/show fields that will be implemented for this version
550
-        return $this->_simplify_form($payment_method->type_obj()->settings_form(), $payment_method->name());
551
-    }
552
-
553
-
554
-    /**
555
-     * Simplifies the form to merely reproduce 4.1's gateway settings functionality
556
-     *
557
-     * @param EE_Form_Section_Proper $form_section
558
-     * @param string                 $payment_method_name
559
-     * @return \EE_Payment_Method_Form
560
-     * @throws \EE_Error
561
-     */
562
-    protected function _simplify_form($form_section, $payment_method_name = '')
563
-    {
564
-        if ($form_section instanceof EE_Payment_Method_Form) {
565
-            $form_section->exclude(
566
-                array(
567
-                    'PMD_type', // dont want them changing the type
568
-                    'PMD_slug', // or the slug (probably never)
569
-                    'PMD_wp_user', // or the user's ID
570
-                    'Currency' // or the currency, until the rest of EE supports simultaneous currencies
571
-                )
572
-            );
573
-            return $form_section;
574
-        } else {
575
-            throw new EE_Error(
576
-                sprintf(
577
-                    __(
578
-                        'The EE_Payment_Method_Form for the "%1$s" payment method is missing or invalid.',
579
-                        'event_espresso'
580
-                    ),
581
-                    $payment_method_name
582
-                )
583
-            );
584
-        }
585
-    }
586
-
587
-
588
-    /**
589
-     * _update_payment_method_button
590
-     *
591
-     * @access protected
592
-     * @param \EE_Payment_Method $payment_method
593
-     * @return \EE_Form_Section_HTML
594
-     */
595
-    protected function _update_payment_method_button(EE_Payment_Method $payment_method)
596
-    {
597
-        $update_button = new EE_Submit_Input(
598
-            array(
599
-                'name'       => 'submit',
600
-                'html_id'    => 'save_' . $payment_method->slug() . '_settings',
601
-                'default'    => sprintf(
602
-                    __('Update %s Payment Settings', 'event_espresso'),
603
-                    $payment_method->admin_name()
604
-                ),
605
-                'html_label' => EEH_HTML::nbsp(),
606
-            )
607
-        );
608
-        return new EE_Form_Section_HTML(
609
-            EEH_HTML::no_row(EEH_HTML::br(2)) .
610
-            EEH_HTML::tr(
611
-                EEH_HTML::th(__('Update Settings', 'event_espresso')) .
612
-                EEH_HTML::td(
613
-                    $update_button->get_html_for_input()
614
-                )
615
-            )
616
-        );
617
-    }
618
-
619
-
620
-    /**
621
-     * _deactivate_payment_method_button
622
-     *
623
-     * @access protected
624
-     * @param \EE_Payment_Method $payment_method
625
-     * @return \EE_Form_Section_Proper
626
-     */
627
-    protected function _deactivate_payment_method_button(EE_Payment_Method $payment_method)
628
-    {
629
-        $link_text_and_title = sprintf(
630
-            __('Deactivate %1$s Payments?', 'event_espresso'),
631
-            $payment_method->admin_name()
632
-        );
633
-        return new EE_Form_Section_HTML(
634
-            EEH_HTML::tr(
635
-                EEH_HTML::th(__('Deactivate Payment Method', 'event_espresso')) .
636
-                EEH_HTML::td(
637
-                    EEH_HTML::link(
638
-                        EE_Admin_Page::add_query_args_and_nonce(
639
-                            array(
640
-                                'action'         => 'deactivate_payment_method',
641
-                                'payment_method' => $payment_method->slug(),
642
-                            ),
643
-                            EE_PAYMENTS_ADMIN_URL
644
-                        ),
645
-                        $link_text_and_title,
646
-                        $link_text_and_title,
647
-                        'deactivate_' . $payment_method->slug(),
648
-                        'espresso-button button-secondary'
649
-                    )
650
-                )
651
-            )
652
-        );
653
-    }
654
-
655
-
656
-    /**
657
-     * _activate_payment_method_button
658
-     *
659
-     * @access protected
660
-     * @param \EE_Payment_Method $payment_method
661
-     * @return \EE_Form_Section_Proper
662
-     */
663
-    protected function _activate_payment_method_button(EE_Payment_Method $payment_method)
664
-    {
665
-        $link_text_and_title = sprintf(
666
-            __('Activate %1$s Payment Method?', 'event_espresso'),
667
-            $payment_method->admin_name()
668
-        );
669
-        return new EE_Form_Section_Proper(
670
-            array(
671
-                'name'            => 'activate_' . $payment_method->slug() . '_settings_form',
672
-                'html_id'         => 'activate_' . $payment_method->slug() . '_settings_form',
673
-                'action'          => '#',
674
-                'layout_strategy' => new EE_Admin_Two_Column_Layout(),
675
-                'subsections'     => apply_filters(
676
-                    'FHEE__Payments_Admin_Page___activate_payment_method_button__form_subsections',
677
-                    array(
678
-                        new EE_Form_Section_HTML(
679
-                            EEH_HTML::tr(
680
-                                EEH_HTML::td(
681
-                                    $payment_method->type_obj()->introductory_html(),
682
-                                    '',
683
-                                    '',
684
-                                    '',
685
-                                    'colspan="2"'
686
-                                )
687
-                            ) .
688
-                            EEH_HTML::tr(
689
-                                EEH_HTML::th(
690
-                                    EEH_HTML::label(__('Click to Activate ', 'event_espresso'))
691
-                                ) .
692
-                                EEH_HTML::td(
693
-                                    EEH_HTML::link(
694
-                                        EE_Admin_Page::add_query_args_and_nonce(
695
-                                            array(
696
-                                                'action'              => 'activate_payment_method',
697
-                                                'payment_method_type' => $payment_method->type(),
698
-                                            ),
699
-                                            EE_PAYMENTS_ADMIN_URL
700
-                                        ),
701
-                                        $link_text_and_title,
702
-                                        $link_text_and_title,
703
-                                        'activate_' . $payment_method->slug(),
704
-                                        'espresso-button-green button-primary'
705
-                                    )
706
-                                )
707
-                            )
708
-                        ),
709
-                    ),
710
-                    $payment_method
711
-                ),
712
-            )
713
-        );
714
-    }
715
-
716
-
717
-    /**
718
-     * _fine_print
719
-     *
720
-     * @access protected
721
-     * @return \EE_Form_Section_HTML
722
-     */
723
-    protected function _fine_print()
724
-    {
725
-        return new EE_Form_Section_HTML(
726
-            EEH_HTML::tr(
727
-                EEH_HTML::th() .
728
-                EEH_HTML::td(
729
-                    EEH_HTML::p(__('All fields marked with a * are required fields', 'event_espresso'), '', 'grey-text')
730
-                )
731
-            )
732
-        );
733
-    }
734
-
735
-
736
-    /**
737
-     * Activates a payment method of that type. Mostly assuming there is only 1 of that type (or none so far)
738
-     *
739
-     * @global WP_User $current_user
740
-     */
741
-    protected function _activate_payment_method()
742
-    {
743
-        if (isset($this->_req_data['payment_method_type'])) {
744
-            $payment_method_type = sanitize_text_field($this->_req_data['payment_method_type']);
745
-            // see if one exists
746
-            EE_Registry::instance()->load_lib('Payment_Method_Manager');
747
-            $payment_method = EE_Payment_Method_Manager::instance()
748
-                                                       ->activate_a_payment_method_of_type($payment_method_type);
749
-            $this->_redirect_after_action(
750
-                1,
751
-                'Payment Method',
752
-                'activated',
753
-                array('action' => 'default', 'payment_method' => $payment_method->slug())
754
-            );
755
-        } else {
756
-            $this->_redirect_after_action(false, 'Payment Method', 'activated', array('action' => 'default'));
757
-        }
758
-    }
759
-
760
-
761
-    /**
762
-     * Deactivates the payment method with the specified slug, and redirects.
763
-     */
764
-    protected function _deactivate_payment_method()
765
-    {
766
-        if (isset($this->_req_data['payment_method'])) {
767
-            $payment_method_slug = sanitize_key($this->_req_data['payment_method']);
768
-            // deactivate it
769
-            EE_Registry::instance()->load_lib('Payment_Method_Manager');
770
-            $count_updated = EE_Payment_Method_Manager::instance()->deactivate_payment_method($payment_method_slug);
771
-            $this->_redirect_after_action(
772
-                $count_updated,
773
-                'Payment Method',
774
-                'deactivated',
775
-                array('action' => 'default', 'payment_method' => $payment_method_slug)
776
-            );
777
-        } else {
778
-            $this->_redirect_after_action(false, 'Payment Method', 'deactivated', array('action' => 'default'));
779
-        }
780
-    }
781
-
782
-
783
-    /**
784
-     * Processes the payment method form that was submitted. This is slightly trickier than usual form
785
-     * processing because we first need to identify WHICH form was processed and which payment method
786
-     * it corresponds to. Once we have done that, we see if the form is valid. If it is, the
787
-     * form's data is saved and we redirect to the default payment methods page, setting the updated payment method
788
-     * as the currently-selected one. If it DOESN'T validate, we render the page with the form's errors (in the
789
-     * subsequently called 'headers_sent_func' which is _payment_methods_list)
790
-     *
791
-     * @return void
792
-     */
793
-    protected function _update_payment_method()
794
-    {
795
-        if ($_SERVER['REQUEST_METHOD'] == 'POST') {
796
-            // ok let's find which gateway form to use based on the form input
797
-            EE_Registry::instance()->load_lib('Payment_Method_Manager');
798
-            /** @var $correct_pmt_form_to_use EE_Payment_Method_Form */
799
-            $correct_pmt_form_to_use = null;
800
-            $payment_method = null;
801
-            foreach (EEM_Payment_Method::instance()->get_all() as $payment_method) {
802
-                // get the form and simplify it, like what we do when we display it
803
-                $pmt_form = $this->_generate_payment_method_settings_form($payment_method);
804
-                if ($pmt_form->form_data_present_in($this->_req_data)) {
805
-                    $correct_pmt_form_to_use = $pmt_form;
806
-                    break;
807
-                }
808
-            }
809
-            // if we couldn't find the correct payment method type...
810
-            if (! $correct_pmt_form_to_use) {
811
-                EE_Error::add_error(
812
-                    __(
813
-                        "We could not find which payment method type your form submission related to. Please contact support",
814
-                        'event_espresso'
815
-                    ),
816
-                    __FILE__,
817
-                    __FUNCTION__,
818
-                    __LINE__
819
-                );
820
-                $this->_redirect_after_action(false, 'Payment Method', 'activated', array('action' => 'default'));
821
-            }
822
-            $correct_pmt_form_to_use->receive_form_submission($this->_req_data);
823
-            if ($correct_pmt_form_to_use->is_valid()) {
824
-                $payment_settings_subform = $correct_pmt_form_to_use->get_subsection('payment_method_settings');
825
-                if (! $payment_settings_subform instanceof EE_Payment_Method_Form) {
826
-                    throw new EE_Error(
827
-                        sprintf(
828
-                            __(
829
-                                'The payment method could not be saved because the form sections were misnamed. We expected to find %1$s, but did not.',
830
-                                'event_espresso'
831
-                            ),
832
-                            'payment_method_settings'
833
-                        )
834
-                    );
835
-                }
836
-                $payment_settings_subform->save();
837
-                /** @var $pm EE_Payment_Method */
838
-                $this->_redirect_after_action(
839
-                    true,
840
-                    'Payment Method',
841
-                    'updated',
842
-                    array('action' => 'default', 'payment_method' => $payment_method->slug())
843
-                );
844
-            } else {
845
-                EE_Error::add_error(
846
-                    sprintf(
847
-                        __(
848
-                            'Payment method of type %s was not saved because there were validation errors. They have been marked in the form',
849
-                            'event_espresso'
850
-                        ),
851
-                        $payment_method instanceof EE_Payment_Method ? $payment_method->type_obj()->pretty_name()
852
-                            : __('"(unknown)"', 'event_espresso')
853
-                    ),
854
-                    __FILE__,
855
-                    __FUNCTION__,
856
-                    __LINE__
857
-                );
858
-            }
859
-        }
860
-        return;
861
-    }
862
-
863
-
864
-    /**
865
-     * Displays payment settings (not payment METHOD settings, that's _payment_method_settings)
866
-     * @throws DomainException
867
-     * @throws EE_Error
868
-     * @throws InvalidArgumentException
869
-     * @throws \EventEspresso\core\exceptions\InvalidDataTypeException
870
-     * @throws \EventEspresso\core\exceptions\InvalidInterfaceException
871
-     */
872
-    protected function _payment_settings()
873
-    {
874
-        $form = $this->getPaymentSettingsForm();
875
-        $this->_set_add_edit_form_tags('update_payment_settings');
876
-        $this->_set_publish_post_box_vars(null, false, false, null, false);
877
-        $this->_template_args['admin_page_content'] =  $form->get_html_and_js();
878
-        $this->display_admin_page_with_sidebar();
879
-    }
880
-
881
-
882
-    /**
883
-     *        _update_payment_settings
884
-     *
885
-     * @access protected
886
-     * @return void
887
-     * @throws EE_Error
888
-     * @throws InvalidArgumentException
889
-     * @throws \EventEspresso\core\exceptions\InvalidDataTypeException
890
-     * @throws \EventEspresso\core\exceptions\InvalidInterfaceException
891
-     */
892
-    protected function _update_payment_settings()
893
-    {
894
-        $form = $this->getPaymentSettingsForm();
895
-        if ($form->was_submitted($this->_req_data)) {
896
-            $form->receive_form_submission($this->_req_data);
897
-            if ($form->is_valid()) {
898
-                /**
899
-                 * @var $reg_config EE_Registration_Config
900
-                 */
901
-                $loader = LoaderFactory::getLoader();
902
-                $reg_config = $loader->getShared('EE_Registration_Config');
903
-                $valid_data = $form->valid_data();
904
-                $reg_config->show_pending_payment_options = $valid_data['show_pending_payment_options'];
905
-                $reg_config->gateway_log_lifespan = $valid_data['gateway_log_lifespan'];
906
-            }
907
-        }
908
-        EE_Registry::instance()->CFG = apply_filters(
909
-            'FHEE__Payments_Admin_Page___update_payment_settings__CFG',
910
-            EE_Registry::instance()->CFG
911
-        );
912
-
913
-        $cfg =  EE_Registry::instance()->CFG ;
914
-
915
-        $what = __('Payment Settings', 'event_espresso');
916
-        $success = $this->_update_espresso_configuration(
917
-            $what,
918
-            EE_Registry::instance()->CFG,
919
-            __FILE__,
920
-            __FUNCTION__,
921
-            __LINE__
922
-        );
923
-        $this->_redirect_after_action(
924
-            $success,
925
-            $what,
926
-            __('updated', 'event_espresso'),
927
-            array('action' => 'payment_settings')
928
-        );
929
-    }
930
-
931
-
932
-    /**
933
-     * Gets the form used for updating payment settings
934
-     *
935
-     * @return EE_Form_Section_Proper
936
-     * @throws EE_Error
937
-     * @throws InvalidArgumentException
938
-     * @throws \EventEspresso\core\exceptions\InvalidDataTypeException
939
-     * @throws \EventEspresso\core\exceptions\InvalidInterfaceException
940
-     */
941
-    protected function getPaymentSettingsForm()
942
-    {
943
-        /**
944
-         * @var $reg_config EE_Registration_Config
945
-         */
946
-        $reg_config = LoaderFactory::getLoader()->getShared('EE_Registration_Config');
947
-        return new EE_Form_Section_Proper(
948
-            array(
949
-                'name' => 'payment-settings',
950
-                'layout_strategy' => new EE_Admin_Two_Column_Layout(),
951
-                'subsections' => array(
952
-                    'show_pending_payment_options' => new EE_Yes_No_Input(
953
-                        array(
954
-                            'html_name' => 'show_pending_payment_options',
955
-                            'default' => $reg_config->show_pending_payment_options,
956
-                            'html_help_text' => esc_html__(
957
-                                "If a payment is marked as 'Pending Payment', or if payment is deferred (ie, an offline gateway like Check, Bank, or Invoice is used), then give registrants the option to retry payment. ",
958
-                                'event_espresso'
959
-                            )
960
-                        )
961
-                    ),
962
-                    'gateway_log_lifespan' => new \EE_Select_Input(
963
-                        $reg_config->gatewayLogLifespanOptions(),
964
-                        array(
965
-                            'html_label_text' => esc_html__('Gateway Logs Lifespan', 'event_espresso'),
966
-                            'html_help_text' => esc_html__('If issues arise with payments being made through a payment gateway, it\'s helpful to log non-sensitive communications with the payment gateway. But it\'s a security responsibility, so it\'s a good idea to not keep them for any longer than necessary.', 'event_espresso'),
967
-                            'default' => $reg_config->gateway_log_lifespan,
968
-                        )
969
-                    )
970
-                )
971
-            )
972
-        );
973
-    }
974
-
975
-
976
-    protected function _payment_log_overview_list_table()
977
-    {
978
-        $this->display_admin_list_table_page_with_sidebar();
979
-    }
980
-
981
-
982
-    protected function _set_list_table_views_payment_log()
983
-    {
984
-        $this->_views = array(
985
-            'all' => array(
986
-                'slug'  => 'all',
987
-                'label' => __('View All Logs', 'event_espresso'),
988
-                'count' => 0,
989
-            ),
990
-        );
991
-    }
992
-
993
-
994
-    /**
995
-     * @param int  $per_page
996
-     * @param int  $current_page
997
-     * @param bool $count
998
-     * @return array
999
-     */
1000
-    public function get_payment_logs($per_page = 50, $current_page = 0, $count = false)
1001
-    {
1002
-        EE_Registry::instance()->load_model('Change_Log');
1003
-        // we may need to do multiple queries (joining differently), so we actually wan tan array of query params
1004
-        $query_params = array(array('LOG_type' => EEM_Change_Log::type_gateway));
1005
-        // check if they've selected a specific payment method
1006
-        if (isset($this->_req_data['_payment_method']) && $this->_req_data['_payment_method'] !== 'all') {
1007
-            $query_params[0]['OR*pm_or_pay_pm'] = array(
1008
-                'Payment.Payment_Method.PMD_ID' => $this->_req_data['_payment_method'],
1009
-                'Payment_Method.PMD_ID'         => $this->_req_data['_payment_method'],
1010
-            );
1011
-        }
1012
-        // take into account search
1013
-        if (isset($this->_req_data['s']) && $this->_req_data['s']) {
1014
-            $similarity_string = array('LIKE', '%' . str_replace("", "%", $this->_req_data['s']) . '%');
1015
-            $query_params[0]['OR*s']['Payment.Transaction.Registration.Attendee.ATT_fname'] = $similarity_string;
1016
-            $query_params[0]['OR*s']['Payment.Transaction.Registration.Attendee.ATT_lname'] = $similarity_string;
1017
-            $query_params[0]['OR*s']['Payment.Transaction.Registration.Attendee.ATT_email'] = $similarity_string;
1018
-            $query_params[0]['OR*s']['Payment.Payment_Method.PMD_name'] = $similarity_string;
1019
-            $query_params[0]['OR*s']['Payment.Payment_Method.PMD_admin_name'] = $similarity_string;
1020
-            $query_params[0]['OR*s']['Payment.Payment_Method.PMD_type'] = $similarity_string;
1021
-            $query_params[0]['OR*s']['LOG_message'] = $similarity_string;
1022
-            $query_params[0]['OR*s']['Payment_Method.PMD_name'] = $similarity_string;
1023
-            $query_params[0]['OR*s']['Payment_Method.PMD_admin_name'] = $similarity_string;
1024
-            $query_params[0]['OR*s']['Payment_Method.PMD_type'] = $similarity_string;
1025
-            $query_params[0]['OR*s']['LOG_message'] = $similarity_string;
1026
-        }
1027
-        if (isset($this->_req_data['payment-filter-start-date'])
1028
-            && isset($this->_req_data['payment-filter-end-date'])
1029
-        ) {
1030
-            // add date
1031
-            $start_date = wp_strip_all_tags($this->_req_data['payment-filter-start-date']);
1032
-            $end_date = wp_strip_all_tags($this->_req_data['payment-filter-end-date']);
1033
-            // make sure our timestamps start and end right at the boundaries for each day
1034
-            $start_date = date('Y-m-d', strtotime($start_date)) . ' 00:00:00';
1035
-            $end_date = date('Y-m-d', strtotime($end_date)) . ' 23:59:59';
1036
-            // convert to timestamps
1037
-            $start_date = strtotime($start_date);
1038
-            $end_date = strtotime($end_date);
1039
-            // makes sure start date is the lowest value and vice versa
1040
-            $start_date = min($start_date, $end_date);
1041
-            $end_date = max($start_date, $end_date);
1042
-            // convert for query
1043
-            $start_date = EEM_Change_Log::instance()
1044
-                                        ->convert_datetime_for_query(
1045
-                                            'LOG_time',
1046
-                                            date('Y-m-d H:i:s', $start_date),
1047
-                                            'Y-m-d H:i:s'
1048
-                                        );
1049
-            $end_date = EEM_Change_Log::instance()
1050
-                                      ->convert_datetime_for_query(
1051
-                                          'LOG_time',
1052
-                                          date('Y-m-d H:i:s', $end_date),
1053
-                                          'Y-m-d H:i:s'
1054
-                                      );
1055
-            $query_params[0]['LOG_time'] = array('BETWEEN', array($start_date, $end_date));
1056
-        }
1057
-        if ($count) {
1058
-            return EEM_Change_Log::instance()->count($query_params);
1059
-        }
1060
-        if (isset($this->_req_data['order'])) {
1061
-            $sort = (isset($this->_req_data['order']) && ! empty($this->_req_data['order'])) ? $this->_req_data['order']
1062
-                : 'DESC';
1063
-            $query_params['order_by'] = array('LOG_time' => $sort);
1064
-        } else {
1065
-            $query_params['order_by'] = array('LOG_time' => 'DESC');
1066
-        }
1067
-        $offset = ($current_page - 1) * $per_page;
1068
-        if (! isset($this->_req_data['download_results'])) {
1069
-            $query_params['limit'] = array($offset, $per_page);
1070
-        }
1071
-        // now they've requested to instead just download the file instead of viewing it.
1072
-        if (isset($this->_req_data['download_results'])) {
1073
-            $wpdb_results = EEM_Change_Log::instance()->get_all_efficiently($query_params);
1074
-            header('Content-Disposition: attachment');
1075
-            header("Content-Disposition: attachment; filename=ee_payment_logs_for_" . sanitize_key(site_url()));
1076
-            echo "<h1>Payment Logs for " . site_url() . "</h1>";
1077
-            echo "<h3>Query:</h3>";
1078
-            var_dump($query_params);
1079
-            echo "<h3>Results:</h3>";
1080
-            var_dump($wpdb_results);
1081
-            die;
1082
-        }
1083
-        $results = EEM_Change_Log::instance()->get_all($query_params);
1084
-        return $results;
1085
-    }
1086
-
1087
-
1088
-    /**
1089
-     * Used by usort to RE-sort log query results, because we lose the ordering
1090
-     * because we're possibly combining the results from two queries
1091
-     *
1092
-     * @param EE_Change_Log $logA
1093
-     * @param EE_Change_Log $logB
1094
-     * @return int
1095
-     */
1096
-    protected function _sort_logs_again($logA, $logB)
1097
-    {
1098
-        $timeA = $logA->get_raw('LOG_time');
1099
-        $timeB = $logB->get_raw('LOG_time');
1100
-        if ($timeA == $timeB) {
1101
-            return 0;
1102
-        }
1103
-        $comparison = $timeA < $timeB ? -1 : 1;
1104
-        if (strtoupper($this->_sort_logs_again_direction) == 'DESC') {
1105
-            return $comparison * -1;
1106
-        } else {
1107
-            return $comparison;
1108
-        }
1109
-    }
1110
-
1111
-
1112
-    protected function _payment_log_details()
1113
-    {
1114
-        EE_Registry::instance()->load_model('Change_Log');
1115
-        /** @var $payment_log EE_Change_Log */
1116
-        $payment_log = EEM_Change_Log::instance()->get_one_by_ID($this->_req_data['ID']);
1117
-        $payment_method = null;
1118
-        $transaction = null;
1119
-        if ($payment_log instanceof EE_Change_Log) {
1120
-            if ($payment_log->object() instanceof EE_Payment) {
1121
-                $payment_method = $payment_log->object()->payment_method();
1122
-                $transaction = $payment_log->object()->transaction();
1123
-            } elseif ($payment_log->object() instanceof EE_Payment_Method) {
1124
-                $payment_method = $payment_log->object();
1125
-            }
1126
-        }
1127
-        $this->_template_args['admin_page_content'] = EEH_Template::display_template(
1128
-            EE_PAYMENTS_TEMPLATE_PATH . 'payment_log_details.template.php',
1129
-            array(
1130
-                'payment_log'    => $payment_log,
1131
-                'payment_method' => $payment_method,
1132
-                'transaction'    => $transaction,
1133
-            ),
1134
-            true
1135
-        );
1136
-        $this->display_admin_page_with_sidebar();
1137
-    }
17
+	/**
18
+	 * Variables used for when we're re-sorting the logs results, in case
19
+	 * we needed to do two queries and we need to resort
20
+	 *
21
+	 * @var string
22
+	 */
23
+	private $_sort_logs_again_direction;
24
+
25
+
26
+	/**
27
+	 * @Constructor
28
+	 * @access public
29
+	 * @param bool $routing indicate whether we want to just load the object and handle routing or just load the object.
30
+	 * @return \Payments_Admin_Page
31
+	 */
32
+	public function __construct($routing = true)
33
+	{
34
+		parent::__construct($routing);
35
+	}
36
+
37
+
38
+	protected function _init_page_props()
39
+	{
40
+		$this->page_slug = EE_PAYMENTS_PG_SLUG;
41
+		$this->page_label = __('Payment Methods', 'event_espresso');
42
+		$this->_admin_base_url = EE_PAYMENTS_ADMIN_URL;
43
+		$this->_admin_base_path = EE_PAYMENTS_ADMIN;
44
+	}
45
+
46
+
47
+	protected function _ajax_hooks()
48
+	{
49
+		// todo: all hooks for ajax goes here.
50
+	}
51
+
52
+
53
+	protected function _define_page_props()
54
+	{
55
+		$this->_admin_page_title = $this->page_label;
56
+		$this->_labels = array(
57
+			'publishbox' => __('Update Settings', 'event_espresso'),
58
+		);
59
+	}
60
+
61
+
62
+	protected function _set_page_routes()
63
+	{
64
+		/**
65
+		 * note that with payment method capabilities, although we've implemented
66
+		 * capability mapping which will be used for accessing payment methods owned by
67
+		 * other users.  This is not fully implemented yet in the payment method ui.
68
+		 * Currently only the "plural" caps are in active use.
69
+		 * When cap mapping is implemented, some routes will need to use the singular form of
70
+		 * capability method and also include the $id of the payment method for the route.
71
+		 **/
72
+		$this->_page_routes = array(
73
+			'default'                   => array(
74
+				'func'       => '_payment_methods_list',
75
+				'capability' => 'ee_edit_payment_methods',
76
+			),
77
+			'payment_settings'          => array(
78
+				'func'       => '_payment_settings',
79
+				'capability' => 'ee_manage_gateways',
80
+			),
81
+			'activate_payment_method'   => array(
82
+				'func'       => '_activate_payment_method',
83
+				'noheader'   => true,
84
+				'capability' => 'ee_edit_payment_methods',
85
+			),
86
+			'deactivate_payment_method' => array(
87
+				'func'       => '_deactivate_payment_method',
88
+				'noheader'   => true,
89
+				'capability' => 'ee_delete_payment_methods',
90
+			),
91
+			'update_payment_method'     => array(
92
+				'func'               => '_update_payment_method',
93
+				'noheader'           => true,
94
+				'headers_sent_route' => 'default',
95
+				'capability'         => 'ee_edit_payment_methods',
96
+			),
97
+			'update_payment_settings'   => array(
98
+				'func'       => '_update_payment_settings',
99
+				'noheader'   => true,
100
+				'capability' => 'ee_manage_gateways',
101
+			),
102
+			'payment_log'               => array(
103
+				'func'       => '_payment_log_overview_list_table',
104
+				'capability' => 'ee_read_payment_methods',
105
+			),
106
+			'payment_log_details'       => array(
107
+				'func'       => '_payment_log_details',
108
+				'capability' => 'ee_read_payment_methods',
109
+			),
110
+		);
111
+	}
112
+
113
+
114
+	protected function _set_page_config()
115
+	{
116
+		$payment_method_list_config = array(
117
+			'nav'           => array(
118
+				'label' => __('Payment Methods', 'event_espresso'),
119
+				'order' => 10,
120
+			),
121
+			'metaboxes'     => $this->_default_espresso_metaboxes,
122
+			'help_tabs'     => array_merge(
123
+				array(
124
+					'payment_methods_overview_help_tab' => array(
125
+						'title'    => __('Payment Methods Overview', 'event_espresso'),
126
+						'filename' => 'payment_methods_overview',
127
+					),
128
+				),
129
+				$this->_add_payment_method_help_tabs()
130
+			),
131
+			'help_tour'     => array('Payment_Methods_Selection_Help_Tour'),
132
+			'require_nonce' => false,
133
+		);
134
+		$this->_page_config = array(
135
+			'default'          => $payment_method_list_config,
136
+			'payment_settings' => array(
137
+				'nav'           => array(
138
+					'label' => __('Settings', 'event_espresso'),
139
+					'order' => 20,
140
+				),
141
+				'help_tabs'     => array(
142
+					'payment_methods_settings_help_tab' => array(
143
+						'title'    => __('Payment Method Settings', 'event_espresso'),
144
+						'filename' => 'payment_methods_settings',
145
+					),
146
+				),
147
+				// 'help_tour' => array( 'Payment_Methods_Settings_Help_Tour' ),
148
+				'metaboxes'     => array_merge($this->_default_espresso_metaboxes, array('_publish_post_box')),
149
+				'require_nonce' => false,
150
+			),
151
+			'payment_log'      => array(
152
+				'nav'           => array(
153
+					'label' => __("Logs", 'event_espresso'),
154
+					'order' => 30,
155
+				),
156
+				'list_table'    => 'Payment_Log_Admin_List_Table',
157
+				'metaboxes'     => $this->_default_espresso_metaboxes,
158
+				'require_nonce' => false,
159
+			),
160
+		);
161
+	}
162
+
163
+
164
+	/**
165
+	 * @return array
166
+	 */
167
+	protected function _add_payment_method_help_tabs()
168
+	{
169
+		EE_Registry::instance()->load_lib('Payment_Method_Manager');
170
+		$payment_method_types = EE_Payment_Method_Manager::instance()->payment_method_types();
171
+		$all_pmt_help_tabs_config = array();
172
+		foreach ($payment_method_types as $payment_method_type) {
173
+			if (! EE_Registry::instance()->CAP->current_user_can(
174
+				$payment_method_type->cap_name(),
175
+				'specific_payment_method_type_access'
176
+			)
177
+			) {
178
+				continue;
179
+			}
180
+			foreach ($payment_method_type->help_tabs_config() as $help_tab_name => $config) {
181
+				$template_args = isset($config['template_args']) ? $config['template_args'] : array();
182
+				$template_args['admin_page_obj'] = $this;
183
+				$all_pmt_help_tabs_config[ $help_tab_name ] = array(
184
+					'title'   => $config['title'],
185
+					'content' => EEH_Template::display_template(
186
+						$payment_method_type->file_folder() . 'help_tabs' . DS . $config['filename'] . '.help_tab.php',
187
+						$template_args,
188
+						true
189
+					),
190
+				);
191
+			}
192
+		}
193
+		return $all_pmt_help_tabs_config;
194
+	}
195
+
196
+
197
+	// none of the below group are currently used for Gateway Settings
198
+	protected function _add_screen_options()
199
+	{
200
+	}
201
+
202
+
203
+	protected function _add_feature_pointers()
204
+	{
205
+	}
206
+
207
+
208
+	public function admin_init()
209
+	{
210
+	}
211
+
212
+
213
+	public function admin_notices()
214
+	{
215
+	}
216
+
217
+
218
+	public function admin_footer_scripts()
219
+	{
220
+	}
221
+
222
+
223
+	public function load_scripts_styles()
224
+	{
225
+		wp_enqueue_script('ee_admin_js');
226
+		wp_enqueue_script('ee-text-links');
227
+		wp_enqueue_script(
228
+			'espresso_payments',
229
+			EE_PAYMENTS_ASSETS_URL . 'espresso_payments_admin.js',
230
+			array('espresso-ui-theme', 'ee-datepicker'),
231
+			EVENT_ESPRESSO_VERSION,
232
+			true
233
+		);
234
+	}
235
+
236
+
237
+	public function load_scripts_styles_default()
238
+	{
239
+		// styles
240
+		wp_register_style(
241
+			'espresso_payments',
242
+			EE_PAYMENTS_ASSETS_URL . 'ee-payments.css',
243
+			array(),
244
+			EVENT_ESPRESSO_VERSION
245
+		);
246
+		wp_enqueue_style('espresso_payments');
247
+		wp_enqueue_style('ee-text-links');
248
+		// scripts
249
+	}
250
+
251
+
252
+	protected function _payment_methods_list()
253
+	{
254
+		/**
255
+		 * first let's ensure payment methods have been setup. We do this here because when people activate a
256
+		 * payment method for the first time (as an addon), it may not setup its capabilities or get registered correctly due
257
+		 * to the loading process.  However, people MUST setup the details for the payment method so its safe to do a
258
+		 * recheck here.
259
+		 */
260
+		EE_Registry::instance()->load_lib('Payment_Method_Manager');
261
+		EEM_Payment_Method::instance()->verify_button_urls();
262
+		// setup tabs, one for each payment method type
263
+		$tabs = array();
264
+		$payment_methods = array();
265
+		foreach (EE_Payment_Method_Manager::instance()->payment_method_types() as $pmt_obj) {
266
+			// we don't want to show admin-only PMTs for now
267
+			if ($pmt_obj instanceof EE_PMT_Admin_Only) {
268
+				continue;
269
+			}
270
+			// check access
271
+			if (! EE_Registry::instance()->CAP->current_user_can(
272
+				$pmt_obj->cap_name(),
273
+				'specific_payment_method_type_access'
274
+			)
275
+			) {
276
+				continue;
277
+			}
278
+			// check for any active pms of that type
279
+			$payment_method = EEM_Payment_Method::instance()->get_one_of_type($pmt_obj->system_name());
280
+			if (! $payment_method instanceof EE_Payment_Method) {
281
+				$payment_method = EE_Payment_Method::new_instance(
282
+					array(
283
+						'PMD_slug'       => sanitize_key($pmt_obj->system_name()),
284
+						'PMD_type'       => $pmt_obj->system_name(),
285
+						'PMD_name'       => $pmt_obj->pretty_name(),
286
+						'PMD_admin_name' => $pmt_obj->pretty_name(),
287
+					)
288
+				);
289
+			}
290
+			$payment_methods[ $payment_method->slug() ] = $payment_method;
291
+		}
292
+		$payment_methods = apply_filters(
293
+			'FHEE__Payments_Admin_Page___payment_methods_list__payment_methods',
294
+			$payment_methods
295
+		);
296
+		foreach ($payment_methods as $payment_method) {
297
+			if ($payment_method instanceof EE_Payment_Method) {
298
+				add_meta_box(
299
+					// html id
300
+					'espresso_' . $payment_method->slug() . '_payment_settings',
301
+					// title
302
+					sprintf(__('%s Settings', 'event_espresso'), $payment_method->admin_name()),
303
+					// callback
304
+					array($this, 'payment_method_settings_meta_box'),
305
+					// post type
306
+					null,
307
+					// context
308
+					'normal',
309
+					// priority
310
+					'default',
311
+					// callback args
312
+					array('payment_method' => $payment_method)
313
+				);
314
+				// setup for tabbed content
315
+				$tabs[ $payment_method->slug() ] = array(
316
+					'label' => $payment_method->admin_name(),
317
+					'class' => $payment_method->active() ? 'gateway-active' : '',
318
+					'href'  => 'espresso_' . $payment_method->slug() . '_payment_settings',
319
+					'title' => __('Modify this Payment Method', 'event_espresso'),
320
+					'slug'  => $payment_method->slug(),
321
+				);
322
+			}
323
+		}
324
+		$this->_template_args['admin_page_header'] = EEH_Tabbed_Content::tab_text_links(
325
+			$tabs,
326
+			'payment_method_links',
327
+			'|',
328
+			$this->_get_active_payment_method_slug()
329
+		);
330
+		$this->display_admin_page_with_sidebar();
331
+	}
332
+
333
+
334
+	/**
335
+	 *   _get_active_payment_method_slug
336
+	 *
337
+	 * @return string
338
+	 */
339
+	protected function _get_active_payment_method_slug()
340
+	{
341
+		$payment_method_slug = false;
342
+		// decide which payment method tab to open first, as dictated by the request's 'payment_method'
343
+		if (isset($this->_req_data['payment_method'])) {
344
+			// if they provided the current payment method, use it
345
+			$payment_method_slug = sanitize_key($this->_req_data['payment_method']);
346
+		}
347
+		$payment_method = EEM_Payment_Method::instance()->get_one(array(array('PMD_slug' => $payment_method_slug)));
348
+		// if that didn't work or wasn't provided, find another way to select the current pm
349
+		if (! $this->_verify_payment_method($payment_method)) {
350
+			// like, looking for an active one
351
+			$payment_method = EEM_Payment_Method::instance()->get_one_active('CART');
352
+			// test that one as well
353
+			if ($this->_verify_payment_method($payment_method)) {
354
+				$payment_method_slug = $payment_method->slug();
355
+			} else {
356
+				$payment_method_slug = 'paypal_standard';
357
+			}
358
+		}
359
+		return $payment_method_slug;
360
+	}
361
+
362
+
363
+	/**
364
+	 *    payment_method_settings_meta_box
365
+	 *    returns TRUE if the passed payment method is properly constructed and the logged in user has the correct
366
+	 *    capabilities to access it
367
+	 *
368
+	 * @param \EE_Payment_Method $payment_method
369
+	 * @return boolean
370
+	 */
371
+	protected function _verify_payment_method($payment_method)
372
+	{
373
+		if ($payment_method instanceof EE_Payment_Method && $payment_method->type_obj() instanceof EE_PMT_Base
374
+			&& EE_Registry::instance()->CAP->current_user_can(
375
+				$payment_method->type_obj()->cap_name(),
376
+				'specific_payment_method_type_access'
377
+			)
378
+		) {
379
+			return true;
380
+		}
381
+		return false;
382
+	}
383
+
384
+
385
+	/**
386
+	 *    payment_method_settings_meta_box
387
+	 *
388
+	 * @param NULL  $post_obj_which_is_null is an object containing the current post (as a $post object)
389
+	 * @param array $metabox                is an array with metabox id, title, callback, and args elements. the value
390
+	 *                                      at 'args' has key 'payment_method', as set within _payment_methods_list
391
+	 * @return string
392
+	 * @throws EE_Error
393
+	 */
394
+	public function payment_method_settings_meta_box($post_obj_which_is_null, $metabox)
395
+	{
396
+		$payment_method = isset($metabox['args'], $metabox['args']['payment_method'])
397
+			? $metabox['args']['payment_method'] : null;
398
+		if (! $payment_method instanceof EE_Payment_Method) {
399
+			throw new EE_Error(
400
+				sprintf(
401
+					__(
402
+						'Payment method metabox setup incorrectly. No Payment method object was supplied',
403
+						'event_espresso'
404
+					)
405
+				)
406
+			);
407
+		}
408
+		$payment_method_scopes = $payment_method->active();
409
+		// if the payment method really exists show its form, otherwise the activation template
410
+		if ($payment_method->ID() && ! empty($payment_method_scopes)) {
411
+			$form = $this->_generate_payment_method_settings_form($payment_method);
412
+			if ($form->form_data_present_in($this->_req_data)) {
413
+				$form->receive_form_submission($this->_req_data);
414
+			}
415
+			echo $form->form_open() . $form->get_html_and_js() . $form->form_close();
416
+		} else {
417
+			echo $this->_activate_payment_method_button($payment_method)->get_html_and_js();
418
+		}
419
+	}
420
+
421
+
422
+	/**
423
+	 * Gets the form for all the settings related to this payment method type
424
+	 *
425
+	 * @access protected
426
+	 * @param \EE_Payment_Method $payment_method
427
+	 * @return \EE_Form_Section_Proper
428
+	 */
429
+	protected function _generate_payment_method_settings_form(EE_Payment_Method $payment_method)
430
+	{
431
+		if (! $payment_method instanceof EE_Payment_Method) {
432
+			return new EE_Form_Section_Proper();
433
+		}
434
+		return new EE_Form_Section_Proper(
435
+			array(
436
+				'name'            => $payment_method->slug() . '_settings_form',
437
+				'html_id'         => $payment_method->slug() . '_settings_form',
438
+				'action'          => EE_Admin_Page::add_query_args_and_nonce(
439
+					array(
440
+						'action'         => 'update_payment_method',
441
+						'payment_method' => $payment_method->slug(),
442
+					),
443
+					EE_PAYMENTS_ADMIN_URL
444
+				),
445
+				'layout_strategy' => new EE_Admin_Two_Column_Layout(),
446
+				'subsections'     => apply_filters(
447
+					'FHEE__Payments_Admin_Page___generate_payment_method_settings_form__form_subsections',
448
+					array(
449
+						'pci_dss_compliance'      => $this->_pci_dss_compliance($payment_method),
450
+						'currency_support'        => $this->_currency_support($payment_method),
451
+						'payment_method_settings' => $this->_payment_method_settings($payment_method),
452
+						'update'                  => $this->_update_payment_method_button($payment_method),
453
+						'deactivate'              => $this->_deactivate_payment_method_button($payment_method),
454
+						'fine_print'              => $this->_fine_print(),
455
+					),
456
+					$payment_method
457
+				),
458
+			)
459
+		);
460
+	}
461
+
462
+
463
+	/**
464
+	 * _pci_dss_compliance
465
+	 *
466
+	 * @access protected
467
+	 * @param \EE_Payment_Method $payment_method
468
+	 * @return \EE_Form_Section_Proper
469
+	 */
470
+	protected function _pci_dss_compliance(EE_Payment_Method $payment_method)
471
+	{
472
+		if ($payment_method->type_obj()->requires_https()) {
473
+			return new EE_Form_Section_HTML(
474
+				EEH_HTML::tr(
475
+					EEH_HTML::th(
476
+						EEH_HTML::label(
477
+							EEH_HTML::strong(__('IMPORTANT', 'event_espresso'), '', 'important-notice')
478
+						)
479
+					) .
480
+					EEH_HTML::td(
481
+						EEH_HTML::strong(
482
+							__(
483
+								'You are responsible for your own website security and Payment Card Industry Data Security Standards (PCI DSS) compliance.',
484
+								'event_espresso'
485
+							)
486
+						)
487
+						.
488
+						EEH_HTML::br()
489
+						.
490
+						__('Learn more about ', 'event_espresso')
491
+						. EEH_HTML::link(
492
+							'https://www.pcisecuritystandards.org/merchants/index.php',
493
+							__('PCI DSS compliance', 'event_espresso')
494
+						)
495
+					)
496
+				)
497
+			);
498
+		} else {
499
+			return new EE_Form_Section_HTML('');
500
+		}
501
+	}
502
+
503
+
504
+	/**
505
+	 * _currency_support
506
+	 *
507
+	 * @access protected
508
+	 * @param \EE_Payment_Method $payment_method
509
+	 * @return \EE_Form_Section_Proper
510
+	 */
511
+	protected function _currency_support(EE_Payment_Method $payment_method)
512
+	{
513
+		if (! $payment_method->usable_for_currency(EE_Config::instance()->currency->code)) {
514
+			return new EE_Form_Section_HTML(
515
+				EEH_HTML::tr(
516
+					EEH_HTML::th(
517
+						EEH_HTML::label(
518
+							EEH_HTML::strong(__('IMPORTANT', 'event_espresso'), '', 'important-notice')
519
+						)
520
+					) .
521
+					EEH_HTML::td(
522
+						EEH_HTML::strong(
523
+							sprintf(
524
+								__(
525
+									'This payment method does not support the currency set on your site (%1$s). Please activate a different payment method or change your site\'s country and associated currency.',
526
+									'event_espresso'
527
+								),
528
+								EE_Config::instance()->currency->code
529
+							)
530
+						)
531
+					)
532
+				)
533
+			);
534
+		} else {
535
+			return new EE_Form_Section_HTML('');
536
+		}
537
+	}
538
+
539
+
540
+	/**
541
+	 * _update_payment_method_button
542
+	 *
543
+	 * @access protected
544
+	 * @param \EE_Payment_Method $payment_method
545
+	 * @return \EE_Form_Section_HTML
546
+	 */
547
+	protected function _payment_method_settings(EE_Payment_Method $payment_method)
548
+	{
549
+		// modify the form so we only have/show fields that will be implemented for this version
550
+		return $this->_simplify_form($payment_method->type_obj()->settings_form(), $payment_method->name());
551
+	}
552
+
553
+
554
+	/**
555
+	 * Simplifies the form to merely reproduce 4.1's gateway settings functionality
556
+	 *
557
+	 * @param EE_Form_Section_Proper $form_section
558
+	 * @param string                 $payment_method_name
559
+	 * @return \EE_Payment_Method_Form
560
+	 * @throws \EE_Error
561
+	 */
562
+	protected function _simplify_form($form_section, $payment_method_name = '')
563
+	{
564
+		if ($form_section instanceof EE_Payment_Method_Form) {
565
+			$form_section->exclude(
566
+				array(
567
+					'PMD_type', // dont want them changing the type
568
+					'PMD_slug', // or the slug (probably never)
569
+					'PMD_wp_user', // or the user's ID
570
+					'Currency' // or the currency, until the rest of EE supports simultaneous currencies
571
+				)
572
+			);
573
+			return $form_section;
574
+		} else {
575
+			throw new EE_Error(
576
+				sprintf(
577
+					__(
578
+						'The EE_Payment_Method_Form for the "%1$s" payment method is missing or invalid.',
579
+						'event_espresso'
580
+					),
581
+					$payment_method_name
582
+				)
583
+			);
584
+		}
585
+	}
586
+
587
+
588
+	/**
589
+	 * _update_payment_method_button
590
+	 *
591
+	 * @access protected
592
+	 * @param \EE_Payment_Method $payment_method
593
+	 * @return \EE_Form_Section_HTML
594
+	 */
595
+	protected function _update_payment_method_button(EE_Payment_Method $payment_method)
596
+	{
597
+		$update_button = new EE_Submit_Input(
598
+			array(
599
+				'name'       => 'submit',
600
+				'html_id'    => 'save_' . $payment_method->slug() . '_settings',
601
+				'default'    => sprintf(
602
+					__('Update %s Payment Settings', 'event_espresso'),
603
+					$payment_method->admin_name()
604
+				),
605
+				'html_label' => EEH_HTML::nbsp(),
606
+			)
607
+		);
608
+		return new EE_Form_Section_HTML(
609
+			EEH_HTML::no_row(EEH_HTML::br(2)) .
610
+			EEH_HTML::tr(
611
+				EEH_HTML::th(__('Update Settings', 'event_espresso')) .
612
+				EEH_HTML::td(
613
+					$update_button->get_html_for_input()
614
+				)
615
+			)
616
+		);
617
+	}
618
+
619
+
620
+	/**
621
+	 * _deactivate_payment_method_button
622
+	 *
623
+	 * @access protected
624
+	 * @param \EE_Payment_Method $payment_method
625
+	 * @return \EE_Form_Section_Proper
626
+	 */
627
+	protected function _deactivate_payment_method_button(EE_Payment_Method $payment_method)
628
+	{
629
+		$link_text_and_title = sprintf(
630
+			__('Deactivate %1$s Payments?', 'event_espresso'),
631
+			$payment_method->admin_name()
632
+		);
633
+		return new EE_Form_Section_HTML(
634
+			EEH_HTML::tr(
635
+				EEH_HTML::th(__('Deactivate Payment Method', 'event_espresso')) .
636
+				EEH_HTML::td(
637
+					EEH_HTML::link(
638
+						EE_Admin_Page::add_query_args_and_nonce(
639
+							array(
640
+								'action'         => 'deactivate_payment_method',
641
+								'payment_method' => $payment_method->slug(),
642
+							),
643
+							EE_PAYMENTS_ADMIN_URL
644
+						),
645
+						$link_text_and_title,
646
+						$link_text_and_title,
647
+						'deactivate_' . $payment_method->slug(),
648
+						'espresso-button button-secondary'
649
+					)
650
+				)
651
+			)
652
+		);
653
+	}
654
+
655
+
656
+	/**
657
+	 * _activate_payment_method_button
658
+	 *
659
+	 * @access protected
660
+	 * @param \EE_Payment_Method $payment_method
661
+	 * @return \EE_Form_Section_Proper
662
+	 */
663
+	protected function _activate_payment_method_button(EE_Payment_Method $payment_method)
664
+	{
665
+		$link_text_and_title = sprintf(
666
+			__('Activate %1$s Payment Method?', 'event_espresso'),
667
+			$payment_method->admin_name()
668
+		);
669
+		return new EE_Form_Section_Proper(
670
+			array(
671
+				'name'            => 'activate_' . $payment_method->slug() . '_settings_form',
672
+				'html_id'         => 'activate_' . $payment_method->slug() . '_settings_form',
673
+				'action'          => '#',
674
+				'layout_strategy' => new EE_Admin_Two_Column_Layout(),
675
+				'subsections'     => apply_filters(
676
+					'FHEE__Payments_Admin_Page___activate_payment_method_button__form_subsections',
677
+					array(
678
+						new EE_Form_Section_HTML(
679
+							EEH_HTML::tr(
680
+								EEH_HTML::td(
681
+									$payment_method->type_obj()->introductory_html(),
682
+									'',
683
+									'',
684
+									'',
685
+									'colspan="2"'
686
+								)
687
+							) .
688
+							EEH_HTML::tr(
689
+								EEH_HTML::th(
690
+									EEH_HTML::label(__('Click to Activate ', 'event_espresso'))
691
+								) .
692
+								EEH_HTML::td(
693
+									EEH_HTML::link(
694
+										EE_Admin_Page::add_query_args_and_nonce(
695
+											array(
696
+												'action'              => 'activate_payment_method',
697
+												'payment_method_type' => $payment_method->type(),
698
+											),
699
+											EE_PAYMENTS_ADMIN_URL
700
+										),
701
+										$link_text_and_title,
702
+										$link_text_and_title,
703
+										'activate_' . $payment_method->slug(),
704
+										'espresso-button-green button-primary'
705
+									)
706
+								)
707
+							)
708
+						),
709
+					),
710
+					$payment_method
711
+				),
712
+			)
713
+		);
714
+	}
715
+
716
+
717
+	/**
718
+	 * _fine_print
719
+	 *
720
+	 * @access protected
721
+	 * @return \EE_Form_Section_HTML
722
+	 */
723
+	protected function _fine_print()
724
+	{
725
+		return new EE_Form_Section_HTML(
726
+			EEH_HTML::tr(
727
+				EEH_HTML::th() .
728
+				EEH_HTML::td(
729
+					EEH_HTML::p(__('All fields marked with a * are required fields', 'event_espresso'), '', 'grey-text')
730
+				)
731
+			)
732
+		);
733
+	}
734
+
735
+
736
+	/**
737
+	 * Activates a payment method of that type. Mostly assuming there is only 1 of that type (or none so far)
738
+	 *
739
+	 * @global WP_User $current_user
740
+	 */
741
+	protected function _activate_payment_method()
742
+	{
743
+		if (isset($this->_req_data['payment_method_type'])) {
744
+			$payment_method_type = sanitize_text_field($this->_req_data['payment_method_type']);
745
+			// see if one exists
746
+			EE_Registry::instance()->load_lib('Payment_Method_Manager');
747
+			$payment_method = EE_Payment_Method_Manager::instance()
748
+													   ->activate_a_payment_method_of_type($payment_method_type);
749
+			$this->_redirect_after_action(
750
+				1,
751
+				'Payment Method',
752
+				'activated',
753
+				array('action' => 'default', 'payment_method' => $payment_method->slug())
754
+			);
755
+		} else {
756
+			$this->_redirect_after_action(false, 'Payment Method', 'activated', array('action' => 'default'));
757
+		}
758
+	}
759
+
760
+
761
+	/**
762
+	 * Deactivates the payment method with the specified slug, and redirects.
763
+	 */
764
+	protected function _deactivate_payment_method()
765
+	{
766
+		if (isset($this->_req_data['payment_method'])) {
767
+			$payment_method_slug = sanitize_key($this->_req_data['payment_method']);
768
+			// deactivate it
769
+			EE_Registry::instance()->load_lib('Payment_Method_Manager');
770
+			$count_updated = EE_Payment_Method_Manager::instance()->deactivate_payment_method($payment_method_slug);
771
+			$this->_redirect_after_action(
772
+				$count_updated,
773
+				'Payment Method',
774
+				'deactivated',
775
+				array('action' => 'default', 'payment_method' => $payment_method_slug)
776
+			);
777
+		} else {
778
+			$this->_redirect_after_action(false, 'Payment Method', 'deactivated', array('action' => 'default'));
779
+		}
780
+	}
781
+
782
+
783
+	/**
784
+	 * Processes the payment method form that was submitted. This is slightly trickier than usual form
785
+	 * processing because we first need to identify WHICH form was processed and which payment method
786
+	 * it corresponds to. Once we have done that, we see if the form is valid. If it is, the
787
+	 * form's data is saved and we redirect to the default payment methods page, setting the updated payment method
788
+	 * as the currently-selected one. If it DOESN'T validate, we render the page with the form's errors (in the
789
+	 * subsequently called 'headers_sent_func' which is _payment_methods_list)
790
+	 *
791
+	 * @return void
792
+	 */
793
+	protected function _update_payment_method()
794
+	{
795
+		if ($_SERVER['REQUEST_METHOD'] == 'POST') {
796
+			// ok let's find which gateway form to use based on the form input
797
+			EE_Registry::instance()->load_lib('Payment_Method_Manager');
798
+			/** @var $correct_pmt_form_to_use EE_Payment_Method_Form */
799
+			$correct_pmt_form_to_use = null;
800
+			$payment_method = null;
801
+			foreach (EEM_Payment_Method::instance()->get_all() as $payment_method) {
802
+				// get the form and simplify it, like what we do when we display it
803
+				$pmt_form = $this->_generate_payment_method_settings_form($payment_method);
804
+				if ($pmt_form->form_data_present_in($this->_req_data)) {
805
+					$correct_pmt_form_to_use = $pmt_form;
806
+					break;
807
+				}
808
+			}
809
+			// if we couldn't find the correct payment method type...
810
+			if (! $correct_pmt_form_to_use) {
811
+				EE_Error::add_error(
812
+					__(
813
+						"We could not find which payment method type your form submission related to. Please contact support",
814
+						'event_espresso'
815
+					),
816
+					__FILE__,
817
+					__FUNCTION__,
818
+					__LINE__
819
+				);
820
+				$this->_redirect_after_action(false, 'Payment Method', 'activated', array('action' => 'default'));
821
+			}
822
+			$correct_pmt_form_to_use->receive_form_submission($this->_req_data);
823
+			if ($correct_pmt_form_to_use->is_valid()) {
824
+				$payment_settings_subform = $correct_pmt_form_to_use->get_subsection('payment_method_settings');
825
+				if (! $payment_settings_subform instanceof EE_Payment_Method_Form) {
826
+					throw new EE_Error(
827
+						sprintf(
828
+							__(
829
+								'The payment method could not be saved because the form sections were misnamed. We expected to find %1$s, but did not.',
830
+								'event_espresso'
831
+							),
832
+							'payment_method_settings'
833
+						)
834
+					);
835
+				}
836
+				$payment_settings_subform->save();
837
+				/** @var $pm EE_Payment_Method */
838
+				$this->_redirect_after_action(
839
+					true,
840
+					'Payment Method',
841
+					'updated',
842
+					array('action' => 'default', 'payment_method' => $payment_method->slug())
843
+				);
844
+			} else {
845
+				EE_Error::add_error(
846
+					sprintf(
847
+						__(
848
+							'Payment method of type %s was not saved because there were validation errors. They have been marked in the form',
849
+							'event_espresso'
850
+						),
851
+						$payment_method instanceof EE_Payment_Method ? $payment_method->type_obj()->pretty_name()
852
+							: __('"(unknown)"', 'event_espresso')
853
+					),
854
+					__FILE__,
855
+					__FUNCTION__,
856
+					__LINE__
857
+				);
858
+			}
859
+		}
860
+		return;
861
+	}
862
+
863
+
864
+	/**
865
+	 * Displays payment settings (not payment METHOD settings, that's _payment_method_settings)
866
+	 * @throws DomainException
867
+	 * @throws EE_Error
868
+	 * @throws InvalidArgumentException
869
+	 * @throws \EventEspresso\core\exceptions\InvalidDataTypeException
870
+	 * @throws \EventEspresso\core\exceptions\InvalidInterfaceException
871
+	 */
872
+	protected function _payment_settings()
873
+	{
874
+		$form = $this->getPaymentSettingsForm();
875
+		$this->_set_add_edit_form_tags('update_payment_settings');
876
+		$this->_set_publish_post_box_vars(null, false, false, null, false);
877
+		$this->_template_args['admin_page_content'] =  $form->get_html_and_js();
878
+		$this->display_admin_page_with_sidebar();
879
+	}
880
+
881
+
882
+	/**
883
+	 *        _update_payment_settings
884
+	 *
885
+	 * @access protected
886
+	 * @return void
887
+	 * @throws EE_Error
888
+	 * @throws InvalidArgumentException
889
+	 * @throws \EventEspresso\core\exceptions\InvalidDataTypeException
890
+	 * @throws \EventEspresso\core\exceptions\InvalidInterfaceException
891
+	 */
892
+	protected function _update_payment_settings()
893
+	{
894
+		$form = $this->getPaymentSettingsForm();
895
+		if ($form->was_submitted($this->_req_data)) {
896
+			$form->receive_form_submission($this->_req_data);
897
+			if ($form->is_valid()) {
898
+				/**
899
+				 * @var $reg_config EE_Registration_Config
900
+				 */
901
+				$loader = LoaderFactory::getLoader();
902
+				$reg_config = $loader->getShared('EE_Registration_Config');
903
+				$valid_data = $form->valid_data();
904
+				$reg_config->show_pending_payment_options = $valid_data['show_pending_payment_options'];
905
+				$reg_config->gateway_log_lifespan = $valid_data['gateway_log_lifespan'];
906
+			}
907
+		}
908
+		EE_Registry::instance()->CFG = apply_filters(
909
+			'FHEE__Payments_Admin_Page___update_payment_settings__CFG',
910
+			EE_Registry::instance()->CFG
911
+		);
912
+
913
+		$cfg =  EE_Registry::instance()->CFG ;
914
+
915
+		$what = __('Payment Settings', 'event_espresso');
916
+		$success = $this->_update_espresso_configuration(
917
+			$what,
918
+			EE_Registry::instance()->CFG,
919
+			__FILE__,
920
+			__FUNCTION__,
921
+			__LINE__
922
+		);
923
+		$this->_redirect_after_action(
924
+			$success,
925
+			$what,
926
+			__('updated', 'event_espresso'),
927
+			array('action' => 'payment_settings')
928
+		);
929
+	}
930
+
931
+
932
+	/**
933
+	 * Gets the form used for updating payment settings
934
+	 *
935
+	 * @return EE_Form_Section_Proper
936
+	 * @throws EE_Error
937
+	 * @throws InvalidArgumentException
938
+	 * @throws \EventEspresso\core\exceptions\InvalidDataTypeException
939
+	 * @throws \EventEspresso\core\exceptions\InvalidInterfaceException
940
+	 */
941
+	protected function getPaymentSettingsForm()
942
+	{
943
+		/**
944
+		 * @var $reg_config EE_Registration_Config
945
+		 */
946
+		$reg_config = LoaderFactory::getLoader()->getShared('EE_Registration_Config');
947
+		return new EE_Form_Section_Proper(
948
+			array(
949
+				'name' => 'payment-settings',
950
+				'layout_strategy' => new EE_Admin_Two_Column_Layout(),
951
+				'subsections' => array(
952
+					'show_pending_payment_options' => new EE_Yes_No_Input(
953
+						array(
954
+							'html_name' => 'show_pending_payment_options',
955
+							'default' => $reg_config->show_pending_payment_options,
956
+							'html_help_text' => esc_html__(
957
+								"If a payment is marked as 'Pending Payment', or if payment is deferred (ie, an offline gateway like Check, Bank, or Invoice is used), then give registrants the option to retry payment. ",
958
+								'event_espresso'
959
+							)
960
+						)
961
+					),
962
+					'gateway_log_lifespan' => new \EE_Select_Input(
963
+						$reg_config->gatewayLogLifespanOptions(),
964
+						array(
965
+							'html_label_text' => esc_html__('Gateway Logs Lifespan', 'event_espresso'),
966
+							'html_help_text' => esc_html__('If issues arise with payments being made through a payment gateway, it\'s helpful to log non-sensitive communications with the payment gateway. But it\'s a security responsibility, so it\'s a good idea to not keep them for any longer than necessary.', 'event_espresso'),
967
+							'default' => $reg_config->gateway_log_lifespan,
968
+						)
969
+					)
970
+				)
971
+			)
972
+		);
973
+	}
974
+
975
+
976
+	protected function _payment_log_overview_list_table()
977
+	{
978
+		$this->display_admin_list_table_page_with_sidebar();
979
+	}
980
+
981
+
982
+	protected function _set_list_table_views_payment_log()
983
+	{
984
+		$this->_views = array(
985
+			'all' => array(
986
+				'slug'  => 'all',
987
+				'label' => __('View All Logs', 'event_espresso'),
988
+				'count' => 0,
989
+			),
990
+		);
991
+	}
992
+
993
+
994
+	/**
995
+	 * @param int  $per_page
996
+	 * @param int  $current_page
997
+	 * @param bool $count
998
+	 * @return array
999
+	 */
1000
+	public function get_payment_logs($per_page = 50, $current_page = 0, $count = false)
1001
+	{
1002
+		EE_Registry::instance()->load_model('Change_Log');
1003
+		// we may need to do multiple queries (joining differently), so we actually wan tan array of query params
1004
+		$query_params = array(array('LOG_type' => EEM_Change_Log::type_gateway));
1005
+		// check if they've selected a specific payment method
1006
+		if (isset($this->_req_data['_payment_method']) && $this->_req_data['_payment_method'] !== 'all') {
1007
+			$query_params[0]['OR*pm_or_pay_pm'] = array(
1008
+				'Payment.Payment_Method.PMD_ID' => $this->_req_data['_payment_method'],
1009
+				'Payment_Method.PMD_ID'         => $this->_req_data['_payment_method'],
1010
+			);
1011
+		}
1012
+		// take into account search
1013
+		if (isset($this->_req_data['s']) && $this->_req_data['s']) {
1014
+			$similarity_string = array('LIKE', '%' . str_replace("", "%", $this->_req_data['s']) . '%');
1015
+			$query_params[0]['OR*s']['Payment.Transaction.Registration.Attendee.ATT_fname'] = $similarity_string;
1016
+			$query_params[0]['OR*s']['Payment.Transaction.Registration.Attendee.ATT_lname'] = $similarity_string;
1017
+			$query_params[0]['OR*s']['Payment.Transaction.Registration.Attendee.ATT_email'] = $similarity_string;
1018
+			$query_params[0]['OR*s']['Payment.Payment_Method.PMD_name'] = $similarity_string;
1019
+			$query_params[0]['OR*s']['Payment.Payment_Method.PMD_admin_name'] = $similarity_string;
1020
+			$query_params[0]['OR*s']['Payment.Payment_Method.PMD_type'] = $similarity_string;
1021
+			$query_params[0]['OR*s']['LOG_message'] = $similarity_string;
1022
+			$query_params[0]['OR*s']['Payment_Method.PMD_name'] = $similarity_string;
1023
+			$query_params[0]['OR*s']['Payment_Method.PMD_admin_name'] = $similarity_string;
1024
+			$query_params[0]['OR*s']['Payment_Method.PMD_type'] = $similarity_string;
1025
+			$query_params[0]['OR*s']['LOG_message'] = $similarity_string;
1026
+		}
1027
+		if (isset($this->_req_data['payment-filter-start-date'])
1028
+			&& isset($this->_req_data['payment-filter-end-date'])
1029
+		) {
1030
+			// add date
1031
+			$start_date = wp_strip_all_tags($this->_req_data['payment-filter-start-date']);
1032
+			$end_date = wp_strip_all_tags($this->_req_data['payment-filter-end-date']);
1033
+			// make sure our timestamps start and end right at the boundaries for each day
1034
+			$start_date = date('Y-m-d', strtotime($start_date)) . ' 00:00:00';
1035
+			$end_date = date('Y-m-d', strtotime($end_date)) . ' 23:59:59';
1036
+			// convert to timestamps
1037
+			$start_date = strtotime($start_date);
1038
+			$end_date = strtotime($end_date);
1039
+			// makes sure start date is the lowest value and vice versa
1040
+			$start_date = min($start_date, $end_date);
1041
+			$end_date = max($start_date, $end_date);
1042
+			// convert for query
1043
+			$start_date = EEM_Change_Log::instance()
1044
+										->convert_datetime_for_query(
1045
+											'LOG_time',
1046
+											date('Y-m-d H:i:s', $start_date),
1047
+											'Y-m-d H:i:s'
1048
+										);
1049
+			$end_date = EEM_Change_Log::instance()
1050
+									  ->convert_datetime_for_query(
1051
+										  'LOG_time',
1052
+										  date('Y-m-d H:i:s', $end_date),
1053
+										  'Y-m-d H:i:s'
1054
+									  );
1055
+			$query_params[0]['LOG_time'] = array('BETWEEN', array($start_date, $end_date));
1056
+		}
1057
+		if ($count) {
1058
+			return EEM_Change_Log::instance()->count($query_params);
1059
+		}
1060
+		if (isset($this->_req_data['order'])) {
1061
+			$sort = (isset($this->_req_data['order']) && ! empty($this->_req_data['order'])) ? $this->_req_data['order']
1062
+				: 'DESC';
1063
+			$query_params['order_by'] = array('LOG_time' => $sort);
1064
+		} else {
1065
+			$query_params['order_by'] = array('LOG_time' => 'DESC');
1066
+		}
1067
+		$offset = ($current_page - 1) * $per_page;
1068
+		if (! isset($this->_req_data['download_results'])) {
1069
+			$query_params['limit'] = array($offset, $per_page);
1070
+		}
1071
+		// now they've requested to instead just download the file instead of viewing it.
1072
+		if (isset($this->_req_data['download_results'])) {
1073
+			$wpdb_results = EEM_Change_Log::instance()->get_all_efficiently($query_params);
1074
+			header('Content-Disposition: attachment');
1075
+			header("Content-Disposition: attachment; filename=ee_payment_logs_for_" . sanitize_key(site_url()));
1076
+			echo "<h1>Payment Logs for " . site_url() . "</h1>";
1077
+			echo "<h3>Query:</h3>";
1078
+			var_dump($query_params);
1079
+			echo "<h3>Results:</h3>";
1080
+			var_dump($wpdb_results);
1081
+			die;
1082
+		}
1083
+		$results = EEM_Change_Log::instance()->get_all($query_params);
1084
+		return $results;
1085
+	}
1086
+
1087
+
1088
+	/**
1089
+	 * Used by usort to RE-sort log query results, because we lose the ordering
1090
+	 * because we're possibly combining the results from two queries
1091
+	 *
1092
+	 * @param EE_Change_Log $logA
1093
+	 * @param EE_Change_Log $logB
1094
+	 * @return int
1095
+	 */
1096
+	protected function _sort_logs_again($logA, $logB)
1097
+	{
1098
+		$timeA = $logA->get_raw('LOG_time');
1099
+		$timeB = $logB->get_raw('LOG_time');
1100
+		if ($timeA == $timeB) {
1101
+			return 0;
1102
+		}
1103
+		$comparison = $timeA < $timeB ? -1 : 1;
1104
+		if (strtoupper($this->_sort_logs_again_direction) == 'DESC') {
1105
+			return $comparison * -1;
1106
+		} else {
1107
+			return $comparison;
1108
+		}
1109
+	}
1110
+
1111
+
1112
+	protected function _payment_log_details()
1113
+	{
1114
+		EE_Registry::instance()->load_model('Change_Log');
1115
+		/** @var $payment_log EE_Change_Log */
1116
+		$payment_log = EEM_Change_Log::instance()->get_one_by_ID($this->_req_data['ID']);
1117
+		$payment_method = null;
1118
+		$transaction = null;
1119
+		if ($payment_log instanceof EE_Change_Log) {
1120
+			if ($payment_log->object() instanceof EE_Payment) {
1121
+				$payment_method = $payment_log->object()->payment_method();
1122
+				$transaction = $payment_log->object()->transaction();
1123
+			} elseif ($payment_log->object() instanceof EE_Payment_Method) {
1124
+				$payment_method = $payment_log->object();
1125
+			}
1126
+		}
1127
+		$this->_template_args['admin_page_content'] = EEH_Template::display_template(
1128
+			EE_PAYMENTS_TEMPLATE_PATH . 'payment_log_details.template.php',
1129
+			array(
1130
+				'payment_log'    => $payment_log,
1131
+				'payment_method' => $payment_method,
1132
+				'transaction'    => $transaction,
1133
+			),
1134
+			true
1135
+		);
1136
+		$this->display_admin_page_with_sidebar();
1137
+	}
1138 1138
 }
Please login to merge, or discard this patch.
Spacing   +42 added lines, -42 removed lines patch added patch discarded remove patch
@@ -170,7 +170,7 @@  discard block
 block discarded – undo
170 170
         $payment_method_types = EE_Payment_Method_Manager::instance()->payment_method_types();
171 171
         $all_pmt_help_tabs_config = array();
172 172
         foreach ($payment_method_types as $payment_method_type) {
173
-            if (! EE_Registry::instance()->CAP->current_user_can(
173
+            if ( ! EE_Registry::instance()->CAP->current_user_can(
174 174
                 $payment_method_type->cap_name(),
175 175
                 'specific_payment_method_type_access'
176 176
             )
@@ -180,10 +180,10 @@  discard block
 block discarded – undo
180 180
             foreach ($payment_method_type->help_tabs_config() as $help_tab_name => $config) {
181 181
                 $template_args = isset($config['template_args']) ? $config['template_args'] : array();
182 182
                 $template_args['admin_page_obj'] = $this;
183
-                $all_pmt_help_tabs_config[ $help_tab_name ] = array(
183
+                $all_pmt_help_tabs_config[$help_tab_name] = array(
184 184
                     'title'   => $config['title'],
185 185
                     'content' => EEH_Template::display_template(
186
-                        $payment_method_type->file_folder() . 'help_tabs' . DS . $config['filename'] . '.help_tab.php',
186
+                        $payment_method_type->file_folder().'help_tabs'.DS.$config['filename'].'.help_tab.php',
187 187
                         $template_args,
188 188
                         true
189 189
                     ),
@@ -226,7 +226,7 @@  discard block
 block discarded – undo
226 226
         wp_enqueue_script('ee-text-links');
227 227
         wp_enqueue_script(
228 228
             'espresso_payments',
229
-            EE_PAYMENTS_ASSETS_URL . 'espresso_payments_admin.js',
229
+            EE_PAYMENTS_ASSETS_URL.'espresso_payments_admin.js',
230 230
             array('espresso-ui-theme', 'ee-datepicker'),
231 231
             EVENT_ESPRESSO_VERSION,
232 232
             true
@@ -239,7 +239,7 @@  discard block
 block discarded – undo
239 239
         // styles
240 240
         wp_register_style(
241 241
             'espresso_payments',
242
-            EE_PAYMENTS_ASSETS_URL . 'ee-payments.css',
242
+            EE_PAYMENTS_ASSETS_URL.'ee-payments.css',
243 243
             array(),
244 244
             EVENT_ESPRESSO_VERSION
245 245
         );
@@ -268,7 +268,7 @@  discard block
 block discarded – undo
268 268
                 continue;
269 269
             }
270 270
             // check access
271
-            if (! EE_Registry::instance()->CAP->current_user_can(
271
+            if ( ! EE_Registry::instance()->CAP->current_user_can(
272 272
                 $pmt_obj->cap_name(),
273 273
                 'specific_payment_method_type_access'
274 274
             )
@@ -277,7 +277,7 @@  discard block
 block discarded – undo
277 277
             }
278 278
             // check for any active pms of that type
279 279
             $payment_method = EEM_Payment_Method::instance()->get_one_of_type($pmt_obj->system_name());
280
-            if (! $payment_method instanceof EE_Payment_Method) {
280
+            if ( ! $payment_method instanceof EE_Payment_Method) {
281 281
                 $payment_method = EE_Payment_Method::new_instance(
282 282
                     array(
283 283
                         'PMD_slug'       => sanitize_key($pmt_obj->system_name()),
@@ -287,7 +287,7 @@  discard block
 block discarded – undo
287 287
                     )
288 288
                 );
289 289
             }
290
-            $payment_methods[ $payment_method->slug() ] = $payment_method;
290
+            $payment_methods[$payment_method->slug()] = $payment_method;
291 291
         }
292 292
         $payment_methods = apply_filters(
293 293
             'FHEE__Payments_Admin_Page___payment_methods_list__payment_methods',
@@ -297,7 +297,7 @@  discard block
 block discarded – undo
297 297
             if ($payment_method instanceof EE_Payment_Method) {
298 298
                 add_meta_box(
299 299
                     // html id
300
-                    'espresso_' . $payment_method->slug() . '_payment_settings',
300
+                    'espresso_'.$payment_method->slug().'_payment_settings',
301 301
                     // title
302 302
                     sprintf(__('%s Settings', 'event_espresso'), $payment_method->admin_name()),
303 303
                     // callback
@@ -312,10 +312,10 @@  discard block
 block discarded – undo
312 312
                     array('payment_method' => $payment_method)
313 313
                 );
314 314
                 // setup for tabbed content
315
-                $tabs[ $payment_method->slug() ] = array(
315
+                $tabs[$payment_method->slug()] = array(
316 316
                     'label' => $payment_method->admin_name(),
317 317
                     'class' => $payment_method->active() ? 'gateway-active' : '',
318
-                    'href'  => 'espresso_' . $payment_method->slug() . '_payment_settings',
318
+                    'href'  => 'espresso_'.$payment_method->slug().'_payment_settings',
319 319
                     'title' => __('Modify this Payment Method', 'event_espresso'),
320 320
                     'slug'  => $payment_method->slug(),
321 321
                 );
@@ -346,7 +346,7 @@  discard block
 block discarded – undo
346 346
         }
347 347
         $payment_method = EEM_Payment_Method::instance()->get_one(array(array('PMD_slug' => $payment_method_slug)));
348 348
         // if that didn't work or wasn't provided, find another way to select the current pm
349
-        if (! $this->_verify_payment_method($payment_method)) {
349
+        if ( ! $this->_verify_payment_method($payment_method)) {
350 350
             // like, looking for an active one
351 351
             $payment_method = EEM_Payment_Method::instance()->get_one_active('CART');
352 352
             // test that one as well
@@ -395,7 +395,7 @@  discard block
 block discarded – undo
395 395
     {
396 396
         $payment_method = isset($metabox['args'], $metabox['args']['payment_method'])
397 397
             ? $metabox['args']['payment_method'] : null;
398
-        if (! $payment_method instanceof EE_Payment_Method) {
398
+        if ( ! $payment_method instanceof EE_Payment_Method) {
399 399
             throw new EE_Error(
400 400
                 sprintf(
401 401
                     __(
@@ -412,7 +412,7 @@  discard block
 block discarded – undo
412 412
             if ($form->form_data_present_in($this->_req_data)) {
413 413
                 $form->receive_form_submission($this->_req_data);
414 414
             }
415
-            echo $form->form_open() . $form->get_html_and_js() . $form->form_close();
415
+            echo $form->form_open().$form->get_html_and_js().$form->form_close();
416 416
         } else {
417 417
             echo $this->_activate_payment_method_button($payment_method)->get_html_and_js();
418 418
         }
@@ -428,13 +428,13 @@  discard block
 block discarded – undo
428 428
      */
429 429
     protected function _generate_payment_method_settings_form(EE_Payment_Method $payment_method)
430 430
     {
431
-        if (! $payment_method instanceof EE_Payment_Method) {
431
+        if ( ! $payment_method instanceof EE_Payment_Method) {
432 432
             return new EE_Form_Section_Proper();
433 433
         }
434 434
         return new EE_Form_Section_Proper(
435 435
             array(
436
-                'name'            => $payment_method->slug() . '_settings_form',
437
-                'html_id'         => $payment_method->slug() . '_settings_form',
436
+                'name'            => $payment_method->slug().'_settings_form',
437
+                'html_id'         => $payment_method->slug().'_settings_form',
438 438
                 'action'          => EE_Admin_Page::add_query_args_and_nonce(
439 439
                     array(
440 440
                         'action'         => 'update_payment_method',
@@ -476,7 +476,7 @@  discard block
 block discarded – undo
476 476
                         EEH_HTML::label(
477 477
                             EEH_HTML::strong(__('IMPORTANT', 'event_espresso'), '', 'important-notice')
478 478
                         )
479
-                    ) .
479
+                    ).
480 480
                     EEH_HTML::td(
481 481
                         EEH_HTML::strong(
482 482
                             __(
@@ -510,14 +510,14 @@  discard block
 block discarded – undo
510 510
      */
511 511
     protected function _currency_support(EE_Payment_Method $payment_method)
512 512
     {
513
-        if (! $payment_method->usable_for_currency(EE_Config::instance()->currency->code)) {
513
+        if ( ! $payment_method->usable_for_currency(EE_Config::instance()->currency->code)) {
514 514
             return new EE_Form_Section_HTML(
515 515
                 EEH_HTML::tr(
516 516
                     EEH_HTML::th(
517 517
                         EEH_HTML::label(
518 518
                             EEH_HTML::strong(__('IMPORTANT', 'event_espresso'), '', 'important-notice')
519 519
                         )
520
-                    ) .
520
+                    ).
521 521
                     EEH_HTML::td(
522 522
                         EEH_HTML::strong(
523 523
                             sprintf(
@@ -597,7 +597,7 @@  discard block
 block discarded – undo
597 597
         $update_button = new EE_Submit_Input(
598 598
             array(
599 599
                 'name'       => 'submit',
600
-                'html_id'    => 'save_' . $payment_method->slug() . '_settings',
600
+                'html_id'    => 'save_'.$payment_method->slug().'_settings',
601 601
                 'default'    => sprintf(
602 602
                     __('Update %s Payment Settings', 'event_espresso'),
603 603
                     $payment_method->admin_name()
@@ -606,9 +606,9 @@  discard block
 block discarded – undo
606 606
             )
607 607
         );
608 608
         return new EE_Form_Section_HTML(
609
-            EEH_HTML::no_row(EEH_HTML::br(2)) .
609
+            EEH_HTML::no_row(EEH_HTML::br(2)).
610 610
             EEH_HTML::tr(
611
-                EEH_HTML::th(__('Update Settings', 'event_espresso')) .
611
+                EEH_HTML::th(__('Update Settings', 'event_espresso')).
612 612
                 EEH_HTML::td(
613 613
                     $update_button->get_html_for_input()
614 614
                 )
@@ -632,7 +632,7 @@  discard block
 block discarded – undo
632 632
         );
633 633
         return new EE_Form_Section_HTML(
634 634
             EEH_HTML::tr(
635
-                EEH_HTML::th(__('Deactivate Payment Method', 'event_espresso')) .
635
+                EEH_HTML::th(__('Deactivate Payment Method', 'event_espresso')).
636 636
                 EEH_HTML::td(
637 637
                     EEH_HTML::link(
638 638
                         EE_Admin_Page::add_query_args_and_nonce(
@@ -644,7 +644,7 @@  discard block
 block discarded – undo
644 644
                         ),
645 645
                         $link_text_and_title,
646 646
                         $link_text_and_title,
647
-                        'deactivate_' . $payment_method->slug(),
647
+                        'deactivate_'.$payment_method->slug(),
648 648
                         'espresso-button button-secondary'
649 649
                     )
650 650
                 )
@@ -668,8 +668,8 @@  discard block
 block discarded – undo
668 668
         );
669 669
         return new EE_Form_Section_Proper(
670 670
             array(
671
-                'name'            => 'activate_' . $payment_method->slug() . '_settings_form',
672
-                'html_id'         => 'activate_' . $payment_method->slug() . '_settings_form',
671
+                'name'            => 'activate_'.$payment_method->slug().'_settings_form',
672
+                'html_id'         => 'activate_'.$payment_method->slug().'_settings_form',
673 673
                 'action'          => '#',
674 674
                 'layout_strategy' => new EE_Admin_Two_Column_Layout(),
675 675
                 'subsections'     => apply_filters(
@@ -684,11 +684,11 @@  discard block
 block discarded – undo
684 684
                                     '',
685 685
                                     'colspan="2"'
686 686
                                 )
687
-                            ) .
687
+                            ).
688 688
                             EEH_HTML::tr(
689 689
                                 EEH_HTML::th(
690 690
                                     EEH_HTML::label(__('Click to Activate ', 'event_espresso'))
691
-                                ) .
691
+                                ).
692 692
                                 EEH_HTML::td(
693 693
                                     EEH_HTML::link(
694 694
                                         EE_Admin_Page::add_query_args_and_nonce(
@@ -700,7 +700,7 @@  discard block
 block discarded – undo
700 700
                                         ),
701 701
                                         $link_text_and_title,
702 702
                                         $link_text_and_title,
703
-                                        'activate_' . $payment_method->slug(),
703
+                                        'activate_'.$payment_method->slug(),
704 704
                                         'espresso-button-green button-primary'
705 705
                                     )
706 706
                                 )
@@ -724,7 +724,7 @@  discard block
 block discarded – undo
724 724
     {
725 725
         return new EE_Form_Section_HTML(
726 726
             EEH_HTML::tr(
727
-                EEH_HTML::th() .
727
+                EEH_HTML::th().
728 728
                 EEH_HTML::td(
729 729
                     EEH_HTML::p(__('All fields marked with a * are required fields', 'event_espresso'), '', 'grey-text')
730 730
                 )
@@ -807,7 +807,7 @@  discard block
 block discarded – undo
807 807
                 }
808 808
             }
809 809
             // if we couldn't find the correct payment method type...
810
-            if (! $correct_pmt_form_to_use) {
810
+            if ( ! $correct_pmt_form_to_use) {
811 811
                 EE_Error::add_error(
812 812
                     __(
813 813
                         "We could not find which payment method type your form submission related to. Please contact support",
@@ -822,7 +822,7 @@  discard block
 block discarded – undo
822 822
             $correct_pmt_form_to_use->receive_form_submission($this->_req_data);
823 823
             if ($correct_pmt_form_to_use->is_valid()) {
824 824
                 $payment_settings_subform = $correct_pmt_form_to_use->get_subsection('payment_method_settings');
825
-                if (! $payment_settings_subform instanceof EE_Payment_Method_Form) {
825
+                if ( ! $payment_settings_subform instanceof EE_Payment_Method_Form) {
826 826
                     throw new EE_Error(
827 827
                         sprintf(
828 828
                             __(
@@ -874,7 +874,7 @@  discard block
 block discarded – undo
874 874
         $form = $this->getPaymentSettingsForm();
875 875
         $this->_set_add_edit_form_tags('update_payment_settings');
876 876
         $this->_set_publish_post_box_vars(null, false, false, null, false);
877
-        $this->_template_args['admin_page_content'] =  $form->get_html_and_js();
877
+        $this->_template_args['admin_page_content'] = $form->get_html_and_js();
878 878
         $this->display_admin_page_with_sidebar();
879 879
     }
880 880
 
@@ -910,7 +910,7 @@  discard block
 block discarded – undo
910 910
             EE_Registry::instance()->CFG
911 911
         );
912 912
 
913
-        $cfg =  EE_Registry::instance()->CFG ;
913
+        $cfg = EE_Registry::instance()->CFG;
914 914
 
915 915
         $what = __('Payment Settings', 'event_espresso');
916 916
         $success = $this->_update_espresso_configuration(
@@ -1011,7 +1011,7 @@  discard block
 block discarded – undo
1011 1011
         }
1012 1012
         // take into account search
1013 1013
         if (isset($this->_req_data['s']) && $this->_req_data['s']) {
1014
-            $similarity_string = array('LIKE', '%' . str_replace("", "%", $this->_req_data['s']) . '%');
1014
+            $similarity_string = array('LIKE', '%'.str_replace("", "%", $this->_req_data['s']).'%');
1015 1015
             $query_params[0]['OR*s']['Payment.Transaction.Registration.Attendee.ATT_fname'] = $similarity_string;
1016 1016
             $query_params[0]['OR*s']['Payment.Transaction.Registration.Attendee.ATT_lname'] = $similarity_string;
1017 1017
             $query_params[0]['OR*s']['Payment.Transaction.Registration.Attendee.ATT_email'] = $similarity_string;
@@ -1031,8 +1031,8 @@  discard block
 block discarded – undo
1031 1031
             $start_date = wp_strip_all_tags($this->_req_data['payment-filter-start-date']);
1032 1032
             $end_date = wp_strip_all_tags($this->_req_data['payment-filter-end-date']);
1033 1033
             // make sure our timestamps start and end right at the boundaries for each day
1034
-            $start_date = date('Y-m-d', strtotime($start_date)) . ' 00:00:00';
1035
-            $end_date = date('Y-m-d', strtotime($end_date)) . ' 23:59:59';
1034
+            $start_date = date('Y-m-d', strtotime($start_date)).' 00:00:00';
1035
+            $end_date = date('Y-m-d', strtotime($end_date)).' 23:59:59';
1036 1036
             // convert to timestamps
1037 1037
             $start_date = strtotime($start_date);
1038 1038
             $end_date = strtotime($end_date);
@@ -1065,15 +1065,15 @@  discard block
 block discarded – undo
1065 1065
             $query_params['order_by'] = array('LOG_time' => 'DESC');
1066 1066
         }
1067 1067
         $offset = ($current_page - 1) * $per_page;
1068
-        if (! isset($this->_req_data['download_results'])) {
1068
+        if ( ! isset($this->_req_data['download_results'])) {
1069 1069
             $query_params['limit'] = array($offset, $per_page);
1070 1070
         }
1071 1071
         // now they've requested to instead just download the file instead of viewing it.
1072 1072
         if (isset($this->_req_data['download_results'])) {
1073 1073
             $wpdb_results = EEM_Change_Log::instance()->get_all_efficiently($query_params);
1074 1074
             header('Content-Disposition: attachment');
1075
-            header("Content-Disposition: attachment; filename=ee_payment_logs_for_" . sanitize_key(site_url()));
1076
-            echo "<h1>Payment Logs for " . site_url() . "</h1>";
1075
+            header("Content-Disposition: attachment; filename=ee_payment_logs_for_".sanitize_key(site_url()));
1076
+            echo "<h1>Payment Logs for ".site_url()."</h1>";
1077 1077
             echo "<h3>Query:</h3>";
1078 1078
             var_dump($query_params);
1079 1079
             echo "<h3>Results:</h3>";
@@ -1125,7 +1125,7 @@  discard block
 block discarded – undo
1125 1125
             }
1126 1126
         }
1127 1127
         $this->_template_args['admin_page_content'] = EEH_Template::display_template(
1128
-            EE_PAYMENTS_TEMPLATE_PATH . 'payment_log_details.template.php',
1128
+            EE_PAYMENTS_TEMPLATE_PATH.'payment_log_details.template.php',
1129 1129
             array(
1130 1130
                 'payment_log'    => $payment_log,
1131 1131
                 'payment_method' => $payment_method,
Please login to merge, or discard this patch.
core/EE_Config.core.php 1 patch
Indentation   +3044 added lines, -3044 removed lines patch added patch discarded remove patch
@@ -13,2438 +13,2438 @@  discard block
 block discarded – undo
13 13
 final class EE_Config implements ResettableInterface
14 14
 {
15 15
 
16
-    const OPTION_NAME = 'ee_config';
17
-
18
-    const LOG_NAME = 'ee_config_log';
19
-
20
-    const LOG_LENGTH = 100;
21
-
22
-    const ADDON_OPTION_NAMES = 'ee_config_option_names';
23
-
24
-
25
-    /**
26
-     *    instance of the EE_Config object
27
-     *
28
-     * @var    EE_Config $_instance
29
-     * @access    private
30
-     */
31
-    private static $_instance;
32
-
33
-    /**
34
-     * @var boolean $_logging_enabled
35
-     */
36
-    private static $_logging_enabled = false;
37
-
38
-    /**
39
-     * @var LegacyShortcodesManager $legacy_shortcodes_manager
40
-     */
41
-    private $legacy_shortcodes_manager;
42
-
43
-    /**
44
-     * An StdClass whose property names are addon slugs,
45
-     * and values are their config classes
46
-     *
47
-     * @var StdClass
48
-     */
49
-    public $addons;
50
-
51
-    /**
52
-     * @var EE_Admin_Config
53
-     */
54
-    public $admin;
55
-
56
-    /**
57
-     * @var EE_Core_Config
58
-     */
59
-    public $core;
60
-
61
-    /**
62
-     * @var EE_Currency_Config
63
-     */
64
-    public $currency;
65
-
66
-    /**
67
-     * @var EE_Organization_Config
68
-     */
69
-    public $organization;
70
-
71
-    /**
72
-     * @var EE_Registration_Config
73
-     */
74
-    public $registration;
75
-
76
-    /**
77
-     * @var EE_Template_Config
78
-     */
79
-    public $template_settings;
80
-
81
-    /**
82
-     * Holds EE environment values.
83
-     *
84
-     * @var EE_Environment_Config
85
-     */
86
-    public $environment;
87
-
88
-    /**
89
-     * settings pertaining to Google maps
90
-     *
91
-     * @var EE_Map_Config
92
-     */
93
-    public $map_settings;
94
-
95
-    /**
96
-     * settings pertaining to Taxes
97
-     *
98
-     * @var EE_Tax_Config
99
-     */
100
-    public $tax_settings;
101
-
102
-
103
-    /**
104
-     * Settings pertaining to global messages settings.
105
-     *
106
-     * @var EE_Messages_Config
107
-     */
108
-    public $messages;
109
-
110
-    /**
111
-     * @deprecated
112
-     * @var EE_Gateway_Config
113
-     */
114
-    public $gateway;
115
-
116
-    /**
117
-     * @var    array $_addon_option_names
118
-     * @access    private
119
-     */
120
-    private $_addon_option_names = array();
121
-
122
-    /**
123
-     * @var    array $_module_route_map
124
-     * @access    private
125
-     */
126
-    private static $_module_route_map = array();
127
-
128
-    /**
129
-     * @var    array $_module_forward_map
130
-     * @access    private
131
-     */
132
-    private static $_module_forward_map = array();
133
-
134
-    /**
135
-     * @var    array $_module_view_map
136
-     * @access    private
137
-     */
138
-    private static $_module_view_map = array();
139
-
140
-
141
-    /**
142
-     * @singleton method used to instantiate class object
143
-     * @access    public
144
-     * @return EE_Config instance
145
-     */
146
-    public static function instance()
147
-    {
148
-        // check if class object is instantiated, and instantiated properly
149
-        if (! self::$_instance instanceof EE_Config) {
150
-            self::$_instance = new self();
151
-        }
152
-        return self::$_instance;
153
-    }
154
-
155
-
156
-    /**
157
-     * Resets the config
158
-     *
159
-     * @param bool    $hard_reset    if TRUE, sets EE_CONFig back to its original settings in the database. If FALSE
160
-     *                               (default) leaves the database alone, and merely resets the EE_Config object to
161
-     *                               reflect its state in the database
162
-     * @param boolean $reinstantiate if TRUE (default) call instance() and return it. Otherwise, just leave
163
-     *                               $_instance as NULL. Useful in case you want to forget about the old instance on
164
-     *                               EE_Config, but might not be ready to instantiate EE_Config currently (eg if the
165
-     *                               site was put into maintenance mode)
166
-     * @return EE_Config
167
-     */
168
-    public static function reset($hard_reset = false, $reinstantiate = true)
169
-    {
170
-        if (self::$_instance instanceof EE_Config) {
171
-            if ($hard_reset) {
172
-                self::$_instance->legacy_shortcodes_manager = null;
173
-                self::$_instance->_addon_option_names = array();
174
-                self::$_instance->_initialize_config();
175
-                self::$_instance->update_espresso_config();
176
-            }
177
-            self::$_instance->update_addon_option_names();
178
-        }
179
-        self::$_instance = null;
180
-        // we don't need to reset the static properties imo because those should
181
-        // only change when a module is added or removed. Currently we don't
182
-        // support removing a module during a request when it previously existed
183
-        if ($reinstantiate) {
184
-            return self::instance();
185
-        } else {
186
-            return null;
187
-        }
188
-    }
189
-
190
-
191
-    /**
192
-     *    class constructor
193
-     *
194
-     * @access    private
195
-     */
196
-    private function __construct()
197
-    {
198
-        do_action('AHEE__EE_Config__construct__begin', $this);
199
-        EE_Config::$_logging_enabled = apply_filters('FHEE__EE_Config___construct__logging_enabled', false);
200
-        // setup empty config classes
201
-        $this->_initialize_config();
202
-        // load existing EE site settings
203
-        $this->_load_core_config();
204
-        // confirm everything loaded correctly and set filtered defaults if not
205
-        $this->_verify_config();
206
-        //  register shortcodes and modules
207
-        add_action(
208
-            'AHEE__EE_System__register_shortcodes_modules_and_widgets',
209
-            array($this, 'register_shortcodes_and_modules'),
210
-            999
211
-        );
212
-        //  initialize shortcodes and modules
213
-        add_action('AHEE__EE_System__core_loaded_and_ready', array($this, 'initialize_shortcodes_and_modules'));
214
-        // register widgets
215
-        add_action('widgets_init', array($this, 'widgets_init'), 10);
216
-        // shutdown
217
-        add_action('shutdown', array($this, 'shutdown'), 10);
218
-        // construct__end hook
219
-        do_action('AHEE__EE_Config__construct__end', $this);
220
-        // hardcoded hack
221
-        $this->template_settings->current_espresso_theme = 'Espresso_Arabica_2014';
222
-    }
223
-
224
-
225
-    /**
226
-     * @return boolean
227
-     */
228
-    public static function logging_enabled()
229
-    {
230
-        return self::$_logging_enabled;
231
-    }
232
-
233
-
234
-    /**
235
-     * use to get the current theme if needed from static context
236
-     *
237
-     * @return string current theme set.
238
-     */
239
-    public static function get_current_theme()
240
-    {
241
-        return isset(self::$_instance->template_settings->current_espresso_theme)
242
-            ? self::$_instance->template_settings->current_espresso_theme : 'Espresso_Arabica_2014';
243
-    }
244
-
245
-
246
-    /**
247
-     *        _initialize_config
248
-     *
249
-     * @access private
250
-     * @return void
251
-     */
252
-    private function _initialize_config()
253
-    {
254
-        EE_Config::trim_log();
255
-        // set defaults
256
-        $this->_addon_option_names = get_option(EE_Config::ADDON_OPTION_NAMES, array());
257
-        $this->addons = new stdClass();
258
-        // set _module_route_map
259
-        EE_Config::$_module_route_map = array();
260
-        // set _module_forward_map
261
-        EE_Config::$_module_forward_map = array();
262
-        // set _module_view_map
263
-        EE_Config::$_module_view_map = array();
264
-    }
265
-
266
-
267
-    /**
268
-     *        load core plugin configuration
269
-     *
270
-     * @access private
271
-     * @return void
272
-     */
273
-    private function _load_core_config()
274
-    {
275
-        // load_core_config__start hook
276
-        do_action('AHEE__EE_Config___load_core_config__start', $this);
277
-        $espresso_config = $this->get_espresso_config();
278
-        foreach ($espresso_config as $config => $settings) {
279
-            // load_core_config__start hook
280
-            $settings = apply_filters(
281
-                'FHEE__EE_Config___load_core_config__config_settings',
282
-                $settings,
283
-                $config,
284
-                $this
285
-            );
286
-            if (is_object($settings) && property_exists($this, $config)) {
287
-                $this->{$config} = apply_filters('FHEE__EE_Config___load_core_config__' . $config, $settings);
288
-                // call configs populate method to ensure any defaults are set for empty values.
289
-                if (method_exists($settings, 'populate')) {
290
-                    $this->{$config}->populate();
291
-                }
292
-                if (method_exists($settings, 'do_hooks')) {
293
-                    $this->{$config}->do_hooks();
294
-                }
295
-            }
296
-        }
297
-        if (apply_filters('FHEE__EE_Config___load_core_config__update_espresso_config', false)) {
298
-            $this->update_espresso_config();
299
-        }
300
-        // load_core_config__end hook
301
-        do_action('AHEE__EE_Config___load_core_config__end', $this);
302
-    }
303
-
304
-
305
-    /**
306
-     *    _verify_config
307
-     *
308
-     * @access    protected
309
-     * @return    void
310
-     */
311
-    protected function _verify_config()
312
-    {
313
-        $this->core = $this->core instanceof EE_Core_Config
314
-            ? $this->core
315
-            : new EE_Core_Config();
316
-        $this->core = apply_filters('FHEE__EE_Config___initialize_config__core', $this->core);
317
-        $this->organization = $this->organization instanceof EE_Organization_Config
318
-            ? $this->organization
319
-            : new EE_Organization_Config();
320
-        $this->organization = apply_filters(
321
-            'FHEE__EE_Config___initialize_config__organization',
322
-            $this->organization
323
-        );
324
-        $this->currency = $this->currency instanceof EE_Currency_Config
325
-            ? $this->currency
326
-            : new EE_Currency_Config();
327
-        $this->currency = apply_filters('FHEE__EE_Config___initialize_config__currency', $this->currency);
328
-        $this->registration = $this->registration instanceof EE_Registration_Config
329
-            ? $this->registration
330
-            : new EE_Registration_Config();
331
-        $this->registration = apply_filters(
332
-            'FHEE__EE_Config___initialize_config__registration',
333
-            $this->registration
334
-        );
335
-        $this->admin = $this->admin instanceof EE_Admin_Config
336
-            ? $this->admin
337
-            : new EE_Admin_Config();
338
-        $this->admin = apply_filters('FHEE__EE_Config___initialize_config__admin', $this->admin);
339
-        $this->template_settings = $this->template_settings instanceof EE_Template_Config
340
-            ? $this->template_settings
341
-            : new EE_Template_Config();
342
-        $this->template_settings = apply_filters(
343
-            'FHEE__EE_Config___initialize_config__template_settings',
344
-            $this->template_settings
345
-        );
346
-        $this->map_settings = $this->map_settings instanceof EE_Map_Config
347
-            ? $this->map_settings
348
-            : new EE_Map_Config();
349
-        $this->map_settings = apply_filters(
350
-            'FHEE__EE_Config___initialize_config__map_settings',
351
-            $this->map_settings
352
-        );
353
-        $this->environment = $this->environment instanceof EE_Environment_Config
354
-            ? $this->environment
355
-            : new EE_Environment_Config();
356
-        $this->environment = apply_filters(
357
-            'FHEE__EE_Config___initialize_config__environment',
358
-            $this->environment
359
-        );
360
-        $this->tax_settings = $this->tax_settings instanceof EE_Tax_Config
361
-            ? $this->tax_settings
362
-            : new EE_Tax_Config();
363
-        $this->tax_settings = apply_filters(
364
-            'FHEE__EE_Config___initialize_config__tax_settings',
365
-            $this->tax_settings
366
-        );
367
-        $this->messages = apply_filters('FHEE__EE_Config__initialize_config__messages', $this->messages);
368
-        $this->messages = $this->messages instanceof EE_Messages_Config
369
-            ? $this->messages
370
-            : new EE_Messages_Config();
371
-        $this->gateway = $this->gateway instanceof EE_Gateway_Config
372
-            ? $this->gateway
373
-            : new EE_Gateway_Config();
374
-        $this->gateway = apply_filters('FHEE__EE_Config___initialize_config__gateway', $this->gateway);
375
-        $this->legacy_shortcodes_manager = null;
376
-    }
377
-
378
-
379
-    /**
380
-     *    get_espresso_config
381
-     *
382
-     * @access    public
383
-     * @return    array of espresso config stuff
384
-     */
385
-    public function get_espresso_config()
386
-    {
387
-        // grab espresso configuration
388
-        return apply_filters(
389
-            'FHEE__EE_Config__get_espresso_config__CFG',
390
-            get_option(EE_Config::OPTION_NAME, array())
391
-        );
392
-    }
393
-
394
-
395
-    /**
396
-     *    double_check_config_comparison
397
-     *
398
-     * @access    public
399
-     * @param string $option
400
-     * @param        $old_value
401
-     * @param        $value
402
-     */
403
-    public function double_check_config_comparison($option = '', $old_value, $value)
404
-    {
405
-        // make sure we're checking the ee config
406
-        if ($option === EE_Config::OPTION_NAME) {
407
-            // run a loose comparison of the old value against the new value for type and properties,
408
-            // but NOT exact instance like WP update_option does (ie: NOT type safe comparison)
409
-            if ($value != $old_value) {
410
-                // if they are NOT the same, then remove the hook,
411
-                // which means the subsequent update results will be based solely on the update query results
412
-                // the reason we do this is because, as stated above,
413
-                // WP update_option performs an exact instance comparison (===) on any update values passed to it
414
-                // this happens PRIOR to serialization and any subsequent update.
415
-                // If values are found to match their previous old value,
416
-                // then WP bails before performing any update.
417
-                // Since we are passing the EE_Config object, it is comparing the EXACT instance of the saved version
418
-                // it just pulled from the db, with the one being passed to it (which will not match).
419
-                // HOWEVER, once the object is serialized and passed off to MySQL to update,
420
-                // MySQL MAY ALSO NOT perform the update because
421
-                // the string it sees in the db looks the same as the new one it has been passed!!!
422
-                // This results in the query returning an "affected rows" value of ZERO,
423
-                // which gets returned immediately by WP update_option and looks like an error.
424
-                remove_action('update_option', array($this, 'check_config_updated'));
425
-            }
426
-        }
427
-    }
428
-
429
-
430
-    /**
431
-     *    update_espresso_config
432
-     *
433
-     * @access   public
434
-     */
435
-    protected function _reset_espresso_addon_config()
436
-    {
437
-        $this->_addon_option_names = array();
438
-        foreach ($this->addons as $addon_name => $addon_config_obj) {
439
-            $addon_config_obj = maybe_unserialize($addon_config_obj);
440
-            if ($addon_config_obj instanceof EE_Config_Base) {
441
-                $this->update_config('addons', $addon_name, $addon_config_obj, false);
442
-            }
443
-            $this->addons->{$addon_name} = null;
444
-        }
445
-    }
446
-
447
-
448
-    /**
449
-     *    update_espresso_config
450
-     *
451
-     * @access   public
452
-     * @param   bool $add_success
453
-     * @param   bool $add_error
454
-     * @return   bool
455
-     */
456
-    public function update_espresso_config($add_success = false, $add_error = true)
457
-    {
458
-        // don't allow config updates during WP heartbeats
459
-        if (\EE_Registry::instance()->REQ->get('action', '') === 'heartbeat') {
460
-            return false;
461
-        }
462
-        // commented out the following re: https://events.codebasehq.com/projects/event-espresso/tickets/8197
463
-        // $clone = clone( self::$_instance );
464
-        // self::$_instance = NULL;
465
-        do_action('AHEE__EE_Config__update_espresso_config__begin', $this);
466
-        $this->_reset_espresso_addon_config();
467
-        // hook into update_option because that happens AFTER the ( $value === $old_value ) conditional
468
-        // but BEFORE the actual update occurs
469
-        add_action('update_option', array($this, 'double_check_config_comparison'), 1, 3);
470
-        // don't want to persist legacy_shortcodes_manager, but don't want to lose it either
471
-        $legacy_shortcodes_manager = $this->legacy_shortcodes_manager;
472
-        $this->legacy_shortcodes_manager = null;
473
-        // now update "ee_config"
474
-        $saved = update_option(EE_Config::OPTION_NAME, $this);
475
-        $this->legacy_shortcodes_manager = $legacy_shortcodes_manager;
476
-        EE_Config::log(EE_Config::OPTION_NAME);
477
-        // if not saved... check if the hook we just added still exists;
478
-        // if it does, it means one of two things:
479
-        // that update_option bailed at the($value === $old_value) conditional,
480
-        // or...
481
-        // the db update query returned 0 rows affected
482
-        // (probably because the data  value was the same from it's perspective)
483
-        // so the existence of the hook means that a negative result from update_option is NOT an error,
484
-        // but just means no update occurred, so don't display an error to the user.
485
-        // BUT... if update_option returns FALSE, AND the hook is missing,
486
-        // then it means that something truly went wrong
487
-        $saved = ! $saved ? has_action('update_option', array($this, 'double_check_config_comparison')) : $saved;
488
-        // remove our action since we don't want it in the system anymore
489
-        remove_action('update_option', array($this, 'double_check_config_comparison'), 1);
490
-        do_action('AHEE__EE_Config__update_espresso_config__end', $this, $saved);
491
-        // self::$_instance = $clone;
492
-        // unset( $clone );
493
-        // if config remains the same or was updated successfully
494
-        if ($saved) {
495
-            if ($add_success) {
496
-                EE_Error::add_success(
497
-                    __('The Event Espresso Configuration Settings have been successfully updated.', 'event_espresso'),
498
-                    __FILE__,
499
-                    __FUNCTION__,
500
-                    __LINE__
501
-                );
502
-            }
503
-            return true;
504
-        } else {
505
-            if ($add_error) {
506
-                EE_Error::add_error(
507
-                    __('The Event Espresso Configuration Settings were not updated.', 'event_espresso'),
508
-                    __FILE__,
509
-                    __FUNCTION__,
510
-                    __LINE__
511
-                );
512
-            }
513
-            return false;
514
-        }
515
-    }
516
-
517
-
518
-    /**
519
-     *    _verify_config_params
520
-     *
521
-     * @access    private
522
-     * @param    string         $section
523
-     * @param    string         $name
524
-     * @param    string         $config_class
525
-     * @param    EE_Config_Base $config_obj
526
-     * @param    array          $tests_to_run
527
-     * @param    bool           $display_errors
528
-     * @return    bool    TRUE on success, FALSE on fail
529
-     */
530
-    private function _verify_config_params(
531
-        $section = '',
532
-        $name = '',
533
-        $config_class = '',
534
-        $config_obj = null,
535
-        $tests_to_run = array(1, 2, 3, 4, 5, 6, 7, 8),
536
-        $display_errors = true
537
-    ) {
538
-        try {
539
-            foreach ($tests_to_run as $test) {
540
-                switch ($test) {
541
-                    // TEST #1 : check that section was set
542
-                    case 1:
543
-                        if (empty($section)) {
544
-                            if ($display_errors) {
545
-                                throw new EE_Error(
546
-                                    sprintf(
547
-                                        __(
548
-                                            'No configuration section has been provided while attempting to save "%s".',
549
-                                            'event_espresso'
550
-                                        ),
551
-                                        $config_class
552
-                                    )
553
-                                );
554
-                            }
555
-                            return false;
556
-                        }
557
-                        break;
558
-                    // TEST #2 : check that settings section exists
559
-                    case 2:
560
-                        if (! isset($this->{$section})) {
561
-                            if ($display_errors) {
562
-                                throw new EE_Error(
563
-                                    sprintf(
564
-                                        __('The "%s" configuration section does not exist.', 'event_espresso'),
565
-                                        $section
566
-                                    )
567
-                                );
568
-                            }
569
-                            return false;
570
-                        }
571
-                        break;
572
-                    // TEST #3 : check that section is the proper format
573
-                    case 3:
574
-                        if (! ($this->{$section} instanceof EE_Config_Base || $this->{$section} instanceof stdClass)
575
-                        ) {
576
-                            if ($display_errors) {
577
-                                throw new EE_Error(
578
-                                    sprintf(
579
-                                        __(
580
-                                            'The "%s" configuration settings have not been formatted correctly.',
581
-                                            'event_espresso'
582
-                                        ),
583
-                                        $section
584
-                                    )
585
-                                );
586
-                            }
587
-                            return false;
588
-                        }
589
-                        break;
590
-                    // TEST #4 : check that config section name has been set
591
-                    case 4:
592
-                        if (empty($name)) {
593
-                            if ($display_errors) {
594
-                                throw new EE_Error(
595
-                                    __(
596
-                                        'No name has been provided for the specific configuration section.',
597
-                                        'event_espresso'
598
-                                    )
599
-                                );
600
-                            }
601
-                            return false;
602
-                        }
603
-                        break;
604
-                    // TEST #5 : check that a config class name has been set
605
-                    case 5:
606
-                        if (empty($config_class)) {
607
-                            if ($display_errors) {
608
-                                throw new EE_Error(
609
-                                    __(
610
-                                        'No class name has been provided for the specific configuration section.',
611
-                                        'event_espresso'
612
-                                    )
613
-                                );
614
-                            }
615
-                            return false;
616
-                        }
617
-                        break;
618
-                    // TEST #6 : verify config class is accessible
619
-                    case 6:
620
-                        if (! class_exists($config_class)) {
621
-                            if ($display_errors) {
622
-                                throw new EE_Error(
623
-                                    sprintf(
624
-                                        __(
625
-                                            'The "%s" class does not exist. Please ensure that an autoloader has been set for it.',
626
-                                            'event_espresso'
627
-                                        ),
628
-                                        $config_class
629
-                                    )
630
-                                );
631
-                            }
632
-                            return false;
633
-                        }
634
-                        break;
635
-                    // TEST #7 : check that config has even been set
636
-                    case 7:
637
-                        if (! isset($this->{$section}->{$name})) {
638
-                            if ($display_errors) {
639
-                                throw new EE_Error(
640
-                                    sprintf(
641
-                                        __('No configuration has been set for "%1$s->%2$s".', 'event_espresso'),
642
-                                        $section,
643
-                                        $name
644
-                                    )
645
-                                );
646
-                            }
647
-                            return false;
648
-                        } else {
649
-                            // and make sure it's not serialized
650
-                            $this->{$section}->{$name} = maybe_unserialize($this->{$section}->{$name});
651
-                        }
652
-                        break;
653
-                    // TEST #8 : check that config is the requested type
654
-                    case 8:
655
-                        if (! $this->{$section}->{$name} instanceof $config_class) {
656
-                            if ($display_errors) {
657
-                                throw new EE_Error(
658
-                                    sprintf(
659
-                                        __(
660
-                                            'The configuration for "%1$s->%2$s" is not of the "%3$s" class.',
661
-                                            'event_espresso'
662
-                                        ),
663
-                                        $section,
664
-                                        $name,
665
-                                        $config_class
666
-                                    )
667
-                                );
668
-                            }
669
-                            return false;
670
-                        }
671
-                        break;
672
-                    // TEST #9 : verify config object
673
-                    case 9:
674
-                        if (! $config_obj instanceof EE_Config_Base) {
675
-                            if ($display_errors) {
676
-                                throw new EE_Error(
677
-                                    sprintf(
678
-                                        __('The "%s" class is not an instance of EE_Config_Base.', 'event_espresso'),
679
-                                        print_r($config_obj, true)
680
-                                    )
681
-                                );
682
-                            }
683
-                            return false;
684
-                        }
685
-                        break;
686
-                }
687
-            }
688
-        } catch (EE_Error $e) {
689
-            $e->get_error();
690
-        }
691
-        // you have successfully run the gauntlet
692
-        return true;
693
-    }
694
-
695
-
696
-    /**
697
-     *    _generate_config_option_name
698
-     *
699
-     * @access        protected
700
-     * @param        string $section
701
-     * @param        string $name
702
-     * @return        string
703
-     */
704
-    private function _generate_config_option_name($section = '', $name = '')
705
-    {
706
-        return 'ee_config-' . strtolower($section . '-' . str_replace(array('EE_', 'EED_'), '', $name));
707
-    }
708
-
709
-
710
-    /**
711
-     *    _set_config_class
712
-     * ensures that a config class is set, either from a passed config class or one generated from the config name
713
-     *
714
-     * @access    private
715
-     * @param    string $config_class
716
-     * @param    string $name
717
-     * @return    string
718
-     */
719
-    private function _set_config_class($config_class = '', $name = '')
720
-    {
721
-        return ! empty($config_class)
722
-            ? $config_class
723
-            : str_replace(' ', '_', ucwords(str_replace('_', ' ', $name))) . '_Config';
724
-    }
725
-
726
-
727
-    /**
728
-     *    set_config
729
-     *
730
-     * @access    protected
731
-     * @param    string         $section
732
-     * @param    string         $name
733
-     * @param    string         $config_class
734
-     * @param    EE_Config_Base $config_obj
735
-     * @return    EE_Config_Base
736
-     */
737
-    public function set_config($section = '', $name = '', $config_class = '', EE_Config_Base $config_obj = null)
738
-    {
739
-        // ensure config class is set to something
740
-        $config_class = $this->_set_config_class($config_class, $name);
741
-        // run tests 1-4, 6, and 7 to verify all config params are set and valid
742
-        if (! $this->_verify_config_params($section, $name, $config_class, null, array(1, 2, 3, 4, 5, 6))) {
743
-            return null;
744
-        }
745
-        $config_option_name = $this->_generate_config_option_name($section, $name);
746
-        // if the config option name hasn't been added yet to the list of option names we're tracking, then do so now
747
-        if (! isset($this->_addon_option_names[ $config_option_name ])) {
748
-            $this->_addon_option_names[ $config_option_name ] = $config_class;
749
-            $this->update_addon_option_names();
750
-        }
751
-        // verify the incoming config object but suppress errors
752
-        if (! $this->_verify_config_params($section, $name, $config_class, $config_obj, array(9), false)) {
753
-            $config_obj = new $config_class();
754
-        }
755
-        if (get_option($config_option_name)) {
756
-            EE_Config::log($config_option_name);
757
-            update_option($config_option_name, $config_obj);
758
-            $this->{$section}->{$name} = $config_obj;
759
-            return $this->{$section}->{$name};
760
-        } else {
761
-            // create a wp-option for this config
762
-            if (add_option($config_option_name, $config_obj, '', 'no')) {
763
-                $this->{$section}->{$name} = maybe_unserialize($config_obj);
764
-                return $this->{$section}->{$name};
765
-            } else {
766
-                EE_Error::add_error(
767
-                    sprintf(__('The "%s" could not be saved to the database.', 'event_espresso'), $config_class),
768
-                    __FILE__,
769
-                    __FUNCTION__,
770
-                    __LINE__
771
-                );
772
-                return null;
773
-            }
774
-        }
775
-    }
776
-
777
-
778
-    /**
779
-     *    update_config
780
-     * Important: the config object must ALREADY be set, otherwise this will produce an error.
781
-     *
782
-     * @access    public
783
-     * @param    string                $section
784
-     * @param    string                $name
785
-     * @param    EE_Config_Base|string $config_obj
786
-     * @param    bool                  $throw_errors
787
-     * @return    bool
788
-     */
789
-    public function update_config($section = '', $name = '', $config_obj = '', $throw_errors = true)
790
-    {
791
-        // don't allow config updates during WP heartbeats
792
-        if (\EE_Registry::instance()->REQ->get('action', '') === 'heartbeat') {
793
-            return false;
794
-        }
795
-        $config_obj = maybe_unserialize($config_obj);
796
-        // get class name of the incoming object
797
-        $config_class = get_class($config_obj);
798
-        // run tests 1-5 and 9 to verify config
799
-        if (! $this->_verify_config_params(
800
-            $section,
801
-            $name,
802
-            $config_class,
803
-            $config_obj,
804
-            array(1, 2, 3, 4, 7, 9)
805
-        )
806
-        ) {
807
-            return false;
808
-        }
809
-        $config_option_name = $this->_generate_config_option_name($section, $name);
810
-        // check if config object has been added to db by seeing if config option name is in $this->_addon_option_names array
811
-        if (! isset($this->_addon_option_names[ $config_option_name ])) {
812
-            // save new config to db
813
-            if ($this->set_config($section, $name, $config_class, $config_obj)) {
814
-                return true;
815
-            }
816
-        } else {
817
-            // first check if the record already exists
818
-            $existing_config = get_option($config_option_name);
819
-            $config_obj = serialize($config_obj);
820
-            // just return if db record is already up to date (NOT type safe comparison)
821
-            if ($existing_config == $config_obj) {
822
-                $this->{$section}->{$name} = $config_obj;
823
-                return true;
824
-            } elseif (update_option($config_option_name, $config_obj)) {
825
-                EE_Config::log($config_option_name);
826
-                // update wp-option for this config class
827
-                $this->{$section}->{$name} = $config_obj;
828
-                return true;
829
-            } elseif ($throw_errors) {
830
-                EE_Error::add_error(
831
-                    sprintf(
832
-                        __(
833
-                            'The "%1$s" object stored at"%2$s" was not successfully updated in the database.',
834
-                            'event_espresso'
835
-                        ),
836
-                        $config_class,
837
-                        'EE_Config->' . $section . '->' . $name
838
-                    ),
839
-                    __FILE__,
840
-                    __FUNCTION__,
841
-                    __LINE__
842
-                );
843
-            }
844
-        }
845
-        return false;
846
-    }
847
-
848
-
849
-    /**
850
-     *    get_config
851
-     *
852
-     * @access    public
853
-     * @param    string $section
854
-     * @param    string $name
855
-     * @param    string $config_class
856
-     * @return    mixed EE_Config_Base | NULL
857
-     */
858
-    public function get_config($section = '', $name = '', $config_class = '')
859
-    {
860
-        // ensure config class is set to something
861
-        $config_class = $this->_set_config_class($config_class, $name);
862
-        // run tests 1-4, 6 and 7 to verify that all params have been set
863
-        if (! $this->_verify_config_params($section, $name, $config_class, null, array(1, 2, 3, 4, 5, 6))) {
864
-            return null;
865
-        }
866
-        // now test if the requested config object exists, but suppress errors
867
-        if ($this->_verify_config_params($section, $name, $config_class, null, array(7, 8), false)) {
868
-            // config already exists, so pass it back
869
-            return $this->{$section}->{$name};
870
-        }
871
-        // load config option from db if it exists
872
-        $config_obj = $this->get_config_option($this->_generate_config_option_name($section, $name));
873
-        // verify the newly retrieved config object, but suppress errors
874
-        if ($this->_verify_config_params($section, $name, $config_class, $config_obj, array(9), false)) {
875
-            // config is good, so set it and pass it back
876
-            $this->{$section}->{$name} = $config_obj;
877
-            return $this->{$section}->{$name};
878
-        }
879
-        // oops! $config_obj is not already set and does not exist in the db, so create a new one
880
-        $config_obj = $this->set_config($section, $name, $config_class);
881
-        // verify the newly created config object
882
-        if ($this->_verify_config_params($section, $name, $config_class, $config_obj, array(9))) {
883
-            return $this->{$section}->{$name};
884
-        } else {
885
-            EE_Error::add_error(
886
-                sprintf(__('The "%s" could not be retrieved from the database.', 'event_espresso'), $config_class),
887
-                __FILE__,
888
-                __FUNCTION__,
889
-                __LINE__
890
-            );
891
-        }
892
-        return null;
893
-    }
894
-
895
-
896
-    /**
897
-     *    get_config_option
898
-     *
899
-     * @access    public
900
-     * @param    string $config_option_name
901
-     * @return    mixed EE_Config_Base | FALSE
902
-     */
903
-    public function get_config_option($config_option_name = '')
904
-    {
905
-        // retrieve the wp-option for this config class.
906
-        $config_option = maybe_unserialize(get_option($config_option_name, array()));
907
-        if (empty($config_option)) {
908
-            EE_Config::log($config_option_name . '-NOT-FOUND');
909
-        }
910
-        return $config_option;
911
-    }
912
-
913
-
914
-    /**
915
-     * log
916
-     *
917
-     * @param string $config_option_name
918
-     */
919
-    public static function log($config_option_name = '')
920
-    {
921
-        if (EE_Config::logging_enabled() && ! empty($config_option_name)) {
922
-            $config_log = get_option(EE_Config::LOG_NAME, array());
923
-            // copy incoming $_REQUEST and sanitize it so we can save it
924
-            $_request = $_REQUEST;
925
-            array_walk_recursive($_request, 'sanitize_text_field');
926
-            $config_log[ (string) microtime(true) ] = array(
927
-                'config_name' => $config_option_name,
928
-                'request'     => $_request,
929
-            );
930
-            update_option(EE_Config::LOG_NAME, $config_log);
931
-        }
932
-    }
933
-
934
-
935
-    /**
936
-     * trim_log
937
-     * reduces the size of the config log to the length specified by EE_Config::LOG_LENGTH
938
-     */
939
-    public static function trim_log()
940
-    {
941
-        if (! EE_Config::logging_enabled()) {
942
-            return;
943
-        }
944
-        $config_log = maybe_unserialize(get_option(EE_Config::LOG_NAME, array()));
945
-        $log_length = count($config_log);
946
-        if ($log_length > EE_Config::LOG_LENGTH) {
947
-            ksort($config_log);
948
-            $config_log = array_slice($config_log, $log_length - EE_Config::LOG_LENGTH, null, true);
949
-            update_option(EE_Config::LOG_NAME, $config_log);
950
-        }
951
-    }
952
-
953
-
954
-    /**
955
-     *    get_page_for_posts
956
-     *    if the wp-option "show_on_front" is set to "page", then this is the post_name for the post set in the
957
-     *    wp-option "page_for_posts", or "posts" if no page is selected
958
-     *
959
-     * @access    public
960
-     * @return    string
961
-     */
962
-    public static function get_page_for_posts()
963
-    {
964
-        $page_for_posts = get_option('page_for_posts');
965
-        if (! $page_for_posts) {
966
-            return 'posts';
967
-        }
968
-        /** @type WPDB $wpdb */
969
-        global $wpdb;
970
-        $SQL = "SELECT post_name from $wpdb->posts WHERE post_type='posts' OR post_type='page' AND post_status='publish' AND ID=%d";
971
-        return $wpdb->get_var($wpdb->prepare($SQL, $page_for_posts));
972
-    }
973
-
974
-
975
-    /**
976
-     *    register_shortcodes_and_modules.
977
-     *    At this point, it's too early to tell if we're maintenance mode or not.
978
-     *    In fact, this is where we give modules a chance to let core know they exist
979
-     *    so they can help trigger maintenance mode if it's needed
980
-     *
981
-     * @access    public
982
-     * @return    void
983
-     */
984
-    public function register_shortcodes_and_modules()
985
-    {
986
-        // allow modules to set hooks for the rest of the system
987
-        EE_Registry::instance()->modules = $this->_register_modules();
988
-    }
989
-
990
-
991
-    /**
992
-     *    initialize_shortcodes_and_modules
993
-     *    meaning they can start adding their hooks to get stuff done
994
-     *
995
-     * @access    public
996
-     * @return    void
997
-     */
998
-    public function initialize_shortcodes_and_modules()
999
-    {
1000
-        // allow modules to set hooks for the rest of the system
1001
-        $this->_initialize_modules();
1002
-    }
1003
-
1004
-
1005
-    /**
1006
-     *    widgets_init
1007
-     *
1008
-     * @access private
1009
-     * @return void
1010
-     */
1011
-    public function widgets_init()
1012
-    {
1013
-        // only init widgets on admin pages when not in complete maintenance, and
1014
-        // on frontend when not in any maintenance mode
1015
-        if (! EE_Maintenance_Mode::instance()->level()
1016
-            || (
1017
-                is_admin()
1018
-                && EE_Maintenance_Mode::instance()->level() !== EE_Maintenance_Mode::level_2_complete_maintenance
1019
-            )
1020
-        ) {
1021
-            // grab list of installed widgets
1022
-            $widgets_to_register = glob(EE_WIDGETS . '*', GLOB_ONLYDIR);
1023
-            // filter list of modules to register
1024
-            $widgets_to_register = apply_filters(
1025
-                'FHEE__EE_Config__register_widgets__widgets_to_register',
1026
-                $widgets_to_register
1027
-            );
1028
-            if (! empty($widgets_to_register)) {
1029
-                // cycle thru widget folders
1030
-                foreach ($widgets_to_register as $widget_path) {
1031
-                    // add to list of installed widget modules
1032
-                    EE_Config::register_ee_widget($widget_path);
1033
-                }
1034
-            }
1035
-            // filter list of installed modules
1036
-            EE_Registry::instance()->widgets = apply_filters(
1037
-                'FHEE__EE_Config__register_widgets__installed_widgets',
1038
-                EE_Registry::instance()->widgets
1039
-            );
1040
-        }
1041
-    }
1042
-
1043
-
1044
-    /**
1045
-     *    register_ee_widget - makes core aware of this widget
1046
-     *
1047
-     * @access    public
1048
-     * @param    string $widget_path - full path up to and including widget folder
1049
-     * @return    void
1050
-     */
1051
-    public static function register_ee_widget($widget_path = null)
1052
-    {
1053
-        do_action('AHEE__EE_Config__register_widget__begin', $widget_path);
1054
-        $widget_ext = '.widget.php';
1055
-        // make all separators match
1056
-        $widget_path = rtrim(str_replace('/\\', DS, $widget_path), DS);
1057
-        // does the file path INCLUDE the actual file name as part of the path ?
1058
-        if (strpos($widget_path, $widget_ext) !== false) {
1059
-            // grab and shortcode file name from directory name and break apart at dots
1060
-            $file_name = explode('.', basename($widget_path));
1061
-            // take first segment from file name pieces and remove class prefix if it exists
1062
-            $widget = strpos($file_name[0], 'EEW_') === 0 ? substr($file_name[0], 4) : $file_name[0];
1063
-            // sanitize shortcode directory name
1064
-            $widget = sanitize_key($widget);
1065
-            // now we need to rebuild the shortcode path
1066
-            $widget_path = explode(DS, $widget_path);
1067
-            // remove last segment
1068
-            array_pop($widget_path);
1069
-            // glue it back together
1070
-            $widget_path = implode(DS, $widget_path);
1071
-        } else {
1072
-            // grab and sanitize widget directory name
1073
-            $widget = sanitize_key(basename($widget_path));
1074
-        }
1075
-        // create classname from widget directory name
1076
-        $widget = str_replace(' ', '_', ucwords(str_replace('_', ' ', $widget)));
1077
-        // add class prefix
1078
-        $widget_class = 'EEW_' . $widget;
1079
-        // does the widget exist ?
1080
-        if (! is_readable($widget_path . DS . $widget_class . $widget_ext)) {
1081
-            $msg = sprintf(
1082
-                __(
1083
-                    'The requested %s widget file could not be found or is not readable due to file permissions. Please ensure the following path is correct: %s',
1084
-                    'event_espresso'
1085
-                ),
1086
-                $widget_class,
1087
-                $widget_path . DS . $widget_class . $widget_ext
1088
-            );
1089
-            EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__);
1090
-            return;
1091
-        }
1092
-        // load the widget class file
1093
-        require_once($widget_path . DS . $widget_class . $widget_ext);
1094
-        // verify that class exists
1095
-        if (! class_exists($widget_class)) {
1096
-            $msg = sprintf(__('The requested %s widget class does not exist.', 'event_espresso'), $widget_class);
1097
-            EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__);
1098
-            return;
1099
-        }
1100
-        register_widget($widget_class);
1101
-        // add to array of registered widgets
1102
-        EE_Registry::instance()->widgets->{$widget_class} = $widget_path . DS . $widget_class . $widget_ext;
1103
-    }
1104
-
1105
-
1106
-    /**
1107
-     *        _register_modules
1108
-     *
1109
-     * @access private
1110
-     * @return array
1111
-     */
1112
-    private function _register_modules()
1113
-    {
1114
-        // grab list of installed modules
1115
-        $modules_to_register = glob(EE_MODULES . '*', GLOB_ONLYDIR);
1116
-        // filter list of modules to register
1117
-        $modules_to_register = apply_filters(
1118
-            'FHEE__EE_Config__register_modules__modules_to_register',
1119
-            $modules_to_register
1120
-        );
1121
-        if (! empty($modules_to_register)) {
1122
-            // loop through folders
1123
-            foreach ($modules_to_register as $module_path) {
1124
-                /**TEMPORARILY EXCLUDE gateways from modules for time being**/
1125
-                if ($module_path !== EE_MODULES . 'zzz-copy-this-module-template'
1126
-                    && $module_path !== EE_MODULES . 'gateways'
1127
-                ) {
1128
-                    // add to list of installed modules
1129
-                    EE_Config::register_module($module_path);
1130
-                }
1131
-            }
1132
-        }
1133
-        // filter list of installed modules
1134
-        return apply_filters(
1135
-            'FHEE__EE_Config___register_modules__installed_modules',
1136
-            EE_Registry::instance()->modules
1137
-        );
1138
-    }
1139
-
1140
-
1141
-    /**
1142
-     *    register_module - makes core aware of this module
1143
-     *
1144
-     * @access    public
1145
-     * @param    string $module_path - full path up to and including module folder
1146
-     * @return    bool
1147
-     */
1148
-    public static function register_module($module_path = null)
1149
-    {
1150
-        do_action('AHEE__EE_Config__register_module__begin', $module_path);
1151
-        $module_ext = '.module.php';
1152
-        // make all separators match
1153
-        $module_path = str_replace(array('\\', '/'), DS, $module_path);
1154
-        // does the file path INCLUDE the actual file name as part of the path ?
1155
-        if (strpos($module_path, $module_ext) !== false) {
1156
-            // grab and shortcode file name from directory name and break apart at dots
1157
-            $module_file = explode('.', basename($module_path));
1158
-            // now we need to rebuild the shortcode path
1159
-            $module_path = explode(DS, $module_path);
1160
-            // remove last segment
1161
-            array_pop($module_path);
1162
-            // glue it back together
1163
-            $module_path = implode(DS, $module_path) . DS;
1164
-            // take first segment from file name pieces and sanitize it
1165
-            $module = preg_replace('/[^a-zA-Z0-9_\-]/', '', $module_file[0]);
1166
-            // ensure class prefix is added
1167
-            $module_class = strpos($module, 'EED_') !== 0 ? 'EED_' . $module : $module;
1168
-        } else {
1169
-            // we need to generate the filename based off of the folder name
1170
-            // grab and sanitize module name
1171
-            $module = strtolower(basename($module_path));
1172
-            $module = preg_replace('/[^a-z0-9_\-]/', '', $module);
1173
-            // like trailingslashit()
1174
-            $module_path = rtrim($module_path, DS) . DS;
1175
-            // create classname from module directory name
1176
-            $module = str_replace(' ', '_', ucwords(str_replace('_', ' ', $module)));
1177
-            // add class prefix
1178
-            $module_class = 'EED_' . $module;
1179
-        }
1180
-        // does the module exist ?
1181
-        if (! is_readable($module_path . DS . $module_class . $module_ext)) {
1182
-            $msg = sprintf(
1183
-                __(
1184
-                    'The requested %s module file could not be found or is not readable due to file permissions.',
1185
-                    'event_espresso'
1186
-                ),
1187
-                $module
1188
-            );
1189
-            EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__);
1190
-            return false;
1191
-        }
1192
-        // load the module class file
1193
-        require_once($module_path . $module_class . $module_ext);
1194
-        // verify that class exists
1195
-        if (! class_exists($module_class)) {
1196
-            $msg = sprintf(__('The requested %s module class does not exist.', 'event_espresso'), $module_class);
1197
-            EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__);
1198
-            return false;
1199
-        }
1200
-        // add to array of registered modules
1201
-        EE_Registry::instance()->modules->{$module_class} = $module_path . $module_class . $module_ext;
1202
-        do_action(
1203
-            'AHEE__EE_Config__register_module__complete',
1204
-            $module_class,
1205
-            EE_Registry::instance()->modules->{$module_class}
1206
-        );
1207
-        return true;
1208
-    }
1209
-
1210
-
1211
-    /**
1212
-     *    _initialize_modules
1213
-     *    allow modules to set hooks for the rest of the system
1214
-     *
1215
-     * @access private
1216
-     * @return void
1217
-     */
1218
-    private function _initialize_modules()
1219
-    {
1220
-        // cycle thru shortcode folders
1221
-        foreach (EE_Registry::instance()->modules as $module_class => $module_path) {
1222
-            // fire the shortcode class's set_hooks methods in case it needs to hook into other parts of the system
1223
-            // which set hooks ?
1224
-            if (is_admin()) {
1225
-                // fire immediately
1226
-                call_user_func(array($module_class, 'set_hooks_admin'));
1227
-            } else {
1228
-                // delay until other systems are online
1229
-                add_action(
1230
-                    'AHEE__EE_System__set_hooks_for_shortcodes_modules_and_addons',
1231
-                    array($module_class, 'set_hooks')
1232
-                );
1233
-            }
1234
-        }
1235
-    }
1236
-
1237
-
1238
-    /**
1239
-     *    register_route - adds module method routes to route_map
1240
-     *
1241
-     * @access    public
1242
-     * @param    string $route       - "pretty" public alias for module method
1243
-     * @param    string $module      - module name (classname without EED_ prefix)
1244
-     * @param    string $method_name - the actual module method to be routed to
1245
-     * @param    string $key         - url param key indicating a route is being called
1246
-     * @return    bool
1247
-     */
1248
-    public static function register_route($route = null, $module = null, $method_name = null, $key = 'ee')
1249
-    {
1250
-        do_action('AHEE__EE_Config__register_route__begin', $route, $module, $method_name);
1251
-        $module = str_replace('EED_', '', $module);
1252
-        $module_class = 'EED_' . $module;
1253
-        if (! isset(EE_Registry::instance()->modules->{$module_class})) {
1254
-            $msg = sprintf(__('The module %s has not been registered.', 'event_espresso'), $module);
1255
-            EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__);
1256
-            return false;
1257
-        }
1258
-        if (empty($route)) {
1259
-            $msg = sprintf(__('No route has been supplied.', 'event_espresso'), $route);
1260
-            EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__);
1261
-            return false;
1262
-        }
1263
-        if (! method_exists('EED_' . $module, $method_name)) {
1264
-            $msg = sprintf(
1265
-                __('A valid class method for the %s route has not been supplied.', 'event_espresso'),
1266
-                $route
1267
-            );
1268
-            EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__);
1269
-            return false;
1270
-        }
1271
-        EE_Config::$_module_route_map[ $key ][ $route ] = array('EED_' . $module, $method_name);
1272
-        return true;
1273
-    }
1274
-
1275
-
1276
-    /**
1277
-     *    get_route - get module method route
1278
-     *
1279
-     * @access    public
1280
-     * @param    string $route - "pretty" public alias for module method
1281
-     * @param    string $key   - url param key indicating a route is being called
1282
-     * @return    string
1283
-     */
1284
-    public static function get_route($route = null, $key = 'ee')
1285
-    {
1286
-        do_action('AHEE__EE_Config__get_route__begin', $route);
1287
-        $route = (string) apply_filters('FHEE__EE_Config__get_route', $route);
1288
-        if (isset(EE_Config::$_module_route_map[ $key ][ $route ])) {
1289
-            return EE_Config::$_module_route_map[ $key ][ $route ];
1290
-        }
1291
-        return null;
1292
-    }
1293
-
1294
-
1295
-    /**
1296
-     *    get_routes - get ALL module method routes
1297
-     *
1298
-     * @access    public
1299
-     * @return    array
1300
-     */
1301
-    public static function get_routes()
1302
-    {
1303
-        return EE_Config::$_module_route_map;
1304
-    }
1305
-
1306
-
1307
-    /**
1308
-     *    register_forward - allows modules to forward request to another module for further processing
1309
-     *
1310
-     * @access    public
1311
-     * @param    string       $route   - "pretty" public alias for module method
1312
-     * @param    integer      $status  - integer value corresponding  to status constant strings set in module parent
1313
-     *                                 class, allows different forwards to be served based on status
1314
-     * @param    array|string $forward - function name or array( class, method )
1315
-     * @param    string       $key     - url param key indicating a route is being called
1316
-     * @return    bool
1317
-     */
1318
-    public static function register_forward($route = null, $status = 0, $forward = null, $key = 'ee')
1319
-    {
1320
-        do_action('AHEE__EE_Config__register_forward', $route, $status, $forward);
1321
-        if (! isset(EE_Config::$_module_route_map[ $key ][ $route ]) || empty($route)) {
1322
-            $msg = sprintf(
1323
-                __('The module route %s for this forward has not been registered.', 'event_espresso'),
1324
-                $route
1325
-            );
1326
-            EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__);
1327
-            return false;
1328
-        }
1329
-        if (empty($forward)) {
1330
-            $msg = sprintf(__('No forwarding route has been supplied.', 'event_espresso'), $route);
1331
-            EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__);
1332
-            return false;
1333
-        }
1334
-        if (is_array($forward)) {
1335
-            if (! isset($forward[1])) {
1336
-                $msg = sprintf(
1337
-                    __('A class method for the %s forwarding route has not been supplied.', 'event_espresso'),
1338
-                    $route
1339
-                );
1340
-                EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__);
1341
-                return false;
1342
-            }
1343
-            if (! method_exists($forward[0], $forward[1])) {
1344
-                $msg = sprintf(
1345
-                    __('The class method %s for the %s forwarding route is in invalid.', 'event_espresso'),
1346
-                    $forward[1],
1347
-                    $route
1348
-                );
1349
-                EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__);
1350
-                return false;
1351
-            }
1352
-        } elseif (! function_exists($forward)) {
1353
-            $msg = sprintf(
1354
-                __('The function %s for the %s forwarding route is in invalid.', 'event_espresso'),
1355
-                $forward,
1356
-                $route
1357
-            );
1358
-            EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__);
1359
-            return false;
1360
-        }
1361
-        EE_Config::$_module_forward_map[ $key ][ $route ][ absint($status) ] = $forward;
1362
-        return true;
1363
-    }
1364
-
1365
-
1366
-    /**
1367
-     *    get_forward - get forwarding route
1368
-     *
1369
-     * @access    public
1370
-     * @param    string  $route  - "pretty" public alias for module method
1371
-     * @param    integer $status - integer value corresponding  to status constant strings set in module parent class,
1372
-     *                           allows different forwards to be served based on status
1373
-     * @param    string  $key    - url param key indicating a route is being called
1374
-     * @return    string
1375
-     */
1376
-    public static function get_forward($route = null, $status = 0, $key = 'ee')
1377
-    {
1378
-        do_action('AHEE__EE_Config__get_forward__begin', $route, $status);
1379
-        if (isset(EE_Config::$_module_forward_map[ $key ][ $route ][ $status ])) {
1380
-            return apply_filters(
1381
-                'FHEE__EE_Config__get_forward',
1382
-                EE_Config::$_module_forward_map[ $key ][ $route ][ $status ],
1383
-                $route,
1384
-                $status
1385
-            );
1386
-        }
1387
-        return null;
1388
-    }
1389
-
1390
-
1391
-    /**
1392
-     *    register_forward - allows modules to specify different view templates for different method routes and status
1393
-     *    results
1394
-     *
1395
-     * @access    public
1396
-     * @param    string  $route  - "pretty" public alias for module method
1397
-     * @param    integer $status - integer value corresponding  to status constant strings set in module parent class,
1398
-     *                           allows different views to be served based on status
1399
-     * @param    string  $view
1400
-     * @param    string  $key    - url param key indicating a route is being called
1401
-     * @return    bool
1402
-     */
1403
-    public static function register_view($route = null, $status = 0, $view = null, $key = 'ee')
1404
-    {
1405
-        do_action('AHEE__EE_Config__register_view__begin', $route, $status, $view);
1406
-        if (! isset(EE_Config::$_module_route_map[ $key ][ $route ]) || empty($route)) {
1407
-            $msg = sprintf(
1408
-                __('The module route %s for this view has not been registered.', 'event_espresso'),
1409
-                $route
1410
-            );
1411
-            EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__);
1412
-            return false;
1413
-        }
1414
-        if (! is_readable($view)) {
1415
-            $msg = sprintf(
1416
-                __(
1417
-                    'The %s view file could not be found or is not readable due to file permissions.',
1418
-                    'event_espresso'
1419
-                ),
1420
-                $view
1421
-            );
1422
-            EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__);
1423
-            return false;
1424
-        }
1425
-        EE_Config::$_module_view_map[ $key ][ $route ][ absint($status) ] = $view;
1426
-        return true;
1427
-    }
1428
-
1429
-
1430
-    /**
1431
-     *    get_view - get view for route and status
1432
-     *
1433
-     * @access    public
1434
-     * @param    string  $route  - "pretty" public alias for module method
1435
-     * @param    integer $status - integer value corresponding  to status constant strings set in module parent class,
1436
-     *                           allows different views to be served based on status
1437
-     * @param    string  $key    - url param key indicating a route is being called
1438
-     * @return    string
1439
-     */
1440
-    public static function get_view($route = null, $status = 0, $key = 'ee')
1441
-    {
1442
-        do_action('AHEE__EE_Config__get_view__begin', $route, $status);
1443
-        if (isset(EE_Config::$_module_view_map[ $key ][ $route ][ $status ])) {
1444
-            return apply_filters(
1445
-                'FHEE__EE_Config__get_view',
1446
-                EE_Config::$_module_view_map[ $key ][ $route ][ $status ],
1447
-                $route,
1448
-                $status
1449
-            );
1450
-        }
1451
-        return null;
1452
-    }
1453
-
1454
-
1455
-    public function update_addon_option_names()
1456
-    {
1457
-        update_option(EE_Config::ADDON_OPTION_NAMES, $this->_addon_option_names);
1458
-    }
1459
-
1460
-
1461
-    public function shutdown()
1462
-    {
1463
-        $this->update_addon_option_names();
1464
-    }
1465
-
1466
-
1467
-    /**
1468
-     * @return LegacyShortcodesManager
1469
-     */
1470
-    public static function getLegacyShortcodesManager()
1471
-    {
1472
-
1473
-        if (! EE_Config::instance()->legacy_shortcodes_manager instanceof LegacyShortcodesManager) {
1474
-            EE_Config::instance()->legacy_shortcodes_manager = new LegacyShortcodesManager(
1475
-                EE_Registry::instance()
1476
-            );
1477
-        }
1478
-        return EE_Config::instance()->legacy_shortcodes_manager;
1479
-    }
1480
-
1481
-
1482
-    /**
1483
-     * register_shortcode - makes core aware of this shortcode
1484
-     *
1485
-     * @deprecated 4.9.26
1486
-     * @param    string $shortcode_path - full path up to and including shortcode folder
1487
-     * @return    bool
1488
-     */
1489
-    public static function register_shortcode($shortcode_path = null)
1490
-    {
1491
-        EE_Error::doing_it_wrong(
1492
-            __METHOD__,
1493
-            __(
1494
-                'Usage is deprecated. Use \EventEspresso\core\services\shortcodes\LegacyShortcodesManager::registerShortcode() as direct replacement, or better yet, please see the new \EventEspresso\core\services\shortcodes\ShortcodesManager class.',
1495
-                'event_espresso'
1496
-            ),
1497
-            '4.9.26'
1498
-        );
1499
-        return EE_Config::instance()->getLegacyShortcodesManager()->registerShortcode($shortcode_path);
1500
-    }
1501
-}
1502
-
1503
-/**
1504
- * Base class used for config classes. These classes should generally not have
1505
- * magic functions in use, except we'll allow them to magically set and get stuff...
1506
- * basically, they should just be well-defined stdClasses
1507
- */
1508
-class EE_Config_Base
1509
-{
1510
-
1511
-    /**
1512
-     * Utility function for escaping the value of a property and returning.
1513
-     *
1514
-     * @param string $property property name (checks to see if exists).
1515
-     * @return mixed if a detected type found return the escaped value, otherwise just the raw value is returned.
1516
-     * @throws \EE_Error
1517
-     */
1518
-    public function get_pretty($property)
1519
-    {
1520
-        if (! property_exists($this, $property)) {
1521
-            throw new EE_Error(
1522
-                sprintf(
1523
-                    __(
1524
-                        '%1$s::get_pretty() has been called with the property %2$s which does not exist on the %1$s config class.',
1525
-                        'event_espresso'
1526
-                    ),
1527
-                    get_class($this),
1528
-                    $property
1529
-                )
1530
-            );
1531
-        }
1532
-        // just handling escaping of strings for now.
1533
-        if (is_string($this->{$property})) {
1534
-            return stripslashes($this->{$property});
1535
-        }
1536
-        return $this->{$property};
1537
-    }
1538
-
1539
-
1540
-    public function populate()
1541
-    {
1542
-        // grab defaults via a new instance of this class.
1543
-        $class_name = get_class($this);
1544
-        $defaults = new $class_name;
1545
-        // loop through the properties for this class and see if they are set.  If they are NOT, then grab the
1546
-        // default from our $defaults object.
1547
-        foreach (get_object_vars($defaults) as $property => $value) {
1548
-            if ($this->{$property} === null) {
1549
-                $this->{$property} = $value;
1550
-            }
1551
-        }
1552
-        // cleanup
1553
-        unset($defaults);
1554
-    }
1555
-
1556
-
1557
-    /**
1558
-     *        __isset
1559
-     *
1560
-     * @param $a
1561
-     * @return bool
1562
-     */
1563
-    public function __isset($a)
1564
-    {
1565
-        return false;
1566
-    }
1567
-
1568
-
1569
-    /**
1570
-     *        __unset
1571
-     *
1572
-     * @param $a
1573
-     * @return bool
1574
-     */
1575
-    public function __unset($a)
1576
-    {
1577
-        return false;
1578
-    }
1579
-
1580
-
1581
-    /**
1582
-     *        __clone
1583
-     */
1584
-    public function __clone()
1585
-    {
1586
-    }
1587
-
1588
-
1589
-    /**
1590
-     *        __wakeup
1591
-     */
1592
-    public function __wakeup()
1593
-    {
1594
-    }
1595
-
1596
-
1597
-    /**
1598
-     *        __destruct
1599
-     */
1600
-    public function __destruct()
1601
-    {
1602
-    }
1603
-}
1604
-
1605
-
1606
-/**
1607
- * Class for defining what's in the EE_Config relating to registration settings
1608
- */
1609
-class EE_Core_Config extends EE_Config_Base
1610
-{
1611
-
1612
-    public $current_blog_id;
1613
-
1614
-    public $ee_ueip_optin;
1615
-
1616
-    public $ee_ueip_has_notified;
1617
-
1618
-    /**
1619
-     * Not to be confused with the 4 critical page variables (See
1620
-     * get_critical_pages_array()), this is just an array of wp posts that have EE
1621
-     * shortcodes in them. Keys are slugs, values are arrays with only 1 element: where the key is the shortcode
1622
-     * in the page, and the value is the page's ID. The key 'posts' is basically a duplicate of this same array.
1623
-     *
1624
-     * @var array
1625
-     */
1626
-    public $post_shortcodes;
1627
-
1628
-    public $module_route_map;
1629
-
1630
-    public $module_forward_map;
1631
-
1632
-    public $module_view_map;
1633
-
1634
-    /**
1635
-     * The next 4 vars are the IDs of critical EE pages.
1636
-     *
1637
-     * @var int
1638
-     */
1639
-    public $reg_page_id;
1640
-
1641
-    public $txn_page_id;
1642
-
1643
-    public $thank_you_page_id;
1644
-
1645
-    public $cancel_page_id;
1646
-
1647
-    /**
1648
-     * The next 4 vars are the URLs of critical EE pages.
1649
-     *
1650
-     * @var int
1651
-     */
1652
-    public $reg_page_url;
1653
-
1654
-    public $txn_page_url;
1655
-
1656
-    public $thank_you_page_url;
1657
-
1658
-    public $cancel_page_url;
1659
-
1660
-    /**
1661
-     * The next vars relate to the custom slugs for EE CPT routes
1662
-     */
1663
-    public $event_cpt_slug;
1664
-
1665
-
1666
-    /**
1667
-     * This caches the _ee_ueip_option in case this config is reset in the same
1668
-     * request across blog switches in a multisite context.
1669
-     * Avoids extra queries to the db for this option.
1670
-     *
1671
-     * @var bool
1672
-     */
1673
-    public static $ee_ueip_option;
1674
-
1675
-
1676
-    /**
1677
-     *    class constructor
1678
-     *
1679
-     * @access    public
1680
-     */
1681
-    public function __construct()
1682
-    {
1683
-        // set default organization settings
1684
-        $this->current_blog_id = get_current_blog_id();
1685
-        $this->current_blog_id = $this->current_blog_id === null ? 1 : $this->current_blog_id;
1686
-        $this->ee_ueip_optin = $this->_get_main_ee_ueip_optin();
1687
-        $this->ee_ueip_has_notified = is_main_site() ? get_option('ee_ueip_has_notified', false) : true;
1688
-        $this->post_shortcodes = array();
1689
-        $this->module_route_map = array();
1690
-        $this->module_forward_map = array();
1691
-        $this->module_view_map = array();
1692
-        // critical EE page IDs
1693
-        $this->reg_page_id = 0;
1694
-        $this->txn_page_id = 0;
1695
-        $this->thank_you_page_id = 0;
1696
-        $this->cancel_page_id = 0;
1697
-        // critical EE page URLs
1698
-        $this->reg_page_url = '';
1699
-        $this->txn_page_url = '';
1700
-        $this->thank_you_page_url = '';
1701
-        $this->cancel_page_url = '';
1702
-        // cpt slugs
1703
-        $this->event_cpt_slug = __('events', 'event_espresso');
1704
-        // ueip constant check
1705
-        if (defined('EE_DISABLE_UXIP') && EE_DISABLE_UXIP) {
1706
-            $this->ee_ueip_optin = false;
1707
-            $this->ee_ueip_has_notified = true;
1708
-        }
1709
-    }
1710
-
1711
-
1712
-    /**
1713
-     * @return array
1714
-     */
1715
-    public function get_critical_pages_array()
1716
-    {
1717
-        return array(
1718
-            $this->reg_page_id,
1719
-            $this->txn_page_id,
1720
-            $this->thank_you_page_id,
1721
-            $this->cancel_page_id,
1722
-        );
1723
-    }
1724
-
1725
-
1726
-    /**
1727
-     * @return array
1728
-     */
1729
-    public function get_critical_pages_shortcodes_array()
1730
-    {
1731
-        return array(
1732
-            $this->reg_page_id       => 'ESPRESSO_CHECKOUT',
1733
-            $this->txn_page_id       => 'ESPRESSO_TXN_PAGE',
1734
-            $this->thank_you_page_id => 'ESPRESSO_THANK_YOU',
1735
-            $this->cancel_page_id    => 'ESPRESSO_CANCELLED',
1736
-        );
1737
-    }
1738
-
1739
-
1740
-    /**
1741
-     *  gets/returns URL for EE reg_page
1742
-     *
1743
-     * @access    public
1744
-     * @return    string
1745
-     */
1746
-    public function reg_page_url()
1747
-    {
1748
-        if (! $this->reg_page_url) {
1749
-            $this->reg_page_url = add_query_arg(
1750
-                array('uts' => time()),
1751
-                get_permalink($this->reg_page_id)
1752
-            ) . '#checkout';
1753
-        }
1754
-        return $this->reg_page_url;
1755
-    }
1756
-
1757
-
1758
-    /**
1759
-     *  gets/returns URL for EE txn_page
1760
-     *
1761
-     * @param array $query_args like what gets passed to
1762
-     *                          add_query_arg() as the first argument
1763
-     * @access    public
1764
-     * @return    string
1765
-     */
1766
-    public function txn_page_url($query_args = array())
1767
-    {
1768
-        if (! $this->txn_page_url) {
1769
-            $this->txn_page_url = get_permalink($this->txn_page_id);
1770
-        }
1771
-        if ($query_args) {
1772
-            return add_query_arg($query_args, $this->txn_page_url);
1773
-        } else {
1774
-            return $this->txn_page_url;
1775
-        }
1776
-    }
1777
-
1778
-
1779
-    /**
1780
-     *  gets/returns URL for EE thank_you_page
1781
-     *
1782
-     * @param array $query_args like what gets passed to
1783
-     *                          add_query_arg() as the first argument
1784
-     * @access    public
1785
-     * @return    string
1786
-     */
1787
-    public function thank_you_page_url($query_args = array())
1788
-    {
1789
-        if (! $this->thank_you_page_url) {
1790
-            $this->thank_you_page_url = get_permalink($this->thank_you_page_id);
1791
-        }
1792
-        if ($query_args) {
1793
-            return add_query_arg($query_args, $this->thank_you_page_url);
1794
-        } else {
1795
-            return $this->thank_you_page_url;
1796
-        }
1797
-    }
1798
-
1799
-
1800
-    /**
1801
-     *  gets/returns URL for EE cancel_page
1802
-     *
1803
-     * @access    public
1804
-     * @return    string
1805
-     */
1806
-    public function cancel_page_url()
1807
-    {
1808
-        if (! $this->cancel_page_url) {
1809
-            $this->cancel_page_url = get_permalink($this->cancel_page_id);
1810
-        }
1811
-        return $this->cancel_page_url;
1812
-    }
1813
-
1814
-
1815
-    /**
1816
-     * Resets all critical page urls to their original state.  Used primarily by the __sleep() magic method currently.
1817
-     *
1818
-     * @since 4.7.5
1819
-     */
1820
-    protected function _reset_urls()
1821
-    {
1822
-        $this->reg_page_url = '';
1823
-        $this->txn_page_url = '';
1824
-        $this->cancel_page_url = '';
1825
-        $this->thank_you_page_url = '';
1826
-    }
1827
-
1828
-
1829
-    /**
1830
-     * Used to return what the optin value is set for the EE User Experience Program.
1831
-     * This accounts for multisite and this value being requested for a subsite.  In multisite, the value is set
1832
-     * on the main site only.
1833
-     *
1834
-     * @return mixed|void
1835
-     */
1836
-    protected function _get_main_ee_ueip_optin()
1837
-    {
1838
-        // if this is the main site then we can just bypass our direct query.
1839
-        if (is_main_site()) {
1840
-            return get_option('ee_ueip_optin', false);
1841
-        }
1842
-        // is this already cached for this request?  If so use it.
1843
-        if (! empty(EE_Core_Config::$ee_ueip_option)) {
1844
-            return EE_Core_Config::$ee_ueip_option;
1845
-        }
1846
-        global $wpdb;
1847
-        $current_network_main_site = is_multisite() ? get_current_site() : null;
1848
-        $current_main_site_id = ! empty($current_network_main_site) ? $current_network_main_site->blog_id : 1;
1849
-        $option = 'ee_ueip_optin';
1850
-        // set correct table for query
1851
-        $table_name = $wpdb->get_blog_prefix($current_main_site_id) . 'options';
1852
-        // rather than getting blog option for the $current_main_site_id, we do a direct $wpdb query because
1853
-        // get_blog_option() does a switch_to_blog an that could cause infinite recursion because EE_Core_Config might be
1854
-        // re-constructed on the blog switch.  Note, we are still executing any core wp filters on this option retrieval.
1855
-        // this bit of code is basically a direct copy of get_option without any caching because we are NOT switched to the blog
1856
-        // for the purpose of caching.
1857
-        $pre = apply_filters('pre_option_' . $option, false, $option);
1858
-        if (false !== $pre) {
1859
-            EE_Core_Config::$ee_ueip_option = $pre;
1860
-            return EE_Core_Config::$ee_ueip_option;
1861
-        }
1862
-        $row = $wpdb->get_row(
1863
-            $wpdb->prepare(
1864
-                "SELECT option_value FROM $table_name WHERE option_name = %s LIMIT 1",
1865
-                $option
1866
-            )
1867
-        );
1868
-        if (is_object($row)) {
1869
-            $value = $row->option_value;
1870
-        } else { // option does not exist so use default.
1871
-            return apply_filters('default_option_' . $option, false, $option);
1872
-        }
1873
-        EE_Core_Config::$ee_ueip_option = apply_filters('option_' . $option, maybe_unserialize($value), $option);
1874
-        return EE_Core_Config::$ee_ueip_option;
1875
-    }
1876
-
1877
-    /**
1878
-     * Utility function for escaping the value of a property and returning.
1879
-     *
1880
-     * @param string $property property name (checks to see if exists).
1881
-     * @return mixed if a detected type found return the escaped value, otherwise just the raw value is returned.
1882
-     * @throws \EE_Error
1883
-     */
1884
-    public function get_pretty($property)
1885
-    {
1886
-        if ($property === 'ee_ueip_optin') {
1887
-            return $this->ee_ueip_optin ? 'yes' : 'no';
1888
-        }
1889
-        return parent::get_pretty($property);
1890
-    }
1891
-
1892
-
1893
-    /**
1894
-     * Currently used to ensure critical page urls have initial values saved to the db instead of any current set values
1895
-     * on the object.
1896
-     *
1897
-     * @return array
1898
-     */
1899
-    public function __sleep()
1900
-    {
1901
-        // reset all url properties
1902
-        $this->_reset_urls();
1903
-        // return what to save to db
1904
-        return array_keys(get_object_vars($this));
1905
-    }
1906
-}
1907
-
1908
-
1909
-/**
1910
- * Config class for storing info on the Organization
1911
- */
1912
-class EE_Organization_Config extends EE_Config_Base
1913
-{
1914
-
1915
-    /**
1916
-     * @var string $name
1917
-     * eg EE4.1
1918
-     */
1919
-    public $name;
1920
-
1921
-    /**
1922
-     * @var string $address_1
1923
-     * eg 123 Onna Road
1924
-     */
1925
-    public $address_1;
1926
-
1927
-    /**
1928
-     * @var string $address_2
1929
-     * eg PO Box 123
1930
-     */
1931
-    public $address_2;
1932
-
1933
-    /**
1934
-     * @var string $city
1935
-     * eg Inna City
1936
-     */
1937
-    public $city;
1938
-
1939
-    /**
1940
-     * @var int $STA_ID
1941
-     * eg 4
1942
-     */
1943
-    public $STA_ID;
1944
-
1945
-    /**
1946
-     * @var string $CNT_ISO
1947
-     * eg US
1948
-     */
1949
-    public $CNT_ISO;
1950
-
1951
-    /**
1952
-     * @var string $zip
1953
-     * eg 12345  or V1A 2B3
1954
-     */
1955
-    public $zip;
1956
-
1957
-    /**
1958
-     * @var string $email
1959
-     * eg [email protected]
1960
-     */
1961
-    public $email;
1962
-
1963
-
1964
-    /**
1965
-     * @var string $phone
1966
-     * eg. 111-111-1111
1967
-     */
1968
-    public $phone;
1969
-
1970
-
1971
-    /**
1972
-     * @var string $vat
1973
-     * VAT/Tax Number
1974
-     */
1975
-    public $vat;
1976
-
1977
-    /**
1978
-     * @var string $logo_url
1979
-     * eg http://www.somedomain.com/wp-content/uploads/kittehs.jpg
1980
-     */
1981
-    public $logo_url;
1982
-
1983
-
1984
-    /**
1985
-     * The below are all various properties for holding links to organization social network profiles
1986
-     *
1987
-     * @var string
1988
-     */
1989
-    /**
1990
-     * facebook (facebook.com/profile.name)
1991
-     *
1992
-     * @var string
1993
-     */
1994
-    public $facebook;
1995
-
1996
-
1997
-    /**
1998
-     * twitter (twitter.com/twitter_handle)
1999
-     *
2000
-     * @var string
2001
-     */
2002
-    public $twitter;
2003
-
2004
-
2005
-    /**
2006
-     * linkedin (linkedin.com/in/profile_name)
2007
-     *
2008
-     * @var string
2009
-     */
2010
-    public $linkedin;
2011
-
2012
-
2013
-    /**
2014
-     * pinterest (www.pinterest.com/profile_name)
2015
-     *
2016
-     * @var string
2017
-     */
2018
-    public $pinterest;
2019
-
2020
-
2021
-    /**
2022
-     * google+ (google.com/+profileName)
2023
-     *
2024
-     * @var string
2025
-     */
2026
-    public $google;
2027
-
2028
-
2029
-    /**
2030
-     * instagram (instagram.com/handle)
2031
-     *
2032
-     * @var string
2033
-     */
2034
-    public $instagram;
2035
-
2036
-
2037
-    /**
2038
-     *    class constructor
2039
-     *
2040
-     * @access    public
2041
-     */
2042
-    public function __construct()
2043
-    {
2044
-        // set default organization settings
2045
-        // decode HTML entities from the WP blogname, because it's stored in the DB with HTML entities encoded
2046
-        $this->name = wp_specialchars_decode(get_bloginfo('name'), ENT_QUOTES);
2047
-        $this->address_1 = '123 Onna Road';
2048
-        $this->address_2 = 'PO Box 123';
2049
-        $this->city = 'Inna City';
2050
-        $this->STA_ID = 4;
2051
-        $this->CNT_ISO = 'US';
2052
-        $this->zip = '12345';
2053
-        $this->email = get_bloginfo('admin_email');
2054
-        $this->phone = '';
2055
-        $this->vat = '123456789';
2056
-        $this->logo_url = '';
2057
-        $this->facebook = '';
2058
-        $this->twitter = '';
2059
-        $this->linkedin = '';
2060
-        $this->pinterest = '';
2061
-        $this->google = '';
2062
-        $this->instagram = '';
2063
-    }
2064
-}
2065
-
2066
-
2067
-/**
2068
- * Class for defining what's in the EE_Config relating to currency
2069
- */
2070
-class EE_Currency_Config extends EE_Config_Base
2071
-{
2072
-
2073
-    /**
2074
-     * @var string $code
2075
-     * eg 'US'
2076
-     */
2077
-    public $code;
2078
-
2079
-    /**
2080
-     * @var string $name
2081
-     * eg 'Dollar'
2082
-     */
2083
-    public $name;
2084
-
2085
-    /**
2086
-     * plural name
2087
-     *
2088
-     * @var string $plural
2089
-     * eg 'Dollars'
2090
-     */
2091
-    public $plural;
2092
-
2093
-    /**
2094
-     * currency sign
2095
-     *
2096
-     * @var string $sign
2097
-     * eg '$'
2098
-     */
2099
-    public $sign;
2100
-
2101
-    /**
2102
-     * Whether the currency sign should come before the number or not
2103
-     *
2104
-     * @var boolean $sign_b4
2105
-     */
2106
-    public $sign_b4;
2107
-
2108
-    /**
2109
-     * How many digits should come after the decimal place
2110
-     *
2111
-     * @var int $dec_plc
2112
-     */
2113
-    public $dec_plc;
2114
-
2115
-    /**
2116
-     * Symbol to use for decimal mark
2117
-     *
2118
-     * @var string $dec_mrk
2119
-     * eg '.'
2120
-     */
2121
-    public $dec_mrk;
2122
-
2123
-    /**
2124
-     * Symbol to use for thousands
2125
-     *
2126
-     * @var string $thsnds
2127
-     * eg ','
2128
-     */
2129
-    public $thsnds;
16
+	const OPTION_NAME = 'ee_config';
17
+
18
+	const LOG_NAME = 'ee_config_log';
19
+
20
+	const LOG_LENGTH = 100;
21
+
22
+	const ADDON_OPTION_NAMES = 'ee_config_option_names';
23
+
24
+
25
+	/**
26
+	 *    instance of the EE_Config object
27
+	 *
28
+	 * @var    EE_Config $_instance
29
+	 * @access    private
30
+	 */
31
+	private static $_instance;
32
+
33
+	/**
34
+	 * @var boolean $_logging_enabled
35
+	 */
36
+	private static $_logging_enabled = false;
37
+
38
+	/**
39
+	 * @var LegacyShortcodesManager $legacy_shortcodes_manager
40
+	 */
41
+	private $legacy_shortcodes_manager;
42
+
43
+	/**
44
+	 * An StdClass whose property names are addon slugs,
45
+	 * and values are their config classes
46
+	 *
47
+	 * @var StdClass
48
+	 */
49
+	public $addons;
50
+
51
+	/**
52
+	 * @var EE_Admin_Config
53
+	 */
54
+	public $admin;
55
+
56
+	/**
57
+	 * @var EE_Core_Config
58
+	 */
59
+	public $core;
60
+
61
+	/**
62
+	 * @var EE_Currency_Config
63
+	 */
64
+	public $currency;
65
+
66
+	/**
67
+	 * @var EE_Organization_Config
68
+	 */
69
+	public $organization;
70
+
71
+	/**
72
+	 * @var EE_Registration_Config
73
+	 */
74
+	public $registration;
75
+
76
+	/**
77
+	 * @var EE_Template_Config
78
+	 */
79
+	public $template_settings;
80
+
81
+	/**
82
+	 * Holds EE environment values.
83
+	 *
84
+	 * @var EE_Environment_Config
85
+	 */
86
+	public $environment;
87
+
88
+	/**
89
+	 * settings pertaining to Google maps
90
+	 *
91
+	 * @var EE_Map_Config
92
+	 */
93
+	public $map_settings;
94
+
95
+	/**
96
+	 * settings pertaining to Taxes
97
+	 *
98
+	 * @var EE_Tax_Config
99
+	 */
100
+	public $tax_settings;
101
+
102
+
103
+	/**
104
+	 * Settings pertaining to global messages settings.
105
+	 *
106
+	 * @var EE_Messages_Config
107
+	 */
108
+	public $messages;
109
+
110
+	/**
111
+	 * @deprecated
112
+	 * @var EE_Gateway_Config
113
+	 */
114
+	public $gateway;
115
+
116
+	/**
117
+	 * @var    array $_addon_option_names
118
+	 * @access    private
119
+	 */
120
+	private $_addon_option_names = array();
121
+
122
+	/**
123
+	 * @var    array $_module_route_map
124
+	 * @access    private
125
+	 */
126
+	private static $_module_route_map = array();
127
+
128
+	/**
129
+	 * @var    array $_module_forward_map
130
+	 * @access    private
131
+	 */
132
+	private static $_module_forward_map = array();
133
+
134
+	/**
135
+	 * @var    array $_module_view_map
136
+	 * @access    private
137
+	 */
138
+	private static $_module_view_map = array();
139
+
140
+
141
+	/**
142
+	 * @singleton method used to instantiate class object
143
+	 * @access    public
144
+	 * @return EE_Config instance
145
+	 */
146
+	public static function instance()
147
+	{
148
+		// check if class object is instantiated, and instantiated properly
149
+		if (! self::$_instance instanceof EE_Config) {
150
+			self::$_instance = new self();
151
+		}
152
+		return self::$_instance;
153
+	}
154
+
155
+
156
+	/**
157
+	 * Resets the config
158
+	 *
159
+	 * @param bool    $hard_reset    if TRUE, sets EE_CONFig back to its original settings in the database. If FALSE
160
+	 *                               (default) leaves the database alone, and merely resets the EE_Config object to
161
+	 *                               reflect its state in the database
162
+	 * @param boolean $reinstantiate if TRUE (default) call instance() and return it. Otherwise, just leave
163
+	 *                               $_instance as NULL. Useful in case you want to forget about the old instance on
164
+	 *                               EE_Config, but might not be ready to instantiate EE_Config currently (eg if the
165
+	 *                               site was put into maintenance mode)
166
+	 * @return EE_Config
167
+	 */
168
+	public static function reset($hard_reset = false, $reinstantiate = true)
169
+	{
170
+		if (self::$_instance instanceof EE_Config) {
171
+			if ($hard_reset) {
172
+				self::$_instance->legacy_shortcodes_manager = null;
173
+				self::$_instance->_addon_option_names = array();
174
+				self::$_instance->_initialize_config();
175
+				self::$_instance->update_espresso_config();
176
+			}
177
+			self::$_instance->update_addon_option_names();
178
+		}
179
+		self::$_instance = null;
180
+		// we don't need to reset the static properties imo because those should
181
+		// only change when a module is added or removed. Currently we don't
182
+		// support removing a module during a request when it previously existed
183
+		if ($reinstantiate) {
184
+			return self::instance();
185
+		} else {
186
+			return null;
187
+		}
188
+	}
189
+
190
+
191
+	/**
192
+	 *    class constructor
193
+	 *
194
+	 * @access    private
195
+	 */
196
+	private function __construct()
197
+	{
198
+		do_action('AHEE__EE_Config__construct__begin', $this);
199
+		EE_Config::$_logging_enabled = apply_filters('FHEE__EE_Config___construct__logging_enabled', false);
200
+		// setup empty config classes
201
+		$this->_initialize_config();
202
+		// load existing EE site settings
203
+		$this->_load_core_config();
204
+		// confirm everything loaded correctly and set filtered defaults if not
205
+		$this->_verify_config();
206
+		//  register shortcodes and modules
207
+		add_action(
208
+			'AHEE__EE_System__register_shortcodes_modules_and_widgets',
209
+			array($this, 'register_shortcodes_and_modules'),
210
+			999
211
+		);
212
+		//  initialize shortcodes and modules
213
+		add_action('AHEE__EE_System__core_loaded_and_ready', array($this, 'initialize_shortcodes_and_modules'));
214
+		// register widgets
215
+		add_action('widgets_init', array($this, 'widgets_init'), 10);
216
+		// shutdown
217
+		add_action('shutdown', array($this, 'shutdown'), 10);
218
+		// construct__end hook
219
+		do_action('AHEE__EE_Config__construct__end', $this);
220
+		// hardcoded hack
221
+		$this->template_settings->current_espresso_theme = 'Espresso_Arabica_2014';
222
+	}
223
+
224
+
225
+	/**
226
+	 * @return boolean
227
+	 */
228
+	public static function logging_enabled()
229
+	{
230
+		return self::$_logging_enabled;
231
+	}
232
+
233
+
234
+	/**
235
+	 * use to get the current theme if needed from static context
236
+	 *
237
+	 * @return string current theme set.
238
+	 */
239
+	public static function get_current_theme()
240
+	{
241
+		return isset(self::$_instance->template_settings->current_espresso_theme)
242
+			? self::$_instance->template_settings->current_espresso_theme : 'Espresso_Arabica_2014';
243
+	}
244
+
245
+
246
+	/**
247
+	 *        _initialize_config
248
+	 *
249
+	 * @access private
250
+	 * @return void
251
+	 */
252
+	private function _initialize_config()
253
+	{
254
+		EE_Config::trim_log();
255
+		// set defaults
256
+		$this->_addon_option_names = get_option(EE_Config::ADDON_OPTION_NAMES, array());
257
+		$this->addons = new stdClass();
258
+		// set _module_route_map
259
+		EE_Config::$_module_route_map = array();
260
+		// set _module_forward_map
261
+		EE_Config::$_module_forward_map = array();
262
+		// set _module_view_map
263
+		EE_Config::$_module_view_map = array();
264
+	}
265
+
266
+
267
+	/**
268
+	 *        load core plugin configuration
269
+	 *
270
+	 * @access private
271
+	 * @return void
272
+	 */
273
+	private function _load_core_config()
274
+	{
275
+		// load_core_config__start hook
276
+		do_action('AHEE__EE_Config___load_core_config__start', $this);
277
+		$espresso_config = $this->get_espresso_config();
278
+		foreach ($espresso_config as $config => $settings) {
279
+			// load_core_config__start hook
280
+			$settings = apply_filters(
281
+				'FHEE__EE_Config___load_core_config__config_settings',
282
+				$settings,
283
+				$config,
284
+				$this
285
+			);
286
+			if (is_object($settings) && property_exists($this, $config)) {
287
+				$this->{$config} = apply_filters('FHEE__EE_Config___load_core_config__' . $config, $settings);
288
+				// call configs populate method to ensure any defaults are set for empty values.
289
+				if (method_exists($settings, 'populate')) {
290
+					$this->{$config}->populate();
291
+				}
292
+				if (method_exists($settings, 'do_hooks')) {
293
+					$this->{$config}->do_hooks();
294
+				}
295
+			}
296
+		}
297
+		if (apply_filters('FHEE__EE_Config___load_core_config__update_espresso_config', false)) {
298
+			$this->update_espresso_config();
299
+		}
300
+		// load_core_config__end hook
301
+		do_action('AHEE__EE_Config___load_core_config__end', $this);
302
+	}
303
+
304
+
305
+	/**
306
+	 *    _verify_config
307
+	 *
308
+	 * @access    protected
309
+	 * @return    void
310
+	 */
311
+	protected function _verify_config()
312
+	{
313
+		$this->core = $this->core instanceof EE_Core_Config
314
+			? $this->core
315
+			: new EE_Core_Config();
316
+		$this->core = apply_filters('FHEE__EE_Config___initialize_config__core', $this->core);
317
+		$this->organization = $this->organization instanceof EE_Organization_Config
318
+			? $this->organization
319
+			: new EE_Organization_Config();
320
+		$this->organization = apply_filters(
321
+			'FHEE__EE_Config___initialize_config__organization',
322
+			$this->organization
323
+		);
324
+		$this->currency = $this->currency instanceof EE_Currency_Config
325
+			? $this->currency
326
+			: new EE_Currency_Config();
327
+		$this->currency = apply_filters('FHEE__EE_Config___initialize_config__currency', $this->currency);
328
+		$this->registration = $this->registration instanceof EE_Registration_Config
329
+			? $this->registration
330
+			: new EE_Registration_Config();
331
+		$this->registration = apply_filters(
332
+			'FHEE__EE_Config___initialize_config__registration',
333
+			$this->registration
334
+		);
335
+		$this->admin = $this->admin instanceof EE_Admin_Config
336
+			? $this->admin
337
+			: new EE_Admin_Config();
338
+		$this->admin = apply_filters('FHEE__EE_Config___initialize_config__admin', $this->admin);
339
+		$this->template_settings = $this->template_settings instanceof EE_Template_Config
340
+			? $this->template_settings
341
+			: new EE_Template_Config();
342
+		$this->template_settings = apply_filters(
343
+			'FHEE__EE_Config___initialize_config__template_settings',
344
+			$this->template_settings
345
+		);
346
+		$this->map_settings = $this->map_settings instanceof EE_Map_Config
347
+			? $this->map_settings
348
+			: new EE_Map_Config();
349
+		$this->map_settings = apply_filters(
350
+			'FHEE__EE_Config___initialize_config__map_settings',
351
+			$this->map_settings
352
+		);
353
+		$this->environment = $this->environment instanceof EE_Environment_Config
354
+			? $this->environment
355
+			: new EE_Environment_Config();
356
+		$this->environment = apply_filters(
357
+			'FHEE__EE_Config___initialize_config__environment',
358
+			$this->environment
359
+		);
360
+		$this->tax_settings = $this->tax_settings instanceof EE_Tax_Config
361
+			? $this->tax_settings
362
+			: new EE_Tax_Config();
363
+		$this->tax_settings = apply_filters(
364
+			'FHEE__EE_Config___initialize_config__tax_settings',
365
+			$this->tax_settings
366
+		);
367
+		$this->messages = apply_filters('FHEE__EE_Config__initialize_config__messages', $this->messages);
368
+		$this->messages = $this->messages instanceof EE_Messages_Config
369
+			? $this->messages
370
+			: new EE_Messages_Config();
371
+		$this->gateway = $this->gateway instanceof EE_Gateway_Config
372
+			? $this->gateway
373
+			: new EE_Gateway_Config();
374
+		$this->gateway = apply_filters('FHEE__EE_Config___initialize_config__gateway', $this->gateway);
375
+		$this->legacy_shortcodes_manager = null;
376
+	}
377
+
378
+
379
+	/**
380
+	 *    get_espresso_config
381
+	 *
382
+	 * @access    public
383
+	 * @return    array of espresso config stuff
384
+	 */
385
+	public function get_espresso_config()
386
+	{
387
+		// grab espresso configuration
388
+		return apply_filters(
389
+			'FHEE__EE_Config__get_espresso_config__CFG',
390
+			get_option(EE_Config::OPTION_NAME, array())
391
+		);
392
+	}
393
+
394
+
395
+	/**
396
+	 *    double_check_config_comparison
397
+	 *
398
+	 * @access    public
399
+	 * @param string $option
400
+	 * @param        $old_value
401
+	 * @param        $value
402
+	 */
403
+	public function double_check_config_comparison($option = '', $old_value, $value)
404
+	{
405
+		// make sure we're checking the ee config
406
+		if ($option === EE_Config::OPTION_NAME) {
407
+			// run a loose comparison of the old value against the new value for type and properties,
408
+			// but NOT exact instance like WP update_option does (ie: NOT type safe comparison)
409
+			if ($value != $old_value) {
410
+				// if they are NOT the same, then remove the hook,
411
+				// which means the subsequent update results will be based solely on the update query results
412
+				// the reason we do this is because, as stated above,
413
+				// WP update_option performs an exact instance comparison (===) on any update values passed to it
414
+				// this happens PRIOR to serialization and any subsequent update.
415
+				// If values are found to match their previous old value,
416
+				// then WP bails before performing any update.
417
+				// Since we are passing the EE_Config object, it is comparing the EXACT instance of the saved version
418
+				// it just pulled from the db, with the one being passed to it (which will not match).
419
+				// HOWEVER, once the object is serialized and passed off to MySQL to update,
420
+				// MySQL MAY ALSO NOT perform the update because
421
+				// the string it sees in the db looks the same as the new one it has been passed!!!
422
+				// This results in the query returning an "affected rows" value of ZERO,
423
+				// which gets returned immediately by WP update_option and looks like an error.
424
+				remove_action('update_option', array($this, 'check_config_updated'));
425
+			}
426
+		}
427
+	}
428
+
429
+
430
+	/**
431
+	 *    update_espresso_config
432
+	 *
433
+	 * @access   public
434
+	 */
435
+	protected function _reset_espresso_addon_config()
436
+	{
437
+		$this->_addon_option_names = array();
438
+		foreach ($this->addons as $addon_name => $addon_config_obj) {
439
+			$addon_config_obj = maybe_unserialize($addon_config_obj);
440
+			if ($addon_config_obj instanceof EE_Config_Base) {
441
+				$this->update_config('addons', $addon_name, $addon_config_obj, false);
442
+			}
443
+			$this->addons->{$addon_name} = null;
444
+		}
445
+	}
446
+
447
+
448
+	/**
449
+	 *    update_espresso_config
450
+	 *
451
+	 * @access   public
452
+	 * @param   bool $add_success
453
+	 * @param   bool $add_error
454
+	 * @return   bool
455
+	 */
456
+	public function update_espresso_config($add_success = false, $add_error = true)
457
+	{
458
+		// don't allow config updates during WP heartbeats
459
+		if (\EE_Registry::instance()->REQ->get('action', '') === 'heartbeat') {
460
+			return false;
461
+		}
462
+		// commented out the following re: https://events.codebasehq.com/projects/event-espresso/tickets/8197
463
+		// $clone = clone( self::$_instance );
464
+		// self::$_instance = NULL;
465
+		do_action('AHEE__EE_Config__update_espresso_config__begin', $this);
466
+		$this->_reset_espresso_addon_config();
467
+		// hook into update_option because that happens AFTER the ( $value === $old_value ) conditional
468
+		// but BEFORE the actual update occurs
469
+		add_action('update_option', array($this, 'double_check_config_comparison'), 1, 3);
470
+		// don't want to persist legacy_shortcodes_manager, but don't want to lose it either
471
+		$legacy_shortcodes_manager = $this->legacy_shortcodes_manager;
472
+		$this->legacy_shortcodes_manager = null;
473
+		// now update "ee_config"
474
+		$saved = update_option(EE_Config::OPTION_NAME, $this);
475
+		$this->legacy_shortcodes_manager = $legacy_shortcodes_manager;
476
+		EE_Config::log(EE_Config::OPTION_NAME);
477
+		// if not saved... check if the hook we just added still exists;
478
+		// if it does, it means one of two things:
479
+		// that update_option bailed at the($value === $old_value) conditional,
480
+		// or...
481
+		// the db update query returned 0 rows affected
482
+		// (probably because the data  value was the same from it's perspective)
483
+		// so the existence of the hook means that a negative result from update_option is NOT an error,
484
+		// but just means no update occurred, so don't display an error to the user.
485
+		// BUT... if update_option returns FALSE, AND the hook is missing,
486
+		// then it means that something truly went wrong
487
+		$saved = ! $saved ? has_action('update_option', array($this, 'double_check_config_comparison')) : $saved;
488
+		// remove our action since we don't want it in the system anymore
489
+		remove_action('update_option', array($this, 'double_check_config_comparison'), 1);
490
+		do_action('AHEE__EE_Config__update_espresso_config__end', $this, $saved);
491
+		// self::$_instance = $clone;
492
+		// unset( $clone );
493
+		// if config remains the same or was updated successfully
494
+		if ($saved) {
495
+			if ($add_success) {
496
+				EE_Error::add_success(
497
+					__('The Event Espresso Configuration Settings have been successfully updated.', 'event_espresso'),
498
+					__FILE__,
499
+					__FUNCTION__,
500
+					__LINE__
501
+				);
502
+			}
503
+			return true;
504
+		} else {
505
+			if ($add_error) {
506
+				EE_Error::add_error(
507
+					__('The Event Espresso Configuration Settings were not updated.', 'event_espresso'),
508
+					__FILE__,
509
+					__FUNCTION__,
510
+					__LINE__
511
+				);
512
+			}
513
+			return false;
514
+		}
515
+	}
516
+
517
+
518
+	/**
519
+	 *    _verify_config_params
520
+	 *
521
+	 * @access    private
522
+	 * @param    string         $section
523
+	 * @param    string         $name
524
+	 * @param    string         $config_class
525
+	 * @param    EE_Config_Base $config_obj
526
+	 * @param    array          $tests_to_run
527
+	 * @param    bool           $display_errors
528
+	 * @return    bool    TRUE on success, FALSE on fail
529
+	 */
530
+	private function _verify_config_params(
531
+		$section = '',
532
+		$name = '',
533
+		$config_class = '',
534
+		$config_obj = null,
535
+		$tests_to_run = array(1, 2, 3, 4, 5, 6, 7, 8),
536
+		$display_errors = true
537
+	) {
538
+		try {
539
+			foreach ($tests_to_run as $test) {
540
+				switch ($test) {
541
+					// TEST #1 : check that section was set
542
+					case 1:
543
+						if (empty($section)) {
544
+							if ($display_errors) {
545
+								throw new EE_Error(
546
+									sprintf(
547
+										__(
548
+											'No configuration section has been provided while attempting to save "%s".',
549
+											'event_espresso'
550
+										),
551
+										$config_class
552
+									)
553
+								);
554
+							}
555
+							return false;
556
+						}
557
+						break;
558
+					// TEST #2 : check that settings section exists
559
+					case 2:
560
+						if (! isset($this->{$section})) {
561
+							if ($display_errors) {
562
+								throw new EE_Error(
563
+									sprintf(
564
+										__('The "%s" configuration section does not exist.', 'event_espresso'),
565
+										$section
566
+									)
567
+								);
568
+							}
569
+							return false;
570
+						}
571
+						break;
572
+					// TEST #3 : check that section is the proper format
573
+					case 3:
574
+						if (! ($this->{$section} instanceof EE_Config_Base || $this->{$section} instanceof stdClass)
575
+						) {
576
+							if ($display_errors) {
577
+								throw new EE_Error(
578
+									sprintf(
579
+										__(
580
+											'The "%s" configuration settings have not been formatted correctly.',
581
+											'event_espresso'
582
+										),
583
+										$section
584
+									)
585
+								);
586
+							}
587
+							return false;
588
+						}
589
+						break;
590
+					// TEST #4 : check that config section name has been set
591
+					case 4:
592
+						if (empty($name)) {
593
+							if ($display_errors) {
594
+								throw new EE_Error(
595
+									__(
596
+										'No name has been provided for the specific configuration section.',
597
+										'event_espresso'
598
+									)
599
+								);
600
+							}
601
+							return false;
602
+						}
603
+						break;
604
+					// TEST #5 : check that a config class name has been set
605
+					case 5:
606
+						if (empty($config_class)) {
607
+							if ($display_errors) {
608
+								throw new EE_Error(
609
+									__(
610
+										'No class name has been provided for the specific configuration section.',
611
+										'event_espresso'
612
+									)
613
+								);
614
+							}
615
+							return false;
616
+						}
617
+						break;
618
+					// TEST #6 : verify config class is accessible
619
+					case 6:
620
+						if (! class_exists($config_class)) {
621
+							if ($display_errors) {
622
+								throw new EE_Error(
623
+									sprintf(
624
+										__(
625
+											'The "%s" class does not exist. Please ensure that an autoloader has been set for it.',
626
+											'event_espresso'
627
+										),
628
+										$config_class
629
+									)
630
+								);
631
+							}
632
+							return false;
633
+						}
634
+						break;
635
+					// TEST #7 : check that config has even been set
636
+					case 7:
637
+						if (! isset($this->{$section}->{$name})) {
638
+							if ($display_errors) {
639
+								throw new EE_Error(
640
+									sprintf(
641
+										__('No configuration has been set for "%1$s->%2$s".', 'event_espresso'),
642
+										$section,
643
+										$name
644
+									)
645
+								);
646
+							}
647
+							return false;
648
+						} else {
649
+							// and make sure it's not serialized
650
+							$this->{$section}->{$name} = maybe_unserialize($this->{$section}->{$name});
651
+						}
652
+						break;
653
+					// TEST #8 : check that config is the requested type
654
+					case 8:
655
+						if (! $this->{$section}->{$name} instanceof $config_class) {
656
+							if ($display_errors) {
657
+								throw new EE_Error(
658
+									sprintf(
659
+										__(
660
+											'The configuration for "%1$s->%2$s" is not of the "%3$s" class.',
661
+											'event_espresso'
662
+										),
663
+										$section,
664
+										$name,
665
+										$config_class
666
+									)
667
+								);
668
+							}
669
+							return false;
670
+						}
671
+						break;
672
+					// TEST #9 : verify config object
673
+					case 9:
674
+						if (! $config_obj instanceof EE_Config_Base) {
675
+							if ($display_errors) {
676
+								throw new EE_Error(
677
+									sprintf(
678
+										__('The "%s" class is not an instance of EE_Config_Base.', 'event_espresso'),
679
+										print_r($config_obj, true)
680
+									)
681
+								);
682
+							}
683
+							return false;
684
+						}
685
+						break;
686
+				}
687
+			}
688
+		} catch (EE_Error $e) {
689
+			$e->get_error();
690
+		}
691
+		// you have successfully run the gauntlet
692
+		return true;
693
+	}
694
+
695
+
696
+	/**
697
+	 *    _generate_config_option_name
698
+	 *
699
+	 * @access        protected
700
+	 * @param        string $section
701
+	 * @param        string $name
702
+	 * @return        string
703
+	 */
704
+	private function _generate_config_option_name($section = '', $name = '')
705
+	{
706
+		return 'ee_config-' . strtolower($section . '-' . str_replace(array('EE_', 'EED_'), '', $name));
707
+	}
708
+
709
+
710
+	/**
711
+	 *    _set_config_class
712
+	 * ensures that a config class is set, either from a passed config class or one generated from the config name
713
+	 *
714
+	 * @access    private
715
+	 * @param    string $config_class
716
+	 * @param    string $name
717
+	 * @return    string
718
+	 */
719
+	private function _set_config_class($config_class = '', $name = '')
720
+	{
721
+		return ! empty($config_class)
722
+			? $config_class
723
+			: str_replace(' ', '_', ucwords(str_replace('_', ' ', $name))) . '_Config';
724
+	}
725
+
726
+
727
+	/**
728
+	 *    set_config
729
+	 *
730
+	 * @access    protected
731
+	 * @param    string         $section
732
+	 * @param    string         $name
733
+	 * @param    string         $config_class
734
+	 * @param    EE_Config_Base $config_obj
735
+	 * @return    EE_Config_Base
736
+	 */
737
+	public function set_config($section = '', $name = '', $config_class = '', EE_Config_Base $config_obj = null)
738
+	{
739
+		// ensure config class is set to something
740
+		$config_class = $this->_set_config_class($config_class, $name);
741
+		// run tests 1-4, 6, and 7 to verify all config params are set and valid
742
+		if (! $this->_verify_config_params($section, $name, $config_class, null, array(1, 2, 3, 4, 5, 6))) {
743
+			return null;
744
+		}
745
+		$config_option_name = $this->_generate_config_option_name($section, $name);
746
+		// if the config option name hasn't been added yet to the list of option names we're tracking, then do so now
747
+		if (! isset($this->_addon_option_names[ $config_option_name ])) {
748
+			$this->_addon_option_names[ $config_option_name ] = $config_class;
749
+			$this->update_addon_option_names();
750
+		}
751
+		// verify the incoming config object but suppress errors
752
+		if (! $this->_verify_config_params($section, $name, $config_class, $config_obj, array(9), false)) {
753
+			$config_obj = new $config_class();
754
+		}
755
+		if (get_option($config_option_name)) {
756
+			EE_Config::log($config_option_name);
757
+			update_option($config_option_name, $config_obj);
758
+			$this->{$section}->{$name} = $config_obj;
759
+			return $this->{$section}->{$name};
760
+		} else {
761
+			// create a wp-option for this config
762
+			if (add_option($config_option_name, $config_obj, '', 'no')) {
763
+				$this->{$section}->{$name} = maybe_unserialize($config_obj);
764
+				return $this->{$section}->{$name};
765
+			} else {
766
+				EE_Error::add_error(
767
+					sprintf(__('The "%s" could not be saved to the database.', 'event_espresso'), $config_class),
768
+					__FILE__,
769
+					__FUNCTION__,
770
+					__LINE__
771
+				);
772
+				return null;
773
+			}
774
+		}
775
+	}
776
+
777
+
778
+	/**
779
+	 *    update_config
780
+	 * Important: the config object must ALREADY be set, otherwise this will produce an error.
781
+	 *
782
+	 * @access    public
783
+	 * @param    string                $section
784
+	 * @param    string                $name
785
+	 * @param    EE_Config_Base|string $config_obj
786
+	 * @param    bool                  $throw_errors
787
+	 * @return    bool
788
+	 */
789
+	public function update_config($section = '', $name = '', $config_obj = '', $throw_errors = true)
790
+	{
791
+		// don't allow config updates during WP heartbeats
792
+		if (\EE_Registry::instance()->REQ->get('action', '') === 'heartbeat') {
793
+			return false;
794
+		}
795
+		$config_obj = maybe_unserialize($config_obj);
796
+		// get class name of the incoming object
797
+		$config_class = get_class($config_obj);
798
+		// run tests 1-5 and 9 to verify config
799
+		if (! $this->_verify_config_params(
800
+			$section,
801
+			$name,
802
+			$config_class,
803
+			$config_obj,
804
+			array(1, 2, 3, 4, 7, 9)
805
+		)
806
+		) {
807
+			return false;
808
+		}
809
+		$config_option_name = $this->_generate_config_option_name($section, $name);
810
+		// check if config object has been added to db by seeing if config option name is in $this->_addon_option_names array
811
+		if (! isset($this->_addon_option_names[ $config_option_name ])) {
812
+			// save new config to db
813
+			if ($this->set_config($section, $name, $config_class, $config_obj)) {
814
+				return true;
815
+			}
816
+		} else {
817
+			// first check if the record already exists
818
+			$existing_config = get_option($config_option_name);
819
+			$config_obj = serialize($config_obj);
820
+			// just return if db record is already up to date (NOT type safe comparison)
821
+			if ($existing_config == $config_obj) {
822
+				$this->{$section}->{$name} = $config_obj;
823
+				return true;
824
+			} elseif (update_option($config_option_name, $config_obj)) {
825
+				EE_Config::log($config_option_name);
826
+				// update wp-option for this config class
827
+				$this->{$section}->{$name} = $config_obj;
828
+				return true;
829
+			} elseif ($throw_errors) {
830
+				EE_Error::add_error(
831
+					sprintf(
832
+						__(
833
+							'The "%1$s" object stored at"%2$s" was not successfully updated in the database.',
834
+							'event_espresso'
835
+						),
836
+						$config_class,
837
+						'EE_Config->' . $section . '->' . $name
838
+					),
839
+					__FILE__,
840
+					__FUNCTION__,
841
+					__LINE__
842
+				);
843
+			}
844
+		}
845
+		return false;
846
+	}
847
+
848
+
849
+	/**
850
+	 *    get_config
851
+	 *
852
+	 * @access    public
853
+	 * @param    string $section
854
+	 * @param    string $name
855
+	 * @param    string $config_class
856
+	 * @return    mixed EE_Config_Base | NULL
857
+	 */
858
+	public function get_config($section = '', $name = '', $config_class = '')
859
+	{
860
+		// ensure config class is set to something
861
+		$config_class = $this->_set_config_class($config_class, $name);
862
+		// run tests 1-4, 6 and 7 to verify that all params have been set
863
+		if (! $this->_verify_config_params($section, $name, $config_class, null, array(1, 2, 3, 4, 5, 6))) {
864
+			return null;
865
+		}
866
+		// now test if the requested config object exists, but suppress errors
867
+		if ($this->_verify_config_params($section, $name, $config_class, null, array(7, 8), false)) {
868
+			// config already exists, so pass it back
869
+			return $this->{$section}->{$name};
870
+		}
871
+		// load config option from db if it exists
872
+		$config_obj = $this->get_config_option($this->_generate_config_option_name($section, $name));
873
+		// verify the newly retrieved config object, but suppress errors
874
+		if ($this->_verify_config_params($section, $name, $config_class, $config_obj, array(9), false)) {
875
+			// config is good, so set it and pass it back
876
+			$this->{$section}->{$name} = $config_obj;
877
+			return $this->{$section}->{$name};
878
+		}
879
+		// oops! $config_obj is not already set and does not exist in the db, so create a new one
880
+		$config_obj = $this->set_config($section, $name, $config_class);
881
+		// verify the newly created config object
882
+		if ($this->_verify_config_params($section, $name, $config_class, $config_obj, array(9))) {
883
+			return $this->{$section}->{$name};
884
+		} else {
885
+			EE_Error::add_error(
886
+				sprintf(__('The "%s" could not be retrieved from the database.', 'event_espresso'), $config_class),
887
+				__FILE__,
888
+				__FUNCTION__,
889
+				__LINE__
890
+			);
891
+		}
892
+		return null;
893
+	}
894
+
895
+
896
+	/**
897
+	 *    get_config_option
898
+	 *
899
+	 * @access    public
900
+	 * @param    string $config_option_name
901
+	 * @return    mixed EE_Config_Base | FALSE
902
+	 */
903
+	public function get_config_option($config_option_name = '')
904
+	{
905
+		// retrieve the wp-option for this config class.
906
+		$config_option = maybe_unserialize(get_option($config_option_name, array()));
907
+		if (empty($config_option)) {
908
+			EE_Config::log($config_option_name . '-NOT-FOUND');
909
+		}
910
+		return $config_option;
911
+	}
912
+
913
+
914
+	/**
915
+	 * log
916
+	 *
917
+	 * @param string $config_option_name
918
+	 */
919
+	public static function log($config_option_name = '')
920
+	{
921
+		if (EE_Config::logging_enabled() && ! empty($config_option_name)) {
922
+			$config_log = get_option(EE_Config::LOG_NAME, array());
923
+			// copy incoming $_REQUEST and sanitize it so we can save it
924
+			$_request = $_REQUEST;
925
+			array_walk_recursive($_request, 'sanitize_text_field');
926
+			$config_log[ (string) microtime(true) ] = array(
927
+				'config_name' => $config_option_name,
928
+				'request'     => $_request,
929
+			);
930
+			update_option(EE_Config::LOG_NAME, $config_log);
931
+		}
932
+	}
933
+
934
+
935
+	/**
936
+	 * trim_log
937
+	 * reduces the size of the config log to the length specified by EE_Config::LOG_LENGTH
938
+	 */
939
+	public static function trim_log()
940
+	{
941
+		if (! EE_Config::logging_enabled()) {
942
+			return;
943
+		}
944
+		$config_log = maybe_unserialize(get_option(EE_Config::LOG_NAME, array()));
945
+		$log_length = count($config_log);
946
+		if ($log_length > EE_Config::LOG_LENGTH) {
947
+			ksort($config_log);
948
+			$config_log = array_slice($config_log, $log_length - EE_Config::LOG_LENGTH, null, true);
949
+			update_option(EE_Config::LOG_NAME, $config_log);
950
+		}
951
+	}
952
+
953
+
954
+	/**
955
+	 *    get_page_for_posts
956
+	 *    if the wp-option "show_on_front" is set to "page", then this is the post_name for the post set in the
957
+	 *    wp-option "page_for_posts", or "posts" if no page is selected
958
+	 *
959
+	 * @access    public
960
+	 * @return    string
961
+	 */
962
+	public static function get_page_for_posts()
963
+	{
964
+		$page_for_posts = get_option('page_for_posts');
965
+		if (! $page_for_posts) {
966
+			return 'posts';
967
+		}
968
+		/** @type WPDB $wpdb */
969
+		global $wpdb;
970
+		$SQL = "SELECT post_name from $wpdb->posts WHERE post_type='posts' OR post_type='page' AND post_status='publish' AND ID=%d";
971
+		return $wpdb->get_var($wpdb->prepare($SQL, $page_for_posts));
972
+	}
973
+
974
+
975
+	/**
976
+	 *    register_shortcodes_and_modules.
977
+	 *    At this point, it's too early to tell if we're maintenance mode or not.
978
+	 *    In fact, this is where we give modules a chance to let core know they exist
979
+	 *    so they can help trigger maintenance mode if it's needed
980
+	 *
981
+	 * @access    public
982
+	 * @return    void
983
+	 */
984
+	public function register_shortcodes_and_modules()
985
+	{
986
+		// allow modules to set hooks for the rest of the system
987
+		EE_Registry::instance()->modules = $this->_register_modules();
988
+	}
989
+
990
+
991
+	/**
992
+	 *    initialize_shortcodes_and_modules
993
+	 *    meaning they can start adding their hooks to get stuff done
994
+	 *
995
+	 * @access    public
996
+	 * @return    void
997
+	 */
998
+	public function initialize_shortcodes_and_modules()
999
+	{
1000
+		// allow modules to set hooks for the rest of the system
1001
+		$this->_initialize_modules();
1002
+	}
1003
+
1004
+
1005
+	/**
1006
+	 *    widgets_init
1007
+	 *
1008
+	 * @access private
1009
+	 * @return void
1010
+	 */
1011
+	public function widgets_init()
1012
+	{
1013
+		// only init widgets on admin pages when not in complete maintenance, and
1014
+		// on frontend when not in any maintenance mode
1015
+		if (! EE_Maintenance_Mode::instance()->level()
1016
+			|| (
1017
+				is_admin()
1018
+				&& EE_Maintenance_Mode::instance()->level() !== EE_Maintenance_Mode::level_2_complete_maintenance
1019
+			)
1020
+		) {
1021
+			// grab list of installed widgets
1022
+			$widgets_to_register = glob(EE_WIDGETS . '*', GLOB_ONLYDIR);
1023
+			// filter list of modules to register
1024
+			$widgets_to_register = apply_filters(
1025
+				'FHEE__EE_Config__register_widgets__widgets_to_register',
1026
+				$widgets_to_register
1027
+			);
1028
+			if (! empty($widgets_to_register)) {
1029
+				// cycle thru widget folders
1030
+				foreach ($widgets_to_register as $widget_path) {
1031
+					// add to list of installed widget modules
1032
+					EE_Config::register_ee_widget($widget_path);
1033
+				}
1034
+			}
1035
+			// filter list of installed modules
1036
+			EE_Registry::instance()->widgets = apply_filters(
1037
+				'FHEE__EE_Config__register_widgets__installed_widgets',
1038
+				EE_Registry::instance()->widgets
1039
+			);
1040
+		}
1041
+	}
1042
+
1043
+
1044
+	/**
1045
+	 *    register_ee_widget - makes core aware of this widget
1046
+	 *
1047
+	 * @access    public
1048
+	 * @param    string $widget_path - full path up to and including widget folder
1049
+	 * @return    void
1050
+	 */
1051
+	public static function register_ee_widget($widget_path = null)
1052
+	{
1053
+		do_action('AHEE__EE_Config__register_widget__begin', $widget_path);
1054
+		$widget_ext = '.widget.php';
1055
+		// make all separators match
1056
+		$widget_path = rtrim(str_replace('/\\', DS, $widget_path), DS);
1057
+		// does the file path INCLUDE the actual file name as part of the path ?
1058
+		if (strpos($widget_path, $widget_ext) !== false) {
1059
+			// grab and shortcode file name from directory name and break apart at dots
1060
+			$file_name = explode('.', basename($widget_path));
1061
+			// take first segment from file name pieces and remove class prefix if it exists
1062
+			$widget = strpos($file_name[0], 'EEW_') === 0 ? substr($file_name[0], 4) : $file_name[0];
1063
+			// sanitize shortcode directory name
1064
+			$widget = sanitize_key($widget);
1065
+			// now we need to rebuild the shortcode path
1066
+			$widget_path = explode(DS, $widget_path);
1067
+			// remove last segment
1068
+			array_pop($widget_path);
1069
+			// glue it back together
1070
+			$widget_path = implode(DS, $widget_path);
1071
+		} else {
1072
+			// grab and sanitize widget directory name
1073
+			$widget = sanitize_key(basename($widget_path));
1074
+		}
1075
+		// create classname from widget directory name
1076
+		$widget = str_replace(' ', '_', ucwords(str_replace('_', ' ', $widget)));
1077
+		// add class prefix
1078
+		$widget_class = 'EEW_' . $widget;
1079
+		// does the widget exist ?
1080
+		if (! is_readable($widget_path . DS . $widget_class . $widget_ext)) {
1081
+			$msg = sprintf(
1082
+				__(
1083
+					'The requested %s widget file could not be found or is not readable due to file permissions. Please ensure the following path is correct: %s',
1084
+					'event_espresso'
1085
+				),
1086
+				$widget_class,
1087
+				$widget_path . DS . $widget_class . $widget_ext
1088
+			);
1089
+			EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__);
1090
+			return;
1091
+		}
1092
+		// load the widget class file
1093
+		require_once($widget_path . DS . $widget_class . $widget_ext);
1094
+		// verify that class exists
1095
+		if (! class_exists($widget_class)) {
1096
+			$msg = sprintf(__('The requested %s widget class does not exist.', 'event_espresso'), $widget_class);
1097
+			EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__);
1098
+			return;
1099
+		}
1100
+		register_widget($widget_class);
1101
+		// add to array of registered widgets
1102
+		EE_Registry::instance()->widgets->{$widget_class} = $widget_path . DS . $widget_class . $widget_ext;
1103
+	}
1104
+
1105
+
1106
+	/**
1107
+	 *        _register_modules
1108
+	 *
1109
+	 * @access private
1110
+	 * @return array
1111
+	 */
1112
+	private function _register_modules()
1113
+	{
1114
+		// grab list of installed modules
1115
+		$modules_to_register = glob(EE_MODULES . '*', GLOB_ONLYDIR);
1116
+		// filter list of modules to register
1117
+		$modules_to_register = apply_filters(
1118
+			'FHEE__EE_Config__register_modules__modules_to_register',
1119
+			$modules_to_register
1120
+		);
1121
+		if (! empty($modules_to_register)) {
1122
+			// loop through folders
1123
+			foreach ($modules_to_register as $module_path) {
1124
+				/**TEMPORARILY EXCLUDE gateways from modules for time being**/
1125
+				if ($module_path !== EE_MODULES . 'zzz-copy-this-module-template'
1126
+					&& $module_path !== EE_MODULES . 'gateways'
1127
+				) {
1128
+					// add to list of installed modules
1129
+					EE_Config::register_module($module_path);
1130
+				}
1131
+			}
1132
+		}
1133
+		// filter list of installed modules
1134
+		return apply_filters(
1135
+			'FHEE__EE_Config___register_modules__installed_modules',
1136
+			EE_Registry::instance()->modules
1137
+		);
1138
+	}
1139
+
1140
+
1141
+	/**
1142
+	 *    register_module - makes core aware of this module
1143
+	 *
1144
+	 * @access    public
1145
+	 * @param    string $module_path - full path up to and including module folder
1146
+	 * @return    bool
1147
+	 */
1148
+	public static function register_module($module_path = null)
1149
+	{
1150
+		do_action('AHEE__EE_Config__register_module__begin', $module_path);
1151
+		$module_ext = '.module.php';
1152
+		// make all separators match
1153
+		$module_path = str_replace(array('\\', '/'), DS, $module_path);
1154
+		// does the file path INCLUDE the actual file name as part of the path ?
1155
+		if (strpos($module_path, $module_ext) !== false) {
1156
+			// grab and shortcode file name from directory name and break apart at dots
1157
+			$module_file = explode('.', basename($module_path));
1158
+			// now we need to rebuild the shortcode path
1159
+			$module_path = explode(DS, $module_path);
1160
+			// remove last segment
1161
+			array_pop($module_path);
1162
+			// glue it back together
1163
+			$module_path = implode(DS, $module_path) . DS;
1164
+			// take first segment from file name pieces and sanitize it
1165
+			$module = preg_replace('/[^a-zA-Z0-9_\-]/', '', $module_file[0]);
1166
+			// ensure class prefix is added
1167
+			$module_class = strpos($module, 'EED_') !== 0 ? 'EED_' . $module : $module;
1168
+		} else {
1169
+			// we need to generate the filename based off of the folder name
1170
+			// grab and sanitize module name
1171
+			$module = strtolower(basename($module_path));
1172
+			$module = preg_replace('/[^a-z0-9_\-]/', '', $module);
1173
+			// like trailingslashit()
1174
+			$module_path = rtrim($module_path, DS) . DS;
1175
+			// create classname from module directory name
1176
+			$module = str_replace(' ', '_', ucwords(str_replace('_', ' ', $module)));
1177
+			// add class prefix
1178
+			$module_class = 'EED_' . $module;
1179
+		}
1180
+		// does the module exist ?
1181
+		if (! is_readable($module_path . DS . $module_class . $module_ext)) {
1182
+			$msg = sprintf(
1183
+				__(
1184
+					'The requested %s module file could not be found or is not readable due to file permissions.',
1185
+					'event_espresso'
1186
+				),
1187
+				$module
1188
+			);
1189
+			EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__);
1190
+			return false;
1191
+		}
1192
+		// load the module class file
1193
+		require_once($module_path . $module_class . $module_ext);
1194
+		// verify that class exists
1195
+		if (! class_exists($module_class)) {
1196
+			$msg = sprintf(__('The requested %s module class does not exist.', 'event_espresso'), $module_class);
1197
+			EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__);
1198
+			return false;
1199
+		}
1200
+		// add to array of registered modules
1201
+		EE_Registry::instance()->modules->{$module_class} = $module_path . $module_class . $module_ext;
1202
+		do_action(
1203
+			'AHEE__EE_Config__register_module__complete',
1204
+			$module_class,
1205
+			EE_Registry::instance()->modules->{$module_class}
1206
+		);
1207
+		return true;
1208
+	}
1209
+
1210
+
1211
+	/**
1212
+	 *    _initialize_modules
1213
+	 *    allow modules to set hooks for the rest of the system
1214
+	 *
1215
+	 * @access private
1216
+	 * @return void
1217
+	 */
1218
+	private function _initialize_modules()
1219
+	{
1220
+		// cycle thru shortcode folders
1221
+		foreach (EE_Registry::instance()->modules as $module_class => $module_path) {
1222
+			// fire the shortcode class's set_hooks methods in case it needs to hook into other parts of the system
1223
+			// which set hooks ?
1224
+			if (is_admin()) {
1225
+				// fire immediately
1226
+				call_user_func(array($module_class, 'set_hooks_admin'));
1227
+			} else {
1228
+				// delay until other systems are online
1229
+				add_action(
1230
+					'AHEE__EE_System__set_hooks_for_shortcodes_modules_and_addons',
1231
+					array($module_class, 'set_hooks')
1232
+				);
1233
+			}
1234
+		}
1235
+	}
1236
+
1237
+
1238
+	/**
1239
+	 *    register_route - adds module method routes to route_map
1240
+	 *
1241
+	 * @access    public
1242
+	 * @param    string $route       - "pretty" public alias for module method
1243
+	 * @param    string $module      - module name (classname without EED_ prefix)
1244
+	 * @param    string $method_name - the actual module method to be routed to
1245
+	 * @param    string $key         - url param key indicating a route is being called
1246
+	 * @return    bool
1247
+	 */
1248
+	public static function register_route($route = null, $module = null, $method_name = null, $key = 'ee')
1249
+	{
1250
+		do_action('AHEE__EE_Config__register_route__begin', $route, $module, $method_name);
1251
+		$module = str_replace('EED_', '', $module);
1252
+		$module_class = 'EED_' . $module;
1253
+		if (! isset(EE_Registry::instance()->modules->{$module_class})) {
1254
+			$msg = sprintf(__('The module %s has not been registered.', 'event_espresso'), $module);
1255
+			EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__);
1256
+			return false;
1257
+		}
1258
+		if (empty($route)) {
1259
+			$msg = sprintf(__('No route has been supplied.', 'event_espresso'), $route);
1260
+			EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__);
1261
+			return false;
1262
+		}
1263
+		if (! method_exists('EED_' . $module, $method_name)) {
1264
+			$msg = sprintf(
1265
+				__('A valid class method for the %s route has not been supplied.', 'event_espresso'),
1266
+				$route
1267
+			);
1268
+			EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__);
1269
+			return false;
1270
+		}
1271
+		EE_Config::$_module_route_map[ $key ][ $route ] = array('EED_' . $module, $method_name);
1272
+		return true;
1273
+	}
1274
+
1275
+
1276
+	/**
1277
+	 *    get_route - get module method route
1278
+	 *
1279
+	 * @access    public
1280
+	 * @param    string $route - "pretty" public alias for module method
1281
+	 * @param    string $key   - url param key indicating a route is being called
1282
+	 * @return    string
1283
+	 */
1284
+	public static function get_route($route = null, $key = 'ee')
1285
+	{
1286
+		do_action('AHEE__EE_Config__get_route__begin', $route);
1287
+		$route = (string) apply_filters('FHEE__EE_Config__get_route', $route);
1288
+		if (isset(EE_Config::$_module_route_map[ $key ][ $route ])) {
1289
+			return EE_Config::$_module_route_map[ $key ][ $route ];
1290
+		}
1291
+		return null;
1292
+	}
1293
+
1294
+
1295
+	/**
1296
+	 *    get_routes - get ALL module method routes
1297
+	 *
1298
+	 * @access    public
1299
+	 * @return    array
1300
+	 */
1301
+	public static function get_routes()
1302
+	{
1303
+		return EE_Config::$_module_route_map;
1304
+	}
1305
+
1306
+
1307
+	/**
1308
+	 *    register_forward - allows modules to forward request to another module for further processing
1309
+	 *
1310
+	 * @access    public
1311
+	 * @param    string       $route   - "pretty" public alias for module method
1312
+	 * @param    integer      $status  - integer value corresponding  to status constant strings set in module parent
1313
+	 *                                 class, allows different forwards to be served based on status
1314
+	 * @param    array|string $forward - function name or array( class, method )
1315
+	 * @param    string       $key     - url param key indicating a route is being called
1316
+	 * @return    bool
1317
+	 */
1318
+	public static function register_forward($route = null, $status = 0, $forward = null, $key = 'ee')
1319
+	{
1320
+		do_action('AHEE__EE_Config__register_forward', $route, $status, $forward);
1321
+		if (! isset(EE_Config::$_module_route_map[ $key ][ $route ]) || empty($route)) {
1322
+			$msg = sprintf(
1323
+				__('The module route %s for this forward has not been registered.', 'event_espresso'),
1324
+				$route
1325
+			);
1326
+			EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__);
1327
+			return false;
1328
+		}
1329
+		if (empty($forward)) {
1330
+			$msg = sprintf(__('No forwarding route has been supplied.', 'event_espresso'), $route);
1331
+			EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__);
1332
+			return false;
1333
+		}
1334
+		if (is_array($forward)) {
1335
+			if (! isset($forward[1])) {
1336
+				$msg = sprintf(
1337
+					__('A class method for the %s forwarding route has not been supplied.', 'event_espresso'),
1338
+					$route
1339
+				);
1340
+				EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__);
1341
+				return false;
1342
+			}
1343
+			if (! method_exists($forward[0], $forward[1])) {
1344
+				$msg = sprintf(
1345
+					__('The class method %s for the %s forwarding route is in invalid.', 'event_espresso'),
1346
+					$forward[1],
1347
+					$route
1348
+				);
1349
+				EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__);
1350
+				return false;
1351
+			}
1352
+		} elseif (! function_exists($forward)) {
1353
+			$msg = sprintf(
1354
+				__('The function %s for the %s forwarding route is in invalid.', 'event_espresso'),
1355
+				$forward,
1356
+				$route
1357
+			);
1358
+			EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__);
1359
+			return false;
1360
+		}
1361
+		EE_Config::$_module_forward_map[ $key ][ $route ][ absint($status) ] = $forward;
1362
+		return true;
1363
+	}
1364
+
1365
+
1366
+	/**
1367
+	 *    get_forward - get forwarding route
1368
+	 *
1369
+	 * @access    public
1370
+	 * @param    string  $route  - "pretty" public alias for module method
1371
+	 * @param    integer $status - integer value corresponding  to status constant strings set in module parent class,
1372
+	 *                           allows different forwards to be served based on status
1373
+	 * @param    string  $key    - url param key indicating a route is being called
1374
+	 * @return    string
1375
+	 */
1376
+	public static function get_forward($route = null, $status = 0, $key = 'ee')
1377
+	{
1378
+		do_action('AHEE__EE_Config__get_forward__begin', $route, $status);
1379
+		if (isset(EE_Config::$_module_forward_map[ $key ][ $route ][ $status ])) {
1380
+			return apply_filters(
1381
+				'FHEE__EE_Config__get_forward',
1382
+				EE_Config::$_module_forward_map[ $key ][ $route ][ $status ],
1383
+				$route,
1384
+				$status
1385
+			);
1386
+		}
1387
+		return null;
1388
+	}
1389
+
1390
+
1391
+	/**
1392
+	 *    register_forward - allows modules to specify different view templates for different method routes and status
1393
+	 *    results
1394
+	 *
1395
+	 * @access    public
1396
+	 * @param    string  $route  - "pretty" public alias for module method
1397
+	 * @param    integer $status - integer value corresponding  to status constant strings set in module parent class,
1398
+	 *                           allows different views to be served based on status
1399
+	 * @param    string  $view
1400
+	 * @param    string  $key    - url param key indicating a route is being called
1401
+	 * @return    bool
1402
+	 */
1403
+	public static function register_view($route = null, $status = 0, $view = null, $key = 'ee')
1404
+	{
1405
+		do_action('AHEE__EE_Config__register_view__begin', $route, $status, $view);
1406
+		if (! isset(EE_Config::$_module_route_map[ $key ][ $route ]) || empty($route)) {
1407
+			$msg = sprintf(
1408
+				__('The module route %s for this view has not been registered.', 'event_espresso'),
1409
+				$route
1410
+			);
1411
+			EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__);
1412
+			return false;
1413
+		}
1414
+		if (! is_readable($view)) {
1415
+			$msg = sprintf(
1416
+				__(
1417
+					'The %s view file could not be found or is not readable due to file permissions.',
1418
+					'event_espresso'
1419
+				),
1420
+				$view
1421
+			);
1422
+			EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__);
1423
+			return false;
1424
+		}
1425
+		EE_Config::$_module_view_map[ $key ][ $route ][ absint($status) ] = $view;
1426
+		return true;
1427
+	}
1428
+
1429
+
1430
+	/**
1431
+	 *    get_view - get view for route and status
1432
+	 *
1433
+	 * @access    public
1434
+	 * @param    string  $route  - "pretty" public alias for module method
1435
+	 * @param    integer $status - integer value corresponding  to status constant strings set in module parent class,
1436
+	 *                           allows different views to be served based on status
1437
+	 * @param    string  $key    - url param key indicating a route is being called
1438
+	 * @return    string
1439
+	 */
1440
+	public static function get_view($route = null, $status = 0, $key = 'ee')
1441
+	{
1442
+		do_action('AHEE__EE_Config__get_view__begin', $route, $status);
1443
+		if (isset(EE_Config::$_module_view_map[ $key ][ $route ][ $status ])) {
1444
+			return apply_filters(
1445
+				'FHEE__EE_Config__get_view',
1446
+				EE_Config::$_module_view_map[ $key ][ $route ][ $status ],
1447
+				$route,
1448
+				$status
1449
+			);
1450
+		}
1451
+		return null;
1452
+	}
1453
+
1454
+
1455
+	public function update_addon_option_names()
1456
+	{
1457
+		update_option(EE_Config::ADDON_OPTION_NAMES, $this->_addon_option_names);
1458
+	}
1459
+
1460
+
1461
+	public function shutdown()
1462
+	{
1463
+		$this->update_addon_option_names();
1464
+	}
1465
+
1466
+
1467
+	/**
1468
+	 * @return LegacyShortcodesManager
1469
+	 */
1470
+	public static function getLegacyShortcodesManager()
1471
+	{
1472
+
1473
+		if (! EE_Config::instance()->legacy_shortcodes_manager instanceof LegacyShortcodesManager) {
1474
+			EE_Config::instance()->legacy_shortcodes_manager = new LegacyShortcodesManager(
1475
+				EE_Registry::instance()
1476
+			);
1477
+		}
1478
+		return EE_Config::instance()->legacy_shortcodes_manager;
1479
+	}
1480
+
1481
+
1482
+	/**
1483
+	 * register_shortcode - makes core aware of this shortcode
1484
+	 *
1485
+	 * @deprecated 4.9.26
1486
+	 * @param    string $shortcode_path - full path up to and including shortcode folder
1487
+	 * @return    bool
1488
+	 */
1489
+	public static function register_shortcode($shortcode_path = null)
1490
+	{
1491
+		EE_Error::doing_it_wrong(
1492
+			__METHOD__,
1493
+			__(
1494
+				'Usage is deprecated. Use \EventEspresso\core\services\shortcodes\LegacyShortcodesManager::registerShortcode() as direct replacement, or better yet, please see the new \EventEspresso\core\services\shortcodes\ShortcodesManager class.',
1495
+				'event_espresso'
1496
+			),
1497
+			'4.9.26'
1498
+		);
1499
+		return EE_Config::instance()->getLegacyShortcodesManager()->registerShortcode($shortcode_path);
1500
+	}
1501
+}
2130 1502
 
1503
+/**
1504
+ * Base class used for config classes. These classes should generally not have
1505
+ * magic functions in use, except we'll allow them to magically set and get stuff...
1506
+ * basically, they should just be well-defined stdClasses
1507
+ */
1508
+class EE_Config_Base
1509
+{
2131 1510
 
2132
-    /**
2133
-     *    class constructor
2134
-     *
2135
-     * @access    public
2136
-     * @param string $CNT_ISO
2137
-     * @throws \EE_Error
2138
-     */
2139
-    public function __construct($CNT_ISO = '')
2140
-    {
2141
-        /** @var \EventEspresso\core\services\database\TableAnalysis $table_analysis */
2142
-        $table_analysis = EE_Registry::instance()->create('TableAnalysis', array(), true);
2143
-        // get country code from organization settings or use default
2144
-        $ORG_CNT = isset(EE_Registry::instance()->CFG->organization)
2145
-                   && EE_Registry::instance()->CFG->organization instanceof EE_Organization_Config
2146
-            ? EE_Registry::instance()->CFG->organization->CNT_ISO
2147
-            : '';
2148
-        // but override if requested
2149
-        $CNT_ISO = ! empty($CNT_ISO) ? $CNT_ISO : $ORG_CNT;
2150
-        // so if that all went well, and we are not in M-Mode (cuz you can't query the db in M-Mode) and double-check the countries table exists
2151
-        if (! empty($CNT_ISO)
2152
-            && EE_Maintenance_Mode::instance()->models_can_query()
2153
-            && $table_analysis->tableExists(EE_Registry::instance()->load_model('Country')->table())
2154
-        ) {
2155
-            // retrieve the country settings from the db, just in case they have been customized
2156
-            $country = EE_Registry::instance()->load_model('Country')->get_one_by_ID($CNT_ISO);
2157
-            if ($country instanceof EE_Country) {
2158
-                $this->code = $country->currency_code();    // currency code: USD, CAD, EUR
2159
-                $this->name = $country->currency_name_single();    // Dollar
2160
-                $this->plural = $country->currency_name_plural();    // Dollars
2161
-                $this->sign = $country->currency_sign();            // currency sign: $
2162
-                $this->sign_b4 = $country->currency_sign_before(
2163
-                );        // currency sign before or after: $TRUE  or  FALSE$
2164
-                $this->dec_plc = $country->currency_decimal_places();    // decimal places: 2 = 0.00  3 = 0.000
2165
-                $this->dec_mrk = $country->currency_decimal_mark(
2166
-                );    // decimal mark: (comma) ',' = 0,01   or (decimal) '.' = 0.01
2167
-                $this->thsnds = $country->currency_thousands_separator(
2168
-                );    // thousands separator: (comma) ',' = 1,000   or (decimal) '.' = 1.000
2169
-            }
2170
-        }
2171
-        // fallback to hardcoded defaults, in case the above failed
2172
-        if (empty($this->code)) {
2173
-            // set default currency settings
2174
-            $this->code = 'USD';    // currency code: USD, CAD, EUR
2175
-            $this->name = __('Dollar', 'event_espresso');    // Dollar
2176
-            $this->plural = __('Dollars', 'event_espresso');    // Dollars
2177
-            $this->sign = '$';    // currency sign: $
2178
-            $this->sign_b4 = true;    // currency sign before or after: $TRUE  or  FALSE$
2179
-            $this->dec_plc = 2;    // decimal places: 2 = 0.00  3 = 0.000
2180
-            $this->dec_mrk = '.';    // decimal mark: (comma) ',' = 0,01   or (decimal) '.' = 0.01
2181
-            $this->thsnds = ',';    // thousands separator: (comma) ',' = 1,000   or (decimal) '.' = 1.000
2182
-        }
2183
-    }
1511
+	/**
1512
+	 * Utility function for escaping the value of a property and returning.
1513
+	 *
1514
+	 * @param string $property property name (checks to see if exists).
1515
+	 * @return mixed if a detected type found return the escaped value, otherwise just the raw value is returned.
1516
+	 * @throws \EE_Error
1517
+	 */
1518
+	public function get_pretty($property)
1519
+	{
1520
+		if (! property_exists($this, $property)) {
1521
+			throw new EE_Error(
1522
+				sprintf(
1523
+					__(
1524
+						'%1$s::get_pretty() has been called with the property %2$s which does not exist on the %1$s config class.',
1525
+						'event_espresso'
1526
+					),
1527
+					get_class($this),
1528
+					$property
1529
+				)
1530
+			);
1531
+		}
1532
+		// just handling escaping of strings for now.
1533
+		if (is_string($this->{$property})) {
1534
+			return stripslashes($this->{$property});
1535
+		}
1536
+		return $this->{$property};
1537
+	}
1538
+
1539
+
1540
+	public function populate()
1541
+	{
1542
+		// grab defaults via a new instance of this class.
1543
+		$class_name = get_class($this);
1544
+		$defaults = new $class_name;
1545
+		// loop through the properties for this class and see if they are set.  If they are NOT, then grab the
1546
+		// default from our $defaults object.
1547
+		foreach (get_object_vars($defaults) as $property => $value) {
1548
+			if ($this->{$property} === null) {
1549
+				$this->{$property} = $value;
1550
+			}
1551
+		}
1552
+		// cleanup
1553
+		unset($defaults);
1554
+	}
1555
+
1556
+
1557
+	/**
1558
+	 *        __isset
1559
+	 *
1560
+	 * @param $a
1561
+	 * @return bool
1562
+	 */
1563
+	public function __isset($a)
1564
+	{
1565
+		return false;
1566
+	}
1567
+
1568
+
1569
+	/**
1570
+	 *        __unset
1571
+	 *
1572
+	 * @param $a
1573
+	 * @return bool
1574
+	 */
1575
+	public function __unset($a)
1576
+	{
1577
+		return false;
1578
+	}
1579
+
1580
+
1581
+	/**
1582
+	 *        __clone
1583
+	 */
1584
+	public function __clone()
1585
+	{
1586
+	}
1587
+
1588
+
1589
+	/**
1590
+	 *        __wakeup
1591
+	 */
1592
+	public function __wakeup()
1593
+	{
1594
+	}
1595
+
1596
+
1597
+	/**
1598
+	 *        __destruct
1599
+	 */
1600
+	public function __destruct()
1601
+	{
1602
+	}
2184 1603
 }
2185 1604
 
2186 1605
 
2187 1606
 /**
2188 1607
  * Class for defining what's in the EE_Config relating to registration settings
2189 1608
  */
2190
-class EE_Registration_Config extends EE_Config_Base
1609
+class EE_Core_Config extends EE_Config_Base
2191 1610
 {
2192 1611
 
2193
-    /**
2194
-     * Default registration status
2195
-     *
2196
-     * @var string $default_STS_ID
2197
-     * eg 'RPP'
2198
-     */
2199
-    public $default_STS_ID;
2200
-
2201
-
2202
-    /**
2203
-     * For new events, this will be the default value for the maximum number of tickets (equivalent to maximum number of
2204
-     * registrations)
2205
-     *
2206
-     * @var int
2207
-     */
2208
-    public $default_maximum_number_of_tickets;
2209
-
2210
-
2211
-    /**
2212
-     * level of validation to apply to email addresses
2213
-     *
2214
-     * @var string $email_validation_level
2215
-     * options: 'basic', 'wp_default', 'i18n', 'i18n_dns'
2216
-     */
2217
-    public $email_validation_level;
2218
-
2219
-    /**
2220
-     *    whether or not to show alternate payment options during the reg process if payment status is pending
2221
-     *
2222
-     * @var boolean $show_pending_payment_options
2223
-     */
2224
-    public $show_pending_payment_options;
2225
-
2226
-    /**
2227
-     * Whether to skip the registration confirmation page
2228
-     *
2229
-     * @var boolean $skip_reg_confirmation
2230
-     */
2231
-    public $skip_reg_confirmation;
2232
-
2233
-    /**
2234
-     * an array of SPCO reg steps where:
2235
-     *        the keys denotes the reg step order
2236
-     *        each element consists of an array with the following elements:
2237
-     *            "file_path" => the file path to the EE_SPCO_Reg_Step class
2238
-     *            "class_name" => the specific EE_SPCO_Reg_Step child class name
2239
-     *            "slug" => the URL param used to trigger the reg step
2240
-     *
2241
-     * @var array $reg_steps
2242
-     */
2243
-    public $reg_steps;
2244
-
2245
-    /**
2246
-     * Whether registration confirmation should be the last page of SPCO
2247
-     *
2248
-     * @var boolean $reg_confirmation_last
2249
-     */
2250
-    public $reg_confirmation_last;
2251
-
2252
-    /**
2253
-     * Whether or not to enable the EE Bot Trap
2254
-     *
2255
-     * @var boolean $use_bot_trap
2256
-     */
2257
-    public $use_bot_trap;
2258
-
2259
-    /**
2260
-     * Whether or not to encrypt some data sent by the EE Bot Trap
2261
-     *
2262
-     * @var boolean $use_encryption
2263
-     */
2264
-    public $use_encryption;
2265
-
2266
-    /**
2267
-     * Whether or not to use ReCaptcha
2268
-     *
2269
-     * @var boolean $use_captcha
2270
-     */
2271
-    public $use_captcha;
2272
-
2273
-    /**
2274
-     * ReCaptcha Theme
2275
-     *
2276
-     * @var string $recaptcha_theme
2277
-     *    options: 'dark', 'light', 'invisible'
2278
-     */
2279
-    public $recaptcha_theme;
2280
-
2281
-    /**
2282
-     * ReCaptcha Badge - determines the position of the reCAPTCHA badge if using Invisible ReCaptcha.
2283
-     *
2284
-     * @var string $recaptcha_badge
2285
-     *    options: 'bottomright', 'bottomleft', 'inline'
2286
-     */
2287
-    public $recaptcha_badge;
2288
-
2289
-    /**
2290
-     * ReCaptcha Type
2291
-     *
2292
-     * @var string $recaptcha_type
2293
-     *    options: 'audio', 'image'
2294
-     */
2295
-    public $recaptcha_type;
2296
-
2297
-    /**
2298
-     * ReCaptcha language
2299
-     *
2300
-     * @var string $recaptcha_language
2301
-     * eg 'en'
2302
-     */
2303
-    public $recaptcha_language;
2304
-
2305
-    /**
2306
-     * ReCaptcha public key
2307
-     *
2308
-     * @var string $recaptcha_publickey
2309
-     */
2310
-    public $recaptcha_publickey;
2311
-
2312
-    /**
2313
-     * ReCaptcha private key
2314
-     *
2315
-     * @var string $recaptcha_privatekey
2316
-     */
2317
-    public $recaptcha_privatekey;
2318
-
2319
-    /**
2320
-     * array of form names protected by ReCaptcha
2321
-     *
2322
-     * @var array $recaptcha_protected_forms
2323
-     */
2324
-    public $recaptcha_protected_forms;
2325
-
2326
-    /**
2327
-     * ReCaptcha width
2328
-     *
2329
-     * @var int $recaptcha_width
2330
-     * @deprecated
2331
-     */
2332
-    public $recaptcha_width;
2333
-
2334
-    /**
2335
-     * Whether or not invalid attempts to directly access the registration checkout page should be tracked.
2336
-     *
2337
-     * @var boolean $track_invalid_checkout_access
2338
-     */
2339
-    protected $track_invalid_checkout_access = true;
2340
-
2341
-    /**
2342
-     * String describing how long to keep payment logs. Passed into DateTime constructor
2343
-     * @var string
2344
-     */
2345
-    public $gateway_log_lifespan = '1 week';
2346
-
1612
+	public $current_blog_id;
1613
+
1614
+	public $ee_ueip_optin;
1615
+
1616
+	public $ee_ueip_has_notified;
1617
+
1618
+	/**
1619
+	 * Not to be confused with the 4 critical page variables (See
1620
+	 * get_critical_pages_array()), this is just an array of wp posts that have EE
1621
+	 * shortcodes in them. Keys are slugs, values are arrays with only 1 element: where the key is the shortcode
1622
+	 * in the page, and the value is the page's ID. The key 'posts' is basically a duplicate of this same array.
1623
+	 *
1624
+	 * @var array
1625
+	 */
1626
+	public $post_shortcodes;
1627
+
1628
+	public $module_route_map;
1629
+
1630
+	public $module_forward_map;
1631
+
1632
+	public $module_view_map;
1633
+
1634
+	/**
1635
+	 * The next 4 vars are the IDs of critical EE pages.
1636
+	 *
1637
+	 * @var int
1638
+	 */
1639
+	public $reg_page_id;
1640
+
1641
+	public $txn_page_id;
1642
+
1643
+	public $thank_you_page_id;
1644
+
1645
+	public $cancel_page_id;
1646
+
1647
+	/**
1648
+	 * The next 4 vars are the URLs of critical EE pages.
1649
+	 *
1650
+	 * @var int
1651
+	 */
1652
+	public $reg_page_url;
1653
+
1654
+	public $txn_page_url;
1655
+
1656
+	public $thank_you_page_url;
1657
+
1658
+	public $cancel_page_url;
1659
+
1660
+	/**
1661
+	 * The next vars relate to the custom slugs for EE CPT routes
1662
+	 */
1663
+	public $event_cpt_slug;
1664
+
1665
+
1666
+	/**
1667
+	 * This caches the _ee_ueip_option in case this config is reset in the same
1668
+	 * request across blog switches in a multisite context.
1669
+	 * Avoids extra queries to the db for this option.
1670
+	 *
1671
+	 * @var bool
1672
+	 */
1673
+	public static $ee_ueip_option;
1674
+
1675
+
1676
+	/**
1677
+	 *    class constructor
1678
+	 *
1679
+	 * @access    public
1680
+	 */
1681
+	public function __construct()
1682
+	{
1683
+		// set default organization settings
1684
+		$this->current_blog_id = get_current_blog_id();
1685
+		$this->current_blog_id = $this->current_blog_id === null ? 1 : $this->current_blog_id;
1686
+		$this->ee_ueip_optin = $this->_get_main_ee_ueip_optin();
1687
+		$this->ee_ueip_has_notified = is_main_site() ? get_option('ee_ueip_has_notified', false) : true;
1688
+		$this->post_shortcodes = array();
1689
+		$this->module_route_map = array();
1690
+		$this->module_forward_map = array();
1691
+		$this->module_view_map = array();
1692
+		// critical EE page IDs
1693
+		$this->reg_page_id = 0;
1694
+		$this->txn_page_id = 0;
1695
+		$this->thank_you_page_id = 0;
1696
+		$this->cancel_page_id = 0;
1697
+		// critical EE page URLs
1698
+		$this->reg_page_url = '';
1699
+		$this->txn_page_url = '';
1700
+		$this->thank_you_page_url = '';
1701
+		$this->cancel_page_url = '';
1702
+		// cpt slugs
1703
+		$this->event_cpt_slug = __('events', 'event_espresso');
1704
+		// ueip constant check
1705
+		if (defined('EE_DISABLE_UXIP') && EE_DISABLE_UXIP) {
1706
+			$this->ee_ueip_optin = false;
1707
+			$this->ee_ueip_has_notified = true;
1708
+		}
1709
+	}
1710
+
1711
+
1712
+	/**
1713
+	 * @return array
1714
+	 */
1715
+	public function get_critical_pages_array()
1716
+	{
1717
+		return array(
1718
+			$this->reg_page_id,
1719
+			$this->txn_page_id,
1720
+			$this->thank_you_page_id,
1721
+			$this->cancel_page_id,
1722
+		);
1723
+	}
1724
+
1725
+
1726
+	/**
1727
+	 * @return array
1728
+	 */
1729
+	public function get_critical_pages_shortcodes_array()
1730
+	{
1731
+		return array(
1732
+			$this->reg_page_id       => 'ESPRESSO_CHECKOUT',
1733
+			$this->txn_page_id       => 'ESPRESSO_TXN_PAGE',
1734
+			$this->thank_you_page_id => 'ESPRESSO_THANK_YOU',
1735
+			$this->cancel_page_id    => 'ESPRESSO_CANCELLED',
1736
+		);
1737
+	}
1738
+
1739
+
1740
+	/**
1741
+	 *  gets/returns URL for EE reg_page
1742
+	 *
1743
+	 * @access    public
1744
+	 * @return    string
1745
+	 */
1746
+	public function reg_page_url()
1747
+	{
1748
+		if (! $this->reg_page_url) {
1749
+			$this->reg_page_url = add_query_arg(
1750
+				array('uts' => time()),
1751
+				get_permalink($this->reg_page_id)
1752
+			) . '#checkout';
1753
+		}
1754
+		return $this->reg_page_url;
1755
+	}
1756
+
1757
+
1758
+	/**
1759
+	 *  gets/returns URL for EE txn_page
1760
+	 *
1761
+	 * @param array $query_args like what gets passed to
1762
+	 *                          add_query_arg() as the first argument
1763
+	 * @access    public
1764
+	 * @return    string
1765
+	 */
1766
+	public function txn_page_url($query_args = array())
1767
+	{
1768
+		if (! $this->txn_page_url) {
1769
+			$this->txn_page_url = get_permalink($this->txn_page_id);
1770
+		}
1771
+		if ($query_args) {
1772
+			return add_query_arg($query_args, $this->txn_page_url);
1773
+		} else {
1774
+			return $this->txn_page_url;
1775
+		}
1776
+	}
1777
+
1778
+
1779
+	/**
1780
+	 *  gets/returns URL for EE thank_you_page
1781
+	 *
1782
+	 * @param array $query_args like what gets passed to
1783
+	 *                          add_query_arg() as the first argument
1784
+	 * @access    public
1785
+	 * @return    string
1786
+	 */
1787
+	public function thank_you_page_url($query_args = array())
1788
+	{
1789
+		if (! $this->thank_you_page_url) {
1790
+			$this->thank_you_page_url = get_permalink($this->thank_you_page_id);
1791
+		}
1792
+		if ($query_args) {
1793
+			return add_query_arg($query_args, $this->thank_you_page_url);
1794
+		} else {
1795
+			return $this->thank_you_page_url;
1796
+		}
1797
+	}
1798
+
1799
+
1800
+	/**
1801
+	 *  gets/returns URL for EE cancel_page
1802
+	 *
1803
+	 * @access    public
1804
+	 * @return    string
1805
+	 */
1806
+	public function cancel_page_url()
1807
+	{
1808
+		if (! $this->cancel_page_url) {
1809
+			$this->cancel_page_url = get_permalink($this->cancel_page_id);
1810
+		}
1811
+		return $this->cancel_page_url;
1812
+	}
1813
+
1814
+
1815
+	/**
1816
+	 * Resets all critical page urls to their original state.  Used primarily by the __sleep() magic method currently.
1817
+	 *
1818
+	 * @since 4.7.5
1819
+	 */
1820
+	protected function _reset_urls()
1821
+	{
1822
+		$this->reg_page_url = '';
1823
+		$this->txn_page_url = '';
1824
+		$this->cancel_page_url = '';
1825
+		$this->thank_you_page_url = '';
1826
+	}
1827
+
1828
+
1829
+	/**
1830
+	 * Used to return what the optin value is set for the EE User Experience Program.
1831
+	 * This accounts for multisite and this value being requested for a subsite.  In multisite, the value is set
1832
+	 * on the main site only.
1833
+	 *
1834
+	 * @return mixed|void
1835
+	 */
1836
+	protected function _get_main_ee_ueip_optin()
1837
+	{
1838
+		// if this is the main site then we can just bypass our direct query.
1839
+		if (is_main_site()) {
1840
+			return get_option('ee_ueip_optin', false);
1841
+		}
1842
+		// is this already cached for this request?  If so use it.
1843
+		if (! empty(EE_Core_Config::$ee_ueip_option)) {
1844
+			return EE_Core_Config::$ee_ueip_option;
1845
+		}
1846
+		global $wpdb;
1847
+		$current_network_main_site = is_multisite() ? get_current_site() : null;
1848
+		$current_main_site_id = ! empty($current_network_main_site) ? $current_network_main_site->blog_id : 1;
1849
+		$option = 'ee_ueip_optin';
1850
+		// set correct table for query
1851
+		$table_name = $wpdb->get_blog_prefix($current_main_site_id) . 'options';
1852
+		// rather than getting blog option for the $current_main_site_id, we do a direct $wpdb query because
1853
+		// get_blog_option() does a switch_to_blog an that could cause infinite recursion because EE_Core_Config might be
1854
+		// re-constructed on the blog switch.  Note, we are still executing any core wp filters on this option retrieval.
1855
+		// this bit of code is basically a direct copy of get_option without any caching because we are NOT switched to the blog
1856
+		// for the purpose of caching.
1857
+		$pre = apply_filters('pre_option_' . $option, false, $option);
1858
+		if (false !== $pre) {
1859
+			EE_Core_Config::$ee_ueip_option = $pre;
1860
+			return EE_Core_Config::$ee_ueip_option;
1861
+		}
1862
+		$row = $wpdb->get_row(
1863
+			$wpdb->prepare(
1864
+				"SELECT option_value FROM $table_name WHERE option_name = %s LIMIT 1",
1865
+				$option
1866
+			)
1867
+		);
1868
+		if (is_object($row)) {
1869
+			$value = $row->option_value;
1870
+		} else { // option does not exist so use default.
1871
+			return apply_filters('default_option_' . $option, false, $option);
1872
+		}
1873
+		EE_Core_Config::$ee_ueip_option = apply_filters('option_' . $option, maybe_unserialize($value), $option);
1874
+		return EE_Core_Config::$ee_ueip_option;
1875
+	}
1876
+
1877
+	/**
1878
+	 * Utility function for escaping the value of a property and returning.
1879
+	 *
1880
+	 * @param string $property property name (checks to see if exists).
1881
+	 * @return mixed if a detected type found return the escaped value, otherwise just the raw value is returned.
1882
+	 * @throws \EE_Error
1883
+	 */
1884
+	public function get_pretty($property)
1885
+	{
1886
+		if ($property === 'ee_ueip_optin') {
1887
+			return $this->ee_ueip_optin ? 'yes' : 'no';
1888
+		}
1889
+		return parent::get_pretty($property);
1890
+	}
1891
+
1892
+
1893
+	/**
1894
+	 * Currently used to ensure critical page urls have initial values saved to the db instead of any current set values
1895
+	 * on the object.
1896
+	 *
1897
+	 * @return array
1898
+	 */
1899
+	public function __sleep()
1900
+	{
1901
+		// reset all url properties
1902
+		$this->_reset_urls();
1903
+		// return what to save to db
1904
+		return array_keys(get_object_vars($this));
1905
+	}
1906
+}
2347 1907
 
2348
-    /**
2349
-     *    class constructor
2350
-     *
2351
-     * @access    public
2352
-     */
2353
-    public function __construct()
2354
-    {
2355
-        // set default registration settings
2356
-        $this->default_STS_ID = EEM_Registration::status_id_pending_payment;
2357
-        $this->email_validation_level = 'wp_default';
2358
-        $this->show_pending_payment_options = true;
2359
-        $this->skip_reg_confirmation = true;
2360
-        $this->reg_steps = array();
2361
-        $this->reg_confirmation_last = false;
2362
-        $this->use_bot_trap = true;
2363
-        $this->use_encryption = true;
2364
-        $this->use_captcha = false;
2365
-        $this->recaptcha_theme = 'light';
2366
-        $this->recaptcha_badge = 'bottomleft';
2367
-        $this->recaptcha_type = 'image';
2368
-        $this->recaptcha_language = 'en';
2369
-        $this->recaptcha_publickey = null;
2370
-        $this->recaptcha_privatekey = null;
2371
-        $this->recaptcha_protected_forms = array();
2372
-        $this->recaptcha_width = 500;
2373
-        $this->default_maximum_number_of_tickets = 10;
2374
-        $this->gateway_log_lifespan = '7 days';
2375
-    }
2376
-
2377
-
2378
-    /**
2379
-     * This is called by the config loader and hooks are initialized AFTER the config has been populated.
2380
-     *
2381
-     * @since 4.8.8.rc.019
2382
-     */
2383
-    public function do_hooks()
2384
-    {
2385
-        add_action('AHEE__EE_Config___load_core_config__end', array($this, 'set_default_reg_status_on_EEM_Event'));
2386
-        add_action('AHEE__EE_Config___load_core_config__end', array($this, 'set_default_max_ticket_on_EEM_Event'));
2387
-    }
2388 1908
 
1909
+/**
1910
+ * Config class for storing info on the Organization
1911
+ */
1912
+class EE_Organization_Config extends EE_Config_Base
1913
+{
2389 1914
 
2390
-    /**
2391
-     * Hooked into `AHEE__EE_Config___load_core_config__end` to ensure the default for the
2392
-     * EVT_default_registration_status field matches the config setting for default_STS_ID.
2393
-     */
2394
-    public function set_default_reg_status_on_EEM_Event()
2395
-    {
2396
-        EEM_Event::set_default_reg_status($this->default_STS_ID);
2397
-    }
1915
+	/**
1916
+	 * @var string $name
1917
+	 * eg EE4.1
1918
+	 */
1919
+	public $name;
1920
+
1921
+	/**
1922
+	 * @var string $address_1
1923
+	 * eg 123 Onna Road
1924
+	 */
1925
+	public $address_1;
1926
+
1927
+	/**
1928
+	 * @var string $address_2
1929
+	 * eg PO Box 123
1930
+	 */
1931
+	public $address_2;
1932
+
1933
+	/**
1934
+	 * @var string $city
1935
+	 * eg Inna City
1936
+	 */
1937
+	public $city;
1938
+
1939
+	/**
1940
+	 * @var int $STA_ID
1941
+	 * eg 4
1942
+	 */
1943
+	public $STA_ID;
1944
+
1945
+	/**
1946
+	 * @var string $CNT_ISO
1947
+	 * eg US
1948
+	 */
1949
+	public $CNT_ISO;
1950
+
1951
+	/**
1952
+	 * @var string $zip
1953
+	 * eg 12345  or V1A 2B3
1954
+	 */
1955
+	public $zip;
1956
+
1957
+	/**
1958
+	 * @var string $email
1959
+	 * eg [email protected]
1960
+	 */
1961
+	public $email;
1962
+
1963
+
1964
+	/**
1965
+	 * @var string $phone
1966
+	 * eg. 111-111-1111
1967
+	 */
1968
+	public $phone;
1969
+
1970
+
1971
+	/**
1972
+	 * @var string $vat
1973
+	 * VAT/Tax Number
1974
+	 */
1975
+	public $vat;
1976
+
1977
+	/**
1978
+	 * @var string $logo_url
1979
+	 * eg http://www.somedomain.com/wp-content/uploads/kittehs.jpg
1980
+	 */
1981
+	public $logo_url;
1982
+
1983
+
1984
+	/**
1985
+	 * The below are all various properties for holding links to organization social network profiles
1986
+	 *
1987
+	 * @var string
1988
+	 */
1989
+	/**
1990
+	 * facebook (facebook.com/profile.name)
1991
+	 *
1992
+	 * @var string
1993
+	 */
1994
+	public $facebook;
1995
+
1996
+
1997
+	/**
1998
+	 * twitter (twitter.com/twitter_handle)
1999
+	 *
2000
+	 * @var string
2001
+	 */
2002
+	public $twitter;
2003
+
2004
+
2005
+	/**
2006
+	 * linkedin (linkedin.com/in/profile_name)
2007
+	 *
2008
+	 * @var string
2009
+	 */
2010
+	public $linkedin;
2011
+
2012
+
2013
+	/**
2014
+	 * pinterest (www.pinterest.com/profile_name)
2015
+	 *
2016
+	 * @var string
2017
+	 */
2018
+	public $pinterest;
2019
+
2020
+
2021
+	/**
2022
+	 * google+ (google.com/+profileName)
2023
+	 *
2024
+	 * @var string
2025
+	 */
2026
+	public $google;
2027
+
2028
+
2029
+	/**
2030
+	 * instagram (instagram.com/handle)
2031
+	 *
2032
+	 * @var string
2033
+	 */
2034
+	public $instagram;
2035
+
2036
+
2037
+	/**
2038
+	 *    class constructor
2039
+	 *
2040
+	 * @access    public
2041
+	 */
2042
+	public function __construct()
2043
+	{
2044
+		// set default organization settings
2045
+		// decode HTML entities from the WP blogname, because it's stored in the DB with HTML entities encoded
2046
+		$this->name = wp_specialchars_decode(get_bloginfo('name'), ENT_QUOTES);
2047
+		$this->address_1 = '123 Onna Road';
2048
+		$this->address_2 = 'PO Box 123';
2049
+		$this->city = 'Inna City';
2050
+		$this->STA_ID = 4;
2051
+		$this->CNT_ISO = 'US';
2052
+		$this->zip = '12345';
2053
+		$this->email = get_bloginfo('admin_email');
2054
+		$this->phone = '';
2055
+		$this->vat = '123456789';
2056
+		$this->logo_url = '';
2057
+		$this->facebook = '';
2058
+		$this->twitter = '';
2059
+		$this->linkedin = '';
2060
+		$this->pinterest = '';
2061
+		$this->google = '';
2062
+		$this->instagram = '';
2063
+	}
2064
+}
2398 2065
 
2399 2066
 
2400
-    /**
2401
-     * Hooked into `AHEE__EE_Config___load_core_config__end` to ensure the default for the EVT_additional_limit field
2402
-     * for Events matches the config setting for default_maximum_number_of_tickets
2403
-     */
2404
-    public function set_default_max_ticket_on_EEM_Event()
2405
-    {
2406
-        EEM_Event::set_default_additional_limit($this->default_maximum_number_of_tickets);
2407
-    }
2067
+/**
2068
+ * Class for defining what's in the EE_Config relating to currency
2069
+ */
2070
+class EE_Currency_Config extends EE_Config_Base
2071
+{
2408 2072
 
2073
+	/**
2074
+	 * @var string $code
2075
+	 * eg 'US'
2076
+	 */
2077
+	public $code;
2078
+
2079
+	/**
2080
+	 * @var string $name
2081
+	 * eg 'Dollar'
2082
+	 */
2083
+	public $name;
2084
+
2085
+	/**
2086
+	 * plural name
2087
+	 *
2088
+	 * @var string $plural
2089
+	 * eg 'Dollars'
2090
+	 */
2091
+	public $plural;
2092
+
2093
+	/**
2094
+	 * currency sign
2095
+	 *
2096
+	 * @var string $sign
2097
+	 * eg '$'
2098
+	 */
2099
+	public $sign;
2100
+
2101
+	/**
2102
+	 * Whether the currency sign should come before the number or not
2103
+	 *
2104
+	 * @var boolean $sign_b4
2105
+	 */
2106
+	public $sign_b4;
2107
+
2108
+	/**
2109
+	 * How many digits should come after the decimal place
2110
+	 *
2111
+	 * @var int $dec_plc
2112
+	 */
2113
+	public $dec_plc;
2114
+
2115
+	/**
2116
+	 * Symbol to use for decimal mark
2117
+	 *
2118
+	 * @var string $dec_mrk
2119
+	 * eg '.'
2120
+	 */
2121
+	public $dec_mrk;
2122
+
2123
+	/**
2124
+	 * Symbol to use for thousands
2125
+	 *
2126
+	 * @var string $thsnds
2127
+	 * eg ','
2128
+	 */
2129
+	public $thsnds;
2130
+
2131
+
2132
+	/**
2133
+	 *    class constructor
2134
+	 *
2135
+	 * @access    public
2136
+	 * @param string $CNT_ISO
2137
+	 * @throws \EE_Error
2138
+	 */
2139
+	public function __construct($CNT_ISO = '')
2140
+	{
2141
+		/** @var \EventEspresso\core\services\database\TableAnalysis $table_analysis */
2142
+		$table_analysis = EE_Registry::instance()->create('TableAnalysis', array(), true);
2143
+		// get country code from organization settings or use default
2144
+		$ORG_CNT = isset(EE_Registry::instance()->CFG->organization)
2145
+				   && EE_Registry::instance()->CFG->organization instanceof EE_Organization_Config
2146
+			? EE_Registry::instance()->CFG->organization->CNT_ISO
2147
+			: '';
2148
+		// but override if requested
2149
+		$CNT_ISO = ! empty($CNT_ISO) ? $CNT_ISO : $ORG_CNT;
2150
+		// so if that all went well, and we are not in M-Mode (cuz you can't query the db in M-Mode) and double-check the countries table exists
2151
+		if (! empty($CNT_ISO)
2152
+			&& EE_Maintenance_Mode::instance()->models_can_query()
2153
+			&& $table_analysis->tableExists(EE_Registry::instance()->load_model('Country')->table())
2154
+		) {
2155
+			// retrieve the country settings from the db, just in case they have been customized
2156
+			$country = EE_Registry::instance()->load_model('Country')->get_one_by_ID($CNT_ISO);
2157
+			if ($country instanceof EE_Country) {
2158
+				$this->code = $country->currency_code();    // currency code: USD, CAD, EUR
2159
+				$this->name = $country->currency_name_single();    // Dollar
2160
+				$this->plural = $country->currency_name_plural();    // Dollars
2161
+				$this->sign = $country->currency_sign();            // currency sign: $
2162
+				$this->sign_b4 = $country->currency_sign_before(
2163
+				);        // currency sign before or after: $TRUE  or  FALSE$
2164
+				$this->dec_plc = $country->currency_decimal_places();    // decimal places: 2 = 0.00  3 = 0.000
2165
+				$this->dec_mrk = $country->currency_decimal_mark(
2166
+				);    // decimal mark: (comma) ',' = 0,01   or (decimal) '.' = 0.01
2167
+				$this->thsnds = $country->currency_thousands_separator(
2168
+				);    // thousands separator: (comma) ',' = 1,000   or (decimal) '.' = 1.000
2169
+			}
2170
+		}
2171
+		// fallback to hardcoded defaults, in case the above failed
2172
+		if (empty($this->code)) {
2173
+			// set default currency settings
2174
+			$this->code = 'USD';    // currency code: USD, CAD, EUR
2175
+			$this->name = __('Dollar', 'event_espresso');    // Dollar
2176
+			$this->plural = __('Dollars', 'event_espresso');    // Dollars
2177
+			$this->sign = '$';    // currency sign: $
2178
+			$this->sign_b4 = true;    // currency sign before or after: $TRUE  or  FALSE$
2179
+			$this->dec_plc = 2;    // decimal places: 2 = 0.00  3 = 0.000
2180
+			$this->dec_mrk = '.';    // decimal mark: (comma) ',' = 0,01   or (decimal) '.' = 0.01
2181
+			$this->thsnds = ',';    // thousands separator: (comma) ',' = 1,000   or (decimal) '.' = 1.000
2182
+		}
2183
+	}
2184
+}
2409 2185
 
2410
-    /**
2411
-     * @return boolean
2412
-     */
2413
-    public function track_invalid_checkout_access()
2414
-    {
2415
-        return $this->track_invalid_checkout_access;
2416
-    }
2417 2186
 
2187
+/**
2188
+ * Class for defining what's in the EE_Config relating to registration settings
2189
+ */
2190
+class EE_Registration_Config extends EE_Config_Base
2191
+{
2418 2192
 
2419
-    /**
2420
-     * @param boolean $track_invalid_checkout_access
2421
-     */
2422
-    public function set_track_invalid_checkout_access($track_invalid_checkout_access)
2423
-    {
2424
-        $this->track_invalid_checkout_access = filter_var(
2425
-            $track_invalid_checkout_access,
2426
-            FILTER_VALIDATE_BOOLEAN
2427
-        );
2428
-    }
2429
-
2430
-
2431
-    /**
2432
-     * Gets the options to make availalbe for the gateway log lifespan
2433
-     * @return array
2434
-     */
2435
-    public function gatewayLogLifespanOptions()
2436
-    {
2437
-        return (array) apply_filters(
2438
-            'FHEE_EE_Admin_Config__gatewayLogLifespanOptions',
2439
-            array(
2440
-                '1 second' => esc_html__('Don\'t Log At All', 'event_espresso'),
2441
-                '1 day' => esc_html__('1 Day', 'event_espresso'),
2442
-                '7 days' => esc_html__('7 Days', 'event_espresso'),
2443
-                '14 days' => esc_html__('14 Days', 'event_espresso'),
2444
-                '30 days' => esc_html__('30 Days', 'event_espresso')
2445
-            )
2446
-        );
2447
-    }
2193
+	/**
2194
+	 * Default registration status
2195
+	 *
2196
+	 * @var string $default_STS_ID
2197
+	 * eg 'RPP'
2198
+	 */
2199
+	public $default_STS_ID;
2200
+
2201
+
2202
+	/**
2203
+	 * For new events, this will be the default value for the maximum number of tickets (equivalent to maximum number of
2204
+	 * registrations)
2205
+	 *
2206
+	 * @var int
2207
+	 */
2208
+	public $default_maximum_number_of_tickets;
2209
+
2210
+
2211
+	/**
2212
+	 * level of validation to apply to email addresses
2213
+	 *
2214
+	 * @var string $email_validation_level
2215
+	 * options: 'basic', 'wp_default', 'i18n', 'i18n_dns'
2216
+	 */
2217
+	public $email_validation_level;
2218
+
2219
+	/**
2220
+	 *    whether or not to show alternate payment options during the reg process if payment status is pending
2221
+	 *
2222
+	 * @var boolean $show_pending_payment_options
2223
+	 */
2224
+	public $show_pending_payment_options;
2225
+
2226
+	/**
2227
+	 * Whether to skip the registration confirmation page
2228
+	 *
2229
+	 * @var boolean $skip_reg_confirmation
2230
+	 */
2231
+	public $skip_reg_confirmation;
2232
+
2233
+	/**
2234
+	 * an array of SPCO reg steps where:
2235
+	 *        the keys denotes the reg step order
2236
+	 *        each element consists of an array with the following elements:
2237
+	 *            "file_path" => the file path to the EE_SPCO_Reg_Step class
2238
+	 *            "class_name" => the specific EE_SPCO_Reg_Step child class name
2239
+	 *            "slug" => the URL param used to trigger the reg step
2240
+	 *
2241
+	 * @var array $reg_steps
2242
+	 */
2243
+	public $reg_steps;
2244
+
2245
+	/**
2246
+	 * Whether registration confirmation should be the last page of SPCO
2247
+	 *
2248
+	 * @var boolean $reg_confirmation_last
2249
+	 */
2250
+	public $reg_confirmation_last;
2251
+
2252
+	/**
2253
+	 * Whether or not to enable the EE Bot Trap
2254
+	 *
2255
+	 * @var boolean $use_bot_trap
2256
+	 */
2257
+	public $use_bot_trap;
2258
+
2259
+	/**
2260
+	 * Whether or not to encrypt some data sent by the EE Bot Trap
2261
+	 *
2262
+	 * @var boolean $use_encryption
2263
+	 */
2264
+	public $use_encryption;
2265
+
2266
+	/**
2267
+	 * Whether or not to use ReCaptcha
2268
+	 *
2269
+	 * @var boolean $use_captcha
2270
+	 */
2271
+	public $use_captcha;
2272
+
2273
+	/**
2274
+	 * ReCaptcha Theme
2275
+	 *
2276
+	 * @var string $recaptcha_theme
2277
+	 *    options: 'dark', 'light', 'invisible'
2278
+	 */
2279
+	public $recaptcha_theme;
2280
+
2281
+	/**
2282
+	 * ReCaptcha Badge - determines the position of the reCAPTCHA badge if using Invisible ReCaptcha.
2283
+	 *
2284
+	 * @var string $recaptcha_badge
2285
+	 *    options: 'bottomright', 'bottomleft', 'inline'
2286
+	 */
2287
+	public $recaptcha_badge;
2288
+
2289
+	/**
2290
+	 * ReCaptcha Type
2291
+	 *
2292
+	 * @var string $recaptcha_type
2293
+	 *    options: 'audio', 'image'
2294
+	 */
2295
+	public $recaptcha_type;
2296
+
2297
+	/**
2298
+	 * ReCaptcha language
2299
+	 *
2300
+	 * @var string $recaptcha_language
2301
+	 * eg 'en'
2302
+	 */
2303
+	public $recaptcha_language;
2304
+
2305
+	/**
2306
+	 * ReCaptcha public key
2307
+	 *
2308
+	 * @var string $recaptcha_publickey
2309
+	 */
2310
+	public $recaptcha_publickey;
2311
+
2312
+	/**
2313
+	 * ReCaptcha private key
2314
+	 *
2315
+	 * @var string $recaptcha_privatekey
2316
+	 */
2317
+	public $recaptcha_privatekey;
2318
+
2319
+	/**
2320
+	 * array of form names protected by ReCaptcha
2321
+	 *
2322
+	 * @var array $recaptcha_protected_forms
2323
+	 */
2324
+	public $recaptcha_protected_forms;
2325
+
2326
+	/**
2327
+	 * ReCaptcha width
2328
+	 *
2329
+	 * @var int $recaptcha_width
2330
+	 * @deprecated
2331
+	 */
2332
+	public $recaptcha_width;
2333
+
2334
+	/**
2335
+	 * Whether or not invalid attempts to directly access the registration checkout page should be tracked.
2336
+	 *
2337
+	 * @var boolean $track_invalid_checkout_access
2338
+	 */
2339
+	protected $track_invalid_checkout_access = true;
2340
+
2341
+	/**
2342
+	 * String describing how long to keep payment logs. Passed into DateTime constructor
2343
+	 * @var string
2344
+	 */
2345
+	public $gateway_log_lifespan = '1 week';
2346
+
2347
+
2348
+	/**
2349
+	 *    class constructor
2350
+	 *
2351
+	 * @access    public
2352
+	 */
2353
+	public function __construct()
2354
+	{
2355
+		// set default registration settings
2356
+		$this->default_STS_ID = EEM_Registration::status_id_pending_payment;
2357
+		$this->email_validation_level = 'wp_default';
2358
+		$this->show_pending_payment_options = true;
2359
+		$this->skip_reg_confirmation = true;
2360
+		$this->reg_steps = array();
2361
+		$this->reg_confirmation_last = false;
2362
+		$this->use_bot_trap = true;
2363
+		$this->use_encryption = true;
2364
+		$this->use_captcha = false;
2365
+		$this->recaptcha_theme = 'light';
2366
+		$this->recaptcha_badge = 'bottomleft';
2367
+		$this->recaptcha_type = 'image';
2368
+		$this->recaptcha_language = 'en';
2369
+		$this->recaptcha_publickey = null;
2370
+		$this->recaptcha_privatekey = null;
2371
+		$this->recaptcha_protected_forms = array();
2372
+		$this->recaptcha_width = 500;
2373
+		$this->default_maximum_number_of_tickets = 10;
2374
+		$this->gateway_log_lifespan = '7 days';
2375
+	}
2376
+
2377
+
2378
+	/**
2379
+	 * This is called by the config loader and hooks are initialized AFTER the config has been populated.
2380
+	 *
2381
+	 * @since 4.8.8.rc.019
2382
+	 */
2383
+	public function do_hooks()
2384
+	{
2385
+		add_action('AHEE__EE_Config___load_core_config__end', array($this, 'set_default_reg_status_on_EEM_Event'));
2386
+		add_action('AHEE__EE_Config___load_core_config__end', array($this, 'set_default_max_ticket_on_EEM_Event'));
2387
+	}
2388
+
2389
+
2390
+	/**
2391
+	 * Hooked into `AHEE__EE_Config___load_core_config__end` to ensure the default for the
2392
+	 * EVT_default_registration_status field matches the config setting for default_STS_ID.
2393
+	 */
2394
+	public function set_default_reg_status_on_EEM_Event()
2395
+	{
2396
+		EEM_Event::set_default_reg_status($this->default_STS_ID);
2397
+	}
2398
+
2399
+
2400
+	/**
2401
+	 * Hooked into `AHEE__EE_Config___load_core_config__end` to ensure the default for the EVT_additional_limit field
2402
+	 * for Events matches the config setting for default_maximum_number_of_tickets
2403
+	 */
2404
+	public function set_default_max_ticket_on_EEM_Event()
2405
+	{
2406
+		EEM_Event::set_default_additional_limit($this->default_maximum_number_of_tickets);
2407
+	}
2408
+
2409
+
2410
+	/**
2411
+	 * @return boolean
2412
+	 */
2413
+	public function track_invalid_checkout_access()
2414
+	{
2415
+		return $this->track_invalid_checkout_access;
2416
+	}
2417
+
2418
+
2419
+	/**
2420
+	 * @param boolean $track_invalid_checkout_access
2421
+	 */
2422
+	public function set_track_invalid_checkout_access($track_invalid_checkout_access)
2423
+	{
2424
+		$this->track_invalid_checkout_access = filter_var(
2425
+			$track_invalid_checkout_access,
2426
+			FILTER_VALIDATE_BOOLEAN
2427
+		);
2428
+	}
2429
+
2430
+
2431
+	/**
2432
+	 * Gets the options to make availalbe for the gateway log lifespan
2433
+	 * @return array
2434
+	 */
2435
+	public function gatewayLogLifespanOptions()
2436
+	{
2437
+		return (array) apply_filters(
2438
+			'FHEE_EE_Admin_Config__gatewayLogLifespanOptions',
2439
+			array(
2440
+				'1 second' => esc_html__('Don\'t Log At All', 'event_espresso'),
2441
+				'1 day' => esc_html__('1 Day', 'event_espresso'),
2442
+				'7 days' => esc_html__('7 Days', 'event_espresso'),
2443
+				'14 days' => esc_html__('14 Days', 'event_espresso'),
2444
+				'30 days' => esc_html__('30 Days', 'event_espresso')
2445
+			)
2446
+		);
2447
+	}
2448 2448
 }
2449 2449
 
2450 2450
 
@@ -2454,154 +2454,154 @@  discard block
 block discarded – undo
2454 2454
 class EE_Admin_Config extends EE_Config_Base
2455 2455
 {
2456 2456
 
2457
-    /**
2458
-     * @var boolean $use_personnel_manager
2459
-     */
2460
-    public $use_personnel_manager;
2461
-
2462
-    /**
2463
-     * @var boolean $use_dashboard_widget
2464
-     */
2465
-    public $use_dashboard_widget;
2466
-
2467
-    /**
2468
-     * @var int $events_in_dashboard
2469
-     */
2470
-    public $events_in_dashboard;
2471
-
2472
-    /**
2473
-     * @var boolean $use_event_timezones
2474
-     */
2475
-    public $use_event_timezones;
2476
-
2477
-    /**
2478
-     * @var boolean $use_full_logging
2479
-     */
2480
-    public $use_full_logging;
2481
-
2482
-    /**
2483
-     * @var string $log_file_name
2484
-     */
2485
-    public $log_file_name;
2486
-
2487
-    /**
2488
-     * @var string $debug_file_name
2489
-     */
2490
-    public $debug_file_name;
2491
-
2492
-    /**
2493
-     * @var boolean $use_remote_logging
2494
-     */
2495
-    public $use_remote_logging;
2496
-
2497
-    /**
2498
-     * @var string $remote_logging_url
2499
-     */
2500
-    public $remote_logging_url;
2501
-
2502
-    /**
2503
-     * @var boolean $show_reg_footer
2504
-     */
2505
-    public $show_reg_footer;
2506
-
2507
-    /**
2508
-     * @var string $affiliate_id
2509
-     */
2510
-    public $affiliate_id;
2511
-
2512
-    /**
2513
-     * help tours on or off (global setting)
2514
-     *
2515
-     * @var boolean
2516
-     */
2517
-    public $help_tour_activation;
2518
-
2519
-    /**
2520
-     * adds extra layer of encoding to session data to prevent serialization errors
2521
-     * but is incompatible with some server configuration errors
2522
-     * if you get "500 internal server errors" during registration, try turning this on
2523
-     * if you get PHP fatal errors regarding base 64 methods not defined, then turn this off
2524
-     *
2525
-     * @var boolean $encode_session_data
2526
-     */
2527
-    private $encode_session_data = false;
2528
-
2529
-
2530
-    /**
2531
-     *    class constructor
2532
-     *
2533
-     * @access    public
2534
-     */
2535
-    public function __construct()
2536
-    {
2537
-        // set default general admin settings
2538
-        $this->use_personnel_manager = true;
2539
-        $this->use_dashboard_widget = true;
2540
-        $this->events_in_dashboard = 30;
2541
-        $this->use_event_timezones = false;
2542
-        $this->use_full_logging = false;
2543
-        $this->use_remote_logging = false;
2544
-        $this->remote_logging_url = null;
2545
-        $this->show_reg_footer = true;
2546
-        $this->affiliate_id = 'default';
2547
-        $this->help_tour_activation = true;
2548
-        $this->encode_session_data = false;
2549
-    }
2550
-
2551
-
2552
-    /**
2553
-     * @param bool $reset
2554
-     * @return string
2555
-     */
2556
-    public function log_file_name($reset = false)
2557
-    {
2558
-        if (empty($this->log_file_name) || $reset) {
2559
-            $this->log_file_name = sanitize_key('espresso_log_' . md5(uniqid('', true))) . '.txt';
2560
-            EE_Config::instance()->update_espresso_config(false, false);
2561
-        }
2562
-        return $this->log_file_name;
2563
-    }
2564
-
2565
-
2566
-    /**
2567
-     * @param bool $reset
2568
-     * @return string
2569
-     */
2570
-    public function debug_file_name($reset = false)
2571
-    {
2572
-        if (empty($this->debug_file_name) || $reset) {
2573
-            $this->debug_file_name = sanitize_key('espresso_debug_' . md5(uniqid('', true))) . '.txt';
2574
-            EE_Config::instance()->update_espresso_config(false, false);
2575
-        }
2576
-        return $this->debug_file_name;
2577
-    }
2578
-
2579
-
2580
-    /**
2581
-     * @return string
2582
-     */
2583
-    public function affiliate_id()
2584
-    {
2585
-        return ! empty($this->affiliate_id) ? $this->affiliate_id : 'default';
2586
-    }
2587
-
2588
-
2589
-    /**
2590
-     * @return boolean
2591
-     */
2592
-    public function encode_session_data()
2593
-    {
2594
-        return filter_var($this->encode_session_data, FILTER_VALIDATE_BOOLEAN);
2595
-    }
2596
-
2597
-
2598
-    /**
2599
-     * @param boolean $encode_session_data
2600
-     */
2601
-    public function set_encode_session_data($encode_session_data)
2602
-    {
2603
-        $this->encode_session_data = filter_var($encode_session_data, FILTER_VALIDATE_BOOLEAN);
2604
-    }
2457
+	/**
2458
+	 * @var boolean $use_personnel_manager
2459
+	 */
2460
+	public $use_personnel_manager;
2461
+
2462
+	/**
2463
+	 * @var boolean $use_dashboard_widget
2464
+	 */
2465
+	public $use_dashboard_widget;
2466
+
2467
+	/**
2468
+	 * @var int $events_in_dashboard
2469
+	 */
2470
+	public $events_in_dashboard;
2471
+
2472
+	/**
2473
+	 * @var boolean $use_event_timezones
2474
+	 */
2475
+	public $use_event_timezones;
2476
+
2477
+	/**
2478
+	 * @var boolean $use_full_logging
2479
+	 */
2480
+	public $use_full_logging;
2481
+
2482
+	/**
2483
+	 * @var string $log_file_name
2484
+	 */
2485
+	public $log_file_name;
2486
+
2487
+	/**
2488
+	 * @var string $debug_file_name
2489
+	 */
2490
+	public $debug_file_name;
2491
+
2492
+	/**
2493
+	 * @var boolean $use_remote_logging
2494
+	 */
2495
+	public $use_remote_logging;
2496
+
2497
+	/**
2498
+	 * @var string $remote_logging_url
2499
+	 */
2500
+	public $remote_logging_url;
2501
+
2502
+	/**
2503
+	 * @var boolean $show_reg_footer
2504
+	 */
2505
+	public $show_reg_footer;
2506
+
2507
+	/**
2508
+	 * @var string $affiliate_id
2509
+	 */
2510
+	public $affiliate_id;
2511
+
2512
+	/**
2513
+	 * help tours on or off (global setting)
2514
+	 *
2515
+	 * @var boolean
2516
+	 */
2517
+	public $help_tour_activation;
2518
+
2519
+	/**
2520
+	 * adds extra layer of encoding to session data to prevent serialization errors
2521
+	 * but is incompatible with some server configuration errors
2522
+	 * if you get "500 internal server errors" during registration, try turning this on
2523
+	 * if you get PHP fatal errors regarding base 64 methods not defined, then turn this off
2524
+	 *
2525
+	 * @var boolean $encode_session_data
2526
+	 */
2527
+	private $encode_session_data = false;
2528
+
2529
+
2530
+	/**
2531
+	 *    class constructor
2532
+	 *
2533
+	 * @access    public
2534
+	 */
2535
+	public function __construct()
2536
+	{
2537
+		// set default general admin settings
2538
+		$this->use_personnel_manager = true;
2539
+		$this->use_dashboard_widget = true;
2540
+		$this->events_in_dashboard = 30;
2541
+		$this->use_event_timezones = false;
2542
+		$this->use_full_logging = false;
2543
+		$this->use_remote_logging = false;
2544
+		$this->remote_logging_url = null;
2545
+		$this->show_reg_footer = true;
2546
+		$this->affiliate_id = 'default';
2547
+		$this->help_tour_activation = true;
2548
+		$this->encode_session_data = false;
2549
+	}
2550
+
2551
+
2552
+	/**
2553
+	 * @param bool $reset
2554
+	 * @return string
2555
+	 */
2556
+	public function log_file_name($reset = false)
2557
+	{
2558
+		if (empty($this->log_file_name) || $reset) {
2559
+			$this->log_file_name = sanitize_key('espresso_log_' . md5(uniqid('', true))) . '.txt';
2560
+			EE_Config::instance()->update_espresso_config(false, false);
2561
+		}
2562
+		return $this->log_file_name;
2563
+	}
2564
+
2565
+
2566
+	/**
2567
+	 * @param bool $reset
2568
+	 * @return string
2569
+	 */
2570
+	public function debug_file_name($reset = false)
2571
+	{
2572
+		if (empty($this->debug_file_name) || $reset) {
2573
+			$this->debug_file_name = sanitize_key('espresso_debug_' . md5(uniqid('', true))) . '.txt';
2574
+			EE_Config::instance()->update_espresso_config(false, false);
2575
+		}
2576
+		return $this->debug_file_name;
2577
+	}
2578
+
2579
+
2580
+	/**
2581
+	 * @return string
2582
+	 */
2583
+	public function affiliate_id()
2584
+	{
2585
+		return ! empty($this->affiliate_id) ? $this->affiliate_id : 'default';
2586
+	}
2587
+
2588
+
2589
+	/**
2590
+	 * @return boolean
2591
+	 */
2592
+	public function encode_session_data()
2593
+	{
2594
+		return filter_var($this->encode_session_data, FILTER_VALIDATE_BOOLEAN);
2595
+	}
2596
+
2597
+
2598
+	/**
2599
+	 * @param boolean $encode_session_data
2600
+	 */
2601
+	public function set_encode_session_data($encode_session_data)
2602
+	{
2603
+		$this->encode_session_data = filter_var($encode_session_data, FILTER_VALIDATE_BOOLEAN);
2604
+	}
2605 2605
 }
2606 2606
 
2607 2607
 
@@ -2611,70 +2611,70 @@  discard block
 block discarded – undo
2611 2611
 class EE_Template_Config extends EE_Config_Base
2612 2612
 {
2613 2613
 
2614
-    /**
2615
-     * @var boolean $enable_default_style
2616
-     */
2617
-    public $enable_default_style;
2618
-
2619
-    /**
2620
-     * @var string $custom_style_sheet
2621
-     */
2622
-    public $custom_style_sheet;
2623
-
2624
-    /**
2625
-     * @var boolean $display_address_in_regform
2626
-     */
2627
-    public $display_address_in_regform;
2628
-
2629
-    /**
2630
-     * @var int $display_description_on_multi_reg_page
2631
-     */
2632
-    public $display_description_on_multi_reg_page;
2633
-
2634
-    /**
2635
-     * @var boolean $use_custom_templates
2636
-     */
2637
-    public $use_custom_templates;
2638
-
2639
-    /**
2640
-     * @var string $current_espresso_theme
2641
-     */
2642
-    public $current_espresso_theme;
2643
-
2644
-    /**
2645
-     * @var EE_Ticket_Selector_Config $EED_Ticket_Selector
2646
-     */
2647
-    public $EED_Ticket_Selector;
2648
-
2649
-    /**
2650
-     * @var EE_Event_Single_Config $EED_Event_Single
2651
-     */
2652
-    public $EED_Event_Single;
2653
-
2654
-    /**
2655
-     * @var EE_Events_Archive_Config $EED_Events_Archive
2656
-     */
2657
-    public $EED_Events_Archive;
2658
-
2659
-
2660
-    /**
2661
-     *    class constructor
2662
-     *
2663
-     * @access    public
2664
-     */
2665
-    public function __construct()
2666
-    {
2667
-        // set default template settings
2668
-        $this->enable_default_style = true;
2669
-        $this->custom_style_sheet = null;
2670
-        $this->display_address_in_regform = true;
2671
-        $this->display_description_on_multi_reg_page = false;
2672
-        $this->use_custom_templates = false;
2673
-        $this->current_espresso_theme = 'Espresso_Arabica_2014';
2674
-        $this->EED_Event_Single = null;
2675
-        $this->EED_Events_Archive = null;
2676
-        $this->EED_Ticket_Selector = null;
2677
-    }
2614
+	/**
2615
+	 * @var boolean $enable_default_style
2616
+	 */
2617
+	public $enable_default_style;
2618
+
2619
+	/**
2620
+	 * @var string $custom_style_sheet
2621
+	 */
2622
+	public $custom_style_sheet;
2623
+
2624
+	/**
2625
+	 * @var boolean $display_address_in_regform
2626
+	 */
2627
+	public $display_address_in_regform;
2628
+
2629
+	/**
2630
+	 * @var int $display_description_on_multi_reg_page
2631
+	 */
2632
+	public $display_description_on_multi_reg_page;
2633
+
2634
+	/**
2635
+	 * @var boolean $use_custom_templates
2636
+	 */
2637
+	public $use_custom_templates;
2638
+
2639
+	/**
2640
+	 * @var string $current_espresso_theme
2641
+	 */
2642
+	public $current_espresso_theme;
2643
+
2644
+	/**
2645
+	 * @var EE_Ticket_Selector_Config $EED_Ticket_Selector
2646
+	 */
2647
+	public $EED_Ticket_Selector;
2648
+
2649
+	/**
2650
+	 * @var EE_Event_Single_Config $EED_Event_Single
2651
+	 */
2652
+	public $EED_Event_Single;
2653
+
2654
+	/**
2655
+	 * @var EE_Events_Archive_Config $EED_Events_Archive
2656
+	 */
2657
+	public $EED_Events_Archive;
2658
+
2659
+
2660
+	/**
2661
+	 *    class constructor
2662
+	 *
2663
+	 * @access    public
2664
+	 */
2665
+	public function __construct()
2666
+	{
2667
+		// set default template settings
2668
+		$this->enable_default_style = true;
2669
+		$this->custom_style_sheet = null;
2670
+		$this->display_address_in_regform = true;
2671
+		$this->display_description_on_multi_reg_page = false;
2672
+		$this->use_custom_templates = false;
2673
+		$this->current_espresso_theme = 'Espresso_Arabica_2014';
2674
+		$this->EED_Event_Single = null;
2675
+		$this->EED_Events_Archive = null;
2676
+		$this->EED_Ticket_Selector = null;
2677
+	}
2678 2678
 }
2679 2679
 
2680 2680
 
@@ -2684,114 +2684,114 @@  discard block
 block discarded – undo
2684 2684
 class EE_Map_Config extends EE_Config_Base
2685 2685
 {
2686 2686
 
2687
-    /**
2688
-     * @var boolean $use_google_maps
2689
-     */
2690
-    public $use_google_maps;
2691
-
2692
-    /**
2693
-     * @var string $api_key
2694
-     */
2695
-    public $google_map_api_key;
2696
-
2697
-    /**
2698
-     * @var int $event_details_map_width
2699
-     */
2700
-    public $event_details_map_width;
2701
-
2702
-    /**
2703
-     * @var int $event_details_map_height
2704
-     */
2705
-    public $event_details_map_height;
2706
-
2707
-    /**
2708
-     * @var int $event_details_map_zoom
2709
-     */
2710
-    public $event_details_map_zoom;
2711
-
2712
-    /**
2713
-     * @var boolean $event_details_display_nav
2714
-     */
2715
-    public $event_details_display_nav;
2716
-
2717
-    /**
2718
-     * @var boolean $event_details_nav_size
2719
-     */
2720
-    public $event_details_nav_size;
2721
-
2722
-    /**
2723
-     * @var string $event_details_control_type
2724
-     */
2725
-    public $event_details_control_type;
2726
-
2727
-    /**
2728
-     * @var string $event_details_map_align
2729
-     */
2730
-    public $event_details_map_align;
2731
-
2732
-    /**
2733
-     * @var int $event_list_map_width
2734
-     */
2735
-    public $event_list_map_width;
2736
-
2737
-    /**
2738
-     * @var int $event_list_map_height
2739
-     */
2740
-    public $event_list_map_height;
2741
-
2742
-    /**
2743
-     * @var int $event_list_map_zoom
2744
-     */
2745
-    public $event_list_map_zoom;
2746
-
2747
-    /**
2748
-     * @var boolean $event_list_display_nav
2749
-     */
2750
-    public $event_list_display_nav;
2751
-
2752
-    /**
2753
-     * @var boolean $event_list_nav_size
2754
-     */
2755
-    public $event_list_nav_size;
2756
-
2757
-    /**
2758
-     * @var string $event_list_control_type
2759
-     */
2760
-    public $event_list_control_type;
2761
-
2762
-    /**
2763
-     * @var string $event_list_map_align
2764
-     */
2765
-    public $event_list_map_align;
2766
-
2767
-
2768
-    /**
2769
-     *    class constructor
2770
-     *
2771
-     * @access    public
2772
-     */
2773
-    public function __construct()
2774
-    {
2775
-        // set default map settings
2776
-        $this->use_google_maps = true;
2777
-        $this->google_map_api_key = '';
2778
-        // for event details pages (reg page)
2779
-        $this->event_details_map_width = 585;            // ee_map_width_single
2780
-        $this->event_details_map_height = 362;            // ee_map_height_single
2781
-        $this->event_details_map_zoom = 14;            // ee_map_zoom_single
2782
-        $this->event_details_display_nav = true;            // ee_map_nav_display_single
2783
-        $this->event_details_nav_size = false;            // ee_map_nav_size_single
2784
-        $this->event_details_control_type = 'default';        // ee_map_type_control_single
2785
-        $this->event_details_map_align = 'center';            // ee_map_align_single
2786
-        // for event list pages
2787
-        $this->event_list_map_width = 300;            // ee_map_width
2788
-        $this->event_list_map_height = 185;        // ee_map_height
2789
-        $this->event_list_map_zoom = 12;            // ee_map_zoom
2790
-        $this->event_list_display_nav = false;        // ee_map_nav_display
2791
-        $this->event_list_nav_size = true;            // ee_map_nav_size
2792
-        $this->event_list_control_type = 'dropdown';        // ee_map_type_control
2793
-        $this->event_list_map_align = 'center';            // ee_map_align
2794
-    }
2687
+	/**
2688
+	 * @var boolean $use_google_maps
2689
+	 */
2690
+	public $use_google_maps;
2691
+
2692
+	/**
2693
+	 * @var string $api_key
2694
+	 */
2695
+	public $google_map_api_key;
2696
+
2697
+	/**
2698
+	 * @var int $event_details_map_width
2699
+	 */
2700
+	public $event_details_map_width;
2701
+
2702
+	/**
2703
+	 * @var int $event_details_map_height
2704
+	 */
2705
+	public $event_details_map_height;
2706
+
2707
+	/**
2708
+	 * @var int $event_details_map_zoom
2709
+	 */
2710
+	public $event_details_map_zoom;
2711
+
2712
+	/**
2713
+	 * @var boolean $event_details_display_nav
2714
+	 */
2715
+	public $event_details_display_nav;
2716
+
2717
+	/**
2718
+	 * @var boolean $event_details_nav_size
2719
+	 */
2720
+	public $event_details_nav_size;
2721
+
2722
+	/**
2723
+	 * @var string $event_details_control_type
2724
+	 */
2725
+	public $event_details_control_type;
2726
+
2727
+	/**
2728
+	 * @var string $event_details_map_align
2729
+	 */
2730
+	public $event_details_map_align;
2731
+
2732
+	/**
2733
+	 * @var int $event_list_map_width
2734
+	 */
2735
+	public $event_list_map_width;
2736
+
2737
+	/**
2738
+	 * @var int $event_list_map_height
2739
+	 */
2740
+	public $event_list_map_height;
2741
+
2742
+	/**
2743
+	 * @var int $event_list_map_zoom
2744
+	 */
2745
+	public $event_list_map_zoom;
2746
+
2747
+	/**
2748
+	 * @var boolean $event_list_display_nav
2749
+	 */
2750
+	public $event_list_display_nav;
2751
+
2752
+	/**
2753
+	 * @var boolean $event_list_nav_size
2754
+	 */
2755
+	public $event_list_nav_size;
2756
+
2757
+	/**
2758
+	 * @var string $event_list_control_type
2759
+	 */
2760
+	public $event_list_control_type;
2761
+
2762
+	/**
2763
+	 * @var string $event_list_map_align
2764
+	 */
2765
+	public $event_list_map_align;
2766
+
2767
+
2768
+	/**
2769
+	 *    class constructor
2770
+	 *
2771
+	 * @access    public
2772
+	 */
2773
+	public function __construct()
2774
+	{
2775
+		// set default map settings
2776
+		$this->use_google_maps = true;
2777
+		$this->google_map_api_key = '';
2778
+		// for event details pages (reg page)
2779
+		$this->event_details_map_width = 585;            // ee_map_width_single
2780
+		$this->event_details_map_height = 362;            // ee_map_height_single
2781
+		$this->event_details_map_zoom = 14;            // ee_map_zoom_single
2782
+		$this->event_details_display_nav = true;            // ee_map_nav_display_single
2783
+		$this->event_details_nav_size = false;            // ee_map_nav_size_single
2784
+		$this->event_details_control_type = 'default';        // ee_map_type_control_single
2785
+		$this->event_details_map_align = 'center';            // ee_map_align_single
2786
+		// for event list pages
2787
+		$this->event_list_map_width = 300;            // ee_map_width
2788
+		$this->event_list_map_height = 185;        // ee_map_height
2789
+		$this->event_list_map_zoom = 12;            // ee_map_zoom
2790
+		$this->event_list_display_nav = false;        // ee_map_nav_display
2791
+		$this->event_list_nav_size = true;            // ee_map_nav_size
2792
+		$this->event_list_control_type = 'dropdown';        // ee_map_type_control
2793
+		$this->event_list_map_align = 'center';            // ee_map_align
2794
+	}
2795 2795
 }
2796 2796
 
2797 2797
 
@@ -2801,46 +2801,46 @@  discard block
 block discarded – undo
2801 2801
 class EE_Events_Archive_Config extends EE_Config_Base
2802 2802
 {
2803 2803
 
2804
-    public $display_status_banner;
2804
+	public $display_status_banner;
2805 2805
 
2806
-    public $display_description;
2806
+	public $display_description;
2807 2807
 
2808
-    public $display_ticket_selector;
2808
+	public $display_ticket_selector;
2809 2809
 
2810
-    public $display_datetimes;
2810
+	public $display_datetimes;
2811 2811
 
2812
-    public $display_venue;
2812
+	public $display_venue;
2813 2813
 
2814
-    public $display_expired_events;
2814
+	public $display_expired_events;
2815 2815
 
2816
-    public $use_sortable_display_order;
2816
+	public $use_sortable_display_order;
2817 2817
 
2818
-    public $display_order_tickets;
2818
+	public $display_order_tickets;
2819 2819
 
2820
-    public $display_order_datetimes;
2820
+	public $display_order_datetimes;
2821 2821
 
2822
-    public $display_order_event;
2822
+	public $display_order_event;
2823 2823
 
2824
-    public $display_order_venue;
2824
+	public $display_order_venue;
2825 2825
 
2826 2826
 
2827
-    /**
2828
-     *    class constructor
2829
-     */
2830
-    public function __construct()
2831
-    {
2832
-        $this->display_status_banner = 0;
2833
-        $this->display_description = 1;
2834
-        $this->display_ticket_selector = 0;
2835
-        $this->display_datetimes = 1;
2836
-        $this->display_venue = 0;
2837
-        $this->display_expired_events = 0;
2838
-        $this->use_sortable_display_order = false;
2839
-        $this->display_order_tickets = 100;
2840
-        $this->display_order_datetimes = 110;
2841
-        $this->display_order_event = 120;
2842
-        $this->display_order_venue = 130;
2843
-    }
2827
+	/**
2828
+	 *    class constructor
2829
+	 */
2830
+	public function __construct()
2831
+	{
2832
+		$this->display_status_banner = 0;
2833
+		$this->display_description = 1;
2834
+		$this->display_ticket_selector = 0;
2835
+		$this->display_datetimes = 1;
2836
+		$this->display_venue = 0;
2837
+		$this->display_expired_events = 0;
2838
+		$this->use_sortable_display_order = false;
2839
+		$this->display_order_tickets = 100;
2840
+		$this->display_order_datetimes = 110;
2841
+		$this->display_order_event = 120;
2842
+		$this->display_order_venue = 130;
2843
+	}
2844 2844
 }
2845 2845
 
2846 2846
 
@@ -2850,34 +2850,34 @@  discard block
 block discarded – undo
2850 2850
 class EE_Event_Single_Config extends EE_Config_Base
2851 2851
 {
2852 2852
 
2853
-    public $display_status_banner_single;
2853
+	public $display_status_banner_single;
2854 2854
 
2855
-    public $display_venue;
2855
+	public $display_venue;
2856 2856
 
2857
-    public $use_sortable_display_order;
2857
+	public $use_sortable_display_order;
2858 2858
 
2859
-    public $display_order_tickets;
2859
+	public $display_order_tickets;
2860 2860
 
2861
-    public $display_order_datetimes;
2861
+	public $display_order_datetimes;
2862 2862
 
2863
-    public $display_order_event;
2863
+	public $display_order_event;
2864 2864
 
2865
-    public $display_order_venue;
2865
+	public $display_order_venue;
2866 2866
 
2867 2867
 
2868
-    /**
2869
-     *    class constructor
2870
-     */
2871
-    public function __construct()
2872
-    {
2873
-        $this->display_status_banner_single = 0;
2874
-        $this->display_venue = 1;
2875
-        $this->use_sortable_display_order = false;
2876
-        $this->display_order_tickets = 100;
2877
-        $this->display_order_datetimes = 110;
2878
-        $this->display_order_event = 120;
2879
-        $this->display_order_venue = 130;
2880
-    }
2868
+	/**
2869
+	 *    class constructor
2870
+	 */
2871
+	public function __construct()
2872
+	{
2873
+		$this->display_status_banner_single = 0;
2874
+		$this->display_venue = 1;
2875
+		$this->use_sortable_display_order = false;
2876
+		$this->display_order_tickets = 100;
2877
+		$this->display_order_datetimes = 110;
2878
+		$this->display_order_event = 120;
2879
+		$this->display_order_venue = 130;
2880
+	}
2881 2881
 }
2882 2882
 
2883 2883
 
@@ -2887,146 +2887,146 @@  discard block
 block discarded – undo
2887 2887
 class EE_Ticket_Selector_Config extends EE_Config_Base
2888 2888
 {
2889 2889
 
2890
-    /**
2891
-     * constant to indicate that a datetime selector should NEVER be shown for ticket selectors
2892
-     */
2893
-    const DO_NOT_SHOW_DATETIME_SELECTOR = 'no_datetime_selector';
2894
-
2895
-    /**
2896
-     * constant to indicate that a datetime selector should only be shown for ticket selectors
2897
-     * when the number of datetimes for the event matches the value set for $datetime_selector_threshold
2898
-     */
2899
-    const MAYBE_SHOW_DATETIME_SELECTOR = 'maybe_datetime_selector';
2900
-
2901
-    /**
2902
-     * @var boolean $show_ticket_sale_columns
2903
-     */
2904
-    public $show_ticket_sale_columns;
2905
-
2906
-    /**
2907
-     * @var boolean $show_ticket_details
2908
-     */
2909
-    public $show_ticket_details;
2910
-
2911
-    /**
2912
-     * @var boolean $show_expired_tickets
2913
-     */
2914
-    public $show_expired_tickets;
2915
-
2916
-    /**
2917
-     * whether or not to display a dropdown box populated with event datetimes
2918
-     * that toggles which tickets are displayed for a ticket selector.
2919
-     * uses one of the *_DATETIME_SELECTOR constants defined above
2920
-     *
2921
-     * @var string $show_datetime_selector
2922
-     */
2923
-    private $show_datetime_selector = 'no_datetime_selector';
2924
-
2925
-    /**
2926
-     * the number of datetimes an event has to have before conditionally displaying a datetime selector
2927
-     *
2928
-     * @var int $datetime_selector_threshold
2929
-     */
2930
-    private $datetime_selector_threshold = 3;
2931
-
2932
-
2933
-    /**
2934
-     *    class constructor
2935
-     */
2936
-    public function __construct()
2937
-    {
2938
-        $this->show_ticket_sale_columns = true;
2939
-        $this->show_ticket_details = true;
2940
-        $this->show_expired_tickets = true;
2941
-        $this->show_datetime_selector = \EE_Ticket_Selector_Config::DO_NOT_SHOW_DATETIME_SELECTOR;
2942
-        $this->datetime_selector_threshold = 3;
2943
-    }
2944
-
2945
-
2946
-    /**
2947
-     * returns true if a datetime selector should be displayed
2948
-     *
2949
-     * @param array $datetimes
2950
-     * @return bool
2951
-     */
2952
-    public function showDatetimeSelector(array $datetimes)
2953
-    {
2954
-        // if the settings are NOT: don't show OR below threshold, THEN active = true
2955
-        return ! (
2956
-            $this->getShowDatetimeSelector() === \EE_Ticket_Selector_Config::DO_NOT_SHOW_DATETIME_SELECTOR
2957
-            || (
2958
-                $this->getShowDatetimeSelector() === \EE_Ticket_Selector_Config::MAYBE_SHOW_DATETIME_SELECTOR
2959
-                && count($datetimes) < $this->getDatetimeSelectorThreshold()
2960
-            )
2961
-        );
2962
-    }
2963
-
2964
-
2965
-    /**
2966
-     * @return string
2967
-     */
2968
-    public function getShowDatetimeSelector()
2969
-    {
2970
-        return $this->show_datetime_selector;
2971
-    }
2972
-
2973
-
2974
-    /**
2975
-     * @param bool $keys_only
2976
-     * @return array
2977
-     */
2978
-    public function getShowDatetimeSelectorOptions($keys_only = true)
2979
-    {
2980
-        return $keys_only
2981
-            ? array(
2982
-                \EE_Ticket_Selector_Config::DO_NOT_SHOW_DATETIME_SELECTOR,
2983
-                \EE_Ticket_Selector_Config::MAYBE_SHOW_DATETIME_SELECTOR,
2984
-            )
2985
-            : array(
2986
-                \EE_Ticket_Selector_Config::DO_NOT_SHOW_DATETIME_SELECTOR => esc_html__(
2987
-                    'Do not show date & time filter',
2988
-                    'event_espresso'
2989
-                ),
2990
-                \EE_Ticket_Selector_Config::MAYBE_SHOW_DATETIME_SELECTOR  => esc_html__(
2991
-                    'Maybe show date & time filter',
2992
-                    'event_espresso'
2993
-                ),
2994
-            );
2995
-    }
2996
-
2997
-
2998
-    /**
2999
-     * @param string $show_datetime_selector
3000
-     */
3001
-    public function setShowDatetimeSelector($show_datetime_selector)
3002
-    {
3003
-        $this->show_datetime_selector = in_array(
3004
-            $show_datetime_selector,
3005
-            $this->getShowDatetimeSelectorOptions(),
3006
-            true
3007
-        )
3008
-            ? $show_datetime_selector
3009
-            : \EE_Ticket_Selector_Config::DO_NOT_SHOW_DATETIME_SELECTOR;
3010
-    }
3011
-
3012
-
3013
-    /**
3014
-     * @return int
3015
-     */
3016
-    public function getDatetimeSelectorThreshold()
3017
-    {
3018
-        return $this->datetime_selector_threshold;
3019
-    }
3020
-
3021
-
3022
-    /**
3023
-     * @param int $datetime_selector_threshold
3024
-     */
3025
-    public function setDatetimeSelectorThreshold($datetime_selector_threshold)
3026
-    {
3027
-        $datetime_selector_threshold = absint($datetime_selector_threshold);
3028
-        $this->datetime_selector_threshold = $datetime_selector_threshold ? $datetime_selector_threshold : 3;
3029
-    }
2890
+	/**
2891
+	 * constant to indicate that a datetime selector should NEVER be shown for ticket selectors
2892
+	 */
2893
+	const DO_NOT_SHOW_DATETIME_SELECTOR = 'no_datetime_selector';
2894
+
2895
+	/**
2896
+	 * constant to indicate that a datetime selector should only be shown for ticket selectors
2897
+	 * when the number of datetimes for the event matches the value set for $datetime_selector_threshold
2898
+	 */
2899
+	const MAYBE_SHOW_DATETIME_SELECTOR = 'maybe_datetime_selector';
2900
+
2901
+	/**
2902
+	 * @var boolean $show_ticket_sale_columns
2903
+	 */
2904
+	public $show_ticket_sale_columns;
2905
+
2906
+	/**
2907
+	 * @var boolean $show_ticket_details
2908
+	 */
2909
+	public $show_ticket_details;
2910
+
2911
+	/**
2912
+	 * @var boolean $show_expired_tickets
2913
+	 */
2914
+	public $show_expired_tickets;
2915
+
2916
+	/**
2917
+	 * whether or not to display a dropdown box populated with event datetimes
2918
+	 * that toggles which tickets are displayed for a ticket selector.
2919
+	 * uses one of the *_DATETIME_SELECTOR constants defined above
2920
+	 *
2921
+	 * @var string $show_datetime_selector
2922
+	 */
2923
+	private $show_datetime_selector = 'no_datetime_selector';
2924
+
2925
+	/**
2926
+	 * the number of datetimes an event has to have before conditionally displaying a datetime selector
2927
+	 *
2928
+	 * @var int $datetime_selector_threshold
2929
+	 */
2930
+	private $datetime_selector_threshold = 3;
2931
+
2932
+
2933
+	/**
2934
+	 *    class constructor
2935
+	 */
2936
+	public function __construct()
2937
+	{
2938
+		$this->show_ticket_sale_columns = true;
2939
+		$this->show_ticket_details = true;
2940
+		$this->show_expired_tickets = true;
2941
+		$this->show_datetime_selector = \EE_Ticket_Selector_Config::DO_NOT_SHOW_DATETIME_SELECTOR;
2942
+		$this->datetime_selector_threshold = 3;
2943
+	}
2944
+
2945
+
2946
+	/**
2947
+	 * returns true if a datetime selector should be displayed
2948
+	 *
2949
+	 * @param array $datetimes
2950
+	 * @return bool
2951
+	 */
2952
+	public function showDatetimeSelector(array $datetimes)
2953
+	{
2954
+		// if the settings are NOT: don't show OR below threshold, THEN active = true
2955
+		return ! (
2956
+			$this->getShowDatetimeSelector() === \EE_Ticket_Selector_Config::DO_NOT_SHOW_DATETIME_SELECTOR
2957
+			|| (
2958
+				$this->getShowDatetimeSelector() === \EE_Ticket_Selector_Config::MAYBE_SHOW_DATETIME_SELECTOR
2959
+				&& count($datetimes) < $this->getDatetimeSelectorThreshold()
2960
+			)
2961
+		);
2962
+	}
2963
+
2964
+
2965
+	/**
2966
+	 * @return string
2967
+	 */
2968
+	public function getShowDatetimeSelector()
2969
+	{
2970
+		return $this->show_datetime_selector;
2971
+	}
2972
+
2973
+
2974
+	/**
2975
+	 * @param bool $keys_only
2976
+	 * @return array
2977
+	 */
2978
+	public function getShowDatetimeSelectorOptions($keys_only = true)
2979
+	{
2980
+		return $keys_only
2981
+			? array(
2982
+				\EE_Ticket_Selector_Config::DO_NOT_SHOW_DATETIME_SELECTOR,
2983
+				\EE_Ticket_Selector_Config::MAYBE_SHOW_DATETIME_SELECTOR,
2984
+			)
2985
+			: array(
2986
+				\EE_Ticket_Selector_Config::DO_NOT_SHOW_DATETIME_SELECTOR => esc_html__(
2987
+					'Do not show date & time filter',
2988
+					'event_espresso'
2989
+				),
2990
+				\EE_Ticket_Selector_Config::MAYBE_SHOW_DATETIME_SELECTOR  => esc_html__(
2991
+					'Maybe show date & time filter',
2992
+					'event_espresso'
2993
+				),
2994
+			);
2995
+	}
2996
+
2997
+
2998
+	/**
2999
+	 * @param string $show_datetime_selector
3000
+	 */
3001
+	public function setShowDatetimeSelector($show_datetime_selector)
3002
+	{
3003
+		$this->show_datetime_selector = in_array(
3004
+			$show_datetime_selector,
3005
+			$this->getShowDatetimeSelectorOptions(),
3006
+			true
3007
+		)
3008
+			? $show_datetime_selector
3009
+			: \EE_Ticket_Selector_Config::DO_NOT_SHOW_DATETIME_SELECTOR;
3010
+	}
3011
+
3012
+
3013
+	/**
3014
+	 * @return int
3015
+	 */
3016
+	public function getDatetimeSelectorThreshold()
3017
+	{
3018
+		return $this->datetime_selector_threshold;
3019
+	}
3020
+
3021
+
3022
+	/**
3023
+	 * @param int $datetime_selector_threshold
3024
+	 */
3025
+	public function setDatetimeSelectorThreshold($datetime_selector_threshold)
3026
+	{
3027
+		$datetime_selector_threshold = absint($datetime_selector_threshold);
3028
+		$this->datetime_selector_threshold = $datetime_selector_threshold ? $datetime_selector_threshold : 3;
3029
+	}
3030 3030
 }
3031 3031
 
3032 3032
 
@@ -3040,81 +3040,81 @@  discard block
 block discarded – undo
3040 3040
 class EE_Environment_Config extends EE_Config_Base
3041 3041
 {
3042 3042
 
3043
-    /**
3044
-     * Hold any php environment variables that we want to track.
3045
-     *
3046
-     * @var stdClass;
3047
-     */
3048
-    public $php;
3049
-
3050
-
3051
-    /**
3052
-     *    constructor
3053
-     */
3054
-    public function __construct()
3055
-    {
3056
-        $this->php = new stdClass();
3057
-        $this->_set_php_values();
3058
-    }
3059
-
3060
-
3061
-    /**
3062
-     * This sets the php environment variables.
3063
-     *
3064
-     * @since 4.4.0
3065
-     * @return void
3066
-     */
3067
-    protected function _set_php_values()
3068
-    {
3069
-        $this->php->max_input_vars = ini_get('max_input_vars');
3070
-        $this->php->version = phpversion();
3071
-    }
3072
-
3073
-
3074
-    /**
3075
-     * helper method for determining whether input_count is
3076
-     * reaching the potential maximum the server can handle
3077
-     * according to max_input_vars
3078
-     *
3079
-     * @param int   $input_count the count of input vars.
3080
-     * @return array {
3081
-     *                           An array that represents whether available space and if no available space the error
3082
-     *                           message.
3083
-     * @type bool   $has_space   whether more inputs can be added.
3084
-     * @type string $msg         Any message to be displayed.
3085
-     *                           }
3086
-     */
3087
-    public function max_input_vars_limit_check($input_count = 0)
3088
-    {
3089
-        if (! empty($this->php->max_input_vars)
3090
-            && ($input_count >= $this->php->max_input_vars)
3091
-            && (PHP_MAJOR_VERSION >= 5 && PHP_MINOR_VERSION >= 3 && PHP_RELEASE_VERSION >= 9)
3092
-        ) {
3093
-            return sprintf(
3094
-                __(
3095
-                    'The maximum number of inputs on this page has been exceeded.  You cannot add anymore items (i.e. tickets, datetimes, custom fields) on this page because of your servers PHP "max_input_vars" setting.%1$sThere are %2$d inputs and the maximum amount currently allowed by your server is %3$d.',
3096
-                    'event_espresso'
3097
-                ),
3098
-                '<br>',
3099
-                $input_count,
3100
-                $this->php->max_input_vars
3101
-            );
3102
-        } else {
3103
-            return '';
3104
-        }
3105
-    }
3106
-
3107
-
3108
-    /**
3109
-     * The purpose of this method is just to force rechecking php values so if they've changed, they get updated.
3110
-     *
3111
-     * @since 4.4.1
3112
-     * @return void
3113
-     */
3114
-    public function recheck_values()
3115
-    {
3116
-        $this->_set_php_values();
3117
-    }
3043
+	/**
3044
+	 * Hold any php environment variables that we want to track.
3045
+	 *
3046
+	 * @var stdClass;
3047
+	 */
3048
+	public $php;
3049
+
3050
+
3051
+	/**
3052
+	 *    constructor
3053
+	 */
3054
+	public function __construct()
3055
+	{
3056
+		$this->php = new stdClass();
3057
+		$this->_set_php_values();
3058
+	}
3059
+
3060
+
3061
+	/**
3062
+	 * This sets the php environment variables.
3063
+	 *
3064
+	 * @since 4.4.0
3065
+	 * @return void
3066
+	 */
3067
+	protected function _set_php_values()
3068
+	{
3069
+		$this->php->max_input_vars = ini_get('max_input_vars');
3070
+		$this->php->version = phpversion();
3071
+	}
3072
+
3073
+
3074
+	/**
3075
+	 * helper method for determining whether input_count is
3076
+	 * reaching the potential maximum the server can handle
3077
+	 * according to max_input_vars
3078
+	 *
3079
+	 * @param int   $input_count the count of input vars.
3080
+	 * @return array {
3081
+	 *                           An array that represents whether available space and if no available space the error
3082
+	 *                           message.
3083
+	 * @type bool   $has_space   whether more inputs can be added.
3084
+	 * @type string $msg         Any message to be displayed.
3085
+	 *                           }
3086
+	 */
3087
+	public function max_input_vars_limit_check($input_count = 0)
3088
+	{
3089
+		if (! empty($this->php->max_input_vars)
3090
+			&& ($input_count >= $this->php->max_input_vars)
3091
+			&& (PHP_MAJOR_VERSION >= 5 && PHP_MINOR_VERSION >= 3 && PHP_RELEASE_VERSION >= 9)
3092
+		) {
3093
+			return sprintf(
3094
+				__(
3095
+					'The maximum number of inputs on this page has been exceeded.  You cannot add anymore items (i.e. tickets, datetimes, custom fields) on this page because of your servers PHP "max_input_vars" setting.%1$sThere are %2$d inputs and the maximum amount currently allowed by your server is %3$d.',
3096
+					'event_espresso'
3097
+				),
3098
+				'<br>',
3099
+				$input_count,
3100
+				$this->php->max_input_vars
3101
+			);
3102
+		} else {
3103
+			return '';
3104
+		}
3105
+	}
3106
+
3107
+
3108
+	/**
3109
+	 * The purpose of this method is just to force rechecking php values so if they've changed, they get updated.
3110
+	 *
3111
+	 * @since 4.4.1
3112
+	 * @return void
3113
+	 */
3114
+	public function recheck_values()
3115
+	{
3116
+		$this->_set_php_values();
3117
+	}
3118 3118
 }
3119 3119
 
3120 3120
 
@@ -3128,21 +3128,21 @@  discard block
 block discarded – undo
3128 3128
 class EE_Tax_Config extends EE_Config_Base
3129 3129
 {
3130 3130
 
3131
-    /*
3131
+	/*
3132 3132
      * flag to indicate whether or not to display ticket prices with the taxes included
3133 3133
      *
3134 3134
      * @var boolean $prices_displayed_including_taxes
3135 3135
      */
3136
-    public $prices_displayed_including_taxes;
3136
+	public $prices_displayed_including_taxes;
3137 3137
 
3138 3138
 
3139
-    /**
3140
-     *    class constructor
3141
-     */
3142
-    public function __construct()
3143
-    {
3144
-        $this->prices_displayed_including_taxes = true;
3145
-    }
3139
+	/**
3140
+	 *    class constructor
3141
+	 */
3142
+	public function __construct()
3143
+	{
3144
+		$this->prices_displayed_including_taxes = true;
3145
+	}
3146 3146
 }
3147 3147
 
3148 3148
 
@@ -3157,18 +3157,18 @@  discard block
 block discarded – undo
3157 3157
 class EE_Messages_Config extends EE_Config_Base
3158 3158
 {
3159 3159
 
3160
-    /**
3161
-     * This is an integer representing the deletion threshold in months for when old messages will get deleted.
3162
-     * A value of 0 represents never deleting.  Default is 0.
3163
-     *
3164
-     * @var integer
3165
-     */
3166
-    public $delete_threshold;
3167
-
3168
-    public function __construct()
3169
-    {
3170
-        $this->delete_threshold = 0;
3171
-    }
3160
+	/**
3161
+	 * This is an integer representing the deletion threshold in months for when old messages will get deleted.
3162
+	 * A value of 0 represents never deleting.  Default is 0.
3163
+	 *
3164
+	 * @var integer
3165
+	 */
3166
+	public $delete_threshold;
3167
+
3168
+	public function __construct()
3169
+	{
3170
+		$this->delete_threshold = 0;
3171
+	}
3172 3172
 }
3173 3173
 
3174 3174
 
@@ -3180,31 +3180,31 @@  discard block
 block discarded – undo
3180 3180
 class EE_Gateway_Config extends EE_Config_Base
3181 3181
 {
3182 3182
 
3183
-    /**
3184
-     * Array with keys that are payment gateways slugs, and values are arrays
3185
-     * with any config info the gateway wants to store
3186
-     *
3187
-     * @var array
3188
-     */
3189
-    public $payment_settings;
3190
-
3191
-    /**
3192
-     * Where keys are gateway slugs, and values are booleans indicating whether or not
3193
-     * the gateway is stored in the uploads directory
3194
-     *
3195
-     * @var array
3196
-     */
3197
-    public $active_gateways;
3198
-
3199
-
3200
-    /**
3201
-     *    class constructor
3202
-     *
3203
-     * @deprecated
3204
-     */
3205
-    public function __construct()
3206
-    {
3207
-        $this->payment_settings = array();
3208
-        $this->active_gateways = array('Invoice' => false);
3209
-    }
3183
+	/**
3184
+	 * Array with keys that are payment gateways slugs, and values are arrays
3185
+	 * with any config info the gateway wants to store
3186
+	 *
3187
+	 * @var array
3188
+	 */
3189
+	public $payment_settings;
3190
+
3191
+	/**
3192
+	 * Where keys are gateway slugs, and values are booleans indicating whether or not
3193
+	 * the gateway is stored in the uploads directory
3194
+	 *
3195
+	 * @var array
3196
+	 */
3197
+	public $active_gateways;
3198
+
3199
+
3200
+	/**
3201
+	 *    class constructor
3202
+	 *
3203
+	 * @deprecated
3204
+	 */
3205
+	public function __construct()
3206
+	{
3207
+		$this->payment_settings = array();
3208
+		$this->active_gateways = array('Invoice' => false);
3209
+	}
3210 3210
 }
Please login to merge, or discard this patch.
espresso.php 1 patch
Indentation   +80 added lines, -80 removed lines patch added patch discarded remove patch
@@ -38,103 +38,103 @@
 block discarded – undo
38 38
  * @since           4.0
39 39
  */
40 40
 if (function_exists('espresso_version')) {
41
-    if (! function_exists('espresso_duplicate_plugin_error')) {
42
-        /**
43
-         *    espresso_duplicate_plugin_error
44
-         *    displays if more than one version of EE is activated at the same time
45
-         */
46
-        function espresso_duplicate_plugin_error()
47
-        {
48
-            ?>
41
+	if (! function_exists('espresso_duplicate_plugin_error')) {
42
+		/**
43
+		 *    espresso_duplicate_plugin_error
44
+		 *    displays if more than one version of EE is activated at the same time
45
+		 */
46
+		function espresso_duplicate_plugin_error()
47
+		{
48
+			?>
49 49
             <div class="error">
50 50
                 <p>
51 51
                     <?php
52
-                    echo esc_html__(
53
-                        'Can not run multiple versions of Event Espresso! One version has been automatically deactivated. Please verify that you have the correct version you want still active.',
54
-                        'event_espresso'
55
-                    ); ?>
52
+					echo esc_html__(
53
+						'Can not run multiple versions of Event Espresso! One version has been automatically deactivated. Please verify that you have the correct version you want still active.',
54
+						'event_espresso'
55
+					); ?>
56 56
                 </p>
57 57
             </div>
58 58
             <?php
59
-            espresso_deactivate_plugin(plugin_basename(__FILE__));
60
-        }
61
-    }
62
-    add_action('admin_notices', 'espresso_duplicate_plugin_error', 1);
59
+			espresso_deactivate_plugin(plugin_basename(__FILE__));
60
+		}
61
+	}
62
+	add_action('admin_notices', 'espresso_duplicate_plugin_error', 1);
63 63
 } else {
64
-    define('EE_MIN_PHP_VER_REQUIRED', '5.4.0');
65
-    if (! version_compare(PHP_VERSION, EE_MIN_PHP_VER_REQUIRED, '>=')) {
66
-        /**
67
-         * espresso_minimum_php_version_error
68
-         *
69
-         * @return void
70
-         */
71
-        function espresso_minimum_php_version_error()
72
-        {
73
-            ?>
64
+	define('EE_MIN_PHP_VER_REQUIRED', '5.4.0');
65
+	if (! version_compare(PHP_VERSION, EE_MIN_PHP_VER_REQUIRED, '>=')) {
66
+		/**
67
+		 * espresso_minimum_php_version_error
68
+		 *
69
+		 * @return void
70
+		 */
71
+		function espresso_minimum_php_version_error()
72
+		{
73
+			?>
74 74
             <div class="error">
75 75
                 <p>
76 76
                     <?php
77
-                    printf(
78
-                        esc_html__(
79
-                            'We\'re sorry, but Event Espresso requires PHP version %1$s or greater in order to operate. You are currently running version %2$s.%3$sIn order to update your version of PHP, you will need to contact your current hosting provider.%3$sFor information on stable PHP versions, please go to %4$s.',
80
-                            'event_espresso'
81
-                        ),
82
-                        EE_MIN_PHP_VER_REQUIRED,
83
-                        PHP_VERSION,
84
-                        '<br/>',
85
-                        '<a href="http://php.net/downloads.php">http://php.net/downloads.php</a>'
86
-                    );
87
-                    ?>
77
+					printf(
78
+						esc_html__(
79
+							'We\'re sorry, but Event Espresso requires PHP version %1$s or greater in order to operate. You are currently running version %2$s.%3$sIn order to update your version of PHP, you will need to contact your current hosting provider.%3$sFor information on stable PHP versions, please go to %4$s.',
80
+							'event_espresso'
81
+						),
82
+						EE_MIN_PHP_VER_REQUIRED,
83
+						PHP_VERSION,
84
+						'<br/>',
85
+						'<a href="http://php.net/downloads.php">http://php.net/downloads.php</a>'
86
+					);
87
+					?>
88 88
                 </p>
89 89
             </div>
90 90
             <?php
91
-            espresso_deactivate_plugin(plugin_basename(__FILE__));
92
-        }
91
+			espresso_deactivate_plugin(plugin_basename(__FILE__));
92
+		}
93 93
 
94
-        add_action('admin_notices', 'espresso_minimum_php_version_error', 1);
95
-    } else {
96
-        define('EVENT_ESPRESSO_MAIN_FILE', __FILE__);
97
-        /**
98
-         * espresso_version
99
-         * Returns the plugin version
100
-         *
101
-         * @return string
102
-         */
103
-        function espresso_version()
104
-        {
105
-            return apply_filters('FHEE__espresso__espresso_version', '4.9.63.rc.009');
106
-        }
94
+		add_action('admin_notices', 'espresso_minimum_php_version_error', 1);
95
+	} else {
96
+		define('EVENT_ESPRESSO_MAIN_FILE', __FILE__);
97
+		/**
98
+		 * espresso_version
99
+		 * Returns the plugin version
100
+		 *
101
+		 * @return string
102
+		 */
103
+		function espresso_version()
104
+		{
105
+			return apply_filters('FHEE__espresso__espresso_version', '4.9.63.rc.009');
106
+		}
107 107
 
108
-        /**
109
-         * espresso_plugin_activation
110
-         * adds a wp-option to indicate that EE has been activated via the WP admin plugins page
111
-         */
112
-        function espresso_plugin_activation()
113
-        {
114
-            update_option('ee_espresso_activation', true);
115
-        }
108
+		/**
109
+		 * espresso_plugin_activation
110
+		 * adds a wp-option to indicate that EE has been activated via the WP admin plugins page
111
+		 */
112
+		function espresso_plugin_activation()
113
+		{
114
+			update_option('ee_espresso_activation', true);
115
+		}
116 116
 
117
-        register_activation_hook(EVENT_ESPRESSO_MAIN_FILE, 'espresso_plugin_activation');
117
+		register_activation_hook(EVENT_ESPRESSO_MAIN_FILE, 'espresso_plugin_activation');
118 118
 
119
-        require_once __DIR__ . '/core/bootstrap_espresso.php';
120
-        bootstrap_espresso();
121
-    }
119
+		require_once __DIR__ . '/core/bootstrap_espresso.php';
120
+		bootstrap_espresso();
121
+	}
122 122
 }
123 123
 if (! function_exists('espresso_deactivate_plugin')) {
124
-    /**
125
-     *    deactivate_plugin
126
-     * usage:  espresso_deactivate_plugin( plugin_basename( __FILE__ ));
127
-     *
128
-     * @access public
129
-     * @param string $plugin_basename - the results of plugin_basename( __FILE__ ) for the plugin's main file
130
-     * @return    void
131
-     */
132
-    function espresso_deactivate_plugin($plugin_basename = '')
133
-    {
134
-        if (! function_exists('deactivate_plugins')) {
135
-            require_once ABSPATH . 'wp-admin/includes/plugin.php';
136
-        }
137
-        unset($_GET['activate'], $_REQUEST['activate']);
138
-        deactivate_plugins($plugin_basename);
139
-    }
124
+	/**
125
+	 *    deactivate_plugin
126
+	 * usage:  espresso_deactivate_plugin( plugin_basename( __FILE__ ));
127
+	 *
128
+	 * @access public
129
+	 * @param string $plugin_basename - the results of plugin_basename( __FILE__ ) for the plugin's main file
130
+	 * @return    void
131
+	 */
132
+	function espresso_deactivate_plugin($plugin_basename = '')
133
+	{
134
+		if (! function_exists('deactivate_plugins')) {
135
+			require_once ABSPATH . 'wp-admin/includes/plugin.php';
136
+		}
137
+		unset($_GET['activate'], $_REQUEST['activate']);
138
+		deactivate_plugins($plugin_basename);
139
+	}
140 140
 }
Please login to merge, or discard this patch.