Completed
Branch FET/extract-activation-detecti... (285969)
by
unknown
05:12 queued 02:43
created
core/services/container/CoffeeShop.php 2 patches
Spacing   +11 added lines, -11 removed lines patch added patch discarded remove patch
@@ -159,7 +159,7 @@  discard block
 block discarded – undo
159 159
         }
160 160
         // if the reservoir doesn't have a closure already for the requested identifier,
161 161
         // then neither a shared service nor a closure for making entities has been built yet
162
-        if (! $this->reservoir->has($identifier)) {
162
+        if ( ! $this->reservoir->has($identifier)) {
163 163
             // so let's brew something up and add it to the proper collection
164 164
             $brewed = $this->makeCoffee($identifier, $arguments, $type);
165 165
         }
@@ -284,7 +284,7 @@  discard block
 block discarded – undo
284 284
      */
285 285
     public function addClosure($identifier, $closure)
286 286
     {
287
-        if (! is_callable($closure)) {
287
+        if ( ! is_callable($closure)) {
288 288
             throw new InvalidDataTypeException('$closure', $closure, 'Closure');
289 289
         }
290 290
         $identifier = $this->processIdentifier($identifier);
@@ -393,7 +393,7 @@  discard block
 block discarded – undo
393 393
             // is the wildcard recipe prefix in the identifier ?
394 394
             if (strpos($identifier, $wildcard) !== false) {
395 395
                 // track matches and use the number of wildcard characters matched for the key
396
-                $matches[ strlen($wildcard) ] = $default_recipe;
396
+                $matches[strlen($wildcard)] = $default_recipe;
397 397
             }
398 398
         }
399 399
         if (count($matches) > 0) {
@@ -433,7 +433,7 @@  discard block
 block discarded – undo
433 433
         }
434 434
         $identifier = $this->processIdentifier($identifier);
435 435
         foreach ((array) $aliases as $alias) {
436
-            $this->filters[ $this->processIdentifier($alias) ] = $identifier;
436
+            $this->filters[$this->processIdentifier($alias)] = $identifier;
437 437
         }
438 438
     }
439 439
 
@@ -475,8 +475,8 @@  discard block
 block discarded – undo
475 475
     private function filterIdentifier($identifier)
476 476
     {
477 477
         $identifier = $this->processIdentifier($identifier);
478
-        return isset($this->filters[ $identifier ]) && ! empty($this->filters[ $identifier ])
479
-            ? $this->filters[ $identifier ]
478
+        return isset($this->filters[$identifier]) && ! empty($this->filters[$identifier])
479
+            ? $this->filters[$identifier]
480 480
             : $identifier;
481 481
     }
482 482
 
@@ -491,7 +491,7 @@  discard block
 block discarded – undo
491 491
      */
492 492
     private function processIdentifier($identifier)
493 493
     {
494
-        if (! is_string($identifier)) {
494
+        if ( ! is_string($identifier)) {
495 495
             throw new InvalidIdentifierException(
496 496
                 is_object($identifier) ? get_class($identifier) : gettype($identifier),
497 497
                 '\Fully\Qualified\ClassName'
@@ -510,7 +510,7 @@  discard block
 block discarded – undo
510 510
      */
511 511
     private function getCoffeeMaker($type)
512 512
     {
513
-        if (! $this->coffee_makers->has($type)) {
513
+        if ( ! $this->coffee_makers->has($type)) {
514 514
             throw new OutOfBoundsException(
515 515
                 esc_html__('The requested coffee maker is either missing or invalid.', 'event_espresso')
516 516
             );
@@ -537,7 +537,7 @@  discard block
 block discarded – undo
537 537
             // does this recipe use a wildcard ? (but is NOT the global default)
538 538
             if ($identifier !== Recipe::DEFAULT_ID && strpos($identifier, '*') !== false) {
539 539
                 // strip the wildcard and use identifier as key
540
-                $default_recipes[ str_replace('*', '', $identifier) ] = $this->recipes->current();
540
+                $default_recipes[str_replace('*', '', $identifier)] = $this->recipes->current();
541 541
             }
542 542
             $this->recipes->next();
543 543
         }
@@ -557,7 +557,7 @@  discard block
 block discarded – undo
557 557
     private function copyDefaultRecipe(RecipeInterface $default_recipe, $identifier, $type = '')
558 558
     {
559 559
         $recipe = clone $default_recipe;
560
-        if (! empty($type)) {
560
+        if ( ! empty($type)) {
561 561
             $recipe->setType($type);
562 562
         }
563 563
         // is this the base default recipe ?
@@ -587,7 +587,7 @@  discard block
 block discarded – undo
587 587
      */
588 588
     private function validateService($identifier, $service)
589 589
     {
590
-        if (! is_object($service)) {
590
+        if ( ! is_object($service)) {
591 591
             throw new InvalidServiceException(
592 592
                 $identifier,
593 593
                 $service
Please login to merge, or discard this patch.
Indentation   +565 added lines, -565 removed lines patch added patch discarded remove patch
@@ -28,569 +28,569 @@
 block discarded – undo
28 28
  */
29 29
 class CoffeeShop implements CoffeePotInterface
30 30
 {
31
-    /**
32
-     * This was the best coffee related name I could think of to represent class name "aliases"
33
-     * So classes can be found via an alias identifier,
34
-     * that is revealed when it is run through... the filters... eh? get it?
35
-     *
36
-     * @var array $filters
37
-     */
38
-    private $filters;
39
-
40
-    /**
41
-     * These are the classes that will actually build the objects (to order of course)
42
-     *
43
-     * @var array $coffee_makers
44
-     */
45
-    private $coffee_makers;
46
-
47
-    /**
48
-     * where the instantiated "singleton" objects are stored
49
-     *
50
-     * @var CollectionInterface $carafe
51
-     */
52
-    private $carafe;
53
-
54
-    /**
55
-     * collection of Recipes that instruct us how to brew objects
56
-     *
57
-     * @var CollectionInterface $recipes
58
-     */
59
-    private $recipes;
60
-
61
-    /**
62
-     * collection of closures for brewing objects
63
-     *
64
-     * @var CollectionInterface $reservoir
65
-     */
66
-    private $reservoir;
67
-
68
-
69
-    /**
70
-     * CoffeeShop constructor
71
-     *
72
-     * @throws InvalidInterfaceException
73
-     */
74
-    public function __construct()
75
-    {
76
-        // array for storing class aliases
77
-        $this->filters = array();
78
-        // create collection for storing shared services
79
-        $this->carafe = new LooseCollection('');
80
-        // create collection for storing recipes that tell us how to build services and entities
81
-        $this->recipes = new Collection('EventEspresso\core\services\container\RecipeInterface');
82
-        // create collection for storing closures for constructing new entities
83
-        $this->reservoir = new Collection('Closure');
84
-        // create collection for storing the generators that build our services and entity closures
85
-        $this->coffee_makers = new Collection('EventEspresso\core\services\container\CoffeeMakerInterface');
86
-    }
87
-
88
-
89
-    /**
90
-     * Returns true if the container can return an entry for the given identifier.
91
-     * Returns false otherwise.
92
-     * `has($identifier)` returning true does not mean that `get($identifier)` will not throw an exception.
93
-     * It does however mean that `get($identifier)` will not throw a `ServiceNotFoundException`.
94
-     *
95
-     * @param string $identifier  Identifier of the entry to look for.
96
-     *                            Typically a Fully Qualified Class Name
97
-     * @return boolean
98
-     * @throws InvalidIdentifierException
99
-     */
100
-    public function has($identifier)
101
-    {
102
-        $identifier = $this->filterIdentifier($identifier);
103
-        return $this->carafe->has($identifier);
104
-    }
105
-
106
-
107
-    /**
108
-     * finds a previously brewed (SHARED) service and returns it
109
-     *
110
-     * @param  string $identifier Identifier for the entity class to be constructed.
111
-     *                            Typically a Fully Qualified Class Name
112
-     * @return mixed
113
-     * @throws InvalidIdentifierException
114
-     * @throws ServiceNotFoundException No service was found for this identifier.
115
-     */
116
-    public function get($identifier)
117
-    {
118
-        $identifier = $this->filterIdentifier($identifier);
119
-        if ($this->carafe->has($identifier)) {
120
-            return $this->carafe->get($identifier);
121
-        }
122
-        throw new ServiceNotFoundException($identifier);
123
-    }
124
-
125
-
126
-    /**
127
-     * returns an instance of the requested entity type using the supplied arguments.
128
-     * If a shared service is requested and an instance is already in the carafe, then it will be returned.
129
-     * If it is not already in the carafe, then the service will be constructed, added to the carafe, and returned
130
-     * If the request is for a new entity and a closure exists in the reservoir for creating it,
131
-     * then a new entity will be instantiated from the closure and returned.
132
-     * If a closure does not exist, then one will be built and added to the reservoir
133
-     * before instantiating the requested entity.
134
-     *
135
-     * @param  string $identifier Identifier for the entity class to be constructed.
136
-     *                            Typically a Fully Qualified Class Name
137
-     * @param array   $arguments  an array of arguments to be passed to the entity constructor
138
-     * @param string  $type
139
-     * @return mixed
140
-     * @throws OutOfBoundsException
141
-     * @throws InstantiationException
142
-     * @throws InvalidDataTypeException
143
-     * @throws InvalidClassException
144
-     * @throws InvalidIdentifierException
145
-     * @throws ServiceExistsException
146
-     * @throws ServiceNotFoundException No service was found for this identifier.
147
-     */
148
-    public function brew($identifier, $arguments = array(), $type = '')
149
-    {
150
-        // resolve any class aliases that may exist
151
-        $identifier = $this->filterIdentifier($identifier);
152
-        // is a shared service being requested and already exists in the carafe?
153
-        $brewed = $this->getShared($identifier, $type);
154
-        // then return whatever was found
155
-        if ($brewed !== false) {
156
-            return $brewed;
157
-        }
158
-        // if the reservoir doesn't have a closure already for the requested identifier,
159
-        // then neither a shared service nor a closure for making entities has been built yet
160
-        if (! $this->reservoir->has($identifier)) {
161
-            // so let's brew something up and add it to the proper collection
162
-            $brewed = $this->makeCoffee($identifier, $arguments, $type);
163
-        }
164
-        // did the requested class only require loading, and if so, was that successful?
165
-        if ($this->brewedLoadOnly($brewed, $identifier, $type) === true) {
166
-            return true;
167
-        }
168
-        // was the brewed item a callable factory function ?
169
-        if (is_callable($brewed)) {
170
-            // then instantiate a new entity from the cached closure
171
-            return $brewed($arguments);
172
-        }
173
-        if ($brewed) {
174
-            // requested object was a shared entity, so attempt to get it from the carafe again
175
-            // because if it wasn't there before, then it should have just been brewed and added,
176
-            // but if it still isn't there, then this time the thrown ServiceNotFoundException will not be caught
177
-            return $this->get($identifier);
178
-        }
179
-        // if identifier is for a non-shared entity,
180
-        // then either a cached closure already existed, or was just brewed
181
-        return $this->brewedClosure($identifier, $arguments);
182
-    }
183
-
184
-
185
-    /**
186
-     * @param string $identifier
187
-     * @param string $type
188
-     * @return bool|mixed
189
-     * @throws InvalidIdentifierException
190
-     */
191
-    protected function getShared($identifier, $type)
192
-    {
193
-        try {
194
-            if (empty($type) || $type === CoffeeMaker::BREW_SHARED) {
195
-                // if a shared service was requested and an instance is in the carafe, then return it
196
-                return $this->get($identifier);
197
-            }
198
-        } catch (ServiceNotFoundException $e) {
199
-            // if not then we'll just catch the ServiceNotFoundException but not do anything just yet,
200
-            // and instead, attempt to build whatever was requested
201
-        }
202
-        return false;
203
-    }
204
-
205
-
206
-    /**
207
-     * @param mixed  $brewed
208
-     * @param string $identifier
209
-     * @param string $type
210
-     * @return bool
211
-     * @throws InvalidClassException
212
-     * @throws InvalidDataTypeException
213
-     * @throws InvalidIdentifierException
214
-     * @throws OutOfBoundsException
215
-     * @throws ServiceExistsException
216
-     * @throws ServiceNotFoundException
217
-     */
218
-    protected function brewedLoadOnly($brewed, $identifier, $type)
219
-    {
220
-        if ($type === CoffeeMaker::BREW_LOAD_ONLY) {
221
-            if ($brewed !== true) {
222
-                throw new ServiceNotFoundException(
223
-                    sprintf(
224
-                        esc_html__(
225
-                            'The "%1$s" class could not be loaded.',
226
-                            'event_espresso'
227
-                        ),
228
-                        $identifier
229
-                    )
230
-                );
231
-            }
232
-            return true;
233
-        }
234
-        return false;
235
-    }
236
-
237
-
238
-    /**
239
-     * @param string $identifier
240
-     * @param array  $arguments
241
-     * @return mixed
242
-     * @throws InstantiationException
243
-     */
244
-    protected function brewedClosure($identifier, array $arguments)
245
-    {
246
-        $closure = $this->reservoir->get($identifier);
247
-        if (empty($closure)) {
248
-            throw new InstantiationException(
249
-                sprintf(
250
-                    esc_html__(
251
-                        'Could not brew an instance of "%1$s".',
252
-                        'event_espresso'
253
-                    ),
254
-                    $identifier
255
-                )
256
-            );
257
-        }
258
-        return $closure($arguments);
259
-    }
260
-
261
-
262
-    /**
263
-     * @param CoffeeMakerInterface $coffee_maker
264
-     * @param string               $type
265
-     * @return bool
266
-     * @throws InvalidIdentifierException
267
-     * @throws InvalidEntityException
268
-     */
269
-    public function addCoffeeMaker(CoffeeMakerInterface $coffee_maker, $type)
270
-    {
271
-        $type = CoffeeMaker::validateType($type);
272
-        return $this->coffee_makers->add($coffee_maker, $type);
273
-    }
274
-
275
-
276
-    /**
277
-     * @param string   $identifier
278
-     * @param callable $closure
279
-     * @return callable|null
280
-     * @throws InvalidIdentifierException
281
-     * @throws InvalidDataTypeException
282
-     */
283
-    public function addClosure($identifier, $closure)
284
-    {
285
-        if (! is_callable($closure)) {
286
-            throw new InvalidDataTypeException('$closure', $closure, 'Closure');
287
-        }
288
-        $identifier = $this->processIdentifier($identifier);
289
-        if ($this->reservoir->add($closure, $identifier)) {
290
-            return $closure;
291
-        }
292
-        return null;
293
-    }
294
-
295
-
296
-    /**
297
-     * @param string $identifier
298
-     * @return boolean
299
-     * @throws InvalidIdentifierException
300
-     */
301
-    public function removeClosure($identifier)
302
-    {
303
-        $identifier = $this->processIdentifier($identifier);
304
-        if ($this->reservoir->has($identifier)) {
305
-            return $this->reservoir->remove($this->reservoir->get($identifier));
306
-        }
307
-        return false;
308
-    }
309
-
310
-
311
-    /**
312
-     * @param  string $identifier Identifier for the entity class that the service applies to
313
-     *                            Typically a Fully Qualified Class Name
314
-     * @param mixed   $service
315
-     * @return bool
316
-     * @throws \EventEspresso\core\services\container\exceptions\InvalidServiceException
317
-     * @throws InvalidIdentifierException
318
-     */
319
-    public function addService($identifier, $service)
320
-    {
321
-        $identifier = $this->processIdentifier($identifier);
322
-        $service = $this->validateService($identifier, $service);
323
-        return $this->carafe->add($service, $identifier);
324
-    }
325
-
326
-
327
-    /**
328
-     * @param string $identifier
329
-     * @return boolean
330
-     * @throws InvalidIdentifierException
331
-     */
332
-    public function removeService($identifier)
333
-    {
334
-        $identifier = $this->processIdentifier($identifier);
335
-        if ($this->carafe->has($identifier)) {
336
-            return $this->carafe->remove($this->carafe->get($identifier));
337
-        }
338
-        return false;
339
-    }
340
-
341
-
342
-    /**
343
-     * Adds instructions on how to brew objects
344
-     *
345
-     * @param RecipeInterface $recipe
346
-     * @return mixed
347
-     * @throws InvalidIdentifierException
348
-     */
349
-    public function addRecipe(RecipeInterface $recipe)
350
-    {
351
-        $this->addAliases($recipe->identifier(), $recipe->filters());
352
-        $identifier = $this->processIdentifier($recipe->identifier());
353
-        return $this->recipes->add($recipe, $identifier);
354
-    }
355
-
356
-
357
-    /**
358
-     * @param string $identifier The Recipe's identifier
359
-     * @return boolean
360
-     * @throws InvalidIdentifierException
361
-     */
362
-    public function removeRecipe($identifier)
363
-    {
364
-        $identifier = $this->processIdentifier($identifier);
365
-        if ($this->recipes->has($identifier)) {
366
-            return $this->recipes->remove($this->recipes->get($identifier));
367
-        }
368
-        return false;
369
-    }
370
-
371
-
372
-    /**
373
-     * Get instructions on how to brew objects
374
-     *
375
-     * @param  string $identifier Identifier for the entity class that the recipe applies to
376
-     *                            Typically a Fully Qualified Class Name
377
-     * @param string  $type
378
-     * @return RecipeInterface
379
-     * @throws OutOfBoundsException
380
-     * @throws InvalidIdentifierException
381
-     */
382
-    public function getRecipe($identifier, $type = '')
383
-    {
384
-        $identifier = $this->processIdentifier($identifier);
385
-        if ($this->recipes->has($identifier)) {
386
-            return $this->recipes->get($identifier);
387
-        }
388
-        $default_recipes = $this->getDefaultRecipes();
389
-        $matches = array();
390
-        foreach ($default_recipes as $wildcard => $default_recipe) {
391
-            // is the wildcard recipe prefix in the identifier ?
392
-            if (strpos($identifier, $wildcard) !== false) {
393
-                // track matches and use the number of wildcard characters matched for the key
394
-                $matches[ strlen($wildcard) ] = $default_recipe;
395
-            }
396
-        }
397
-        if (count($matches) > 0) {
398
-            // sort our recipes by the number of wildcard characters matched
399
-            ksort($matches);
400
-            // then grab the last recipe form the list, since it had the most matching characters
401
-            $match = array_pop($matches);
402
-            // since we are using a default recipe, we need to set it's identifier and fqcn
403
-            return $this->copyDefaultRecipe($match, $identifier, $type);
404
-        }
405
-        if ($this->recipes->has(Recipe::DEFAULT_ID)) {
406
-            // since we are using a default recipe, we need to set it's identifier and fqcn
407
-            return $this->copyDefaultRecipe($this->recipes->get(Recipe::DEFAULT_ID), $identifier, $type);
408
-        }
409
-        throw new OutOfBoundsException(
410
-            sprintf(
411
-                esc_html__('Could not brew coffee because no recipes were found for class "%1$s".', 'event_espresso'),
412
-                $identifier
413
-            )
414
-        );
415
-    }
416
-
417
-
418
-    /**
419
-     * adds class name aliases to list of filters
420
-     *
421
-     * @param  string       $identifier Identifier for the entity class that the alias applies to
422
-     *                                  Typically a Fully Qualified Class Name
423
-     * @param  array|string $aliases
424
-     * @return void
425
-     * @throws InvalidIdentifierException
426
-     */
427
-    public function addAliases($identifier, $aliases)
428
-    {
429
-        if (empty($aliases)) {
430
-            return;
431
-        }
432
-        $identifier = $this->processIdentifier($identifier);
433
-        foreach ((array) $aliases as $alias) {
434
-            $this->filters[ $this->processIdentifier($alias) ] = $identifier;
435
-        }
436
-    }
437
-
438
-
439
-    /**
440
-     * Adds a service to one of the internal collections
441
-     *
442
-     * @param        $identifier
443
-     * @param array  $arguments
444
-     * @param string $type
445
-     * @return mixed
446
-     * @throws InvalidDataTypeException
447
-     * @throws InvalidClassException
448
-     * @throws OutOfBoundsException
449
-     * @throws InvalidIdentifierException
450
-     * @throws ServiceExistsException
451
-     */
452
-    private function makeCoffee($identifier, $arguments = array(), $type = '')
453
-    {
454
-        if ((empty($type) || $type === CoffeeMaker::BREW_SHARED) && $this->has($identifier)) {
455
-            throw new ServiceExistsException($identifier);
456
-        }
457
-        $identifier = $this->filterIdentifier($identifier);
458
-        $recipe = $this->getRecipe($identifier, $type);
459
-        $type = ! empty($type) ? $type : $recipe->type();
460
-        $coffee_maker = $this->getCoffeeMaker($type);
461
-        return $coffee_maker->brew($recipe, $arguments);
462
-    }
463
-
464
-
465
-    /**
466
-     * filters alias identifiers to find the real class name
467
-     *
468
-     * @param  string $identifier Identifier for the entity class that the filter applies to
469
-     *                            Typically a Fully Qualified Class Name
470
-     * @return string
471
-     * @throws InvalidIdentifierException
472
-     */
473
-    private function filterIdentifier($identifier)
474
-    {
475
-        $identifier = $this->processIdentifier($identifier);
476
-        return isset($this->filters[ $identifier ]) && ! empty($this->filters[ $identifier ])
477
-            ? $this->filters[ $identifier ]
478
-            : $identifier;
479
-    }
480
-
481
-
482
-    /**
483
-     * verifies and standardizes identifiers
484
-     *
485
-     * @param  string $identifier Identifier for the entity class
486
-     *                            Typically a Fully Qualified Class Name
487
-     * @return string
488
-     * @throws InvalidIdentifierException
489
-     */
490
-    private function processIdentifier($identifier)
491
-    {
492
-        if (! is_string($identifier)) {
493
-            throw new InvalidIdentifierException(
494
-                is_object($identifier) ? get_class($identifier) : gettype($identifier),
495
-                '\Fully\Qualified\ClassName'
496
-            );
497
-        }
498
-        return ltrim($identifier, '\\');
499
-    }
500
-
501
-
502
-    /**
503
-     * @param string $type
504
-     * @return CoffeeMakerInterface
505
-     * @throws OutOfBoundsException
506
-     * @throws InvalidDataTypeException
507
-     * @throws InvalidClassException
508
-     */
509
-    private function getCoffeeMaker($type)
510
-    {
511
-        if (! $this->coffee_makers->has($type)) {
512
-            throw new OutOfBoundsException(
513
-                esc_html__('The requested coffee maker is either missing or invalid.', 'event_espresso')
514
-            );
515
-        }
516
-        return $this->coffee_makers->get($type);
517
-    }
518
-
519
-
520
-    /**
521
-     * Retrieves all recipes that use a wildcard "*" in their identifier
522
-     * This allows recipes to be set up for handling
523
-     * legacy classes that do not support PSR-4 autoloading.
524
-     * for example:
525
-     * using "EEM_*" for a recipe identifier would target all legacy models like EEM_Attendee
526
-     *
527
-     * @return array
528
-     */
529
-    private function getDefaultRecipes()
530
-    {
531
-        $default_recipes = array();
532
-        $this->recipes->rewind();
533
-        while ($this->recipes->valid()) {
534
-            $identifier = $this->recipes->getInfo();
535
-            // does this recipe use a wildcard ? (but is NOT the global default)
536
-            if ($identifier !== Recipe::DEFAULT_ID && strpos($identifier, '*') !== false) {
537
-                // strip the wildcard and use identifier as key
538
-                $default_recipes[ str_replace('*', '', $identifier) ] = $this->recipes->current();
539
-            }
540
-            $this->recipes->next();
541
-        }
542
-        return $default_recipes;
543
-    }
544
-
545
-
546
-    /**
547
-     * clones a default recipe and then copies details
548
-     * from the incoming request to it so that it can be used
549
-     *
550
-     * @param RecipeInterface $default_recipe
551
-     * @param string          $identifier
552
-     * @param string          $type
553
-     * @return RecipeInterface
554
-     */
555
-    private function copyDefaultRecipe(RecipeInterface $default_recipe, $identifier, $type = '')
556
-    {
557
-        $recipe = clone $default_recipe;
558
-        if (! empty($type)) {
559
-            $recipe->setType($type);
560
-        }
561
-        // is this the base default recipe ?
562
-        if ($default_recipe->identifier() === Recipe::DEFAULT_ID) {
563
-            $recipe->setIdentifier($identifier);
564
-            $recipe->setFqcn($identifier);
565
-            return $recipe;
566
-        }
567
-        $recipe->setIdentifier($identifier);
568
-        foreach ($default_recipe->paths() as $path) {
569
-            $path = str_replace('*', $identifier, $path);
570
-            if (is_readable($path)) {
571
-                $recipe->setPaths($path);
572
-            }
573
-        }
574
-        $recipe->setFqcn($identifier);
575
-        return $recipe;
576
-    }
577
-
578
-
579
-    /**
580
-     * @param  string $identifier Identifier for the entity class that the service applies to
581
-     *                            Typically a Fully Qualified Class Name
582
-     * @param mixed   $service
583
-     * @return mixed
584
-     * @throws InvalidServiceException
585
-     */
586
-    private function validateService($identifier, $service)
587
-    {
588
-        if (! is_object($service)) {
589
-            throw new InvalidServiceException(
590
-                $identifier,
591
-                $service
592
-            );
593
-        }
594
-        return $service;
595
-    }
31
+	/**
32
+	 * This was the best coffee related name I could think of to represent class name "aliases"
33
+	 * So classes can be found via an alias identifier,
34
+	 * that is revealed when it is run through... the filters... eh? get it?
35
+	 *
36
+	 * @var array $filters
37
+	 */
38
+	private $filters;
39
+
40
+	/**
41
+	 * These are the classes that will actually build the objects (to order of course)
42
+	 *
43
+	 * @var array $coffee_makers
44
+	 */
45
+	private $coffee_makers;
46
+
47
+	/**
48
+	 * where the instantiated "singleton" objects are stored
49
+	 *
50
+	 * @var CollectionInterface $carafe
51
+	 */
52
+	private $carafe;
53
+
54
+	/**
55
+	 * collection of Recipes that instruct us how to brew objects
56
+	 *
57
+	 * @var CollectionInterface $recipes
58
+	 */
59
+	private $recipes;
60
+
61
+	/**
62
+	 * collection of closures for brewing objects
63
+	 *
64
+	 * @var CollectionInterface $reservoir
65
+	 */
66
+	private $reservoir;
67
+
68
+
69
+	/**
70
+	 * CoffeeShop constructor
71
+	 *
72
+	 * @throws InvalidInterfaceException
73
+	 */
74
+	public function __construct()
75
+	{
76
+		// array for storing class aliases
77
+		$this->filters = array();
78
+		// create collection for storing shared services
79
+		$this->carafe = new LooseCollection('');
80
+		// create collection for storing recipes that tell us how to build services and entities
81
+		$this->recipes = new Collection('EventEspresso\core\services\container\RecipeInterface');
82
+		// create collection for storing closures for constructing new entities
83
+		$this->reservoir = new Collection('Closure');
84
+		// create collection for storing the generators that build our services and entity closures
85
+		$this->coffee_makers = new Collection('EventEspresso\core\services\container\CoffeeMakerInterface');
86
+	}
87
+
88
+
89
+	/**
90
+	 * Returns true if the container can return an entry for the given identifier.
91
+	 * Returns false otherwise.
92
+	 * `has($identifier)` returning true does not mean that `get($identifier)` will not throw an exception.
93
+	 * It does however mean that `get($identifier)` will not throw a `ServiceNotFoundException`.
94
+	 *
95
+	 * @param string $identifier  Identifier of the entry to look for.
96
+	 *                            Typically a Fully Qualified Class Name
97
+	 * @return boolean
98
+	 * @throws InvalidIdentifierException
99
+	 */
100
+	public function has($identifier)
101
+	{
102
+		$identifier = $this->filterIdentifier($identifier);
103
+		return $this->carafe->has($identifier);
104
+	}
105
+
106
+
107
+	/**
108
+	 * finds a previously brewed (SHARED) service and returns it
109
+	 *
110
+	 * @param  string $identifier Identifier for the entity class to be constructed.
111
+	 *                            Typically a Fully Qualified Class Name
112
+	 * @return mixed
113
+	 * @throws InvalidIdentifierException
114
+	 * @throws ServiceNotFoundException No service was found for this identifier.
115
+	 */
116
+	public function get($identifier)
117
+	{
118
+		$identifier = $this->filterIdentifier($identifier);
119
+		if ($this->carafe->has($identifier)) {
120
+			return $this->carafe->get($identifier);
121
+		}
122
+		throw new ServiceNotFoundException($identifier);
123
+	}
124
+
125
+
126
+	/**
127
+	 * returns an instance of the requested entity type using the supplied arguments.
128
+	 * If a shared service is requested and an instance is already in the carafe, then it will be returned.
129
+	 * If it is not already in the carafe, then the service will be constructed, added to the carafe, and returned
130
+	 * If the request is for a new entity and a closure exists in the reservoir for creating it,
131
+	 * then a new entity will be instantiated from the closure and returned.
132
+	 * If a closure does not exist, then one will be built and added to the reservoir
133
+	 * before instantiating the requested entity.
134
+	 *
135
+	 * @param  string $identifier Identifier for the entity class to be constructed.
136
+	 *                            Typically a Fully Qualified Class Name
137
+	 * @param array   $arguments  an array of arguments to be passed to the entity constructor
138
+	 * @param string  $type
139
+	 * @return mixed
140
+	 * @throws OutOfBoundsException
141
+	 * @throws InstantiationException
142
+	 * @throws InvalidDataTypeException
143
+	 * @throws InvalidClassException
144
+	 * @throws InvalidIdentifierException
145
+	 * @throws ServiceExistsException
146
+	 * @throws ServiceNotFoundException No service was found for this identifier.
147
+	 */
148
+	public function brew($identifier, $arguments = array(), $type = '')
149
+	{
150
+		// resolve any class aliases that may exist
151
+		$identifier = $this->filterIdentifier($identifier);
152
+		// is a shared service being requested and already exists in the carafe?
153
+		$brewed = $this->getShared($identifier, $type);
154
+		// then return whatever was found
155
+		if ($brewed !== false) {
156
+			return $brewed;
157
+		}
158
+		// if the reservoir doesn't have a closure already for the requested identifier,
159
+		// then neither a shared service nor a closure for making entities has been built yet
160
+		if (! $this->reservoir->has($identifier)) {
161
+			// so let's brew something up and add it to the proper collection
162
+			$brewed = $this->makeCoffee($identifier, $arguments, $type);
163
+		}
164
+		// did the requested class only require loading, and if so, was that successful?
165
+		if ($this->brewedLoadOnly($brewed, $identifier, $type) === true) {
166
+			return true;
167
+		}
168
+		// was the brewed item a callable factory function ?
169
+		if (is_callable($brewed)) {
170
+			// then instantiate a new entity from the cached closure
171
+			return $brewed($arguments);
172
+		}
173
+		if ($brewed) {
174
+			// requested object was a shared entity, so attempt to get it from the carafe again
175
+			// because if it wasn't there before, then it should have just been brewed and added,
176
+			// but if it still isn't there, then this time the thrown ServiceNotFoundException will not be caught
177
+			return $this->get($identifier);
178
+		}
179
+		// if identifier is for a non-shared entity,
180
+		// then either a cached closure already existed, or was just brewed
181
+		return $this->brewedClosure($identifier, $arguments);
182
+	}
183
+
184
+
185
+	/**
186
+	 * @param string $identifier
187
+	 * @param string $type
188
+	 * @return bool|mixed
189
+	 * @throws InvalidIdentifierException
190
+	 */
191
+	protected function getShared($identifier, $type)
192
+	{
193
+		try {
194
+			if (empty($type) || $type === CoffeeMaker::BREW_SHARED) {
195
+				// if a shared service was requested and an instance is in the carafe, then return it
196
+				return $this->get($identifier);
197
+			}
198
+		} catch (ServiceNotFoundException $e) {
199
+			// if not then we'll just catch the ServiceNotFoundException but not do anything just yet,
200
+			// and instead, attempt to build whatever was requested
201
+		}
202
+		return false;
203
+	}
204
+
205
+
206
+	/**
207
+	 * @param mixed  $brewed
208
+	 * @param string $identifier
209
+	 * @param string $type
210
+	 * @return bool
211
+	 * @throws InvalidClassException
212
+	 * @throws InvalidDataTypeException
213
+	 * @throws InvalidIdentifierException
214
+	 * @throws OutOfBoundsException
215
+	 * @throws ServiceExistsException
216
+	 * @throws ServiceNotFoundException
217
+	 */
218
+	protected function brewedLoadOnly($brewed, $identifier, $type)
219
+	{
220
+		if ($type === CoffeeMaker::BREW_LOAD_ONLY) {
221
+			if ($brewed !== true) {
222
+				throw new ServiceNotFoundException(
223
+					sprintf(
224
+						esc_html__(
225
+							'The "%1$s" class could not be loaded.',
226
+							'event_espresso'
227
+						),
228
+						$identifier
229
+					)
230
+				);
231
+			}
232
+			return true;
233
+		}
234
+		return false;
235
+	}
236
+
237
+
238
+	/**
239
+	 * @param string $identifier
240
+	 * @param array  $arguments
241
+	 * @return mixed
242
+	 * @throws InstantiationException
243
+	 */
244
+	protected function brewedClosure($identifier, array $arguments)
245
+	{
246
+		$closure = $this->reservoir->get($identifier);
247
+		if (empty($closure)) {
248
+			throw new InstantiationException(
249
+				sprintf(
250
+					esc_html__(
251
+						'Could not brew an instance of "%1$s".',
252
+						'event_espresso'
253
+					),
254
+					$identifier
255
+				)
256
+			);
257
+		}
258
+		return $closure($arguments);
259
+	}
260
+
261
+
262
+	/**
263
+	 * @param CoffeeMakerInterface $coffee_maker
264
+	 * @param string               $type
265
+	 * @return bool
266
+	 * @throws InvalidIdentifierException
267
+	 * @throws InvalidEntityException
268
+	 */
269
+	public function addCoffeeMaker(CoffeeMakerInterface $coffee_maker, $type)
270
+	{
271
+		$type = CoffeeMaker::validateType($type);
272
+		return $this->coffee_makers->add($coffee_maker, $type);
273
+	}
274
+
275
+
276
+	/**
277
+	 * @param string   $identifier
278
+	 * @param callable $closure
279
+	 * @return callable|null
280
+	 * @throws InvalidIdentifierException
281
+	 * @throws InvalidDataTypeException
282
+	 */
283
+	public function addClosure($identifier, $closure)
284
+	{
285
+		if (! is_callable($closure)) {
286
+			throw new InvalidDataTypeException('$closure', $closure, 'Closure');
287
+		}
288
+		$identifier = $this->processIdentifier($identifier);
289
+		if ($this->reservoir->add($closure, $identifier)) {
290
+			return $closure;
291
+		}
292
+		return null;
293
+	}
294
+
295
+
296
+	/**
297
+	 * @param string $identifier
298
+	 * @return boolean
299
+	 * @throws InvalidIdentifierException
300
+	 */
301
+	public function removeClosure($identifier)
302
+	{
303
+		$identifier = $this->processIdentifier($identifier);
304
+		if ($this->reservoir->has($identifier)) {
305
+			return $this->reservoir->remove($this->reservoir->get($identifier));
306
+		}
307
+		return false;
308
+	}
309
+
310
+
311
+	/**
312
+	 * @param  string $identifier Identifier for the entity class that the service applies to
313
+	 *                            Typically a Fully Qualified Class Name
314
+	 * @param mixed   $service
315
+	 * @return bool
316
+	 * @throws \EventEspresso\core\services\container\exceptions\InvalidServiceException
317
+	 * @throws InvalidIdentifierException
318
+	 */
319
+	public function addService($identifier, $service)
320
+	{
321
+		$identifier = $this->processIdentifier($identifier);
322
+		$service = $this->validateService($identifier, $service);
323
+		return $this->carafe->add($service, $identifier);
324
+	}
325
+
326
+
327
+	/**
328
+	 * @param string $identifier
329
+	 * @return boolean
330
+	 * @throws InvalidIdentifierException
331
+	 */
332
+	public function removeService($identifier)
333
+	{
334
+		$identifier = $this->processIdentifier($identifier);
335
+		if ($this->carafe->has($identifier)) {
336
+			return $this->carafe->remove($this->carafe->get($identifier));
337
+		}
338
+		return false;
339
+	}
340
+
341
+
342
+	/**
343
+	 * Adds instructions on how to brew objects
344
+	 *
345
+	 * @param RecipeInterface $recipe
346
+	 * @return mixed
347
+	 * @throws InvalidIdentifierException
348
+	 */
349
+	public function addRecipe(RecipeInterface $recipe)
350
+	{
351
+		$this->addAliases($recipe->identifier(), $recipe->filters());
352
+		$identifier = $this->processIdentifier($recipe->identifier());
353
+		return $this->recipes->add($recipe, $identifier);
354
+	}
355
+
356
+
357
+	/**
358
+	 * @param string $identifier The Recipe's identifier
359
+	 * @return boolean
360
+	 * @throws InvalidIdentifierException
361
+	 */
362
+	public function removeRecipe($identifier)
363
+	{
364
+		$identifier = $this->processIdentifier($identifier);
365
+		if ($this->recipes->has($identifier)) {
366
+			return $this->recipes->remove($this->recipes->get($identifier));
367
+		}
368
+		return false;
369
+	}
370
+
371
+
372
+	/**
373
+	 * Get instructions on how to brew objects
374
+	 *
375
+	 * @param  string $identifier Identifier for the entity class that the recipe applies to
376
+	 *                            Typically a Fully Qualified Class Name
377
+	 * @param string  $type
378
+	 * @return RecipeInterface
379
+	 * @throws OutOfBoundsException
380
+	 * @throws InvalidIdentifierException
381
+	 */
382
+	public function getRecipe($identifier, $type = '')
383
+	{
384
+		$identifier = $this->processIdentifier($identifier);
385
+		if ($this->recipes->has($identifier)) {
386
+			return $this->recipes->get($identifier);
387
+		}
388
+		$default_recipes = $this->getDefaultRecipes();
389
+		$matches = array();
390
+		foreach ($default_recipes as $wildcard => $default_recipe) {
391
+			// is the wildcard recipe prefix in the identifier ?
392
+			if (strpos($identifier, $wildcard) !== false) {
393
+				// track matches and use the number of wildcard characters matched for the key
394
+				$matches[ strlen($wildcard) ] = $default_recipe;
395
+			}
396
+		}
397
+		if (count($matches) > 0) {
398
+			// sort our recipes by the number of wildcard characters matched
399
+			ksort($matches);
400
+			// then grab the last recipe form the list, since it had the most matching characters
401
+			$match = array_pop($matches);
402
+			// since we are using a default recipe, we need to set it's identifier and fqcn
403
+			return $this->copyDefaultRecipe($match, $identifier, $type);
404
+		}
405
+		if ($this->recipes->has(Recipe::DEFAULT_ID)) {
406
+			// since we are using a default recipe, we need to set it's identifier and fqcn
407
+			return $this->copyDefaultRecipe($this->recipes->get(Recipe::DEFAULT_ID), $identifier, $type);
408
+		}
409
+		throw new OutOfBoundsException(
410
+			sprintf(
411
+				esc_html__('Could not brew coffee because no recipes were found for class "%1$s".', 'event_espresso'),
412
+				$identifier
413
+			)
414
+		);
415
+	}
416
+
417
+
418
+	/**
419
+	 * adds class name aliases to list of filters
420
+	 *
421
+	 * @param  string       $identifier Identifier for the entity class that the alias applies to
422
+	 *                                  Typically a Fully Qualified Class Name
423
+	 * @param  array|string $aliases
424
+	 * @return void
425
+	 * @throws InvalidIdentifierException
426
+	 */
427
+	public function addAliases($identifier, $aliases)
428
+	{
429
+		if (empty($aliases)) {
430
+			return;
431
+		}
432
+		$identifier = $this->processIdentifier($identifier);
433
+		foreach ((array) $aliases as $alias) {
434
+			$this->filters[ $this->processIdentifier($alias) ] = $identifier;
435
+		}
436
+	}
437
+
438
+
439
+	/**
440
+	 * Adds a service to one of the internal collections
441
+	 *
442
+	 * @param        $identifier
443
+	 * @param array  $arguments
444
+	 * @param string $type
445
+	 * @return mixed
446
+	 * @throws InvalidDataTypeException
447
+	 * @throws InvalidClassException
448
+	 * @throws OutOfBoundsException
449
+	 * @throws InvalidIdentifierException
450
+	 * @throws ServiceExistsException
451
+	 */
452
+	private function makeCoffee($identifier, $arguments = array(), $type = '')
453
+	{
454
+		if ((empty($type) || $type === CoffeeMaker::BREW_SHARED) && $this->has($identifier)) {
455
+			throw new ServiceExistsException($identifier);
456
+		}
457
+		$identifier = $this->filterIdentifier($identifier);
458
+		$recipe = $this->getRecipe($identifier, $type);
459
+		$type = ! empty($type) ? $type : $recipe->type();
460
+		$coffee_maker = $this->getCoffeeMaker($type);
461
+		return $coffee_maker->brew($recipe, $arguments);
462
+	}
463
+
464
+
465
+	/**
466
+	 * filters alias identifiers to find the real class name
467
+	 *
468
+	 * @param  string $identifier Identifier for the entity class that the filter applies to
469
+	 *                            Typically a Fully Qualified Class Name
470
+	 * @return string
471
+	 * @throws InvalidIdentifierException
472
+	 */
473
+	private function filterIdentifier($identifier)
474
+	{
475
+		$identifier = $this->processIdentifier($identifier);
476
+		return isset($this->filters[ $identifier ]) && ! empty($this->filters[ $identifier ])
477
+			? $this->filters[ $identifier ]
478
+			: $identifier;
479
+	}
480
+
481
+
482
+	/**
483
+	 * verifies and standardizes identifiers
484
+	 *
485
+	 * @param  string $identifier Identifier for the entity class
486
+	 *                            Typically a Fully Qualified Class Name
487
+	 * @return string
488
+	 * @throws InvalidIdentifierException
489
+	 */
490
+	private function processIdentifier($identifier)
491
+	{
492
+		if (! is_string($identifier)) {
493
+			throw new InvalidIdentifierException(
494
+				is_object($identifier) ? get_class($identifier) : gettype($identifier),
495
+				'\Fully\Qualified\ClassName'
496
+			);
497
+		}
498
+		return ltrim($identifier, '\\');
499
+	}
500
+
501
+
502
+	/**
503
+	 * @param string $type
504
+	 * @return CoffeeMakerInterface
505
+	 * @throws OutOfBoundsException
506
+	 * @throws InvalidDataTypeException
507
+	 * @throws InvalidClassException
508
+	 */
509
+	private function getCoffeeMaker($type)
510
+	{
511
+		if (! $this->coffee_makers->has($type)) {
512
+			throw new OutOfBoundsException(
513
+				esc_html__('The requested coffee maker is either missing or invalid.', 'event_espresso')
514
+			);
515
+		}
516
+		return $this->coffee_makers->get($type);
517
+	}
518
+
519
+
520
+	/**
521
+	 * Retrieves all recipes that use a wildcard "*" in their identifier
522
+	 * This allows recipes to be set up for handling
523
+	 * legacy classes that do not support PSR-4 autoloading.
524
+	 * for example:
525
+	 * using "EEM_*" for a recipe identifier would target all legacy models like EEM_Attendee
526
+	 *
527
+	 * @return array
528
+	 */
529
+	private function getDefaultRecipes()
530
+	{
531
+		$default_recipes = array();
532
+		$this->recipes->rewind();
533
+		while ($this->recipes->valid()) {
534
+			$identifier = $this->recipes->getInfo();
535
+			// does this recipe use a wildcard ? (but is NOT the global default)
536
+			if ($identifier !== Recipe::DEFAULT_ID && strpos($identifier, '*') !== false) {
537
+				// strip the wildcard and use identifier as key
538
+				$default_recipes[ str_replace('*', '', $identifier) ] = $this->recipes->current();
539
+			}
540
+			$this->recipes->next();
541
+		}
542
+		return $default_recipes;
543
+	}
544
+
545
+
546
+	/**
547
+	 * clones a default recipe and then copies details
548
+	 * from the incoming request to it so that it can be used
549
+	 *
550
+	 * @param RecipeInterface $default_recipe
551
+	 * @param string          $identifier
552
+	 * @param string          $type
553
+	 * @return RecipeInterface
554
+	 */
555
+	private function copyDefaultRecipe(RecipeInterface $default_recipe, $identifier, $type = '')
556
+	{
557
+		$recipe = clone $default_recipe;
558
+		if (! empty($type)) {
559
+			$recipe->setType($type);
560
+		}
561
+		// is this the base default recipe ?
562
+		if ($default_recipe->identifier() === Recipe::DEFAULT_ID) {
563
+			$recipe->setIdentifier($identifier);
564
+			$recipe->setFqcn($identifier);
565
+			return $recipe;
566
+		}
567
+		$recipe->setIdentifier($identifier);
568
+		foreach ($default_recipe->paths() as $path) {
569
+			$path = str_replace('*', $identifier, $path);
570
+			if (is_readable($path)) {
571
+				$recipe->setPaths($path);
572
+			}
573
+		}
574
+		$recipe->setFqcn($identifier);
575
+		return $recipe;
576
+	}
577
+
578
+
579
+	/**
580
+	 * @param  string $identifier Identifier for the entity class that the service applies to
581
+	 *                            Typically a Fully Qualified Class Name
582
+	 * @param mixed   $service
583
+	 * @return mixed
584
+	 * @throws InvalidServiceException
585
+	 */
586
+	private function validateService($identifier, $service)
587
+	{
588
+		if (! is_object($service)) {
589
+			throw new InvalidServiceException(
590
+				$identifier,
591
+				$service
592
+			);
593
+		}
594
+		return $service;
595
+	}
596 596
 }
Please login to merge, or discard this patch.
core/EE_Config.core.php 2 patches
Spacing   +117 added lines, -117 removed lines patch added patch discarded remove patch
@@ -147,7 +147,7 @@  discard block
 block discarded – undo
147 147
     public static function instance()
148 148
     {
149 149
         // check if class object is instantiated, and instantiated properly
150
-        if (! self::$_instance instanceof EE_Config) {
150
+        if ( ! self::$_instance instanceof EE_Config) {
151 151
             self::$_instance = new self();
152 152
         }
153 153
         return self::$_instance;
@@ -285,7 +285,7 @@  discard block
 block discarded – undo
285 285
                 $this
286 286
             );
287 287
             if (is_object($settings) && property_exists($this, $config)) {
288
-                $this->{$config} = apply_filters('FHEE__EE_Config___load_core_config__' . $config, $settings);
288
+                $this->{$config} = apply_filters('FHEE__EE_Config___load_core_config__'.$config, $settings);
289 289
                 // call configs populate method to ensure any defaults are set for empty values.
290 290
                 if (method_exists($settings, 'populate')) {
291 291
                     $this->{$config}->populate();
@@ -560,7 +560,7 @@  discard block
 block discarded – undo
560 560
                         break;
561 561
                     // TEST #2 : check that settings section exists
562 562
                     case 2:
563
-                        if (! isset($this->{$section})) {
563
+                        if ( ! isset($this->{$section})) {
564 564
                             if ($display_errors) {
565 565
                                 throw new EE_Error(
566 566
                                     sprintf(
@@ -621,7 +621,7 @@  discard block
 block discarded – undo
621 621
                         break;
622 622
                     // TEST #6 : verify config class is accessible
623 623
                     case 6:
624
-                        if (! class_exists($config_class)) {
624
+                        if ( ! class_exists($config_class)) {
625 625
                             if ($display_errors) {
626 626
                                 throw new EE_Error(
627 627
                                     sprintf(
@@ -638,7 +638,7 @@  discard block
 block discarded – undo
638 638
                         break;
639 639
                     // TEST #7 : check that config has even been set
640 640
                     case 7:
641
-                        if (! isset($this->{$section}->{$name})) {
641
+                        if ( ! isset($this->{$section}->{$name})) {
642 642
                             if ($display_errors) {
643 643
                                 throw new EE_Error(
644 644
                                     sprintf(
@@ -656,7 +656,7 @@  discard block
 block discarded – undo
656 656
                         break;
657 657
                     // TEST #8 : check that config is the requested type
658 658
                     case 8:
659
-                        if (! $this->{$section}->{$name} instanceof $config_class) {
659
+                        if ( ! $this->{$section}->{$name} instanceof $config_class) {
660 660
                             if ($display_errors) {
661 661
                                 throw new EE_Error(
662 662
                                     sprintf(
@@ -675,7 +675,7 @@  discard block
 block discarded – undo
675 675
                         break;
676 676
                     // TEST #9 : verify config object
677 677
                     case 9:
678
-                        if (! $config_obj instanceof EE_Config_Base) {
678
+                        if ( ! $config_obj instanceof EE_Config_Base) {
679 679
                             if ($display_errors) {
680 680
                                 throw new EE_Error(
681 681
                                     sprintf(
@@ -707,7 +707,7 @@  discard block
 block discarded – undo
707 707
      */
708 708
     private function _generate_config_option_name($section = '', $name = '')
709 709
     {
710
-        return 'ee_config-' . strtolower($section . '-' . str_replace(array('EE_', 'EED_'), '', $name));
710
+        return 'ee_config-'.strtolower($section.'-'.str_replace(array('EE_', 'EED_'), '', $name));
711 711
     }
712 712
 
713 713
 
@@ -724,7 +724,7 @@  discard block
 block discarded – undo
724 724
     {
725 725
         return ! empty($config_class)
726 726
             ? $config_class
727
-            : str_replace(' ', '_', ucwords(str_replace('_', ' ', $name))) . '_Config';
727
+            : str_replace(' ', '_', ucwords(str_replace('_', ' ', $name))).'_Config';
728 728
     }
729 729
 
730 730
 
@@ -743,17 +743,17 @@  discard block
 block discarded – undo
743 743
         // ensure config class is set to something
744 744
         $config_class = $this->_set_config_class($config_class, $name);
745 745
         // run tests 1-4, 6, and 7 to verify all config params are set and valid
746
-        if (! $this->_verify_config_params($section, $name, $config_class, null, array(1, 2, 3, 4, 5, 6))) {
746
+        if ( ! $this->_verify_config_params($section, $name, $config_class, null, array(1, 2, 3, 4, 5, 6))) {
747 747
             return null;
748 748
         }
749 749
         $config_option_name = $this->_generate_config_option_name($section, $name);
750 750
         // if the config option name hasn't been added yet to the list of option names we're tracking, then do so now
751
-        if (! isset($this->_addon_option_names[ $config_option_name ])) {
752
-            $this->_addon_option_names[ $config_option_name ] = $config_class;
751
+        if ( ! isset($this->_addon_option_names[$config_option_name])) {
752
+            $this->_addon_option_names[$config_option_name] = $config_class;
753 753
             $this->update_addon_option_names();
754 754
         }
755 755
         // verify the incoming config object but suppress errors
756
-        if (! $this->_verify_config_params($section, $name, $config_class, $config_obj, array(9), false)) {
756
+        if ( ! $this->_verify_config_params($section, $name, $config_class, $config_obj, array(9), false)) {
757 757
             $config_obj = new $config_class();
758 758
         }
759 759
         if (get_option($config_option_name)) {
@@ -815,7 +815,7 @@  discard block
 block discarded – undo
815 815
         }
816 816
         $config_option_name = $this->_generate_config_option_name($section, $name);
817 817
         // check if config object has been added to db by seeing if config option name is in $this->_addon_option_names array
818
-        if (! isset($this->_addon_option_names[ $config_option_name ])) {
818
+        if ( ! isset($this->_addon_option_names[$config_option_name])) {
819 819
             // save new config to db
820 820
             if ($this->set_config($section, $name, $config_class, $config_obj)) {
821 821
                 return true;
@@ -841,7 +841,7 @@  discard block
 block discarded – undo
841 841
                             'event_espresso'
842 842
                         ),
843 843
                         $config_class,
844
-                        'EE_Config->' . $section . '->' . $name
844
+                        'EE_Config->'.$section.'->'.$name
845 845
                     ),
846 846
                     __FILE__,
847 847
                     __FUNCTION__,
@@ -867,7 +867,7 @@  discard block
 block discarded – undo
867 867
         // ensure config class is set to something
868 868
         $config_class = $this->_set_config_class($config_class, $name);
869 869
         // run tests 1-4, 6 and 7 to verify that all params have been set
870
-        if (! $this->_verify_config_params($section, $name, $config_class, null, array(1, 2, 3, 4, 5, 6))) {
870
+        if ( ! $this->_verify_config_params($section, $name, $config_class, null, array(1, 2, 3, 4, 5, 6))) {
871 871
             return null;
872 872
         }
873 873
         // now test if the requested config object exists, but suppress errors
@@ -912,7 +912,7 @@  discard block
 block discarded – undo
912 912
         // retrieve the wp-option for this config class.
913 913
         $config_option = maybe_unserialize(get_option($config_option_name, array()));
914 914
         if (empty($config_option)) {
915
-            EE_Config::log($config_option_name . '-NOT-FOUND');
915
+            EE_Config::log($config_option_name.'-NOT-FOUND');
916 916
         }
917 917
         return $config_option;
918 918
     }
@@ -929,7 +929,7 @@  discard block
 block discarded – undo
929 929
             $config_log = get_option(EE_Config::LOG_NAME, array());
930 930
             /** @var RequestParams $request */
931 931
             $request = LoaderFactory::getLoader()->getShared(RequestParams::class);
932
-            $config_log[ (string) microtime(true) ] = array(
932
+            $config_log[(string) microtime(true)] = array(
933 933
                 'config_name' => $config_option_name,
934 934
                 'request'     => $request->requestParams(),
935 935
             );
@@ -944,7 +944,7 @@  discard block
 block discarded – undo
944 944
      */
945 945
     public static function trim_log()
946 946
     {
947
-        if (! EE_Config::logging_enabled()) {
947
+        if ( ! EE_Config::logging_enabled()) {
948 948
             return;
949 949
         }
950 950
         $config_log = maybe_unserialize(get_option(EE_Config::LOG_NAME, array()));
@@ -968,7 +968,7 @@  discard block
 block discarded – undo
968 968
     public static function get_page_for_posts()
969 969
     {
970 970
         $page_for_posts = get_option('page_for_posts');
971
-        if (! $page_for_posts) {
971
+        if ( ! $page_for_posts) {
972 972
             return 'posts';
973 973
         }
974 974
         global $wpdb;
@@ -1025,13 +1025,13 @@  discard block
 block discarded – undo
1025 1025
             )
1026 1026
         ) {
1027 1027
             // grab list of installed widgets
1028
-            $widgets_to_register = glob(EE_WIDGETS . '*', GLOB_ONLYDIR);
1028
+            $widgets_to_register = glob(EE_WIDGETS.'*', GLOB_ONLYDIR);
1029 1029
             // filter list of modules to register
1030 1030
             $widgets_to_register = apply_filters(
1031 1031
                 'FHEE__EE_Config__register_widgets__widgets_to_register',
1032 1032
                 $widgets_to_register
1033 1033
             );
1034
-            if (! empty($widgets_to_register)) {
1034
+            if ( ! empty($widgets_to_register)) {
1035 1035
                 // cycle thru widget folders
1036 1036
                 foreach ($widgets_to_register as $widget_path) {
1037 1037
                     // add to list of installed widget modules
@@ -1081,31 +1081,31 @@  discard block
 block discarded – undo
1081 1081
         // create classname from widget directory name
1082 1082
         $widget = str_replace(' ', '_', ucwords(str_replace('_', ' ', $widget)));
1083 1083
         // add class prefix
1084
-        $widget_class = 'EEW_' . $widget;
1084
+        $widget_class = 'EEW_'.$widget;
1085 1085
         // does the widget exist ?
1086
-        if (! is_readable($widget_path . '/' . $widget_class . $widget_ext)) {
1086
+        if ( ! is_readable($widget_path.'/'.$widget_class.$widget_ext)) {
1087 1087
             $msg = sprintf(
1088 1088
                 esc_html__(
1089 1089
                     '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',
1090 1090
                     'event_espresso'
1091 1091
                 ),
1092 1092
                 $widget_class,
1093
-                $widget_path . '/' . $widget_class . $widget_ext
1093
+                $widget_path.'/'.$widget_class.$widget_ext
1094 1094
             );
1095
-            EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__);
1095
+            EE_Error::add_error($msg.'||'.$msg, __FILE__, __FUNCTION__, __LINE__);
1096 1096
             return;
1097 1097
         }
1098 1098
         // load the widget class file
1099
-        require_once($widget_path . '/' . $widget_class . $widget_ext);
1099
+        require_once($widget_path.'/'.$widget_class.$widget_ext);
1100 1100
         // verify that class exists
1101
-        if (! class_exists($widget_class)) {
1101
+        if ( ! class_exists($widget_class)) {
1102 1102
             $msg = sprintf(esc_html__('The requested %s widget class does not exist.', 'event_espresso'), $widget_class);
1103
-            EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__);
1103
+            EE_Error::add_error($msg.'||'.$msg, __FILE__, __FUNCTION__, __LINE__);
1104 1104
             return;
1105 1105
         }
1106 1106
         register_widget($widget_class);
1107 1107
         // add to array of registered widgets
1108
-        EE_Registry::instance()->widgets->{$widget_class} = $widget_path . '/' . $widget_class . $widget_ext;
1108
+        EE_Registry::instance()->widgets->{$widget_class} = $widget_path.'/'.$widget_class.$widget_ext;
1109 1109
     }
1110 1110
 
1111 1111
 
@@ -1118,19 +1118,19 @@  discard block
 block discarded – undo
1118 1118
     private function _register_modules()
1119 1119
     {
1120 1120
         // grab list of installed modules
1121
-        $modules_to_register = glob(EE_MODULES . '*', GLOB_ONLYDIR);
1121
+        $modules_to_register = glob(EE_MODULES.'*', GLOB_ONLYDIR);
1122 1122
         // filter list of modules to register
1123 1123
         $modules_to_register = apply_filters(
1124 1124
             'FHEE__EE_Config__register_modules__modules_to_register',
1125 1125
             $modules_to_register
1126 1126
         );
1127
-        if (! empty($modules_to_register)) {
1127
+        if ( ! empty($modules_to_register)) {
1128 1128
             // loop through folders
1129 1129
             foreach ($modules_to_register as $module_path) {
1130 1130
                 /**TEMPORARILY EXCLUDE gateways from modules for time being**/
1131 1131
                 if (
1132
-                    $module_path !== EE_MODULES . 'zzz-copy-this-module-template'
1133
-                    && $module_path !== EE_MODULES . 'gateways'
1132
+                    $module_path !== EE_MODULES.'zzz-copy-this-module-template'
1133
+                    && $module_path !== EE_MODULES.'gateways'
1134 1134
                 ) {
1135 1135
                     // add to list of installed modules
1136 1136
                     EE_Config::register_module($module_path);
@@ -1167,25 +1167,25 @@  discard block
 block discarded – undo
1167 1167
             // remove last segment
1168 1168
             array_pop($module_path);
1169 1169
             // glue it back together
1170
-            $module_path = implode('/', $module_path) . '/';
1170
+            $module_path = implode('/', $module_path).'/';
1171 1171
             // take first segment from file name pieces and sanitize it
1172 1172
             $module = preg_replace('/[^a-zA-Z0-9_\-]/', '', $module_file[0]);
1173 1173
             // ensure class prefix is added
1174
-            $module_class = strpos($module, 'EED_') !== 0 ? 'EED_' . $module : $module;
1174
+            $module_class = strpos($module, 'EED_') !== 0 ? 'EED_'.$module : $module;
1175 1175
         } else {
1176 1176
             // we need to generate the filename based off of the folder name
1177 1177
             // grab and sanitize module name
1178 1178
             $module = strtolower(basename($module_path));
1179 1179
             $module = preg_replace('/[^a-z0-9_\-]/', '', $module);
1180 1180
             // like trailingslashit()
1181
-            $module_path = rtrim($module_path, '/') . '/';
1181
+            $module_path = rtrim($module_path, '/').'/';
1182 1182
             // create classname from module directory name
1183 1183
             $module = str_replace(' ', '_', ucwords(str_replace('_', ' ', $module)));
1184 1184
             // add class prefix
1185
-            $module_class = 'EED_' . $module;
1185
+            $module_class = 'EED_'.$module;
1186 1186
         }
1187 1187
         // does the module exist ?
1188
-        if (! is_readable($module_path . '/' . $module_class . $module_ext)) {
1188
+        if ( ! is_readable($module_path.'/'.$module_class.$module_ext)) {
1189 1189
             $msg = sprintf(
1190 1190
                 esc_html__(
1191 1191
                     'The requested %s module file could not be found or is not readable due to file permissions.',
@@ -1193,19 +1193,19 @@  discard block
 block discarded – undo
1193 1193
                 ),
1194 1194
                 $module
1195 1195
             );
1196
-            EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__);
1196
+            EE_Error::add_error($msg.'||'.$msg, __FILE__, __FUNCTION__, __LINE__);
1197 1197
             return false;
1198 1198
         }
1199 1199
         // load the module class file
1200
-        require_once($module_path . $module_class . $module_ext);
1200
+        require_once($module_path.$module_class.$module_ext);
1201 1201
         // verify that class exists
1202
-        if (! class_exists($module_class)) {
1202
+        if ( ! class_exists($module_class)) {
1203 1203
             $msg = sprintf(esc_html__('The requested %s module class does not exist.', 'event_espresso'), $module_class);
1204
-            EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__);
1204
+            EE_Error::add_error($msg.'||'.$msg, __FILE__, __FUNCTION__, __LINE__);
1205 1205
             return false;
1206 1206
         }
1207 1207
         // add to array of registered modules
1208
-        EE_Registry::instance()->modules->{$module_class} = $module_path . $module_class . $module_ext;
1208
+        EE_Registry::instance()->modules->{$module_class} = $module_path.$module_class.$module_ext;
1209 1209
         do_action(
1210 1210
             'AHEE__EE_Config__register_module__complete',
1211 1211
             $module_class,
@@ -1256,26 +1256,26 @@  discard block
 block discarded – undo
1256 1256
     {
1257 1257
         do_action('AHEE__EE_Config__register_route__begin', $route, $module, $method_name);
1258 1258
         $module = str_replace('EED_', '', $module);
1259
-        $module_class = 'EED_' . $module;
1260
-        if (! isset(EE_Registry::instance()->modules->{$module_class})) {
1259
+        $module_class = 'EED_'.$module;
1260
+        if ( ! isset(EE_Registry::instance()->modules->{$module_class})) {
1261 1261
             $msg = sprintf(esc_html__('The module %s has not been registered.', 'event_espresso'), $module);
1262
-            EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__);
1262
+            EE_Error::add_error($msg.'||'.$msg, __FILE__, __FUNCTION__, __LINE__);
1263 1263
             return false;
1264 1264
         }
1265 1265
         if (empty($route)) {
1266 1266
             $msg = sprintf(esc_html__('No route has been supplied.', 'event_espresso'), $route);
1267
-            EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__);
1267
+            EE_Error::add_error($msg.'||'.$msg, __FILE__, __FUNCTION__, __LINE__);
1268 1268
             return false;
1269 1269
         }
1270
-        if (! method_exists('EED_' . $module, $method_name)) {
1270
+        if ( ! method_exists('EED_'.$module, $method_name)) {
1271 1271
             $msg = sprintf(
1272 1272
                 esc_html__('A valid class method for the %s route has not been supplied.', 'event_espresso'),
1273 1273
                 $route
1274 1274
             );
1275
-            EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__);
1275
+            EE_Error::add_error($msg.'||'.$msg, __FILE__, __FUNCTION__, __LINE__);
1276 1276
             return false;
1277 1277
         }
1278
-        EE_Config::$_module_route_map[ (string) $key ][ (string) $route ] = array('EED_' . $module, $method_name);
1278
+        EE_Config::$_module_route_map[(string) $key][(string) $route] = array('EED_'.$module, $method_name);
1279 1279
         return true;
1280 1280
     }
1281 1281
 
@@ -1292,8 +1292,8 @@  discard block
 block discarded – undo
1292 1292
     {
1293 1293
         do_action('AHEE__EE_Config__get_route__begin', $route);
1294 1294
         $route = (string) apply_filters('FHEE__EE_Config__get_route', $route);
1295
-        if (isset(EE_Config::$_module_route_map[ $key ][ $route ])) {
1296
-            return EE_Config::$_module_route_map[ $key ][ $route ];
1295
+        if (isset(EE_Config::$_module_route_map[$key][$route])) {
1296
+            return EE_Config::$_module_route_map[$key][$route];
1297 1297
         }
1298 1298
         return null;
1299 1299
     }
@@ -1325,47 +1325,47 @@  discard block
 block discarded – undo
1325 1325
     public static function register_forward($route = null, $status = 0, $forward = null, $key = 'ee')
1326 1326
     {
1327 1327
         do_action('AHEE__EE_Config__register_forward', $route, $status, $forward);
1328
-        if (! isset(EE_Config::$_module_route_map[ $key ][ $route ]) || empty($route)) {
1328
+        if ( ! isset(EE_Config::$_module_route_map[$key][$route]) || empty($route)) {
1329 1329
             $msg = sprintf(
1330 1330
                 esc_html__('The module route %s for this forward has not been registered.', 'event_espresso'),
1331 1331
                 $route
1332 1332
             );
1333
-            EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__);
1333
+            EE_Error::add_error($msg.'||'.$msg, __FILE__, __FUNCTION__, __LINE__);
1334 1334
             return false;
1335 1335
         }
1336 1336
         if (empty($forward)) {
1337 1337
             $msg = sprintf(esc_html__('No forwarding route has been supplied.', 'event_espresso'), $route);
1338
-            EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__);
1338
+            EE_Error::add_error($msg.'||'.$msg, __FILE__, __FUNCTION__, __LINE__);
1339 1339
             return false;
1340 1340
         }
1341 1341
         if (is_array($forward)) {
1342
-            if (! isset($forward[1])) {
1342
+            if ( ! isset($forward[1])) {
1343 1343
                 $msg = sprintf(
1344 1344
                     esc_html__('A class method for the %s forwarding route has not been supplied.', 'event_espresso'),
1345 1345
                     $route
1346 1346
                 );
1347
-                EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__);
1347
+                EE_Error::add_error($msg.'||'.$msg, __FILE__, __FUNCTION__, __LINE__);
1348 1348
                 return false;
1349 1349
             }
1350
-            if (! method_exists($forward[0], $forward[1])) {
1350
+            if ( ! method_exists($forward[0], $forward[1])) {
1351 1351
                 $msg = sprintf(
1352 1352
                     esc_html__('The class method %s for the %s forwarding route is in invalid.', 'event_espresso'),
1353 1353
                     $forward[1],
1354 1354
                     $route
1355 1355
                 );
1356
-                EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__);
1356
+                EE_Error::add_error($msg.'||'.$msg, __FILE__, __FUNCTION__, __LINE__);
1357 1357
                 return false;
1358 1358
             }
1359
-        } elseif (! function_exists($forward)) {
1359
+        } elseif ( ! function_exists($forward)) {
1360 1360
             $msg = sprintf(
1361 1361
                 esc_html__('The function %s for the %s forwarding route is in invalid.', 'event_espresso'),
1362 1362
                 $forward,
1363 1363
                 $route
1364 1364
             );
1365
-            EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__);
1365
+            EE_Error::add_error($msg.'||'.$msg, __FILE__, __FUNCTION__, __LINE__);
1366 1366
             return false;
1367 1367
         }
1368
-        EE_Config::$_module_forward_map[ $key ][ $route ][ absint($status) ] = $forward;
1368
+        EE_Config::$_module_forward_map[$key][$route][absint($status)] = $forward;
1369 1369
         return true;
1370 1370
     }
1371 1371
 
@@ -1383,10 +1383,10 @@  discard block
 block discarded – undo
1383 1383
     public static function get_forward($route = null, $status = 0, $key = 'ee')
1384 1384
     {
1385 1385
         do_action('AHEE__EE_Config__get_forward__begin', $route, $status);
1386
-        if (isset(EE_Config::$_module_forward_map[ $key ][ $route ][ $status ])) {
1386
+        if (isset(EE_Config::$_module_forward_map[$key][$route][$status])) {
1387 1387
             return apply_filters(
1388 1388
                 'FHEE__EE_Config__get_forward',
1389
-                EE_Config::$_module_forward_map[ $key ][ $route ][ $status ],
1389
+                EE_Config::$_module_forward_map[$key][$route][$status],
1390 1390
                 $route,
1391 1391
                 $status
1392 1392
             );
@@ -1410,15 +1410,15 @@  discard block
 block discarded – undo
1410 1410
     public static function register_view($route = null, $status = 0, $view = null, $key = 'ee')
1411 1411
     {
1412 1412
         do_action('AHEE__EE_Config__register_view__begin', $route, $status, $view);
1413
-        if (! isset(EE_Config::$_module_route_map[ $key ][ $route ]) || empty($route)) {
1413
+        if ( ! isset(EE_Config::$_module_route_map[$key][$route]) || empty($route)) {
1414 1414
             $msg = sprintf(
1415 1415
                 esc_html__('The module route %s for this view has not been registered.', 'event_espresso'),
1416 1416
                 $route
1417 1417
             );
1418
-            EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__);
1418
+            EE_Error::add_error($msg.'||'.$msg, __FILE__, __FUNCTION__, __LINE__);
1419 1419
             return false;
1420 1420
         }
1421
-        if (! is_readable($view)) {
1421
+        if ( ! is_readable($view)) {
1422 1422
             $msg = sprintf(
1423 1423
                 esc_html__(
1424 1424
                     'The %s view file could not be found or is not readable due to file permissions.',
@@ -1426,10 +1426,10 @@  discard block
 block discarded – undo
1426 1426
                 ),
1427 1427
                 $view
1428 1428
             );
1429
-            EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__);
1429
+            EE_Error::add_error($msg.'||'.$msg, __FILE__, __FUNCTION__, __LINE__);
1430 1430
             return false;
1431 1431
         }
1432
-        EE_Config::$_module_view_map[ $key ][ $route ][ absint($status) ] = $view;
1432
+        EE_Config::$_module_view_map[$key][$route][absint($status)] = $view;
1433 1433
         return true;
1434 1434
     }
1435 1435
 
@@ -1447,10 +1447,10 @@  discard block
 block discarded – undo
1447 1447
     public static function get_view($route = null, $status = 0, $key = 'ee')
1448 1448
     {
1449 1449
         do_action('AHEE__EE_Config__get_view__begin', $route, $status);
1450
-        if (isset(EE_Config::$_module_view_map[ $key ][ $route ][ $status ])) {
1450
+        if (isset(EE_Config::$_module_view_map[$key][$route][$status])) {
1451 1451
             return apply_filters(
1452 1452
                 'FHEE__EE_Config__get_view',
1453
-                EE_Config::$_module_view_map[ $key ][ $route ][ $status ],
1453
+                EE_Config::$_module_view_map[$key][$route][$status],
1454 1454
                 $route,
1455 1455
                 $status
1456 1456
             );
@@ -1476,7 +1476,7 @@  discard block
 block discarded – undo
1476 1476
      */
1477 1477
     public static function getLegacyShortcodesManager()
1478 1478
     {
1479
-        if (! EE_Config::instance()->legacy_shortcodes_manager instanceof LegacyShortcodesManager) {
1479
+        if ( ! EE_Config::instance()->legacy_shortcodes_manager instanceof LegacyShortcodesManager) {
1480 1480
             EE_Config::instance()->legacy_shortcodes_manager = LoaderFactory::getLoader()->getShared(
1481 1481
                 LegacyShortcodesManager::class
1482 1482
             );
@@ -1523,7 +1523,7 @@  discard block
 block discarded – undo
1523 1523
      */
1524 1524
     public function get_pretty($property)
1525 1525
     {
1526
-        if (! property_exists($this, $property)) {
1526
+        if ( ! property_exists($this, $property)) {
1527 1527
             throw new EE_Error(
1528 1528
                 sprintf(
1529 1529
                     esc_html__(
@@ -1752,11 +1752,11 @@  discard block
 block discarded – undo
1752 1752
      */
1753 1753
     public function reg_page_url()
1754 1754
     {
1755
-        if (! $this->reg_page_url) {
1755
+        if ( ! $this->reg_page_url) {
1756 1756
             $this->reg_page_url = add_query_arg(
1757 1757
                 array('uts' => time()),
1758 1758
                 get_permalink($this->reg_page_id)
1759
-            ) . '#checkout';
1759
+            ).'#checkout';
1760 1760
         }
1761 1761
         return $this->reg_page_url;
1762 1762
     }
@@ -1772,7 +1772,7 @@  discard block
 block discarded – undo
1772 1772
      */
1773 1773
     public function txn_page_url($query_args = array())
1774 1774
     {
1775
-        if (! $this->txn_page_url) {
1775
+        if ( ! $this->txn_page_url) {
1776 1776
             $this->txn_page_url = get_permalink($this->txn_page_id);
1777 1777
         }
1778 1778
         if ($query_args) {
@@ -1793,7 +1793,7 @@  discard block
 block discarded – undo
1793 1793
      */
1794 1794
     public function thank_you_page_url($query_args = array())
1795 1795
     {
1796
-        if (! $this->thank_you_page_url) {
1796
+        if ( ! $this->thank_you_page_url) {
1797 1797
             $this->thank_you_page_url = get_permalink($this->thank_you_page_id);
1798 1798
         }
1799 1799
         if ($query_args) {
@@ -1812,7 +1812,7 @@  discard block
 block discarded – undo
1812 1812
      */
1813 1813
     public function cancel_page_url()
1814 1814
     {
1815
-        if (! $this->cancel_page_url) {
1815
+        if ( ! $this->cancel_page_url) {
1816 1816
             $this->cancel_page_url = get_permalink($this->cancel_page_id);
1817 1817
         }
1818 1818
         return $this->cancel_page_url;
@@ -1855,13 +1855,13 @@  discard block
 block discarded – undo
1855 1855
         $current_main_site_id = ! empty($current_network_main_site) ? $current_network_main_site->blog_id : 1;
1856 1856
         $option = self::OPTION_NAME_UXIP;
1857 1857
         // set correct table for query
1858
-        $table_name = $wpdb->get_blog_prefix($current_main_site_id) . 'options';
1858
+        $table_name = $wpdb->get_blog_prefix($current_main_site_id).'options';
1859 1859
         // rather than getting blog option for the $current_main_site_id, we do a direct $wpdb query because
1860 1860
         // get_blog_option() does a switch_to_blog an that could cause infinite recursion because EE_Core_Config might be
1861 1861
         // re-constructed on the blog switch.  Note, we are still executing any core wp filters on this option retrieval.
1862 1862
         // this bit of code is basically a direct copy of get_option without any caching because we are NOT switched to the blog
1863 1863
         // for the purpose of caching.
1864
-        $pre = apply_filters('pre_option_' . $option, false, $option);
1864
+        $pre = apply_filters('pre_option_'.$option, false, $option);
1865 1865
         if (false !== $pre) {
1866 1866
             EE_Core_Config::$ee_ueip_option = $pre;
1867 1867
             return EE_Core_Config::$ee_ueip_option;
@@ -1875,10 +1875,10 @@  discard block
 block discarded – undo
1875 1875
         if (is_object($row)) {
1876 1876
             $value = $row->option_value;
1877 1877
         } else { // option does not exist so use default.
1878
-            EE_Core_Config::$ee_ueip_option =  apply_filters('default_option_' . $option, false, $option);
1878
+            EE_Core_Config::$ee_ueip_option = apply_filters('default_option_'.$option, false, $option);
1879 1879
             return EE_Core_Config::$ee_ueip_option;
1880 1880
         }
1881
-        EE_Core_Config::$ee_ueip_option = apply_filters('option_' . $option, maybe_unserialize($value), $option);
1881
+        EE_Core_Config::$ee_ueip_option = apply_filters('option_'.$option, maybe_unserialize($value), $option);
1882 1882
         return EE_Core_Config::$ee_ueip_option;
1883 1883
     }
1884 1884
 
@@ -2140,30 +2140,30 @@  discard block
 block discarded – undo
2140 2140
             // retrieve the country settings from the db, just in case they have been customized
2141 2141
             $country = EE_Registry::instance()->load_model('Country')->get_one_by_ID($CNT_ISO);
2142 2142
             if ($country instanceof EE_Country) {
2143
-                $this->code = $country->currency_code();    // currency code: USD, CAD, EUR
2144
-                $this->name = $country->currency_name_single();    // Dollar
2145
-                $this->plural = $country->currency_name_plural();    // Dollars
2146
-                $this->sign = $country->currency_sign();            // currency sign: $
2143
+                $this->code = $country->currency_code(); // currency code: USD, CAD, EUR
2144
+                $this->name = $country->currency_name_single(); // Dollar
2145
+                $this->plural = $country->currency_name_plural(); // Dollars
2146
+                $this->sign = $country->currency_sign(); // currency sign: $
2147 2147
                 $this->sign_b4 = $country->currency_sign_before(
2148
-                );        // currency sign before or after: $TRUE  or  FALSE$
2149
-                $this->dec_plc = $country->currency_decimal_places();    // decimal places: 2 = 0.00  3 = 0.000
2148
+                ); // currency sign before or after: $TRUE  or  FALSE$
2149
+                $this->dec_plc = $country->currency_decimal_places(); // decimal places: 2 = 0.00  3 = 0.000
2150 2150
                 $this->dec_mrk = $country->currency_decimal_mark(
2151
-                );    // decimal mark: (comma) ',' = 0,01   or (decimal) '.' = 0.01
2151
+                ); // decimal mark: (comma) ',' = 0,01   or (decimal) '.' = 0.01
2152 2152
                 $this->thsnds = $country->currency_thousands_separator(
2153
-                );    // thousands separator: (comma) ',' = 1,000   or (decimal) '.' = 1.000
2153
+                ); // thousands separator: (comma) ',' = 1,000   or (decimal) '.' = 1.000
2154 2154
             }
2155 2155
         }
2156 2156
         // fallback to hardcoded defaults, in case the above failed
2157 2157
         if (empty($this->code)) {
2158 2158
             // set default currency settings
2159
-            $this->code = 'USD';    // currency code: USD, CAD, EUR
2160
-            $this->name = esc_html__('Dollar', 'event_espresso');    // Dollar
2161
-            $this->plural = esc_html__('Dollars', 'event_espresso');    // Dollars
2162
-            $this->sign = '$';    // currency sign: $
2163
-            $this->sign_b4 = true;    // currency sign before or after: $TRUE  or  FALSE$
2164
-            $this->dec_plc = 2;    // decimal places: 2 = 0.00  3 = 0.000
2165
-            $this->dec_mrk = '.';    // decimal mark: (comma) ',' = 0,01   or (decimal) '.' = 0.01
2166
-            $this->thsnds = ',';    // thousands separator: (comma) ',' = 1,000   or (decimal) '.' = 1.000
2159
+            $this->code = 'USD'; // currency code: USD, CAD, EUR
2160
+            $this->name = esc_html__('Dollar', 'event_espresso'); // Dollar
2161
+            $this->plural = esc_html__('Dollars', 'event_espresso'); // Dollars
2162
+            $this->sign = '$'; // currency sign: $
2163
+            $this->sign_b4 = true; // currency sign before or after: $TRUE  or  FALSE$
2164
+            $this->dec_plc = 2; // decimal places: 2 = 0.00  3 = 0.000
2165
+            $this->dec_mrk = '.'; // decimal mark: (comma) ',' = 0,01   or (decimal) '.' = 0.01
2166
+            $this->thsnds = ','; // thousands separator: (comma) ',' = 1,000   or (decimal) '.' = 1.000
2167 2167
         }
2168 2168
     }
2169 2169
 }
@@ -2432,8 +2432,8 @@  discard block
 block discarded – undo
2432 2432
             $closing_a_tag = '';
2433 2433
             if (function_exists('get_privacy_policy_url')) {
2434 2434
                 $privacy_page_url = get_privacy_policy_url();
2435
-                if (! empty($privacy_page_url)) {
2436
-                    $opening_a_tag = '<a href="' . $privacy_page_url . '" target="_blank">';
2435
+                if ( ! empty($privacy_page_url)) {
2436
+                    $opening_a_tag = '<a href="'.$privacy_page_url.'" target="_blank">';
2437 2437
                     $closing_a_tag = '</a>';
2438 2438
                 }
2439 2439
             }
@@ -2662,7 +2662,7 @@  discard block
 block discarded – undo
2662 2662
     public function log_file_name($reset = false)
2663 2663
     {
2664 2664
         if (empty($this->log_file_name) || $reset) {
2665
-            $this->log_file_name = sanitize_key('espresso_log_' . md5(uniqid('', true))) . '.txt';
2665
+            $this->log_file_name = sanitize_key('espresso_log_'.md5(uniqid('', true))).'.txt';
2666 2666
             EE_Config::instance()->update_espresso_config(false, false);
2667 2667
         }
2668 2668
         return $this->log_file_name;
@@ -2676,7 +2676,7 @@  discard block
 block discarded – undo
2676 2676
     public function debug_file_name($reset = false)
2677 2677
     {
2678 2678
         if (empty($this->debug_file_name) || $reset) {
2679
-            $this->debug_file_name = sanitize_key('espresso_debug_' . md5(uniqid('', true))) . '.txt';
2679
+            $this->debug_file_name = sanitize_key('espresso_debug_'.md5(uniqid('', true))).'.txt';
2680 2680
             EE_Config::instance()->update_espresso_config(false, false);
2681 2681
         }
2682 2682
         return $this->debug_file_name;
@@ -2880,21 +2880,21 @@  discard block
 block discarded – undo
2880 2880
         $this->use_google_maps = true;
2881 2881
         $this->google_map_api_key = '';
2882 2882
         // for event details pages (reg page)
2883
-        $this->event_details_map_width = 585;            // ee_map_width_single
2884
-        $this->event_details_map_height = 362;            // ee_map_height_single
2885
-        $this->event_details_map_zoom = 14;            // ee_map_zoom_single
2886
-        $this->event_details_display_nav = true;            // ee_map_nav_display_single
2887
-        $this->event_details_nav_size = false;            // ee_map_nav_size_single
2888
-        $this->event_details_control_type = 'default';        // ee_map_type_control_single
2889
-        $this->event_details_map_align = 'center';            // ee_map_align_single
2883
+        $this->event_details_map_width = 585; // ee_map_width_single
2884
+        $this->event_details_map_height = 362; // ee_map_height_single
2885
+        $this->event_details_map_zoom = 14; // ee_map_zoom_single
2886
+        $this->event_details_display_nav = true; // ee_map_nav_display_single
2887
+        $this->event_details_nav_size = false; // ee_map_nav_size_single
2888
+        $this->event_details_control_type = 'default'; // ee_map_type_control_single
2889
+        $this->event_details_map_align = 'center'; // ee_map_align_single
2890 2890
         // for event list pages
2891
-        $this->event_list_map_width = 300;            // ee_map_width
2892
-        $this->event_list_map_height = 185;        // ee_map_height
2893
-        $this->event_list_map_zoom = 12;            // ee_map_zoom
2894
-        $this->event_list_display_nav = false;        // ee_map_nav_display
2895
-        $this->event_list_nav_size = true;            // ee_map_nav_size
2896
-        $this->event_list_control_type = 'dropdown';        // ee_map_type_control
2897
-        $this->event_list_map_align = 'center';            // ee_map_align
2891
+        $this->event_list_map_width = 300; // ee_map_width
2892
+        $this->event_list_map_height = 185; // ee_map_height
2893
+        $this->event_list_map_zoom = 12; // ee_map_zoom
2894
+        $this->event_list_display_nav = false; // ee_map_nav_display
2895
+        $this->event_list_nav_size = true; // ee_map_nav_size
2896
+        $this->event_list_control_type = 'dropdown'; // ee_map_type_control
2897
+        $this->event_list_map_align = 'center'; // ee_map_align
2898 2898
     }
2899 2899
 }
2900 2900
 
Please login to merge, or discard this patch.
Indentation   +3177 added lines, -3177 removed lines patch added patch discarded remove patch
@@ -18,2538 +18,2538 @@  discard block
 block discarded – undo
18 18
  */
19 19
 final class EE_Config implements ResettableInterface
20 20
 {
21
-    const OPTION_NAME = 'ee_config';
22
-
23
-    const LOG_NAME = 'ee_config_log';
24
-
25
-    const LOG_LENGTH = 100;
26
-
27
-    const ADDON_OPTION_NAMES = 'ee_config_option_names';
28
-
29
-    /**
30
-     *    instance of the EE_Config object
31
-     *
32
-     * @var    EE_Config $_instance
33
-     * @access    private
34
-     */
35
-    private static $_instance;
36
-
37
-    /**
38
-     * @var boolean $_logging_enabled
39
-     */
40
-    private static $_logging_enabled = false;
41
-
42
-    /**
43
-     * @var LegacyShortcodesManager $legacy_shortcodes_manager
44
-     */
45
-    private $legacy_shortcodes_manager;
46
-
47
-    /**
48
-     * An StdClass whose property names are addon slugs,
49
-     * and values are their config classes
50
-     *
51
-     * @var StdClass
52
-     */
53
-    public $addons;
54
-
55
-    /**
56
-     * @var EE_Admin_Config
57
-     */
58
-    public $admin;
59
-
60
-    /**
61
-     * @var EE_Core_Config
62
-     */
63
-    public $core;
64
-
65
-    /**
66
-     * @var EE_Currency_Config
67
-     */
68
-    public $currency;
69
-
70
-    /**
71
-     * @var EE_Organization_Config
72
-     */
73
-    public $organization;
74
-
75
-    /**
76
-     * @var EE_Registration_Config
77
-     */
78
-    public $registration;
79
-
80
-    /**
81
-     * @var EE_Template_Config
82
-     */
83
-    public $template_settings;
84
-
85
-    /**
86
-     * Holds EE environment values.
87
-     *
88
-     * @var EE_Environment_Config
89
-     */
90
-    public $environment;
91
-
92
-    /**
93
-     * settings pertaining to Google maps
94
-     *
95
-     * @var EE_Map_Config
96
-     */
97
-    public $map_settings;
98
-
99
-    /**
100
-     * settings pertaining to Taxes
101
-     *
102
-     * @var EE_Tax_Config
103
-     */
104
-    public $tax_settings;
105
-
106
-    /**
107
-     * Settings pertaining to global messages settings.
108
-     *
109
-     * @var EE_Messages_Config
110
-     */
111
-    public $messages;
112
-
113
-    /**
114
-     * @deprecated
115
-     * @var EE_Gateway_Config
116
-     */
117
-    public $gateway;
118
-
119
-    /**
120
-     * @var    array $_addon_option_names
121
-     * @access    private
122
-     */
123
-    private $_addon_option_names = array();
124
-
125
-    /**
126
-     * @var    array $_module_route_map
127
-     * @access    private
128
-     */
129
-    private static $_module_route_map = array();
130
-
131
-    /**
132
-     * @var    array $_module_forward_map
133
-     * @access    private
134
-     */
135
-    private static $_module_forward_map = array();
136
-
137
-    /**
138
-     * @var    array $_module_view_map
139
-     * @access    private
140
-     */
141
-    private static $_module_view_map = array();
142
-
143
-
144
-    /**
145
-     * @singleton method used to instantiate class object
146
-     * @access    public
147
-     * @return EE_Config instance
148
-     */
149
-    public static function instance()
150
-    {
151
-        // check if class object is instantiated, and instantiated properly
152
-        if (! self::$_instance instanceof EE_Config) {
153
-            self::$_instance = new self();
154
-        }
155
-        return self::$_instance;
156
-    }
157
-
158
-
159
-    /**
160
-     * Resets the config
161
-     *
162
-     * @param bool    $hard_reset    if TRUE, sets EE_CONFig back to its original settings in the database. If FALSE
163
-     *                               (default) leaves the database alone, and merely resets the EE_Config object to
164
-     *                               reflect its state in the database
165
-     * @param boolean $reinstantiate if TRUE (default) call instance() and return it. Otherwise, just leave
166
-     *                               $_instance as NULL. Useful in case you want to forget about the old instance on
167
-     *                               EE_Config, but might not be ready to instantiate EE_Config currently (eg if the
168
-     *                               site was put into maintenance mode)
169
-     * @return EE_Config
170
-     */
171
-    public static function reset($hard_reset = false, $reinstantiate = true)
172
-    {
173
-        if (self::$_instance instanceof EE_Config) {
174
-            if ($hard_reset) {
175
-                self::$_instance->legacy_shortcodes_manager = null;
176
-                self::$_instance->_addon_option_names = array();
177
-                self::$_instance->_initialize_config();
178
-                self::$_instance->update_espresso_config();
179
-            }
180
-            self::$_instance->update_addon_option_names();
181
-        }
182
-        self::$_instance = null;
183
-        // we don't need to reset the static properties imo because those should
184
-        // only change when a module is added or removed. Currently we don't
185
-        // support removing a module during a request when it previously existed
186
-        if ($reinstantiate) {
187
-            return self::instance();
188
-        } else {
189
-            return null;
190
-        }
191
-    }
192
-
193
-
194
-    /**
195
-     *    class constructor
196
-     *
197
-     * @access    private
198
-     */
199
-    private function __construct()
200
-    {
201
-        do_action('AHEE__EE_Config__construct__begin', $this);
202
-        EE_Config::$_logging_enabled = apply_filters('FHEE__EE_Config___construct__logging_enabled', false);
203
-        // setup empty config classes
204
-        $this->_initialize_config();
205
-        // load existing EE site settings
206
-        $this->_load_core_config();
207
-        // confirm everything loaded correctly and set filtered defaults if not
208
-        $this->_verify_config();
209
-        //  register shortcodes and modules
210
-        add_action(
211
-            'AHEE__EE_System__register_shortcodes_modules_and_widgets',
212
-            array($this, 'register_shortcodes_and_modules'),
213
-            999
214
-        );
215
-        //  initialize shortcodes and modules
216
-        add_action('AHEE__EE_System__core_loaded_and_ready', array($this, 'initialize_shortcodes_and_modules'));
217
-        // register widgets
218
-        add_action('widgets_init', array($this, 'widgets_init'), 10);
219
-        // shutdown
220
-        add_action('shutdown', array($this, 'shutdown'), 10);
221
-        // construct__end hook
222
-        do_action('AHEE__EE_Config__construct__end', $this);
223
-        // hardcoded hack
224
-        $this->template_settings->current_espresso_theme = 'Espresso_Arabica_2014';
225
-    }
226
-
227
-
228
-    /**
229
-     * @return boolean
230
-     */
231
-    public static function logging_enabled()
232
-    {
233
-        return self::$_logging_enabled;
234
-    }
235
-
236
-
237
-    /**
238
-     * use to get the current theme if needed from static context
239
-     *
240
-     * @return string current theme set.
241
-     */
242
-    public static function get_current_theme()
243
-    {
244
-        return isset(self::$_instance->template_settings->current_espresso_theme)
245
-            ? self::$_instance->template_settings->current_espresso_theme : 'Espresso_Arabica_2014';
246
-    }
247
-
248
-
249
-    /**
250
-     *        _initialize_config
251
-     *
252
-     * @access private
253
-     * @return void
254
-     */
255
-    private function _initialize_config()
256
-    {
257
-        EE_Config::trim_log();
258
-        // set defaults
259
-        $this->_addon_option_names = get_option(EE_Config::ADDON_OPTION_NAMES, array());
260
-        $this->addons = new stdClass();
261
-        // set _module_route_map
262
-        EE_Config::$_module_route_map = array();
263
-        // set _module_forward_map
264
-        EE_Config::$_module_forward_map = array();
265
-        // set _module_view_map
266
-        EE_Config::$_module_view_map = array();
267
-    }
268
-
269
-
270
-    /**
271
-     *        load core plugin configuration
272
-     *
273
-     * @access private
274
-     * @return void
275
-     */
276
-    private function _load_core_config()
277
-    {
278
-        // load_core_config__start hook
279
-        do_action('AHEE__EE_Config___load_core_config__start', $this);
280
-        $espresso_config = $this->get_espresso_config();
281
-        foreach ($espresso_config as $config => $settings) {
282
-            // load_core_config__start hook
283
-            $settings = apply_filters(
284
-                'FHEE__EE_Config___load_core_config__config_settings',
285
-                $settings,
286
-                $config,
287
-                $this
288
-            );
289
-            if (is_object($settings) && property_exists($this, $config)) {
290
-                $this->{$config} = apply_filters('FHEE__EE_Config___load_core_config__' . $config, $settings);
291
-                // call configs populate method to ensure any defaults are set for empty values.
292
-                if (method_exists($settings, 'populate')) {
293
-                    $this->{$config}->populate();
294
-                }
295
-                if (method_exists($settings, 'do_hooks')) {
296
-                    $this->{$config}->do_hooks();
297
-                }
298
-            }
299
-        }
300
-        if (apply_filters('FHEE__EE_Config___load_core_config__update_espresso_config', false)) {
301
-            $this->update_espresso_config();
302
-        }
303
-        // load_core_config__end hook
304
-        do_action('AHEE__EE_Config___load_core_config__end', $this);
305
-    }
306
-
307
-
308
-    /**
309
-     *    _verify_config
310
-     *
311
-     * @access    protected
312
-     * @return    void
313
-     */
314
-    protected function _verify_config()
315
-    {
316
-        $this->core = $this->core instanceof EE_Core_Config
317
-            ? $this->core
318
-            : new EE_Core_Config();
319
-        $this->core = apply_filters('FHEE__EE_Config___initialize_config__core', $this->core);
320
-        $this->organization = $this->organization instanceof EE_Organization_Config
321
-            ? $this->organization
322
-            : new EE_Organization_Config();
323
-        $this->organization = apply_filters(
324
-            'FHEE__EE_Config___initialize_config__organization',
325
-            $this->organization
326
-        );
327
-        $this->currency = $this->currency instanceof EE_Currency_Config
328
-            ? $this->currency
329
-            : new EE_Currency_Config();
330
-        $this->currency = apply_filters('FHEE__EE_Config___initialize_config__currency', $this->currency);
331
-        $this->registration = $this->registration instanceof EE_Registration_Config
332
-            ? $this->registration
333
-            : new EE_Registration_Config();
334
-        $this->registration = apply_filters(
335
-            'FHEE__EE_Config___initialize_config__registration',
336
-            $this->registration
337
-        );
338
-        $this->admin = $this->admin instanceof EE_Admin_Config
339
-            ? $this->admin
340
-            : new EE_Admin_Config();
341
-        $this->admin = apply_filters('FHEE__EE_Config___initialize_config__admin', $this->admin);
342
-        $this->template_settings = $this->template_settings instanceof EE_Template_Config
343
-            ? $this->template_settings
344
-            : new EE_Template_Config();
345
-        $this->template_settings = apply_filters(
346
-            'FHEE__EE_Config___initialize_config__template_settings',
347
-            $this->template_settings
348
-        );
349
-        $this->map_settings = $this->map_settings instanceof EE_Map_Config
350
-            ? $this->map_settings
351
-            : new EE_Map_Config();
352
-        $this->map_settings = apply_filters(
353
-            'FHEE__EE_Config___initialize_config__map_settings',
354
-            $this->map_settings
355
-        );
356
-        $this->environment = $this->environment instanceof EE_Environment_Config
357
-            ? $this->environment
358
-            : new EE_Environment_Config();
359
-        $this->environment = apply_filters(
360
-            'FHEE__EE_Config___initialize_config__environment',
361
-            $this->environment
362
-        );
363
-        $this->tax_settings = $this->tax_settings instanceof EE_Tax_Config
364
-            ? $this->tax_settings
365
-            : new EE_Tax_Config();
366
-        $this->tax_settings = apply_filters(
367
-            'FHEE__EE_Config___initialize_config__tax_settings',
368
-            $this->tax_settings
369
-        );
370
-        $this->messages = apply_filters('FHEE__EE_Config__initialize_config__messages', $this->messages);
371
-        $this->messages = $this->messages instanceof EE_Messages_Config
372
-            ? $this->messages
373
-            : new EE_Messages_Config();
374
-        $this->gateway = $this->gateway instanceof EE_Gateway_Config
375
-            ? $this->gateway
376
-            : new EE_Gateway_Config();
377
-        $this->gateway = apply_filters('FHEE__EE_Config___initialize_config__gateway', $this->gateway);
378
-        $this->legacy_shortcodes_manager = null;
379
-    }
380
-
381
-
382
-    /**
383
-     *    get_espresso_config
384
-     *
385
-     * @access    public
386
-     * @return    array of espresso config stuff
387
-     */
388
-    public function get_espresso_config()
389
-    {
390
-        // grab espresso configuration
391
-        return apply_filters(
392
-            'FHEE__EE_Config__get_espresso_config__CFG',
393
-            get_option(EE_Config::OPTION_NAME, array())
394
-        );
395
-    }
396
-
397
-
398
-    /**
399
-     * @param string $option
400
-     * @param mixed  $old_value
401
-     * @param mixed  $value
402
-     */
403
-    public function double_check_config_comparison(string $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
-        /** @var RequestInterface $request */
460
-        $request = LoaderFactory::getLoader()->getShared(RequestInterface::class);
461
-        if ($request->isWordPressHeartbeat()) {
462
-            return false;
463
-        }
464
-        // commented out the following re: https://events.codebasehq.com/projects/event-espresso/tickets/8197
465
-        // $clone = clone( self::$_instance );
466
-        // self::$_instance = NULL;
467
-        do_action('AHEE__EE_Config__update_espresso_config__begin', $this);
468
-        $this->_reset_espresso_addon_config();
469
-        // hook into update_option because that happens AFTER the ( $value === $old_value ) conditional
470
-        // but BEFORE the actual update occurs
471
-        add_action('update_option', array($this, 'double_check_config_comparison'), 1, 3);
472
-        // don't want to persist legacy_shortcodes_manager, but don't want to lose it either
473
-        $legacy_shortcodes_manager = $this->legacy_shortcodes_manager;
474
-        $this->legacy_shortcodes_manager = null;
475
-        // now update "ee_config"
476
-        $saved = update_option(EE_Config::OPTION_NAME, $this);
477
-        $this->legacy_shortcodes_manager = $legacy_shortcodes_manager;
478
-        EE_Config::log(EE_Config::OPTION_NAME);
479
-        // if not saved... check if the hook we just added still exists;
480
-        // if it does, it means one of two things:
481
-        // that update_option bailed at the($value === $old_value) conditional,
482
-        // or...
483
-        // the db update query returned 0 rows affected
484
-        // (probably because the data  value was the same from it's perspective)
485
-        // so the existence of the hook means that a negative result from update_option is NOT an error,
486
-        // but just means no update occurred, so don't display an error to the user.
487
-        // BUT... if update_option returns FALSE, AND the hook is missing,
488
-        // then it means that something truly went wrong
489
-        $saved = ! $saved ? has_action('update_option', array($this, 'double_check_config_comparison')) : $saved;
490
-        // remove our action since we don't want it in the system anymore
491
-        remove_action('update_option', array($this, 'double_check_config_comparison'), 1);
492
-        do_action('AHEE__EE_Config__update_espresso_config__end', $this, $saved);
493
-        // self::$_instance = $clone;
494
-        // unset( $clone );
495
-        // if config remains the same or was updated successfully
496
-        if ($saved) {
497
-            if ($add_success) {
498
-                EE_Error::add_success(
499
-                    esc_html__('The Event Espresso Configuration Settings have been successfully updated.', 'event_espresso'),
500
-                    __FILE__,
501
-                    __FUNCTION__,
502
-                    __LINE__
503
-                );
504
-            }
505
-            return true;
506
-        } else {
507
-            if ($add_error) {
508
-                EE_Error::add_error(
509
-                    esc_html__('The Event Espresso Configuration Settings were not updated.', 'event_espresso'),
510
-                    __FILE__,
511
-                    __FUNCTION__,
512
-                    __LINE__
513
-                );
514
-            }
515
-            return false;
516
-        }
517
-    }
518
-
519
-
520
-    /**
521
-     *    _verify_config_params
522
-     *
523
-     * @access    private
524
-     * @param    string         $section
525
-     * @param    string         $name
526
-     * @param    string         $config_class
527
-     * @param    EE_Config_Base $config_obj
528
-     * @param    array          $tests_to_run
529
-     * @param    bool           $display_errors
530
-     * @return    bool    TRUE on success, FALSE on fail
531
-     */
532
-    private function _verify_config_params(
533
-        $section = '',
534
-        $name = '',
535
-        $config_class = '',
536
-        $config_obj = null,
537
-        $tests_to_run = array(1, 2, 3, 4, 5, 6, 7, 8),
538
-        $display_errors = true
539
-    ) {
540
-        try {
541
-            foreach ($tests_to_run as $test) {
542
-                switch ($test) {
543
-                    // TEST #1 : check that section was set
544
-                    case 1:
545
-                        if (empty($section)) {
546
-                            if ($display_errors) {
547
-                                throw new EE_Error(
548
-                                    sprintf(
549
-                                        esc_html__(
550
-                                            'No configuration section has been provided while attempting to save "%s".',
551
-                                            'event_espresso'
552
-                                        ),
553
-                                        $config_class
554
-                                    )
555
-                                );
556
-                            }
557
-                            return false;
558
-                        }
559
-                        break;
560
-                    // TEST #2 : check that settings section exists
561
-                    case 2:
562
-                        if (! isset($this->{$section})) {
563
-                            if ($display_errors) {
564
-                                throw new EE_Error(
565
-                                    sprintf(
566
-                                        esc_html__('The "%s" configuration section does not exist.', 'event_espresso'),
567
-                                        $section
568
-                                    )
569
-                                );
570
-                            }
571
-                            return false;
572
-                        }
573
-                        break;
574
-                    // TEST #3 : check that section is the proper format
575
-                    case 3:
576
-                        if (
577
-                            ! ($this->{$section} instanceof EE_Config_Base || $this->{$section} instanceof stdClass)
578
-                        ) {
579
-                            if ($display_errors) {
580
-                                throw new EE_Error(
581
-                                    sprintf(
582
-                                        esc_html__(
583
-                                            'The "%s" configuration settings have not been formatted correctly.',
584
-                                            'event_espresso'
585
-                                        ),
586
-                                        $section
587
-                                    )
588
-                                );
589
-                            }
590
-                            return false;
591
-                        }
592
-                        break;
593
-                    // TEST #4 : check that config section name has been set
594
-                    case 4:
595
-                        if (empty($name)) {
596
-                            if ($display_errors) {
597
-                                throw new EE_Error(
598
-                                    esc_html__(
599
-                                        'No name has been provided for the specific configuration section.',
600
-                                        'event_espresso'
601
-                                    )
602
-                                );
603
-                            }
604
-                            return false;
605
-                        }
606
-                        break;
607
-                    // TEST #5 : check that a config class name has been set
608
-                    case 5:
609
-                        if (empty($config_class)) {
610
-                            if ($display_errors) {
611
-                                throw new EE_Error(
612
-                                    esc_html__(
613
-                                        'No class name has been provided for the specific configuration section.',
614
-                                        'event_espresso'
615
-                                    )
616
-                                );
617
-                            }
618
-                            return false;
619
-                        }
620
-                        break;
621
-                    // TEST #6 : verify config class is accessible
622
-                    case 6:
623
-                        if (! class_exists($config_class)) {
624
-                            if ($display_errors) {
625
-                                throw new EE_Error(
626
-                                    sprintf(
627
-                                        esc_html__(
628
-                                            'The "%s" class does not exist. Please ensure that an autoloader has been set for it.',
629
-                                            'event_espresso'
630
-                                        ),
631
-                                        $config_class
632
-                                    )
633
-                                );
634
-                            }
635
-                            return false;
636
-                        }
637
-                        break;
638
-                    // TEST #7 : check that config has even been set
639
-                    case 7:
640
-                        if (! isset($this->{$section}->{$name})) {
641
-                            if ($display_errors) {
642
-                                throw new EE_Error(
643
-                                    sprintf(
644
-                                        esc_html__('No configuration has been set for "%1$s->%2$s".', 'event_espresso'),
645
-                                        $section,
646
-                                        $name
647
-                                    )
648
-                                );
649
-                            }
650
-                            return false;
651
-                        } else {
652
-                            // and make sure it's not serialized
653
-                            $this->{$section}->{$name} = maybe_unserialize($this->{$section}->{$name});
654
-                        }
655
-                        break;
656
-                    // TEST #8 : check that config is the requested type
657
-                    case 8:
658
-                        if (! $this->{$section}->{$name} instanceof $config_class) {
659
-                            if ($display_errors) {
660
-                                throw new EE_Error(
661
-                                    sprintf(
662
-                                        esc_html__(
663
-                                            'The configuration for "%1$s->%2$s" is not of the "%3$s" class.',
664
-                                            'event_espresso'
665
-                                        ),
666
-                                        $section,
667
-                                        $name,
668
-                                        $config_class
669
-                                    )
670
-                                );
671
-                            }
672
-                            return false;
673
-                        }
674
-                        break;
675
-                    // TEST #9 : verify config object
676
-                    case 9:
677
-                        if (! $config_obj instanceof EE_Config_Base) {
678
-                            if ($display_errors) {
679
-                                throw new EE_Error(
680
-                                    sprintf(
681
-                                        esc_html__('The "%s" class is not an instance of EE_Config_Base.', 'event_espresso'),
682
-                                        print_r($config_obj, true)
683
-                                    )
684
-                                );
685
-                            }
686
-                            return false;
687
-                        }
688
-                        break;
689
-                }
690
-            }
691
-        } catch (EE_Error $e) {
692
-            $e->get_error();
693
-        }
694
-        // you have successfully run the gauntlet
695
-        return true;
696
-    }
697
-
698
-
699
-    /**
700
-     *    _generate_config_option_name
701
-     *
702
-     * @access        protected
703
-     * @param        string $section
704
-     * @param        string $name
705
-     * @return        string
706
-     */
707
-    private function _generate_config_option_name($section = '', $name = '')
708
-    {
709
-        return 'ee_config-' . strtolower($section . '-' . str_replace(array('EE_', 'EED_'), '', $name));
710
-    }
711
-
712
-
713
-    /**
714
-     *    _set_config_class
715
-     * ensures that a config class is set, either from a passed config class or one generated from the config name
716
-     *
717
-     * @access    private
718
-     * @param    string $config_class
719
-     * @param    string $name
720
-     * @return    string
721
-     */
722
-    private function _set_config_class($config_class = '', $name = '')
723
-    {
724
-        return ! empty($config_class)
725
-            ? $config_class
726
-            : str_replace(' ', '_', ucwords(str_replace('_', ' ', $name))) . '_Config';
727
-    }
728
-
729
-
730
-    /**
731
-     *    set_config
732
-     *
733
-     * @access    protected
734
-     * @param    string         $section
735
-     * @param    string         $name
736
-     * @param    string         $config_class
737
-     * @param    EE_Config_Base $config_obj
738
-     * @return    EE_Config_Base
739
-     */
740
-    public function set_config($section = '', $name = '', $config_class = '', EE_Config_Base $config_obj = null)
741
-    {
742
-        // ensure config class is set to something
743
-        $config_class = $this->_set_config_class($config_class, $name);
744
-        // run tests 1-4, 6, and 7 to verify all config params are set and valid
745
-        if (! $this->_verify_config_params($section, $name, $config_class, null, array(1, 2, 3, 4, 5, 6))) {
746
-            return null;
747
-        }
748
-        $config_option_name = $this->_generate_config_option_name($section, $name);
749
-        // if the config option name hasn't been added yet to the list of option names we're tracking, then do so now
750
-        if (! isset($this->_addon_option_names[ $config_option_name ])) {
751
-            $this->_addon_option_names[ $config_option_name ] = $config_class;
752
-            $this->update_addon_option_names();
753
-        }
754
-        // verify the incoming config object but suppress errors
755
-        if (! $this->_verify_config_params($section, $name, $config_class, $config_obj, array(9), false)) {
756
-            $config_obj = new $config_class();
757
-        }
758
-        if (get_option($config_option_name)) {
759
-            EE_Config::log($config_option_name);
760
-            update_option($config_option_name, $config_obj);
761
-            $this->{$section}->{$name} = $config_obj;
762
-            return $this->{$section}->{$name};
763
-        } else {
764
-            // create a wp-option for this config
765
-            if (add_option($config_option_name, $config_obj, '', 'no')) {
766
-                $this->{$section}->{$name} = maybe_unserialize($config_obj);
767
-                return $this->{$section}->{$name};
768
-            } else {
769
-                EE_Error::add_error(
770
-                    sprintf(esc_html__('The "%s" could not be saved to the database.', 'event_espresso'), $config_class),
771
-                    __FILE__,
772
-                    __FUNCTION__,
773
-                    __LINE__
774
-                );
775
-                return null;
776
-            }
777
-        }
778
-    }
779
-
780
-
781
-    /**
782
-     *    update_config
783
-     * Important: the config object must ALREADY be set, otherwise this will produce an error.
784
-     *
785
-     * @access    public
786
-     * @param    string                $section
787
-     * @param    string                $name
788
-     * @param    EE_Config_Base|string $config_obj
789
-     * @param    bool                  $throw_errors
790
-     * @return    bool
791
-     */
792
-    public function update_config($section = '', $name = '', $config_obj = '', $throw_errors = true)
793
-    {
794
-        // don't allow config updates during WP heartbeats
795
-        /** @var RequestInterface $request */
796
-        $request = LoaderFactory::getLoader()->getShared(RequestInterface::class);
797
-        if ($request->isWordPressHeartbeat()) {
798
-            return false;
799
-        }
800
-        $config_obj = maybe_unserialize($config_obj);
801
-        // get class name of the incoming object
802
-        $config_class = get_class($config_obj);
803
-        // run tests 1-5 and 9 to verify config
804
-        if (
805
-            ! $this->_verify_config_params(
806
-                $section,
807
-                $name,
808
-                $config_class,
809
-                $config_obj,
810
-                array(1, 2, 3, 4, 7, 9)
811
-            )
812
-        ) {
813
-            return false;
814
-        }
815
-        $config_option_name = $this->_generate_config_option_name($section, $name);
816
-        // check if config object has been added to db by seeing if config option name is in $this->_addon_option_names array
817
-        if (! isset($this->_addon_option_names[ $config_option_name ])) {
818
-            // save new config to db
819
-            if ($this->set_config($section, $name, $config_class, $config_obj)) {
820
-                return true;
821
-            }
822
-        } else {
823
-            // first check if the record already exists
824
-            $existing_config = get_option($config_option_name);
825
-            $config_obj = serialize($config_obj);
826
-            // just return if db record is already up to date (NOT type safe comparison)
827
-            if ($existing_config == $config_obj) {
828
-                $this->{$section}->{$name} = $config_obj;
829
-                return true;
830
-            } elseif (update_option($config_option_name, $config_obj)) {
831
-                EE_Config::log($config_option_name);
832
-                // update wp-option for this config class
833
-                $this->{$section}->{$name} = $config_obj;
834
-                return true;
835
-            } elseif ($throw_errors) {
836
-                EE_Error::add_error(
837
-                    sprintf(
838
-                        esc_html__(
839
-                            'The "%1$s" object stored at"%2$s" was not successfully updated in the database.',
840
-                            'event_espresso'
841
-                        ),
842
-                        $config_class,
843
-                        'EE_Config->' . $section . '->' . $name
844
-                    ),
845
-                    __FILE__,
846
-                    __FUNCTION__,
847
-                    __LINE__
848
-                );
849
-            }
850
-        }
851
-        return false;
852
-    }
853
-
854
-
855
-    /**
856
-     *    get_config
857
-     *
858
-     * @access    public
859
-     * @param    string $section
860
-     * @param    string $name
861
-     * @param    string $config_class
862
-     * @return    mixed EE_Config_Base | NULL
863
-     */
864
-    public function get_config($section = '', $name = '', $config_class = '')
865
-    {
866
-        // ensure config class is set to something
867
-        $config_class = $this->_set_config_class($config_class, $name);
868
-        // run tests 1-4, 6 and 7 to verify that all params have been set
869
-        if (! $this->_verify_config_params($section, $name, $config_class, null, array(1, 2, 3, 4, 5, 6))) {
870
-            return null;
871
-        }
872
-        // now test if the requested config object exists, but suppress errors
873
-        if ($this->_verify_config_params($section, $name, $config_class, null, array(7, 8), false)) {
874
-            // config already exists, so pass it back
875
-            return $this->{$section}->{$name};
876
-        }
877
-        // load config option from db if it exists
878
-        $config_obj = $this->get_config_option($this->_generate_config_option_name($section, $name));
879
-        // verify the newly retrieved config object, but suppress errors
880
-        if ($this->_verify_config_params($section, $name, $config_class, $config_obj, array(9), false)) {
881
-            // config is good, so set it and pass it back
882
-            $this->{$section}->{$name} = $config_obj;
883
-            return $this->{$section}->{$name};
884
-        }
885
-        // oops! $config_obj is not already set and does not exist in the db, so create a new one
886
-        $config_obj = $this->set_config($section, $name, $config_class);
887
-        // verify the newly created config object
888
-        if ($this->_verify_config_params($section, $name, $config_class, $config_obj, array(9))) {
889
-            return $this->{$section}->{$name};
890
-        } else {
891
-            EE_Error::add_error(
892
-                sprintf(esc_html__('The "%s" could not be retrieved from the database.', 'event_espresso'), $config_class),
893
-                __FILE__,
894
-                __FUNCTION__,
895
-                __LINE__
896
-            );
897
-        }
898
-        return null;
899
-    }
900
-
901
-
902
-    /**
903
-     *    get_config_option
904
-     *
905
-     * @access    public
906
-     * @param    string $config_option_name
907
-     * @return    mixed EE_Config_Base | FALSE
908
-     */
909
-    public function get_config_option($config_option_name = '')
910
-    {
911
-        // retrieve the wp-option for this config class.
912
-        $config_option = maybe_unserialize(get_option($config_option_name, array()));
913
-        if (empty($config_option)) {
914
-            EE_Config::log($config_option_name . '-NOT-FOUND');
915
-        }
916
-        return $config_option;
917
-    }
918
-
919
-
920
-    /**
921
-     * log
922
-     *
923
-     * @param string $config_option_name
924
-     */
925
-    public static function log($config_option_name = '')
926
-    {
927
-        if (EE_Config::logging_enabled() && ! empty($config_option_name)) {
928
-            $config_log = get_option(EE_Config::LOG_NAME, array());
929
-            /** @var RequestParams $request */
930
-            $request = LoaderFactory::getLoader()->getShared(RequestParams::class);
931
-            $config_log[ (string) microtime(true) ] = array(
932
-                'config_name' => $config_option_name,
933
-                'request'     => $request->requestParams(),
934
-            );
935
-            update_option(EE_Config::LOG_NAME, $config_log);
936
-        }
937
-    }
938
-
939
-
940
-    /**
941
-     * trim_log
942
-     * reduces the size of the config log to the length specified by EE_Config::LOG_LENGTH
943
-     */
944
-    public static function trim_log()
945
-    {
946
-        if (! EE_Config::logging_enabled()) {
947
-            return;
948
-        }
949
-        $config_log = maybe_unserialize(get_option(EE_Config::LOG_NAME, array()));
950
-        $log_length = count($config_log);
951
-        if ($log_length > EE_Config::LOG_LENGTH) {
952
-            ksort($config_log);
953
-            $config_log = array_slice($config_log, $log_length - EE_Config::LOG_LENGTH, null, true);
954
-            update_option(EE_Config::LOG_NAME, $config_log);
955
-        }
956
-    }
957
-
958
-
959
-    /**
960
-     *    get_page_for_posts
961
-     *    if the wp-option "show_on_front" is set to "page", then this is the post_name for the post set in the
962
-     *    wp-option "page_for_posts", or "posts" if no page is selected
963
-     *
964
-     * @access    public
965
-     * @return    string
966
-     */
967
-    public static function get_page_for_posts()
968
-    {
969
-        $page_for_posts = get_option('page_for_posts');
970
-        if (! $page_for_posts) {
971
-            return 'posts';
972
-        }
973
-        global $wpdb;
974
-        $SQL = "SELECT post_name from $wpdb->posts WHERE post_type='posts' OR post_type='page' AND post_status='publish' AND ID=%d";
975
-        return $wpdb->get_var($wpdb->prepare($SQL, $page_for_posts));
976
-    }
977
-
978
-
979
-    /**
980
-     *    register_shortcodes_and_modules.
981
-     *    At this point, it's too early to tell if we're maintenance mode or not.
982
-     *    In fact, this is where we give modules a chance to let core know they exist
983
-     *    so they can help trigger maintenance mode if it's needed
984
-     *
985
-     * @access    public
986
-     * @return    void
987
-     */
988
-    public function register_shortcodes_and_modules()
989
-    {
990
-        // allow modules to set hooks for the rest of the system
991
-        EE_Registry::instance()->modules = $this->_register_modules();
992
-    }
993
-
994
-
995
-    /**
996
-     *    initialize_shortcodes_and_modules
997
-     *    meaning they can start adding their hooks to get stuff done
998
-     *
999
-     * @access    public
1000
-     * @return    void
1001
-     */
1002
-    public function initialize_shortcodes_and_modules()
1003
-    {
1004
-        // allow modules to set hooks for the rest of the system
1005
-        $this->_initialize_modules();
1006
-    }
1007
-
1008
-
1009
-    /**
1010
-     *    widgets_init
1011
-     *
1012
-     * @access private
1013
-     * @return void
1014
-     */
1015
-    public function widgets_init()
1016
-    {
1017
-        // only init widgets on admin pages when not in complete maintenance, and
1018
-        // on frontend when not in any maintenance mode
1019
-        if (
1020
-            ! EE_Maintenance_Mode::instance()->level()
1021
-            || (
1022
-                is_admin()
1023
-                && EE_Maintenance_Mode::instance()->level() !== EE_Maintenance_Mode::level_2_complete_maintenance
1024
-            )
1025
-        ) {
1026
-            // grab list of installed widgets
1027
-            $widgets_to_register = glob(EE_WIDGETS . '*', GLOB_ONLYDIR);
1028
-            // filter list of modules to register
1029
-            $widgets_to_register = apply_filters(
1030
-                'FHEE__EE_Config__register_widgets__widgets_to_register',
1031
-                $widgets_to_register
1032
-            );
1033
-            if (! empty($widgets_to_register)) {
1034
-                // cycle thru widget folders
1035
-                foreach ($widgets_to_register as $widget_path) {
1036
-                    // add to list of installed widget modules
1037
-                    EE_Config::register_ee_widget($widget_path);
1038
-                }
1039
-            }
1040
-            // filter list of installed modules
1041
-            EE_Registry::instance()->widgets = apply_filters(
1042
-                'FHEE__EE_Config__register_widgets__installed_widgets',
1043
-                EE_Registry::instance()->widgets
1044
-            );
1045
-        }
1046
-    }
1047
-
1048
-
1049
-    /**
1050
-     *    register_ee_widget - makes core aware of this widget
1051
-     *
1052
-     * @access    public
1053
-     * @param    string $widget_path - full path up to and including widget folder
1054
-     * @return    void
1055
-     */
1056
-    public static function register_ee_widget($widget_path = null)
1057
-    {
1058
-        do_action('AHEE__EE_Config__register_widget__begin', $widget_path);
1059
-        $widget_ext = '.widget.php';
1060
-        // make all separators match
1061
-        $widget_path = rtrim(str_replace('\\', DS, $widget_path), DS);
1062
-        // does the file path INCLUDE the actual file name as part of the path ?
1063
-        if (strpos($widget_path, $widget_ext) !== false) {
1064
-            // grab and shortcode file name from directory name and break apart at dots
1065
-            $file_name = explode('.', basename($widget_path));
1066
-            // take first segment from file name pieces and remove class prefix if it exists
1067
-            $widget = strpos($file_name[0], 'EEW_') === 0 ? substr($file_name[0], 4) : $file_name[0];
1068
-            // sanitize shortcode directory name
1069
-            $widget = sanitize_key($widget);
1070
-            // now we need to rebuild the shortcode path
1071
-            $widget_path = explode('/', $widget_path);
1072
-            // remove last segment
1073
-            array_pop($widget_path);
1074
-            // glue it back together
1075
-            $widget_path = implode(DS, $widget_path);
1076
-        } else {
1077
-            // grab and sanitize widget directory name
1078
-            $widget = sanitize_key(basename($widget_path));
1079
-        }
1080
-        // create classname from widget directory name
1081
-        $widget = str_replace(' ', '_', ucwords(str_replace('_', ' ', $widget)));
1082
-        // add class prefix
1083
-        $widget_class = 'EEW_' . $widget;
1084
-        // does the widget exist ?
1085
-        if (! is_readable($widget_path . '/' . $widget_class . $widget_ext)) {
1086
-            $msg = sprintf(
1087
-                esc_html__(
1088
-                    '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',
1089
-                    'event_espresso'
1090
-                ),
1091
-                $widget_class,
1092
-                $widget_path . '/' . $widget_class . $widget_ext
1093
-            );
1094
-            EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__);
1095
-            return;
1096
-        }
1097
-        // load the widget class file
1098
-        require_once($widget_path . '/' . $widget_class . $widget_ext);
1099
-        // verify that class exists
1100
-        if (! class_exists($widget_class)) {
1101
-            $msg = sprintf(esc_html__('The requested %s widget class does not exist.', 'event_espresso'), $widget_class);
1102
-            EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__);
1103
-            return;
1104
-        }
1105
-        register_widget($widget_class);
1106
-        // add to array of registered widgets
1107
-        EE_Registry::instance()->widgets->{$widget_class} = $widget_path . '/' . $widget_class . $widget_ext;
1108
-    }
1109
-
1110
-
1111
-    /**
1112
-     *        _register_modules
1113
-     *
1114
-     * @access private
1115
-     * @return array
1116
-     */
1117
-    private function _register_modules()
1118
-    {
1119
-        // grab list of installed modules
1120
-        $modules_to_register = glob(EE_MODULES . '*', GLOB_ONLYDIR);
1121
-        // filter list of modules to register
1122
-        $modules_to_register = apply_filters(
1123
-            'FHEE__EE_Config__register_modules__modules_to_register',
1124
-            $modules_to_register
1125
-        );
1126
-        if (! empty($modules_to_register)) {
1127
-            // loop through folders
1128
-            foreach ($modules_to_register as $module_path) {
1129
-                /**TEMPORARILY EXCLUDE gateways from modules for time being**/
1130
-                if (
1131
-                    $module_path !== EE_MODULES . 'zzz-copy-this-module-template'
1132
-                    && $module_path !== EE_MODULES . 'gateways'
1133
-                ) {
1134
-                    // add to list of installed modules
1135
-                    EE_Config::register_module($module_path);
1136
-                }
1137
-            }
1138
-        }
1139
-        // filter list of installed modules
1140
-        return apply_filters(
1141
-            'FHEE__EE_Config___register_modules__installed_modules',
1142
-            EE_Registry::instance()->modules
1143
-        );
1144
-    }
1145
-
1146
-
1147
-    /**
1148
-     *    register_module - makes core aware of this module
1149
-     *
1150
-     * @access    public
1151
-     * @param    string $module_path - full path up to and including module folder
1152
-     * @return    bool
1153
-     */
1154
-    public static function register_module($module_path = null)
1155
-    {
1156
-        do_action('AHEE__EE_Config__register_module__begin', $module_path);
1157
-        $module_ext = '.module.php';
1158
-        // make all separators match
1159
-        $module_path = str_replace(array('\\', '/'), '/', $module_path);
1160
-        // does the file path INCLUDE the actual file name as part of the path ?
1161
-        if (strpos($module_path, $module_ext) !== false) {
1162
-            // grab and shortcode file name from directory name and break apart at dots
1163
-            $module_file = explode('.', basename($module_path));
1164
-            // now we need to rebuild the shortcode path
1165
-            $module_path = explode('/', $module_path);
1166
-            // remove last segment
1167
-            array_pop($module_path);
1168
-            // glue it back together
1169
-            $module_path = implode('/', $module_path) . '/';
1170
-            // take first segment from file name pieces and sanitize it
1171
-            $module = preg_replace('/[^a-zA-Z0-9_\-]/', '', $module_file[0]);
1172
-            // ensure class prefix is added
1173
-            $module_class = strpos($module, 'EED_') !== 0 ? 'EED_' . $module : $module;
1174
-        } else {
1175
-            // we need to generate the filename based off of the folder name
1176
-            // grab and sanitize module name
1177
-            $module = strtolower(basename($module_path));
1178
-            $module = preg_replace('/[^a-z0-9_\-]/', '', $module);
1179
-            // like trailingslashit()
1180
-            $module_path = rtrim($module_path, '/') . '/';
1181
-            // create classname from module directory name
1182
-            $module = str_replace(' ', '_', ucwords(str_replace('_', ' ', $module)));
1183
-            // add class prefix
1184
-            $module_class = 'EED_' . $module;
1185
-        }
1186
-        // does the module exist ?
1187
-        if (! is_readable($module_path . '/' . $module_class . $module_ext)) {
1188
-            $msg = sprintf(
1189
-                esc_html__(
1190
-                    'The requested %s module file could not be found or is not readable due to file permissions.',
1191
-                    'event_espresso'
1192
-                ),
1193
-                $module
1194
-            );
1195
-            EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__);
1196
-            return false;
1197
-        }
1198
-        // load the module class file
1199
-        require_once($module_path . $module_class . $module_ext);
1200
-        // verify that class exists
1201
-        if (! class_exists($module_class)) {
1202
-            $msg = sprintf(esc_html__('The requested %s module class does not exist.', 'event_espresso'), $module_class);
1203
-            EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__);
1204
-            return false;
1205
-        }
1206
-        // add to array of registered modules
1207
-        EE_Registry::instance()->modules->{$module_class} = $module_path . $module_class . $module_ext;
1208
-        do_action(
1209
-            'AHEE__EE_Config__register_module__complete',
1210
-            $module_class,
1211
-            EE_Registry::instance()->modules->{$module_class}
1212
-        );
1213
-        return true;
1214
-    }
1215
-
1216
-
1217
-    /**
1218
-     *    _initialize_modules
1219
-     *    allow modules to set hooks for the rest of the system
1220
-     *
1221
-     * @access private
1222
-     * @return void
1223
-     */
1224
-    private function _initialize_modules()
1225
-    {
1226
-        // cycle thru shortcode folders
1227
-        foreach (EE_Registry::instance()->modules as $module_class => $module_path) {
1228
-            // fire the shortcode class's set_hooks methods in case it needs to hook into other parts of the system
1229
-            // which set hooks ?
1230
-            if (is_admin()) {
1231
-                // fire immediately
1232
-                call_user_func(array($module_class, 'set_hooks_admin'));
1233
-            } else {
1234
-                // delay until other systems are online
1235
-                add_action(
1236
-                    'AHEE__EE_System__set_hooks_for_shortcodes_modules_and_addons',
1237
-                    array($module_class, 'set_hooks')
1238
-                );
1239
-            }
1240
-        }
1241
-    }
1242
-
1243
-
1244
-    /**
1245
-     *    register_route - adds module method routes to route_map
1246
-     *
1247
-     * @access    public
1248
-     * @param    string $route       - "pretty" public alias for module method
1249
-     * @param    string $module      - module name (classname without EED_ prefix)
1250
-     * @param    string $method_name - the actual module method to be routed to
1251
-     * @param    string $key         - url param key indicating a route is being called
1252
-     * @return    bool
1253
-     */
1254
-    public static function register_route($route = null, $module = null, $method_name = null, $key = 'ee')
1255
-    {
1256
-        do_action('AHEE__EE_Config__register_route__begin', $route, $module, $method_name);
1257
-        $module = str_replace('EED_', '', $module);
1258
-        $module_class = 'EED_' . $module;
1259
-        if (! isset(EE_Registry::instance()->modules->{$module_class})) {
1260
-            $msg = sprintf(esc_html__('The module %s has not been registered.', 'event_espresso'), $module);
1261
-            EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__);
1262
-            return false;
1263
-        }
1264
-        if (empty($route)) {
1265
-            $msg = sprintf(esc_html__('No route has been supplied.', 'event_espresso'), $route);
1266
-            EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__);
1267
-            return false;
1268
-        }
1269
-        if (! method_exists('EED_' . $module, $method_name)) {
1270
-            $msg = sprintf(
1271
-                esc_html__('A valid class method for the %s route has not been supplied.', 'event_espresso'),
1272
-                $route
1273
-            );
1274
-            EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__);
1275
-            return false;
1276
-        }
1277
-        EE_Config::$_module_route_map[ (string) $key ][ (string) $route ] = array('EED_' . $module, $method_name);
1278
-        return true;
1279
-    }
1280
-
1281
-
1282
-    /**
1283
-     *    get_route - get module method route
1284
-     *
1285
-     * @access    public
1286
-     * @param    string $route - "pretty" public alias for module method
1287
-     * @param    string $key   - url param key indicating a route is being called
1288
-     * @return    string
1289
-     */
1290
-    public static function get_route($route = null, $key = 'ee')
1291
-    {
1292
-        do_action('AHEE__EE_Config__get_route__begin', $route);
1293
-        $route = (string) apply_filters('FHEE__EE_Config__get_route', $route);
1294
-        if (isset(EE_Config::$_module_route_map[ $key ][ $route ])) {
1295
-            return EE_Config::$_module_route_map[ $key ][ $route ];
1296
-        }
1297
-        return null;
1298
-    }
1299
-
1300
-
1301
-    /**
1302
-     *    get_routes - get ALL module method routes
1303
-     *
1304
-     * @access    public
1305
-     * @return    array
1306
-     */
1307
-    public static function get_routes()
1308
-    {
1309
-        return EE_Config::$_module_route_map;
1310
-    }
1311
-
1312
-
1313
-    /**
1314
-     *    register_forward - allows modules to forward request to another module for further processing
1315
-     *
1316
-     * @access    public
1317
-     * @param    string       $route   - "pretty" public alias for module method
1318
-     * @param    integer      $status  - integer value corresponding  to status constant strings set in module parent
1319
-     *                                 class, allows different forwards to be served based on status
1320
-     * @param    array|string $forward - function name or array( class, method )
1321
-     * @param    string       $key     - url param key indicating a route is being called
1322
-     * @return    bool
1323
-     */
1324
-    public static function register_forward($route = null, $status = 0, $forward = null, $key = 'ee')
1325
-    {
1326
-        do_action('AHEE__EE_Config__register_forward', $route, $status, $forward);
1327
-        if (! isset(EE_Config::$_module_route_map[ $key ][ $route ]) || empty($route)) {
1328
-            $msg = sprintf(
1329
-                esc_html__('The module route %s for this forward has not been registered.', 'event_espresso'),
1330
-                $route
1331
-            );
1332
-            EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__);
1333
-            return false;
1334
-        }
1335
-        if (empty($forward)) {
1336
-            $msg = sprintf(esc_html__('No forwarding route has been supplied.', 'event_espresso'), $route);
1337
-            EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__);
1338
-            return false;
1339
-        }
1340
-        if (is_array($forward)) {
1341
-            if (! isset($forward[1])) {
1342
-                $msg = sprintf(
1343
-                    esc_html__('A class method for the %s forwarding route has not been supplied.', 'event_espresso'),
1344
-                    $route
1345
-                );
1346
-                EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__);
1347
-                return false;
1348
-            }
1349
-            if (! method_exists($forward[0], $forward[1])) {
1350
-                $msg = sprintf(
1351
-                    esc_html__('The class method %s for the %s forwarding route is in invalid.', 'event_espresso'),
1352
-                    $forward[1],
1353
-                    $route
1354
-                );
1355
-                EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__);
1356
-                return false;
1357
-            }
1358
-        } elseif (! function_exists($forward)) {
1359
-            $msg = sprintf(
1360
-                esc_html__('The function %s for the %s forwarding route is in invalid.', 'event_espresso'),
1361
-                $forward,
1362
-                $route
1363
-            );
1364
-            EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__);
1365
-            return false;
1366
-        }
1367
-        EE_Config::$_module_forward_map[ $key ][ $route ][ absint($status) ] = $forward;
1368
-        return true;
1369
-    }
1370
-
1371
-
1372
-    /**
1373
-     *    get_forward - get forwarding route
1374
-     *
1375
-     * @access    public
1376
-     * @param    string  $route  - "pretty" public alias for module method
1377
-     * @param    integer $status - integer value corresponding  to status constant strings set in module parent class,
1378
-     *                           allows different forwards to be served based on status
1379
-     * @param    string  $key    - url param key indicating a route is being called
1380
-     * @return    string
1381
-     */
1382
-    public static function get_forward($route = null, $status = 0, $key = 'ee')
1383
-    {
1384
-        do_action('AHEE__EE_Config__get_forward__begin', $route, $status);
1385
-        if (isset(EE_Config::$_module_forward_map[ $key ][ $route ][ $status ])) {
1386
-            return apply_filters(
1387
-                'FHEE__EE_Config__get_forward',
1388
-                EE_Config::$_module_forward_map[ $key ][ $route ][ $status ],
1389
-                $route,
1390
-                $status
1391
-            );
1392
-        }
1393
-        return null;
1394
-    }
1395
-
1396
-
1397
-    /**
1398
-     *    register_forward - allows modules to specify different view templates for different method routes and status
1399
-     *    results
1400
-     *
1401
-     * @access    public
1402
-     * @param    string  $route  - "pretty" public alias for module method
1403
-     * @param    integer $status - integer value corresponding  to status constant strings set in module parent class,
1404
-     *                           allows different views to be served based on status
1405
-     * @param    string  $view
1406
-     * @param    string  $key    - url param key indicating a route is being called
1407
-     * @return    bool
1408
-     */
1409
-    public static function register_view($route = null, $status = 0, $view = null, $key = 'ee')
1410
-    {
1411
-        do_action('AHEE__EE_Config__register_view__begin', $route, $status, $view);
1412
-        if (! isset(EE_Config::$_module_route_map[ $key ][ $route ]) || empty($route)) {
1413
-            $msg = sprintf(
1414
-                esc_html__('The module route %s for this view has not been registered.', 'event_espresso'),
1415
-                $route
1416
-            );
1417
-            EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__);
1418
-            return false;
1419
-        }
1420
-        if (! is_readable($view)) {
1421
-            $msg = sprintf(
1422
-                esc_html__(
1423
-                    'The %s view file could not be found or is not readable due to file permissions.',
1424
-                    'event_espresso'
1425
-                ),
1426
-                $view
1427
-            );
1428
-            EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__);
1429
-            return false;
1430
-        }
1431
-        EE_Config::$_module_view_map[ $key ][ $route ][ absint($status) ] = $view;
1432
-        return true;
1433
-    }
1434
-
1435
-
1436
-    /**
1437
-     *    get_view - get view for route and status
1438
-     *
1439
-     * @access    public
1440
-     * @param    string  $route  - "pretty" public alias for module method
1441
-     * @param    integer $status - integer value corresponding  to status constant strings set in module parent class,
1442
-     *                           allows different views to be served based on status
1443
-     * @param    string  $key    - url param key indicating a route is being called
1444
-     * @return    string
1445
-     */
1446
-    public static function get_view($route = null, $status = 0, $key = 'ee')
1447
-    {
1448
-        do_action('AHEE__EE_Config__get_view__begin', $route, $status);
1449
-        if (isset(EE_Config::$_module_view_map[ $key ][ $route ][ $status ])) {
1450
-            return apply_filters(
1451
-                'FHEE__EE_Config__get_view',
1452
-                EE_Config::$_module_view_map[ $key ][ $route ][ $status ],
1453
-                $route,
1454
-                $status
1455
-            );
1456
-        }
1457
-        return null;
1458
-    }
1459
-
1460
-
1461
-    public function update_addon_option_names()
1462
-    {
1463
-        update_option(EE_Config::ADDON_OPTION_NAMES, $this->_addon_option_names);
1464
-    }
1465
-
1466
-
1467
-    public function shutdown()
1468
-    {
1469
-        $this->update_addon_option_names();
1470
-    }
1471
-
1472
-
1473
-    /**
1474
-     * @return LegacyShortcodesManager
1475
-     */
1476
-    public static function getLegacyShortcodesManager()
1477
-    {
1478
-        if (! EE_Config::instance()->legacy_shortcodes_manager instanceof LegacyShortcodesManager) {
1479
-            EE_Config::instance()->legacy_shortcodes_manager = LoaderFactory::getLoader()->getShared(
1480
-                LegacyShortcodesManager::class
1481
-            );
1482
-        }
1483
-        return EE_Config::instance()->legacy_shortcodes_manager;
1484
-    }
1485
-
1486
-
1487
-    /**
1488
-     * register_shortcode - makes core aware of this shortcode
1489
-     *
1490
-     * @deprecated 4.9.26
1491
-     * @param    string $shortcode_path - full path up to and including shortcode folder
1492
-     * @return    bool
1493
-     */
1494
-    public static function register_shortcode($shortcode_path = null)
1495
-    {
1496
-        EE_Error::doing_it_wrong(
1497
-            __METHOD__,
1498
-            esc_html__(
1499
-                '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.',
1500
-                'event_espresso'
1501
-            ),
1502
-            '4.9.26'
1503
-        );
1504
-        return EE_Config::instance()->getLegacyShortcodesManager()->registerShortcode($shortcode_path);
1505
-    }
1506
-}
1507
-
1508
-/**
1509
- * Base class used for config classes. These classes should generally not have
1510
- * magic functions in use, except we'll allow them to magically set and get stuff...
1511
- * basically, they should just be well-defined stdClasses
1512
- */
1513
-class EE_Config_Base
1514
-{
1515
-    /**
1516
-     * Utility function for escaping the value of a property and returning.
1517
-     *
1518
-     * @param string $property property name (checks to see if exists).
1519
-     * @return mixed if a detected type found return the escaped value, otherwise just the raw value is returned.
1520
-     * @throws EE_Error
1521
-     */
1522
-    public function get_pretty($property)
1523
-    {
1524
-        if (! property_exists($this, $property)) {
1525
-            throw new EE_Error(
1526
-                sprintf(
1527
-                    esc_html__(
1528
-                        '%1$s::get_pretty() has been called with the property %2$s which does not exist on the %1$s config class.',
1529
-                        'event_espresso'
1530
-                    ),
1531
-                    get_class($this),
1532
-                    $property
1533
-                )
1534
-            );
1535
-        }
1536
-        // just handling escaping of strings for now.
1537
-        if (is_string($this->{$property})) {
1538
-            return stripslashes($this->{$property});
1539
-        }
1540
-        return $this->{$property};
1541
-    }
1542
-
1543
-
1544
-    public function populate()
1545
-    {
1546
-        // grab defaults via a new instance of this class.
1547
-        $class_name = get_class($this);
1548
-        $defaults = new $class_name();
1549
-        // loop through the properties for this class and see if they are set.  If they are NOT, then grab the
1550
-        // default from our $defaults object.
1551
-        foreach (get_object_vars($defaults) as $property => $value) {
1552
-            if ($this->{$property} === null) {
1553
-                $this->{$property} = $value;
1554
-            }
1555
-        }
1556
-        // cleanup
1557
-        unset($defaults);
1558
-    }
1559
-
1560
-
1561
-    /**
1562
-     *        __isset
1563
-     *
1564
-     * @param $a
1565
-     * @return bool
1566
-     */
1567
-    public function __isset($a)
1568
-    {
1569
-        return false;
1570
-    }
1571
-
1572
-
1573
-    /**
1574
-     *        __unset
1575
-     *
1576
-     * @param $a
1577
-     * @return bool
1578
-     */
1579
-    public function __unset($a)
1580
-    {
1581
-        return false;
1582
-    }
1583
-
1584
-
1585
-    /**
1586
-     *        __clone
1587
-     */
1588
-    public function __clone()
1589
-    {
1590
-    }
1591
-
1592
-
1593
-    /**
1594
-     *        __wakeup
1595
-     */
1596
-    public function __wakeup()
1597
-    {
1598
-    }
1599
-
1600
-
1601
-    /**
1602
-     *        __destruct
1603
-     */
1604
-    public function __destruct()
1605
-    {
1606
-    }
1607
-}
1608
-
1609
-/**
1610
- * Class for defining what's in the EE_Config relating to registration settings
1611
- */
1612
-class EE_Core_Config extends EE_Config_Base
1613
-{
1614
-    const OPTION_NAME_UXIP = 'ee_ueip_optin';
1615
-
1616
-
1617
-    public $current_blog_id;
1618
-
1619
-    public $ee_ueip_optin;
1620
-
1621
-    public $ee_ueip_has_notified;
1622
-
1623
-    /**
1624
-     * Not to be confused with the 4 critical page variables (See
1625
-     * get_critical_pages_array()), this is just an array of wp posts that have EE
1626
-     * shortcodes in them. Keys are slugs, values are arrays with only 1 element: where the key is the shortcode
1627
-     * in the page, and the value is the page's ID. The key 'posts' is basically a duplicate of this same array.
1628
-     *
1629
-     * @var array
1630
-     */
1631
-    public $post_shortcodes;
1632
-
1633
-    public $module_route_map;
1634
-
1635
-    public $module_forward_map;
1636
-
1637
-    public $module_view_map;
1638
-
1639
-    /**
1640
-     * The next 4 vars are the IDs of critical EE pages.
1641
-     *
1642
-     * @var int
1643
-     */
1644
-    public $reg_page_id;
1645
-
1646
-    public $txn_page_id;
1647
-
1648
-    public $thank_you_page_id;
1649
-
1650
-    public $cancel_page_id;
1651
-
1652
-    /**
1653
-     * The next 4 vars are the URLs of critical EE pages.
1654
-     *
1655
-     * @var int
1656
-     */
1657
-    public $reg_page_url;
1658
-
1659
-    public $txn_page_url;
1660
-
1661
-    public $thank_you_page_url;
1662
-
1663
-    public $cancel_page_url;
1664
-
1665
-    /**
1666
-     * The next vars relate to the custom slugs for EE CPT routes
1667
-     */
1668
-    public $event_cpt_slug;
1669
-
1670
-    /**
1671
-     * This caches the _ee_ueip_option in case this config is reset in the same
1672
-     * request across blog switches in a multisite context.
1673
-     * Avoids extra queries to the db for this option.
1674
-     *
1675
-     * @var bool
1676
-     */
1677
-    public static $ee_ueip_option;
1678
-
1679
-
1680
-    /**
1681
-     *    class constructor
1682
-     *
1683
-     * @access    public
1684
-     */
1685
-    public function __construct()
1686
-    {
1687
-        // set default organization settings
1688
-        $this->current_blog_id = get_current_blog_id();
1689
-        $this->current_blog_id = $this->current_blog_id === null ? 1 : $this->current_blog_id;
1690
-        $this->ee_ueip_optin = $this->_get_main_ee_ueip_optin();
1691
-        $this->ee_ueip_has_notified = is_main_site() ? get_option('ee_ueip_has_notified', false) : true;
1692
-        $this->post_shortcodes = array();
1693
-        $this->module_route_map = array();
1694
-        $this->module_forward_map = array();
1695
-        $this->module_view_map = array();
1696
-        // critical EE page IDs
1697
-        $this->reg_page_id = 0;
1698
-        $this->txn_page_id = 0;
1699
-        $this->thank_you_page_id = 0;
1700
-        $this->cancel_page_id = 0;
1701
-        // critical EE page URLs
1702
-        $this->reg_page_url = '';
1703
-        $this->txn_page_url = '';
1704
-        $this->thank_you_page_url = '';
1705
-        $this->cancel_page_url = '';
1706
-        // cpt slugs
1707
-        $this->event_cpt_slug = esc_html__('events', 'event_espresso');
1708
-        // ueip constant check
1709
-        if (defined('EE_DISABLE_UXIP') && EE_DISABLE_UXIP) {
1710
-            $this->ee_ueip_optin = false;
1711
-            $this->ee_ueip_has_notified = true;
1712
-        }
1713
-    }
1714
-
1715
-
1716
-    /**
1717
-     * @return array
1718
-     */
1719
-    public function get_critical_pages_array()
1720
-    {
1721
-        return array(
1722
-            $this->reg_page_id,
1723
-            $this->txn_page_id,
1724
-            $this->thank_you_page_id,
1725
-            $this->cancel_page_id,
1726
-        );
1727
-    }
1728
-
1729
-
1730
-    /**
1731
-     * @return array
1732
-     */
1733
-    public function get_critical_pages_shortcodes_array()
1734
-    {
1735
-        return array(
1736
-            $this->reg_page_id       => 'ESPRESSO_CHECKOUT',
1737
-            $this->txn_page_id       => 'ESPRESSO_TXN_PAGE',
1738
-            $this->thank_you_page_id => 'ESPRESSO_THANK_YOU',
1739
-            $this->cancel_page_id    => 'ESPRESSO_CANCELLED',
1740
-        );
1741
-    }
1742
-
1743
-
1744
-    /**
1745
-     *  gets/returns URL for EE reg_page
1746
-     *
1747
-     * @access    public
1748
-     * @return    string
1749
-     */
1750
-    public function reg_page_url()
1751
-    {
1752
-        if (! $this->reg_page_url) {
1753
-            $this->reg_page_url = add_query_arg(
1754
-                array('uts' => time()),
1755
-                get_permalink($this->reg_page_id)
1756
-            ) . '#checkout';
1757
-        }
1758
-        return $this->reg_page_url;
1759
-    }
1760
-
1761
-
1762
-    /**
1763
-     *  gets/returns URL for EE txn_page
1764
-     *
1765
-     * @param array $query_args like what gets passed to
1766
-     *                          add_query_arg() as the first argument
1767
-     * @access    public
1768
-     * @return    string
1769
-     */
1770
-    public function txn_page_url($query_args = array())
1771
-    {
1772
-        if (! $this->txn_page_url) {
1773
-            $this->txn_page_url = get_permalink($this->txn_page_id);
1774
-        }
1775
-        if ($query_args) {
1776
-            return add_query_arg($query_args, $this->txn_page_url);
1777
-        } else {
1778
-            return $this->txn_page_url;
1779
-        }
1780
-    }
1781
-
1782
-
1783
-    /**
1784
-     *  gets/returns URL for EE thank_you_page
1785
-     *
1786
-     * @param array $query_args like what gets passed to
1787
-     *                          add_query_arg() as the first argument
1788
-     * @access    public
1789
-     * @return    string
1790
-     */
1791
-    public function thank_you_page_url($query_args = array())
1792
-    {
1793
-        if (! $this->thank_you_page_url) {
1794
-            $this->thank_you_page_url = get_permalink($this->thank_you_page_id);
1795
-        }
1796
-        if ($query_args) {
1797
-            return add_query_arg($query_args, $this->thank_you_page_url);
1798
-        } else {
1799
-            return $this->thank_you_page_url;
1800
-        }
1801
-    }
1802
-
1803
-
1804
-    /**
1805
-     *  gets/returns URL for EE cancel_page
1806
-     *
1807
-     * @access    public
1808
-     * @return    string
1809
-     */
1810
-    public function cancel_page_url()
1811
-    {
1812
-        if (! $this->cancel_page_url) {
1813
-            $this->cancel_page_url = get_permalink($this->cancel_page_id);
1814
-        }
1815
-        return $this->cancel_page_url;
1816
-    }
1817
-
1818
-
1819
-    /**
1820
-     * Resets all critical page urls to their original state.  Used primarily by the __sleep() magic method currently.
1821
-     *
1822
-     * @since 4.7.5
1823
-     */
1824
-    protected function _reset_urls()
1825
-    {
1826
-        $this->reg_page_url = '';
1827
-        $this->txn_page_url = '';
1828
-        $this->cancel_page_url = '';
1829
-        $this->thank_you_page_url = '';
1830
-    }
1831
-
1832
-
1833
-    /**
1834
-     * Used to return what the optin value is set for the EE User Experience Program.
1835
-     * This accounts for multisite and this value being requested for a subsite.  In multisite, the value is set
1836
-     * on the main site only.
1837
-     *
1838
-     * @return bool
1839
-     */
1840
-    protected function _get_main_ee_ueip_optin()
1841
-    {
1842
-        // if this is the main site then we can just bypass our direct query.
1843
-        if (is_main_site()) {
1844
-            return get_option(self::OPTION_NAME_UXIP, false);
1845
-        }
1846
-        // is this already cached for this request?  If so use it.
1847
-        if (EE_Core_Config::$ee_ueip_option !== null) {
1848
-            return EE_Core_Config::$ee_ueip_option;
1849
-        }
1850
-        global $wpdb;
1851
-        $current_network_main_site = is_multisite() ? get_current_site() : null;
1852
-        $current_main_site_id = ! empty($current_network_main_site) ? $current_network_main_site->blog_id : 1;
1853
-        $option = self::OPTION_NAME_UXIP;
1854
-        // set correct table for query
1855
-        $table_name = $wpdb->get_blog_prefix($current_main_site_id) . 'options';
1856
-        // rather than getting blog option for the $current_main_site_id, we do a direct $wpdb query because
1857
-        // get_blog_option() does a switch_to_blog an that could cause infinite recursion because EE_Core_Config might be
1858
-        // re-constructed on the blog switch.  Note, we are still executing any core wp filters on this option retrieval.
1859
-        // this bit of code is basically a direct copy of get_option without any caching because we are NOT switched to the blog
1860
-        // for the purpose of caching.
1861
-        $pre = apply_filters('pre_option_' . $option, false, $option);
1862
-        if (false !== $pre) {
1863
-            EE_Core_Config::$ee_ueip_option = $pre;
1864
-            return EE_Core_Config::$ee_ueip_option;
1865
-        }
1866
-        $row = $wpdb->get_row(
1867
-            $wpdb->prepare(
1868
-                "SELECT option_value FROM $table_name WHERE option_name = %s LIMIT 1",
1869
-                $option
1870
-            )
1871
-        );
1872
-        if (is_object($row)) {
1873
-            $value = $row->option_value;
1874
-        } else { // option does not exist so use default.
1875
-            EE_Core_Config::$ee_ueip_option =  apply_filters('default_option_' . $option, false, $option);
1876
-            return EE_Core_Config::$ee_ueip_option;
1877
-        }
1878
-        EE_Core_Config::$ee_ueip_option = apply_filters('option_' . $option, maybe_unserialize($value), $option);
1879
-        return EE_Core_Config::$ee_ueip_option;
1880
-    }
1881
-
1882
-
1883
-    /**
1884
-     * Utility function for escaping the value of a property and returning.
1885
-     *
1886
-     * @param string $property property name (checks to see if exists).
1887
-     * @return mixed if a detected type found return the escaped value, otherwise just the raw value is returned.
1888
-     * @throws EE_Error
1889
-     */
1890
-    public function get_pretty($property)
1891
-    {
1892
-        if ($property === self::OPTION_NAME_UXIP) {
1893
-            return $this->ee_ueip_optin ? 'yes' : 'no';
1894
-        }
1895
-        return parent::get_pretty($property);
1896
-    }
1897
-
1898
-
1899
-    /**
1900
-     * Currently used to ensure critical page urls have initial values saved to the db instead of any current set values
1901
-     * on the object.
1902
-     *
1903
-     * @return array
1904
-     */
1905
-    public function __sleep()
1906
-    {
1907
-        // reset all url properties
1908
-        $this->_reset_urls();
1909
-        // return what to save to db
1910
-        return array_keys(get_object_vars($this));
1911
-    }
1912
-}
1913
-
1914
-/**
1915
- * Config class for storing info on the Organization
1916
- */
1917
-class EE_Organization_Config extends EE_Config_Base
1918
-{
1919
-    /**
1920
-     * @var string $name
1921
-     * eg EE4.1
1922
-     */
1923
-    public $name;
1924
-
1925
-    /**
1926
-     * @var string $address_1
1927
-     * eg 123 Onna Road
1928
-     */
1929
-    public $address_1 = '';
1930
-
1931
-    /**
1932
-     * @var string $address_2
1933
-     * eg PO Box 123
1934
-     */
1935
-    public $address_2 = '';
1936
-
1937
-    /**
1938
-     * @var string $city
1939
-     * eg Inna City
1940
-     */
1941
-    public $city = '';
1942
-
1943
-    /**
1944
-     * @var int $STA_ID
1945
-     * eg 4
1946
-     */
1947
-    public $STA_ID = 0;
1948
-
1949
-    /**
1950
-     * @var string $CNT_ISO
1951
-     * eg US
1952
-     */
1953
-    public $CNT_ISO = '';
1954
-
1955
-    /**
1956
-     * @var string $zip
1957
-     * eg 12345  or V1A 2B3
1958
-     */
1959
-    public $zip = '';
1960
-
1961
-    /**
1962
-     * @var string $email
1963
-     * eg [email protected]
1964
-     */
1965
-    public $email;
1966
-
1967
-    /**
1968
-     * @var string $phone
1969
-     * eg. 111-111-1111
1970
-     */
1971
-    public $phone = '';
1972
-
1973
-    /**
1974
-     * @var string $vat
1975
-     * VAT/Tax Number
1976
-     */
1977
-    public $vat = '';
1978
-
1979
-    /**
1980
-     * @var string $logo_url
1981
-     * eg http://www.somedomain.com/wp-content/uploads/kittehs.jpg
1982
-     */
1983
-    public $logo_url = '';
1984
-
1985
-    /**
1986
-     * The below are all various properties for holding links to organization social network profiles
1987
-     *
1988
-     * @var string
1989
-     */
1990
-    /**
1991
-     * facebook (facebook.com/profile.name)
1992
-     *
1993
-     * @var string
1994
-     */
1995
-    public $facebook = '';
1996
-
1997
-    /**
1998
-     * twitter (twitter.com/twitter_handle)
1999
-     *
2000
-     * @var string
2001
-     */
2002
-    public $twitter = '';
2003
-
2004
-    /**
2005
-     * linkedin (linkedin.com/in/profile_name)
2006
-     *
2007
-     * @var string
2008
-     */
2009
-    public $linkedin = '';
2010
-
2011
-    /**
2012
-     * pinterest (www.pinterest.com/profile_name)
2013
-     *
2014
-     * @var string
2015
-     */
2016
-    public $pinterest = '';
2017
-
2018
-    /**
2019
-     * google+ (google.com/+profileName)
2020
-     *
2021
-     * @var string
2022
-     */
2023
-    public $google = '';
2024
-
2025
-    /**
2026
-     * instagram (instagram.com/handle)
2027
-     *
2028
-     * @var string
2029
-     */
2030
-    public $instagram = '';
2031
-
2032
-
2033
-    /**
2034
-     *    class constructor
2035
-     *
2036
-     * @access    public
2037
-     */
2038
-    public function __construct()
2039
-    {
2040
-        // set default organization settings
2041
-        // decode HTML entities from the WP blogname, because it's stored in the DB with HTML entities encoded
2042
-        $this->name = wp_specialchars_decode(get_bloginfo('name'), ENT_QUOTES);
2043
-        $this->email = get_bloginfo('admin_email');
2044
-    }
2045
-}
2046
-
2047
-/**
2048
- * Class for defining what's in the EE_Config relating to currency
2049
- */
2050
-class EE_Currency_Config extends EE_Config_Base
2051
-{
2052
-    /**
2053
-     * @var string $code
2054
-     * eg 'US'
2055
-     */
2056
-    public $code;
2057
-
2058
-    /**
2059
-     * @var string $name
2060
-     * eg 'Dollar'
2061
-     */
2062
-    public $name;
2063
-
2064
-    /**
2065
-     * plural name
2066
-     *
2067
-     * @var string $plural
2068
-     * eg 'Dollars'
2069
-     */
2070
-    public $plural;
2071
-
2072
-    /**
2073
-     * currency sign
2074
-     *
2075
-     * @var string $sign
2076
-     * eg '$'
2077
-     */
2078
-    public $sign;
2079
-
2080
-    /**
2081
-     * Whether the currency sign should come before the number or not
2082
-     *
2083
-     * @var boolean $sign_b4
2084
-     */
2085
-    public $sign_b4;
2086
-
2087
-    /**
2088
-     * How many digits should come after the decimal place
2089
-     *
2090
-     * @var int $dec_plc
2091
-     */
2092
-    public $dec_plc;
2093
-
2094
-    /**
2095
-     * Symbol to use for decimal mark
2096
-     *
2097
-     * @var string $dec_mrk
2098
-     * eg '.'
2099
-     */
2100
-    public $dec_mrk;
2101
-
2102
-    /**
2103
-     * Symbol to use for thousands
2104
-     *
2105
-     * @var string $thsnds
2106
-     * eg ','
2107
-     */
2108
-    public $thsnds;
2109
-
2110
-
2111
-    /**
2112
-     *    class constructor
2113
-     *
2114
-     * @access    public
2115
-     * @param string $CNT_ISO
2116
-     * @throws EE_Error
2117
-     * @throws ReflectionException
2118
-     */
2119
-    public function __construct($CNT_ISO = '')
2120
-    {
2121
-        /** @var TableAnalysis $table_analysis */
2122
-        $table_analysis = EE_Registry::instance()->create('TableAnalysis', array(), true);
2123
-        // get country code from organization settings or use default
2124
-        $ORG_CNT = isset(EE_Registry::instance()->CFG->organization)
2125
-                   && EE_Registry::instance()->CFG->organization instanceof EE_Organization_Config
2126
-            ? EE_Registry::instance()->CFG->organization->CNT_ISO
2127
-            : '';
2128
-        // but override if requested
2129
-        $CNT_ISO = ! empty($CNT_ISO) ? $CNT_ISO : $ORG_CNT;
2130
-        // 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
2131
-        if (
2132
-            ! empty($CNT_ISO)
2133
-            && EE_Maintenance_Mode::instance()->models_can_query()
2134
-            && $table_analysis->tableExists(EE_Registry::instance()->load_model('Country')->table())
2135
-        ) {
2136
-            // retrieve the country settings from the db, just in case they have been customized
2137
-            $country = EE_Registry::instance()->load_model('Country')->get_one_by_ID($CNT_ISO);
2138
-            if ($country instanceof EE_Country) {
2139
-                $this->code = $country->currency_code();    // currency code: USD, CAD, EUR
2140
-                $this->name = $country->currency_name_single();    // Dollar
2141
-                $this->plural = $country->currency_name_plural();    // Dollars
2142
-                $this->sign = $country->currency_sign();            // currency sign: $
2143
-                $this->sign_b4 = $country->currency_sign_before(
2144
-                );        // currency sign before or after: $TRUE  or  FALSE$
2145
-                $this->dec_plc = $country->currency_decimal_places();    // decimal places: 2 = 0.00  3 = 0.000
2146
-                $this->dec_mrk = $country->currency_decimal_mark(
2147
-                );    // decimal mark: (comma) ',' = 0,01   or (decimal) '.' = 0.01
2148
-                $this->thsnds = $country->currency_thousands_separator(
2149
-                );    // thousands separator: (comma) ',' = 1,000   or (decimal) '.' = 1.000
2150
-            }
2151
-        }
2152
-        // fallback to hardcoded defaults, in case the above failed
2153
-        if (empty($this->code)) {
2154
-            // set default currency settings
2155
-            $this->code = 'USD';    // currency code: USD, CAD, EUR
2156
-            $this->name = esc_html__('Dollar', 'event_espresso');    // Dollar
2157
-            $this->plural = esc_html__('Dollars', 'event_espresso');    // Dollars
2158
-            $this->sign = '$';    // currency sign: $
2159
-            $this->sign_b4 = true;    // currency sign before or after: $TRUE  or  FALSE$
2160
-            $this->dec_plc = 2;    // decimal places: 2 = 0.00  3 = 0.000
2161
-            $this->dec_mrk = '.';    // decimal mark: (comma) ',' = 0,01   or (decimal) '.' = 0.01
2162
-            $this->thsnds = ',';    // thousands separator: (comma) ',' = 1,000   or (decimal) '.' = 1.000
2163
-        }
2164
-    }
2165
-}
2166
-
2167
-/**
2168
- * Class for defining what's in the EE_Config relating to registration settings
2169
- */
2170
-class EE_Registration_Config extends EE_Config_Base
2171
-{
2172
-    /**
2173
-     * Default registration status
2174
-     *
2175
-     * @var string $default_STS_ID
2176
-     * eg 'RPP'
2177
-     */
2178
-    public $default_STS_ID;
2179
-
2180
-    /**
2181
-     * For new events, this will be the default value for the maximum number of tickets (equivalent to maximum number of
2182
-     * registrations)
2183
-     *
2184
-     * @var int
2185
-     */
2186
-    public $default_maximum_number_of_tickets;
2187
-
2188
-    /**
2189
-     * level of validation to apply to email addresses
2190
-     *
2191
-     * @var string $email_validation_level
2192
-     * options: 'basic', 'wp_default', 'i18n', 'i18n_dns'
2193
-     */
2194
-    public $email_validation_level;
2195
-
2196
-    /**
2197
-     *    whether or not to show alternate payment options during the reg process if payment status is pending
2198
-     *
2199
-     * @var boolean $show_pending_payment_options
2200
-     */
2201
-    public $show_pending_payment_options;
2202
-
2203
-    /**
2204
-     * Whether to skip the registration confirmation page
2205
-     *
2206
-     * @var boolean $skip_reg_confirmation
2207
-     */
2208
-    public $skip_reg_confirmation;
2209
-
2210
-    /**
2211
-     * an array of SPCO reg steps where:
2212
-     *        the keys denotes the reg step order
2213
-     *        each element consists of an array with the following elements:
2214
-     *            "file_path" => the file path to the EE_SPCO_Reg_Step class
2215
-     *            "class_name" => the specific EE_SPCO_Reg_Step child class name
2216
-     *            "slug" => the URL param used to trigger the reg step
2217
-     *
2218
-     * @var array $reg_steps
2219
-     */
2220
-    public $reg_steps;
2221
-
2222
-    /**
2223
-     * Whether registration confirmation should be the last page of SPCO
2224
-     *
2225
-     * @var boolean $reg_confirmation_last
2226
-     */
2227
-    public $reg_confirmation_last;
2228
-
2229
-    /**
2230
-     * Whether or not to enable the EE Bot Trap
2231
-     *
2232
-     * @var boolean $use_bot_trap
2233
-     */
2234
-    public $use_bot_trap;
2235
-
2236
-    /**
2237
-     * Whether or not to encrypt some data sent by the EE Bot Trap
2238
-     *
2239
-     * @var boolean $use_encryption
2240
-     */
2241
-    public $use_encryption;
2242
-
2243
-    /**
2244
-     * Whether or not to use ReCaptcha
2245
-     *
2246
-     * @var boolean $use_captcha
2247
-     */
2248
-    public $use_captcha;
2249
-
2250
-    /**
2251
-     * ReCaptcha Theme
2252
-     *
2253
-     * @var string $recaptcha_theme
2254
-     *    options: 'dark', 'light', 'invisible'
2255
-     */
2256
-    public $recaptcha_theme;
2257
-
2258
-    /**
2259
-     * ReCaptcha Badge - determines the position of the reCAPTCHA badge if using Invisible ReCaptcha.
2260
-     *
2261
-     * @var string $recaptcha_badge
2262
-     *    options: 'bottomright', 'bottomleft', 'inline'
2263
-     */
2264
-    public $recaptcha_badge;
2265
-
2266
-    /**
2267
-     * ReCaptcha Type
2268
-     *
2269
-     * @var string $recaptcha_type
2270
-     *    options: 'audio', 'image'
2271
-     */
2272
-    public $recaptcha_type;
2273
-
2274
-    /**
2275
-     * ReCaptcha language
2276
-     *
2277
-     * @var string $recaptcha_language
2278
-     * eg 'en'
2279
-     */
2280
-    public $recaptcha_language;
2281
-
2282
-    /**
2283
-     * ReCaptcha public key
2284
-     *
2285
-     * @var string $recaptcha_publickey
2286
-     */
2287
-    public $recaptcha_publickey;
2288
-
2289
-    /**
2290
-     * ReCaptcha private key
2291
-     *
2292
-     * @var string $recaptcha_privatekey
2293
-     */
2294
-    public $recaptcha_privatekey;
2295
-
2296
-    /**
2297
-     * array of form names protected by ReCaptcha
2298
-     *
2299
-     * @var array $recaptcha_protected_forms
2300
-     */
2301
-    public $recaptcha_protected_forms;
21
+	const OPTION_NAME = 'ee_config';
22
+
23
+	const LOG_NAME = 'ee_config_log';
24
+
25
+	const LOG_LENGTH = 100;
26
+
27
+	const ADDON_OPTION_NAMES = 'ee_config_option_names';
28
+
29
+	/**
30
+	 *    instance of the EE_Config object
31
+	 *
32
+	 * @var    EE_Config $_instance
33
+	 * @access    private
34
+	 */
35
+	private static $_instance;
36
+
37
+	/**
38
+	 * @var boolean $_logging_enabled
39
+	 */
40
+	private static $_logging_enabled = false;
41
+
42
+	/**
43
+	 * @var LegacyShortcodesManager $legacy_shortcodes_manager
44
+	 */
45
+	private $legacy_shortcodes_manager;
46
+
47
+	/**
48
+	 * An StdClass whose property names are addon slugs,
49
+	 * and values are their config classes
50
+	 *
51
+	 * @var StdClass
52
+	 */
53
+	public $addons;
54
+
55
+	/**
56
+	 * @var EE_Admin_Config
57
+	 */
58
+	public $admin;
59
+
60
+	/**
61
+	 * @var EE_Core_Config
62
+	 */
63
+	public $core;
64
+
65
+	/**
66
+	 * @var EE_Currency_Config
67
+	 */
68
+	public $currency;
69
+
70
+	/**
71
+	 * @var EE_Organization_Config
72
+	 */
73
+	public $organization;
74
+
75
+	/**
76
+	 * @var EE_Registration_Config
77
+	 */
78
+	public $registration;
79
+
80
+	/**
81
+	 * @var EE_Template_Config
82
+	 */
83
+	public $template_settings;
84
+
85
+	/**
86
+	 * Holds EE environment values.
87
+	 *
88
+	 * @var EE_Environment_Config
89
+	 */
90
+	public $environment;
91
+
92
+	/**
93
+	 * settings pertaining to Google maps
94
+	 *
95
+	 * @var EE_Map_Config
96
+	 */
97
+	public $map_settings;
98
+
99
+	/**
100
+	 * settings pertaining to Taxes
101
+	 *
102
+	 * @var EE_Tax_Config
103
+	 */
104
+	public $tax_settings;
105
+
106
+	/**
107
+	 * Settings pertaining to global messages settings.
108
+	 *
109
+	 * @var EE_Messages_Config
110
+	 */
111
+	public $messages;
112
+
113
+	/**
114
+	 * @deprecated
115
+	 * @var EE_Gateway_Config
116
+	 */
117
+	public $gateway;
118
+
119
+	/**
120
+	 * @var    array $_addon_option_names
121
+	 * @access    private
122
+	 */
123
+	private $_addon_option_names = array();
124
+
125
+	/**
126
+	 * @var    array $_module_route_map
127
+	 * @access    private
128
+	 */
129
+	private static $_module_route_map = array();
130
+
131
+	/**
132
+	 * @var    array $_module_forward_map
133
+	 * @access    private
134
+	 */
135
+	private static $_module_forward_map = array();
136
+
137
+	/**
138
+	 * @var    array $_module_view_map
139
+	 * @access    private
140
+	 */
141
+	private static $_module_view_map = array();
142
+
143
+
144
+	/**
145
+	 * @singleton method used to instantiate class object
146
+	 * @access    public
147
+	 * @return EE_Config instance
148
+	 */
149
+	public static function instance()
150
+	{
151
+		// check if class object is instantiated, and instantiated properly
152
+		if (! self::$_instance instanceof EE_Config) {
153
+			self::$_instance = new self();
154
+		}
155
+		return self::$_instance;
156
+	}
157
+
158
+
159
+	/**
160
+	 * Resets the config
161
+	 *
162
+	 * @param bool    $hard_reset    if TRUE, sets EE_CONFig back to its original settings in the database. If FALSE
163
+	 *                               (default) leaves the database alone, and merely resets the EE_Config object to
164
+	 *                               reflect its state in the database
165
+	 * @param boolean $reinstantiate if TRUE (default) call instance() and return it. Otherwise, just leave
166
+	 *                               $_instance as NULL. Useful in case you want to forget about the old instance on
167
+	 *                               EE_Config, but might not be ready to instantiate EE_Config currently (eg if the
168
+	 *                               site was put into maintenance mode)
169
+	 * @return EE_Config
170
+	 */
171
+	public static function reset($hard_reset = false, $reinstantiate = true)
172
+	{
173
+		if (self::$_instance instanceof EE_Config) {
174
+			if ($hard_reset) {
175
+				self::$_instance->legacy_shortcodes_manager = null;
176
+				self::$_instance->_addon_option_names = array();
177
+				self::$_instance->_initialize_config();
178
+				self::$_instance->update_espresso_config();
179
+			}
180
+			self::$_instance->update_addon_option_names();
181
+		}
182
+		self::$_instance = null;
183
+		// we don't need to reset the static properties imo because those should
184
+		// only change when a module is added or removed. Currently we don't
185
+		// support removing a module during a request when it previously existed
186
+		if ($reinstantiate) {
187
+			return self::instance();
188
+		} else {
189
+			return null;
190
+		}
191
+	}
192
+
193
+
194
+	/**
195
+	 *    class constructor
196
+	 *
197
+	 * @access    private
198
+	 */
199
+	private function __construct()
200
+	{
201
+		do_action('AHEE__EE_Config__construct__begin', $this);
202
+		EE_Config::$_logging_enabled = apply_filters('FHEE__EE_Config___construct__logging_enabled', false);
203
+		// setup empty config classes
204
+		$this->_initialize_config();
205
+		// load existing EE site settings
206
+		$this->_load_core_config();
207
+		// confirm everything loaded correctly and set filtered defaults if not
208
+		$this->_verify_config();
209
+		//  register shortcodes and modules
210
+		add_action(
211
+			'AHEE__EE_System__register_shortcodes_modules_and_widgets',
212
+			array($this, 'register_shortcodes_and_modules'),
213
+			999
214
+		);
215
+		//  initialize shortcodes and modules
216
+		add_action('AHEE__EE_System__core_loaded_and_ready', array($this, 'initialize_shortcodes_and_modules'));
217
+		// register widgets
218
+		add_action('widgets_init', array($this, 'widgets_init'), 10);
219
+		// shutdown
220
+		add_action('shutdown', array($this, 'shutdown'), 10);
221
+		// construct__end hook
222
+		do_action('AHEE__EE_Config__construct__end', $this);
223
+		// hardcoded hack
224
+		$this->template_settings->current_espresso_theme = 'Espresso_Arabica_2014';
225
+	}
226
+
227
+
228
+	/**
229
+	 * @return boolean
230
+	 */
231
+	public static function logging_enabled()
232
+	{
233
+		return self::$_logging_enabled;
234
+	}
235
+
236
+
237
+	/**
238
+	 * use to get the current theme if needed from static context
239
+	 *
240
+	 * @return string current theme set.
241
+	 */
242
+	public static function get_current_theme()
243
+	{
244
+		return isset(self::$_instance->template_settings->current_espresso_theme)
245
+			? self::$_instance->template_settings->current_espresso_theme : 'Espresso_Arabica_2014';
246
+	}
247
+
248
+
249
+	/**
250
+	 *        _initialize_config
251
+	 *
252
+	 * @access private
253
+	 * @return void
254
+	 */
255
+	private function _initialize_config()
256
+	{
257
+		EE_Config::trim_log();
258
+		// set defaults
259
+		$this->_addon_option_names = get_option(EE_Config::ADDON_OPTION_NAMES, array());
260
+		$this->addons = new stdClass();
261
+		// set _module_route_map
262
+		EE_Config::$_module_route_map = array();
263
+		// set _module_forward_map
264
+		EE_Config::$_module_forward_map = array();
265
+		// set _module_view_map
266
+		EE_Config::$_module_view_map = array();
267
+	}
268
+
269
+
270
+	/**
271
+	 *        load core plugin configuration
272
+	 *
273
+	 * @access private
274
+	 * @return void
275
+	 */
276
+	private function _load_core_config()
277
+	{
278
+		// load_core_config__start hook
279
+		do_action('AHEE__EE_Config___load_core_config__start', $this);
280
+		$espresso_config = $this->get_espresso_config();
281
+		foreach ($espresso_config as $config => $settings) {
282
+			// load_core_config__start hook
283
+			$settings = apply_filters(
284
+				'FHEE__EE_Config___load_core_config__config_settings',
285
+				$settings,
286
+				$config,
287
+				$this
288
+			);
289
+			if (is_object($settings) && property_exists($this, $config)) {
290
+				$this->{$config} = apply_filters('FHEE__EE_Config___load_core_config__' . $config, $settings);
291
+				// call configs populate method to ensure any defaults are set for empty values.
292
+				if (method_exists($settings, 'populate')) {
293
+					$this->{$config}->populate();
294
+				}
295
+				if (method_exists($settings, 'do_hooks')) {
296
+					$this->{$config}->do_hooks();
297
+				}
298
+			}
299
+		}
300
+		if (apply_filters('FHEE__EE_Config___load_core_config__update_espresso_config', false)) {
301
+			$this->update_espresso_config();
302
+		}
303
+		// load_core_config__end hook
304
+		do_action('AHEE__EE_Config___load_core_config__end', $this);
305
+	}
306
+
307
+
308
+	/**
309
+	 *    _verify_config
310
+	 *
311
+	 * @access    protected
312
+	 * @return    void
313
+	 */
314
+	protected function _verify_config()
315
+	{
316
+		$this->core = $this->core instanceof EE_Core_Config
317
+			? $this->core
318
+			: new EE_Core_Config();
319
+		$this->core = apply_filters('FHEE__EE_Config___initialize_config__core', $this->core);
320
+		$this->organization = $this->organization instanceof EE_Organization_Config
321
+			? $this->organization
322
+			: new EE_Organization_Config();
323
+		$this->organization = apply_filters(
324
+			'FHEE__EE_Config___initialize_config__organization',
325
+			$this->organization
326
+		);
327
+		$this->currency = $this->currency instanceof EE_Currency_Config
328
+			? $this->currency
329
+			: new EE_Currency_Config();
330
+		$this->currency = apply_filters('FHEE__EE_Config___initialize_config__currency', $this->currency);
331
+		$this->registration = $this->registration instanceof EE_Registration_Config
332
+			? $this->registration
333
+			: new EE_Registration_Config();
334
+		$this->registration = apply_filters(
335
+			'FHEE__EE_Config___initialize_config__registration',
336
+			$this->registration
337
+		);
338
+		$this->admin = $this->admin instanceof EE_Admin_Config
339
+			? $this->admin
340
+			: new EE_Admin_Config();
341
+		$this->admin = apply_filters('FHEE__EE_Config___initialize_config__admin', $this->admin);
342
+		$this->template_settings = $this->template_settings instanceof EE_Template_Config
343
+			? $this->template_settings
344
+			: new EE_Template_Config();
345
+		$this->template_settings = apply_filters(
346
+			'FHEE__EE_Config___initialize_config__template_settings',
347
+			$this->template_settings
348
+		);
349
+		$this->map_settings = $this->map_settings instanceof EE_Map_Config
350
+			? $this->map_settings
351
+			: new EE_Map_Config();
352
+		$this->map_settings = apply_filters(
353
+			'FHEE__EE_Config___initialize_config__map_settings',
354
+			$this->map_settings
355
+		);
356
+		$this->environment = $this->environment instanceof EE_Environment_Config
357
+			? $this->environment
358
+			: new EE_Environment_Config();
359
+		$this->environment = apply_filters(
360
+			'FHEE__EE_Config___initialize_config__environment',
361
+			$this->environment
362
+		);
363
+		$this->tax_settings = $this->tax_settings instanceof EE_Tax_Config
364
+			? $this->tax_settings
365
+			: new EE_Tax_Config();
366
+		$this->tax_settings = apply_filters(
367
+			'FHEE__EE_Config___initialize_config__tax_settings',
368
+			$this->tax_settings
369
+		);
370
+		$this->messages = apply_filters('FHEE__EE_Config__initialize_config__messages', $this->messages);
371
+		$this->messages = $this->messages instanceof EE_Messages_Config
372
+			? $this->messages
373
+			: new EE_Messages_Config();
374
+		$this->gateway = $this->gateway instanceof EE_Gateway_Config
375
+			? $this->gateway
376
+			: new EE_Gateway_Config();
377
+		$this->gateway = apply_filters('FHEE__EE_Config___initialize_config__gateway', $this->gateway);
378
+		$this->legacy_shortcodes_manager = null;
379
+	}
380
+
381
+
382
+	/**
383
+	 *    get_espresso_config
384
+	 *
385
+	 * @access    public
386
+	 * @return    array of espresso config stuff
387
+	 */
388
+	public function get_espresso_config()
389
+	{
390
+		// grab espresso configuration
391
+		return apply_filters(
392
+			'FHEE__EE_Config__get_espresso_config__CFG',
393
+			get_option(EE_Config::OPTION_NAME, array())
394
+		);
395
+	}
396
+
397
+
398
+	/**
399
+	 * @param string $option
400
+	 * @param mixed  $old_value
401
+	 * @param mixed  $value
402
+	 */
403
+	public function double_check_config_comparison(string $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
+		/** @var RequestInterface $request */
460
+		$request = LoaderFactory::getLoader()->getShared(RequestInterface::class);
461
+		if ($request->isWordPressHeartbeat()) {
462
+			return false;
463
+		}
464
+		// commented out the following re: https://events.codebasehq.com/projects/event-espresso/tickets/8197
465
+		// $clone = clone( self::$_instance );
466
+		// self::$_instance = NULL;
467
+		do_action('AHEE__EE_Config__update_espresso_config__begin', $this);
468
+		$this->_reset_espresso_addon_config();
469
+		// hook into update_option because that happens AFTER the ( $value === $old_value ) conditional
470
+		// but BEFORE the actual update occurs
471
+		add_action('update_option', array($this, 'double_check_config_comparison'), 1, 3);
472
+		// don't want to persist legacy_shortcodes_manager, but don't want to lose it either
473
+		$legacy_shortcodes_manager = $this->legacy_shortcodes_manager;
474
+		$this->legacy_shortcodes_manager = null;
475
+		// now update "ee_config"
476
+		$saved = update_option(EE_Config::OPTION_NAME, $this);
477
+		$this->legacy_shortcodes_manager = $legacy_shortcodes_manager;
478
+		EE_Config::log(EE_Config::OPTION_NAME);
479
+		// if not saved... check if the hook we just added still exists;
480
+		// if it does, it means one of two things:
481
+		// that update_option bailed at the($value === $old_value) conditional,
482
+		// or...
483
+		// the db update query returned 0 rows affected
484
+		// (probably because the data  value was the same from it's perspective)
485
+		// so the existence of the hook means that a negative result from update_option is NOT an error,
486
+		// but just means no update occurred, so don't display an error to the user.
487
+		// BUT... if update_option returns FALSE, AND the hook is missing,
488
+		// then it means that something truly went wrong
489
+		$saved = ! $saved ? has_action('update_option', array($this, 'double_check_config_comparison')) : $saved;
490
+		// remove our action since we don't want it in the system anymore
491
+		remove_action('update_option', array($this, 'double_check_config_comparison'), 1);
492
+		do_action('AHEE__EE_Config__update_espresso_config__end', $this, $saved);
493
+		// self::$_instance = $clone;
494
+		// unset( $clone );
495
+		// if config remains the same or was updated successfully
496
+		if ($saved) {
497
+			if ($add_success) {
498
+				EE_Error::add_success(
499
+					esc_html__('The Event Espresso Configuration Settings have been successfully updated.', 'event_espresso'),
500
+					__FILE__,
501
+					__FUNCTION__,
502
+					__LINE__
503
+				);
504
+			}
505
+			return true;
506
+		} else {
507
+			if ($add_error) {
508
+				EE_Error::add_error(
509
+					esc_html__('The Event Espresso Configuration Settings were not updated.', 'event_espresso'),
510
+					__FILE__,
511
+					__FUNCTION__,
512
+					__LINE__
513
+				);
514
+			}
515
+			return false;
516
+		}
517
+	}
518
+
519
+
520
+	/**
521
+	 *    _verify_config_params
522
+	 *
523
+	 * @access    private
524
+	 * @param    string         $section
525
+	 * @param    string         $name
526
+	 * @param    string         $config_class
527
+	 * @param    EE_Config_Base $config_obj
528
+	 * @param    array          $tests_to_run
529
+	 * @param    bool           $display_errors
530
+	 * @return    bool    TRUE on success, FALSE on fail
531
+	 */
532
+	private function _verify_config_params(
533
+		$section = '',
534
+		$name = '',
535
+		$config_class = '',
536
+		$config_obj = null,
537
+		$tests_to_run = array(1, 2, 3, 4, 5, 6, 7, 8),
538
+		$display_errors = true
539
+	) {
540
+		try {
541
+			foreach ($tests_to_run as $test) {
542
+				switch ($test) {
543
+					// TEST #1 : check that section was set
544
+					case 1:
545
+						if (empty($section)) {
546
+							if ($display_errors) {
547
+								throw new EE_Error(
548
+									sprintf(
549
+										esc_html__(
550
+											'No configuration section has been provided while attempting to save "%s".',
551
+											'event_espresso'
552
+										),
553
+										$config_class
554
+									)
555
+								);
556
+							}
557
+							return false;
558
+						}
559
+						break;
560
+					// TEST #2 : check that settings section exists
561
+					case 2:
562
+						if (! isset($this->{$section})) {
563
+							if ($display_errors) {
564
+								throw new EE_Error(
565
+									sprintf(
566
+										esc_html__('The "%s" configuration section does not exist.', 'event_espresso'),
567
+										$section
568
+									)
569
+								);
570
+							}
571
+							return false;
572
+						}
573
+						break;
574
+					// TEST #3 : check that section is the proper format
575
+					case 3:
576
+						if (
577
+							! ($this->{$section} instanceof EE_Config_Base || $this->{$section} instanceof stdClass)
578
+						) {
579
+							if ($display_errors) {
580
+								throw new EE_Error(
581
+									sprintf(
582
+										esc_html__(
583
+											'The "%s" configuration settings have not been formatted correctly.',
584
+											'event_espresso'
585
+										),
586
+										$section
587
+									)
588
+								);
589
+							}
590
+							return false;
591
+						}
592
+						break;
593
+					// TEST #4 : check that config section name has been set
594
+					case 4:
595
+						if (empty($name)) {
596
+							if ($display_errors) {
597
+								throw new EE_Error(
598
+									esc_html__(
599
+										'No name has been provided for the specific configuration section.',
600
+										'event_espresso'
601
+									)
602
+								);
603
+							}
604
+							return false;
605
+						}
606
+						break;
607
+					// TEST #5 : check that a config class name has been set
608
+					case 5:
609
+						if (empty($config_class)) {
610
+							if ($display_errors) {
611
+								throw new EE_Error(
612
+									esc_html__(
613
+										'No class name has been provided for the specific configuration section.',
614
+										'event_espresso'
615
+									)
616
+								);
617
+							}
618
+							return false;
619
+						}
620
+						break;
621
+					// TEST #6 : verify config class is accessible
622
+					case 6:
623
+						if (! class_exists($config_class)) {
624
+							if ($display_errors) {
625
+								throw new EE_Error(
626
+									sprintf(
627
+										esc_html__(
628
+											'The "%s" class does not exist. Please ensure that an autoloader has been set for it.',
629
+											'event_espresso'
630
+										),
631
+										$config_class
632
+									)
633
+								);
634
+							}
635
+							return false;
636
+						}
637
+						break;
638
+					// TEST #7 : check that config has even been set
639
+					case 7:
640
+						if (! isset($this->{$section}->{$name})) {
641
+							if ($display_errors) {
642
+								throw new EE_Error(
643
+									sprintf(
644
+										esc_html__('No configuration has been set for "%1$s->%2$s".', 'event_espresso'),
645
+										$section,
646
+										$name
647
+									)
648
+								);
649
+							}
650
+							return false;
651
+						} else {
652
+							// and make sure it's not serialized
653
+							$this->{$section}->{$name} = maybe_unserialize($this->{$section}->{$name});
654
+						}
655
+						break;
656
+					// TEST #8 : check that config is the requested type
657
+					case 8:
658
+						if (! $this->{$section}->{$name} instanceof $config_class) {
659
+							if ($display_errors) {
660
+								throw new EE_Error(
661
+									sprintf(
662
+										esc_html__(
663
+											'The configuration for "%1$s->%2$s" is not of the "%3$s" class.',
664
+											'event_espresso'
665
+										),
666
+										$section,
667
+										$name,
668
+										$config_class
669
+									)
670
+								);
671
+							}
672
+							return false;
673
+						}
674
+						break;
675
+					// TEST #9 : verify config object
676
+					case 9:
677
+						if (! $config_obj instanceof EE_Config_Base) {
678
+							if ($display_errors) {
679
+								throw new EE_Error(
680
+									sprintf(
681
+										esc_html__('The "%s" class is not an instance of EE_Config_Base.', 'event_espresso'),
682
+										print_r($config_obj, true)
683
+									)
684
+								);
685
+							}
686
+							return false;
687
+						}
688
+						break;
689
+				}
690
+			}
691
+		} catch (EE_Error $e) {
692
+			$e->get_error();
693
+		}
694
+		// you have successfully run the gauntlet
695
+		return true;
696
+	}
697
+
698
+
699
+	/**
700
+	 *    _generate_config_option_name
701
+	 *
702
+	 * @access        protected
703
+	 * @param        string $section
704
+	 * @param        string $name
705
+	 * @return        string
706
+	 */
707
+	private function _generate_config_option_name($section = '', $name = '')
708
+	{
709
+		return 'ee_config-' . strtolower($section . '-' . str_replace(array('EE_', 'EED_'), '', $name));
710
+	}
711
+
712
+
713
+	/**
714
+	 *    _set_config_class
715
+	 * ensures that a config class is set, either from a passed config class or one generated from the config name
716
+	 *
717
+	 * @access    private
718
+	 * @param    string $config_class
719
+	 * @param    string $name
720
+	 * @return    string
721
+	 */
722
+	private function _set_config_class($config_class = '', $name = '')
723
+	{
724
+		return ! empty($config_class)
725
+			? $config_class
726
+			: str_replace(' ', '_', ucwords(str_replace('_', ' ', $name))) . '_Config';
727
+	}
728
+
729
+
730
+	/**
731
+	 *    set_config
732
+	 *
733
+	 * @access    protected
734
+	 * @param    string         $section
735
+	 * @param    string         $name
736
+	 * @param    string         $config_class
737
+	 * @param    EE_Config_Base $config_obj
738
+	 * @return    EE_Config_Base
739
+	 */
740
+	public function set_config($section = '', $name = '', $config_class = '', EE_Config_Base $config_obj = null)
741
+	{
742
+		// ensure config class is set to something
743
+		$config_class = $this->_set_config_class($config_class, $name);
744
+		// run tests 1-4, 6, and 7 to verify all config params are set and valid
745
+		if (! $this->_verify_config_params($section, $name, $config_class, null, array(1, 2, 3, 4, 5, 6))) {
746
+			return null;
747
+		}
748
+		$config_option_name = $this->_generate_config_option_name($section, $name);
749
+		// if the config option name hasn't been added yet to the list of option names we're tracking, then do so now
750
+		if (! isset($this->_addon_option_names[ $config_option_name ])) {
751
+			$this->_addon_option_names[ $config_option_name ] = $config_class;
752
+			$this->update_addon_option_names();
753
+		}
754
+		// verify the incoming config object but suppress errors
755
+		if (! $this->_verify_config_params($section, $name, $config_class, $config_obj, array(9), false)) {
756
+			$config_obj = new $config_class();
757
+		}
758
+		if (get_option($config_option_name)) {
759
+			EE_Config::log($config_option_name);
760
+			update_option($config_option_name, $config_obj);
761
+			$this->{$section}->{$name} = $config_obj;
762
+			return $this->{$section}->{$name};
763
+		} else {
764
+			// create a wp-option for this config
765
+			if (add_option($config_option_name, $config_obj, '', 'no')) {
766
+				$this->{$section}->{$name} = maybe_unserialize($config_obj);
767
+				return $this->{$section}->{$name};
768
+			} else {
769
+				EE_Error::add_error(
770
+					sprintf(esc_html__('The "%s" could not be saved to the database.', 'event_espresso'), $config_class),
771
+					__FILE__,
772
+					__FUNCTION__,
773
+					__LINE__
774
+				);
775
+				return null;
776
+			}
777
+		}
778
+	}
779
+
780
+
781
+	/**
782
+	 *    update_config
783
+	 * Important: the config object must ALREADY be set, otherwise this will produce an error.
784
+	 *
785
+	 * @access    public
786
+	 * @param    string                $section
787
+	 * @param    string                $name
788
+	 * @param    EE_Config_Base|string $config_obj
789
+	 * @param    bool                  $throw_errors
790
+	 * @return    bool
791
+	 */
792
+	public function update_config($section = '', $name = '', $config_obj = '', $throw_errors = true)
793
+	{
794
+		// don't allow config updates during WP heartbeats
795
+		/** @var RequestInterface $request */
796
+		$request = LoaderFactory::getLoader()->getShared(RequestInterface::class);
797
+		if ($request->isWordPressHeartbeat()) {
798
+			return false;
799
+		}
800
+		$config_obj = maybe_unserialize($config_obj);
801
+		// get class name of the incoming object
802
+		$config_class = get_class($config_obj);
803
+		// run tests 1-5 and 9 to verify config
804
+		if (
805
+			! $this->_verify_config_params(
806
+				$section,
807
+				$name,
808
+				$config_class,
809
+				$config_obj,
810
+				array(1, 2, 3, 4, 7, 9)
811
+			)
812
+		) {
813
+			return false;
814
+		}
815
+		$config_option_name = $this->_generate_config_option_name($section, $name);
816
+		// check if config object has been added to db by seeing if config option name is in $this->_addon_option_names array
817
+		if (! isset($this->_addon_option_names[ $config_option_name ])) {
818
+			// save new config to db
819
+			if ($this->set_config($section, $name, $config_class, $config_obj)) {
820
+				return true;
821
+			}
822
+		} else {
823
+			// first check if the record already exists
824
+			$existing_config = get_option($config_option_name);
825
+			$config_obj = serialize($config_obj);
826
+			// just return if db record is already up to date (NOT type safe comparison)
827
+			if ($existing_config == $config_obj) {
828
+				$this->{$section}->{$name} = $config_obj;
829
+				return true;
830
+			} elseif (update_option($config_option_name, $config_obj)) {
831
+				EE_Config::log($config_option_name);
832
+				// update wp-option for this config class
833
+				$this->{$section}->{$name} = $config_obj;
834
+				return true;
835
+			} elseif ($throw_errors) {
836
+				EE_Error::add_error(
837
+					sprintf(
838
+						esc_html__(
839
+							'The "%1$s" object stored at"%2$s" was not successfully updated in the database.',
840
+							'event_espresso'
841
+						),
842
+						$config_class,
843
+						'EE_Config->' . $section . '->' . $name
844
+					),
845
+					__FILE__,
846
+					__FUNCTION__,
847
+					__LINE__
848
+				);
849
+			}
850
+		}
851
+		return false;
852
+	}
853
+
854
+
855
+	/**
856
+	 *    get_config
857
+	 *
858
+	 * @access    public
859
+	 * @param    string $section
860
+	 * @param    string $name
861
+	 * @param    string $config_class
862
+	 * @return    mixed EE_Config_Base | NULL
863
+	 */
864
+	public function get_config($section = '', $name = '', $config_class = '')
865
+	{
866
+		// ensure config class is set to something
867
+		$config_class = $this->_set_config_class($config_class, $name);
868
+		// run tests 1-4, 6 and 7 to verify that all params have been set
869
+		if (! $this->_verify_config_params($section, $name, $config_class, null, array(1, 2, 3, 4, 5, 6))) {
870
+			return null;
871
+		}
872
+		// now test if the requested config object exists, but suppress errors
873
+		if ($this->_verify_config_params($section, $name, $config_class, null, array(7, 8), false)) {
874
+			// config already exists, so pass it back
875
+			return $this->{$section}->{$name};
876
+		}
877
+		// load config option from db if it exists
878
+		$config_obj = $this->get_config_option($this->_generate_config_option_name($section, $name));
879
+		// verify the newly retrieved config object, but suppress errors
880
+		if ($this->_verify_config_params($section, $name, $config_class, $config_obj, array(9), false)) {
881
+			// config is good, so set it and pass it back
882
+			$this->{$section}->{$name} = $config_obj;
883
+			return $this->{$section}->{$name};
884
+		}
885
+		// oops! $config_obj is not already set and does not exist in the db, so create a new one
886
+		$config_obj = $this->set_config($section, $name, $config_class);
887
+		// verify the newly created config object
888
+		if ($this->_verify_config_params($section, $name, $config_class, $config_obj, array(9))) {
889
+			return $this->{$section}->{$name};
890
+		} else {
891
+			EE_Error::add_error(
892
+				sprintf(esc_html__('The "%s" could not be retrieved from the database.', 'event_espresso'), $config_class),
893
+				__FILE__,
894
+				__FUNCTION__,
895
+				__LINE__
896
+			);
897
+		}
898
+		return null;
899
+	}
900
+
901
+
902
+	/**
903
+	 *    get_config_option
904
+	 *
905
+	 * @access    public
906
+	 * @param    string $config_option_name
907
+	 * @return    mixed EE_Config_Base | FALSE
908
+	 */
909
+	public function get_config_option($config_option_name = '')
910
+	{
911
+		// retrieve the wp-option for this config class.
912
+		$config_option = maybe_unserialize(get_option($config_option_name, array()));
913
+		if (empty($config_option)) {
914
+			EE_Config::log($config_option_name . '-NOT-FOUND');
915
+		}
916
+		return $config_option;
917
+	}
918
+
919
+
920
+	/**
921
+	 * log
922
+	 *
923
+	 * @param string $config_option_name
924
+	 */
925
+	public static function log($config_option_name = '')
926
+	{
927
+		if (EE_Config::logging_enabled() && ! empty($config_option_name)) {
928
+			$config_log = get_option(EE_Config::LOG_NAME, array());
929
+			/** @var RequestParams $request */
930
+			$request = LoaderFactory::getLoader()->getShared(RequestParams::class);
931
+			$config_log[ (string) microtime(true) ] = array(
932
+				'config_name' => $config_option_name,
933
+				'request'     => $request->requestParams(),
934
+			);
935
+			update_option(EE_Config::LOG_NAME, $config_log);
936
+		}
937
+	}
938
+
939
+
940
+	/**
941
+	 * trim_log
942
+	 * reduces the size of the config log to the length specified by EE_Config::LOG_LENGTH
943
+	 */
944
+	public static function trim_log()
945
+	{
946
+		if (! EE_Config::logging_enabled()) {
947
+			return;
948
+		}
949
+		$config_log = maybe_unserialize(get_option(EE_Config::LOG_NAME, array()));
950
+		$log_length = count($config_log);
951
+		if ($log_length > EE_Config::LOG_LENGTH) {
952
+			ksort($config_log);
953
+			$config_log = array_slice($config_log, $log_length - EE_Config::LOG_LENGTH, null, true);
954
+			update_option(EE_Config::LOG_NAME, $config_log);
955
+		}
956
+	}
957
+
958
+
959
+	/**
960
+	 *    get_page_for_posts
961
+	 *    if the wp-option "show_on_front" is set to "page", then this is the post_name for the post set in the
962
+	 *    wp-option "page_for_posts", or "posts" if no page is selected
963
+	 *
964
+	 * @access    public
965
+	 * @return    string
966
+	 */
967
+	public static function get_page_for_posts()
968
+	{
969
+		$page_for_posts = get_option('page_for_posts');
970
+		if (! $page_for_posts) {
971
+			return 'posts';
972
+		}
973
+		global $wpdb;
974
+		$SQL = "SELECT post_name from $wpdb->posts WHERE post_type='posts' OR post_type='page' AND post_status='publish' AND ID=%d";
975
+		return $wpdb->get_var($wpdb->prepare($SQL, $page_for_posts));
976
+	}
977
+
978
+
979
+	/**
980
+	 *    register_shortcodes_and_modules.
981
+	 *    At this point, it's too early to tell if we're maintenance mode or not.
982
+	 *    In fact, this is where we give modules a chance to let core know they exist
983
+	 *    so they can help trigger maintenance mode if it's needed
984
+	 *
985
+	 * @access    public
986
+	 * @return    void
987
+	 */
988
+	public function register_shortcodes_and_modules()
989
+	{
990
+		// allow modules to set hooks for the rest of the system
991
+		EE_Registry::instance()->modules = $this->_register_modules();
992
+	}
993
+
994
+
995
+	/**
996
+	 *    initialize_shortcodes_and_modules
997
+	 *    meaning they can start adding their hooks to get stuff done
998
+	 *
999
+	 * @access    public
1000
+	 * @return    void
1001
+	 */
1002
+	public function initialize_shortcodes_and_modules()
1003
+	{
1004
+		// allow modules to set hooks for the rest of the system
1005
+		$this->_initialize_modules();
1006
+	}
1007
+
1008
+
1009
+	/**
1010
+	 *    widgets_init
1011
+	 *
1012
+	 * @access private
1013
+	 * @return void
1014
+	 */
1015
+	public function widgets_init()
1016
+	{
1017
+		// only init widgets on admin pages when not in complete maintenance, and
1018
+		// on frontend when not in any maintenance mode
1019
+		if (
1020
+			! EE_Maintenance_Mode::instance()->level()
1021
+			|| (
1022
+				is_admin()
1023
+				&& EE_Maintenance_Mode::instance()->level() !== EE_Maintenance_Mode::level_2_complete_maintenance
1024
+			)
1025
+		) {
1026
+			// grab list of installed widgets
1027
+			$widgets_to_register = glob(EE_WIDGETS . '*', GLOB_ONLYDIR);
1028
+			// filter list of modules to register
1029
+			$widgets_to_register = apply_filters(
1030
+				'FHEE__EE_Config__register_widgets__widgets_to_register',
1031
+				$widgets_to_register
1032
+			);
1033
+			if (! empty($widgets_to_register)) {
1034
+				// cycle thru widget folders
1035
+				foreach ($widgets_to_register as $widget_path) {
1036
+					// add to list of installed widget modules
1037
+					EE_Config::register_ee_widget($widget_path);
1038
+				}
1039
+			}
1040
+			// filter list of installed modules
1041
+			EE_Registry::instance()->widgets = apply_filters(
1042
+				'FHEE__EE_Config__register_widgets__installed_widgets',
1043
+				EE_Registry::instance()->widgets
1044
+			);
1045
+		}
1046
+	}
1047
+
1048
+
1049
+	/**
1050
+	 *    register_ee_widget - makes core aware of this widget
1051
+	 *
1052
+	 * @access    public
1053
+	 * @param    string $widget_path - full path up to and including widget folder
1054
+	 * @return    void
1055
+	 */
1056
+	public static function register_ee_widget($widget_path = null)
1057
+	{
1058
+		do_action('AHEE__EE_Config__register_widget__begin', $widget_path);
1059
+		$widget_ext = '.widget.php';
1060
+		// make all separators match
1061
+		$widget_path = rtrim(str_replace('\\', DS, $widget_path), DS);
1062
+		// does the file path INCLUDE the actual file name as part of the path ?
1063
+		if (strpos($widget_path, $widget_ext) !== false) {
1064
+			// grab and shortcode file name from directory name and break apart at dots
1065
+			$file_name = explode('.', basename($widget_path));
1066
+			// take first segment from file name pieces and remove class prefix if it exists
1067
+			$widget = strpos($file_name[0], 'EEW_') === 0 ? substr($file_name[0], 4) : $file_name[0];
1068
+			// sanitize shortcode directory name
1069
+			$widget = sanitize_key($widget);
1070
+			// now we need to rebuild the shortcode path
1071
+			$widget_path = explode('/', $widget_path);
1072
+			// remove last segment
1073
+			array_pop($widget_path);
1074
+			// glue it back together
1075
+			$widget_path = implode(DS, $widget_path);
1076
+		} else {
1077
+			// grab and sanitize widget directory name
1078
+			$widget = sanitize_key(basename($widget_path));
1079
+		}
1080
+		// create classname from widget directory name
1081
+		$widget = str_replace(' ', '_', ucwords(str_replace('_', ' ', $widget)));
1082
+		// add class prefix
1083
+		$widget_class = 'EEW_' . $widget;
1084
+		// does the widget exist ?
1085
+		if (! is_readable($widget_path . '/' . $widget_class . $widget_ext)) {
1086
+			$msg = sprintf(
1087
+				esc_html__(
1088
+					'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',
1089
+					'event_espresso'
1090
+				),
1091
+				$widget_class,
1092
+				$widget_path . '/' . $widget_class . $widget_ext
1093
+			);
1094
+			EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__);
1095
+			return;
1096
+		}
1097
+		// load the widget class file
1098
+		require_once($widget_path . '/' . $widget_class . $widget_ext);
1099
+		// verify that class exists
1100
+		if (! class_exists($widget_class)) {
1101
+			$msg = sprintf(esc_html__('The requested %s widget class does not exist.', 'event_espresso'), $widget_class);
1102
+			EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__);
1103
+			return;
1104
+		}
1105
+		register_widget($widget_class);
1106
+		// add to array of registered widgets
1107
+		EE_Registry::instance()->widgets->{$widget_class} = $widget_path . '/' . $widget_class . $widget_ext;
1108
+	}
1109
+
1110
+
1111
+	/**
1112
+	 *        _register_modules
1113
+	 *
1114
+	 * @access private
1115
+	 * @return array
1116
+	 */
1117
+	private function _register_modules()
1118
+	{
1119
+		// grab list of installed modules
1120
+		$modules_to_register = glob(EE_MODULES . '*', GLOB_ONLYDIR);
1121
+		// filter list of modules to register
1122
+		$modules_to_register = apply_filters(
1123
+			'FHEE__EE_Config__register_modules__modules_to_register',
1124
+			$modules_to_register
1125
+		);
1126
+		if (! empty($modules_to_register)) {
1127
+			// loop through folders
1128
+			foreach ($modules_to_register as $module_path) {
1129
+				/**TEMPORARILY EXCLUDE gateways from modules for time being**/
1130
+				if (
1131
+					$module_path !== EE_MODULES . 'zzz-copy-this-module-template'
1132
+					&& $module_path !== EE_MODULES . 'gateways'
1133
+				) {
1134
+					// add to list of installed modules
1135
+					EE_Config::register_module($module_path);
1136
+				}
1137
+			}
1138
+		}
1139
+		// filter list of installed modules
1140
+		return apply_filters(
1141
+			'FHEE__EE_Config___register_modules__installed_modules',
1142
+			EE_Registry::instance()->modules
1143
+		);
1144
+	}
1145
+
1146
+
1147
+	/**
1148
+	 *    register_module - makes core aware of this module
1149
+	 *
1150
+	 * @access    public
1151
+	 * @param    string $module_path - full path up to and including module folder
1152
+	 * @return    bool
1153
+	 */
1154
+	public static function register_module($module_path = null)
1155
+	{
1156
+		do_action('AHEE__EE_Config__register_module__begin', $module_path);
1157
+		$module_ext = '.module.php';
1158
+		// make all separators match
1159
+		$module_path = str_replace(array('\\', '/'), '/', $module_path);
1160
+		// does the file path INCLUDE the actual file name as part of the path ?
1161
+		if (strpos($module_path, $module_ext) !== false) {
1162
+			// grab and shortcode file name from directory name and break apart at dots
1163
+			$module_file = explode('.', basename($module_path));
1164
+			// now we need to rebuild the shortcode path
1165
+			$module_path = explode('/', $module_path);
1166
+			// remove last segment
1167
+			array_pop($module_path);
1168
+			// glue it back together
1169
+			$module_path = implode('/', $module_path) . '/';
1170
+			// take first segment from file name pieces and sanitize it
1171
+			$module = preg_replace('/[^a-zA-Z0-9_\-]/', '', $module_file[0]);
1172
+			// ensure class prefix is added
1173
+			$module_class = strpos($module, 'EED_') !== 0 ? 'EED_' . $module : $module;
1174
+		} else {
1175
+			// we need to generate the filename based off of the folder name
1176
+			// grab and sanitize module name
1177
+			$module = strtolower(basename($module_path));
1178
+			$module = preg_replace('/[^a-z0-9_\-]/', '', $module);
1179
+			// like trailingslashit()
1180
+			$module_path = rtrim($module_path, '/') . '/';
1181
+			// create classname from module directory name
1182
+			$module = str_replace(' ', '_', ucwords(str_replace('_', ' ', $module)));
1183
+			// add class prefix
1184
+			$module_class = 'EED_' . $module;
1185
+		}
1186
+		// does the module exist ?
1187
+		if (! is_readable($module_path . '/' . $module_class . $module_ext)) {
1188
+			$msg = sprintf(
1189
+				esc_html__(
1190
+					'The requested %s module file could not be found or is not readable due to file permissions.',
1191
+					'event_espresso'
1192
+				),
1193
+				$module
1194
+			);
1195
+			EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__);
1196
+			return false;
1197
+		}
1198
+		// load the module class file
1199
+		require_once($module_path . $module_class . $module_ext);
1200
+		// verify that class exists
1201
+		if (! class_exists($module_class)) {
1202
+			$msg = sprintf(esc_html__('The requested %s module class does not exist.', 'event_espresso'), $module_class);
1203
+			EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__);
1204
+			return false;
1205
+		}
1206
+		// add to array of registered modules
1207
+		EE_Registry::instance()->modules->{$module_class} = $module_path . $module_class . $module_ext;
1208
+		do_action(
1209
+			'AHEE__EE_Config__register_module__complete',
1210
+			$module_class,
1211
+			EE_Registry::instance()->modules->{$module_class}
1212
+		);
1213
+		return true;
1214
+	}
1215
+
1216
+
1217
+	/**
1218
+	 *    _initialize_modules
1219
+	 *    allow modules to set hooks for the rest of the system
1220
+	 *
1221
+	 * @access private
1222
+	 * @return void
1223
+	 */
1224
+	private function _initialize_modules()
1225
+	{
1226
+		// cycle thru shortcode folders
1227
+		foreach (EE_Registry::instance()->modules as $module_class => $module_path) {
1228
+			// fire the shortcode class's set_hooks methods in case it needs to hook into other parts of the system
1229
+			// which set hooks ?
1230
+			if (is_admin()) {
1231
+				// fire immediately
1232
+				call_user_func(array($module_class, 'set_hooks_admin'));
1233
+			} else {
1234
+				// delay until other systems are online
1235
+				add_action(
1236
+					'AHEE__EE_System__set_hooks_for_shortcodes_modules_and_addons',
1237
+					array($module_class, 'set_hooks')
1238
+				);
1239
+			}
1240
+		}
1241
+	}
1242
+
1243
+
1244
+	/**
1245
+	 *    register_route - adds module method routes to route_map
1246
+	 *
1247
+	 * @access    public
1248
+	 * @param    string $route       - "pretty" public alias for module method
1249
+	 * @param    string $module      - module name (classname without EED_ prefix)
1250
+	 * @param    string $method_name - the actual module method to be routed to
1251
+	 * @param    string $key         - url param key indicating a route is being called
1252
+	 * @return    bool
1253
+	 */
1254
+	public static function register_route($route = null, $module = null, $method_name = null, $key = 'ee')
1255
+	{
1256
+		do_action('AHEE__EE_Config__register_route__begin', $route, $module, $method_name);
1257
+		$module = str_replace('EED_', '', $module);
1258
+		$module_class = 'EED_' . $module;
1259
+		if (! isset(EE_Registry::instance()->modules->{$module_class})) {
1260
+			$msg = sprintf(esc_html__('The module %s has not been registered.', 'event_espresso'), $module);
1261
+			EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__);
1262
+			return false;
1263
+		}
1264
+		if (empty($route)) {
1265
+			$msg = sprintf(esc_html__('No route has been supplied.', 'event_espresso'), $route);
1266
+			EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__);
1267
+			return false;
1268
+		}
1269
+		if (! method_exists('EED_' . $module, $method_name)) {
1270
+			$msg = sprintf(
1271
+				esc_html__('A valid class method for the %s route has not been supplied.', 'event_espresso'),
1272
+				$route
1273
+			);
1274
+			EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__);
1275
+			return false;
1276
+		}
1277
+		EE_Config::$_module_route_map[ (string) $key ][ (string) $route ] = array('EED_' . $module, $method_name);
1278
+		return true;
1279
+	}
1280
+
1281
+
1282
+	/**
1283
+	 *    get_route - get module method route
1284
+	 *
1285
+	 * @access    public
1286
+	 * @param    string $route - "pretty" public alias for module method
1287
+	 * @param    string $key   - url param key indicating a route is being called
1288
+	 * @return    string
1289
+	 */
1290
+	public static function get_route($route = null, $key = 'ee')
1291
+	{
1292
+		do_action('AHEE__EE_Config__get_route__begin', $route);
1293
+		$route = (string) apply_filters('FHEE__EE_Config__get_route', $route);
1294
+		if (isset(EE_Config::$_module_route_map[ $key ][ $route ])) {
1295
+			return EE_Config::$_module_route_map[ $key ][ $route ];
1296
+		}
1297
+		return null;
1298
+	}
1299
+
1300
+
1301
+	/**
1302
+	 *    get_routes - get ALL module method routes
1303
+	 *
1304
+	 * @access    public
1305
+	 * @return    array
1306
+	 */
1307
+	public static function get_routes()
1308
+	{
1309
+		return EE_Config::$_module_route_map;
1310
+	}
1311
+
1312
+
1313
+	/**
1314
+	 *    register_forward - allows modules to forward request to another module for further processing
1315
+	 *
1316
+	 * @access    public
1317
+	 * @param    string       $route   - "pretty" public alias for module method
1318
+	 * @param    integer      $status  - integer value corresponding  to status constant strings set in module parent
1319
+	 *                                 class, allows different forwards to be served based on status
1320
+	 * @param    array|string $forward - function name or array( class, method )
1321
+	 * @param    string       $key     - url param key indicating a route is being called
1322
+	 * @return    bool
1323
+	 */
1324
+	public static function register_forward($route = null, $status = 0, $forward = null, $key = 'ee')
1325
+	{
1326
+		do_action('AHEE__EE_Config__register_forward', $route, $status, $forward);
1327
+		if (! isset(EE_Config::$_module_route_map[ $key ][ $route ]) || empty($route)) {
1328
+			$msg = sprintf(
1329
+				esc_html__('The module route %s for this forward has not been registered.', 'event_espresso'),
1330
+				$route
1331
+			);
1332
+			EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__);
1333
+			return false;
1334
+		}
1335
+		if (empty($forward)) {
1336
+			$msg = sprintf(esc_html__('No forwarding route has been supplied.', 'event_espresso'), $route);
1337
+			EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__);
1338
+			return false;
1339
+		}
1340
+		if (is_array($forward)) {
1341
+			if (! isset($forward[1])) {
1342
+				$msg = sprintf(
1343
+					esc_html__('A class method for the %s forwarding route has not been supplied.', 'event_espresso'),
1344
+					$route
1345
+				);
1346
+				EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__);
1347
+				return false;
1348
+			}
1349
+			if (! method_exists($forward[0], $forward[1])) {
1350
+				$msg = sprintf(
1351
+					esc_html__('The class method %s for the %s forwarding route is in invalid.', 'event_espresso'),
1352
+					$forward[1],
1353
+					$route
1354
+				);
1355
+				EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__);
1356
+				return false;
1357
+			}
1358
+		} elseif (! function_exists($forward)) {
1359
+			$msg = sprintf(
1360
+				esc_html__('The function %s for the %s forwarding route is in invalid.', 'event_espresso'),
1361
+				$forward,
1362
+				$route
1363
+			);
1364
+			EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__);
1365
+			return false;
1366
+		}
1367
+		EE_Config::$_module_forward_map[ $key ][ $route ][ absint($status) ] = $forward;
1368
+		return true;
1369
+	}
1370
+
1371
+
1372
+	/**
1373
+	 *    get_forward - get forwarding route
1374
+	 *
1375
+	 * @access    public
1376
+	 * @param    string  $route  - "pretty" public alias for module method
1377
+	 * @param    integer $status - integer value corresponding  to status constant strings set in module parent class,
1378
+	 *                           allows different forwards to be served based on status
1379
+	 * @param    string  $key    - url param key indicating a route is being called
1380
+	 * @return    string
1381
+	 */
1382
+	public static function get_forward($route = null, $status = 0, $key = 'ee')
1383
+	{
1384
+		do_action('AHEE__EE_Config__get_forward__begin', $route, $status);
1385
+		if (isset(EE_Config::$_module_forward_map[ $key ][ $route ][ $status ])) {
1386
+			return apply_filters(
1387
+				'FHEE__EE_Config__get_forward',
1388
+				EE_Config::$_module_forward_map[ $key ][ $route ][ $status ],
1389
+				$route,
1390
+				$status
1391
+			);
1392
+		}
1393
+		return null;
1394
+	}
1395
+
1396
+
1397
+	/**
1398
+	 *    register_forward - allows modules to specify different view templates for different method routes and status
1399
+	 *    results
1400
+	 *
1401
+	 * @access    public
1402
+	 * @param    string  $route  - "pretty" public alias for module method
1403
+	 * @param    integer $status - integer value corresponding  to status constant strings set in module parent class,
1404
+	 *                           allows different views to be served based on status
1405
+	 * @param    string  $view
1406
+	 * @param    string  $key    - url param key indicating a route is being called
1407
+	 * @return    bool
1408
+	 */
1409
+	public static function register_view($route = null, $status = 0, $view = null, $key = 'ee')
1410
+	{
1411
+		do_action('AHEE__EE_Config__register_view__begin', $route, $status, $view);
1412
+		if (! isset(EE_Config::$_module_route_map[ $key ][ $route ]) || empty($route)) {
1413
+			$msg = sprintf(
1414
+				esc_html__('The module route %s for this view has not been registered.', 'event_espresso'),
1415
+				$route
1416
+			);
1417
+			EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__);
1418
+			return false;
1419
+		}
1420
+		if (! is_readable($view)) {
1421
+			$msg = sprintf(
1422
+				esc_html__(
1423
+					'The %s view file could not be found or is not readable due to file permissions.',
1424
+					'event_espresso'
1425
+				),
1426
+				$view
1427
+			);
1428
+			EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__);
1429
+			return false;
1430
+		}
1431
+		EE_Config::$_module_view_map[ $key ][ $route ][ absint($status) ] = $view;
1432
+		return true;
1433
+	}
1434
+
1435
+
1436
+	/**
1437
+	 *    get_view - get view for route and status
1438
+	 *
1439
+	 * @access    public
1440
+	 * @param    string  $route  - "pretty" public alias for module method
1441
+	 * @param    integer $status - integer value corresponding  to status constant strings set in module parent class,
1442
+	 *                           allows different views to be served based on status
1443
+	 * @param    string  $key    - url param key indicating a route is being called
1444
+	 * @return    string
1445
+	 */
1446
+	public static function get_view($route = null, $status = 0, $key = 'ee')
1447
+	{
1448
+		do_action('AHEE__EE_Config__get_view__begin', $route, $status);
1449
+		if (isset(EE_Config::$_module_view_map[ $key ][ $route ][ $status ])) {
1450
+			return apply_filters(
1451
+				'FHEE__EE_Config__get_view',
1452
+				EE_Config::$_module_view_map[ $key ][ $route ][ $status ],
1453
+				$route,
1454
+				$status
1455
+			);
1456
+		}
1457
+		return null;
1458
+	}
1459
+
1460
+
1461
+	public function update_addon_option_names()
1462
+	{
1463
+		update_option(EE_Config::ADDON_OPTION_NAMES, $this->_addon_option_names);
1464
+	}
1465
+
1466
+
1467
+	public function shutdown()
1468
+	{
1469
+		$this->update_addon_option_names();
1470
+	}
1471
+
1472
+
1473
+	/**
1474
+	 * @return LegacyShortcodesManager
1475
+	 */
1476
+	public static function getLegacyShortcodesManager()
1477
+	{
1478
+		if (! EE_Config::instance()->legacy_shortcodes_manager instanceof LegacyShortcodesManager) {
1479
+			EE_Config::instance()->legacy_shortcodes_manager = LoaderFactory::getLoader()->getShared(
1480
+				LegacyShortcodesManager::class
1481
+			);
1482
+		}
1483
+		return EE_Config::instance()->legacy_shortcodes_manager;
1484
+	}
1485
+
1486
+
1487
+	/**
1488
+	 * register_shortcode - makes core aware of this shortcode
1489
+	 *
1490
+	 * @deprecated 4.9.26
1491
+	 * @param    string $shortcode_path - full path up to and including shortcode folder
1492
+	 * @return    bool
1493
+	 */
1494
+	public static function register_shortcode($shortcode_path = null)
1495
+	{
1496
+		EE_Error::doing_it_wrong(
1497
+			__METHOD__,
1498
+			esc_html__(
1499
+				'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.',
1500
+				'event_espresso'
1501
+			),
1502
+			'4.9.26'
1503
+		);
1504
+		return EE_Config::instance()->getLegacyShortcodesManager()->registerShortcode($shortcode_path);
1505
+	}
1506
+}
2302 1507
 
2303
-    /**
2304
-     * ReCaptcha width
2305
-     *
2306
-     * @var int $recaptcha_width
2307
-     * @deprecated
2308
-     */
2309
-    public $recaptcha_width;
1508
+/**
1509
+ * Base class used for config classes. These classes should generally not have
1510
+ * magic functions in use, except we'll allow them to magically set and get stuff...
1511
+ * basically, they should just be well-defined stdClasses
1512
+ */
1513
+class EE_Config_Base
1514
+{
1515
+	/**
1516
+	 * Utility function for escaping the value of a property and returning.
1517
+	 *
1518
+	 * @param string $property property name (checks to see if exists).
1519
+	 * @return mixed if a detected type found return the escaped value, otherwise just the raw value is returned.
1520
+	 * @throws EE_Error
1521
+	 */
1522
+	public function get_pretty($property)
1523
+	{
1524
+		if (! property_exists($this, $property)) {
1525
+			throw new EE_Error(
1526
+				sprintf(
1527
+					esc_html__(
1528
+						'%1$s::get_pretty() has been called with the property %2$s which does not exist on the %1$s config class.',
1529
+						'event_espresso'
1530
+					),
1531
+					get_class($this),
1532
+					$property
1533
+				)
1534
+			);
1535
+		}
1536
+		// just handling escaping of strings for now.
1537
+		if (is_string($this->{$property})) {
1538
+			return stripslashes($this->{$property});
1539
+		}
1540
+		return $this->{$property};
1541
+	}
1542
+
1543
+
1544
+	public function populate()
1545
+	{
1546
+		// grab defaults via a new instance of this class.
1547
+		$class_name = get_class($this);
1548
+		$defaults = new $class_name();
1549
+		// loop through the properties for this class and see if they are set.  If they are NOT, then grab the
1550
+		// default from our $defaults object.
1551
+		foreach (get_object_vars($defaults) as $property => $value) {
1552
+			if ($this->{$property} === null) {
1553
+				$this->{$property} = $value;
1554
+			}
1555
+		}
1556
+		// cleanup
1557
+		unset($defaults);
1558
+	}
1559
+
1560
+
1561
+	/**
1562
+	 *        __isset
1563
+	 *
1564
+	 * @param $a
1565
+	 * @return bool
1566
+	 */
1567
+	public function __isset($a)
1568
+	{
1569
+		return false;
1570
+	}
1571
+
1572
+
1573
+	/**
1574
+	 *        __unset
1575
+	 *
1576
+	 * @param $a
1577
+	 * @return bool
1578
+	 */
1579
+	public function __unset($a)
1580
+	{
1581
+		return false;
1582
+	}
1583
+
1584
+
1585
+	/**
1586
+	 *        __clone
1587
+	 */
1588
+	public function __clone()
1589
+	{
1590
+	}
1591
+
1592
+
1593
+	/**
1594
+	 *        __wakeup
1595
+	 */
1596
+	public function __wakeup()
1597
+	{
1598
+	}
1599
+
1600
+
1601
+	/**
1602
+	 *        __destruct
1603
+	 */
1604
+	public function __destruct()
1605
+	{
1606
+	}
1607
+}
2310 1608
 
2311
-    /**
2312
-     * Whether or not invalid attempts to directly access the registration checkout page should be tracked.
2313
-     *
2314
-     * @var boolean $track_invalid_checkout_access
2315
-     */
2316
-    protected $track_invalid_checkout_access = true;
1609
+/**
1610
+ * Class for defining what's in the EE_Config relating to registration settings
1611
+ */
1612
+class EE_Core_Config extends EE_Config_Base
1613
+{
1614
+	const OPTION_NAME_UXIP = 'ee_ueip_optin';
1615
+
1616
+
1617
+	public $current_blog_id;
1618
+
1619
+	public $ee_ueip_optin;
1620
+
1621
+	public $ee_ueip_has_notified;
1622
+
1623
+	/**
1624
+	 * Not to be confused with the 4 critical page variables (See
1625
+	 * get_critical_pages_array()), this is just an array of wp posts that have EE
1626
+	 * shortcodes in them. Keys are slugs, values are arrays with only 1 element: where the key is the shortcode
1627
+	 * in the page, and the value is the page's ID. The key 'posts' is basically a duplicate of this same array.
1628
+	 *
1629
+	 * @var array
1630
+	 */
1631
+	public $post_shortcodes;
1632
+
1633
+	public $module_route_map;
1634
+
1635
+	public $module_forward_map;
1636
+
1637
+	public $module_view_map;
1638
+
1639
+	/**
1640
+	 * The next 4 vars are the IDs of critical EE pages.
1641
+	 *
1642
+	 * @var int
1643
+	 */
1644
+	public $reg_page_id;
1645
+
1646
+	public $txn_page_id;
1647
+
1648
+	public $thank_you_page_id;
1649
+
1650
+	public $cancel_page_id;
1651
+
1652
+	/**
1653
+	 * The next 4 vars are the URLs of critical EE pages.
1654
+	 *
1655
+	 * @var int
1656
+	 */
1657
+	public $reg_page_url;
1658
+
1659
+	public $txn_page_url;
1660
+
1661
+	public $thank_you_page_url;
1662
+
1663
+	public $cancel_page_url;
1664
+
1665
+	/**
1666
+	 * The next vars relate to the custom slugs for EE CPT routes
1667
+	 */
1668
+	public $event_cpt_slug;
1669
+
1670
+	/**
1671
+	 * This caches the _ee_ueip_option in case this config is reset in the same
1672
+	 * request across blog switches in a multisite context.
1673
+	 * Avoids extra queries to the db for this option.
1674
+	 *
1675
+	 * @var bool
1676
+	 */
1677
+	public static $ee_ueip_option;
1678
+
1679
+
1680
+	/**
1681
+	 *    class constructor
1682
+	 *
1683
+	 * @access    public
1684
+	 */
1685
+	public function __construct()
1686
+	{
1687
+		// set default organization settings
1688
+		$this->current_blog_id = get_current_blog_id();
1689
+		$this->current_blog_id = $this->current_blog_id === null ? 1 : $this->current_blog_id;
1690
+		$this->ee_ueip_optin = $this->_get_main_ee_ueip_optin();
1691
+		$this->ee_ueip_has_notified = is_main_site() ? get_option('ee_ueip_has_notified', false) : true;
1692
+		$this->post_shortcodes = array();
1693
+		$this->module_route_map = array();
1694
+		$this->module_forward_map = array();
1695
+		$this->module_view_map = array();
1696
+		// critical EE page IDs
1697
+		$this->reg_page_id = 0;
1698
+		$this->txn_page_id = 0;
1699
+		$this->thank_you_page_id = 0;
1700
+		$this->cancel_page_id = 0;
1701
+		// critical EE page URLs
1702
+		$this->reg_page_url = '';
1703
+		$this->txn_page_url = '';
1704
+		$this->thank_you_page_url = '';
1705
+		$this->cancel_page_url = '';
1706
+		// cpt slugs
1707
+		$this->event_cpt_slug = esc_html__('events', 'event_espresso');
1708
+		// ueip constant check
1709
+		if (defined('EE_DISABLE_UXIP') && EE_DISABLE_UXIP) {
1710
+			$this->ee_ueip_optin = false;
1711
+			$this->ee_ueip_has_notified = true;
1712
+		}
1713
+	}
1714
+
1715
+
1716
+	/**
1717
+	 * @return array
1718
+	 */
1719
+	public function get_critical_pages_array()
1720
+	{
1721
+		return array(
1722
+			$this->reg_page_id,
1723
+			$this->txn_page_id,
1724
+			$this->thank_you_page_id,
1725
+			$this->cancel_page_id,
1726
+		);
1727
+	}
1728
+
1729
+
1730
+	/**
1731
+	 * @return array
1732
+	 */
1733
+	public function get_critical_pages_shortcodes_array()
1734
+	{
1735
+		return array(
1736
+			$this->reg_page_id       => 'ESPRESSO_CHECKOUT',
1737
+			$this->txn_page_id       => 'ESPRESSO_TXN_PAGE',
1738
+			$this->thank_you_page_id => 'ESPRESSO_THANK_YOU',
1739
+			$this->cancel_page_id    => 'ESPRESSO_CANCELLED',
1740
+		);
1741
+	}
1742
+
1743
+
1744
+	/**
1745
+	 *  gets/returns URL for EE reg_page
1746
+	 *
1747
+	 * @access    public
1748
+	 * @return    string
1749
+	 */
1750
+	public function reg_page_url()
1751
+	{
1752
+		if (! $this->reg_page_url) {
1753
+			$this->reg_page_url = add_query_arg(
1754
+				array('uts' => time()),
1755
+				get_permalink($this->reg_page_id)
1756
+			) . '#checkout';
1757
+		}
1758
+		return $this->reg_page_url;
1759
+	}
1760
+
1761
+
1762
+	/**
1763
+	 *  gets/returns URL for EE txn_page
1764
+	 *
1765
+	 * @param array $query_args like what gets passed to
1766
+	 *                          add_query_arg() as the first argument
1767
+	 * @access    public
1768
+	 * @return    string
1769
+	 */
1770
+	public function txn_page_url($query_args = array())
1771
+	{
1772
+		if (! $this->txn_page_url) {
1773
+			$this->txn_page_url = get_permalink($this->txn_page_id);
1774
+		}
1775
+		if ($query_args) {
1776
+			return add_query_arg($query_args, $this->txn_page_url);
1777
+		} else {
1778
+			return $this->txn_page_url;
1779
+		}
1780
+	}
1781
+
1782
+
1783
+	/**
1784
+	 *  gets/returns URL for EE thank_you_page
1785
+	 *
1786
+	 * @param array $query_args like what gets passed to
1787
+	 *                          add_query_arg() as the first argument
1788
+	 * @access    public
1789
+	 * @return    string
1790
+	 */
1791
+	public function thank_you_page_url($query_args = array())
1792
+	{
1793
+		if (! $this->thank_you_page_url) {
1794
+			$this->thank_you_page_url = get_permalink($this->thank_you_page_id);
1795
+		}
1796
+		if ($query_args) {
1797
+			return add_query_arg($query_args, $this->thank_you_page_url);
1798
+		} else {
1799
+			return $this->thank_you_page_url;
1800
+		}
1801
+	}
1802
+
1803
+
1804
+	/**
1805
+	 *  gets/returns URL for EE cancel_page
1806
+	 *
1807
+	 * @access    public
1808
+	 * @return    string
1809
+	 */
1810
+	public function cancel_page_url()
1811
+	{
1812
+		if (! $this->cancel_page_url) {
1813
+			$this->cancel_page_url = get_permalink($this->cancel_page_id);
1814
+		}
1815
+		return $this->cancel_page_url;
1816
+	}
1817
+
1818
+
1819
+	/**
1820
+	 * Resets all critical page urls to their original state.  Used primarily by the __sleep() magic method currently.
1821
+	 *
1822
+	 * @since 4.7.5
1823
+	 */
1824
+	protected function _reset_urls()
1825
+	{
1826
+		$this->reg_page_url = '';
1827
+		$this->txn_page_url = '';
1828
+		$this->cancel_page_url = '';
1829
+		$this->thank_you_page_url = '';
1830
+	}
1831
+
1832
+
1833
+	/**
1834
+	 * Used to return what the optin value is set for the EE User Experience Program.
1835
+	 * This accounts for multisite and this value being requested for a subsite.  In multisite, the value is set
1836
+	 * on the main site only.
1837
+	 *
1838
+	 * @return bool
1839
+	 */
1840
+	protected function _get_main_ee_ueip_optin()
1841
+	{
1842
+		// if this is the main site then we can just bypass our direct query.
1843
+		if (is_main_site()) {
1844
+			return get_option(self::OPTION_NAME_UXIP, false);
1845
+		}
1846
+		// is this already cached for this request?  If so use it.
1847
+		if (EE_Core_Config::$ee_ueip_option !== null) {
1848
+			return EE_Core_Config::$ee_ueip_option;
1849
+		}
1850
+		global $wpdb;
1851
+		$current_network_main_site = is_multisite() ? get_current_site() : null;
1852
+		$current_main_site_id = ! empty($current_network_main_site) ? $current_network_main_site->blog_id : 1;
1853
+		$option = self::OPTION_NAME_UXIP;
1854
+		// set correct table for query
1855
+		$table_name = $wpdb->get_blog_prefix($current_main_site_id) . 'options';
1856
+		// rather than getting blog option for the $current_main_site_id, we do a direct $wpdb query because
1857
+		// get_blog_option() does a switch_to_blog an that could cause infinite recursion because EE_Core_Config might be
1858
+		// re-constructed on the blog switch.  Note, we are still executing any core wp filters on this option retrieval.
1859
+		// this bit of code is basically a direct copy of get_option without any caching because we are NOT switched to the blog
1860
+		// for the purpose of caching.
1861
+		$pre = apply_filters('pre_option_' . $option, false, $option);
1862
+		if (false !== $pre) {
1863
+			EE_Core_Config::$ee_ueip_option = $pre;
1864
+			return EE_Core_Config::$ee_ueip_option;
1865
+		}
1866
+		$row = $wpdb->get_row(
1867
+			$wpdb->prepare(
1868
+				"SELECT option_value FROM $table_name WHERE option_name = %s LIMIT 1",
1869
+				$option
1870
+			)
1871
+		);
1872
+		if (is_object($row)) {
1873
+			$value = $row->option_value;
1874
+		} else { // option does not exist so use default.
1875
+			EE_Core_Config::$ee_ueip_option =  apply_filters('default_option_' . $option, false, $option);
1876
+			return EE_Core_Config::$ee_ueip_option;
1877
+		}
1878
+		EE_Core_Config::$ee_ueip_option = apply_filters('option_' . $option, maybe_unserialize($value), $option);
1879
+		return EE_Core_Config::$ee_ueip_option;
1880
+	}
1881
+
1882
+
1883
+	/**
1884
+	 * Utility function for escaping the value of a property and returning.
1885
+	 *
1886
+	 * @param string $property property name (checks to see if exists).
1887
+	 * @return mixed if a detected type found return the escaped value, otherwise just the raw value is returned.
1888
+	 * @throws EE_Error
1889
+	 */
1890
+	public function get_pretty($property)
1891
+	{
1892
+		if ($property === self::OPTION_NAME_UXIP) {
1893
+			return $this->ee_ueip_optin ? 'yes' : 'no';
1894
+		}
1895
+		return parent::get_pretty($property);
1896
+	}
1897
+
1898
+
1899
+	/**
1900
+	 * Currently used to ensure critical page urls have initial values saved to the db instead of any current set values
1901
+	 * on the object.
1902
+	 *
1903
+	 * @return array
1904
+	 */
1905
+	public function __sleep()
1906
+	{
1907
+		// reset all url properties
1908
+		$this->_reset_urls();
1909
+		// return what to save to db
1910
+		return array_keys(get_object_vars($this));
1911
+	}
1912
+}
2317 1913
 
2318
-    /**
2319
-     * Whether or not to show the privacy policy consent checkbox
2320
-     *
2321
-     * @var bool
2322
-     */
2323
-    public $consent_checkbox_enabled;
1914
+/**
1915
+ * Config class for storing info on the Organization
1916
+ */
1917
+class EE_Organization_Config extends EE_Config_Base
1918
+{
1919
+	/**
1920
+	 * @var string $name
1921
+	 * eg EE4.1
1922
+	 */
1923
+	public $name;
1924
+
1925
+	/**
1926
+	 * @var string $address_1
1927
+	 * eg 123 Onna Road
1928
+	 */
1929
+	public $address_1 = '';
1930
+
1931
+	/**
1932
+	 * @var string $address_2
1933
+	 * eg PO Box 123
1934
+	 */
1935
+	public $address_2 = '';
1936
+
1937
+	/**
1938
+	 * @var string $city
1939
+	 * eg Inna City
1940
+	 */
1941
+	public $city = '';
1942
+
1943
+	/**
1944
+	 * @var int $STA_ID
1945
+	 * eg 4
1946
+	 */
1947
+	public $STA_ID = 0;
1948
+
1949
+	/**
1950
+	 * @var string $CNT_ISO
1951
+	 * eg US
1952
+	 */
1953
+	public $CNT_ISO = '';
1954
+
1955
+	/**
1956
+	 * @var string $zip
1957
+	 * eg 12345  or V1A 2B3
1958
+	 */
1959
+	public $zip = '';
1960
+
1961
+	/**
1962
+	 * @var string $email
1963
+	 * eg [email protected]
1964
+	 */
1965
+	public $email;
1966
+
1967
+	/**
1968
+	 * @var string $phone
1969
+	 * eg. 111-111-1111
1970
+	 */
1971
+	public $phone = '';
1972
+
1973
+	/**
1974
+	 * @var string $vat
1975
+	 * VAT/Tax Number
1976
+	 */
1977
+	public $vat = '';
1978
+
1979
+	/**
1980
+	 * @var string $logo_url
1981
+	 * eg http://www.somedomain.com/wp-content/uploads/kittehs.jpg
1982
+	 */
1983
+	public $logo_url = '';
1984
+
1985
+	/**
1986
+	 * The below are all various properties for holding links to organization social network profiles
1987
+	 *
1988
+	 * @var string
1989
+	 */
1990
+	/**
1991
+	 * facebook (facebook.com/profile.name)
1992
+	 *
1993
+	 * @var string
1994
+	 */
1995
+	public $facebook = '';
1996
+
1997
+	/**
1998
+	 * twitter (twitter.com/twitter_handle)
1999
+	 *
2000
+	 * @var string
2001
+	 */
2002
+	public $twitter = '';
2003
+
2004
+	/**
2005
+	 * linkedin (linkedin.com/in/profile_name)
2006
+	 *
2007
+	 * @var string
2008
+	 */
2009
+	public $linkedin = '';
2010
+
2011
+	/**
2012
+	 * pinterest (www.pinterest.com/profile_name)
2013
+	 *
2014
+	 * @var string
2015
+	 */
2016
+	public $pinterest = '';
2017
+
2018
+	/**
2019
+	 * google+ (google.com/+profileName)
2020
+	 *
2021
+	 * @var string
2022
+	 */
2023
+	public $google = '';
2024
+
2025
+	/**
2026
+	 * instagram (instagram.com/handle)
2027
+	 *
2028
+	 * @var string
2029
+	 */
2030
+	public $instagram = '';
2031
+
2032
+
2033
+	/**
2034
+	 *    class constructor
2035
+	 *
2036
+	 * @access    public
2037
+	 */
2038
+	public function __construct()
2039
+	{
2040
+		// set default organization settings
2041
+		// decode HTML entities from the WP blogname, because it's stored in the DB with HTML entities encoded
2042
+		$this->name = wp_specialchars_decode(get_bloginfo('name'), ENT_QUOTES);
2043
+		$this->email = get_bloginfo('admin_email');
2044
+	}
2045
+}
2324 2046
 
2325
-    /**
2326
-     * Label text to show on the checkbox
2327
-     *
2328
-     * @var string
2329
-     */
2330
-    public $consent_checkbox_label_text;
2047
+/**
2048
+ * Class for defining what's in the EE_Config relating to currency
2049
+ */
2050
+class EE_Currency_Config extends EE_Config_Base
2051
+{
2052
+	/**
2053
+	 * @var string $code
2054
+	 * eg 'US'
2055
+	 */
2056
+	public $code;
2057
+
2058
+	/**
2059
+	 * @var string $name
2060
+	 * eg 'Dollar'
2061
+	 */
2062
+	public $name;
2063
+
2064
+	/**
2065
+	 * plural name
2066
+	 *
2067
+	 * @var string $plural
2068
+	 * eg 'Dollars'
2069
+	 */
2070
+	public $plural;
2071
+
2072
+	/**
2073
+	 * currency sign
2074
+	 *
2075
+	 * @var string $sign
2076
+	 * eg '$'
2077
+	 */
2078
+	public $sign;
2079
+
2080
+	/**
2081
+	 * Whether the currency sign should come before the number or not
2082
+	 *
2083
+	 * @var boolean $sign_b4
2084
+	 */
2085
+	public $sign_b4;
2086
+
2087
+	/**
2088
+	 * How many digits should come after the decimal place
2089
+	 *
2090
+	 * @var int $dec_plc
2091
+	 */
2092
+	public $dec_plc;
2093
+
2094
+	/**
2095
+	 * Symbol to use for decimal mark
2096
+	 *
2097
+	 * @var string $dec_mrk
2098
+	 * eg '.'
2099
+	 */
2100
+	public $dec_mrk;
2101
+
2102
+	/**
2103
+	 * Symbol to use for thousands
2104
+	 *
2105
+	 * @var string $thsnds
2106
+	 * eg ','
2107
+	 */
2108
+	public $thsnds;
2109
+
2110
+
2111
+	/**
2112
+	 *    class constructor
2113
+	 *
2114
+	 * @access    public
2115
+	 * @param string $CNT_ISO
2116
+	 * @throws EE_Error
2117
+	 * @throws ReflectionException
2118
+	 */
2119
+	public function __construct($CNT_ISO = '')
2120
+	{
2121
+		/** @var TableAnalysis $table_analysis */
2122
+		$table_analysis = EE_Registry::instance()->create('TableAnalysis', array(), true);
2123
+		// get country code from organization settings or use default
2124
+		$ORG_CNT = isset(EE_Registry::instance()->CFG->organization)
2125
+				   && EE_Registry::instance()->CFG->organization instanceof EE_Organization_Config
2126
+			? EE_Registry::instance()->CFG->organization->CNT_ISO
2127
+			: '';
2128
+		// but override if requested
2129
+		$CNT_ISO = ! empty($CNT_ISO) ? $CNT_ISO : $ORG_CNT;
2130
+		// 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
2131
+		if (
2132
+			! empty($CNT_ISO)
2133
+			&& EE_Maintenance_Mode::instance()->models_can_query()
2134
+			&& $table_analysis->tableExists(EE_Registry::instance()->load_model('Country')->table())
2135
+		) {
2136
+			// retrieve the country settings from the db, just in case they have been customized
2137
+			$country = EE_Registry::instance()->load_model('Country')->get_one_by_ID($CNT_ISO);
2138
+			if ($country instanceof EE_Country) {
2139
+				$this->code = $country->currency_code();    // currency code: USD, CAD, EUR
2140
+				$this->name = $country->currency_name_single();    // Dollar
2141
+				$this->plural = $country->currency_name_plural();    // Dollars
2142
+				$this->sign = $country->currency_sign();            // currency sign: $
2143
+				$this->sign_b4 = $country->currency_sign_before(
2144
+				);        // currency sign before or after: $TRUE  or  FALSE$
2145
+				$this->dec_plc = $country->currency_decimal_places();    // decimal places: 2 = 0.00  3 = 0.000
2146
+				$this->dec_mrk = $country->currency_decimal_mark(
2147
+				);    // decimal mark: (comma) ',' = 0,01   or (decimal) '.' = 0.01
2148
+				$this->thsnds = $country->currency_thousands_separator(
2149
+				);    // thousands separator: (comma) ',' = 1,000   or (decimal) '.' = 1.000
2150
+			}
2151
+		}
2152
+		// fallback to hardcoded defaults, in case the above failed
2153
+		if (empty($this->code)) {
2154
+			// set default currency settings
2155
+			$this->code = 'USD';    // currency code: USD, CAD, EUR
2156
+			$this->name = esc_html__('Dollar', 'event_espresso');    // Dollar
2157
+			$this->plural = esc_html__('Dollars', 'event_espresso');    // Dollars
2158
+			$this->sign = '$';    // currency sign: $
2159
+			$this->sign_b4 = true;    // currency sign before or after: $TRUE  or  FALSE$
2160
+			$this->dec_plc = 2;    // decimal places: 2 = 0.00  3 = 0.000
2161
+			$this->dec_mrk = '.';    // decimal mark: (comma) ',' = 0,01   or (decimal) '.' = 0.01
2162
+			$this->thsnds = ',';    // thousands separator: (comma) ',' = 1,000   or (decimal) '.' = 1.000
2163
+		}
2164
+	}
2165
+}
2331 2166
 
2332
-    /*
2167
+/**
2168
+ * Class for defining what's in the EE_Config relating to registration settings
2169
+ */
2170
+class EE_Registration_Config extends EE_Config_Base
2171
+{
2172
+	/**
2173
+	 * Default registration status
2174
+	 *
2175
+	 * @var string $default_STS_ID
2176
+	 * eg 'RPP'
2177
+	 */
2178
+	public $default_STS_ID;
2179
+
2180
+	/**
2181
+	 * For new events, this will be the default value for the maximum number of tickets (equivalent to maximum number of
2182
+	 * registrations)
2183
+	 *
2184
+	 * @var int
2185
+	 */
2186
+	public $default_maximum_number_of_tickets;
2187
+
2188
+	/**
2189
+	 * level of validation to apply to email addresses
2190
+	 *
2191
+	 * @var string $email_validation_level
2192
+	 * options: 'basic', 'wp_default', 'i18n', 'i18n_dns'
2193
+	 */
2194
+	public $email_validation_level;
2195
+
2196
+	/**
2197
+	 *    whether or not to show alternate payment options during the reg process if payment status is pending
2198
+	 *
2199
+	 * @var boolean $show_pending_payment_options
2200
+	 */
2201
+	public $show_pending_payment_options;
2202
+
2203
+	/**
2204
+	 * Whether to skip the registration confirmation page
2205
+	 *
2206
+	 * @var boolean $skip_reg_confirmation
2207
+	 */
2208
+	public $skip_reg_confirmation;
2209
+
2210
+	/**
2211
+	 * an array of SPCO reg steps where:
2212
+	 *        the keys denotes the reg step order
2213
+	 *        each element consists of an array with the following elements:
2214
+	 *            "file_path" => the file path to the EE_SPCO_Reg_Step class
2215
+	 *            "class_name" => the specific EE_SPCO_Reg_Step child class name
2216
+	 *            "slug" => the URL param used to trigger the reg step
2217
+	 *
2218
+	 * @var array $reg_steps
2219
+	 */
2220
+	public $reg_steps;
2221
+
2222
+	/**
2223
+	 * Whether registration confirmation should be the last page of SPCO
2224
+	 *
2225
+	 * @var boolean $reg_confirmation_last
2226
+	 */
2227
+	public $reg_confirmation_last;
2228
+
2229
+	/**
2230
+	 * Whether or not to enable the EE Bot Trap
2231
+	 *
2232
+	 * @var boolean $use_bot_trap
2233
+	 */
2234
+	public $use_bot_trap;
2235
+
2236
+	/**
2237
+	 * Whether or not to encrypt some data sent by the EE Bot Trap
2238
+	 *
2239
+	 * @var boolean $use_encryption
2240
+	 */
2241
+	public $use_encryption;
2242
+
2243
+	/**
2244
+	 * Whether or not to use ReCaptcha
2245
+	 *
2246
+	 * @var boolean $use_captcha
2247
+	 */
2248
+	public $use_captcha;
2249
+
2250
+	/**
2251
+	 * ReCaptcha Theme
2252
+	 *
2253
+	 * @var string $recaptcha_theme
2254
+	 *    options: 'dark', 'light', 'invisible'
2255
+	 */
2256
+	public $recaptcha_theme;
2257
+
2258
+	/**
2259
+	 * ReCaptcha Badge - determines the position of the reCAPTCHA badge if using Invisible ReCaptcha.
2260
+	 *
2261
+	 * @var string $recaptcha_badge
2262
+	 *    options: 'bottomright', 'bottomleft', 'inline'
2263
+	 */
2264
+	public $recaptcha_badge;
2265
+
2266
+	/**
2267
+	 * ReCaptcha Type
2268
+	 *
2269
+	 * @var string $recaptcha_type
2270
+	 *    options: 'audio', 'image'
2271
+	 */
2272
+	public $recaptcha_type;
2273
+
2274
+	/**
2275
+	 * ReCaptcha language
2276
+	 *
2277
+	 * @var string $recaptcha_language
2278
+	 * eg 'en'
2279
+	 */
2280
+	public $recaptcha_language;
2281
+
2282
+	/**
2283
+	 * ReCaptcha public key
2284
+	 *
2285
+	 * @var string $recaptcha_publickey
2286
+	 */
2287
+	public $recaptcha_publickey;
2288
+
2289
+	/**
2290
+	 * ReCaptcha private key
2291
+	 *
2292
+	 * @var string $recaptcha_privatekey
2293
+	 */
2294
+	public $recaptcha_privatekey;
2295
+
2296
+	/**
2297
+	 * array of form names protected by ReCaptcha
2298
+	 *
2299
+	 * @var array $recaptcha_protected_forms
2300
+	 */
2301
+	public $recaptcha_protected_forms;
2302
+
2303
+	/**
2304
+	 * ReCaptcha width
2305
+	 *
2306
+	 * @var int $recaptcha_width
2307
+	 * @deprecated
2308
+	 */
2309
+	public $recaptcha_width;
2310
+
2311
+	/**
2312
+	 * Whether or not invalid attempts to directly access the registration checkout page should be tracked.
2313
+	 *
2314
+	 * @var boolean $track_invalid_checkout_access
2315
+	 */
2316
+	protected $track_invalid_checkout_access = true;
2317
+
2318
+	/**
2319
+	 * Whether or not to show the privacy policy consent checkbox
2320
+	 *
2321
+	 * @var bool
2322
+	 */
2323
+	public $consent_checkbox_enabled;
2324
+
2325
+	/**
2326
+	 * Label text to show on the checkbox
2327
+	 *
2328
+	 * @var string
2329
+	 */
2330
+	public $consent_checkbox_label_text;
2331
+
2332
+	/*
2333 2333
      * String describing how long to keep payment logs. Passed into DateTime constructor
2334 2334
      * @var string
2335 2335
      */
2336
-    public $gateway_log_lifespan = '1 week';
2337
-
2338
-    /**
2339
-     * Enable copy attendee info at form
2340
-     *
2341
-     * @var boolean $enable_copy_attendee
2342
-     */
2343
-    protected $copy_attendee_info = true;
2344
-
2345
-
2346
-    /**
2347
-     *    class constructor
2348
-     *
2349
-     * @access    public
2350
-     */
2351
-    public function __construct()
2352
-    {
2353
-        // set default registration settings
2354
-        $this->default_STS_ID = EEM_Registration::status_id_pending_payment;
2355
-        $this->email_validation_level = 'wp_default';
2356
-        $this->show_pending_payment_options = true;
2357
-        $this->skip_reg_confirmation = true;
2358
-        $this->reg_steps = array();
2359
-        $this->reg_confirmation_last = false;
2360
-        $this->use_bot_trap = true;
2361
-        $this->use_encryption = true;
2362
-        $this->use_captcha = false;
2363
-        $this->recaptcha_theme = 'light';
2364
-        $this->recaptcha_badge = 'bottomleft';
2365
-        $this->recaptcha_type = 'image';
2366
-        $this->recaptcha_language = 'en';
2367
-        $this->recaptcha_publickey = null;
2368
-        $this->recaptcha_privatekey = null;
2369
-        $this->recaptcha_protected_forms = array();
2370
-        $this->recaptcha_width = 500;
2371
-        $this->default_maximum_number_of_tickets = 10;
2372
-        $this->consent_checkbox_enabled = false;
2373
-        $this->consent_checkbox_label_text = '';
2374
-        $this->gateway_log_lifespan = '7 days';
2375
-        $this->copy_attendee_info = true;
2376
-    }
2377
-
2378
-
2379
-    /**
2380
-     * This is called by the config loader and hooks are initialized AFTER the config has been populated.
2381
-     *
2382
-     * @since 4.8.8.rc.019
2383
-     */
2384
-    public function do_hooks()
2385
-    {
2386
-        add_action('AHEE__EE_Config___load_core_config__end', array($this, 'set_default_reg_status_on_EEM_Event'));
2387
-        add_action('AHEE__EE_Config___load_core_config__end', array($this, 'set_default_max_ticket_on_EEM_Event'));
2388
-        add_action('setup_theme', array($this, 'setDefaultCheckboxLabelText'));
2389
-    }
2390
-
2391
-
2392
-    /**
2393
-     * Hooked into `AHEE__EE_Config___load_core_config__end` to ensure the default for the
2394
-     * EVT_default_registration_status field matches the config setting for default_STS_ID.
2395
-     */
2396
-    public function set_default_reg_status_on_EEM_Event()
2397
-    {
2398
-        EEM_Event::set_default_reg_status($this->default_STS_ID);
2399
-    }
2400
-
2401
-
2402
-    /**
2403
-     * Hooked into `AHEE__EE_Config___load_core_config__end` to ensure the default for the EVT_additional_limit field
2404
-     * for Events matches the config setting for default_maximum_number_of_tickets
2405
-     */
2406
-    public function set_default_max_ticket_on_EEM_Event()
2407
-    {
2408
-        EEM_Event::set_default_additional_limit($this->default_maximum_number_of_tickets);
2409
-    }
2410
-
2411
-
2412
-    /**
2413
-     * Sets the default consent checkbox text. This needs to be done a bit later than when EE_Registration_Config is
2414
-     * constructed because that happens before we can get the privacy policy page's permalink.
2415
-     *
2416
-     * @throws InvalidArgumentException
2417
-     * @throws InvalidDataTypeException
2418
-     * @throws InvalidInterfaceException
2419
-     */
2420
-    public function setDefaultCheckboxLabelText()
2421
-    {
2422
-        if (
2423
-            $this->getConsentCheckboxLabelText() === null
2424
-            || $this->getConsentCheckboxLabelText() === ''
2425
-        ) {
2426
-            $opening_a_tag = '';
2427
-            $closing_a_tag = '';
2428
-            if (function_exists('get_privacy_policy_url')) {
2429
-                $privacy_page_url = get_privacy_policy_url();
2430
-                if (! empty($privacy_page_url)) {
2431
-                    $opening_a_tag = '<a href="' . $privacy_page_url . '" target="_blank">';
2432
-                    $closing_a_tag = '</a>';
2433
-                }
2434
-            }
2435
-            $loader = LoaderFactory::getLoader();
2436
-            $org_config = $loader->getShared('EE_Organization_Config');
2437
-            /**
2438
-             * @var $org_config EE_Organization_Config
2439
-             */
2440
-
2441
-            $this->setConsentCheckboxLabelText(
2442
-                sprintf(
2443
-                    esc_html__(
2444
-                        'I consent to %1$s storing and using my personal information, according to their %2$sprivacy policy%3$s.',
2445
-                        'event_espresso'
2446
-                    ),
2447
-                    $org_config->name,
2448
-                    $opening_a_tag,
2449
-                    $closing_a_tag
2450
-                )
2451
-            );
2452
-        }
2453
-    }
2454
-
2455
-
2456
-    /**
2457
-     * @return boolean
2458
-     */
2459
-    public function track_invalid_checkout_access()
2460
-    {
2461
-        return $this->track_invalid_checkout_access;
2462
-    }
2463
-
2464
-
2465
-    /**
2466
-     * @param boolean $track_invalid_checkout_access
2467
-     */
2468
-    public function set_track_invalid_checkout_access($track_invalid_checkout_access)
2469
-    {
2470
-        $this->track_invalid_checkout_access = filter_var(
2471
-            $track_invalid_checkout_access,
2472
-            FILTER_VALIDATE_BOOLEAN
2473
-        );
2474
-    }
2475
-
2476
-    /**
2477
-     * @return boolean
2478
-     */
2479
-    public function copyAttendeeInfo()
2480
-    {
2481
-        return $this->copy_attendee_info;
2482
-    }
2483
-
2484
-
2485
-    /**
2486
-     * @param boolean $copy_attendee_info
2487
-     */
2488
-    public function setCopyAttendeeInfo($copy_attendee_info)
2489
-    {
2490
-        $this->copy_attendee_info = filter_var(
2491
-            $copy_attendee_info,
2492
-            FILTER_VALIDATE_BOOLEAN
2493
-        );
2494
-    }
2495
-
2496
-
2497
-    /**
2498
-     * Gets the options to make availalbe for the gateway log lifespan
2499
-     * @return array
2500
-     */
2501
-    public function gatewayLogLifespanOptions()
2502
-    {
2503
-        return (array) apply_filters(
2504
-            'FHEE_EE_Admin_Config__gatewayLogLifespanOptions',
2505
-            array(
2506
-                '1 second' => esc_html__('Don\'t Log At All', 'event_espresso'),
2507
-                '1 day' => esc_html__('1 Day', 'event_espresso'),
2508
-                '7 days' => esc_html__('7 Days', 'event_espresso'),
2509
-                '14 days' => esc_html__('14 Days', 'event_espresso'),
2510
-                '30 days' => esc_html__('30 Days', 'event_espresso')
2511
-            )
2512
-        );
2513
-    }
2514
-
2515
-
2516
-    /**
2517
-     * @return bool
2518
-     */
2519
-    public function isConsentCheckboxEnabled()
2520
-    {
2521
-        return $this->consent_checkbox_enabled;
2522
-    }
2523
-
2524
-
2525
-    /**
2526
-     * @param bool $consent_checkbox_enabled
2527
-     */
2528
-    public function setConsentCheckboxEnabled($consent_checkbox_enabled)
2529
-    {
2530
-        $this->consent_checkbox_enabled = filter_var(
2531
-            $consent_checkbox_enabled,
2532
-            FILTER_VALIDATE_BOOLEAN
2533
-        );
2534
-    }
2535
-
2536
-
2537
-    /**
2538
-     * @return string
2539
-     */
2540
-    public function getConsentCheckboxLabelText()
2541
-    {
2542
-        return $this->consent_checkbox_label_text;
2543
-    }
2544
-
2545
-
2546
-    /**
2547
-     * @param string $consent_checkbox_label_text
2548
-     */
2549
-    public function setConsentCheckboxLabelText($consent_checkbox_label_text)
2550
-    {
2551
-        $this->consent_checkbox_label_text = (string) $consent_checkbox_label_text;
2552
-    }
2336
+	public $gateway_log_lifespan = '1 week';
2337
+
2338
+	/**
2339
+	 * Enable copy attendee info at form
2340
+	 *
2341
+	 * @var boolean $enable_copy_attendee
2342
+	 */
2343
+	protected $copy_attendee_info = true;
2344
+
2345
+
2346
+	/**
2347
+	 *    class constructor
2348
+	 *
2349
+	 * @access    public
2350
+	 */
2351
+	public function __construct()
2352
+	{
2353
+		// set default registration settings
2354
+		$this->default_STS_ID = EEM_Registration::status_id_pending_payment;
2355
+		$this->email_validation_level = 'wp_default';
2356
+		$this->show_pending_payment_options = true;
2357
+		$this->skip_reg_confirmation = true;
2358
+		$this->reg_steps = array();
2359
+		$this->reg_confirmation_last = false;
2360
+		$this->use_bot_trap = true;
2361
+		$this->use_encryption = true;
2362
+		$this->use_captcha = false;
2363
+		$this->recaptcha_theme = 'light';
2364
+		$this->recaptcha_badge = 'bottomleft';
2365
+		$this->recaptcha_type = 'image';
2366
+		$this->recaptcha_language = 'en';
2367
+		$this->recaptcha_publickey = null;
2368
+		$this->recaptcha_privatekey = null;
2369
+		$this->recaptcha_protected_forms = array();
2370
+		$this->recaptcha_width = 500;
2371
+		$this->default_maximum_number_of_tickets = 10;
2372
+		$this->consent_checkbox_enabled = false;
2373
+		$this->consent_checkbox_label_text = '';
2374
+		$this->gateway_log_lifespan = '7 days';
2375
+		$this->copy_attendee_info = true;
2376
+	}
2377
+
2378
+
2379
+	/**
2380
+	 * This is called by the config loader and hooks are initialized AFTER the config has been populated.
2381
+	 *
2382
+	 * @since 4.8.8.rc.019
2383
+	 */
2384
+	public function do_hooks()
2385
+	{
2386
+		add_action('AHEE__EE_Config___load_core_config__end', array($this, 'set_default_reg_status_on_EEM_Event'));
2387
+		add_action('AHEE__EE_Config___load_core_config__end', array($this, 'set_default_max_ticket_on_EEM_Event'));
2388
+		add_action('setup_theme', array($this, 'setDefaultCheckboxLabelText'));
2389
+	}
2390
+
2391
+
2392
+	/**
2393
+	 * Hooked into `AHEE__EE_Config___load_core_config__end` to ensure the default for the
2394
+	 * EVT_default_registration_status field matches the config setting for default_STS_ID.
2395
+	 */
2396
+	public function set_default_reg_status_on_EEM_Event()
2397
+	{
2398
+		EEM_Event::set_default_reg_status($this->default_STS_ID);
2399
+	}
2400
+
2401
+
2402
+	/**
2403
+	 * Hooked into `AHEE__EE_Config___load_core_config__end` to ensure the default for the EVT_additional_limit field
2404
+	 * for Events matches the config setting for default_maximum_number_of_tickets
2405
+	 */
2406
+	public function set_default_max_ticket_on_EEM_Event()
2407
+	{
2408
+		EEM_Event::set_default_additional_limit($this->default_maximum_number_of_tickets);
2409
+	}
2410
+
2411
+
2412
+	/**
2413
+	 * Sets the default consent checkbox text. This needs to be done a bit later than when EE_Registration_Config is
2414
+	 * constructed because that happens before we can get the privacy policy page's permalink.
2415
+	 *
2416
+	 * @throws InvalidArgumentException
2417
+	 * @throws InvalidDataTypeException
2418
+	 * @throws InvalidInterfaceException
2419
+	 */
2420
+	public function setDefaultCheckboxLabelText()
2421
+	{
2422
+		if (
2423
+			$this->getConsentCheckboxLabelText() === null
2424
+			|| $this->getConsentCheckboxLabelText() === ''
2425
+		) {
2426
+			$opening_a_tag = '';
2427
+			$closing_a_tag = '';
2428
+			if (function_exists('get_privacy_policy_url')) {
2429
+				$privacy_page_url = get_privacy_policy_url();
2430
+				if (! empty($privacy_page_url)) {
2431
+					$opening_a_tag = '<a href="' . $privacy_page_url . '" target="_blank">';
2432
+					$closing_a_tag = '</a>';
2433
+				}
2434
+			}
2435
+			$loader = LoaderFactory::getLoader();
2436
+			$org_config = $loader->getShared('EE_Organization_Config');
2437
+			/**
2438
+			 * @var $org_config EE_Organization_Config
2439
+			 */
2440
+
2441
+			$this->setConsentCheckboxLabelText(
2442
+				sprintf(
2443
+					esc_html__(
2444
+						'I consent to %1$s storing and using my personal information, according to their %2$sprivacy policy%3$s.',
2445
+						'event_espresso'
2446
+					),
2447
+					$org_config->name,
2448
+					$opening_a_tag,
2449
+					$closing_a_tag
2450
+				)
2451
+			);
2452
+		}
2453
+	}
2454
+
2455
+
2456
+	/**
2457
+	 * @return boolean
2458
+	 */
2459
+	public function track_invalid_checkout_access()
2460
+	{
2461
+		return $this->track_invalid_checkout_access;
2462
+	}
2463
+
2464
+
2465
+	/**
2466
+	 * @param boolean $track_invalid_checkout_access
2467
+	 */
2468
+	public function set_track_invalid_checkout_access($track_invalid_checkout_access)
2469
+	{
2470
+		$this->track_invalid_checkout_access = filter_var(
2471
+			$track_invalid_checkout_access,
2472
+			FILTER_VALIDATE_BOOLEAN
2473
+		);
2474
+	}
2475
+
2476
+	/**
2477
+	 * @return boolean
2478
+	 */
2479
+	public function copyAttendeeInfo()
2480
+	{
2481
+		return $this->copy_attendee_info;
2482
+	}
2483
+
2484
+
2485
+	/**
2486
+	 * @param boolean $copy_attendee_info
2487
+	 */
2488
+	public function setCopyAttendeeInfo($copy_attendee_info)
2489
+	{
2490
+		$this->copy_attendee_info = filter_var(
2491
+			$copy_attendee_info,
2492
+			FILTER_VALIDATE_BOOLEAN
2493
+		);
2494
+	}
2495
+
2496
+
2497
+	/**
2498
+	 * Gets the options to make availalbe for the gateway log lifespan
2499
+	 * @return array
2500
+	 */
2501
+	public function gatewayLogLifespanOptions()
2502
+	{
2503
+		return (array) apply_filters(
2504
+			'FHEE_EE_Admin_Config__gatewayLogLifespanOptions',
2505
+			array(
2506
+				'1 second' => esc_html__('Don\'t Log At All', 'event_espresso'),
2507
+				'1 day' => esc_html__('1 Day', 'event_espresso'),
2508
+				'7 days' => esc_html__('7 Days', 'event_espresso'),
2509
+				'14 days' => esc_html__('14 Days', 'event_espresso'),
2510
+				'30 days' => esc_html__('30 Days', 'event_espresso')
2511
+			)
2512
+		);
2513
+	}
2514
+
2515
+
2516
+	/**
2517
+	 * @return bool
2518
+	 */
2519
+	public function isConsentCheckboxEnabled()
2520
+	{
2521
+		return $this->consent_checkbox_enabled;
2522
+	}
2523
+
2524
+
2525
+	/**
2526
+	 * @param bool $consent_checkbox_enabled
2527
+	 */
2528
+	public function setConsentCheckboxEnabled($consent_checkbox_enabled)
2529
+	{
2530
+		$this->consent_checkbox_enabled = filter_var(
2531
+			$consent_checkbox_enabled,
2532
+			FILTER_VALIDATE_BOOLEAN
2533
+		);
2534
+	}
2535
+
2536
+
2537
+	/**
2538
+	 * @return string
2539
+	 */
2540
+	public function getConsentCheckboxLabelText()
2541
+	{
2542
+		return $this->consent_checkbox_label_text;
2543
+	}
2544
+
2545
+
2546
+	/**
2547
+	 * @param string $consent_checkbox_label_text
2548
+	 */
2549
+	public function setConsentCheckboxLabelText($consent_checkbox_label_text)
2550
+	{
2551
+		$this->consent_checkbox_label_text = (string) $consent_checkbox_label_text;
2552
+	}
2553 2553
 }
2554 2554
 
2555 2555
 /**
@@ -2557,143 +2557,143 @@  discard block
 block discarded – undo
2557 2557
  */
2558 2558
 class EE_Admin_Config extends EE_Config_Base
2559 2559
 {
2560
-    /**
2561
-     * @var boolean $use_personnel_manager
2562
-     */
2563
-    public $use_personnel_manager;
2564
-
2565
-    /**
2566
-     * @var boolean $use_dashboard_widget
2567
-     */
2568
-    public $use_dashboard_widget;
2569
-
2570
-    /**
2571
-     * @var int $events_in_dashboard
2572
-     */
2573
-    public $events_in_dashboard;
2574
-
2575
-    /**
2576
-     * @var boolean $use_event_timezones
2577
-     */
2578
-    public $use_event_timezones;
2579
-
2580
-    /**
2581
-     * @var string $log_file_name
2582
-     */
2583
-    public $log_file_name;
2584
-
2585
-    /**
2586
-     * @var string $debug_file_name
2587
-     */
2588
-    public $debug_file_name;
2589
-
2590
-    /**
2591
-     * @var boolean $use_remote_logging
2592
-     */
2593
-    public $use_remote_logging;
2594
-
2595
-    /**
2596
-     * @var string $remote_logging_url
2597
-     */
2598
-    public $remote_logging_url;
2599
-
2600
-    /**
2601
-     * @var boolean $show_reg_footer
2602
-     */
2603
-    public $show_reg_footer;
2604
-
2605
-    /**
2606
-     * @var string $affiliate_id
2607
-     */
2608
-    public $affiliate_id;
2609
-
2610
-    /**
2611
-     * adds extra layer of encoding to session data to prevent serialization errors
2612
-     * but is incompatible with some server configuration errors
2613
-     * if you get "500 internal server errors" during registration, try turning this on
2614
-     * if you get PHP fatal errors regarding base 64 methods not defined, then turn this off
2615
-     *
2616
-     * @var boolean $encode_session_data
2617
-     */
2618
-    private $encode_session_data = false;
2619
-
2620
-
2621
-    /**
2622
-     *    class constructor
2623
-     *
2624
-     * @access    public
2625
-     */
2626
-    public function __construct()
2627
-    {
2628
-        // set default general admin settings
2629
-        $this->use_personnel_manager = true;
2630
-        $this->use_dashboard_widget = true;
2631
-        $this->events_in_dashboard = 30;
2632
-        $this->use_event_timezones = false;
2633
-        $this->use_remote_logging = false;
2634
-        $this->remote_logging_url = null;
2635
-        $this->show_reg_footer = apply_filters(
2636
-            'FHEE__EE_Admin_Config__show_reg_footer__default',
2637
-            false
2638
-        );
2639
-        $this->affiliate_id = 'default';
2640
-        $this->encode_session_data = false;
2641
-    }
2642
-
2643
-
2644
-    /**
2645
-     * @param bool $reset
2646
-     * @return string
2647
-     */
2648
-    public function log_file_name($reset = false)
2649
-    {
2650
-        if (empty($this->log_file_name) || $reset) {
2651
-            $this->log_file_name = sanitize_key('espresso_log_' . md5(uniqid('', true))) . '.txt';
2652
-            EE_Config::instance()->update_espresso_config(false, false);
2653
-        }
2654
-        return $this->log_file_name;
2655
-    }
2656
-
2657
-
2658
-    /**
2659
-     * @param bool $reset
2660
-     * @return string
2661
-     */
2662
-    public function debug_file_name($reset = false)
2663
-    {
2664
-        if (empty($this->debug_file_name) || $reset) {
2665
-            $this->debug_file_name = sanitize_key('espresso_debug_' . md5(uniqid('', true))) . '.txt';
2666
-            EE_Config::instance()->update_espresso_config(false, false);
2667
-        }
2668
-        return $this->debug_file_name;
2669
-    }
2670
-
2671
-
2672
-    /**
2673
-     * @return string
2674
-     */
2675
-    public function affiliate_id()
2676
-    {
2677
-        return ! empty($this->affiliate_id) ? $this->affiliate_id : 'default';
2678
-    }
2679
-
2680
-
2681
-    /**
2682
-     * @return boolean
2683
-     */
2684
-    public function encode_session_data()
2685
-    {
2686
-        return filter_var($this->encode_session_data, FILTER_VALIDATE_BOOLEAN);
2687
-    }
2688
-
2689
-
2690
-    /**
2691
-     * @param boolean $encode_session_data
2692
-     */
2693
-    public function set_encode_session_data($encode_session_data)
2694
-    {
2695
-        $this->encode_session_data = filter_var($encode_session_data, FILTER_VALIDATE_BOOLEAN);
2696
-    }
2560
+	/**
2561
+	 * @var boolean $use_personnel_manager
2562
+	 */
2563
+	public $use_personnel_manager;
2564
+
2565
+	/**
2566
+	 * @var boolean $use_dashboard_widget
2567
+	 */
2568
+	public $use_dashboard_widget;
2569
+
2570
+	/**
2571
+	 * @var int $events_in_dashboard
2572
+	 */
2573
+	public $events_in_dashboard;
2574
+
2575
+	/**
2576
+	 * @var boolean $use_event_timezones
2577
+	 */
2578
+	public $use_event_timezones;
2579
+
2580
+	/**
2581
+	 * @var string $log_file_name
2582
+	 */
2583
+	public $log_file_name;
2584
+
2585
+	/**
2586
+	 * @var string $debug_file_name
2587
+	 */
2588
+	public $debug_file_name;
2589
+
2590
+	/**
2591
+	 * @var boolean $use_remote_logging
2592
+	 */
2593
+	public $use_remote_logging;
2594
+
2595
+	/**
2596
+	 * @var string $remote_logging_url
2597
+	 */
2598
+	public $remote_logging_url;
2599
+
2600
+	/**
2601
+	 * @var boolean $show_reg_footer
2602
+	 */
2603
+	public $show_reg_footer;
2604
+
2605
+	/**
2606
+	 * @var string $affiliate_id
2607
+	 */
2608
+	public $affiliate_id;
2609
+
2610
+	/**
2611
+	 * adds extra layer of encoding to session data to prevent serialization errors
2612
+	 * but is incompatible with some server configuration errors
2613
+	 * if you get "500 internal server errors" during registration, try turning this on
2614
+	 * if you get PHP fatal errors regarding base 64 methods not defined, then turn this off
2615
+	 *
2616
+	 * @var boolean $encode_session_data
2617
+	 */
2618
+	private $encode_session_data = false;
2619
+
2620
+
2621
+	/**
2622
+	 *    class constructor
2623
+	 *
2624
+	 * @access    public
2625
+	 */
2626
+	public function __construct()
2627
+	{
2628
+		// set default general admin settings
2629
+		$this->use_personnel_manager = true;
2630
+		$this->use_dashboard_widget = true;
2631
+		$this->events_in_dashboard = 30;
2632
+		$this->use_event_timezones = false;
2633
+		$this->use_remote_logging = false;
2634
+		$this->remote_logging_url = null;
2635
+		$this->show_reg_footer = apply_filters(
2636
+			'FHEE__EE_Admin_Config__show_reg_footer__default',
2637
+			false
2638
+		);
2639
+		$this->affiliate_id = 'default';
2640
+		$this->encode_session_data = false;
2641
+	}
2642
+
2643
+
2644
+	/**
2645
+	 * @param bool $reset
2646
+	 * @return string
2647
+	 */
2648
+	public function log_file_name($reset = false)
2649
+	{
2650
+		if (empty($this->log_file_name) || $reset) {
2651
+			$this->log_file_name = sanitize_key('espresso_log_' . md5(uniqid('', true))) . '.txt';
2652
+			EE_Config::instance()->update_espresso_config(false, false);
2653
+		}
2654
+		return $this->log_file_name;
2655
+	}
2656
+
2657
+
2658
+	/**
2659
+	 * @param bool $reset
2660
+	 * @return string
2661
+	 */
2662
+	public function debug_file_name($reset = false)
2663
+	{
2664
+		if (empty($this->debug_file_name) || $reset) {
2665
+			$this->debug_file_name = sanitize_key('espresso_debug_' . md5(uniqid('', true))) . '.txt';
2666
+			EE_Config::instance()->update_espresso_config(false, false);
2667
+		}
2668
+		return $this->debug_file_name;
2669
+	}
2670
+
2671
+
2672
+	/**
2673
+	 * @return string
2674
+	 */
2675
+	public function affiliate_id()
2676
+	{
2677
+		return ! empty($this->affiliate_id) ? $this->affiliate_id : 'default';
2678
+	}
2679
+
2680
+
2681
+	/**
2682
+	 * @return boolean
2683
+	 */
2684
+	public function encode_session_data()
2685
+	{
2686
+		return filter_var($this->encode_session_data, FILTER_VALIDATE_BOOLEAN);
2687
+	}
2688
+
2689
+
2690
+	/**
2691
+	 * @param boolean $encode_session_data
2692
+	 */
2693
+	public function set_encode_session_data($encode_session_data)
2694
+	{
2695
+		$this->encode_session_data = filter_var($encode_session_data, FILTER_VALIDATE_BOOLEAN);
2696
+	}
2697 2697
 }
2698 2698
 
2699 2699
 /**
@@ -2701,70 +2701,70 @@  discard block
 block discarded – undo
2701 2701
  */
2702 2702
 class EE_Template_Config extends EE_Config_Base
2703 2703
 {
2704
-    /**
2705
-     * @var boolean $enable_default_style
2706
-     */
2707
-    public $enable_default_style;
2708
-
2709
-    /**
2710
-     * @var string $custom_style_sheet
2711
-     */
2712
-    public $custom_style_sheet;
2713
-
2714
-    /**
2715
-     * @var boolean $display_address_in_regform
2716
-     */
2717
-    public $display_address_in_regform;
2718
-
2719
-    /**
2720
-     * @var int $display_description_on_multi_reg_page
2721
-     */
2722
-    public $display_description_on_multi_reg_page;
2723
-
2724
-    /**
2725
-     * @var boolean $use_custom_templates
2726
-     */
2727
-    public $use_custom_templates;
2728
-
2729
-    /**
2730
-     * @var string $current_espresso_theme
2731
-     */
2732
-    public $current_espresso_theme;
2733
-
2734
-    /**
2735
-     * @var EE_Ticket_Selector_Config $EED_Ticket_Selector
2736
-     */
2737
-    public $EED_Ticket_Selector;
2738
-
2739
-    /**
2740
-     * @var EE_Event_Single_Config $EED_Event_Single
2741
-     */
2742
-    public $EED_Event_Single;
2743
-
2744
-    /**
2745
-     * @var EE_Events_Archive_Config $EED_Events_Archive
2746
-     */
2747
-    public $EED_Events_Archive;
2748
-
2749
-
2750
-    /**
2751
-     *    class constructor
2752
-     *
2753
-     * @access    public
2754
-     */
2755
-    public function __construct()
2756
-    {
2757
-        // set default template settings
2758
-        $this->enable_default_style = true;
2759
-        $this->custom_style_sheet = null;
2760
-        $this->display_address_in_regform = true;
2761
-        $this->display_description_on_multi_reg_page = false;
2762
-        $this->use_custom_templates = false;
2763
-        $this->current_espresso_theme = 'Espresso_Arabica_2014';
2764
-        $this->EED_Event_Single = null;
2765
-        $this->EED_Events_Archive = null;
2766
-        $this->EED_Ticket_Selector = null;
2767
-    }
2704
+	/**
2705
+	 * @var boolean $enable_default_style
2706
+	 */
2707
+	public $enable_default_style;
2708
+
2709
+	/**
2710
+	 * @var string $custom_style_sheet
2711
+	 */
2712
+	public $custom_style_sheet;
2713
+
2714
+	/**
2715
+	 * @var boolean $display_address_in_regform
2716
+	 */
2717
+	public $display_address_in_regform;
2718
+
2719
+	/**
2720
+	 * @var int $display_description_on_multi_reg_page
2721
+	 */
2722
+	public $display_description_on_multi_reg_page;
2723
+
2724
+	/**
2725
+	 * @var boolean $use_custom_templates
2726
+	 */
2727
+	public $use_custom_templates;
2728
+
2729
+	/**
2730
+	 * @var string $current_espresso_theme
2731
+	 */
2732
+	public $current_espresso_theme;
2733
+
2734
+	/**
2735
+	 * @var EE_Ticket_Selector_Config $EED_Ticket_Selector
2736
+	 */
2737
+	public $EED_Ticket_Selector;
2738
+
2739
+	/**
2740
+	 * @var EE_Event_Single_Config $EED_Event_Single
2741
+	 */
2742
+	public $EED_Event_Single;
2743
+
2744
+	/**
2745
+	 * @var EE_Events_Archive_Config $EED_Events_Archive
2746
+	 */
2747
+	public $EED_Events_Archive;
2748
+
2749
+
2750
+	/**
2751
+	 *    class constructor
2752
+	 *
2753
+	 * @access    public
2754
+	 */
2755
+	public function __construct()
2756
+	{
2757
+		// set default template settings
2758
+		$this->enable_default_style = true;
2759
+		$this->custom_style_sheet = null;
2760
+		$this->display_address_in_regform = true;
2761
+		$this->display_description_on_multi_reg_page = false;
2762
+		$this->use_custom_templates = false;
2763
+		$this->current_espresso_theme = 'Espresso_Arabica_2014';
2764
+		$this->EED_Event_Single = null;
2765
+		$this->EED_Events_Archive = null;
2766
+		$this->EED_Ticket_Selector = null;
2767
+	}
2768 2768
 }
2769 2769
 
2770 2770
 /**
@@ -2772,114 +2772,114 @@  discard block
 block discarded – undo
2772 2772
  */
2773 2773
 class EE_Map_Config extends EE_Config_Base
2774 2774
 {
2775
-    /**
2776
-     * @var boolean $use_google_maps
2777
-     */
2778
-    public $use_google_maps;
2779
-
2780
-    /**
2781
-     * @var string $api_key
2782
-     */
2783
-    public $google_map_api_key;
2784
-
2785
-    /**
2786
-     * @var int $event_details_map_width
2787
-     */
2788
-    public $event_details_map_width;
2789
-
2790
-    /**
2791
-     * @var int $event_details_map_height
2792
-     */
2793
-    public $event_details_map_height;
2794
-
2795
-    /**
2796
-     * @var int $event_details_map_zoom
2797
-     */
2798
-    public $event_details_map_zoom;
2799
-
2800
-    /**
2801
-     * @var boolean $event_details_display_nav
2802
-     */
2803
-    public $event_details_display_nav;
2804
-
2805
-    /**
2806
-     * @var boolean $event_details_nav_size
2807
-     */
2808
-    public $event_details_nav_size;
2809
-
2810
-    /**
2811
-     * @var string $event_details_control_type
2812
-     */
2813
-    public $event_details_control_type;
2814
-
2815
-    /**
2816
-     * @var string $event_details_map_align
2817
-     */
2818
-    public $event_details_map_align;
2819
-
2820
-    /**
2821
-     * @var int $event_list_map_width
2822
-     */
2823
-    public $event_list_map_width;
2824
-
2825
-    /**
2826
-     * @var int $event_list_map_height
2827
-     */
2828
-    public $event_list_map_height;
2829
-
2830
-    /**
2831
-     * @var int $event_list_map_zoom
2832
-     */
2833
-    public $event_list_map_zoom;
2834
-
2835
-    /**
2836
-     * @var boolean $event_list_display_nav
2837
-     */
2838
-    public $event_list_display_nav;
2839
-
2840
-    /**
2841
-     * @var boolean $event_list_nav_size
2842
-     */
2843
-    public $event_list_nav_size;
2844
-
2845
-    /**
2846
-     * @var string $event_list_control_type
2847
-     */
2848
-    public $event_list_control_type;
2849
-
2850
-    /**
2851
-     * @var string $event_list_map_align
2852
-     */
2853
-    public $event_list_map_align;
2854
-
2855
-
2856
-    /**
2857
-     *    class constructor
2858
-     *
2859
-     * @access    public
2860
-     */
2861
-    public function __construct()
2862
-    {
2863
-        // set default map settings
2864
-        $this->use_google_maps = true;
2865
-        $this->google_map_api_key = '';
2866
-        // for event details pages (reg page)
2867
-        $this->event_details_map_width = 585;            // ee_map_width_single
2868
-        $this->event_details_map_height = 362;            // ee_map_height_single
2869
-        $this->event_details_map_zoom = 14;            // ee_map_zoom_single
2870
-        $this->event_details_display_nav = true;            // ee_map_nav_display_single
2871
-        $this->event_details_nav_size = false;            // ee_map_nav_size_single
2872
-        $this->event_details_control_type = 'default';        // ee_map_type_control_single
2873
-        $this->event_details_map_align = 'center';            // ee_map_align_single
2874
-        // for event list pages
2875
-        $this->event_list_map_width = 300;            // ee_map_width
2876
-        $this->event_list_map_height = 185;        // ee_map_height
2877
-        $this->event_list_map_zoom = 12;            // ee_map_zoom
2878
-        $this->event_list_display_nav = false;        // ee_map_nav_display
2879
-        $this->event_list_nav_size = true;            // ee_map_nav_size
2880
-        $this->event_list_control_type = 'dropdown';        // ee_map_type_control
2881
-        $this->event_list_map_align = 'center';            // ee_map_align
2882
-    }
2775
+	/**
2776
+	 * @var boolean $use_google_maps
2777
+	 */
2778
+	public $use_google_maps;
2779
+
2780
+	/**
2781
+	 * @var string $api_key
2782
+	 */
2783
+	public $google_map_api_key;
2784
+
2785
+	/**
2786
+	 * @var int $event_details_map_width
2787
+	 */
2788
+	public $event_details_map_width;
2789
+
2790
+	/**
2791
+	 * @var int $event_details_map_height
2792
+	 */
2793
+	public $event_details_map_height;
2794
+
2795
+	/**
2796
+	 * @var int $event_details_map_zoom
2797
+	 */
2798
+	public $event_details_map_zoom;
2799
+
2800
+	/**
2801
+	 * @var boolean $event_details_display_nav
2802
+	 */
2803
+	public $event_details_display_nav;
2804
+
2805
+	/**
2806
+	 * @var boolean $event_details_nav_size
2807
+	 */
2808
+	public $event_details_nav_size;
2809
+
2810
+	/**
2811
+	 * @var string $event_details_control_type
2812
+	 */
2813
+	public $event_details_control_type;
2814
+
2815
+	/**
2816
+	 * @var string $event_details_map_align
2817
+	 */
2818
+	public $event_details_map_align;
2819
+
2820
+	/**
2821
+	 * @var int $event_list_map_width
2822
+	 */
2823
+	public $event_list_map_width;
2824
+
2825
+	/**
2826
+	 * @var int $event_list_map_height
2827
+	 */
2828
+	public $event_list_map_height;
2829
+
2830
+	/**
2831
+	 * @var int $event_list_map_zoom
2832
+	 */
2833
+	public $event_list_map_zoom;
2834
+
2835
+	/**
2836
+	 * @var boolean $event_list_display_nav
2837
+	 */
2838
+	public $event_list_display_nav;
2839
+
2840
+	/**
2841
+	 * @var boolean $event_list_nav_size
2842
+	 */
2843
+	public $event_list_nav_size;
2844
+
2845
+	/**
2846
+	 * @var string $event_list_control_type
2847
+	 */
2848
+	public $event_list_control_type;
2849
+
2850
+	/**
2851
+	 * @var string $event_list_map_align
2852
+	 */
2853
+	public $event_list_map_align;
2854
+
2855
+
2856
+	/**
2857
+	 *    class constructor
2858
+	 *
2859
+	 * @access    public
2860
+	 */
2861
+	public function __construct()
2862
+	{
2863
+		// set default map settings
2864
+		$this->use_google_maps = true;
2865
+		$this->google_map_api_key = '';
2866
+		// for event details pages (reg page)
2867
+		$this->event_details_map_width = 585;            // ee_map_width_single
2868
+		$this->event_details_map_height = 362;            // ee_map_height_single
2869
+		$this->event_details_map_zoom = 14;            // ee_map_zoom_single
2870
+		$this->event_details_display_nav = true;            // ee_map_nav_display_single
2871
+		$this->event_details_nav_size = false;            // ee_map_nav_size_single
2872
+		$this->event_details_control_type = 'default';        // ee_map_type_control_single
2873
+		$this->event_details_map_align = 'center';            // ee_map_align_single
2874
+		// for event list pages
2875
+		$this->event_list_map_width = 300;            // ee_map_width
2876
+		$this->event_list_map_height = 185;        // ee_map_height
2877
+		$this->event_list_map_zoom = 12;            // ee_map_zoom
2878
+		$this->event_list_display_nav = false;        // ee_map_nav_display
2879
+		$this->event_list_nav_size = true;            // ee_map_nav_size
2880
+		$this->event_list_control_type = 'dropdown';        // ee_map_type_control
2881
+		$this->event_list_map_align = 'center';            // ee_map_align
2882
+	}
2883 2883
 }
2884 2884
 
2885 2885
 /**
@@ -2887,46 +2887,46 @@  discard block
 block discarded – undo
2887 2887
  */
2888 2888
 class EE_Events_Archive_Config extends EE_Config_Base
2889 2889
 {
2890
-    public $display_status_banner;
2890
+	public $display_status_banner;
2891 2891
 
2892
-    public $display_description;
2892
+	public $display_description;
2893 2893
 
2894
-    public $display_ticket_selector;
2894
+	public $display_ticket_selector;
2895 2895
 
2896
-    public $display_datetimes;
2896
+	public $display_datetimes;
2897 2897
 
2898
-    public $display_venue;
2898
+	public $display_venue;
2899 2899
 
2900
-    public $display_expired_events;
2900
+	public $display_expired_events;
2901 2901
 
2902
-    public $use_sortable_display_order;
2902
+	public $use_sortable_display_order;
2903 2903
 
2904
-    public $display_order_tickets;
2904
+	public $display_order_tickets;
2905 2905
 
2906
-    public $display_order_datetimes;
2906
+	public $display_order_datetimes;
2907 2907
 
2908
-    public $display_order_event;
2908
+	public $display_order_event;
2909 2909
 
2910
-    public $display_order_venue;
2910
+	public $display_order_venue;
2911 2911
 
2912 2912
 
2913
-    /**
2914
-     *    class constructor
2915
-     */
2916
-    public function __construct()
2917
-    {
2918
-        $this->display_status_banner = 0;
2919
-        $this->display_description = 1;
2920
-        $this->display_ticket_selector = 0;
2921
-        $this->display_datetimes = 1;
2922
-        $this->display_venue = 0;
2923
-        $this->display_expired_events = 0;
2924
-        $this->use_sortable_display_order = false;
2925
-        $this->display_order_tickets = 100;
2926
-        $this->display_order_datetimes = 110;
2927
-        $this->display_order_event = 120;
2928
-        $this->display_order_venue = 130;
2929
-    }
2913
+	/**
2914
+	 *    class constructor
2915
+	 */
2916
+	public function __construct()
2917
+	{
2918
+		$this->display_status_banner = 0;
2919
+		$this->display_description = 1;
2920
+		$this->display_ticket_selector = 0;
2921
+		$this->display_datetimes = 1;
2922
+		$this->display_venue = 0;
2923
+		$this->display_expired_events = 0;
2924
+		$this->use_sortable_display_order = false;
2925
+		$this->display_order_tickets = 100;
2926
+		$this->display_order_datetimes = 110;
2927
+		$this->display_order_event = 120;
2928
+		$this->display_order_venue = 130;
2929
+	}
2930 2930
 }
2931 2931
 
2932 2932
 /**
@@ -2934,34 +2934,34 @@  discard block
 block discarded – undo
2934 2934
  */
2935 2935
 class EE_Event_Single_Config extends EE_Config_Base
2936 2936
 {
2937
-    public $display_status_banner_single;
2937
+	public $display_status_banner_single;
2938 2938
 
2939
-    public $display_venue;
2939
+	public $display_venue;
2940 2940
 
2941
-    public $use_sortable_display_order;
2941
+	public $use_sortable_display_order;
2942 2942
 
2943
-    public $display_order_tickets;
2943
+	public $display_order_tickets;
2944 2944
 
2945
-    public $display_order_datetimes;
2945
+	public $display_order_datetimes;
2946 2946
 
2947
-    public $display_order_event;
2947
+	public $display_order_event;
2948 2948
 
2949
-    public $display_order_venue;
2949
+	public $display_order_venue;
2950 2950
 
2951 2951
 
2952
-    /**
2953
-     *    class constructor
2954
-     */
2955
-    public function __construct()
2956
-    {
2957
-        $this->display_status_banner_single = 0;
2958
-        $this->display_venue = 1;
2959
-        $this->use_sortable_display_order = false;
2960
-        $this->display_order_tickets = 100;
2961
-        $this->display_order_datetimes = 110;
2962
-        $this->display_order_event = 120;
2963
-        $this->display_order_venue = 130;
2964
-    }
2952
+	/**
2953
+	 *    class constructor
2954
+	 */
2955
+	public function __construct()
2956
+	{
2957
+		$this->display_status_banner_single = 0;
2958
+		$this->display_venue = 1;
2959
+		$this->use_sortable_display_order = false;
2960
+		$this->display_order_tickets = 100;
2961
+		$this->display_order_datetimes = 110;
2962
+		$this->display_order_event = 120;
2963
+		$this->display_order_venue = 130;
2964
+	}
2965 2965
 }
2966 2966
 
2967 2967
 /**
@@ -2969,172 +2969,172 @@  discard block
 block discarded – undo
2969 2969
  */
2970 2970
 class EE_Ticket_Selector_Config extends EE_Config_Base
2971 2971
 {
2972
-    /**
2973
-     * constant to indicate that a datetime selector should NEVER be shown for ticket selectors
2974
-     */
2975
-    const DO_NOT_SHOW_DATETIME_SELECTOR = 'no_datetime_selector';
2976
-
2977
-    /**
2978
-     * constant to indicate that a datetime selector should only be shown for ticket selectors
2979
-     * when the number of datetimes for the event matches the value set for $datetime_selector_threshold
2980
-     */
2981
-    const MAYBE_SHOW_DATETIME_SELECTOR = 'maybe_datetime_selector';
2982
-
2983
-    /**
2984
-     * @var boolean $show_ticket_sale_columns
2985
-     */
2986
-    public $show_ticket_sale_columns;
2987
-
2988
-    /**
2989
-     * @var boolean $show_ticket_details
2990
-     */
2991
-    public $show_ticket_details;
2992
-
2993
-    /**
2994
-     * @var boolean $show_expired_tickets
2995
-     */
2996
-    public $show_expired_tickets;
2997
-
2998
-    /**
2999
-     * whether or not to display a dropdown box populated with event datetimes
3000
-     * that toggles which tickets are displayed for a ticket selector.
3001
-     * uses one of the *_DATETIME_SELECTOR constants defined above
3002
-     *
3003
-     * @var string $show_datetime_selector
3004
-     */
3005
-    private $show_datetime_selector = 'no_datetime_selector';
3006
-
3007
-    /**
3008
-     * the number of datetimes an event has to have before conditionally displaying a datetime selector
3009
-     *
3010
-     * @var int $datetime_selector_threshold
3011
-     */
3012
-    private $datetime_selector_threshold = 3;
3013
-
3014
-    /**
3015
-     * determines the maximum number of "checked" dates in the date and time filter
3016
-     *
3017
-     * @var int $datetime_selector_checked
3018
-     */
3019
-    private $datetime_selector_max_checked = 10;
3020
-
3021
-
3022
-    /**
3023
-     *    class constructor
3024
-     */
3025
-    public function __construct()
3026
-    {
3027
-        $this->show_ticket_sale_columns = true;
3028
-        $this->show_ticket_details = true;
3029
-        $this->show_expired_tickets = true;
3030
-        $this->show_datetime_selector = EE_Ticket_Selector_Config::DO_NOT_SHOW_DATETIME_SELECTOR;
3031
-        $this->datetime_selector_threshold = 3;
3032
-        $this->datetime_selector_max_checked = 10;
3033
-    }
3034
-
3035
-
3036
-    /**
3037
-     * returns true if a datetime selector should be displayed
3038
-     *
3039
-     * @param array $datetimes
3040
-     * @return bool
3041
-     */
3042
-    public function showDatetimeSelector(array $datetimes)
3043
-    {
3044
-        // if the settings are NOT: don't show OR below threshold, THEN active = true
3045
-        return ! (
3046
-            $this->getShowDatetimeSelector() === EE_Ticket_Selector_Config::DO_NOT_SHOW_DATETIME_SELECTOR
3047
-            || (
3048
-                $this->getShowDatetimeSelector() === EE_Ticket_Selector_Config::MAYBE_SHOW_DATETIME_SELECTOR
3049
-                && count($datetimes) < $this->getDatetimeSelectorThreshold()
3050
-            )
3051
-        );
3052
-    }
3053
-
3054
-
3055
-    /**
3056
-     * @return string
3057
-     */
3058
-    public function getShowDatetimeSelector()
3059
-    {
3060
-        return $this->show_datetime_selector;
3061
-    }
3062
-
3063
-
3064
-    /**
3065
-     * @param bool $keys_only
3066
-     * @return array
3067
-     */
3068
-    public function getShowDatetimeSelectorOptions($keys_only = true)
3069
-    {
3070
-        return $keys_only
3071
-            ? array(
3072
-                EE_Ticket_Selector_Config::DO_NOT_SHOW_DATETIME_SELECTOR,
3073
-                EE_Ticket_Selector_Config::MAYBE_SHOW_DATETIME_SELECTOR,
3074
-            )
3075
-            : array(
3076
-                EE_Ticket_Selector_Config::DO_NOT_SHOW_DATETIME_SELECTOR => esc_html__(
3077
-                    'Do not show date & time filter',
3078
-                    'event_espresso'
3079
-                ),
3080
-                EE_Ticket_Selector_Config::MAYBE_SHOW_DATETIME_SELECTOR  => esc_html__(
3081
-                    'Maybe show date & time filter',
3082
-                    'event_espresso'
3083
-                ),
3084
-            );
3085
-    }
3086
-
3087
-
3088
-    /**
3089
-     * @param string $show_datetime_selector
3090
-     */
3091
-    public function setShowDatetimeSelector($show_datetime_selector)
3092
-    {
3093
-        $this->show_datetime_selector = in_array(
3094
-            $show_datetime_selector,
3095
-            $this->getShowDatetimeSelectorOptions(),
3096
-            true
3097
-        )
3098
-            ? $show_datetime_selector
3099
-            : EE_Ticket_Selector_Config::DO_NOT_SHOW_DATETIME_SELECTOR;
3100
-    }
3101
-
3102
-
3103
-    /**
3104
-     * @return int
3105
-     */
3106
-    public function getDatetimeSelectorThreshold()
3107
-    {
3108
-        return $this->datetime_selector_threshold;
3109
-    }
3110
-
3111
-
3112
-    /**
3113
-     * @param int $datetime_selector_threshold
3114
-     */
3115
-    public function setDatetimeSelectorThreshold($datetime_selector_threshold)
3116
-    {
3117
-        $datetime_selector_threshold = absint($datetime_selector_threshold);
3118
-        $this->datetime_selector_threshold = $datetime_selector_threshold ? $datetime_selector_threshold : 3;
3119
-    }
3120
-
3121
-
3122
-    /**
3123
-     * @return int
3124
-     */
3125
-    public function getDatetimeSelectorMaxChecked()
3126
-    {
3127
-        return $this->datetime_selector_max_checked;
3128
-    }
3129
-
3130
-
3131
-    /**
3132
-     * @param int $datetime_selector_max_checked
3133
-     */
3134
-    public function setDatetimeSelectorMaxChecked($datetime_selector_max_checked)
3135
-    {
3136
-        $this->datetime_selector_max_checked = absint($datetime_selector_max_checked);
3137
-    }
2972
+	/**
2973
+	 * constant to indicate that a datetime selector should NEVER be shown for ticket selectors
2974
+	 */
2975
+	const DO_NOT_SHOW_DATETIME_SELECTOR = 'no_datetime_selector';
2976
+
2977
+	/**
2978
+	 * constant to indicate that a datetime selector should only be shown for ticket selectors
2979
+	 * when the number of datetimes for the event matches the value set for $datetime_selector_threshold
2980
+	 */
2981
+	const MAYBE_SHOW_DATETIME_SELECTOR = 'maybe_datetime_selector';
2982
+
2983
+	/**
2984
+	 * @var boolean $show_ticket_sale_columns
2985
+	 */
2986
+	public $show_ticket_sale_columns;
2987
+
2988
+	/**
2989
+	 * @var boolean $show_ticket_details
2990
+	 */
2991
+	public $show_ticket_details;
2992
+
2993
+	/**
2994
+	 * @var boolean $show_expired_tickets
2995
+	 */
2996
+	public $show_expired_tickets;
2997
+
2998
+	/**
2999
+	 * whether or not to display a dropdown box populated with event datetimes
3000
+	 * that toggles which tickets are displayed for a ticket selector.
3001
+	 * uses one of the *_DATETIME_SELECTOR constants defined above
3002
+	 *
3003
+	 * @var string $show_datetime_selector
3004
+	 */
3005
+	private $show_datetime_selector = 'no_datetime_selector';
3006
+
3007
+	/**
3008
+	 * the number of datetimes an event has to have before conditionally displaying a datetime selector
3009
+	 *
3010
+	 * @var int $datetime_selector_threshold
3011
+	 */
3012
+	private $datetime_selector_threshold = 3;
3013
+
3014
+	/**
3015
+	 * determines the maximum number of "checked" dates in the date and time filter
3016
+	 *
3017
+	 * @var int $datetime_selector_checked
3018
+	 */
3019
+	private $datetime_selector_max_checked = 10;
3020
+
3021
+
3022
+	/**
3023
+	 *    class constructor
3024
+	 */
3025
+	public function __construct()
3026
+	{
3027
+		$this->show_ticket_sale_columns = true;
3028
+		$this->show_ticket_details = true;
3029
+		$this->show_expired_tickets = true;
3030
+		$this->show_datetime_selector = EE_Ticket_Selector_Config::DO_NOT_SHOW_DATETIME_SELECTOR;
3031
+		$this->datetime_selector_threshold = 3;
3032
+		$this->datetime_selector_max_checked = 10;
3033
+	}
3034
+
3035
+
3036
+	/**
3037
+	 * returns true if a datetime selector should be displayed
3038
+	 *
3039
+	 * @param array $datetimes
3040
+	 * @return bool
3041
+	 */
3042
+	public function showDatetimeSelector(array $datetimes)
3043
+	{
3044
+		// if the settings are NOT: don't show OR below threshold, THEN active = true
3045
+		return ! (
3046
+			$this->getShowDatetimeSelector() === EE_Ticket_Selector_Config::DO_NOT_SHOW_DATETIME_SELECTOR
3047
+			|| (
3048
+				$this->getShowDatetimeSelector() === EE_Ticket_Selector_Config::MAYBE_SHOW_DATETIME_SELECTOR
3049
+				&& count($datetimes) < $this->getDatetimeSelectorThreshold()
3050
+			)
3051
+		);
3052
+	}
3053
+
3054
+
3055
+	/**
3056
+	 * @return string
3057
+	 */
3058
+	public function getShowDatetimeSelector()
3059
+	{
3060
+		return $this->show_datetime_selector;
3061
+	}
3062
+
3063
+
3064
+	/**
3065
+	 * @param bool $keys_only
3066
+	 * @return array
3067
+	 */
3068
+	public function getShowDatetimeSelectorOptions($keys_only = true)
3069
+	{
3070
+		return $keys_only
3071
+			? array(
3072
+				EE_Ticket_Selector_Config::DO_NOT_SHOW_DATETIME_SELECTOR,
3073
+				EE_Ticket_Selector_Config::MAYBE_SHOW_DATETIME_SELECTOR,
3074
+			)
3075
+			: array(
3076
+				EE_Ticket_Selector_Config::DO_NOT_SHOW_DATETIME_SELECTOR => esc_html__(
3077
+					'Do not show date & time filter',
3078
+					'event_espresso'
3079
+				),
3080
+				EE_Ticket_Selector_Config::MAYBE_SHOW_DATETIME_SELECTOR  => esc_html__(
3081
+					'Maybe show date & time filter',
3082
+					'event_espresso'
3083
+				),
3084
+			);
3085
+	}
3086
+
3087
+
3088
+	/**
3089
+	 * @param string $show_datetime_selector
3090
+	 */
3091
+	public function setShowDatetimeSelector($show_datetime_selector)
3092
+	{
3093
+		$this->show_datetime_selector = in_array(
3094
+			$show_datetime_selector,
3095
+			$this->getShowDatetimeSelectorOptions(),
3096
+			true
3097
+		)
3098
+			? $show_datetime_selector
3099
+			: EE_Ticket_Selector_Config::DO_NOT_SHOW_DATETIME_SELECTOR;
3100
+	}
3101
+
3102
+
3103
+	/**
3104
+	 * @return int
3105
+	 */
3106
+	public function getDatetimeSelectorThreshold()
3107
+	{
3108
+		return $this->datetime_selector_threshold;
3109
+	}
3110
+
3111
+
3112
+	/**
3113
+	 * @param int $datetime_selector_threshold
3114
+	 */
3115
+	public function setDatetimeSelectorThreshold($datetime_selector_threshold)
3116
+	{
3117
+		$datetime_selector_threshold = absint($datetime_selector_threshold);
3118
+		$this->datetime_selector_threshold = $datetime_selector_threshold ? $datetime_selector_threshold : 3;
3119
+	}
3120
+
3121
+
3122
+	/**
3123
+	 * @return int
3124
+	 */
3125
+	public function getDatetimeSelectorMaxChecked()
3126
+	{
3127
+		return $this->datetime_selector_max_checked;
3128
+	}
3129
+
3130
+
3131
+	/**
3132
+	 * @param int $datetime_selector_max_checked
3133
+	 */
3134
+	public function setDatetimeSelectorMaxChecked($datetime_selector_max_checked)
3135
+	{
3136
+		$this->datetime_selector_max_checked = absint($datetime_selector_max_checked);
3137
+	}
3138 3138
 }
3139 3139
 
3140 3140
 /**
@@ -3146,87 +3146,87 @@  discard block
 block discarded – undo
3146 3146
  */
3147 3147
 class EE_Environment_Config extends EE_Config_Base
3148 3148
 {
3149
-    /**
3150
-     * Hold any php environment variables that we want to track.
3151
-     *
3152
-     * @var stdClass;
3153
-     */
3154
-    public $php;
3155
-
3156
-
3157
-    /**
3158
-     *    constructor
3159
-     */
3160
-    public function __construct()
3161
-    {
3162
-        $this->php = new stdClass();
3163
-        $this->_set_php_values();
3164
-    }
3165
-
3166
-
3167
-    /**
3168
-     * This sets the php environment variables.
3169
-     *
3170
-     * @since 4.4.0
3171
-     * @return void
3172
-     */
3173
-    protected function _set_php_values()
3174
-    {
3175
-        $this->php->max_input_vars = ini_get('max_input_vars');
3176
-        $this->php->version = phpversion();
3177
-    }
3178
-
3179
-
3180
-    /**
3181
-     * helper method for determining whether input_count is
3182
-     * reaching the potential maximum the server can handle
3183
-     * according to max_input_vars
3184
-     *
3185
-     * @param int   $input_count the count of input vars.
3186
-     * @return array {
3187
-     *                           An array that represents whether available space and if no available space the error
3188
-     *                           message.
3189
-     * @type bool   $has_space   whether more inputs can be added.
3190
-     * @type string $msg         Any message to be displayed.
3191
-     *                           }
3192
-     */
3193
-    public function max_input_vars_limit_check($input_count = 0)
3194
-    {
3195
-        if (
3196
-            ! empty($this->php->max_input_vars)
3197
-            && ($input_count >= $this->php->max_input_vars)
3198
-        ) {
3199
-            // check the server setting because the config value could be stale
3200
-            $max_input_vars = ini_get('max_input_vars');
3201
-            if ($input_count >= $max_input_vars) {
3202
-                return sprintf(
3203
-                    esc_html__(
3204
-                        'The maximum number of inputs on this page has been exceeded. You cannot make edits to this page because of your server\'s PHP "max_input_vars" setting.%1$sThere are %2$d inputs and the maximum amount currently allowed by your server is %3$d.%1$sPlease contact your web host and ask them to raise the "max_input_vars" limit.',
3205
-                        'event_espresso'
3206
-                    ),
3207
-                    '<br>',
3208
-                    $input_count,
3209
-                    $max_input_vars
3210
-                );
3211
-            } else {
3212
-                return '';
3213
-            }
3214
-        } else {
3215
-            return '';
3216
-        }
3217
-    }
3218
-
3219
-
3220
-    /**
3221
-     * The purpose of this method is just to force rechecking php values so if they've changed, they get updated.
3222
-     *
3223
-     * @since 4.4.1
3224
-     * @return void
3225
-     */
3226
-    public function recheck_values()
3227
-    {
3228
-        $this->_set_php_values();
3229
-    }
3149
+	/**
3150
+	 * Hold any php environment variables that we want to track.
3151
+	 *
3152
+	 * @var stdClass;
3153
+	 */
3154
+	public $php;
3155
+
3156
+
3157
+	/**
3158
+	 *    constructor
3159
+	 */
3160
+	public function __construct()
3161
+	{
3162
+		$this->php = new stdClass();
3163
+		$this->_set_php_values();
3164
+	}
3165
+
3166
+
3167
+	/**
3168
+	 * This sets the php environment variables.
3169
+	 *
3170
+	 * @since 4.4.0
3171
+	 * @return void
3172
+	 */
3173
+	protected function _set_php_values()
3174
+	{
3175
+		$this->php->max_input_vars = ini_get('max_input_vars');
3176
+		$this->php->version = phpversion();
3177
+	}
3178
+
3179
+
3180
+	/**
3181
+	 * helper method for determining whether input_count is
3182
+	 * reaching the potential maximum the server can handle
3183
+	 * according to max_input_vars
3184
+	 *
3185
+	 * @param int   $input_count the count of input vars.
3186
+	 * @return array {
3187
+	 *                           An array that represents whether available space and if no available space the error
3188
+	 *                           message.
3189
+	 * @type bool   $has_space   whether more inputs can be added.
3190
+	 * @type string $msg         Any message to be displayed.
3191
+	 *                           }
3192
+	 */
3193
+	public function max_input_vars_limit_check($input_count = 0)
3194
+	{
3195
+		if (
3196
+			! empty($this->php->max_input_vars)
3197
+			&& ($input_count >= $this->php->max_input_vars)
3198
+		) {
3199
+			// check the server setting because the config value could be stale
3200
+			$max_input_vars = ini_get('max_input_vars');
3201
+			if ($input_count >= $max_input_vars) {
3202
+				return sprintf(
3203
+					esc_html__(
3204
+						'The maximum number of inputs on this page has been exceeded. You cannot make edits to this page because of your server\'s PHP "max_input_vars" setting.%1$sThere are %2$d inputs and the maximum amount currently allowed by your server is %3$d.%1$sPlease contact your web host and ask them to raise the "max_input_vars" limit.',
3205
+						'event_espresso'
3206
+					),
3207
+					'<br>',
3208
+					$input_count,
3209
+					$max_input_vars
3210
+				);
3211
+			} else {
3212
+				return '';
3213
+			}
3214
+		} else {
3215
+			return '';
3216
+		}
3217
+	}
3218
+
3219
+
3220
+	/**
3221
+	 * The purpose of this method is just to force rechecking php values so if they've changed, they get updated.
3222
+	 *
3223
+	 * @since 4.4.1
3224
+	 * @return void
3225
+	 */
3226
+	public function recheck_values()
3227
+	{
3228
+		$this->_set_php_values();
3229
+	}
3230 3230
 }
3231 3231
 
3232 3232
 /**
@@ -3238,21 +3238,21 @@  discard block
 block discarded – undo
3238 3238
  */
3239 3239
 class EE_Tax_Config extends EE_Config_Base
3240 3240
 {
3241
-    /*
3241
+	/*
3242 3242
      * flag to indicate whether or not to display ticket prices with the taxes included
3243 3243
      *
3244 3244
      * @var boolean $prices_displayed_including_taxes
3245 3245
      */
3246
-    public $prices_displayed_including_taxes;
3246
+	public $prices_displayed_including_taxes;
3247 3247
 
3248 3248
 
3249
-    /**
3250
-     *    class constructor
3251
-     */
3252
-    public function __construct()
3253
-    {
3254
-        $this->prices_displayed_including_taxes = true;
3255
-    }
3249
+	/**
3250
+	 *    class constructor
3251
+	 */
3252
+	public function __construct()
3253
+	{
3254
+		$this->prices_displayed_including_taxes = true;
3255
+	}
3256 3256
 }
3257 3257
 
3258 3258
 /**
@@ -3265,19 +3265,19 @@  discard block
 block discarded – undo
3265 3265
  */
3266 3266
 class EE_Messages_Config extends EE_Config_Base
3267 3267
 {
3268
-    /**
3269
-     * This is an integer representing the deletion threshold in months for when old messages will get deleted.
3270
-     * A value of 0 represents never deleting.  Default is 0.
3271
-     *
3272
-     * @var integer
3273
-     */
3274
-    public $delete_threshold;
3275
-
3276
-
3277
-    public function __construct()
3278
-    {
3279
-        $this->delete_threshold = 0;
3280
-    }
3268
+	/**
3269
+	 * This is an integer representing the deletion threshold in months for when old messages will get deleted.
3270
+	 * A value of 0 represents never deleting.  Default is 0.
3271
+	 *
3272
+	 * @var integer
3273
+	 */
3274
+	public $delete_threshold;
3275
+
3276
+
3277
+	public function __construct()
3278
+	{
3279
+		$this->delete_threshold = 0;
3280
+	}
3281 3281
 }
3282 3282
 
3283 3283
 /**
@@ -3287,31 +3287,31 @@  discard block
 block discarded – undo
3287 3287
  */
3288 3288
 class EE_Gateway_Config extends EE_Config_Base
3289 3289
 {
3290
-    /**
3291
-     * Array with keys that are payment gateways slugs, and values are arrays
3292
-     * with any config info the gateway wants to store
3293
-     *
3294
-     * @var array
3295
-     */
3296
-    public $payment_settings;
3297
-
3298
-    /**
3299
-     * Where keys are gateway slugs, and values are booleans indicating whether or not
3300
-     * the gateway is stored in the uploads directory
3301
-     *
3302
-     * @var array
3303
-     */
3304
-    public $active_gateways;
3305
-
3306
-
3307
-    /**
3308
-     *    class constructor
3309
-     *
3310
-     * @deprecated
3311
-     */
3312
-    public function __construct()
3313
-    {
3314
-        $this->payment_settings = array();
3315
-        $this->active_gateways = array('Invoice' => false);
3316
-    }
3290
+	/**
3291
+	 * Array with keys that are payment gateways slugs, and values are arrays
3292
+	 * with any config info the gateway wants to store
3293
+	 *
3294
+	 * @var array
3295
+	 */
3296
+	public $payment_settings;
3297
+
3298
+	/**
3299
+	 * Where keys are gateway slugs, and values are booleans indicating whether or not
3300
+	 * the gateway is stored in the uploads directory
3301
+	 *
3302
+	 * @var array
3303
+	 */
3304
+	public $active_gateways;
3305
+
3306
+
3307
+	/**
3308
+	 *    class constructor
3309
+	 *
3310
+	 * @deprecated
3311
+	 */
3312
+	public function __construct()
3313
+	{
3314
+		$this->payment_settings = array();
3315
+		$this->active_gateways = array('Invoice' => false);
3316
+	}
3317 3317
 }
Please login to merge, or discard this patch.
core/CPTs/CptQueryModifier.php 2 patches
Indentation   +578 added lines, -578 removed lines patch added patch discarded remove patch
@@ -30,582 +30,582 @@
 block discarded – undo
30 30
  */
31 31
 class CptQueryModifier
32 32
 {
33
-    /**
34
-     * @var CurrentPage $current_page
35
-     */
36
-    protected $current_page;
37
-
38
-    /**
39
-     * @var string $post_type
40
-     */
41
-    protected $post_type = '';
42
-
43
-    /**
44
-     * CPT details from CustomPostTypeDefinitions for specific post type
45
-     *
46
-     * @var array $cpt_details
47
-     */
48
-    protected $cpt_details = array();
49
-
50
-    /**
51
-     * @var EE_Table_Base[] $model_tables
52
-     */
53
-    protected $model_tables = array();
54
-
55
-    /**
56
-     * @var array $taxonomies
57
-     */
58
-    protected $taxonomies = array();
59
-
60
-    /**
61
-     * meta table for the related CPT
62
-     *
63
-     * @var EE_Secondary_Table $meta_table
64
-     */
65
-    protected $meta_table;
66
-
67
-    /**
68
-     * EEM_CPT_Base model for the related CPT
69
-     *
70
-     * @var EEM_CPT_Base $model
71
-     */
72
-    protected $model;
73
-
74
-    /**
75
-     * @var EE_Request_Handler $request_handler
76
-     */
77
-    protected $request_handler;
78
-
79
-    /**
80
-     * @var WP_Query $wp_query
81
-     */
82
-    protected $wp_query;
83
-
84
-    /**
85
-     * @var LoaderInterface $loader
86
-     */
87
-    protected $loader;
88
-
89
-    /**
90
-     * @var RequestInterface $request
91
-     */
92
-    protected $request;
93
-
94
-
95
-    /**
96
-     * CptQueryModifier constructor
97
-     *
98
-     * @param string             $post_type
99
-     * @param array              $cpt_details
100
-     * @param WP_Query           $WP_Query
101
-     * @param CurrentPage $current_page
102
-     * @param RequestInterface   $request
103
-     * @param LoaderInterface    $loader
104
-     * @throws EE_Error
105
-     */
106
-    public function __construct(
107
-        $post_type,
108
-        array $cpt_details,
109
-        WP_Query $WP_Query,
110
-        CurrentPage $current_page,
111
-        RequestInterface $request,
112
-        LoaderInterface $loader
113
-    ) {
114
-        $this->loader = $loader;
115
-        $this->request = $request;
116
-        $this->current_page = $current_page;
117
-        $this->setWpQuery($WP_Query);
118
-        $this->setPostType($post_type);
119
-        $this->setCptDetails($cpt_details);
120
-        $this->init();
121
-    }
122
-
123
-
124
-    /**
125
-     * @return string
126
-     */
127
-    public function postType()
128
-    {
129
-        return $this->post_type;
130
-    }
131
-
132
-
133
-    /**
134
-     * @param string $post_type
135
-     */
136
-    protected function setPostType($post_type)
137
-    {
138
-        $this->post_type = $post_type;
139
-    }
140
-
141
-
142
-    /**
143
-     * @return array
144
-     */
145
-    public function cptDetails()
146
-    {
147
-        return $this->cpt_details;
148
-    }
149
-
150
-
151
-    /**
152
-     * @param array $cpt_details
153
-     */
154
-    protected function setCptDetails($cpt_details)
155
-    {
156
-        $this->cpt_details = $cpt_details;
157
-    }
158
-
159
-
160
-    /**
161
-     * @return EE_Table_Base[]
162
-     */
163
-    public function modelTables()
164
-    {
165
-        return $this->model_tables;
166
-    }
167
-
168
-
169
-    /**
170
-     * @param EE_Table_Base[] $model_tables
171
-     */
172
-    protected function setModelTables($model_tables)
173
-    {
174
-        $this->model_tables = $model_tables;
175
-    }
176
-
177
-
178
-    /**
179
-     * @return array
180
-     * @throws InvalidArgumentException
181
-     * @throws InvalidDataTypeException
182
-     * @throws InvalidInterfaceException
183
-     */
184
-    public function taxonomies()
185
-    {
186
-        if (empty($this->taxonomies)) {
187
-            $this->initializeTaxonomies();
188
-        }
189
-        return $this->taxonomies;
190
-    }
191
-
192
-
193
-    /**
194
-     * @param array $taxonomies
195
-     */
196
-    protected function setTaxonomies(array $taxonomies)
197
-    {
198
-        $this->taxonomies = $taxonomies;
199
-    }
200
-
201
-
202
-    /**
203
-     * @return EE_Secondary_Table
204
-     */
205
-    public function metaTable()
206
-    {
207
-        return $this->meta_table;
208
-    }
209
-
210
-
211
-    /**
212
-     * @param EE_Secondary_Table $meta_table
213
-     */
214
-    public function setMetaTable(EE_Secondary_Table $meta_table)
215
-    {
216
-        $this->meta_table = $meta_table;
217
-    }
218
-
219
-
220
-    /**
221
-     * @return EEM_Base
222
-     */
223
-    public function model()
224
-    {
225
-        return $this->model;
226
-    }
227
-
228
-
229
-    /**
230
-     * @param EEM_Base $CPT_model
231
-     */
232
-    protected function setModel(EEM_Base $CPT_model)
233
-    {
234
-        $this->model = $CPT_model;
235
-    }
236
-
237
-
238
-    /**
239
-     * @deprecated 4.9.63.p
240
-     * @return EE_Request_Handler
241
-     */
242
-    public function request()
243
-    {
244
-        if (! $this->request_handler instanceof EE_Request_Handler) {
245
-            $this->request_handler = LoaderFactory::getLoader()->getShared('EE_Request_Handler');
246
-        }
247
-        return $this->request_handler;
248
-    }
249
-
250
-
251
-
252
-    // phpcs:disable PSR1.Methods.CamelCapsMethodName.NotCamelCaps
253
-
254
-
255
-    /**
256
-     * @return WP_Query
257
-     */
258
-    public function WpQuery()
259
-    {
260
-        return $this->wp_query;
261
-    }
262
-    // phpcs:enable
263
-
264
-
265
-    /**
266
-     * @param WP_Query $wp_query
267
-     */
268
-    public function setWpQuery(WP_Query $wp_query)
269
-    {
270
-        $this->wp_query = $wp_query;
271
-    }
272
-
273
-
274
-    /**
275
-     * @return void
276
-     * @throws InvalidDataTypeException
277
-     * @throws InvalidInterfaceException
278
-     * @throws InvalidArgumentException
279
-     */
280
-    protected function initializeTaxonomies()
281
-    {
282
-        // check if taxonomies have already been set and that this CPT has taxonomies registered for it
283
-        if (
284
-            empty($this->taxonomies)
285
-            && isset($this->cpt_details['args']['taxonomies'])
286
-        ) {
287
-            // if so then grab them, but we want the taxonomy name as the key
288
-            $taxonomies = array_flip($this->cpt_details['args']['taxonomies']);
289
-            // then grab the list of ALL taxonomies
290
-            /** @var CustomTaxonomyDefinitions
291
-             * $taxonomy_definitions
292
-             */
293
-            $taxonomy_definitions = $this->loader->getShared(
294
-                'EventEspresso\core\domain\entities\custom_post_types\CustomTaxonomyDefinitions'
295
-            );
296
-            $all_taxonomies = $taxonomy_definitions->getCustomTaxonomyDefinitions();
297
-            foreach ($taxonomies as $taxonomy => &$details) {
298
-                // add details to our taxonomies if they exist
299
-                $details = isset($all_taxonomies[ $taxonomy ])
300
-                    ? $all_taxonomies[ $taxonomy ]
301
-                    : array();
302
-            }
303
-            // ALWAYS unset() variables that were passed by reference
304
-            unset($details);
305
-            $this->setTaxonomies($taxonomies);
306
-        }
307
-    }
308
-
309
-
310
-    /**
311
-     * @since 4.9.63.p
312
-     * @throws EE_Error
313
-     */
314
-    protected function init()
315
-    {
316
-        $this->setAdditionalCptDetails();
317
-        $this->setRequestVarsIfCpt();
318
-        // convert post_type to model name
319
-        $model_name = str_replace('EE_', '', $this->cpt_details['class_name']);
320
-        // load all tables related to CPT
321
-        $this->setupModelsAndTables($model_name);
322
-        // load and instantiate CPT_*_Strategy
323
-        $CPT_Strategy = $this->cptStrategyClass($model_name);
324
-        // !!!!!!!!!!  IMPORTANT !!!!!!!!!!!!
325
-        // here's the list of available filters in the WP_Query object
326
-        // 'posts_where_paged'
327
-        // 'posts_groupby'
328
-        // 'posts_join_paged'
329
-        // 'posts_orderby'
330
-        // 'posts_distinct'
331
-        // 'post_limits'
332
-        // 'posts_fields'
333
-        // 'posts_join'
334
-        add_filter('posts_fields', array($this, 'postsFields'));
335
-        add_filter('posts_join', array($this, 'postsJoin'));
336
-        add_filter(
337
-            'get_' . $this->post_type . '_metadata',
338
-            array($CPT_Strategy, 'get_EE_post_type_metadata'),
339
-            1,
340
-            4
341
-        );
342
-        add_filter('the_posts', array($this, 'thePosts'), 1, 1);
343
-        if ($this->wp_query->is_main_query()) {
344
-            add_filter('get_edit_post_link', array($this, 'getEditPostLink'), 10, 2);
345
-            $this->addTemplateFilters();
346
-        }
347
-    }
348
-
349
-
350
-    /**
351
-     * sets some basic query vars that pertain to the CPT
352
-     *
353
-     * @access protected
354
-     * @return void
355
-     */
356
-    protected function setAdditionalCptDetails()
357
-    {
358
-        // the post or category or term that is triggering EE
359
-        $this->cpt_details['espresso_page'] = $this->current_page->isEspressoPage();
360
-        // requested post name
361
-        $this->cpt_details['post_name'] = $this->request->getRequestParam('post_name');
362
-        // add support for viewing 'private', 'draft', or 'pending' posts
363
-        if (
364
-            isset($this->wp_query->query_vars['p'])
365
-            && $this->wp_query->query_vars['p'] !== 0
366
-            && is_user_logged_in()
367
-            && current_user_can('edit_post', $this->wp_query->query_vars['p'])
368
-        ) {
369
-            // we can just inject directly into the WP_Query object
370
-            $this->wp_query->query['post_status'] = array('publish', 'private', 'draft', 'pending');
371
-            // now set the main 'ee' request var so that the appropriate module can load the appropriate template(s)
372
-            $this->request->setRequestParam('ee', $this->cpt_details['singular_slug']);
373
-        }
374
-    }
375
-
376
-
377
-    /**
378
-     * Checks if we're on a EE-CPT archive-or-single page, and if we've never set the EE request var.
379
-     * If so, sets the 'ee' request variable
380
-     * so other parts of EE can know what CPT is getting queried.
381
-     * To Mike's knowledge, this must be called from during or after the pre_get_posts hook
382
-     * in order for is_archive() and is_single() methods to work properly.
383
-     *
384
-     * @return void
385
-     */
386
-    public function setRequestVarsIfCpt()
387
-    {
388
-        // check if ee action var has been set
389
-        if (! $this->request->requestParamIsSet('ee')) {
390
-            // check that route exists for CPT archive slug
391
-            if (is_archive() && EE_Config::get_route($this->cpt_details['plural_slug'])) {
392
-                // ie: set "ee" to "events"
393
-                $this->request->setRequestParam('ee', $this->cpt_details['plural_slug']);
394
-                // or does it match a single page CPT like /event/
395
-            } elseif (is_single() && EE_Config::get_route($this->cpt_details['singular_slug'])) {
396
-                // ie: set "ee" to "event"
397
-                $this->request->setRequestParam('ee', $this->cpt_details['singular_slug']);
398
-            }
399
-        }
400
-    }
401
-
402
-
403
-    /**
404
-     * setupModelsAndTables
405
-     *
406
-     * @access protected
407
-     * @param string $model_name
408
-     * @throws EE_Error
409
-     */
410
-    protected function setupModelsAndTables($model_name)
411
-    {
412
-        // get CPT table data via CPT Model
413
-        $full_model_name = strpos($model_name, 'EEM_') !== 0
414
-            ? 'EEM_' . $model_name
415
-            : $model_name;
416
-        $model = $this->loader->getShared($full_model_name);
417
-        if (! $model instanceof EEM_Base) {
418
-            throw new EE_Error(
419
-                sprintf(
420
-                    esc_html__(
421
-                        'The "%1$s" model could not be loaded.',
422
-                        'event_espresso'
423
-                    ),
424
-                    $full_model_name
425
-                )
426
-            );
427
-        }
428
-        $this->setModel($model);
429
-        $this->setModelTables($this->model->get_tables());
430
-        $meta_model = $model_name . '_Meta';
431
-        // is there a Meta Table for this CPT?
432
-        if (
433
-            isset($this->cpt_details['tables'][ $meta_model ])
434
-            && $this->cpt_details['tables'][ $meta_model ] instanceof EE_Secondary_Table
435
-        ) {
436
-            $this->setMetaTable($this->cpt_details['tables'][ $meta_model ]);
437
-        }
438
-    }
439
-
440
-
441
-    /**
442
-     * cptStrategyClass
443
-     *
444
-     * @access protected
445
-     * @param  string $model_name
446
-     * @return string
447
-     */
448
-    protected function cptStrategyClass($model_name)
449
-    {
450
-        // creates classname like:  CPT_Event_Strategy
451
-        $CPT_Strategy_class_name = 'EE_CPT_' . $model_name . '_Strategy';
452
-        // load and instantiate
453
-        $CPT_Strategy = $this->loader->getShared(
454
-            $CPT_Strategy_class_name,
455
-            array('WP_Query' => $this->wp_query, 'CPT' => $this->cpt_details)
456
-        );
457
-        if ($CPT_Strategy === null) {
458
-            $CPT_Strategy = $this->loader->getShared(
459
-                'EE_CPT_Default_Strategy',
460
-                array('WP_Query' => $this->wp_query, 'CPT' => $this->cpt_details)
461
-            );
462
-        }
463
-        return $CPT_Strategy;
464
-    }
465
-
466
-
467
-    /**
468
-     * postsFields
469
-     *
470
-     * @access public
471
-     * @param  $SQL
472
-     * @return string
473
-     */
474
-    public function postsFields($SQL)
475
-    {
476
-        // does this CPT have a meta table ?
477
-        if ($this->meta_table instanceof EE_Secondary_Table) {
478
-            // adds something like ", wp_esp_event_meta.* " to WP Query SELECT statement
479
-            $SQL .= ', ' . $this->meta_table->get_table_name() . '.* ';
480
-        }
481
-        remove_filter('posts_fields', array($this, 'postsFields'));
482
-        return $SQL;
483
-    }
484
-
485
-
486
-    /**
487
-     * postsJoin
488
-     *
489
-     * @access public
490
-     * @param  $SQL
491
-     * @return string
492
-     */
493
-    public function postsJoin($SQL)
494
-    {
495
-        // does this CPT have a meta table ?
496
-        if ($this->meta_table instanceof EE_Secondary_Table) {
497
-            global $wpdb;
498
-            // adds something like " LEFT JOIN wp_esp_event_meta ON ( wp_esp_event_meta.EVT_ID = wp_posts.ID ) " to WP Query JOIN statement
499
-            $SQL .= ' LEFT JOIN '
500
-                    . $this->meta_table->get_table_name()
501
-                    . ' ON ( '
502
-                    . $this->meta_table->get_table_name()
503
-                    . '.'
504
-                    . $this->meta_table->get_fk_on_table()
505
-                    . ' = '
506
-                    . $wpdb->posts
507
-                    . '.ID ) ';
508
-        }
509
-        remove_filter('posts_join', array($this, 'postsJoin'));
510
-        return $SQL;
511
-    }
512
-
513
-
514
-    /**
515
-     * thePosts
516
-     *
517
-     * @access public
518
-     * @param  WP_Post[] $posts
519
-     * @return WP_Post[]
520
-     */
521
-    public function thePosts($posts)
522
-    {
523
-        $CPT_class = $this->cpt_details['class_name'];
524
-        // loop thru posts
525
-        if (is_array($posts) && $this->model instanceof EEM_CPT_Base) {
526
-            foreach ($posts as $post) {
527
-                if ($post->post_type === $this->post_type) {
528
-                    $post->{$CPT_class} = $this->model->instantiate_class_from_post_object($post);
529
-                }
530
-            }
531
-        }
532
-        remove_filter('the_posts', array($this, 'thePosts'), 1);
533
-        return $posts;
534
-    }
535
-
536
-
537
-    /**
538
-     * @param $url
539
-     * @param $ID
540
-     * @return string
541
-     */
542
-    public function getEditPostLink($url, $ID)
543
-    {
544
-        // need to make sure we only edit links if our cpt
545
-        global $post;
546
-        // notice if the cpt is registered with `show_ee_ui` set to false, we take that to mean that the WordPress core ui
547
-        // for interacting with the CPT is desired and there is no EE UI for interacting with the CPT in the admin.
548
-        if (
549
-            ! $post instanceof WP_Post
550
-            || $post->post_type !== $this->post_type
551
-            || (
552
-                isset($this->cpt_details['args']['show_ee_ui'])
553
-                && ! $this->cpt_details['args']['show_ee_ui']
554
-            )
555
-        ) {
556
-            return $url;
557
-        }
558
-        // k made it here so all is good.
559
-        return wp_nonce_url(
560
-            add_query_arg(
561
-                array('page' => $this->post_type, 'post' => $ID, 'action' => 'edit'),
562
-                admin_url('admin.php')
563
-            ),
564
-            'edit',
565
-            'edit_nonce'
566
-        );
567
-    }
568
-
569
-
570
-    /**
571
-     * Execute any template filters.
572
-     * This method is only called if in main query.
573
-     *
574
-     * @return void
575
-     */
576
-    public function addTemplateFilters()
577
-    {
578
-        // if requested cpt supports page_templates and it's the main query
579
-        if (! empty($this->cpt_details['args']['page_templates']) && $this->wp_query->is_main_query()) {
580
-            // then let's hook into the appropriate query_template hook
581
-            add_filter('single_template', array($this, 'singleCptTemplate'));
582
-        }
583
-    }
584
-
585
-
586
-    /**
587
-     * Callback for single_template wp filter.
588
-     * This is used to load the set page_template for a single ee cpt if its set.  If "default" then we load the normal
589
-     * hierarchy.
590
-     *
591
-     * @access public
592
-     * @param string $current_template Existing default template path derived for this page call.
593
-     * @return string the path to the full template file.
594
-     */
595
-    public function singleCptTemplate($current_template)
596
-    {
597
-        $object = get_queried_object();
598
-        // does this called object HAVE a page template set that is something other than the default.
599
-        $template = get_post_meta($object->ID, '_wp_page_template', true);
600
-        // exit early if default or not set or invalid path (accounts for theme changes)
601
-        if (
602
-            $template === 'default'
603
-            || empty($template)
604
-            || ! is_readable(get_stylesheet_directory() . '/' . $template)
605
-        ) {
606
-            return $current_template;
607
-        }
608
-        // made it here so we SHOULD be able to just locate the template and then return it.
609
-        return locate_template(array($template));
610
-    }
33
+	/**
34
+	 * @var CurrentPage $current_page
35
+	 */
36
+	protected $current_page;
37
+
38
+	/**
39
+	 * @var string $post_type
40
+	 */
41
+	protected $post_type = '';
42
+
43
+	/**
44
+	 * CPT details from CustomPostTypeDefinitions for specific post type
45
+	 *
46
+	 * @var array $cpt_details
47
+	 */
48
+	protected $cpt_details = array();
49
+
50
+	/**
51
+	 * @var EE_Table_Base[] $model_tables
52
+	 */
53
+	protected $model_tables = array();
54
+
55
+	/**
56
+	 * @var array $taxonomies
57
+	 */
58
+	protected $taxonomies = array();
59
+
60
+	/**
61
+	 * meta table for the related CPT
62
+	 *
63
+	 * @var EE_Secondary_Table $meta_table
64
+	 */
65
+	protected $meta_table;
66
+
67
+	/**
68
+	 * EEM_CPT_Base model for the related CPT
69
+	 *
70
+	 * @var EEM_CPT_Base $model
71
+	 */
72
+	protected $model;
73
+
74
+	/**
75
+	 * @var EE_Request_Handler $request_handler
76
+	 */
77
+	protected $request_handler;
78
+
79
+	/**
80
+	 * @var WP_Query $wp_query
81
+	 */
82
+	protected $wp_query;
83
+
84
+	/**
85
+	 * @var LoaderInterface $loader
86
+	 */
87
+	protected $loader;
88
+
89
+	/**
90
+	 * @var RequestInterface $request
91
+	 */
92
+	protected $request;
93
+
94
+
95
+	/**
96
+	 * CptQueryModifier constructor
97
+	 *
98
+	 * @param string             $post_type
99
+	 * @param array              $cpt_details
100
+	 * @param WP_Query           $WP_Query
101
+	 * @param CurrentPage $current_page
102
+	 * @param RequestInterface   $request
103
+	 * @param LoaderInterface    $loader
104
+	 * @throws EE_Error
105
+	 */
106
+	public function __construct(
107
+		$post_type,
108
+		array $cpt_details,
109
+		WP_Query $WP_Query,
110
+		CurrentPage $current_page,
111
+		RequestInterface $request,
112
+		LoaderInterface $loader
113
+	) {
114
+		$this->loader = $loader;
115
+		$this->request = $request;
116
+		$this->current_page = $current_page;
117
+		$this->setWpQuery($WP_Query);
118
+		$this->setPostType($post_type);
119
+		$this->setCptDetails($cpt_details);
120
+		$this->init();
121
+	}
122
+
123
+
124
+	/**
125
+	 * @return string
126
+	 */
127
+	public function postType()
128
+	{
129
+		return $this->post_type;
130
+	}
131
+
132
+
133
+	/**
134
+	 * @param string $post_type
135
+	 */
136
+	protected function setPostType($post_type)
137
+	{
138
+		$this->post_type = $post_type;
139
+	}
140
+
141
+
142
+	/**
143
+	 * @return array
144
+	 */
145
+	public function cptDetails()
146
+	{
147
+		return $this->cpt_details;
148
+	}
149
+
150
+
151
+	/**
152
+	 * @param array $cpt_details
153
+	 */
154
+	protected function setCptDetails($cpt_details)
155
+	{
156
+		$this->cpt_details = $cpt_details;
157
+	}
158
+
159
+
160
+	/**
161
+	 * @return EE_Table_Base[]
162
+	 */
163
+	public function modelTables()
164
+	{
165
+		return $this->model_tables;
166
+	}
167
+
168
+
169
+	/**
170
+	 * @param EE_Table_Base[] $model_tables
171
+	 */
172
+	protected function setModelTables($model_tables)
173
+	{
174
+		$this->model_tables = $model_tables;
175
+	}
176
+
177
+
178
+	/**
179
+	 * @return array
180
+	 * @throws InvalidArgumentException
181
+	 * @throws InvalidDataTypeException
182
+	 * @throws InvalidInterfaceException
183
+	 */
184
+	public function taxonomies()
185
+	{
186
+		if (empty($this->taxonomies)) {
187
+			$this->initializeTaxonomies();
188
+		}
189
+		return $this->taxonomies;
190
+	}
191
+
192
+
193
+	/**
194
+	 * @param array $taxonomies
195
+	 */
196
+	protected function setTaxonomies(array $taxonomies)
197
+	{
198
+		$this->taxonomies = $taxonomies;
199
+	}
200
+
201
+
202
+	/**
203
+	 * @return EE_Secondary_Table
204
+	 */
205
+	public function metaTable()
206
+	{
207
+		return $this->meta_table;
208
+	}
209
+
210
+
211
+	/**
212
+	 * @param EE_Secondary_Table $meta_table
213
+	 */
214
+	public function setMetaTable(EE_Secondary_Table $meta_table)
215
+	{
216
+		$this->meta_table = $meta_table;
217
+	}
218
+
219
+
220
+	/**
221
+	 * @return EEM_Base
222
+	 */
223
+	public function model()
224
+	{
225
+		return $this->model;
226
+	}
227
+
228
+
229
+	/**
230
+	 * @param EEM_Base $CPT_model
231
+	 */
232
+	protected function setModel(EEM_Base $CPT_model)
233
+	{
234
+		$this->model = $CPT_model;
235
+	}
236
+
237
+
238
+	/**
239
+	 * @deprecated 4.9.63.p
240
+	 * @return EE_Request_Handler
241
+	 */
242
+	public function request()
243
+	{
244
+		if (! $this->request_handler instanceof EE_Request_Handler) {
245
+			$this->request_handler = LoaderFactory::getLoader()->getShared('EE_Request_Handler');
246
+		}
247
+		return $this->request_handler;
248
+	}
249
+
250
+
251
+
252
+	// phpcs:disable PSR1.Methods.CamelCapsMethodName.NotCamelCaps
253
+
254
+
255
+	/**
256
+	 * @return WP_Query
257
+	 */
258
+	public function WpQuery()
259
+	{
260
+		return $this->wp_query;
261
+	}
262
+	// phpcs:enable
263
+
264
+
265
+	/**
266
+	 * @param WP_Query $wp_query
267
+	 */
268
+	public function setWpQuery(WP_Query $wp_query)
269
+	{
270
+		$this->wp_query = $wp_query;
271
+	}
272
+
273
+
274
+	/**
275
+	 * @return void
276
+	 * @throws InvalidDataTypeException
277
+	 * @throws InvalidInterfaceException
278
+	 * @throws InvalidArgumentException
279
+	 */
280
+	protected function initializeTaxonomies()
281
+	{
282
+		// check if taxonomies have already been set and that this CPT has taxonomies registered for it
283
+		if (
284
+			empty($this->taxonomies)
285
+			&& isset($this->cpt_details['args']['taxonomies'])
286
+		) {
287
+			// if so then grab them, but we want the taxonomy name as the key
288
+			$taxonomies = array_flip($this->cpt_details['args']['taxonomies']);
289
+			// then grab the list of ALL taxonomies
290
+			/** @var CustomTaxonomyDefinitions
291
+			 * $taxonomy_definitions
292
+			 */
293
+			$taxonomy_definitions = $this->loader->getShared(
294
+				'EventEspresso\core\domain\entities\custom_post_types\CustomTaxonomyDefinitions'
295
+			);
296
+			$all_taxonomies = $taxonomy_definitions->getCustomTaxonomyDefinitions();
297
+			foreach ($taxonomies as $taxonomy => &$details) {
298
+				// add details to our taxonomies if they exist
299
+				$details = isset($all_taxonomies[ $taxonomy ])
300
+					? $all_taxonomies[ $taxonomy ]
301
+					: array();
302
+			}
303
+			// ALWAYS unset() variables that were passed by reference
304
+			unset($details);
305
+			$this->setTaxonomies($taxonomies);
306
+		}
307
+	}
308
+
309
+
310
+	/**
311
+	 * @since 4.9.63.p
312
+	 * @throws EE_Error
313
+	 */
314
+	protected function init()
315
+	{
316
+		$this->setAdditionalCptDetails();
317
+		$this->setRequestVarsIfCpt();
318
+		// convert post_type to model name
319
+		$model_name = str_replace('EE_', '', $this->cpt_details['class_name']);
320
+		// load all tables related to CPT
321
+		$this->setupModelsAndTables($model_name);
322
+		// load and instantiate CPT_*_Strategy
323
+		$CPT_Strategy = $this->cptStrategyClass($model_name);
324
+		// !!!!!!!!!!  IMPORTANT !!!!!!!!!!!!
325
+		// here's the list of available filters in the WP_Query object
326
+		// 'posts_where_paged'
327
+		// 'posts_groupby'
328
+		// 'posts_join_paged'
329
+		// 'posts_orderby'
330
+		// 'posts_distinct'
331
+		// 'post_limits'
332
+		// 'posts_fields'
333
+		// 'posts_join'
334
+		add_filter('posts_fields', array($this, 'postsFields'));
335
+		add_filter('posts_join', array($this, 'postsJoin'));
336
+		add_filter(
337
+			'get_' . $this->post_type . '_metadata',
338
+			array($CPT_Strategy, 'get_EE_post_type_metadata'),
339
+			1,
340
+			4
341
+		);
342
+		add_filter('the_posts', array($this, 'thePosts'), 1, 1);
343
+		if ($this->wp_query->is_main_query()) {
344
+			add_filter('get_edit_post_link', array($this, 'getEditPostLink'), 10, 2);
345
+			$this->addTemplateFilters();
346
+		}
347
+	}
348
+
349
+
350
+	/**
351
+	 * sets some basic query vars that pertain to the CPT
352
+	 *
353
+	 * @access protected
354
+	 * @return void
355
+	 */
356
+	protected function setAdditionalCptDetails()
357
+	{
358
+		// the post or category or term that is triggering EE
359
+		$this->cpt_details['espresso_page'] = $this->current_page->isEspressoPage();
360
+		// requested post name
361
+		$this->cpt_details['post_name'] = $this->request->getRequestParam('post_name');
362
+		// add support for viewing 'private', 'draft', or 'pending' posts
363
+		if (
364
+			isset($this->wp_query->query_vars['p'])
365
+			&& $this->wp_query->query_vars['p'] !== 0
366
+			&& is_user_logged_in()
367
+			&& current_user_can('edit_post', $this->wp_query->query_vars['p'])
368
+		) {
369
+			// we can just inject directly into the WP_Query object
370
+			$this->wp_query->query['post_status'] = array('publish', 'private', 'draft', 'pending');
371
+			// now set the main 'ee' request var so that the appropriate module can load the appropriate template(s)
372
+			$this->request->setRequestParam('ee', $this->cpt_details['singular_slug']);
373
+		}
374
+	}
375
+
376
+
377
+	/**
378
+	 * Checks if we're on a EE-CPT archive-or-single page, and if we've never set the EE request var.
379
+	 * If so, sets the 'ee' request variable
380
+	 * so other parts of EE can know what CPT is getting queried.
381
+	 * To Mike's knowledge, this must be called from during or after the pre_get_posts hook
382
+	 * in order for is_archive() and is_single() methods to work properly.
383
+	 *
384
+	 * @return void
385
+	 */
386
+	public function setRequestVarsIfCpt()
387
+	{
388
+		// check if ee action var has been set
389
+		if (! $this->request->requestParamIsSet('ee')) {
390
+			// check that route exists for CPT archive slug
391
+			if (is_archive() && EE_Config::get_route($this->cpt_details['plural_slug'])) {
392
+				// ie: set "ee" to "events"
393
+				$this->request->setRequestParam('ee', $this->cpt_details['plural_slug']);
394
+				// or does it match a single page CPT like /event/
395
+			} elseif (is_single() && EE_Config::get_route($this->cpt_details['singular_slug'])) {
396
+				// ie: set "ee" to "event"
397
+				$this->request->setRequestParam('ee', $this->cpt_details['singular_slug']);
398
+			}
399
+		}
400
+	}
401
+
402
+
403
+	/**
404
+	 * setupModelsAndTables
405
+	 *
406
+	 * @access protected
407
+	 * @param string $model_name
408
+	 * @throws EE_Error
409
+	 */
410
+	protected function setupModelsAndTables($model_name)
411
+	{
412
+		// get CPT table data via CPT Model
413
+		$full_model_name = strpos($model_name, 'EEM_') !== 0
414
+			? 'EEM_' . $model_name
415
+			: $model_name;
416
+		$model = $this->loader->getShared($full_model_name);
417
+		if (! $model instanceof EEM_Base) {
418
+			throw new EE_Error(
419
+				sprintf(
420
+					esc_html__(
421
+						'The "%1$s" model could not be loaded.',
422
+						'event_espresso'
423
+					),
424
+					$full_model_name
425
+				)
426
+			);
427
+		}
428
+		$this->setModel($model);
429
+		$this->setModelTables($this->model->get_tables());
430
+		$meta_model = $model_name . '_Meta';
431
+		// is there a Meta Table for this CPT?
432
+		if (
433
+			isset($this->cpt_details['tables'][ $meta_model ])
434
+			&& $this->cpt_details['tables'][ $meta_model ] instanceof EE_Secondary_Table
435
+		) {
436
+			$this->setMetaTable($this->cpt_details['tables'][ $meta_model ]);
437
+		}
438
+	}
439
+
440
+
441
+	/**
442
+	 * cptStrategyClass
443
+	 *
444
+	 * @access protected
445
+	 * @param  string $model_name
446
+	 * @return string
447
+	 */
448
+	protected function cptStrategyClass($model_name)
449
+	{
450
+		// creates classname like:  CPT_Event_Strategy
451
+		$CPT_Strategy_class_name = 'EE_CPT_' . $model_name . '_Strategy';
452
+		// load and instantiate
453
+		$CPT_Strategy = $this->loader->getShared(
454
+			$CPT_Strategy_class_name,
455
+			array('WP_Query' => $this->wp_query, 'CPT' => $this->cpt_details)
456
+		);
457
+		if ($CPT_Strategy === null) {
458
+			$CPT_Strategy = $this->loader->getShared(
459
+				'EE_CPT_Default_Strategy',
460
+				array('WP_Query' => $this->wp_query, 'CPT' => $this->cpt_details)
461
+			);
462
+		}
463
+		return $CPT_Strategy;
464
+	}
465
+
466
+
467
+	/**
468
+	 * postsFields
469
+	 *
470
+	 * @access public
471
+	 * @param  $SQL
472
+	 * @return string
473
+	 */
474
+	public function postsFields($SQL)
475
+	{
476
+		// does this CPT have a meta table ?
477
+		if ($this->meta_table instanceof EE_Secondary_Table) {
478
+			// adds something like ", wp_esp_event_meta.* " to WP Query SELECT statement
479
+			$SQL .= ', ' . $this->meta_table->get_table_name() . '.* ';
480
+		}
481
+		remove_filter('posts_fields', array($this, 'postsFields'));
482
+		return $SQL;
483
+	}
484
+
485
+
486
+	/**
487
+	 * postsJoin
488
+	 *
489
+	 * @access public
490
+	 * @param  $SQL
491
+	 * @return string
492
+	 */
493
+	public function postsJoin($SQL)
494
+	{
495
+		// does this CPT have a meta table ?
496
+		if ($this->meta_table instanceof EE_Secondary_Table) {
497
+			global $wpdb;
498
+			// adds something like " LEFT JOIN wp_esp_event_meta ON ( wp_esp_event_meta.EVT_ID = wp_posts.ID ) " to WP Query JOIN statement
499
+			$SQL .= ' LEFT JOIN '
500
+					. $this->meta_table->get_table_name()
501
+					. ' ON ( '
502
+					. $this->meta_table->get_table_name()
503
+					. '.'
504
+					. $this->meta_table->get_fk_on_table()
505
+					. ' = '
506
+					. $wpdb->posts
507
+					. '.ID ) ';
508
+		}
509
+		remove_filter('posts_join', array($this, 'postsJoin'));
510
+		return $SQL;
511
+	}
512
+
513
+
514
+	/**
515
+	 * thePosts
516
+	 *
517
+	 * @access public
518
+	 * @param  WP_Post[] $posts
519
+	 * @return WP_Post[]
520
+	 */
521
+	public function thePosts($posts)
522
+	{
523
+		$CPT_class = $this->cpt_details['class_name'];
524
+		// loop thru posts
525
+		if (is_array($posts) && $this->model instanceof EEM_CPT_Base) {
526
+			foreach ($posts as $post) {
527
+				if ($post->post_type === $this->post_type) {
528
+					$post->{$CPT_class} = $this->model->instantiate_class_from_post_object($post);
529
+				}
530
+			}
531
+		}
532
+		remove_filter('the_posts', array($this, 'thePosts'), 1);
533
+		return $posts;
534
+	}
535
+
536
+
537
+	/**
538
+	 * @param $url
539
+	 * @param $ID
540
+	 * @return string
541
+	 */
542
+	public function getEditPostLink($url, $ID)
543
+	{
544
+		// need to make sure we only edit links if our cpt
545
+		global $post;
546
+		// notice if the cpt is registered with `show_ee_ui` set to false, we take that to mean that the WordPress core ui
547
+		// for interacting with the CPT is desired and there is no EE UI for interacting with the CPT in the admin.
548
+		if (
549
+			! $post instanceof WP_Post
550
+			|| $post->post_type !== $this->post_type
551
+			|| (
552
+				isset($this->cpt_details['args']['show_ee_ui'])
553
+				&& ! $this->cpt_details['args']['show_ee_ui']
554
+			)
555
+		) {
556
+			return $url;
557
+		}
558
+		// k made it here so all is good.
559
+		return wp_nonce_url(
560
+			add_query_arg(
561
+				array('page' => $this->post_type, 'post' => $ID, 'action' => 'edit'),
562
+				admin_url('admin.php')
563
+			),
564
+			'edit',
565
+			'edit_nonce'
566
+		);
567
+	}
568
+
569
+
570
+	/**
571
+	 * Execute any template filters.
572
+	 * This method is only called if in main query.
573
+	 *
574
+	 * @return void
575
+	 */
576
+	public function addTemplateFilters()
577
+	{
578
+		// if requested cpt supports page_templates and it's the main query
579
+		if (! empty($this->cpt_details['args']['page_templates']) && $this->wp_query->is_main_query()) {
580
+			// then let's hook into the appropriate query_template hook
581
+			add_filter('single_template', array($this, 'singleCptTemplate'));
582
+		}
583
+	}
584
+
585
+
586
+	/**
587
+	 * Callback for single_template wp filter.
588
+	 * This is used to load the set page_template for a single ee cpt if its set.  If "default" then we load the normal
589
+	 * hierarchy.
590
+	 *
591
+	 * @access public
592
+	 * @param string $current_template Existing default template path derived for this page call.
593
+	 * @return string the path to the full template file.
594
+	 */
595
+	public function singleCptTemplate($current_template)
596
+	{
597
+		$object = get_queried_object();
598
+		// does this called object HAVE a page template set that is something other than the default.
599
+		$template = get_post_meta($object->ID, '_wp_page_template', true);
600
+		// exit early if default or not set or invalid path (accounts for theme changes)
601
+		if (
602
+			$template === 'default'
603
+			|| empty($template)
604
+			|| ! is_readable(get_stylesheet_directory() . '/' . $template)
605
+		) {
606
+			return $current_template;
607
+		}
608
+		// made it here so we SHOULD be able to just locate the template and then return it.
609
+		return locate_template(array($template));
610
+	}
611 611
 }
Please login to merge, or discard this patch.
Spacing   +15 added lines, -15 removed lines patch added patch discarded remove patch
@@ -241,7 +241,7 @@  discard block
 block discarded – undo
241 241
      */
242 242
     public function request()
243 243
     {
244
-        if (! $this->request_handler instanceof EE_Request_Handler) {
244
+        if ( ! $this->request_handler instanceof EE_Request_Handler) {
245 245
             $this->request_handler = LoaderFactory::getLoader()->getShared('EE_Request_Handler');
246 246
         }
247 247
         return $this->request_handler;
@@ -296,8 +296,8 @@  discard block
 block discarded – undo
296 296
             $all_taxonomies = $taxonomy_definitions->getCustomTaxonomyDefinitions();
297 297
             foreach ($taxonomies as $taxonomy => &$details) {
298 298
                 // add details to our taxonomies if they exist
299
-                $details = isset($all_taxonomies[ $taxonomy ])
300
-                    ? $all_taxonomies[ $taxonomy ]
299
+                $details = isset($all_taxonomies[$taxonomy])
300
+                    ? $all_taxonomies[$taxonomy]
301 301
                     : array();
302 302
             }
303 303
             // ALWAYS unset() variables that were passed by reference
@@ -334,7 +334,7 @@  discard block
 block discarded – undo
334 334
         add_filter('posts_fields', array($this, 'postsFields'));
335 335
         add_filter('posts_join', array($this, 'postsJoin'));
336 336
         add_filter(
337
-            'get_' . $this->post_type . '_metadata',
337
+            'get_'.$this->post_type.'_metadata',
338 338
             array($CPT_Strategy, 'get_EE_post_type_metadata'),
339 339
             1,
340 340
             4
@@ -386,7 +386,7 @@  discard block
 block discarded – undo
386 386
     public function setRequestVarsIfCpt()
387 387
     {
388 388
         // check if ee action var has been set
389
-        if (! $this->request->requestParamIsSet('ee')) {
389
+        if ( ! $this->request->requestParamIsSet('ee')) {
390 390
             // check that route exists for CPT archive slug
391 391
             if (is_archive() && EE_Config::get_route($this->cpt_details['plural_slug'])) {
392 392
                 // ie: set "ee" to "events"
@@ -411,10 +411,10 @@  discard block
 block discarded – undo
411 411
     {
412 412
         // get CPT table data via CPT Model
413 413
         $full_model_name = strpos($model_name, 'EEM_') !== 0
414
-            ? 'EEM_' . $model_name
414
+            ? 'EEM_'.$model_name
415 415
             : $model_name;
416 416
         $model = $this->loader->getShared($full_model_name);
417
-        if (! $model instanceof EEM_Base) {
417
+        if ( ! $model instanceof EEM_Base) {
418 418
             throw new EE_Error(
419 419
                 sprintf(
420 420
                     esc_html__(
@@ -427,13 +427,13 @@  discard block
 block discarded – undo
427 427
         }
428 428
         $this->setModel($model);
429 429
         $this->setModelTables($this->model->get_tables());
430
-        $meta_model = $model_name . '_Meta';
430
+        $meta_model = $model_name.'_Meta';
431 431
         // is there a Meta Table for this CPT?
432 432
         if (
433
-            isset($this->cpt_details['tables'][ $meta_model ])
434
-            && $this->cpt_details['tables'][ $meta_model ] instanceof EE_Secondary_Table
433
+            isset($this->cpt_details['tables'][$meta_model])
434
+            && $this->cpt_details['tables'][$meta_model] instanceof EE_Secondary_Table
435 435
         ) {
436
-            $this->setMetaTable($this->cpt_details['tables'][ $meta_model ]);
436
+            $this->setMetaTable($this->cpt_details['tables'][$meta_model]);
437 437
         }
438 438
     }
439 439
 
@@ -448,7 +448,7 @@  discard block
 block discarded – undo
448 448
     protected function cptStrategyClass($model_name)
449 449
     {
450 450
         // creates classname like:  CPT_Event_Strategy
451
-        $CPT_Strategy_class_name = 'EE_CPT_' . $model_name . '_Strategy';
451
+        $CPT_Strategy_class_name = 'EE_CPT_'.$model_name.'_Strategy';
452 452
         // load and instantiate
453 453
         $CPT_Strategy = $this->loader->getShared(
454 454
             $CPT_Strategy_class_name,
@@ -476,7 +476,7 @@  discard block
 block discarded – undo
476 476
         // does this CPT have a meta table ?
477 477
         if ($this->meta_table instanceof EE_Secondary_Table) {
478 478
             // adds something like ", wp_esp_event_meta.* " to WP Query SELECT statement
479
-            $SQL .= ', ' . $this->meta_table->get_table_name() . '.* ';
479
+            $SQL .= ', '.$this->meta_table->get_table_name().'.* ';
480 480
         }
481 481
         remove_filter('posts_fields', array($this, 'postsFields'));
482 482
         return $SQL;
@@ -576,7 +576,7 @@  discard block
 block discarded – undo
576 576
     public function addTemplateFilters()
577 577
     {
578 578
         // if requested cpt supports page_templates and it's the main query
579
-        if (! empty($this->cpt_details['args']['page_templates']) && $this->wp_query->is_main_query()) {
579
+        if ( ! empty($this->cpt_details['args']['page_templates']) && $this->wp_query->is_main_query()) {
580 580
             // then let's hook into the appropriate query_template hook
581 581
             add_filter('single_template', array($this, 'singleCptTemplate'));
582 582
         }
@@ -601,7 +601,7 @@  discard block
 block discarded – undo
601 601
         if (
602 602
             $template === 'default'
603 603
             || empty($template)
604
-            || ! is_readable(get_stylesheet_directory() . '/' . $template)
604
+            || ! is_readable(get_stylesheet_directory().'/'.$template)
605 605
         ) {
606 606
             return $current_template;
607 607
         }
Please login to merge, or discard this patch.
core/EE_Cron_Tasks.core.php 2 patches
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;
@@ -72,7 +72,7 @@  discard block
 block discarded – undo
72 72
              */
73 73
             add_action(
74 74
                 'AHEE__EE_System__load_core_configuration__complete',
75
-                function () {
75
+                function() {
76 76
                     EE_Registry::instance()->NET_CFG->core->do_messages_on_same_request = true;
77 77
                     EE_Registry::instance()->NET_CFG->update_config(true, false);
78 78
                     add_option('ee_disabled_wp_cron_check', 1, '', false);
@@ -124,16 +124,16 @@  discard block
 block discarded – undo
124 124
             'AHEE__EE_Cron_Tasks__clean_up_junk_transactions',
125 125
         );
126 126
         $crons = (array) get_option('cron');
127
-        if (! is_array($crons)) {
127
+        if ( ! is_array($crons)) {
128 128
             return;
129 129
         }
130 130
         foreach ($crons as $timestamp => $cron) {
131 131
             /** @var array[] $cron */
132 132
             foreach ($ee_crons as $ee_cron) {
133
-                if (isset($cron[ $ee_cron ]) && is_array($cron[ $ee_cron ])) {
133
+                if (isset($cron[$ee_cron]) && is_array($cron[$ee_cron])) {
134 134
                     do_action('AHEE_log', __CLASS__, __FUNCTION__, $ee_cron, 'scheduled EE cron');
135
-                    foreach ($cron[ $ee_cron ] as $ee_cron_details) {
136
-                        if (! empty($ee_cron_details['args'])) {
135
+                    foreach ($cron[$ee_cron] as $ee_cron_details) {
136
+                        if ( ! empty($ee_cron_details['args'])) {
137 137
                             do_action(
138 138
                                 'AHEE_log',
139 139
                                 __CLASS__,
@@ -160,7 +160,7 @@  discard block
 block discarded – undo
160 160
      */
161 161
     public static function reschedule_cron_for_transactions_if_maintenance_mode($cron_task, array $TXN_IDs)
162 162
     {
163
-        if (! method_exists('EE_Cron_Tasks', $cron_task)) {
163
+        if ( ! method_exists('EE_Cron_Tasks', $cron_task)) {
164 164
             throw new DomainException(
165 165
                 sprintf(
166 166
                     esc_html__('"%1$s" is not valid method on EE_Cron_Tasks.', 'event_espresso'),
@@ -169,7 +169,7 @@  discard block
 block discarded – undo
169 169
             );
170 170
         }
171 171
         // reschedule the cron if we can't hit the db right now
172
-        if (! EE_Maintenance_Mode::instance()->models_can_query()) {
172
+        if ( ! EE_Maintenance_Mode::instance()->models_can_query()) {
173 173
             foreach ($TXN_IDs as $TXN_ID => $additional_vars) {
174 174
                 // ensure $additional_vars is an array
175 175
                 $additional_vars = is_array($additional_vars) ? $additional_vars : array($additional_vars);
@@ -250,7 +250,7 @@  discard block
 block discarded – undo
250 250
     {
251 251
         do_action('AHEE_log', __CLASS__, __FUNCTION__, $TXN_ID, '$TXN_ID');
252 252
         if (absint($TXN_ID)) {
253
-            self::$_update_transactions_with_payment[ $TXN_ID ] = $PAY_ID;
253
+            self::$_update_transactions_with_payment[$TXN_ID] = $PAY_ID;
254 254
             add_action(
255 255
                 'shutdown',
256 256
                 array('EE_Cron_Tasks', 'update_transaction_with_payment'),
@@ -297,7 +297,7 @@  discard block
 block discarded – undo
297 297
         EE_Registry::instance()->load_model('Transaction');
298 298
         foreach (self::$_update_transactions_with_payment as $TXN_ID => $PAY_ID) {
299 299
             // reschedule the cron if we can't hit the db right now
300
-            if (! EE_Maintenance_Mode::instance()->models_can_query()) {
300
+            if ( ! EE_Maintenance_Mode::instance()->models_can_query()) {
301 301
                 // reset cron job for updating the TXN
302 302
                 EE_Cron_Tasks::schedule_update_transaction_with_payment(
303 303
                     time() + EE_Cron_Tasks::reschedule_timeout,
@@ -313,7 +313,7 @@  discard block
 block discarded – undo
313 313
                 // now try to update the TXN with any payments
314 314
                 $payment_processor->update_txn_based_on_payment($transaction, $payment, true, true);
315 315
             }
316
-            unset(self::$_update_transactions_with_payment[ $TXN_ID ]);
316
+            unset(self::$_update_transactions_with_payment[$TXN_ID]);
317 317
         }
318 318
     }
319 319
 
@@ -374,7 +374,7 @@  discard block
 block discarded – undo
374 374
     public static function expired_transaction_check($TXN_ID = 0)
375 375
     {
376 376
         if (absint($TXN_ID)) {
377
-            self::$_expired_transactions[ $TXN_ID ] = $TXN_ID;
377
+            self::$_expired_transactions[$TXN_ID] = $TXN_ID;
378 378
             add_action(
379 379
                 'shutdown',
380 380
                 array('EE_Cron_Tasks', 'process_expired_transactions'),
@@ -502,7 +502,7 @@  discard block
 block discarded – undo
502 502
                         break;
503 503
                 }
504 504
             }
505
-            unset(self::$_expired_transactions[ $TXN_ID ]);
505
+            unset(self::$_expired_transactions[$TXN_ID]);
506 506
         }
507 507
     }
508 508
 
@@ -549,7 +549,7 @@  discard block
 block discarded – undo
549 549
             $reg_config = LoaderFactory::getLoader()->load('EE_Registration_Config');
550 550
             $time_diff_for_comparison = apply_filters(
551 551
                 'FHEE__EE_Cron_Tasks__clean_out_old_gateway_logs__time_diff_for_comparison',
552
-                '-' . $reg_config->gateway_log_lifespan
552
+                '-'.$reg_config->gateway_log_lifespan
553 553
             );
554 554
             EEM_Change_Log::instance()->delete_gateway_logs_older_than(new DateTime($time_diff_for_comparison));
555 555
         }
Please login to merge, or discard this patch.
Indentation   +600 added lines, -600 removed lines patch added patch discarded remove patch
@@ -14,607 +14,607 @@
 block discarded – undo
14 14
  */
15 15
 class EE_Cron_Tasks extends EE_Base
16 16
 {
17
-    /**
18
-     * WordPress doesn't allow duplicate crons within 10 minutes of the original,
19
-     * so we'll set our retry time for just over 10 minutes to avoid that
20
-     */
21
-    const reschedule_timeout = 605;
22
-
23
-
24
-    /**
25
-     * @var EE_Cron_Tasks
26
-     */
27
-    private static $_instance;
28
-
29
-
30
-    /**
31
-     * @return EE_Cron_Tasks
32
-     * @throws ReflectionException
33
-     * @throws EE_Error
34
-     * @throws InvalidArgumentException
35
-     * @throws InvalidInterfaceException
36
-     * @throws InvalidDataTypeException
37
-     */
38
-    public static function instance()
39
-    {
40
-        if (! self::$_instance instanceof EE_Cron_Tasks) {
41
-            self::$_instance = new self();
42
-        }
43
-        return self::$_instance;
44
-    }
45
-
46
-
47
-    /**
48
-     * @access private
49
-     * @throws InvalidDataTypeException
50
-     * @throws InvalidInterfaceException
51
-     * @throws InvalidArgumentException
52
-     * @throws EE_Error
53
-     * @throws ReflectionException
54
-     */
55
-    private function __construct()
56
-    {
57
-        do_action('AHEE_log', __CLASS__, __FUNCTION__);
58
-        // verify that WP Cron is enabled
59
-        if (
60
-            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
-                    esc_html__('"%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 (
17
+	/**
18
+	 * WordPress doesn't allow duplicate crons within 10 minutes of the original,
19
+	 * so we'll set our retry time for just over 10 minutes to avoid that
20
+	 */
21
+	const reschedule_timeout = 605;
22
+
23
+
24
+	/**
25
+	 * @var EE_Cron_Tasks
26
+	 */
27
+	private static $_instance;
28
+
29
+
30
+	/**
31
+	 * @return EE_Cron_Tasks
32
+	 * @throws ReflectionException
33
+	 * @throws EE_Error
34
+	 * @throws InvalidArgumentException
35
+	 * @throws InvalidInterfaceException
36
+	 * @throws InvalidDataTypeException
37
+	 */
38
+	public static function instance()
39
+	{
40
+		if (! self::$_instance instanceof EE_Cron_Tasks) {
41
+			self::$_instance = new self();
42
+		}
43
+		return self::$_instance;
44
+	}
45
+
46
+
47
+	/**
48
+	 * @access private
49
+	 * @throws InvalidDataTypeException
50
+	 * @throws InvalidInterfaceException
51
+	 * @throws InvalidArgumentException
52
+	 * @throws EE_Error
53
+	 * @throws ReflectionException
54
+	 */
55
+	private function __construct()
56
+	{
57
+		do_action('AHEE_log', __CLASS__, __FUNCTION__);
58
+		// verify that WP Cron is enabled
59
+		if (
60
+			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
+					esc_html__('"%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 (
281 281
 // are there any TXNs that need cleaning up ?
282
-            empty(self::$_update_transactions_with_payment)
283
-            // reschedule the cron if we can't hit the db right now
284
-            || EE_Cron_Tasks::reschedule_cron_for_transactions_if_maintenance_mode(
285
-                'schedule_update_transaction_with_payment',
286
-                self::$_update_transactions_with_payment
287
-            )
288
-        ) {
289
-            return;
290
-        }
291
-        /** @type EE_Payment_Processor $payment_processor */
292
-        $payment_processor = EE_Registry::instance()->load_core('Payment_Processor');
293
-        // set revisit flag for payment processor
294
-        $payment_processor->set_revisit();
295
-        // load EEM_Transaction
296
-        EE_Registry::instance()->load_model('Transaction');
297
-        foreach (self::$_update_transactions_with_payment as $TXN_ID => $PAY_ID) {
298
-            // reschedule the cron if we can't hit the db right now
299
-            if (! EE_Maintenance_Mode::instance()->models_can_query()) {
300
-                // reset cron job for updating the TXN
301
-                EE_Cron_Tasks::schedule_update_transaction_with_payment(
302
-                    time() + EE_Cron_Tasks::reschedule_timeout,
303
-                    $TXN_ID,
304
-                    $PAY_ID
305
-                );
306
-                continue;
307
-            }
308
-            $transaction = EEM_Transaction::instance()->get_one_by_ID($TXN_ID);
309
-            $payment = EEM_Payment::instance()->get_one_by_ID($PAY_ID);
310
-            // verify transaction
311
-            if ($transaction instanceof EE_Transaction && $payment instanceof EE_Payment) {
312
-                // now try to update the TXN with any payments
313
-                $payment_processor->update_txn_based_on_payment($transaction, $payment, true, true);
314
-            }
315
-            unset(self::$_update_transactions_with_payment[ $TXN_ID ]);
316
-        }
317
-    }
318
-
319
-
320
-
321
-    /************  END OF UPDATE TRANSACTION WITH PAYMENT  ************/
322
-
323
-
324
-    /*****************  EXPIRED TRANSACTION CHECK *****************/
325
-
326
-
327
-    /**
328
-     * array of TXN IDs
329
-     *
330
-     * @var array
331
-     */
332
-    protected static $_expired_transactions = array();
333
-
334
-
335
-    /**
336
-     * schedule_expired_transaction_check
337
-     * sets a wp_schedule_single_event() for following up on TXNs after their session has expired
338
-     *
339
-     * @param int $timestamp
340
-     * @param int $TXN_ID
341
-     */
342
-    public static function schedule_expired_transaction_check(
343
-        $timestamp,
344
-        $TXN_ID
345
-    ) {
346
-        // validate $TXN_ID and $timestamp
347
-        $TXN_ID = absint($TXN_ID);
348
-        $timestamp = absint($timestamp);
349
-        if ($TXN_ID && $timestamp) {
350
-            wp_schedule_single_event(
351
-                $timestamp,
352
-                'AHEE__EE_Cron_Tasks__expired_transaction_check',
353
-                array($TXN_ID)
354
-            );
355
-        }
356
-    }
357
-
358
-
359
-    /**
360
-     * expired_transaction_check
361
-     * this is the callback for the action hook:
362
-     * 'AHEE__EE_Cron_Tasks__transaction_session_expiration_check'
363
-     * which is utilized by wp_schedule_single_event()
364
-     * in \EED_Single_Page_Checkout::_initialize_transaction().
365
-     * The passed TXN_ID gets added to an array, and then the
366
-     * process_expired_transactions() function is hooked into
367
-     * 'AHEE__EE_System__core_loaded_and_ready' which will actually handle the
368
-     * processing of any failed transactions, because doing so now would be
369
-     * too early and the required resources may not be available
370
-     *
371
-     * @param int $TXN_ID
372
-     */
373
-    public static function expired_transaction_check($TXN_ID = 0)
374
-    {
375
-        if (absint($TXN_ID)) {
376
-            self::$_expired_transactions[ $TXN_ID ] = $TXN_ID;
377
-            add_action(
378
-                'shutdown',
379
-                array('EE_Cron_Tasks', 'process_expired_transactions'),
380
-                5
381
-            );
382
-        }
383
-    }
384
-
385
-
386
-    /**
387
-     * process_expired_transactions
388
-     * loops through the self::$_expired_transactions array and processes any failed TXNs
389
-     *
390
-     * @throws EE_Error
391
-     * @throws InvalidDataTypeException
392
-     * @throws InvalidInterfaceException
393
-     * @throws InvalidArgumentException
394
-     * @throws ReflectionException
395
-     * @throws DomainException
396
-     * @throws RuntimeException
397
-     */
398
-    public static function process_expired_transactions()
399
-    {
400
-        if (
282
+			empty(self::$_update_transactions_with_payment)
283
+			// reschedule the cron if we can't hit the db right now
284
+			|| EE_Cron_Tasks::reschedule_cron_for_transactions_if_maintenance_mode(
285
+				'schedule_update_transaction_with_payment',
286
+				self::$_update_transactions_with_payment
287
+			)
288
+		) {
289
+			return;
290
+		}
291
+		/** @type EE_Payment_Processor $payment_processor */
292
+		$payment_processor = EE_Registry::instance()->load_core('Payment_Processor');
293
+		// set revisit flag for payment processor
294
+		$payment_processor->set_revisit();
295
+		// load EEM_Transaction
296
+		EE_Registry::instance()->load_model('Transaction');
297
+		foreach (self::$_update_transactions_with_payment as $TXN_ID => $PAY_ID) {
298
+			// reschedule the cron if we can't hit the db right now
299
+			if (! EE_Maintenance_Mode::instance()->models_can_query()) {
300
+				// reset cron job for updating the TXN
301
+				EE_Cron_Tasks::schedule_update_transaction_with_payment(
302
+					time() + EE_Cron_Tasks::reschedule_timeout,
303
+					$TXN_ID,
304
+					$PAY_ID
305
+				);
306
+				continue;
307
+			}
308
+			$transaction = EEM_Transaction::instance()->get_one_by_ID($TXN_ID);
309
+			$payment = EEM_Payment::instance()->get_one_by_ID($PAY_ID);
310
+			// verify transaction
311
+			if ($transaction instanceof EE_Transaction && $payment instanceof EE_Payment) {
312
+				// now try to update the TXN with any payments
313
+				$payment_processor->update_txn_based_on_payment($transaction, $payment, true, true);
314
+			}
315
+			unset(self::$_update_transactions_with_payment[ $TXN_ID ]);
316
+		}
317
+	}
318
+
319
+
320
+
321
+	/************  END OF UPDATE TRANSACTION WITH PAYMENT  ************/
322
+
323
+
324
+	/*****************  EXPIRED TRANSACTION CHECK *****************/
325
+
326
+
327
+	/**
328
+	 * array of TXN IDs
329
+	 *
330
+	 * @var array
331
+	 */
332
+	protected static $_expired_transactions = array();
333
+
334
+
335
+	/**
336
+	 * schedule_expired_transaction_check
337
+	 * sets a wp_schedule_single_event() for following up on TXNs after their session has expired
338
+	 *
339
+	 * @param int $timestamp
340
+	 * @param int $TXN_ID
341
+	 */
342
+	public static function schedule_expired_transaction_check(
343
+		$timestamp,
344
+		$TXN_ID
345
+	) {
346
+		// validate $TXN_ID and $timestamp
347
+		$TXN_ID = absint($TXN_ID);
348
+		$timestamp = absint($timestamp);
349
+		if ($TXN_ID && $timestamp) {
350
+			wp_schedule_single_event(
351
+				$timestamp,
352
+				'AHEE__EE_Cron_Tasks__expired_transaction_check',
353
+				array($TXN_ID)
354
+			);
355
+		}
356
+	}
357
+
358
+
359
+	/**
360
+	 * expired_transaction_check
361
+	 * this is the callback for the action hook:
362
+	 * 'AHEE__EE_Cron_Tasks__transaction_session_expiration_check'
363
+	 * which is utilized by wp_schedule_single_event()
364
+	 * in \EED_Single_Page_Checkout::_initialize_transaction().
365
+	 * The passed TXN_ID gets added to an array, and then the
366
+	 * process_expired_transactions() function is hooked into
367
+	 * 'AHEE__EE_System__core_loaded_and_ready' which will actually handle the
368
+	 * processing of any failed transactions, because doing so now would be
369
+	 * too early and the required resources may not be available
370
+	 *
371
+	 * @param int $TXN_ID
372
+	 */
373
+	public static function expired_transaction_check($TXN_ID = 0)
374
+	{
375
+		if (absint($TXN_ID)) {
376
+			self::$_expired_transactions[ $TXN_ID ] = $TXN_ID;
377
+			add_action(
378
+				'shutdown',
379
+				array('EE_Cron_Tasks', 'process_expired_transactions'),
380
+				5
381
+			);
382
+		}
383
+	}
384
+
385
+
386
+	/**
387
+	 * process_expired_transactions
388
+	 * loops through the self::$_expired_transactions array and processes any failed TXNs
389
+	 *
390
+	 * @throws EE_Error
391
+	 * @throws InvalidDataTypeException
392
+	 * @throws InvalidInterfaceException
393
+	 * @throws InvalidArgumentException
394
+	 * @throws ReflectionException
395
+	 * @throws DomainException
396
+	 * @throws RuntimeException
397
+	 */
398
+	public static function process_expired_transactions()
399
+	{
400
+		if (
401 401
 // are there any TXNs that need cleaning up ?
402
-            empty(self::$_expired_transactions)
403
-            // reschedule the cron if we can't hit the db right now
404
-            || EE_Cron_Tasks::reschedule_cron_for_transactions_if_maintenance_mode(
405
-                'schedule_expired_transaction_check',
406
-                self::$_expired_transactions
407
-            )
408
-        ) {
409
-            return;
410
-        }
411
-        /** @type EE_Transaction_Processor $transaction_processor */
412
-        $transaction_processor = EE_Registry::instance()->load_class('Transaction_Processor');
413
-        // set revisit flag for txn processor
414
-        $transaction_processor->set_revisit();
415
-        // load EEM_Transaction
416
-        EE_Registry::instance()->load_model('Transaction');
417
-        foreach (self::$_expired_transactions as $TXN_ID) {
418
-            $transaction = EEM_Transaction::instance()->get_one_by_ID($TXN_ID);
419
-            // verify transaction and whether it is failed or not
420
-            if ($transaction instanceof EE_Transaction) {
421
-                switch ($transaction->status_ID()) {
422
-                    // Completed TXNs
423
-                    case EEM_Transaction::complete_status_code:
424
-                        // Don't update the transaction/registrations if the Primary Registration is Not Approved.
425
-                        $primary_registration = $transaction->primary_registration();
426
-                        if (
427
-                            $primary_registration instanceof EE_Registration
428
-                            && $primary_registration->status_ID() !== EEM_Registration::status_id_not_approved
429
-                        ) {
430
-                            /** @type EE_Transaction_Processor $transaction_processor */
431
-                            $transaction_processor = EE_Registry::instance()->load_class('Transaction_Processor');
432
-                            $transaction_processor->update_transaction_and_registrations_after_checkout_or_payment(
433
-                                $transaction,
434
-                                $transaction->last_payment()
435
-                            );
436
-                            do_action(
437
-                                'AHEE__EE_Cron_Tasks__process_expired_transactions__completed_transaction',
438
-                                $transaction
439
-                            );
440
-                        }
441
-                        break;
442
-                    // Overpaid TXNs
443
-                    case EEM_Transaction::overpaid_status_code:
444
-                        do_action(
445
-                            'AHEE__EE_Cron_Tasks__process_expired_transactions__overpaid_transaction',
446
-                            $transaction
447
-                        );
448
-                        break;
449
-                    // Incomplete TXNs
450
-                    case EEM_Transaction::incomplete_status_code:
451
-                        do_action(
452
-                            'AHEE__EE_Cron_Tasks__process_expired_transactions__incomplete_transaction',
453
-                            $transaction
454
-                        );
455
-                        // todo : move business logic into EE_Transaction_Processor for finalizing abandoned transactions
456
-                        break;
457
-                    // Abandoned TXNs
458
-                    case EEM_Transaction::abandoned_status_code:
459
-                        // run hook before updating transaction, primarily so
460
-                        // EED_Ticket_Sales_Monitor::process_abandoned_transactions() can release reserved tickets
461
-                        do_action(
462
-                            'AHEE__EE_Cron_Tasks__process_expired_transactions__abandoned_transaction',
463
-                            $transaction
464
-                        );
465
-                        // don't finalize the TXN if it has already been completed
466
-                        if ($transaction->all_reg_steps_completed() !== true) {
467
-                            /** @type EE_Payment_Processor $payment_processor */
468
-                            $payment_processor = EE_Registry::instance()->load_core('Payment_Processor');
469
-                            // let's simulate an IPN here which will trigger any notifications that need to go out
470
-                            $payment_processor->update_txn_based_on_payment(
471
-                                $transaction,
472
-                                $transaction->last_payment(),
473
-                                true,
474
-                                true
475
-                            );
476
-                        }
477
-                        break;
478
-                    // Failed TXNs
479
-                    case EEM_Transaction::failed_status_code:
480
-                        do_action(
481
-                            'AHEE__EE_Cron_Tasks__process_expired_transactions__failed_transaction',
482
-                            $transaction
483
-                        );
484
-                        // todo :
485
-                        // perform garbage collection here and remove clean_out_junk_transactions()
486
-                        // $registrations = $transaction->registrations();
487
-                        // if (! empty($registrations)) {
488
-                        //     foreach ($registrations as $registration) {
489
-                        //         if ($registration instanceof EE_Registration) {
490
-                        //             $delete_registration = true;
491
-                        //             if ($registration->attendee() instanceof EE_Attendee) {
492
-                        //                 $delete_registration = false;
493
-                        //             }
494
-                        //             if ($delete_registration) {
495
-                        //                 $registration->delete_permanently();
496
-                        //                 $registration->delete_related_permanently();
497
-                        //             }
498
-                        //         }
499
-                        //     }
500
-                        // }
501
-                        break;
502
-                }
503
-            }
504
-            unset(self::$_expired_transactions[ $TXN_ID ]);
505
-        }
506
-    }
507
-
508
-
509
-
510
-    /*************  END OF EXPIRED TRANSACTION CHECK  *************/
511
-
512
-
513
-    /************* START CLEAN UP BOT TRANSACTIONS **********************/
514
-
515
-
516
-    /**
517
-     * callback for 'AHEE__EE_Cron_Tasks__clean_up_junk_transactions'
518
-     * which is setup during activation to run on an hourly cron
519
-     *
520
-     * @throws EE_Error
521
-     * @throws InvalidArgumentException
522
-     * @throws InvalidDataTypeException
523
-     * @throws InvalidInterfaceException
524
-     * @throws DomainException
525
-     */
526
-    public static function clean_out_junk_transactions()
527
-    {
528
-        if (EE_Maintenance_Mode::instance()->models_can_query()) {
529
-            EED_Ticket_Sales_Monitor::reset_reservation_counts();
530
-            EEM_Transaction::instance('')->delete_junk_transactions();
531
-            EEM_Registration::instance('')->delete_registrations_with_no_transaction();
532
-            EEM_Line_Item::instance('')->delete_line_items_with_no_transaction();
533
-        }
534
-    }
535
-
536
-
537
-    /**
538
-     * Deletes old gateway logs. After about a week we usually don't need them for debugging. But folks can filter that.
539
-     *
540
-     * @throws EE_Error
541
-     * @throws InvalidDataTypeException
542
-     * @throws InvalidInterfaceException
543
-     * @throws InvalidArgumentException
544
-     */
545
-    public static function clean_out_old_gateway_logs()
546
-    {
547
-        if (EE_Maintenance_Mode::instance()->models_can_query()) {
548
-            $reg_config = LoaderFactory::getLoader()->load('EE_Registration_Config');
549
-            $time_diff_for_comparison = apply_filters(
550
-                'FHEE__EE_Cron_Tasks__clean_out_old_gateway_logs__time_diff_for_comparison',
551
-                '-' . $reg_config->gateway_log_lifespan
552
-            );
553
-            EEM_Change_Log::instance()->delete_gateway_logs_older_than(new DateTime($time_diff_for_comparison));
554
-        }
555
-    }
556
-
557
-
558
-    /*****************  FINALIZE ABANDONED TRANSACTIONS *****************/
559
-
560
-
561
-    /**
562
-     * @var array
563
-     */
564
-    protected static $_abandoned_transactions = array();
565
-
566
-
567
-    /**
568
-     * @deprecated
569
-     * @param int $timestamp
570
-     * @param int $TXN_ID
571
-     */
572
-    public static function schedule_finalize_abandoned_transactions_check($timestamp, $TXN_ID)
573
-    {
574
-        EE_Cron_Tasks::schedule_expired_transaction_check($timestamp, $TXN_ID);
575
-    }
576
-
577
-
578
-    /**
579
-     * @deprecated
580
-     * @param int $TXN_ID
581
-     */
582
-    public static function check_for_abandoned_transactions($TXN_ID = 0)
583
-    {
584
-        EE_Cron_Tasks::expired_transaction_check($TXN_ID);
585
-    }
586
-
587
-
588
-    /**
589
-     * @deprecated
590
-     * @throws EE_Error
591
-     * @throws DomainException
592
-     * @throws InvalidDataTypeException
593
-     * @throws InvalidInterfaceException
594
-     * @throws InvalidArgumentException
595
-     * @throws ReflectionException
596
-     * @throws RuntimeException
597
-     */
598
-    public static function finalize_abandoned_transactions()
599
-    {
600
-        do_action('AHEE_log', __CLASS__, __FUNCTION__);
601
-        if (
402
+			empty(self::$_expired_transactions)
403
+			// reschedule the cron if we can't hit the db right now
404
+			|| EE_Cron_Tasks::reschedule_cron_for_transactions_if_maintenance_mode(
405
+				'schedule_expired_transaction_check',
406
+				self::$_expired_transactions
407
+			)
408
+		) {
409
+			return;
410
+		}
411
+		/** @type EE_Transaction_Processor $transaction_processor */
412
+		$transaction_processor = EE_Registry::instance()->load_class('Transaction_Processor');
413
+		// set revisit flag for txn processor
414
+		$transaction_processor->set_revisit();
415
+		// load EEM_Transaction
416
+		EE_Registry::instance()->load_model('Transaction');
417
+		foreach (self::$_expired_transactions as $TXN_ID) {
418
+			$transaction = EEM_Transaction::instance()->get_one_by_ID($TXN_ID);
419
+			// verify transaction and whether it is failed or not
420
+			if ($transaction instanceof EE_Transaction) {
421
+				switch ($transaction->status_ID()) {
422
+					// Completed TXNs
423
+					case EEM_Transaction::complete_status_code:
424
+						// Don't update the transaction/registrations if the Primary Registration is Not Approved.
425
+						$primary_registration = $transaction->primary_registration();
426
+						if (
427
+							$primary_registration instanceof EE_Registration
428
+							&& $primary_registration->status_ID() !== EEM_Registration::status_id_not_approved
429
+						) {
430
+							/** @type EE_Transaction_Processor $transaction_processor */
431
+							$transaction_processor = EE_Registry::instance()->load_class('Transaction_Processor');
432
+							$transaction_processor->update_transaction_and_registrations_after_checkout_or_payment(
433
+								$transaction,
434
+								$transaction->last_payment()
435
+							);
436
+							do_action(
437
+								'AHEE__EE_Cron_Tasks__process_expired_transactions__completed_transaction',
438
+								$transaction
439
+							);
440
+						}
441
+						break;
442
+					// Overpaid TXNs
443
+					case EEM_Transaction::overpaid_status_code:
444
+						do_action(
445
+							'AHEE__EE_Cron_Tasks__process_expired_transactions__overpaid_transaction',
446
+							$transaction
447
+						);
448
+						break;
449
+					// Incomplete TXNs
450
+					case EEM_Transaction::incomplete_status_code:
451
+						do_action(
452
+							'AHEE__EE_Cron_Tasks__process_expired_transactions__incomplete_transaction',
453
+							$transaction
454
+						);
455
+						// todo : move business logic into EE_Transaction_Processor for finalizing abandoned transactions
456
+						break;
457
+					// Abandoned TXNs
458
+					case EEM_Transaction::abandoned_status_code:
459
+						// run hook before updating transaction, primarily so
460
+						// EED_Ticket_Sales_Monitor::process_abandoned_transactions() can release reserved tickets
461
+						do_action(
462
+							'AHEE__EE_Cron_Tasks__process_expired_transactions__abandoned_transaction',
463
+							$transaction
464
+						);
465
+						// don't finalize the TXN if it has already been completed
466
+						if ($transaction->all_reg_steps_completed() !== true) {
467
+							/** @type EE_Payment_Processor $payment_processor */
468
+							$payment_processor = EE_Registry::instance()->load_core('Payment_Processor');
469
+							// let's simulate an IPN here which will trigger any notifications that need to go out
470
+							$payment_processor->update_txn_based_on_payment(
471
+								$transaction,
472
+								$transaction->last_payment(),
473
+								true,
474
+								true
475
+							);
476
+						}
477
+						break;
478
+					// Failed TXNs
479
+					case EEM_Transaction::failed_status_code:
480
+						do_action(
481
+							'AHEE__EE_Cron_Tasks__process_expired_transactions__failed_transaction',
482
+							$transaction
483
+						);
484
+						// todo :
485
+						// perform garbage collection here and remove clean_out_junk_transactions()
486
+						// $registrations = $transaction->registrations();
487
+						// if (! empty($registrations)) {
488
+						//     foreach ($registrations as $registration) {
489
+						//         if ($registration instanceof EE_Registration) {
490
+						//             $delete_registration = true;
491
+						//             if ($registration->attendee() instanceof EE_Attendee) {
492
+						//                 $delete_registration = false;
493
+						//             }
494
+						//             if ($delete_registration) {
495
+						//                 $registration->delete_permanently();
496
+						//                 $registration->delete_related_permanently();
497
+						//             }
498
+						//         }
499
+						//     }
500
+						// }
501
+						break;
502
+				}
503
+			}
504
+			unset(self::$_expired_transactions[ $TXN_ID ]);
505
+		}
506
+	}
507
+
508
+
509
+
510
+	/*************  END OF EXPIRED TRANSACTION CHECK  *************/
511
+
512
+
513
+	/************* START CLEAN UP BOT TRANSACTIONS **********************/
514
+
515
+
516
+	/**
517
+	 * callback for 'AHEE__EE_Cron_Tasks__clean_up_junk_transactions'
518
+	 * which is setup during activation to run on an hourly cron
519
+	 *
520
+	 * @throws EE_Error
521
+	 * @throws InvalidArgumentException
522
+	 * @throws InvalidDataTypeException
523
+	 * @throws InvalidInterfaceException
524
+	 * @throws DomainException
525
+	 */
526
+	public static function clean_out_junk_transactions()
527
+	{
528
+		if (EE_Maintenance_Mode::instance()->models_can_query()) {
529
+			EED_Ticket_Sales_Monitor::reset_reservation_counts();
530
+			EEM_Transaction::instance('')->delete_junk_transactions();
531
+			EEM_Registration::instance('')->delete_registrations_with_no_transaction();
532
+			EEM_Line_Item::instance('')->delete_line_items_with_no_transaction();
533
+		}
534
+	}
535
+
536
+
537
+	/**
538
+	 * Deletes old gateway logs. After about a week we usually don't need them for debugging. But folks can filter that.
539
+	 *
540
+	 * @throws EE_Error
541
+	 * @throws InvalidDataTypeException
542
+	 * @throws InvalidInterfaceException
543
+	 * @throws InvalidArgumentException
544
+	 */
545
+	public static function clean_out_old_gateway_logs()
546
+	{
547
+		if (EE_Maintenance_Mode::instance()->models_can_query()) {
548
+			$reg_config = LoaderFactory::getLoader()->load('EE_Registration_Config');
549
+			$time_diff_for_comparison = apply_filters(
550
+				'FHEE__EE_Cron_Tasks__clean_out_old_gateway_logs__time_diff_for_comparison',
551
+				'-' . $reg_config->gateway_log_lifespan
552
+			);
553
+			EEM_Change_Log::instance()->delete_gateway_logs_older_than(new DateTime($time_diff_for_comparison));
554
+		}
555
+	}
556
+
557
+
558
+	/*****************  FINALIZE ABANDONED TRANSACTIONS *****************/
559
+
560
+
561
+	/**
562
+	 * @var array
563
+	 */
564
+	protected static $_abandoned_transactions = array();
565
+
566
+
567
+	/**
568
+	 * @deprecated
569
+	 * @param int $timestamp
570
+	 * @param int $TXN_ID
571
+	 */
572
+	public static function schedule_finalize_abandoned_transactions_check($timestamp, $TXN_ID)
573
+	{
574
+		EE_Cron_Tasks::schedule_expired_transaction_check($timestamp, $TXN_ID);
575
+	}
576
+
577
+
578
+	/**
579
+	 * @deprecated
580
+	 * @param int $TXN_ID
581
+	 */
582
+	public static function check_for_abandoned_transactions($TXN_ID = 0)
583
+	{
584
+		EE_Cron_Tasks::expired_transaction_check($TXN_ID);
585
+	}
586
+
587
+
588
+	/**
589
+	 * @deprecated
590
+	 * @throws EE_Error
591
+	 * @throws DomainException
592
+	 * @throws InvalidDataTypeException
593
+	 * @throws InvalidInterfaceException
594
+	 * @throws InvalidArgumentException
595
+	 * @throws ReflectionException
596
+	 * @throws RuntimeException
597
+	 */
598
+	public static function finalize_abandoned_transactions()
599
+	{
600
+		do_action('AHEE_log', __CLASS__, __FUNCTION__);
601
+		if (
602 602
 // are there any TXNs that need cleaning up ?
603
-            empty(self::$_abandoned_transactions)
604
-            // reschedule the cron if we can't hit the db right now
605
-            || EE_Cron_Tasks::reschedule_cron_for_transactions_if_maintenance_mode(
606
-                'schedule_expired_transaction_check',
607
-                self::$_abandoned_transactions
608
-            )
609
-        ) {
610
-            return;
611
-        }
612
-        // combine our arrays of transaction IDs
613
-        self::$_expired_transactions = self::$_abandoned_transactions + self::$_expired_transactions;
614
-        // and deal with abandoned transactions here now...
615
-        EE_Cron_Tasks::process_expired_transactions();
616
-    }
617
-
618
-
619
-    /*************  END OF FINALIZE ABANDONED TRANSACTIONS  *************/
603
+			empty(self::$_abandoned_transactions)
604
+			// reschedule the cron if we can't hit the db right now
605
+			|| EE_Cron_Tasks::reschedule_cron_for_transactions_if_maintenance_mode(
606
+				'schedule_expired_transaction_check',
607
+				self::$_abandoned_transactions
608
+			)
609
+		) {
610
+			return;
611
+		}
612
+		// combine our arrays of transaction IDs
613
+		self::$_expired_transactions = self::$_abandoned_transactions + self::$_expired_transactions;
614
+		// and deal with abandoned transactions here now...
615
+		EE_Cron_Tasks::process_expired_transactions();
616
+	}
617
+
618
+
619
+	/*************  END OF FINALIZE ABANDONED TRANSACTIONS  *************/
620 620
 }
Please login to merge, or discard this patch.
core/helpers/EEH_Address.helper.php 2 patches
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -30,13 +30,13 @@  discard block
 block discarded – undo
30 30
         $add_wrapper = true
31 31
     ) {
32 32
         // check that incoming object implements the EEI_Address interface
33
-        if (! $obj_with_address instanceof EEI_Address) {
33
+        if ( ! $obj_with_address instanceof EEI_Address) {
34 34
             $msg = esc_html__('The address could not be formatted.', 'event_espresso');
35 35
             $dev_msg = esc_html__(
36 36
                 'The Address Formatter requires passed objects to implement the EEI_Address interface.',
37 37
                 'event_espresso'
38 38
             );
39
-            EE_Error::add_error($msg . '||' . $dev_msg, __FILE__, __FUNCTION__, __LINE__);
39
+            EE_Error::add_error($msg.'||'.$dev_msg, __FILE__, __FUNCTION__, __LINE__);
40 40
             return null;
41 41
         }
42 42
         // obtain an address formatter
@@ -47,7 +47,7 @@  discard block
 block discarded – undo
47 47
             ? EEH_Address::_schema_formatting($formatter, $obj_with_address)
48 48
             : EEH_Address::_regular_formatting($formatter, $obj_with_address, $add_wrapper);
49 49
         $formatted_address = $add_wrapper && ! $use_schema
50
-            ? '<div class="espresso-address-dv">' . $formatted_address . '</div>'
50
+            ? '<div class="espresso-address-dv">'.$formatted_address.'</div>'
51 51
             : $formatted_address;
52 52
         // return the formatted address
53 53
         return $formatted_address;
Please login to merge, or discard this patch.
Indentation   +111 added lines, -111 removed lines patch added patch discarded remove patch
@@ -10,124 +10,124 @@
 block discarded – undo
10 10
  */
11 11
 class EEH_Address
12 12
 {
13
-    /**
14
-     *    format - output formatted EE object address information
15
-     *
16
-     * @access public
17
-     * @param         object      EEI_Address $obj_with_address
18
-     * @param string  $type       how the address is formatted. for example: 'multiline' or 'inline'
19
-     * @param boolean $use_schema whether to apply schema.org formatting to the address
20
-     * @param bool    $add_wrapper
21
-     * @return string
22
-     */
23
-    public static function format(
24
-        $obj_with_address = null,
25
-        $type = 'multiline',
26
-        $use_schema = true,
27
-        $add_wrapper = true
28
-    ) {
29
-        // check that incoming object implements the EEI_Address interface
30
-        if (! $obj_with_address instanceof EEI_Address) {
31
-            $msg = esc_html__('The address could not be formatted.', 'event_espresso');
32
-            $dev_msg = esc_html__(
33
-                'The Address Formatter requires passed objects to implement the EEI_Address interface.',
34
-                'event_espresso'
35
-            );
36
-            EE_Error::add_error($msg . '||' . $dev_msg, __FILE__, __FUNCTION__, __LINE__);
37
-            return null;
38
-        }
39
-        // obtain an address formatter
40
-        $formatter = EEH_Address::_get_formatter($type);
41
-        // apply schema.org formatting ?
42
-        $use_schema = ! is_admin() ? $use_schema : false;
43
-        $formatted_address = $use_schema
44
-            ? EEH_Address::_schema_formatting($formatter, $obj_with_address)
45
-            : EEH_Address::_regular_formatting($formatter, $obj_with_address, $add_wrapper);
46
-        $formatted_address = $add_wrapper && ! $use_schema
47
-            ? '<div class="espresso-address-dv">' . $formatted_address . '</div>'
48
-            : $formatted_address;
49
-        // return the formatted address
50
-        return $formatted_address;
51
-    }
13
+	/**
14
+	 *    format - output formatted EE object address information
15
+	 *
16
+	 * @access public
17
+	 * @param         object      EEI_Address $obj_with_address
18
+	 * @param string  $type       how the address is formatted. for example: 'multiline' or 'inline'
19
+	 * @param boolean $use_schema whether to apply schema.org formatting to the address
20
+	 * @param bool    $add_wrapper
21
+	 * @return string
22
+	 */
23
+	public static function format(
24
+		$obj_with_address = null,
25
+		$type = 'multiline',
26
+		$use_schema = true,
27
+		$add_wrapper = true
28
+	) {
29
+		// check that incoming object implements the EEI_Address interface
30
+		if (! $obj_with_address instanceof EEI_Address) {
31
+			$msg = esc_html__('The address could not be formatted.', 'event_espresso');
32
+			$dev_msg = esc_html__(
33
+				'The Address Formatter requires passed objects to implement the EEI_Address interface.',
34
+				'event_espresso'
35
+			);
36
+			EE_Error::add_error($msg . '||' . $dev_msg, __FILE__, __FUNCTION__, __LINE__);
37
+			return null;
38
+		}
39
+		// obtain an address formatter
40
+		$formatter = EEH_Address::_get_formatter($type);
41
+		// apply schema.org formatting ?
42
+		$use_schema = ! is_admin() ? $use_schema : false;
43
+		$formatted_address = $use_schema
44
+			? EEH_Address::_schema_formatting($formatter, $obj_with_address)
45
+			: EEH_Address::_regular_formatting($formatter, $obj_with_address, $add_wrapper);
46
+		$formatted_address = $add_wrapper && ! $use_schema
47
+			? '<div class="espresso-address-dv">' . $formatted_address . '</div>'
48
+			: $formatted_address;
49
+		// return the formatted address
50
+		return $formatted_address;
51
+	}
52 52
 
53 53
 
54 54
 
55
-    /**
56
-     *    _get_formatter - obtain the requester formatter class
57
-     *
58
-     * @access private
59
-     * @param string $type how the address is formatted. for example: 'multiline' or 'inline'
60
-     * @return EEI_Address_Formatter
61
-     */
62
-    private static function _get_formatter($type)
63
-    {
64
-        switch ($type) {
65
-            case 'multiline':
66
-                return new EventEspresso\core\services\address\formatters\MultiLineAddressFormatter();
67
-            case 'inline':
68
-                return new EventEspresso\core\services\address\formatters\InlineAddressFormatter();
69
-            default:
70
-                return new EventEspresso\core\services\address\formatters\NullAddressFormatter();
71
-        }
72
-    }
55
+	/**
56
+	 *    _get_formatter - obtain the requester formatter class
57
+	 *
58
+	 * @access private
59
+	 * @param string $type how the address is formatted. for example: 'multiline' or 'inline'
60
+	 * @return EEI_Address_Formatter
61
+	 */
62
+	private static function _get_formatter($type)
63
+	{
64
+		switch ($type) {
65
+			case 'multiline':
66
+				return new EventEspresso\core\services\address\formatters\MultiLineAddressFormatter();
67
+			case 'inline':
68
+				return new EventEspresso\core\services\address\formatters\InlineAddressFormatter();
69
+			default:
70
+				return new EventEspresso\core\services\address\formatters\NullAddressFormatter();
71
+		}
72
+	}
73 73
 
74 74
 
75 75
 
76
-    /**
77
-     *    _regular_formatting
78
-     *    adds formatting to an address
79
-     *
80
-     * @access private
81
-     * @param      object EEI_Address_Formatter $formatter
82
-     * @param      object EEI_Address $obj_with_address
83
-     * @param bool $add_wrapper
84
-     * @return string
85
-     */
86
-    private static function _regular_formatting(
87
-        EEI_Address_Formatter $formatter,
88
-        EEI_Address $obj_with_address,
89
-        $add_wrapper = true
90
-    ) {
91
-        $formatted_address = $add_wrapper ? '<div>' : '';
92
-        $formatted_address .= $formatter->format(
93
-            $obj_with_address->address(),
94
-            $obj_with_address->address2(),
95
-            $obj_with_address->city(),
96
-            $obj_with_address->state_name(),
97
-            $obj_with_address->zip(),
98
-            $obj_with_address->country_name(),
99
-            $obj_with_address->country_ID()
100
-        );
101
-        $formatted_address .= $add_wrapper ? '</div>' : '';
102
-        // return the formatted address
103
-        return $formatted_address;
104
-    }
76
+	/**
77
+	 *    _regular_formatting
78
+	 *    adds formatting to an address
79
+	 *
80
+	 * @access private
81
+	 * @param      object EEI_Address_Formatter $formatter
82
+	 * @param      object EEI_Address $obj_with_address
83
+	 * @param bool $add_wrapper
84
+	 * @return string
85
+	 */
86
+	private static function _regular_formatting(
87
+		EEI_Address_Formatter $formatter,
88
+		EEI_Address $obj_with_address,
89
+		$add_wrapper = true
90
+	) {
91
+		$formatted_address = $add_wrapper ? '<div>' : '';
92
+		$formatted_address .= $formatter->format(
93
+			$obj_with_address->address(),
94
+			$obj_with_address->address2(),
95
+			$obj_with_address->city(),
96
+			$obj_with_address->state_name(),
97
+			$obj_with_address->zip(),
98
+			$obj_with_address->country_name(),
99
+			$obj_with_address->country_ID()
100
+		);
101
+		$formatted_address .= $add_wrapper ? '</div>' : '';
102
+		// return the formatted address
103
+		return $formatted_address;
104
+	}
105 105
 
106 106
 
107 107
 
108
-    /**
109
-     *    _schema_formatting
110
-     *    adds schema.org formatting to an address
111
-     *
112
-     * @access private
113
-     * @param object EEI_Address_Formatter $formatter
114
-     * @param object EEI_Address $obj_with_address
115
-     * @return string
116
-     */
117
-    private static function _schema_formatting(EEI_Address_Formatter $formatter, EEI_Address $obj_with_address)
118
-    {
119
-        $formatted_address = '<div itemprop="address" itemscope itemtype="http://schema.org/PostalAddress">';
120
-        $formatted_address .= $formatter->format(
121
-            EEH_Schema::streetAddress($obj_with_address),
122
-            EEH_Schema::postOfficeBoxNumber($obj_with_address),
123
-            EEH_Schema::addressLocality($obj_with_address),
124
-            EEH_Schema::addressRegion($obj_with_address),
125
-            EEH_Schema::postalCode($obj_with_address),
126
-            EEH_Schema::addressCountry($obj_with_address),
127
-            $obj_with_address->country_ID()
128
-        );
129
-        $formatted_address .= '</div>';
130
-        // return the formatted address
131
-        return $formatted_address;
132
-    }
108
+	/**
109
+	 *    _schema_formatting
110
+	 *    adds schema.org formatting to an address
111
+	 *
112
+	 * @access private
113
+	 * @param object EEI_Address_Formatter $formatter
114
+	 * @param object EEI_Address $obj_with_address
115
+	 * @return string
116
+	 */
117
+	private static function _schema_formatting(EEI_Address_Formatter $formatter, EEI_Address $obj_with_address)
118
+	{
119
+		$formatted_address = '<div itemprop="address" itemscope itemtype="http://schema.org/PostalAddress">';
120
+		$formatted_address .= $formatter->format(
121
+			EEH_Schema::streetAddress($obj_with_address),
122
+			EEH_Schema::postOfficeBoxNumber($obj_with_address),
123
+			EEH_Schema::addressLocality($obj_with_address),
124
+			EEH_Schema::addressRegion($obj_with_address),
125
+			EEH_Schema::postalCode($obj_with_address),
126
+			EEH_Schema::addressCountry($obj_with_address),
127
+			$obj_with_address->country_ID()
128
+		);
129
+		$formatted_address .= '</div>';
130
+		// return the formatted address
131
+		return $formatted_address;
132
+	}
133 133
 }
Please login to merge, or discard this patch.
core/helpers/EEH_Sideloader.helper.php 2 patches
Spacing   +8 added lines, -8 removed lines patch added patch discarded remove patch
@@ -62,13 +62,13 @@  discard block
 block discarded – undo
62 62
             '_upload_to' => $this->_get_wp_uploads_dir(),
63 63
             '_download_from' => '',
64 64
             '_permissions' => 0644,
65
-            '_new_file_name' => 'EE_Sideloader_' . uniqid() . '.default'
65
+            '_new_file_name' => 'EE_Sideloader_'.uniqid().'.default'
66 66
             );
67 67
 
68 68
         $props = array_merge($defaults, $init);
69 69
 
70 70
         foreach ($props as $property => $val) {
71
-            $setter = 'set' . $property;
71
+            $setter = 'set'.$property;
72 72
             if (method_exists($this, $setter)) {
73 73
                 $this->$setter($val);
74 74
             } else {
@@ -90,7 +90,7 @@  discard block
 block discarded – undo
90 90
         }
91 91
 
92 92
         // make sure we include the required wp file for needed functions
93
-        require_once(ABSPATH . 'wp-admin/includes/file.php');
93
+        require_once(ABSPATH.'wp-admin/includes/file.php');
94 94
     }
95 95
 
96 96
 
@@ -216,7 +216,7 @@  discard block
 block discarded – undo
216 216
         // setup temp dir
217 217
         $temp_file = wp_tempnam($this->_download_from);
218 218
 
219
-        if (!$temp_file) {
219
+        if ( ! $temp_file) {
220 220
             EE_Error::add_error(
221 221
                 esc_html__('Something went wrong with the upload.  Unable to create a tmp file for the uploaded file on the server', 'event_espresso'),
222 222
                 __FILE__,
@@ -228,7 +228,7 @@  discard block
 block discarded – undo
228 228
 
229 229
         do_action('AHEE__EEH_Sideloader__sideload__before', $this, $temp_file);
230 230
 
231
-        $wp_remote_args = apply_filters('FHEE__EEH_Sideloader__sideload__wp_remote_args', array( 'timeout' => 500, 'stream' => true, 'filename' => $temp_file ), $this, $temp_file);
231
+        $wp_remote_args = apply_filters('FHEE__EEH_Sideloader__sideload__wp_remote_args', array('timeout' => 500, 'stream' => true, 'filename' => $temp_file), $this, $temp_file);
232 232
 
233 233
         $response = wp_safe_remote_get($this->_download_from, $wp_remote_args);
234 234
 
@@ -267,7 +267,7 @@  discard block
 block discarded – undo
267 267
         $file = $temp_file;
268 268
 
269 269
         // now we have the file, let's get it in the right directory with the right name.
270
-        $path = apply_filters('FHEE__EEH_Sideloader__sideload__new_path', $this->_upload_to . $this->_new_file_name, $this);
270
+        $path = apply_filters('FHEE__EEH_Sideloader__sideload__new_path', $this->_upload_to.$this->_new_file_name, $this);
271 271
 
272 272
         // move file in
273 273
         if (false === @ rename($file, $path)) {
@@ -308,7 +308,7 @@  discard block
 block discarded – undo
308 308
     public function set_upload_from($upload_from)
309 309
     {
310 310
         EE_Error::doing_it_wrong(
311
-            __CLASS__ . '::' . __FUNCTION__,
311
+            __CLASS__.'::'.__FUNCTION__,
312 312
             esc_html__(
313 313
                 'EEH_Sideloader::set_upload_from was renamed to EEH_Sideloader::set_download_from',
314 314
                 'event_espresso'
@@ -327,7 +327,7 @@  discard block
 block discarded – undo
327 327
     public function get_upload_from()
328 328
     {
329 329
         EE_Error::doing_it_wrong(
330
-            __CLASS__ . '::' . __FUNCTION__,
330
+            __CLASS__.'::'.__FUNCTION__,
331 331
             esc_html__(
332 332
                 'EEH_Sideloader::get_upload_from was renamed to EEH_Sideloader::get_download_from',
333 333
                 'event_espresso'
Please login to merge, or discard this patch.
Indentation   +324 added lines, -324 removed lines patch added patch discarded remove patch
@@ -11,328 +11,328 @@
 block discarded – undo
11 11
  */
12 12
 class EEH_Sideloader extends EEH_Base
13 13
 {
14
-    /**
15
-     * @since   4.1.0
16
-     * @var     string
17
-     */
18
-    private $_upload_to;
19
-
20
-    /**
21
-     * @since   4.10.5.p
22
-     * @var     string
23
-     */
24
-    private $_download_from;
25
-
26
-    /**
27
-     * @since   4.1.0
28
-     * @var     string
29
-     */
30
-    private $_permissions;
31
-
32
-    /**
33
-     * @since   4.1.0
34
-     * @var     string
35
-     */
36
-    private $_new_file_name;
37
-
38
-
39
-    /**
40
-     * constructor allows the user to set the properties on the sideloader on construct.  However, there are also setters for doing so.
41
-     *
42
-     * @since 4.1.0
43
-     * @param array $init array fo initializing the sideloader if keys match the properties.
44
-     */
45
-    public function __construct($init = array())
46
-    {
47
-        $this->_init($init);
48
-    }
49
-
50
-
51
-    /**
52
-     * sets the properties for class either to defaults or using incoming initialization array
53
-     *
54
-     * @since 4.1.0
55
-     * @param  array  $init array on init (keys match properties others ignored)
56
-     * @return void
57
-     */
58
-    private function _init($init)
59
-    {
60
-        $defaults = array(
61
-            '_upload_to' => $this->_get_wp_uploads_dir(),
62
-            '_download_from' => '',
63
-            '_permissions' => 0644,
64
-            '_new_file_name' => 'EE_Sideloader_' . uniqid() . '.default'
65
-            );
66
-
67
-        $props = array_merge($defaults, $init);
68
-
69
-        foreach ($props as $property => $val) {
70
-            $setter = 'set' . $property;
71
-            if (method_exists($this, $setter)) {
72
-                $this->$setter($val);
73
-            } else {
74
-                 // No setter found.
75
-                EE_Error::add_error(
76
-                    sprintf(
77
-                        esc_html__(
78
-                            'EEH_Sideloader::%1$s not found. There is no setter for the %2$s property.',
79
-                            'event_espresso'
80
-                        ),
81
-                        $setter,
82
-                        $property
83
-                    ),
84
-                    __FILE__,
85
-                    __FUNCTION__,
86
-                    __LINE__
87
-                );
88
-            }
89
-        }
90
-
91
-        // make sure we include the required wp file for needed functions
92
-        require_once(ABSPATH . 'wp-admin/includes/file.php');
93
-    }
94
-
95
-
96
-    // utilities
97
-
98
-
99
-    /**
100
-     * @since 4.1.0
101
-     * @return void
102
-     */
103
-    private function _get_wp_uploads_dir()
104
-    {
105
-    }
106
-
107
-    // setters
108
-
109
-
110
-    /**
111
-     * sets the _upload_to property to the directory to upload to.
112
-     *
113
-     * @since 4.1.0
114
-     * @param $upload_to_folder
115
-     * @return void
116
-     */
117
-    public function set_upload_to($upload_to_folder)
118
-    {
119
-        $this->_upload_to = $upload_to_folder;
120
-    }
121
-
122
-
123
-    /**
124
-     * sets the _download_from property to the location we should download the file from.
125
-     *
126
-     * @since 4.10.5.p
127
-     * @param string $download_from The full path to the file we should sideload.
128
-     * @return void
129
-     */
130
-    public function set_download_from($download_from)
131
-    {
132
-        $this->_download_from = $download_from;
133
-    }
134
-
135
-
136
-    /**
137
-     * sets the _permissions property used on the sideloaded file.
138
-     *
139
-     * @since 4.1.0
140
-     * @param int $permissions
141
-     * @return void
142
-     */
143
-    public function set_permissions($permissions)
144
-    {
145
-        $this->_permissions = $permissions;
146
-    }
147
-
148
-
149
-    /**
150
-     * sets the _new_file_name property used on the sideloaded file.
151
-     *
152
-     * @since 4.1.0
153
-     * @param string $new_file_name
154
-     * @return void
155
-     */
156
-    public function set_new_file_name($new_file_name)
157
-    {
158
-        $this->_new_file_name = $new_file_name;
159
-    }
160
-
161
-    // getters
162
-
163
-
164
-    /**
165
-     * @since 4.1.0
166
-     * @return string
167
-     */
168
-    public function get_upload_to()
169
-    {
170
-        return $this->_upload_to;
171
-    }
172
-
173
-
174
-    /**
175
-     * @since 4.10.5.p
176
-     * @return string
177
-     */
178
-    public function get_download_from()
179
-    {
180
-        return $this->_download_from;
181
-    }
182
-
183
-
184
-    /**
185
-     * @since 4.1.0
186
-     * @return int
187
-     */
188
-    public function get_permissions()
189
-    {
190
-        return $this->_permissions;
191
-    }
192
-
193
-
194
-    /**
195
-     * @since 4.1.0
196
-     * @return string
197
-     */
198
-    public function get_new_file_name()
199
-    {
200
-        return $this->_new_file_name;
201
-    }
202
-
203
-
204
-    // upload methods
205
-
206
-
207
-    /**
208
-     * Downloads the file using the WordPress HTTP API.
209
-     *
210
-     * @since 4.1.0
211
-     * @return bool
212
-     */
213
-    public function sideload()
214
-    {
215
-        // setup temp dir
216
-        $temp_file = wp_tempnam($this->_download_from);
217
-
218
-        if (!$temp_file) {
219
-            EE_Error::add_error(
220
-                esc_html__('Something went wrong with the upload.  Unable to create a tmp file for the uploaded file on the server', 'event_espresso'),
221
-                __FILE__,
222
-                __FUNCTION__,
223
-                __LINE__
224
-            );
225
-            return false;
226
-        }
227
-
228
-        do_action('AHEE__EEH_Sideloader__sideload__before', $this, $temp_file);
229
-
230
-        $wp_remote_args = apply_filters('FHEE__EEH_Sideloader__sideload__wp_remote_args', array( 'timeout' => 500, 'stream' => true, 'filename' => $temp_file ), $this, $temp_file);
231
-
232
-        $response = wp_safe_remote_get($this->_download_from, $wp_remote_args);
233
-
234
-        if (is_wp_error($response) || 200 != wp_remote_retrieve_response_code($response)) {
235
-            unlink($temp_file);
236
-            if (defined('WP_DEBUG') && WP_DEBUG) {
237
-                EE_Error::add_error(
238
-                    sprintf(
239
-                        esc_html__('Unable to upload the file. Either the path given to download from is incorrect, or something else happened. Here is the path given: %s', 'event_espresso'),
240
-                        $this->_download_from
241
-                    ),
242
-                    __FILE__,
243
-                    __FUNCTION__,
244
-                    __LINE__
245
-                );
246
-            }
247
-            return false;
248
-        }
249
-
250
-        // possible md5 check
251
-        $content_md5 = wp_remote_retrieve_header($response, 'content-md5');
252
-        if ($content_md5) {
253
-            $md5_check = verify_file_md5($temp_file, $content_md5);
254
-            if (is_wp_error($md5_check)) {
255
-                unlink($temp_file);
256
-                EE_Error::add_error(
257
-                    $md5_check->get_error_message(),
258
-                    __FILE__,
259
-                    __FUNCTION__,
260
-                    __LINE__
261
-                );
262
-                return false;
263
-            }
264
-        }
265
-
266
-        $file = $temp_file;
267
-
268
-        // now we have the file, let's get it in the right directory with the right name.
269
-        $path = apply_filters('FHEE__EEH_Sideloader__sideload__new_path', $this->_upload_to . $this->_new_file_name, $this);
270
-
271
-        // move file in
272
-        if (false === @ rename($file, $path)) {
273
-            unlink($temp_file);
274
-            EE_Error::add_error(
275
-                sprintf(
276
-                    esc_html__('Unable to move the file to new location (possible permissions errors). This is the path the class attempted to move the file to: %s', 'event_espresso'),
277
-                    $path
278
-                ),
279
-                __FILE__,
280
-                __FUNCTION__,
281
-                __LINE__
282
-            );
283
-            return false;
284
-        }
285
-
286
-        // set permissions
287
-        $permissions = apply_filters('FHEE__EEH_Sideloader__sideload__permissions_applied', $this->_permissions, $this);
288
-        chmod($path, $permissions);
289
-
290
-        // that's it.  let's allow for actions after file uploaded.
291
-        do_action('AHEE__EE_Sideloader__sideload_after', $this, $path);
292
-
293
-        // unlink tempfile
294
-        @unlink($temp_file);
295
-        return true;
296
-    }
297
-
298
-    // deprecated
299
-
300
-    /**
301
-     * sets the _upload_from property to the location we should download the file from.
302
-     *
303
-     * @param string $upload_from The full path to the file we should sideload.
304
-     * @return void
305
-     * @deprecated since version 4.10.5.p
306
-     */
307
-    public function set_upload_from($upload_from)
308
-    {
309
-        EE_Error::doing_it_wrong(
310
-            __CLASS__ . '::' . __FUNCTION__,
311
-            esc_html__(
312
-                'EEH_Sideloader::set_upload_from was renamed to EEH_Sideloader::set_download_from',
313
-                'event_espresso'
314
-            ),
315
-            '4.10.5.p'
316
-        );
317
-        $this->set_download_from($upload_from);
318
-    }
319
-
320
-
321
-    /**
322
-     * @since 4.1.0
323
-     * @return string
324
-     * @deprecated since version 4.10.5.p
325
-     */
326
-    public function get_upload_from()
327
-    {
328
-        EE_Error::doing_it_wrong(
329
-            __CLASS__ . '::' . __FUNCTION__,
330
-            esc_html__(
331
-                'EEH_Sideloader::get_upload_from was renamed to EEH_Sideloader::get_download_from',
332
-                'event_espresso'
333
-            ),
334
-            '4.10.5.p'
335
-        );
336
-        return $this->_download_from;
337
-    }
14
+	/**
15
+	 * @since   4.1.0
16
+	 * @var     string
17
+	 */
18
+	private $_upload_to;
19
+
20
+	/**
21
+	 * @since   4.10.5.p
22
+	 * @var     string
23
+	 */
24
+	private $_download_from;
25
+
26
+	/**
27
+	 * @since   4.1.0
28
+	 * @var     string
29
+	 */
30
+	private $_permissions;
31
+
32
+	/**
33
+	 * @since   4.1.0
34
+	 * @var     string
35
+	 */
36
+	private $_new_file_name;
37
+
38
+
39
+	/**
40
+	 * constructor allows the user to set the properties on the sideloader on construct.  However, there are also setters for doing so.
41
+	 *
42
+	 * @since 4.1.0
43
+	 * @param array $init array fo initializing the sideloader if keys match the properties.
44
+	 */
45
+	public function __construct($init = array())
46
+	{
47
+		$this->_init($init);
48
+	}
49
+
50
+
51
+	/**
52
+	 * sets the properties for class either to defaults or using incoming initialization array
53
+	 *
54
+	 * @since 4.1.0
55
+	 * @param  array  $init array on init (keys match properties others ignored)
56
+	 * @return void
57
+	 */
58
+	private function _init($init)
59
+	{
60
+		$defaults = array(
61
+			'_upload_to' => $this->_get_wp_uploads_dir(),
62
+			'_download_from' => '',
63
+			'_permissions' => 0644,
64
+			'_new_file_name' => 'EE_Sideloader_' . uniqid() . '.default'
65
+			);
66
+
67
+		$props = array_merge($defaults, $init);
68
+
69
+		foreach ($props as $property => $val) {
70
+			$setter = 'set' . $property;
71
+			if (method_exists($this, $setter)) {
72
+				$this->$setter($val);
73
+			} else {
74
+				 // No setter found.
75
+				EE_Error::add_error(
76
+					sprintf(
77
+						esc_html__(
78
+							'EEH_Sideloader::%1$s not found. There is no setter for the %2$s property.',
79
+							'event_espresso'
80
+						),
81
+						$setter,
82
+						$property
83
+					),
84
+					__FILE__,
85
+					__FUNCTION__,
86
+					__LINE__
87
+				);
88
+			}
89
+		}
90
+
91
+		// make sure we include the required wp file for needed functions
92
+		require_once(ABSPATH . 'wp-admin/includes/file.php');
93
+	}
94
+
95
+
96
+	// utilities
97
+
98
+
99
+	/**
100
+	 * @since 4.1.0
101
+	 * @return void
102
+	 */
103
+	private function _get_wp_uploads_dir()
104
+	{
105
+	}
106
+
107
+	// setters
108
+
109
+
110
+	/**
111
+	 * sets the _upload_to property to the directory to upload to.
112
+	 *
113
+	 * @since 4.1.0
114
+	 * @param $upload_to_folder
115
+	 * @return void
116
+	 */
117
+	public function set_upload_to($upload_to_folder)
118
+	{
119
+		$this->_upload_to = $upload_to_folder;
120
+	}
121
+
122
+
123
+	/**
124
+	 * sets the _download_from property to the location we should download the file from.
125
+	 *
126
+	 * @since 4.10.5.p
127
+	 * @param string $download_from The full path to the file we should sideload.
128
+	 * @return void
129
+	 */
130
+	public function set_download_from($download_from)
131
+	{
132
+		$this->_download_from = $download_from;
133
+	}
134
+
135
+
136
+	/**
137
+	 * sets the _permissions property used on the sideloaded file.
138
+	 *
139
+	 * @since 4.1.0
140
+	 * @param int $permissions
141
+	 * @return void
142
+	 */
143
+	public function set_permissions($permissions)
144
+	{
145
+		$this->_permissions = $permissions;
146
+	}
147
+
148
+
149
+	/**
150
+	 * sets the _new_file_name property used on the sideloaded file.
151
+	 *
152
+	 * @since 4.1.0
153
+	 * @param string $new_file_name
154
+	 * @return void
155
+	 */
156
+	public function set_new_file_name($new_file_name)
157
+	{
158
+		$this->_new_file_name = $new_file_name;
159
+	}
160
+
161
+	// getters
162
+
163
+
164
+	/**
165
+	 * @since 4.1.0
166
+	 * @return string
167
+	 */
168
+	public function get_upload_to()
169
+	{
170
+		return $this->_upload_to;
171
+	}
172
+
173
+
174
+	/**
175
+	 * @since 4.10.5.p
176
+	 * @return string
177
+	 */
178
+	public function get_download_from()
179
+	{
180
+		return $this->_download_from;
181
+	}
182
+
183
+
184
+	/**
185
+	 * @since 4.1.0
186
+	 * @return int
187
+	 */
188
+	public function get_permissions()
189
+	{
190
+		return $this->_permissions;
191
+	}
192
+
193
+
194
+	/**
195
+	 * @since 4.1.0
196
+	 * @return string
197
+	 */
198
+	public function get_new_file_name()
199
+	{
200
+		return $this->_new_file_name;
201
+	}
202
+
203
+
204
+	// upload methods
205
+
206
+
207
+	/**
208
+	 * Downloads the file using the WordPress HTTP API.
209
+	 *
210
+	 * @since 4.1.0
211
+	 * @return bool
212
+	 */
213
+	public function sideload()
214
+	{
215
+		// setup temp dir
216
+		$temp_file = wp_tempnam($this->_download_from);
217
+
218
+		if (!$temp_file) {
219
+			EE_Error::add_error(
220
+				esc_html__('Something went wrong with the upload.  Unable to create a tmp file for the uploaded file on the server', 'event_espresso'),
221
+				__FILE__,
222
+				__FUNCTION__,
223
+				__LINE__
224
+			);
225
+			return false;
226
+		}
227
+
228
+		do_action('AHEE__EEH_Sideloader__sideload__before', $this, $temp_file);
229
+
230
+		$wp_remote_args = apply_filters('FHEE__EEH_Sideloader__sideload__wp_remote_args', array( 'timeout' => 500, 'stream' => true, 'filename' => $temp_file ), $this, $temp_file);
231
+
232
+		$response = wp_safe_remote_get($this->_download_from, $wp_remote_args);
233
+
234
+		if (is_wp_error($response) || 200 != wp_remote_retrieve_response_code($response)) {
235
+			unlink($temp_file);
236
+			if (defined('WP_DEBUG') && WP_DEBUG) {
237
+				EE_Error::add_error(
238
+					sprintf(
239
+						esc_html__('Unable to upload the file. Either the path given to download from is incorrect, or something else happened. Here is the path given: %s', 'event_espresso'),
240
+						$this->_download_from
241
+					),
242
+					__FILE__,
243
+					__FUNCTION__,
244
+					__LINE__
245
+				);
246
+			}
247
+			return false;
248
+		}
249
+
250
+		// possible md5 check
251
+		$content_md5 = wp_remote_retrieve_header($response, 'content-md5');
252
+		if ($content_md5) {
253
+			$md5_check = verify_file_md5($temp_file, $content_md5);
254
+			if (is_wp_error($md5_check)) {
255
+				unlink($temp_file);
256
+				EE_Error::add_error(
257
+					$md5_check->get_error_message(),
258
+					__FILE__,
259
+					__FUNCTION__,
260
+					__LINE__
261
+				);
262
+				return false;
263
+			}
264
+		}
265
+
266
+		$file = $temp_file;
267
+
268
+		// now we have the file, let's get it in the right directory with the right name.
269
+		$path = apply_filters('FHEE__EEH_Sideloader__sideload__new_path', $this->_upload_to . $this->_new_file_name, $this);
270
+
271
+		// move file in
272
+		if (false === @ rename($file, $path)) {
273
+			unlink($temp_file);
274
+			EE_Error::add_error(
275
+				sprintf(
276
+					esc_html__('Unable to move the file to new location (possible permissions errors). This is the path the class attempted to move the file to: %s', 'event_espresso'),
277
+					$path
278
+				),
279
+				__FILE__,
280
+				__FUNCTION__,
281
+				__LINE__
282
+			);
283
+			return false;
284
+		}
285
+
286
+		// set permissions
287
+		$permissions = apply_filters('FHEE__EEH_Sideloader__sideload__permissions_applied', $this->_permissions, $this);
288
+		chmod($path, $permissions);
289
+
290
+		// that's it.  let's allow for actions after file uploaded.
291
+		do_action('AHEE__EE_Sideloader__sideload_after', $this, $path);
292
+
293
+		// unlink tempfile
294
+		@unlink($temp_file);
295
+		return true;
296
+	}
297
+
298
+	// deprecated
299
+
300
+	/**
301
+	 * sets the _upload_from property to the location we should download the file from.
302
+	 *
303
+	 * @param string $upload_from The full path to the file we should sideload.
304
+	 * @return void
305
+	 * @deprecated since version 4.10.5.p
306
+	 */
307
+	public function set_upload_from($upload_from)
308
+	{
309
+		EE_Error::doing_it_wrong(
310
+			__CLASS__ . '::' . __FUNCTION__,
311
+			esc_html__(
312
+				'EEH_Sideloader::set_upload_from was renamed to EEH_Sideloader::set_download_from',
313
+				'event_espresso'
314
+			),
315
+			'4.10.5.p'
316
+		);
317
+		$this->set_download_from($upload_from);
318
+	}
319
+
320
+
321
+	/**
322
+	 * @since 4.1.0
323
+	 * @return string
324
+	 * @deprecated since version 4.10.5.p
325
+	 */
326
+	public function get_upload_from()
327
+	{
328
+		EE_Error::doing_it_wrong(
329
+			__CLASS__ . '::' . __FUNCTION__,
330
+			esc_html__(
331
+				'EEH_Sideloader::get_upload_from was renamed to EEH_Sideloader::get_download_from',
332
+				'event_espresso'
333
+			),
334
+			'4.10.5.p'
335
+		);
336
+		return $this->_download_from;
337
+	}
338 338
 }
Please login to merge, or discard this patch.
core/helpers/EEH_MSG_Template.helper.php 2 patches
Spacing   +56 added lines, -56 removed lines patch added patch discarded remove patch
@@ -95,7 +95,7 @@  discard block
 block discarded – undo
95 95
             }
96 96
             $new_message_template_group = EEH_MSG_Template::create_new_templates($messenger, $message_type, $GRP_ID, $global);
97 97
 
98
-            if (! $new_message_template_group) {
98
+            if ( ! $new_message_template_group) {
99 99
                 continue;
100 100
             }
101 101
             $templates[] = $new_message_template_group;
@@ -130,7 +130,7 @@  discard block
 block discarded – undo
130 130
                     )
131 131
                 )
132 132
             )
133
-            : EEM_Message_Template::instance()->count(array( array( 'GRP_ID' => $GRP_ID ) ));
133
+            : EEM_Message_Template::instance()->count(array(array('GRP_ID' => $GRP_ID)));
134 134
 
135 135
         return $count > 0;
136 136
     }
@@ -147,14 +147,14 @@  discard block
 block discarded – undo
147 147
      */
148 148
     public static function update_to_active($messenger_names, $message_type_names)
149 149
     {
150
-        $messenger_names = is_array($messenger_names) ? $messenger_names : array( $messenger_names );
151
-        $message_type_names = is_array($message_type_names) ? $message_type_names : array( $message_type_names );
150
+        $messenger_names = is_array($messenger_names) ? $messenger_names : array($messenger_names);
151
+        $message_type_names = is_array($message_type_names) ? $message_type_names : array($message_type_names);
152 152
         return EEM_Message_Template_Group::instance()->update(
153
-            array( 'MTP_is_active' => 1 ),
153
+            array('MTP_is_active' => 1),
154 154
             array(
155 155
                 array(
156
-                    'MTP_messenger'     => array( 'IN', $messenger_names ),
157
-                    'MTP_message_type'  => array( 'IN', $message_type_names )
156
+                    'MTP_messenger'     => array('IN', $messenger_names),
157
+                    'MTP_message_type'  => array('IN', $message_type_names)
158 158
                 )
159 159
             )
160 160
         );
@@ -242,13 +242,13 @@  discard block
 block discarded – undo
242 242
         $messenger = $message_resource_manager->get_messenger($messenger);
243 243
 
244 244
         // if messenger isn't a EE_messenger resource then bail.
245
-        if (! $messenger instanceof EE_messenger) {
245
+        if ( ! $messenger instanceof EE_messenger) {
246 246
             return array();
247 247
         }
248 248
 
249 249
         // validate class for getting our list of shortcodes
250
-        $classname = 'EE_Messages_' . $messenger_name . '_' . $mt_name . '_Validator';
251
-        if (! class_exists($classname)) {
250
+        $classname = 'EE_Messages_'.$messenger_name.'_'.$mt_name.'_Validator';
251
+        if ( ! class_exists($classname)) {
252 252
             $msg[] = esc_html__('The Validator class was unable to load', 'event_espresso');
253 253
             $msg[] = sprintf(
254 254
                 esc_html__('The class name compiled was %s. Please check and make sure the spelling and case is correct for the class name and that there is an autoloader in place for this class', 'event_espresso'),
@@ -264,44 +264,44 @@  discard block
 block discarded – undo
264 264
         // let's make sure we're only getting the shortcode part of the validators
265 265
         $shortcodes = array();
266 266
         foreach ($valid_shortcodes as $field => $validators) {
267
-            $shortcodes[ $field ] = $validators['shortcodes'];
267
+            $shortcodes[$field] = $validators['shortcodes'];
268 268
         }
269 269
         $valid_shortcodes = $shortcodes;
270 270
 
271 271
         // if not all fields let's make sure we ONLY include the shortcodes for the specified fields.
272
-        if (! empty($fields)) {
272
+        if ( ! empty($fields)) {
273 273
             $specified_shortcodes = array();
274 274
             foreach ($fields as $field) {
275
-                if (isset($valid_shortcodes[ $field ])) {
276
-                    $specified_shortcodes[ $field ] = $valid_shortcodes[ $field ];
275
+                if (isset($valid_shortcodes[$field])) {
276
+                    $specified_shortcodes[$field] = $valid_shortcodes[$field];
277 277
                 }
278 278
             }
279 279
             $valid_shortcodes = $specified_shortcodes;
280 280
         }
281 281
 
282 282
         // if not merged then let's replace the fields with the localized fields
283
-        if (! $merged) {
283
+        if ( ! $merged) {
284 284
             // let's get all the fields for the set messenger so that we can get the localized label and use that in the returned array.
285 285
             $field_settings = $messenger->get_template_fields();
286 286
             $localized = array();
287 287
             foreach ($valid_shortcodes as $field => $shortcodes) {
288 288
                 // get localized field label
289
-                if (isset($field_settings[ $field ])) {
289
+                if (isset($field_settings[$field])) {
290 290
                     // possible that this is used as a main field.
291
-                    if (empty($field_settings[ $field ])) {
292
-                        if (isset($field_settings['extra'][ $field ])) {
293
-                            $_field = $field_settings['extra'][ $field ]['main']['label'];
291
+                    if (empty($field_settings[$field])) {
292
+                        if (isset($field_settings['extra'][$field])) {
293
+                            $_field = $field_settings['extra'][$field]['main']['label'];
294 294
                         } else {
295 295
                             $_field = $field;
296 296
                         }
297 297
                     } else {
298
-                        $_field = $field_settings[ $field ]['label'];
298
+                        $_field = $field_settings[$field]['label'];
299 299
                     }
300 300
                 } elseif (isset($field_settings['extra'])) {
301 301
                     // loop through extra "main fields" and see if any of their children have our field
302 302
                     foreach ($field_settings['extra'] as $fields) {
303
-                        if (isset($fields[ $field ])) {
304
-                            $_field = $fields[ $field ]['label'];
303
+                        if (isset($fields[$field])) {
304
+                            $_field = $fields[$field]['label'];
305 305
                         } else {
306 306
                             $_field = $field;
307 307
                         }
@@ -310,7 +310,7 @@  discard block
 block discarded – undo
310 310
                     $_field = $field;
311 311
                 }
312 312
                 if (isset($_field)) {
313
-                    $localized[ (string) $_field ] = $shortcodes;
313
+                    $localized[(string) $_field] = $shortcodes;
314 314
                 }
315 315
             }
316 316
             $valid_shortcodes = $localized;
@@ -321,10 +321,10 @@  discard block
 block discarded – undo
321 321
             $merged_codes = array();
322 322
             foreach ($valid_shortcodes as $shortcode) {
323 323
                 foreach ($shortcode as $code => $label) {
324
-                    if (isset($merged_codes[ $code ])) {
324
+                    if (isset($merged_codes[$code])) {
325 325
                         continue;
326 326
                     } else {
327
-                        $merged_codes[ $code ] = $label;
327
+                        $merged_codes[$code] = $label;
328 328
                     }
329 329
                 }
330 330
             }
@@ -475,12 +475,12 @@  discard block
 block discarded – undo
475 475
         $sending_messenger = ''
476 476
     ) {
477 477
         // first determine if the url can be to the EE_Message object.
478
-        if (! $message_type->always_generate()) {
478
+        if ( ! $message_type->always_generate()) {
479 479
             return EEH_MSG_Template::generate_browser_trigger($message);
480 480
         }
481 481
 
482 482
         // if $registration object is not valid then exit early because there's nothing that can be generated.
483
-        if (! $registration instanceof EE_Registration) {
483
+        if ( ! $registration instanceof EE_Registration) {
484 484
             throw new EE_Error(
485 485
                 esc_html__('Incoming value for registration is not a valid EE_Registration object.', 'event_espresso')
486 486
             );
@@ -488,7 +488,7 @@  discard block
 block discarded – undo
488 488
 
489 489
         // validate given context
490 490
         $contexts = $message_type->get_contexts();
491
-        if ($message->context() !== '' && ! isset($contexts[ $message->context() ])) {
491
+        if ($message->context() !== '' && ! isset($contexts[$message->context()])) {
492 492
             throw new EE_Error(
493 493
                 sprintf(
494 494
                     esc_html__('The context %s is not a valid context for %s.', 'event_espresso'),
@@ -499,11 +499,11 @@  discard block
 block discarded – undo
499 499
         }
500 500
 
501 501
         // valid sending messenger but only if sending messenger set.  Otherwise generating messenger is used.
502
-        if (! empty($sending_messenger)) {
502
+        if ( ! empty($sending_messenger)) {
503 503
             $with_messengers = $message_type->with_messengers();
504 504
             if (
505
-                ! isset($with_messengers[ $message->messenger() ])
506
-                 || ! in_array($sending_messenger, $with_messengers[ $message->messenger() ])
505
+                ! isset($with_messengers[$message->messenger()])
506
+                 || ! in_array($sending_messenger, $with_messengers[$message->messenger()])
507 507
             ) {
508 508
                 throw new EE_Error(
509 509
                     sprintf(
@@ -636,7 +636,7 @@  discard block
 block discarded – undo
636 636
     public static function get_message_action_icon($type)
637 637
     {
638 638
         $action_icons = self::get_message_action_icons();
639
-        return isset($action_icons[ $type ]) ? $action_icons[ $type ] : [];
639
+        return isset($action_icons[$type]) ? $action_icons[$type] : [];
640 640
     }
641 641
 
642 642
 
@@ -701,7 +701,7 @@  discard block
 block discarded – undo
701 701
     public static function get_message_action_url($type, EE_Message $message = null, $query_params = array())
702 702
     {
703 703
         $action_urls = self::get_message_action_urls($message, $query_params);
704
-        return isset($action_urls[ $type ])  ? $action_urls[ $type ] : '';
704
+        return isset($action_urls[$type]) ? $action_urls[$type] : '';
705 705
     }
706 706
 
707 707
 
@@ -722,7 +722,7 @@  discard block
 block discarded – undo
722 722
         EE_Registry::instance()->load_helper('URL');
723 723
         // if $message is not an instance of EE_Message then let's just do a dummy.
724 724
         $message = empty($message) ? EE_Message_Factory::create() : $message;
725
-        $action_urls =  apply_filters(
725
+        $action_urls = apply_filters(
726 726
             'FHEE__EEH_MSG_Template__get_message_action_url',
727 727
             array(
728 728
                 'view' => EEH_MSG_Template::generate_browser_trigger($message),
@@ -805,7 +805,7 @@  discard block
 block discarded – undo
805 805
     {
806 806
         $url = EEH_MSG_Template::get_message_action_url($type, $message, $query_params);
807 807
         $icon_css = EEH_MSG_Template::get_message_action_icon($type);
808
-        $title = isset($icon_css['label']) ? 'title="' . $icon_css['label'] . '"' : '';
808
+        $title = isset($icon_css['label']) ? 'title="'.$icon_css['label'].'"' : '';
809 809
 
810 810
         if (empty($url) || empty($icon_css) || ! isset($icon_css['css_class'])) {
811 811
             return '';
@@ -814,14 +814,14 @@  discard block
 block discarded – undo
814 814
         $icon_css['css_class'] .= esc_attr(
815 815
             apply_filters(
816 816
                 'FHEE__EEH_MSG_Template__get_message_action_link__icon_css_class',
817
-                ' js-ee-message-action-link ee-message-action-link-' . $type,
817
+                ' js-ee-message-action-link ee-message-action-link-'.$type,
818 818
                 $type,
819 819
                 $message,
820 820
                 $query_params
821 821
             )
822 822
         );
823 823
 
824
-        return '<a href="' . $url . '" ' . $title . '><span class="' . esc_attr($icon_css['css_class']) . '"></span></a>';
824
+        return '<a href="'.$url.'" '.$title.'><span class="'.esc_attr($icon_css['css_class']).'"></span></a>';
825 825
     }
826 826
 
827 827
 
@@ -862,7 +862,7 @@  discard block
 block discarded – undo
862 862
     public static function convert_reg_status_to_message_type($reg_status)
863 863
     {
864 864
         $reg_status_array = self::reg_status_to_message_type_array();
865
-        return isset($reg_status_array[ $reg_status ]) ? $reg_status_array[ $reg_status ] : '';
865
+        return isset($reg_status_array[$reg_status]) ? $reg_status_array[$reg_status] : '';
866 866
     }
867 867
 
868 868
 
@@ -900,7 +900,7 @@  discard block
 block discarded – undo
900 900
     public static function convert_payment_status_to_message_type($payment_status)
901 901
     {
902 902
         $payment_status_array = self::payment_status_to_message_type_array();
903
-        return isset($payment_status_array[ $payment_status ]) ? $payment_status_array[ $payment_status ] : '';
903
+        return isset($payment_status_array[$payment_status]) ? $payment_status_array[$payment_status] : '';
904 904
     }
905 905
 
906 906
 
@@ -913,7 +913,7 @@  discard block
 block discarded – undo
913 913
      */
914 914
     public static function get_template_pack($template_pack_name)
915 915
     {
916
-        if (! self::$_template_pack_collection instanceof EE_Object_Collection) {
916
+        if ( ! self::$_template_pack_collection instanceof EE_Object_Collection) {
917 917
             self::$_template_pack_collection = new EE_Messages_Template_Pack_Collection();
918 918
         }
919 919
 
@@ -926,14 +926,14 @@  discard block
 block discarded – undo
926 926
 
927 927
         // nope...let's get it.
928 928
         // not set yet so let's attempt to get it.
929
-        $pack_class_name = 'EE_Messages_Template_Pack_' . str_replace(
929
+        $pack_class_name = 'EE_Messages_Template_Pack_'.str_replace(
930 930
             ' ',
931 931
             '_',
932 932
             ucwords(
933 933
                 str_replace('_', ' ', $template_pack_name)
934 934
             )
935 935
         );
936
-        if (! class_exists($pack_class_name) && $template_pack_name !== 'default') {
936
+        if ( ! class_exists($pack_class_name) && $template_pack_name !== 'default') {
937 937
             return self::get_template_pack('default');
938 938
         } else {
939 939
             $template_pack = new $pack_class_name();
@@ -956,18 +956,18 @@  discard block
 block discarded – undo
956 956
     public static function get_template_pack_collection()
957 957
     {
958 958
         $new_collection = false;
959
-        if (! self::$_template_pack_collection instanceof EE_Messages_Template_Pack_Collection) {
959
+        if ( ! self::$_template_pack_collection instanceof EE_Messages_Template_Pack_Collection) {
960 960
             self::$_template_pack_collection = new EE_Messages_Template_Pack_Collection();
961 961
             $new_collection = true;
962 962
         }
963 963
 
964 964
         // glob the defaults directory for messages
965
-        $templates = glob(EE_LIBRARIES . 'messages/defaults/*', GLOB_ONLYDIR);
965
+        $templates = glob(EE_LIBRARIES.'messages/defaults/*', GLOB_ONLYDIR);
966 966
         foreach ($templates as $template_path) {
967 967
             // grab folder name
968 968
             $template = basename($template_path);
969 969
 
970
-            if (! $new_collection) {
970
+            if ( ! $new_collection) {
971 971
                 // already have it?
972 972
                 if (self::$_template_pack_collection->get_by_name($template) instanceof EE_Messages_Template_Pack) {
973 973
                     continue;
@@ -975,7 +975,7 @@  discard block
 block discarded – undo
975 975
             }
976 976
 
977 977
             // setup classname.
978
-            $template_pack_class_name = 'EE_Messages_Template_Pack_' . str_replace(
978
+            $template_pack_class_name = 'EE_Messages_Template_Pack_'.str_replace(
979 979
                 ' ',
980 980
                 '_',
981 981
                 ucwords(
@@ -986,7 +986,7 @@  discard block
 block discarded – undo
986 986
                     )
987 987
                 )
988 988
             );
989
-            if (! class_exists($template_pack_class_name)) {
989
+            if ( ! class_exists($template_pack_class_name)) {
990 990
                 continue;
991 991
             }
992 992
             self::$_template_pack_collection->add(new $template_pack_class_name());
@@ -1028,7 +1028,7 @@  discard block
 block discarded – undo
1028 1028
         $Message_Resource_Manager = EE_Registry::instance()->load_lib('Message_Resource_Manager');
1029 1029
         $messenger = $Message_Resource_Manager->valid_messenger($messenger_name);
1030 1030
         $message_type = $Message_Resource_Manager->valid_message_type($message_type_name);
1031
-        if (! EEH_MSG_Template::message_type_has_active_templates_for_messenger($messenger, $message_type, $global)) {
1031
+        if ( ! EEH_MSG_Template::message_type_has_active_templates_for_messenger($messenger, $message_type, $global)) {
1032 1032
             return array();
1033 1033
         }
1034 1034
         // whew made it this far!  Okay, let's go ahead and create the templates then
@@ -1048,13 +1048,13 @@  discard block
 block discarded – undo
1048 1048
     protected static function _create_new_templates(EE_messenger $messenger, EE_message_type $message_type, $GRP_ID, $global)
1049 1049
     {
1050 1050
         // if we're creating a custom template then we don't need to use the defaults class
1051
-        if (! $global) {
1051
+        if ( ! $global) {
1052 1052
             return EEH_MSG_Template::_create_custom_template_group($messenger, $message_type, $GRP_ID);
1053 1053
         }
1054 1054
         /** @type EE_Messages_Template_Defaults $Message_Template_Defaults */
1055 1055
         $Message_Template_Defaults = EE_Registry::factory(
1056 1056
             'EE_Messages_Template_Defaults',
1057
-            array( $messenger, $message_type, $GRP_ID )
1057
+            array($messenger, $message_type, $GRP_ID)
1058 1058
         );
1059 1059
         // generate templates
1060 1060
         $success = $Message_Template_Defaults->create_new_templates();
@@ -1062,7 +1062,7 @@  discard block
 block discarded – undo
1062 1062
         // if creating the template failed.  Then we should deactivate the related message_type for the messenger because
1063 1063
         // its not active if it doesn't have a template.  Note this is only happening for GLOBAL template creation
1064 1064
         // attempts.
1065
-        if (! $success) {
1065
+        if ( ! $success) {
1066 1066
             /** @var EE_Message_Resource_Manager $message_resource_manager */
1067 1067
             $message_resource_manager = EE_Registry::instance()->load_lib('Message_Resource_Manager');
1068 1068
             $message_resource_manager->deactivate_message_type_for_messenger($message_type->name, $messenger->name);
@@ -1097,7 +1097,7 @@  discard block
 block discarded – undo
1097 1097
     private static function _create_custom_template_group(EE_messenger $messenger, EE_message_type $message_type, $GRP_ID)
1098 1098
     {
1099 1099
         // defaults
1100
-        $success = array( 'GRP_ID' => null, 'MTP_context' => '' );
1100
+        $success = array('GRP_ID' => null, 'MTP_context' => '');
1101 1101
         // get the template group to use as a template from the db.  If $GRP_ID is empty then we'll assume the base will be the global template matching the messenger and message type.
1102 1102
         $Message_Template_Group = empty($GRP_ID)
1103 1103
             ? EEM_Message_Template_Group::instance()->get_one(
@@ -1111,7 +1111,7 @@  discard block
 block discarded – undo
1111 1111
             )
1112 1112
             : EEM_Message_Template_Group::instance()->get_one_by_ID($GRP_ID);
1113 1113
         // if we don't have a mtg at this point then we need to bail.
1114
-        if (! $Message_Template_Group instanceof EE_Message_Template_Group) {
1114
+        if ( ! $Message_Template_Group instanceof EE_Message_Template_Group) {
1115 1115
             EE_Error::add_error(
1116 1116
                 sprintf(
1117 1117
                     esc_html__(
@@ -1157,7 +1157,7 @@  discard block
 block discarded – undo
1157 1157
         $success['template_name'] = $template_name;
1158 1158
         // add new message templates and add relation to.
1159 1159
         foreach ($message_templates as $message_template) {
1160
-            if (! $message_template instanceof EE_Message_Template) {
1160
+            if ( ! $message_template instanceof EE_Message_Template) {
1161 1161
                 continue;
1162 1162
             }
1163 1163
             $new_message_template = clone $message_template;
@@ -1236,7 +1236,7 @@  discard block
 block discarded – undo
1236 1236
         $Message_Resource_Manager = EE_Registry::instance()->load_lib('Message_Resource_Manager');
1237 1237
         $messenger = $Message_Resource_Manager->valid_messenger($messenger_name);
1238 1238
         $message_type = $Message_Resource_Manager->valid_message_type($message_type_name);
1239
-        if (! EEH_MSG_Template::message_type_has_active_templates_for_messenger($messenger, $message_type)) {
1239
+        if ( ! EEH_MSG_Template::message_type_has_active_templates_for_messenger($messenger, $message_type)) {
1240 1240
             return array();
1241 1241
         }
1242 1242
 
@@ -1248,7 +1248,7 @@  discard block
 block discarded – undo
1248 1248
                 if (in_array($field, $excluded_fields_for_messenger, true)) {
1249 1249
                     continue;
1250 1250
                 }
1251
-                $template_fields[ $context ][ $field ] = $value;
1251
+                $template_fields[$context][$field] = $value;
1252 1252
             }
1253 1253
         }
1254 1254
         if (empty($template_fields)) {
Please login to merge, or discard this patch.
Indentation   +1249 added lines, -1249 removed lines patch added patch discarded remove patch
@@ -13,1253 +13,1253 @@
 block discarded – undo
13 13
  */
14 14
 class EEH_MSG_Template
15 15
 {
16
-    /**
17
-     * Holds a collection of EE_Message_Template_Pack objects.
18
-     * @type EE_Messages_Template_Pack_Collection
19
-     */
20
-    protected static $_template_pack_collection;
21
-
22
-
23
-    /**
24
-     * @throws EE_Error
25
-     */
26
-    private static function _set_autoloader()
27
-    {
28
-        EED_Messages::set_autoloaders();
29
-    }
30
-
31
-
32
-    /**
33
-     * generate_new_templates
34
-     * This will handle the messenger, message_type selection when "adding a new custom template" for an event and will
35
-     * automatically create the defaults for the event.  The user would then be redirected to edit the default context
36
-     * for the event.
37
-     *
38
-     * @access protected
39
-     * @param string $messenger     the messenger we are generating templates for
40
-     * @param array  $message_types array of message types that the templates are generated for.
41
-     * @param int    $GRP_ID        If a non global template is being generated then it is expected we'll have a GRP_ID
42
-     *                              to use as the base for the new generated template.
43
-     * @param bool   $global        true indicates generating templates on messenger activation. false requires GRP_ID
44
-     *                              for event specific template generation.
45
-     * @return array  @see EEH_MSG_Template::_create_new_templates for the return value of each element in the array
46
-     *                for templates that are generated.  If this is an empty array then it means no templates were
47
-     *                generated which usually means there was an error.  Anything in the array with an empty value for
48
-     *                `MTP_context` means that it was not a new generated template but just reactivated (which only
49
-     *                happens for global templates that already exist in the database.
50
-     * @throws EE_Error
51
-     * @throws ReflectionException
52
-     */
53
-    public static function generate_new_templates($messenger, $message_types, $GRP_ID = 0, $global = false)
54
-    {
55
-        // make sure message_type is an array.
56
-        $message_types = (array) $message_types;
57
-        $templates = array();
58
-
59
-        if (empty($messenger)) {
60
-            throw new EE_Error(esc_html__('We need a messenger to generate templates!', 'event_espresso'));
61
-        }
62
-
63
-        // if we STILL have empty $message_types then we need to generate an error message b/c we NEED message types to do the template files.
64
-        if (empty($message_types)) {
65
-            throw new EE_Error(esc_html__('We need at least one message type to generate templates!', 'event_espresso'));
66
-        }
67
-
68
-        EEH_MSG_Template::_set_autoloader();
69
-        foreach ($message_types as $message_type) {
70
-            // if this is global template generation.
71
-            if ($global) {
72
-                // let's attempt to get the GRP_ID for this combo IF GRP_ID is empty.
73
-                if (empty($GRP_ID)) {
74
-                    $GRP_ID = EEM_Message_Template_Group::instance()->get_one(
75
-                        array(
76
-                            array(
77
-                                'MTP_messenger'    => $messenger,
78
-                                'MTP_message_type' => $message_type,
79
-                                'MTP_is_global'    => true,
80
-                            ),
81
-                        )
82
-                    );
83
-                    $GRP_ID = $GRP_ID instanceof EE_Message_Template_Group ? $GRP_ID->ID() : 0;
84
-                }
85
-                // First let's determine if we already HAVE global templates for this messenger and message_type combination.
86
-                //  If we do then NO generation!!
87
-                if (EEH_MSG_Template::already_generated($messenger, $message_type, $GRP_ID)) {
88
-                    $templates[] = array(
89
-                        'GRP_ID' => $GRP_ID,
90
-                        'MTP_context' => '',
91
-                    );
92
-                    // we already have generated templates for this so let's go to the next message type.
93
-                    continue;
94
-                }
95
-            }
96
-            $new_message_template_group = EEH_MSG_Template::create_new_templates($messenger, $message_type, $GRP_ID, $global);
97
-
98
-            if (! $new_message_template_group) {
99
-                continue;
100
-            }
101
-            $templates[] = $new_message_template_group;
102
-        }
103
-
104
-        return $templates;
105
-    }
106
-
107
-
108
-    /**
109
-     * The purpose of this method is to determine if there are already generated templates in the database for the
110
-     * given variables.
111
-     *
112
-     * @param string $messenger    messenger
113
-     * @param string $message_type message type
114
-     * @param int    $GRP_ID       GRP ID ( if a custom template) (if not provided then we're just doing global
115
-     *                             template check)
116
-     * @return bool                true = generated, false = hasn't been generated.
117
-     * @throws EE_Error
118
-     */
119
-    public static function already_generated($messenger, $message_type, $GRP_ID = 0)
120
-    {
121
-        EEH_MSG_Template::_set_autoloader();
122
-        // what method we use depends on whether we have an GRP_ID or not
123
-        $count = empty($GRP_ID)
124
-            ? EEM_Message_Template::instance()->count(
125
-                array(
126
-                    array(
127
-                        'Message_Template_Group.MTP_messenger'    => $messenger,
128
-                        'Message_Template_Group.MTP_message_type' => $message_type,
129
-                        'Message_Template_Group.MTP_is_global'    => true
130
-                    )
131
-                )
132
-            )
133
-            : EEM_Message_Template::instance()->count(array( array( 'GRP_ID' => $GRP_ID ) ));
134
-
135
-        return $count > 0;
136
-    }
137
-
138
-
139
-    /**
140
-     * Updates all message templates matching the incoming messengers and message types to active status.
141
-     *
142
-     * @static
143
-     * @param array $messenger_names    Messenger slug
144
-     * @param array $message_type_names Message type slug
145
-     * @return  int                         count of updated records.
146
-     * @throws EE_Error
147
-     */
148
-    public static function update_to_active($messenger_names, $message_type_names)
149
-    {
150
-        $messenger_names = is_array($messenger_names) ? $messenger_names : array( $messenger_names );
151
-        $message_type_names = is_array($message_type_names) ? $message_type_names : array( $message_type_names );
152
-        return EEM_Message_Template_Group::instance()->update(
153
-            array( 'MTP_is_active' => 1 ),
154
-            array(
155
-                array(
156
-                    'MTP_messenger'     => array( 'IN', $messenger_names ),
157
-                    'MTP_message_type'  => array( 'IN', $message_type_names )
158
-                )
159
-            )
160
-        );
161
-    }
162
-
163
-
164
-    /**
165
-     * Updates all message template groups matching the incoming arguments to inactive status.
166
-     *
167
-     * @static
168
-     * @param array $messenger_names    The messenger slugs.
169
-     *                                  If empty then all templates matching the message types are marked inactive.
170
-     *                                  Otherwise only templates matching the messengers and message types.
171
-     * @param array $message_type_names The message type slugs.
172
-     *                                  If empty then all templates matching the messengers are marked inactive.
173
-     *                                  Otherwise only templates matching the messengers and message types.
174
-     *
175
-     * @return int  count of updated records.
176
-     * @throws EE_Error
177
-     */
178
-    public static function update_to_inactive($messenger_names = array(), $message_type_names = array())
179
-    {
180
-        return EEM_Message_Template_Group::instance()->deactivate_message_template_groups_for(
181
-            $messenger_names,
182
-            $message_type_names
183
-        );
184
-    }
185
-
186
-
187
-    /**
188
-     * The purpose of this function is to return all installed message objects
189
-     * (messengers and message type regardless of whether they are ACTIVE or not)
190
-     *
191
-     * @param string $type
192
-     * @return array array consisting of installed messenger objects and installed message type objects.
193
-     * @throws EE_Error
194
-     * @throws ReflectionException
195
-     * @deprecated 4.9.0
196
-     * @static
197
-     */
198
-    public static function get_installed_message_objects($type = 'all')
199
-    {
200
-        self::_set_autoloader();
201
-        $message_resource_manager = EE_Registry::instance()->load_lib('Message_Resource_Manager');
202
-        return array(
203
-            'messenger' => $message_resource_manager->installed_messengers(),
204
-            'message_type' => $message_resource_manager->installed_message_types()
205
-        );
206
-    }
207
-
208
-
209
-    /**
210
-     * This will return an array of shortcodes => labels from the
211
-     * messenger and message_type objects associated with this
212
-     * template.
213
-     *
214
-     * @param string $message_type
215
-     * @param string $messenger
216
-     * @param array  $fields                        What fields we're returning valid shortcodes for.
217
-     *                                              If empty then we assume all fields are to be returned. Optional.
218
-     * @param string $context                       What context we're going to return shortcodes for. Optional.
219
-     * @param bool   $merged                        If TRUE then we don't return shortcodes indexed by field,
220
-     *                                              but instead an array of the unique shortcodes for all the given (
221
-     *                                              or all) fields. Optional.
222
-     * @return array                                an array of shortcodes in the format
223
-     *                                              array( '[shortcode] => 'label')
224
-     *                                              OR
225
-     *                                              FALSE if no shortcodes found.
226
-     * @throws ReflectionException
227
-     * @throws EE_Error*@since 4.3.0
228
-     *
229
-     */
230
-    public static function get_shortcodes(
231
-        $message_type,
232
-        $messenger,
233
-        $fields = array(),
234
-        $context = 'admin',
235
-        $merged = false
236
-    ) {
237
-        $messenger_name = str_replace(' ', '_', ucwords(str_replace('_', ' ', $messenger)));
238
-        $mt_name = str_replace(' ', '_', ucwords(str_replace('_', ' ', $message_type)));
239
-        /** @var EE_Message_Resource_Manager $message_resource_manager */
240
-        $message_resource_manager = EE_Registry::instance()->load_lib('Message_Resource_Manager');
241
-        // convert slug to object
242
-        $messenger = $message_resource_manager->get_messenger($messenger);
243
-
244
-        // if messenger isn't a EE_messenger resource then bail.
245
-        if (! $messenger instanceof EE_messenger) {
246
-            return array();
247
-        }
248
-
249
-        // validate class for getting our list of shortcodes
250
-        $classname = 'EE_Messages_' . $messenger_name . '_' . $mt_name . '_Validator';
251
-        if (! class_exists($classname)) {
252
-            $msg[] = esc_html__('The Validator class was unable to load', 'event_espresso');
253
-            $msg[] = sprintf(
254
-                esc_html__('The class name compiled was %s. Please check and make sure the spelling and case is correct for the class name and that there is an autoloader in place for this class', 'event_espresso'),
255
-                $classname
256
-            );
257
-            throw new EE_Error(implode('||', $msg));
258
-        }
259
-
260
-        /** @type EE_Messages_Validator $_VLD */
261
-        $_VLD = new $classname(array(), $context);
262
-        $valid_shortcodes = $_VLD->get_validators();
263
-
264
-        // let's make sure we're only getting the shortcode part of the validators
265
-        $shortcodes = array();
266
-        foreach ($valid_shortcodes as $field => $validators) {
267
-            $shortcodes[ $field ] = $validators['shortcodes'];
268
-        }
269
-        $valid_shortcodes = $shortcodes;
270
-
271
-        // if not all fields let's make sure we ONLY include the shortcodes for the specified fields.
272
-        if (! empty($fields)) {
273
-            $specified_shortcodes = array();
274
-            foreach ($fields as $field) {
275
-                if (isset($valid_shortcodes[ $field ])) {
276
-                    $specified_shortcodes[ $field ] = $valid_shortcodes[ $field ];
277
-                }
278
-            }
279
-            $valid_shortcodes = $specified_shortcodes;
280
-        }
281
-
282
-        // if not merged then let's replace the fields with the localized fields
283
-        if (! $merged) {
284
-            // let's get all the fields for the set messenger so that we can get the localized label and use that in the returned array.
285
-            $field_settings = $messenger->get_template_fields();
286
-            $localized = array();
287
-            foreach ($valid_shortcodes as $field => $shortcodes) {
288
-                // get localized field label
289
-                if (isset($field_settings[ $field ])) {
290
-                    // possible that this is used as a main field.
291
-                    if (empty($field_settings[ $field ])) {
292
-                        if (isset($field_settings['extra'][ $field ])) {
293
-                            $_field = $field_settings['extra'][ $field ]['main']['label'];
294
-                        } else {
295
-                            $_field = $field;
296
-                        }
297
-                    } else {
298
-                        $_field = $field_settings[ $field ]['label'];
299
-                    }
300
-                } elseif (isset($field_settings['extra'])) {
301
-                    // loop through extra "main fields" and see if any of their children have our field
302
-                    foreach ($field_settings['extra'] as $fields) {
303
-                        if (isset($fields[ $field ])) {
304
-                            $_field = $fields[ $field ]['label'];
305
-                        } else {
306
-                            $_field = $field;
307
-                        }
308
-                    }
309
-                } else {
310
-                    $_field = $field;
311
-                }
312
-                if (isset($_field)) {
313
-                    $localized[ (string) $_field ] = $shortcodes;
314
-                }
315
-            }
316
-            $valid_shortcodes = $localized;
317
-        }
318
-
319
-        // if $merged then let's merge all the shortcodes into one list NOT indexed by field.
320
-        if ($merged) {
321
-            $merged_codes = array();
322
-            foreach ($valid_shortcodes as $shortcode) {
323
-                foreach ($shortcode as $code => $label) {
324
-                    if (isset($merged_codes[ $code ])) {
325
-                        continue;
326
-                    } else {
327
-                        $merged_codes[ $code ] = $label;
328
-                    }
329
-                }
330
-            }
331
-            $valid_shortcodes = $merged_codes;
332
-        }
333
-
334
-        return $valid_shortcodes;
335
-    }
336
-
337
-
338
-    /**
339
-     * Get Messenger object.
340
-     *
341
-     * @param string $messenger messenger slug for the messenger object we want to retrieve.
342
-     * @return EE_messenger
343
-     * @throws ReflectionException
344
-     * @throws EE_Error*@since 4.3.0
345
-     * @deprecated 4.9.0
346
-     */
347
-    public static function messenger_obj($messenger)
348
-    {
349
-        /** @type EE_Message_Resource_Manager $Message_Resource_Manager */
350
-        $Message_Resource_Manager = EE_Registry::instance()->load_lib('Message_Resource_Manager');
351
-        return $Message_Resource_Manager->get_messenger($messenger);
352
-    }
353
-
354
-
355
-    /**
356
-     * get Message type object
357
-     *
358
-     * @param string $message_type the slug for the message type object to retrieve
359
-     * @return EE_message_type
360
-     * @throws ReflectionException
361
-     * @throws EE_Error*@since 4.3.0
362
-     * @deprecated 4.9.0
363
-     */
364
-    public static function message_type_obj($message_type)
365
-    {
366
-        /** @type EE_Message_Resource_Manager $Message_Resource_Manager */
367
-        $Message_Resource_Manager = EE_Registry::instance()->load_lib('Message_Resource_Manager');
368
-        return $Message_Resource_Manager->get_message_type($message_type);
369
-    }
370
-
371
-
372
-    /**
373
-     * Given a message_type slug, will return whether that message type is active in the system or not.
374
-     *
375
-     * @since    4.3.0
376
-     * @param string $message_type message type to check for.
377
-     * @return boolean
378
-     * @throws EE_Error
379
-     * @throws ReflectionException
380
-     */
381
-    public static function is_mt_active($message_type)
382
-    {
383
-        /** @type EE_Message_Resource_Manager $Message_Resource_Manager */
384
-        $Message_Resource_Manager = EE_Registry::instance()->load_lib('Message_Resource_Manager');
385
-        $active_mts = $Message_Resource_Manager->list_of_active_message_types();
386
-        return in_array($message_type, $active_mts);
387
-    }
388
-
389
-
390
-    /**
391
-     * Given a messenger slug, will return whether that messenger is active in the system or not.
392
-     *
393
-     * @since    4.3.0
394
-     *
395
-     * @param string $messenger slug for messenger to check.
396
-     * @return boolean
397
-     * @throws EE_Error
398
-     * @throws ReflectionException
399
-     */
400
-    public static function is_messenger_active($messenger)
401
-    {
402
-        /** @type EE_Message_Resource_Manager $Message_Resource_Manager */
403
-        $Message_Resource_Manager = EE_Registry::instance()->load_lib('Message_Resource_Manager');
404
-        $active_messenger = $Message_Resource_Manager->get_active_messenger($messenger);
405
-        return $active_messenger instanceof EE_messenger;
406
-    }
407
-
408
-
409
-    /**
410
-     * Used to return active messengers array stored in the wp options table.
411
-     * If no value is present in the option then an empty array is returned.
412
-     *
413
-     * @deprecated 4.9
414
-     * @since      4.3.1
415
-     *
416
-     * @return array
417
-     * @throws EE_Error
418
-     * @throws ReflectionException
419
-     */
420
-    public static function get_active_messengers_in_db()
421
-    {
422
-        EE_Error::doing_it_wrong(
423
-            __METHOD__,
424
-            esc_html__('Please use EE_Message_Resource_Manager::get_active_messengers_option() instead.', 'event_espresso'),
425
-            '4.9.0'
426
-        );
427
-        /** @var EE_Message_Resource_Manager $Message_Resource_Manager */
428
-        $Message_Resource_Manager = EE_Registry::instance()->load_lib('Message_Resource_Manager');
429
-        return $Message_Resource_Manager->get_active_messengers_option();
430
-    }
431
-
432
-
433
-    /**
434
-     * Used to update the active messengers array stored in the wp options table.
435
-     *
436
-     * @since      4.3.1
437
-     * @deprecated 4.9.0
438
-     *
439
-     * @param array $data_to_save Incoming data to save.
440
-     *
441
-     * @return bool FALSE if not updated, TRUE if updated.
442
-     * @throws EE_Error
443
-     * @throws ReflectionException
444
-     */
445
-    public static function update_active_messengers_in_db($data_to_save)
446
-    {
447
-        EE_Error::doing_it_wrong(
448
-            __METHOD__,
449
-            esc_html__('Please use EE_Message_Resource_Manager::update_active_messengers_option() instead.', 'event_espresso'),
450
-            '4.9.0'
451
-        );
452
-        /** @var EE_Message_Resource_Manager $Message_Resource_Manager */
453
-        $Message_Resource_Manager = EE_Registry::instance()->load_lib('Message_Resource_Manager');
454
-        return $Message_Resource_Manager->update_active_messengers_option($data_to_save);
455
-    }
456
-
457
-
458
-    /**
459
-     * This does some validation of incoming params, determines what type of url is being prepped and returns the
460
-     * appropriate url trigger
461
-     *
462
-     * @param EE_message_type $message_type
463
-     * @param EE_Message $message
464
-     * @param EE_Registration | null $registration  The registration object must be included if this
465
-     *                                              is going to be a registration trigger url.
466
-     * @param string $sending_messenger             The (optional) sending messenger for the url.
467
-     *
468
-     * @return string
469
-     * @throws EE_Error
470
-     */
471
-    public static function get_url_trigger(
472
-        EE_message_type $message_type,
473
-        EE_Message $message,
474
-        $registration = null,
475
-        $sending_messenger = ''
476
-    ) {
477
-        // first determine if the url can be to the EE_Message object.
478
-        if (! $message_type->always_generate()) {
479
-            return EEH_MSG_Template::generate_browser_trigger($message);
480
-        }
481
-
482
-        // if $registration object is not valid then exit early because there's nothing that can be generated.
483
-        if (! $registration instanceof EE_Registration) {
484
-            throw new EE_Error(
485
-                esc_html__('Incoming value for registration is not a valid EE_Registration object.', 'event_espresso')
486
-            );
487
-        }
488
-
489
-        // validate given context
490
-        $contexts = $message_type->get_contexts();
491
-        if ($message->context() !== '' && ! isset($contexts[ $message->context() ])) {
492
-            throw new EE_Error(
493
-                sprintf(
494
-                    esc_html__('The context %s is not a valid context for %s.', 'event_espresso'),
495
-                    $message->context(),
496
-                    get_class($message_type)
497
-                )
498
-            );
499
-        }
500
-
501
-        // valid sending messenger but only if sending messenger set.  Otherwise generating messenger is used.
502
-        if (! empty($sending_messenger)) {
503
-            $with_messengers = $message_type->with_messengers();
504
-            if (
505
-                ! isset($with_messengers[ $message->messenger() ])
506
-                 || ! in_array($sending_messenger, $with_messengers[ $message->messenger() ])
507
-            ) {
508
-                throw new EE_Error(
509
-                    sprintf(
510
-                        esc_html__(
511
-                            'The given sending messenger string (%1$s) does not match a valid sending messenger with the %2$s.  If this is incorrect, make sure that the message type has defined this messenger as a sending messenger in its $_with_messengers array.',
512
-                            'event_espresso'
513
-                        ),
514
-                        $sending_messenger,
515
-                        get_class($message_type)
516
-                    )
517
-                );
518
-            }
519
-        } else {
520
-            $sending_messenger = $message->messenger();
521
-        }
522
-        return EEH_MSG_Template::generate_url_trigger(
523
-            $sending_messenger,
524
-            $message->messenger(),
525
-            $message->context(),
526
-            $message->message_type(),
527
-            $registration,
528
-            $message->GRP_ID()
529
-        );
530
-    }
531
-
532
-
533
-    /**
534
-     * This returns the url for triggering a in browser view of a specific EE_Message object.
535
-     * @param EE_Message $message
536
-     * @return string.
537
-     */
538
-    public static function generate_browser_trigger(EE_Message $message)
539
-    {
540
-        $query_args = array(
541
-            'ee' => 'msg_browser_trigger',
542
-            'token' => $message->MSG_token()
543
-        );
544
-        return apply_filters(
545
-            'FHEE__EEH_MSG_Template__generate_browser_trigger',
546
-            add_query_arg($query_args, site_url()),
547
-            $message
548
-        );
549
-    }
550
-
551
-
552
-
553
-
554
-
555
-
556
-    /**
557
-     * This returns the url for triggering an in browser view of the error saved on the incoming message object.
558
-     * @param EE_Message $message
559
-     * @return string
560
-     */
561
-    public static function generate_error_display_trigger(EE_Message $message)
562
-    {
563
-        return apply_filters(
564
-            'FHEE__EEH_MSG_Template__generate_error_display_trigger',
565
-            add_query_arg(
566
-                array(
567
-                    'ee' => 'msg_browser_error_trigger',
568
-                    'token' => $message->MSG_token()
569
-                ),
570
-                site_url()
571
-            ),
572
-            $message
573
-        );
574
-    }
575
-
576
-
577
-    /**
578
-     * This generates a url trigger for the msg_url_trigger route using the given arguments
579
-     *
580
-     * @param string          $sending_messenger      The sending messenger slug.
581
-     * @param string          $generating_messenger   The generating messenger slug.
582
-     * @param string          $context                The context for the template.
583
-     * @param string          $message_type           The message type slug
584
-     * @param EE_Registration $registration
585
-     * @param integer         $message_template_group id   The EE_Message_Template_Group ID for the template.
586
-     * @param integer         $data_id                The id to the EE_Base_Class for getting the data used by the
587
-     *                                                trigger.
588
-     * @return string          The generated url.
589
-     * @throws EE_Error
590
-     */
591
-    public static function generate_url_trigger(
592
-        $sending_messenger,
593
-        $generating_messenger,
594
-        $context,
595
-        $message_type,
596
-        EE_Registration $registration,
597
-        $message_template_group,
598
-        $data_id = 0
599
-    ) {
600
-        $query_args = array(
601
-            'ee' => 'msg_url_trigger',
602
-            'snd_msgr' => $sending_messenger,
603
-            'gen_msgr' => $generating_messenger,
604
-            'message_type' => $message_type,
605
-            'context' => $context,
606
-            'token' => $registration->reg_url_link(),
607
-            'GRP_ID' => $message_template_group,
608
-            'id' => $data_id
609
-            );
610
-        $url = add_query_arg($query_args, get_home_url());
611
-
612
-        // made it here so now we can just get the url and filter it.  Filtered globally and by message type.
613
-        return apply_filters(
614
-            'FHEE__EEH_MSG_Template__generate_url_trigger',
615
-            $url,
616
-            $sending_messenger,
617
-            $generating_messenger,
618
-            $context,
619
-            $message_type,
620
-            $registration,
621
-            $message_template_group,
622
-            $data_id
623
-        );
624
-    }
625
-
626
-
627
-
628
-
629
-    /**
630
-     * Return the specific css for the action icon given.
631
-     *
632
-     * @param string $type  What action to return.
633
-     * @return string[]
634
-     * @since 4.9.0
635
-     */
636
-    public static function get_message_action_icon($type)
637
-    {
638
-        $action_icons = self::get_message_action_icons();
639
-        return isset($action_icons[ $type ]) ? $action_icons[ $type ] : [];
640
-    }
641
-
642
-
643
-    /**
644
-     * This is used for retrieving the css classes used for the icons representing message actions.
645
-     *
646
-     * @since 4.9.0
647
-     *
648
-     * @return array
649
-     */
650
-    public static function get_message_action_icons()
651
-    {
652
-        return apply_filters(
653
-            'FHEE__EEH_MSG_Template__message_action_icons',
654
-            array(
655
-                'view' => array(
656
-                    'label' => esc_html__('View Message', 'event_espresso'),
657
-                    'css_class' => 'dashicons dashicons-welcome-view-site',
658
-                ),
659
-                'error' => array(
660
-                    'label' => esc_html__('View Error Message', 'event_espresso'),
661
-                    'css_class' => 'dashicons dashicons-info',
662
-                ),
663
-                'see_notifications_for' => array(
664
-                    'label' => esc_html__('View Related Messages', 'event_espresso'),
665
-                    'css_class' => 'dashicons dashicons-megaphone',
666
-                ),
667
-                'generate_now' => array(
668
-                    'label' => esc_html__('Generate the message now.', 'event_espresso'),
669
-                    'css_class' => 'dashicons dashicons-admin-tools',
670
-                ),
671
-                'send_now' => array(
672
-                    'label' => esc_html__('Send Immediately', 'event_espresso'),
673
-                    'css_class' => 'dashicons dashicons-controls-forward',
674
-                ),
675
-                'queue_for_resending' => array(
676
-                    'label' => esc_html__('Queue for Resending', 'event_espresso'),
677
-                    'css_class' => 'dashicons dashicons-controls-repeat',
678
-                ),
679
-                'view_transaction' => array(
680
-                    'label' => esc_html__('View related Transaction', 'event_espresso'),
681
-                    'css_class' => 'dashicons dashicons-cart',
682
-                )
683
-            )
684
-        );
685
-    }
686
-
687
-
688
-    /**
689
-     * This returns the url for a given action related to EE_Message.
690
-     *
691
-     * @param string     $type         What type of action to return the url for.
692
-     * @param EE_Message $message      Required for generating the correct url for some types.
693
-     * @param array      $query_params Any additional query params to be included with the generated url.
694
-     *
695
-     * @return string
696
-     * @throws EE_Error
697
-     * @throws ReflectionException
698
-     * @since 4.9.0
699
-     *
700
-     */
701
-    public static function get_message_action_url($type, EE_Message $message = null, $query_params = array())
702
-    {
703
-        $action_urls = self::get_message_action_urls($message, $query_params);
704
-        return isset($action_urls[ $type ])  ? $action_urls[ $type ] : '';
705
-    }
706
-
707
-
708
-    /**
709
-     * This returns all the current urls for EE_Message actions.
710
-     *
711
-     * @since 4.9.0
712
-     *
713
-     * @param EE_Message $message      The EE_Message object required to generate correct urls for some types.
714
-     * @param array      $query_params Any additional query_params to be included with the generated url.
715
-     *
716
-     * @return array
717
-     * @throws EE_Error
718
-     * @throws ReflectionException
719
-     */
720
-    public static function get_message_action_urls(EE_Message $message = null, $query_params = array())
721
-    {
722
-        EE_Registry::instance()->load_helper('URL');
723
-        // if $message is not an instance of EE_Message then let's just do a dummy.
724
-        $message = empty($message) ? EE_Message_Factory::create() : $message;
725
-        $action_urls =  apply_filters(
726
-            'FHEE__EEH_MSG_Template__get_message_action_url',
727
-            array(
728
-                'view' => EEH_MSG_Template::generate_browser_trigger($message),
729
-                'error' => EEH_MSG_Template::generate_error_display_trigger($message),
730
-                'see_notifications_for' => EEH_URL::add_query_args_and_nonce(
731
-                    array_merge(
732
-                        array(
733
-                            'page' => 'espresso_messages',
734
-                            'action' => 'default',
735
-                            'filterby' => 1,
736
-                        ),
737
-                        $query_params
738
-                    ),
739
-                    admin_url('admin.php')
740
-                ),
741
-                'generate_now' => EEH_URL::add_query_args_and_nonce(
742
-                    array(
743
-                        'page' => 'espresso_messages',
744
-                        'action' => 'generate_now',
745
-                        'MSG_ID' => $message->ID()
746
-                    ),
747
-                    admin_url('admin.php')
748
-                ),
749
-                'send_now' => EEH_URL::add_query_args_and_nonce(
750
-                    array(
751
-                        'page' => 'espresso_messages',
752
-                        'action' => 'send_now',
753
-                        'MSG_ID' => $message->ID()
754
-                    ),
755
-                    admin_url('admin.php')
756
-                ),
757
-                'queue_for_resending' => EEH_URL::add_query_args_and_nonce(
758
-                    array(
759
-                        'page' => 'espresso_messages',
760
-                        'action' => 'queue_for_resending',
761
-                        'MSG_ID' => $message->ID()
762
-                    ),
763
-                    admin_url('admin.php')
764
-                ),
765
-            )
766
-        );
767
-        if (
768
-            $message->TXN_ID() > 0
769
-            && EE_Registry::instance()->CAP->current_user_can(
770
-                'ee_read_transaction',
771
-                'espresso_transactions_default',
772
-                $message->TXN_ID()
773
-            )
774
-        ) {
775
-            $action_urls['view_transaction'] = EEH_URL::add_query_args_and_nonce(
776
-                array(
777
-                    'page' => 'espresso_transactions',
778
-                    'action' => 'view_transaction',
779
-                    'TXN_ID' => $message->TXN_ID()
780
-                ),
781
-                admin_url('admin.php')
782
-            );
783
-        } else {
784
-            $action_urls['view_transaction'] = '';
785
-        }
786
-        return $action_urls;
787
-    }
788
-
789
-
790
-    /**
791
-     * This returns a generated link html including the icon used for the action link for EE_Message actions.
792
-     *
793
-     * @param string          $type         What type of action the link is for (if invalid type is passed in then an
794
-     *                                      empty string is returned)
795
-     * @param EE_Message|null $message      The EE_Message object (required for some actions to generate correctly)
796
-     * @param array           $query_params Any extra query params to include in the generated link.
797
-     *
798
-     * @return string
799
-     * @throws EE_Error
800
-     * @throws ReflectionException
801
-     * @since 4.9.0
802
-     *
803
-     */
804
-    public static function get_message_action_link($type, EE_Message $message = null, $query_params = array())
805
-    {
806
-        $url = EEH_MSG_Template::get_message_action_url($type, $message, $query_params);
807
-        $icon_css = EEH_MSG_Template::get_message_action_icon($type);
808
-        $title = isset($icon_css['label']) ? 'title="' . $icon_css['label'] . '"' : '';
809
-
810
-        if (empty($url) || empty($icon_css) || ! isset($icon_css['css_class'])) {
811
-            return '';
812
-        }
813
-
814
-        $icon_css['css_class'] .= esc_attr(
815
-            apply_filters(
816
-                'FHEE__EEH_MSG_Template__get_message_action_link__icon_css_class',
817
-                ' js-ee-message-action-link ee-message-action-link-' . $type,
818
-                $type,
819
-                $message,
820
-                $query_params
821
-            )
822
-        );
823
-
824
-        return '<a href="' . $url . '" ' . $title . '><span class="' . esc_attr($icon_css['css_class']) . '"></span></a>';
825
-    }
826
-
827
-
828
-
829
-
830
-
831
-    /**
832
-     * This returns an array with keys as reg statuses and values as the corresponding message type slug (filtered).
833
-     *
834
-     * @since 4.9.0
835
-     * @return array
836
-     */
837
-    public static function reg_status_to_message_type_array()
838
-    {
839
-        return (array) apply_filters(
840
-            'FHEE__EEH_MSG_Template__reg_status_to_message_type_array',
841
-            array(
842
-                EEM_Registration::status_id_approved => 'registration',
843
-                EEM_Registration::status_id_pending_payment => 'pending_approval',
844
-                EEM_Registration::status_id_not_approved => 'not_approved_registration',
845
-                EEM_Registration::status_id_cancelled => 'cancelled_registration',
846
-                EEM_Registration::status_id_declined => 'declined_registration'
847
-            )
848
-        );
849
-    }
850
-
851
-
852
-
853
-
854
-    /**
855
-     * This returns the corresponding registration message type slug to the given reg status. If there isn't a
856
-     * match, then returns an empty string.
857
-     *
858
-     * @since 4.9.0
859
-     * @param $reg_status
860
-     * @return string
861
-     */
862
-    public static function convert_reg_status_to_message_type($reg_status)
863
-    {
864
-        $reg_status_array = self::reg_status_to_message_type_array();
865
-        return isset($reg_status_array[ $reg_status ]) ? $reg_status_array[ $reg_status ] : '';
866
-    }
867
-
868
-
869
-    /**
870
-     * This returns an array with keys as payment stati and values as the corresponding message type slug (filtered).
871
-     *
872
-     * @since 4.9.0
873
-     * @return array
874
-     */
875
-    public static function payment_status_to_message_type_array()
876
-    {
877
-        return (array) apply_filters(
878
-            'FHEE__EEH_MSG_Template__payment_status_to_message_type_array',
879
-            array(
880
-                EEM_Payment::status_id_approved => 'payment',
881
-                EEM_Payment::status_id_pending => 'payment_pending',
882
-                EEM_Payment::status_id_cancelled => 'payment_cancelled',
883
-                EEM_Payment::status_id_declined => 'payment_declined',
884
-                EEM_Payment::status_id_failed => 'payment_failed'
885
-            )
886
-        );
887
-    }
888
-
889
-
890
-
891
-
892
-    /**
893
-     * This returns the corresponding payment message type slug to the given payment status. If there isn't a match then
894
-     * an empty string is returned
895
-     *
896
-     * @since 4.9.0
897
-     * @param $payment_status
898
-     * @return string
899
-     */
900
-    public static function convert_payment_status_to_message_type($payment_status)
901
-    {
902
-        $payment_status_array = self::payment_status_to_message_type_array();
903
-        return isset($payment_status_array[ $payment_status ]) ? $payment_status_array[ $payment_status ] : '';
904
-    }
905
-
906
-
907
-    /**
908
-     * This is used to retrieve the template pack for the given name.
909
-     *
910
-     * @param string $template_pack_name  should match the set `dbref` property value on the EE_Messages_Template_Pack.
911
-     *
912
-     * @return EE_Messages_Template_Pack
913
-     */
914
-    public static function get_template_pack($template_pack_name)
915
-    {
916
-        if (! self::$_template_pack_collection instanceof EE_Object_Collection) {
917
-            self::$_template_pack_collection = new EE_Messages_Template_Pack_Collection();
918
-        }
919
-
920
-        // first see if in collection already
921
-        $template_pack = self::$_template_pack_collection->get_by_name($template_pack_name);
922
-
923
-        if ($template_pack instanceof EE_Messages_Template_Pack) {
924
-            return $template_pack;
925
-        }
926
-
927
-        // nope...let's get it.
928
-        // not set yet so let's attempt to get it.
929
-        $pack_class_name = 'EE_Messages_Template_Pack_' . str_replace(
930
-            ' ',
931
-            '_',
932
-            ucwords(
933
-                str_replace('_', ' ', $template_pack_name)
934
-            )
935
-        );
936
-        if (! class_exists($pack_class_name) && $template_pack_name !== 'default') {
937
-            return self::get_template_pack('default');
938
-        } else {
939
-            $template_pack = new $pack_class_name();
940
-            self::$_template_pack_collection->add($template_pack);
941
-            return $template_pack;
942
-        }
943
-    }
944
-
945
-
946
-
947
-
948
-    /**
949
-     * Globs template packs installed in core and returns the template pack collection with all installed template packs
950
-     * in it.
951
-     *
952
-     * @since 4.9.0
953
-     *
954
-     * @return EE_Messages_Template_Pack_Collection
955
-     */
956
-    public static function get_template_pack_collection()
957
-    {
958
-        $new_collection = false;
959
-        if (! self::$_template_pack_collection instanceof EE_Messages_Template_Pack_Collection) {
960
-            self::$_template_pack_collection = new EE_Messages_Template_Pack_Collection();
961
-            $new_collection = true;
962
-        }
963
-
964
-        // glob the defaults directory for messages
965
-        $templates = glob(EE_LIBRARIES . 'messages/defaults/*', GLOB_ONLYDIR);
966
-        foreach ($templates as $template_path) {
967
-            // grab folder name
968
-            $template = basename($template_path);
969
-
970
-            if (! $new_collection) {
971
-                // already have it?
972
-                if (self::$_template_pack_collection->get_by_name($template) instanceof EE_Messages_Template_Pack) {
973
-                    continue;
974
-                }
975
-            }
976
-
977
-            // setup classname.
978
-            $template_pack_class_name = 'EE_Messages_Template_Pack_' . str_replace(
979
-                ' ',
980
-                '_',
981
-                ucwords(
982
-                    str_replace(
983
-                        '_',
984
-                        ' ',
985
-                        $template
986
-                    )
987
-                )
988
-            );
989
-            if (! class_exists($template_pack_class_name)) {
990
-                continue;
991
-            }
992
-            self::$_template_pack_collection->add(new $template_pack_class_name());
993
-        }
994
-
995
-        /**
996
-         * Filter for plugins to add in any additional template packs
997
-         * Note the filter name here is for backward compat, this used to be found in EED_Messages.
998
-         */
999
-        $additional_template_packs = apply_filters('FHEE__EED_Messages__get_template_packs__template_packs', array());
1000
-        foreach ((array) $additional_template_packs as $template_pack) {
1001
-            if (
1002
-                self::$_template_pack_collection->get_by_name(
1003
-                    $template_pack->dbref
1004
-                ) instanceof EE_Messages_Template_Pack
1005
-            ) {
1006
-                continue;
1007
-            }
1008
-            self::$_template_pack_collection->add($template_pack);
1009
-        }
1010
-        return self::$_template_pack_collection;
1011
-    }
1012
-
1013
-
1014
-    /**
1015
-     * This is a wrapper for the protected _create_new_templates function
1016
-     *
1017
-     * @param string $messenger_name
1018
-     * @param string $message_type_name message type that the templates are being created for
1019
-     * @param int    $GRP_ID
1020
-     * @param bool   $global
1021
-     * @return array
1022
-     * @throws EE_Error
1023
-     * @throws ReflectionException
1024
-     */
1025
-    public static function create_new_templates($messenger_name, $message_type_name, $GRP_ID = 0, $global = false)
1026
-    {
1027
-        /** @type EE_Message_Resource_Manager $Message_Resource_Manager */
1028
-        $Message_Resource_Manager = EE_Registry::instance()->load_lib('Message_Resource_Manager');
1029
-        $messenger = $Message_Resource_Manager->valid_messenger($messenger_name);
1030
-        $message_type = $Message_Resource_Manager->valid_message_type($message_type_name);
1031
-        if (! EEH_MSG_Template::message_type_has_active_templates_for_messenger($messenger, $message_type, $global)) {
1032
-            return array();
1033
-        }
1034
-        // whew made it this far!  Okay, let's go ahead and create the templates then
1035
-        return EEH_MSG_Template::_create_new_templates($messenger, $message_type, $GRP_ID, $global);
1036
-    }
1037
-
1038
-
1039
-    /**
1040
-     * @param EE_messenger     $messenger
1041
-     * @param EE_message_type  $message_type
1042
-     * @param                  $GRP_ID
1043
-     * @param                  $global
1044
-     * @return array|mixed
1045
-     * @throws EE_Error
1046
-     * @throws ReflectionException
1047
-     */
1048
-    protected static function _create_new_templates(EE_messenger $messenger, EE_message_type $message_type, $GRP_ID, $global)
1049
-    {
1050
-        // if we're creating a custom template then we don't need to use the defaults class
1051
-        if (! $global) {
1052
-            return EEH_MSG_Template::_create_custom_template_group($messenger, $message_type, $GRP_ID);
1053
-        }
1054
-        /** @type EE_Messages_Template_Defaults $Message_Template_Defaults */
1055
-        $Message_Template_Defaults = EE_Registry::factory(
1056
-            'EE_Messages_Template_Defaults',
1057
-            array( $messenger, $message_type, $GRP_ID )
1058
-        );
1059
-        // generate templates
1060
-        $success = $Message_Template_Defaults->create_new_templates();
1061
-
1062
-        // if creating the template failed.  Then we should deactivate the related message_type for the messenger because
1063
-        // its not active if it doesn't have a template.  Note this is only happening for GLOBAL template creation
1064
-        // attempts.
1065
-        if (! $success) {
1066
-            /** @var EE_Message_Resource_Manager $message_resource_manager */
1067
-            $message_resource_manager = EE_Registry::instance()->load_lib('Message_Resource_Manager');
1068
-            $message_resource_manager->deactivate_message_type_for_messenger($message_type->name, $messenger->name);
1069
-        }
1070
-
1071
-        /**
1072
-         * $success is in an array in the following format
1073
-         * array(
1074
-         *    'GRP_ID' => $new_grp_id,
1075
-         *    'MTP_context' => $first_context_in_new_templates,
1076
-         * )
1077
-         */
1078
-        return $success;
1079
-    }
1080
-
1081
-
1082
-    /**
1083
-     * This creates a custom template using the incoming GRP_ID
1084
-     *
1085
-     * @param EE_messenger    $messenger
1086
-     * @param EE_message_type $message_type
1087
-     * @param int             $GRP_ID           GRP_ID for the template_group being used as the base
1088
-     * @return  array $success              This will be an array in the format:
1089
-     *                                          array(
1090
-     *                                          'GRP_ID' => $new_grp_id,
1091
-     *                                          'MTP_context' => $first_context_in_created_template
1092
-     *                                          )
1093
-     * @throws EE_Error
1094
-     * @throws ReflectionException
1095
-     * @access private
1096
-     */
1097
-    private static function _create_custom_template_group(EE_messenger $messenger, EE_message_type $message_type, $GRP_ID)
1098
-    {
1099
-        // defaults
1100
-        $success = array( 'GRP_ID' => null, 'MTP_context' => '' );
1101
-        // get the template group to use as a template from the db.  If $GRP_ID is empty then we'll assume the base will be the global template matching the messenger and message type.
1102
-        $Message_Template_Group = empty($GRP_ID)
1103
-            ? EEM_Message_Template_Group::instance()->get_one(
1104
-                array(
1105
-                    array(
1106
-                        'MTP_messenger'    => $messenger->name,
1107
-                        'MTP_message_type' => $message_type->name,
1108
-                        'MTP_is_global'    => true
1109
-                    )
1110
-                )
1111
-            )
1112
-            : EEM_Message_Template_Group::instance()->get_one_by_ID($GRP_ID);
1113
-        // if we don't have a mtg at this point then we need to bail.
1114
-        if (! $Message_Template_Group instanceof EE_Message_Template_Group) {
1115
-            EE_Error::add_error(
1116
-                sprintf(
1117
-                    esc_html__(
1118
-                        'Something went wrong with generating the custom template from this group id: %s.  This usually happens when there is no matching message template group in the db.',
1119
-                        'event_espresso'
1120
-                    ),
1121
-                    $GRP_ID
1122
-                ),
1123
-                __FILE__,
1124
-                __FUNCTION__,
1125
-                __LINE__
1126
-            );
1127
-            return $success;
1128
-        }
1129
-        // let's get all the related message_template objects for this group.
1130
-        $message_templates = $Message_Template_Group->message_templates();
1131
-        // now we have what we need to setup the new template
1132
-        $new_mtg = clone $Message_Template_Group;
1133
-        $new_mtg->set('GRP_ID', 0);
1134
-        $new_mtg->set('MTP_is_global', false);
1135
-
1136
-        /** @var RequestInterface $request */
1137
-        $request = LoaderFactory::getLoader()->getShared(RequestInterface::class);
1138
-        $template_name = $request->isAjax() && $request->requestParamIsSet('templateName')
1139
-            ? $request->getRequestParam('templateName')
1140
-            : esc_html__('New Custom Template', 'event_espresso');
1141
-        $template_description = $request->isAjax() && $request->requestParamIsSet('templateDescription')
1142
-            ? $request->getRequestParam('templateDescription')
1143
-            : sprintf(
1144
-                esc_html__(
1145
-                    'This is a custom template that was created for the %s messenger and %s message type.',
1146
-                    'event_espresso'
1147
-                ),
1148
-                $new_mtg->messenger_obj()->label['singular'],
1149
-                $new_mtg->message_type_obj()->label['singular']
1150
-            );
1151
-        $new_mtg->set('MTP_name', $template_name);
1152
-        $new_mtg->set('MTP_description', $template_description);
1153
-        // remove ALL relations on this template group so they don't get saved!
1154
-        $new_mtg->_remove_relations('Message_Template');
1155
-        $new_mtg->save();
1156
-        $success['GRP_ID'] = $new_mtg->ID();
1157
-        $success['template_name'] = $template_name;
1158
-        // add new message templates and add relation to.
1159
-        foreach ($message_templates as $message_template) {
1160
-            if (! $message_template instanceof EE_Message_Template) {
1161
-                continue;
1162
-            }
1163
-            $new_message_template = clone $message_template;
1164
-            $new_message_template->set('MTP_ID', 0);
1165
-            $new_message_template->set('GRP_ID', $new_mtg->ID()); // relation
1166
-            $new_message_template->save();
1167
-            if (empty($success['MTP_context']) && $new_message_template->get('MTP_context') !== 'admin') {
1168
-                $success['MTP_context'] = $new_message_template->get('MTP_context');
1169
-            }
1170
-        }
1171
-        return $success;
1172
-    }
1173
-
1174
-
1175
-    /**
1176
-     * message_type_has_active_templates_for_messenger
1177
-     *
1178
-     * @param EE_messenger    $messenger
1179
-     * @param EE_message_type $message_type
1180
-     * @param bool            $global
1181
-     * @return bool
1182
-     * @throws EE_Error
1183
-     */
1184
-    public static function message_type_has_active_templates_for_messenger(
1185
-        EE_messenger $messenger,
1186
-        EE_message_type $message_type,
1187
-        $global = false
1188
-    ) {
1189
-        // is given message_type valid for given messenger (if this is not a global save)
1190
-        if ($global) {
1191
-            return true;
1192
-        }
1193
-        $active_templates = EEM_Message_Template_Group::instance()->count(
1194
-            array(
1195
-                array(
1196
-                    'MTP_is_active'    => true,
1197
-                    'MTP_messenger'    => $messenger->name,
1198
-                    'MTP_message_type' => $message_type->name
1199
-                )
1200
-            )
1201
-        );
1202
-        if ($active_templates > 0) {
1203
-            return true;
1204
-        }
1205
-        EE_Error::add_error(
1206
-            sprintf(
1207
-                esc_html__(
1208
-                    'The %1$s message type is not registered with the %2$s messenger. Please visit the Messenger activation page to assign this message type first if you want to use it.',
1209
-                    'event_espresso'
1210
-                ),
1211
-                $message_type->name,
1212
-                $messenger->name
1213
-            ),
1214
-            __FILE__,
1215
-            __FUNCTION__,
1216
-            __LINE__
1217
-        );
1218
-        return false;
1219
-    }
1220
-
1221
-
1222
-    /**
1223
-     * get_fields
1224
-     * This takes a given messenger and message type and returns all the template fields indexed by context (and with field type).
1225
-     *
1226
-     * @param string $messenger_name    name of EE_messenger
1227
-     * @param string $message_type_name name of EE_message_type
1228
-     * @return array
1229
-     * @throws EE_Error
1230
-     * @throws ReflectionException
1231
-     */
1232
-    public static function get_fields($messenger_name, $message_type_name)
1233
-    {
1234
-        $template_fields = array();
1235
-        /** @type EE_Message_Resource_Manager $Message_Resource_Manager */
1236
-        $Message_Resource_Manager = EE_Registry::instance()->load_lib('Message_Resource_Manager');
1237
-        $messenger = $Message_Resource_Manager->valid_messenger($messenger_name);
1238
-        $message_type = $Message_Resource_Manager->valid_message_type($message_type_name);
1239
-        if (! EEH_MSG_Template::message_type_has_active_templates_for_messenger($messenger, $message_type)) {
1240
-            return array();
1241
-        }
1242
-
1243
-        $excluded_fields_for_messenger = $message_type->excludedFieldsForMessenger($messenger_name);
1244
-
1245
-        // okay now let's assemble an array with the messenger template fields added to the message_type contexts.
1246
-        foreach ($message_type->get_contexts() as $context => $details) {
1247
-            foreach ($messenger->get_template_fields() as $field => $value) {
1248
-                if (in_array($field, $excluded_fields_for_messenger, true)) {
1249
-                    continue;
1250
-                }
1251
-                $template_fields[ $context ][ $field ] = $value;
1252
-            }
1253
-        }
1254
-        if (empty($template_fields)) {
1255
-            EE_Error::add_error(
1256
-                esc_html__('Something went wrong and we couldn\'t get any templates assembled', 'event_espresso'),
1257
-                __FILE__,
1258
-                __FUNCTION__,
1259
-                __LINE__
1260
-            );
1261
-            return array();
1262
-        }
1263
-        return $template_fields;
1264
-    }
16
+	/**
17
+	 * Holds a collection of EE_Message_Template_Pack objects.
18
+	 * @type EE_Messages_Template_Pack_Collection
19
+	 */
20
+	protected static $_template_pack_collection;
21
+
22
+
23
+	/**
24
+	 * @throws EE_Error
25
+	 */
26
+	private static function _set_autoloader()
27
+	{
28
+		EED_Messages::set_autoloaders();
29
+	}
30
+
31
+
32
+	/**
33
+	 * generate_new_templates
34
+	 * This will handle the messenger, message_type selection when "adding a new custom template" for an event and will
35
+	 * automatically create the defaults for the event.  The user would then be redirected to edit the default context
36
+	 * for the event.
37
+	 *
38
+	 * @access protected
39
+	 * @param string $messenger     the messenger we are generating templates for
40
+	 * @param array  $message_types array of message types that the templates are generated for.
41
+	 * @param int    $GRP_ID        If a non global template is being generated then it is expected we'll have a GRP_ID
42
+	 *                              to use as the base for the new generated template.
43
+	 * @param bool   $global        true indicates generating templates on messenger activation. false requires GRP_ID
44
+	 *                              for event specific template generation.
45
+	 * @return array  @see EEH_MSG_Template::_create_new_templates for the return value of each element in the array
46
+	 *                for templates that are generated.  If this is an empty array then it means no templates were
47
+	 *                generated which usually means there was an error.  Anything in the array with an empty value for
48
+	 *                `MTP_context` means that it was not a new generated template but just reactivated (which only
49
+	 *                happens for global templates that already exist in the database.
50
+	 * @throws EE_Error
51
+	 * @throws ReflectionException
52
+	 */
53
+	public static function generate_new_templates($messenger, $message_types, $GRP_ID = 0, $global = false)
54
+	{
55
+		// make sure message_type is an array.
56
+		$message_types = (array) $message_types;
57
+		$templates = array();
58
+
59
+		if (empty($messenger)) {
60
+			throw new EE_Error(esc_html__('We need a messenger to generate templates!', 'event_espresso'));
61
+		}
62
+
63
+		// if we STILL have empty $message_types then we need to generate an error message b/c we NEED message types to do the template files.
64
+		if (empty($message_types)) {
65
+			throw new EE_Error(esc_html__('We need at least one message type to generate templates!', 'event_espresso'));
66
+		}
67
+
68
+		EEH_MSG_Template::_set_autoloader();
69
+		foreach ($message_types as $message_type) {
70
+			// if this is global template generation.
71
+			if ($global) {
72
+				// let's attempt to get the GRP_ID for this combo IF GRP_ID is empty.
73
+				if (empty($GRP_ID)) {
74
+					$GRP_ID = EEM_Message_Template_Group::instance()->get_one(
75
+						array(
76
+							array(
77
+								'MTP_messenger'    => $messenger,
78
+								'MTP_message_type' => $message_type,
79
+								'MTP_is_global'    => true,
80
+							),
81
+						)
82
+					);
83
+					$GRP_ID = $GRP_ID instanceof EE_Message_Template_Group ? $GRP_ID->ID() : 0;
84
+				}
85
+				// First let's determine if we already HAVE global templates for this messenger and message_type combination.
86
+				//  If we do then NO generation!!
87
+				if (EEH_MSG_Template::already_generated($messenger, $message_type, $GRP_ID)) {
88
+					$templates[] = array(
89
+						'GRP_ID' => $GRP_ID,
90
+						'MTP_context' => '',
91
+					);
92
+					// we already have generated templates for this so let's go to the next message type.
93
+					continue;
94
+				}
95
+			}
96
+			$new_message_template_group = EEH_MSG_Template::create_new_templates($messenger, $message_type, $GRP_ID, $global);
97
+
98
+			if (! $new_message_template_group) {
99
+				continue;
100
+			}
101
+			$templates[] = $new_message_template_group;
102
+		}
103
+
104
+		return $templates;
105
+	}
106
+
107
+
108
+	/**
109
+	 * The purpose of this method is to determine if there are already generated templates in the database for the
110
+	 * given variables.
111
+	 *
112
+	 * @param string $messenger    messenger
113
+	 * @param string $message_type message type
114
+	 * @param int    $GRP_ID       GRP ID ( if a custom template) (if not provided then we're just doing global
115
+	 *                             template check)
116
+	 * @return bool                true = generated, false = hasn't been generated.
117
+	 * @throws EE_Error
118
+	 */
119
+	public static function already_generated($messenger, $message_type, $GRP_ID = 0)
120
+	{
121
+		EEH_MSG_Template::_set_autoloader();
122
+		// what method we use depends on whether we have an GRP_ID or not
123
+		$count = empty($GRP_ID)
124
+			? EEM_Message_Template::instance()->count(
125
+				array(
126
+					array(
127
+						'Message_Template_Group.MTP_messenger'    => $messenger,
128
+						'Message_Template_Group.MTP_message_type' => $message_type,
129
+						'Message_Template_Group.MTP_is_global'    => true
130
+					)
131
+				)
132
+			)
133
+			: EEM_Message_Template::instance()->count(array( array( 'GRP_ID' => $GRP_ID ) ));
134
+
135
+		return $count > 0;
136
+	}
137
+
138
+
139
+	/**
140
+	 * Updates all message templates matching the incoming messengers and message types to active status.
141
+	 *
142
+	 * @static
143
+	 * @param array $messenger_names    Messenger slug
144
+	 * @param array $message_type_names Message type slug
145
+	 * @return  int                         count of updated records.
146
+	 * @throws EE_Error
147
+	 */
148
+	public static function update_to_active($messenger_names, $message_type_names)
149
+	{
150
+		$messenger_names = is_array($messenger_names) ? $messenger_names : array( $messenger_names );
151
+		$message_type_names = is_array($message_type_names) ? $message_type_names : array( $message_type_names );
152
+		return EEM_Message_Template_Group::instance()->update(
153
+			array( 'MTP_is_active' => 1 ),
154
+			array(
155
+				array(
156
+					'MTP_messenger'     => array( 'IN', $messenger_names ),
157
+					'MTP_message_type'  => array( 'IN', $message_type_names )
158
+				)
159
+			)
160
+		);
161
+	}
162
+
163
+
164
+	/**
165
+	 * Updates all message template groups matching the incoming arguments to inactive status.
166
+	 *
167
+	 * @static
168
+	 * @param array $messenger_names    The messenger slugs.
169
+	 *                                  If empty then all templates matching the message types are marked inactive.
170
+	 *                                  Otherwise only templates matching the messengers and message types.
171
+	 * @param array $message_type_names The message type slugs.
172
+	 *                                  If empty then all templates matching the messengers are marked inactive.
173
+	 *                                  Otherwise only templates matching the messengers and message types.
174
+	 *
175
+	 * @return int  count of updated records.
176
+	 * @throws EE_Error
177
+	 */
178
+	public static function update_to_inactive($messenger_names = array(), $message_type_names = array())
179
+	{
180
+		return EEM_Message_Template_Group::instance()->deactivate_message_template_groups_for(
181
+			$messenger_names,
182
+			$message_type_names
183
+		);
184
+	}
185
+
186
+
187
+	/**
188
+	 * The purpose of this function is to return all installed message objects
189
+	 * (messengers and message type regardless of whether they are ACTIVE or not)
190
+	 *
191
+	 * @param string $type
192
+	 * @return array array consisting of installed messenger objects and installed message type objects.
193
+	 * @throws EE_Error
194
+	 * @throws ReflectionException
195
+	 * @deprecated 4.9.0
196
+	 * @static
197
+	 */
198
+	public static function get_installed_message_objects($type = 'all')
199
+	{
200
+		self::_set_autoloader();
201
+		$message_resource_manager = EE_Registry::instance()->load_lib('Message_Resource_Manager');
202
+		return array(
203
+			'messenger' => $message_resource_manager->installed_messengers(),
204
+			'message_type' => $message_resource_manager->installed_message_types()
205
+		);
206
+	}
207
+
208
+
209
+	/**
210
+	 * This will return an array of shortcodes => labels from the
211
+	 * messenger and message_type objects associated with this
212
+	 * template.
213
+	 *
214
+	 * @param string $message_type
215
+	 * @param string $messenger
216
+	 * @param array  $fields                        What fields we're returning valid shortcodes for.
217
+	 *                                              If empty then we assume all fields are to be returned. Optional.
218
+	 * @param string $context                       What context we're going to return shortcodes for. Optional.
219
+	 * @param bool   $merged                        If TRUE then we don't return shortcodes indexed by field,
220
+	 *                                              but instead an array of the unique shortcodes for all the given (
221
+	 *                                              or all) fields. Optional.
222
+	 * @return array                                an array of shortcodes in the format
223
+	 *                                              array( '[shortcode] => 'label')
224
+	 *                                              OR
225
+	 *                                              FALSE if no shortcodes found.
226
+	 * @throws ReflectionException
227
+	 * @throws EE_Error*@since 4.3.0
228
+	 *
229
+	 */
230
+	public static function get_shortcodes(
231
+		$message_type,
232
+		$messenger,
233
+		$fields = array(),
234
+		$context = 'admin',
235
+		$merged = false
236
+	) {
237
+		$messenger_name = str_replace(' ', '_', ucwords(str_replace('_', ' ', $messenger)));
238
+		$mt_name = str_replace(' ', '_', ucwords(str_replace('_', ' ', $message_type)));
239
+		/** @var EE_Message_Resource_Manager $message_resource_manager */
240
+		$message_resource_manager = EE_Registry::instance()->load_lib('Message_Resource_Manager');
241
+		// convert slug to object
242
+		$messenger = $message_resource_manager->get_messenger($messenger);
243
+
244
+		// if messenger isn't a EE_messenger resource then bail.
245
+		if (! $messenger instanceof EE_messenger) {
246
+			return array();
247
+		}
248
+
249
+		// validate class for getting our list of shortcodes
250
+		$classname = 'EE_Messages_' . $messenger_name . '_' . $mt_name . '_Validator';
251
+		if (! class_exists($classname)) {
252
+			$msg[] = esc_html__('The Validator class was unable to load', 'event_espresso');
253
+			$msg[] = sprintf(
254
+				esc_html__('The class name compiled was %s. Please check and make sure the spelling and case is correct for the class name and that there is an autoloader in place for this class', 'event_espresso'),
255
+				$classname
256
+			);
257
+			throw new EE_Error(implode('||', $msg));
258
+		}
259
+
260
+		/** @type EE_Messages_Validator $_VLD */
261
+		$_VLD = new $classname(array(), $context);
262
+		$valid_shortcodes = $_VLD->get_validators();
263
+
264
+		// let's make sure we're only getting the shortcode part of the validators
265
+		$shortcodes = array();
266
+		foreach ($valid_shortcodes as $field => $validators) {
267
+			$shortcodes[ $field ] = $validators['shortcodes'];
268
+		}
269
+		$valid_shortcodes = $shortcodes;
270
+
271
+		// if not all fields let's make sure we ONLY include the shortcodes for the specified fields.
272
+		if (! empty($fields)) {
273
+			$specified_shortcodes = array();
274
+			foreach ($fields as $field) {
275
+				if (isset($valid_shortcodes[ $field ])) {
276
+					$specified_shortcodes[ $field ] = $valid_shortcodes[ $field ];
277
+				}
278
+			}
279
+			$valid_shortcodes = $specified_shortcodes;
280
+		}
281
+
282
+		// if not merged then let's replace the fields with the localized fields
283
+		if (! $merged) {
284
+			// let's get all the fields for the set messenger so that we can get the localized label and use that in the returned array.
285
+			$field_settings = $messenger->get_template_fields();
286
+			$localized = array();
287
+			foreach ($valid_shortcodes as $field => $shortcodes) {
288
+				// get localized field label
289
+				if (isset($field_settings[ $field ])) {
290
+					// possible that this is used as a main field.
291
+					if (empty($field_settings[ $field ])) {
292
+						if (isset($field_settings['extra'][ $field ])) {
293
+							$_field = $field_settings['extra'][ $field ]['main']['label'];
294
+						} else {
295
+							$_field = $field;
296
+						}
297
+					} else {
298
+						$_field = $field_settings[ $field ]['label'];
299
+					}
300
+				} elseif (isset($field_settings['extra'])) {
301
+					// loop through extra "main fields" and see if any of their children have our field
302
+					foreach ($field_settings['extra'] as $fields) {
303
+						if (isset($fields[ $field ])) {
304
+							$_field = $fields[ $field ]['label'];
305
+						} else {
306
+							$_field = $field;
307
+						}
308
+					}
309
+				} else {
310
+					$_field = $field;
311
+				}
312
+				if (isset($_field)) {
313
+					$localized[ (string) $_field ] = $shortcodes;
314
+				}
315
+			}
316
+			$valid_shortcodes = $localized;
317
+		}
318
+
319
+		// if $merged then let's merge all the shortcodes into one list NOT indexed by field.
320
+		if ($merged) {
321
+			$merged_codes = array();
322
+			foreach ($valid_shortcodes as $shortcode) {
323
+				foreach ($shortcode as $code => $label) {
324
+					if (isset($merged_codes[ $code ])) {
325
+						continue;
326
+					} else {
327
+						$merged_codes[ $code ] = $label;
328
+					}
329
+				}
330
+			}
331
+			$valid_shortcodes = $merged_codes;
332
+		}
333
+
334
+		return $valid_shortcodes;
335
+	}
336
+
337
+
338
+	/**
339
+	 * Get Messenger object.
340
+	 *
341
+	 * @param string $messenger messenger slug for the messenger object we want to retrieve.
342
+	 * @return EE_messenger
343
+	 * @throws ReflectionException
344
+	 * @throws EE_Error*@since 4.3.0
345
+	 * @deprecated 4.9.0
346
+	 */
347
+	public static function messenger_obj($messenger)
348
+	{
349
+		/** @type EE_Message_Resource_Manager $Message_Resource_Manager */
350
+		$Message_Resource_Manager = EE_Registry::instance()->load_lib('Message_Resource_Manager');
351
+		return $Message_Resource_Manager->get_messenger($messenger);
352
+	}
353
+
354
+
355
+	/**
356
+	 * get Message type object
357
+	 *
358
+	 * @param string $message_type the slug for the message type object to retrieve
359
+	 * @return EE_message_type
360
+	 * @throws ReflectionException
361
+	 * @throws EE_Error*@since 4.3.0
362
+	 * @deprecated 4.9.0
363
+	 */
364
+	public static function message_type_obj($message_type)
365
+	{
366
+		/** @type EE_Message_Resource_Manager $Message_Resource_Manager */
367
+		$Message_Resource_Manager = EE_Registry::instance()->load_lib('Message_Resource_Manager');
368
+		return $Message_Resource_Manager->get_message_type($message_type);
369
+	}
370
+
371
+
372
+	/**
373
+	 * Given a message_type slug, will return whether that message type is active in the system or not.
374
+	 *
375
+	 * @since    4.3.0
376
+	 * @param string $message_type message type to check for.
377
+	 * @return boolean
378
+	 * @throws EE_Error
379
+	 * @throws ReflectionException
380
+	 */
381
+	public static function is_mt_active($message_type)
382
+	{
383
+		/** @type EE_Message_Resource_Manager $Message_Resource_Manager */
384
+		$Message_Resource_Manager = EE_Registry::instance()->load_lib('Message_Resource_Manager');
385
+		$active_mts = $Message_Resource_Manager->list_of_active_message_types();
386
+		return in_array($message_type, $active_mts);
387
+	}
388
+
389
+
390
+	/**
391
+	 * Given a messenger slug, will return whether that messenger is active in the system or not.
392
+	 *
393
+	 * @since    4.3.0
394
+	 *
395
+	 * @param string $messenger slug for messenger to check.
396
+	 * @return boolean
397
+	 * @throws EE_Error
398
+	 * @throws ReflectionException
399
+	 */
400
+	public static function is_messenger_active($messenger)
401
+	{
402
+		/** @type EE_Message_Resource_Manager $Message_Resource_Manager */
403
+		$Message_Resource_Manager = EE_Registry::instance()->load_lib('Message_Resource_Manager');
404
+		$active_messenger = $Message_Resource_Manager->get_active_messenger($messenger);
405
+		return $active_messenger instanceof EE_messenger;
406
+	}
407
+
408
+
409
+	/**
410
+	 * Used to return active messengers array stored in the wp options table.
411
+	 * If no value is present in the option then an empty array is returned.
412
+	 *
413
+	 * @deprecated 4.9
414
+	 * @since      4.3.1
415
+	 *
416
+	 * @return array
417
+	 * @throws EE_Error
418
+	 * @throws ReflectionException
419
+	 */
420
+	public static function get_active_messengers_in_db()
421
+	{
422
+		EE_Error::doing_it_wrong(
423
+			__METHOD__,
424
+			esc_html__('Please use EE_Message_Resource_Manager::get_active_messengers_option() instead.', 'event_espresso'),
425
+			'4.9.0'
426
+		);
427
+		/** @var EE_Message_Resource_Manager $Message_Resource_Manager */
428
+		$Message_Resource_Manager = EE_Registry::instance()->load_lib('Message_Resource_Manager');
429
+		return $Message_Resource_Manager->get_active_messengers_option();
430
+	}
431
+
432
+
433
+	/**
434
+	 * Used to update the active messengers array stored in the wp options table.
435
+	 *
436
+	 * @since      4.3.1
437
+	 * @deprecated 4.9.0
438
+	 *
439
+	 * @param array $data_to_save Incoming data to save.
440
+	 *
441
+	 * @return bool FALSE if not updated, TRUE if updated.
442
+	 * @throws EE_Error
443
+	 * @throws ReflectionException
444
+	 */
445
+	public static function update_active_messengers_in_db($data_to_save)
446
+	{
447
+		EE_Error::doing_it_wrong(
448
+			__METHOD__,
449
+			esc_html__('Please use EE_Message_Resource_Manager::update_active_messengers_option() instead.', 'event_espresso'),
450
+			'4.9.0'
451
+		);
452
+		/** @var EE_Message_Resource_Manager $Message_Resource_Manager */
453
+		$Message_Resource_Manager = EE_Registry::instance()->load_lib('Message_Resource_Manager');
454
+		return $Message_Resource_Manager->update_active_messengers_option($data_to_save);
455
+	}
456
+
457
+
458
+	/**
459
+	 * This does some validation of incoming params, determines what type of url is being prepped and returns the
460
+	 * appropriate url trigger
461
+	 *
462
+	 * @param EE_message_type $message_type
463
+	 * @param EE_Message $message
464
+	 * @param EE_Registration | null $registration  The registration object must be included if this
465
+	 *                                              is going to be a registration trigger url.
466
+	 * @param string $sending_messenger             The (optional) sending messenger for the url.
467
+	 *
468
+	 * @return string
469
+	 * @throws EE_Error
470
+	 */
471
+	public static function get_url_trigger(
472
+		EE_message_type $message_type,
473
+		EE_Message $message,
474
+		$registration = null,
475
+		$sending_messenger = ''
476
+	) {
477
+		// first determine if the url can be to the EE_Message object.
478
+		if (! $message_type->always_generate()) {
479
+			return EEH_MSG_Template::generate_browser_trigger($message);
480
+		}
481
+
482
+		// if $registration object is not valid then exit early because there's nothing that can be generated.
483
+		if (! $registration instanceof EE_Registration) {
484
+			throw new EE_Error(
485
+				esc_html__('Incoming value for registration is not a valid EE_Registration object.', 'event_espresso')
486
+			);
487
+		}
488
+
489
+		// validate given context
490
+		$contexts = $message_type->get_contexts();
491
+		if ($message->context() !== '' && ! isset($contexts[ $message->context() ])) {
492
+			throw new EE_Error(
493
+				sprintf(
494
+					esc_html__('The context %s is not a valid context for %s.', 'event_espresso'),
495
+					$message->context(),
496
+					get_class($message_type)
497
+				)
498
+			);
499
+		}
500
+
501
+		// valid sending messenger but only if sending messenger set.  Otherwise generating messenger is used.
502
+		if (! empty($sending_messenger)) {
503
+			$with_messengers = $message_type->with_messengers();
504
+			if (
505
+				! isset($with_messengers[ $message->messenger() ])
506
+				 || ! in_array($sending_messenger, $with_messengers[ $message->messenger() ])
507
+			) {
508
+				throw new EE_Error(
509
+					sprintf(
510
+						esc_html__(
511
+							'The given sending messenger string (%1$s) does not match a valid sending messenger with the %2$s.  If this is incorrect, make sure that the message type has defined this messenger as a sending messenger in its $_with_messengers array.',
512
+							'event_espresso'
513
+						),
514
+						$sending_messenger,
515
+						get_class($message_type)
516
+					)
517
+				);
518
+			}
519
+		} else {
520
+			$sending_messenger = $message->messenger();
521
+		}
522
+		return EEH_MSG_Template::generate_url_trigger(
523
+			$sending_messenger,
524
+			$message->messenger(),
525
+			$message->context(),
526
+			$message->message_type(),
527
+			$registration,
528
+			$message->GRP_ID()
529
+		);
530
+	}
531
+
532
+
533
+	/**
534
+	 * This returns the url for triggering a in browser view of a specific EE_Message object.
535
+	 * @param EE_Message $message
536
+	 * @return string.
537
+	 */
538
+	public static function generate_browser_trigger(EE_Message $message)
539
+	{
540
+		$query_args = array(
541
+			'ee' => 'msg_browser_trigger',
542
+			'token' => $message->MSG_token()
543
+		);
544
+		return apply_filters(
545
+			'FHEE__EEH_MSG_Template__generate_browser_trigger',
546
+			add_query_arg($query_args, site_url()),
547
+			$message
548
+		);
549
+	}
550
+
551
+
552
+
553
+
554
+
555
+
556
+	/**
557
+	 * This returns the url for triggering an in browser view of the error saved on the incoming message object.
558
+	 * @param EE_Message $message
559
+	 * @return string
560
+	 */
561
+	public static function generate_error_display_trigger(EE_Message $message)
562
+	{
563
+		return apply_filters(
564
+			'FHEE__EEH_MSG_Template__generate_error_display_trigger',
565
+			add_query_arg(
566
+				array(
567
+					'ee' => 'msg_browser_error_trigger',
568
+					'token' => $message->MSG_token()
569
+				),
570
+				site_url()
571
+			),
572
+			$message
573
+		);
574
+	}
575
+
576
+
577
+	/**
578
+	 * This generates a url trigger for the msg_url_trigger route using the given arguments
579
+	 *
580
+	 * @param string          $sending_messenger      The sending messenger slug.
581
+	 * @param string          $generating_messenger   The generating messenger slug.
582
+	 * @param string          $context                The context for the template.
583
+	 * @param string          $message_type           The message type slug
584
+	 * @param EE_Registration $registration
585
+	 * @param integer         $message_template_group id   The EE_Message_Template_Group ID for the template.
586
+	 * @param integer         $data_id                The id to the EE_Base_Class for getting the data used by the
587
+	 *                                                trigger.
588
+	 * @return string          The generated url.
589
+	 * @throws EE_Error
590
+	 */
591
+	public static function generate_url_trigger(
592
+		$sending_messenger,
593
+		$generating_messenger,
594
+		$context,
595
+		$message_type,
596
+		EE_Registration $registration,
597
+		$message_template_group,
598
+		$data_id = 0
599
+	) {
600
+		$query_args = array(
601
+			'ee' => 'msg_url_trigger',
602
+			'snd_msgr' => $sending_messenger,
603
+			'gen_msgr' => $generating_messenger,
604
+			'message_type' => $message_type,
605
+			'context' => $context,
606
+			'token' => $registration->reg_url_link(),
607
+			'GRP_ID' => $message_template_group,
608
+			'id' => $data_id
609
+			);
610
+		$url = add_query_arg($query_args, get_home_url());
611
+
612
+		// made it here so now we can just get the url and filter it.  Filtered globally and by message type.
613
+		return apply_filters(
614
+			'FHEE__EEH_MSG_Template__generate_url_trigger',
615
+			$url,
616
+			$sending_messenger,
617
+			$generating_messenger,
618
+			$context,
619
+			$message_type,
620
+			$registration,
621
+			$message_template_group,
622
+			$data_id
623
+		);
624
+	}
625
+
626
+
627
+
628
+
629
+	/**
630
+	 * Return the specific css for the action icon given.
631
+	 *
632
+	 * @param string $type  What action to return.
633
+	 * @return string[]
634
+	 * @since 4.9.0
635
+	 */
636
+	public static function get_message_action_icon($type)
637
+	{
638
+		$action_icons = self::get_message_action_icons();
639
+		return isset($action_icons[ $type ]) ? $action_icons[ $type ] : [];
640
+	}
641
+
642
+
643
+	/**
644
+	 * This is used for retrieving the css classes used for the icons representing message actions.
645
+	 *
646
+	 * @since 4.9.0
647
+	 *
648
+	 * @return array
649
+	 */
650
+	public static function get_message_action_icons()
651
+	{
652
+		return apply_filters(
653
+			'FHEE__EEH_MSG_Template__message_action_icons',
654
+			array(
655
+				'view' => array(
656
+					'label' => esc_html__('View Message', 'event_espresso'),
657
+					'css_class' => 'dashicons dashicons-welcome-view-site',
658
+				),
659
+				'error' => array(
660
+					'label' => esc_html__('View Error Message', 'event_espresso'),
661
+					'css_class' => 'dashicons dashicons-info',
662
+				),
663
+				'see_notifications_for' => array(
664
+					'label' => esc_html__('View Related Messages', 'event_espresso'),
665
+					'css_class' => 'dashicons dashicons-megaphone',
666
+				),
667
+				'generate_now' => array(
668
+					'label' => esc_html__('Generate the message now.', 'event_espresso'),
669
+					'css_class' => 'dashicons dashicons-admin-tools',
670
+				),
671
+				'send_now' => array(
672
+					'label' => esc_html__('Send Immediately', 'event_espresso'),
673
+					'css_class' => 'dashicons dashicons-controls-forward',
674
+				),
675
+				'queue_for_resending' => array(
676
+					'label' => esc_html__('Queue for Resending', 'event_espresso'),
677
+					'css_class' => 'dashicons dashicons-controls-repeat',
678
+				),
679
+				'view_transaction' => array(
680
+					'label' => esc_html__('View related Transaction', 'event_espresso'),
681
+					'css_class' => 'dashicons dashicons-cart',
682
+				)
683
+			)
684
+		);
685
+	}
686
+
687
+
688
+	/**
689
+	 * This returns the url for a given action related to EE_Message.
690
+	 *
691
+	 * @param string     $type         What type of action to return the url for.
692
+	 * @param EE_Message $message      Required for generating the correct url for some types.
693
+	 * @param array      $query_params Any additional query params to be included with the generated url.
694
+	 *
695
+	 * @return string
696
+	 * @throws EE_Error
697
+	 * @throws ReflectionException
698
+	 * @since 4.9.0
699
+	 *
700
+	 */
701
+	public static function get_message_action_url($type, EE_Message $message = null, $query_params = array())
702
+	{
703
+		$action_urls = self::get_message_action_urls($message, $query_params);
704
+		return isset($action_urls[ $type ])  ? $action_urls[ $type ] : '';
705
+	}
706
+
707
+
708
+	/**
709
+	 * This returns all the current urls for EE_Message actions.
710
+	 *
711
+	 * @since 4.9.0
712
+	 *
713
+	 * @param EE_Message $message      The EE_Message object required to generate correct urls for some types.
714
+	 * @param array      $query_params Any additional query_params to be included with the generated url.
715
+	 *
716
+	 * @return array
717
+	 * @throws EE_Error
718
+	 * @throws ReflectionException
719
+	 */
720
+	public static function get_message_action_urls(EE_Message $message = null, $query_params = array())
721
+	{
722
+		EE_Registry::instance()->load_helper('URL');
723
+		// if $message is not an instance of EE_Message then let's just do a dummy.
724
+		$message = empty($message) ? EE_Message_Factory::create() : $message;
725
+		$action_urls =  apply_filters(
726
+			'FHEE__EEH_MSG_Template__get_message_action_url',
727
+			array(
728
+				'view' => EEH_MSG_Template::generate_browser_trigger($message),
729
+				'error' => EEH_MSG_Template::generate_error_display_trigger($message),
730
+				'see_notifications_for' => EEH_URL::add_query_args_and_nonce(
731
+					array_merge(
732
+						array(
733
+							'page' => 'espresso_messages',
734
+							'action' => 'default',
735
+							'filterby' => 1,
736
+						),
737
+						$query_params
738
+					),
739
+					admin_url('admin.php')
740
+				),
741
+				'generate_now' => EEH_URL::add_query_args_and_nonce(
742
+					array(
743
+						'page' => 'espresso_messages',
744
+						'action' => 'generate_now',
745
+						'MSG_ID' => $message->ID()
746
+					),
747
+					admin_url('admin.php')
748
+				),
749
+				'send_now' => EEH_URL::add_query_args_and_nonce(
750
+					array(
751
+						'page' => 'espresso_messages',
752
+						'action' => 'send_now',
753
+						'MSG_ID' => $message->ID()
754
+					),
755
+					admin_url('admin.php')
756
+				),
757
+				'queue_for_resending' => EEH_URL::add_query_args_and_nonce(
758
+					array(
759
+						'page' => 'espresso_messages',
760
+						'action' => 'queue_for_resending',
761
+						'MSG_ID' => $message->ID()
762
+					),
763
+					admin_url('admin.php')
764
+				),
765
+			)
766
+		);
767
+		if (
768
+			$message->TXN_ID() > 0
769
+			&& EE_Registry::instance()->CAP->current_user_can(
770
+				'ee_read_transaction',
771
+				'espresso_transactions_default',
772
+				$message->TXN_ID()
773
+			)
774
+		) {
775
+			$action_urls['view_transaction'] = EEH_URL::add_query_args_and_nonce(
776
+				array(
777
+					'page' => 'espresso_transactions',
778
+					'action' => 'view_transaction',
779
+					'TXN_ID' => $message->TXN_ID()
780
+				),
781
+				admin_url('admin.php')
782
+			);
783
+		} else {
784
+			$action_urls['view_transaction'] = '';
785
+		}
786
+		return $action_urls;
787
+	}
788
+
789
+
790
+	/**
791
+	 * This returns a generated link html including the icon used for the action link for EE_Message actions.
792
+	 *
793
+	 * @param string          $type         What type of action the link is for (if invalid type is passed in then an
794
+	 *                                      empty string is returned)
795
+	 * @param EE_Message|null $message      The EE_Message object (required for some actions to generate correctly)
796
+	 * @param array           $query_params Any extra query params to include in the generated link.
797
+	 *
798
+	 * @return string
799
+	 * @throws EE_Error
800
+	 * @throws ReflectionException
801
+	 * @since 4.9.0
802
+	 *
803
+	 */
804
+	public static function get_message_action_link($type, EE_Message $message = null, $query_params = array())
805
+	{
806
+		$url = EEH_MSG_Template::get_message_action_url($type, $message, $query_params);
807
+		$icon_css = EEH_MSG_Template::get_message_action_icon($type);
808
+		$title = isset($icon_css['label']) ? 'title="' . $icon_css['label'] . '"' : '';
809
+
810
+		if (empty($url) || empty($icon_css) || ! isset($icon_css['css_class'])) {
811
+			return '';
812
+		}
813
+
814
+		$icon_css['css_class'] .= esc_attr(
815
+			apply_filters(
816
+				'FHEE__EEH_MSG_Template__get_message_action_link__icon_css_class',
817
+				' js-ee-message-action-link ee-message-action-link-' . $type,
818
+				$type,
819
+				$message,
820
+				$query_params
821
+			)
822
+		);
823
+
824
+		return '<a href="' . $url . '" ' . $title . '><span class="' . esc_attr($icon_css['css_class']) . '"></span></a>';
825
+	}
826
+
827
+
828
+
829
+
830
+
831
+	/**
832
+	 * This returns an array with keys as reg statuses and values as the corresponding message type slug (filtered).
833
+	 *
834
+	 * @since 4.9.0
835
+	 * @return array
836
+	 */
837
+	public static function reg_status_to_message_type_array()
838
+	{
839
+		return (array) apply_filters(
840
+			'FHEE__EEH_MSG_Template__reg_status_to_message_type_array',
841
+			array(
842
+				EEM_Registration::status_id_approved => 'registration',
843
+				EEM_Registration::status_id_pending_payment => 'pending_approval',
844
+				EEM_Registration::status_id_not_approved => 'not_approved_registration',
845
+				EEM_Registration::status_id_cancelled => 'cancelled_registration',
846
+				EEM_Registration::status_id_declined => 'declined_registration'
847
+			)
848
+		);
849
+	}
850
+
851
+
852
+
853
+
854
+	/**
855
+	 * This returns the corresponding registration message type slug to the given reg status. If there isn't a
856
+	 * match, then returns an empty string.
857
+	 *
858
+	 * @since 4.9.0
859
+	 * @param $reg_status
860
+	 * @return string
861
+	 */
862
+	public static function convert_reg_status_to_message_type($reg_status)
863
+	{
864
+		$reg_status_array = self::reg_status_to_message_type_array();
865
+		return isset($reg_status_array[ $reg_status ]) ? $reg_status_array[ $reg_status ] : '';
866
+	}
867
+
868
+
869
+	/**
870
+	 * This returns an array with keys as payment stati and values as the corresponding message type slug (filtered).
871
+	 *
872
+	 * @since 4.9.0
873
+	 * @return array
874
+	 */
875
+	public static function payment_status_to_message_type_array()
876
+	{
877
+		return (array) apply_filters(
878
+			'FHEE__EEH_MSG_Template__payment_status_to_message_type_array',
879
+			array(
880
+				EEM_Payment::status_id_approved => 'payment',
881
+				EEM_Payment::status_id_pending => 'payment_pending',
882
+				EEM_Payment::status_id_cancelled => 'payment_cancelled',
883
+				EEM_Payment::status_id_declined => 'payment_declined',
884
+				EEM_Payment::status_id_failed => 'payment_failed'
885
+			)
886
+		);
887
+	}
888
+
889
+
890
+
891
+
892
+	/**
893
+	 * This returns the corresponding payment message type slug to the given payment status. If there isn't a match then
894
+	 * an empty string is returned
895
+	 *
896
+	 * @since 4.9.0
897
+	 * @param $payment_status
898
+	 * @return string
899
+	 */
900
+	public static function convert_payment_status_to_message_type($payment_status)
901
+	{
902
+		$payment_status_array = self::payment_status_to_message_type_array();
903
+		return isset($payment_status_array[ $payment_status ]) ? $payment_status_array[ $payment_status ] : '';
904
+	}
905
+
906
+
907
+	/**
908
+	 * This is used to retrieve the template pack for the given name.
909
+	 *
910
+	 * @param string $template_pack_name  should match the set `dbref` property value on the EE_Messages_Template_Pack.
911
+	 *
912
+	 * @return EE_Messages_Template_Pack
913
+	 */
914
+	public static function get_template_pack($template_pack_name)
915
+	{
916
+		if (! self::$_template_pack_collection instanceof EE_Object_Collection) {
917
+			self::$_template_pack_collection = new EE_Messages_Template_Pack_Collection();
918
+		}
919
+
920
+		// first see if in collection already
921
+		$template_pack = self::$_template_pack_collection->get_by_name($template_pack_name);
922
+
923
+		if ($template_pack instanceof EE_Messages_Template_Pack) {
924
+			return $template_pack;
925
+		}
926
+
927
+		// nope...let's get it.
928
+		// not set yet so let's attempt to get it.
929
+		$pack_class_name = 'EE_Messages_Template_Pack_' . str_replace(
930
+			' ',
931
+			'_',
932
+			ucwords(
933
+				str_replace('_', ' ', $template_pack_name)
934
+			)
935
+		);
936
+		if (! class_exists($pack_class_name) && $template_pack_name !== 'default') {
937
+			return self::get_template_pack('default');
938
+		} else {
939
+			$template_pack = new $pack_class_name();
940
+			self::$_template_pack_collection->add($template_pack);
941
+			return $template_pack;
942
+		}
943
+	}
944
+
945
+
946
+
947
+
948
+	/**
949
+	 * Globs template packs installed in core and returns the template pack collection with all installed template packs
950
+	 * in it.
951
+	 *
952
+	 * @since 4.9.0
953
+	 *
954
+	 * @return EE_Messages_Template_Pack_Collection
955
+	 */
956
+	public static function get_template_pack_collection()
957
+	{
958
+		$new_collection = false;
959
+		if (! self::$_template_pack_collection instanceof EE_Messages_Template_Pack_Collection) {
960
+			self::$_template_pack_collection = new EE_Messages_Template_Pack_Collection();
961
+			$new_collection = true;
962
+		}
963
+
964
+		// glob the defaults directory for messages
965
+		$templates = glob(EE_LIBRARIES . 'messages/defaults/*', GLOB_ONLYDIR);
966
+		foreach ($templates as $template_path) {
967
+			// grab folder name
968
+			$template = basename($template_path);
969
+
970
+			if (! $new_collection) {
971
+				// already have it?
972
+				if (self::$_template_pack_collection->get_by_name($template) instanceof EE_Messages_Template_Pack) {
973
+					continue;
974
+				}
975
+			}
976
+
977
+			// setup classname.
978
+			$template_pack_class_name = 'EE_Messages_Template_Pack_' . str_replace(
979
+				' ',
980
+				'_',
981
+				ucwords(
982
+					str_replace(
983
+						'_',
984
+						' ',
985
+						$template
986
+					)
987
+				)
988
+			);
989
+			if (! class_exists($template_pack_class_name)) {
990
+				continue;
991
+			}
992
+			self::$_template_pack_collection->add(new $template_pack_class_name());
993
+		}
994
+
995
+		/**
996
+		 * Filter for plugins to add in any additional template packs
997
+		 * Note the filter name here is for backward compat, this used to be found in EED_Messages.
998
+		 */
999
+		$additional_template_packs = apply_filters('FHEE__EED_Messages__get_template_packs__template_packs', array());
1000
+		foreach ((array) $additional_template_packs as $template_pack) {
1001
+			if (
1002
+				self::$_template_pack_collection->get_by_name(
1003
+					$template_pack->dbref
1004
+				) instanceof EE_Messages_Template_Pack
1005
+			) {
1006
+				continue;
1007
+			}
1008
+			self::$_template_pack_collection->add($template_pack);
1009
+		}
1010
+		return self::$_template_pack_collection;
1011
+	}
1012
+
1013
+
1014
+	/**
1015
+	 * This is a wrapper for the protected _create_new_templates function
1016
+	 *
1017
+	 * @param string $messenger_name
1018
+	 * @param string $message_type_name message type that the templates are being created for
1019
+	 * @param int    $GRP_ID
1020
+	 * @param bool   $global
1021
+	 * @return array
1022
+	 * @throws EE_Error
1023
+	 * @throws ReflectionException
1024
+	 */
1025
+	public static function create_new_templates($messenger_name, $message_type_name, $GRP_ID = 0, $global = false)
1026
+	{
1027
+		/** @type EE_Message_Resource_Manager $Message_Resource_Manager */
1028
+		$Message_Resource_Manager = EE_Registry::instance()->load_lib('Message_Resource_Manager');
1029
+		$messenger = $Message_Resource_Manager->valid_messenger($messenger_name);
1030
+		$message_type = $Message_Resource_Manager->valid_message_type($message_type_name);
1031
+		if (! EEH_MSG_Template::message_type_has_active_templates_for_messenger($messenger, $message_type, $global)) {
1032
+			return array();
1033
+		}
1034
+		// whew made it this far!  Okay, let's go ahead and create the templates then
1035
+		return EEH_MSG_Template::_create_new_templates($messenger, $message_type, $GRP_ID, $global);
1036
+	}
1037
+
1038
+
1039
+	/**
1040
+	 * @param EE_messenger     $messenger
1041
+	 * @param EE_message_type  $message_type
1042
+	 * @param                  $GRP_ID
1043
+	 * @param                  $global
1044
+	 * @return array|mixed
1045
+	 * @throws EE_Error
1046
+	 * @throws ReflectionException
1047
+	 */
1048
+	protected static function _create_new_templates(EE_messenger $messenger, EE_message_type $message_type, $GRP_ID, $global)
1049
+	{
1050
+		// if we're creating a custom template then we don't need to use the defaults class
1051
+		if (! $global) {
1052
+			return EEH_MSG_Template::_create_custom_template_group($messenger, $message_type, $GRP_ID);
1053
+		}
1054
+		/** @type EE_Messages_Template_Defaults $Message_Template_Defaults */
1055
+		$Message_Template_Defaults = EE_Registry::factory(
1056
+			'EE_Messages_Template_Defaults',
1057
+			array( $messenger, $message_type, $GRP_ID )
1058
+		);
1059
+		// generate templates
1060
+		$success = $Message_Template_Defaults->create_new_templates();
1061
+
1062
+		// if creating the template failed.  Then we should deactivate the related message_type for the messenger because
1063
+		// its not active if it doesn't have a template.  Note this is only happening for GLOBAL template creation
1064
+		// attempts.
1065
+		if (! $success) {
1066
+			/** @var EE_Message_Resource_Manager $message_resource_manager */
1067
+			$message_resource_manager = EE_Registry::instance()->load_lib('Message_Resource_Manager');
1068
+			$message_resource_manager->deactivate_message_type_for_messenger($message_type->name, $messenger->name);
1069
+		}
1070
+
1071
+		/**
1072
+		 * $success is in an array in the following format
1073
+		 * array(
1074
+		 *    'GRP_ID' => $new_grp_id,
1075
+		 *    'MTP_context' => $first_context_in_new_templates,
1076
+		 * )
1077
+		 */
1078
+		return $success;
1079
+	}
1080
+
1081
+
1082
+	/**
1083
+	 * This creates a custom template using the incoming GRP_ID
1084
+	 *
1085
+	 * @param EE_messenger    $messenger
1086
+	 * @param EE_message_type $message_type
1087
+	 * @param int             $GRP_ID           GRP_ID for the template_group being used as the base
1088
+	 * @return  array $success              This will be an array in the format:
1089
+	 *                                          array(
1090
+	 *                                          'GRP_ID' => $new_grp_id,
1091
+	 *                                          'MTP_context' => $first_context_in_created_template
1092
+	 *                                          )
1093
+	 * @throws EE_Error
1094
+	 * @throws ReflectionException
1095
+	 * @access private
1096
+	 */
1097
+	private static function _create_custom_template_group(EE_messenger $messenger, EE_message_type $message_type, $GRP_ID)
1098
+	{
1099
+		// defaults
1100
+		$success = array( 'GRP_ID' => null, 'MTP_context' => '' );
1101
+		// get the template group to use as a template from the db.  If $GRP_ID is empty then we'll assume the base will be the global template matching the messenger and message type.
1102
+		$Message_Template_Group = empty($GRP_ID)
1103
+			? EEM_Message_Template_Group::instance()->get_one(
1104
+				array(
1105
+					array(
1106
+						'MTP_messenger'    => $messenger->name,
1107
+						'MTP_message_type' => $message_type->name,
1108
+						'MTP_is_global'    => true
1109
+					)
1110
+				)
1111
+			)
1112
+			: EEM_Message_Template_Group::instance()->get_one_by_ID($GRP_ID);
1113
+		// if we don't have a mtg at this point then we need to bail.
1114
+		if (! $Message_Template_Group instanceof EE_Message_Template_Group) {
1115
+			EE_Error::add_error(
1116
+				sprintf(
1117
+					esc_html__(
1118
+						'Something went wrong with generating the custom template from this group id: %s.  This usually happens when there is no matching message template group in the db.',
1119
+						'event_espresso'
1120
+					),
1121
+					$GRP_ID
1122
+				),
1123
+				__FILE__,
1124
+				__FUNCTION__,
1125
+				__LINE__
1126
+			);
1127
+			return $success;
1128
+		}
1129
+		// let's get all the related message_template objects for this group.
1130
+		$message_templates = $Message_Template_Group->message_templates();
1131
+		// now we have what we need to setup the new template
1132
+		$new_mtg = clone $Message_Template_Group;
1133
+		$new_mtg->set('GRP_ID', 0);
1134
+		$new_mtg->set('MTP_is_global', false);
1135
+
1136
+		/** @var RequestInterface $request */
1137
+		$request = LoaderFactory::getLoader()->getShared(RequestInterface::class);
1138
+		$template_name = $request->isAjax() && $request->requestParamIsSet('templateName')
1139
+			? $request->getRequestParam('templateName')
1140
+			: esc_html__('New Custom Template', 'event_espresso');
1141
+		$template_description = $request->isAjax() && $request->requestParamIsSet('templateDescription')
1142
+			? $request->getRequestParam('templateDescription')
1143
+			: sprintf(
1144
+				esc_html__(
1145
+					'This is a custom template that was created for the %s messenger and %s message type.',
1146
+					'event_espresso'
1147
+				),
1148
+				$new_mtg->messenger_obj()->label['singular'],
1149
+				$new_mtg->message_type_obj()->label['singular']
1150
+			);
1151
+		$new_mtg->set('MTP_name', $template_name);
1152
+		$new_mtg->set('MTP_description', $template_description);
1153
+		// remove ALL relations on this template group so they don't get saved!
1154
+		$new_mtg->_remove_relations('Message_Template');
1155
+		$new_mtg->save();
1156
+		$success['GRP_ID'] = $new_mtg->ID();
1157
+		$success['template_name'] = $template_name;
1158
+		// add new message templates and add relation to.
1159
+		foreach ($message_templates as $message_template) {
1160
+			if (! $message_template instanceof EE_Message_Template) {
1161
+				continue;
1162
+			}
1163
+			$new_message_template = clone $message_template;
1164
+			$new_message_template->set('MTP_ID', 0);
1165
+			$new_message_template->set('GRP_ID', $new_mtg->ID()); // relation
1166
+			$new_message_template->save();
1167
+			if (empty($success['MTP_context']) && $new_message_template->get('MTP_context') !== 'admin') {
1168
+				$success['MTP_context'] = $new_message_template->get('MTP_context');
1169
+			}
1170
+		}
1171
+		return $success;
1172
+	}
1173
+
1174
+
1175
+	/**
1176
+	 * message_type_has_active_templates_for_messenger
1177
+	 *
1178
+	 * @param EE_messenger    $messenger
1179
+	 * @param EE_message_type $message_type
1180
+	 * @param bool            $global
1181
+	 * @return bool
1182
+	 * @throws EE_Error
1183
+	 */
1184
+	public static function message_type_has_active_templates_for_messenger(
1185
+		EE_messenger $messenger,
1186
+		EE_message_type $message_type,
1187
+		$global = false
1188
+	) {
1189
+		// is given message_type valid for given messenger (if this is not a global save)
1190
+		if ($global) {
1191
+			return true;
1192
+		}
1193
+		$active_templates = EEM_Message_Template_Group::instance()->count(
1194
+			array(
1195
+				array(
1196
+					'MTP_is_active'    => true,
1197
+					'MTP_messenger'    => $messenger->name,
1198
+					'MTP_message_type' => $message_type->name
1199
+				)
1200
+			)
1201
+		);
1202
+		if ($active_templates > 0) {
1203
+			return true;
1204
+		}
1205
+		EE_Error::add_error(
1206
+			sprintf(
1207
+				esc_html__(
1208
+					'The %1$s message type is not registered with the %2$s messenger. Please visit the Messenger activation page to assign this message type first if you want to use it.',
1209
+					'event_espresso'
1210
+				),
1211
+				$message_type->name,
1212
+				$messenger->name
1213
+			),
1214
+			__FILE__,
1215
+			__FUNCTION__,
1216
+			__LINE__
1217
+		);
1218
+		return false;
1219
+	}
1220
+
1221
+
1222
+	/**
1223
+	 * get_fields
1224
+	 * This takes a given messenger and message type and returns all the template fields indexed by context (and with field type).
1225
+	 *
1226
+	 * @param string $messenger_name    name of EE_messenger
1227
+	 * @param string $message_type_name name of EE_message_type
1228
+	 * @return array
1229
+	 * @throws EE_Error
1230
+	 * @throws ReflectionException
1231
+	 */
1232
+	public static function get_fields($messenger_name, $message_type_name)
1233
+	{
1234
+		$template_fields = array();
1235
+		/** @type EE_Message_Resource_Manager $Message_Resource_Manager */
1236
+		$Message_Resource_Manager = EE_Registry::instance()->load_lib('Message_Resource_Manager');
1237
+		$messenger = $Message_Resource_Manager->valid_messenger($messenger_name);
1238
+		$message_type = $Message_Resource_Manager->valid_message_type($message_type_name);
1239
+		if (! EEH_MSG_Template::message_type_has_active_templates_for_messenger($messenger, $message_type)) {
1240
+			return array();
1241
+		}
1242
+
1243
+		$excluded_fields_for_messenger = $message_type->excludedFieldsForMessenger($messenger_name);
1244
+
1245
+		// okay now let's assemble an array with the messenger template fields added to the message_type contexts.
1246
+		foreach ($message_type->get_contexts() as $context => $details) {
1247
+			foreach ($messenger->get_template_fields() as $field => $value) {
1248
+				if (in_array($field, $excluded_fields_for_messenger, true)) {
1249
+					continue;
1250
+				}
1251
+				$template_fields[ $context ][ $field ] = $value;
1252
+			}
1253
+		}
1254
+		if (empty($template_fields)) {
1255
+			EE_Error::add_error(
1256
+				esc_html__('Something went wrong and we couldn\'t get any templates assembled', 'event_espresso'),
1257
+				__FILE__,
1258
+				__FUNCTION__,
1259
+				__LINE__
1260
+			);
1261
+			return array();
1262
+		}
1263
+		return $template_fields;
1264
+	}
1265 1265
 }
Please login to merge, or discard this patch.
core/helpers/EEH_Autoloader.helper.php 2 patches
Spacing   +22 added lines, -22 removed lines patch added patch discarded remove patch
@@ -53,7 +53,7 @@  discard block
 block discarded – undo
53 53
         if (self::$_autoloaders === null) {
54 54
             self::$_autoloaders = array();
55 55
             $this->_register_custom_autoloaders();
56
-            spl_autoload_register(array( $this, 'espresso_autoloader' ));
56
+            spl_autoload_register(array($this, 'espresso_autoloader'));
57 57
         }
58 58
     }
59 59
 
@@ -66,7 +66,7 @@  discard block
 block discarded – undo
66 66
     public static function instance()
67 67
     {
68 68
         // check if class object is instantiated
69
-        if (! self::$_instance instanceof EEH_Autoloader) {
69
+        if ( ! self::$_instance instanceof EEH_Autoloader) {
70 70
             self::$_instance = new self();
71 71
         }
72 72
         return self::$_instance;
@@ -85,8 +85,8 @@  discard block
 block discarded – undo
85 85
      */
86 86
     public static function espresso_autoloader($class_name)
87 87
     {
88
-        if (isset(self::$_autoloaders[ $class_name ])) {
89
-            require_once(self::$_autoloaders[ $class_name ]);
88
+        if (isset(self::$_autoloaders[$class_name])) {
89
+            require_once(self::$_autoloaders[$class_name]);
90 90
         }
91 91
     }
92 92
 
@@ -103,7 +103,7 @@  discard block
 block discarded – undo
103 103
      */
104 104
     public static function register_autoloader($class_paths, $read_check = true, $debug = false)
105 105
     {
106
-        $class_paths = is_array($class_paths) ? $class_paths : array( $class_paths );
106
+        $class_paths = is_array($class_paths) ? $class_paths : array($class_paths);
107 107
         foreach ($class_paths as $class => $path) {
108 108
             // skip all files that are not PHP
109 109
             if (substr($path, strlen($path) - 3) !== 'php') {
@@ -122,10 +122,10 @@  discard block
 block discarded – undo
122 122
             if ($read_check && ! is_readable($path)) {
123 123
                 throw new EE_Error(sprintf(esc_html__('The file for the %s class could not be found or is not readable due to file permissions. Please ensure the following path is correct: %s', 'event_espresso'), $class, $path));
124 124
             }
125
-            if (! isset(self::$_autoloaders[ $class ])) {
126
-                self::$_autoloaders[ $class ] = str_replace(array( '/', '\\' ), '/', $path);
127
-                if (EE_DEBUG && ( EEH_Autoloader::$debug === 'paths' || EEH_Autoloader::$debug === 'all' || $debug )) {
128
-                    EEH_Debug_Tools::printr(self::$_autoloaders[ $class ], $class, __FILE__, __LINE__);
125
+            if ( ! isset(self::$_autoloaders[$class])) {
126
+                self::$_autoloaders[$class] = str_replace(array('/', '\\'), '/', $path);
127
+                if (EE_DEBUG && (EEH_Autoloader::$debug === 'paths' || EEH_Autoloader::$debug === 'all' || $debug)) {
128
+                    EEH_Debug_Tools::printr(self::$_autoloaders[$class], $class, __FILE__, __LINE__);
129 129
                 }
130 130
             }
131 131
         }
@@ -157,13 +157,13 @@  discard block
 block discarded – undo
157 157
     {
158 158
         EEH_Autoloader::$debug = '';
159 159
         \EEH_Autoloader::register_helpers_autoloaders();
160
-        EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_CORE . 'interfaces');
160
+        EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_CORE.'interfaces');
161 161
         EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_CORE);
162 162
         EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_INTERFACES, true);
163 163
         EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_MODELS, true);
164 164
         EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_CLASSES);
165 165
         EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_FORM_SECTIONS, true);
166
-        EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_LIBRARIES . 'messages');
166
+        EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_LIBRARIES.'messages');
167 167
         if (EEH_Autoloader::$debug === 'times' || EEH_Autoloader::$debug === 'all') {
168 168
             EEH_Debug_Tools::instance()->show_times();
169 169
         }
@@ -205,7 +205,7 @@  discard block
 block discarded – undo
205 205
      */
206 206
     public static function register_line_item_display_autoloaders()
207 207
     {
208
-        EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_LIBRARIES . 'line_item_display', true);
208
+        EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_LIBRARIES.'line_item_display', true);
209 209
     }
210 210
 
211 211
 
@@ -218,7 +218,7 @@  discard block
 block discarded – undo
218 218
      */
219 219
     public static function register_line_item_filter_autoloaders()
220 220
     {
221
-        EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_LIBRARIES . 'line_item_filters', true);
221
+        EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_LIBRARIES.'line_item_filters', true);
222 222
     }
223 223
 
224 224
 
@@ -231,7 +231,7 @@  discard block
 block discarded – undo
231 231
      */
232 232
     public static function register_template_part_autoloaders()
233 233
     {
234
-        EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_LIBRARIES . 'template_parts', true);
234
+        EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_LIBRARIES.'template_parts', true);
235 235
     }
236 236
 
237 237
 
@@ -241,7 +241,7 @@  discard block
 block discarded – undo
241 241
      */
242 242
     public static function register_business_classes()
243 243
     {
244
-        EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_CORE . 'business');
244
+        EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_CORE.'business');
245 245
     }
246 246
 
247 247
 
@@ -264,11 +264,11 @@  discard block
 block discarded – undo
264 264
             EEH_Debug_Tools::instance()->start_timer(basename($folder));
265 265
         }
266 266
         // make sure last char is a /
267
-        $folder .= $folder[ strlen($folder) - 1 ] !== '/' ? '/' : '';
267
+        $folder .= $folder[strlen($folder) - 1] !== '/' ? '/' : '';
268 268
         $class_to_filepath_map = array();
269
-        $exclude = array( 'index' );
269
+        $exclude = array('index');
270 270
         // get all the files in that folder that end in php
271
-        $filepaths = glob($folder . '*');
271
+        $filepaths = glob($folder.'*');
272 272
 
273 273
         if (empty($filepaths)) {
274 274
             return;
@@ -277,8 +277,8 @@  discard block
 block discarded – undo
277 277
         foreach ($filepaths as $filepath) {
278 278
             if (substr($filepath, -4, 4) === '.php') {
279 279
                 $class_name = EEH_File::get_classname_from_filepath_with_standard_filename($filepath);
280
-                if (! in_array($class_name, $exclude)) {
281
-                    $class_to_filepath_map [ $class_name ] = $filepath;
280
+                if ( ! in_array($class_name, $exclude)) {
281
+                    $class_to_filepath_map [$class_name] = $filepath;
282 282
                 }
283 283
             } elseif ($recursive) {
284 284
                 EEH_Autoloader::register_autoloaders_for_each_file_in_folder($filepath, $recursive, $debug);
@@ -303,8 +303,8 @@  discard block
 block discarded – undo
303 303
      */
304 304
     public static function add_alias($class_name, $alias)
305 305
     {
306
-        if (isset(self::$_autoloaders[ $class_name ])) {
307
-            self::$_autoloaders[ $alias ] = self::$_autoloaders[ $class_name ];
306
+        if (isset(self::$_autoloaders[$class_name])) {
307
+            self::$_autoloaders[$alias] = self::$_autoloaders[$class_name];
308 308
         }
309 309
     }
310 310
 }
Please login to merge, or discard this patch.
Indentation   +292 added lines, -292 removed lines patch added patch discarded remove patch
@@ -13,296 +13,296 @@
 block discarded – undo
13 13
  */
14 14
 class EEH_Autoloader extends EEH_Base
15 15
 {
16
-    /**
17
-     *    instance of the EE_System object
18
-     *
19
-     * @var    $_instance
20
-     * @access    private
21
-     */
22
-    private static $_instance = null;
23
-
24
-    /**
25
-    *   $_autoloaders
26
-    *   @var array $_autoloaders
27
-    *   @access     private
28
-    */
29
-    private static $_autoloaders;
30
-
31
-    /**
32
-     * set to "paths" to display autoloader class => path mappings
33
-     * set to "times" to display autoloader loading times
34
-     * set to "all" to display both
35
-     *
36
-     * @var string $debug
37
-     * @access    private
38
-     */
39
-    public static $debug = false;
40
-
41
-
42
-    /**
43
-     *    class constructor
44
-     *
45
-     * @access    private
46
-     * @return \EEH_Autoloader
47
-     * @throws Exception
48
-     */
49
-    private function __construct()
50
-    {
51
-        if (self::$_autoloaders === null) {
52
-            self::$_autoloaders = array();
53
-            $this->_register_custom_autoloaders();
54
-            spl_autoload_register(array( $this, 'espresso_autoloader' ));
55
-        }
56
-    }
57
-
58
-
59
-
60
-    /**
61
-     * @access public
62
-     * @return EEH_Autoloader
63
-     */
64
-    public static function instance()
65
-    {
66
-        // check if class object is instantiated
67
-        if (! self::$_instance instanceof EEH_Autoloader) {
68
-            self::$_instance = new self();
69
-        }
70
-        return self::$_instance;
71
-    }
72
-
73
-
74
-
75
-    /**
76
-     *    espresso_autoloader
77
-     *
78
-     * @access    public
79
-     * @param   $class_name
80
-     * @internal  param $className
81
-     * @internal  param string $class_name - simple class name ie: session
82
-     * @return  void
83
-     */
84
-    public static function espresso_autoloader($class_name)
85
-    {
86
-        if (isset(self::$_autoloaders[ $class_name ])) {
87
-            require_once(self::$_autoloaders[ $class_name ]);
88
-        }
89
-    }
90
-
91
-
92
-
93
-    /**
94
-     *    register_autoloader
95
-     *
96
-     * @access    public
97
-     * @param array | string $class_paths - array of key => value pairings between class names and paths
98
-     * @param bool           $read_check  true if we need to check whether the file is readable or not.
99
-     * @param bool           $debug **deprecated**
100
-     * @throws \EE_Error
101
-     */
102
-    public static function register_autoloader($class_paths, $read_check = true, $debug = false)
103
-    {
104
-        $class_paths = is_array($class_paths) ? $class_paths : array( $class_paths );
105
-        foreach ($class_paths as $class => $path) {
106
-            // skip all files that are not PHP
107
-            if (substr($path, strlen($path) - 3) !== 'php') {
108
-                continue;
109
-            }
110
-            // don't give up! you gotta...
111
-            // get some class
112
-            if (empty($class)) {
113
-                throw new EE_Error(sprintf(esc_html__('No Class name was specified while registering an autoloader for the following path: %s.', 'event_espresso'), $path));
114
-            }
115
-            // one day you will find the path young grasshopper
116
-            if (empty($path)) {
117
-                throw new EE_Error(sprintf(esc_html__('No path was specified while registering an autoloader for the %s class.', 'event_espresso'), $class));
118
-            }
119
-            // is file readable ?
120
-            if ($read_check && ! is_readable($path)) {
121
-                throw new EE_Error(sprintf(esc_html__('The file for the %s class could not be found or is not readable due to file permissions. Please ensure the following path is correct: %s', 'event_espresso'), $class, $path));
122
-            }
123
-            if (! isset(self::$_autoloaders[ $class ])) {
124
-                self::$_autoloaders[ $class ] = str_replace(array( '/', '\\' ), '/', $path);
125
-                if (EE_DEBUG && ( EEH_Autoloader::$debug === 'paths' || EEH_Autoloader::$debug === 'all' || $debug )) {
126
-                    EEH_Debug_Tools::printr(self::$_autoloaders[ $class ], $class, __FILE__, __LINE__);
127
-                }
128
-            }
129
-        }
130
-    }
131
-
132
-
133
-
134
-
135
-    /**
136
-     *  get_autoloaders
137
-     *
138
-     *  @access public
139
-     *  @return array
140
-     */
141
-    public static function get_autoloaders()
142
-    {
143
-        return self::$_autoloaders;
144
-    }
145
-
146
-
147
-    /**
148
-     *  register core, model and class 'autoloaders'
149
-     *
150
-     * @access private
151
-     * @return void
152
-     * @throws EE_Error
153
-     */
154
-    private function _register_custom_autoloaders()
155
-    {
156
-        EEH_Autoloader::$debug = '';
157
-        \EEH_Autoloader::register_helpers_autoloaders();
158
-        EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_CORE . 'interfaces');
159
-        EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_CORE);
160
-        EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_INTERFACES, true);
161
-        EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_MODELS, true);
162
-        EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_CLASSES);
163
-        EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_FORM_SECTIONS, true);
164
-        EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_LIBRARIES . 'messages');
165
-        if (EEH_Autoloader::$debug === 'times' || EEH_Autoloader::$debug === 'all') {
166
-            EEH_Debug_Tools::instance()->show_times();
167
-        }
168
-    }
169
-
170
-
171
-
172
-    /**
173
-     *    register core, model and class 'autoloaders'
174
-     *
175
-     * @access public
176
-     */
177
-    public static function register_helpers_autoloaders()
178
-    {
179
-        EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_HELPERS);
180
-    }
181
-
182
-
183
-
184
-
185
-    /**
186
-     *  register core, model and class 'autoloaders'
187
-     *
188
-     *  @access public
189
-     *  @return void
190
-     */
191
-    public static function register_form_sections_autoloaders()
192
-    {
193
-        // EEH_Autoloader::register_autoloaders_for_each_file_in_folder( EE_FORM_SECTIONS, true );
194
-    }
195
-
196
-
197
-    /**
198
-     *  register core, model and class 'autoloaders'
199
-     *
200
-     * @access public
201
-     * @return void
202
-     * @throws EE_Error
203
-     */
204
-    public static function register_line_item_display_autoloaders()
205
-    {
206
-        EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_LIBRARIES . 'line_item_display', true);
207
-    }
208
-
209
-
210
-    /**
211
-     *  register core, model and class 'autoloaders'
212
-     *
213
-     * @access public
214
-     * @return void
215
-     * @throws EE_Error
216
-     */
217
-    public static function register_line_item_filter_autoloaders()
218
-    {
219
-        EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_LIBRARIES . 'line_item_filters', true);
220
-    }
221
-
222
-
223
-    /**
224
-     *  register template part 'autoloaders'
225
-     *
226
-     * @access public
227
-     * @return void
228
-     * @throws EE_Error
229
-     */
230
-    public static function register_template_part_autoloaders()
231
-    {
232
-        EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_LIBRARIES . 'template_parts', true);
233
-    }
234
-
235
-
236
-    /**
237
-     * @return void
238
-     * @throws EE_Error
239
-     */
240
-    public static function register_business_classes()
241
-    {
242
-        EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_CORE . 'business');
243
-    }
244
-
245
-
246
-
247
-    /**
248
-     * Assumes all the files in this folder have the normal naming scheme (namely that their classname
249
-     * is the file's name, plus ".whatever.php".) and adds each of them to the autoloader list.
250
-     * If that's not the case, you'll need to improve this function or just use EEH_File::get_classname_from_filepath_with_standard_filename() directly.
251
-     * Yes this has to scan the directory for files, but it only does it once -- not on EACH
252
-     * time the autoloader is used
253
-     *
254
-     * @param string $folder name, with or without trailing /, doesn't matter
255
-     * @param bool   $recursive
256
-     * @param bool   $debug  **deprecated**
257
-     * @throws \EE_Error
258
-     */
259
-    public static function register_autoloaders_for_each_file_in_folder($folder, $recursive = false, $debug = false)
260
-    {
261
-        if (EEH_Autoloader::$debug === 'times' || EEH_Autoloader::$debug === 'all' || $debug) {
262
-            EEH_Debug_Tools::instance()->start_timer(basename($folder));
263
-        }
264
-        // make sure last char is a /
265
-        $folder .= $folder[ strlen($folder) - 1 ] !== '/' ? '/' : '';
266
-        $class_to_filepath_map = array();
267
-        $exclude = array( 'index' );
268
-        // get all the files in that folder that end in php
269
-        $filepaths = glob($folder . '*');
270
-
271
-        if (empty($filepaths)) {
272
-            return;
273
-        }
274
-
275
-        foreach ($filepaths as $filepath) {
276
-            if (substr($filepath, -4, 4) === '.php') {
277
-                $class_name = EEH_File::get_classname_from_filepath_with_standard_filename($filepath);
278
-                if (! in_array($class_name, $exclude)) {
279
-                    $class_to_filepath_map [ $class_name ] = $filepath;
280
-                }
281
-            } elseif ($recursive) {
282
-                EEH_Autoloader::register_autoloaders_for_each_file_in_folder($filepath, $recursive, $debug);
283
-            }
284
-        }
285
-        // we remove the necessity to do a is_readable() check via the $read_check flag because glob by nature will not return non_readable files/directories.
286
-        self::register_autoloader($class_to_filepath_map, false, $debug);
287
-        if (EEH_Autoloader::$debug === 'times' || EEH_Autoloader::$debug === 'all') {
288
-            EEH_Debug_Tools::instance()->stop_timer(basename($folder));
289
-        }
290
-    }
291
-
292
-
293
-
294
-    /**
295
-     * add_alias
296
-     * register additional autoloader based on variation of the classname for an existing autoloader
297
-     *
298
-     * @access    public
299
-     * @param string $class_name - simple class name ie: EE_Session
300
-     * @param string $alias - variation on class name ie: EE_session, session, etc
301
-     */
302
-    public static function add_alias($class_name, $alias)
303
-    {
304
-        if (isset(self::$_autoloaders[ $class_name ])) {
305
-            self::$_autoloaders[ $alias ] = self::$_autoloaders[ $class_name ];
306
-        }
307
-    }
16
+	/**
17
+	 *    instance of the EE_System object
18
+	 *
19
+	 * @var    $_instance
20
+	 * @access    private
21
+	 */
22
+	private static $_instance = null;
23
+
24
+	/**
25
+	 *   $_autoloaders
26
+	 *   @var array $_autoloaders
27
+	 *   @access     private
28
+	 */
29
+	private static $_autoloaders;
30
+
31
+	/**
32
+	 * set to "paths" to display autoloader class => path mappings
33
+	 * set to "times" to display autoloader loading times
34
+	 * set to "all" to display both
35
+	 *
36
+	 * @var string $debug
37
+	 * @access    private
38
+	 */
39
+	public static $debug = false;
40
+
41
+
42
+	/**
43
+	 *    class constructor
44
+	 *
45
+	 * @access    private
46
+	 * @return \EEH_Autoloader
47
+	 * @throws Exception
48
+	 */
49
+	private function __construct()
50
+	{
51
+		if (self::$_autoloaders === null) {
52
+			self::$_autoloaders = array();
53
+			$this->_register_custom_autoloaders();
54
+			spl_autoload_register(array( $this, 'espresso_autoloader' ));
55
+		}
56
+	}
57
+
58
+
59
+
60
+	/**
61
+	 * @access public
62
+	 * @return EEH_Autoloader
63
+	 */
64
+	public static function instance()
65
+	{
66
+		// check if class object is instantiated
67
+		if (! self::$_instance instanceof EEH_Autoloader) {
68
+			self::$_instance = new self();
69
+		}
70
+		return self::$_instance;
71
+	}
72
+
73
+
74
+
75
+	/**
76
+	 *    espresso_autoloader
77
+	 *
78
+	 * @access    public
79
+	 * @param   $class_name
80
+	 * @internal  param $className
81
+	 * @internal  param string $class_name - simple class name ie: session
82
+	 * @return  void
83
+	 */
84
+	public static function espresso_autoloader($class_name)
85
+	{
86
+		if (isset(self::$_autoloaders[ $class_name ])) {
87
+			require_once(self::$_autoloaders[ $class_name ]);
88
+		}
89
+	}
90
+
91
+
92
+
93
+	/**
94
+	 *    register_autoloader
95
+	 *
96
+	 * @access    public
97
+	 * @param array | string $class_paths - array of key => value pairings between class names and paths
98
+	 * @param bool           $read_check  true if we need to check whether the file is readable or not.
99
+	 * @param bool           $debug **deprecated**
100
+	 * @throws \EE_Error
101
+	 */
102
+	public static function register_autoloader($class_paths, $read_check = true, $debug = false)
103
+	{
104
+		$class_paths = is_array($class_paths) ? $class_paths : array( $class_paths );
105
+		foreach ($class_paths as $class => $path) {
106
+			// skip all files that are not PHP
107
+			if (substr($path, strlen($path) - 3) !== 'php') {
108
+				continue;
109
+			}
110
+			// don't give up! you gotta...
111
+			// get some class
112
+			if (empty($class)) {
113
+				throw new EE_Error(sprintf(esc_html__('No Class name was specified while registering an autoloader for the following path: %s.', 'event_espresso'), $path));
114
+			}
115
+			// one day you will find the path young grasshopper
116
+			if (empty($path)) {
117
+				throw new EE_Error(sprintf(esc_html__('No path was specified while registering an autoloader for the %s class.', 'event_espresso'), $class));
118
+			}
119
+			// is file readable ?
120
+			if ($read_check && ! is_readable($path)) {
121
+				throw new EE_Error(sprintf(esc_html__('The file for the %s class could not be found or is not readable due to file permissions. Please ensure the following path is correct: %s', 'event_espresso'), $class, $path));
122
+			}
123
+			if (! isset(self::$_autoloaders[ $class ])) {
124
+				self::$_autoloaders[ $class ] = str_replace(array( '/', '\\' ), '/', $path);
125
+				if (EE_DEBUG && ( EEH_Autoloader::$debug === 'paths' || EEH_Autoloader::$debug === 'all' || $debug )) {
126
+					EEH_Debug_Tools::printr(self::$_autoloaders[ $class ], $class, __FILE__, __LINE__);
127
+				}
128
+			}
129
+		}
130
+	}
131
+
132
+
133
+
134
+
135
+	/**
136
+	 *  get_autoloaders
137
+	 *
138
+	 *  @access public
139
+	 *  @return array
140
+	 */
141
+	public static function get_autoloaders()
142
+	{
143
+		return self::$_autoloaders;
144
+	}
145
+
146
+
147
+	/**
148
+	 *  register core, model and class 'autoloaders'
149
+	 *
150
+	 * @access private
151
+	 * @return void
152
+	 * @throws EE_Error
153
+	 */
154
+	private function _register_custom_autoloaders()
155
+	{
156
+		EEH_Autoloader::$debug = '';
157
+		\EEH_Autoloader::register_helpers_autoloaders();
158
+		EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_CORE . 'interfaces');
159
+		EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_CORE);
160
+		EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_INTERFACES, true);
161
+		EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_MODELS, true);
162
+		EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_CLASSES);
163
+		EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_FORM_SECTIONS, true);
164
+		EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_LIBRARIES . 'messages');
165
+		if (EEH_Autoloader::$debug === 'times' || EEH_Autoloader::$debug === 'all') {
166
+			EEH_Debug_Tools::instance()->show_times();
167
+		}
168
+	}
169
+
170
+
171
+
172
+	/**
173
+	 *    register core, model and class 'autoloaders'
174
+	 *
175
+	 * @access public
176
+	 */
177
+	public static function register_helpers_autoloaders()
178
+	{
179
+		EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_HELPERS);
180
+	}
181
+
182
+
183
+
184
+
185
+	/**
186
+	 *  register core, model and class 'autoloaders'
187
+	 *
188
+	 *  @access public
189
+	 *  @return void
190
+	 */
191
+	public static function register_form_sections_autoloaders()
192
+	{
193
+		// EEH_Autoloader::register_autoloaders_for_each_file_in_folder( EE_FORM_SECTIONS, true );
194
+	}
195
+
196
+
197
+	/**
198
+	 *  register core, model and class 'autoloaders'
199
+	 *
200
+	 * @access public
201
+	 * @return void
202
+	 * @throws EE_Error
203
+	 */
204
+	public static function register_line_item_display_autoloaders()
205
+	{
206
+		EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_LIBRARIES . 'line_item_display', true);
207
+	}
208
+
209
+
210
+	/**
211
+	 *  register core, model and class 'autoloaders'
212
+	 *
213
+	 * @access public
214
+	 * @return void
215
+	 * @throws EE_Error
216
+	 */
217
+	public static function register_line_item_filter_autoloaders()
218
+	{
219
+		EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_LIBRARIES . 'line_item_filters', true);
220
+	}
221
+
222
+
223
+	/**
224
+	 *  register template part 'autoloaders'
225
+	 *
226
+	 * @access public
227
+	 * @return void
228
+	 * @throws EE_Error
229
+	 */
230
+	public static function register_template_part_autoloaders()
231
+	{
232
+		EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_LIBRARIES . 'template_parts', true);
233
+	}
234
+
235
+
236
+	/**
237
+	 * @return void
238
+	 * @throws EE_Error
239
+	 */
240
+	public static function register_business_classes()
241
+	{
242
+		EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_CORE . 'business');
243
+	}
244
+
245
+
246
+
247
+	/**
248
+	 * Assumes all the files in this folder have the normal naming scheme (namely that their classname
249
+	 * is the file's name, plus ".whatever.php".) and adds each of them to the autoloader list.
250
+	 * If that's not the case, you'll need to improve this function or just use EEH_File::get_classname_from_filepath_with_standard_filename() directly.
251
+	 * Yes this has to scan the directory for files, but it only does it once -- not on EACH
252
+	 * time the autoloader is used
253
+	 *
254
+	 * @param string $folder name, with or without trailing /, doesn't matter
255
+	 * @param bool   $recursive
256
+	 * @param bool   $debug  **deprecated**
257
+	 * @throws \EE_Error
258
+	 */
259
+	public static function register_autoloaders_for_each_file_in_folder($folder, $recursive = false, $debug = false)
260
+	{
261
+		if (EEH_Autoloader::$debug === 'times' || EEH_Autoloader::$debug === 'all' || $debug) {
262
+			EEH_Debug_Tools::instance()->start_timer(basename($folder));
263
+		}
264
+		// make sure last char is a /
265
+		$folder .= $folder[ strlen($folder) - 1 ] !== '/' ? '/' : '';
266
+		$class_to_filepath_map = array();
267
+		$exclude = array( 'index' );
268
+		// get all the files in that folder that end in php
269
+		$filepaths = glob($folder . '*');
270
+
271
+		if (empty($filepaths)) {
272
+			return;
273
+		}
274
+
275
+		foreach ($filepaths as $filepath) {
276
+			if (substr($filepath, -4, 4) === '.php') {
277
+				$class_name = EEH_File::get_classname_from_filepath_with_standard_filename($filepath);
278
+				if (! in_array($class_name, $exclude)) {
279
+					$class_to_filepath_map [ $class_name ] = $filepath;
280
+				}
281
+			} elseif ($recursive) {
282
+				EEH_Autoloader::register_autoloaders_for_each_file_in_folder($filepath, $recursive, $debug);
283
+			}
284
+		}
285
+		// we remove the necessity to do a is_readable() check via the $read_check flag because glob by nature will not return non_readable files/directories.
286
+		self::register_autoloader($class_to_filepath_map, false, $debug);
287
+		if (EEH_Autoloader::$debug === 'times' || EEH_Autoloader::$debug === 'all') {
288
+			EEH_Debug_Tools::instance()->stop_timer(basename($folder));
289
+		}
290
+	}
291
+
292
+
293
+
294
+	/**
295
+	 * add_alias
296
+	 * register additional autoloader based on variation of the classname for an existing autoloader
297
+	 *
298
+	 * @access    public
299
+	 * @param string $class_name - simple class name ie: EE_Session
300
+	 * @param string $alias - variation on class name ie: EE_session, session, etc
301
+	 */
302
+	public static function add_alias($class_name, $alias)
303
+	{
304
+		if (isset(self::$_autoloaders[ $class_name ])) {
305
+			self::$_autoloaders[ $alias ] = self::$_autoloaders[ $class_name ];
306
+		}
307
+	}
308 308
 }
Please login to merge, or discard this patch.
core/helpers/EEH_Template_Validator.helper.php 2 patches
Spacing   +13 added lines, -13 removed lines patch added patch discarded remove patch
@@ -40,10 +40,10 @@  discard block
 block discarded – undo
40 40
      */
41 41
     public static function verify_is_array_of($variable_to_test, $name_of_variable, $class_name, $allow_null = 'allow_null')
42 42
     {
43
-        if (!WP_DEBUG) {
43
+        if ( ! WP_DEBUG) {
44 44
             return;
45 45
         }
46
-        self::verify_argument_is_one_of($allow_null, 'allow_null', array('allow_null','do_not_allow_null'));
46
+        self::verify_argument_is_one_of($allow_null, 'allow_null', array('allow_null', 'do_not_allow_null'));
47 47
         if ('allow_null' == $allow_null && is_null($variable_to_test)) {
48 48
             return;
49 49
         }
@@ -66,7 +66,7 @@  discard block
 block discarded – undo
66 66
      */
67 67
     public static function verify_isnt_null($variable_to_test, $name_of_variable)
68 68
     {
69
-        if (!WP_DEBUG) {
69
+        if ( ! WP_DEBUG) {
70 70
             return;
71 71
         }
72 72
         if ($variable_to_test == null && $variable_to_test != 0 && $variable_to_test != false) {
@@ -86,10 +86,10 @@  discard block
 block discarded – undo
86 86
      */
87 87
     public static function verify_is_true($expression_to_test, $expression_string_representation)
88 88
     {
89
-        if (!WP_DEBUG) {
89
+        if ( ! WP_DEBUG) {
90 90
             return;
91 91
         }
92
-        if (!$expression_to_test) {
92
+        if ( ! $expression_to_test) {
93 93
             $error[] = esc_html__('Template error.', 'event_espresso');
94 94
             $error[] = esc_html__("%s evaluated to false, but it must be true!", 'event_espresso');
95 95
             throw new EE_Error(sprintf(implode(",", $error), $expression_string_representation));
@@ -110,14 +110,14 @@  discard block
 block discarded – undo
110 110
      */
111 111
     public static function verify_instanceof($variable_to_test, $name_of_variable, $class_name, $allow_null = 'do_not_allow_null')
112 112
     {
113
-        if (!WP_DEBUG) {
113
+        if ( ! WP_DEBUG) {
114 114
             return;
115 115
         }
116
-        self::verify_argument_is_one_of($allow_null, 'allow_null', array('allow_null','do_not_allow_null'));
116
+        self::verify_argument_is_one_of($allow_null, 'allow_null', array('allow_null', 'do_not_allow_null'));
117 117
         if ($allow_null == 'allow_null' && is_null($variable_to_test)) {
118 118
             return;
119 119
         }
120
-        if ($variable_to_test == null ||  ! ( $variable_to_test instanceof $class_name )) {
120
+        if ($variable_to_test == null || ! ($variable_to_test instanceof $class_name)) {
121 121
             $msg[] = esc_html__('Variable %s is not of the correct type.', 'event_espresso');
122 122
             $msg[] = esc_html__("It should be of type %s", 'event_espresso');
123 123
             throw new EE_Error(sprintf(implode(",", $msg), $name_of_variable, $name_of_variable, $class_name));
@@ -138,14 +138,14 @@  discard block
 block discarded – undo
138 138
      */
139 139
     public static function verify_is_array($variable_to_test, $variable_name, $allow_empty = 'allow_empty')
140 140
     {
141
-        if (!WP_DEBUG) {
141
+        if ( ! WP_DEBUG) {
142 142
             return;
143 143
         }
144
-        self::verify_argument_is_one_of($allow_empty, $variable_name, array('allow_empty','do_not_allow_empty'));
144
+        self::verify_argument_is_one_of($allow_empty, $variable_name, array('allow_empty', 'do_not_allow_empty'));
145 145
         if (empty($variable_to_test) && 'allow_empty' == $allow_empty) {
146 146
             return;
147 147
         }
148
-        if (!is_array($variable_to_test)) {
148
+        if ( ! is_array($variable_to_test)) {
149 149
             $error[] = esc_html__('Variable %s should be an array, but it is not.', 'event_espresso');
150 150
             $error[] = esc_html__("Its value is, instead '%s'", 'event_espresso');
151 151
             throw new EE_Error(sprintf(implode(",", $error), $variable_name, $variable_name, $variable_to_test));
@@ -168,10 +168,10 @@  discard block
 block discarded – undo
168 168
      */
169 169
     public static function verify_argument_is_one_of($variable_to_test, $variable_name, $string_options)
170 170
     {
171
-        if (!WP_DEBUG) {
171
+        if ( ! WP_DEBUG) {
172 172
             return;
173 173
         }
174
-        if (!in_array($variable_to_test, $string_options)) {
174
+        if ( ! in_array($variable_to_test, $string_options)) {
175 175
             $msg[0] = esc_html__('Malconfigured template.', 'event_espresso');
176 176
             $msg[1] = esc_html__("Variable named '%s' was set to '%s'. It can only be one of '%s'", 'event_espresso');
177 177
             throw new EE_Error(sprintf(implode("||", $msg), $variable_name, $variable_to_test, implode("', '", $string_options)));
Please login to merge, or discard this patch.
Indentation   +148 added lines, -148 removed lines patch added patch discarded remove patch
@@ -24,152 +24,152 @@
 block discarded – undo
24 24
  */
25 25
 class EEH_Template_Validator
26 26
 {
27
-    /**
28
-     * Throws an EE_Error if $variabel_to_test isn't an array of objects of class $class_name
29
-     * @param mixed $variable_to_test
30
-     * @param string $name_of_variable helpful in throwing intelligent errors
31
-     * @param string $class_name eg EE_Answer, EE_Transaction, etc.
32
-     * @param string $allow_null one of 'allow_null', or 'do_not_allow_null'
33
-     * @return void
34
-     * @throws EE_Error (indirectly)
35
-     */
36
-    public static function verify_is_array_of($variable_to_test, $name_of_variable, $class_name, $allow_null = 'allow_null')
37
-    {
38
-        if (!WP_DEBUG) {
39
-            return;
40
-        }
41
-        self::verify_argument_is_one_of($allow_null, 'allow_null', array('allow_null','do_not_allow_null'));
42
-        if ('allow_null' == $allow_null && is_null($variable_to_test)) {
43
-            return;
44
-        }
45
-        self::verify_is_array($variable_to_test, $name_of_variable);
46
-        foreach ($variable_to_test as $key => $array_element) {
47
-            self::verify_instanceof($array_element, $key, $class_name);
48
-        }
49
-    }
50
-
51
-
52
-
53
-
54
-
55
-    /**
56
-     * throws an EE_Error if $variable_to_test is null
57
-     * @param mixed $variable_to_test
58
-     * @param string $name_of_variable helpful for throwing intelligent errors
59
-     * @return void
60
-     * @throws EE_Error
61
-     */
62
-    public static function verify_isnt_null($variable_to_test, $name_of_variable)
63
-    {
64
-        if (!WP_DEBUG) {
65
-            return;
66
-        }
67
-        if ($variable_to_test == null && $variable_to_test != 0 && $variable_to_test != false) {
68
-            $error[] = esc_html__('Variable named %s is null.', 'event_espresso');
69
-            $error[] = esc_html__("Consider looking at the stack trace to see why it wasn't set.", 'event_espresso');
70
-            throw new EE_Error(sprintf(implode(",", $error), $name_of_variable, $name_of_variable));
71
-        }
72
-    }
73
-
74
-    /**
75
-     * When WP_DEBUG is activted, throws an error if $expression_to_test is false.
76
-     * @param boolean $expression_to_test
77
-     * @param string $expression_string_representation a string representation of your expression
78
-     * for example, if your expression were $var1==23, then this should be '$var1==23'
79
-     * @return void
80
-     * @throws EE_Error
81
-     */
82
-    public static function verify_is_true($expression_to_test, $expression_string_representation)
83
-    {
84
-        if (!WP_DEBUG) {
85
-            return;
86
-        }
87
-        if (!$expression_to_test) {
88
-            $error[] = esc_html__('Template error.', 'event_espresso');
89
-            $error[] = esc_html__("%s evaluated to false, but it must be true!", 'event_espresso');
90
-            throw new EE_Error(sprintf(implode(",", $error), $expression_string_representation));
91
-        }
92
-    }
93
-
94
-
95
-
96
-
97
-
98
-    /**
99
-     * For verifying that a variable is indeed an object of class $class_name
100
-     * @param mixed $variable_to_test
101
-     * @param string $name_of_variable helpful when throwing errors
102
-     * @param string $class_name eg, EE_Answer,
103
-     * @return void
104
-     * @throws EE_Error
105
-     */
106
-    public static function verify_instanceof($variable_to_test, $name_of_variable, $class_name, $allow_null = 'do_not_allow_null')
107
-    {
108
-        if (!WP_DEBUG) {
109
-            return;
110
-        }
111
-        self::verify_argument_is_one_of($allow_null, 'allow_null', array('allow_null','do_not_allow_null'));
112
-        if ($allow_null == 'allow_null' && is_null($variable_to_test)) {
113
-            return;
114
-        }
115
-        if ($variable_to_test == null ||  ! ( $variable_to_test instanceof $class_name )) {
116
-            $msg[] = esc_html__('Variable %s is not of the correct type.', 'event_espresso');
117
-            $msg[] = esc_html__("It should be of type %s", 'event_espresso');
118
-            throw new EE_Error(sprintf(implode(",", $msg), $name_of_variable, $name_of_variable, $class_name));
119
-        }
120
-    }
121
-
122
-
123
-
124
-
125
-
126
-    /**
127
-     * For verifying that a variable is indeed an array, else throw an EE_Error
128
-     * @param type $variable_to_test
129
-     * @param type $variable_name
130
-     * @param type $allow_empty one of 'allow_empty' or 'do_not_allow_empty'
131
-     * @return void
132
-     * @throws EE_Error
133
-     */
134
-    public static function verify_is_array($variable_to_test, $variable_name, $allow_empty = 'allow_empty')
135
-    {
136
-        if (!WP_DEBUG) {
137
-            return;
138
-        }
139
-        self::verify_argument_is_one_of($allow_empty, $variable_name, array('allow_empty','do_not_allow_empty'));
140
-        if (empty($variable_to_test) && 'allow_empty' == $allow_empty) {
141
-            return;
142
-        }
143
-        if (!is_array($variable_to_test)) {
144
-            $error[] = esc_html__('Variable %s should be an array, but it is not.', 'event_espresso');
145
-            $error[] = esc_html__("Its value is, instead '%s'", 'event_espresso');
146
-            throw new EE_Error(sprintf(implode(",", $error), $variable_name, $variable_name, $variable_to_test));
147
-        }
148
-    }
149
-
150
-
151
-
152
-
153
-
154
-
155
-
156
-    /**
157
-     * for verifying that a variable is one of the string optiosn supplied
158
-     * @param mixed $variable_to_test
159
-     * @param mixed $variable_name the name you've given the variable. Eg, '$foo'. THis helps in producing better error messages
160
-     * @param array $string_options an array of acceptable values
161
-     * @return void
162
-     * @throws EE_Error
163
-     */
164
-    public static function verify_argument_is_one_of($variable_to_test, $variable_name, $string_options)
165
-    {
166
-        if (!WP_DEBUG) {
167
-            return;
168
-        }
169
-        if (!in_array($variable_to_test, $string_options)) {
170
-            $msg[0] = esc_html__('Malconfigured template.', 'event_espresso');
171
-            $msg[1] = esc_html__("Variable named '%s' was set to '%s'. It can only be one of '%s'", 'event_espresso');
172
-            throw new EE_Error(sprintf(implode("||", $msg), $variable_name, $variable_to_test, implode("', '", $string_options)));
173
-        }
174
-    }
27
+	/**
28
+	 * Throws an EE_Error if $variabel_to_test isn't an array of objects of class $class_name
29
+	 * @param mixed $variable_to_test
30
+	 * @param string $name_of_variable helpful in throwing intelligent errors
31
+	 * @param string $class_name eg EE_Answer, EE_Transaction, etc.
32
+	 * @param string $allow_null one of 'allow_null', or 'do_not_allow_null'
33
+	 * @return void
34
+	 * @throws EE_Error (indirectly)
35
+	 */
36
+	public static function verify_is_array_of($variable_to_test, $name_of_variable, $class_name, $allow_null = 'allow_null')
37
+	{
38
+		if (!WP_DEBUG) {
39
+			return;
40
+		}
41
+		self::verify_argument_is_one_of($allow_null, 'allow_null', array('allow_null','do_not_allow_null'));
42
+		if ('allow_null' == $allow_null && is_null($variable_to_test)) {
43
+			return;
44
+		}
45
+		self::verify_is_array($variable_to_test, $name_of_variable);
46
+		foreach ($variable_to_test as $key => $array_element) {
47
+			self::verify_instanceof($array_element, $key, $class_name);
48
+		}
49
+	}
50
+
51
+
52
+
53
+
54
+
55
+	/**
56
+	 * throws an EE_Error if $variable_to_test is null
57
+	 * @param mixed $variable_to_test
58
+	 * @param string $name_of_variable helpful for throwing intelligent errors
59
+	 * @return void
60
+	 * @throws EE_Error
61
+	 */
62
+	public static function verify_isnt_null($variable_to_test, $name_of_variable)
63
+	{
64
+		if (!WP_DEBUG) {
65
+			return;
66
+		}
67
+		if ($variable_to_test == null && $variable_to_test != 0 && $variable_to_test != false) {
68
+			$error[] = esc_html__('Variable named %s is null.', 'event_espresso');
69
+			$error[] = esc_html__("Consider looking at the stack trace to see why it wasn't set.", 'event_espresso');
70
+			throw new EE_Error(sprintf(implode(",", $error), $name_of_variable, $name_of_variable));
71
+		}
72
+	}
73
+
74
+	/**
75
+	 * When WP_DEBUG is activted, throws an error if $expression_to_test is false.
76
+	 * @param boolean $expression_to_test
77
+	 * @param string $expression_string_representation a string representation of your expression
78
+	 * for example, if your expression were $var1==23, then this should be '$var1==23'
79
+	 * @return void
80
+	 * @throws EE_Error
81
+	 */
82
+	public static function verify_is_true($expression_to_test, $expression_string_representation)
83
+	{
84
+		if (!WP_DEBUG) {
85
+			return;
86
+		}
87
+		if (!$expression_to_test) {
88
+			$error[] = esc_html__('Template error.', 'event_espresso');
89
+			$error[] = esc_html__("%s evaluated to false, but it must be true!", 'event_espresso');
90
+			throw new EE_Error(sprintf(implode(",", $error), $expression_string_representation));
91
+		}
92
+	}
93
+
94
+
95
+
96
+
97
+
98
+	/**
99
+	 * For verifying that a variable is indeed an object of class $class_name
100
+	 * @param mixed $variable_to_test
101
+	 * @param string $name_of_variable helpful when throwing errors
102
+	 * @param string $class_name eg, EE_Answer,
103
+	 * @return void
104
+	 * @throws EE_Error
105
+	 */
106
+	public static function verify_instanceof($variable_to_test, $name_of_variable, $class_name, $allow_null = 'do_not_allow_null')
107
+	{
108
+		if (!WP_DEBUG) {
109
+			return;
110
+		}
111
+		self::verify_argument_is_one_of($allow_null, 'allow_null', array('allow_null','do_not_allow_null'));
112
+		if ($allow_null == 'allow_null' && is_null($variable_to_test)) {
113
+			return;
114
+		}
115
+		if ($variable_to_test == null ||  ! ( $variable_to_test instanceof $class_name )) {
116
+			$msg[] = esc_html__('Variable %s is not of the correct type.', 'event_espresso');
117
+			$msg[] = esc_html__("It should be of type %s", 'event_espresso');
118
+			throw new EE_Error(sprintf(implode(",", $msg), $name_of_variable, $name_of_variable, $class_name));
119
+		}
120
+	}
121
+
122
+
123
+
124
+
125
+
126
+	/**
127
+	 * For verifying that a variable is indeed an array, else throw an EE_Error
128
+	 * @param type $variable_to_test
129
+	 * @param type $variable_name
130
+	 * @param type $allow_empty one of 'allow_empty' or 'do_not_allow_empty'
131
+	 * @return void
132
+	 * @throws EE_Error
133
+	 */
134
+	public static function verify_is_array($variable_to_test, $variable_name, $allow_empty = 'allow_empty')
135
+	{
136
+		if (!WP_DEBUG) {
137
+			return;
138
+		}
139
+		self::verify_argument_is_one_of($allow_empty, $variable_name, array('allow_empty','do_not_allow_empty'));
140
+		if (empty($variable_to_test) && 'allow_empty' == $allow_empty) {
141
+			return;
142
+		}
143
+		if (!is_array($variable_to_test)) {
144
+			$error[] = esc_html__('Variable %s should be an array, but it is not.', 'event_espresso');
145
+			$error[] = esc_html__("Its value is, instead '%s'", 'event_espresso');
146
+			throw new EE_Error(sprintf(implode(",", $error), $variable_name, $variable_name, $variable_to_test));
147
+		}
148
+	}
149
+
150
+
151
+
152
+
153
+
154
+
155
+
156
+	/**
157
+	 * for verifying that a variable is one of the string optiosn supplied
158
+	 * @param mixed $variable_to_test
159
+	 * @param mixed $variable_name the name you've given the variable. Eg, '$foo'. THis helps in producing better error messages
160
+	 * @param array $string_options an array of acceptable values
161
+	 * @return void
162
+	 * @throws EE_Error
163
+	 */
164
+	public static function verify_argument_is_one_of($variable_to_test, $variable_name, $string_options)
165
+	{
166
+		if (!WP_DEBUG) {
167
+			return;
168
+		}
169
+		if (!in_array($variable_to_test, $string_options)) {
170
+			$msg[0] = esc_html__('Malconfigured template.', 'event_espresso');
171
+			$msg[1] = esc_html__("Variable named '%s' was set to '%s'. It can only be one of '%s'", 'event_espresso');
172
+			throw new EE_Error(sprintf(implode("||", $msg), $variable_name, $variable_to_test, implode("', '", $string_options)));
173
+		}
174
+	}
175 175
 }
Please login to merge, or discard this patch.