Completed
Branch BUG/11294/expired-cart-ticket-... (22bfe9)
by
unknown
48:53 queued 33:02
created
core/services/loaders/CoreLoader.php 1 patch
Indentation   +109 added lines, -109 removed lines patch added patch discarded remove patch
@@ -33,115 +33,115 @@
 block discarded – undo
33 33
 class CoreLoader implements LoaderDecoratorInterface
34 34
 {
35 35
 
36
-    /**
37
-     * @var EE_Registry|CoffeeShop $generator
38
-     */
39
-    private $generator;
40
-
41
-
42
-
43
-    /**
44
-     * CoreLoader constructor.
45
-     *
46
-     * @param EE_Registry|CoffeeShop $generator
47
-     * @throws InvalidArgumentException
48
-     */
49
-    public function __construct($generator)
50
-    {
51
-        if(!($generator instanceof EE_Registry || $generator instanceof CoffeeShop)) {
52
-            throw new InvalidArgumentException(
53
-                esc_html__(
54
-                    'The CoreLoader class must receive an instance of EE_Registry or the CoffeeShop DI container.',
55
-                    'event_espresso'
56
-                )
57
-            );
58
-        }
59
-        $this->generator = $generator;
60
-    }
61
-
62
-
63
-
64
-    /**
65
-     * Calls the appropriate loading method from the installed generator;
66
-     * If EE_Registry is being used, then the additional parameters for the EE_Registry::create() method
67
-     * can be added to the $arguments array and they will be extracted and passed to EE_Registry::create(),
68
-     * but NOT to the class being instantiated.
69
-     * This is done by adding the parameters to the $arguments array as follows:
70
-     *  array(
71
-     *      'EE_Registry::create(from_db)'   => true, // boolean value, default = false
72
-     *      'EE_Registry::create(load_only)' => true, // boolean value, default = false
73
-     *      'EE_Registry::create(addon)'     => true, // boolean value, default = false
74
-     *  )
75
-     *
76
-     * @param string $fqcn
77
-     * @param array  $arguments
78
-     * @param bool   $shared
79
-     * @return mixed
80
-     * @throws OutOfBoundsException
81
-     * @throws ServiceExistsException
82
-     * @throws InstantiationException
83
-     * @throws InvalidIdentifierException
84
-     * @throws InvalidDataTypeException
85
-     * @throws InvalidClassException
86
-     * @throws EE_Error
87
-     * @throws ServiceNotFoundException
88
-     * @throws ReflectionException
89
-     */
90
-    public function load($fqcn, $arguments = array(), $shared = true)
91
-    {
92
-        $shared = filter_var($shared, FILTER_VALIDATE_BOOLEAN);
93
-        if($this->generator instanceof EE_Registry) {
94
-            // check if additional EE_Registry::create() arguments have been passed
95
-            // from_db
96
-            $from_db = isset($arguments['EE_Registry::create(from_db)'])
97
-                ? filter_var($arguments['EE_Registry::create(from_db)'], FILTER_VALIDATE_BOOLEAN)
98
-                : false;
99
-            // load_only
100
-            $load_only = isset($arguments['EE_Registry::create(load_only)'])
101
-                ? filter_var($arguments['EE_Registry::create(load_only)'], FILTER_VALIDATE_BOOLEAN)
102
-                : false;
103
-            // addon
104
-            $addon = isset($arguments['EE_Registry::create(addon)'])
105
-                ? filter_var($arguments['EE_Registry::create(addon)'], FILTER_VALIDATE_BOOLEAN)
106
-                : false;
107
-            unset(
108
-                $arguments['EE_Registry::create(from_db)'],
109
-                $arguments['EE_Registry::create(load_only)'],
110
-                $arguments['EE_Registry::create(addon)']
111
-            );
112
-            // addons need to be cached on EE_Registry
113
-            $shared = $addon ? true : $shared;
114
-            return $this->generator->create(
115
-                $fqcn,
116
-                $arguments,
117
-                $shared,
118
-                $from_db,
119
-                $load_only,
120
-                $addon
121
-            );
122
-        }
123
-        return $this->generator->brew(
124
-            $fqcn,
125
-            $arguments,
126
-            $shared ? CoffeeMaker::BREW_SHARED : CoffeeMaker::BREW_NEW
127
-        );
128
-
129
-    }
130
-
131
-
132
-
133
-    /**
134
-     * calls reset() on generator if method exists
135
-     *
136
-     * @throws EE_Error
137
-     * @throws ReflectionException
138
-     */
139
-    public function reset()
140
-    {
141
-        if ($this->generator instanceof ResettableInterface) {
142
-            $this->generator->reset();
143
-        }
144
-    }
36
+	/**
37
+	 * @var EE_Registry|CoffeeShop $generator
38
+	 */
39
+	private $generator;
40
+
41
+
42
+
43
+	/**
44
+	 * CoreLoader constructor.
45
+	 *
46
+	 * @param EE_Registry|CoffeeShop $generator
47
+	 * @throws InvalidArgumentException
48
+	 */
49
+	public function __construct($generator)
50
+	{
51
+		if(!($generator instanceof EE_Registry || $generator instanceof CoffeeShop)) {
52
+			throw new InvalidArgumentException(
53
+				esc_html__(
54
+					'The CoreLoader class must receive an instance of EE_Registry or the CoffeeShop DI container.',
55
+					'event_espresso'
56
+				)
57
+			);
58
+		}
59
+		$this->generator = $generator;
60
+	}
61
+
62
+
63
+
64
+	/**
65
+	 * Calls the appropriate loading method from the installed generator;
66
+	 * If EE_Registry is being used, then the additional parameters for the EE_Registry::create() method
67
+	 * can be added to the $arguments array and they will be extracted and passed to EE_Registry::create(),
68
+	 * but NOT to the class being instantiated.
69
+	 * This is done by adding the parameters to the $arguments array as follows:
70
+	 *  array(
71
+	 *      'EE_Registry::create(from_db)'   => true, // boolean value, default = false
72
+	 *      'EE_Registry::create(load_only)' => true, // boolean value, default = false
73
+	 *      'EE_Registry::create(addon)'     => true, // boolean value, default = false
74
+	 *  )
75
+	 *
76
+	 * @param string $fqcn
77
+	 * @param array  $arguments
78
+	 * @param bool   $shared
79
+	 * @return mixed
80
+	 * @throws OutOfBoundsException
81
+	 * @throws ServiceExistsException
82
+	 * @throws InstantiationException
83
+	 * @throws InvalidIdentifierException
84
+	 * @throws InvalidDataTypeException
85
+	 * @throws InvalidClassException
86
+	 * @throws EE_Error
87
+	 * @throws ServiceNotFoundException
88
+	 * @throws ReflectionException
89
+	 */
90
+	public function load($fqcn, $arguments = array(), $shared = true)
91
+	{
92
+		$shared = filter_var($shared, FILTER_VALIDATE_BOOLEAN);
93
+		if($this->generator instanceof EE_Registry) {
94
+			// check if additional EE_Registry::create() arguments have been passed
95
+			// from_db
96
+			$from_db = isset($arguments['EE_Registry::create(from_db)'])
97
+				? filter_var($arguments['EE_Registry::create(from_db)'], FILTER_VALIDATE_BOOLEAN)
98
+				: false;
99
+			// load_only
100
+			$load_only = isset($arguments['EE_Registry::create(load_only)'])
101
+				? filter_var($arguments['EE_Registry::create(load_only)'], FILTER_VALIDATE_BOOLEAN)
102
+				: false;
103
+			// addon
104
+			$addon = isset($arguments['EE_Registry::create(addon)'])
105
+				? filter_var($arguments['EE_Registry::create(addon)'], FILTER_VALIDATE_BOOLEAN)
106
+				: false;
107
+			unset(
108
+				$arguments['EE_Registry::create(from_db)'],
109
+				$arguments['EE_Registry::create(load_only)'],
110
+				$arguments['EE_Registry::create(addon)']
111
+			);
112
+			// addons need to be cached on EE_Registry
113
+			$shared = $addon ? true : $shared;
114
+			return $this->generator->create(
115
+				$fqcn,
116
+				$arguments,
117
+				$shared,
118
+				$from_db,
119
+				$load_only,
120
+				$addon
121
+			);
122
+		}
123
+		return $this->generator->brew(
124
+			$fqcn,
125
+			$arguments,
126
+			$shared ? CoffeeMaker::BREW_SHARED : CoffeeMaker::BREW_NEW
127
+		);
128
+
129
+	}
130
+
131
+
132
+
133
+	/**
134
+	 * calls reset() on generator if method exists
135
+	 *
136
+	 * @throws EE_Error
137
+	 * @throws ReflectionException
138
+	 */
139
+	public function reset()
140
+	{
141
+		if ($this->generator instanceof ResettableInterface) {
142
+			$this->generator->reset();
143
+		}
144
+	}
145 145
 
146 146
 }
147 147
 // End of file CoreLoader.php
Please login to merge, or discard this patch.
core/services/loaders/CachingLoader.php 2 patches
Indentation   +165 added lines, -165 removed lines patch added patch discarded remove patch
@@ -22,171 +22,171 @@
 block discarded – undo
22 22
 class CachingLoader extends CachingLoaderDecorator
23 23
 {
24 24
 
25
-    /**
26
-     * @var CollectionInterface $cache
27
-     */
28
-    protected $cache;
29
-
30
-    /**
31
-     * @var string $identifier
32
-     */
33
-    protected $identifier;
34
-
35
-
36
-
37
-    /**
38
-     * CachingLoader constructor.
39
-     *
40
-     * @param LoaderDecoratorInterface $loader
41
-     * @param CollectionInterface      $cache
42
-     * @param string                   $identifier
43
-     * @throws InvalidDataTypeException
44
-     */
45
-    public function __construct(
46
-        LoaderDecoratorInterface $loader,
47
-        CollectionInterface $cache,
48
-        $identifier = ''
49
-    ) {
50
-        parent::__construct($loader);
51
-        $this->cache = $cache;
52
-        $this->setIdentifier($identifier);
53
-        if ($this->identifier !== '') {
54
-            // to only clear this cache, and assuming an identifier has been set, simply do the following:
55
-            // do_action('AHEE__EventEspresso_core_services_loaders_CachingLoader__resetCache__IDENTIFIER');
56
-            // where "IDENTIFIER" = the string that was set during construction
57
-            add_action(
58
-                "AHEE__EventEspresso_core_services_loaders_CachingLoader__resetCache__{$identifier}",
59
-                array($this, 'reset')
60
-            );
61
-        }
62
-        // to clear ALL caches, simply do the following:
63
-        // do_action('AHEE__EventEspresso_core_services_loaders_CachingLoader__resetCache');
64
-        add_action(
65
-            'AHEE__EventEspresso_core_services_loaders_CachingLoader__resetCache',
66
-            array($this, 'reset')
67
-        );
68
-    }
69
-
70
-
71
-
72
-    /**
73
-     * @return string
74
-     */
75
-    public function identifier()
76
-    {
77
-        return $this->identifier;
78
-    }
79
-
80
-
81
-
82
-    /**
83
-     * @param string $identifier
84
-     * @throws InvalidDataTypeException
85
-     */
86
-    private function setIdentifier($identifier)
87
-    {
88
-        if (! is_string($identifier)) {
89
-            throw new InvalidDataTypeException('$identifier', $identifier, 'string');
90
-        }
91
-        $this->identifier = $identifier;
92
-    }
93
-
94
-
95
-    /**
96
-     * @param string $fqcn
97
-     * @param mixed  $object
98
-     * @return bool
99
-     * @throws InvalidArgumentException
100
-     */
101
-    public function share($fqcn, $object)
102
-    {
103
-        if ($object instanceof $fqcn) {
104
-            return $this->cache->add($object, md5($fqcn));
105
-        }
106
-        throw new InvalidArgumentException(
107
-            sprintf(
108
-                esc_html__(
109
-                    'The supplied class name "%1$s" must match the class of the supplied object.',
110
-                    'event_espresso'
111
-                ),
112
-                $fqcn
113
-            )
114
-        );
115
-    }
116
-
117
-
118
-    /**
119
-     * @param string $fqcn
120
-     * @param array  $arguments
121
-     * @param bool   $shared
122
-     * @return mixed
123
-     */
124
-    public function load($fqcn, $arguments = array(), $shared = true)
125
-    {
126
-        $fqcn = ltrim($fqcn, '\\');
127
-        // caching can be turned off via the following code:
128
-        // add_filter('FHEE__EventEspresso_core_services_loaders_CachingLoader__load__bypass_cache', '__return_true');
129
-        if(
130
-            apply_filters(
131
-                'FHEE__EventEspresso_core_services_loaders_CachingLoader__load__bypass_cache',
132
-                false,
133
-                $this
134
-            )
135
-        ){
136
-            // even though $shared might be true, caching could be bypassed for whatever reason,
137
-            // so we don't want the core loader to cache anything, therefore caching is turned off
138
-            return $this->loader->load($fqcn, $arguments, false);
139
-        }
140
-        $identifier = md5($fqcn . $this->getIdentifierForArgument($arguments));
141
-        if ($this->cache->has($identifier)) {
142
-            return $this->cache->get($identifier);
143
-        }
144
-        $object = $this->loader->load($fqcn, $arguments, $shared);
145
-        if ($object instanceof $fqcn) {
146
-            $this->cache->add($object, $identifier);
147
-        }
148
-        return $object;
149
-    }
150
-
151
-
152
-
153
-    /**
154
-     * empties cache and calls reset() on loader if method exists
155
-     */
156
-    public function reset()
157
-    {
158
-        $this->cache->trashAndDetachAll();
159
-        $this->loader->reset();
160
-    }
161
-
162
-
163
-
164
-    /**
165
-     * build a string representation of a class' arguments
166
-     * (mostly because Closures can't be serialized)
167
-     *
168
-     * @param array $arguments
169
-     * @return string
170
-     */
171
-    private function getIdentifierForArgument(array $arguments)
172
-    {
173
-        $identifier = '';
174
-        foreach ($arguments as $argument) {
175
-            switch (true) {
176
-                case is_object($argument) :
177
-                case $argument instanceof Closure :
178
-                    $identifier .= spl_object_hash($argument);
179
-                    break;
180
-                case is_array($argument) :
181
-                    $identifier .= $this->getIdentifierForArgument($argument);
182
-                    break;
183
-                default :
184
-                    $identifier .= $argument;
185
-                    break;
186
-            }
187
-        }
188
-        return $identifier;
189
-    }
25
+	/**
26
+	 * @var CollectionInterface $cache
27
+	 */
28
+	protected $cache;
29
+
30
+	/**
31
+	 * @var string $identifier
32
+	 */
33
+	protected $identifier;
34
+
35
+
36
+
37
+	/**
38
+	 * CachingLoader constructor.
39
+	 *
40
+	 * @param LoaderDecoratorInterface $loader
41
+	 * @param CollectionInterface      $cache
42
+	 * @param string                   $identifier
43
+	 * @throws InvalidDataTypeException
44
+	 */
45
+	public function __construct(
46
+		LoaderDecoratorInterface $loader,
47
+		CollectionInterface $cache,
48
+		$identifier = ''
49
+	) {
50
+		parent::__construct($loader);
51
+		$this->cache = $cache;
52
+		$this->setIdentifier($identifier);
53
+		if ($this->identifier !== '') {
54
+			// to only clear this cache, and assuming an identifier has been set, simply do the following:
55
+			// do_action('AHEE__EventEspresso_core_services_loaders_CachingLoader__resetCache__IDENTIFIER');
56
+			// where "IDENTIFIER" = the string that was set during construction
57
+			add_action(
58
+				"AHEE__EventEspresso_core_services_loaders_CachingLoader__resetCache__{$identifier}",
59
+				array($this, 'reset')
60
+			);
61
+		}
62
+		// to clear ALL caches, simply do the following:
63
+		// do_action('AHEE__EventEspresso_core_services_loaders_CachingLoader__resetCache');
64
+		add_action(
65
+			'AHEE__EventEspresso_core_services_loaders_CachingLoader__resetCache',
66
+			array($this, 'reset')
67
+		);
68
+	}
69
+
70
+
71
+
72
+	/**
73
+	 * @return string
74
+	 */
75
+	public function identifier()
76
+	{
77
+		return $this->identifier;
78
+	}
79
+
80
+
81
+
82
+	/**
83
+	 * @param string $identifier
84
+	 * @throws InvalidDataTypeException
85
+	 */
86
+	private function setIdentifier($identifier)
87
+	{
88
+		if (! is_string($identifier)) {
89
+			throw new InvalidDataTypeException('$identifier', $identifier, 'string');
90
+		}
91
+		$this->identifier = $identifier;
92
+	}
93
+
94
+
95
+	/**
96
+	 * @param string $fqcn
97
+	 * @param mixed  $object
98
+	 * @return bool
99
+	 * @throws InvalidArgumentException
100
+	 */
101
+	public function share($fqcn, $object)
102
+	{
103
+		if ($object instanceof $fqcn) {
104
+			return $this->cache->add($object, md5($fqcn));
105
+		}
106
+		throw new InvalidArgumentException(
107
+			sprintf(
108
+				esc_html__(
109
+					'The supplied class name "%1$s" must match the class of the supplied object.',
110
+					'event_espresso'
111
+				),
112
+				$fqcn
113
+			)
114
+		);
115
+	}
116
+
117
+
118
+	/**
119
+	 * @param string $fqcn
120
+	 * @param array  $arguments
121
+	 * @param bool   $shared
122
+	 * @return mixed
123
+	 */
124
+	public function load($fqcn, $arguments = array(), $shared = true)
125
+	{
126
+		$fqcn = ltrim($fqcn, '\\');
127
+		// caching can be turned off via the following code:
128
+		// add_filter('FHEE__EventEspresso_core_services_loaders_CachingLoader__load__bypass_cache', '__return_true');
129
+		if(
130
+			apply_filters(
131
+				'FHEE__EventEspresso_core_services_loaders_CachingLoader__load__bypass_cache',
132
+				false,
133
+				$this
134
+			)
135
+		){
136
+			// even though $shared might be true, caching could be bypassed for whatever reason,
137
+			// so we don't want the core loader to cache anything, therefore caching is turned off
138
+			return $this->loader->load($fqcn, $arguments, false);
139
+		}
140
+		$identifier = md5($fqcn . $this->getIdentifierForArgument($arguments));
141
+		if ($this->cache->has($identifier)) {
142
+			return $this->cache->get($identifier);
143
+		}
144
+		$object = $this->loader->load($fqcn, $arguments, $shared);
145
+		if ($object instanceof $fqcn) {
146
+			$this->cache->add($object, $identifier);
147
+		}
148
+		return $object;
149
+	}
150
+
151
+
152
+
153
+	/**
154
+	 * empties cache and calls reset() on loader if method exists
155
+	 */
156
+	public function reset()
157
+	{
158
+		$this->cache->trashAndDetachAll();
159
+		$this->loader->reset();
160
+	}
161
+
162
+
163
+
164
+	/**
165
+	 * build a string representation of a class' arguments
166
+	 * (mostly because Closures can't be serialized)
167
+	 *
168
+	 * @param array $arguments
169
+	 * @return string
170
+	 */
171
+	private function getIdentifierForArgument(array $arguments)
172
+	{
173
+		$identifier = '';
174
+		foreach ($arguments as $argument) {
175
+			switch (true) {
176
+				case is_object($argument) :
177
+				case $argument instanceof Closure :
178
+					$identifier .= spl_object_hash($argument);
179
+					break;
180
+				case is_array($argument) :
181
+					$identifier .= $this->getIdentifierForArgument($argument);
182
+					break;
183
+				default :
184
+					$identifier .= $argument;
185
+					break;
186
+			}
187
+		}
188
+		return $identifier;
189
+	}
190 190
 
191 191
 
192 192
 }
Please login to merge, or discard this patch.
Spacing   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -85,7 +85,7 @@  discard block
 block discarded – undo
85 85
      */
86 86
     private function setIdentifier($identifier)
87 87
     {
88
-        if (! is_string($identifier)) {
88
+        if ( ! is_string($identifier)) {
89 89
             throw new InvalidDataTypeException('$identifier', $identifier, 'string');
90 90
         }
91 91
         $this->identifier = $identifier;
@@ -126,18 +126,18 @@  discard block
 block discarded – undo
126 126
         $fqcn = ltrim($fqcn, '\\');
127 127
         // caching can be turned off via the following code:
128 128
         // add_filter('FHEE__EventEspresso_core_services_loaders_CachingLoader__load__bypass_cache', '__return_true');
129
-        if(
129
+        if (
130 130
             apply_filters(
131 131
                 'FHEE__EventEspresso_core_services_loaders_CachingLoader__load__bypass_cache',
132 132
                 false,
133 133
                 $this
134 134
             )
135
-        ){
135
+        ) {
136 136
             // even though $shared might be true, caching could be bypassed for whatever reason,
137 137
             // so we don't want the core loader to cache anything, therefore caching is turned off
138 138
             return $this->loader->load($fqcn, $arguments, false);
139 139
         }
140
-        $identifier = md5($fqcn . $this->getIdentifierForArgument($arguments));
140
+        $identifier = md5($fqcn.$this->getIdentifierForArgument($arguments));
141 141
         if ($this->cache->has($identifier)) {
142 142
             return $this->cache->get($identifier);
143 143
         }
Please login to merge, or discard this patch.
core/EE_System.core.php 2 patches
Spacing   +30 added lines, -30 removed lines patch added patch discarded remove patch
@@ -140,7 +140,7 @@  discard block
 block discarded – undo
140 140
         EE_Maintenance_Mode $maintenance_mode = null
141 141
     ) {
142 142
         // check if class object is instantiated
143
-        if (! self::$_instance instanceof EE_System) {
143
+        if ( ! self::$_instance instanceof EE_System) {
144 144
             self::$_instance = new self($registry, $loader, $request, $maintenance_mode);
145 145
         }
146 146
         return self::$_instance;
@@ -259,7 +259,7 @@  discard block
 block discarded – undo
259 259
         $this->capabilities = $this->loader->getShared('EE_Capabilities');
260 260
         add_action(
261 261
             'AHEE__EE_Capabilities__init_caps__before_initialization',
262
-            function ()
262
+            function()
263 263
             {
264 264
                 LoaderFactory::getLoader()->getShared('EE_Payment_Method_Manager');
265 265
             }
@@ -303,7 +303,7 @@  discard block
 block discarded – undo
303 303
     {
304 304
         // set autoloaders for all of the classes implementing EEI_Plugin_API
305 305
         // which provide helpers for EE plugin authors to more easily register certain components with EE.
306
-        EEH_Autoloader::instance()->register_autoloaders_for_each_file_in_folder(EE_LIBRARIES . 'plugin_api');
306
+        EEH_Autoloader::instance()->register_autoloaders_for_each_file_in_folder(EE_LIBRARIES.'plugin_api');
307 307
         $this->loader->getShared('EE_Request_Handler');
308 308
     }
309 309
 
@@ -323,14 +323,14 @@  discard block
 block discarded – undo
323 323
         $load_callback,
324 324
         $plugin_file_constant
325 325
     ) {
326
-        if (! defined($version_constant)) {
326
+        if ( ! defined($version_constant)) {
327 327
             return;
328 328
         }
329 329
         $addon_version = constant($version_constant);
330 330
         if ($addon_version && version_compare($addon_version, $min_version_required, '<')) {
331 331
             remove_action('AHEE__EE_System__load_espresso_addons', $load_callback);
332
-            if (! function_exists('deactivate_plugins')) {
333
-                require_once ABSPATH . 'wp-admin/includes/plugin.php';
332
+            if ( ! function_exists('deactivate_plugins')) {
333
+                require_once ABSPATH.'wp-admin/includes/plugin.php';
334 334
             }
335 335
             deactivate_plugins(plugin_basename(constant($plugin_file_constant)));
336 336
             unset($_GET['activate'], $_REQUEST['activate'], $_GET['activate-multi'], $_REQUEST['activate-multi']);
@@ -343,7 +343,7 @@  discard block
 block discarded – undo
343 343
                     $addon_name,
344 344
                     $min_version_required
345 345
                 ),
346
-                __FILE__, __FUNCTION__ . "({$addon_name})", __LINE__
346
+                __FILE__, __FUNCTION__."({$addon_name})", __LINE__
347 347
             );
348 348
             EE_Error::get_notices(false, true);
349 349
         }
@@ -393,7 +393,7 @@  discard block
 block discarded – undo
393 393
                 true
394 394
             )
395 395
         ) {
396
-            include_once EE_THIRD_PARTY . 'wp-api-basic-auth' . DS . 'basic-auth.php';
396
+            include_once EE_THIRD_PARTY.'wp-api-basic-auth'.DS.'basic-auth.php';
397 397
         }
398 398
         do_action('AHEE__EE_System__load_espresso_addons__complete');
399 399
     }
@@ -500,11 +500,11 @@  discard block
 block discarded – undo
500 500
     private function fix_espresso_db_upgrade_option($espresso_db_update = null)
501 501
     {
502 502
         do_action('FHEE__EE_System__manage_fix_espresso_db_upgrade_option__begin', $espresso_db_update);
503
-        if (! $espresso_db_update) {
503
+        if ( ! $espresso_db_update) {
504 504
             $espresso_db_update = get_option('espresso_db_update');
505 505
         }
506 506
         // check that option is an array
507
-        if (! is_array($espresso_db_update)) {
507
+        if ( ! is_array($espresso_db_update)) {
508 508
             // if option is FALSE, then it never existed
509 509
             if ($espresso_db_update === false) {
510 510
                 // make $espresso_db_update an array and save option with autoload OFF
@@ -524,10 +524,10 @@  discard block
 block discarded – undo
524 524
                     //so it must be numerically-indexed, where values are versions installed...
525 525
                     //fix it!
526 526
                     $version_string                         = $should_be_array;
527
-                    $corrected_db_update[ $version_string ] = array('unknown-date');
527
+                    $corrected_db_update[$version_string] = array('unknown-date');
528 528
                 } else {
529 529
                     //ok it checks out
530
-                    $corrected_db_update[ $should_be_version_string ] = $should_be_array;
530
+                    $corrected_db_update[$should_be_version_string] = $should_be_array;
531 531
                 }
532 532
             }
533 533
             $espresso_db_update = $corrected_db_update;
@@ -609,13 +609,13 @@  discard block
 block discarded – undo
609 609
      */
610 610
     public function update_list_of_installed_versions($version_history = null, $current_version_to_add = null)
611 611
     {
612
-        if (! $version_history) {
612
+        if ( ! $version_history) {
613 613
             $version_history = $this->fix_espresso_db_upgrade_option($version_history);
614 614
         }
615 615
         if ($current_version_to_add === null) {
616 616
             $current_version_to_add = espresso_version();
617 617
         }
618
-        $version_history[ $current_version_to_add ][] = date('Y-m-d H:i:s', time());
618
+        $version_history[$current_version_to_add][] = date('Y-m-d H:i:s', time());
619 619
         // re-save
620 620
         return update_option('espresso_db_update', $version_history);
621 621
     }
@@ -708,7 +708,7 @@  discard block
 block discarded – undo
708 708
         if ($activation_history_for_addon) {
709 709
             //it exists, so this isn't a completely new install
710 710
             //check if this version already in that list of previously installed versions
711
-            if (! isset($activation_history_for_addon[ $version_to_upgrade_to ])) {
711
+            if ( ! isset($activation_history_for_addon[$version_to_upgrade_to])) {
712 712
                 //it a version we haven't seen before
713 713
                 if ($version_is_higher === 1) {
714 714
                     $req_type = EE_System::req_type_upgrade;
@@ -788,7 +788,7 @@  discard block
 block discarded – undo
788 788
             foreach ($activation_history as $version => $times_activated) {
789 789
                 //check there is a record of when this version was activated. Otherwise,
790 790
                 //mark it as unknown
791
-                if (! $times_activated) {
791
+                if ( ! $times_activated) {
792 792
                     $times_activated = array('unknown-date');
793 793
                 }
794 794
                 if (is_string($times_activated)) {
@@ -889,7 +889,7 @@  discard block
 block discarded – undo
889 889
     private function _parse_model_names()
890 890
     {
891 891
         //get all the files in the EE_MODELS folder that end in .model.php
892
-        $models                 = glob(EE_MODELS . '*.model.php');
892
+        $models                 = glob(EE_MODELS.'*.model.php');
893 893
         $model_names            = array();
894 894
         $non_abstract_db_models = array();
895 895
         foreach ($models as $model) {
@@ -898,9 +898,9 @@  discard block
 block discarded – undo
898 898
             $short_name      = str_replace('EEM_', '', $classname);
899 899
             $reflectionClass = new ReflectionClass($classname);
900 900
             if ($reflectionClass->isSubclassOf('EEM_Base') && ! $reflectionClass->isAbstract()) {
901
-                $non_abstract_db_models[ $short_name ] = $classname;
901
+                $non_abstract_db_models[$short_name] = $classname;
902 902
             }
903
-            $model_names[ $short_name ] = $classname;
903
+            $model_names[$short_name] = $classname;
904 904
         }
905 905
         $this->registry->models                 = apply_filters('FHEE__EE_System__parse_model_names', $model_names);
906 906
         $this->registry->non_abstract_db_models = apply_filters(
@@ -919,8 +919,8 @@  discard block
 block discarded – undo
919 919
      */
920 920
     private function _maybe_brew_regular()
921 921
     {
922
-        if ((! defined('EE_DECAF') || EE_DECAF !== true) && is_readable(EE_CAFF_PATH . 'brewing_regular.php')) {
923
-            require_once EE_CAFF_PATH . 'brewing_regular.php';
922
+        if (( ! defined('EE_DECAF') || EE_DECAF !== true) && is_readable(EE_CAFF_PATH.'brewing_regular.php')) {
923
+            require_once EE_CAFF_PATH.'brewing_regular.php';
924 924
         }
925 925
     }
926 926
 
@@ -973,17 +973,17 @@  discard block
 block discarded – undo
973 973
         $class_names = EEH_Class_Tools::get_class_names_for_all_callbacks_on_hook(
974 974
             'AHEE__EE_System__register_shortcodes_modules_and_addons'
975 975
         );
976
-        if (! empty($class_names)) {
976
+        if ( ! empty($class_names)) {
977 977
             $msg = __(
978 978
                 'The following plugins, addons, or modules appear to be incompatible with this version of Event Espresso and were automatically deactivated to avoid fatal errors:',
979 979
                 'event_espresso'
980 980
             );
981 981
             $msg .= '<ul>';
982 982
             foreach ($class_names as $class_name) {
983
-                $msg .= '<li><b>Event Espresso - ' . str_replace(
983
+                $msg .= '<li><b>Event Espresso - '.str_replace(
984 984
                         array('EE_', 'EEM_', 'EED_', 'EES_', 'EEW_'), '',
985 985
                         $class_name
986
-                    ) . '</b></li>';
986
+                    ).'</b></li>';
987 987
             }
988 988
             $msg .= '</ul>';
989 989
             $msg .= __(
@@ -1054,7 +1054,7 @@  discard block
 block discarded – undo
1054 1054
     private function _deactivate_incompatible_addons()
1055 1055
     {
1056 1056
         $incompatible_addons = get_option('ee_incompatible_addons', array());
1057
-        if (! empty($incompatible_addons)) {
1057
+        if ( ! empty($incompatible_addons)) {
1058 1058
             $active_plugins = get_option('active_plugins', array());
1059 1059
             foreach ($active_plugins as $active_plugin) {
1060 1060
                 foreach ($incompatible_addons as $incompatible_addon) {
@@ -1149,10 +1149,10 @@  discard block
 block discarded – undo
1149 1149
         do_action('AHEE__EE_System__core_loaded_and_ready');
1150 1150
         // load_espresso_template_tags
1151 1151
         if (
1152
-            is_readable(EE_PUBLIC . 'template_tags.php')
1152
+            is_readable(EE_PUBLIC.'template_tags.php')
1153 1153
             && ($this->request->isFrontend() || $this->request->isIframe() || $this->request->isFeed())
1154 1154
         ) {
1155
-            require_once EE_PUBLIC . 'template_tags.php';
1155
+            require_once EE_PUBLIC.'template_tags.php';
1156 1156
         }
1157 1157
         do_action('AHEE__EE_System__set_hooks_for_shortcodes_modules_and_addons');
1158 1158
         if ($this->request->isAdmin() || $this->request->isFrontend() || $this->request->isIframe()) {
@@ -1216,13 +1216,13 @@  discard block
 block discarded – undo
1216 1216
     public static function do_not_cache()
1217 1217
     {
1218 1218
         // set no cache constants
1219
-        if (! defined('DONOTCACHEPAGE')) {
1219
+        if ( ! defined('DONOTCACHEPAGE')) {
1220 1220
             define('DONOTCACHEPAGE', true);
1221 1221
         }
1222
-        if (! defined('DONOTCACHCEOBJECT')) {
1222
+        if ( ! defined('DONOTCACHCEOBJECT')) {
1223 1223
             define('DONOTCACHCEOBJECT', true);
1224 1224
         }
1225
-        if (! defined('DONOTCACHEDB')) {
1225
+        if ( ! defined('DONOTCACHEDB')) {
1226 1226
             define('DONOTCACHEDB', true);
1227 1227
         }
1228 1228
         // add no cache headers
Please login to merge, or discard this patch.
Indentation   +1253 added lines, -1253 removed lines patch added patch discarded remove patch
@@ -24,1259 +24,1259 @@
 block discarded – undo
24 24
 {
25 25
 
26 26
 
27
-    /**
28
-     * indicates this is a 'normal' request. Ie, not activation, nor upgrade, nor activation.
29
-     * So examples of this would be a normal GET request on the frontend or backend, or a POST, etc
30
-     */
31
-    const req_type_normal = 0;
32
-
33
-    /**
34
-     * Indicates this is a brand new installation of EE so we should install
35
-     * tables and default data etc
36
-     */
37
-    const req_type_new_activation = 1;
38
-
39
-    /**
40
-     * we've detected that EE has been reactivated (or EE was activated during maintenance mode,
41
-     * and we just exited maintenance mode). We MUST check the database is setup properly
42
-     * and that default data is setup too
43
-     */
44
-    const req_type_reactivation = 2;
45
-
46
-    /**
47
-     * indicates that EE has been upgraded since its previous request.
48
-     * We may have data migration scripts to call and will want to trigger maintenance mode
49
-     */
50
-    const req_type_upgrade = 3;
51
-
52
-    /**
53
-     * TODO  will detect that EE has been DOWNGRADED. We probably don't want to run in this case...
54
-     */
55
-    const req_type_downgrade = 4;
56
-
57
-    /**
58
-     * @deprecated since version 4.6.0.dev.006
59
-     * Now whenever a new_activation is detected the request type is still just
60
-     * new_activation (same for reactivation, upgrade, downgrade etc), but if we'r ein maintenance mode
61
-     * EE_System::initialize_db_if_no_migrations_required and EE_Addon::initialize_db_if_no_migrations_required
62
-     * will instead enqueue that EE plugin's db initialization for when we're taken out of maintenance mode.
63
-     * (Specifically, when the migration manager indicates migrations are finished
64
-     * EE_Data_Migration_Manager::initialize_db_for_enqueued_ee_plugins() will be called)
65
-     */
66
-    const req_type_activation_but_not_installed = 5;
67
-
68
-    /**
69
-     * option prefix for recording the activation history (like core's "espresso_db_update") of addons
70
-     */
71
-    const addon_activation_history_option_prefix = 'ee_addon_activation_history_';
72
-
73
-
74
-    /**
75
-     * @var EE_System $_instance
76
-     */
77
-    private static $_instance;
78
-
79
-    /**
80
-     * @var EE_Registry $registry
81
-     */
82
-    private $registry;
83
-
84
-    /**
85
-     * @var LoaderInterface $loader
86
-     */
87
-    private $loader;
88
-
89
-    /**
90
-     * @var EE_Capabilities $capabilities
91
-     */
92
-    private $capabilities;
93
-
94
-    /**
95
-     * @var RequestInterface $request
96
-     */
97
-    private $request;
98
-
99
-    /**
100
-     * @var EE_Maintenance_Mode $maintenance_mode
101
-     */
102
-    private $maintenance_mode;
103
-
104
-    /**
105
-     * Stores which type of request this is, options being one of the constants on EE_System starting with req_type_*.
106
-     * It can be a brand-new activation, a reactivation, an upgrade, a downgrade, or a normal request.
107
-     *
108
-     * @var int $_req_type
109
-     */
110
-    private $_req_type;
111
-
112
-    /**
113
-     * Whether or not there was a non-micro version change in EE core version during this request
114
-     *
115
-     * @var boolean $_major_version_change
116
-     */
117
-    private $_major_version_change = false;
118
-
119
-    /**
120
-     * A Context DTO dedicated solely to identifying the current request type.
121
-     *
122
-     * @var RequestTypeContextCheckerInterface $request_type
123
-     */
124
-    private $request_type;
125
-
126
-
127
-
128
-    /**
129
-     * @singleton method used to instantiate class object
130
-     * @param EE_Registry|null         $registry
131
-     * @param LoaderInterface|null     $loader
132
-     * @param RequestInterface|null          $request
133
-     * @param EE_Maintenance_Mode|null $maintenance_mode
134
-     * @return EE_System
135
-     */
136
-    public static function instance(
137
-        EE_Registry $registry = null,
138
-        LoaderInterface $loader = null,
139
-        RequestInterface $request = null,
140
-        EE_Maintenance_Mode $maintenance_mode = null
141
-    ) {
142
-        // check if class object is instantiated
143
-        if (! self::$_instance instanceof EE_System) {
144
-            self::$_instance = new self($registry, $loader, $request, $maintenance_mode);
145
-        }
146
-        return self::$_instance;
147
-    }
148
-
149
-
150
-
151
-    /**
152
-     * resets the instance and returns it
153
-     *
154
-     * @return EE_System
155
-     */
156
-    public static function reset()
157
-    {
158
-        self::$_instance->_req_type = null;
159
-        //make sure none of the old hooks are left hanging around
160
-        remove_all_actions('AHEE__EE_System__perform_activations_upgrades_and_migrations');
161
-        //we need to reset the migration manager in order for it to detect DMSs properly
162
-        EE_Data_Migration_Manager::reset();
163
-        self::instance()->detect_activations_or_upgrades();
164
-        self::instance()->perform_activations_upgrades_and_migrations();
165
-        return self::instance();
166
-    }
167
-
168
-
169
-
170
-    /**
171
-     * sets hooks for running rest of system
172
-     * provides "AHEE__EE_System__construct__complete" hook for EE Addons to use as their starting point
173
-     * starting EE Addons from any other point may lead to problems
174
-     *
175
-     * @param EE_Registry         $registry
176
-     * @param LoaderInterface     $loader
177
-     * @param RequestInterface          $request
178
-     * @param EE_Maintenance_Mode $maintenance_mode
179
-     */
180
-    private function __construct(
181
-        EE_Registry $registry,
182
-        LoaderInterface $loader,
183
-        RequestInterface $request,
184
-        EE_Maintenance_Mode $maintenance_mode
185
-    ) {
186
-        $this->registry         = $registry;
187
-        $this->loader           = $loader;
188
-        $this->request          = $request;
189
-        $this->maintenance_mode = $maintenance_mode;
190
-        do_action('AHEE__EE_System__construct__begin', $this);
191
-        add_action(
192
-            'AHEE__EE_Bootstrap__load_espresso_addons',
193
-            array($this, 'loadCapabilities'),
194
-            5
195
-        );
196
-        add_action(
197
-            'AHEE__EE_Bootstrap__load_espresso_addons',
198
-            array($this, 'loadCommandBus'),
199
-            7
200
-        );
201
-        add_action(
202
-            'AHEE__EE_Bootstrap__load_espresso_addons',
203
-            array($this, 'loadPluginApi'),
204
-            9
205
-        );
206
-        // allow addons to load first so that they can register autoloaders, set hooks for running DMS's, etc
207
-        add_action(
208
-            'AHEE__EE_Bootstrap__load_espresso_addons',
209
-            array($this, 'load_espresso_addons')
210
-        );
211
-        // when an ee addon is activated, we want to call the core hook(s) again
212
-        // because the newly-activated addon didn't get a chance to run at all
213
-        add_action('activate_plugin', array($this, 'load_espresso_addons'), 1);
214
-        // detect whether install or upgrade
215
-        add_action(
216
-            'AHEE__EE_Bootstrap__detect_activations_or_upgrades',
217
-            array($this, 'detect_activations_or_upgrades'),
218
-            3
219
-        );
220
-        // load EE_Config, EE_Textdomain, etc
221
-        add_action(
222
-            'AHEE__EE_Bootstrap__load_core_configuration',
223
-            array($this, 'load_core_configuration'),
224
-            5
225
-        );
226
-        // load EE_Config, EE_Textdomain, etc
227
-        add_action(
228
-            'AHEE__EE_Bootstrap__register_shortcodes_modules_and_widgets',
229
-            array($this, 'register_shortcodes_modules_and_widgets'),
230
-            7
231
-        );
232
-        // you wanna get going? I wanna get going... let's get going!
233
-        add_action(
234
-            'AHEE__EE_Bootstrap__brew_espresso',
235
-            array($this, 'brew_espresso'),
236
-            9
237
-        );
238
-        //other housekeeping
239
-        //exclude EE critical pages from wp_list_pages
240
-        add_filter(
241
-            'wp_list_pages_excludes',
242
-            array($this, 'remove_pages_from_wp_list_pages'),
243
-            10
244
-        );
245
-        // ALL EE Addons should use the following hook point to attach their initial setup too
246
-        // it's extremely important for EE Addons to register any class autoloaders so that they can be available when the EE_Config loads
247
-        do_action('AHEE__EE_System__construct__complete', $this);
248
-    }
249
-
250
-
251
-    /**
252
-     * load and setup EE_Capabilities
253
-     *
254
-     * @return void
255
-     * @throws EE_Error
256
-     */
257
-    public function loadCapabilities()
258
-    {
259
-        $this->capabilities = $this->loader->getShared('EE_Capabilities');
260
-        add_action(
261
-            'AHEE__EE_Capabilities__init_caps__before_initialization',
262
-            function ()
263
-            {
264
-                LoaderFactory::getLoader()->getShared('EE_Payment_Method_Manager');
265
-            }
266
-        );
267
-    }
268
-
269
-
270
-
271
-    /**
272
-     * create and cache the CommandBus, and also add middleware
273
-     * The CapChecker middleware requires the use of EE_Capabilities
274
-     * which is why we need to load the CommandBus after Caps are set up
275
-     *
276
-     * @return void
277
-     * @throws EE_Error
278
-     */
279
-    public function loadCommandBus()
280
-    {
281
-        $this->loader->getShared(
282
-            'CommandBusInterface',
283
-            array(
284
-                null,
285
-                apply_filters(
286
-                    'FHEE__EE_Load_Espresso_Core__handle_request__CommandBus_middleware',
287
-                    array(
288
-                        $this->loader->getShared('EventEspresso\core\services\commands\middleware\CapChecker'),
289
-                        $this->loader->getShared('EventEspresso\core\services\commands\middleware\AddActionHook'),
290
-                    )
291
-                ),
292
-            )
293
-        );
294
-    }
295
-
296
-
297
-
298
-    /**
299
-     * @return void
300
-     * @throws EE_Error
301
-     */
302
-    public function loadPluginApi()
303
-    {
304
-        // set autoloaders for all of the classes implementing EEI_Plugin_API
305
-        // which provide helpers for EE plugin authors to more easily register certain components with EE.
306
-        EEH_Autoloader::instance()->register_autoloaders_for_each_file_in_folder(EE_LIBRARIES . 'plugin_api');
307
-        $this->loader->getShared('EE_Request_Handler');
308
-    }
309
-
310
-
311
-    /**
312
-     * @param string $addon_name
313
-     * @param string $version_constant
314
-     * @param string $min_version_required
315
-     * @param string $load_callback
316
-     * @param string $plugin_file_constant
317
-     * @return void
318
-     */
319
-    private function deactivateIncompatibleAddon(
320
-        $addon_name,
321
-        $version_constant,
322
-        $min_version_required,
323
-        $load_callback,
324
-        $plugin_file_constant
325
-    ) {
326
-        if (! defined($version_constant)) {
327
-            return;
328
-        }
329
-        $addon_version = constant($version_constant);
330
-        if ($addon_version && version_compare($addon_version, $min_version_required, '<')) {
331
-            remove_action('AHEE__EE_System__load_espresso_addons', $load_callback);
332
-            if (! function_exists('deactivate_plugins')) {
333
-                require_once ABSPATH . 'wp-admin/includes/plugin.php';
334
-            }
335
-            deactivate_plugins(plugin_basename(constant($plugin_file_constant)));
336
-            unset($_GET['activate'], $_REQUEST['activate'], $_GET['activate-multi'], $_REQUEST['activate-multi']);
337
-            EE_Error::add_error(
338
-                sprintf(
339
-                    esc_html__(
340
-                        'We\'re sorry, but the Event Espresso %1$s addon was deactivated because version %2$s or higher is required with this version of Event Espresso core.',
341
-                        'event_espresso'
342
-                    ),
343
-                    $addon_name,
344
-                    $min_version_required
345
-                ),
346
-                __FILE__, __FUNCTION__ . "({$addon_name})", __LINE__
347
-            );
348
-            EE_Error::get_notices(false, true);
349
-        }
350
-    }
351
-
352
-
353
-    /**
354
-     * load_espresso_addons
355
-     * allow addons to load first so that they can set hooks for running DMS's, etc
356
-     * this is hooked into both:
357
-     *    'AHEE__EE_Bootstrap__load_core_configuration'
358
-     *        which runs during the WP 'plugins_loaded' action at priority 5
359
-     *    and the WP 'activate_plugin' hook point
360
-     *
361
-     * @access public
362
-     * @return void
363
-     */
364
-    public function load_espresso_addons()
365
-    {
366
-        $this->deactivateIncompatibleAddon(
367
-            'Wait Lists',
368
-            'EE_WAIT_LISTS_VERSION',
369
-            '1.0.0.beta.074',
370
-            'load_espresso_wait_lists',
371
-            'EE_WAIT_LISTS_PLUGIN_FILE'
372
-        );
373
-        $this->deactivateIncompatibleAddon(
374
-            'Automated Upcoming Event Notifications',
375
-            'EE_AUTOMATED_UPCOMING_EVENT_NOTIFICATION_VERSION',
376
-            '1.0.0.beta.091',
377
-            'load_espresso_automated_upcoming_event_notification',
378
-            'EE_AUTOMATED_UPCOMING_EVENT_NOTIFICATION_PLUGIN_FILE'
379
-        );
380
-        do_action('AHEE__EE_System__load_espresso_addons');
381
-        //if the WP API basic auth plugin isn't already loaded, load it now.
382
-        //We want it for mobile apps. Just include the entire plugin
383
-        //also, don't load the basic auth when a plugin is getting activated, because
384
-        //it could be the basic auth plugin, and it doesn't check if its methods are already defined
385
-        //and causes a fatal error
386
-        if (
387
-            $this->request->getRequestParam('activate') !== 'true'
388
-            && ! function_exists('json_basic_auth_handler')
389
-            && ! function_exists('json_basic_auth_error')
390
-            && ! in_array(
391
-                $this->request->getRequestParam('action'),
392
-                array('activate', 'activate-selected'),
393
-                true
394
-            )
395
-        ) {
396
-            include_once EE_THIRD_PARTY . 'wp-api-basic-auth' . DS . 'basic-auth.php';
397
-        }
398
-        do_action('AHEE__EE_System__load_espresso_addons__complete');
399
-    }
400
-
401
-
402
-
403
-    /**
404
-     * detect_activations_or_upgrades
405
-     * Checks for activation or upgrade of core first;
406
-     * then also checks if any registered addons have been activated or upgraded
407
-     * This is hooked into 'AHEE__EE_Bootstrap__detect_activations_or_upgrades'
408
-     * which runs during the WP 'plugins_loaded' action at priority 3
409
-     *
410
-     * @access public
411
-     * @return void
412
-     */
413
-    public function detect_activations_or_upgrades()
414
-    {
415
-        //first off: let's make sure to handle core
416
-        $this->detect_if_activation_or_upgrade();
417
-        foreach ($this->registry->addons as $addon) {
418
-            if ($addon instanceof EE_Addon) {
419
-                //detect teh request type for that addon
420
-                $addon->detect_activation_or_upgrade();
421
-            }
422
-        }
423
-    }
424
-
425
-
426
-
427
-    /**
428
-     * detect_if_activation_or_upgrade
429
-     * Takes care of detecting whether this is a brand new install or code upgrade,
430
-     * and either setting up the DB or setting up maintenance mode etc.
431
-     *
432
-     * @access public
433
-     * @return void
434
-     */
435
-    public function detect_if_activation_or_upgrade()
436
-    {
437
-        do_action('AHEE__EE_System___detect_if_activation_or_upgrade__begin');
438
-        // check if db has been updated, or if its a brand-new installation
439
-        $espresso_db_update = $this->fix_espresso_db_upgrade_option();
440
-        $request_type       = $this->detect_req_type($espresso_db_update);
441
-        //EEH_Debug_Tools::printr( $request_type, '$request_type', __FILE__, __LINE__ );
442
-        switch ($request_type) {
443
-            case EE_System::req_type_new_activation:
444
-                do_action('AHEE__EE_System__detect_if_activation_or_upgrade__new_activation');
445
-                $this->_handle_core_version_change($espresso_db_update);
446
-                break;
447
-            case EE_System::req_type_reactivation:
448
-                do_action('AHEE__EE_System__detect_if_activation_or_upgrade__reactivation');
449
-                $this->_handle_core_version_change($espresso_db_update);
450
-                break;
451
-            case EE_System::req_type_upgrade:
452
-                do_action('AHEE__EE_System__detect_if_activation_or_upgrade__upgrade');
453
-                //migrations may be required now that we've upgraded
454
-                $this->maintenance_mode->set_maintenance_mode_if_db_old();
455
-                $this->_handle_core_version_change($espresso_db_update);
456
-                //				echo "done upgrade";die;
457
-                break;
458
-            case EE_System::req_type_downgrade:
459
-                do_action('AHEE__EE_System__detect_if_activation_or_upgrade__downgrade');
460
-                //its possible migrations are no longer required
461
-                $this->maintenance_mode->set_maintenance_mode_if_db_old();
462
-                $this->_handle_core_version_change($espresso_db_update);
463
-                break;
464
-            case EE_System::req_type_normal:
465
-            default:
466
-                break;
467
-        }
468
-        do_action('AHEE__EE_System__detect_if_activation_or_upgrade__complete');
469
-    }
470
-
471
-
472
-
473
-    /**
474
-     * Updates the list of installed versions and sets hooks for
475
-     * initializing the database later during the request
476
-     *
477
-     * @param array $espresso_db_update
478
-     */
479
-    private function _handle_core_version_change($espresso_db_update)
480
-    {
481
-        $this->update_list_of_installed_versions($espresso_db_update);
482
-        //get ready to verify the DB is ok (provided we aren't in maintenance mode, of course)
483
-        add_action(
484
-            'AHEE__EE_System__perform_activations_upgrades_and_migrations',
485
-            array($this, 'initialize_db_if_no_migrations_required')
486
-        );
487
-    }
488
-
489
-
490
-
491
-    /**
492
-     * standardizes the wp option 'espresso_db_upgrade' which actually stores
493
-     * information about what versions of EE have been installed and activated,
494
-     * NOT necessarily the state of the database
495
-     *
496
-     * @param mixed $espresso_db_update           the value of the WordPress option.
497
-     *                                            If not supplied, fetches it from the options table
498
-     * @return array the correct value of 'espresso_db_upgrade', after saving it, if it needed correction
499
-     */
500
-    private function fix_espresso_db_upgrade_option($espresso_db_update = null)
501
-    {
502
-        do_action('FHEE__EE_System__manage_fix_espresso_db_upgrade_option__begin', $espresso_db_update);
503
-        if (! $espresso_db_update) {
504
-            $espresso_db_update = get_option('espresso_db_update');
505
-        }
506
-        // check that option is an array
507
-        if (! is_array($espresso_db_update)) {
508
-            // if option is FALSE, then it never existed
509
-            if ($espresso_db_update === false) {
510
-                // make $espresso_db_update an array and save option with autoload OFF
511
-                $espresso_db_update = array();
512
-                add_option('espresso_db_update', $espresso_db_update, '', 'no');
513
-            } else {
514
-                // option is NOT FALSE but also is NOT an array, so make it an array and save it
515
-                $espresso_db_update = array($espresso_db_update => array());
516
-                update_option('espresso_db_update', $espresso_db_update);
517
-            }
518
-        } else {
519
-            $corrected_db_update = array();
520
-            //if IS an array, but is it an array where KEYS are version numbers, and values are arrays?
521
-            foreach ($espresso_db_update as $should_be_version_string => $should_be_array) {
522
-                if (is_int($should_be_version_string) && ! is_array($should_be_array)) {
523
-                    //the key is an int, and the value IS NOT an array
524
-                    //so it must be numerically-indexed, where values are versions installed...
525
-                    //fix it!
526
-                    $version_string                         = $should_be_array;
527
-                    $corrected_db_update[ $version_string ] = array('unknown-date');
528
-                } else {
529
-                    //ok it checks out
530
-                    $corrected_db_update[ $should_be_version_string ] = $should_be_array;
531
-                }
532
-            }
533
-            $espresso_db_update = $corrected_db_update;
534
-            update_option('espresso_db_update', $espresso_db_update);
535
-        }
536
-        do_action('FHEE__EE_System__manage_fix_espresso_db_upgrade_option__complete', $espresso_db_update);
537
-        return $espresso_db_update;
538
-    }
539
-
540
-
541
-
542
-    /**
543
-     * Does the traditional work of setting up the plugin's database and adding default data.
544
-     * If migration script/process did not exist, this is what would happen on every activation/reactivation/upgrade.
545
-     * NOTE: if we're in maintenance mode (which would be the case if we detect there are data
546
-     * migration scripts that need to be run and a version change happens), enqueues core for database initialization,
547
-     * so that it will be done when migrations are finished
548
-     *
549
-     * @param boolean $initialize_addons_too if true, we double-check addons' database tables etc too;
550
-     * @param boolean $verify_schema         if true will re-check the database tables have the correct schema.
551
-     *                                       This is a resource-intensive job
552
-     *                                       so we prefer to only do it when necessary
553
-     * @return void
554
-     * @throws EE_Error
555
-     */
556
-    public function initialize_db_if_no_migrations_required($initialize_addons_too = false, $verify_schema = true)
557
-    {
558
-        $request_type = $this->detect_req_type();
559
-        //only initialize system if we're not in maintenance mode.
560
-        if ($this->maintenance_mode->level() !== EE_Maintenance_Mode::level_2_complete_maintenance) {
561
-            update_option('ee_flush_rewrite_rules', true);
562
-            if ($verify_schema) {
563
-                EEH_Activation::initialize_db_and_folders();
564
-            }
565
-            EEH_Activation::initialize_db_content();
566
-            EEH_Activation::system_initialization();
567
-            if ($initialize_addons_too) {
568
-                $this->initialize_addons();
569
-            }
570
-        } else {
571
-            EE_Data_Migration_Manager::instance()->enqueue_db_initialization_for('Core');
572
-        }
573
-        if ($request_type === EE_System::req_type_new_activation
574
-            || $request_type === EE_System::req_type_reactivation
575
-            || (
576
-                $request_type === EE_System::req_type_upgrade
577
-                && $this->is_major_version_change()
578
-            )
579
-        ) {
580
-            add_action('AHEE__EE_System__initialize_last', array($this, 'redirect_to_about_ee'), 9);
581
-        }
582
-    }
583
-
584
-
585
-
586
-    /**
587
-     * Initializes the db for all registered addons
588
-     *
589
-     * @throws EE_Error
590
-     */
591
-    public function initialize_addons()
592
-    {
593
-        //foreach registered addon, make sure its db is up-to-date too
594
-        foreach ($this->registry->addons as $addon) {
595
-            if ($addon instanceof EE_Addon) {
596
-                $addon->initialize_db_if_no_migrations_required();
597
-            }
598
-        }
599
-    }
600
-
601
-
602
-
603
-    /**
604
-     * Adds the current code version to the saved wp option which stores a list of all ee versions ever installed.
605
-     *
606
-     * @param    array  $version_history
607
-     * @param    string $current_version_to_add version to be added to the version history
608
-     * @return    boolean success as to whether or not this option was changed
609
-     */
610
-    public function update_list_of_installed_versions($version_history = null, $current_version_to_add = null)
611
-    {
612
-        if (! $version_history) {
613
-            $version_history = $this->fix_espresso_db_upgrade_option($version_history);
614
-        }
615
-        if ($current_version_to_add === null) {
616
-            $current_version_to_add = espresso_version();
617
-        }
618
-        $version_history[ $current_version_to_add ][] = date('Y-m-d H:i:s', time());
619
-        // re-save
620
-        return update_option('espresso_db_update', $version_history);
621
-    }
622
-
623
-
624
-
625
-    /**
626
-     * Detects if the current version indicated in the has existed in the list of
627
-     * previously-installed versions of EE (espresso_db_update). Does NOT modify it (ie, no side-effect)
628
-     *
629
-     * @param array $espresso_db_update array from the wp option stored under the name 'espresso_db_update'.
630
-     *                                  If not supplied, fetches it from the options table.
631
-     *                                  Also, caches its result so later parts of the code can also know whether
632
-     *                                  there's been an update or not. This way we can add the current version to
633
-     *                                  espresso_db_update, but still know if this is a new install or not
634
-     * @return int one of the constants on EE_System::req_type_
635
-     */
636
-    public function detect_req_type($espresso_db_update = null)
637
-    {
638
-        if ($this->_req_type === null) {
639
-            $espresso_db_update          = ! empty($espresso_db_update)
640
-                ? $espresso_db_update
641
-                : $this->fix_espresso_db_upgrade_option();
642
-            $this->_req_type             = EE_System::detect_req_type_given_activation_history(
643
-                $espresso_db_update,
644
-                'ee_espresso_activation', espresso_version()
645
-            );
646
-            $this->_major_version_change = $this->_detect_major_version_change($espresso_db_update);
647
-            $this->request->setIsActivation($this->_req_type !== EE_System::req_type_normal);
648
-        }
649
-        return $this->_req_type;
650
-    }
651
-
652
-
653
-
654
-    /**
655
-     * Returns whether or not there was a non-micro version change (ie, change in either
656
-     * the first or second number in the version. Eg 4.9.0.rc.001 to 4.10.0.rc.000,
657
-     * but not 4.9.0.rc.0001 to 4.9.1.rc.0001
658
-     *
659
-     * @param $activation_history
660
-     * @return bool
661
-     */
662
-    private function _detect_major_version_change($activation_history)
663
-    {
664
-        $previous_version       = EE_System::_get_most_recently_active_version_from_activation_history($activation_history);
665
-        $previous_version_parts = explode('.', $previous_version);
666
-        $current_version_parts  = explode('.', espresso_version());
667
-        return isset($previous_version_parts[0], $previous_version_parts[1], $current_version_parts[0], $current_version_parts[1])
668
-               && ($previous_version_parts[0] !== $current_version_parts[0]
669
-                   || $previous_version_parts[1] !== $current_version_parts[1]
670
-               );
671
-    }
672
-
673
-
674
-
675
-    /**
676
-     * Returns true if either the major or minor version of EE changed during this request.
677
-     * Eg 4.9.0.rc.001 to 4.10.0.rc.000, but not 4.9.0.rc.0001 to 4.9.1.rc.0001
678
-     *
679
-     * @return bool
680
-     */
681
-    public function is_major_version_change()
682
-    {
683
-        return $this->_major_version_change;
684
-    }
685
-
686
-
687
-
688
-    /**
689
-     * Determines the request type for any ee addon, given three piece of info: the current array of activation
690
-     * histories (for core that' 'espresso_db_update' wp option); the name of the WordPress option which is temporarily
691
-     * set upon activation of the plugin (for core it's 'ee_espresso_activation'); and the version that this plugin was
692
-     * just activated to (for core that will always be espresso_version())
693
-     *
694
-     * @param array  $activation_history_for_addon     the option's value which stores the activation history for this
695
-     *                                                 ee plugin. for core that's 'espresso_db_update'
696
-     * @param string $activation_indicator_option_name the name of the WordPress option that is temporarily set to
697
-     *                                                 indicate that this plugin was just activated
698
-     * @param string $version_to_upgrade_to            the version that was just upgraded to (for core that will be
699
-     *                                                 espresso_version())
700
-     * @return int one of the constants on EE_System::req_type_*
701
-     */
702
-    public static function detect_req_type_given_activation_history(
703
-        $activation_history_for_addon,
704
-        $activation_indicator_option_name,
705
-        $version_to_upgrade_to
706
-    ) {
707
-        $version_is_higher = self::_new_version_is_higher($activation_history_for_addon, $version_to_upgrade_to);
708
-        if ($activation_history_for_addon) {
709
-            //it exists, so this isn't a completely new install
710
-            //check if this version already in that list of previously installed versions
711
-            if (! isset($activation_history_for_addon[ $version_to_upgrade_to ])) {
712
-                //it a version we haven't seen before
713
-                if ($version_is_higher === 1) {
714
-                    $req_type = EE_System::req_type_upgrade;
715
-                } else {
716
-                    $req_type = EE_System::req_type_downgrade;
717
-                }
718
-                delete_option($activation_indicator_option_name);
719
-            } else {
720
-                // its not an update. maybe a reactivation?
721
-                if (get_option($activation_indicator_option_name, false)) {
722
-                    if ($version_is_higher === -1) {
723
-                        $req_type = EE_System::req_type_downgrade;
724
-                    } elseif ($version_is_higher === 0) {
725
-                        //we've seen this version before, but it's an activation. must be a reactivation
726
-                        $req_type = EE_System::req_type_reactivation;
727
-                    } else {//$version_is_higher === 1
728
-                        $req_type = EE_System::req_type_upgrade;
729
-                    }
730
-                    delete_option($activation_indicator_option_name);
731
-                } else {
732
-                    //we've seen this version before and the activation indicate doesn't show it was just activated
733
-                    if ($version_is_higher === -1) {
734
-                        $req_type = EE_System::req_type_downgrade;
735
-                    } elseif ($version_is_higher === 0) {
736
-                        //we've seen this version before and it's not an activation. its normal request
737
-                        $req_type = EE_System::req_type_normal;
738
-                    } else {//$version_is_higher === 1
739
-                        $req_type = EE_System::req_type_upgrade;
740
-                    }
741
-                }
742
-            }
743
-        } else {
744
-            //brand new install
745
-            $req_type = EE_System::req_type_new_activation;
746
-            delete_option($activation_indicator_option_name);
747
-        }
748
-        return $req_type;
749
-    }
750
-
751
-
752
-
753
-    /**
754
-     * Detects if the $version_to_upgrade_to is higher than the most recent version in
755
-     * the $activation_history_for_addon
756
-     *
757
-     * @param array  $activation_history_for_addon (keys are versions, values are arrays of times activated,
758
-     *                                             sometimes containing 'unknown-date'
759
-     * @param string $version_to_upgrade_to        (current version)
760
-     * @return int results of version_compare( $version_to_upgrade_to, $most_recently_active_version ).
761
-     *                                             ie, -1 if $version_to_upgrade_to is LOWER (downgrade);
762
-     *                                             0 if $version_to_upgrade_to MATCHES (reactivation or normal request);
763
-     *                                             1 if $version_to_upgrade_to is HIGHER (upgrade) ;
764
-     */
765
-    private static function _new_version_is_higher($activation_history_for_addon, $version_to_upgrade_to)
766
-    {
767
-        //find the most recently-activated version
768
-        $most_recently_active_version =
769
-            EE_System::_get_most_recently_active_version_from_activation_history($activation_history_for_addon);
770
-        return version_compare($version_to_upgrade_to, $most_recently_active_version);
771
-    }
772
-
773
-
774
-
775
-    /**
776
-     * Gets the most recently active version listed in the activation history,
777
-     * and if none are found (ie, it's a brand new install) returns '0.0.0.dev.000'.
778
-     *
779
-     * @param array $activation_history  (keys are versions, values are arrays of times activated,
780
-     *                                   sometimes containing 'unknown-date'
781
-     * @return string
782
-     */
783
-    private static function _get_most_recently_active_version_from_activation_history($activation_history)
784
-    {
785
-        $most_recently_active_version_activation = '1970-01-01 00:00:00';
786
-        $most_recently_active_version            = '0.0.0.dev.000';
787
-        if (is_array($activation_history)) {
788
-            foreach ($activation_history as $version => $times_activated) {
789
-                //check there is a record of when this version was activated. Otherwise,
790
-                //mark it as unknown
791
-                if (! $times_activated) {
792
-                    $times_activated = array('unknown-date');
793
-                }
794
-                if (is_string($times_activated)) {
795
-                    $times_activated = array($times_activated);
796
-                }
797
-                foreach ($times_activated as $an_activation) {
798
-                    if ($an_activation !== 'unknown-date'
799
-                        && $an_activation
800
-                           > $most_recently_active_version_activation) {
801
-                        $most_recently_active_version            = $version;
802
-                        $most_recently_active_version_activation = $an_activation === 'unknown-date'
803
-                            ? '1970-01-01 00:00:00'
804
-                            : $an_activation;
805
-                    }
806
-                }
807
-            }
808
-        }
809
-        return $most_recently_active_version;
810
-    }
811
-
812
-
813
-
814
-    /**
815
-     * This redirects to the about EE page after activation
816
-     *
817
-     * @return void
818
-     */
819
-    public function redirect_to_about_ee()
820
-    {
821
-        $notices = EE_Error::get_notices(false);
822
-        //if current user is an admin and it's not an ajax or rest request
823
-        if (
824
-            ! isset($notices['errors'])
825
-            && $this->request->isAdmin()
826
-            && apply_filters(
827
-                'FHEE__EE_System__redirect_to_about_ee__do_redirect',
828
-                $this->capabilities->current_user_can('manage_options', 'espresso_about_default')
829
-            )
830
-        ) {
831
-            $query_params = array('page' => 'espresso_about');
832
-            if (EE_System::instance()->detect_req_type() === EE_System::req_type_new_activation) {
833
-                $query_params['new_activation'] = true;
834
-            }
835
-            if (EE_System::instance()->detect_req_type() === EE_System::req_type_reactivation) {
836
-                $query_params['reactivation'] = true;
837
-            }
838
-            $url = add_query_arg($query_params, admin_url('admin.php'));
839
-            wp_safe_redirect($url);
840
-            exit();
841
-        }
842
-    }
843
-
844
-
845
-
846
-    /**
847
-     * load_core_configuration
848
-     * this is hooked into 'AHEE__EE_Bootstrap__load_core_configuration'
849
-     * which runs during the WP 'plugins_loaded' action at priority 5
850
-     *
851
-     * @return void
852
-     * @throws ReflectionException
853
-     */
854
-    public function load_core_configuration()
855
-    {
856
-        do_action('AHEE__EE_System__load_core_configuration__begin', $this);
857
-        $this->loader->getShared('EE_Load_Textdomain');
858
-        //load textdomain
859
-        EE_Load_Textdomain::load_textdomain();
860
-        // load and setup EE_Config and EE_Network_Config
861
-        $config = $this->loader->getShared('EE_Config');
862
-        $this->loader->getShared('EE_Network_Config');
863
-        // setup autoloaders
864
-        // enable logging?
865
-        if ($config->admin->use_full_logging) {
866
-            $this->loader->getShared('EE_Log');
867
-        }
868
-        // check for activation errors
869
-        $activation_errors = get_option('ee_plugin_activation_errors', false);
870
-        if ($activation_errors) {
871
-            EE_Error::add_error($activation_errors, __FILE__, __FUNCTION__, __LINE__);
872
-            update_option('ee_plugin_activation_errors', false);
873
-        }
874
-        // get model names
875
-        $this->_parse_model_names();
876
-        //load caf stuff a chance to play during the activation process too.
877
-        $this->_maybe_brew_regular();
878
-        do_action('AHEE__EE_System__load_core_configuration__complete', $this);
879
-    }
880
-
881
-
882
-
883
-    /**
884
-     * cycles through all of the models/*.model.php files, and assembles an array of model names
885
-     *
886
-     * @return void
887
-     * @throws ReflectionException
888
-     */
889
-    private function _parse_model_names()
890
-    {
891
-        //get all the files in the EE_MODELS folder that end in .model.php
892
-        $models                 = glob(EE_MODELS . '*.model.php');
893
-        $model_names            = array();
894
-        $non_abstract_db_models = array();
895
-        foreach ($models as $model) {
896
-            // get model classname
897
-            $classname       = EEH_File::get_classname_from_filepath_with_standard_filename($model);
898
-            $short_name      = str_replace('EEM_', '', $classname);
899
-            $reflectionClass = new ReflectionClass($classname);
900
-            if ($reflectionClass->isSubclassOf('EEM_Base') && ! $reflectionClass->isAbstract()) {
901
-                $non_abstract_db_models[ $short_name ] = $classname;
902
-            }
903
-            $model_names[ $short_name ] = $classname;
904
-        }
905
-        $this->registry->models                 = apply_filters('FHEE__EE_System__parse_model_names', $model_names);
906
-        $this->registry->non_abstract_db_models = apply_filters(
907
-            'FHEE__EE_System__parse_implemented_model_names',
908
-            $non_abstract_db_models
909
-        );
910
-    }
911
-
912
-
913
-
914
-    /**
915
-     * The purpose of this method is to simply check for a file named "caffeinated/brewing_regular.php" for any hooks
916
-     * that need to be setup before our EE_System launches.
917
-     *
918
-     * @return void
919
-     */
920
-    private function _maybe_brew_regular()
921
-    {
922
-        if ((! defined('EE_DECAF') || EE_DECAF !== true) && is_readable(EE_CAFF_PATH . 'brewing_regular.php')) {
923
-            require_once EE_CAFF_PATH . 'brewing_regular.php';
924
-        }
925
-    }
926
-
927
-
928
-
929
-    /**
930
-     * register_shortcodes_modules_and_widgets
931
-     * generate lists of shortcodes and modules, then verify paths and classes
932
-     * This is hooked into 'AHEE__EE_Bootstrap__register_shortcodes_modules_and_widgets'
933
-     * which runs during the WP 'plugins_loaded' action at priority 7
934
-     *
935
-     * @access public
936
-     * @return void
937
-     * @throws Exception
938
-     */
939
-    public function register_shortcodes_modules_and_widgets()
940
-    {
941
-        if ($this->request->isFrontend() || $this->request->isIframe()) {
942
-            try {
943
-                // load, register, and add shortcodes the new way
944
-                $this->loader->getShared(
945
-                    'EventEspresso\core\services\shortcodes\ShortcodesManager',
946
-                    array(
947
-                        // and the old way, but we'll put it under control of the new system
948
-                        EE_Config::getLegacyShortcodesManager(),
949
-                    )
950
-                );
951
-            } catch (Exception $exception) {
952
-                new ExceptionStackTraceDisplay($exception);
953
-            }
954
-        }
955
-        do_action('AHEE__EE_System__register_shortcodes_modules_and_widgets');
956
-        // check for addons using old hook point
957
-        if (has_action('AHEE__EE_System__register_shortcodes_modules_and_addons')) {
958
-            $this->_incompatible_addon_error();
959
-        }
960
-    }
961
-
962
-
963
-
964
-    /**
965
-     * _incompatible_addon_error
966
-     *
967
-     * @access public
968
-     * @return void
969
-     */
970
-    private function _incompatible_addon_error()
971
-    {
972
-        // get array of classes hooking into here
973
-        $class_names = EEH_Class_Tools::get_class_names_for_all_callbacks_on_hook(
974
-            'AHEE__EE_System__register_shortcodes_modules_and_addons'
975
-        );
976
-        if (! empty($class_names)) {
977
-            $msg = __(
978
-                'The following plugins, addons, or modules appear to be incompatible with this version of Event Espresso and were automatically deactivated to avoid fatal errors:',
979
-                'event_espresso'
980
-            );
981
-            $msg .= '<ul>';
982
-            foreach ($class_names as $class_name) {
983
-                $msg .= '<li><b>Event Espresso - ' . str_replace(
984
-                        array('EE_', 'EEM_', 'EED_', 'EES_', 'EEW_'), '',
985
-                        $class_name
986
-                    ) . '</b></li>';
987
-            }
988
-            $msg .= '</ul>';
989
-            $msg .= __(
990
-                'Compatibility issues can be avoided and/or resolved by keeping addons and plugins updated to the latest version.',
991
-                'event_espresso'
992
-            );
993
-            // save list of incompatible addons to wp-options for later use
994
-            add_option('ee_incompatible_addons', $class_names, '', 'no');
995
-            if (is_admin()) {
996
-                EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
997
-            }
998
-        }
999
-    }
1000
-
1001
-
1002
-
1003
-    /**
1004
-     * brew_espresso
1005
-     * begins the process of setting hooks for initializing EE in the correct order
1006
-     * This is happening on the 'AHEE__EE_Bootstrap__brew_espresso' hook point
1007
-     * which runs during the WP 'plugins_loaded' action at priority 9
1008
-     *
1009
-     * @return void
1010
-     */
1011
-    public function brew_espresso()
1012
-    {
1013
-        do_action('AHEE__EE_System__brew_espresso__begin', $this);
1014
-        // load some final core systems
1015
-        add_action('init', array($this, 'set_hooks_for_core'), 1);
1016
-        add_action('init', array($this, 'perform_activations_upgrades_and_migrations'), 3);
1017
-        add_action('init', array($this, 'load_CPTs_and_session'), 5);
1018
-        add_action('init', array($this, 'load_controllers'), 7);
1019
-        add_action('init', array($this, 'core_loaded_and_ready'), 9);
1020
-        add_action('init', array($this, 'initialize'), 10);
1021
-        add_action('init', array($this, 'initialize_last'), 100);
1022
-        if (is_admin() && apply_filters('FHEE__EE_System__brew_espresso__load_pue', true)) {
1023
-            // pew pew pew
1024
-            $this->loader->getShared('EE_PUE');
1025
-            do_action('AHEE__EE_System__brew_espresso__after_pue_init');
1026
-        }
1027
-        do_action('AHEE__EE_System__brew_espresso__complete', $this);
1028
-    }
1029
-
1030
-
1031
-
1032
-    /**
1033
-     *    set_hooks_for_core
1034
-     *
1035
-     * @access public
1036
-     * @return    void
1037
-     * @throws EE_Error
1038
-     */
1039
-    public function set_hooks_for_core()
1040
-    {
1041
-        $this->_deactivate_incompatible_addons();
1042
-        do_action('AHEE__EE_System__set_hooks_for_core');
1043
-        //caps need to be initialized on every request so that capability maps are set.
1044
-        //@see https://events.codebasehq.com/projects/event-espresso/tickets/8674
1045
-        $this->registry->CAP->init_caps();
1046
-    }
1047
-
1048
-
1049
-
1050
-    /**
1051
-     * Using the information gathered in EE_System::_incompatible_addon_error,
1052
-     * deactivates any addons considered incompatible with the current version of EE
1053
-     */
1054
-    private function _deactivate_incompatible_addons()
1055
-    {
1056
-        $incompatible_addons = get_option('ee_incompatible_addons', array());
1057
-        if (! empty($incompatible_addons)) {
1058
-            $active_plugins = get_option('active_plugins', array());
1059
-            foreach ($active_plugins as $active_plugin) {
1060
-                foreach ($incompatible_addons as $incompatible_addon) {
1061
-                    if (strpos($active_plugin, $incompatible_addon) !== false) {
1062
-                        unset($_GET['activate']);
1063
-                        espresso_deactivate_plugin($active_plugin);
1064
-                    }
1065
-                }
1066
-            }
1067
-        }
1068
-    }
1069
-
1070
-
1071
-
1072
-    /**
1073
-     *    perform_activations_upgrades_and_migrations
1074
-     *
1075
-     * @access public
1076
-     * @return    void
1077
-     */
1078
-    public function perform_activations_upgrades_and_migrations()
1079
-    {
1080
-        //first check if we had previously attempted to setup EE's directories but failed
1081
-        if ($this->request->isActivation() && EEH_Activation::upload_directories_incomplete()) {
1082
-            EEH_Activation::create_upload_directories();
1083
-        }
1084
-        do_action('AHEE__EE_System__perform_activations_upgrades_and_migrations');
1085
-    }
1086
-
1087
-
1088
-
1089
-    /**
1090
-     *    load_CPTs_and_session
1091
-     *
1092
-     * @access public
1093
-     * @return    void
1094
-     */
1095
-    public function load_CPTs_and_session()
1096
-    {
1097
-        do_action('AHEE__EE_System__load_CPTs_and_session__start');
1098
-        // register Custom Post Types
1099
-        $this->loader->getShared('EE_Register_CPTs');
1100
-        do_action('AHEE__EE_System__load_CPTs_and_session__complete');
1101
-    }
1102
-
1103
-
1104
-
1105
-    /**
1106
-     * load_controllers
1107
-     * this is the best place to load any additional controllers that needs access to EE core.
1108
-     * it is expected that all basic core EE systems, that are not dependant on the current request are loaded at this
1109
-     * time
1110
-     *
1111
-     * @access public
1112
-     * @return void
1113
-     */
1114
-    public function load_controllers()
1115
-    {
1116
-        do_action('AHEE__EE_System__load_controllers__start');
1117
-        // let's get it started
1118
-        if (
1119
-            ! $this->maintenance_mode->level()
1120
-            && ($this->request->isFrontend() || $this->request->isFrontAjax())
1121
-        ) {
1122
-            do_action('AHEE__EE_System__load_controllers__load_front_controllers');
1123
-            $this->loader->getShared('EE_Front_Controller');
1124
-        } elseif ($this->request->isAdmin() || $this->request->isAdminAjax()) {
1125
-            do_action('AHEE__EE_System__load_controllers__load_admin_controllers');
1126
-            $this->loader->getShared('EE_Admin');
1127
-        }
1128
-        do_action('AHEE__EE_System__load_controllers__complete');
1129
-    }
1130
-
1131
-
1132
-
1133
-    /**
1134
-     * core_loaded_and_ready
1135
-     * all of the basic EE core should be loaded at this point and available regardless of M-Mode
1136
-     *
1137
-     * @access public
1138
-     * @return void
1139
-     */
1140
-    public function core_loaded_and_ready()
1141
-    {
1142
-        if (
1143
-            $this->request->isAdmin()
1144
-            || $this->request->isEeAjax()
1145
-            || $this->request->isFrontend()
1146
-        ) {
1147
-            $this->loader->getShared('EE_Session');
1148
-        }
1149
-        do_action('AHEE__EE_System__core_loaded_and_ready');
1150
-        // load_espresso_template_tags
1151
-        if (
1152
-            is_readable(EE_PUBLIC . 'template_tags.php')
1153
-            && ($this->request->isFrontend() || $this->request->isIframe() || $this->request->isFeed())
1154
-        ) {
1155
-            require_once EE_PUBLIC . 'template_tags.php';
1156
-        }
1157
-        do_action('AHEE__EE_System__set_hooks_for_shortcodes_modules_and_addons');
1158
-        if ($this->request->isAdmin() || $this->request->isFrontend() || $this->request->isIframe()) {
1159
-            $this->loader->getShared('EventEspresso\core\services\assets\Registry');
1160
-        }
1161
-    }
1162
-
1163
-
1164
-
1165
-    /**
1166
-     * initialize
1167
-     * this is the best place to begin initializing client code
1168
-     *
1169
-     * @access public
1170
-     * @return void
1171
-     */
1172
-    public function initialize()
1173
-    {
1174
-        do_action('AHEE__EE_System__initialize');
1175
-    }
1176
-
1177
-
1178
-
1179
-    /**
1180
-     * initialize_last
1181
-     * this is run really late during the WP init hook point, and ensures that mostly everything else that needs to
1182
-     * initialize has done so
1183
-     *
1184
-     * @access public
1185
-     * @return void
1186
-     */
1187
-    public function initialize_last()
1188
-    {
1189
-        do_action('AHEE__EE_System__initialize_last');
1190
-        add_action('admin_bar_init', array($this, 'addEspressoToolbar'));
1191
-    }
1192
-
1193
-
1194
-
1195
-    /**
1196
-     * @return void
1197
-     * @throws EE_Error
1198
-     */
1199
-    public function addEspressoToolbar()
1200
-    {
1201
-        $this->loader->getShared(
1202
-            'EventEspresso\core\domain\services\admin\AdminToolBar',
1203
-            array($this->registry->CAP)
1204
-        );
1205
-    }
1206
-
1207
-
1208
-
1209
-    /**
1210
-     * do_not_cache
1211
-     * sets no cache headers and defines no cache constants for WP plugins
1212
-     *
1213
-     * @access public
1214
-     * @return void
1215
-     */
1216
-    public static function do_not_cache()
1217
-    {
1218
-        // set no cache constants
1219
-        if (! defined('DONOTCACHEPAGE')) {
1220
-            define('DONOTCACHEPAGE', true);
1221
-        }
1222
-        if (! defined('DONOTCACHCEOBJECT')) {
1223
-            define('DONOTCACHCEOBJECT', true);
1224
-        }
1225
-        if (! defined('DONOTCACHEDB')) {
1226
-            define('DONOTCACHEDB', true);
1227
-        }
1228
-        // add no cache headers
1229
-        add_action('send_headers', array('EE_System', 'nocache_headers'), 10);
1230
-        // plus a little extra for nginx and Google Chrome
1231
-        add_filter('nocache_headers', array('EE_System', 'extra_nocache_headers'), 10, 1);
1232
-        // prevent browsers from prefetching of the rel='next' link, because it may contain content that interferes with the registration process
1233
-        remove_action('wp_head', 'adjacent_posts_rel_link_wp_head');
1234
-    }
1235
-
1236
-
1237
-
1238
-    /**
1239
-     *    extra_nocache_headers
1240
-     *
1241
-     * @access    public
1242
-     * @param $headers
1243
-     * @return    array
1244
-     */
1245
-    public static function extra_nocache_headers($headers)
1246
-    {
1247
-        // for NGINX
1248
-        $headers['X-Accel-Expires'] = 0;
1249
-        // plus extra for Google Chrome since it doesn't seem to respect "no-cache", but WILL respect "no-store"
1250
-        $headers['Cache-Control'] = 'no-store, no-cache, must-revalidate, max-age=0';
1251
-        return $headers;
1252
-    }
1253
-
1254
-
1255
-
1256
-    /**
1257
-     *    nocache_headers
1258
-     *
1259
-     * @access    public
1260
-     * @return    void
1261
-     */
1262
-    public static function nocache_headers()
1263
-    {
1264
-        nocache_headers();
1265
-    }
1266
-
1267
-
1268
-
1269
-    /**
1270
-     * simply hooks into "wp_list_pages_exclude" filter (for wp_list_pages method) and makes sure EE critical pages are
1271
-     * never returned with the function.
1272
-     *
1273
-     * @param  array $exclude_array any existing pages being excluded are in this array.
1274
-     * @return array
1275
-     */
1276
-    public function remove_pages_from_wp_list_pages($exclude_array)
1277
-    {
1278
-        return array_merge($exclude_array, $this->registry->CFG->core->get_critical_pages_array());
1279
-    }
27
+	/**
28
+	 * indicates this is a 'normal' request. Ie, not activation, nor upgrade, nor activation.
29
+	 * So examples of this would be a normal GET request on the frontend or backend, or a POST, etc
30
+	 */
31
+	const req_type_normal = 0;
32
+
33
+	/**
34
+	 * Indicates this is a brand new installation of EE so we should install
35
+	 * tables and default data etc
36
+	 */
37
+	const req_type_new_activation = 1;
38
+
39
+	/**
40
+	 * we've detected that EE has been reactivated (or EE was activated during maintenance mode,
41
+	 * and we just exited maintenance mode). We MUST check the database is setup properly
42
+	 * and that default data is setup too
43
+	 */
44
+	const req_type_reactivation = 2;
45
+
46
+	/**
47
+	 * indicates that EE has been upgraded since its previous request.
48
+	 * We may have data migration scripts to call and will want to trigger maintenance mode
49
+	 */
50
+	const req_type_upgrade = 3;
51
+
52
+	/**
53
+	 * TODO  will detect that EE has been DOWNGRADED. We probably don't want to run in this case...
54
+	 */
55
+	const req_type_downgrade = 4;
56
+
57
+	/**
58
+	 * @deprecated since version 4.6.0.dev.006
59
+	 * Now whenever a new_activation is detected the request type is still just
60
+	 * new_activation (same for reactivation, upgrade, downgrade etc), but if we'r ein maintenance mode
61
+	 * EE_System::initialize_db_if_no_migrations_required and EE_Addon::initialize_db_if_no_migrations_required
62
+	 * will instead enqueue that EE plugin's db initialization for when we're taken out of maintenance mode.
63
+	 * (Specifically, when the migration manager indicates migrations are finished
64
+	 * EE_Data_Migration_Manager::initialize_db_for_enqueued_ee_plugins() will be called)
65
+	 */
66
+	const req_type_activation_but_not_installed = 5;
67
+
68
+	/**
69
+	 * option prefix for recording the activation history (like core's "espresso_db_update") of addons
70
+	 */
71
+	const addon_activation_history_option_prefix = 'ee_addon_activation_history_';
72
+
73
+
74
+	/**
75
+	 * @var EE_System $_instance
76
+	 */
77
+	private static $_instance;
78
+
79
+	/**
80
+	 * @var EE_Registry $registry
81
+	 */
82
+	private $registry;
83
+
84
+	/**
85
+	 * @var LoaderInterface $loader
86
+	 */
87
+	private $loader;
88
+
89
+	/**
90
+	 * @var EE_Capabilities $capabilities
91
+	 */
92
+	private $capabilities;
93
+
94
+	/**
95
+	 * @var RequestInterface $request
96
+	 */
97
+	private $request;
98
+
99
+	/**
100
+	 * @var EE_Maintenance_Mode $maintenance_mode
101
+	 */
102
+	private $maintenance_mode;
103
+
104
+	/**
105
+	 * Stores which type of request this is, options being one of the constants on EE_System starting with req_type_*.
106
+	 * It can be a brand-new activation, a reactivation, an upgrade, a downgrade, or a normal request.
107
+	 *
108
+	 * @var int $_req_type
109
+	 */
110
+	private $_req_type;
111
+
112
+	/**
113
+	 * Whether or not there was a non-micro version change in EE core version during this request
114
+	 *
115
+	 * @var boolean $_major_version_change
116
+	 */
117
+	private $_major_version_change = false;
118
+
119
+	/**
120
+	 * A Context DTO dedicated solely to identifying the current request type.
121
+	 *
122
+	 * @var RequestTypeContextCheckerInterface $request_type
123
+	 */
124
+	private $request_type;
125
+
126
+
127
+
128
+	/**
129
+	 * @singleton method used to instantiate class object
130
+	 * @param EE_Registry|null         $registry
131
+	 * @param LoaderInterface|null     $loader
132
+	 * @param RequestInterface|null          $request
133
+	 * @param EE_Maintenance_Mode|null $maintenance_mode
134
+	 * @return EE_System
135
+	 */
136
+	public static function instance(
137
+		EE_Registry $registry = null,
138
+		LoaderInterface $loader = null,
139
+		RequestInterface $request = null,
140
+		EE_Maintenance_Mode $maintenance_mode = null
141
+	) {
142
+		// check if class object is instantiated
143
+		if (! self::$_instance instanceof EE_System) {
144
+			self::$_instance = new self($registry, $loader, $request, $maintenance_mode);
145
+		}
146
+		return self::$_instance;
147
+	}
148
+
149
+
150
+
151
+	/**
152
+	 * resets the instance and returns it
153
+	 *
154
+	 * @return EE_System
155
+	 */
156
+	public static function reset()
157
+	{
158
+		self::$_instance->_req_type = null;
159
+		//make sure none of the old hooks are left hanging around
160
+		remove_all_actions('AHEE__EE_System__perform_activations_upgrades_and_migrations');
161
+		//we need to reset the migration manager in order for it to detect DMSs properly
162
+		EE_Data_Migration_Manager::reset();
163
+		self::instance()->detect_activations_or_upgrades();
164
+		self::instance()->perform_activations_upgrades_and_migrations();
165
+		return self::instance();
166
+	}
167
+
168
+
169
+
170
+	/**
171
+	 * sets hooks for running rest of system
172
+	 * provides "AHEE__EE_System__construct__complete" hook for EE Addons to use as their starting point
173
+	 * starting EE Addons from any other point may lead to problems
174
+	 *
175
+	 * @param EE_Registry         $registry
176
+	 * @param LoaderInterface     $loader
177
+	 * @param RequestInterface          $request
178
+	 * @param EE_Maintenance_Mode $maintenance_mode
179
+	 */
180
+	private function __construct(
181
+		EE_Registry $registry,
182
+		LoaderInterface $loader,
183
+		RequestInterface $request,
184
+		EE_Maintenance_Mode $maintenance_mode
185
+	) {
186
+		$this->registry         = $registry;
187
+		$this->loader           = $loader;
188
+		$this->request          = $request;
189
+		$this->maintenance_mode = $maintenance_mode;
190
+		do_action('AHEE__EE_System__construct__begin', $this);
191
+		add_action(
192
+			'AHEE__EE_Bootstrap__load_espresso_addons',
193
+			array($this, 'loadCapabilities'),
194
+			5
195
+		);
196
+		add_action(
197
+			'AHEE__EE_Bootstrap__load_espresso_addons',
198
+			array($this, 'loadCommandBus'),
199
+			7
200
+		);
201
+		add_action(
202
+			'AHEE__EE_Bootstrap__load_espresso_addons',
203
+			array($this, 'loadPluginApi'),
204
+			9
205
+		);
206
+		// allow addons to load first so that they can register autoloaders, set hooks for running DMS's, etc
207
+		add_action(
208
+			'AHEE__EE_Bootstrap__load_espresso_addons',
209
+			array($this, 'load_espresso_addons')
210
+		);
211
+		// when an ee addon is activated, we want to call the core hook(s) again
212
+		// because the newly-activated addon didn't get a chance to run at all
213
+		add_action('activate_plugin', array($this, 'load_espresso_addons'), 1);
214
+		// detect whether install or upgrade
215
+		add_action(
216
+			'AHEE__EE_Bootstrap__detect_activations_or_upgrades',
217
+			array($this, 'detect_activations_or_upgrades'),
218
+			3
219
+		);
220
+		// load EE_Config, EE_Textdomain, etc
221
+		add_action(
222
+			'AHEE__EE_Bootstrap__load_core_configuration',
223
+			array($this, 'load_core_configuration'),
224
+			5
225
+		);
226
+		// load EE_Config, EE_Textdomain, etc
227
+		add_action(
228
+			'AHEE__EE_Bootstrap__register_shortcodes_modules_and_widgets',
229
+			array($this, 'register_shortcodes_modules_and_widgets'),
230
+			7
231
+		);
232
+		// you wanna get going? I wanna get going... let's get going!
233
+		add_action(
234
+			'AHEE__EE_Bootstrap__brew_espresso',
235
+			array($this, 'brew_espresso'),
236
+			9
237
+		);
238
+		//other housekeeping
239
+		//exclude EE critical pages from wp_list_pages
240
+		add_filter(
241
+			'wp_list_pages_excludes',
242
+			array($this, 'remove_pages_from_wp_list_pages'),
243
+			10
244
+		);
245
+		// ALL EE Addons should use the following hook point to attach their initial setup too
246
+		// it's extremely important for EE Addons to register any class autoloaders so that they can be available when the EE_Config loads
247
+		do_action('AHEE__EE_System__construct__complete', $this);
248
+	}
249
+
250
+
251
+	/**
252
+	 * load and setup EE_Capabilities
253
+	 *
254
+	 * @return void
255
+	 * @throws EE_Error
256
+	 */
257
+	public function loadCapabilities()
258
+	{
259
+		$this->capabilities = $this->loader->getShared('EE_Capabilities');
260
+		add_action(
261
+			'AHEE__EE_Capabilities__init_caps__before_initialization',
262
+			function ()
263
+			{
264
+				LoaderFactory::getLoader()->getShared('EE_Payment_Method_Manager');
265
+			}
266
+		);
267
+	}
268
+
269
+
270
+
271
+	/**
272
+	 * create and cache the CommandBus, and also add middleware
273
+	 * The CapChecker middleware requires the use of EE_Capabilities
274
+	 * which is why we need to load the CommandBus after Caps are set up
275
+	 *
276
+	 * @return void
277
+	 * @throws EE_Error
278
+	 */
279
+	public function loadCommandBus()
280
+	{
281
+		$this->loader->getShared(
282
+			'CommandBusInterface',
283
+			array(
284
+				null,
285
+				apply_filters(
286
+					'FHEE__EE_Load_Espresso_Core__handle_request__CommandBus_middleware',
287
+					array(
288
+						$this->loader->getShared('EventEspresso\core\services\commands\middleware\CapChecker'),
289
+						$this->loader->getShared('EventEspresso\core\services\commands\middleware\AddActionHook'),
290
+					)
291
+				),
292
+			)
293
+		);
294
+	}
295
+
296
+
297
+
298
+	/**
299
+	 * @return void
300
+	 * @throws EE_Error
301
+	 */
302
+	public function loadPluginApi()
303
+	{
304
+		// set autoloaders for all of the classes implementing EEI_Plugin_API
305
+		// which provide helpers for EE plugin authors to more easily register certain components with EE.
306
+		EEH_Autoloader::instance()->register_autoloaders_for_each_file_in_folder(EE_LIBRARIES . 'plugin_api');
307
+		$this->loader->getShared('EE_Request_Handler');
308
+	}
309
+
310
+
311
+	/**
312
+	 * @param string $addon_name
313
+	 * @param string $version_constant
314
+	 * @param string $min_version_required
315
+	 * @param string $load_callback
316
+	 * @param string $plugin_file_constant
317
+	 * @return void
318
+	 */
319
+	private function deactivateIncompatibleAddon(
320
+		$addon_name,
321
+		$version_constant,
322
+		$min_version_required,
323
+		$load_callback,
324
+		$plugin_file_constant
325
+	) {
326
+		if (! defined($version_constant)) {
327
+			return;
328
+		}
329
+		$addon_version = constant($version_constant);
330
+		if ($addon_version && version_compare($addon_version, $min_version_required, '<')) {
331
+			remove_action('AHEE__EE_System__load_espresso_addons', $load_callback);
332
+			if (! function_exists('deactivate_plugins')) {
333
+				require_once ABSPATH . 'wp-admin/includes/plugin.php';
334
+			}
335
+			deactivate_plugins(plugin_basename(constant($plugin_file_constant)));
336
+			unset($_GET['activate'], $_REQUEST['activate'], $_GET['activate-multi'], $_REQUEST['activate-multi']);
337
+			EE_Error::add_error(
338
+				sprintf(
339
+					esc_html__(
340
+						'We\'re sorry, but the Event Espresso %1$s addon was deactivated because version %2$s or higher is required with this version of Event Espresso core.',
341
+						'event_espresso'
342
+					),
343
+					$addon_name,
344
+					$min_version_required
345
+				),
346
+				__FILE__, __FUNCTION__ . "({$addon_name})", __LINE__
347
+			);
348
+			EE_Error::get_notices(false, true);
349
+		}
350
+	}
351
+
352
+
353
+	/**
354
+	 * load_espresso_addons
355
+	 * allow addons to load first so that they can set hooks for running DMS's, etc
356
+	 * this is hooked into both:
357
+	 *    'AHEE__EE_Bootstrap__load_core_configuration'
358
+	 *        which runs during the WP 'plugins_loaded' action at priority 5
359
+	 *    and the WP 'activate_plugin' hook point
360
+	 *
361
+	 * @access public
362
+	 * @return void
363
+	 */
364
+	public function load_espresso_addons()
365
+	{
366
+		$this->deactivateIncompatibleAddon(
367
+			'Wait Lists',
368
+			'EE_WAIT_LISTS_VERSION',
369
+			'1.0.0.beta.074',
370
+			'load_espresso_wait_lists',
371
+			'EE_WAIT_LISTS_PLUGIN_FILE'
372
+		);
373
+		$this->deactivateIncompatibleAddon(
374
+			'Automated Upcoming Event Notifications',
375
+			'EE_AUTOMATED_UPCOMING_EVENT_NOTIFICATION_VERSION',
376
+			'1.0.0.beta.091',
377
+			'load_espresso_automated_upcoming_event_notification',
378
+			'EE_AUTOMATED_UPCOMING_EVENT_NOTIFICATION_PLUGIN_FILE'
379
+		);
380
+		do_action('AHEE__EE_System__load_espresso_addons');
381
+		//if the WP API basic auth plugin isn't already loaded, load it now.
382
+		//We want it for mobile apps. Just include the entire plugin
383
+		//also, don't load the basic auth when a plugin is getting activated, because
384
+		//it could be the basic auth plugin, and it doesn't check if its methods are already defined
385
+		//and causes a fatal error
386
+		if (
387
+			$this->request->getRequestParam('activate') !== 'true'
388
+			&& ! function_exists('json_basic_auth_handler')
389
+			&& ! function_exists('json_basic_auth_error')
390
+			&& ! in_array(
391
+				$this->request->getRequestParam('action'),
392
+				array('activate', 'activate-selected'),
393
+				true
394
+			)
395
+		) {
396
+			include_once EE_THIRD_PARTY . 'wp-api-basic-auth' . DS . 'basic-auth.php';
397
+		}
398
+		do_action('AHEE__EE_System__load_espresso_addons__complete');
399
+	}
400
+
401
+
402
+
403
+	/**
404
+	 * detect_activations_or_upgrades
405
+	 * Checks for activation or upgrade of core first;
406
+	 * then also checks if any registered addons have been activated or upgraded
407
+	 * This is hooked into 'AHEE__EE_Bootstrap__detect_activations_or_upgrades'
408
+	 * which runs during the WP 'plugins_loaded' action at priority 3
409
+	 *
410
+	 * @access public
411
+	 * @return void
412
+	 */
413
+	public function detect_activations_or_upgrades()
414
+	{
415
+		//first off: let's make sure to handle core
416
+		$this->detect_if_activation_or_upgrade();
417
+		foreach ($this->registry->addons as $addon) {
418
+			if ($addon instanceof EE_Addon) {
419
+				//detect teh request type for that addon
420
+				$addon->detect_activation_or_upgrade();
421
+			}
422
+		}
423
+	}
424
+
425
+
426
+
427
+	/**
428
+	 * detect_if_activation_or_upgrade
429
+	 * Takes care of detecting whether this is a brand new install or code upgrade,
430
+	 * and either setting up the DB or setting up maintenance mode etc.
431
+	 *
432
+	 * @access public
433
+	 * @return void
434
+	 */
435
+	public function detect_if_activation_or_upgrade()
436
+	{
437
+		do_action('AHEE__EE_System___detect_if_activation_or_upgrade__begin');
438
+		// check if db has been updated, or if its a brand-new installation
439
+		$espresso_db_update = $this->fix_espresso_db_upgrade_option();
440
+		$request_type       = $this->detect_req_type($espresso_db_update);
441
+		//EEH_Debug_Tools::printr( $request_type, '$request_type', __FILE__, __LINE__ );
442
+		switch ($request_type) {
443
+			case EE_System::req_type_new_activation:
444
+				do_action('AHEE__EE_System__detect_if_activation_or_upgrade__new_activation');
445
+				$this->_handle_core_version_change($espresso_db_update);
446
+				break;
447
+			case EE_System::req_type_reactivation:
448
+				do_action('AHEE__EE_System__detect_if_activation_or_upgrade__reactivation');
449
+				$this->_handle_core_version_change($espresso_db_update);
450
+				break;
451
+			case EE_System::req_type_upgrade:
452
+				do_action('AHEE__EE_System__detect_if_activation_or_upgrade__upgrade');
453
+				//migrations may be required now that we've upgraded
454
+				$this->maintenance_mode->set_maintenance_mode_if_db_old();
455
+				$this->_handle_core_version_change($espresso_db_update);
456
+				//				echo "done upgrade";die;
457
+				break;
458
+			case EE_System::req_type_downgrade:
459
+				do_action('AHEE__EE_System__detect_if_activation_or_upgrade__downgrade');
460
+				//its possible migrations are no longer required
461
+				$this->maintenance_mode->set_maintenance_mode_if_db_old();
462
+				$this->_handle_core_version_change($espresso_db_update);
463
+				break;
464
+			case EE_System::req_type_normal:
465
+			default:
466
+				break;
467
+		}
468
+		do_action('AHEE__EE_System__detect_if_activation_or_upgrade__complete');
469
+	}
470
+
471
+
472
+
473
+	/**
474
+	 * Updates the list of installed versions and sets hooks for
475
+	 * initializing the database later during the request
476
+	 *
477
+	 * @param array $espresso_db_update
478
+	 */
479
+	private function _handle_core_version_change($espresso_db_update)
480
+	{
481
+		$this->update_list_of_installed_versions($espresso_db_update);
482
+		//get ready to verify the DB is ok (provided we aren't in maintenance mode, of course)
483
+		add_action(
484
+			'AHEE__EE_System__perform_activations_upgrades_and_migrations',
485
+			array($this, 'initialize_db_if_no_migrations_required')
486
+		);
487
+	}
488
+
489
+
490
+
491
+	/**
492
+	 * standardizes the wp option 'espresso_db_upgrade' which actually stores
493
+	 * information about what versions of EE have been installed and activated,
494
+	 * NOT necessarily the state of the database
495
+	 *
496
+	 * @param mixed $espresso_db_update           the value of the WordPress option.
497
+	 *                                            If not supplied, fetches it from the options table
498
+	 * @return array the correct value of 'espresso_db_upgrade', after saving it, if it needed correction
499
+	 */
500
+	private function fix_espresso_db_upgrade_option($espresso_db_update = null)
501
+	{
502
+		do_action('FHEE__EE_System__manage_fix_espresso_db_upgrade_option__begin', $espresso_db_update);
503
+		if (! $espresso_db_update) {
504
+			$espresso_db_update = get_option('espresso_db_update');
505
+		}
506
+		// check that option is an array
507
+		if (! is_array($espresso_db_update)) {
508
+			// if option is FALSE, then it never existed
509
+			if ($espresso_db_update === false) {
510
+				// make $espresso_db_update an array and save option with autoload OFF
511
+				$espresso_db_update = array();
512
+				add_option('espresso_db_update', $espresso_db_update, '', 'no');
513
+			} else {
514
+				// option is NOT FALSE but also is NOT an array, so make it an array and save it
515
+				$espresso_db_update = array($espresso_db_update => array());
516
+				update_option('espresso_db_update', $espresso_db_update);
517
+			}
518
+		} else {
519
+			$corrected_db_update = array();
520
+			//if IS an array, but is it an array where KEYS are version numbers, and values are arrays?
521
+			foreach ($espresso_db_update as $should_be_version_string => $should_be_array) {
522
+				if (is_int($should_be_version_string) && ! is_array($should_be_array)) {
523
+					//the key is an int, and the value IS NOT an array
524
+					//so it must be numerically-indexed, where values are versions installed...
525
+					//fix it!
526
+					$version_string                         = $should_be_array;
527
+					$corrected_db_update[ $version_string ] = array('unknown-date');
528
+				} else {
529
+					//ok it checks out
530
+					$corrected_db_update[ $should_be_version_string ] = $should_be_array;
531
+				}
532
+			}
533
+			$espresso_db_update = $corrected_db_update;
534
+			update_option('espresso_db_update', $espresso_db_update);
535
+		}
536
+		do_action('FHEE__EE_System__manage_fix_espresso_db_upgrade_option__complete', $espresso_db_update);
537
+		return $espresso_db_update;
538
+	}
539
+
540
+
541
+
542
+	/**
543
+	 * Does the traditional work of setting up the plugin's database and adding default data.
544
+	 * If migration script/process did not exist, this is what would happen on every activation/reactivation/upgrade.
545
+	 * NOTE: if we're in maintenance mode (which would be the case if we detect there are data
546
+	 * migration scripts that need to be run and a version change happens), enqueues core for database initialization,
547
+	 * so that it will be done when migrations are finished
548
+	 *
549
+	 * @param boolean $initialize_addons_too if true, we double-check addons' database tables etc too;
550
+	 * @param boolean $verify_schema         if true will re-check the database tables have the correct schema.
551
+	 *                                       This is a resource-intensive job
552
+	 *                                       so we prefer to only do it when necessary
553
+	 * @return void
554
+	 * @throws EE_Error
555
+	 */
556
+	public function initialize_db_if_no_migrations_required($initialize_addons_too = false, $verify_schema = true)
557
+	{
558
+		$request_type = $this->detect_req_type();
559
+		//only initialize system if we're not in maintenance mode.
560
+		if ($this->maintenance_mode->level() !== EE_Maintenance_Mode::level_2_complete_maintenance) {
561
+			update_option('ee_flush_rewrite_rules', true);
562
+			if ($verify_schema) {
563
+				EEH_Activation::initialize_db_and_folders();
564
+			}
565
+			EEH_Activation::initialize_db_content();
566
+			EEH_Activation::system_initialization();
567
+			if ($initialize_addons_too) {
568
+				$this->initialize_addons();
569
+			}
570
+		} else {
571
+			EE_Data_Migration_Manager::instance()->enqueue_db_initialization_for('Core');
572
+		}
573
+		if ($request_type === EE_System::req_type_new_activation
574
+			|| $request_type === EE_System::req_type_reactivation
575
+			|| (
576
+				$request_type === EE_System::req_type_upgrade
577
+				&& $this->is_major_version_change()
578
+			)
579
+		) {
580
+			add_action('AHEE__EE_System__initialize_last', array($this, 'redirect_to_about_ee'), 9);
581
+		}
582
+	}
583
+
584
+
585
+
586
+	/**
587
+	 * Initializes the db for all registered addons
588
+	 *
589
+	 * @throws EE_Error
590
+	 */
591
+	public function initialize_addons()
592
+	{
593
+		//foreach registered addon, make sure its db is up-to-date too
594
+		foreach ($this->registry->addons as $addon) {
595
+			if ($addon instanceof EE_Addon) {
596
+				$addon->initialize_db_if_no_migrations_required();
597
+			}
598
+		}
599
+	}
600
+
601
+
602
+
603
+	/**
604
+	 * Adds the current code version to the saved wp option which stores a list of all ee versions ever installed.
605
+	 *
606
+	 * @param    array  $version_history
607
+	 * @param    string $current_version_to_add version to be added to the version history
608
+	 * @return    boolean success as to whether or not this option was changed
609
+	 */
610
+	public function update_list_of_installed_versions($version_history = null, $current_version_to_add = null)
611
+	{
612
+		if (! $version_history) {
613
+			$version_history = $this->fix_espresso_db_upgrade_option($version_history);
614
+		}
615
+		if ($current_version_to_add === null) {
616
+			$current_version_to_add = espresso_version();
617
+		}
618
+		$version_history[ $current_version_to_add ][] = date('Y-m-d H:i:s', time());
619
+		// re-save
620
+		return update_option('espresso_db_update', $version_history);
621
+	}
622
+
623
+
624
+
625
+	/**
626
+	 * Detects if the current version indicated in the has existed in the list of
627
+	 * previously-installed versions of EE (espresso_db_update). Does NOT modify it (ie, no side-effect)
628
+	 *
629
+	 * @param array $espresso_db_update array from the wp option stored under the name 'espresso_db_update'.
630
+	 *                                  If not supplied, fetches it from the options table.
631
+	 *                                  Also, caches its result so later parts of the code can also know whether
632
+	 *                                  there's been an update or not. This way we can add the current version to
633
+	 *                                  espresso_db_update, but still know if this is a new install or not
634
+	 * @return int one of the constants on EE_System::req_type_
635
+	 */
636
+	public function detect_req_type($espresso_db_update = null)
637
+	{
638
+		if ($this->_req_type === null) {
639
+			$espresso_db_update          = ! empty($espresso_db_update)
640
+				? $espresso_db_update
641
+				: $this->fix_espresso_db_upgrade_option();
642
+			$this->_req_type             = EE_System::detect_req_type_given_activation_history(
643
+				$espresso_db_update,
644
+				'ee_espresso_activation', espresso_version()
645
+			);
646
+			$this->_major_version_change = $this->_detect_major_version_change($espresso_db_update);
647
+			$this->request->setIsActivation($this->_req_type !== EE_System::req_type_normal);
648
+		}
649
+		return $this->_req_type;
650
+	}
651
+
652
+
653
+
654
+	/**
655
+	 * Returns whether or not there was a non-micro version change (ie, change in either
656
+	 * the first or second number in the version. Eg 4.9.0.rc.001 to 4.10.0.rc.000,
657
+	 * but not 4.9.0.rc.0001 to 4.9.1.rc.0001
658
+	 *
659
+	 * @param $activation_history
660
+	 * @return bool
661
+	 */
662
+	private function _detect_major_version_change($activation_history)
663
+	{
664
+		$previous_version       = EE_System::_get_most_recently_active_version_from_activation_history($activation_history);
665
+		$previous_version_parts = explode('.', $previous_version);
666
+		$current_version_parts  = explode('.', espresso_version());
667
+		return isset($previous_version_parts[0], $previous_version_parts[1], $current_version_parts[0], $current_version_parts[1])
668
+			   && ($previous_version_parts[0] !== $current_version_parts[0]
669
+				   || $previous_version_parts[1] !== $current_version_parts[1]
670
+			   );
671
+	}
672
+
673
+
674
+
675
+	/**
676
+	 * Returns true if either the major or minor version of EE changed during this request.
677
+	 * Eg 4.9.0.rc.001 to 4.10.0.rc.000, but not 4.9.0.rc.0001 to 4.9.1.rc.0001
678
+	 *
679
+	 * @return bool
680
+	 */
681
+	public function is_major_version_change()
682
+	{
683
+		return $this->_major_version_change;
684
+	}
685
+
686
+
687
+
688
+	/**
689
+	 * Determines the request type for any ee addon, given three piece of info: the current array of activation
690
+	 * histories (for core that' 'espresso_db_update' wp option); the name of the WordPress option which is temporarily
691
+	 * set upon activation of the plugin (for core it's 'ee_espresso_activation'); and the version that this plugin was
692
+	 * just activated to (for core that will always be espresso_version())
693
+	 *
694
+	 * @param array  $activation_history_for_addon     the option's value which stores the activation history for this
695
+	 *                                                 ee plugin. for core that's 'espresso_db_update'
696
+	 * @param string $activation_indicator_option_name the name of the WordPress option that is temporarily set to
697
+	 *                                                 indicate that this plugin was just activated
698
+	 * @param string $version_to_upgrade_to            the version that was just upgraded to (for core that will be
699
+	 *                                                 espresso_version())
700
+	 * @return int one of the constants on EE_System::req_type_*
701
+	 */
702
+	public static function detect_req_type_given_activation_history(
703
+		$activation_history_for_addon,
704
+		$activation_indicator_option_name,
705
+		$version_to_upgrade_to
706
+	) {
707
+		$version_is_higher = self::_new_version_is_higher($activation_history_for_addon, $version_to_upgrade_to);
708
+		if ($activation_history_for_addon) {
709
+			//it exists, so this isn't a completely new install
710
+			//check if this version already in that list of previously installed versions
711
+			if (! isset($activation_history_for_addon[ $version_to_upgrade_to ])) {
712
+				//it a version we haven't seen before
713
+				if ($version_is_higher === 1) {
714
+					$req_type = EE_System::req_type_upgrade;
715
+				} else {
716
+					$req_type = EE_System::req_type_downgrade;
717
+				}
718
+				delete_option($activation_indicator_option_name);
719
+			} else {
720
+				// its not an update. maybe a reactivation?
721
+				if (get_option($activation_indicator_option_name, false)) {
722
+					if ($version_is_higher === -1) {
723
+						$req_type = EE_System::req_type_downgrade;
724
+					} elseif ($version_is_higher === 0) {
725
+						//we've seen this version before, but it's an activation. must be a reactivation
726
+						$req_type = EE_System::req_type_reactivation;
727
+					} else {//$version_is_higher === 1
728
+						$req_type = EE_System::req_type_upgrade;
729
+					}
730
+					delete_option($activation_indicator_option_name);
731
+				} else {
732
+					//we've seen this version before and the activation indicate doesn't show it was just activated
733
+					if ($version_is_higher === -1) {
734
+						$req_type = EE_System::req_type_downgrade;
735
+					} elseif ($version_is_higher === 0) {
736
+						//we've seen this version before and it's not an activation. its normal request
737
+						$req_type = EE_System::req_type_normal;
738
+					} else {//$version_is_higher === 1
739
+						$req_type = EE_System::req_type_upgrade;
740
+					}
741
+				}
742
+			}
743
+		} else {
744
+			//brand new install
745
+			$req_type = EE_System::req_type_new_activation;
746
+			delete_option($activation_indicator_option_name);
747
+		}
748
+		return $req_type;
749
+	}
750
+
751
+
752
+
753
+	/**
754
+	 * Detects if the $version_to_upgrade_to is higher than the most recent version in
755
+	 * the $activation_history_for_addon
756
+	 *
757
+	 * @param array  $activation_history_for_addon (keys are versions, values are arrays of times activated,
758
+	 *                                             sometimes containing 'unknown-date'
759
+	 * @param string $version_to_upgrade_to        (current version)
760
+	 * @return int results of version_compare( $version_to_upgrade_to, $most_recently_active_version ).
761
+	 *                                             ie, -1 if $version_to_upgrade_to is LOWER (downgrade);
762
+	 *                                             0 if $version_to_upgrade_to MATCHES (reactivation or normal request);
763
+	 *                                             1 if $version_to_upgrade_to is HIGHER (upgrade) ;
764
+	 */
765
+	private static function _new_version_is_higher($activation_history_for_addon, $version_to_upgrade_to)
766
+	{
767
+		//find the most recently-activated version
768
+		$most_recently_active_version =
769
+			EE_System::_get_most_recently_active_version_from_activation_history($activation_history_for_addon);
770
+		return version_compare($version_to_upgrade_to, $most_recently_active_version);
771
+	}
772
+
773
+
774
+
775
+	/**
776
+	 * Gets the most recently active version listed in the activation history,
777
+	 * and if none are found (ie, it's a brand new install) returns '0.0.0.dev.000'.
778
+	 *
779
+	 * @param array $activation_history  (keys are versions, values are arrays of times activated,
780
+	 *                                   sometimes containing 'unknown-date'
781
+	 * @return string
782
+	 */
783
+	private static function _get_most_recently_active_version_from_activation_history($activation_history)
784
+	{
785
+		$most_recently_active_version_activation = '1970-01-01 00:00:00';
786
+		$most_recently_active_version            = '0.0.0.dev.000';
787
+		if (is_array($activation_history)) {
788
+			foreach ($activation_history as $version => $times_activated) {
789
+				//check there is a record of when this version was activated. Otherwise,
790
+				//mark it as unknown
791
+				if (! $times_activated) {
792
+					$times_activated = array('unknown-date');
793
+				}
794
+				if (is_string($times_activated)) {
795
+					$times_activated = array($times_activated);
796
+				}
797
+				foreach ($times_activated as $an_activation) {
798
+					if ($an_activation !== 'unknown-date'
799
+						&& $an_activation
800
+						   > $most_recently_active_version_activation) {
801
+						$most_recently_active_version            = $version;
802
+						$most_recently_active_version_activation = $an_activation === 'unknown-date'
803
+							? '1970-01-01 00:00:00'
804
+							: $an_activation;
805
+					}
806
+				}
807
+			}
808
+		}
809
+		return $most_recently_active_version;
810
+	}
811
+
812
+
813
+
814
+	/**
815
+	 * This redirects to the about EE page after activation
816
+	 *
817
+	 * @return void
818
+	 */
819
+	public function redirect_to_about_ee()
820
+	{
821
+		$notices = EE_Error::get_notices(false);
822
+		//if current user is an admin and it's not an ajax or rest request
823
+		if (
824
+			! isset($notices['errors'])
825
+			&& $this->request->isAdmin()
826
+			&& apply_filters(
827
+				'FHEE__EE_System__redirect_to_about_ee__do_redirect',
828
+				$this->capabilities->current_user_can('manage_options', 'espresso_about_default')
829
+			)
830
+		) {
831
+			$query_params = array('page' => 'espresso_about');
832
+			if (EE_System::instance()->detect_req_type() === EE_System::req_type_new_activation) {
833
+				$query_params['new_activation'] = true;
834
+			}
835
+			if (EE_System::instance()->detect_req_type() === EE_System::req_type_reactivation) {
836
+				$query_params['reactivation'] = true;
837
+			}
838
+			$url = add_query_arg($query_params, admin_url('admin.php'));
839
+			wp_safe_redirect($url);
840
+			exit();
841
+		}
842
+	}
843
+
844
+
845
+
846
+	/**
847
+	 * load_core_configuration
848
+	 * this is hooked into 'AHEE__EE_Bootstrap__load_core_configuration'
849
+	 * which runs during the WP 'plugins_loaded' action at priority 5
850
+	 *
851
+	 * @return void
852
+	 * @throws ReflectionException
853
+	 */
854
+	public function load_core_configuration()
855
+	{
856
+		do_action('AHEE__EE_System__load_core_configuration__begin', $this);
857
+		$this->loader->getShared('EE_Load_Textdomain');
858
+		//load textdomain
859
+		EE_Load_Textdomain::load_textdomain();
860
+		// load and setup EE_Config and EE_Network_Config
861
+		$config = $this->loader->getShared('EE_Config');
862
+		$this->loader->getShared('EE_Network_Config');
863
+		// setup autoloaders
864
+		// enable logging?
865
+		if ($config->admin->use_full_logging) {
866
+			$this->loader->getShared('EE_Log');
867
+		}
868
+		// check for activation errors
869
+		$activation_errors = get_option('ee_plugin_activation_errors', false);
870
+		if ($activation_errors) {
871
+			EE_Error::add_error($activation_errors, __FILE__, __FUNCTION__, __LINE__);
872
+			update_option('ee_plugin_activation_errors', false);
873
+		}
874
+		// get model names
875
+		$this->_parse_model_names();
876
+		//load caf stuff a chance to play during the activation process too.
877
+		$this->_maybe_brew_regular();
878
+		do_action('AHEE__EE_System__load_core_configuration__complete', $this);
879
+	}
880
+
881
+
882
+
883
+	/**
884
+	 * cycles through all of the models/*.model.php files, and assembles an array of model names
885
+	 *
886
+	 * @return void
887
+	 * @throws ReflectionException
888
+	 */
889
+	private function _parse_model_names()
890
+	{
891
+		//get all the files in the EE_MODELS folder that end in .model.php
892
+		$models                 = glob(EE_MODELS . '*.model.php');
893
+		$model_names            = array();
894
+		$non_abstract_db_models = array();
895
+		foreach ($models as $model) {
896
+			// get model classname
897
+			$classname       = EEH_File::get_classname_from_filepath_with_standard_filename($model);
898
+			$short_name      = str_replace('EEM_', '', $classname);
899
+			$reflectionClass = new ReflectionClass($classname);
900
+			if ($reflectionClass->isSubclassOf('EEM_Base') && ! $reflectionClass->isAbstract()) {
901
+				$non_abstract_db_models[ $short_name ] = $classname;
902
+			}
903
+			$model_names[ $short_name ] = $classname;
904
+		}
905
+		$this->registry->models                 = apply_filters('FHEE__EE_System__parse_model_names', $model_names);
906
+		$this->registry->non_abstract_db_models = apply_filters(
907
+			'FHEE__EE_System__parse_implemented_model_names',
908
+			$non_abstract_db_models
909
+		);
910
+	}
911
+
912
+
913
+
914
+	/**
915
+	 * The purpose of this method is to simply check for a file named "caffeinated/brewing_regular.php" for any hooks
916
+	 * that need to be setup before our EE_System launches.
917
+	 *
918
+	 * @return void
919
+	 */
920
+	private function _maybe_brew_regular()
921
+	{
922
+		if ((! defined('EE_DECAF') || EE_DECAF !== true) && is_readable(EE_CAFF_PATH . 'brewing_regular.php')) {
923
+			require_once EE_CAFF_PATH . 'brewing_regular.php';
924
+		}
925
+	}
926
+
927
+
928
+
929
+	/**
930
+	 * register_shortcodes_modules_and_widgets
931
+	 * generate lists of shortcodes and modules, then verify paths and classes
932
+	 * This is hooked into 'AHEE__EE_Bootstrap__register_shortcodes_modules_and_widgets'
933
+	 * which runs during the WP 'plugins_loaded' action at priority 7
934
+	 *
935
+	 * @access public
936
+	 * @return void
937
+	 * @throws Exception
938
+	 */
939
+	public function register_shortcodes_modules_and_widgets()
940
+	{
941
+		if ($this->request->isFrontend() || $this->request->isIframe()) {
942
+			try {
943
+				// load, register, and add shortcodes the new way
944
+				$this->loader->getShared(
945
+					'EventEspresso\core\services\shortcodes\ShortcodesManager',
946
+					array(
947
+						// and the old way, but we'll put it under control of the new system
948
+						EE_Config::getLegacyShortcodesManager(),
949
+					)
950
+				);
951
+			} catch (Exception $exception) {
952
+				new ExceptionStackTraceDisplay($exception);
953
+			}
954
+		}
955
+		do_action('AHEE__EE_System__register_shortcodes_modules_and_widgets');
956
+		// check for addons using old hook point
957
+		if (has_action('AHEE__EE_System__register_shortcodes_modules_and_addons')) {
958
+			$this->_incompatible_addon_error();
959
+		}
960
+	}
961
+
962
+
963
+
964
+	/**
965
+	 * _incompatible_addon_error
966
+	 *
967
+	 * @access public
968
+	 * @return void
969
+	 */
970
+	private function _incompatible_addon_error()
971
+	{
972
+		// get array of classes hooking into here
973
+		$class_names = EEH_Class_Tools::get_class_names_for_all_callbacks_on_hook(
974
+			'AHEE__EE_System__register_shortcodes_modules_and_addons'
975
+		);
976
+		if (! empty($class_names)) {
977
+			$msg = __(
978
+				'The following plugins, addons, or modules appear to be incompatible with this version of Event Espresso and were automatically deactivated to avoid fatal errors:',
979
+				'event_espresso'
980
+			);
981
+			$msg .= '<ul>';
982
+			foreach ($class_names as $class_name) {
983
+				$msg .= '<li><b>Event Espresso - ' . str_replace(
984
+						array('EE_', 'EEM_', 'EED_', 'EES_', 'EEW_'), '',
985
+						$class_name
986
+					) . '</b></li>';
987
+			}
988
+			$msg .= '</ul>';
989
+			$msg .= __(
990
+				'Compatibility issues can be avoided and/or resolved by keeping addons and plugins updated to the latest version.',
991
+				'event_espresso'
992
+			);
993
+			// save list of incompatible addons to wp-options for later use
994
+			add_option('ee_incompatible_addons', $class_names, '', 'no');
995
+			if (is_admin()) {
996
+				EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
997
+			}
998
+		}
999
+	}
1000
+
1001
+
1002
+
1003
+	/**
1004
+	 * brew_espresso
1005
+	 * begins the process of setting hooks for initializing EE in the correct order
1006
+	 * This is happening on the 'AHEE__EE_Bootstrap__brew_espresso' hook point
1007
+	 * which runs during the WP 'plugins_loaded' action at priority 9
1008
+	 *
1009
+	 * @return void
1010
+	 */
1011
+	public function brew_espresso()
1012
+	{
1013
+		do_action('AHEE__EE_System__brew_espresso__begin', $this);
1014
+		// load some final core systems
1015
+		add_action('init', array($this, 'set_hooks_for_core'), 1);
1016
+		add_action('init', array($this, 'perform_activations_upgrades_and_migrations'), 3);
1017
+		add_action('init', array($this, 'load_CPTs_and_session'), 5);
1018
+		add_action('init', array($this, 'load_controllers'), 7);
1019
+		add_action('init', array($this, 'core_loaded_and_ready'), 9);
1020
+		add_action('init', array($this, 'initialize'), 10);
1021
+		add_action('init', array($this, 'initialize_last'), 100);
1022
+		if (is_admin() && apply_filters('FHEE__EE_System__brew_espresso__load_pue', true)) {
1023
+			// pew pew pew
1024
+			$this->loader->getShared('EE_PUE');
1025
+			do_action('AHEE__EE_System__brew_espresso__after_pue_init');
1026
+		}
1027
+		do_action('AHEE__EE_System__brew_espresso__complete', $this);
1028
+	}
1029
+
1030
+
1031
+
1032
+	/**
1033
+	 *    set_hooks_for_core
1034
+	 *
1035
+	 * @access public
1036
+	 * @return    void
1037
+	 * @throws EE_Error
1038
+	 */
1039
+	public function set_hooks_for_core()
1040
+	{
1041
+		$this->_deactivate_incompatible_addons();
1042
+		do_action('AHEE__EE_System__set_hooks_for_core');
1043
+		//caps need to be initialized on every request so that capability maps are set.
1044
+		//@see https://events.codebasehq.com/projects/event-espresso/tickets/8674
1045
+		$this->registry->CAP->init_caps();
1046
+	}
1047
+
1048
+
1049
+
1050
+	/**
1051
+	 * Using the information gathered in EE_System::_incompatible_addon_error,
1052
+	 * deactivates any addons considered incompatible with the current version of EE
1053
+	 */
1054
+	private function _deactivate_incompatible_addons()
1055
+	{
1056
+		$incompatible_addons = get_option('ee_incompatible_addons', array());
1057
+		if (! empty($incompatible_addons)) {
1058
+			$active_plugins = get_option('active_plugins', array());
1059
+			foreach ($active_plugins as $active_plugin) {
1060
+				foreach ($incompatible_addons as $incompatible_addon) {
1061
+					if (strpos($active_plugin, $incompatible_addon) !== false) {
1062
+						unset($_GET['activate']);
1063
+						espresso_deactivate_plugin($active_plugin);
1064
+					}
1065
+				}
1066
+			}
1067
+		}
1068
+	}
1069
+
1070
+
1071
+
1072
+	/**
1073
+	 *    perform_activations_upgrades_and_migrations
1074
+	 *
1075
+	 * @access public
1076
+	 * @return    void
1077
+	 */
1078
+	public function perform_activations_upgrades_and_migrations()
1079
+	{
1080
+		//first check if we had previously attempted to setup EE's directories but failed
1081
+		if ($this->request->isActivation() && EEH_Activation::upload_directories_incomplete()) {
1082
+			EEH_Activation::create_upload_directories();
1083
+		}
1084
+		do_action('AHEE__EE_System__perform_activations_upgrades_and_migrations');
1085
+	}
1086
+
1087
+
1088
+
1089
+	/**
1090
+	 *    load_CPTs_and_session
1091
+	 *
1092
+	 * @access public
1093
+	 * @return    void
1094
+	 */
1095
+	public function load_CPTs_and_session()
1096
+	{
1097
+		do_action('AHEE__EE_System__load_CPTs_and_session__start');
1098
+		// register Custom Post Types
1099
+		$this->loader->getShared('EE_Register_CPTs');
1100
+		do_action('AHEE__EE_System__load_CPTs_and_session__complete');
1101
+	}
1102
+
1103
+
1104
+
1105
+	/**
1106
+	 * load_controllers
1107
+	 * this is the best place to load any additional controllers that needs access to EE core.
1108
+	 * it is expected that all basic core EE systems, that are not dependant on the current request are loaded at this
1109
+	 * time
1110
+	 *
1111
+	 * @access public
1112
+	 * @return void
1113
+	 */
1114
+	public function load_controllers()
1115
+	{
1116
+		do_action('AHEE__EE_System__load_controllers__start');
1117
+		// let's get it started
1118
+		if (
1119
+			! $this->maintenance_mode->level()
1120
+			&& ($this->request->isFrontend() || $this->request->isFrontAjax())
1121
+		) {
1122
+			do_action('AHEE__EE_System__load_controllers__load_front_controllers');
1123
+			$this->loader->getShared('EE_Front_Controller');
1124
+		} elseif ($this->request->isAdmin() || $this->request->isAdminAjax()) {
1125
+			do_action('AHEE__EE_System__load_controllers__load_admin_controllers');
1126
+			$this->loader->getShared('EE_Admin');
1127
+		}
1128
+		do_action('AHEE__EE_System__load_controllers__complete');
1129
+	}
1130
+
1131
+
1132
+
1133
+	/**
1134
+	 * core_loaded_and_ready
1135
+	 * all of the basic EE core should be loaded at this point and available regardless of M-Mode
1136
+	 *
1137
+	 * @access public
1138
+	 * @return void
1139
+	 */
1140
+	public function core_loaded_and_ready()
1141
+	{
1142
+		if (
1143
+			$this->request->isAdmin()
1144
+			|| $this->request->isEeAjax()
1145
+			|| $this->request->isFrontend()
1146
+		) {
1147
+			$this->loader->getShared('EE_Session');
1148
+		}
1149
+		do_action('AHEE__EE_System__core_loaded_and_ready');
1150
+		// load_espresso_template_tags
1151
+		if (
1152
+			is_readable(EE_PUBLIC . 'template_tags.php')
1153
+			&& ($this->request->isFrontend() || $this->request->isIframe() || $this->request->isFeed())
1154
+		) {
1155
+			require_once EE_PUBLIC . 'template_tags.php';
1156
+		}
1157
+		do_action('AHEE__EE_System__set_hooks_for_shortcodes_modules_and_addons');
1158
+		if ($this->request->isAdmin() || $this->request->isFrontend() || $this->request->isIframe()) {
1159
+			$this->loader->getShared('EventEspresso\core\services\assets\Registry');
1160
+		}
1161
+	}
1162
+
1163
+
1164
+
1165
+	/**
1166
+	 * initialize
1167
+	 * this is the best place to begin initializing client code
1168
+	 *
1169
+	 * @access public
1170
+	 * @return void
1171
+	 */
1172
+	public function initialize()
1173
+	{
1174
+		do_action('AHEE__EE_System__initialize');
1175
+	}
1176
+
1177
+
1178
+
1179
+	/**
1180
+	 * initialize_last
1181
+	 * this is run really late during the WP init hook point, and ensures that mostly everything else that needs to
1182
+	 * initialize has done so
1183
+	 *
1184
+	 * @access public
1185
+	 * @return void
1186
+	 */
1187
+	public function initialize_last()
1188
+	{
1189
+		do_action('AHEE__EE_System__initialize_last');
1190
+		add_action('admin_bar_init', array($this, 'addEspressoToolbar'));
1191
+	}
1192
+
1193
+
1194
+
1195
+	/**
1196
+	 * @return void
1197
+	 * @throws EE_Error
1198
+	 */
1199
+	public function addEspressoToolbar()
1200
+	{
1201
+		$this->loader->getShared(
1202
+			'EventEspresso\core\domain\services\admin\AdminToolBar',
1203
+			array($this->registry->CAP)
1204
+		);
1205
+	}
1206
+
1207
+
1208
+
1209
+	/**
1210
+	 * do_not_cache
1211
+	 * sets no cache headers and defines no cache constants for WP plugins
1212
+	 *
1213
+	 * @access public
1214
+	 * @return void
1215
+	 */
1216
+	public static function do_not_cache()
1217
+	{
1218
+		// set no cache constants
1219
+		if (! defined('DONOTCACHEPAGE')) {
1220
+			define('DONOTCACHEPAGE', true);
1221
+		}
1222
+		if (! defined('DONOTCACHCEOBJECT')) {
1223
+			define('DONOTCACHCEOBJECT', true);
1224
+		}
1225
+		if (! defined('DONOTCACHEDB')) {
1226
+			define('DONOTCACHEDB', true);
1227
+		}
1228
+		// add no cache headers
1229
+		add_action('send_headers', array('EE_System', 'nocache_headers'), 10);
1230
+		// plus a little extra for nginx and Google Chrome
1231
+		add_filter('nocache_headers', array('EE_System', 'extra_nocache_headers'), 10, 1);
1232
+		// prevent browsers from prefetching of the rel='next' link, because it may contain content that interferes with the registration process
1233
+		remove_action('wp_head', 'adjacent_posts_rel_link_wp_head');
1234
+	}
1235
+
1236
+
1237
+
1238
+	/**
1239
+	 *    extra_nocache_headers
1240
+	 *
1241
+	 * @access    public
1242
+	 * @param $headers
1243
+	 * @return    array
1244
+	 */
1245
+	public static function extra_nocache_headers($headers)
1246
+	{
1247
+		// for NGINX
1248
+		$headers['X-Accel-Expires'] = 0;
1249
+		// plus extra for Google Chrome since it doesn't seem to respect "no-cache", but WILL respect "no-store"
1250
+		$headers['Cache-Control'] = 'no-store, no-cache, must-revalidate, max-age=0';
1251
+		return $headers;
1252
+	}
1253
+
1254
+
1255
+
1256
+	/**
1257
+	 *    nocache_headers
1258
+	 *
1259
+	 * @access    public
1260
+	 * @return    void
1261
+	 */
1262
+	public static function nocache_headers()
1263
+	{
1264
+		nocache_headers();
1265
+	}
1266
+
1267
+
1268
+
1269
+	/**
1270
+	 * simply hooks into "wp_list_pages_exclude" filter (for wp_list_pages method) and makes sure EE critical pages are
1271
+	 * never returned with the function.
1272
+	 *
1273
+	 * @param  array $exclude_array any existing pages being excluded are in this array.
1274
+	 * @return array
1275
+	 */
1276
+	public function remove_pages_from_wp_list_pages($exclude_array)
1277
+	{
1278
+		return array_merge($exclude_array, $this->registry->CFG->core->get_critical_pages_array());
1279
+	}
1280 1280
 
1281 1281
 
1282 1282
 
Please login to merge, or discard this patch.
admin_pages/transactions/Transactions_Admin_Page.core.php 3 patches
Doc Comments   +1 added lines patch added patch discarded remove patch
@@ -2166,6 +2166,7 @@
 block discarded – undo
2166 2166
      *
2167 2167
      * @access protected
2168 2168
      * @param \EE_Payment | null $payment
2169
+     * @param EE_Payment $payment
2169 2170
      */
2170 2171
     protected function _maybe_send_notifications($payment = null)
2171 2172
     {
Please login to merge, or discard this patch.
Spacing   +79 added lines, -79 removed lines patch added patch discarded remove patch
@@ -266,7 +266,7 @@  discard block
 block discarded – undo
266 266
             'An error occurred! Your request may have been processed, but a valid response from the server was not received. Please refresh the page and try again.',
267 267
             'event_espresso'
268 268
         );
269
-        EE_Registry::$i18n_js_strings['error_occurred']          = esc_html__(
269
+        EE_Registry::$i18n_js_strings['error_occurred'] = esc_html__(
270 270
             'An error occurred! Please refresh the page and try again.',
271 271
             'event_espresso'
272 272
         );
@@ -364,13 +364,13 @@  discard block
 block discarded – undo
364 364
         //enqueue style
365 365
         wp_register_style(
366 366
             'espresso_txn',
367
-            TXN_ASSETS_URL . 'espresso_transactions_admin.css',
367
+            TXN_ASSETS_URL.'espresso_transactions_admin.css',
368 368
             array(),
369 369
             EVENT_ESPRESSO_VERSION
370 370
         );
371 371
         wp_enqueue_style('espresso_txn');
372 372
         //scripts
373
-        wp_register_script('espresso_txn', TXN_ASSETS_URL . 'espresso_transactions_admin.js', array(
373
+        wp_register_script('espresso_txn', TXN_ASSETS_URL.'espresso_transactions_admin.js', array(
374 374
             'ee_admin_js',
375 375
             'ee-datepicker',
376 376
             'jquery-ui-datepicker',
@@ -466,7 +466,7 @@  discard block
 block discarded – undo
466 466
             : null;
467 467
         $this->_transaction->verify_abandoned_transaction_status();
468 468
 
469
-        if (! $this->_transaction instanceof EE_Transaction) {
469
+        if ( ! $this->_transaction instanceof EE_Transaction) {
470 470
             $error_msg = sprintf(
471 471
                 esc_html__(
472 472
                     'An error occurred and the details for the transaction with the ID # %d could not be retrieved.',
@@ -564,7 +564,7 @@  discard block
 block discarded – undo
564 564
             'FHEE__Transactions_Admin_Page___transaction_legend_items__more_items',
565 565
             array(
566 566
                 'overpaid'   => array(
567
-                    'class' => 'ee-status-legend ee-status-legend-' . EEM_Transaction::overpaid_status_code,
567
+                    'class' => 'ee-status-legend ee-status-legend-'.EEM_Transaction::overpaid_status_code,
568 568
                     'desc'  => EEH_Template::pretty_status(
569 569
                         EEM_Transaction::overpaid_status_code,
570 570
                         false,
@@ -572,7 +572,7 @@  discard block
 block discarded – undo
572 572
                     ),
573 573
                 ),
574 574
                 'complete'   => array(
575
-                    'class' => 'ee-status-legend ee-status-legend-' . EEM_Transaction::complete_status_code,
575
+                    'class' => 'ee-status-legend ee-status-legend-'.EEM_Transaction::complete_status_code,
576 576
                     'desc'  => EEH_Template::pretty_status(
577 577
                         EEM_Transaction::complete_status_code,
578 578
                         false,
@@ -580,7 +580,7 @@  discard block
 block discarded – undo
580 580
                     ),
581 581
                 ),
582 582
                 'incomplete' => array(
583
-                    'class' => 'ee-status-legend ee-status-legend-' . EEM_Transaction::incomplete_status_code,
583
+                    'class' => 'ee-status-legend ee-status-legend-'.EEM_Transaction::incomplete_status_code,
584 584
                     'desc'  => EEH_Template::pretty_status(
585 585
                         EEM_Transaction::incomplete_status_code,
586 586
                         false,
@@ -588,7 +588,7 @@  discard block
 block discarded – undo
588 588
                     ),
589 589
                 ),
590 590
                 'abandoned'  => array(
591
-                    'class' => 'ee-status-legend ee-status-legend-' . EEM_Transaction::abandoned_status_code,
591
+                    'class' => 'ee-status-legend ee-status-legend-'.EEM_Transaction::abandoned_status_code,
592 592
                     'desc'  => EEH_Template::pretty_status(
593 593
                         EEM_Transaction::abandoned_status_code,
594 594
                         false,
@@ -596,7 +596,7 @@  discard block
 block discarded – undo
596 596
                     ),
597 597
                 ),
598 598
                 'failed'     => array(
599
-                    'class' => 'ee-status-legend ee-status-legend-' . EEM_Transaction::failed_status_code,
599
+                    'class' => 'ee-status-legend ee-status-legend-'.EEM_Transaction::failed_status_code,
600 600
                     'desc'  => EEH_Template::pretty_status(
601 601
                         EEM_Transaction::failed_status_code,
602 602
                         false,
@@ -645,11 +645,11 @@  discard block
 block discarded – undo
645 645
                     'Click to Edit event',
646 646
                     'event_espresso'
647 647
                 )
648
-                . '">' . $event->get('EVT_name') . '</a>',
648
+                . '">'.$event->get('EVT_name').'</a>',
649 649
                 '</h3>'
650 650
             )
651 651
             : '';
652
-        $this->_template_args['after_list_table']  = $this->_display_legend($this->_transaction_legend_items());
652
+        $this->_template_args['after_list_table'] = $this->_display_legend($this->_transaction_legend_items());
653 653
         $this->display_admin_list_table_page_with_no_sidebar();
654 654
     }
655 655
 
@@ -691,7 +691,7 @@  discard block
 block discarded – undo
691 691
 
692 692
         $this->_template_args['txn_status']['value'] = self::$_txn_status[$this->_transaction->get('STS_ID')];
693 693
         $this->_template_args['txn_status']['label'] = esc_html__('Transaction Status', 'event_espresso');
694
-        $this->_template_args['txn_status']['class'] = 'status-' . $this->_transaction->get('STS_ID');
694
+        $this->_template_args['txn_status']['class'] = 'status-'.$this->_transaction->get('STS_ID');
695 695
 
696 696
         $this->_template_args['grand_total'] = $this->_transaction->get('TXN_total');
697 697
         $this->_template_args['total_paid']  = $this->_transaction->get('TXN_paid');
@@ -772,7 +772,7 @@  discard block
 block discarded – undo
772 772
 
773 773
 
774 774
         // next link
775
-        $next_txn                                 = $this->_transaction->next(
775
+        $next_txn = $this->_transaction->next(
776 776
             null,
777 777
             array(array('STS_ID' => array('!=', EEM_Transaction::failed_status_code))),
778 778
             'TXN_ID'
@@ -787,7 +787,7 @@  discard block
 block discarded – undo
787 787
             )
788 788
             : '';
789 789
         // previous link
790
-        $previous_txn                                 = $this->_transaction->previous(
790
+        $previous_txn = $this->_transaction->previous(
791 791
             null,
792 792
             array(array('STS_ID' => array('!=', EEM_Transaction::failed_status_code))),
793 793
             'TXN_ID'
@@ -837,7 +837,7 @@  discard block
 block discarded – undo
837 837
         // grab messages at the last second
838 838
         $this->_template_args['notices'] = EE_Error::get_notices();
839 839
         // path to template
840
-        $template_path                             = TXN_TEMPLATE_PATH . 'txn_admin_details_header.template.php';
840
+        $template_path                             = TXN_TEMPLATE_PATH.'txn_admin_details_header.template.php';
841 841
         $this->_template_args['admin_page_header'] = EEH_Template::display_template(
842 842
             $template_path,
843 843
             $this->_template_args,
@@ -926,7 +926,7 @@  discard block
 block discarded – undo
926 926
 
927 927
         //get line table
928 928
         EEH_Autoloader::register_line_item_display_autoloaders();
929
-        $Line_Item_Display                       = new EE_Line_Item_Display(
929
+        $Line_Item_Display = new EE_Line_Item_Display(
930 930
             'admin_table',
931 931
             'EE_Admin_Table_Line_Item_Display_Strategy'
932 932
         );
@@ -937,13 +937,13 @@  discard block
 block discarded – undo
937 937
                                                                       ->get('REG_code');
938 938
 
939 939
         // process taxes
940
-        $taxes                         = $this->_transaction->get_many_related(
940
+        $taxes = $this->_transaction->get_many_related(
941 941
             'Line_Item',
942 942
             array(array('LIN_type' => EEM_Line_Item::type_tax))
943 943
         );
944 944
         $this->_template_args['taxes'] = ! empty($taxes) ? $taxes : false;
945 945
 
946
-        $this->_template_args['grand_total']     = EEH_Template::format_currency(
946
+        $this->_template_args['grand_total'] = EEH_Template::format_currency(
947 947
             $this->_transaction->get('TXN_total'),
948 948
             false,
949 949
             false
@@ -953,7 +953,7 @@  discard block
 block discarded – undo
953 953
 
954 954
         // process payment details
955 955
         $payments = $this->_transaction->get_many_related('Payment');
956
-        if (! empty($payments)) {
956
+        if ( ! empty($payments)) {
957 957
             $this->_template_args['payments']              = $payments;
958 958
             $this->_template_args['existing_reg_payments'] = $this->_get_registration_payment_IDs($payments);
959 959
         } else {
@@ -1014,7 +1014,7 @@  discard block
 block discarded – undo
1014 1014
                                   esc_html__('%1$s : Initiated %2$s', 'event_espresso'),
1015 1015
                                   ucwords(str_replace('_', ' ', $reg_step)),
1016 1016
                                   date(
1017
-                                      get_option('date_format') . ' ' . get_option('time_format'),
1017
+                                      get_option('date_format').' '.get_option('time_format'),
1018 1018
                                       ($reg_step_status + (get_option('gmt_offset') * HOUR_IN_SECONDS))
1019 1019
                                   )
1020 1020
                               )
@@ -1028,7 +1028,7 @@  discard block
 block discarded – undo
1028 1028
                               . '</li>';
1029 1029
             }
1030 1030
         }
1031
-        $reg_steps                                                 .= '</ul>';
1031
+        $reg_steps .= '</ul>';
1032 1032
         $this->_template_args['txn_details']['reg_steps']['value'] = $reg_steps;
1033 1033
         $this->_template_args['txn_details']['reg_steps']['label'] = esc_html__(
1034 1034
             'Registration Step Progress',
@@ -1041,11 +1041,11 @@  discard block
 block discarded – undo
1041 1041
         $this->_get_payment_status_array();
1042 1042
         $this->_get_reg_status_selection(); //sets up the template args for the reg status array for the transaction.
1043 1043
 
1044
-        $this->_template_args['transaction_form_url']    = add_query_arg(array(
1044
+        $this->_template_args['transaction_form_url'] = add_query_arg(array(
1045 1045
             'action'  => 'edit_transaction',
1046 1046
             'process' => 'transaction',
1047 1047
         ), TXN_ADMIN_URL);
1048
-        $this->_template_args['apply_payment_form_url']  = add_query_arg(array(
1048
+        $this->_template_args['apply_payment_form_url'] = add_query_arg(array(
1049 1049
             'page'   => 'espresso_transactions',
1050 1050
             'action' => 'espresso_apply_payment',
1051 1051
         ), WP_AJAX_URL);
@@ -1056,7 +1056,7 @@  discard block
 block discarded – undo
1056 1056
 
1057 1057
         // 'espresso_delete_payment_nonce'
1058 1058
 
1059
-        $template_path = TXN_TEMPLATE_PATH . 'txn_admin_details_main_meta_box_txn_details.template.php';
1059
+        $template_path = TXN_TEMPLATE_PATH.'txn_admin_details_main_meta_box_txn_details.template.php';
1060 1060
         echo EEH_Template::display_template($template_path, $this->_template_args, true);
1061 1061
     }
1062 1062
 
@@ -1085,11 +1085,11 @@  discard block
 block discarded – undo
1085 1085
                 ),
1086 1086
             ),
1087 1087
         ));
1088
-        if (! empty($reg_payments)) {
1088
+        if ( ! empty($reg_payments)) {
1089 1089
             foreach ($payments as $payment) {
1090
-                if (! $payment instanceof EE_Payment) {
1090
+                if ( ! $payment instanceof EE_Payment) {
1091 1091
                     continue;
1092
-                } elseif (! isset($existing_reg_payments[$payment->ID()])) {
1092
+                } elseif ( ! isset($existing_reg_payments[$payment->ID()])) {
1093 1093
                     $existing_reg_payments[$payment->ID()] = array();
1094 1094
                 }
1095 1095
                 foreach ($reg_payments as $reg_payment) {
@@ -1118,7 +1118,7 @@  discard block
 block discarded – undo
1118 1118
     protected function _get_registrations_to_apply_payment_to()
1119 1119
     {
1120 1120
         // we want any registration with an active status (ie: not deleted or cancelled)
1121
-        $query_params                      = array(
1121
+        $query_params = array(
1122 1122
             array(
1123 1123
                 'STS_ID' => array(
1124 1124
                     'IN',
@@ -1137,16 +1137,16 @@  discard block
 block discarded – undo
1137 1137
                                                  '',
1138 1138
                                                  'clear: both; margin: 1.5em 0 0; display: none;'
1139 1139
                                              );
1140
-        $registrations_to_apply_payment_to .= EEH_HTML::br() . EEH_HTML::div('', '', 'admin-primary-mbox-tbl-wrap');
1140
+        $registrations_to_apply_payment_to .= EEH_HTML::br().EEH_HTML::div('', '', 'admin-primary-mbox-tbl-wrap');
1141 1141
         $registrations_to_apply_payment_to .= EEH_HTML::table('', '', 'admin-primary-mbox-tbl');
1142 1142
         $registrations_to_apply_payment_to .= EEH_HTML::thead(
1143 1143
             EEH_HTML::tr(
1144
-                EEH_HTML::th(esc_html__('ID', 'event_espresso')) .
1145
-                EEH_HTML::th(esc_html__('Registrant', 'event_espresso')) .
1146
-                EEH_HTML::th(esc_html__('Ticket', 'event_espresso')) .
1147
-                EEH_HTML::th(esc_html__('Event', 'event_espresso')) .
1148
-                EEH_HTML::th(esc_html__('Paid', 'event_espresso'), '', 'txn-admin-payment-paid-td jst-cntr') .
1149
-                EEH_HTML::th(esc_html__('Owing', 'event_espresso'), '', 'txn-admin-payment-owing-td jst-cntr') .
1144
+                EEH_HTML::th(esc_html__('ID', 'event_espresso')).
1145
+                EEH_HTML::th(esc_html__('Registrant', 'event_espresso')).
1146
+                EEH_HTML::th(esc_html__('Ticket', 'event_espresso')).
1147
+                EEH_HTML::th(esc_html__('Event', 'event_espresso')).
1148
+                EEH_HTML::th(esc_html__('Paid', 'event_espresso'), '', 'txn-admin-payment-paid-td jst-cntr').
1149
+                EEH_HTML::th(esc_html__('Owing', 'event_espresso'), '', 'txn-admin-payment-owing-td jst-cntr').
1150 1150
                 EEH_HTML::th(esc_html__('Apply', 'event_espresso'), '', 'jst-cntr')
1151 1151
             )
1152 1152
         );
@@ -1161,29 +1161,29 @@  discard block
 block discarded – undo
1161 1161
                     : esc_html__('Unknown Attendee', 'event_espresso');
1162 1162
                 $owing                             = $registration->final_price() - $registration->paid();
1163 1163
                 $taxable                           = $registration->ticket()->taxable()
1164
-                    ? ' <span class="smaller-text lt-grey-text"> ' . esc_html__('+ tax', 'event_espresso') . '</span>'
1164
+                    ? ' <span class="smaller-text lt-grey-text"> '.esc_html__('+ tax', 'event_espresso').'</span>'
1165 1165
                     : '';
1166 1166
                 $checked = empty($existing_reg_payments) || in_array($registration->ID(), $existing_reg_payments)
1167 1167
                     ? ' checked="checked"'
1168 1168
                     : '';
1169
-                $disabled                          = $registration->final_price() > 0 ? '' : ' disabled';
1169
+                $disabled = $registration->final_price() > 0 ? '' : ' disabled';
1170 1170
                 $registrations_to_apply_payment_to .= EEH_HTML::tr(
1171
-                    EEH_HTML::td($registration->ID()) .
1172
-                    EEH_HTML::td($attendee_name) .
1171
+                    EEH_HTML::td($registration->ID()).
1172
+                    EEH_HTML::td($attendee_name).
1173 1173
                     EEH_HTML::td(
1174
-                        $registration->ticket()->name() . ' : ' . $registration->ticket()->pretty_price() . $taxable
1175
-                    ) .
1176
-                    EEH_HTML::td($registration->event_name()) .
1177
-                    EEH_HTML::td($registration->pretty_paid(), '', 'txn-admin-payment-paid-td jst-cntr') .
1178
-                    EEH_HTML::td(EEH_Template::format_currency($owing), '', 'txn-admin-payment-owing-td jst-cntr') .
1174
+                        $registration->ticket()->name().' : '.$registration->ticket()->pretty_price().$taxable
1175
+                    ).
1176
+                    EEH_HTML::td($registration->event_name()).
1177
+                    EEH_HTML::td($registration->pretty_paid(), '', 'txn-admin-payment-paid-td jst-cntr').
1178
+                    EEH_HTML::td(EEH_Template::format_currency($owing), '', 'txn-admin-payment-owing-td jst-cntr').
1179 1179
                     EEH_HTML::td(
1180
-                        '<input type="checkbox" value="' . $registration->ID()
1180
+                        '<input type="checkbox" value="'.$registration->ID()
1181 1181
                         . '" name="txn_admin_payment[registrations]"'
1182
-                        . $checked . $disabled . '>',
1182
+                        . $checked.$disabled.'>',
1183 1183
                         '',
1184 1184
                         'jst-cntr'
1185 1185
                     ),
1186
-                    'apply-payment-registration-row-' . $registration->ID()
1186
+                    'apply-payment-registration-row-'.$registration->ID()
1187 1187
                 );
1188 1188
             }
1189 1189
         }
@@ -1198,7 +1198,7 @@  discard block
 block discarded – undo
1198 1198
             '',
1199 1199
             'clear description'
1200 1200
         );
1201
-        $registrations_to_apply_payment_to                         .= EEH_HTML::divx();
1201
+        $registrations_to_apply_payment_to .= EEH_HTML::divx();
1202 1202
         $this->_template_args['registrations_to_apply_payment_to'] = $registrations_to_apply_payment_to;
1203 1203
     }
1204 1204
 
@@ -1263,12 +1263,12 @@  discard block
 block discarded – undo
1263 1263
                 array(
1264 1264
                     'OR*payment_method_for_payment' => array(
1265 1265
                         'PMD_ID'    => array('IN', $payment_methods_of_payments),
1266
-                        'PMD_scope' => array('LIKE', '%' . EEM_Payment_Method::scope_admin . '%'),
1266
+                        'PMD_scope' => array('LIKE', '%'.EEM_Payment_Method::scope_admin.'%'),
1267 1267
                     ),
1268 1268
                 ),
1269 1269
             );
1270 1270
         } else {
1271
-            $query_args = array(array('PMD_scope' => array('LIKE', '%' . EEM_Payment_Method::scope_admin . '%')));
1271
+            $query_args = array(array('PMD_scope' => array('LIKE', '%'.EEM_Payment_Method::scope_admin.'%')));
1272 1272
         }
1273 1273
         $this->_template_args['payment_methods'] = EEM_Payment_Method::instance()->get_all($query_args);
1274 1274
     }
@@ -1297,7 +1297,7 @@  discard block
 block discarded – undo
1297 1297
             'Line_Item',
1298 1298
             array(array('LIN_type' => 'line-item'))
1299 1299
         );
1300
-        if (! empty($line_items)) {
1300
+        if ( ! empty($line_items)) {
1301 1301
             foreach ($line_items as $item) {
1302 1302
                 if ($item instanceof EE_Line_Item) {
1303 1303
                     switch ($item->OBJ_type()) {
@@ -1307,7 +1307,7 @@  discard block
 block discarded – undo
1307 1307
                             $ticket = $item->ticket();
1308 1308
                             //right now we're only handling tickets here.
1309 1309
                             //Cause its expected that only tickets will have attendees right?
1310
-                            if (! $ticket instanceof EE_Ticket) {
1310
+                            if ( ! $ticket instanceof EE_Ticket) {
1311 1311
                                 continue;
1312 1312
                             }
1313 1313
                             try {
@@ -1316,7 +1316,7 @@  discard block
 block discarded – undo
1316 1316
                                 EE_Error::add_error($e->getMessage(), __FILE__, __FUNCTION__, __LINE__);
1317 1317
                                 $event_name = esc_html__('Unknown Event', 'event_espresso');
1318 1318
                             }
1319
-                            $event_name   .= ' - ' . $item->get('LIN_name');
1319
+                            $event_name   .= ' - '.$item->get('LIN_name');
1320 1320
                             $ticket_price = EEH_Template::format_currency($item->get('LIN_unit_price'));
1321 1321
                             // now get all of the registrations for this transaction that use this ticket
1322 1322
                             $registrations = $ticket->get_many_related(
@@ -1324,7 +1324,7 @@  discard block
 block discarded – undo
1324 1324
                                 array(array('TXN_ID' => $this->_transaction->ID()))
1325 1325
                             );
1326 1326
                             foreach ($registrations as $registration) {
1327
-                                if (! $registration instanceof EE_Registration) {
1327
+                                if ( ! $registration instanceof EE_Registration) {
1328 1328
                                     continue;
1329 1329
                                 }
1330 1330
                                 $this->_template_args['event_attendees'][$registration->ID()]['STS_ID']
@@ -1343,12 +1343,12 @@  discard block
 block discarded – undo
1343 1343
                                     $this->_template_args['event_attendees'][$registration->ID()]['attendee']
1344 1344
                                         = $attendee->full_name();
1345 1345
                                     $this->_template_args['event_attendees'][$registration->ID()]['email']
1346
-                                        = '<a href="mailto:' . $attendee->email() . '?subject=' . $event_name
1346
+                                        = '<a href="mailto:'.$attendee->email().'?subject='.$event_name
1347 1347
                                           . esc_html__(
1348 1348
                                               ' Event',
1349 1349
                                               'event_espresso'
1350 1350
                                           )
1351
-                                          . '">' . $attendee->email() . '</a>';
1351
+                                          . '">'.$attendee->email().'</a>';
1352 1352
                                     $this->_template_args['event_attendees'][$registration->ID()]['address']
1353 1353
                                         = EEH_Address::format($attendee, 'inline', false, false);
1354 1354
                                 } else {
@@ -1372,7 +1372,7 @@  discard block
 block discarded – undo
1372 1372
                 TXN_ADMIN_URL
1373 1373
             );
1374 1374
             echo EEH_Template::display_template(
1375
-                TXN_TEMPLATE_PATH . 'txn_admin_details_main_meta_box_attendees.template.php',
1375
+                TXN_TEMPLATE_PATH.'txn_admin_details_main_meta_box_attendees.template.php',
1376 1376
                 $this->_template_args,
1377 1377
                 true
1378 1378
             );
@@ -1407,12 +1407,12 @@  discard block
 block discarded – undo
1407 1407
         $primary_att = $this->_transaction->primary_registration() instanceof EE_Registration
1408 1408
             ? $this->_transaction->primary_registration()->get_first_related('Attendee')
1409 1409
             : null;
1410
-        if (! $primary_att instanceof EE_Attendee) {
1410
+        if ( ! $primary_att instanceof EE_Attendee) {
1411 1411
             $this->_template_args['no_attendee_message'] = esc_html__(
1412 1412
                 'There is no attached contact for this transaction.  The transaction either failed due to an error or was abandoned.',
1413 1413
                 'event_espresso'
1414 1414
             );
1415
-            $primary_att                                 = EEM_Attendee::instance()->create_default_object();
1415
+            $primary_att = EEM_Attendee::instance()->create_default_object();
1416 1416
         }
1417 1417
         $this->_template_args['ATT_ID']            = $primary_att->ID();
1418 1418
         $this->_template_args['prime_reg_fname']   = $primary_att->fname();
@@ -1426,7 +1426,7 @@  discard block
 block discarded – undo
1426 1426
         // get formatted address for registrant
1427 1427
         $this->_template_args['formatted_address'] = EEH_Address::format($primary_att);
1428 1428
         echo EEH_Template::display_template(
1429
-            TXN_TEMPLATE_PATH . 'txn_admin_details_side_meta_box_registrant.template.php',
1429
+            TXN_TEMPLATE_PATH.'txn_admin_details_side_meta_box_registrant.template.php',
1430 1430
             $this->_template_args,
1431 1431
             true
1432 1432
         );
@@ -1451,8 +1451,8 @@  discard block
 block discarded – undo
1451 1451
             TXN_ADMIN_URL
1452 1452
         );
1453 1453
 
1454
-        $template_path = TXN_TEMPLATE_PATH . 'txn_admin_details_side_meta_box_billing_info.template.php';
1455
-        echo EEH_Template::display_template($template_path, $this->_template_args, true);/**/
1454
+        $template_path = TXN_TEMPLATE_PATH.'txn_admin_details_side_meta_box_billing_info.template.php';
1455
+        echo EEH_Template::display_template($template_path, $this->_template_args, true); /**/
1456 1456
     }
1457 1457
 
1458 1458
 
@@ -1477,7 +1477,7 @@  discard block
 block discarded – undo
1477 1477
             'ee_edit_payments',
1478 1478
             'apply_payment_or_refund_from_registration_details'
1479 1479
         );
1480
-        if (! empty($valid_data) && $has_access) {
1480
+        if ( ! empty($valid_data) && $has_access) {
1481 1481
             $PAY_ID = $valid_data['PAY_ID'];
1482 1482
             //save  the new payment
1483 1483
             $payment = $this->_create_payment_from_request_data($valid_data);
@@ -1490,7 +1490,7 @@  discard block
 block discarded – undo
1490 1490
                 $REG_IDs = $this->_get_REG_IDs_to_apply_payment_to($payment);
1491 1491
                 $this->_remove_existing_registration_payments($payment, $PAY_ID);
1492 1492
                 // apply payment to registrations (if applicable)
1493
-                if (! empty($REG_IDs)) {
1493
+                if ( ! empty($REG_IDs)) {
1494 1494
                     $this->_update_registration_payments($transaction, $payment, $REG_IDs);
1495 1495
                     $this->_maybe_send_notifications();
1496 1496
                     // now process status changes for the same registrations
@@ -1538,7 +1538,7 @@  discard block
 block discarded – undo
1538 1538
                 );
1539 1539
             }
1540 1540
         }
1541
-        $notices              = EE_Error::get_notices(
1541
+        $notices = EE_Error::get_notices(
1542 1542
             false,
1543 1543
             false,
1544 1544
             false
@@ -1559,14 +1559,14 @@  discard block
 block discarded – undo
1559 1559
      */
1560 1560
     protected function _validate_payment_request_data()
1561 1561
     {
1562
-        if (! isset($this->_req_data['txn_admin_payment'])) {
1562
+        if ( ! isset($this->_req_data['txn_admin_payment'])) {
1563 1563
             return false;
1564 1564
         }
1565 1565
         $payment_form = $this->_generate_payment_form_section();
1566 1566
         try {
1567 1567
             if ($payment_form->was_submitted()) {
1568 1568
                 $payment_form->receive_form_submission();
1569
-                if (! $payment_form->is_valid()) {
1569
+                if ( ! $payment_form->is_valid()) {
1570 1570
                     $submission_error_messages = array();
1571 1571
                     foreach ($payment_form->get_validation_errors_accumulated() as $validation_error) {
1572 1572
                         if ($validation_error instanceof EE_Validation_Error) {
@@ -1744,7 +1744,7 @@  discard block
 block discarded – undo
1744 1744
             array('Y-m-d', 'g:i a')
1745 1745
         );
1746 1746
 
1747
-        if (! $payment->save()) {
1747
+        if ( ! $payment->save()) {
1748 1748
             EE_Error::add_error(
1749 1749
                 sprintf(
1750 1750
                     esc_html__('Payment %1$d has not been successfully saved to the database.', 'event_espresso'),
@@ -1809,7 +1809,7 @@  discard block
 block discarded – undo
1809 1809
         $REG_IDs = array();
1810 1810
         // grab array of IDs for specific registrations to apply changes to
1811 1811
         if (isset($this->_req_data['txn_admin_payment']['registrations'])) {
1812
-            $REG_IDs = (array)$this->_req_data['txn_admin_payment']['registrations'];
1812
+            $REG_IDs = (array) $this->_req_data['txn_admin_payment']['registrations'];
1813 1813
         }
1814 1814
         //nothing specified ? then get all reg IDs
1815 1815
         if (empty($REG_IDs)) {
@@ -1937,12 +1937,12 @@  discard block
 block discarded – undo
1937 1937
         // but add in some conditions regarding payment,
1938 1938
         // so that we don't apply payments to registrations that are free or have already been paid for
1939 1939
         // but ONLY if the payment is NOT a refund ( ie: the payment amount is not negative )
1940
-        if (! $payment->is_a_refund()) {
1940
+        if ( ! $payment->is_a_refund()) {
1941 1941
             $registration_query_where_params['REG_final_price']  = array('!=', 0);
1942 1942
             $registration_query_where_params['REG_final_price*'] = array('!=', 'REG_paid', true);
1943 1943
         }
1944 1944
         $registrations = $transaction->registrations(array($registration_query_where_params));
1945
-        if (! empty($registrations)) {
1945
+        if ( ! empty($registrations)) {
1946 1946
             /** @type EE_Payment_Processor $payment_processor */
1947 1947
             $payment_processor = EE_Registry::instance()->load_core('Payment_Processor');
1948 1948
             $payment_processor->process_registration_payments($transaction, $payment, $registrations);
@@ -2142,7 +2142,7 @@  discard block
 block discarded – undo
2142 2142
     {
2143 2143
         $registration_payment_data = array();
2144 2144
         //if non empty reg_ids lets get an array of registrations and update the values for the apply_payment/refund rows.
2145
-        if (! empty($REG_IDs)) {
2145
+        if ( ! empty($REG_IDs)) {
2146 2146
             $registrations = EEM_Registration::instance()->get_all(array(array('REG_ID' => array('IN', $REG_IDs))));
2147 2147
             foreach ($registrations as $registration) {
2148 2148
                 if ($registration instanceof EE_Registration) {
@@ -2255,13 +2255,13 @@  discard block
 block discarded – undo
2255 2255
                 'm/d/Y',
2256 2256
                 strtotime('-10 year')
2257 2257
             );
2258
-        $end_date   = isset($this->_req_data['txn-filter-end-date'])
2258
+        $end_date = isset($this->_req_data['txn-filter-end-date'])
2259 2259
             ? wp_strip_all_tags($this->_req_data['txn-filter-end-date'])
2260 2260
             : date('m/d/Y');
2261 2261
 
2262 2262
         //make sure our timestamps start and end right at the boundaries for each day
2263
-        $start_date = date('Y-m-d', strtotime($start_date)) . ' 00:00:00';
2264
-        $end_date   = date('Y-m-d', strtotime($end_date)) . ' 23:59:59';
2263
+        $start_date = date('Y-m-d', strtotime($start_date)).' 00:00:00';
2264
+        $end_date   = date('Y-m-d', strtotime($end_date)).' 23:59:59';
2265 2265
 
2266 2266
 
2267 2267
         //convert to timestamps
@@ -2278,7 +2278,7 @@  discard block
 block discarded – undo
2278 2278
             date('Y-m-d H:i:s', $start_date),
2279 2279
             'Y-m-d H:i:s'
2280 2280
         );
2281
-        $end_date   = EEM_Transaction::instance()->convert_datetime_for_query(
2281
+        $end_date = EEM_Transaction::instance()->convert_datetime_for_query(
2282 2282
             'TXN_timestamp',
2283 2283
             date('Y-m-d H:i:s', $end_date),
2284 2284
             'Y-m-d H:i:s'
@@ -2320,7 +2320,7 @@  discard block
 block discarded – undo
2320 2320
         }
2321 2321
 
2322 2322
         if (isset($this->_req_data['s'])) {
2323
-            $search_string = '%' . $this->_req_data['s'] . '%';
2323
+            $search_string = '%'.$this->_req_data['s'].'%';
2324 2324
             $_where['OR']  = array(
2325 2325
                 'Registration.Event.EVT_name'         => array('LIKE', $search_string),
2326 2326
                 'Registration.Event.EVT_desc'         => array('LIKE', $search_string),
@@ -2347,9 +2347,9 @@  discard block
 block discarded – undo
2347 2347
         }
2348 2348
 
2349 2349
         //failed transactions
2350
-        $failed    = (! empty($this->_req_data['status']) && $this->_req_data['status'] === 'failed' && ! $count)
2350
+        $failed    = ( ! empty($this->_req_data['status']) && $this->_req_data['status'] === 'failed' && ! $count)
2351 2351
                      || ($count && $view === 'failed');
2352
-        $abandoned = (! empty($this->_req_data['status']) && $this->_req_data['status'] === 'abandoned' && ! $count)
2352
+        $abandoned = ( ! empty($this->_req_data['status']) && $this->_req_data['status'] === 'abandoned' && ! $count)
2353 2353
                      || ($count && $view === 'abandoned');
2354 2354
 
2355 2355
         if ($failed) {
Please login to merge, or discard this patch.
Indentation   +2366 added lines, -2366 removed lines patch added patch discarded remove patch
@@ -16,2370 +16,2370 @@
 block discarded – undo
16 16
 class Transactions_Admin_Page extends EE_Admin_Page
17 17
 {
18 18
 
19
-    /**
20
-     * @var EE_Transaction
21
-     */
22
-    private $_transaction;
23
-
24
-    /**
25
-     * @var EE_Session
26
-     */
27
-    private $_session;
28
-
29
-    /**
30
-     * @var array $_txn_status
31
-     */
32
-    private static $_txn_status;
33
-
34
-    /**
35
-     * @var array $_pay_status
36
-     */
37
-    private static $_pay_status;
38
-
39
-    /**
40
-     * @var array $_existing_reg_payment_REG_IDs
41
-     */
42
-    protected $_existing_reg_payment_REG_IDs = null;
43
-
44
-
45
-    /**
46
-     * @Constructor
47
-     * @access public
48
-     * @param bool $routing
49
-     * @throws EE_Error
50
-     * @throws InvalidArgumentException
51
-     * @throws ReflectionException
52
-     * @throws InvalidDataTypeException
53
-     * @throws InvalidInterfaceException
54
-     */
55
-    public function __construct($routing = true)
56
-    {
57
-        parent::__construct($routing);
58
-    }
59
-
60
-
61
-    /**
62
-     *    _init_page_props
63
-     *
64
-     * @return void
65
-     */
66
-    protected function _init_page_props()
67
-    {
68
-        $this->page_slug        = TXN_PG_SLUG;
69
-        $this->page_label       = esc_html__('Transactions', 'event_espresso');
70
-        $this->_admin_base_url  = TXN_ADMIN_URL;
71
-        $this->_admin_base_path = TXN_ADMIN;
72
-    }
73
-
74
-
75
-    /**
76
-     *    _ajax_hooks
77
-     *
78
-     * @return void
79
-     */
80
-    protected function _ajax_hooks()
81
-    {
82
-        add_action('wp_ajax_espresso_apply_payment', array($this, 'apply_payments_or_refunds'));
83
-        add_action('wp_ajax_espresso_apply_refund', array($this, 'apply_payments_or_refunds'));
84
-        add_action('wp_ajax_espresso_delete_payment', array($this, 'delete_payment'));
85
-    }
86
-
87
-
88
-    /**
89
-     *    _define_page_props
90
-     *
91
-     * @return void
92
-     */
93
-    protected function _define_page_props()
94
-    {
95
-        $this->_admin_page_title = $this->page_label;
96
-        $this->_labels           = array(
97
-            'buttons' => array(
98
-                'add'    => esc_html__('Add New Transaction', 'event_espresso'),
99
-                'edit'   => esc_html__('Edit Transaction', 'event_espresso'),
100
-                'delete' => esc_html__('Delete Transaction', 'event_espresso'),
101
-            ),
102
-        );
103
-    }
104
-
105
-
106
-    /**
107
-     *        grab url requests and route them
108
-     *
109
-     * @access private
110
-     * @return void
111
-     * @throws EE_Error
112
-     * @throws InvalidArgumentException
113
-     * @throws InvalidDataTypeException
114
-     * @throws InvalidInterfaceException
115
-     */
116
-    public function _set_page_routes()
117
-    {
118
-
119
-        $this->_set_transaction_status_array();
120
-
121
-        $txn_id = ! empty($this->_req_data['TXN_ID'])
122
-                  && ! is_array($this->_req_data['TXN_ID'])
123
-            ? $this->_req_data['TXN_ID']
124
-            : 0;
125
-
126
-        $this->_page_routes = array(
127
-
128
-            'default' => array(
129
-                'func'       => '_transactions_overview_list_table',
130
-                'capability' => 'ee_read_transactions',
131
-            ),
132
-
133
-            'view_transaction' => array(
134
-                'func'       => '_transaction_details',
135
-                'capability' => 'ee_read_transaction',
136
-                'obj_id'     => $txn_id,
137
-            ),
138
-
139
-            'send_payment_reminder' => array(
140
-                'func'       => '_send_payment_reminder',
141
-                'noheader'   => true,
142
-                'capability' => 'ee_send_message',
143
-            ),
144
-
145
-            'espresso_apply_payment' => array(
146
-                'func'       => 'apply_payments_or_refunds',
147
-                'noheader'   => true,
148
-                'capability' => 'ee_edit_payments',
149
-            ),
150
-
151
-            'espresso_apply_refund' => array(
152
-                'func'       => 'apply_payments_or_refunds',
153
-                'noheader'   => true,
154
-                'capability' => 'ee_edit_payments',
155
-            ),
156
-
157
-            'espresso_delete_payment' => array(
158
-                'func'       => 'delete_payment',
159
-                'noheader'   => true,
160
-                'capability' => 'ee_delete_payments',
161
-            ),
162
-
163
-        );
164
-    }
165
-
166
-
167
-    protected function _set_page_config()
168
-    {
169
-        $this->_page_config = array(
170
-            'default'          => array(
171
-                'nav'           => array(
172
-                    'label' => esc_html__('Overview', 'event_espresso'),
173
-                    'order' => 10,
174
-                ),
175
-                'list_table'    => 'EE_Admin_Transactions_List_Table',
176
-                'help_tabs'     => array(
177
-                    'transactions_overview_help_tab'                       => array(
178
-                        'title'    => esc_html__('Transactions Overview', 'event_espresso'),
179
-                        'filename' => 'transactions_overview',
180
-                    ),
181
-                    'transactions_overview_table_column_headings_help_tab' => array(
182
-                        'title'    => esc_html__('Transactions Table Column Headings', 'event_espresso'),
183
-                        'filename' => 'transactions_overview_table_column_headings',
184
-                    ),
185
-                    'transactions_overview_views_filters_help_tab'         => array(
186
-                        'title'    => esc_html__('Transaction Views & Filters & Search', 'event_espresso'),
187
-                        'filename' => 'transactions_overview_views_filters_search',
188
-                    ),
189
-                ),
190
-                'help_tour'     => array('Transactions_Overview_Help_Tour'),
191
-                /**
192
-                 * commented out because currently we are not displaying tips for transaction list table status but this
193
-                 * may change in a later iteration so want to keep the code for then.
194
-                 */
195
-                //'qtips' => array( 'Transactions_List_Table_Tips' ),
196
-                'require_nonce' => false,
197
-            ),
198
-            'view_transaction' => array(
199
-                'nav'       => array(
200
-                    'label'      => esc_html__('View Transaction', 'event_espresso'),
201
-                    'order'      => 5,
202
-                    'url'        => isset($this->_req_data['TXN_ID'])
203
-                        ? add_query_arg(array('TXN_ID' => $this->_req_data['TXN_ID']), $this->_current_page_view_url)
204
-                        : $this->_admin_base_url,
205
-                    'persistent' => false,
206
-                ),
207
-                'help_tabs' => array(
208
-                    'transactions_view_transaction_help_tab'                                              => array(
209
-                        'title'    => esc_html__('View Transaction', 'event_espresso'),
210
-                        'filename' => 'transactions_view_transaction',
211
-                    ),
212
-                    'transactions_view_transaction_transaction_details_table_help_tab'                    => array(
213
-                        'title'    => esc_html__('Transaction Details Table', 'event_espresso'),
214
-                        'filename' => 'transactions_view_transaction_transaction_details_table',
215
-                    ),
216
-                    'transactions_view_transaction_attendees_registered_help_tab'                         => array(
217
-                        'title'    => esc_html__('Attendees Registered', 'event_espresso'),
218
-                        'filename' => 'transactions_view_transaction_attendees_registered',
219
-                    ),
220
-                    'transactions_view_transaction_views_primary_registrant_billing_information_help_tab' => array(
221
-                        'title'    => esc_html__('Primary Registrant & Billing Information', 'event_espresso'),
222
-                        'filename' => 'transactions_view_transaction_primary_registrant_billing_information',
223
-                    ),
224
-                ),
225
-                'qtips'     => array('Transaction_Details_Tips'),
226
-                'help_tour' => array('Transaction_Details_Help_Tour'),
227
-                'metaboxes' => array('_transaction_details_metaboxes'),
228
-
229
-                'require_nonce' => false,
230
-            ),
231
-        );
232
-    }
233
-
234
-
235
-    /**
236
-     * The below methods aren't used by this class currently
237
-     */
238
-    protected function _add_screen_options()
239
-    {
240
-        //noop
241
-    }
242
-
243
-    protected function _add_feature_pointers()
244
-    {
245
-        //noop
246
-    }
247
-
248
-    public function admin_init()
249
-    {
250
-        // IF a registration was JUST added via the admin...
251
-        if (isset(
252
-            $this->_req_data['redirect_from'],
253
-            $this->_req_data['EVT_ID'],
254
-            $this->_req_data['event_name']
255
-        )) {
256
-            // then set a cookie so that we can block any attempts to use
257
-            // the back button as a way to enter another registration.
258
-            setcookie(
259
-                'ee_registration_added',
260
-                $this->_req_data['EVT_ID'], time() + WEEK_IN_SECONDS, '/'
261
-            );
262
-            // and update the global
263
-            $_COOKIE['ee_registration_added'] = $this->_req_data['EVT_ID'];
264
-        }
265
-        EE_Registry::$i18n_js_strings['invalid_server_response'] = esc_html__(
266
-            'An error occurred! Your request may have been processed, but a valid response from the server was not received. Please refresh the page and try again.',
267
-            'event_espresso'
268
-        );
269
-        EE_Registry::$i18n_js_strings['error_occurred']          = esc_html__(
270
-            'An error occurred! Please refresh the page and try again.',
271
-            'event_espresso'
272
-        );
273
-        EE_Registry::$i18n_js_strings['txn_status_array']        = self::$_txn_status;
274
-        EE_Registry::$i18n_js_strings['pay_status_array']        = self::$_pay_status;
275
-        EE_Registry::$i18n_js_strings['payments_total']          = esc_html__('Payments Total', 'event_espresso');
276
-        EE_Registry::$i18n_js_strings['transaction_overpaid']    = esc_html__(
277
-            'This transaction has been overpaid ! Payments Total',
278
-            'event_espresso'
279
-        );
280
-    }
281
-
282
-    public function admin_notices()
283
-    {
284
-        //noop
285
-    }
286
-
287
-    public function admin_footer_scripts()
288
-    {
289
-        //noop
290
-    }
291
-
292
-
293
-    /**
294
-     * _set_transaction_status_array
295
-     * sets list of transaction statuses
296
-     *
297
-     * @access private
298
-     * @return void
299
-     * @throws EE_Error
300
-     * @throws InvalidArgumentException
301
-     * @throws InvalidDataTypeException
302
-     * @throws InvalidInterfaceException
303
-     */
304
-    private function _set_transaction_status_array()
305
-    {
306
-        self::$_txn_status = EEM_Transaction::instance()->status_array(true);
307
-    }
308
-
309
-
310
-    /**
311
-     * get_transaction_status_array
312
-     * return the transaction status array for wp_list_table
313
-     *
314
-     * @access public
315
-     * @return array
316
-     */
317
-    public function get_transaction_status_array()
318
-    {
319
-        return self::$_txn_status;
320
-    }
321
-
322
-
323
-    /**
324
-     *    get list of payment statuses
325
-     *
326
-     * @access private
327
-     * @return void
328
-     * @throws EE_Error
329
-     * @throws InvalidArgumentException
330
-     * @throws InvalidDataTypeException
331
-     * @throws InvalidInterfaceException
332
-     */
333
-    private function _get_payment_status_array()
334
-    {
335
-        self::$_pay_status                      = EEM_Payment::instance()->status_array(true);
336
-        $this->_template_args['payment_status'] = self::$_pay_status;
337
-
338
-    }
339
-
340
-
341
-    /**
342
-     *    _add_screen_options_default
343
-     *
344
-     * @access protected
345
-     * @return void
346
-     * @throws InvalidArgumentException
347
-     * @throws InvalidDataTypeException
348
-     * @throws InvalidInterfaceException
349
-     */
350
-    protected function _add_screen_options_default()
351
-    {
352
-        $this->_per_page_screen_option();
353
-    }
354
-
355
-
356
-    /**
357
-     * load_scripts_styles
358
-     *
359
-     * @access public
360
-     * @return void
361
-     */
362
-    public function load_scripts_styles()
363
-    {
364
-        //enqueue style
365
-        wp_register_style(
366
-            'espresso_txn',
367
-            TXN_ASSETS_URL . 'espresso_transactions_admin.css',
368
-            array(),
369
-            EVENT_ESPRESSO_VERSION
370
-        );
371
-        wp_enqueue_style('espresso_txn');
372
-        //scripts
373
-        wp_register_script('espresso_txn', TXN_ASSETS_URL . 'espresso_transactions_admin.js', array(
374
-            'ee_admin_js',
375
-            'ee-datepicker',
376
-            'jquery-ui-datepicker',
377
-            'jquery-ui-draggable',
378
-            'ee-dialog',
379
-            'ee-accounting',
380
-            'ee-serialize-full-array',
381
-        ), EVENT_ESPRESSO_VERSION, true);
382
-        wp_enqueue_script('espresso_txn');
383
-    }
384
-
385
-
386
-    /**
387
-     *    load_scripts_styles_view_transaction
388
-     *
389
-     * @access public
390
-     * @return void
391
-     */
392
-    public function load_scripts_styles_view_transaction()
393
-    {
394
-        //styles
395
-        wp_enqueue_style('espresso-ui-theme');
396
-    }
397
-
398
-
399
-    /**
400
-     *    load_scripts_styles_default
401
-     *
402
-     * @access public
403
-     * @return void
404
-     */
405
-    public function load_scripts_styles_default()
406
-    {
407
-        //styles
408
-        wp_enqueue_style('espresso-ui-theme');
409
-    }
410
-
411
-
412
-    /**
413
-     *    _set_list_table_views_default
414
-     *
415
-     * @access protected
416
-     * @return void
417
-     */
418
-    protected function _set_list_table_views_default()
419
-    {
420
-        $this->_views = array(
421
-            'all'       => array(
422
-                'slug'  => 'all',
423
-                'label' => esc_html__('View All Transactions', 'event_espresso'),
424
-                'count' => 0,
425
-            ),
426
-            'abandoned' => array(
427
-                'slug'  => 'abandoned',
428
-                'label' => esc_html__('Abandoned Transactions', 'event_espresso'),
429
-                'count' => 0,
430
-            ),
431
-            'failed'    => array(
432
-                'slug'  => 'failed',
433
-                'label' => esc_html__('Failed Transactions', 'event_espresso'),
434
-                'count' => 0,
435
-            ),
436
-        );
437
-    }
438
-
439
-
440
-    /**
441
-     * _set_transaction_object
442
-     * This sets the _transaction property for the transaction details screen
443
-     *
444
-     * @access private
445
-     * @return void
446
-     * @throws EE_Error
447
-     * @throws InvalidArgumentException
448
-     * @throws RuntimeException
449
-     * @throws InvalidDataTypeException
450
-     * @throws InvalidInterfaceException
451
-     */
452
-    private function _set_transaction_object()
453
-    {
454
-        if ($this->_transaction instanceof EE_Transaction) {
455
-            return;
456
-        } //get out we've already set the object
457
-
458
-        $TXN_ID = ! empty($this->_req_data['TXN_ID'])
459
-            ? absint($this->_req_data['TXN_ID'])
460
-            : false;
461
-
462
-        //get transaction object
463
-        $this->_transaction = EEM_Transaction::instance()->get_one_by_ID($TXN_ID);
464
-        $this->_session     = $this->_transaction instanceof EE_Transaction
465
-            ? $this->_transaction->get('TXN_session_data')
466
-            : null;
467
-        $this->_transaction->verify_abandoned_transaction_status();
468
-
469
-        if (! $this->_transaction instanceof EE_Transaction) {
470
-            $error_msg = sprintf(
471
-                esc_html__(
472
-                    'An error occurred and the details for the transaction with the ID # %d could not be retrieved.',
473
-                    'event_espresso'
474
-                ),
475
-                $TXN_ID
476
-            );
477
-            EE_Error::add_error($error_msg, __FILE__, __FUNCTION__, __LINE__);
478
-        }
479
-    }
480
-
481
-
482
-    /**
483
-     *    _transaction_legend_items
484
-     *
485
-     * @access protected
486
-     * @return array
487
-     * @throws EE_Error
488
-     * @throws InvalidArgumentException
489
-     * @throws ReflectionException
490
-     * @throws InvalidDataTypeException
491
-     * @throws InvalidInterfaceException
492
-     */
493
-    protected function _transaction_legend_items()
494
-    {
495
-        EE_Registry::instance()->load_helper('MSG_Template');
496
-        $items = array();
497
-
498
-        if (EE_Registry::instance()->CAP->current_user_can(
499
-            'ee_read_global_messages',
500
-            'view_filtered_messages'
501
-        )) {
502
-            $related_for_icon = EEH_MSG_Template::get_message_action_icon('see_notifications_for');
503
-            if (is_array($related_for_icon)
504
-                && isset($related_for_icon['css_class'], $related_for_icon['label'])
505
-            ) {
506
-                $items['view_related_messages'] = array(
507
-                    'class' => $related_for_icon['css_class'],
508
-                    'desc'  => $related_for_icon['label'],
509
-                );
510
-            }
511
-        }
512
-
513
-        $items = apply_filters(
514
-            'FHEE__Transactions_Admin_Page___transaction_legend_items__items',
515
-            array_merge(
516
-                $items,
517
-                array(
518
-                    'view_details'          => array(
519
-                        'class' => 'dashicons dashicons-cart',
520
-                        'desc'  => esc_html__('View Transaction Details', 'event_espresso'),
521
-                    ),
522
-                    'view_invoice'          => array(
523
-                        'class' => 'dashicons dashicons-media-spreadsheet',
524
-                        'desc'  => esc_html__('View Transaction Invoice', 'event_espresso'),
525
-                    ),
526
-                    'view_receipt'          => array(
527
-                        'class' => 'dashicons dashicons-media-default',
528
-                        'desc'  => esc_html__('View Transaction Receipt', 'event_espresso'),
529
-                    ),
530
-                    'view_registration'     => array(
531
-                        'class' => 'dashicons dashicons-clipboard',
532
-                        'desc'  => esc_html__('View Registration Details', 'event_espresso'),
533
-                    ),
534
-                    'payment_overview_link' => array(
535
-                        'class' => 'dashicons dashicons-money',
536
-                        'desc'  => esc_html__('Make Payment on Frontend', 'event_espresso'),
537
-                    ),
538
-                )
539
-            )
540
-        );
541
-
542
-        if (EE_Registry::instance()->CAP->current_user_can(
543
-            'ee_send_message',
544
-            'espresso_transactions_send_payment_reminder'
545
-        )) {
546
-            if (EEH_MSG_Template::is_mt_active('payment_reminder')) {
547
-                $items['send_payment_reminder'] = array(
548
-                    'class' => 'dashicons dashicons-email-alt',
549
-                    'desc'  => esc_html__('Send Payment Reminder', 'event_espresso'),
550
-                );
551
-            } else {
552
-                $items['blank*'] = array(
553
-                    'class' => '',
554
-                    'desc'  => '',
555
-                );
556
-            }
557
-        } else {
558
-            $items['blank*'] = array(
559
-                'class' => '',
560
-                'desc'  => '',
561
-            );
562
-        }
563
-        $more_items = apply_filters(
564
-            'FHEE__Transactions_Admin_Page___transaction_legend_items__more_items',
565
-            array(
566
-                'overpaid'   => array(
567
-                    'class' => 'ee-status-legend ee-status-legend-' . EEM_Transaction::overpaid_status_code,
568
-                    'desc'  => EEH_Template::pretty_status(
569
-                        EEM_Transaction::overpaid_status_code,
570
-                        false,
571
-                        'sentence'
572
-                    ),
573
-                ),
574
-                'complete'   => array(
575
-                    'class' => 'ee-status-legend ee-status-legend-' . EEM_Transaction::complete_status_code,
576
-                    'desc'  => EEH_Template::pretty_status(
577
-                        EEM_Transaction::complete_status_code,
578
-                        false,
579
-                        'sentence'
580
-                    ),
581
-                ),
582
-                'incomplete' => array(
583
-                    'class' => 'ee-status-legend ee-status-legend-' . EEM_Transaction::incomplete_status_code,
584
-                    'desc'  => EEH_Template::pretty_status(
585
-                        EEM_Transaction::incomplete_status_code,
586
-                        false,
587
-                        'sentence'
588
-                    ),
589
-                ),
590
-                'abandoned'  => array(
591
-                    'class' => 'ee-status-legend ee-status-legend-' . EEM_Transaction::abandoned_status_code,
592
-                    'desc'  => EEH_Template::pretty_status(
593
-                        EEM_Transaction::abandoned_status_code,
594
-                        false,
595
-                        'sentence'
596
-                    ),
597
-                ),
598
-                'failed'     => array(
599
-                    'class' => 'ee-status-legend ee-status-legend-' . EEM_Transaction::failed_status_code,
600
-                    'desc'  => EEH_Template::pretty_status(
601
-                        EEM_Transaction::failed_status_code,
602
-                        false,
603
-                        'sentence'
604
-                    ),
605
-                ),
606
-            )
607
-        );
608
-
609
-        return array_merge($items, $more_items);
610
-    }
611
-
612
-
613
-    /**
614
-     *    _transactions_overview_list_table
615
-     *
616
-     * @access protected
617
-     * @return void
618
-     * @throws DomainException
619
-     * @throws EE_Error
620
-     * @throws InvalidArgumentException
621
-     * @throws InvalidDataTypeException
622
-     * @throws InvalidInterfaceException
623
-     * @throws ReflectionException
624
-     */
625
-    protected function _transactions_overview_list_table()
626
-    {
627
-        $this->_admin_page_title = esc_html__('Transactions', 'event_espresso');
628
-        $event = isset($this->_req_data['EVT_ID'])
629
-            ? EEM_Event::instance()->get_one_by_ID($this->_req_data['EVT_ID'])
630
-            : null;
631
-        $this->_template_args['admin_page_header'] = $event instanceof EE_Event
632
-            ? sprintf(
633
-                esc_html__(
634
-                    '%sViewing Transactions for the Event: %s%s',
635
-                    'event_espresso'
636
-                ),
637
-                '<h3>',
638
-                '<a href="'
639
-                . EE_Admin_Page::add_query_args_and_nonce(
640
-                    array('action' => 'edit', 'post' => $event->ID()),
641
-                    EVENTS_ADMIN_URL
642
-                )
643
-                . '" title="'
644
-                . esc_attr__(
645
-                    'Click to Edit event',
646
-                    'event_espresso'
647
-                )
648
-                . '">' . $event->get('EVT_name') . '</a>',
649
-                '</h3>'
650
-            )
651
-            : '';
652
-        $this->_template_args['after_list_table']  = $this->_display_legend($this->_transaction_legend_items());
653
-        $this->display_admin_list_table_page_with_no_sidebar();
654
-    }
655
-
656
-
657
-    /**
658
-     *    _transaction_details
659
-     * generates HTML for the View Transaction Details Admin page
660
-     *
661
-     * @access protected
662
-     * @return void
663
-     * @throws DomainException
664
-     * @throws EE_Error
665
-     * @throws InvalidArgumentException
666
-     * @throws InvalidDataTypeException
667
-     * @throws InvalidInterfaceException
668
-     * @throws RuntimeException
669
-     */
670
-    protected function _transaction_details()
671
-    {
672
-        do_action('AHEE__Transactions_Admin_Page__transaction_details__start', $this->_transaction);
673
-
674
-        $this->_set_transaction_status_array();
675
-
676
-        $this->_template_args                      = array();
677
-        $this->_template_args['transactions_page'] = $this->_wp_page_slug;
678
-
679
-        $this->_set_transaction_object();
680
-
681
-        $primary_registration = $this->_transaction->primary_registration();
682
-        $attendee = $primary_registration instanceof EE_Registration
683
-            ? $primary_registration->attendee()
684
-            : null;
685
-
686
-        $this->_template_args['txn_nmbr']['value'] = $this->_transaction->ID();
687
-        $this->_template_args['txn_nmbr']['label'] = esc_html__('Transaction Number', 'event_espresso');
688
-
689
-        $this->_template_args['txn_datetime']['value'] = $this->_transaction->get_i18n_datetime('TXN_timestamp');
690
-        $this->_template_args['txn_datetime']['label'] = esc_html__('Date', 'event_espresso');
691
-
692
-        $this->_template_args['txn_status']['value'] = self::$_txn_status[$this->_transaction->get('STS_ID')];
693
-        $this->_template_args['txn_status']['label'] = esc_html__('Transaction Status', 'event_espresso');
694
-        $this->_template_args['txn_status']['class'] = 'status-' . $this->_transaction->get('STS_ID');
695
-
696
-        $this->_template_args['grand_total'] = $this->_transaction->get('TXN_total');
697
-        $this->_template_args['total_paid']  = $this->_transaction->get('TXN_paid');
698
-
699
-        if ($attendee instanceof EE_Attendee
700
-            && EE_Registry::instance()->CAP->current_user_can(
701
-                'ee_send_message',
702
-                'espresso_transactions_send_payment_reminder'
703
-            )
704
-        ) {
705
-            $this->_template_args['send_payment_reminder_button'] =
706
-                EEH_MSG_Template::is_mt_active('payment_reminder')
707
-                && $this->_transaction->get('STS_ID') !== EEM_Transaction::complete_status_code
708
-                && $this->_transaction->get('STS_ID') !== EEM_Transaction::overpaid_status_code
709
-                    ? EEH_Template::get_button_or_link(
710
-                        EE_Admin_Page::add_query_args_and_nonce(
711
-                            array(
712
-                                'action'      => 'send_payment_reminder',
713
-                                'TXN_ID'      => $this->_transaction->ID(),
714
-                                'redirect_to' => 'view_transaction',
715
-                            ),
716
-                            TXN_ADMIN_URL
717
-                        ),
718
-                        __(' Send Payment Reminder', 'event_espresso'),
719
-                        'button secondary-button right',
720
-                        'dashicons dashicons-email-alt'
721
-                    )
722
-                    : '';
723
-        } else {
724
-            $this->_template_args['send_payment_reminder_button'] = '';
725
-        }
726
-
727
-        $amount_due = $this->_transaction->get('TXN_total') - $this->_transaction->get('TXN_paid');
728
-        $this->_template_args['amount_due'] = EEH_Template::format_currency(
729
-            $amount_due,
730
-            true
731
-        );
732
-        if (EE_Registry::instance()->CFG->currency->sign_b4) {
733
-            $this->_template_args['amount_due'] = EE_Registry::instance()->CFG->currency->sign
734
-                                                  . $this->_template_args['amount_due'];
735
-        } else {
736
-            $this->_template_args['amount_due'] .= EE_Registry::instance()->CFG->currency->sign;
737
-        }
738
-        $this->_template_args['amount_due_class'] = '';
739
-
740
-        if ($this->_transaction->get('TXN_paid') == $this->_transaction->get('TXN_total')) {
741
-            // paid in full
742
-            $this->_template_args['amount_due'] = false;
743
-        } elseif ($this->_transaction->get('TXN_paid') > $this->_transaction->get('TXN_total')) {
744
-            // overpaid
745
-            $this->_template_args['amount_due_class'] = 'txn-overview-no-payment-spn';
746
-        } elseif ($this->_transaction->get('TXN_total') > 0
747
-                  && $this->_transaction->get('TXN_paid') > 0
748
-        ) {
749
-            // monies owing
750
-            $this->_template_args['amount_due_class'] = 'txn-overview-part-payment-spn';
751
-        } elseif ($this->_transaction->get('TXN_total') > 0
752
-                  && $this->_transaction->get('TXN_paid') == 0
753
-        ) {
754
-            // no payments made yet
755
-            $this->_template_args['amount_due_class'] = 'txn-overview-no-payment-spn';
756
-        } elseif ($this->_transaction->get('TXN_total') == 0) {
757
-            // free event
758
-            $this->_template_args['amount_due'] = false;
759
-        }
760
-
761
-        $payment_method = $this->_transaction->payment_method();
762
-
763
-        $this->_template_args['method_of_payment_name'] = $payment_method instanceof EE_Payment_Method
764
-            ? $payment_method->admin_name()
765
-            : esc_html__('Unknown', 'event_espresso');
766
-
767
-        $this->_template_args['currency_sign'] = EE_Registry::instance()->CFG->currency->sign;
768
-        // link back to overview
769
-        $this->_template_args['txn_overview_url'] = ! empty($_SERVER['HTTP_REFERER'])
770
-            ? $_SERVER['HTTP_REFERER']
771
-            : TXN_ADMIN_URL;
772
-
773
-
774
-        // next link
775
-        $next_txn                                 = $this->_transaction->next(
776
-            null,
777
-            array(array('STS_ID' => array('!=', EEM_Transaction::failed_status_code))),
778
-            'TXN_ID'
779
-        );
780
-        $this->_template_args['next_transaction'] = $next_txn
781
-            ? $this->_next_link(
782
-                EE_Admin_Page::add_query_args_and_nonce(
783
-                    array('action' => 'view_transaction', 'TXN_ID' => $next_txn['TXN_ID']),
784
-                    TXN_ADMIN_URL
785
-                ),
786
-                'dashicons dashicons-arrow-right ee-icon-size-22'
787
-            )
788
-            : '';
789
-        // previous link
790
-        $previous_txn                                 = $this->_transaction->previous(
791
-            null,
792
-            array(array('STS_ID' => array('!=', EEM_Transaction::failed_status_code))),
793
-            'TXN_ID'
794
-        );
795
-        $this->_template_args['previous_transaction'] = $previous_txn
796
-            ? $this->_previous_link(
797
-                EE_Admin_Page::add_query_args_and_nonce(
798
-                    array('action' => 'view_transaction', 'TXN_ID' => $previous_txn['TXN_ID']),
799
-                    TXN_ADMIN_URL
800
-                ),
801
-                'dashicons dashicons-arrow-left ee-icon-size-22'
802
-            )
803
-            : '';
804
-
805
-        // were we just redirected here after adding a new registration ???
806
-        if (isset(
807
-            $this->_req_data['redirect_from'],
808
-            $this->_req_data['EVT_ID'],
809
-            $this->_req_data['event_name']
810
-        )) {
811
-            if (EE_Registry::instance()->CAP->current_user_can(
812
-                'ee_edit_registrations',
813
-                'espresso_registrations_new_registration',
814
-                $this->_req_data['EVT_ID']
815
-            )) {
816
-                $this->_admin_page_title .= '<a id="add-new-registration" class="add-new-h2 button-primary" href="';
817
-                $this->_admin_page_title .= EE_Admin_Page::add_query_args_and_nonce(
818
-                    array(
819
-                        'page'     => 'espresso_registrations',
820
-                        'action'   => 'new_registration',
821
-                        'return'   => 'default',
822
-                        'TXN_ID'   => $this->_transaction->ID(),
823
-                        'event_id' => $this->_req_data['EVT_ID'],
824
-                    ),
825
-                    REG_ADMIN_URL
826
-                );
827
-                $this->_admin_page_title .= '">';
828
-
829
-                $this->_admin_page_title .= sprintf(
830
-                    esc_html__('Add Another New Registration to Event: "%1$s" ?', 'event_espresso'),
831
-                    htmlentities(urldecode($this->_req_data['event_name']), ENT_QUOTES, 'UTF-8')
832
-                );
833
-                $this->_admin_page_title .= '</a>';
834
-            }
835
-            EE_Registry::instance()->SSN->clear_session(__CLASS__, __FUNCTION__);
836
-        }
837
-        // grab messages at the last second
838
-        $this->_template_args['notices'] = EE_Error::get_notices();
839
-        // path to template
840
-        $template_path                             = TXN_TEMPLATE_PATH . 'txn_admin_details_header.template.php';
841
-        $this->_template_args['admin_page_header'] = EEH_Template::display_template(
842
-            $template_path,
843
-            $this->_template_args,
844
-            true
845
-        );
846
-
847
-        // the details template wrapper
848
-        $this->display_admin_page_with_sidebar();
849
-
850
-    }
851
-
852
-
853
-    /**
854
-     *        _transaction_details_metaboxes
855
-     *
856
-     * @access protected
857
-     * @return void
858
-     * @throws EE_Error
859
-     * @throws InvalidArgumentException
860
-     * @throws InvalidDataTypeException
861
-     * @throws InvalidInterfaceException
862
-     * @throws RuntimeException
863
-     */
864
-    protected function _transaction_details_metaboxes()
865
-    {
866
-
867
-        $this->_set_transaction_object();
868
-
869
-        add_meta_box(
870
-            'edit-txn-details-mbox',
871
-            esc_html__('Transaction Details', 'event_espresso'),
872
-            array($this, 'txn_details_meta_box'),
873
-            $this->_wp_page_slug,
874
-            'normal',
875
-            'high'
876
-        );
877
-        add_meta_box(
878
-            'edit-txn-attendees-mbox',
879
-            esc_html__('Attendees Registered in this Transaction', 'event_espresso'),
880
-            array($this, 'txn_attendees_meta_box'),
881
-            $this->_wp_page_slug,
882
-            'normal',
883
-            'high',
884
-            array('TXN_ID' => $this->_transaction->ID())
885
-        );
886
-        add_meta_box(
887
-            'edit-txn-registrant-mbox',
888
-            esc_html__('Primary Contact', 'event_espresso'),
889
-            array($this, 'txn_registrant_side_meta_box'),
890
-            $this->_wp_page_slug,
891
-            'side',
892
-            'high'
893
-        );
894
-        add_meta_box(
895
-            'edit-txn-billing-info-mbox',
896
-            esc_html__('Billing Information', 'event_espresso'),
897
-            array($this, 'txn_billing_info_side_meta_box'),
898
-            $this->_wp_page_slug,
899
-            'side',
900
-            'high'
901
-        );
902
-    }
903
-
904
-
905
-    /**
906
-     * txn_details_meta_box
907
-     * generates HTML for the Transaction main meta box
908
-     *
909
-     * @access public
910
-     * @return void
911
-     * @throws DomainException
912
-     * @throws EE_Error
913
-     * @throws InvalidArgumentException
914
-     * @throws InvalidDataTypeException
915
-     * @throws InvalidInterfaceException
916
-     * @throws RuntimeException
917
-     */
918
-    public function txn_details_meta_box()
919
-    {
920
-
921
-        $this->_set_transaction_object();
922
-        $this->_template_args['TXN_ID']   = $this->_transaction->ID();
923
-        $this->_template_args['attendee'] = $this->_transaction->primary_registration() instanceof EE_Registration
924
-            ? $this->_transaction->primary_registration()->attendee()
925
-            : null;
926
-        $this->_template_args['can_edit_payments'] = EE_Registry::instance()->CAP->current_user_can(
927
-            'ee_edit_payments',
928
-            'apply_payment_or_refund_from_registration_details'
929
-        );
930
-        $this->_template_args['can_delete_payments'] = EE_Registry::instance()->CAP->current_user_can(
931
-            'ee_delete_payments',
932
-            'delete_payment_from_registration_details'
933
-        );
934
-
935
-        //get line table
936
-        EEH_Autoloader::register_line_item_display_autoloaders();
937
-        $Line_Item_Display                       = new EE_Line_Item_Display(
938
-            'admin_table',
939
-            'EE_Admin_Table_Line_Item_Display_Strategy'
940
-        );
941
-        $this->_template_args['line_item_table'] = $Line_Item_Display->display_line_item(
942
-            $this->_transaction->total_line_item()
943
-        );
944
-        $this->_template_args['REG_code']        = $this->_transaction->get_first_related('Registration')
945
-                                                                      ->get('REG_code');
946
-
947
-        // process taxes
948
-        $taxes                         = $this->_transaction->get_many_related(
949
-            'Line_Item',
950
-            array(array('LIN_type' => EEM_Line_Item::type_tax))
951
-        );
952
-        $this->_template_args['taxes'] = ! empty($taxes) ? $taxes : false;
953
-
954
-        $this->_template_args['grand_total']     = EEH_Template::format_currency(
955
-            $this->_transaction->get('TXN_total'),
956
-            false,
957
-            false
958
-        );
959
-        $this->_template_args['grand_raw_total'] = $this->_transaction->get('TXN_total');
960
-        $this->_template_args['TXN_status']      = $this->_transaction->get('STS_ID');
961
-
962
-        // process payment details
963
-        $payments = $this->_transaction->get_many_related('Payment');
964
-        if (! empty($payments)) {
965
-            $this->_template_args['payments']              = $payments;
966
-            $this->_template_args['existing_reg_payments'] = $this->_get_registration_payment_IDs($payments);
967
-        } else {
968
-            $this->_template_args['payments']              = false;
969
-            $this->_template_args['existing_reg_payments'] = array();
970
-        }
971
-
972
-        $this->_template_args['edit_payment_url']   = add_query_arg(array('action' => 'edit_payment'), TXN_ADMIN_URL);
973
-        $this->_template_args['delete_payment_url'] = add_query_arg(
974
-            array('action' => 'espresso_delete_payment'),
975
-            TXN_ADMIN_URL
976
-        );
977
-
978
-        if (isset($txn_details['invoice_number'])) {
979
-            $this->_template_args['txn_details']['invoice_number']['value'] = $this->_template_args['REG_code'];
980
-            $this->_template_args['txn_details']['invoice_number']['label'] = esc_html__(
981
-                'Invoice Number',
982
-                'event_espresso'
983
-            );
984
-        }
985
-
986
-        $this->_template_args['txn_details']['registration_session']['value'] = $this->_transaction
987
-            ->get_first_related('Registration')
988
-            ->get('REG_session');
989
-        $this->_template_args['txn_details']['registration_session']['label'] = esc_html__(
990
-            'Registration Session',
991
-            'event_espresso'
992
-        );
993
-
994
-        $this->_template_args['txn_details']['ip_address']['value'] = isset($this->_session['ip_address'])
995
-            ? $this->_session['ip_address']
996
-            : '';
997
-        $this->_template_args['txn_details']['ip_address']['label'] = esc_html__(
998
-            'Transaction placed from IP',
999
-            'event_espresso'
1000
-        );
1001
-
1002
-        $this->_template_args['txn_details']['user_agent']['value'] = isset($this->_session['user_agent'])
1003
-            ? $this->_session['user_agent']
1004
-            : '';
1005
-        $this->_template_args['txn_details']['user_agent']['label'] = esc_html__(
1006
-            'Registrant User Agent',
1007
-            'event_espresso'
1008
-        );
1009
-
1010
-        $reg_steps = '<ul>';
1011
-        foreach ($this->_transaction->reg_steps() as $reg_step => $reg_step_status) {
1012
-            if ($reg_step_status === true) {
1013
-                $reg_steps .= '<li style="color:#70cc50">'
1014
-                              . sprintf(
1015
-                                  esc_html__('%1$s : Completed', 'event_espresso'),
1016
-                                  ucwords(str_replace('_', ' ', $reg_step))
1017
-                              )
1018
-                              . '</li>';
1019
-            } elseif (is_numeric($reg_step_status) && $reg_step_status !== false) {
1020
-                $reg_steps .= '<li style="color:#2EA2CC">'
1021
-                              . sprintf(
1022
-                                  esc_html__('%1$s : Initiated %2$s', 'event_espresso'),
1023
-                                  ucwords(str_replace('_', ' ', $reg_step)),
1024
-                                  date(
1025
-                                      get_option('date_format') . ' ' . get_option('time_format'),
1026
-                                      ($reg_step_status + (get_option('gmt_offset') * HOUR_IN_SECONDS))
1027
-                                  )
1028
-                              )
1029
-                              . '</li>';
1030
-            } else {
1031
-                $reg_steps .= '<li style="color:#E76700">'
1032
-                              . sprintf(
1033
-                                  esc_html__('%1$s : Never Initiated', 'event_espresso'),
1034
-                                  ucwords(str_replace('_', ' ', $reg_step))
1035
-                              )
1036
-                              . '</li>';
1037
-            }
1038
-        }
1039
-        $reg_steps                                                 .= '</ul>';
1040
-        $this->_template_args['txn_details']['reg_steps']['value'] = $reg_steps;
1041
-        $this->_template_args['txn_details']['reg_steps']['label'] = esc_html__(
1042
-            'Registration Step Progress',
1043
-            'event_espresso'
1044
-        );
1045
-
1046
-
1047
-        $this->_get_registrations_to_apply_payment_to();
1048
-        $this->_get_payment_methods($payments);
1049
-        $this->_get_payment_status_array();
1050
-        $this->_get_reg_status_selection(); //sets up the template args for the reg status array for the transaction.
1051
-
1052
-        $this->_template_args['transaction_form_url']    = add_query_arg(array(
1053
-            'action'  => 'edit_transaction',
1054
-            'process' => 'transaction',
1055
-        ), TXN_ADMIN_URL);
1056
-        $this->_template_args['apply_payment_form_url']  = add_query_arg(array(
1057
-            'page'   => 'espresso_transactions',
1058
-            'action' => 'espresso_apply_payment',
1059
-        ), WP_AJAX_URL);
1060
-        $this->_template_args['delete_payment_form_url'] = add_query_arg(array(
1061
-            'page'   => 'espresso_transactions',
1062
-            'action' => 'espresso_delete_payment',
1063
-        ), WP_AJAX_URL);
1064
-
1065
-        // 'espresso_delete_payment_nonce'
1066
-
1067
-        $template_path = TXN_TEMPLATE_PATH . 'txn_admin_details_main_meta_box_txn_details.template.php';
1068
-        echo EEH_Template::display_template($template_path, $this->_template_args, true);
1069
-    }
1070
-
1071
-
1072
-    /**
1073
-     * _get_registration_payment_IDs
1074
-     *    generates an array of Payment IDs and their corresponding Registration IDs
1075
-     *
1076
-     * @access protected
1077
-     * @param EE_Payment[] $payments
1078
-     * @return array
1079
-     * @throws EE_Error
1080
-     * @throws InvalidArgumentException
1081
-     * @throws InvalidDataTypeException
1082
-     * @throws InvalidInterfaceException
1083
-     */
1084
-    protected function _get_registration_payment_IDs($payments = array())
1085
-    {
1086
-        $existing_reg_payments = array();
1087
-        // get all reg payments for these payments
1088
-        $reg_payments = EEM_Registration_Payment::instance()->get_all(array(
1089
-            array(
1090
-                'PAY_ID' => array(
1091
-                    'IN',
1092
-                    array_keys($payments),
1093
-                ),
1094
-            ),
1095
-        ));
1096
-        if (! empty($reg_payments)) {
1097
-            foreach ($payments as $payment) {
1098
-                if (! $payment instanceof EE_Payment) {
1099
-                    continue;
1100
-                } elseif (! isset($existing_reg_payments[$payment->ID()])) {
1101
-                    $existing_reg_payments[$payment->ID()] = array();
1102
-                }
1103
-                foreach ($reg_payments as $reg_payment) {
1104
-                    if ($reg_payment instanceof EE_Registration_Payment
1105
-                        && $reg_payment->payment_ID() === $payment->ID()
1106
-                    ) {
1107
-                        $existing_reg_payments[$payment->ID()][] = $reg_payment->registration_ID();
1108
-                    }
1109
-                }
1110
-            }
1111
-        }
1112
-
1113
-        return $existing_reg_payments;
1114
-    }
1115
-
1116
-
1117
-    /**
1118
-     * _get_registrations_to_apply_payment_to
1119
-     *    generates HTML for displaying a series of checkboxes in the admin payment modal window
1120
-     * which allows the admin to only apply the payment to the specific registrations
1121
-     *
1122
-     * @access protected
1123
-     * @return void
1124
-     * @throws \EE_Error
1125
-     */
1126
-    protected function _get_registrations_to_apply_payment_to()
1127
-    {
1128
-        // we want any registration with an active status (ie: not deleted or cancelled)
1129
-        $query_params                      = array(
1130
-            array(
1131
-                'STS_ID' => array(
1132
-                    'IN',
1133
-                    array(
1134
-                        EEM_Registration::status_id_approved,
1135
-                        EEM_Registration::status_id_pending_payment,
1136
-                        EEM_Registration::status_id_not_approved,
1137
-                    ),
1138
-                ),
1139
-            ),
1140
-        );
1141
-        $registrations_to_apply_payment_to = EEH_HTML::br()
1142
-                                             . EEH_HTML::div(
1143
-                                                 '',
1144
-                                                 'txn-admin-apply-payment-to-registrations-dv',
1145
-                                                 '',
1146
-                                                 'clear: both; margin: 1.5em 0 0; display: none;'
1147
-                                             );
1148
-        $registrations_to_apply_payment_to .= EEH_HTML::br() . EEH_HTML::div('', '', 'admin-primary-mbox-tbl-wrap');
1149
-        $registrations_to_apply_payment_to .= EEH_HTML::table('', '', 'admin-primary-mbox-tbl');
1150
-        $registrations_to_apply_payment_to .= EEH_HTML::thead(
1151
-            EEH_HTML::tr(
1152
-                EEH_HTML::th(esc_html__('ID', 'event_espresso')) .
1153
-                EEH_HTML::th(esc_html__('Registrant', 'event_espresso')) .
1154
-                EEH_HTML::th(esc_html__('Ticket', 'event_espresso')) .
1155
-                EEH_HTML::th(esc_html__('Event', 'event_espresso')) .
1156
-                EEH_HTML::th(esc_html__('Paid', 'event_espresso'), '', 'txn-admin-payment-paid-td jst-cntr') .
1157
-                EEH_HTML::th(esc_html__('Owing', 'event_espresso'), '', 'txn-admin-payment-owing-td jst-cntr') .
1158
-                EEH_HTML::th(esc_html__('Apply', 'event_espresso'), '', 'jst-cntr')
1159
-            )
1160
-        );
1161
-        $registrations_to_apply_payment_to .= EEH_HTML::tbody();
1162
-        // get registrations for TXN
1163
-        $registrations = $this->_transaction->registrations($query_params);
1164
-        $existing_reg_payments = $this->_template_args['existing_reg_payments'];
1165
-        foreach ($registrations as $registration) {
1166
-            if ($registration instanceof EE_Registration) {
1167
-                $attendee_name                     = $registration->attendee() instanceof EE_Attendee
1168
-                    ? $registration->attendee()->full_name()
1169
-                    : esc_html__('Unknown Attendee', 'event_espresso');
1170
-                $owing                             = $registration->final_price() - $registration->paid();
1171
-                $taxable                           = $registration->ticket()->taxable()
1172
-                    ? ' <span class="smaller-text lt-grey-text"> ' . esc_html__('+ tax', 'event_espresso') . '</span>'
1173
-                    : '';
1174
-                $checked = empty($existing_reg_payments) || in_array($registration->ID(), $existing_reg_payments)
1175
-                    ? ' checked="checked"'
1176
-                    : '';
1177
-                $disabled                          = $registration->final_price() > 0 ? '' : ' disabled';
1178
-                $registrations_to_apply_payment_to .= EEH_HTML::tr(
1179
-                    EEH_HTML::td($registration->ID()) .
1180
-                    EEH_HTML::td($attendee_name) .
1181
-                    EEH_HTML::td(
1182
-                        $registration->ticket()->name() . ' : ' . $registration->ticket()->pretty_price() . $taxable
1183
-                    ) .
1184
-                    EEH_HTML::td($registration->event_name()) .
1185
-                    EEH_HTML::td($registration->pretty_paid(), '', 'txn-admin-payment-paid-td jst-cntr') .
1186
-                    EEH_HTML::td(EEH_Template::format_currency($owing), '', 'txn-admin-payment-owing-td jst-cntr') .
1187
-                    EEH_HTML::td(
1188
-                        '<input type="checkbox" value="' . $registration->ID()
1189
-                        . '" name="txn_admin_payment[registrations]"'
1190
-                        . $checked . $disabled . '>',
1191
-                        '',
1192
-                        'jst-cntr'
1193
-                    ),
1194
-                    'apply-payment-registration-row-' . $registration->ID()
1195
-                );
1196
-            }
1197
-        }
1198
-        $registrations_to_apply_payment_to                         .= EEH_HTML::tbodyx();
1199
-        $registrations_to_apply_payment_to                         .= EEH_HTML::tablex();
1200
-        $registrations_to_apply_payment_to                         .= EEH_HTML::divx();
1201
-        $registrations_to_apply_payment_to                         .= EEH_HTML::p(
1202
-            esc_html__(
1203
-                'The payment will only be applied to the registrations that have a check mark in their corresponding check box. Checkboxes for free registrations have been disabled.',
1204
-                'event_espresso'
1205
-            ),
1206
-            '',
1207
-            'clear description'
1208
-        );
1209
-        $registrations_to_apply_payment_to                         .= EEH_HTML::divx();
1210
-        $this->_template_args['registrations_to_apply_payment_to'] = $registrations_to_apply_payment_to;
1211
-    }
1212
-
1213
-
1214
-    /**
1215
-     * _get_reg_status_selection
1216
-     *
1217
-     * @todo   this will need to be adjusted either once MER comes along OR we move default reg status to tickets
1218
-     *         instead of events.
1219
-     * @access protected
1220
-     * @return void
1221
-     * @throws EE_Error
1222
-     */
1223
-    protected function _get_reg_status_selection()
1224
-    {
1225
-        //first get all possible statuses
1226
-        $statuses = EEM_Registration::reg_status_array(array(), true);
1227
-        //let's add a "don't change" option.
1228
-        $status_array['NAN']                                 = esc_html__('Leave the Same', 'event_espresso');
1229
-        $status_array                                        = array_merge($status_array, $statuses);
1230
-        $this->_template_args['status_change_select']        = EEH_Form_Fields::select_input(
1231
-            'txn_reg_status_change[reg_status]',
1232
-            $status_array,
1233
-            'NAN',
1234
-            'id="txn-admin-payment-reg-status-inp"',
1235
-            'txn-reg-status-change-reg-status'
1236
-        );
1237
-        $this->_template_args['delete_status_change_select'] = EEH_Form_Fields::select_input(
1238
-            'delete_txn_reg_status_change[reg_status]',
1239
-            $status_array,
1240
-            'NAN',
1241
-            'delete-txn-admin-payment-reg-status-inp',
1242
-            'delete-txn-reg-status-change-reg-status'
1243
-        );
1244
-    }
1245
-
1246
-
1247
-    /**
1248
-     *    _get_payment_methods
1249
-     * Gets all the payment methods available generally, or the ones that are already
1250
-     * selected on these payments (in case their payment methods are no longer active).
1251
-     * Has the side-effect of updating the template args' payment_methods item
1252
-     *
1253
-     * @access private
1254
-     * @param EE_Payment[] to show on this page
1255
-     * @return void
1256
-     * @throws EE_Error
1257
-     * @throws InvalidArgumentException
1258
-     * @throws InvalidDataTypeException
1259
-     * @throws InvalidInterfaceException
1260
-     */
1261
-    private function _get_payment_methods($payments = array())
1262
-    {
1263
-        $payment_methods_of_payments = array();
1264
-        foreach ($payments as $payment) {
1265
-            if ($payment instanceof EE_Payment) {
1266
-                $payment_methods_of_payments[] = $payment->get('PMD_ID');
1267
-            }
1268
-        }
1269
-        if ($payment_methods_of_payments) {
1270
-            $query_args = array(
1271
-                array(
1272
-                    'OR*payment_method_for_payment' => array(
1273
-                        'PMD_ID'    => array('IN', $payment_methods_of_payments),
1274
-                        'PMD_scope' => array('LIKE', '%' . EEM_Payment_Method::scope_admin . '%'),
1275
-                    ),
1276
-                ),
1277
-            );
1278
-        } else {
1279
-            $query_args = array(array('PMD_scope' => array('LIKE', '%' . EEM_Payment_Method::scope_admin . '%')));
1280
-        }
1281
-        $this->_template_args['payment_methods'] = EEM_Payment_Method::instance()->get_all($query_args);
1282
-    }
1283
-
1284
-
1285
-    /**
1286
-     * txn_attendees_meta_box
1287
-     *    generates HTML for the Attendees Transaction main meta box
1288
-     *
1289
-     * @access public
1290
-     * @param WP_Post $post
1291
-     * @param array   $metabox
1292
-     * @return void
1293
-     * @throws DomainException
1294
-     * @throws EE_Error
1295
-     */
1296
-    public function txn_attendees_meta_box($post, $metabox = array('args' => array()))
1297
-    {
1298
-
1299
-        /** @noinspection NonSecureExtractUsageInspection */
1300
-        extract($metabox['args']);
1301
-        $this->_template_args['post']            = $post;
1302
-        $this->_template_args['event_attendees'] = array();
1303
-        // process items in cart
1304
-        $line_items = $this->_transaction->get_many_related(
1305
-            'Line_Item',
1306
-            array(array('LIN_type' => 'line-item'))
1307
-        );
1308
-        if (! empty($line_items)) {
1309
-            foreach ($line_items as $item) {
1310
-                if ($item instanceof EE_Line_Item) {
1311
-                    switch ($item->OBJ_type()) {
1312
-                        case 'Event':
1313
-                            break;
1314
-                        case 'Ticket':
1315
-                            $ticket = $item->ticket();
1316
-                            //right now we're only handling tickets here.
1317
-                            //Cause its expected that only tickets will have attendees right?
1318
-                            if (! $ticket instanceof EE_Ticket) {
1319
-                                continue;
1320
-                            }
1321
-                            try {
1322
-                                $event_name = $ticket->get_event_name();
1323
-                            } catch (Exception $e) {
1324
-                                EE_Error::add_error($e->getMessage(), __FILE__, __FUNCTION__, __LINE__);
1325
-                                $event_name = esc_html__('Unknown Event', 'event_espresso');
1326
-                            }
1327
-                            $event_name   .= ' - ' . $item->get('LIN_name');
1328
-                            $ticket_price = EEH_Template::format_currency($item->get('LIN_unit_price'));
1329
-                            // now get all of the registrations for this transaction that use this ticket
1330
-                            $registrations = $ticket->get_many_related(
1331
-                                'Registration',
1332
-                                array(array('TXN_ID' => $this->_transaction->ID()))
1333
-                            );
1334
-                            foreach ($registrations as $registration) {
1335
-                                if (! $registration instanceof EE_Registration) {
1336
-                                    continue;
1337
-                                }
1338
-                                $this->_template_args['event_attendees'][$registration->ID()]['STS_ID']
1339
-                                    = $registration->status_ID();
1340
-                                $this->_template_args['event_attendees'][$registration->ID()]['att_num']
1341
-                                    = $registration->count();
1342
-                                $this->_template_args['event_attendees'][$registration->ID()]['event_ticket_name']
1343
-                                    = $event_name;
1344
-                                $this->_template_args['event_attendees'][$registration->ID()]['ticket_price']
1345
-                                    = $ticket_price;
1346
-                                // attendee info
1347
-                                $attendee = $registration->get_first_related('Attendee');
1348
-                                if ($attendee instanceof EE_Attendee) {
1349
-                                    $this->_template_args['event_attendees'][$registration->ID()]['att_id']
1350
-                                        = $attendee->ID();
1351
-                                    $this->_template_args['event_attendees'][$registration->ID()]['attendee']
1352
-                                        = $attendee->full_name();
1353
-                                    $this->_template_args['event_attendees'][$registration->ID()]['email']
1354
-                                        = '<a href="mailto:' . $attendee->email() . '?subject=' . $event_name
1355
-                                          . esc_html__(
1356
-                                              ' Event',
1357
-                                              'event_espresso'
1358
-                                          )
1359
-                                          . '">' . $attendee->email() . '</a>';
1360
-                                    $this->_template_args['event_attendees'][$registration->ID()]['address']
1361
-                                        = EEH_Address::format($attendee, 'inline', false, false);
1362
-                                } else {
1363
-                                    $this->_template_args['event_attendees'][$registration->ID()]['att_id']   = '';
1364
-                                    $this->_template_args['event_attendees'][$registration->ID()]['attendee'] = '';
1365
-                                    $this->_template_args['event_attendees'][$registration->ID()]['email']    = '';
1366
-                                    $this->_template_args['event_attendees'][$registration->ID()]['address']  = '';
1367
-                                }
1368
-                            }
1369
-                            break;
1370
-
1371
-                    }
1372
-                }
1373
-            }
1374
-
1375
-            $this->_template_args['transaction_form_url'] = add_query_arg(
1376
-                array(
1377
-                    'action'  => 'edit_transaction',
1378
-                    'process' => 'attendees',
1379
-                ),
1380
-                TXN_ADMIN_URL
1381
-            );
1382
-            echo EEH_Template::display_template(
1383
-                TXN_TEMPLATE_PATH . 'txn_admin_details_main_meta_box_attendees.template.php',
1384
-                $this->_template_args,
1385
-                true
1386
-            );
1387
-
1388
-        } else {
1389
-            echo sprintf(
1390
-                esc_html__(
1391
-                    '%1$sFor some reason, there are no attendees registered for this transaction. Likely the registration was abandoned in process.%2$s',
1392
-                    'event_espresso'
1393
-                ),
1394
-                '<p class="important-notice">',
1395
-                '</p>'
1396
-            );
1397
-        }
1398
-    }
1399
-
1400
-
1401
-    /**
1402
-     * txn_registrant_side_meta_box
1403
-     * generates HTML for the Edit Transaction side meta box
1404
-     *
1405
-     * @access public
1406
-     * @return void
1407
-     * @throws DomainException
1408
-     * @throws EE_Error
1409
-     * @throws InvalidArgumentException
1410
-     * @throws InvalidDataTypeException
1411
-     * @throws InvalidInterfaceException
1412
-     */
1413
-    public function txn_registrant_side_meta_box()
1414
-    {
1415
-        $primary_att = $this->_transaction->primary_registration() instanceof EE_Registration
1416
-            ? $this->_transaction->primary_registration()->get_first_related('Attendee')
1417
-            : null;
1418
-        if (! $primary_att instanceof EE_Attendee) {
1419
-            $this->_template_args['no_attendee_message'] = esc_html__(
1420
-                'There is no attached contact for this transaction.  The transaction either failed due to an error or was abandoned.',
1421
-                'event_espresso'
1422
-            );
1423
-            $primary_att                                 = EEM_Attendee::instance()->create_default_object();
1424
-        }
1425
-        $this->_template_args['ATT_ID']            = $primary_att->ID();
1426
-        $this->_template_args['prime_reg_fname']   = $primary_att->fname();
1427
-        $this->_template_args['prime_reg_lname']   = $primary_att->lname();
1428
-        $this->_template_args['prime_reg_email']   = $primary_att->email();
1429
-        $this->_template_args['prime_reg_phone']   = $primary_att->phone();
1430
-        $this->_template_args['edit_attendee_url'] = EE_Admin_Page::add_query_args_and_nonce(array(
1431
-            'action' => 'edit_attendee',
1432
-            'post'   => $primary_att->ID(),
1433
-        ), REG_ADMIN_URL);
1434
-        // get formatted address for registrant
1435
-        $this->_template_args['formatted_address'] = EEH_Address::format($primary_att);
1436
-        echo EEH_Template::display_template(
1437
-            TXN_TEMPLATE_PATH . 'txn_admin_details_side_meta_box_registrant.template.php',
1438
-            $this->_template_args,
1439
-            true
1440
-        );
1441
-    }
1442
-
1443
-
1444
-    /**
1445
-     * txn_billing_info_side_meta_box
1446
-     *    generates HTML for the Edit Transaction side meta box
1447
-     *
1448
-     * @access public
1449
-     * @return void
1450
-     * @throws DomainException
1451
-     * @throws EE_Error
1452
-     */
1453
-    public function txn_billing_info_side_meta_box()
1454
-    {
1455
-
1456
-        $this->_template_args['billing_form']     = $this->_transaction->billing_info();
1457
-        $this->_template_args['billing_form_url'] = add_query_arg(
1458
-            array('action' => 'edit_transaction', 'process' => 'billing'),
1459
-            TXN_ADMIN_URL
1460
-        );
1461
-
1462
-        $template_path = TXN_TEMPLATE_PATH . 'txn_admin_details_side_meta_box_billing_info.template.php';
1463
-        echo EEH_Template::display_template($template_path, $this->_template_args, true);/**/
1464
-    }
1465
-
1466
-
1467
-    /**
1468
-     * apply_payments_or_refunds
1469
-     *    registers a payment or refund made towards a transaction
1470
-     *
1471
-     * @access public
1472
-     * @return void
1473
-     * @throws EE_Error
1474
-     * @throws InvalidArgumentException
1475
-     * @throws ReflectionException
1476
-     * @throws RuntimeException
1477
-     * @throws InvalidDataTypeException
1478
-     * @throws InvalidInterfaceException
1479
-     */
1480
-    public function apply_payments_or_refunds()
1481
-    {
1482
-        $json_response_data = array('return_data' => false);
1483
-        $valid_data         = $this->_validate_payment_request_data();
1484
-        $has_access = EE_Registry::instance()->CAP->current_user_can(
1485
-            'ee_edit_payments',
1486
-            'apply_payment_or_refund_from_registration_details'
1487
-        );
1488
-        if (! empty($valid_data) && $has_access) {
1489
-            $PAY_ID = $valid_data['PAY_ID'];
1490
-            //save  the new payment
1491
-            $payment = $this->_create_payment_from_request_data($valid_data);
1492
-            // get the TXN for this payment
1493
-            $transaction = $payment->transaction();
1494
-            // verify transaction
1495
-            if ($transaction instanceof EE_Transaction) {
1496
-                // calculate_total_payments_and_update_status
1497
-                $this->_process_transaction_payments($transaction);
1498
-                $REG_IDs = $this->_get_REG_IDs_to_apply_payment_to($payment);
1499
-                $this->_remove_existing_registration_payments($payment, $PAY_ID);
1500
-                // apply payment to registrations (if applicable)
1501
-                if (! empty($REG_IDs)) {
1502
-                    $this->_update_registration_payments($transaction, $payment, $REG_IDs);
1503
-                    $this->_maybe_send_notifications();
1504
-                    // now process status changes for the same registrations
1505
-                    $this->_process_registration_status_change($transaction, $REG_IDs);
1506
-                }
1507
-                $this->_maybe_send_notifications($payment);
1508
-                //prepare to render page
1509
-                $json_response_data['return_data'] = $this->_build_payment_json_response($payment, $REG_IDs);
1510
-                do_action(
1511
-                    'AHEE__Transactions_Admin_Page__apply_payments_or_refund__after_recording',
1512
-                    $transaction,
1513
-                    $payment
1514
-                );
1515
-            } else {
1516
-                EE_Error::add_error(
1517
-                    esc_html__(
1518
-                        'A valid Transaction for this payment could not be retrieved.',
1519
-                        'event_espresso'
1520
-                    ),
1521
-                    __FILE__,
1522
-                    __FUNCTION__,
1523
-                    __LINE__
1524
-                );
1525
-            }
1526
-        } else {
1527
-            if ($has_access) {
1528
-                EE_Error::add_error(
1529
-                    esc_html__(
1530
-                        'The payment form data could not be processed. Please try again.',
1531
-                        'event_espresso'
1532
-                    ),
1533
-                    __FILE__,
1534
-                    __FUNCTION__,
1535
-                    __LINE__
1536
-                );
1537
-            } else {
1538
-                EE_Error::add_error(
1539
-                    esc_html__(
1540
-                        'You do not have access to apply payments or refunds to a registration.',
1541
-                        'event_espresso'
1542
-                    ),
1543
-                    __FILE__,
1544
-                    __FUNCTION__,
1545
-                    __LINE__
1546
-                );
1547
-            }
1548
-        }
1549
-        $notices              = EE_Error::get_notices(
1550
-            false,
1551
-            false,
1552
-            false
1553
-        );
1554
-        $this->_template_args = array(
1555
-            'data'    => $json_response_data,
1556
-            'error'   => $notices['errors'],
1557
-            'success' => $notices['success'],
1558
-        );
1559
-        $this->_return_json();
1560
-    }
1561
-
1562
-
1563
-    /**
1564
-     * _validate_payment_request_data
1565
-     *
1566
-     * @return array
1567
-     */
1568
-    protected function _validate_payment_request_data()
1569
-    {
1570
-        if (! isset($this->_req_data['txn_admin_payment'])) {
1571
-            return false;
1572
-        }
1573
-        $payment_form = $this->_generate_payment_form_section();
1574
-        try {
1575
-            if ($payment_form->was_submitted()) {
1576
-                $payment_form->receive_form_submission();
1577
-                if (! $payment_form->is_valid()) {
1578
-                    $submission_error_messages = array();
1579
-                    foreach ($payment_form->get_validation_errors_accumulated() as $validation_error) {
1580
-                        if ($validation_error instanceof EE_Validation_Error) {
1581
-                            $submission_error_messages[] = sprintf(
1582
-                                _x('%s : %s', 'Form Section Name : Form Validation Error', 'event_espresso'),
1583
-                                $validation_error->get_form_section()->html_label_text(),
1584
-                                $validation_error->getMessage()
1585
-                            );
1586
-                        }
1587
-                    }
1588
-                    EE_Error::add_error(
1589
-                        implode('<br />', $submission_error_messages),
1590
-                        __FILE__,
1591
-                        __FUNCTION__,
1592
-                        __LINE__
1593
-                    );
1594
-
1595
-                    return array();
1596
-                }
1597
-            }
1598
-        } catch (EE_Error $e) {
1599
-            EE_Error::add_error($e->getMessage(), __FILE__, __FUNCTION__, __LINE__);
1600
-
1601
-            return array();
1602
-        }
1603
-
1604
-        return $payment_form->valid_data();
1605
-    }
1606
-
1607
-
1608
-    /**
1609
-     * _generate_payment_form_section
1610
-     *
1611
-     * @return EE_Form_Section_Proper
1612
-     */
1613
-    protected function _generate_payment_form_section()
1614
-    {
1615
-        return new EE_Form_Section_Proper(
1616
-            array(
1617
-                'name'        => 'txn_admin_payment',
1618
-                'subsections' => array(
1619
-                    'PAY_ID'          => new EE_Text_Input(
1620
-                        array(
1621
-                            'default'               => 0,
1622
-                            'required'              => false,
1623
-                            'html_label_text'       => esc_html__('Payment ID', 'event_espresso'),
1624
-                            'validation_strategies' => array(new EE_Int_Normalization()),
1625
-                        )
1626
-                    ),
1627
-                    'TXN_ID'          => new EE_Text_Input(
1628
-                        array(
1629
-                            'default'               => 0,
1630
-                            'required'              => true,
1631
-                            'html_label_text'       => esc_html__('Transaction ID', 'event_espresso'),
1632
-                            'validation_strategies' => array(new EE_Int_Normalization()),
1633
-                        )
1634
-                    ),
1635
-                    'type'            => new EE_Text_Input(
1636
-                        array(
1637
-                            'default'               => 1,
1638
-                            'required'              => true,
1639
-                            'html_label_text'       => esc_html__('Payment or Refund', 'event_espresso'),
1640
-                            'validation_strategies' => array(new EE_Int_Normalization()),
1641
-                        )
1642
-                    ),
1643
-                    'amount'          => new EE_Text_Input(
1644
-                        array(
1645
-                            'default'               => 0,
1646
-                            'required'              => true,
1647
-                            'html_label_text'       => esc_html__('Payment amount', 'event_espresso'),
1648
-                            'validation_strategies' => array(new EE_Float_Normalization()),
1649
-                        )
1650
-                    ),
1651
-                    'status'          => new EE_Text_Input(
1652
-                        array(
1653
-                            'default'         => EEM_Payment::status_id_approved,
1654
-                            'required'        => true,
1655
-                            'html_label_text' => esc_html__('Payment status', 'event_espresso'),
1656
-                        )
1657
-                    ),
1658
-                    'PMD_ID'          => new EE_Text_Input(
1659
-                        array(
1660
-                            'default'               => 2,
1661
-                            'required'              => true,
1662
-                            'html_label_text'       => esc_html__('Payment Method', 'event_espresso'),
1663
-                            'validation_strategies' => array(new EE_Int_Normalization()),
1664
-                        )
1665
-                    ),
1666
-                    'date'            => new EE_Text_Input(
1667
-                        array(
1668
-                            'default'         => time(),
1669
-                            'required'        => true,
1670
-                            'html_label_text' => esc_html__('Payment date', 'event_espresso'),
1671
-                        )
1672
-                    ),
1673
-                    'txn_id_chq_nmbr' => new EE_Text_Input(
1674
-                        array(
1675
-                            'default'               => '',
1676
-                            'required'              => false,
1677
-                            'html_label_text'       => esc_html__('Transaction or Cheque Number', 'event_espresso'),
1678
-                            'validation_strategies' => array(
1679
-                                new EE_Max_Length_Validation_Strategy(
1680
-                                    esc_html__('Input too long', 'event_espresso'),
1681
-                                    100
1682
-                                ),
1683
-                            ),
1684
-                        )
1685
-                    ),
1686
-                    'po_number'       => new EE_Text_Input(
1687
-                        array(
1688
-                            'default'               => '',
1689
-                            'required'              => false,
1690
-                            'html_label_text'       => esc_html__('Purchase Order Number', 'event_espresso'),
1691
-                            'validation_strategies' => array(
1692
-                                new EE_Max_Length_Validation_Strategy(
1693
-                                    esc_html__('Input too long', 'event_espresso'),
1694
-                                    100
1695
-                                ),
1696
-                            ),
1697
-                        )
1698
-                    ),
1699
-                    'accounting'      => new EE_Text_Input(
1700
-                        array(
1701
-                            'default'               => '',
1702
-                            'required'              => false,
1703
-                            'html_label_text'       => esc_html__('Extra Field for Accounting', 'event_espresso'),
1704
-                            'validation_strategies' => array(
1705
-                                new EE_Max_Length_Validation_Strategy(
1706
-                                    esc_html__('Input too long', 'event_espresso'),
1707
-                                    100
1708
-                                ),
1709
-                            ),
1710
-                        )
1711
-                    ),
1712
-                ),
1713
-            )
1714
-        );
1715
-    }
1716
-
1717
-
1718
-    /**
1719
-     * _create_payment_from_request_data
1720
-     *
1721
-     * @param array $valid_data
1722
-     * @return EE_Payment
1723
-     * @throws EE_Error
1724
-     */
1725
-    protected function _create_payment_from_request_data($valid_data)
1726
-    {
1727
-        $PAY_ID = $valid_data['PAY_ID'];
1728
-        // get payment amount
1729
-        $amount = $valid_data['amount'] ? abs($valid_data['amount']) : 0;
1730
-        // payments have a type value of 1 and refunds have a type value of -1
1731
-        // so multiplying amount by type will give a positive value for payments, and negative values for refunds
1732
-        $amount = $valid_data['type'] < 0 ? $amount * -1 : $amount;
1733
-        // for some reason the date string coming in has extra spaces between the date and time.  This fixes that.
1734
-        $date    = $valid_data['date']
1735
-            ? preg_replace('/\s+/', ' ', $valid_data['date'])
1736
-            : date('Y-m-d g:i a', current_time('timestamp'));
1737
-        $payment = EE_Payment::new_instance(
1738
-            array(
1739
-                'TXN_ID'              => $valid_data['TXN_ID'],
1740
-                'STS_ID'              => $valid_data['status'],
1741
-                'PAY_timestamp'       => $date,
1742
-                'PAY_source'          => EEM_Payment_Method::scope_admin,
1743
-                'PMD_ID'              => $valid_data['PMD_ID'],
1744
-                'PAY_amount'          => $amount,
1745
-                'PAY_txn_id_chq_nmbr' => $valid_data['txn_id_chq_nmbr'],
1746
-                'PAY_po_number'       => $valid_data['po_number'],
1747
-                'PAY_extra_accntng'   => $valid_data['accounting'],
1748
-                'PAY_details'         => $valid_data,
1749
-                'PAY_ID'              => $PAY_ID,
1750
-            ),
1751
-            '',
1752
-            array('Y-m-d', 'g:i a')
1753
-        );
1754
-
1755
-        if (! $payment->save()) {
1756
-            EE_Error::add_error(
1757
-                sprintf(
1758
-                    esc_html__('Payment %1$d has not been successfully saved to the database.', 'event_espresso'),
1759
-                    $payment->ID()
1760
-                ),
1761
-                __FILE__, __FUNCTION__, __LINE__
1762
-            );
1763
-        }
1764
-
1765
-        return $payment;
1766
-    }
1767
-
1768
-
1769
-    /**
1770
-     * _process_transaction_payments
1771
-     *
1772
-     * @param \EE_Transaction $transaction
1773
-     * @return void
1774
-     * @throws EE_Error
1775
-     * @throws InvalidArgumentException
1776
-     * @throws ReflectionException
1777
-     * @throws InvalidDataTypeException
1778
-     * @throws InvalidInterfaceException
1779
-     */
1780
-    protected function _process_transaction_payments(EE_Transaction $transaction)
1781
-    {
1782
-        /** @type EE_Transaction_Payments $transaction_payments */
1783
-        $transaction_payments = EE_Registry::instance()->load_class('Transaction_Payments');
1784
-        //update the transaction with this payment
1785
-        if ($transaction_payments->calculate_total_payments_and_update_status($transaction)) {
1786
-            EE_Error::add_success(esc_html__(
1787
-                'The payment has been processed successfully.', 'event_espresso'),
1788
-                __FILE__,
1789
-                __FUNCTION__,
1790
-                __LINE__
1791
-            );
1792
-        } else {
1793
-            EE_Error::add_error(
1794
-                esc_html__(
1795
-                    'The payment was processed successfully but the amount paid for the transaction was not updated.',
1796
-                    'event_espresso'
1797
-                )
1798
-                ,
1799
-                __FILE__,
1800
-                __FUNCTION__,
1801
-                __LINE__
1802
-            );
1803
-        }
1804
-    }
1805
-
1806
-
1807
-    /**
1808
-     * _get_REG_IDs_to_apply_payment_to
1809
-     * returns a list of registration IDs that the payment will apply to
1810
-     *
1811
-     * @param \EE_Payment $payment
1812
-     * @return array
1813
-     * @throws EE_Error
1814
-     */
1815
-    protected function _get_REG_IDs_to_apply_payment_to(EE_Payment $payment)
1816
-    {
1817
-        $REG_IDs = array();
1818
-        // grab array of IDs for specific registrations to apply changes to
1819
-        if (isset($this->_req_data['txn_admin_payment']['registrations'])) {
1820
-            $REG_IDs = (array)$this->_req_data['txn_admin_payment']['registrations'];
1821
-        }
1822
-        //nothing specified ? then get all reg IDs
1823
-        if (empty($REG_IDs)) {
1824
-            $registrations = $payment->transaction()->registrations();
1825
-            $REG_IDs       = ! empty($registrations)
1826
-                ? array_keys($registrations)
1827
-                : $this->_get_existing_reg_payment_REG_IDs($payment);
1828
-        }
1829
-
1830
-        // ensure that REG_IDs are integers and NOT strings
1831
-        return array_map('intval', $REG_IDs);
1832
-    }
1833
-
1834
-
1835
-    /**
1836
-     * @return array
1837
-     */
1838
-    public function existing_reg_payment_REG_IDs()
1839
-    {
1840
-        return $this->_existing_reg_payment_REG_IDs;
1841
-    }
1842
-
1843
-
1844
-    /**
1845
-     * @param array $existing_reg_payment_REG_IDs
1846
-     */
1847
-    public function set_existing_reg_payment_REG_IDs($existing_reg_payment_REG_IDs = null)
1848
-    {
1849
-        $this->_existing_reg_payment_REG_IDs = $existing_reg_payment_REG_IDs;
1850
-    }
1851
-
1852
-
1853
-    /**
1854
-     * _get_existing_reg_payment_REG_IDs
1855
-     * returns a list of registration IDs that the payment is currently related to
1856
-     * as recorded in the database
1857
-     *
1858
-     * @param \EE_Payment $payment
1859
-     * @return array
1860
-     * @throws EE_Error
1861
-     */
1862
-    protected function _get_existing_reg_payment_REG_IDs(EE_Payment $payment)
1863
-    {
1864
-        if ($this->existing_reg_payment_REG_IDs() === null) {
1865
-            // let's get any existing reg payment records for this payment
1866
-            $existing_reg_payment_REG_IDs = $payment->get_many_related('Registration');
1867
-            // but we only want the REG IDs, so grab the array keys
1868
-            $existing_reg_payment_REG_IDs = ! empty($existing_reg_payment_REG_IDs)
1869
-                ? array_keys($existing_reg_payment_REG_IDs)
1870
-                : array();
1871
-            $this->set_existing_reg_payment_REG_IDs($existing_reg_payment_REG_IDs);
1872
-        }
1873
-
1874
-        return $this->existing_reg_payment_REG_IDs();
1875
-    }
1876
-
1877
-
1878
-    /**
1879
-     * _remove_existing_registration_payments
1880
-     * this calculates the difference between existing relations
1881
-     * to the supplied payment and the new list registration IDs,
1882
-     * removes any related registrations that no longer apply,
1883
-     * and then updates the registration paid fields
1884
-     *
1885
-     * @param \EE_Payment $payment
1886
-     * @param int         $PAY_ID
1887
-     * @return bool;
1888
-     * @throws EE_Error
1889
-     * @throws InvalidArgumentException
1890
-     * @throws ReflectionException
1891
-     * @throws InvalidDataTypeException
1892
-     * @throws InvalidInterfaceException
1893
-     */
1894
-    protected function _remove_existing_registration_payments(EE_Payment $payment, $PAY_ID = 0)
1895
-    {
1896
-        // newly created payments will have nothing recorded for $PAY_ID
1897
-        if ($PAY_ID == 0) {
1898
-            return false;
1899
-        }
1900
-        $existing_reg_payment_REG_IDs = $this->_get_existing_reg_payment_REG_IDs($payment);
1901
-        if (empty($existing_reg_payment_REG_IDs)) {
1902
-            return false;
1903
-        }
1904
-        /** @type EE_Transaction_Payments $transaction_payments */
1905
-        $transaction_payments = EE_Registry::instance()->load_class('Transaction_Payments');
1906
-
1907
-        return $transaction_payments->delete_registration_payments_and_update_registrations(
1908
-            $payment,
1909
-            array(
1910
-                array(
1911
-                    'PAY_ID' => $payment->ID(),
1912
-                    'REG_ID' => array('IN', $existing_reg_payment_REG_IDs),
1913
-                ),
1914
-            )
1915
-        );
1916
-    }
1917
-
1918
-
1919
-    /**
1920
-     * _update_registration_payments
1921
-     * this applies the payments to the selected registrations
1922
-     * but only if they have not already been paid for
1923
-     *
1924
-     * @param  EE_Transaction $transaction
1925
-     * @param \EE_Payment     $payment
1926
-     * @param array           $REG_IDs
1927
-     * @return void
1928
-     * @throws EE_Error
1929
-     * @throws InvalidArgumentException
1930
-     * @throws ReflectionException
1931
-     * @throws RuntimeException
1932
-     * @throws InvalidDataTypeException
1933
-     * @throws InvalidInterfaceException
1934
-     */
1935
-    protected function _update_registration_payments(
1936
-        EE_Transaction $transaction,
1937
-        EE_Payment $payment,
1938
-        $REG_IDs = array()
1939
-    ) {
1940
-        // we can pass our own custom set of registrations to EE_Payment_Processor::process_registration_payments()
1941
-        // so let's do that using our set of REG_IDs from the form
1942
-        $registration_query_where_params = array(
1943
-            'REG_ID' => array('IN', $REG_IDs),
1944
-        );
1945
-        // but add in some conditions regarding payment,
1946
-        // so that we don't apply payments to registrations that are free or have already been paid for
1947
-        // but ONLY if the payment is NOT a refund ( ie: the payment amount is not negative )
1948
-        if (! $payment->is_a_refund()) {
1949
-            $registration_query_where_params['REG_final_price']  = array('!=', 0);
1950
-            $registration_query_where_params['REG_final_price*'] = array('!=', 'REG_paid', true);
1951
-        }
1952
-        $registrations = $transaction->registrations(array($registration_query_where_params));
1953
-        if (! empty($registrations)) {
1954
-            /** @type EE_Payment_Processor $payment_processor */
1955
-            $payment_processor = EE_Registry::instance()->load_core('Payment_Processor');
1956
-            $payment_processor->process_registration_payments($transaction, $payment, $registrations);
1957
-        }
1958
-    }
1959
-
1960
-
1961
-    /**
1962
-     * _process_registration_status_change
1963
-     * This processes requested registration status changes for all the registrations
1964
-     * on a given transaction and (optionally) sends out notifications for the changes.
1965
-     *
1966
-     * @param  EE_Transaction $transaction
1967
-     * @param array           $REG_IDs
1968
-     * @return bool
1969
-     * @throws EE_Error
1970
-     * @throws InvalidArgumentException
1971
-     * @throws ReflectionException
1972
-     * @throws InvalidDataTypeException
1973
-     * @throws InvalidInterfaceException
1974
-     */
1975
-    protected function _process_registration_status_change(EE_Transaction $transaction, $REG_IDs = array())
1976
-    {
1977
-        // first if there is no change in status then we get out.
1978
-        if (
1979
-            ! isset($this->_req_data['txn_reg_status_change']['reg_status'])
1980
-            || $this->_req_data['txn_reg_status_change']['reg_status'] === 'NAN'
1981
-        ) {
1982
-            //no error message, no change requested, just nothing to do man.
1983
-            return false;
1984
-        }
1985
-        /** @type EE_Transaction_Processor $transaction_processor */
1986
-        $transaction_processor = EE_Registry::instance()->load_class('Transaction_Processor');
1987
-
1988
-        // made it here dude?  Oh WOW.  K, let's take care of changing the statuses
1989
-        return $transaction_processor->manually_update_registration_statuses(
1990
-            $transaction,
1991
-            sanitize_text_field($this->_req_data['txn_reg_status_change']['reg_status']),
1992
-            array(array('REG_ID' => array('IN', $REG_IDs)))
1993
-        );
1994
-    }
1995
-
1996
-
1997
-    /**
1998
-     * _build_payment_json_response
1999
-     *
2000
-     * @access public
2001
-     * @param \EE_Payment $payment
2002
-     * @param array       $REG_IDs
2003
-     * @param bool | null $delete_txn_reg_status_change
2004
-     * @return array
2005
-     * @throws EE_Error
2006
-     * @throws InvalidArgumentException
2007
-     * @throws InvalidDataTypeException
2008
-     * @throws InvalidInterfaceException
2009
-     */
2010
-    protected function _build_payment_json_response(
2011
-        EE_Payment $payment,
2012
-        $REG_IDs = array(),
2013
-        $delete_txn_reg_status_change = null
2014
-    ) {
2015
-        // was the payment deleted ?
2016
-        if (is_bool($delete_txn_reg_status_change)) {
2017
-            return array(
2018
-                'PAY_ID'                       => $payment->ID(),
2019
-                'amount'                       => $payment->amount(),
2020
-                'total_paid'                   => $payment->transaction()->paid(),
2021
-                'txn_status'                   => $payment->transaction()->status_ID(),
2022
-                'pay_status'                   => $payment->STS_ID(),
2023
-                'registrations'                => $this->_registration_payment_data_array($REG_IDs),
2024
-                'delete_txn_reg_status_change' => $delete_txn_reg_status_change,
2025
-            );
2026
-        } else {
2027
-            $this->_get_payment_status_array();
2028
-
2029
-            return array(
2030
-                'amount'           => $payment->amount(),
2031
-                'total_paid'       => $payment->transaction()->paid(),
2032
-                'txn_status'       => $payment->transaction()->status_ID(),
2033
-                'pay_status'       => $payment->STS_ID(),
2034
-                'PAY_ID'           => $payment->ID(),
2035
-                'STS_ID'           => $payment->STS_ID(),
2036
-                'status'           => self::$_pay_status[$payment->STS_ID()],
2037
-                'date'             => $payment->timestamp('Y-m-d', 'h:i a'),
2038
-                'method'           => strtoupper($payment->source()),
2039
-                'PM_ID'            => $payment->payment_method() ? $payment->payment_method()->ID() : 1,
2040
-                'gateway'          => $payment->payment_method()
2041
-                    ? $payment->payment_method()->admin_name()
2042
-                    : esc_html__("Unknown", 'event_espresso'),
2043
-                'gateway_response' => $payment->gateway_response(),
2044
-                'txn_id_chq_nmbr'  => $payment->txn_id_chq_nmbr(),
2045
-                'po_number'        => $payment->po_number(),
2046
-                'extra_accntng'    => $payment->extra_accntng(),
2047
-                'registrations'    => $this->_registration_payment_data_array($REG_IDs),
2048
-            );
2049
-        }
2050
-    }
2051
-
2052
-
2053
-    /**
2054
-     * delete_payment
2055
-     *    delete a payment or refund made towards a transaction
2056
-     *
2057
-     * @access public
2058
-     * @return void
2059
-     * @throws EE_Error
2060
-     * @throws InvalidArgumentException
2061
-     * @throws ReflectionException
2062
-     * @throws InvalidDataTypeException
2063
-     * @throws InvalidInterfaceException
2064
-     */
2065
-    public function delete_payment()
2066
-    {
2067
-        $json_response_data = array('return_data' => false);
2068
-        $PAY_ID             = isset($this->_req_data['delete_txn_admin_payment']['PAY_ID'])
2069
-            ? absint($this->_req_data['delete_txn_admin_payment']['PAY_ID'])
2070
-            : 0;
2071
-        $can_delete = EE_Registry::instance()->CAP->current_user_can(
2072
-            'ee_delete_payments',
2073
-            'delete_payment_from_registration_details'
2074
-        );
2075
-        if ($PAY_ID && $can_delete) {
2076
-            $delete_txn_reg_status_change = isset($this->_req_data['delete_txn_reg_status_change'])
2077
-                ? $this->_req_data['delete_txn_reg_status_change']
2078
-                : false;
2079
-            $payment                      = EEM_Payment::instance()->get_one_by_ID($PAY_ID);
2080
-            if ($payment instanceof EE_Payment) {
2081
-                $REG_IDs = $this->_get_existing_reg_payment_REG_IDs($payment);
2082
-                /** @type EE_Transaction_Payments $transaction_payments */
2083
-                $transaction_payments = EE_Registry::instance()->load_class('Transaction_Payments');
2084
-                if ($transaction_payments->delete_payment_and_update_transaction($payment)) {
2085
-                    $json_response_data['return_data'] = $this->_build_payment_json_response(
2086
-                        $payment,
2087
-                        $REG_IDs,
2088
-                        $delete_txn_reg_status_change
2089
-                    );
2090
-                    if ($delete_txn_reg_status_change) {
2091
-                        $this->_req_data['txn_reg_status_change'] = $delete_txn_reg_status_change;
2092
-                        //MAKE sure we also add the delete_txn_req_status_change to the
2093
-                        //$_REQUEST global because that's how messages will be looking for it.
2094
-                        $_REQUEST['txn_reg_status_change'] = $delete_txn_reg_status_change;
2095
-                        $this->_maybe_send_notifications();
2096
-                        $this->_process_registration_status_change($payment->transaction(), $REG_IDs);
2097
-                    }
2098
-                }
2099
-            } else {
2100
-                EE_Error::add_error(
2101
-                    esc_html__('Valid Payment data could not be retrieved from the database.', 'event_espresso'),
2102
-                    __FILE__, __FUNCTION__, __LINE__
2103
-                );
2104
-            }
2105
-        } else {
2106
-            if ($can_delete) {
2107
-                EE_Error::add_error(
2108
-                    esc_html__(
2109
-                        'A valid Payment ID was not received, therefore payment form data could not be loaded.',
2110
-                        'event_espresso'
2111
-                    ),
2112
-                    __FILE__, __FUNCTION__, __LINE__
2113
-                );
2114
-            } else {
2115
-                EE_Error::add_error(
2116
-                    esc_html__(
2117
-                        'You do not have access to delete a payment.',
2118
-                        'event_espresso'
2119
-                    ),
2120
-                    __FILE__,
2121
-                    __FUNCTION__,
2122
-                    __LINE__
2123
-                );
2124
-            }
2125
-        }
2126
-        $notices              = EE_Error::get_notices(false, false, false);
2127
-        $this->_template_args = array(
2128
-            'data'      => $json_response_data,
2129
-            'success'   => $notices['success'],
2130
-            'error'     => $notices['errors'],
2131
-            'attention' => $notices['attention'],
2132
-        );
2133
-        $this->_return_json();
2134
-    }
2135
-
2136
-
2137
-    /**
2138
-     * _registration_payment_data_array
2139
-     * adds info for 'owing' and 'paid' for each registration to the json response
2140
-     *
2141
-     * @access protected
2142
-     * @param array $REG_IDs
2143
-     * @return array
2144
-     * @throws EE_Error
2145
-     * @throws InvalidArgumentException
2146
-     * @throws InvalidDataTypeException
2147
-     * @throws InvalidInterfaceException
2148
-     */
2149
-    protected function _registration_payment_data_array($REG_IDs)
2150
-    {
2151
-        $registration_payment_data = array();
2152
-        //if non empty reg_ids lets get an array of registrations and update the values for the apply_payment/refund rows.
2153
-        if (! empty($REG_IDs)) {
2154
-            $registrations = EEM_Registration::instance()->get_all(array(array('REG_ID' => array('IN', $REG_IDs))));
2155
-            foreach ($registrations as $registration) {
2156
-                if ($registration instanceof EE_Registration) {
2157
-                    $registration_payment_data[$registration->ID()] = array(
2158
-                        'paid'  => $registration->pretty_paid(),
2159
-                        'owing' => EEH_Template::format_currency($registration->final_price() - $registration->paid()),
2160
-                    );
2161
-                }
2162
-            }
2163
-        }
2164
-
2165
-        return $registration_payment_data;
2166
-    }
2167
-
2168
-
2169
-    /**
2170
-     * _maybe_send_notifications
2171
-     * determines whether or not the admin has indicated that notifications should be sent.
2172
-     * If so, will toggle a filter switch for delivering registration notices.
2173
-     * If passed an EE_Payment object, then it will trigger payment notifications instead.
2174
-     *
2175
-     * @access protected
2176
-     * @param \EE_Payment | null $payment
2177
-     */
2178
-    protected function _maybe_send_notifications($payment = null)
2179
-    {
2180
-        switch ($payment instanceof EE_Payment) {
2181
-            // payment notifications
2182
-            case true :
2183
-                if (
2184
-                    isset(
2185
-                        $this->_req_data['txn_payments'],
2186
-                        $this->_req_data['txn_payments']['send_notifications']
2187
-                    ) &&
2188
-                    filter_var($this->_req_data['txn_payments']['send_notifications'], FILTER_VALIDATE_BOOLEAN)
2189
-                ) {
2190
-                    $this->_process_payment_notification($payment);
2191
-                }
2192
-                break;
2193
-            // registration notifications
2194
-            case false :
2195
-                if (
2196
-                    isset(
2197
-                        $this->_req_data['txn_reg_status_change'],
2198
-                        $this->_req_data['txn_reg_status_change']['send_notifications']
2199
-                    ) &&
2200
-                    filter_var($this->_req_data['txn_reg_status_change']['send_notifications'], FILTER_VALIDATE_BOOLEAN)
2201
-                ) {
2202
-                    add_filter('FHEE__EED_Messages___maybe_registration__deliver_notifications', '__return_true');
2203
-                }
2204
-                break;
2205
-        }
2206
-    }
2207
-
2208
-
2209
-    /**
2210
-     * _send_payment_reminder
2211
-     *    generates HTML for the View Transaction Details Admin page
2212
-     *
2213
-     * @access protected
2214
-     * @return void
2215
-     * @throws EE_Error
2216
-     * @throws InvalidArgumentException
2217
-     * @throws InvalidDataTypeException
2218
-     * @throws InvalidInterfaceException
2219
-     */
2220
-    protected function _send_payment_reminder()
2221
-    {
2222
-        $TXN_ID      = ! empty($this->_req_data['TXN_ID']) ? absint($this->_req_data['TXN_ID']) : false;
2223
-        $transaction = EEM_Transaction::instance()->get_one_by_ID($TXN_ID);
2224
-        $query_args  = isset($this->_req_data['redirect_to']) ? array(
2225
-            'action' => $this->_req_data['redirect_to'],
2226
-            'TXN_ID' => $this->_req_data['TXN_ID'],
2227
-        ) : array();
2228
-        do_action(
2229
-            'AHEE__Transactions_Admin_Page___send_payment_reminder__process_admin_payment_reminder',
2230
-            $transaction
2231
-        );
2232
-        $this->_redirect_after_action(
2233
-            false,
2234
-            esc_html__('payment reminder', 'event_espresso'),
2235
-            esc_html__('sent', 'event_espresso'),
2236
-            $query_args,
2237
-            true
2238
-        );
2239
-    }
2240
-
2241
-
2242
-    /**
2243
-     *  get_transactions
2244
-     *    get transactions for given parameters (used by list table)
2245
-     *
2246
-     * @param  int     $perpage how many transactions displayed per page
2247
-     * @param  boolean $count   return the count or objects
2248
-     * @param string   $view
2249
-     * @return mixed int = count || array of transaction objects
2250
-     * @throws EE_Error
2251
-     * @throws InvalidArgumentException
2252
-     * @throws InvalidDataTypeException
2253
-     * @throws InvalidInterfaceException
2254
-     */
2255
-    public function get_transactions($perpage, $count = false, $view = '')
2256
-    {
2257
-
2258
-        $TXN = EEM_Transaction::instance();
2259
-
2260
-        $start_date = isset($this->_req_data['txn-filter-start-date'])
2261
-            ? wp_strip_all_tags($this->_req_data['txn-filter-start-date'])
2262
-            : date(
2263
-                'm/d/Y',
2264
-                strtotime('-10 year')
2265
-            );
2266
-        $end_date   = isset($this->_req_data['txn-filter-end-date'])
2267
-            ? wp_strip_all_tags($this->_req_data['txn-filter-end-date'])
2268
-            : date('m/d/Y');
2269
-
2270
-        //make sure our timestamps start and end right at the boundaries for each day
2271
-        $start_date = date('Y-m-d', strtotime($start_date)) . ' 00:00:00';
2272
-        $end_date   = date('Y-m-d', strtotime($end_date)) . ' 23:59:59';
2273
-
2274
-
2275
-        //convert to timestamps
2276
-        $start_date = strtotime($start_date);
2277
-        $end_date   = strtotime($end_date);
2278
-
2279
-        //makes sure start date is the lowest value and vice versa
2280
-        $start_date = min($start_date, $end_date);
2281
-        $end_date   = max($start_date, $end_date);
2282
-
2283
-        //convert to correct format for query
2284
-        $start_date = EEM_Transaction::instance()->convert_datetime_for_query(
2285
-            'TXN_timestamp',
2286
-            date('Y-m-d H:i:s', $start_date),
2287
-            'Y-m-d H:i:s'
2288
-        );
2289
-        $end_date   = EEM_Transaction::instance()->convert_datetime_for_query(
2290
-            'TXN_timestamp',
2291
-            date('Y-m-d H:i:s', $end_date),
2292
-            'Y-m-d H:i:s'
2293
-        );
2294
-
2295
-
2296
-        //set orderby
2297
-        $this->_req_data['orderby'] = ! empty($this->_req_data['orderby']) ? $this->_req_data['orderby'] : '';
2298
-
2299
-        switch ($this->_req_data['orderby']) {
2300
-            case 'TXN_ID':
2301
-                $orderby = 'TXN_ID';
2302
-                break;
2303
-            case 'ATT_fname':
2304
-                $orderby = 'Registration.Attendee.ATT_fname';
2305
-                break;
2306
-            case 'event_name':
2307
-                $orderby = 'Registration.Event.EVT_name';
2308
-                break;
2309
-            default: //'TXN_timestamp'
2310
-                $orderby = 'TXN_timestamp';
2311
-        }
2312
-
2313
-        $sort         = ! empty($this->_req_data['order']) ? $this->_req_data['order'] : 'DESC';
2314
-        $current_page = ! empty($this->_req_data['paged']) ? $this->_req_data['paged'] : 1;
2315
-        $per_page     = ! empty($perpage) ? $perpage : 10;
2316
-        $per_page     = ! empty($this->_req_data['perpage']) ? $this->_req_data['perpage'] : $per_page;
2317
-
2318
-        $offset = ($current_page - 1) * $per_page;
2319
-        $limit  = array($offset, $per_page);
2320
-
2321
-        $_where = array(
2322
-            'TXN_timestamp'          => array('BETWEEN', array($start_date, $end_date)),
2323
-            'Registration.REG_count' => 1,
2324
-        );
2325
-
2326
-        if (isset($this->_req_data['EVT_ID'])) {
2327
-            $_where['Registration.EVT_ID'] = $this->_req_data['EVT_ID'];
2328
-        }
2329
-
2330
-        if (isset($this->_req_data['s'])) {
2331
-            $search_string = '%' . $this->_req_data['s'] . '%';
2332
-            $_where['OR']  = array(
2333
-                'Registration.Event.EVT_name'         => array('LIKE', $search_string),
2334
-                'Registration.Event.EVT_desc'         => array('LIKE', $search_string),
2335
-                'Registration.Event.EVT_short_desc'   => array('LIKE', $search_string),
2336
-                'Registration.Attendee.ATT_full_name' => array('LIKE', $search_string),
2337
-                'Registration.Attendee.ATT_fname'     => array('LIKE', $search_string),
2338
-                'Registration.Attendee.ATT_lname'     => array('LIKE', $search_string),
2339
-                'Registration.Attendee.ATT_short_bio' => array('LIKE', $search_string),
2340
-                'Registration.Attendee.ATT_email'     => array('LIKE', $search_string),
2341
-                'Registration.Attendee.ATT_address'   => array('LIKE', $search_string),
2342
-                'Registration.Attendee.ATT_address2'  => array('LIKE', $search_string),
2343
-                'Registration.Attendee.ATT_city'      => array('LIKE', $search_string),
2344
-                'Registration.REG_final_price'        => array('LIKE', $search_string),
2345
-                'Registration.REG_code'               => array('LIKE', $search_string),
2346
-                'Registration.REG_count'              => array('LIKE', $search_string),
2347
-                'Registration.REG_group_size'         => array('LIKE', $search_string),
2348
-                'Registration.Ticket.TKT_name'        => array('LIKE', $search_string),
2349
-                'Registration.Ticket.TKT_description' => array('LIKE', $search_string),
2350
-                'Payment.PAY_source'                  => array('LIKE', $search_string),
2351
-                'Payment.Payment_Method.PMD_name'     => array('LIKE', $search_string),
2352
-                'TXN_session_data'                    => array('LIKE', $search_string),
2353
-                'Payment.PAY_txn_id_chq_nmbr'         => array('LIKE', $search_string),
2354
-            );
2355
-        }
2356
-
2357
-        //failed transactions
2358
-        $failed    = (! empty($this->_req_data['status']) && $this->_req_data['status'] === 'failed' && ! $count)
2359
-                     || ($count && $view === 'failed');
2360
-        $abandoned = (! empty($this->_req_data['status']) && $this->_req_data['status'] === 'abandoned' && ! $count)
2361
-                     || ($count && $view === 'abandoned');
2362
-
2363
-        if ($failed) {
2364
-            $_where['STS_ID'] = EEM_Transaction::failed_status_code;
2365
-        } else if ($abandoned) {
2366
-            $_where['STS_ID'] = EEM_Transaction::abandoned_status_code;
2367
-        } else {
2368
-            $_where['STS_ID']  = array('!=', EEM_Transaction::failed_status_code);
2369
-            $_where['STS_ID*'] = array('!=', EEM_Transaction::abandoned_status_code);
2370
-        }
2371
-
2372
-        $query_params = array(
2373
-            $_where,
2374
-            'order_by'                 => array($orderby => $sort),
2375
-            'limit'                    => $limit,
2376
-            'default_where_conditions' => EEM_Base::default_where_conditions_this_only,
2377
-        );
2378
-
2379
-        $transactions = $count
2380
-            ? $TXN->count(array($_where), 'TXN_ID', true)
2381
-            : $TXN->get_all($query_params);
2382
-
2383
-        return $transactions;
2384
-    }
19
+	/**
20
+	 * @var EE_Transaction
21
+	 */
22
+	private $_transaction;
23
+
24
+	/**
25
+	 * @var EE_Session
26
+	 */
27
+	private $_session;
28
+
29
+	/**
30
+	 * @var array $_txn_status
31
+	 */
32
+	private static $_txn_status;
33
+
34
+	/**
35
+	 * @var array $_pay_status
36
+	 */
37
+	private static $_pay_status;
38
+
39
+	/**
40
+	 * @var array $_existing_reg_payment_REG_IDs
41
+	 */
42
+	protected $_existing_reg_payment_REG_IDs = null;
43
+
44
+
45
+	/**
46
+	 * @Constructor
47
+	 * @access public
48
+	 * @param bool $routing
49
+	 * @throws EE_Error
50
+	 * @throws InvalidArgumentException
51
+	 * @throws ReflectionException
52
+	 * @throws InvalidDataTypeException
53
+	 * @throws InvalidInterfaceException
54
+	 */
55
+	public function __construct($routing = true)
56
+	{
57
+		parent::__construct($routing);
58
+	}
59
+
60
+
61
+	/**
62
+	 *    _init_page_props
63
+	 *
64
+	 * @return void
65
+	 */
66
+	protected function _init_page_props()
67
+	{
68
+		$this->page_slug        = TXN_PG_SLUG;
69
+		$this->page_label       = esc_html__('Transactions', 'event_espresso');
70
+		$this->_admin_base_url  = TXN_ADMIN_URL;
71
+		$this->_admin_base_path = TXN_ADMIN;
72
+	}
73
+
74
+
75
+	/**
76
+	 *    _ajax_hooks
77
+	 *
78
+	 * @return void
79
+	 */
80
+	protected function _ajax_hooks()
81
+	{
82
+		add_action('wp_ajax_espresso_apply_payment', array($this, 'apply_payments_or_refunds'));
83
+		add_action('wp_ajax_espresso_apply_refund', array($this, 'apply_payments_or_refunds'));
84
+		add_action('wp_ajax_espresso_delete_payment', array($this, 'delete_payment'));
85
+	}
86
+
87
+
88
+	/**
89
+	 *    _define_page_props
90
+	 *
91
+	 * @return void
92
+	 */
93
+	protected function _define_page_props()
94
+	{
95
+		$this->_admin_page_title = $this->page_label;
96
+		$this->_labels           = array(
97
+			'buttons' => array(
98
+				'add'    => esc_html__('Add New Transaction', 'event_espresso'),
99
+				'edit'   => esc_html__('Edit Transaction', 'event_espresso'),
100
+				'delete' => esc_html__('Delete Transaction', 'event_espresso'),
101
+			),
102
+		);
103
+	}
104
+
105
+
106
+	/**
107
+	 *        grab url requests and route them
108
+	 *
109
+	 * @access private
110
+	 * @return void
111
+	 * @throws EE_Error
112
+	 * @throws InvalidArgumentException
113
+	 * @throws InvalidDataTypeException
114
+	 * @throws InvalidInterfaceException
115
+	 */
116
+	public function _set_page_routes()
117
+	{
118
+
119
+		$this->_set_transaction_status_array();
120
+
121
+		$txn_id = ! empty($this->_req_data['TXN_ID'])
122
+				  && ! is_array($this->_req_data['TXN_ID'])
123
+			? $this->_req_data['TXN_ID']
124
+			: 0;
125
+
126
+		$this->_page_routes = array(
127
+
128
+			'default' => array(
129
+				'func'       => '_transactions_overview_list_table',
130
+				'capability' => 'ee_read_transactions',
131
+			),
132
+
133
+			'view_transaction' => array(
134
+				'func'       => '_transaction_details',
135
+				'capability' => 'ee_read_transaction',
136
+				'obj_id'     => $txn_id,
137
+			),
138
+
139
+			'send_payment_reminder' => array(
140
+				'func'       => '_send_payment_reminder',
141
+				'noheader'   => true,
142
+				'capability' => 'ee_send_message',
143
+			),
144
+
145
+			'espresso_apply_payment' => array(
146
+				'func'       => 'apply_payments_or_refunds',
147
+				'noheader'   => true,
148
+				'capability' => 'ee_edit_payments',
149
+			),
150
+
151
+			'espresso_apply_refund' => array(
152
+				'func'       => 'apply_payments_or_refunds',
153
+				'noheader'   => true,
154
+				'capability' => 'ee_edit_payments',
155
+			),
156
+
157
+			'espresso_delete_payment' => array(
158
+				'func'       => 'delete_payment',
159
+				'noheader'   => true,
160
+				'capability' => 'ee_delete_payments',
161
+			),
162
+
163
+		);
164
+	}
165
+
166
+
167
+	protected function _set_page_config()
168
+	{
169
+		$this->_page_config = array(
170
+			'default'          => array(
171
+				'nav'           => array(
172
+					'label' => esc_html__('Overview', 'event_espresso'),
173
+					'order' => 10,
174
+				),
175
+				'list_table'    => 'EE_Admin_Transactions_List_Table',
176
+				'help_tabs'     => array(
177
+					'transactions_overview_help_tab'                       => array(
178
+						'title'    => esc_html__('Transactions Overview', 'event_espresso'),
179
+						'filename' => 'transactions_overview',
180
+					),
181
+					'transactions_overview_table_column_headings_help_tab' => array(
182
+						'title'    => esc_html__('Transactions Table Column Headings', 'event_espresso'),
183
+						'filename' => 'transactions_overview_table_column_headings',
184
+					),
185
+					'transactions_overview_views_filters_help_tab'         => array(
186
+						'title'    => esc_html__('Transaction Views & Filters & Search', 'event_espresso'),
187
+						'filename' => 'transactions_overview_views_filters_search',
188
+					),
189
+				),
190
+				'help_tour'     => array('Transactions_Overview_Help_Tour'),
191
+				/**
192
+				 * commented out because currently we are not displaying tips for transaction list table status but this
193
+				 * may change in a later iteration so want to keep the code for then.
194
+				 */
195
+				//'qtips' => array( 'Transactions_List_Table_Tips' ),
196
+				'require_nonce' => false,
197
+			),
198
+			'view_transaction' => array(
199
+				'nav'       => array(
200
+					'label'      => esc_html__('View Transaction', 'event_espresso'),
201
+					'order'      => 5,
202
+					'url'        => isset($this->_req_data['TXN_ID'])
203
+						? add_query_arg(array('TXN_ID' => $this->_req_data['TXN_ID']), $this->_current_page_view_url)
204
+						: $this->_admin_base_url,
205
+					'persistent' => false,
206
+				),
207
+				'help_tabs' => array(
208
+					'transactions_view_transaction_help_tab'                                              => array(
209
+						'title'    => esc_html__('View Transaction', 'event_espresso'),
210
+						'filename' => 'transactions_view_transaction',
211
+					),
212
+					'transactions_view_transaction_transaction_details_table_help_tab'                    => array(
213
+						'title'    => esc_html__('Transaction Details Table', 'event_espresso'),
214
+						'filename' => 'transactions_view_transaction_transaction_details_table',
215
+					),
216
+					'transactions_view_transaction_attendees_registered_help_tab'                         => array(
217
+						'title'    => esc_html__('Attendees Registered', 'event_espresso'),
218
+						'filename' => 'transactions_view_transaction_attendees_registered',
219
+					),
220
+					'transactions_view_transaction_views_primary_registrant_billing_information_help_tab' => array(
221
+						'title'    => esc_html__('Primary Registrant & Billing Information', 'event_espresso'),
222
+						'filename' => 'transactions_view_transaction_primary_registrant_billing_information',
223
+					),
224
+				),
225
+				'qtips'     => array('Transaction_Details_Tips'),
226
+				'help_tour' => array('Transaction_Details_Help_Tour'),
227
+				'metaboxes' => array('_transaction_details_metaboxes'),
228
+
229
+				'require_nonce' => false,
230
+			),
231
+		);
232
+	}
233
+
234
+
235
+	/**
236
+	 * The below methods aren't used by this class currently
237
+	 */
238
+	protected function _add_screen_options()
239
+	{
240
+		//noop
241
+	}
242
+
243
+	protected function _add_feature_pointers()
244
+	{
245
+		//noop
246
+	}
247
+
248
+	public function admin_init()
249
+	{
250
+		// IF a registration was JUST added via the admin...
251
+		if (isset(
252
+			$this->_req_data['redirect_from'],
253
+			$this->_req_data['EVT_ID'],
254
+			$this->_req_data['event_name']
255
+		)) {
256
+			// then set a cookie so that we can block any attempts to use
257
+			// the back button as a way to enter another registration.
258
+			setcookie(
259
+				'ee_registration_added',
260
+				$this->_req_data['EVT_ID'], time() + WEEK_IN_SECONDS, '/'
261
+			);
262
+			// and update the global
263
+			$_COOKIE['ee_registration_added'] = $this->_req_data['EVT_ID'];
264
+		}
265
+		EE_Registry::$i18n_js_strings['invalid_server_response'] = esc_html__(
266
+			'An error occurred! Your request may have been processed, but a valid response from the server was not received. Please refresh the page and try again.',
267
+			'event_espresso'
268
+		);
269
+		EE_Registry::$i18n_js_strings['error_occurred']          = esc_html__(
270
+			'An error occurred! Please refresh the page and try again.',
271
+			'event_espresso'
272
+		);
273
+		EE_Registry::$i18n_js_strings['txn_status_array']        = self::$_txn_status;
274
+		EE_Registry::$i18n_js_strings['pay_status_array']        = self::$_pay_status;
275
+		EE_Registry::$i18n_js_strings['payments_total']          = esc_html__('Payments Total', 'event_espresso');
276
+		EE_Registry::$i18n_js_strings['transaction_overpaid']    = esc_html__(
277
+			'This transaction has been overpaid ! Payments Total',
278
+			'event_espresso'
279
+		);
280
+	}
281
+
282
+	public function admin_notices()
283
+	{
284
+		//noop
285
+	}
286
+
287
+	public function admin_footer_scripts()
288
+	{
289
+		//noop
290
+	}
291
+
292
+
293
+	/**
294
+	 * _set_transaction_status_array
295
+	 * sets list of transaction statuses
296
+	 *
297
+	 * @access private
298
+	 * @return void
299
+	 * @throws EE_Error
300
+	 * @throws InvalidArgumentException
301
+	 * @throws InvalidDataTypeException
302
+	 * @throws InvalidInterfaceException
303
+	 */
304
+	private function _set_transaction_status_array()
305
+	{
306
+		self::$_txn_status = EEM_Transaction::instance()->status_array(true);
307
+	}
308
+
309
+
310
+	/**
311
+	 * get_transaction_status_array
312
+	 * return the transaction status array for wp_list_table
313
+	 *
314
+	 * @access public
315
+	 * @return array
316
+	 */
317
+	public function get_transaction_status_array()
318
+	{
319
+		return self::$_txn_status;
320
+	}
321
+
322
+
323
+	/**
324
+	 *    get list of payment statuses
325
+	 *
326
+	 * @access private
327
+	 * @return void
328
+	 * @throws EE_Error
329
+	 * @throws InvalidArgumentException
330
+	 * @throws InvalidDataTypeException
331
+	 * @throws InvalidInterfaceException
332
+	 */
333
+	private function _get_payment_status_array()
334
+	{
335
+		self::$_pay_status                      = EEM_Payment::instance()->status_array(true);
336
+		$this->_template_args['payment_status'] = self::$_pay_status;
337
+
338
+	}
339
+
340
+
341
+	/**
342
+	 *    _add_screen_options_default
343
+	 *
344
+	 * @access protected
345
+	 * @return void
346
+	 * @throws InvalidArgumentException
347
+	 * @throws InvalidDataTypeException
348
+	 * @throws InvalidInterfaceException
349
+	 */
350
+	protected function _add_screen_options_default()
351
+	{
352
+		$this->_per_page_screen_option();
353
+	}
354
+
355
+
356
+	/**
357
+	 * load_scripts_styles
358
+	 *
359
+	 * @access public
360
+	 * @return void
361
+	 */
362
+	public function load_scripts_styles()
363
+	{
364
+		//enqueue style
365
+		wp_register_style(
366
+			'espresso_txn',
367
+			TXN_ASSETS_URL . 'espresso_transactions_admin.css',
368
+			array(),
369
+			EVENT_ESPRESSO_VERSION
370
+		);
371
+		wp_enqueue_style('espresso_txn');
372
+		//scripts
373
+		wp_register_script('espresso_txn', TXN_ASSETS_URL . 'espresso_transactions_admin.js', array(
374
+			'ee_admin_js',
375
+			'ee-datepicker',
376
+			'jquery-ui-datepicker',
377
+			'jquery-ui-draggable',
378
+			'ee-dialog',
379
+			'ee-accounting',
380
+			'ee-serialize-full-array',
381
+		), EVENT_ESPRESSO_VERSION, true);
382
+		wp_enqueue_script('espresso_txn');
383
+	}
384
+
385
+
386
+	/**
387
+	 *    load_scripts_styles_view_transaction
388
+	 *
389
+	 * @access public
390
+	 * @return void
391
+	 */
392
+	public function load_scripts_styles_view_transaction()
393
+	{
394
+		//styles
395
+		wp_enqueue_style('espresso-ui-theme');
396
+	}
397
+
398
+
399
+	/**
400
+	 *    load_scripts_styles_default
401
+	 *
402
+	 * @access public
403
+	 * @return void
404
+	 */
405
+	public function load_scripts_styles_default()
406
+	{
407
+		//styles
408
+		wp_enqueue_style('espresso-ui-theme');
409
+	}
410
+
411
+
412
+	/**
413
+	 *    _set_list_table_views_default
414
+	 *
415
+	 * @access protected
416
+	 * @return void
417
+	 */
418
+	protected function _set_list_table_views_default()
419
+	{
420
+		$this->_views = array(
421
+			'all'       => array(
422
+				'slug'  => 'all',
423
+				'label' => esc_html__('View All Transactions', 'event_espresso'),
424
+				'count' => 0,
425
+			),
426
+			'abandoned' => array(
427
+				'slug'  => 'abandoned',
428
+				'label' => esc_html__('Abandoned Transactions', 'event_espresso'),
429
+				'count' => 0,
430
+			),
431
+			'failed'    => array(
432
+				'slug'  => 'failed',
433
+				'label' => esc_html__('Failed Transactions', 'event_espresso'),
434
+				'count' => 0,
435
+			),
436
+		);
437
+	}
438
+
439
+
440
+	/**
441
+	 * _set_transaction_object
442
+	 * This sets the _transaction property for the transaction details screen
443
+	 *
444
+	 * @access private
445
+	 * @return void
446
+	 * @throws EE_Error
447
+	 * @throws InvalidArgumentException
448
+	 * @throws RuntimeException
449
+	 * @throws InvalidDataTypeException
450
+	 * @throws InvalidInterfaceException
451
+	 */
452
+	private function _set_transaction_object()
453
+	{
454
+		if ($this->_transaction instanceof EE_Transaction) {
455
+			return;
456
+		} //get out we've already set the object
457
+
458
+		$TXN_ID = ! empty($this->_req_data['TXN_ID'])
459
+			? absint($this->_req_data['TXN_ID'])
460
+			: false;
461
+
462
+		//get transaction object
463
+		$this->_transaction = EEM_Transaction::instance()->get_one_by_ID($TXN_ID);
464
+		$this->_session     = $this->_transaction instanceof EE_Transaction
465
+			? $this->_transaction->get('TXN_session_data')
466
+			: null;
467
+		$this->_transaction->verify_abandoned_transaction_status();
468
+
469
+		if (! $this->_transaction instanceof EE_Transaction) {
470
+			$error_msg = sprintf(
471
+				esc_html__(
472
+					'An error occurred and the details for the transaction with the ID # %d could not be retrieved.',
473
+					'event_espresso'
474
+				),
475
+				$TXN_ID
476
+			);
477
+			EE_Error::add_error($error_msg, __FILE__, __FUNCTION__, __LINE__);
478
+		}
479
+	}
480
+
481
+
482
+	/**
483
+	 *    _transaction_legend_items
484
+	 *
485
+	 * @access protected
486
+	 * @return array
487
+	 * @throws EE_Error
488
+	 * @throws InvalidArgumentException
489
+	 * @throws ReflectionException
490
+	 * @throws InvalidDataTypeException
491
+	 * @throws InvalidInterfaceException
492
+	 */
493
+	protected function _transaction_legend_items()
494
+	{
495
+		EE_Registry::instance()->load_helper('MSG_Template');
496
+		$items = array();
497
+
498
+		if (EE_Registry::instance()->CAP->current_user_can(
499
+			'ee_read_global_messages',
500
+			'view_filtered_messages'
501
+		)) {
502
+			$related_for_icon = EEH_MSG_Template::get_message_action_icon('see_notifications_for');
503
+			if (is_array($related_for_icon)
504
+				&& isset($related_for_icon['css_class'], $related_for_icon['label'])
505
+			) {
506
+				$items['view_related_messages'] = array(
507
+					'class' => $related_for_icon['css_class'],
508
+					'desc'  => $related_for_icon['label'],
509
+				);
510
+			}
511
+		}
512
+
513
+		$items = apply_filters(
514
+			'FHEE__Transactions_Admin_Page___transaction_legend_items__items',
515
+			array_merge(
516
+				$items,
517
+				array(
518
+					'view_details'          => array(
519
+						'class' => 'dashicons dashicons-cart',
520
+						'desc'  => esc_html__('View Transaction Details', 'event_espresso'),
521
+					),
522
+					'view_invoice'          => array(
523
+						'class' => 'dashicons dashicons-media-spreadsheet',
524
+						'desc'  => esc_html__('View Transaction Invoice', 'event_espresso'),
525
+					),
526
+					'view_receipt'          => array(
527
+						'class' => 'dashicons dashicons-media-default',
528
+						'desc'  => esc_html__('View Transaction Receipt', 'event_espresso'),
529
+					),
530
+					'view_registration'     => array(
531
+						'class' => 'dashicons dashicons-clipboard',
532
+						'desc'  => esc_html__('View Registration Details', 'event_espresso'),
533
+					),
534
+					'payment_overview_link' => array(
535
+						'class' => 'dashicons dashicons-money',
536
+						'desc'  => esc_html__('Make Payment on Frontend', 'event_espresso'),
537
+					),
538
+				)
539
+			)
540
+		);
541
+
542
+		if (EE_Registry::instance()->CAP->current_user_can(
543
+			'ee_send_message',
544
+			'espresso_transactions_send_payment_reminder'
545
+		)) {
546
+			if (EEH_MSG_Template::is_mt_active('payment_reminder')) {
547
+				$items['send_payment_reminder'] = array(
548
+					'class' => 'dashicons dashicons-email-alt',
549
+					'desc'  => esc_html__('Send Payment Reminder', 'event_espresso'),
550
+				);
551
+			} else {
552
+				$items['blank*'] = array(
553
+					'class' => '',
554
+					'desc'  => '',
555
+				);
556
+			}
557
+		} else {
558
+			$items['blank*'] = array(
559
+				'class' => '',
560
+				'desc'  => '',
561
+			);
562
+		}
563
+		$more_items = apply_filters(
564
+			'FHEE__Transactions_Admin_Page___transaction_legend_items__more_items',
565
+			array(
566
+				'overpaid'   => array(
567
+					'class' => 'ee-status-legend ee-status-legend-' . EEM_Transaction::overpaid_status_code,
568
+					'desc'  => EEH_Template::pretty_status(
569
+						EEM_Transaction::overpaid_status_code,
570
+						false,
571
+						'sentence'
572
+					),
573
+				),
574
+				'complete'   => array(
575
+					'class' => 'ee-status-legend ee-status-legend-' . EEM_Transaction::complete_status_code,
576
+					'desc'  => EEH_Template::pretty_status(
577
+						EEM_Transaction::complete_status_code,
578
+						false,
579
+						'sentence'
580
+					),
581
+				),
582
+				'incomplete' => array(
583
+					'class' => 'ee-status-legend ee-status-legend-' . EEM_Transaction::incomplete_status_code,
584
+					'desc'  => EEH_Template::pretty_status(
585
+						EEM_Transaction::incomplete_status_code,
586
+						false,
587
+						'sentence'
588
+					),
589
+				),
590
+				'abandoned'  => array(
591
+					'class' => 'ee-status-legend ee-status-legend-' . EEM_Transaction::abandoned_status_code,
592
+					'desc'  => EEH_Template::pretty_status(
593
+						EEM_Transaction::abandoned_status_code,
594
+						false,
595
+						'sentence'
596
+					),
597
+				),
598
+				'failed'     => array(
599
+					'class' => 'ee-status-legend ee-status-legend-' . EEM_Transaction::failed_status_code,
600
+					'desc'  => EEH_Template::pretty_status(
601
+						EEM_Transaction::failed_status_code,
602
+						false,
603
+						'sentence'
604
+					),
605
+				),
606
+			)
607
+		);
608
+
609
+		return array_merge($items, $more_items);
610
+	}
611
+
612
+
613
+	/**
614
+	 *    _transactions_overview_list_table
615
+	 *
616
+	 * @access protected
617
+	 * @return void
618
+	 * @throws DomainException
619
+	 * @throws EE_Error
620
+	 * @throws InvalidArgumentException
621
+	 * @throws InvalidDataTypeException
622
+	 * @throws InvalidInterfaceException
623
+	 * @throws ReflectionException
624
+	 */
625
+	protected function _transactions_overview_list_table()
626
+	{
627
+		$this->_admin_page_title = esc_html__('Transactions', 'event_espresso');
628
+		$event = isset($this->_req_data['EVT_ID'])
629
+			? EEM_Event::instance()->get_one_by_ID($this->_req_data['EVT_ID'])
630
+			: null;
631
+		$this->_template_args['admin_page_header'] = $event instanceof EE_Event
632
+			? sprintf(
633
+				esc_html__(
634
+					'%sViewing Transactions for the Event: %s%s',
635
+					'event_espresso'
636
+				),
637
+				'<h3>',
638
+				'<a href="'
639
+				. EE_Admin_Page::add_query_args_and_nonce(
640
+					array('action' => 'edit', 'post' => $event->ID()),
641
+					EVENTS_ADMIN_URL
642
+				)
643
+				. '" title="'
644
+				. esc_attr__(
645
+					'Click to Edit event',
646
+					'event_espresso'
647
+				)
648
+				. '">' . $event->get('EVT_name') . '</a>',
649
+				'</h3>'
650
+			)
651
+			: '';
652
+		$this->_template_args['after_list_table']  = $this->_display_legend($this->_transaction_legend_items());
653
+		$this->display_admin_list_table_page_with_no_sidebar();
654
+	}
655
+
656
+
657
+	/**
658
+	 *    _transaction_details
659
+	 * generates HTML for the View Transaction Details Admin page
660
+	 *
661
+	 * @access protected
662
+	 * @return void
663
+	 * @throws DomainException
664
+	 * @throws EE_Error
665
+	 * @throws InvalidArgumentException
666
+	 * @throws InvalidDataTypeException
667
+	 * @throws InvalidInterfaceException
668
+	 * @throws RuntimeException
669
+	 */
670
+	protected function _transaction_details()
671
+	{
672
+		do_action('AHEE__Transactions_Admin_Page__transaction_details__start', $this->_transaction);
673
+
674
+		$this->_set_transaction_status_array();
675
+
676
+		$this->_template_args                      = array();
677
+		$this->_template_args['transactions_page'] = $this->_wp_page_slug;
678
+
679
+		$this->_set_transaction_object();
680
+
681
+		$primary_registration = $this->_transaction->primary_registration();
682
+		$attendee = $primary_registration instanceof EE_Registration
683
+			? $primary_registration->attendee()
684
+			: null;
685
+
686
+		$this->_template_args['txn_nmbr']['value'] = $this->_transaction->ID();
687
+		$this->_template_args['txn_nmbr']['label'] = esc_html__('Transaction Number', 'event_espresso');
688
+
689
+		$this->_template_args['txn_datetime']['value'] = $this->_transaction->get_i18n_datetime('TXN_timestamp');
690
+		$this->_template_args['txn_datetime']['label'] = esc_html__('Date', 'event_espresso');
691
+
692
+		$this->_template_args['txn_status']['value'] = self::$_txn_status[$this->_transaction->get('STS_ID')];
693
+		$this->_template_args['txn_status']['label'] = esc_html__('Transaction Status', 'event_espresso');
694
+		$this->_template_args['txn_status']['class'] = 'status-' . $this->_transaction->get('STS_ID');
695
+
696
+		$this->_template_args['grand_total'] = $this->_transaction->get('TXN_total');
697
+		$this->_template_args['total_paid']  = $this->_transaction->get('TXN_paid');
698
+
699
+		if ($attendee instanceof EE_Attendee
700
+			&& EE_Registry::instance()->CAP->current_user_can(
701
+				'ee_send_message',
702
+				'espresso_transactions_send_payment_reminder'
703
+			)
704
+		) {
705
+			$this->_template_args['send_payment_reminder_button'] =
706
+				EEH_MSG_Template::is_mt_active('payment_reminder')
707
+				&& $this->_transaction->get('STS_ID') !== EEM_Transaction::complete_status_code
708
+				&& $this->_transaction->get('STS_ID') !== EEM_Transaction::overpaid_status_code
709
+					? EEH_Template::get_button_or_link(
710
+						EE_Admin_Page::add_query_args_and_nonce(
711
+							array(
712
+								'action'      => 'send_payment_reminder',
713
+								'TXN_ID'      => $this->_transaction->ID(),
714
+								'redirect_to' => 'view_transaction',
715
+							),
716
+							TXN_ADMIN_URL
717
+						),
718
+						__(' Send Payment Reminder', 'event_espresso'),
719
+						'button secondary-button right',
720
+						'dashicons dashicons-email-alt'
721
+					)
722
+					: '';
723
+		} else {
724
+			$this->_template_args['send_payment_reminder_button'] = '';
725
+		}
726
+
727
+		$amount_due = $this->_transaction->get('TXN_total') - $this->_transaction->get('TXN_paid');
728
+		$this->_template_args['amount_due'] = EEH_Template::format_currency(
729
+			$amount_due,
730
+			true
731
+		);
732
+		if (EE_Registry::instance()->CFG->currency->sign_b4) {
733
+			$this->_template_args['amount_due'] = EE_Registry::instance()->CFG->currency->sign
734
+												  . $this->_template_args['amount_due'];
735
+		} else {
736
+			$this->_template_args['amount_due'] .= EE_Registry::instance()->CFG->currency->sign;
737
+		}
738
+		$this->_template_args['amount_due_class'] = '';
739
+
740
+		if ($this->_transaction->get('TXN_paid') == $this->_transaction->get('TXN_total')) {
741
+			// paid in full
742
+			$this->_template_args['amount_due'] = false;
743
+		} elseif ($this->_transaction->get('TXN_paid') > $this->_transaction->get('TXN_total')) {
744
+			// overpaid
745
+			$this->_template_args['amount_due_class'] = 'txn-overview-no-payment-spn';
746
+		} elseif ($this->_transaction->get('TXN_total') > 0
747
+				  && $this->_transaction->get('TXN_paid') > 0
748
+		) {
749
+			// monies owing
750
+			$this->_template_args['amount_due_class'] = 'txn-overview-part-payment-spn';
751
+		} elseif ($this->_transaction->get('TXN_total') > 0
752
+				  && $this->_transaction->get('TXN_paid') == 0
753
+		) {
754
+			// no payments made yet
755
+			$this->_template_args['amount_due_class'] = 'txn-overview-no-payment-spn';
756
+		} elseif ($this->_transaction->get('TXN_total') == 0) {
757
+			// free event
758
+			$this->_template_args['amount_due'] = false;
759
+		}
760
+
761
+		$payment_method = $this->_transaction->payment_method();
762
+
763
+		$this->_template_args['method_of_payment_name'] = $payment_method instanceof EE_Payment_Method
764
+			? $payment_method->admin_name()
765
+			: esc_html__('Unknown', 'event_espresso');
766
+
767
+		$this->_template_args['currency_sign'] = EE_Registry::instance()->CFG->currency->sign;
768
+		// link back to overview
769
+		$this->_template_args['txn_overview_url'] = ! empty($_SERVER['HTTP_REFERER'])
770
+			? $_SERVER['HTTP_REFERER']
771
+			: TXN_ADMIN_URL;
772
+
773
+
774
+		// next link
775
+		$next_txn                                 = $this->_transaction->next(
776
+			null,
777
+			array(array('STS_ID' => array('!=', EEM_Transaction::failed_status_code))),
778
+			'TXN_ID'
779
+		);
780
+		$this->_template_args['next_transaction'] = $next_txn
781
+			? $this->_next_link(
782
+				EE_Admin_Page::add_query_args_and_nonce(
783
+					array('action' => 'view_transaction', 'TXN_ID' => $next_txn['TXN_ID']),
784
+					TXN_ADMIN_URL
785
+				),
786
+				'dashicons dashicons-arrow-right ee-icon-size-22'
787
+			)
788
+			: '';
789
+		// previous link
790
+		$previous_txn                                 = $this->_transaction->previous(
791
+			null,
792
+			array(array('STS_ID' => array('!=', EEM_Transaction::failed_status_code))),
793
+			'TXN_ID'
794
+		);
795
+		$this->_template_args['previous_transaction'] = $previous_txn
796
+			? $this->_previous_link(
797
+				EE_Admin_Page::add_query_args_and_nonce(
798
+					array('action' => 'view_transaction', 'TXN_ID' => $previous_txn['TXN_ID']),
799
+					TXN_ADMIN_URL
800
+				),
801
+				'dashicons dashicons-arrow-left ee-icon-size-22'
802
+			)
803
+			: '';
804
+
805
+		// were we just redirected here after adding a new registration ???
806
+		if (isset(
807
+			$this->_req_data['redirect_from'],
808
+			$this->_req_data['EVT_ID'],
809
+			$this->_req_data['event_name']
810
+		)) {
811
+			if (EE_Registry::instance()->CAP->current_user_can(
812
+				'ee_edit_registrations',
813
+				'espresso_registrations_new_registration',
814
+				$this->_req_data['EVT_ID']
815
+			)) {
816
+				$this->_admin_page_title .= '<a id="add-new-registration" class="add-new-h2 button-primary" href="';
817
+				$this->_admin_page_title .= EE_Admin_Page::add_query_args_and_nonce(
818
+					array(
819
+						'page'     => 'espresso_registrations',
820
+						'action'   => 'new_registration',
821
+						'return'   => 'default',
822
+						'TXN_ID'   => $this->_transaction->ID(),
823
+						'event_id' => $this->_req_data['EVT_ID'],
824
+					),
825
+					REG_ADMIN_URL
826
+				);
827
+				$this->_admin_page_title .= '">';
828
+
829
+				$this->_admin_page_title .= sprintf(
830
+					esc_html__('Add Another New Registration to Event: "%1$s" ?', 'event_espresso'),
831
+					htmlentities(urldecode($this->_req_data['event_name']), ENT_QUOTES, 'UTF-8')
832
+				);
833
+				$this->_admin_page_title .= '</a>';
834
+			}
835
+			EE_Registry::instance()->SSN->clear_session(__CLASS__, __FUNCTION__);
836
+		}
837
+		// grab messages at the last second
838
+		$this->_template_args['notices'] = EE_Error::get_notices();
839
+		// path to template
840
+		$template_path                             = TXN_TEMPLATE_PATH . 'txn_admin_details_header.template.php';
841
+		$this->_template_args['admin_page_header'] = EEH_Template::display_template(
842
+			$template_path,
843
+			$this->_template_args,
844
+			true
845
+		);
846
+
847
+		// the details template wrapper
848
+		$this->display_admin_page_with_sidebar();
849
+
850
+	}
851
+
852
+
853
+	/**
854
+	 *        _transaction_details_metaboxes
855
+	 *
856
+	 * @access protected
857
+	 * @return void
858
+	 * @throws EE_Error
859
+	 * @throws InvalidArgumentException
860
+	 * @throws InvalidDataTypeException
861
+	 * @throws InvalidInterfaceException
862
+	 * @throws RuntimeException
863
+	 */
864
+	protected function _transaction_details_metaboxes()
865
+	{
866
+
867
+		$this->_set_transaction_object();
868
+
869
+		add_meta_box(
870
+			'edit-txn-details-mbox',
871
+			esc_html__('Transaction Details', 'event_espresso'),
872
+			array($this, 'txn_details_meta_box'),
873
+			$this->_wp_page_slug,
874
+			'normal',
875
+			'high'
876
+		);
877
+		add_meta_box(
878
+			'edit-txn-attendees-mbox',
879
+			esc_html__('Attendees Registered in this Transaction', 'event_espresso'),
880
+			array($this, 'txn_attendees_meta_box'),
881
+			$this->_wp_page_slug,
882
+			'normal',
883
+			'high',
884
+			array('TXN_ID' => $this->_transaction->ID())
885
+		);
886
+		add_meta_box(
887
+			'edit-txn-registrant-mbox',
888
+			esc_html__('Primary Contact', 'event_espresso'),
889
+			array($this, 'txn_registrant_side_meta_box'),
890
+			$this->_wp_page_slug,
891
+			'side',
892
+			'high'
893
+		);
894
+		add_meta_box(
895
+			'edit-txn-billing-info-mbox',
896
+			esc_html__('Billing Information', 'event_espresso'),
897
+			array($this, 'txn_billing_info_side_meta_box'),
898
+			$this->_wp_page_slug,
899
+			'side',
900
+			'high'
901
+		);
902
+	}
903
+
904
+
905
+	/**
906
+	 * txn_details_meta_box
907
+	 * generates HTML for the Transaction main meta box
908
+	 *
909
+	 * @access public
910
+	 * @return void
911
+	 * @throws DomainException
912
+	 * @throws EE_Error
913
+	 * @throws InvalidArgumentException
914
+	 * @throws InvalidDataTypeException
915
+	 * @throws InvalidInterfaceException
916
+	 * @throws RuntimeException
917
+	 */
918
+	public function txn_details_meta_box()
919
+	{
920
+
921
+		$this->_set_transaction_object();
922
+		$this->_template_args['TXN_ID']   = $this->_transaction->ID();
923
+		$this->_template_args['attendee'] = $this->_transaction->primary_registration() instanceof EE_Registration
924
+			? $this->_transaction->primary_registration()->attendee()
925
+			: null;
926
+		$this->_template_args['can_edit_payments'] = EE_Registry::instance()->CAP->current_user_can(
927
+			'ee_edit_payments',
928
+			'apply_payment_or_refund_from_registration_details'
929
+		);
930
+		$this->_template_args['can_delete_payments'] = EE_Registry::instance()->CAP->current_user_can(
931
+			'ee_delete_payments',
932
+			'delete_payment_from_registration_details'
933
+		);
934
+
935
+		//get line table
936
+		EEH_Autoloader::register_line_item_display_autoloaders();
937
+		$Line_Item_Display                       = new EE_Line_Item_Display(
938
+			'admin_table',
939
+			'EE_Admin_Table_Line_Item_Display_Strategy'
940
+		);
941
+		$this->_template_args['line_item_table'] = $Line_Item_Display->display_line_item(
942
+			$this->_transaction->total_line_item()
943
+		);
944
+		$this->_template_args['REG_code']        = $this->_transaction->get_first_related('Registration')
945
+																	  ->get('REG_code');
946
+
947
+		// process taxes
948
+		$taxes                         = $this->_transaction->get_many_related(
949
+			'Line_Item',
950
+			array(array('LIN_type' => EEM_Line_Item::type_tax))
951
+		);
952
+		$this->_template_args['taxes'] = ! empty($taxes) ? $taxes : false;
953
+
954
+		$this->_template_args['grand_total']     = EEH_Template::format_currency(
955
+			$this->_transaction->get('TXN_total'),
956
+			false,
957
+			false
958
+		);
959
+		$this->_template_args['grand_raw_total'] = $this->_transaction->get('TXN_total');
960
+		$this->_template_args['TXN_status']      = $this->_transaction->get('STS_ID');
961
+
962
+		// process payment details
963
+		$payments = $this->_transaction->get_many_related('Payment');
964
+		if (! empty($payments)) {
965
+			$this->_template_args['payments']              = $payments;
966
+			$this->_template_args['existing_reg_payments'] = $this->_get_registration_payment_IDs($payments);
967
+		} else {
968
+			$this->_template_args['payments']              = false;
969
+			$this->_template_args['existing_reg_payments'] = array();
970
+		}
971
+
972
+		$this->_template_args['edit_payment_url']   = add_query_arg(array('action' => 'edit_payment'), TXN_ADMIN_URL);
973
+		$this->_template_args['delete_payment_url'] = add_query_arg(
974
+			array('action' => 'espresso_delete_payment'),
975
+			TXN_ADMIN_URL
976
+		);
977
+
978
+		if (isset($txn_details['invoice_number'])) {
979
+			$this->_template_args['txn_details']['invoice_number']['value'] = $this->_template_args['REG_code'];
980
+			$this->_template_args['txn_details']['invoice_number']['label'] = esc_html__(
981
+				'Invoice Number',
982
+				'event_espresso'
983
+			);
984
+		}
985
+
986
+		$this->_template_args['txn_details']['registration_session']['value'] = $this->_transaction
987
+			->get_first_related('Registration')
988
+			->get('REG_session');
989
+		$this->_template_args['txn_details']['registration_session']['label'] = esc_html__(
990
+			'Registration Session',
991
+			'event_espresso'
992
+		);
993
+
994
+		$this->_template_args['txn_details']['ip_address']['value'] = isset($this->_session['ip_address'])
995
+			? $this->_session['ip_address']
996
+			: '';
997
+		$this->_template_args['txn_details']['ip_address']['label'] = esc_html__(
998
+			'Transaction placed from IP',
999
+			'event_espresso'
1000
+		);
1001
+
1002
+		$this->_template_args['txn_details']['user_agent']['value'] = isset($this->_session['user_agent'])
1003
+			? $this->_session['user_agent']
1004
+			: '';
1005
+		$this->_template_args['txn_details']['user_agent']['label'] = esc_html__(
1006
+			'Registrant User Agent',
1007
+			'event_espresso'
1008
+		);
1009
+
1010
+		$reg_steps = '<ul>';
1011
+		foreach ($this->_transaction->reg_steps() as $reg_step => $reg_step_status) {
1012
+			if ($reg_step_status === true) {
1013
+				$reg_steps .= '<li style="color:#70cc50">'
1014
+							  . sprintf(
1015
+								  esc_html__('%1$s : Completed', 'event_espresso'),
1016
+								  ucwords(str_replace('_', ' ', $reg_step))
1017
+							  )
1018
+							  . '</li>';
1019
+			} elseif (is_numeric($reg_step_status) && $reg_step_status !== false) {
1020
+				$reg_steps .= '<li style="color:#2EA2CC">'
1021
+							  . sprintf(
1022
+								  esc_html__('%1$s : Initiated %2$s', 'event_espresso'),
1023
+								  ucwords(str_replace('_', ' ', $reg_step)),
1024
+								  date(
1025
+									  get_option('date_format') . ' ' . get_option('time_format'),
1026
+									  ($reg_step_status + (get_option('gmt_offset') * HOUR_IN_SECONDS))
1027
+								  )
1028
+							  )
1029
+							  . '</li>';
1030
+			} else {
1031
+				$reg_steps .= '<li style="color:#E76700">'
1032
+							  . sprintf(
1033
+								  esc_html__('%1$s : Never Initiated', 'event_espresso'),
1034
+								  ucwords(str_replace('_', ' ', $reg_step))
1035
+							  )
1036
+							  . '</li>';
1037
+			}
1038
+		}
1039
+		$reg_steps                                                 .= '</ul>';
1040
+		$this->_template_args['txn_details']['reg_steps']['value'] = $reg_steps;
1041
+		$this->_template_args['txn_details']['reg_steps']['label'] = esc_html__(
1042
+			'Registration Step Progress',
1043
+			'event_espresso'
1044
+		);
1045
+
1046
+
1047
+		$this->_get_registrations_to_apply_payment_to();
1048
+		$this->_get_payment_methods($payments);
1049
+		$this->_get_payment_status_array();
1050
+		$this->_get_reg_status_selection(); //sets up the template args for the reg status array for the transaction.
1051
+
1052
+		$this->_template_args['transaction_form_url']    = add_query_arg(array(
1053
+			'action'  => 'edit_transaction',
1054
+			'process' => 'transaction',
1055
+		), TXN_ADMIN_URL);
1056
+		$this->_template_args['apply_payment_form_url']  = add_query_arg(array(
1057
+			'page'   => 'espresso_transactions',
1058
+			'action' => 'espresso_apply_payment',
1059
+		), WP_AJAX_URL);
1060
+		$this->_template_args['delete_payment_form_url'] = add_query_arg(array(
1061
+			'page'   => 'espresso_transactions',
1062
+			'action' => 'espresso_delete_payment',
1063
+		), WP_AJAX_URL);
1064
+
1065
+		// 'espresso_delete_payment_nonce'
1066
+
1067
+		$template_path = TXN_TEMPLATE_PATH . 'txn_admin_details_main_meta_box_txn_details.template.php';
1068
+		echo EEH_Template::display_template($template_path, $this->_template_args, true);
1069
+	}
1070
+
1071
+
1072
+	/**
1073
+	 * _get_registration_payment_IDs
1074
+	 *    generates an array of Payment IDs and their corresponding Registration IDs
1075
+	 *
1076
+	 * @access protected
1077
+	 * @param EE_Payment[] $payments
1078
+	 * @return array
1079
+	 * @throws EE_Error
1080
+	 * @throws InvalidArgumentException
1081
+	 * @throws InvalidDataTypeException
1082
+	 * @throws InvalidInterfaceException
1083
+	 */
1084
+	protected function _get_registration_payment_IDs($payments = array())
1085
+	{
1086
+		$existing_reg_payments = array();
1087
+		// get all reg payments for these payments
1088
+		$reg_payments = EEM_Registration_Payment::instance()->get_all(array(
1089
+			array(
1090
+				'PAY_ID' => array(
1091
+					'IN',
1092
+					array_keys($payments),
1093
+				),
1094
+			),
1095
+		));
1096
+		if (! empty($reg_payments)) {
1097
+			foreach ($payments as $payment) {
1098
+				if (! $payment instanceof EE_Payment) {
1099
+					continue;
1100
+				} elseif (! isset($existing_reg_payments[$payment->ID()])) {
1101
+					$existing_reg_payments[$payment->ID()] = array();
1102
+				}
1103
+				foreach ($reg_payments as $reg_payment) {
1104
+					if ($reg_payment instanceof EE_Registration_Payment
1105
+						&& $reg_payment->payment_ID() === $payment->ID()
1106
+					) {
1107
+						$existing_reg_payments[$payment->ID()][] = $reg_payment->registration_ID();
1108
+					}
1109
+				}
1110
+			}
1111
+		}
1112
+
1113
+		return $existing_reg_payments;
1114
+	}
1115
+
1116
+
1117
+	/**
1118
+	 * _get_registrations_to_apply_payment_to
1119
+	 *    generates HTML for displaying a series of checkboxes in the admin payment modal window
1120
+	 * which allows the admin to only apply the payment to the specific registrations
1121
+	 *
1122
+	 * @access protected
1123
+	 * @return void
1124
+	 * @throws \EE_Error
1125
+	 */
1126
+	protected function _get_registrations_to_apply_payment_to()
1127
+	{
1128
+		// we want any registration with an active status (ie: not deleted or cancelled)
1129
+		$query_params                      = array(
1130
+			array(
1131
+				'STS_ID' => array(
1132
+					'IN',
1133
+					array(
1134
+						EEM_Registration::status_id_approved,
1135
+						EEM_Registration::status_id_pending_payment,
1136
+						EEM_Registration::status_id_not_approved,
1137
+					),
1138
+				),
1139
+			),
1140
+		);
1141
+		$registrations_to_apply_payment_to = EEH_HTML::br()
1142
+											 . EEH_HTML::div(
1143
+												 '',
1144
+												 'txn-admin-apply-payment-to-registrations-dv',
1145
+												 '',
1146
+												 'clear: both; margin: 1.5em 0 0; display: none;'
1147
+											 );
1148
+		$registrations_to_apply_payment_to .= EEH_HTML::br() . EEH_HTML::div('', '', 'admin-primary-mbox-tbl-wrap');
1149
+		$registrations_to_apply_payment_to .= EEH_HTML::table('', '', 'admin-primary-mbox-tbl');
1150
+		$registrations_to_apply_payment_to .= EEH_HTML::thead(
1151
+			EEH_HTML::tr(
1152
+				EEH_HTML::th(esc_html__('ID', 'event_espresso')) .
1153
+				EEH_HTML::th(esc_html__('Registrant', 'event_espresso')) .
1154
+				EEH_HTML::th(esc_html__('Ticket', 'event_espresso')) .
1155
+				EEH_HTML::th(esc_html__('Event', 'event_espresso')) .
1156
+				EEH_HTML::th(esc_html__('Paid', 'event_espresso'), '', 'txn-admin-payment-paid-td jst-cntr') .
1157
+				EEH_HTML::th(esc_html__('Owing', 'event_espresso'), '', 'txn-admin-payment-owing-td jst-cntr') .
1158
+				EEH_HTML::th(esc_html__('Apply', 'event_espresso'), '', 'jst-cntr')
1159
+			)
1160
+		);
1161
+		$registrations_to_apply_payment_to .= EEH_HTML::tbody();
1162
+		// get registrations for TXN
1163
+		$registrations = $this->_transaction->registrations($query_params);
1164
+		$existing_reg_payments = $this->_template_args['existing_reg_payments'];
1165
+		foreach ($registrations as $registration) {
1166
+			if ($registration instanceof EE_Registration) {
1167
+				$attendee_name                     = $registration->attendee() instanceof EE_Attendee
1168
+					? $registration->attendee()->full_name()
1169
+					: esc_html__('Unknown Attendee', 'event_espresso');
1170
+				$owing                             = $registration->final_price() - $registration->paid();
1171
+				$taxable                           = $registration->ticket()->taxable()
1172
+					? ' <span class="smaller-text lt-grey-text"> ' . esc_html__('+ tax', 'event_espresso') . '</span>'
1173
+					: '';
1174
+				$checked = empty($existing_reg_payments) || in_array($registration->ID(), $existing_reg_payments)
1175
+					? ' checked="checked"'
1176
+					: '';
1177
+				$disabled                          = $registration->final_price() > 0 ? '' : ' disabled';
1178
+				$registrations_to_apply_payment_to .= EEH_HTML::tr(
1179
+					EEH_HTML::td($registration->ID()) .
1180
+					EEH_HTML::td($attendee_name) .
1181
+					EEH_HTML::td(
1182
+						$registration->ticket()->name() . ' : ' . $registration->ticket()->pretty_price() . $taxable
1183
+					) .
1184
+					EEH_HTML::td($registration->event_name()) .
1185
+					EEH_HTML::td($registration->pretty_paid(), '', 'txn-admin-payment-paid-td jst-cntr') .
1186
+					EEH_HTML::td(EEH_Template::format_currency($owing), '', 'txn-admin-payment-owing-td jst-cntr') .
1187
+					EEH_HTML::td(
1188
+						'<input type="checkbox" value="' . $registration->ID()
1189
+						. '" name="txn_admin_payment[registrations]"'
1190
+						. $checked . $disabled . '>',
1191
+						'',
1192
+						'jst-cntr'
1193
+					),
1194
+					'apply-payment-registration-row-' . $registration->ID()
1195
+				);
1196
+			}
1197
+		}
1198
+		$registrations_to_apply_payment_to                         .= EEH_HTML::tbodyx();
1199
+		$registrations_to_apply_payment_to                         .= EEH_HTML::tablex();
1200
+		$registrations_to_apply_payment_to                         .= EEH_HTML::divx();
1201
+		$registrations_to_apply_payment_to                         .= EEH_HTML::p(
1202
+			esc_html__(
1203
+				'The payment will only be applied to the registrations that have a check mark in their corresponding check box. Checkboxes for free registrations have been disabled.',
1204
+				'event_espresso'
1205
+			),
1206
+			'',
1207
+			'clear description'
1208
+		);
1209
+		$registrations_to_apply_payment_to                         .= EEH_HTML::divx();
1210
+		$this->_template_args['registrations_to_apply_payment_to'] = $registrations_to_apply_payment_to;
1211
+	}
1212
+
1213
+
1214
+	/**
1215
+	 * _get_reg_status_selection
1216
+	 *
1217
+	 * @todo   this will need to be adjusted either once MER comes along OR we move default reg status to tickets
1218
+	 *         instead of events.
1219
+	 * @access protected
1220
+	 * @return void
1221
+	 * @throws EE_Error
1222
+	 */
1223
+	protected function _get_reg_status_selection()
1224
+	{
1225
+		//first get all possible statuses
1226
+		$statuses = EEM_Registration::reg_status_array(array(), true);
1227
+		//let's add a "don't change" option.
1228
+		$status_array['NAN']                                 = esc_html__('Leave the Same', 'event_espresso');
1229
+		$status_array                                        = array_merge($status_array, $statuses);
1230
+		$this->_template_args['status_change_select']        = EEH_Form_Fields::select_input(
1231
+			'txn_reg_status_change[reg_status]',
1232
+			$status_array,
1233
+			'NAN',
1234
+			'id="txn-admin-payment-reg-status-inp"',
1235
+			'txn-reg-status-change-reg-status'
1236
+		);
1237
+		$this->_template_args['delete_status_change_select'] = EEH_Form_Fields::select_input(
1238
+			'delete_txn_reg_status_change[reg_status]',
1239
+			$status_array,
1240
+			'NAN',
1241
+			'delete-txn-admin-payment-reg-status-inp',
1242
+			'delete-txn-reg-status-change-reg-status'
1243
+		);
1244
+	}
1245
+
1246
+
1247
+	/**
1248
+	 *    _get_payment_methods
1249
+	 * Gets all the payment methods available generally, or the ones that are already
1250
+	 * selected on these payments (in case their payment methods are no longer active).
1251
+	 * Has the side-effect of updating the template args' payment_methods item
1252
+	 *
1253
+	 * @access private
1254
+	 * @param EE_Payment[] to show on this page
1255
+	 * @return void
1256
+	 * @throws EE_Error
1257
+	 * @throws InvalidArgumentException
1258
+	 * @throws InvalidDataTypeException
1259
+	 * @throws InvalidInterfaceException
1260
+	 */
1261
+	private function _get_payment_methods($payments = array())
1262
+	{
1263
+		$payment_methods_of_payments = array();
1264
+		foreach ($payments as $payment) {
1265
+			if ($payment instanceof EE_Payment) {
1266
+				$payment_methods_of_payments[] = $payment->get('PMD_ID');
1267
+			}
1268
+		}
1269
+		if ($payment_methods_of_payments) {
1270
+			$query_args = array(
1271
+				array(
1272
+					'OR*payment_method_for_payment' => array(
1273
+						'PMD_ID'    => array('IN', $payment_methods_of_payments),
1274
+						'PMD_scope' => array('LIKE', '%' . EEM_Payment_Method::scope_admin . '%'),
1275
+					),
1276
+				),
1277
+			);
1278
+		} else {
1279
+			$query_args = array(array('PMD_scope' => array('LIKE', '%' . EEM_Payment_Method::scope_admin . '%')));
1280
+		}
1281
+		$this->_template_args['payment_methods'] = EEM_Payment_Method::instance()->get_all($query_args);
1282
+	}
1283
+
1284
+
1285
+	/**
1286
+	 * txn_attendees_meta_box
1287
+	 *    generates HTML for the Attendees Transaction main meta box
1288
+	 *
1289
+	 * @access public
1290
+	 * @param WP_Post $post
1291
+	 * @param array   $metabox
1292
+	 * @return void
1293
+	 * @throws DomainException
1294
+	 * @throws EE_Error
1295
+	 */
1296
+	public function txn_attendees_meta_box($post, $metabox = array('args' => array()))
1297
+	{
1298
+
1299
+		/** @noinspection NonSecureExtractUsageInspection */
1300
+		extract($metabox['args']);
1301
+		$this->_template_args['post']            = $post;
1302
+		$this->_template_args['event_attendees'] = array();
1303
+		// process items in cart
1304
+		$line_items = $this->_transaction->get_many_related(
1305
+			'Line_Item',
1306
+			array(array('LIN_type' => 'line-item'))
1307
+		);
1308
+		if (! empty($line_items)) {
1309
+			foreach ($line_items as $item) {
1310
+				if ($item instanceof EE_Line_Item) {
1311
+					switch ($item->OBJ_type()) {
1312
+						case 'Event':
1313
+							break;
1314
+						case 'Ticket':
1315
+							$ticket = $item->ticket();
1316
+							//right now we're only handling tickets here.
1317
+							//Cause its expected that only tickets will have attendees right?
1318
+							if (! $ticket instanceof EE_Ticket) {
1319
+								continue;
1320
+							}
1321
+							try {
1322
+								$event_name = $ticket->get_event_name();
1323
+							} catch (Exception $e) {
1324
+								EE_Error::add_error($e->getMessage(), __FILE__, __FUNCTION__, __LINE__);
1325
+								$event_name = esc_html__('Unknown Event', 'event_espresso');
1326
+							}
1327
+							$event_name   .= ' - ' . $item->get('LIN_name');
1328
+							$ticket_price = EEH_Template::format_currency($item->get('LIN_unit_price'));
1329
+							// now get all of the registrations for this transaction that use this ticket
1330
+							$registrations = $ticket->get_many_related(
1331
+								'Registration',
1332
+								array(array('TXN_ID' => $this->_transaction->ID()))
1333
+							);
1334
+							foreach ($registrations as $registration) {
1335
+								if (! $registration instanceof EE_Registration) {
1336
+									continue;
1337
+								}
1338
+								$this->_template_args['event_attendees'][$registration->ID()]['STS_ID']
1339
+									= $registration->status_ID();
1340
+								$this->_template_args['event_attendees'][$registration->ID()]['att_num']
1341
+									= $registration->count();
1342
+								$this->_template_args['event_attendees'][$registration->ID()]['event_ticket_name']
1343
+									= $event_name;
1344
+								$this->_template_args['event_attendees'][$registration->ID()]['ticket_price']
1345
+									= $ticket_price;
1346
+								// attendee info
1347
+								$attendee = $registration->get_first_related('Attendee');
1348
+								if ($attendee instanceof EE_Attendee) {
1349
+									$this->_template_args['event_attendees'][$registration->ID()]['att_id']
1350
+										= $attendee->ID();
1351
+									$this->_template_args['event_attendees'][$registration->ID()]['attendee']
1352
+										= $attendee->full_name();
1353
+									$this->_template_args['event_attendees'][$registration->ID()]['email']
1354
+										= '<a href="mailto:' . $attendee->email() . '?subject=' . $event_name
1355
+										  . esc_html__(
1356
+											  ' Event',
1357
+											  'event_espresso'
1358
+										  )
1359
+										  . '">' . $attendee->email() . '</a>';
1360
+									$this->_template_args['event_attendees'][$registration->ID()]['address']
1361
+										= EEH_Address::format($attendee, 'inline', false, false);
1362
+								} else {
1363
+									$this->_template_args['event_attendees'][$registration->ID()]['att_id']   = '';
1364
+									$this->_template_args['event_attendees'][$registration->ID()]['attendee'] = '';
1365
+									$this->_template_args['event_attendees'][$registration->ID()]['email']    = '';
1366
+									$this->_template_args['event_attendees'][$registration->ID()]['address']  = '';
1367
+								}
1368
+							}
1369
+							break;
1370
+
1371
+					}
1372
+				}
1373
+			}
1374
+
1375
+			$this->_template_args['transaction_form_url'] = add_query_arg(
1376
+				array(
1377
+					'action'  => 'edit_transaction',
1378
+					'process' => 'attendees',
1379
+				),
1380
+				TXN_ADMIN_URL
1381
+			);
1382
+			echo EEH_Template::display_template(
1383
+				TXN_TEMPLATE_PATH . 'txn_admin_details_main_meta_box_attendees.template.php',
1384
+				$this->_template_args,
1385
+				true
1386
+			);
1387
+
1388
+		} else {
1389
+			echo sprintf(
1390
+				esc_html__(
1391
+					'%1$sFor some reason, there are no attendees registered for this transaction. Likely the registration was abandoned in process.%2$s',
1392
+					'event_espresso'
1393
+				),
1394
+				'<p class="important-notice">',
1395
+				'</p>'
1396
+			);
1397
+		}
1398
+	}
1399
+
1400
+
1401
+	/**
1402
+	 * txn_registrant_side_meta_box
1403
+	 * generates HTML for the Edit Transaction side meta box
1404
+	 *
1405
+	 * @access public
1406
+	 * @return void
1407
+	 * @throws DomainException
1408
+	 * @throws EE_Error
1409
+	 * @throws InvalidArgumentException
1410
+	 * @throws InvalidDataTypeException
1411
+	 * @throws InvalidInterfaceException
1412
+	 */
1413
+	public function txn_registrant_side_meta_box()
1414
+	{
1415
+		$primary_att = $this->_transaction->primary_registration() instanceof EE_Registration
1416
+			? $this->_transaction->primary_registration()->get_first_related('Attendee')
1417
+			: null;
1418
+		if (! $primary_att instanceof EE_Attendee) {
1419
+			$this->_template_args['no_attendee_message'] = esc_html__(
1420
+				'There is no attached contact for this transaction.  The transaction either failed due to an error or was abandoned.',
1421
+				'event_espresso'
1422
+			);
1423
+			$primary_att                                 = EEM_Attendee::instance()->create_default_object();
1424
+		}
1425
+		$this->_template_args['ATT_ID']            = $primary_att->ID();
1426
+		$this->_template_args['prime_reg_fname']   = $primary_att->fname();
1427
+		$this->_template_args['prime_reg_lname']   = $primary_att->lname();
1428
+		$this->_template_args['prime_reg_email']   = $primary_att->email();
1429
+		$this->_template_args['prime_reg_phone']   = $primary_att->phone();
1430
+		$this->_template_args['edit_attendee_url'] = EE_Admin_Page::add_query_args_and_nonce(array(
1431
+			'action' => 'edit_attendee',
1432
+			'post'   => $primary_att->ID(),
1433
+		), REG_ADMIN_URL);
1434
+		// get formatted address for registrant
1435
+		$this->_template_args['formatted_address'] = EEH_Address::format($primary_att);
1436
+		echo EEH_Template::display_template(
1437
+			TXN_TEMPLATE_PATH . 'txn_admin_details_side_meta_box_registrant.template.php',
1438
+			$this->_template_args,
1439
+			true
1440
+		);
1441
+	}
1442
+
1443
+
1444
+	/**
1445
+	 * txn_billing_info_side_meta_box
1446
+	 *    generates HTML for the Edit Transaction side meta box
1447
+	 *
1448
+	 * @access public
1449
+	 * @return void
1450
+	 * @throws DomainException
1451
+	 * @throws EE_Error
1452
+	 */
1453
+	public function txn_billing_info_side_meta_box()
1454
+	{
1455
+
1456
+		$this->_template_args['billing_form']     = $this->_transaction->billing_info();
1457
+		$this->_template_args['billing_form_url'] = add_query_arg(
1458
+			array('action' => 'edit_transaction', 'process' => 'billing'),
1459
+			TXN_ADMIN_URL
1460
+		);
1461
+
1462
+		$template_path = TXN_TEMPLATE_PATH . 'txn_admin_details_side_meta_box_billing_info.template.php';
1463
+		echo EEH_Template::display_template($template_path, $this->_template_args, true);/**/
1464
+	}
1465
+
1466
+
1467
+	/**
1468
+	 * apply_payments_or_refunds
1469
+	 *    registers a payment or refund made towards a transaction
1470
+	 *
1471
+	 * @access public
1472
+	 * @return void
1473
+	 * @throws EE_Error
1474
+	 * @throws InvalidArgumentException
1475
+	 * @throws ReflectionException
1476
+	 * @throws RuntimeException
1477
+	 * @throws InvalidDataTypeException
1478
+	 * @throws InvalidInterfaceException
1479
+	 */
1480
+	public function apply_payments_or_refunds()
1481
+	{
1482
+		$json_response_data = array('return_data' => false);
1483
+		$valid_data         = $this->_validate_payment_request_data();
1484
+		$has_access = EE_Registry::instance()->CAP->current_user_can(
1485
+			'ee_edit_payments',
1486
+			'apply_payment_or_refund_from_registration_details'
1487
+		);
1488
+		if (! empty($valid_data) && $has_access) {
1489
+			$PAY_ID = $valid_data['PAY_ID'];
1490
+			//save  the new payment
1491
+			$payment = $this->_create_payment_from_request_data($valid_data);
1492
+			// get the TXN for this payment
1493
+			$transaction = $payment->transaction();
1494
+			// verify transaction
1495
+			if ($transaction instanceof EE_Transaction) {
1496
+				// calculate_total_payments_and_update_status
1497
+				$this->_process_transaction_payments($transaction);
1498
+				$REG_IDs = $this->_get_REG_IDs_to_apply_payment_to($payment);
1499
+				$this->_remove_existing_registration_payments($payment, $PAY_ID);
1500
+				// apply payment to registrations (if applicable)
1501
+				if (! empty($REG_IDs)) {
1502
+					$this->_update_registration_payments($transaction, $payment, $REG_IDs);
1503
+					$this->_maybe_send_notifications();
1504
+					// now process status changes for the same registrations
1505
+					$this->_process_registration_status_change($transaction, $REG_IDs);
1506
+				}
1507
+				$this->_maybe_send_notifications($payment);
1508
+				//prepare to render page
1509
+				$json_response_data['return_data'] = $this->_build_payment_json_response($payment, $REG_IDs);
1510
+				do_action(
1511
+					'AHEE__Transactions_Admin_Page__apply_payments_or_refund__after_recording',
1512
+					$transaction,
1513
+					$payment
1514
+				);
1515
+			} else {
1516
+				EE_Error::add_error(
1517
+					esc_html__(
1518
+						'A valid Transaction for this payment could not be retrieved.',
1519
+						'event_espresso'
1520
+					),
1521
+					__FILE__,
1522
+					__FUNCTION__,
1523
+					__LINE__
1524
+				);
1525
+			}
1526
+		} else {
1527
+			if ($has_access) {
1528
+				EE_Error::add_error(
1529
+					esc_html__(
1530
+						'The payment form data could not be processed. Please try again.',
1531
+						'event_espresso'
1532
+					),
1533
+					__FILE__,
1534
+					__FUNCTION__,
1535
+					__LINE__
1536
+				);
1537
+			} else {
1538
+				EE_Error::add_error(
1539
+					esc_html__(
1540
+						'You do not have access to apply payments or refunds to a registration.',
1541
+						'event_espresso'
1542
+					),
1543
+					__FILE__,
1544
+					__FUNCTION__,
1545
+					__LINE__
1546
+				);
1547
+			}
1548
+		}
1549
+		$notices              = EE_Error::get_notices(
1550
+			false,
1551
+			false,
1552
+			false
1553
+		);
1554
+		$this->_template_args = array(
1555
+			'data'    => $json_response_data,
1556
+			'error'   => $notices['errors'],
1557
+			'success' => $notices['success'],
1558
+		);
1559
+		$this->_return_json();
1560
+	}
1561
+
1562
+
1563
+	/**
1564
+	 * _validate_payment_request_data
1565
+	 *
1566
+	 * @return array
1567
+	 */
1568
+	protected function _validate_payment_request_data()
1569
+	{
1570
+		if (! isset($this->_req_data['txn_admin_payment'])) {
1571
+			return false;
1572
+		}
1573
+		$payment_form = $this->_generate_payment_form_section();
1574
+		try {
1575
+			if ($payment_form->was_submitted()) {
1576
+				$payment_form->receive_form_submission();
1577
+				if (! $payment_form->is_valid()) {
1578
+					$submission_error_messages = array();
1579
+					foreach ($payment_form->get_validation_errors_accumulated() as $validation_error) {
1580
+						if ($validation_error instanceof EE_Validation_Error) {
1581
+							$submission_error_messages[] = sprintf(
1582
+								_x('%s : %s', 'Form Section Name : Form Validation Error', 'event_espresso'),
1583
+								$validation_error->get_form_section()->html_label_text(),
1584
+								$validation_error->getMessage()
1585
+							);
1586
+						}
1587
+					}
1588
+					EE_Error::add_error(
1589
+						implode('<br />', $submission_error_messages),
1590
+						__FILE__,
1591
+						__FUNCTION__,
1592
+						__LINE__
1593
+					);
1594
+
1595
+					return array();
1596
+				}
1597
+			}
1598
+		} catch (EE_Error $e) {
1599
+			EE_Error::add_error($e->getMessage(), __FILE__, __FUNCTION__, __LINE__);
1600
+
1601
+			return array();
1602
+		}
1603
+
1604
+		return $payment_form->valid_data();
1605
+	}
1606
+
1607
+
1608
+	/**
1609
+	 * _generate_payment_form_section
1610
+	 *
1611
+	 * @return EE_Form_Section_Proper
1612
+	 */
1613
+	protected function _generate_payment_form_section()
1614
+	{
1615
+		return new EE_Form_Section_Proper(
1616
+			array(
1617
+				'name'        => 'txn_admin_payment',
1618
+				'subsections' => array(
1619
+					'PAY_ID'          => new EE_Text_Input(
1620
+						array(
1621
+							'default'               => 0,
1622
+							'required'              => false,
1623
+							'html_label_text'       => esc_html__('Payment ID', 'event_espresso'),
1624
+							'validation_strategies' => array(new EE_Int_Normalization()),
1625
+						)
1626
+					),
1627
+					'TXN_ID'          => new EE_Text_Input(
1628
+						array(
1629
+							'default'               => 0,
1630
+							'required'              => true,
1631
+							'html_label_text'       => esc_html__('Transaction ID', 'event_espresso'),
1632
+							'validation_strategies' => array(new EE_Int_Normalization()),
1633
+						)
1634
+					),
1635
+					'type'            => new EE_Text_Input(
1636
+						array(
1637
+							'default'               => 1,
1638
+							'required'              => true,
1639
+							'html_label_text'       => esc_html__('Payment or Refund', 'event_espresso'),
1640
+							'validation_strategies' => array(new EE_Int_Normalization()),
1641
+						)
1642
+					),
1643
+					'amount'          => new EE_Text_Input(
1644
+						array(
1645
+							'default'               => 0,
1646
+							'required'              => true,
1647
+							'html_label_text'       => esc_html__('Payment amount', 'event_espresso'),
1648
+							'validation_strategies' => array(new EE_Float_Normalization()),
1649
+						)
1650
+					),
1651
+					'status'          => new EE_Text_Input(
1652
+						array(
1653
+							'default'         => EEM_Payment::status_id_approved,
1654
+							'required'        => true,
1655
+							'html_label_text' => esc_html__('Payment status', 'event_espresso'),
1656
+						)
1657
+					),
1658
+					'PMD_ID'          => new EE_Text_Input(
1659
+						array(
1660
+							'default'               => 2,
1661
+							'required'              => true,
1662
+							'html_label_text'       => esc_html__('Payment Method', 'event_espresso'),
1663
+							'validation_strategies' => array(new EE_Int_Normalization()),
1664
+						)
1665
+					),
1666
+					'date'            => new EE_Text_Input(
1667
+						array(
1668
+							'default'         => time(),
1669
+							'required'        => true,
1670
+							'html_label_text' => esc_html__('Payment date', 'event_espresso'),
1671
+						)
1672
+					),
1673
+					'txn_id_chq_nmbr' => new EE_Text_Input(
1674
+						array(
1675
+							'default'               => '',
1676
+							'required'              => false,
1677
+							'html_label_text'       => esc_html__('Transaction or Cheque Number', 'event_espresso'),
1678
+							'validation_strategies' => array(
1679
+								new EE_Max_Length_Validation_Strategy(
1680
+									esc_html__('Input too long', 'event_espresso'),
1681
+									100
1682
+								),
1683
+							),
1684
+						)
1685
+					),
1686
+					'po_number'       => new EE_Text_Input(
1687
+						array(
1688
+							'default'               => '',
1689
+							'required'              => false,
1690
+							'html_label_text'       => esc_html__('Purchase Order Number', 'event_espresso'),
1691
+							'validation_strategies' => array(
1692
+								new EE_Max_Length_Validation_Strategy(
1693
+									esc_html__('Input too long', 'event_espresso'),
1694
+									100
1695
+								),
1696
+							),
1697
+						)
1698
+					),
1699
+					'accounting'      => new EE_Text_Input(
1700
+						array(
1701
+							'default'               => '',
1702
+							'required'              => false,
1703
+							'html_label_text'       => esc_html__('Extra Field for Accounting', 'event_espresso'),
1704
+							'validation_strategies' => array(
1705
+								new EE_Max_Length_Validation_Strategy(
1706
+									esc_html__('Input too long', 'event_espresso'),
1707
+									100
1708
+								),
1709
+							),
1710
+						)
1711
+					),
1712
+				),
1713
+			)
1714
+		);
1715
+	}
1716
+
1717
+
1718
+	/**
1719
+	 * _create_payment_from_request_data
1720
+	 *
1721
+	 * @param array $valid_data
1722
+	 * @return EE_Payment
1723
+	 * @throws EE_Error
1724
+	 */
1725
+	protected function _create_payment_from_request_data($valid_data)
1726
+	{
1727
+		$PAY_ID = $valid_data['PAY_ID'];
1728
+		// get payment amount
1729
+		$amount = $valid_data['amount'] ? abs($valid_data['amount']) : 0;
1730
+		// payments have a type value of 1 and refunds have a type value of -1
1731
+		// so multiplying amount by type will give a positive value for payments, and negative values for refunds
1732
+		$amount = $valid_data['type'] < 0 ? $amount * -1 : $amount;
1733
+		// for some reason the date string coming in has extra spaces between the date and time.  This fixes that.
1734
+		$date    = $valid_data['date']
1735
+			? preg_replace('/\s+/', ' ', $valid_data['date'])
1736
+			: date('Y-m-d g:i a', current_time('timestamp'));
1737
+		$payment = EE_Payment::new_instance(
1738
+			array(
1739
+				'TXN_ID'              => $valid_data['TXN_ID'],
1740
+				'STS_ID'              => $valid_data['status'],
1741
+				'PAY_timestamp'       => $date,
1742
+				'PAY_source'          => EEM_Payment_Method::scope_admin,
1743
+				'PMD_ID'              => $valid_data['PMD_ID'],
1744
+				'PAY_amount'          => $amount,
1745
+				'PAY_txn_id_chq_nmbr' => $valid_data['txn_id_chq_nmbr'],
1746
+				'PAY_po_number'       => $valid_data['po_number'],
1747
+				'PAY_extra_accntng'   => $valid_data['accounting'],
1748
+				'PAY_details'         => $valid_data,
1749
+				'PAY_ID'              => $PAY_ID,
1750
+			),
1751
+			'',
1752
+			array('Y-m-d', 'g:i a')
1753
+		);
1754
+
1755
+		if (! $payment->save()) {
1756
+			EE_Error::add_error(
1757
+				sprintf(
1758
+					esc_html__('Payment %1$d has not been successfully saved to the database.', 'event_espresso'),
1759
+					$payment->ID()
1760
+				),
1761
+				__FILE__, __FUNCTION__, __LINE__
1762
+			);
1763
+		}
1764
+
1765
+		return $payment;
1766
+	}
1767
+
1768
+
1769
+	/**
1770
+	 * _process_transaction_payments
1771
+	 *
1772
+	 * @param \EE_Transaction $transaction
1773
+	 * @return void
1774
+	 * @throws EE_Error
1775
+	 * @throws InvalidArgumentException
1776
+	 * @throws ReflectionException
1777
+	 * @throws InvalidDataTypeException
1778
+	 * @throws InvalidInterfaceException
1779
+	 */
1780
+	protected function _process_transaction_payments(EE_Transaction $transaction)
1781
+	{
1782
+		/** @type EE_Transaction_Payments $transaction_payments */
1783
+		$transaction_payments = EE_Registry::instance()->load_class('Transaction_Payments');
1784
+		//update the transaction with this payment
1785
+		if ($transaction_payments->calculate_total_payments_and_update_status($transaction)) {
1786
+			EE_Error::add_success(esc_html__(
1787
+				'The payment has been processed successfully.', 'event_espresso'),
1788
+				__FILE__,
1789
+				__FUNCTION__,
1790
+				__LINE__
1791
+			);
1792
+		} else {
1793
+			EE_Error::add_error(
1794
+				esc_html__(
1795
+					'The payment was processed successfully but the amount paid for the transaction was not updated.',
1796
+					'event_espresso'
1797
+				)
1798
+				,
1799
+				__FILE__,
1800
+				__FUNCTION__,
1801
+				__LINE__
1802
+			);
1803
+		}
1804
+	}
1805
+
1806
+
1807
+	/**
1808
+	 * _get_REG_IDs_to_apply_payment_to
1809
+	 * returns a list of registration IDs that the payment will apply to
1810
+	 *
1811
+	 * @param \EE_Payment $payment
1812
+	 * @return array
1813
+	 * @throws EE_Error
1814
+	 */
1815
+	protected function _get_REG_IDs_to_apply_payment_to(EE_Payment $payment)
1816
+	{
1817
+		$REG_IDs = array();
1818
+		// grab array of IDs for specific registrations to apply changes to
1819
+		if (isset($this->_req_data['txn_admin_payment']['registrations'])) {
1820
+			$REG_IDs = (array)$this->_req_data['txn_admin_payment']['registrations'];
1821
+		}
1822
+		//nothing specified ? then get all reg IDs
1823
+		if (empty($REG_IDs)) {
1824
+			$registrations = $payment->transaction()->registrations();
1825
+			$REG_IDs       = ! empty($registrations)
1826
+				? array_keys($registrations)
1827
+				: $this->_get_existing_reg_payment_REG_IDs($payment);
1828
+		}
1829
+
1830
+		// ensure that REG_IDs are integers and NOT strings
1831
+		return array_map('intval', $REG_IDs);
1832
+	}
1833
+
1834
+
1835
+	/**
1836
+	 * @return array
1837
+	 */
1838
+	public function existing_reg_payment_REG_IDs()
1839
+	{
1840
+		return $this->_existing_reg_payment_REG_IDs;
1841
+	}
1842
+
1843
+
1844
+	/**
1845
+	 * @param array $existing_reg_payment_REG_IDs
1846
+	 */
1847
+	public function set_existing_reg_payment_REG_IDs($existing_reg_payment_REG_IDs = null)
1848
+	{
1849
+		$this->_existing_reg_payment_REG_IDs = $existing_reg_payment_REG_IDs;
1850
+	}
1851
+
1852
+
1853
+	/**
1854
+	 * _get_existing_reg_payment_REG_IDs
1855
+	 * returns a list of registration IDs that the payment is currently related to
1856
+	 * as recorded in the database
1857
+	 *
1858
+	 * @param \EE_Payment $payment
1859
+	 * @return array
1860
+	 * @throws EE_Error
1861
+	 */
1862
+	protected function _get_existing_reg_payment_REG_IDs(EE_Payment $payment)
1863
+	{
1864
+		if ($this->existing_reg_payment_REG_IDs() === null) {
1865
+			// let's get any existing reg payment records for this payment
1866
+			$existing_reg_payment_REG_IDs = $payment->get_many_related('Registration');
1867
+			// but we only want the REG IDs, so grab the array keys
1868
+			$existing_reg_payment_REG_IDs = ! empty($existing_reg_payment_REG_IDs)
1869
+				? array_keys($existing_reg_payment_REG_IDs)
1870
+				: array();
1871
+			$this->set_existing_reg_payment_REG_IDs($existing_reg_payment_REG_IDs);
1872
+		}
1873
+
1874
+		return $this->existing_reg_payment_REG_IDs();
1875
+	}
1876
+
1877
+
1878
+	/**
1879
+	 * _remove_existing_registration_payments
1880
+	 * this calculates the difference between existing relations
1881
+	 * to the supplied payment and the new list registration IDs,
1882
+	 * removes any related registrations that no longer apply,
1883
+	 * and then updates the registration paid fields
1884
+	 *
1885
+	 * @param \EE_Payment $payment
1886
+	 * @param int         $PAY_ID
1887
+	 * @return bool;
1888
+	 * @throws EE_Error
1889
+	 * @throws InvalidArgumentException
1890
+	 * @throws ReflectionException
1891
+	 * @throws InvalidDataTypeException
1892
+	 * @throws InvalidInterfaceException
1893
+	 */
1894
+	protected function _remove_existing_registration_payments(EE_Payment $payment, $PAY_ID = 0)
1895
+	{
1896
+		// newly created payments will have nothing recorded for $PAY_ID
1897
+		if ($PAY_ID == 0) {
1898
+			return false;
1899
+		}
1900
+		$existing_reg_payment_REG_IDs = $this->_get_existing_reg_payment_REG_IDs($payment);
1901
+		if (empty($existing_reg_payment_REG_IDs)) {
1902
+			return false;
1903
+		}
1904
+		/** @type EE_Transaction_Payments $transaction_payments */
1905
+		$transaction_payments = EE_Registry::instance()->load_class('Transaction_Payments');
1906
+
1907
+		return $transaction_payments->delete_registration_payments_and_update_registrations(
1908
+			$payment,
1909
+			array(
1910
+				array(
1911
+					'PAY_ID' => $payment->ID(),
1912
+					'REG_ID' => array('IN', $existing_reg_payment_REG_IDs),
1913
+				),
1914
+			)
1915
+		);
1916
+	}
1917
+
1918
+
1919
+	/**
1920
+	 * _update_registration_payments
1921
+	 * this applies the payments to the selected registrations
1922
+	 * but only if they have not already been paid for
1923
+	 *
1924
+	 * @param  EE_Transaction $transaction
1925
+	 * @param \EE_Payment     $payment
1926
+	 * @param array           $REG_IDs
1927
+	 * @return void
1928
+	 * @throws EE_Error
1929
+	 * @throws InvalidArgumentException
1930
+	 * @throws ReflectionException
1931
+	 * @throws RuntimeException
1932
+	 * @throws InvalidDataTypeException
1933
+	 * @throws InvalidInterfaceException
1934
+	 */
1935
+	protected function _update_registration_payments(
1936
+		EE_Transaction $transaction,
1937
+		EE_Payment $payment,
1938
+		$REG_IDs = array()
1939
+	) {
1940
+		// we can pass our own custom set of registrations to EE_Payment_Processor::process_registration_payments()
1941
+		// so let's do that using our set of REG_IDs from the form
1942
+		$registration_query_where_params = array(
1943
+			'REG_ID' => array('IN', $REG_IDs),
1944
+		);
1945
+		// but add in some conditions regarding payment,
1946
+		// so that we don't apply payments to registrations that are free or have already been paid for
1947
+		// but ONLY if the payment is NOT a refund ( ie: the payment amount is not negative )
1948
+		if (! $payment->is_a_refund()) {
1949
+			$registration_query_where_params['REG_final_price']  = array('!=', 0);
1950
+			$registration_query_where_params['REG_final_price*'] = array('!=', 'REG_paid', true);
1951
+		}
1952
+		$registrations = $transaction->registrations(array($registration_query_where_params));
1953
+		if (! empty($registrations)) {
1954
+			/** @type EE_Payment_Processor $payment_processor */
1955
+			$payment_processor = EE_Registry::instance()->load_core('Payment_Processor');
1956
+			$payment_processor->process_registration_payments($transaction, $payment, $registrations);
1957
+		}
1958
+	}
1959
+
1960
+
1961
+	/**
1962
+	 * _process_registration_status_change
1963
+	 * This processes requested registration status changes for all the registrations
1964
+	 * on a given transaction and (optionally) sends out notifications for the changes.
1965
+	 *
1966
+	 * @param  EE_Transaction $transaction
1967
+	 * @param array           $REG_IDs
1968
+	 * @return bool
1969
+	 * @throws EE_Error
1970
+	 * @throws InvalidArgumentException
1971
+	 * @throws ReflectionException
1972
+	 * @throws InvalidDataTypeException
1973
+	 * @throws InvalidInterfaceException
1974
+	 */
1975
+	protected function _process_registration_status_change(EE_Transaction $transaction, $REG_IDs = array())
1976
+	{
1977
+		// first if there is no change in status then we get out.
1978
+		if (
1979
+			! isset($this->_req_data['txn_reg_status_change']['reg_status'])
1980
+			|| $this->_req_data['txn_reg_status_change']['reg_status'] === 'NAN'
1981
+		) {
1982
+			//no error message, no change requested, just nothing to do man.
1983
+			return false;
1984
+		}
1985
+		/** @type EE_Transaction_Processor $transaction_processor */
1986
+		$transaction_processor = EE_Registry::instance()->load_class('Transaction_Processor');
1987
+
1988
+		// made it here dude?  Oh WOW.  K, let's take care of changing the statuses
1989
+		return $transaction_processor->manually_update_registration_statuses(
1990
+			$transaction,
1991
+			sanitize_text_field($this->_req_data['txn_reg_status_change']['reg_status']),
1992
+			array(array('REG_ID' => array('IN', $REG_IDs)))
1993
+		);
1994
+	}
1995
+
1996
+
1997
+	/**
1998
+	 * _build_payment_json_response
1999
+	 *
2000
+	 * @access public
2001
+	 * @param \EE_Payment $payment
2002
+	 * @param array       $REG_IDs
2003
+	 * @param bool | null $delete_txn_reg_status_change
2004
+	 * @return array
2005
+	 * @throws EE_Error
2006
+	 * @throws InvalidArgumentException
2007
+	 * @throws InvalidDataTypeException
2008
+	 * @throws InvalidInterfaceException
2009
+	 */
2010
+	protected function _build_payment_json_response(
2011
+		EE_Payment $payment,
2012
+		$REG_IDs = array(),
2013
+		$delete_txn_reg_status_change = null
2014
+	) {
2015
+		// was the payment deleted ?
2016
+		if (is_bool($delete_txn_reg_status_change)) {
2017
+			return array(
2018
+				'PAY_ID'                       => $payment->ID(),
2019
+				'amount'                       => $payment->amount(),
2020
+				'total_paid'                   => $payment->transaction()->paid(),
2021
+				'txn_status'                   => $payment->transaction()->status_ID(),
2022
+				'pay_status'                   => $payment->STS_ID(),
2023
+				'registrations'                => $this->_registration_payment_data_array($REG_IDs),
2024
+				'delete_txn_reg_status_change' => $delete_txn_reg_status_change,
2025
+			);
2026
+		} else {
2027
+			$this->_get_payment_status_array();
2028
+
2029
+			return array(
2030
+				'amount'           => $payment->amount(),
2031
+				'total_paid'       => $payment->transaction()->paid(),
2032
+				'txn_status'       => $payment->transaction()->status_ID(),
2033
+				'pay_status'       => $payment->STS_ID(),
2034
+				'PAY_ID'           => $payment->ID(),
2035
+				'STS_ID'           => $payment->STS_ID(),
2036
+				'status'           => self::$_pay_status[$payment->STS_ID()],
2037
+				'date'             => $payment->timestamp('Y-m-d', 'h:i a'),
2038
+				'method'           => strtoupper($payment->source()),
2039
+				'PM_ID'            => $payment->payment_method() ? $payment->payment_method()->ID() : 1,
2040
+				'gateway'          => $payment->payment_method()
2041
+					? $payment->payment_method()->admin_name()
2042
+					: esc_html__("Unknown", 'event_espresso'),
2043
+				'gateway_response' => $payment->gateway_response(),
2044
+				'txn_id_chq_nmbr'  => $payment->txn_id_chq_nmbr(),
2045
+				'po_number'        => $payment->po_number(),
2046
+				'extra_accntng'    => $payment->extra_accntng(),
2047
+				'registrations'    => $this->_registration_payment_data_array($REG_IDs),
2048
+			);
2049
+		}
2050
+	}
2051
+
2052
+
2053
+	/**
2054
+	 * delete_payment
2055
+	 *    delete a payment or refund made towards a transaction
2056
+	 *
2057
+	 * @access public
2058
+	 * @return void
2059
+	 * @throws EE_Error
2060
+	 * @throws InvalidArgumentException
2061
+	 * @throws ReflectionException
2062
+	 * @throws InvalidDataTypeException
2063
+	 * @throws InvalidInterfaceException
2064
+	 */
2065
+	public function delete_payment()
2066
+	{
2067
+		$json_response_data = array('return_data' => false);
2068
+		$PAY_ID             = isset($this->_req_data['delete_txn_admin_payment']['PAY_ID'])
2069
+			? absint($this->_req_data['delete_txn_admin_payment']['PAY_ID'])
2070
+			: 0;
2071
+		$can_delete = EE_Registry::instance()->CAP->current_user_can(
2072
+			'ee_delete_payments',
2073
+			'delete_payment_from_registration_details'
2074
+		);
2075
+		if ($PAY_ID && $can_delete) {
2076
+			$delete_txn_reg_status_change = isset($this->_req_data['delete_txn_reg_status_change'])
2077
+				? $this->_req_data['delete_txn_reg_status_change']
2078
+				: false;
2079
+			$payment                      = EEM_Payment::instance()->get_one_by_ID($PAY_ID);
2080
+			if ($payment instanceof EE_Payment) {
2081
+				$REG_IDs = $this->_get_existing_reg_payment_REG_IDs($payment);
2082
+				/** @type EE_Transaction_Payments $transaction_payments */
2083
+				$transaction_payments = EE_Registry::instance()->load_class('Transaction_Payments');
2084
+				if ($transaction_payments->delete_payment_and_update_transaction($payment)) {
2085
+					$json_response_data['return_data'] = $this->_build_payment_json_response(
2086
+						$payment,
2087
+						$REG_IDs,
2088
+						$delete_txn_reg_status_change
2089
+					);
2090
+					if ($delete_txn_reg_status_change) {
2091
+						$this->_req_data['txn_reg_status_change'] = $delete_txn_reg_status_change;
2092
+						//MAKE sure we also add the delete_txn_req_status_change to the
2093
+						//$_REQUEST global because that's how messages will be looking for it.
2094
+						$_REQUEST['txn_reg_status_change'] = $delete_txn_reg_status_change;
2095
+						$this->_maybe_send_notifications();
2096
+						$this->_process_registration_status_change($payment->transaction(), $REG_IDs);
2097
+					}
2098
+				}
2099
+			} else {
2100
+				EE_Error::add_error(
2101
+					esc_html__('Valid Payment data could not be retrieved from the database.', 'event_espresso'),
2102
+					__FILE__, __FUNCTION__, __LINE__
2103
+				);
2104
+			}
2105
+		} else {
2106
+			if ($can_delete) {
2107
+				EE_Error::add_error(
2108
+					esc_html__(
2109
+						'A valid Payment ID was not received, therefore payment form data could not be loaded.',
2110
+						'event_espresso'
2111
+					),
2112
+					__FILE__, __FUNCTION__, __LINE__
2113
+				);
2114
+			} else {
2115
+				EE_Error::add_error(
2116
+					esc_html__(
2117
+						'You do not have access to delete a payment.',
2118
+						'event_espresso'
2119
+					),
2120
+					__FILE__,
2121
+					__FUNCTION__,
2122
+					__LINE__
2123
+				);
2124
+			}
2125
+		}
2126
+		$notices              = EE_Error::get_notices(false, false, false);
2127
+		$this->_template_args = array(
2128
+			'data'      => $json_response_data,
2129
+			'success'   => $notices['success'],
2130
+			'error'     => $notices['errors'],
2131
+			'attention' => $notices['attention'],
2132
+		);
2133
+		$this->_return_json();
2134
+	}
2135
+
2136
+
2137
+	/**
2138
+	 * _registration_payment_data_array
2139
+	 * adds info for 'owing' and 'paid' for each registration to the json response
2140
+	 *
2141
+	 * @access protected
2142
+	 * @param array $REG_IDs
2143
+	 * @return array
2144
+	 * @throws EE_Error
2145
+	 * @throws InvalidArgumentException
2146
+	 * @throws InvalidDataTypeException
2147
+	 * @throws InvalidInterfaceException
2148
+	 */
2149
+	protected function _registration_payment_data_array($REG_IDs)
2150
+	{
2151
+		$registration_payment_data = array();
2152
+		//if non empty reg_ids lets get an array of registrations and update the values for the apply_payment/refund rows.
2153
+		if (! empty($REG_IDs)) {
2154
+			$registrations = EEM_Registration::instance()->get_all(array(array('REG_ID' => array('IN', $REG_IDs))));
2155
+			foreach ($registrations as $registration) {
2156
+				if ($registration instanceof EE_Registration) {
2157
+					$registration_payment_data[$registration->ID()] = array(
2158
+						'paid'  => $registration->pretty_paid(),
2159
+						'owing' => EEH_Template::format_currency($registration->final_price() - $registration->paid()),
2160
+					);
2161
+				}
2162
+			}
2163
+		}
2164
+
2165
+		return $registration_payment_data;
2166
+	}
2167
+
2168
+
2169
+	/**
2170
+	 * _maybe_send_notifications
2171
+	 * determines whether or not the admin has indicated that notifications should be sent.
2172
+	 * If so, will toggle a filter switch for delivering registration notices.
2173
+	 * If passed an EE_Payment object, then it will trigger payment notifications instead.
2174
+	 *
2175
+	 * @access protected
2176
+	 * @param \EE_Payment | null $payment
2177
+	 */
2178
+	protected function _maybe_send_notifications($payment = null)
2179
+	{
2180
+		switch ($payment instanceof EE_Payment) {
2181
+			// payment notifications
2182
+			case true :
2183
+				if (
2184
+					isset(
2185
+						$this->_req_data['txn_payments'],
2186
+						$this->_req_data['txn_payments']['send_notifications']
2187
+					) &&
2188
+					filter_var($this->_req_data['txn_payments']['send_notifications'], FILTER_VALIDATE_BOOLEAN)
2189
+				) {
2190
+					$this->_process_payment_notification($payment);
2191
+				}
2192
+				break;
2193
+			// registration notifications
2194
+			case false :
2195
+				if (
2196
+					isset(
2197
+						$this->_req_data['txn_reg_status_change'],
2198
+						$this->_req_data['txn_reg_status_change']['send_notifications']
2199
+					) &&
2200
+					filter_var($this->_req_data['txn_reg_status_change']['send_notifications'], FILTER_VALIDATE_BOOLEAN)
2201
+				) {
2202
+					add_filter('FHEE__EED_Messages___maybe_registration__deliver_notifications', '__return_true');
2203
+				}
2204
+				break;
2205
+		}
2206
+	}
2207
+
2208
+
2209
+	/**
2210
+	 * _send_payment_reminder
2211
+	 *    generates HTML for the View Transaction Details Admin page
2212
+	 *
2213
+	 * @access protected
2214
+	 * @return void
2215
+	 * @throws EE_Error
2216
+	 * @throws InvalidArgumentException
2217
+	 * @throws InvalidDataTypeException
2218
+	 * @throws InvalidInterfaceException
2219
+	 */
2220
+	protected function _send_payment_reminder()
2221
+	{
2222
+		$TXN_ID      = ! empty($this->_req_data['TXN_ID']) ? absint($this->_req_data['TXN_ID']) : false;
2223
+		$transaction = EEM_Transaction::instance()->get_one_by_ID($TXN_ID);
2224
+		$query_args  = isset($this->_req_data['redirect_to']) ? array(
2225
+			'action' => $this->_req_data['redirect_to'],
2226
+			'TXN_ID' => $this->_req_data['TXN_ID'],
2227
+		) : array();
2228
+		do_action(
2229
+			'AHEE__Transactions_Admin_Page___send_payment_reminder__process_admin_payment_reminder',
2230
+			$transaction
2231
+		);
2232
+		$this->_redirect_after_action(
2233
+			false,
2234
+			esc_html__('payment reminder', 'event_espresso'),
2235
+			esc_html__('sent', 'event_espresso'),
2236
+			$query_args,
2237
+			true
2238
+		);
2239
+	}
2240
+
2241
+
2242
+	/**
2243
+	 *  get_transactions
2244
+	 *    get transactions for given parameters (used by list table)
2245
+	 *
2246
+	 * @param  int     $perpage how many transactions displayed per page
2247
+	 * @param  boolean $count   return the count or objects
2248
+	 * @param string   $view
2249
+	 * @return mixed int = count || array of transaction objects
2250
+	 * @throws EE_Error
2251
+	 * @throws InvalidArgumentException
2252
+	 * @throws InvalidDataTypeException
2253
+	 * @throws InvalidInterfaceException
2254
+	 */
2255
+	public function get_transactions($perpage, $count = false, $view = '')
2256
+	{
2257
+
2258
+		$TXN = EEM_Transaction::instance();
2259
+
2260
+		$start_date = isset($this->_req_data['txn-filter-start-date'])
2261
+			? wp_strip_all_tags($this->_req_data['txn-filter-start-date'])
2262
+			: date(
2263
+				'm/d/Y',
2264
+				strtotime('-10 year')
2265
+			);
2266
+		$end_date   = isset($this->_req_data['txn-filter-end-date'])
2267
+			? wp_strip_all_tags($this->_req_data['txn-filter-end-date'])
2268
+			: date('m/d/Y');
2269
+
2270
+		//make sure our timestamps start and end right at the boundaries for each day
2271
+		$start_date = date('Y-m-d', strtotime($start_date)) . ' 00:00:00';
2272
+		$end_date   = date('Y-m-d', strtotime($end_date)) . ' 23:59:59';
2273
+
2274
+
2275
+		//convert to timestamps
2276
+		$start_date = strtotime($start_date);
2277
+		$end_date   = strtotime($end_date);
2278
+
2279
+		//makes sure start date is the lowest value and vice versa
2280
+		$start_date = min($start_date, $end_date);
2281
+		$end_date   = max($start_date, $end_date);
2282
+
2283
+		//convert to correct format for query
2284
+		$start_date = EEM_Transaction::instance()->convert_datetime_for_query(
2285
+			'TXN_timestamp',
2286
+			date('Y-m-d H:i:s', $start_date),
2287
+			'Y-m-d H:i:s'
2288
+		);
2289
+		$end_date   = EEM_Transaction::instance()->convert_datetime_for_query(
2290
+			'TXN_timestamp',
2291
+			date('Y-m-d H:i:s', $end_date),
2292
+			'Y-m-d H:i:s'
2293
+		);
2294
+
2295
+
2296
+		//set orderby
2297
+		$this->_req_data['orderby'] = ! empty($this->_req_data['orderby']) ? $this->_req_data['orderby'] : '';
2298
+
2299
+		switch ($this->_req_data['orderby']) {
2300
+			case 'TXN_ID':
2301
+				$orderby = 'TXN_ID';
2302
+				break;
2303
+			case 'ATT_fname':
2304
+				$orderby = 'Registration.Attendee.ATT_fname';
2305
+				break;
2306
+			case 'event_name':
2307
+				$orderby = 'Registration.Event.EVT_name';
2308
+				break;
2309
+			default: //'TXN_timestamp'
2310
+				$orderby = 'TXN_timestamp';
2311
+		}
2312
+
2313
+		$sort         = ! empty($this->_req_data['order']) ? $this->_req_data['order'] : 'DESC';
2314
+		$current_page = ! empty($this->_req_data['paged']) ? $this->_req_data['paged'] : 1;
2315
+		$per_page     = ! empty($perpage) ? $perpage : 10;
2316
+		$per_page     = ! empty($this->_req_data['perpage']) ? $this->_req_data['perpage'] : $per_page;
2317
+
2318
+		$offset = ($current_page - 1) * $per_page;
2319
+		$limit  = array($offset, $per_page);
2320
+
2321
+		$_where = array(
2322
+			'TXN_timestamp'          => array('BETWEEN', array($start_date, $end_date)),
2323
+			'Registration.REG_count' => 1,
2324
+		);
2325
+
2326
+		if (isset($this->_req_data['EVT_ID'])) {
2327
+			$_where['Registration.EVT_ID'] = $this->_req_data['EVT_ID'];
2328
+		}
2329
+
2330
+		if (isset($this->_req_data['s'])) {
2331
+			$search_string = '%' . $this->_req_data['s'] . '%';
2332
+			$_where['OR']  = array(
2333
+				'Registration.Event.EVT_name'         => array('LIKE', $search_string),
2334
+				'Registration.Event.EVT_desc'         => array('LIKE', $search_string),
2335
+				'Registration.Event.EVT_short_desc'   => array('LIKE', $search_string),
2336
+				'Registration.Attendee.ATT_full_name' => array('LIKE', $search_string),
2337
+				'Registration.Attendee.ATT_fname'     => array('LIKE', $search_string),
2338
+				'Registration.Attendee.ATT_lname'     => array('LIKE', $search_string),
2339
+				'Registration.Attendee.ATT_short_bio' => array('LIKE', $search_string),
2340
+				'Registration.Attendee.ATT_email'     => array('LIKE', $search_string),
2341
+				'Registration.Attendee.ATT_address'   => array('LIKE', $search_string),
2342
+				'Registration.Attendee.ATT_address2'  => array('LIKE', $search_string),
2343
+				'Registration.Attendee.ATT_city'      => array('LIKE', $search_string),
2344
+				'Registration.REG_final_price'        => array('LIKE', $search_string),
2345
+				'Registration.REG_code'               => array('LIKE', $search_string),
2346
+				'Registration.REG_count'              => array('LIKE', $search_string),
2347
+				'Registration.REG_group_size'         => array('LIKE', $search_string),
2348
+				'Registration.Ticket.TKT_name'        => array('LIKE', $search_string),
2349
+				'Registration.Ticket.TKT_description' => array('LIKE', $search_string),
2350
+				'Payment.PAY_source'                  => array('LIKE', $search_string),
2351
+				'Payment.Payment_Method.PMD_name'     => array('LIKE', $search_string),
2352
+				'TXN_session_data'                    => array('LIKE', $search_string),
2353
+				'Payment.PAY_txn_id_chq_nmbr'         => array('LIKE', $search_string),
2354
+			);
2355
+		}
2356
+
2357
+		//failed transactions
2358
+		$failed    = (! empty($this->_req_data['status']) && $this->_req_data['status'] === 'failed' && ! $count)
2359
+					 || ($count && $view === 'failed');
2360
+		$abandoned = (! empty($this->_req_data['status']) && $this->_req_data['status'] === 'abandoned' && ! $count)
2361
+					 || ($count && $view === 'abandoned');
2362
+
2363
+		if ($failed) {
2364
+			$_where['STS_ID'] = EEM_Transaction::failed_status_code;
2365
+		} else if ($abandoned) {
2366
+			$_where['STS_ID'] = EEM_Transaction::abandoned_status_code;
2367
+		} else {
2368
+			$_where['STS_ID']  = array('!=', EEM_Transaction::failed_status_code);
2369
+			$_where['STS_ID*'] = array('!=', EEM_Transaction::abandoned_status_code);
2370
+		}
2371
+
2372
+		$query_params = array(
2373
+			$_where,
2374
+			'order_by'                 => array($orderby => $sort),
2375
+			'limit'                    => $limit,
2376
+			'default_where_conditions' => EEM_Base::default_where_conditions_this_only,
2377
+		);
2378
+
2379
+		$transactions = $count
2380
+			? $TXN->count(array($_where), 'TXN_ID', true)
2381
+			: $TXN->get_all($query_params);
2382
+
2383
+		return $transactions;
2384
+	}
2385 2385
 }
Please login to merge, or discard this patch.
templates/txn_admin_details_main_meta_box_txn_details.template.php 3 patches
Spacing   +9 added lines, -9 removed lines patch added patch discarded remove patch
@@ -159,7 +159,7 @@  discard block
 block discarded – undo
159 159
                                 <div id="payment-accntng-<?php echo $PAY_ID; ?>"><?php echo $payment->extra_accntng(); ?></div>
160 160
                             </td>
161 161
                             <td class=" jst-rght">
162
-                                <?php $payment_class = $payment->amount() > 0 ? 'txn-admin-payment-status-' . $payment->STS_ID() : 'txn-admin-payment-status-PDC'; ?>
162
+                                <?php $payment_class = $payment->amount() > 0 ? 'txn-admin-payment-status-'.$payment->STS_ID() : 'txn-admin-payment-status-PDC'; ?>
163 163
                                 <span class="<?php echo $payment_class; ?>">
164 164
 							<div id="payment-amount-<?php echo $PAY_ID; ?>"
165 165
                                  style="display:inline;"><?php echo EEH_Template::format_currency($payment->amount(),
@@ -173,8 +173,8 @@  discard block
 block discarded – undo
173 173
                     <?php endforeach; // $payment?>
174 174
                     <?php
175 175
                     $pay_totals_class = $payment_total > $grand_raw_total ? ' important-notice' : '';
176
-                    $overpaid = $payment_total > $grand_raw_total ? '<span id="overpaid">' . esc_html__('This transaction has been overpaid ! ',
177
-                            'event_espresso') . '</span>' : '';
176
+                    $overpaid = $payment_total > $grand_raw_total ? '<span id="overpaid">'.esc_html__('This transaction has been overpaid ! ',
177
+                            'event_espresso').'</span>' : '';
178 178
                     ?>
179 179
                     <tr id="txn-admin-no-payments-tr" class="admin-primary-mbox-total-tr hidden">
180 180
                         <td class=" jst-rght" colspan="11">
@@ -184,9 +184,9 @@  discard block
 block discarded – undo
184 184
                     <tr id="txn-admin-payments-total-tr"
185 185
                         class="admin-primary-mbox-total-tr<?php echo $pay_totals_class; ?>">
186 186
                         <th class=" jst-rght" colspan="10"><span
187
-                                    id="payments-total-spn"><?php echo $overpaid . sprintf(esc_html__('Payments Total %s',
187
+                                    id="payments-total-spn"><?php echo $overpaid.sprintf(esc_html__('Payments Total %s',
188 188
                                         'event_espresso'),
189
-                                        '(' . EE_Registry::instance()->CFG->currency->code . ')'); ?></span></th>
189
+                                        '('.EE_Registry::instance()->CFG->currency->code.')'); ?></span></th>
190 190
                         <th class=" jst-rght"><span
191 191
                                     id="txn-admin-payment-total"><?php echo EEH_Template::format_currency($payment_total,
192 192
                                     false, false); ?></span></th>
@@ -299,7 +299,7 @@  discard block
 block discarded – undo
299 299
             <h2 id="admin-modal-dialog-apply-payment-h2" class="admin-modal-dialog-h2 hdr-has-icon"
300 300
                 style="display:none;">
301 301
                 <div class="ee-icon ee-icon-cash-add float-left"></div>
302
-                <?php echo esc_html__('Apply a Payment to Transaction #', 'event_espresso') . $txn_nmbr['value']; ?>
302
+                <?php echo esc_html__('Apply a Payment to Transaction #', 'event_espresso').$txn_nmbr['value']; ?>
303 303
             </h2>
304 304
 
305 305
             <h2 id="admin-modal-dialog-edit-payment-h2" class="admin-modal-dialog-h2 hdr-has-icon"
@@ -328,7 +328,7 @@  discard block
 block discarded – undo
328 328
             <h2 id="admin-modal-dialog-apply-refund-h2" class="admin-modal-dialog-h2 hdr-has-icon"
329 329
                 style="display:none;">
330 330
                 <div class="ee-icon ee-icon-cash-remove float-left"></div>
331
-                <?php echo esc_html__('Apply a Refund to Transaction #', 'event_espresso') . $txn_nmbr['value']; ?>
331
+                <?php echo esc_html__('Apply a Refund to Transaction #', 'event_espresso').$txn_nmbr['value']; ?>
332 332
             </h2>
333 333
 
334 334
             <form name="txn-admin-apply-payment-frm" id="txn-admin-apply-payment-frm"
@@ -557,7 +557,7 @@  discard block
 block discarded – undo
557 557
                 style="display:none;">
558 558
                 <span class="ee-icon ee-icon-cash-add"></span>
559 559
                 <?php echo esc_html__('Delete Payment/Refund for Transaction #',
560
-                        'event_espresso') . $txn_nmbr['value']; ?>
560
+                        'event_espresso').$txn_nmbr['value']; ?>
561 561
             </h2>
562 562
 
563 563
             <form name="txn-admin-delete-payment-frm" id="txn-admin-delete-payment-frm"
@@ -643,7 +643,7 @@  discard block
 block discarded – undo
643 643
                     <?php foreach ($delivered_messages[$TXN_ID] as $timestamp => $delivered_message) :
644 644
                         ?>
645 645
                         <tr>
646
-                            <td class="jst-left"><?php echo date(get_option('date_format') . ' ' . get_option('time_format'),
646
+                            <td class="jst-left"><?php echo date(get_option('date_format').' '.get_option('time_format'),
647 647
                                     ($timestamp + (get_option('gmt_offset') * HOUR_IN_SECONDS))); ?></td>
648 648
                             <td class="jst-left"><?php echo isset($delivered_message['message_type']) ? $delivered_message['message_type'] : ''; ?></td>
649 649
                             <td class="jst-left"><?php echo isset($delivered_message['pay_status']) ? $delivered_message['pay_status'] : ''; ?></td>
Please login to merge, or discard this patch.
Braces   +10 added lines, -4 removed lines patch added patch discarded remove patch
@@ -191,10 +191,13 @@  discard block
 block discarded – undo
191 191
                                     id="txn-admin-payment-total"><?php echo EEH_Template::format_currency($payment_total,
192 192
                                     false, false); ?></span></th>
193 193
                     </tr>
194
-                <?php else : ?>
194
+                <?php else {
195
+	: ?>
195 196
                     <tr id="txn-admin-no-payments-tr" class="admin-primary-mbox-total-tr">
196 197
                         <td class=" jst-rght" colspan="11">
197
-                            <span class="important-notice"><?php echo $no_payment_text; ?></span>
198
+                            <span class="important-notice"><?php echo $no_payment_text;
199
+}
200
+?></span>
198 201
                         </td>
199 202
                     </tr>
200 203
                     <tr id="txn-admin-payments-total-tr" class="admin-primary-mbox-total-tr hidden">
@@ -285,10 +288,13 @@  discard block
 block discarded – undo
285 288
                         <?php esc_html_e('Apply Refund', 'event_espresso'); ?>
286 289
                     </a>
287 290
                 </li>
288
-            <?php else : ?>
291
+            <?php else {
292
+	: ?>
289 293
                 <li>
290 294
                     <p><?php esc_html__('You do not have access to apply payments or refunds.',
291
-                            'event_espresso'); ?></p>
295
+                            'event_espresso');
296
+}
297
+?></p>
292 298
                 </li>
293 299
             <?php endif; ?>
294 300
         </ul>
Please login to merge, or discard this patch.
Indentation   +81 added lines, -81 removed lines patch added patch discarded remove patch
@@ -12,7 +12,7 @@  discard block
 block discarded – undo
12 12
     <a id="display-additional-transaction-session-info" class="display-the-hidden smaller-text"
13 13
        rel="additional-transaction-session-info">
14 14
         <span class="dashicons dashicons-plus-alt"></span><?php esc_html_e('view additional transaction session details',
15
-            'event_espresso'); ?>
15
+			'event_espresso'); ?>
16 16
     </a>
17 17
 
18 18
     <div id="additional-transaction-session-info-dv" class="hidden">
@@ -20,7 +20,7 @@  discard block
 block discarded – undo
20 20
         <a id="hide-additional-transaction-session-info" class="hide-the-displayed hidden smaller-text"
21 21
            rel="additional-transaction-session-info">
22 22
             <span class="dashicons dashicons-dismiss"></span><?php esc_html_e('hide additional transaction session details',
23
-                'event_espresso'); ?>
23
+				'event_espresso'); ?>
24 24
         </a>
25 25
         <br class="clear"/>
26 26
 
@@ -45,16 +45,16 @@  discard block
 block discarded – undo
45 45
 
46 46
 
47 47
     <?php if ($attendee instanceof EE_Attendee && ($grand_raw_total > 0 || $TXN_status !== EEM_Transaction::complete_status_code || ! empty($payments))) :
48
-        $no_payment_text = $can_edit_payments
49
-            ? esc_html__(
50
-                'No payments have been applied to this transaction yet. Click "Apply Payment" below to make a payment.',
51
-                'event_espresso'
52
-            )
53
-            : esc_html__(
54
-                'No payments have been applied to this transaction yet.',
55
-                'event_espresso'
56
-            );
57
-        ?>
48
+		$no_payment_text = $can_edit_payments
49
+			? esc_html__(
50
+				'No payments have been applied to this transaction yet. Click "Apply Payment" below to make a payment.',
51
+				'event_espresso'
52
+			)
53
+			: esc_html__(
54
+				'No payments have been applied to this transaction yet.',
55
+				'event_espresso'
56
+			);
57
+		?>
58 58
 
59 59
         <h3 class="admin-primary-mbox-h4 hdr-has-icon">
60 60
             <span class="ee-icon ee-icon-cash"></span><?php esc_html_e('Payment Details', 'event_espresso'); ?>
@@ -82,10 +82,10 @@  discard block
 block discarded – undo
82 82
                 <?php if ($payments) : ?>
83 83
                     <?php $payment_total = 0; ?>
84 84
                     <?php foreach ($payments as $PAY_ID => $payment) :
85
-                        $existing_reg_payment_json = isset($existing_reg_payments[$PAY_ID])
86
-                            ? wp_json_encode($existing_reg_payments[$PAY_ID])
87
-                            : '{}';
88
-                        ?>
85
+						$existing_reg_payment_json = isset($existing_reg_payments[$PAY_ID])
86
+							? wp_json_encode($existing_reg_payments[$PAY_ID])
87
+							: '{}';
88
+						?>
89 89
                         <tr id="txn-admin-payment-tr-<?php echo $PAY_ID; ?>">
90 90
                             <td>
91 91
                                 <span id="payment-status-<?php echo $PAY_ID; ?>"
@@ -132,7 +132,7 @@  discard block
 block discarded – undo
132 132
                             <td class=" jst-left">
133 133
                                 <div id="payment-gateway-<?php echo $PAY_ID; ?>">
134 134
                                     <?php echo $payment->payment_method() ? $payment->payment_method()->admin_name() : esc_html__("Unknown",
135
-                                        'event_espresso'); ?>
135
+										'event_espresso'); ?>
136 136
                                 </div>
137 137
                                 <div id="payment-gateway-id-<?php echo $PAY_ID; ?>"
138 138
                                      class="hidden"><?php echo $payment->payment_method() ? $payment->payment_method()->ID() : 0; ?></div>
@@ -154,19 +154,19 @@  discard block
 block discarded – undo
154 154
                                 <span class="<?php echo $payment_class; ?>">
155 155
 							<div id="payment-amount-<?php echo $PAY_ID; ?>"
156 156
                                  style="display:inline;"><?php echo EEH_Template::format_currency($payment->amount(),
157
-                                    false, false); ?></div>
157
+									false, false); ?></div>
158 158
 						</span>
159 159
                             </td>
160 160
                         </tr>
161 161
                         <?php
162
-                        $payment_total += $payment->STS_ID() == 'PAP' ? $payment->amount() : 0;
163
-                        ?>
162
+						$payment_total += $payment->STS_ID() == 'PAP' ? $payment->amount() : 0;
163
+						?>
164 164
                     <?php endforeach; // $payment?>
165 165
                     <?php
166
-                    $pay_totals_class = $payment_total > $grand_raw_total ? ' important-notice' : '';
167
-                    $overpaid = $payment_total > $grand_raw_total ? '<span id="overpaid">' . esc_html__('This transaction has been overpaid ! ',
168
-                            'event_espresso') . '</span>' : '';
169
-                    ?>
166
+					$pay_totals_class = $payment_total > $grand_raw_total ? ' important-notice' : '';
167
+					$overpaid = $payment_total > $grand_raw_total ? '<span id="overpaid">' . esc_html__('This transaction has been overpaid ! ',
168
+							'event_espresso') . '</span>' : '';
169
+					?>
170 170
                     <tr id="txn-admin-no-payments-tr" class="admin-primary-mbox-total-tr hidden">
171 171
                         <td class=" jst-rght" colspan="11">
172 172
                             <span class="important-notice"><?php echo $no_payment_text; ?></span>
@@ -176,11 +176,11 @@  discard block
 block discarded – undo
176 176
                         class="admin-primary-mbox-total-tr<?php echo $pay_totals_class; ?>">
177 177
                         <th class=" jst-rght" colspan="10"><span
178 178
                                     id="payments-total-spn"><?php echo $overpaid . sprintf(esc_html__('Payments Total %s',
179
-                                        'event_espresso'),
180
-                                        '(' . EE_Registry::instance()->CFG->currency->code . ')'); ?></span></th>
179
+										'event_espresso'),
180
+										'(' . EE_Registry::instance()->CFG->currency->code . ')'); ?></span></th>
181 181
                         <th class=" jst-rght"><span
182 182
                                     id="txn-admin-payment-total"><?php echo EEH_Template::format_currency($payment_total,
183
-                                    false, false); ?></span></th>
183
+									false, false); ?></span></th>
184 184
                     </tr>
185 185
                 <?php else : ?>
186 186
                     <tr id="txn-admin-no-payments-tr" class="admin-primary-mbox-total-tr">
@@ -191,11 +191,11 @@  discard block
 block discarded – undo
191 191
                     <tr id="txn-admin-payments-total-tr" class="admin-primary-mbox-total-tr hidden">
192 192
                         <th class=" jst-rght" colspan="10"><span
193 193
                                     id="payments-total-spn"><?php echo esc_html__('Payments Total',
194
-                                    'event_espresso'); ?></span></th>
194
+									'event_espresso'); ?></span></th>
195 195
                         <th class=" jst-rght"><span id="txn-admin-payment-total"></span></th>
196 196
                     </tr>
197 197
                 <?php endif; // $payments
198
-                ?>
198
+				?>
199 199
 
200 200
                 <tr id="txn-admin-payment-empty-row-tr" class="hidden">
201 201
                     <td>
@@ -260,7 +260,7 @@  discard block
 block discarded – undo
260 260
 
261 261
         <ul id="txn-admin-payment-options-ul">
262 262
             <?php if ($can_edit_payments) :
263
-                ?>
263
+				?>
264 264
                 <li>
265 265
                     <a id="display-txn-admin-apply-payment" class="button-primary no-icon no-hide"
266 266
                        rel="txn-admin-apply-payment"> <!--display-the-hidden -->
@@ -276,7 +276,7 @@  discard block
 block discarded – undo
276 276
             <?php else : ?>
277 277
                 <li>
278 278
                     <p><?php esc_html__('You do not have access to apply payments or refunds.',
279
-                            'event_espresso'); ?></p>
279
+							'event_espresso'); ?></p>
280 280
                 </li>
281 281
             <?php endif; ?>
282 282
         </ul>
@@ -294,23 +294,23 @@  discard block
 block discarded – undo
294 294
                 style="display:none;">
295 295
                 <div class="ee-icon ee-icon-cash-edit float-left"></div>
296 296
                 <?php
297
-                echo sprintf(
298
-                    __('Edit Payment #%s for Transaction #%s', 'event_espresso'),
299
-                    '<span></span>',
300
-                    $txn_nmbr['value']
301
-                );
302
-                ?>
297
+				echo sprintf(
298
+					__('Edit Payment #%s for Transaction #%s', 'event_espresso'),
299
+					'<span></span>',
300
+					$txn_nmbr['value']
301
+				);
302
+				?>
303 303
             </h2>
304 304
 
305 305
             <h2 id="admin-modal-dialog-edit-refund-h2" class="admin-modal-dialog-h2 hdr-has-icon" style="display:none;">
306 306
                 <div class="ee-icon ee-icon-cash-edit float-left"></div>
307 307
                 <?php
308
-                echo sprintf(
309
-                    __('Edit Refund #%s for Transaction #%s', 'event_espresso'),
310
-                    '<span></span>',
311
-                    $txn_nmbr['value']
312
-                );
313
-                ?>
308
+				echo sprintf(
309
+					__('Edit Refund #%s for Transaction #%s', 'event_espresso'),
310
+					'<span></span>',
311
+					$txn_nmbr['value']
312
+				);
313
+				?>
314 314
             </h2>
315 315
 
316 316
             <h2 id="admin-modal-dialog-apply-refund-h2" class="admin-modal-dialog-h2 hdr-has-icon"
@@ -343,55 +343,55 @@  discard block
 block discarded – undo
343 343
 
344 344
                         <div class="txn-admin-apply-payment-date-dv admin-modal-dialog-row">
345 345
                             <div class="validation-notice-dv"><?php esc_html_e('The following is  a required field',
346
-                                    'event_espresso'); ?></div>
346
+									'event_espresso'); ?></div>
347 347
                             <label for="txn-admin-payment-date-inp" class=""><?php esc_html_e('Payment Date',
348
-                                    'event_espresso'); ?></label>
348
+									'event_espresso'); ?></label>
349 349
                             <input name="txn_admin_payment[date]" id="txn-admin-payment-date-inp"
350 350
                                    class="txn-admin-apply-payment-inp required" type="text"
351 351
                                    value="<?php echo date('Y-m-d g:i a', current_time('timestamp')); ?>"/>
352 352
                             <p class="description"><?php esc_html_e('The date the payment was actually made on',
353
-                                    'event_espresso'); ?></p>
353
+									'event_espresso'); ?></p>
354 354
                         </div>
355 355
 
356 356
                         <div class="txn-admin-apply-payment-amount-dv admin-modal-dialog-row">
357 357
                             <div class="validation-notice-dv"><?php esc_html_e('The following is  a required field',
358
-                                    'event_espresso'); ?></div>
358
+									'event_espresso'); ?></div>
359 359
                             <label for="txn-admin-payment-amount-inp" class=""><?php esc_html_e('Amount',
360
-                                    'event_espresso'); ?></label>
360
+									'event_espresso'); ?></label>
361 361
                             <input name="txn_admin_payment[amount]" id="txn-admin-payment-amount-inp"
362 362
                                    class="txn-admin-apply-payment-inp required" type="text" value=""/>
363 363
                             <p class="description"><?php esc_html_e('The amount of the payment',
364
-                                    'event_espresso'); ?></p>
364
+									'event_espresso'); ?></p>
365 365
                         </div>
366 366
 
367 367
                         <div class="txn-admin-apply-payment-method-dv admin-modal-dialog-row">
368 368
                             <div class="validation-notice-dv"><?php esc_html_e('The following is  a required field',
369
-                                    'event_espresso'); ?></div>
369
+									'event_espresso'); ?></div>
370 370
                             <label for="txn-admin-payment-method-inp" class=""><?php esc_html_e('Method of Payment',
371
-                                    'event_espresso'); ?></label>
371
+									'event_espresso'); ?></label>
372 372
                             <select name="txn_admin_payment[PMD_ID]" id="txn-admin-payment-method-slct"
373 373
                                     class="txn-admin-apply-payment-slct required" type="text">
374 374
                                 <?php foreach ($payment_methods as $method) : ?>
375 375
                                     <?php $selected = $method->slug() == 'cash' ? ' selected="selected"' : ''; ?>
376 376
                                     <option id="payment-method-opt-<?php echo $method->slug(); ?>"
377 377
                                             value="<?php echo $method->ID(); ?>"<?php echo $selected; ?>><?php echo sanitize_key($method->admin_desc()) ? substr($method->admin_desc(),
378
-                                            0, 128) : $method->admin_name(); ?>&nbsp;&nbsp;
378
+											0, 128) : $method->admin_name(); ?>&nbsp;&nbsp;
379 379
                                     </option>
380 380
                                 <?php endforeach; ?>
381 381
                             </select>
382 382
                             <p class="description"><?php esc_html_e('Whether the payment was made via PayPal, Credit Card, Cheque, or Cash',
383
-                                    'event_espresso'); ?></p>
383
+									'event_espresso'); ?></p>
384 384
                         </div>
385 385
 
386 386
                         <div class="mop-PP mop-CC mop-CHQ mop">
387 387
                             <div class="txn-admin-apply-payment-gw-txn-id-dv admin-modal-dialog-row">
388 388
                                 <label for="txn-admin-payment-txn-id-inp" class=""><?php esc_html_e('TXN ID / CHQ #',
389
-                                        'event_espresso'); ?></label>
389
+										'event_espresso'); ?></label>
390 390
                                 <input name="txn_admin_payment[txn_id_chq_nmbr]"
391 391
                                        id="txn-admin-payment-txn-id-chq-nmbr-inp" class="txn-admin-apply-payment-inp"
392 392
                                        type="text" maxlength="100"/>
393 393
                                 <p class="description"><?php esc_html_e('The Transaction ID sent back from the payment gateway, or the Cheque #',
394
-                                        'event_espresso'); ?></p>
394
+										'event_espresso'); ?></p>
395 395
                             </div>
396 396
                         </div>
397 397
 
@@ -403,14 +403,14 @@  discard block
 block discarded – undo
403 403
                                        id="txn-admin-payment-gateway-response-inp" class="txn-admin-apply-payment-inp"
404 404
                                        type="text"/>
405 405
                                 <p class="description"><?php esc_html_e('The gateway response string (optional)',
406
-                                        'event_espresso'); ?></p>
406
+										'event_espresso'); ?></p>
407 407
                             </div>
408 408
                         </div>
409 409
 
410 410
                         <div class="mop-PP mop-CC mop">
411 411
                             <div class="txn-admin-apply-payment-status-dv admin-modal-dialog-row">
412 412
                                 <label for="txn-admin-payment-status-inp" class=""><?php esc_html_e('Payment Status',
413
-                                        'event_espresso'); ?></label>
413
+										'event_espresso'); ?></label>
414 414
                                 <select name="txn_admin_payment[status]" id="txn-admin-payment-status-slct"
415 415
                                         class="txn-admin-apply-payment-slct" type="text">
416 416
                                     <?php foreach ($payment_status as $STS_ID => $STS_code) : ?>
@@ -422,35 +422,35 @@  discard block
 block discarded – undo
422 422
                                     <?php endforeach; ?>
423 423
                                 </select>
424 424
                                 <p class="description"><?php esc_html_e('Whether the payment was approved, cancelled, declined or failed after submission to the gateway',
425
-                                        'event_espresso'); ?></p>
425
+										'event_espresso'); ?></p>
426 426
                             </div>
427 427
                         </div>
428 428
 
429 429
                         <div class="txn-admin-apply-payment-po-nmbr-dv admin-modal-dialog-row">
430 430
                             <label for="txn-admin-payment-po-nmbr-inp" class=""><?php esc_html_e('P.O. / S.O. #',
431
-                                    'event_espresso'); ?></label>
431
+									'event_espresso'); ?></label>
432 432
                             <input name="txn_admin_payment[po_number]" id="txn-admin-payment-po-nmbr-inp"
433 433
                                    class="txn-admin-apply-payment-inp" type="text" maxlength="100"/>
434 434
                             <p class="description"><?php esc_html_e('The Purchase or Sales Order Number if any (optional)',
435
-                                    'event_espresso'); ?></p>
435
+									'event_espresso'); ?></p>
436 436
                         </div>
437 437
 
438 438
                         <div class="txn-admin-apply-payment-accounting-dv admin-modal-dialog-row">
439 439
                             <label for="txn-admin-payment-accounting-inp"
440 440
                                    class="last"><?php esc_html_e('Notes / Extra Accounting',
441
-                                    'event_espresso'); ?></label>
441
+									'event_espresso'); ?></label>
442 442
                             <input name="txn_admin_payment[accounting]" id="txn-admin-payment-accounting-inp"
443 443
                                    class="txn-admin-apply-payment-inp" type="text" value="<?php echo $REG_code; ?>"
444 444
                                    maxlength="100"/> <input type="hidden" id="txn-admin-reg-code-inp"
445 445
                                                             value="<?php echo $REG_code; ?>"/>
446 446
                             <p class="description"><?php esc_html_e('An extra field you may use for accounting purposes or simple notes. Defaults to the primary registrant\'s registration code.',
447
-                                    'event_espresso'); ?></p>
447
+									'event_espresso'); ?></p>
448 448
                         </div>
449 449
 
450 450
                         <div class="txn-admin-apply-payment-registrations-dv admin-modal-dialog-row">
451 451
                             <label for="txn-admin-payment-registrations-inp"
452 452
                                    class="last"><?php esc_html_e('Registrations to Apply Payment to:',
453
-                                    'event_espresso'); ?></label>
453
+									'event_espresso'); ?></label>
454 454
                             <label class="txn-admin-apply-payment-to-registrations-lbl">
455 455
                                 <input type="radio" value="1" id="txn-admin-apply-payment-to-all-registrations-inp"
456 456
                                        name="txn_admin_payment[apply_to_all_registrations]" checked="checked"/>
@@ -467,10 +467,10 @@  discard block
 block discarded – undo
467 467
                         <div class="txn-admin-payment-reg-status-dv admin-modal-dialog-row">
468 468
                             <label for="txn-admin-payment-reg-status-inp"
469 469
                                    class="last"><?php esc_html_e('Change Registration Status?',
470
-                                    'event_espresso'); ?></label>
470
+									'event_espresso'); ?></label>
471 471
                             <?php echo $status_change_select; ?>
472 472
                             <p class="description"><?php esc_html_e('If you wish to change the status for the registrations selected above, then select which status from this dropdown.',
473
-                                    'event_espresso'); ?></p>
473
+									'event_espresso'); ?></p>
474 474
                             <br/>
475 475
                         </div>
476 476
 
@@ -490,7 +490,7 @@  discard block
 block discarded – undo
490 490
                             </label>
491 491
                             <br class="clear-float"/>
492 492
                             <p class="description"><?php printf(esc_html__('By default %1$sa payment message is sent to the primary registrant%2$s after submitting this form.%3$sHowever, if you check the "Registration Messages" box, the system will also send any related messages matching the status of the registrations to %1$seach registration for this transaction%2$s.',
493
-                                    'event_espresso'), '<strong>', '</strong>', '<br />'); ?></p>
493
+									'event_espresso'), '<strong>', '</strong>', '<br />'); ?></p>
494 494
                             <label></label>
495 495
                         </div>
496 496
                         <div class="clear"></div>
@@ -530,7 +530,7 @@  discard block
 block discarded – undo
530 530
                     </li>
531 531
                     <li>
532 532
                         <span id="ee-ajax-processing-text" style="display:none;"><?php esc_html_e('Processing...',
533
-                                'event_espresso'); ?></span>
533
+								'event_espresso'); ?></span>
534 534
                     </li>
535 535
                 </ul>
536 536
 
@@ -545,7 +545,7 @@  discard block
 block discarded – undo
545 545
                 style="display:none;">
546 546
                 <span class="ee-icon ee-icon-cash-add"></span>
547 547
                 <?php echo esc_html__('Delete Payment/Refund for Transaction #',
548
-                        'event_espresso') . $txn_nmbr['value']; ?>
548
+						'event_espresso') . $txn_nmbr['value']; ?>
549 549
             </h2>
550 550
 
551 551
             <form name="txn-admin-delete-payment-frm" id="txn-admin-delete-payment-frm"
@@ -566,10 +566,10 @@  discard block
 block discarded – undo
566 566
                         <div class="txn-admin-apply-payment-accounting-dv admin-modal-dialog-row">
567 567
                             <label for="delete-txn-admin-payment-reg-status-inp"
568 568
                                    class="last"><?php esc_html_e('Change Registration Status?',
569
-                                    'event_espresso'); ?></label>
569
+									'event_espresso'); ?></label>
570 570
                             <?php echo $delete_status_change_select; ?>
571 571
                             <p class="description"><?php printf(esc_html__('If you wish to change the status of all the registrations associated with this transaction after deleting this payment/refund, then select which status from this dropdown. %sNote: ALL registrations associated with this transaction will be updated to this new status.%s',
572
-                                    'event_espresso'), '<strong>', '</strong>'); ?></p>
572
+									'event_espresso'), '<strong>', '</strong>'); ?></p>
573 573
                         </div>
574 574
 
575 575
                         <div class="ee-attention txn-admin-apply-payment-accounting-dv admin-modal-dialog-row">
@@ -577,7 +577,7 @@  discard block
 block discarded – undo
577 577
                                    class="last"><?php esc_html_e('Send Related Messages?', 'event_espresso'); ?></label>
578 578
                             <input type="checkbox" value="1" name="delete_txn_reg_status_change[send_notifications]">
579 579
                             <p class="description"><?php esc_html_e('If you check this box, the system will send any related registration messages matching the status of the registrations to each registration for this transaction. No Payment notifications are sent when deleting a payment.',
580
-                                    'event_espresso'); ?></p>
580
+									'event_espresso'); ?></p>
581 581
                         </div>
582 582
                         <div class="clear"></div>
583 583
 
@@ -609,13 +609,13 @@  discard block
 block discarded – undo
609 609
     <?php endif; // $grand_raw_total > 0?>
610 610
 
611 611
     <?php
612
-    if (WP_DEBUG) {
613
-        $delivered_messages = get_option('EED_Messages__payment', array());
614
-        if (isset($delivered_messages[$TXN_ID])) {
615
-            ?>
612
+	if (WP_DEBUG) {
613
+		$delivered_messages = get_option('EED_Messages__payment', array());
614
+		if (isset($delivered_messages[$TXN_ID])) {
615
+			?>
616 616
             <h4 class="admin-primary-mbox-h4 hdr-has-icon"><span
617 617
                         class="dashicons dashicons-email-alt"></span><?php esc_html_e('Messages Sent to Primary Registrant',
618
-                    'event_espresso'); ?></h4>
618
+					'event_espresso'); ?></h4>
619 619
 
620 620
             <div class="admin-primary-mbox-tbl-wrap">
621 621
                 <table class="admin-primary-mbox-tbl">
@@ -629,10 +629,10 @@  discard block
 block discarded – undo
629 629
                     </thead>
630 630
                     <tbody>
631 631
                     <?php foreach ($delivered_messages[$TXN_ID] as $timestamp => $delivered_message) :
632
-                        ?>
632
+						?>
633 633
                         <tr>
634 634
                             <td class="jst-left"><?php echo date(get_option('date_format') . ' ' . get_option('time_format'),
635
-                                    ($timestamp + (get_option('gmt_offset') * HOUR_IN_SECONDS))); ?></td>
635
+									($timestamp + (get_option('gmt_offset') * HOUR_IN_SECONDS))); ?></td>
636 636
                             <td class="jst-left"><?php echo isset($delivered_message['message_type']) ? $delivered_message['message_type'] : ''; ?></td>
637 637
                             <td class="jst-left"><?php echo isset($delivered_message['pay_status']) ? $delivered_message['pay_status'] : ''; ?></td>
638 638
                             <td class="jst-left"><?php echo isset($delivered_message['txn_status']) ? $delivered_message['txn_status'] : ''; ?></td>
@@ -642,9 +642,9 @@  discard block
 block discarded – undo
642 642
                 </table>
643 643
             </div>
644 644
             <?php
645
-        }
646
-    }
647
-    ?>
645
+		}
646
+	}
647
+	?>
648 648
 
649 649
 
650 650
 </div>
Please login to merge, or discard this patch.
admin_pages/registrations/EE_Attendee_Contact_List_Table.class.php 3 patches
Doc Comments   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -303,7 +303,7 @@  discard block
 block discarded – undo
303 303
      * ATT_address column
304 304
      *
305 305
      * @param EE_Attendee $attendee
306
-     * @return mixed
306
+     * @return string
307 307
      * @throws EE_Error
308 308
      */
309 309
     public function column_ATT_address(EE_Attendee $attendee)
@@ -316,7 +316,7 @@  discard block
 block discarded – undo
316 316
      * ATT_city column
317 317
      *
318 318
      * @param EE_Attendee $attendee
319
-     * @return mixed
319
+     * @return string
320 320
      * @throws EE_Error
321 321
      */
322 322
     public function column_ATT_city(EE_Attendee $attendee)
@@ -369,7 +369,7 @@  discard block
 block discarded – undo
369 369
      * Phone Number column
370 370
      *
371 371
      * @param EE_Attendee $attendee
372
-     * @return mixed
372
+     * @return string
373 373
      * @throws EE_Error
374 374
      */
375 375
     public function column_ATT_phone(EE_Attendee $attendee)
Please login to merge, or discard this patch.
Indentation   +361 added lines, -361 removed lines patch added patch discarded remove patch
@@ -15,365 +15,365 @@
 block discarded – undo
15 15
  */
16 16
 class EE_Attendee_Contact_List_Table extends EE_Admin_List_Table
17 17
 {
18
-    /**
19
-     * Initial setup of data (called by parent).
20
-     */
21
-    protected function _setup_data()
22
-    {
23
-        $this->_data = $this->_view !== 'trash'
24
-            ? $this->_admin_page->get_attendees($this->_per_page)
25
-            : $this->_admin_page->get_attendees($this->_per_page, false, true);
26
-        $this->_all_data_count = $this->_view !== 'trash'
27
-            ? $this->_admin_page->get_attendees($this->_per_page, true)
28
-            : $this->_admin_page->get_attendees($this->_per_page, true, true);
29
-    }
30
-
31
-
32
-    /**
33
-     * Initial setup of properties.
34
-     */
35
-    protected function _set_properties()
36
-    {
37
-        $this->_wp_list_args = array(
38
-            'singular' => esc_html__('attendee', 'event_espresso'),
39
-            'plural'   => esc_html__('attendees', 'event_espresso'),
40
-            'ajax'     => true,
41
-            'screen'   => $this->_admin_page->get_current_screen()->id,
42
-        );
43
-
44
-        $this->_columns = array(
45
-            'cb'          => '<input type="checkbox" />', //Render a checkbox instead of text
46
-            'ATT_ID'      => esc_html__('ID', 'event_espresso'),
47
-            'ATT_fname'   => esc_html__('First Name', 'event_espresso'),
48
-            'ATT_lname'   => esc_html__('Last Name', 'event_espresso'),
49
-            'ATT_email'   => esc_html__('Email Address', 'event_espresso'),
50
-            'Registration_Count' => esc_html__('# Registrations', 'event_espresso'),
51
-            'ATT_phone'   => esc_html__('Phone', 'event_espresso'),
52
-            'ATT_address' => esc_html__('Address', 'event_espresso'),
53
-            'ATT_city'    => esc_html__('City', 'event_espresso'),
54
-            'STA_ID'      => esc_html__('State/Province', 'event_espresso'),
55
-            'CNT_ISO'     => esc_html__('Country', 'event_espresso'),
56
-        );
57
-
58
-        $this->_sortable_columns = array(
59
-            'ATT_ID'    => array('ATT_ID' => false),
60
-            'ATT_lname' => array('ATT_lname' => true), //true means its already sorted
61
-            'ATT_fname' => array('ATT_fname' => false),
62
-            'ATT_email' => array('ATT_email' => false),
63
-            'Registration_Count' => array('Registration_Count' => false),
64
-            'ATT_city'  => array('ATT_city' => false),
65
-            'STA_ID'    => array('STA_ID' => false),
66
-            'CNT_ISO'   => array('CNT_ISO' => false),
67
-        );
68
-
69
-        $this->_hidden_columns = array(
70
-            'ATT_phone',
71
-            'ATT_address',
72
-            'ATT_city',
73
-            'STA_ID',
74
-            'CNT_ISO'
75
-        );
76
-    }
77
-
78
-
79
-    /**
80
-     * Initial setup of filters
81
-     * @return array
82
-     */
83
-    protected function _get_table_filters()
84
-    {
85
-        return array();
86
-    }
87
-
88
-
89
-    /**
90
-     * Initial setup of counts for views
91
-     * @throws InvalidArgumentException
92
-     * @throws InvalidDataTypeException
93
-     * @throws InvalidInterfaceException
94
-     */
95
-    protected function _add_view_counts()
96
-    {
97
-        $this->_views['in_use']['count'] = $this->_admin_page->get_attendees($this->_per_page, true);
98
-        if (EE_Registry::instance()->CAP->current_user_can(
99
-            'ee_delete_contacts',
100
-            'espresso_registrations_delete_registration'
101
-        )) {
102
-            $this->_views['trash']['count'] = $this->_admin_page->get_attendees($this->_per_page, true, true);
103
-        }
104
-    }
105
-
106
-
107
-    /**
108
-     * Get count of attendees.
109
-     * @return int
110
-     * @throws EE_Error
111
-     * @throws InvalidArgumentException
112
-     * @throws InvalidDataTypeException
113
-     * @throws InvalidInterfaceException
114
-     */
115
-    protected function _get_attendees_count()
116
-    {
117
-        return EEM_Attendee::instance()->count();
118
-    }
119
-
120
-
121
-    /**
122
-     * Checkbox column
123
-     *
124
-     * @param EE_Attendee $attendee  Unable to typehint this method because overrides parent.
125
-     * @return string
126
-     * @throws EE_Error
127
-     */
128
-    public function column_cb($attendee)
129
-    {
130
-        if (! $attendee instanceof EE_Attendee) {
131
-            return '';
132
-        }
133
-        return sprintf(
134
-            '<input type="checkbox" name="checkbox[%1$s]" value="%1$s" />',
135
-            $attendee->ID()
136
-        );
137
-    }
138
-
139
-
140
-    /**
141
-     * ATT_ID column
142
-     *
143
-     * @param EE_Attendee $attendee
144
-     * @return string
145
-     * @throws EE_Error
146
-     */
147
-    public function column_ATT_ID(EE_Attendee $attendee)
148
-    {
149
-        $content = $attendee->ID();
150
-        $attendee_name = $attendee instanceof EE_Attendee ? $attendee->full_name() : '';
151
-        $content .= '  <span class="show-on-mobile-view-only">' . $attendee_name . '</span>';
152
-        return $content;
153
-    }
154
-
155
-
156
-    /**
157
-     * ATT_lname column
158
-     *
159
-     * @param EE_Attendee $attendee
160
-     * @return string
161
-     * @throws InvalidArgumentException
162
-     * @throws InvalidDataTypeException
163
-     * @throws InvalidInterfaceException
164
-     * @throws EE_Error
165
-     */
166
-    public function column_ATT_lname(EE_Attendee $attendee)
167
-    {
168
-        // edit attendee link
169
-        $edit_lnk_url = EE_Admin_Page::add_query_args_and_nonce(
170
-            array(
171
-                'action' => 'edit_attendee',
172
-                'post'   => $attendee->ID(),
173
-            ),
174
-            REG_ADMIN_URL
175
-        );
176
-        $name_link = EE_Registry::instance()->CAP->current_user_can(
177
-            'ee_edit_contacts',
178
-            'espresso_registrations_edit_attendee'
179
-        )
180
-            ? '<a href="' . $edit_lnk_url . '" title="'
181
-              . esc_attr__('Edit Contact', 'event_espresso') . '">'
182
-              . $attendee->lname() . '</a>'
183
-            : $attendee->lname();
184
-        return $name_link;
185
-    }
186
-
187
-
188
-    /**
189
-     * ATT_fname column
190
-     *
191
-     * @param EE_Attendee $attendee
192
-     * @return string
193
-     * @throws InvalidArgumentException
194
-     * @throws InvalidDataTypeException
195
-     * @throws InvalidInterfaceException
196
-     * @throws EE_Error
197
-     */
198
-    public function column_ATT_fname(EE_Attendee $attendee)
199
-    {
200
-        //Build row actions
201
-        $actions = array();
202
-        // edit attendee link
203
-        if (EE_Registry::instance()->CAP->current_user_can(
204
-            'ee_edit_contacts',
205
-            'espresso_registrations_edit_attendee'
206
-        )) {
207
-            $edit_lnk_url = EE_Admin_Page::add_query_args_and_nonce(
208
-                array(
209
-                    'action' => 'edit_attendee',
210
-                    'post'   => $attendee->ID(),
211
-                ),
212
-                REG_ADMIN_URL
213
-            );
214
-            $actions['edit'] = '<a href="' . $edit_lnk_url . '" title="'
215
-                               . esc_attr__('Edit Contact', 'event_espresso') . '">'
216
-                               . esc_html__('Edit', 'event_espresso') . '</a>';
217
-        }
218
-
219
-        if ($this->_view === 'in_use') {
220
-            // trash attendee link
221
-            if (EE_Registry::instance()->CAP->current_user_can(
222
-                'ee_delete_contacts',
223
-                'espresso_registrations_trash_attendees'
224
-            )) {
225
-                $trash_lnk_url = EE_Admin_Page::add_query_args_and_nonce(
226
-                    array(
227
-                        'action' => 'trash_attendee',
228
-                        'ATT_ID' => $attendee->ID(),
229
-                    ),
230
-                    REG_ADMIN_URL
231
-                );
232
-                $actions['trash'] = '<a href="' . $trash_lnk_url . '" title="'
233
-                                    . esc_attr__('Move Contact to Trash', 'event_espresso')
234
-                                    . '">' . esc_html__('Trash', 'event_espresso') . '</a>';
235
-            }
236
-        } else {
237
-            if (EE_Registry::instance()->CAP->current_user_can(
238
-                'ee_delete_contacts',
239
-                'espresso_registrations_restore_attendees'
240
-            )) {
241
-                // restore attendee link
242
-                $restore_lnk_url = EE_Admin_Page::add_query_args_and_nonce(array(
243
-                    'action' => 'restore_attendees',
244
-                    'ATT_ID' => $attendee->ID(),
245
-                ), REG_ADMIN_URL);
246
-                $actions['restore'] = '<a href="' . $restore_lnk_url . '" title="'
247
-                                      . esc_attr__('Restore Contact', 'event_espresso') . '">'
248
-                                      . esc_html__('Restore', 'event_espresso') . '</a>';
249
-            }
250
-        }
251
-
252
-        $edit_lnk_url = EE_Admin_Page::add_query_args_and_nonce(array(
253
-            'action' => 'edit_attendee',
254
-            'post'   => $attendee->ID(),
255
-        ), REG_ADMIN_URL);
256
-        $name_link = EE_Registry::instance()->CAP->current_user_can(
257
-            'ee_edit_contacts',
258
-            'espresso_registrations_edit_attendee'
259
-        )
260
-            ? '<a href="' . $edit_lnk_url . '" title="'
261
-              . esc_attr__('Edit Contact', 'event_espresso') . '">' . $attendee->fname() . '</a>'
262
-            : $attendee->fname();
263
-
264
-        //Return the name contents
265
-        return sprintf('%1$s %2$s', $name_link, $this->row_actions($actions));
266
-    }
267
-
268
-
269
-    /**
270
-     * Email Column
271
-     *
272
-     * @param EE_Attendee $attendee
273
-     * @return string
274
-     * @throws EE_Error
275
-     */
276
-    public function column_ATT_email(EE_Attendee $attendee)
277
-    {
278
-        return '<a href="mailto:' . $attendee->email() . '">' . $attendee->email() . '</a>';
279
-    }
280
-
281
-
282
-    /**
283
-     * Column displaying count of registrations attached to Attendee.
284
-     *
285
-     * @param EE_Attendee $attendee
286
-     * @return string
287
-     * @throws EE_Error
288
-     */
289
-    public function column_Registration_Count(EE_Attendee $attendee)
290
-    {
291
-        $link = EEH_URL::add_query_args_and_nonce(
292
-            array(
293
-                'action' => 'default',
294
-                'ATT_ID' => $attendee->ID()
295
-            ),
296
-            REG_ADMIN_URL
297
-        );
298
-        return '<a href="' . $link . '">' . $attendee->getCustomSelect('Registration_Count') . '</a>';
299
-    }
300
-
301
-
302
-    /**
303
-     * ATT_address column
304
-     *
305
-     * @param EE_Attendee $attendee
306
-     * @return mixed
307
-     * @throws EE_Error
308
-     */
309
-    public function column_ATT_address(EE_Attendee $attendee)
310
-    {
311
-        return $attendee->address();
312
-    }
313
-
314
-
315
-    /**
316
-     * ATT_city column
317
-     *
318
-     * @param EE_Attendee $attendee
319
-     * @return mixed
320
-     * @throws EE_Error
321
-     */
322
-    public function column_ATT_city(EE_Attendee $attendee)
323
-    {
324
-        return $attendee->city();
325
-    }
326
-
327
-
328
-    /**
329
-     * State Column
330
-     *
331
-     * @param EE_Attendee $attendee
332
-     * @return string
333
-     * @throws EE_Error
334
-     * @throws InvalidArgumentException
335
-     * @throws InvalidDataTypeException
336
-     * @throws InvalidInterfaceException
337
-     */
338
-    public function column_STA_ID(EE_Attendee $attendee)
339
-    {
340
-        $states = EEM_State::instance()->get_all_states();
341
-        $state = isset($states[$attendee->state_ID()])
342
-            ? $states[$attendee->state_ID()]->get('STA_name')
343
-            : $attendee->state_ID();
344
-        return ! is_numeric($state) ? $state : '';
345
-    }
346
-
347
-
348
-    /**
349
-     * Country Column
350
-     *
351
-     * @param EE_Attendee $attendee
352
-     * @return string
353
-     * @throws EE_Error
354
-     * @throws InvalidArgumentException
355
-     * @throws InvalidDataTypeException
356
-     * @throws InvalidInterfaceException
357
-     */
358
-    public function column_CNT_ISO(EE_Attendee $attendee)
359
-    {
360
-        $countries = EEM_Country::instance()->get_all_countries();
361
-        $country = isset($countries[$attendee->country_ID()])
362
-            ? $countries[$attendee->country_ID()]->get('CNT_name')
363
-            : $attendee->country_ID();
364
-        return ! is_numeric($country) ? $country : '';
365
-    }
366
-
367
-
368
-    /**
369
-     * Phone Number column
370
-     *
371
-     * @param EE_Attendee $attendee
372
-     * @return mixed
373
-     * @throws EE_Error
374
-     */
375
-    public function column_ATT_phone(EE_Attendee $attendee)
376
-    {
377
-        return $attendee->phone();
378
-    }
18
+	/**
19
+	 * Initial setup of data (called by parent).
20
+	 */
21
+	protected function _setup_data()
22
+	{
23
+		$this->_data = $this->_view !== 'trash'
24
+			? $this->_admin_page->get_attendees($this->_per_page)
25
+			: $this->_admin_page->get_attendees($this->_per_page, false, true);
26
+		$this->_all_data_count = $this->_view !== 'trash'
27
+			? $this->_admin_page->get_attendees($this->_per_page, true)
28
+			: $this->_admin_page->get_attendees($this->_per_page, true, true);
29
+	}
30
+
31
+
32
+	/**
33
+	 * Initial setup of properties.
34
+	 */
35
+	protected function _set_properties()
36
+	{
37
+		$this->_wp_list_args = array(
38
+			'singular' => esc_html__('attendee', 'event_espresso'),
39
+			'plural'   => esc_html__('attendees', 'event_espresso'),
40
+			'ajax'     => true,
41
+			'screen'   => $this->_admin_page->get_current_screen()->id,
42
+		);
43
+
44
+		$this->_columns = array(
45
+			'cb'          => '<input type="checkbox" />', //Render a checkbox instead of text
46
+			'ATT_ID'      => esc_html__('ID', 'event_espresso'),
47
+			'ATT_fname'   => esc_html__('First Name', 'event_espresso'),
48
+			'ATT_lname'   => esc_html__('Last Name', 'event_espresso'),
49
+			'ATT_email'   => esc_html__('Email Address', 'event_espresso'),
50
+			'Registration_Count' => esc_html__('# Registrations', 'event_espresso'),
51
+			'ATT_phone'   => esc_html__('Phone', 'event_espresso'),
52
+			'ATT_address' => esc_html__('Address', 'event_espresso'),
53
+			'ATT_city'    => esc_html__('City', 'event_espresso'),
54
+			'STA_ID'      => esc_html__('State/Province', 'event_espresso'),
55
+			'CNT_ISO'     => esc_html__('Country', 'event_espresso'),
56
+		);
57
+
58
+		$this->_sortable_columns = array(
59
+			'ATT_ID'    => array('ATT_ID' => false),
60
+			'ATT_lname' => array('ATT_lname' => true), //true means its already sorted
61
+			'ATT_fname' => array('ATT_fname' => false),
62
+			'ATT_email' => array('ATT_email' => false),
63
+			'Registration_Count' => array('Registration_Count' => false),
64
+			'ATT_city'  => array('ATT_city' => false),
65
+			'STA_ID'    => array('STA_ID' => false),
66
+			'CNT_ISO'   => array('CNT_ISO' => false),
67
+		);
68
+
69
+		$this->_hidden_columns = array(
70
+			'ATT_phone',
71
+			'ATT_address',
72
+			'ATT_city',
73
+			'STA_ID',
74
+			'CNT_ISO'
75
+		);
76
+	}
77
+
78
+
79
+	/**
80
+	 * Initial setup of filters
81
+	 * @return array
82
+	 */
83
+	protected function _get_table_filters()
84
+	{
85
+		return array();
86
+	}
87
+
88
+
89
+	/**
90
+	 * Initial setup of counts for views
91
+	 * @throws InvalidArgumentException
92
+	 * @throws InvalidDataTypeException
93
+	 * @throws InvalidInterfaceException
94
+	 */
95
+	protected function _add_view_counts()
96
+	{
97
+		$this->_views['in_use']['count'] = $this->_admin_page->get_attendees($this->_per_page, true);
98
+		if (EE_Registry::instance()->CAP->current_user_can(
99
+			'ee_delete_contacts',
100
+			'espresso_registrations_delete_registration'
101
+		)) {
102
+			$this->_views['trash']['count'] = $this->_admin_page->get_attendees($this->_per_page, true, true);
103
+		}
104
+	}
105
+
106
+
107
+	/**
108
+	 * Get count of attendees.
109
+	 * @return int
110
+	 * @throws EE_Error
111
+	 * @throws InvalidArgumentException
112
+	 * @throws InvalidDataTypeException
113
+	 * @throws InvalidInterfaceException
114
+	 */
115
+	protected function _get_attendees_count()
116
+	{
117
+		return EEM_Attendee::instance()->count();
118
+	}
119
+
120
+
121
+	/**
122
+	 * Checkbox column
123
+	 *
124
+	 * @param EE_Attendee $attendee  Unable to typehint this method because overrides parent.
125
+	 * @return string
126
+	 * @throws EE_Error
127
+	 */
128
+	public function column_cb($attendee)
129
+	{
130
+		if (! $attendee instanceof EE_Attendee) {
131
+			return '';
132
+		}
133
+		return sprintf(
134
+			'<input type="checkbox" name="checkbox[%1$s]" value="%1$s" />',
135
+			$attendee->ID()
136
+		);
137
+	}
138
+
139
+
140
+	/**
141
+	 * ATT_ID column
142
+	 *
143
+	 * @param EE_Attendee $attendee
144
+	 * @return string
145
+	 * @throws EE_Error
146
+	 */
147
+	public function column_ATT_ID(EE_Attendee $attendee)
148
+	{
149
+		$content = $attendee->ID();
150
+		$attendee_name = $attendee instanceof EE_Attendee ? $attendee->full_name() : '';
151
+		$content .= '  <span class="show-on-mobile-view-only">' . $attendee_name . '</span>';
152
+		return $content;
153
+	}
154
+
155
+
156
+	/**
157
+	 * ATT_lname column
158
+	 *
159
+	 * @param EE_Attendee $attendee
160
+	 * @return string
161
+	 * @throws InvalidArgumentException
162
+	 * @throws InvalidDataTypeException
163
+	 * @throws InvalidInterfaceException
164
+	 * @throws EE_Error
165
+	 */
166
+	public function column_ATT_lname(EE_Attendee $attendee)
167
+	{
168
+		// edit attendee link
169
+		$edit_lnk_url = EE_Admin_Page::add_query_args_and_nonce(
170
+			array(
171
+				'action' => 'edit_attendee',
172
+				'post'   => $attendee->ID(),
173
+			),
174
+			REG_ADMIN_URL
175
+		);
176
+		$name_link = EE_Registry::instance()->CAP->current_user_can(
177
+			'ee_edit_contacts',
178
+			'espresso_registrations_edit_attendee'
179
+		)
180
+			? '<a href="' . $edit_lnk_url . '" title="'
181
+			  . esc_attr__('Edit Contact', 'event_espresso') . '">'
182
+			  . $attendee->lname() . '</a>'
183
+			: $attendee->lname();
184
+		return $name_link;
185
+	}
186
+
187
+
188
+	/**
189
+	 * ATT_fname column
190
+	 *
191
+	 * @param EE_Attendee $attendee
192
+	 * @return string
193
+	 * @throws InvalidArgumentException
194
+	 * @throws InvalidDataTypeException
195
+	 * @throws InvalidInterfaceException
196
+	 * @throws EE_Error
197
+	 */
198
+	public function column_ATT_fname(EE_Attendee $attendee)
199
+	{
200
+		//Build row actions
201
+		$actions = array();
202
+		// edit attendee link
203
+		if (EE_Registry::instance()->CAP->current_user_can(
204
+			'ee_edit_contacts',
205
+			'espresso_registrations_edit_attendee'
206
+		)) {
207
+			$edit_lnk_url = EE_Admin_Page::add_query_args_and_nonce(
208
+				array(
209
+					'action' => 'edit_attendee',
210
+					'post'   => $attendee->ID(),
211
+				),
212
+				REG_ADMIN_URL
213
+			);
214
+			$actions['edit'] = '<a href="' . $edit_lnk_url . '" title="'
215
+							   . esc_attr__('Edit Contact', 'event_espresso') . '">'
216
+							   . esc_html__('Edit', 'event_espresso') . '</a>';
217
+		}
218
+
219
+		if ($this->_view === 'in_use') {
220
+			// trash attendee link
221
+			if (EE_Registry::instance()->CAP->current_user_can(
222
+				'ee_delete_contacts',
223
+				'espresso_registrations_trash_attendees'
224
+			)) {
225
+				$trash_lnk_url = EE_Admin_Page::add_query_args_and_nonce(
226
+					array(
227
+						'action' => 'trash_attendee',
228
+						'ATT_ID' => $attendee->ID(),
229
+					),
230
+					REG_ADMIN_URL
231
+				);
232
+				$actions['trash'] = '<a href="' . $trash_lnk_url . '" title="'
233
+									. esc_attr__('Move Contact to Trash', 'event_espresso')
234
+									. '">' . esc_html__('Trash', 'event_espresso') . '</a>';
235
+			}
236
+		} else {
237
+			if (EE_Registry::instance()->CAP->current_user_can(
238
+				'ee_delete_contacts',
239
+				'espresso_registrations_restore_attendees'
240
+			)) {
241
+				// restore attendee link
242
+				$restore_lnk_url = EE_Admin_Page::add_query_args_and_nonce(array(
243
+					'action' => 'restore_attendees',
244
+					'ATT_ID' => $attendee->ID(),
245
+				), REG_ADMIN_URL);
246
+				$actions['restore'] = '<a href="' . $restore_lnk_url . '" title="'
247
+									  . esc_attr__('Restore Contact', 'event_espresso') . '">'
248
+									  . esc_html__('Restore', 'event_espresso') . '</a>';
249
+			}
250
+		}
251
+
252
+		$edit_lnk_url = EE_Admin_Page::add_query_args_and_nonce(array(
253
+			'action' => 'edit_attendee',
254
+			'post'   => $attendee->ID(),
255
+		), REG_ADMIN_URL);
256
+		$name_link = EE_Registry::instance()->CAP->current_user_can(
257
+			'ee_edit_contacts',
258
+			'espresso_registrations_edit_attendee'
259
+		)
260
+			? '<a href="' . $edit_lnk_url . '" title="'
261
+			  . esc_attr__('Edit Contact', 'event_espresso') . '">' . $attendee->fname() . '</a>'
262
+			: $attendee->fname();
263
+
264
+		//Return the name contents
265
+		return sprintf('%1$s %2$s', $name_link, $this->row_actions($actions));
266
+	}
267
+
268
+
269
+	/**
270
+	 * Email Column
271
+	 *
272
+	 * @param EE_Attendee $attendee
273
+	 * @return string
274
+	 * @throws EE_Error
275
+	 */
276
+	public function column_ATT_email(EE_Attendee $attendee)
277
+	{
278
+		return '<a href="mailto:' . $attendee->email() . '">' . $attendee->email() . '</a>';
279
+	}
280
+
281
+
282
+	/**
283
+	 * Column displaying count of registrations attached to Attendee.
284
+	 *
285
+	 * @param EE_Attendee $attendee
286
+	 * @return string
287
+	 * @throws EE_Error
288
+	 */
289
+	public function column_Registration_Count(EE_Attendee $attendee)
290
+	{
291
+		$link = EEH_URL::add_query_args_and_nonce(
292
+			array(
293
+				'action' => 'default',
294
+				'ATT_ID' => $attendee->ID()
295
+			),
296
+			REG_ADMIN_URL
297
+		);
298
+		return '<a href="' . $link . '">' . $attendee->getCustomSelect('Registration_Count') . '</a>';
299
+	}
300
+
301
+
302
+	/**
303
+	 * ATT_address column
304
+	 *
305
+	 * @param EE_Attendee $attendee
306
+	 * @return mixed
307
+	 * @throws EE_Error
308
+	 */
309
+	public function column_ATT_address(EE_Attendee $attendee)
310
+	{
311
+		return $attendee->address();
312
+	}
313
+
314
+
315
+	/**
316
+	 * ATT_city column
317
+	 *
318
+	 * @param EE_Attendee $attendee
319
+	 * @return mixed
320
+	 * @throws EE_Error
321
+	 */
322
+	public function column_ATT_city(EE_Attendee $attendee)
323
+	{
324
+		return $attendee->city();
325
+	}
326
+
327
+
328
+	/**
329
+	 * State Column
330
+	 *
331
+	 * @param EE_Attendee $attendee
332
+	 * @return string
333
+	 * @throws EE_Error
334
+	 * @throws InvalidArgumentException
335
+	 * @throws InvalidDataTypeException
336
+	 * @throws InvalidInterfaceException
337
+	 */
338
+	public function column_STA_ID(EE_Attendee $attendee)
339
+	{
340
+		$states = EEM_State::instance()->get_all_states();
341
+		$state = isset($states[$attendee->state_ID()])
342
+			? $states[$attendee->state_ID()]->get('STA_name')
343
+			: $attendee->state_ID();
344
+		return ! is_numeric($state) ? $state : '';
345
+	}
346
+
347
+
348
+	/**
349
+	 * Country Column
350
+	 *
351
+	 * @param EE_Attendee $attendee
352
+	 * @return string
353
+	 * @throws EE_Error
354
+	 * @throws InvalidArgumentException
355
+	 * @throws InvalidDataTypeException
356
+	 * @throws InvalidInterfaceException
357
+	 */
358
+	public function column_CNT_ISO(EE_Attendee $attendee)
359
+	{
360
+		$countries = EEM_Country::instance()->get_all_countries();
361
+		$country = isset($countries[$attendee->country_ID()])
362
+			? $countries[$attendee->country_ID()]->get('CNT_name')
363
+			: $attendee->country_ID();
364
+		return ! is_numeric($country) ? $country : '';
365
+	}
366
+
367
+
368
+	/**
369
+	 * Phone Number column
370
+	 *
371
+	 * @param EE_Attendee $attendee
372
+	 * @return mixed
373
+	 * @throws EE_Error
374
+	 */
375
+	public function column_ATT_phone(EE_Attendee $attendee)
376
+	{
377
+		return $attendee->phone();
378
+	}
379 379
 }
Please login to merge, or discard this patch.
Spacing   +17 added lines, -17 removed lines patch added patch discarded remove patch
@@ -127,7 +127,7 @@  discard block
 block discarded – undo
127 127
      */
128 128
     public function column_cb($attendee)
129 129
     {
130
-        if (! $attendee instanceof EE_Attendee) {
130
+        if ( ! $attendee instanceof EE_Attendee) {
131 131
             return '';
132 132
         }
133 133
         return sprintf(
@@ -148,7 +148,7 @@  discard block
 block discarded – undo
148 148
     {
149 149
         $content = $attendee->ID();
150 150
         $attendee_name = $attendee instanceof EE_Attendee ? $attendee->full_name() : '';
151
-        $content .= '  <span class="show-on-mobile-view-only">' . $attendee_name . '</span>';
151
+        $content .= '  <span class="show-on-mobile-view-only">'.$attendee_name.'</span>';
152 152
         return $content;
153 153
     }
154 154
 
@@ -177,9 +177,9 @@  discard block
 block discarded – undo
177 177
             'ee_edit_contacts',
178 178
             'espresso_registrations_edit_attendee'
179 179
         )
180
-            ? '<a href="' . $edit_lnk_url . '" title="'
181
-              . esc_attr__('Edit Contact', 'event_espresso') . '">'
182
-              . $attendee->lname() . '</a>'
180
+            ? '<a href="'.$edit_lnk_url.'" title="'
181
+              . esc_attr__('Edit Contact', 'event_espresso').'">'
182
+              . $attendee->lname().'</a>'
183 183
             : $attendee->lname();
184 184
         return $name_link;
185 185
     }
@@ -211,9 +211,9 @@  discard block
 block discarded – undo
211 211
                 ),
212 212
                 REG_ADMIN_URL
213 213
             );
214
-            $actions['edit'] = '<a href="' . $edit_lnk_url . '" title="'
215
-                               . esc_attr__('Edit Contact', 'event_espresso') . '">'
216
-                               . esc_html__('Edit', 'event_espresso') . '</a>';
214
+            $actions['edit'] = '<a href="'.$edit_lnk_url.'" title="'
215
+                               . esc_attr__('Edit Contact', 'event_espresso').'">'
216
+                               . esc_html__('Edit', 'event_espresso').'</a>';
217 217
         }
218 218
 
219 219
         if ($this->_view === 'in_use') {
@@ -229,9 +229,9 @@  discard block
 block discarded – undo
229 229
                     ),
230 230
                     REG_ADMIN_URL
231 231
                 );
232
-                $actions['trash'] = '<a href="' . $trash_lnk_url . '" title="'
232
+                $actions['trash'] = '<a href="'.$trash_lnk_url.'" title="'
233 233
                                     . esc_attr__('Move Contact to Trash', 'event_espresso')
234
-                                    . '">' . esc_html__('Trash', 'event_espresso') . '</a>';
234
+                                    . '">'.esc_html__('Trash', 'event_espresso').'</a>';
235 235
             }
236 236
         } else {
237 237
             if (EE_Registry::instance()->CAP->current_user_can(
@@ -243,9 +243,9 @@  discard block
 block discarded – undo
243 243
                     'action' => 'restore_attendees',
244 244
                     'ATT_ID' => $attendee->ID(),
245 245
                 ), REG_ADMIN_URL);
246
-                $actions['restore'] = '<a href="' . $restore_lnk_url . '" title="'
247
-                                      . esc_attr__('Restore Contact', 'event_espresso') . '">'
248
-                                      . esc_html__('Restore', 'event_espresso') . '</a>';
246
+                $actions['restore'] = '<a href="'.$restore_lnk_url.'" title="'
247
+                                      . esc_attr__('Restore Contact', 'event_espresso').'">'
248
+                                      . esc_html__('Restore', 'event_espresso').'</a>';
249 249
             }
250 250
         }
251 251
 
@@ -257,8 +257,8 @@  discard block
 block discarded – undo
257 257
             'ee_edit_contacts',
258 258
             'espresso_registrations_edit_attendee'
259 259
         )
260
-            ? '<a href="' . $edit_lnk_url . '" title="'
261
-              . esc_attr__('Edit Contact', 'event_espresso') . '">' . $attendee->fname() . '</a>'
260
+            ? '<a href="'.$edit_lnk_url.'" title="'
261
+              . esc_attr__('Edit Contact', 'event_espresso').'">'.$attendee->fname().'</a>'
262 262
             : $attendee->fname();
263 263
 
264 264
         //Return the name contents
@@ -275,7 +275,7 @@  discard block
 block discarded – undo
275 275
      */
276 276
     public function column_ATT_email(EE_Attendee $attendee)
277 277
     {
278
-        return '<a href="mailto:' . $attendee->email() . '">' . $attendee->email() . '</a>';
278
+        return '<a href="mailto:'.$attendee->email().'">'.$attendee->email().'</a>';
279 279
     }
280 280
 
281 281
 
@@ -295,7 +295,7 @@  discard block
 block discarded – undo
295 295
             ),
296 296
             REG_ADMIN_URL
297 297
         );
298
-        return '<a href="' . $link . '">' . $attendee->getCustomSelect('Registration_Count') . '</a>';
298
+        return '<a href="'.$link.'">'.$attendee->getCustomSelect('Registration_Count').'</a>';
299 299
     }
300 300
 
301 301
 
Please login to merge, or discard this patch.
admin_pages/registrations/Registrations_Admin_Page.core.php 2 patches
Indentation   +3722 added lines, -3722 removed lines patch added patch discarded remove patch
@@ -30,2339 +30,2339 @@  discard block
 block discarded – undo
30 30
 class Registrations_Admin_Page extends EE_Admin_Page_CPT
31 31
 {
32 32
 
33
-    /**
34
-     * @var EE_Registration
35
-     */
36
-    private $_registration;
37
-
38
-    /**
39
-     * @var EE_Event
40
-     */
41
-    private $_reg_event;
42
-
43
-    /**
44
-     * @var EE_Session
45
-     */
46
-    private $_session;
47
-
48
-    private static $_reg_status;
49
-
50
-    /**
51
-     * Form for displaying the custom questions for this registration.
52
-     * This gets used a few times throughout the request so its best to cache it
53
-     *
54
-     * @var EE_Registration_Custom_Questions_Form
55
-     */
56
-    protected $_reg_custom_questions_form = null;
57
-
58
-
59
-    /**
60
-     *        constructor
61
-     *
62
-     * @Constructor
63
-     * @access public
64
-     * @param bool $routing
65
-     * @return Registrations_Admin_Page
66
-     */
67
-    public function __construct($routing = true)
68
-    {
69
-        parent::__construct($routing);
70
-        add_action('wp_loaded', array($this, 'wp_loaded'));
71
-    }
72
-
73
-
74
-    public function wp_loaded()
75
-    {
76
-        // when adding a new registration...
77
-        if (isset($this->_req_data['action']) && $this->_req_data['action'] === 'new_registration') {
78
-            EE_System::do_not_cache();
79
-            if (! isset($this->_req_data['processing_registration'])
80
-                 || absint($this->_req_data['processing_registration']) !== 1
81
-            ) {
82
-                // and it's NOT the attendee information reg step
83
-                // force cookie expiration by setting time to last week
84
-                setcookie('ee_registration_added', 0, time() - WEEK_IN_SECONDS, '/');
85
-                // and update the global
86
-                $_COOKIE['ee_registration_added'] = 0;
87
-            }
88
-        }
89
-    }
90
-
91
-
92
-    protected function _init_page_props()
93
-    {
94
-        $this->page_slug        = REG_PG_SLUG;
95
-        $this->_admin_base_url  = REG_ADMIN_URL;
96
-        $this->_admin_base_path = REG_ADMIN;
97
-        $this->page_label       = esc_html__('Registrations', 'event_espresso');
98
-        $this->_cpt_routes      = array(
99
-            'add_new_attendee' => 'espresso_attendees',
100
-            'edit_attendee'    => 'espresso_attendees',
101
-            'insert_attendee'  => 'espresso_attendees',
102
-            'update_attendee'  => 'espresso_attendees',
103
-        );
104
-        $this->_cpt_model_names = array(
105
-            'add_new_attendee' => 'EEM_Attendee',
106
-            'edit_attendee'    => 'EEM_Attendee',
107
-        );
108
-        $this->_cpt_edit_routes = array(
109
-            'espresso_attendees' => 'edit_attendee',
110
-        );
111
-        $this->_pagenow_map     = array(
112
-            'add_new_attendee' => 'post-new.php',
113
-            'edit_attendee'    => 'post.php',
114
-            'trash'            => 'post.php',
115
-        );
116
-        add_action('edit_form_after_title', array($this, 'after_title_form_fields'), 10);
117
-        //add filters so that the comment urls don't take users to a confusing 404 page
118
-        add_filter('get_comment_link', array($this, 'clear_comment_link'), 10, 3);
119
-    }
120
-
121
-
122
-    public function clear_comment_link($link, $comment, $args)
123
-    {
124
-        //gotta make sure this only happens on this route
125
-        $post_type = get_post_type($comment->comment_post_ID);
126
-        if ($post_type === 'espresso_attendees') {
127
-            return '#commentsdiv';
128
-        }
129
-        return $link;
130
-    }
131
-
132
-
133
-    protected function _ajax_hooks()
134
-    {
135
-        //todo: all hooks for registrations ajax goes in here
136
-        add_action('wp_ajax_toggle_checkin_status', array($this, 'toggle_checkin_status'));
137
-    }
138
-
139
-
140
-    protected function _define_page_props()
141
-    {
142
-        $this->_admin_page_title = $this->page_label;
143
-        $this->_labels           = array(
144
-            'buttons'                      => array(
145
-                'add-registrant'      => esc_html__('Add New Registration', 'event_espresso'),
146
-                'add-attendee'        => esc_html__('Add Contact', 'event_espresso'),
147
-                'edit'                => esc_html__('Edit Contact', 'event_espresso'),
148
-                'report'              => esc_html__("Event Registrations CSV Report", "event_espresso"),
149
-                'report_all'          => esc_html__('All Registrations CSV Report', 'event_espresso'),
150
-                'report_filtered'     => esc_html__('Filtered CSV Report', 'event_espresso'),
151
-                'contact_list_report' => esc_html__('Contact List Report', 'event_espresso'),
152
-                'contact_list_export' => esc_html__("Export Data", "event_espresso"),
153
-            ),
154
-            'publishbox'                   => array(
155
-                'add_new_attendee' => esc_html__("Add Contact Record", 'event_espresso'),
156
-                'edit_attendee'    => esc_html__("Update Contact Record", 'event_espresso'),
157
-            ),
158
-            'hide_add_button_on_cpt_route' => array(
159
-                'edit_attendee' => true,
160
-            ),
161
-        );
162
-    }
163
-
164
-
165
-    /**
166
-     *        grab url requests and route them
167
-     *
168
-     * @access private
169
-     * @return void
170
-     */
171
-    public function _set_page_routes()
172
-    {
173
-        $this->_get_registration_status_array();
174
-        $reg_id             = ! empty($this->_req_data['_REG_ID']) && ! is_array($this->_req_data['_REG_ID'])
175
-            ? $this->_req_data['_REG_ID'] : 0;
176
-        $reg_id = empty($reg_id) && ! empty($this->_req_data['reg_status_change_form']['REG_ID'])
177
-            ? $this->_req_data['reg_status_change_form']['REG_ID']
178
-            : $reg_id;
179
-        $att_id             = ! empty($this->_req_data['ATT_ID']) && ! is_array($this->_req_data['ATT_ID'])
180
-            ? $this->_req_data['ATT_ID'] : 0;
181
-        $att_id             = ! empty($this->_req_data['post']) && ! is_array($this->_req_data['post'])
182
-            ? $this->_req_data['post']
183
-            : $att_id;
184
-        $this->_page_routes = array(
185
-            'default'                            => array(
186
-                'func'       => '_registrations_overview_list_table',
187
-                'capability' => 'ee_read_registrations',
188
-            ),
189
-            'view_registration'                  => array(
190
-                'func'       => '_registration_details',
191
-                'capability' => 'ee_read_registration',
192
-                'obj_id'     => $reg_id,
193
-            ),
194
-            'edit_registration'                  => array(
195
-                'func'               => '_update_attendee_registration_form',
196
-                'noheader'           => true,
197
-                'headers_sent_route' => 'view_registration',
198
-                'capability'         => 'ee_edit_registration',
199
-                'obj_id'             => $reg_id,
200
-                '_REG_ID'            => $reg_id,
201
-            ),
202
-            'trash_registrations'                => array(
203
-                'func'       => '_trash_or_restore_registrations',
204
-                'args'       => array('trash' => true),
205
-                'noheader'   => true,
206
-                'capability' => 'ee_delete_registrations',
207
-            ),
208
-            'restore_registrations'              => array(
209
-                'func'       => '_trash_or_restore_registrations',
210
-                'args'       => array('trash' => false),
211
-                'noheader'   => true,
212
-                'capability' => 'ee_delete_registrations',
213
-            ),
214
-            'delete_registrations'               => array(
215
-                'func'       => '_delete_registrations',
216
-                'noheader'   => true,
217
-                'capability' => 'ee_delete_registrations',
218
-            ),
219
-            'new_registration'                   => array(
220
-                'func'       => 'new_registration',
221
-                'capability' => 'ee_edit_registrations',
222
-            ),
223
-            'process_reg_step'                   => array(
224
-                'func'       => 'process_reg_step',
225
-                'noheader'   => true,
226
-                'capability' => 'ee_edit_registrations',
227
-            ),
228
-            'redirect_to_txn'                    => array(
229
-                'func'       => 'redirect_to_txn',
230
-                'noheader'   => true,
231
-                'capability' => 'ee_edit_registrations',
232
-            ),
233
-            'change_reg_status'                  => array(
234
-                'func'       => '_change_reg_status',
235
-                'noheader'   => true,
236
-                'capability' => 'ee_edit_registration',
237
-                'obj_id'     => $reg_id,
238
-            ),
239
-            'approve_registration'               => array(
240
-                'func'       => 'approve_registration',
241
-                'noheader'   => true,
242
-                'capability' => 'ee_edit_registration',
243
-                'obj_id'     => $reg_id,
244
-            ),
245
-            'approve_and_notify_registration'    => array(
246
-                'func'       => 'approve_registration',
247
-                'noheader'   => true,
248
-                'args'       => array(true),
249
-                'capability' => 'ee_edit_registration',
250
-                'obj_id'     => $reg_id,
251
-            ),
252
-            'approve_registrations'               => array(
253
-                'func'       => 'bulk_action_on_registrations',
254
-                'noheader'   => true,
255
-                'capability' => 'ee_edit_registrations',
256
-                'args' => array('approve')
257
-            ),
258
-            'approve_and_notify_registrations'               => array(
259
-                'func'       => 'bulk_action_on_registrations',
260
-                'noheader'   => true,
261
-                'capability' => 'ee_edit_registrations',
262
-                'args' => array('approve', true)
263
-            ),
264
-            'decline_registration'               => array(
265
-                'func'       => 'decline_registration',
266
-                'noheader'   => true,
267
-                'capability' => 'ee_edit_registration',
268
-                'obj_id'     => $reg_id,
269
-            ),
270
-            'decline_and_notify_registration'    => array(
271
-                'func'       => 'decline_registration',
272
-                'noheader'   => true,
273
-                'args'       => array(true),
274
-                'capability' => 'ee_edit_registration',
275
-                'obj_id'     => $reg_id,
276
-            ),
277
-            'decline_registrations'               => array(
278
-                'func'       => 'bulk_action_on_registrations',
279
-                'noheader'   => true,
280
-                'capability' => 'ee_edit_registrations',
281
-                'args' => array('decline')
282
-            ),
283
-            'decline_and_notify_registrations'    => array(
284
-                'func'       => 'bulk_action_on_registrations',
285
-                'noheader'   => true,
286
-                'capability' => 'ee_edit_registrations',
287
-                'args' => array('decline', true)
288
-            ),
289
-            'pending_registration'               => array(
290
-                'func'       => 'pending_registration',
291
-                'noheader'   => true,
292
-                'capability' => 'ee_edit_registration',
293
-                'obj_id'     => $reg_id,
294
-            ),
295
-            'pending_and_notify_registration'    => array(
296
-                'func'       => 'pending_registration',
297
-                'noheader'   => true,
298
-                'args'       => array(true),
299
-                'capability' => 'ee_edit_registration',
300
-                'obj_id'     => $reg_id,
301
-            ),
302
-            'pending_registrations'               => array(
303
-                'func'       => 'bulk_action_on_registrations',
304
-                'noheader'   => true,
305
-                'capability' => 'ee_edit_registrations',
306
-                'args' => array('pending')
307
-            ),
308
-            'pending_and_notify_registrations'    => array(
309
-                'func'       => 'bulk_action_on_registrations',
310
-                'noheader'   => true,
311
-                'capability' => 'ee_edit_registrations',
312
-                'args' => array('pending', true)
313
-            ),
314
-            'no_approve_registration'            => array(
315
-                'func'       => 'not_approve_registration',
316
-                'noheader'   => true,
317
-                'capability' => 'ee_edit_registration',
318
-                'obj_id'     => $reg_id,
319
-            ),
320
-            'no_approve_and_notify_registration' => array(
321
-                'func'       => 'not_approve_registration',
322
-                'noheader'   => true,
323
-                'args'       => array(true),
324
-                'capability' => 'ee_edit_registration',
325
-                'obj_id'     => $reg_id,
326
-            ),
327
-            'no_approve_registrations'            => array(
328
-                'func'       => 'bulk_action_on_registrations',
329
-                'noheader'   => true,
330
-                'capability' => 'ee_edit_registrations',
331
-                'args' => array('not_approve')
332
-            ),
333
-            'no_approve_and_notify_registrations' => array(
334
-                'func'       => 'bulk_action_on_registrations',
335
-                'noheader'   => true,
336
-                'capability' => 'ee_edit_registrations',
337
-                'args' => array('not_approve', true)
338
-            ),
339
-            'cancel_registration'                => array(
340
-                'func'       => 'cancel_registration',
341
-                'noheader'   => true,
342
-                'capability' => 'ee_edit_registration',
343
-                'obj_id'     => $reg_id,
344
-            ),
345
-            'cancel_and_notify_registration'     => array(
346
-                'func'       => 'cancel_registration',
347
-                'noheader'   => true,
348
-                'args'       => array(true),
349
-                'capability' => 'ee_edit_registration',
350
-                'obj_id'     => $reg_id,
351
-            ),
352
-            'cancel_registrations'                => array(
353
-                'func'       => 'bulk_action_on_registrations',
354
-                'noheader'   => true,
355
-                'capability' => 'ee_edit_registrations',
356
-                'args' => array('cancel')
357
-            ),
358
-            'cancel_and_notify_registrations'     => array(
359
-                'func'       => 'bulk_action_on_registrations',
360
-                'noheader'   => true,
361
-                'capability' => 'ee_edit_registrations',
362
-                'args' => array('cancel', true)
363
-            ),
364
-            'wait_list_registration' => array(
365
-                'func'       => 'wait_list_registration',
366
-                'noheader'   => true,
367
-                'capability' => 'ee_edit_registration',
368
-                'obj_id'     => $reg_id,
369
-            ),
370
-            'wait_list_and_notify_registration' => array(
371
-                'func'       => 'wait_list_registration',
372
-                'noheader'   => true,
373
-                'args'       => array(true),
374
-                'capability' => 'ee_edit_registration',
375
-                'obj_id'     => $reg_id,
376
-            ),
377
-            'contact_list'                       => array(
378
-                'func'       => '_attendee_contact_list_table',
379
-                'capability' => 'ee_read_contacts',
380
-            ),
381
-            'add_new_attendee'                   => array(
382
-                'func' => '_create_new_cpt_item',
383
-                'args' => array(
384
-                    'new_attendee' => true,
385
-                    'capability'   => 'ee_edit_contacts',
386
-                ),
387
-            ),
388
-            'edit_attendee'                      => array(
389
-                'func'       => '_edit_cpt_item',
390
-                'capability' => 'ee_edit_contacts',
391
-                'obj_id'     => $att_id,
392
-            ),
393
-            'duplicate_attendee'                 => array(
394
-                'func'       => '_duplicate_attendee',
395
-                'noheader'   => true,
396
-                'capability' => 'ee_edit_contacts',
397
-                'obj_id'     => $att_id,
398
-            ),
399
-            'insert_attendee'                    => array(
400
-                'func'       => '_insert_or_update_attendee',
401
-                'args'       => array(
402
-                    'new_attendee' => true,
403
-                ),
404
-                'noheader'   => true,
405
-                'capability' => 'ee_edit_contacts',
406
-            ),
407
-            'update_attendee'                    => array(
408
-                'func'       => '_insert_or_update_attendee',
409
-                'args'       => array(
410
-                    'new_attendee' => false,
411
-                ),
412
-                'noheader'   => true,
413
-                'capability' => 'ee_edit_contacts',
414
-                'obj_id'     => $att_id,
415
-            ),
416
-            'trash_attendees' => array(
417
-                'func' => '_trash_or_restore_attendees',
418
-                'args' => array(
419
-                    'trash' => 'true'
420
-                ),
421
-                'noheader' => true,
422
-                'capability' => 'ee_delete_contacts'
423
-            ),
424
-            'trash_attendee'                    => array(
425
-                'func'       => '_trash_or_restore_attendees',
426
-                'args'       => array(
427
-                    'trash' => true,
428
-                ),
429
-                'noheader'   => true,
430
-                'capability' => 'ee_delete_contacts',
431
-                'obj_id'     => $att_id,
432
-            ),
433
-            'restore_attendees'                  => array(
434
-                'func'       => '_trash_or_restore_attendees',
435
-                'args'       => array(
436
-                    'trash' => false,
437
-                ),
438
-                'noheader'   => true,
439
-                'capability' => 'ee_delete_contacts',
440
-                'obj_id'     => $att_id,
441
-            ),
442
-            'resend_registration'                => array(
443
-                'func'       => '_resend_registration',
444
-                'noheader'   => true,
445
-                'capability' => 'ee_send_message',
446
-            ),
447
-            'registrations_report'               => array(
448
-                'func'       => '_registrations_report',
449
-                'noheader'   => true,
450
-                'capability' => 'ee_read_registrations',
451
-            ),
452
-            'contact_list_export'                => array(
453
-                'func'       => '_contact_list_export',
454
-                'noheader'   => true,
455
-                'capability' => 'export',
456
-            ),
457
-            'contact_list_report'                => array(
458
-                'func'       => '_contact_list_report',
459
-                'noheader'   => true,
460
-                'capability' => 'ee_read_contacts',
461
-            ),
462
-        );
463
-    }
464
-
465
-
466
-    protected function _set_page_config()
467
-    {
468
-        $this->_page_config = array(
469
-            'default'           => array(
470
-                'nav'           => array(
471
-                    'label' => esc_html__('Overview', 'event_espresso'),
472
-                    'order' => 5,
473
-                ),
474
-                'help_tabs'     => array(
475
-                    'registrations_overview_help_tab'                       => array(
476
-                        'title'    => esc_html__('Registrations Overview', 'event_espresso'),
477
-                        'filename' => 'registrations_overview',
478
-                    ),
479
-                    'registrations_overview_table_column_headings_help_tab' => array(
480
-                        'title'    => esc_html__('Registrations Table Column Headings', 'event_espresso'),
481
-                        'filename' => 'registrations_overview_table_column_headings',
482
-                    ),
483
-                    'registrations_overview_filters_help_tab'               => array(
484
-                        'title'    => esc_html__('Registration Filters', 'event_espresso'),
485
-                        'filename' => 'registrations_overview_filters',
486
-                    ),
487
-                    'registrations_overview_views_help_tab'                 => array(
488
-                        'title'    => esc_html__('Registration Views', 'event_espresso'),
489
-                        'filename' => 'registrations_overview_views',
490
-                    ),
491
-                    'registrations_regoverview_other_help_tab'              => array(
492
-                        'title'    => esc_html__('Registrations Other', 'event_espresso'),
493
-                        'filename' => 'registrations_overview_other',
494
-                    ),
495
-                ),
496
-                'help_tour'     => array('Registration_Overview_Help_Tour'),
497
-                'qtips'         => array('Registration_List_Table_Tips'),
498
-                'list_table'    => 'EE_Registrations_List_Table',
499
-                'require_nonce' => false,
500
-            ),
501
-            'view_registration' => array(
502
-                'nav'           => array(
503
-                    'label'      => esc_html__('REG Details', 'event_espresso'),
504
-                    'order'      => 15,
505
-                    'url'        => isset($this->_req_data['_REG_ID'])
506
-                        ? add_query_arg(array('_REG_ID' => $this->_req_data['_REG_ID']), $this->_current_page_view_url)
507
-                        : $this->_admin_base_url,
508
-                    'persistent' => false,
509
-                ),
510
-                'help_tabs'     => array(
511
-                    'registrations_details_help_tab'                    => array(
512
-                        'title'    => esc_html__('Registration Details', 'event_espresso'),
513
-                        'filename' => 'registrations_details',
514
-                    ),
515
-                    'registrations_details_table_help_tab'              => array(
516
-                        'title'    => esc_html__('Registration Details Table', 'event_espresso'),
517
-                        'filename' => 'registrations_details_table',
518
-                    ),
519
-                    'registrations_details_form_answers_help_tab'       => array(
520
-                        'title'    => esc_html__('Registration Form Answers', 'event_espresso'),
521
-                        'filename' => 'registrations_details_form_answers',
522
-                    ),
523
-                    'registrations_details_registrant_details_help_tab' => array(
524
-                        'title'    => esc_html__('Contact Details', 'event_espresso'),
525
-                        'filename' => 'registrations_details_registrant_details',
526
-                    ),
527
-                ),
528
-                'help_tour'     => array('Registration_Details_Help_Tour'),
529
-                'metaboxes'     => array_merge(
530
-                    $this->_default_espresso_metaboxes,
531
-                    array('_registration_details_metaboxes')
532
-                ),
533
-                'require_nonce' => false,
534
-            ),
535
-            'new_registration'  => array(
536
-                'nav'           => array(
537
-                    'label'      => esc_html__('Add New Registration', 'event_espresso'),
538
-                    'url'        => '#',
539
-                    'order'      => 15,
540
-                    'persistent' => false,
541
-                ),
542
-                'metaboxes'     => $this->_default_espresso_metaboxes,
543
-                'labels'        => array(
544
-                    'publishbox' => esc_html__('Save Registration', 'event_espresso'),
545
-                ),
546
-                'require_nonce' => false,
547
-            ),
548
-            'add_new_attendee'  => array(
549
-                'nav'           => array(
550
-                    'label'      => esc_html__('Add Contact', 'event_espresso'),
551
-                    'order'      => 15,
552
-                    'persistent' => false,
553
-                ),
554
-                'metaboxes'     => array_merge(
555
-                    $this->_default_espresso_metaboxes,
556
-                    array('_publish_post_box', 'attendee_editor_metaboxes')
557
-                ),
558
-                'require_nonce' => false,
559
-            ),
560
-            'edit_attendee'     => array(
561
-                'nav'           => array(
562
-                    'label'      => esc_html__('Edit Contact', 'event_espresso'),
563
-                    'order'      => 15,
564
-                    'persistent' => false,
565
-                    'url'        => isset($this->_req_data['ATT_ID'])
566
-                        ? add_query_arg(array('ATT_ID' => $this->_req_data['ATT_ID']), $this->_current_page_view_url)
567
-                        : $this->_admin_base_url,
568
-                ),
569
-                'metaboxes'     => array('attendee_editor_metaboxes'),
570
-                'require_nonce' => false,
571
-            ),
572
-            'contact_list'      => array(
573
-                'nav'           => array(
574
-                    'label' => esc_html__('Contact List', 'event_espresso'),
575
-                    'order' => 20,
576
-                ),
577
-                'list_table'    => 'EE_Attendee_Contact_List_Table',
578
-                'help_tabs'     => array(
579
-                    'registrations_contact_list_help_tab'                       => array(
580
-                        'title'    => esc_html__('Registrations Contact List', 'event_espresso'),
581
-                        'filename' => 'registrations_contact_list',
582
-                    ),
583
-                    'registrations_contact-list_table_column_headings_help_tab' => array(
584
-                        'title'    => esc_html__('Contact List Table Column Headings', 'event_espresso'),
585
-                        'filename' => 'registrations_contact_list_table_column_headings',
586
-                    ),
587
-                    'registrations_contact_list_views_help_tab'                 => array(
588
-                        'title'    => esc_html__('Contact List Views', 'event_espresso'),
589
-                        'filename' => 'registrations_contact_list_views',
590
-                    ),
591
-                    'registrations_contact_list_other_help_tab'                 => array(
592
-                        'title'    => esc_html__('Contact List Other', 'event_espresso'),
593
-                        'filename' => 'registrations_contact_list_other',
594
-                    ),
595
-                ),
596
-                'help_tour'     => array('Contact_List_Help_Tour'),
597
-                'metaboxes'     => array(),
598
-                'require_nonce' => false,
599
-            ),
600
-            //override default cpt routes
601
-            'create_new'        => '',
602
-            'edit'              => '',
603
-        );
604
-    }
605
-
606
-
607
-    /**
608
-     * The below methods aren't used by this class currently
609
-     */
610
-    protected function _add_screen_options()
611
-    {
612
-    }
613
-
614
-
615
-    protected function _add_feature_pointers()
616
-    {
617
-    }
618
-
619
-
620
-    public function admin_init()
621
-    {
622
-        EE_Registry::$i18n_js_strings['update_att_qstns'] = esc_html__(
623
-            'click "Update Registration Questions" to save your changes',
624
-            'event_espresso'
625
-        );
626
-    }
627
-
628
-
629
-    public function admin_notices()
630
-    {
631
-    }
632
-
633
-
634
-    public function admin_footer_scripts()
635
-    {
636
-    }
637
-
638
-
639
-    /**
640
-     *        get list of registration statuses
641
-     *
642
-     * @access private
643
-     * @return void
644
-     * @throws EE_Error
645
-     */
646
-    private function _get_registration_status_array()
647
-    {
648
-        self::$_reg_status = EEM_Registration::reg_status_array(array(), true);
649
-    }
650
-
651
-
652
-    protected function _add_screen_options_default()
653
-    {
654
-        $this->_per_page_screen_option();
655
-    }
656
-
657
-
658
-    protected function _add_screen_options_contact_list()
659
-    {
660
-        $page_title              = $this->_admin_page_title;
661
-        $this->_admin_page_title = esc_html__("Contacts", 'event_espresso');
662
-        $this->_per_page_screen_option();
663
-        $this->_admin_page_title = $page_title;
664
-    }
665
-
666
-
667
-    public function load_scripts_styles()
668
-    {
669
-        //style
670
-        wp_register_style(
671
-            'espresso_reg',
672
-            REG_ASSETS_URL . 'espresso_registrations_admin.css',
673
-            array('ee-admin-css'),
674
-            EVENT_ESPRESSO_VERSION
675
-        );
676
-        wp_enqueue_style('espresso_reg');
677
-        //script
678
-        wp_register_script(
679
-            'espresso_reg',
680
-            REG_ASSETS_URL . 'espresso_registrations_admin.js',
681
-            array('jquery-ui-datepicker', 'jquery-ui-draggable', 'ee_admin_js'),
682
-            EVENT_ESPRESSO_VERSION,
683
-            true
684
-        );
685
-        wp_enqueue_script('espresso_reg');
686
-    }
687
-
688
-
689
-    public function load_scripts_styles_edit_attendee()
690
-    {
691
-        //stuff to only show up on our attendee edit details page.
692
-        $attendee_details_translations = array(
693
-            'att_publish_text' => sprintf(
694
-                esc_html__('Created on: <b>%1$s</b>', 'event_espresso'),
695
-                $this->_cpt_model_obj->get_datetime('ATT_created')
696
-            ),
697
-        );
698
-        wp_localize_script('espresso_reg', 'ATTENDEE_DETAILS', $attendee_details_translations);
699
-        wp_enqueue_script('jquery-validate');
700
-    }
701
-
702
-
703
-    public function load_scripts_styles_view_registration()
704
-    {
705
-        //styles
706
-        wp_enqueue_style('espresso-ui-theme');
707
-        //scripts
708
-        $this->_get_reg_custom_questions_form($this->_registration->ID());
709
-        $this->_reg_custom_questions_form->wp_enqueue_scripts(true);
710
-    }
711
-
712
-
713
-    public function load_scripts_styles_contact_list()
714
-    {
715
-        wp_deregister_style('espresso_reg');
716
-        wp_register_style(
717
-            'espresso_att',
718
-            REG_ASSETS_URL . 'espresso_attendees_admin.css',
719
-            array('ee-admin-css'),
720
-            EVENT_ESPRESSO_VERSION
721
-        );
722
-        wp_enqueue_style('espresso_att');
723
-    }
724
-
725
-
726
-    public function load_scripts_styles_new_registration()
727
-    {
728
-        wp_register_script(
729
-            'ee-spco-for-admin',
730
-            REG_ASSETS_URL . 'spco_for_admin.js',
731
-            array('underscore', 'jquery'),
732
-            EVENT_ESPRESSO_VERSION,
733
-            true
734
-        );
735
-        wp_enqueue_script('ee-spco-for-admin');
736
-        add_filter('FHEE__EED_Ticket_Selector__load_tckt_slctr_assets', '__return_true');
737
-        EE_Form_Section_Proper::wp_enqueue_scripts();
738
-        EED_Ticket_Selector::load_tckt_slctr_assets();
739
-        EE_Datepicker_Input::enqueue_styles_and_scripts();
740
-    }
741
-
742
-
743
-    public function AHEE__EE_Admin_Page__route_admin_request_resend_registration()
744
-    {
745
-        add_filter('FHEE_load_EE_messages', '__return_true');
746
-    }
747
-
748
-
749
-    public function AHEE__EE_Admin_Page__route_admin_request_approve_registration()
750
-    {
751
-        add_filter('FHEE_load_EE_messages', '__return_true');
752
-    }
753
-
754
-
755
-    protected function _set_list_table_views_default()
756
-    {
757
-        //for notification related bulk actions we need to make sure only active messengers have an option.
758
-        EED_Messages::set_autoloaders();
759
-        /** @type EE_Message_Resource_Manager $message_resource_manager */
760
-        $message_resource_manager = EE_Registry::instance()->load_lib('Message_Resource_Manager');
761
-        $active_mts               = $message_resource_manager->list_of_active_message_types();
762
-        //key= bulk_action_slug, value= message type.
763
-        $match_array = array(
764
-            'approve_registrations'    => 'registration',
765
-            'decline_registrations'    => 'declined_registration',
766
-            'pending_registrations'    => 'pending_approval',
767
-            'no_approve_registrations' => 'not_approved_registration',
768
-            'cancel_registrations'     => 'cancelled_registration',
769
-        );
770
-        $can_send = EE_Registry::instance()->CAP->current_user_can(
771
-            'ee_send_message',
772
-            'batch_send_messages'
773
-        );
774
-        /** setup reg status bulk actions **/
775
-        $def_reg_status_actions['approve_registrations'] = esc_html__('Approve Registrations', 'event_espresso');
776
-        if ($can_send && in_array($match_array['approve_registrations'], $active_mts, true)) {
777
-                $def_reg_status_actions['approve_and_notify_registrations'] = esc_html__(
778
-                    'Approve and Notify Registrations',
779
-                    'event_espresso'
780
-                );
781
-        }
782
-        $def_reg_status_actions['decline_registrations'] = esc_html__('Decline Registrations', 'event_espresso');
783
-        if ($can_send && in_array($match_array['decline_registrations'], $active_mts, true)) {
784
-                $def_reg_status_actions['decline_and_notify_registrations'] = esc_html__(
785
-                    'Decline and Notify Registrations',
786
-                    'event_espresso'
787
-                );
788
-        }
789
-        $def_reg_status_actions['pending_registrations'] = esc_html__(
790
-            'Set Registrations to Pending Payment',
791
-            'event_espresso'
792
-        );
793
-        if ($can_send && in_array($match_array['pending_registrations'], $active_mts, true)) {
794
-                $def_reg_status_actions['pending_and_notify_registrations'] = esc_html__(
795
-                    'Set Registrations to Pending Payment and Notify',
796
-                    'event_espresso'
797
-                );
798
-        }
799
-        $def_reg_status_actions['no_approve_registrations'] = esc_html__(
800
-            'Set Registrations to Not Approved',
801
-            'event_espresso'
802
-        );
803
-        if ($can_send && in_array($match_array['no_approve_registrations'], $active_mts, true)) {
804
-                $def_reg_status_actions['no_approve_and_notify_registrations'] = esc_html__(
805
-                    'Set Registrations to Not Approved and Notify',
806
-                    'event_espresso'
807
-                );
808
-        }
809
-        $def_reg_status_actions['cancel_registrations'] = esc_html__('Cancel Registrations', 'event_espresso');
810
-        if ($can_send && in_array($match_array['cancel_registrations'], $active_mts, true)) {
811
-                $def_reg_status_actions['cancel_and_notify_registrations'] = esc_html__(
812
-                    'Cancel Registrations and Notify',
813
-                    'event_espresso'
814
-                );
815
-        }
816
-        $def_reg_status_actions = apply_filters(
817
-            'FHEE__Registrations_Admin_Page___set_list_table_views_default__def_reg_status_actions_array',
818
-            $def_reg_status_actions,
819
-            $active_mts,
820
-            $can_send
821
-        );
822
-
823
-        $this->_views = array(
824
-            'all'   => array(
825
-                'slug'        => 'all',
826
-                'label'       => esc_html__('View All Registrations', 'event_espresso'),
827
-                'count'       => 0,
828
-                'bulk_action' => array_merge($def_reg_status_actions, array(
829
-                    'trash_registrations' => esc_html__('Trash Registrations', 'event_espresso'),
830
-                )),
831
-            ),
832
-            'month' => array(
833
-                'slug'        => 'month',
834
-                'label'       => esc_html__('This Month', 'event_espresso'),
835
-                'count'       => 0,
836
-                'bulk_action' => array_merge($def_reg_status_actions, array(
837
-                    'trash_registrations' => esc_html__('Trash Registrations', 'event_espresso'),
838
-                )),
839
-            ),
840
-            'today' => array(
841
-                'slug'        => 'today',
842
-                'label'       => sprintf(
843
-                    esc_html__('Today - %s', 'event_espresso'),
844
-                    date('M d, Y', current_time('timestamp'))
845
-                ),
846
-                'count'       => 0,
847
-                'bulk_action' => array_merge($def_reg_status_actions, array(
848
-                    'trash_registrations' => esc_html__('Trash Registrations', 'event_espresso'),
849
-                )),
850
-            ),
851
-        );
852
-        if (EE_Registry::instance()->CAP->current_user_can(
853
-            'ee_delete_registrations',
854
-            'espresso_registrations_delete_registration'
855
-        )) {
856
-            $this->_views['incomplete'] = array(
857
-                'slug'        => 'incomplete',
858
-                'label'       => esc_html__('Incomplete', 'event_espresso'),
859
-                'count'       => 0,
860
-                'bulk_action' => array(
861
-                    'trash_registrations' => esc_html__('Trash Registrations', 'event_espresso'),
862
-                ),
863
-            );
864
-            $this->_views['trash']      = array(
865
-                'slug'        => 'trash',
866
-                'label'       => esc_html__('Trash', 'event_espresso'),
867
-                'count'       => 0,
868
-                'bulk_action' => array(
869
-                    'restore_registrations' => esc_html__('Restore Registrations', 'event_espresso'),
870
-                    'delete_registrations'  => esc_html__('Delete Registrations Permanently', 'event_espresso'),
871
-                ),
872
-            );
873
-        }
874
-    }
875
-
876
-
877
-    protected function _set_list_table_views_contact_list()
878
-    {
879
-        $this->_views = array(
880
-            'in_use' => array(
881
-                'slug'        => 'in_use',
882
-                'label'       => esc_html__('In Use', 'event_espresso'),
883
-                'count'       => 0,
884
-                'bulk_action' => array(
885
-                    'trash_attendees' => esc_html__('Move to Trash', 'event_espresso'),
886
-                ),
887
-            ),
888
-        );
889
-        if (EE_Registry::instance()->CAP->current_user_can('ee_delete_contacts',
890
-            'espresso_registrations_trash_attendees')
891
-        ) {
892
-            $this->_views['trash'] = array(
893
-                'slug'        => 'trash',
894
-                'label'       => esc_html__('Trash', 'event_espresso'),
895
-                'count'       => 0,
896
-                'bulk_action' => array(
897
-                    'restore_attendees' => esc_html__('Restore from Trash', 'event_espresso'),
898
-                ),
899
-            );
900
-        }
901
-    }
902
-
903
-
904
-    protected function _registration_legend_items()
905
-    {
906
-        $fc_items = array(
907
-            'star-icon'        => array(
908
-                'class' => 'dashicons dashicons-star-filled lt-blue-icon ee-icon-size-8',
909
-                'desc'  => esc_html__('This is the Primary Registrant', 'event_espresso'),
910
-            ),
911
-            'view_details'     => array(
912
-                'class' => 'dashicons dashicons-clipboard',
913
-                'desc'  => esc_html__('View Registration Details', 'event_espresso'),
914
-            ),
915
-            'edit_attendee'    => array(
916
-                'class' => 'ee-icon ee-icon-user-edit ee-icon-size-16',
917
-                'desc'  => esc_html__('Edit Contact Details', 'event_espresso'),
918
-            ),
919
-            'view_transaction' => array(
920
-                'class' => 'dashicons dashicons-cart',
921
-                'desc'  => esc_html__('View Transaction Details', 'event_espresso'),
922
-            ),
923
-            'view_invoice'     => array(
924
-                'class' => 'dashicons dashicons-media-spreadsheet',
925
-                'desc'  => esc_html__('View Transaction Invoice', 'event_espresso'),
926
-            ),
927
-        );
928
-        if (EE_Registry::instance()->CAP->current_user_can(
929
-            'ee_send_message',
930
-            'espresso_registrations_resend_registration'
931
-        )) {
932
-            $fc_items['resend_registration'] = array(
933
-                'class' => 'dashicons dashicons-email-alt',
934
-                'desc'  => esc_html__('Resend Registration Details', 'event_espresso'),
935
-            );
936
-        } else {
937
-            $fc_items['blank'] = array('class' => 'blank', 'desc' => '');
938
-        }
939
-        if (EE_Registry::instance()->CAP->current_user_can(
940
-            'ee_read_global_messages',
941
-            'view_filtered_messages'
942
-        )) {
943
-            $related_for_icon = EEH_MSG_Template::get_message_action_icon('see_notifications_for');
944
-            if (isset($related_for_icon['css_class']) && isset($related_for_icon['label'])) {
945
-                $fc_items['view_related_messages'] = array(
946
-                    'class' => $related_for_icon['css_class'],
947
-                    'desc'  => $related_for_icon['label'],
948
-                );
949
-            }
950
-        }
951
-        $sc_items = array(
952
-            'approved_status'   => array(
953
-                'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_approved,
954
-                'desc'  => EEH_Template::pretty_status(
955
-                    EEM_Registration::status_id_approved,
956
-                    false,
957
-                    'sentence'
958
-                ),
959
-            ),
960
-            'pending_status'    => array(
961
-                'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_pending_payment,
962
-                'desc'  => EEH_Template::pretty_status(
963
-                    EEM_Registration::status_id_pending_payment,
964
-                    false,
965
-                    'sentence'
966
-                ),
967
-            ),
968
-            'wait_list'         => array(
969
-                'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_wait_list,
970
-                'desc'  => EEH_Template::pretty_status(
971
-                    EEM_Registration::status_id_wait_list,
972
-                    false,
973
-                    'sentence'
974
-                ),
975
-            ),
976
-            'incomplete_status' => array(
977
-                'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_incomplete,
978
-                'desc'  => EEH_Template::pretty_status(
979
-                    EEM_Registration::status_id_incomplete,
980
-                    false,
981
-                    'sentence'
982
-                ),
983
-            ),
984
-            'not_approved'      => array(
985
-                'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_not_approved,
986
-                'desc'  => EEH_Template::pretty_status(
987
-                    EEM_Registration::status_id_not_approved,
988
-                    false,
989
-                    'sentence'
990
-                ),
991
-            ),
992
-            'declined_status'   => array(
993
-                'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_declined,
994
-                'desc'  => EEH_Template::pretty_status(
995
-                    EEM_Registration::status_id_declined,
996
-                    false,
997
-                    'sentence'
998
-                ),
999
-            ),
1000
-            'cancelled_status'  => array(
1001
-                'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_cancelled,
1002
-                'desc'  => EEH_Template::pretty_status(
1003
-                    EEM_Registration::status_id_cancelled,
1004
-                    false,
1005
-                    'sentence'
1006
-                ),
1007
-            ),
1008
-        );
1009
-        return array_merge($fc_items, $sc_items);
1010
-    }
1011
-
1012
-
1013
-
1014
-    /***************************************        REGISTRATION OVERVIEW        **************************************/
1015
-    /**
1016
-     * @throws \EE_Error
1017
-     */
1018
-    protected function _registrations_overview_list_table()
1019
-    {
1020
-        $this->_template_args['admin_page_header'] = '';
1021
-        $EVT_ID                                    = ! empty($this->_req_data['event_id'])
1022
-            ? absint($this->_req_data['event_id'])
1023
-            : 0;
1024
-        $ATT_ID = !empty($this->_req_data['ATT_ID'])
1025
-            ? absint($this->_req_data['ATT_ID'])
1026
-            : 0;
1027
-        if ($ATT_ID) {
1028
-            $attendee = EEM_Attendee::instance()->get_one_by_ID($ATT_ID);
1029
-            if ($attendee instanceof EE_Attendee) {
1030
-                $this->_template_args['admin_page_header'] = sprintf(
1031
-                    esc_html__(
1032
-                        '%1$s Viewing registrations for %2$s%3$s',
1033
-                        'event_espresso'
1034
-                    ),
1035
-                    '<h3 style="line-height:1.5em;">',
1036
-                    '<a href="' . EE_Admin_Page::add_query_args_and_nonce(
1037
-                        array(
1038
-                            'action' => 'edit_attendee',
1039
-                            'post' => $ATT_ID
1040
-                        ),
1041
-                        REG_ADMIN_URL
1042
-                    ) . '">' . $attendee->full_name() . '</a>',
1043
-                    '</h3>'
1044
-                );
1045
-            }
1046
-        }
1047
-        if ($EVT_ID) {
1048
-            if (EE_Registry::instance()->CAP->current_user_can(
1049
-                'ee_edit_registrations',
1050
-                'espresso_registrations_new_registration',
1051
-                $EVT_ID
1052
-            )) {
1053
-                $this->_admin_page_title .= ' ' . $this->get_action_link_or_button(
1054
-                    'new_registration',
1055
-                    'add-registrant',
1056
-                    array('event_id' => $EVT_ID),
1057
-                    'add-new-h2'
1058
-                );
1059
-            }
1060
-            $event = EEM_Event::instance()->get_one_by_ID($EVT_ID);
1061
-            if ($event instanceof EE_Event) {
1062
-                $this->_template_args['admin_page_header'] = sprintf(
1063
-                    esc_html__(
1064
-                        '%s Viewing registrations for the event: %s%s',
1065
-                        'event_espresso'
1066
-                    ),
1067
-                    '<h3 style="line-height:1.5em;">',
1068
-                    '<br /><a href="'
1069
-                        . EE_Admin_Page::add_query_args_and_nonce(
1070
-                            array(
1071
-                                'action' => 'edit',
1072
-                                'post'   => $event->ID(),
1073
-                            ),
1074
-                            EVENTS_ADMIN_URL
1075
-                        )
1076
-                        . '">&nbsp;'
1077
-                        . $event->get('EVT_name')
1078
-                        . '&nbsp;</a>&nbsp;',
1079
-                    '</h3>'
1080
-                );
1081
-            }
1082
-            $DTT_ID   = ! empty($this->_req_data['datetime_id']) ? absint($this->_req_data['datetime_id']) : 0;
1083
-            $datetime = EEM_Datetime::instance()->get_one_by_ID($DTT_ID);
1084
-            if ($datetime instanceof EE_Datetime && $this->_template_args['admin_page_header'] !== '') {
1085
-                $this->_template_args['admin_page_header'] = substr(
1086
-                    $this->_template_args['admin_page_header'],
1087
-                    0,
1088
-                    -5
1089
-                );
1090
-                $this->_template_args['admin_page_header'] .= ' &nbsp;<span class="drk-grey-text">';
1091
-                $this->_template_args['admin_page_header'] .= '<span class="dashicons dashicons-calendar"></span>';
1092
-                $this->_template_args['admin_page_header'] .= $datetime->name();
1093
-                $this->_template_args['admin_page_header'] .= ' ( ' . $datetime->start_date() . ' )';
1094
-                $this->_template_args['admin_page_header'] .= '</span></h3>';
1095
-            }
1096
-        }
1097
-        $this->_template_args['after_list_table'] = $this->_display_legend($this->_registration_legend_items());
1098
-        $this->display_admin_list_table_page_with_no_sidebar();
1099
-    }
1100
-
1101
-
1102
-    /**
1103
-     * This sets the _registration property for the registration details screen
1104
-     *
1105
-     * @access private
1106
-     * @return bool
1107
-     * @throws EE_Error
1108
-     * @throws InvalidArgumentException
1109
-     * @throws InvalidDataTypeException
1110
-     * @throws InvalidInterfaceException
1111
-     */
1112
-    private function _set_registration_object()
1113
-    {
1114
-        //get out if we've already set the object
1115
-        if ($this->_registration instanceof EE_Registration) {
1116
-            return true;
1117
-        }
1118
-        $REG    = EEM_Registration::instance();
1119
-        $REG_ID = ( ! empty($this->_req_data['_REG_ID'])) ? absint($this->_req_data['_REG_ID']) : false;
1120
-        if ($this->_registration = $REG->get_one_by_ID($REG_ID)) {
1121
-            return true;
1122
-        } else {
1123
-            $error_msg = sprintf(
1124
-                esc_html__(
1125
-                    'An error occurred and the details for Registration ID #%s could not be retrieved.',
1126
-                    'event_espresso'
1127
-                ),
1128
-                $REG_ID
1129
-            );
1130
-            EE_Error::add_error($error_msg, __FILE__, __FUNCTION__, __LINE__);
1131
-            $this->_registration = null;
1132
-            return false;
1133
-        }
1134
-    }
1135
-
1136
-
1137
-    /**
1138
-     * Used to retrieve registrations for the list table.
1139
-     *
1140
-     * @param int  $per_page
1141
-     * @param bool $count
1142
-     * @param bool $this_month
1143
-     * @param bool $today
1144
-     * @return EE_Registration[]|int
1145
-     * @throws EE_Error
1146
-     * @throws InvalidArgumentException
1147
-     * @throws InvalidDataTypeException
1148
-     * @throws InvalidInterfaceException
1149
-     */
1150
-    public function get_registrations(
1151
-        $per_page = 10,
1152
-        $count = false,
1153
-        $this_month = false,
1154
-        $today = false
1155
-    ) {
1156
-        if ($this_month) {
1157
-            $this->_req_data['status'] = 'month';
1158
-        }
1159
-        if ($today) {
1160
-            $this->_req_data['status'] = 'today';
1161
-        }
1162
-        $query_params = $this->_get_registration_query_parameters($this->_req_data, $per_page, $count);
1163
-        /**
1164
-         * Override the default groupby added by EEM_Base so that sorts with multiple order bys work as expected
1165
-         * @link https://events.codebasehq.com/projects/event-espresso/tickets/10093
1166
-         * @see EEM_Base::get_all()
1167
-         */
1168
-        $query_params['group_by'] = '';
1169
-
1170
-        return $count
1171
-            ? EEM_Registration::instance()->count($query_params)
1172
-            /** @type EE_Registration[] */
1173
-            : EEM_Registration::instance()->get_all($query_params);
1174
-    }
1175
-
1176
-
1177
-    /**
1178
-     * Retrieves the query parameters to be used by the Registration model for getting registrations.
1179
-     * Note: this listens to values on the request for some of the query parameters.
1180
-     *
1181
-     * @param array $request
1182
-     * @param int   $per_page
1183
-     * @param bool  $count
1184
-     * @return array
1185
-     * @throws EE_Error
1186
-     */
1187
-    protected function _get_registration_query_parameters(
1188
-        $request = array(),
1189
-        $per_page = 10,
1190
-        $count = false
1191
-    ) {
1192
-
1193
-        $query_params = array(
1194
-            0                          => $this->_get_where_conditions_for_registrations_query(
1195
-                $request
1196
-            ),
1197
-            'caps'                     => EEM_Registration::caps_read_admin,
1198
-            'default_where_conditions' => 'this_model_only',
1199
-        );
1200
-        if (! $count) {
1201
-            $query_params = array_merge(
1202
-                $query_params,
1203
-                $this->_get_orderby_for_registrations_query(),
1204
-                $this->_get_limit($per_page)
1205
-            );
1206
-        }
1207
-
1208
-        return $query_params;
1209
-    }
1210
-
1211
-
1212
-    /**
1213
-     * This will add ATT_ID to the provided $where array for EE model query parameters.
1214
-     *
1215
-     * @param array $request usually the same as $this->_req_data but not necessarily
1216
-     * @return array
1217
-     */
1218
-    protected function addAttendeeIdToWhereConditions(array $request)
1219
-    {
1220
-        $where = array();
1221
-        if (! empty($request['ATT_ID'])) {
1222
-            $where['ATT_ID'] = absint($request['ATT_ID']);
1223
-        }
1224
-        return $where;
1225
-    }
1226
-
1227
-
1228
-    /**
1229
-     * This will add EVT_ID to the provided $where array for EE model query parameters.
1230
-     *
1231
-     * @param array $request usually the same as $this->_req_data but not necessarily
1232
-     * @return array
1233
-     */
1234
-    protected function _add_event_id_to_where_conditions(array $request)
1235
-    {
1236
-        $where = array();
1237
-        if (! empty($request['event_id'])) {
1238
-            $where['EVT_ID'] = absint($request['event_id']);
1239
-        }
1240
-        return $where;
1241
-    }
1242
-
1243
-
1244
-    /**
1245
-     * Adds category ID if it exists in the request to the where conditions for the registrations query.
1246
-     *
1247
-     * @param array $request usually the same as $this->_req_data but not necessarily
1248
-     * @return array
1249
-     */
1250
-    protected function _add_category_id_to_where_conditions(array $request)
1251
-    {
1252
-        $where = array();
1253
-        if (! empty($request['EVT_CAT']) && (int)$request['EVT_CAT'] !== -1) {
1254
-            $where['Event.Term_Taxonomy.term_id'] = absint($request['EVT_CAT']);
1255
-        }
1256
-        return $where;
1257
-    }
1258
-
1259
-
1260
-    /**
1261
-     * Adds the datetime ID if it exists in the request to the where conditions for the registrations query.
1262
-     *
1263
-     * @param array $request usually the same as $this->_req_data but not necessarily
1264
-     * @return array
1265
-     */
1266
-    protected function _add_datetime_id_to_where_conditions(array $request)
1267
-    {
1268
-        $where = array();
1269
-        if (! empty($request['datetime_id'])) {
1270
-            $where['Ticket.Datetime.DTT_ID'] = absint($request['datetime_id']);
1271
-        }
1272
-        if (! empty($request['DTT_ID'])) {
1273
-            $where['Ticket.Datetime.DTT_ID'] = absint($request['DTT_ID']);
1274
-        }
1275
-        return $where;
1276
-    }
1277
-
1278
-
1279
-    /**
1280
-     * Adds the correct registration status to the where conditions for the registrations query.
1281
-     *
1282
-     * @param array $request usually the same as $this->_req_data but not necessarily
1283
-     * @return array
1284
-     */
1285
-    protected function _add_registration_status_to_where_conditions(array $request)
1286
-    {
1287
-        $where = array();
1288
-        $view = EEH_Array::is_set($request, 'status', '');
1289
-        $registration_status = ! empty($request['_reg_status'])
1290
-            ? sanitize_text_field($request['_reg_status'])
1291
-            : '';
1292
-
1293
-        /*
33
+	/**
34
+	 * @var EE_Registration
35
+	 */
36
+	private $_registration;
37
+
38
+	/**
39
+	 * @var EE_Event
40
+	 */
41
+	private $_reg_event;
42
+
43
+	/**
44
+	 * @var EE_Session
45
+	 */
46
+	private $_session;
47
+
48
+	private static $_reg_status;
49
+
50
+	/**
51
+	 * Form for displaying the custom questions for this registration.
52
+	 * This gets used a few times throughout the request so its best to cache it
53
+	 *
54
+	 * @var EE_Registration_Custom_Questions_Form
55
+	 */
56
+	protected $_reg_custom_questions_form = null;
57
+
58
+
59
+	/**
60
+	 *        constructor
61
+	 *
62
+	 * @Constructor
63
+	 * @access public
64
+	 * @param bool $routing
65
+	 * @return Registrations_Admin_Page
66
+	 */
67
+	public function __construct($routing = true)
68
+	{
69
+		parent::__construct($routing);
70
+		add_action('wp_loaded', array($this, 'wp_loaded'));
71
+	}
72
+
73
+
74
+	public function wp_loaded()
75
+	{
76
+		// when adding a new registration...
77
+		if (isset($this->_req_data['action']) && $this->_req_data['action'] === 'new_registration') {
78
+			EE_System::do_not_cache();
79
+			if (! isset($this->_req_data['processing_registration'])
80
+				 || absint($this->_req_data['processing_registration']) !== 1
81
+			) {
82
+				// and it's NOT the attendee information reg step
83
+				// force cookie expiration by setting time to last week
84
+				setcookie('ee_registration_added', 0, time() - WEEK_IN_SECONDS, '/');
85
+				// and update the global
86
+				$_COOKIE['ee_registration_added'] = 0;
87
+			}
88
+		}
89
+	}
90
+
91
+
92
+	protected function _init_page_props()
93
+	{
94
+		$this->page_slug        = REG_PG_SLUG;
95
+		$this->_admin_base_url  = REG_ADMIN_URL;
96
+		$this->_admin_base_path = REG_ADMIN;
97
+		$this->page_label       = esc_html__('Registrations', 'event_espresso');
98
+		$this->_cpt_routes      = array(
99
+			'add_new_attendee' => 'espresso_attendees',
100
+			'edit_attendee'    => 'espresso_attendees',
101
+			'insert_attendee'  => 'espresso_attendees',
102
+			'update_attendee'  => 'espresso_attendees',
103
+		);
104
+		$this->_cpt_model_names = array(
105
+			'add_new_attendee' => 'EEM_Attendee',
106
+			'edit_attendee'    => 'EEM_Attendee',
107
+		);
108
+		$this->_cpt_edit_routes = array(
109
+			'espresso_attendees' => 'edit_attendee',
110
+		);
111
+		$this->_pagenow_map     = array(
112
+			'add_new_attendee' => 'post-new.php',
113
+			'edit_attendee'    => 'post.php',
114
+			'trash'            => 'post.php',
115
+		);
116
+		add_action('edit_form_after_title', array($this, 'after_title_form_fields'), 10);
117
+		//add filters so that the comment urls don't take users to a confusing 404 page
118
+		add_filter('get_comment_link', array($this, 'clear_comment_link'), 10, 3);
119
+	}
120
+
121
+
122
+	public function clear_comment_link($link, $comment, $args)
123
+	{
124
+		//gotta make sure this only happens on this route
125
+		$post_type = get_post_type($comment->comment_post_ID);
126
+		if ($post_type === 'espresso_attendees') {
127
+			return '#commentsdiv';
128
+		}
129
+		return $link;
130
+	}
131
+
132
+
133
+	protected function _ajax_hooks()
134
+	{
135
+		//todo: all hooks for registrations ajax goes in here
136
+		add_action('wp_ajax_toggle_checkin_status', array($this, 'toggle_checkin_status'));
137
+	}
138
+
139
+
140
+	protected function _define_page_props()
141
+	{
142
+		$this->_admin_page_title = $this->page_label;
143
+		$this->_labels           = array(
144
+			'buttons'                      => array(
145
+				'add-registrant'      => esc_html__('Add New Registration', 'event_espresso'),
146
+				'add-attendee'        => esc_html__('Add Contact', 'event_espresso'),
147
+				'edit'                => esc_html__('Edit Contact', 'event_espresso'),
148
+				'report'              => esc_html__("Event Registrations CSV Report", "event_espresso"),
149
+				'report_all'          => esc_html__('All Registrations CSV Report', 'event_espresso'),
150
+				'report_filtered'     => esc_html__('Filtered CSV Report', 'event_espresso'),
151
+				'contact_list_report' => esc_html__('Contact List Report', 'event_espresso'),
152
+				'contact_list_export' => esc_html__("Export Data", "event_espresso"),
153
+			),
154
+			'publishbox'                   => array(
155
+				'add_new_attendee' => esc_html__("Add Contact Record", 'event_espresso'),
156
+				'edit_attendee'    => esc_html__("Update Contact Record", 'event_espresso'),
157
+			),
158
+			'hide_add_button_on_cpt_route' => array(
159
+				'edit_attendee' => true,
160
+			),
161
+		);
162
+	}
163
+
164
+
165
+	/**
166
+	 *        grab url requests and route them
167
+	 *
168
+	 * @access private
169
+	 * @return void
170
+	 */
171
+	public function _set_page_routes()
172
+	{
173
+		$this->_get_registration_status_array();
174
+		$reg_id             = ! empty($this->_req_data['_REG_ID']) && ! is_array($this->_req_data['_REG_ID'])
175
+			? $this->_req_data['_REG_ID'] : 0;
176
+		$reg_id = empty($reg_id) && ! empty($this->_req_data['reg_status_change_form']['REG_ID'])
177
+			? $this->_req_data['reg_status_change_form']['REG_ID']
178
+			: $reg_id;
179
+		$att_id             = ! empty($this->_req_data['ATT_ID']) && ! is_array($this->_req_data['ATT_ID'])
180
+			? $this->_req_data['ATT_ID'] : 0;
181
+		$att_id             = ! empty($this->_req_data['post']) && ! is_array($this->_req_data['post'])
182
+			? $this->_req_data['post']
183
+			: $att_id;
184
+		$this->_page_routes = array(
185
+			'default'                            => array(
186
+				'func'       => '_registrations_overview_list_table',
187
+				'capability' => 'ee_read_registrations',
188
+			),
189
+			'view_registration'                  => array(
190
+				'func'       => '_registration_details',
191
+				'capability' => 'ee_read_registration',
192
+				'obj_id'     => $reg_id,
193
+			),
194
+			'edit_registration'                  => array(
195
+				'func'               => '_update_attendee_registration_form',
196
+				'noheader'           => true,
197
+				'headers_sent_route' => 'view_registration',
198
+				'capability'         => 'ee_edit_registration',
199
+				'obj_id'             => $reg_id,
200
+				'_REG_ID'            => $reg_id,
201
+			),
202
+			'trash_registrations'                => array(
203
+				'func'       => '_trash_or_restore_registrations',
204
+				'args'       => array('trash' => true),
205
+				'noheader'   => true,
206
+				'capability' => 'ee_delete_registrations',
207
+			),
208
+			'restore_registrations'              => array(
209
+				'func'       => '_trash_or_restore_registrations',
210
+				'args'       => array('trash' => false),
211
+				'noheader'   => true,
212
+				'capability' => 'ee_delete_registrations',
213
+			),
214
+			'delete_registrations'               => array(
215
+				'func'       => '_delete_registrations',
216
+				'noheader'   => true,
217
+				'capability' => 'ee_delete_registrations',
218
+			),
219
+			'new_registration'                   => array(
220
+				'func'       => 'new_registration',
221
+				'capability' => 'ee_edit_registrations',
222
+			),
223
+			'process_reg_step'                   => array(
224
+				'func'       => 'process_reg_step',
225
+				'noheader'   => true,
226
+				'capability' => 'ee_edit_registrations',
227
+			),
228
+			'redirect_to_txn'                    => array(
229
+				'func'       => 'redirect_to_txn',
230
+				'noheader'   => true,
231
+				'capability' => 'ee_edit_registrations',
232
+			),
233
+			'change_reg_status'                  => array(
234
+				'func'       => '_change_reg_status',
235
+				'noheader'   => true,
236
+				'capability' => 'ee_edit_registration',
237
+				'obj_id'     => $reg_id,
238
+			),
239
+			'approve_registration'               => array(
240
+				'func'       => 'approve_registration',
241
+				'noheader'   => true,
242
+				'capability' => 'ee_edit_registration',
243
+				'obj_id'     => $reg_id,
244
+			),
245
+			'approve_and_notify_registration'    => array(
246
+				'func'       => 'approve_registration',
247
+				'noheader'   => true,
248
+				'args'       => array(true),
249
+				'capability' => 'ee_edit_registration',
250
+				'obj_id'     => $reg_id,
251
+			),
252
+			'approve_registrations'               => array(
253
+				'func'       => 'bulk_action_on_registrations',
254
+				'noheader'   => true,
255
+				'capability' => 'ee_edit_registrations',
256
+				'args' => array('approve')
257
+			),
258
+			'approve_and_notify_registrations'               => array(
259
+				'func'       => 'bulk_action_on_registrations',
260
+				'noheader'   => true,
261
+				'capability' => 'ee_edit_registrations',
262
+				'args' => array('approve', true)
263
+			),
264
+			'decline_registration'               => array(
265
+				'func'       => 'decline_registration',
266
+				'noheader'   => true,
267
+				'capability' => 'ee_edit_registration',
268
+				'obj_id'     => $reg_id,
269
+			),
270
+			'decline_and_notify_registration'    => array(
271
+				'func'       => 'decline_registration',
272
+				'noheader'   => true,
273
+				'args'       => array(true),
274
+				'capability' => 'ee_edit_registration',
275
+				'obj_id'     => $reg_id,
276
+			),
277
+			'decline_registrations'               => array(
278
+				'func'       => 'bulk_action_on_registrations',
279
+				'noheader'   => true,
280
+				'capability' => 'ee_edit_registrations',
281
+				'args' => array('decline')
282
+			),
283
+			'decline_and_notify_registrations'    => array(
284
+				'func'       => 'bulk_action_on_registrations',
285
+				'noheader'   => true,
286
+				'capability' => 'ee_edit_registrations',
287
+				'args' => array('decline', true)
288
+			),
289
+			'pending_registration'               => array(
290
+				'func'       => 'pending_registration',
291
+				'noheader'   => true,
292
+				'capability' => 'ee_edit_registration',
293
+				'obj_id'     => $reg_id,
294
+			),
295
+			'pending_and_notify_registration'    => array(
296
+				'func'       => 'pending_registration',
297
+				'noheader'   => true,
298
+				'args'       => array(true),
299
+				'capability' => 'ee_edit_registration',
300
+				'obj_id'     => $reg_id,
301
+			),
302
+			'pending_registrations'               => array(
303
+				'func'       => 'bulk_action_on_registrations',
304
+				'noheader'   => true,
305
+				'capability' => 'ee_edit_registrations',
306
+				'args' => array('pending')
307
+			),
308
+			'pending_and_notify_registrations'    => array(
309
+				'func'       => 'bulk_action_on_registrations',
310
+				'noheader'   => true,
311
+				'capability' => 'ee_edit_registrations',
312
+				'args' => array('pending', true)
313
+			),
314
+			'no_approve_registration'            => array(
315
+				'func'       => 'not_approve_registration',
316
+				'noheader'   => true,
317
+				'capability' => 'ee_edit_registration',
318
+				'obj_id'     => $reg_id,
319
+			),
320
+			'no_approve_and_notify_registration' => array(
321
+				'func'       => 'not_approve_registration',
322
+				'noheader'   => true,
323
+				'args'       => array(true),
324
+				'capability' => 'ee_edit_registration',
325
+				'obj_id'     => $reg_id,
326
+			),
327
+			'no_approve_registrations'            => array(
328
+				'func'       => 'bulk_action_on_registrations',
329
+				'noheader'   => true,
330
+				'capability' => 'ee_edit_registrations',
331
+				'args' => array('not_approve')
332
+			),
333
+			'no_approve_and_notify_registrations' => array(
334
+				'func'       => 'bulk_action_on_registrations',
335
+				'noheader'   => true,
336
+				'capability' => 'ee_edit_registrations',
337
+				'args' => array('not_approve', true)
338
+			),
339
+			'cancel_registration'                => array(
340
+				'func'       => 'cancel_registration',
341
+				'noheader'   => true,
342
+				'capability' => 'ee_edit_registration',
343
+				'obj_id'     => $reg_id,
344
+			),
345
+			'cancel_and_notify_registration'     => array(
346
+				'func'       => 'cancel_registration',
347
+				'noheader'   => true,
348
+				'args'       => array(true),
349
+				'capability' => 'ee_edit_registration',
350
+				'obj_id'     => $reg_id,
351
+			),
352
+			'cancel_registrations'                => array(
353
+				'func'       => 'bulk_action_on_registrations',
354
+				'noheader'   => true,
355
+				'capability' => 'ee_edit_registrations',
356
+				'args' => array('cancel')
357
+			),
358
+			'cancel_and_notify_registrations'     => array(
359
+				'func'       => 'bulk_action_on_registrations',
360
+				'noheader'   => true,
361
+				'capability' => 'ee_edit_registrations',
362
+				'args' => array('cancel', true)
363
+			),
364
+			'wait_list_registration' => array(
365
+				'func'       => 'wait_list_registration',
366
+				'noheader'   => true,
367
+				'capability' => 'ee_edit_registration',
368
+				'obj_id'     => $reg_id,
369
+			),
370
+			'wait_list_and_notify_registration' => array(
371
+				'func'       => 'wait_list_registration',
372
+				'noheader'   => true,
373
+				'args'       => array(true),
374
+				'capability' => 'ee_edit_registration',
375
+				'obj_id'     => $reg_id,
376
+			),
377
+			'contact_list'                       => array(
378
+				'func'       => '_attendee_contact_list_table',
379
+				'capability' => 'ee_read_contacts',
380
+			),
381
+			'add_new_attendee'                   => array(
382
+				'func' => '_create_new_cpt_item',
383
+				'args' => array(
384
+					'new_attendee' => true,
385
+					'capability'   => 'ee_edit_contacts',
386
+				),
387
+			),
388
+			'edit_attendee'                      => array(
389
+				'func'       => '_edit_cpt_item',
390
+				'capability' => 'ee_edit_contacts',
391
+				'obj_id'     => $att_id,
392
+			),
393
+			'duplicate_attendee'                 => array(
394
+				'func'       => '_duplicate_attendee',
395
+				'noheader'   => true,
396
+				'capability' => 'ee_edit_contacts',
397
+				'obj_id'     => $att_id,
398
+			),
399
+			'insert_attendee'                    => array(
400
+				'func'       => '_insert_or_update_attendee',
401
+				'args'       => array(
402
+					'new_attendee' => true,
403
+				),
404
+				'noheader'   => true,
405
+				'capability' => 'ee_edit_contacts',
406
+			),
407
+			'update_attendee'                    => array(
408
+				'func'       => '_insert_or_update_attendee',
409
+				'args'       => array(
410
+					'new_attendee' => false,
411
+				),
412
+				'noheader'   => true,
413
+				'capability' => 'ee_edit_contacts',
414
+				'obj_id'     => $att_id,
415
+			),
416
+			'trash_attendees' => array(
417
+				'func' => '_trash_or_restore_attendees',
418
+				'args' => array(
419
+					'trash' => 'true'
420
+				),
421
+				'noheader' => true,
422
+				'capability' => 'ee_delete_contacts'
423
+			),
424
+			'trash_attendee'                    => array(
425
+				'func'       => '_trash_or_restore_attendees',
426
+				'args'       => array(
427
+					'trash' => true,
428
+				),
429
+				'noheader'   => true,
430
+				'capability' => 'ee_delete_contacts',
431
+				'obj_id'     => $att_id,
432
+			),
433
+			'restore_attendees'                  => array(
434
+				'func'       => '_trash_or_restore_attendees',
435
+				'args'       => array(
436
+					'trash' => false,
437
+				),
438
+				'noheader'   => true,
439
+				'capability' => 'ee_delete_contacts',
440
+				'obj_id'     => $att_id,
441
+			),
442
+			'resend_registration'                => array(
443
+				'func'       => '_resend_registration',
444
+				'noheader'   => true,
445
+				'capability' => 'ee_send_message',
446
+			),
447
+			'registrations_report'               => array(
448
+				'func'       => '_registrations_report',
449
+				'noheader'   => true,
450
+				'capability' => 'ee_read_registrations',
451
+			),
452
+			'contact_list_export'                => array(
453
+				'func'       => '_contact_list_export',
454
+				'noheader'   => true,
455
+				'capability' => 'export',
456
+			),
457
+			'contact_list_report'                => array(
458
+				'func'       => '_contact_list_report',
459
+				'noheader'   => true,
460
+				'capability' => 'ee_read_contacts',
461
+			),
462
+		);
463
+	}
464
+
465
+
466
+	protected function _set_page_config()
467
+	{
468
+		$this->_page_config = array(
469
+			'default'           => array(
470
+				'nav'           => array(
471
+					'label' => esc_html__('Overview', 'event_espresso'),
472
+					'order' => 5,
473
+				),
474
+				'help_tabs'     => array(
475
+					'registrations_overview_help_tab'                       => array(
476
+						'title'    => esc_html__('Registrations Overview', 'event_espresso'),
477
+						'filename' => 'registrations_overview',
478
+					),
479
+					'registrations_overview_table_column_headings_help_tab' => array(
480
+						'title'    => esc_html__('Registrations Table Column Headings', 'event_espresso'),
481
+						'filename' => 'registrations_overview_table_column_headings',
482
+					),
483
+					'registrations_overview_filters_help_tab'               => array(
484
+						'title'    => esc_html__('Registration Filters', 'event_espresso'),
485
+						'filename' => 'registrations_overview_filters',
486
+					),
487
+					'registrations_overview_views_help_tab'                 => array(
488
+						'title'    => esc_html__('Registration Views', 'event_espresso'),
489
+						'filename' => 'registrations_overview_views',
490
+					),
491
+					'registrations_regoverview_other_help_tab'              => array(
492
+						'title'    => esc_html__('Registrations Other', 'event_espresso'),
493
+						'filename' => 'registrations_overview_other',
494
+					),
495
+				),
496
+				'help_tour'     => array('Registration_Overview_Help_Tour'),
497
+				'qtips'         => array('Registration_List_Table_Tips'),
498
+				'list_table'    => 'EE_Registrations_List_Table',
499
+				'require_nonce' => false,
500
+			),
501
+			'view_registration' => array(
502
+				'nav'           => array(
503
+					'label'      => esc_html__('REG Details', 'event_espresso'),
504
+					'order'      => 15,
505
+					'url'        => isset($this->_req_data['_REG_ID'])
506
+						? add_query_arg(array('_REG_ID' => $this->_req_data['_REG_ID']), $this->_current_page_view_url)
507
+						: $this->_admin_base_url,
508
+					'persistent' => false,
509
+				),
510
+				'help_tabs'     => array(
511
+					'registrations_details_help_tab'                    => array(
512
+						'title'    => esc_html__('Registration Details', 'event_espresso'),
513
+						'filename' => 'registrations_details',
514
+					),
515
+					'registrations_details_table_help_tab'              => array(
516
+						'title'    => esc_html__('Registration Details Table', 'event_espresso'),
517
+						'filename' => 'registrations_details_table',
518
+					),
519
+					'registrations_details_form_answers_help_tab'       => array(
520
+						'title'    => esc_html__('Registration Form Answers', 'event_espresso'),
521
+						'filename' => 'registrations_details_form_answers',
522
+					),
523
+					'registrations_details_registrant_details_help_tab' => array(
524
+						'title'    => esc_html__('Contact Details', 'event_espresso'),
525
+						'filename' => 'registrations_details_registrant_details',
526
+					),
527
+				),
528
+				'help_tour'     => array('Registration_Details_Help_Tour'),
529
+				'metaboxes'     => array_merge(
530
+					$this->_default_espresso_metaboxes,
531
+					array('_registration_details_metaboxes')
532
+				),
533
+				'require_nonce' => false,
534
+			),
535
+			'new_registration'  => array(
536
+				'nav'           => array(
537
+					'label'      => esc_html__('Add New Registration', 'event_espresso'),
538
+					'url'        => '#',
539
+					'order'      => 15,
540
+					'persistent' => false,
541
+				),
542
+				'metaboxes'     => $this->_default_espresso_metaboxes,
543
+				'labels'        => array(
544
+					'publishbox' => esc_html__('Save Registration', 'event_espresso'),
545
+				),
546
+				'require_nonce' => false,
547
+			),
548
+			'add_new_attendee'  => array(
549
+				'nav'           => array(
550
+					'label'      => esc_html__('Add Contact', 'event_espresso'),
551
+					'order'      => 15,
552
+					'persistent' => false,
553
+				),
554
+				'metaboxes'     => array_merge(
555
+					$this->_default_espresso_metaboxes,
556
+					array('_publish_post_box', 'attendee_editor_metaboxes')
557
+				),
558
+				'require_nonce' => false,
559
+			),
560
+			'edit_attendee'     => array(
561
+				'nav'           => array(
562
+					'label'      => esc_html__('Edit Contact', 'event_espresso'),
563
+					'order'      => 15,
564
+					'persistent' => false,
565
+					'url'        => isset($this->_req_data['ATT_ID'])
566
+						? add_query_arg(array('ATT_ID' => $this->_req_data['ATT_ID']), $this->_current_page_view_url)
567
+						: $this->_admin_base_url,
568
+				),
569
+				'metaboxes'     => array('attendee_editor_metaboxes'),
570
+				'require_nonce' => false,
571
+			),
572
+			'contact_list'      => array(
573
+				'nav'           => array(
574
+					'label' => esc_html__('Contact List', 'event_espresso'),
575
+					'order' => 20,
576
+				),
577
+				'list_table'    => 'EE_Attendee_Contact_List_Table',
578
+				'help_tabs'     => array(
579
+					'registrations_contact_list_help_tab'                       => array(
580
+						'title'    => esc_html__('Registrations Contact List', 'event_espresso'),
581
+						'filename' => 'registrations_contact_list',
582
+					),
583
+					'registrations_contact-list_table_column_headings_help_tab' => array(
584
+						'title'    => esc_html__('Contact List Table Column Headings', 'event_espresso'),
585
+						'filename' => 'registrations_contact_list_table_column_headings',
586
+					),
587
+					'registrations_contact_list_views_help_tab'                 => array(
588
+						'title'    => esc_html__('Contact List Views', 'event_espresso'),
589
+						'filename' => 'registrations_contact_list_views',
590
+					),
591
+					'registrations_contact_list_other_help_tab'                 => array(
592
+						'title'    => esc_html__('Contact List Other', 'event_espresso'),
593
+						'filename' => 'registrations_contact_list_other',
594
+					),
595
+				),
596
+				'help_tour'     => array('Contact_List_Help_Tour'),
597
+				'metaboxes'     => array(),
598
+				'require_nonce' => false,
599
+			),
600
+			//override default cpt routes
601
+			'create_new'        => '',
602
+			'edit'              => '',
603
+		);
604
+	}
605
+
606
+
607
+	/**
608
+	 * The below methods aren't used by this class currently
609
+	 */
610
+	protected function _add_screen_options()
611
+	{
612
+	}
613
+
614
+
615
+	protected function _add_feature_pointers()
616
+	{
617
+	}
618
+
619
+
620
+	public function admin_init()
621
+	{
622
+		EE_Registry::$i18n_js_strings['update_att_qstns'] = esc_html__(
623
+			'click "Update Registration Questions" to save your changes',
624
+			'event_espresso'
625
+		);
626
+	}
627
+
628
+
629
+	public function admin_notices()
630
+	{
631
+	}
632
+
633
+
634
+	public function admin_footer_scripts()
635
+	{
636
+	}
637
+
638
+
639
+	/**
640
+	 *        get list of registration statuses
641
+	 *
642
+	 * @access private
643
+	 * @return void
644
+	 * @throws EE_Error
645
+	 */
646
+	private function _get_registration_status_array()
647
+	{
648
+		self::$_reg_status = EEM_Registration::reg_status_array(array(), true);
649
+	}
650
+
651
+
652
+	protected function _add_screen_options_default()
653
+	{
654
+		$this->_per_page_screen_option();
655
+	}
656
+
657
+
658
+	protected function _add_screen_options_contact_list()
659
+	{
660
+		$page_title              = $this->_admin_page_title;
661
+		$this->_admin_page_title = esc_html__("Contacts", 'event_espresso');
662
+		$this->_per_page_screen_option();
663
+		$this->_admin_page_title = $page_title;
664
+	}
665
+
666
+
667
+	public function load_scripts_styles()
668
+	{
669
+		//style
670
+		wp_register_style(
671
+			'espresso_reg',
672
+			REG_ASSETS_URL . 'espresso_registrations_admin.css',
673
+			array('ee-admin-css'),
674
+			EVENT_ESPRESSO_VERSION
675
+		);
676
+		wp_enqueue_style('espresso_reg');
677
+		//script
678
+		wp_register_script(
679
+			'espresso_reg',
680
+			REG_ASSETS_URL . 'espresso_registrations_admin.js',
681
+			array('jquery-ui-datepicker', 'jquery-ui-draggable', 'ee_admin_js'),
682
+			EVENT_ESPRESSO_VERSION,
683
+			true
684
+		);
685
+		wp_enqueue_script('espresso_reg');
686
+	}
687
+
688
+
689
+	public function load_scripts_styles_edit_attendee()
690
+	{
691
+		//stuff to only show up on our attendee edit details page.
692
+		$attendee_details_translations = array(
693
+			'att_publish_text' => sprintf(
694
+				esc_html__('Created on: <b>%1$s</b>', 'event_espresso'),
695
+				$this->_cpt_model_obj->get_datetime('ATT_created')
696
+			),
697
+		);
698
+		wp_localize_script('espresso_reg', 'ATTENDEE_DETAILS', $attendee_details_translations);
699
+		wp_enqueue_script('jquery-validate');
700
+	}
701
+
702
+
703
+	public function load_scripts_styles_view_registration()
704
+	{
705
+		//styles
706
+		wp_enqueue_style('espresso-ui-theme');
707
+		//scripts
708
+		$this->_get_reg_custom_questions_form($this->_registration->ID());
709
+		$this->_reg_custom_questions_form->wp_enqueue_scripts(true);
710
+	}
711
+
712
+
713
+	public function load_scripts_styles_contact_list()
714
+	{
715
+		wp_deregister_style('espresso_reg');
716
+		wp_register_style(
717
+			'espresso_att',
718
+			REG_ASSETS_URL . 'espresso_attendees_admin.css',
719
+			array('ee-admin-css'),
720
+			EVENT_ESPRESSO_VERSION
721
+		);
722
+		wp_enqueue_style('espresso_att');
723
+	}
724
+
725
+
726
+	public function load_scripts_styles_new_registration()
727
+	{
728
+		wp_register_script(
729
+			'ee-spco-for-admin',
730
+			REG_ASSETS_URL . 'spco_for_admin.js',
731
+			array('underscore', 'jquery'),
732
+			EVENT_ESPRESSO_VERSION,
733
+			true
734
+		);
735
+		wp_enqueue_script('ee-spco-for-admin');
736
+		add_filter('FHEE__EED_Ticket_Selector__load_tckt_slctr_assets', '__return_true');
737
+		EE_Form_Section_Proper::wp_enqueue_scripts();
738
+		EED_Ticket_Selector::load_tckt_slctr_assets();
739
+		EE_Datepicker_Input::enqueue_styles_and_scripts();
740
+	}
741
+
742
+
743
+	public function AHEE__EE_Admin_Page__route_admin_request_resend_registration()
744
+	{
745
+		add_filter('FHEE_load_EE_messages', '__return_true');
746
+	}
747
+
748
+
749
+	public function AHEE__EE_Admin_Page__route_admin_request_approve_registration()
750
+	{
751
+		add_filter('FHEE_load_EE_messages', '__return_true');
752
+	}
753
+
754
+
755
+	protected function _set_list_table_views_default()
756
+	{
757
+		//for notification related bulk actions we need to make sure only active messengers have an option.
758
+		EED_Messages::set_autoloaders();
759
+		/** @type EE_Message_Resource_Manager $message_resource_manager */
760
+		$message_resource_manager = EE_Registry::instance()->load_lib('Message_Resource_Manager');
761
+		$active_mts               = $message_resource_manager->list_of_active_message_types();
762
+		//key= bulk_action_slug, value= message type.
763
+		$match_array = array(
764
+			'approve_registrations'    => 'registration',
765
+			'decline_registrations'    => 'declined_registration',
766
+			'pending_registrations'    => 'pending_approval',
767
+			'no_approve_registrations' => 'not_approved_registration',
768
+			'cancel_registrations'     => 'cancelled_registration',
769
+		);
770
+		$can_send = EE_Registry::instance()->CAP->current_user_can(
771
+			'ee_send_message',
772
+			'batch_send_messages'
773
+		);
774
+		/** setup reg status bulk actions **/
775
+		$def_reg_status_actions['approve_registrations'] = esc_html__('Approve Registrations', 'event_espresso');
776
+		if ($can_send && in_array($match_array['approve_registrations'], $active_mts, true)) {
777
+				$def_reg_status_actions['approve_and_notify_registrations'] = esc_html__(
778
+					'Approve and Notify Registrations',
779
+					'event_espresso'
780
+				);
781
+		}
782
+		$def_reg_status_actions['decline_registrations'] = esc_html__('Decline Registrations', 'event_espresso');
783
+		if ($can_send && in_array($match_array['decline_registrations'], $active_mts, true)) {
784
+				$def_reg_status_actions['decline_and_notify_registrations'] = esc_html__(
785
+					'Decline and Notify Registrations',
786
+					'event_espresso'
787
+				);
788
+		}
789
+		$def_reg_status_actions['pending_registrations'] = esc_html__(
790
+			'Set Registrations to Pending Payment',
791
+			'event_espresso'
792
+		);
793
+		if ($can_send && in_array($match_array['pending_registrations'], $active_mts, true)) {
794
+				$def_reg_status_actions['pending_and_notify_registrations'] = esc_html__(
795
+					'Set Registrations to Pending Payment and Notify',
796
+					'event_espresso'
797
+				);
798
+		}
799
+		$def_reg_status_actions['no_approve_registrations'] = esc_html__(
800
+			'Set Registrations to Not Approved',
801
+			'event_espresso'
802
+		);
803
+		if ($can_send && in_array($match_array['no_approve_registrations'], $active_mts, true)) {
804
+				$def_reg_status_actions['no_approve_and_notify_registrations'] = esc_html__(
805
+					'Set Registrations to Not Approved and Notify',
806
+					'event_espresso'
807
+				);
808
+		}
809
+		$def_reg_status_actions['cancel_registrations'] = esc_html__('Cancel Registrations', 'event_espresso');
810
+		if ($can_send && in_array($match_array['cancel_registrations'], $active_mts, true)) {
811
+				$def_reg_status_actions['cancel_and_notify_registrations'] = esc_html__(
812
+					'Cancel Registrations and Notify',
813
+					'event_espresso'
814
+				);
815
+		}
816
+		$def_reg_status_actions = apply_filters(
817
+			'FHEE__Registrations_Admin_Page___set_list_table_views_default__def_reg_status_actions_array',
818
+			$def_reg_status_actions,
819
+			$active_mts,
820
+			$can_send
821
+		);
822
+
823
+		$this->_views = array(
824
+			'all'   => array(
825
+				'slug'        => 'all',
826
+				'label'       => esc_html__('View All Registrations', 'event_espresso'),
827
+				'count'       => 0,
828
+				'bulk_action' => array_merge($def_reg_status_actions, array(
829
+					'trash_registrations' => esc_html__('Trash Registrations', 'event_espresso'),
830
+				)),
831
+			),
832
+			'month' => array(
833
+				'slug'        => 'month',
834
+				'label'       => esc_html__('This Month', 'event_espresso'),
835
+				'count'       => 0,
836
+				'bulk_action' => array_merge($def_reg_status_actions, array(
837
+					'trash_registrations' => esc_html__('Trash Registrations', 'event_espresso'),
838
+				)),
839
+			),
840
+			'today' => array(
841
+				'slug'        => 'today',
842
+				'label'       => sprintf(
843
+					esc_html__('Today - %s', 'event_espresso'),
844
+					date('M d, Y', current_time('timestamp'))
845
+				),
846
+				'count'       => 0,
847
+				'bulk_action' => array_merge($def_reg_status_actions, array(
848
+					'trash_registrations' => esc_html__('Trash Registrations', 'event_espresso'),
849
+				)),
850
+			),
851
+		);
852
+		if (EE_Registry::instance()->CAP->current_user_can(
853
+			'ee_delete_registrations',
854
+			'espresso_registrations_delete_registration'
855
+		)) {
856
+			$this->_views['incomplete'] = array(
857
+				'slug'        => 'incomplete',
858
+				'label'       => esc_html__('Incomplete', 'event_espresso'),
859
+				'count'       => 0,
860
+				'bulk_action' => array(
861
+					'trash_registrations' => esc_html__('Trash Registrations', 'event_espresso'),
862
+				),
863
+			);
864
+			$this->_views['trash']      = array(
865
+				'slug'        => 'trash',
866
+				'label'       => esc_html__('Trash', 'event_espresso'),
867
+				'count'       => 0,
868
+				'bulk_action' => array(
869
+					'restore_registrations' => esc_html__('Restore Registrations', 'event_espresso'),
870
+					'delete_registrations'  => esc_html__('Delete Registrations Permanently', 'event_espresso'),
871
+				),
872
+			);
873
+		}
874
+	}
875
+
876
+
877
+	protected function _set_list_table_views_contact_list()
878
+	{
879
+		$this->_views = array(
880
+			'in_use' => array(
881
+				'slug'        => 'in_use',
882
+				'label'       => esc_html__('In Use', 'event_espresso'),
883
+				'count'       => 0,
884
+				'bulk_action' => array(
885
+					'trash_attendees' => esc_html__('Move to Trash', 'event_espresso'),
886
+				),
887
+			),
888
+		);
889
+		if (EE_Registry::instance()->CAP->current_user_can('ee_delete_contacts',
890
+			'espresso_registrations_trash_attendees')
891
+		) {
892
+			$this->_views['trash'] = array(
893
+				'slug'        => 'trash',
894
+				'label'       => esc_html__('Trash', 'event_espresso'),
895
+				'count'       => 0,
896
+				'bulk_action' => array(
897
+					'restore_attendees' => esc_html__('Restore from Trash', 'event_espresso'),
898
+				),
899
+			);
900
+		}
901
+	}
902
+
903
+
904
+	protected function _registration_legend_items()
905
+	{
906
+		$fc_items = array(
907
+			'star-icon'        => array(
908
+				'class' => 'dashicons dashicons-star-filled lt-blue-icon ee-icon-size-8',
909
+				'desc'  => esc_html__('This is the Primary Registrant', 'event_espresso'),
910
+			),
911
+			'view_details'     => array(
912
+				'class' => 'dashicons dashicons-clipboard',
913
+				'desc'  => esc_html__('View Registration Details', 'event_espresso'),
914
+			),
915
+			'edit_attendee'    => array(
916
+				'class' => 'ee-icon ee-icon-user-edit ee-icon-size-16',
917
+				'desc'  => esc_html__('Edit Contact Details', 'event_espresso'),
918
+			),
919
+			'view_transaction' => array(
920
+				'class' => 'dashicons dashicons-cart',
921
+				'desc'  => esc_html__('View Transaction Details', 'event_espresso'),
922
+			),
923
+			'view_invoice'     => array(
924
+				'class' => 'dashicons dashicons-media-spreadsheet',
925
+				'desc'  => esc_html__('View Transaction Invoice', 'event_espresso'),
926
+			),
927
+		);
928
+		if (EE_Registry::instance()->CAP->current_user_can(
929
+			'ee_send_message',
930
+			'espresso_registrations_resend_registration'
931
+		)) {
932
+			$fc_items['resend_registration'] = array(
933
+				'class' => 'dashicons dashicons-email-alt',
934
+				'desc'  => esc_html__('Resend Registration Details', 'event_espresso'),
935
+			);
936
+		} else {
937
+			$fc_items['blank'] = array('class' => 'blank', 'desc' => '');
938
+		}
939
+		if (EE_Registry::instance()->CAP->current_user_can(
940
+			'ee_read_global_messages',
941
+			'view_filtered_messages'
942
+		)) {
943
+			$related_for_icon = EEH_MSG_Template::get_message_action_icon('see_notifications_for');
944
+			if (isset($related_for_icon['css_class']) && isset($related_for_icon['label'])) {
945
+				$fc_items['view_related_messages'] = array(
946
+					'class' => $related_for_icon['css_class'],
947
+					'desc'  => $related_for_icon['label'],
948
+				);
949
+			}
950
+		}
951
+		$sc_items = array(
952
+			'approved_status'   => array(
953
+				'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_approved,
954
+				'desc'  => EEH_Template::pretty_status(
955
+					EEM_Registration::status_id_approved,
956
+					false,
957
+					'sentence'
958
+				),
959
+			),
960
+			'pending_status'    => array(
961
+				'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_pending_payment,
962
+				'desc'  => EEH_Template::pretty_status(
963
+					EEM_Registration::status_id_pending_payment,
964
+					false,
965
+					'sentence'
966
+				),
967
+			),
968
+			'wait_list'         => array(
969
+				'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_wait_list,
970
+				'desc'  => EEH_Template::pretty_status(
971
+					EEM_Registration::status_id_wait_list,
972
+					false,
973
+					'sentence'
974
+				),
975
+			),
976
+			'incomplete_status' => array(
977
+				'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_incomplete,
978
+				'desc'  => EEH_Template::pretty_status(
979
+					EEM_Registration::status_id_incomplete,
980
+					false,
981
+					'sentence'
982
+				),
983
+			),
984
+			'not_approved'      => array(
985
+				'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_not_approved,
986
+				'desc'  => EEH_Template::pretty_status(
987
+					EEM_Registration::status_id_not_approved,
988
+					false,
989
+					'sentence'
990
+				),
991
+			),
992
+			'declined_status'   => array(
993
+				'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_declined,
994
+				'desc'  => EEH_Template::pretty_status(
995
+					EEM_Registration::status_id_declined,
996
+					false,
997
+					'sentence'
998
+				),
999
+			),
1000
+			'cancelled_status'  => array(
1001
+				'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_cancelled,
1002
+				'desc'  => EEH_Template::pretty_status(
1003
+					EEM_Registration::status_id_cancelled,
1004
+					false,
1005
+					'sentence'
1006
+				),
1007
+			),
1008
+		);
1009
+		return array_merge($fc_items, $sc_items);
1010
+	}
1011
+
1012
+
1013
+
1014
+	/***************************************        REGISTRATION OVERVIEW        **************************************/
1015
+	/**
1016
+	 * @throws \EE_Error
1017
+	 */
1018
+	protected function _registrations_overview_list_table()
1019
+	{
1020
+		$this->_template_args['admin_page_header'] = '';
1021
+		$EVT_ID                                    = ! empty($this->_req_data['event_id'])
1022
+			? absint($this->_req_data['event_id'])
1023
+			: 0;
1024
+		$ATT_ID = !empty($this->_req_data['ATT_ID'])
1025
+			? absint($this->_req_data['ATT_ID'])
1026
+			: 0;
1027
+		if ($ATT_ID) {
1028
+			$attendee = EEM_Attendee::instance()->get_one_by_ID($ATT_ID);
1029
+			if ($attendee instanceof EE_Attendee) {
1030
+				$this->_template_args['admin_page_header'] = sprintf(
1031
+					esc_html__(
1032
+						'%1$s Viewing registrations for %2$s%3$s',
1033
+						'event_espresso'
1034
+					),
1035
+					'<h3 style="line-height:1.5em;">',
1036
+					'<a href="' . EE_Admin_Page::add_query_args_and_nonce(
1037
+						array(
1038
+							'action' => 'edit_attendee',
1039
+							'post' => $ATT_ID
1040
+						),
1041
+						REG_ADMIN_URL
1042
+					) . '">' . $attendee->full_name() . '</a>',
1043
+					'</h3>'
1044
+				);
1045
+			}
1046
+		}
1047
+		if ($EVT_ID) {
1048
+			if (EE_Registry::instance()->CAP->current_user_can(
1049
+				'ee_edit_registrations',
1050
+				'espresso_registrations_new_registration',
1051
+				$EVT_ID
1052
+			)) {
1053
+				$this->_admin_page_title .= ' ' . $this->get_action_link_or_button(
1054
+					'new_registration',
1055
+					'add-registrant',
1056
+					array('event_id' => $EVT_ID),
1057
+					'add-new-h2'
1058
+				);
1059
+			}
1060
+			$event = EEM_Event::instance()->get_one_by_ID($EVT_ID);
1061
+			if ($event instanceof EE_Event) {
1062
+				$this->_template_args['admin_page_header'] = sprintf(
1063
+					esc_html__(
1064
+						'%s Viewing registrations for the event: %s%s',
1065
+						'event_espresso'
1066
+					),
1067
+					'<h3 style="line-height:1.5em;">',
1068
+					'<br /><a href="'
1069
+						. EE_Admin_Page::add_query_args_and_nonce(
1070
+							array(
1071
+								'action' => 'edit',
1072
+								'post'   => $event->ID(),
1073
+							),
1074
+							EVENTS_ADMIN_URL
1075
+						)
1076
+						. '">&nbsp;'
1077
+						. $event->get('EVT_name')
1078
+						. '&nbsp;</a>&nbsp;',
1079
+					'</h3>'
1080
+				);
1081
+			}
1082
+			$DTT_ID   = ! empty($this->_req_data['datetime_id']) ? absint($this->_req_data['datetime_id']) : 0;
1083
+			$datetime = EEM_Datetime::instance()->get_one_by_ID($DTT_ID);
1084
+			if ($datetime instanceof EE_Datetime && $this->_template_args['admin_page_header'] !== '') {
1085
+				$this->_template_args['admin_page_header'] = substr(
1086
+					$this->_template_args['admin_page_header'],
1087
+					0,
1088
+					-5
1089
+				);
1090
+				$this->_template_args['admin_page_header'] .= ' &nbsp;<span class="drk-grey-text">';
1091
+				$this->_template_args['admin_page_header'] .= '<span class="dashicons dashicons-calendar"></span>';
1092
+				$this->_template_args['admin_page_header'] .= $datetime->name();
1093
+				$this->_template_args['admin_page_header'] .= ' ( ' . $datetime->start_date() . ' )';
1094
+				$this->_template_args['admin_page_header'] .= '</span></h3>';
1095
+			}
1096
+		}
1097
+		$this->_template_args['after_list_table'] = $this->_display_legend($this->_registration_legend_items());
1098
+		$this->display_admin_list_table_page_with_no_sidebar();
1099
+	}
1100
+
1101
+
1102
+	/**
1103
+	 * This sets the _registration property for the registration details screen
1104
+	 *
1105
+	 * @access private
1106
+	 * @return bool
1107
+	 * @throws EE_Error
1108
+	 * @throws InvalidArgumentException
1109
+	 * @throws InvalidDataTypeException
1110
+	 * @throws InvalidInterfaceException
1111
+	 */
1112
+	private function _set_registration_object()
1113
+	{
1114
+		//get out if we've already set the object
1115
+		if ($this->_registration instanceof EE_Registration) {
1116
+			return true;
1117
+		}
1118
+		$REG    = EEM_Registration::instance();
1119
+		$REG_ID = ( ! empty($this->_req_data['_REG_ID'])) ? absint($this->_req_data['_REG_ID']) : false;
1120
+		if ($this->_registration = $REG->get_one_by_ID($REG_ID)) {
1121
+			return true;
1122
+		} else {
1123
+			$error_msg = sprintf(
1124
+				esc_html__(
1125
+					'An error occurred and the details for Registration ID #%s could not be retrieved.',
1126
+					'event_espresso'
1127
+				),
1128
+				$REG_ID
1129
+			);
1130
+			EE_Error::add_error($error_msg, __FILE__, __FUNCTION__, __LINE__);
1131
+			$this->_registration = null;
1132
+			return false;
1133
+		}
1134
+	}
1135
+
1136
+
1137
+	/**
1138
+	 * Used to retrieve registrations for the list table.
1139
+	 *
1140
+	 * @param int  $per_page
1141
+	 * @param bool $count
1142
+	 * @param bool $this_month
1143
+	 * @param bool $today
1144
+	 * @return EE_Registration[]|int
1145
+	 * @throws EE_Error
1146
+	 * @throws InvalidArgumentException
1147
+	 * @throws InvalidDataTypeException
1148
+	 * @throws InvalidInterfaceException
1149
+	 */
1150
+	public function get_registrations(
1151
+		$per_page = 10,
1152
+		$count = false,
1153
+		$this_month = false,
1154
+		$today = false
1155
+	) {
1156
+		if ($this_month) {
1157
+			$this->_req_data['status'] = 'month';
1158
+		}
1159
+		if ($today) {
1160
+			$this->_req_data['status'] = 'today';
1161
+		}
1162
+		$query_params = $this->_get_registration_query_parameters($this->_req_data, $per_page, $count);
1163
+		/**
1164
+		 * Override the default groupby added by EEM_Base so that sorts with multiple order bys work as expected
1165
+		 * @link https://events.codebasehq.com/projects/event-espresso/tickets/10093
1166
+		 * @see EEM_Base::get_all()
1167
+		 */
1168
+		$query_params['group_by'] = '';
1169
+
1170
+		return $count
1171
+			? EEM_Registration::instance()->count($query_params)
1172
+			/** @type EE_Registration[] */
1173
+			: EEM_Registration::instance()->get_all($query_params);
1174
+	}
1175
+
1176
+
1177
+	/**
1178
+	 * Retrieves the query parameters to be used by the Registration model for getting registrations.
1179
+	 * Note: this listens to values on the request for some of the query parameters.
1180
+	 *
1181
+	 * @param array $request
1182
+	 * @param int   $per_page
1183
+	 * @param bool  $count
1184
+	 * @return array
1185
+	 * @throws EE_Error
1186
+	 */
1187
+	protected function _get_registration_query_parameters(
1188
+		$request = array(),
1189
+		$per_page = 10,
1190
+		$count = false
1191
+	) {
1192
+
1193
+		$query_params = array(
1194
+			0                          => $this->_get_where_conditions_for_registrations_query(
1195
+				$request
1196
+			),
1197
+			'caps'                     => EEM_Registration::caps_read_admin,
1198
+			'default_where_conditions' => 'this_model_only',
1199
+		);
1200
+		if (! $count) {
1201
+			$query_params = array_merge(
1202
+				$query_params,
1203
+				$this->_get_orderby_for_registrations_query(),
1204
+				$this->_get_limit($per_page)
1205
+			);
1206
+		}
1207
+
1208
+		return $query_params;
1209
+	}
1210
+
1211
+
1212
+	/**
1213
+	 * This will add ATT_ID to the provided $where array for EE model query parameters.
1214
+	 *
1215
+	 * @param array $request usually the same as $this->_req_data but not necessarily
1216
+	 * @return array
1217
+	 */
1218
+	protected function addAttendeeIdToWhereConditions(array $request)
1219
+	{
1220
+		$where = array();
1221
+		if (! empty($request['ATT_ID'])) {
1222
+			$where['ATT_ID'] = absint($request['ATT_ID']);
1223
+		}
1224
+		return $where;
1225
+	}
1226
+
1227
+
1228
+	/**
1229
+	 * This will add EVT_ID to the provided $where array for EE model query parameters.
1230
+	 *
1231
+	 * @param array $request usually the same as $this->_req_data but not necessarily
1232
+	 * @return array
1233
+	 */
1234
+	protected function _add_event_id_to_where_conditions(array $request)
1235
+	{
1236
+		$where = array();
1237
+		if (! empty($request['event_id'])) {
1238
+			$where['EVT_ID'] = absint($request['event_id']);
1239
+		}
1240
+		return $where;
1241
+	}
1242
+
1243
+
1244
+	/**
1245
+	 * Adds category ID if it exists in the request to the where conditions for the registrations query.
1246
+	 *
1247
+	 * @param array $request usually the same as $this->_req_data but not necessarily
1248
+	 * @return array
1249
+	 */
1250
+	protected function _add_category_id_to_where_conditions(array $request)
1251
+	{
1252
+		$where = array();
1253
+		if (! empty($request['EVT_CAT']) && (int)$request['EVT_CAT'] !== -1) {
1254
+			$where['Event.Term_Taxonomy.term_id'] = absint($request['EVT_CAT']);
1255
+		}
1256
+		return $where;
1257
+	}
1258
+
1259
+
1260
+	/**
1261
+	 * Adds the datetime ID if it exists in the request to the where conditions for the registrations query.
1262
+	 *
1263
+	 * @param array $request usually the same as $this->_req_data but not necessarily
1264
+	 * @return array
1265
+	 */
1266
+	protected function _add_datetime_id_to_where_conditions(array $request)
1267
+	{
1268
+		$where = array();
1269
+		if (! empty($request['datetime_id'])) {
1270
+			$where['Ticket.Datetime.DTT_ID'] = absint($request['datetime_id']);
1271
+		}
1272
+		if (! empty($request['DTT_ID'])) {
1273
+			$where['Ticket.Datetime.DTT_ID'] = absint($request['DTT_ID']);
1274
+		}
1275
+		return $where;
1276
+	}
1277
+
1278
+
1279
+	/**
1280
+	 * Adds the correct registration status to the where conditions for the registrations query.
1281
+	 *
1282
+	 * @param array $request usually the same as $this->_req_data but not necessarily
1283
+	 * @return array
1284
+	 */
1285
+	protected function _add_registration_status_to_where_conditions(array $request)
1286
+	{
1287
+		$where = array();
1288
+		$view = EEH_Array::is_set($request, 'status', '');
1289
+		$registration_status = ! empty($request['_reg_status'])
1290
+			? sanitize_text_field($request['_reg_status'])
1291
+			: '';
1292
+
1293
+		/*
1294 1294
          * If filtering by registration status, then we show registrations matching that status.
1295 1295
          * If not filtering by specified status, then we show all registrations excluding incomplete registrations
1296 1296
          * UNLESS viewing trashed registrations.
1297 1297
          */
1298
-        if (! empty($registration_status)) {
1299
-            $where['STS_ID'] = $registration_status;
1300
-        } else {
1301
-            //make sure we exclude incomplete registrations, but only if not trashed.
1302
-            if ($view === 'trash') {
1303
-                $where['REG_deleted'] = true;
1304
-            } elseif ($view === 'incomplete') {
1305
-                $where['STS_ID'] = EEM_Registration::status_id_incomplete;
1306
-            } else {
1307
-                $where['STS_ID'] = array('!=', EEM_Registration::status_id_incomplete);
1308
-            }
1309
-        }
1310
-        return $where;
1311
-    }
1312
-
1313
-
1314
-    /**
1315
-     * Adds any provided date restraints to the where conditions for the registrations query.
1316
-     *
1317
-     * @param array $request usually the same as $this->_req_data but not necessarily
1318
-     * @return array
1319
-     * @throws EE_Error
1320
-     * @throws InvalidArgumentException
1321
-     * @throws InvalidDataTypeException
1322
-     * @throws InvalidInterfaceException
1323
-     */
1324
-    protected function _add_date_to_where_conditions(array $request)
1325
-    {
1326
-        $where = array();
1327
-        $view = EEH_Array::is_set($request, 'status', '');
1328
-        $month_range             = ! empty($request['month_range'])
1329
-            ? sanitize_text_field($request['month_range'])
1330
-            : '';
1331
-        $retrieve_for_today      = $view === 'today';
1332
-        $retrieve_for_this_month = $view === 'month';
1333
-
1334
-        if ($retrieve_for_today) {
1335
-            $now               = date('Y-m-d', current_time('timestamp'));
1336
-            $where['REG_date'] = array(
1337
-                'BETWEEN',
1338
-                array(
1339
-                    EEM_Registration::instance()->convert_datetime_for_query(
1340
-                        'REG_date',
1341
-                        $now . ' 00:00:00',
1342
-                        'Y-m-d H:i:s'
1343
-                    ),
1344
-                    EEM_Registration::instance()->convert_datetime_for_query(
1345
-                        'REG_date',
1346
-                        $now . ' 23:59:59',
1347
-                        'Y-m-d H:i:s'
1348
-                    ),
1349
-                ),
1350
-            );
1351
-        } elseif ($retrieve_for_this_month) {
1352
-            $current_year_and_month = date('Y-m', current_time('timestamp'));
1353
-            $days_this_month        = date('t', current_time('timestamp'));
1354
-            $where['REG_date']      = array(
1355
-                'BETWEEN',
1356
-                array(
1357
-                    EEM_Registration::instance()->convert_datetime_for_query(
1358
-                        'REG_date',
1359
-                        $current_year_and_month . '-01 00:00:00',
1360
-                        'Y-m-d H:i:s'
1361
-                    ),
1362
-                    EEM_Registration::instance()->convert_datetime_for_query(
1363
-                        'REG_date',
1364
-                        $current_year_and_month . '-' . $days_this_month . ' 23:59:59',
1365
-                        'Y-m-d H:i:s'
1366
-                    ),
1367
-                ),
1368
-            );
1369
-        } elseif ($month_range) {
1370
-            $pieces          = explode(' ', $month_range, 3);
1371
-            $month_requested = ! empty($pieces[0])
1372
-                ? date('m', \EEH_DTT_Helper::first_of_month_timestamp($pieces[0]))
1373
-                : '';
1374
-            $year_requested  = ! empty($pieces[1])
1375
-                ? $pieces[1]
1376
-                : '';
1377
-            //if there is not a month or year then we can't go further
1378
-            if ($month_requested && $year_requested) {
1379
-                $days_in_month     = date('t', strtotime($year_requested . '-' . $month_requested . '-' . '01'));
1380
-                $where['REG_date'] = array(
1381
-                    'BETWEEN',
1382
-                    array(
1383
-                        EEM_Registration::instance()->convert_datetime_for_query(
1384
-                            'REG_date',
1385
-                            $year_requested . '-' . $month_requested . '-01 00:00:00',
1386
-                            'Y-m-d H:i:s'
1387
-                        ),
1388
-                        EEM_Registration::instance()->convert_datetime_for_query(
1389
-                            'REG_date',
1390
-                            $year_requested . '-' . $month_requested . '-' . $days_in_month . ' 23:59:59',
1391
-                            'Y-m-d H:i:s'
1392
-                        ),
1393
-                    ),
1394
-                );
1395
-            }
1396
-        }
1397
-        return $where;
1398
-    }
1399
-
1400
-
1401
-    /**
1402
-     * Adds any provided search restraints to the where conditions for the registrations query
1403
-     *
1404
-     * @param array $request usually the same as $this->_req_data but not necessarily
1405
-     * @return array
1406
-     */
1407
-    protected function _add_search_to_where_conditions(array $request)
1408
-    {
1409
-        $where = array();
1410
-        if (! empty($request['s'])) {
1411
-            $search_string = '%' . sanitize_text_field($request['s']) . '%';
1412
-            $where['OR*search_conditions'] = array(
1413
-                'Event.EVT_name'                          => array('LIKE', $search_string),
1414
-                'Event.EVT_desc'                          => array('LIKE', $search_string),
1415
-                'Event.EVT_short_desc'                    => array('LIKE', $search_string),
1416
-                'Attendee.ATT_full_name'                  => array('LIKE', $search_string),
1417
-                'Attendee.ATT_fname'                      => array('LIKE', $search_string),
1418
-                'Attendee.ATT_lname'                      => array('LIKE', $search_string),
1419
-                'Attendee.ATT_short_bio'                  => array('LIKE', $search_string),
1420
-                'Attendee.ATT_email'                      => array('LIKE', $search_string),
1421
-                'Attendee.ATT_address'                    => array('LIKE', $search_string),
1422
-                'Attendee.ATT_address2'                   => array('LIKE', $search_string),
1423
-                'Attendee.ATT_city'                       => array('LIKE', $search_string),
1424
-                'REG_final_price'                         => array('LIKE', $search_string),
1425
-                'REG_code'                                => array('LIKE', $search_string),
1426
-                'REG_count'                               => array('LIKE', $search_string),
1427
-                'REG_group_size'                          => array('LIKE', $search_string),
1428
-                'Ticket.TKT_name'                         => array('LIKE', $search_string),
1429
-                'Ticket.TKT_description'                  => array('LIKE', $search_string),
1430
-                'Transaction.Payment.PAY_txn_id_chq_nmbr' => array('LIKE', $search_string),
1431
-            );
1432
-        }
1433
-        return $where;
1434
-    }
1435
-
1436
-
1437
-    /**
1438
-     * Sets up the where conditions for the registrations query.
1439
-     *
1440
-     * @param array $request
1441
-     * @return array
1442
-     * @throws EE_Error
1443
-     */
1444
-    protected function _get_where_conditions_for_registrations_query($request)
1445
-    {
1446
-        return apply_filters(
1447
-            'FHEE__Registrations_Admin_Page___get_where_conditions_for_registrations_query',
1448
-            array_merge(
1449
-                $this->addAttendeeIdToWhereConditions($request),
1450
-                $this->_add_event_id_to_where_conditions($request),
1451
-                $this->_add_category_id_to_where_conditions($request),
1452
-                $this->_add_datetime_id_to_where_conditions($request),
1453
-                $this->_add_registration_status_to_where_conditions($request),
1454
-                $this->_add_date_to_where_conditions($request),
1455
-                $this->_add_search_to_where_conditions($request)
1456
-            ),
1457
-            $request
1458
-        );
1459
-    }
1460
-
1461
-
1462
-    /**
1463
-     * Sets up the orderby for the registrations query.
1464
-     *
1465
-     * @return array
1466
-     */
1467
-    protected function _get_orderby_for_registrations_query()
1468
-    {
1469
-        $orderby_field = ! empty($this->_req_data['orderby'])
1470
-            ? sanitize_text_field($this->_req_data['orderby'])
1471
-            : '';
1472
-        switch ($orderby_field) {
1473
-            case '_REG_ID':
1474
-                $orderby = array('REG_ID');
1475
-                break;
1476
-            case '_Reg_status':
1477
-                $orderby = array('STS_ID');
1478
-                break;
1479
-            case 'ATT_fname':
1480
-                $orderby = array('Attendee.ATT_fname', 'Attendee.ATT_lname');
1481
-                break;
1482
-            case 'ATT_lname':
1483
-                $orderby = array('Attendee.ATT_lname', 'Attendee.ATT_fname');
1484
-                break;
1485
-            case 'event_name':
1486
-                $orderby = array('Event.EVT_name');
1487
-                break;
1488
-            case 'DTT_EVT_start':
1489
-                $orderby = array('Event.Datetime.DTT_EVT_start');
1490
-                break;
1491
-            default: //'REG_date'
1492
-                $orderby = array('REG_date');
1493
-        }
1494
-
1495
-        //order
1496
-        $order = ! empty($this->_req_data['order'])
1497
-            ? sanitize_text_field($this->_req_data['order'])
1498
-            : 'DESC';
1499
-        $orderby = array_combine(
1500
-            $orderby,
1501
-            array_fill(0, count($orderby), $order)
1502
-        );
1503
-        //because there are many registrations with the same date, define
1504
-        //a secondary way to order them, otherwise MySQL seems to be a bit random
1505
-        if (empty($orderby['REG_ID'])) {
1506
-            $orderby['REG_ID'] = $order;
1507
-        }
1508
-        return array('order_by' => $orderby);
1509
-    }
1510
-
1511
-
1512
-    /**
1513
-     * Sets up the limit for the registrations query.
1514
-     *
1515
-     * @param $per_page
1516
-     * @return array
1517
-     */
1518
-    protected function _get_limit($per_page)
1519
-    {
1520
-        $current_page = ! empty($this->_req_data['paged'])
1521
-            ? absint($this->_req_data['paged'])
1522
-            : 1;
1523
-        $per_page     = ! empty($this->_req_data['perpage'])
1524
-            ? $this->_req_data['perpage']
1525
-            : $per_page;
1526
-
1527
-        //-1 means return all results so get out if that's set.
1528
-        if ((int)$per_page === -1) {
1529
-            return array();
1530
-        }
1531
-        $per_page = absint($per_page);
1532
-        $offset   = ($current_page - 1) * $per_page;
1533
-        return array('limit' => array($offset, $per_page));
1534
-    }
1535
-
1536
-
1537
-    public function get_registration_status_array()
1538
-    {
1539
-        return self::$_reg_status;
1540
-    }
1541
-
1542
-
1543
-
1544
-
1545
-    /***************************************        REGISTRATION DETAILS        ***************************************/
1546
-    /**
1547
-     *        generates HTML for the View Registration Details Admin page
1548
-     *
1549
-     * @access protected
1550
-     * @return void
1551
-     * @throws DomainException
1552
-     * @throws EE_Error
1553
-     * @throws InvalidArgumentException
1554
-     * @throws InvalidDataTypeException
1555
-     * @throws InvalidInterfaceException
1556
-     * @throws EntityNotFoundException
1557
-     */
1558
-    protected function _registration_details()
1559
-    {
1560
-        $this->_template_args = array();
1561
-        $this->_set_registration_object();
1562
-        if (is_object($this->_registration)) {
1563
-            $transaction                                   = $this->_registration->transaction()
1564
-                ? $this->_registration->transaction()
1565
-                : EE_Transaction::new_instance();
1566
-            $this->_session                                = $transaction->session_data();
1567
-            $event_id                                      = $this->_registration->event_ID();
1568
-            $this->_template_args['reg_nmbr']['value']     = $this->_registration->ID();
1569
-            $this->_template_args['reg_nmbr']['label']     = esc_html__('Registration Number', 'event_espresso');
1570
-            $this->_template_args['reg_datetime']['value'] = $this->_registration->get_i18n_datetime('REG_date');
1571
-            $this->_template_args['reg_datetime']['label'] = esc_html__('Date', 'event_espresso');
1572
-            $this->_template_args['grand_total']           = $transaction->total();
1573
-            $this->_template_args['currency_sign']         = EE_Registry::instance()->CFG->currency->sign;
1574
-            // link back to overview
1575
-            $this->_template_args['reg_overview_url']            = REG_ADMIN_URL;
1576
-            $this->_template_args['registration']                = $this->_registration;
1577
-            $this->_template_args['filtered_registrations_link'] = EE_Admin_Page::add_query_args_and_nonce(
1578
-                array(
1579
-                    'action'   => 'default',
1580
-                    'event_id' => $event_id,
1581
-                ),
1582
-                REG_ADMIN_URL
1583
-            );
1584
-            $this->_template_args['filtered_transactions_link']  = EE_Admin_Page::add_query_args_and_nonce(
1585
-                array(
1586
-                    'action' => 'default',
1587
-                    'EVT_ID' => $event_id,
1588
-                    'page'   => 'espresso_transactions',
1589
-                ),
1590
-                admin_url('admin.php')
1591
-            );
1592
-            $this->_template_args['event_link']                  = EE_Admin_Page::add_query_args_and_nonce(
1593
-                array(
1594
-                    'page'   => 'espresso_events',
1595
-                    'action' => 'edit',
1596
-                    'post'   => $event_id,
1597
-                ),
1598
-                admin_url('admin.php')
1599
-            );
1600
-            //next and previous links
1601
-            $next_reg                                      = $this->_registration->next(
1602
-                null,
1603
-                array(),
1604
-                'REG_ID'
1605
-            );
1606
-            $this->_template_args['next_registration']     = $next_reg
1607
-                ? $this->_next_link(
1608
-                    EE_Admin_Page::add_query_args_and_nonce(
1609
-                        array(
1610
-                            'action'  => 'view_registration',
1611
-                            '_REG_ID' => $next_reg['REG_ID'],
1612
-                        ),
1613
-                        REG_ADMIN_URL
1614
-                    ),
1615
-                    'dashicons dashicons-arrow-right ee-icon-size-22'
1616
-                )
1617
-                : '';
1618
-            $previous_reg                                  = $this->_registration->previous(
1619
-                null,
1620
-                array(),
1621
-                'REG_ID'
1622
-            );
1623
-            $this->_template_args['previous_registration'] = $previous_reg
1624
-                ? $this->_previous_link(
1625
-                    EE_Admin_Page::add_query_args_and_nonce(
1626
-                        array(
1627
-                            'action'  => 'view_registration',
1628
-                            '_REG_ID' => $previous_reg['REG_ID'],
1629
-                        ),
1630
-                        REG_ADMIN_URL
1631
-                    ),
1632
-                    'dashicons dashicons-arrow-left ee-icon-size-22'
1633
-                )
1634
-                : '';
1635
-            // grab header
1636
-            $template_path                             = REG_TEMPLATE_PATH . 'reg_admin_details_header.template.php';
1637
-            $this->_template_args['REG_ID']            = $this->_registration->ID();
1638
-            $this->_template_args['admin_page_header'] = EEH_Template::display_template(
1639
-                $template_path,
1640
-                $this->_template_args,
1641
-                true
1642
-            );
1643
-        } else {
1644
-            $this->_template_args['admin_page_header'] = $this->display_espresso_notices();
1645
-        }
1646
-        // the details template wrapper
1647
-        $this->display_admin_page_with_sidebar();
1648
-    }
1649
-
1650
-
1651
-    protected function _registration_details_metaboxes()
1652
-    {
1653
-        do_action('AHEE__Registrations_Admin_Page___registration_details_metabox__start', $this);
1654
-        $this->_set_registration_object();
1655
-        $attendee = $this->_registration instanceof EE_Registration ? $this->_registration->attendee() : null;
1656
-        add_meta_box('edit-reg-status-mbox', esc_html__('Registration Status', 'event_espresso'),
1657
-            array($this, 'set_reg_status_buttons_metabox'), $this->wp_page_slug, 'normal', 'high');
1658
-        add_meta_box('edit-reg-details-mbox', esc_html__('Registration Details', 'event_espresso'),
1659
-            array($this, '_reg_details_meta_box'), $this->wp_page_slug, 'normal', 'high');
1660
-        if ($attendee instanceof EE_Attendee
1661
-            && EE_Registry::instance()->CAP->current_user_can(
1662
-                'ee_edit_registration',
1663
-                'edit-reg-questions-mbox',
1664
-                $this->_registration->ID()
1665
-            )
1666
-        ) {
1667
-            add_meta_box(
1668
-                'edit-reg-questions-mbox',
1669
-                esc_html__('Registration Form Answers', 'event_espresso'),
1670
-                array($this, '_reg_questions_meta_box'),
1671
-                $this->wp_page_slug,
1672
-                'normal',
1673
-                'high'
1674
-            );
1675
-        }
1676
-        add_meta_box(
1677
-            'edit-reg-registrant-mbox',
1678
-            esc_html__('Contact Details', 'event_espresso'),
1679
-            array($this, '_reg_registrant_side_meta_box'),
1680
-            $this->wp_page_slug,
1681
-            'side',
1682
-            'high'
1683
-        );
1684
-        if ($this->_registration->group_size() > 1) {
1685
-            add_meta_box(
1686
-                'edit-reg-attendees-mbox',
1687
-                esc_html__('Other Registrations in this Transaction', 'event_espresso'),
1688
-                array($this, '_reg_attendees_meta_box'),
1689
-                $this->wp_page_slug,
1690
-                'normal',
1691
-                'high'
1692
-            );
1693
-        }
1694
-    }
1695
-
1696
-
1697
-    /**
1698
-     * set_reg_status_buttons_metabox
1699
-     *
1700
-     * @access protected
1701
-     * @return string
1702
-     * @throws \EE_Error
1703
-     */
1704
-    public function set_reg_status_buttons_metabox()
1705
-    {
1706
-        $this->_set_registration_object();
1707
-        $change_reg_status_form = $this->_generate_reg_status_change_form();
1708
-        echo $change_reg_status_form->form_open(
1709
-            self::add_query_args_and_nonce(
1710
-                array(
1711
-                    'action' => 'change_reg_status',
1712
-                ),
1713
-                REG_ADMIN_URL
1714
-            )
1715
-        );
1716
-        echo $change_reg_status_form->get_html();
1717
-        echo $change_reg_status_form->form_close();
1718
-    }
1719
-
1720
-
1721
-    /**
1722
-     * @return EE_Form_Section_Proper
1723
-     * @throws EE_Error
1724
-     * @throws InvalidArgumentException
1725
-     * @throws InvalidDataTypeException
1726
-     * @throws InvalidInterfaceException
1727
-     * @throws \EventEspresso\core\exceptions\EntityNotFoundException
1728
-     */
1729
-    protected function _generate_reg_status_change_form()
1730
-    {
1731
-        return new EE_Form_Section_Proper(array(
1732
-            'name'            => 'reg_status_change_form',
1733
-            'html_id'         => 'reg-status-change-form',
1734
-            'layout_strategy' => new EE_Admin_Two_Column_Layout(),
1735
-            'subsections'     => array(
1736
-                'return'             => new EE_Hidden_Input(array(
1737
-                    'name'    => 'return',
1738
-                    'default' => 'view_registration',
1739
-                )),
1740
-                'REG_ID'             => new EE_Hidden_Input(array(
1741
-                    'name'    => 'REG_ID',
1742
-                    'default' => $this->_registration->ID(),
1743
-                )),
1744
-                'current_status'     => new EE_Form_Section_HTML(
1745
-                    EEH_HTML::tr(
1746
-                        EEH_HTML::th(
1747
-                            EEH_HTML::label(
1748
-                                EEH_HTML::strong(esc_html__('Current Registration Status', 'event_espresso')
1749
-                                )
1750
-                            )
1751
-                        )
1752
-                        . EEH_HTML::td(
1753
-                            EEH_HTML::strong(
1754
-                                $this->_registration->pretty_status(),
1755
-                                '',
1756
-                                'status-' . $this->_registration->status_ID(),
1757
-                                'line-height: 1em; font-size: 1.5em; font-weight: bold;'
1758
-                            )
1759
-                        )
1760
-                    )
1761
-                ),
1762
-                'reg_status'         => new EE_Select_Input(
1763
-                    $this->_get_reg_statuses(),
1764
-                    array(
1765
-                        'html_label_text' => esc_html__('Change Registration Status to', 'event_espresso'),
1766
-                        'default'         => $this->_registration->status_ID(),
1767
-                    )
1768
-                ),
1769
-                'send_notifications' => new EE_Yes_No_Input(
1770
-                    array(
1771
-                        'html_label_text' => esc_html__('Send Related Messages', 'event_espresso'),
1772
-                        'default'         => false,
1773
-                        'html_help_text'  => esc_html__(
1774
-                            'If set to "Yes", then the related messages will be sent to the registrant.',
1775
-                            'event_espresso'
1776
-                        ),
1777
-                    )
1778
-                ),
1779
-                'submit'             => new EE_Submit_Input(
1780
-                    array(
1781
-                        'html_class'      => 'button-primary',
1782
-                        'html_label_text' => '&nbsp;',
1783
-                        'default'         => esc_html__('Update Registration Status', 'event_espresso'),
1784
-                    )
1785
-                ),
1786
-            ),
1787
-        ));
1788
-    }
1789
-
1790
-
1791
-    /**
1792
-     * Returns an array of all the buttons for the various statuses and switch status actions
1793
-     *
1794
-     * @return array
1795
-     * @throws EE_Error
1796
-     * @throws InvalidArgumentException
1797
-     * @throws InvalidDataTypeException
1798
-     * @throws InvalidInterfaceException
1799
-     * @throws EntityNotFoundException
1800
-     */
1801
-    protected function _get_reg_statuses()
1802
-    {
1803
-        $reg_status_array = EEM_Registration::instance()->reg_status_array();
1804
-        unset ($reg_status_array[EEM_Registration::status_id_incomplete]);
1805
-        // get current reg status
1806
-        $current_status = $this->_registration->status_ID();
1807
-        // is registration for free event? This will determine whether to display the pending payment option
1808
-        if (
1809
-            $current_status !== EEM_Registration::status_id_pending_payment
1810
-            && EEH_Money::compare_floats($this->_registration->ticket()->price(), 0.00)
1811
-        ) {
1812
-            unset($reg_status_array[EEM_Registration::status_id_pending_payment]);
1813
-        }
1814
-        return EEM_Status::instance()->localized_status($reg_status_array, false, 'sentence');
1815
-    }
1816
-
1817
-
1818
-    /**
1819
-     * This method is used when using _REG_ID from request which may or may not be an array of reg_ids.
1820
-     *
1821
-     * @param bool $status REG status given for changing registrations to.
1822
-     * @param bool $notify Whether to send messages notifications or not.
1823
-     * @return array (array with reg_id(s) updated and whether update was successful.
1824
-     * @throws EE_Error
1825
-     * @throws InvalidArgumentException
1826
-     * @throws InvalidDataTypeException
1827
-     * @throws InvalidInterfaceException
1828
-     * @throws ReflectionException
1829
-     * @throws RuntimeException
1830
-     * @throws EntityNotFoundException
1831
-     */
1832
-    protected function _set_registration_status_from_request($status = false, $notify = false)
1833
-    {
1834
-        if (isset($this->_req_data['reg_status_change_form'])) {
1835
-            $REG_IDs = isset($this->_req_data['reg_status_change_form']['REG_ID'])
1836
-                ? (array)$this->_req_data['reg_status_change_form']['REG_ID']
1837
-                : array();
1838
-        } else {
1839
-            $REG_IDs = isset($this->_req_data['_REG_ID'])
1840
-                ? (array)$this->_req_data['_REG_ID']
1841
-                : array();
1842
-        }
1843
-        // sanitize $REG_IDs
1844
-        $REG_IDs = array_map('absint', $REG_IDs);
1845
-        // and remove empty entries
1846
-        $REG_IDs = array_filter($REG_IDs);
1847
-
1848
-        $result = $this->_set_registration_status($REG_IDs, $status, $notify);
1849
-
1850
-        /**
1851
-         * Set and filter $_req_data['_REG_ID'] for any potential future messages notifications.
1852
-         * Currently this value is used downstream by the _process_resend_registration method.
1853
-         *
1854
-         * @param int|array                $registration_ids The registration ids that have had their status changed successfully.
1855
-         * @param bool                     $status           The status registrations were changed to.
1856
-         * @param bool                     $success          If the status was changed successfully for all registrations.
1857
-         * @param Registrations_Admin_Page $admin_page_object
1858
-         */
1859
-        $this->_req_data['_REG_ID'] = apply_filters(
1860
-            'FHEE__Registrations_Admin_Page___set_registration_status_from_request__REG_IDs',
1861
-            $result['REG_ID'],
1862
-            $status,
1863
-            $result['success'],
1864
-            $this
1865
-        );
1866
-
1867
-        //notify?
1868
-        if ($notify
1869
-            && $result['success']
1870
-            && ! empty($this->_req_data['_REG_ID'])
1871
-            && EE_Registry::instance()->CAP->current_user_can(
1872
-                'ee_send_message',
1873
-                'espresso_registrations_resend_registration'
1874
-            )
1875
-        ) {
1876
-            $this->_process_resend_registration();
1877
-        }
1878
-        return $result;
1879
-    }
1880
-
1881
-
1882
-    /**
1883
-     * Set the registration status for the given reg_id (which may or may not be an array, it gets typecast to an
1884
-     * array). Note, this method does NOT take care of possible notifications.  That is required by calling code.
1885
-     *
1886
-     * @param array  $REG_IDs
1887
-     * @param string $status
1888
-     * @param bool   $notify  Used to indicate whether notification was requested or not.  This determines the context
1889
-     *                        slug sent with setting the registration status.
1890
-     * @return array (an array with 'success' key representing whether status change was successful, and 'REG_ID' as
1891
-     * @throws EE_Error
1892
-     * @throws InvalidArgumentException
1893
-     * @throws InvalidDataTypeException
1894
-     * @throws InvalidInterfaceException
1895
-     * @throws ReflectionException
1896
-     * @throws RuntimeException
1897
-     * @throws EntityNotFoundException
1898
-     */
1899
-    protected function _set_registration_status($REG_IDs = array(), $status = '', $notify = false)
1900
-    {
1901
-        $success = false;
1902
-        // typecast $REG_IDs
1903
-        $REG_IDs = (array)$REG_IDs;
1904
-        if ( ! empty($REG_IDs)) {
1905
-            $success = true;
1906
-            // set default status if none is passed
1907
-            $status = $status ? $status : EEM_Registration::status_id_pending_payment;
1908
-            $status_context = $notify
1909
-                ? Domain::CONTEXT_REGISTRATION_STATUS_CHANGE_REGISTRATION_ADMIN_NOTIFY
1910
-                : Domain::CONTEXT_REGISTRATION_STATUS_CHANGE_REGISTRATION_ADMIN;
1911
-            //loop through REG_ID's and change status
1912
-            foreach ($REG_IDs as $REG_ID) {
1913
-                $registration = EEM_Registration::instance()->get_one_by_ID($REG_ID);
1914
-                if ($registration instanceof EE_Registration) {
1915
-                    $registration->set_status(
1916
-                        $status,
1917
-                        false,
1918
-                        new Context(
1919
-                            $status_context,
1920
-                            esc_html__(
1921
-                                'Manually triggered status change on a Registration Admin Page route.',
1922
-                                'event_espresso'
1923
-                            )
1924
-                        )
1925
-                    );
1926
-                    $result = $registration->save();
1927
-                    // verifying explicit fails because update *may* just return 0 for 0 rows affected
1928
-                    $success = $result !== false ? $success : false;
1929
-                }
1930
-            }
1931
-        }
1932
-
1933
-        //return $success and processed registrations
1934
-        return array('REG_ID' => $REG_IDs, 'success' => $success);
1935
-    }
1936
-
1937
-
1938
-    /**
1939
-     * Common logic for setting up success message and redirecting to appropriate route
1940
-     *
1941
-     * @param  string $STS_ID status id for the registration changed to
1942
-     * @param   bool  $notify indicates whether the _set_registration_status_from_request does notifications or not.
1943
-     * @return void
1944
-     * @throws EE_Error
1945
-     */
1946
-    protected function _reg_status_change_return($STS_ID, $notify = false)
1947
-    {
1948
-        $result  = ! empty($STS_ID) ? $this->_set_registration_status_from_request($STS_ID, $notify)
1949
-            : array('success' => false);
1950
-        $success = isset($result['success']) && $result['success'];
1951
-        //setup success message
1952
-        if ($success) {
1953
-            if (is_array($result['REG_ID']) && count($result['REG_ID']) === 1) {
1954
-                $msg = sprintf(esc_html__('Registration status has been set to %s', 'event_espresso'),
1955
-                    EEH_Template::pretty_status($STS_ID, false, 'lower'));
1956
-            } else {
1957
-                $msg = sprintf(esc_html__('Registrations have been set to %s.', 'event_espresso'),
1958
-                    EEH_Template::pretty_status($STS_ID, false, 'lower'));
1959
-            }
1960
-            EE_Error::add_success($msg);
1961
-        } else {
1962
-            EE_Error::add_error(
1963
-                esc_html__(
1964
-                    'Something went wrong, and the status was not changed',
1965
-                    'event_espresso'
1966
-                ), __FILE__, __LINE__, __FUNCTION__
1967
-            );
1968
-        }
1969
-        if (isset($this->_req_data['return']) && $this->_req_data['return'] == 'view_registration') {
1970
-            $route = array('action' => 'view_registration', '_REG_ID' => reset($result['REG_ID']));
1971
-        } else {
1972
-            $route = array('action' => 'default');
1973
-        }
1974
-        //unset nonces
1975
-        foreach ($this->_req_data as $ref => $value) {
1976
-            if (strpos($ref, 'nonce') !== false) {
1977
-                unset($this->_req_data[$ref]);
1978
-                continue;
1979
-            }
1980
-            $value                 = is_array($value) ? array_map('urlencode', $value) : urlencode($value);
1981
-            $this->_req_data[$ref] = $value;
1982
-        }
1983
-        //merge request vars so that the reloaded list table contains any existing filter query params
1984
-        $route = array_merge($this->_req_data, $route);
1985
-        $this->_redirect_after_action($success, '', '', $route, true);
1986
-    }
1987
-
1988
-
1989
-    /**
1990
-     * incoming reg status change from reg details page.
1991
-     *
1992
-     * @return void
1993
-     */
1994
-    protected function _change_reg_status()
1995
-    {
1996
-        $this->_req_data['return'] = 'view_registration';
1997
-        //set notify based on whether the send notifications toggle is set or not
1998
-        $notify = ! empty($this->_req_data['reg_status_change_form']['send_notifications']);
1999
-        //$notify = ! empty( $this->_req_data['txn_reg_status_change']['send_notifications'] );
2000
-        $this->_req_data['reg_status_change_form']['reg_status'] = isset($this->_req_data['reg_status_change_form']['reg_status'])
2001
-            ? $this->_req_data['reg_status_change_form']['reg_status'] : '';
2002
-        switch ($this->_req_data['reg_status_change_form']['reg_status']) {
2003
-            case EEM_Registration::status_id_approved :
2004
-            case EEH_Template::pretty_status(EEM_Registration::status_id_approved, false, 'sentence') :
2005
-                $this->approve_registration($notify);
2006
-                break;
2007
-            case EEM_Registration::status_id_pending_payment :
2008
-            case EEH_Template::pretty_status(EEM_Registration::status_id_pending_payment, false, 'sentence') :
2009
-                $this->pending_registration($notify);
2010
-                break;
2011
-            case EEM_Registration::status_id_not_approved :
2012
-            case EEH_Template::pretty_status(EEM_Registration::status_id_not_approved, false, 'sentence') :
2013
-                $this->not_approve_registration($notify);
2014
-                break;
2015
-            case EEM_Registration::status_id_declined :
2016
-            case EEH_Template::pretty_status(EEM_Registration::status_id_declined, false, 'sentence') :
2017
-                $this->decline_registration($notify);
2018
-                break;
2019
-            case EEM_Registration::status_id_cancelled :
2020
-            case EEH_Template::pretty_status(EEM_Registration::status_id_cancelled, false, 'sentence') :
2021
-                $this->cancel_registration($notify);
2022
-                break;
2023
-            case EEM_Registration::status_id_wait_list :
2024
-            case EEH_Template::pretty_status(EEM_Registration::status_id_wait_list, false, 'sentence') :
2025
-                $this->wait_list_registration($notify);
2026
-                break;
2027
-            case EEM_Registration::status_id_incomplete :
2028
-            default :
2029
-                $result['success'] = false;
2030
-                unset($this->_req_data['return']);
2031
-                $this->_reg_status_change_return('', false);
2032
-                break;
2033
-        }
2034
-    }
2035
-
2036
-
2037
-    /**
2038
-     * Callback for bulk action routes.
2039
-     * Note: although we could just register the singular route callbacks for each bulk action route as well, this
2040
-     * method was chosen so there is one central place all the registration status bulk actions are going through.
2041
-     * Potentially, this provides an easier place to locate logic that is specific to these bulk actions (as opposed to
2042
-     * when an action is happening on just a single registration).
2043
-     * @param      $action
2044
-     * @param bool $notify
2045
-     */
2046
-    protected function bulk_action_on_registrations($action, $notify = false) {
2047
-        do_action(
2048
-            'AHEE__Registrations_Admin_Page__bulk_action_on_registrations__before_execution',
2049
-            $this,
2050
-            $action,
2051
-            $notify
2052
-        );
2053
-        $method = $action . '_registration';
2054
-        if (method_exists($this, $method)) {
2055
-            $this->$method($notify);
2056
-        }
2057
-    }
2058
-
2059
-
2060
-    /**
2061
-     * approve_registration
2062
-     *
2063
-     * @access protected
2064
-     * @param bool $notify whether or not to notify the registrant about their approval.
2065
-     * @return void
2066
-     */
2067
-    protected function approve_registration($notify = false)
2068
-    {
2069
-        $this->_reg_status_change_return(EEM_Registration::status_id_approved, $notify);
2070
-    }
2071
-
2072
-
2073
-    /**
2074
-     *        decline_registration
2075
-     *
2076
-     * @access protected
2077
-     * @param bool $notify whether or not to notify the registrant about their status change.
2078
-     * @return void
2079
-     */
2080
-    protected function decline_registration($notify = false)
2081
-    {
2082
-        $this->_reg_status_change_return(EEM_Registration::status_id_declined, $notify);
2083
-    }
2084
-
2085
-
2086
-    /**
2087
-     *        cancel_registration
2088
-     *
2089
-     * @access protected
2090
-     * @param bool $notify whether or not to notify the registrant about their status change.
2091
-     * @return void
2092
-     */
2093
-    protected function cancel_registration($notify = false)
2094
-    {
2095
-        $this->_reg_status_change_return(EEM_Registration::status_id_cancelled, $notify);
2096
-    }
2097
-
2098
-
2099
-    /**
2100
-     *        not_approve_registration
2101
-     *
2102
-     * @access protected
2103
-     * @param bool $notify whether or not to notify the registrant about their status change.
2104
-     * @return void
2105
-     */
2106
-    protected function not_approve_registration($notify = false)
2107
-    {
2108
-        $this->_reg_status_change_return(EEM_Registration::status_id_not_approved, $notify);
2109
-    }
2110
-
2111
-
2112
-    /**
2113
-     *        decline_registration
2114
-     *
2115
-     * @access protected
2116
-     * @param bool $notify whether or not to notify the registrant about their status change.
2117
-     * @return void
2118
-     */
2119
-    protected function pending_registration($notify = false)
2120
-    {
2121
-        $this->_reg_status_change_return(EEM_Registration::status_id_pending_payment, $notify);
2122
-    }
2123
-
2124
-
2125
-    /**
2126
-     * waitlist_registration
2127
-     *
2128
-     * @access protected
2129
-     * @param bool $notify whether or not to notify the registrant about their status change.
2130
-     * @return void
2131
-     */
2132
-    protected function wait_list_registration($notify = false)
2133
-    {
2134
-        $this->_reg_status_change_return(EEM_Registration::status_id_wait_list, $notify);
2135
-    }
2136
-
2137
-
2138
-    /**
2139
-     *        generates HTML for the Registration main meta box
2140
-     *
2141
-     * @access public
2142
-     * @return void
2143
-     * @throws DomainException
2144
-     * @throws EE_Error
2145
-     * @throws InvalidArgumentException
2146
-     * @throws InvalidDataTypeException
2147
-     * @throws InvalidInterfaceException
2148
-     * @throws ReflectionException
2149
-     * @throws EntityNotFoundException
2150
-     */
2151
-    public function _reg_details_meta_box()
2152
-    {
2153
-        EEH_Autoloader::register_line_item_display_autoloaders();
2154
-        EEH_Autoloader::register_line_item_filter_autoloaders();
2155
-        EE_Registry::instance()->load_helper('Line_Item');
2156
-        $transaction    = $this->_registration->transaction() ? $this->_registration->transaction()
2157
-            : EE_Transaction::new_instance();
2158
-        $this->_session = $transaction->session_data();
2159
-        $filters        = new EE_Line_Item_Filter_Collection();
2160
-        //$filters->add( new EE_Non_Zero_Line_Item_Filter() );
2161
-        $filters->add(new EE_Single_Registration_Line_Item_Filter($this->_registration));
2162
-        $line_item_filter_processor              = new EE_Line_Item_Filter_Processor($filters,
2163
-            $transaction->total_line_item());
2164
-        $filtered_line_item_tree                 = $line_item_filter_processor->process();
2165
-        $line_item_display                       = new EE_Line_Item_Display('reg_admin_table',
2166
-            'EE_Admin_Table_Registration_Line_Item_Display_Strategy');
2167
-        $this->_template_args['line_item_table'] = $line_item_display->display_line_item(
2168
-            $filtered_line_item_tree,
2169
-            array('EE_Registration' => $this->_registration)
2170
-        );
2171
-        $attendee                                = $this->_registration->attendee();
2172
-        if (EE_Registry::instance()->CAP->current_user_can(
2173
-            'ee_read_transaction',
2174
-            'espresso_transactions_view_transaction'
2175
-        )) {
2176
-            $this->_template_args['view_transaction_button'] = EEH_Template::get_button_or_link(
2177
-                EE_Admin_Page::add_query_args_and_nonce(
2178
-                    array(
2179
-                        'action' => 'view_transaction',
2180
-                        'TXN_ID' => $transaction->ID(),
2181
-                    ),
2182
-                    TXN_ADMIN_URL
2183
-                ),
2184
-                esc_html__(' View Transaction', 'event_espresso'),
2185
-                'button secondary-button right',
2186
-                'dashicons dashicons-cart'
2187
-            );
2188
-        } else {
2189
-            $this->_template_args['view_transaction_button'] = '';
2190
-        }
2191
-        if ($attendee instanceof EE_Attendee
2192
-            && EE_Registry::instance()->CAP->current_user_can(
2193
-                'ee_send_message',
2194
-                'espresso_registrations_resend_registration'
2195
-            )
2196
-        ) {
2197
-            $this->_template_args['resend_registration_button'] = EEH_Template::get_button_or_link(
2198
-                EE_Admin_Page::add_query_args_and_nonce(
2199
-                    array(
2200
-                        'action'      => 'resend_registration',
2201
-                        '_REG_ID'     => $this->_registration->ID(),
2202
-                        'redirect_to' => 'view_registration',
2203
-                    ),
2204
-                    REG_ADMIN_URL
2205
-                ),
2206
-                esc_html__(' Resend Registration', 'event_espresso'),
2207
-                'button secondary-button right',
2208
-                'dashicons dashicons-email-alt'
2209
-            );
2210
-        } else {
2211
-            $this->_template_args['resend_registration_button'] = '';
2212
-        }
2213
-        $this->_template_args['currency_sign'] = EE_Registry::instance()->CFG->currency->sign;
2214
-        $payment                               = $transaction->get_first_related('Payment');
2215
-        $payment                               = ! $payment instanceof EE_Payment
2216
-            ? EE_Payment::new_instance()
2217
-            : $payment;
2218
-        $payment_method                        = $payment->get_first_related('Payment_Method');
2219
-        $payment_method                        = ! $payment_method instanceof EE_Payment_Method
2220
-            ? EE_Payment_Method::new_instance()
2221
-            : $payment_method;
2222
-        $reg_details                           = array(
2223
-            'payment_method'       => $payment_method->name(),
2224
-            'response_msg'         => $payment->gateway_response(),
2225
-            'registration_id'      => $this->_registration->get('REG_code'),
2226
-            'registration_session' => $this->_registration->session_ID(),
2227
-            'ip_address'           => isset($this->_session['ip_address']) ? $this->_session['ip_address'] : '',
2228
-            'user_agent'           => isset($this->_session['user_agent']) ? $this->_session['user_agent'] : '',
2229
-        );
2230
-        if (isset($reg_details['registration_id'])) {
2231
-            $this->_template_args['reg_details']['registration_id']['value'] = $reg_details['registration_id'];
2232
-            $this->_template_args['reg_details']['registration_id']['label'] = esc_html__(
2233
-                'Registration ID',
2234
-                'event_espresso'
2235
-            );
2236
-            $this->_template_args['reg_details']['registration_id']['class'] = 'regular-text';
2237
-        }
2238
-        if (isset($reg_details['payment_method'])) {
2239
-            $this->_template_args['reg_details']['payment_method']['value'] = $reg_details['payment_method'];
2240
-            $this->_template_args['reg_details']['payment_method']['label'] = esc_html__(
2241
-                'Most Recent Payment Method',
2242
-                'event_espresso'
2243
-            );
2244
-            $this->_template_args['reg_details']['payment_method']['class'] = 'regular-text';
2245
-            $this->_template_args['reg_details']['response_msg']['value']   = $reg_details['response_msg'];
2246
-            $this->_template_args['reg_details']['response_msg']['label']   = esc_html__(
2247
-                'Payment method response',
2248
-                'event_espresso'
2249
-            );
2250
-            $this->_template_args['reg_details']['response_msg']['class']   = 'regular-text';
2251
-        }
2252
-        $this->_template_args['reg_details']['registration_session']['value'] = $reg_details['registration_session'];
2253
-        $this->_template_args['reg_details']['registration_session']['label'] = esc_html__(
2254
-            'Registration Session',
2255
-            'event_espresso'
2256
-        );
2257
-        $this->_template_args['reg_details']['registration_session']['class'] = 'regular-text';
2258
-        $this->_template_args['reg_details']['ip_address']['value']           = $reg_details['ip_address'];
2259
-        $this->_template_args['reg_details']['ip_address']['label']           = esc_html__(
2260
-            'Registration placed from IP',
2261
-            'event_espresso'
2262
-        );
2263
-        $this->_template_args['reg_details']['ip_address']['class']           = 'regular-text';
2264
-        $this->_template_args['reg_details']['user_agent']['value']           = $reg_details['user_agent'];
2265
-        $this->_template_args['reg_details']['user_agent']['label']           = esc_html__('Registrant User Agent',
2266
-            'event_espresso');
2267
-        $this->_template_args['reg_details']['user_agent']['class']           = 'large-text';
2268
-        $this->_template_args['event_link']                                   = EE_Admin_Page::add_query_args_and_nonce(
2269
-            array(
2270
-                'action'   => 'default',
2271
-                'event_id' => $this->_registration->event_ID(),
2272
-            ),
2273
-            REG_ADMIN_URL
2274
-        );
2275
-        $this->_template_args['REG_ID']                                       = $this->_registration->ID();
2276
-        $this->_template_args['event_id']                                     = $this->_registration->event_ID();
2277
-        $template_path                                                        =
2278
-            REG_TEMPLATE_PATH . 'reg_admin_details_main_meta_box_reg_details.template.php';
2279
-        echo EEH_Template::display_template($template_path, $this->_template_args, true);
2280
-    }
2281
-
2282
-
2283
-    /**
2284
-     * generates HTML for the Registration Questions meta box.
2285
-     * If pre-4.8.32.rc.000 hooks are used, uses old methods (with its filters),
2286
-     * otherwise uses new forms system
2287
-     *
2288
-     * @access public
2289
-     * @return void
2290
-     * @throws DomainException
2291
-     * @throws EE_Error
2292
-     */
2293
-    public function _reg_questions_meta_box()
2294
-    {
2295
-        //allow someone to override this method entirely
2296
-        if (apply_filters('FHEE__Registrations_Admin_Page___reg_questions_meta_box__do_default', true, $this,
2297
-            $this->_registration)) {
2298
-            $form                                              = $this->_get_reg_custom_questions_form(
2299
-                $this->_registration->ID()
2300
-            );
2301
-            $this->_template_args['att_questions']             = count($form->subforms()) > 0
2302
-                ? $form->get_html_and_js()
2303
-                : '';
2304
-            $this->_template_args['reg_questions_form_action'] = 'edit_registration';
2305
-            $this->_template_args['REG_ID']                    = $this->_registration->ID();
2306
-            $template_path                                     =
2307
-                REG_TEMPLATE_PATH . 'reg_admin_details_main_meta_box_reg_questions.template.php';
2308
-            echo EEH_Template::display_template($template_path, $this->_template_args, true);
2309
-        }
2310
-    }
2311
-
2312
-
2313
-    /**
2314
-     * form_before_question_group
2315
-     *
2316
-     * @deprecated    as of 4.8.32.rc.000
2317
-     * @access        public
2318
-     * @param        string $output
2319
-     * @return        string
2320
-     */
2321
-    public function form_before_question_group($output)
2322
-    {
2323
-        EE_Error::doing_it_wrong(
2324
-            __CLASS__ . '::' . __FUNCTION__,
2325
-            esc_html__(
2326
-                'This method would have been protected but was used on a filter callback so needed to be public. Please discontinue usage as it will be removed soon.',
2327
-                'event_espresso'
2328
-            ),
2329
-            '4.8.32.rc.000'
2330
-        );
2331
-        return '
1298
+		if (! empty($registration_status)) {
1299
+			$where['STS_ID'] = $registration_status;
1300
+		} else {
1301
+			//make sure we exclude incomplete registrations, but only if not trashed.
1302
+			if ($view === 'trash') {
1303
+				$where['REG_deleted'] = true;
1304
+			} elseif ($view === 'incomplete') {
1305
+				$where['STS_ID'] = EEM_Registration::status_id_incomplete;
1306
+			} else {
1307
+				$where['STS_ID'] = array('!=', EEM_Registration::status_id_incomplete);
1308
+			}
1309
+		}
1310
+		return $where;
1311
+	}
1312
+
1313
+
1314
+	/**
1315
+	 * Adds any provided date restraints to the where conditions for the registrations query.
1316
+	 *
1317
+	 * @param array $request usually the same as $this->_req_data but not necessarily
1318
+	 * @return array
1319
+	 * @throws EE_Error
1320
+	 * @throws InvalidArgumentException
1321
+	 * @throws InvalidDataTypeException
1322
+	 * @throws InvalidInterfaceException
1323
+	 */
1324
+	protected function _add_date_to_where_conditions(array $request)
1325
+	{
1326
+		$where = array();
1327
+		$view = EEH_Array::is_set($request, 'status', '');
1328
+		$month_range             = ! empty($request['month_range'])
1329
+			? sanitize_text_field($request['month_range'])
1330
+			: '';
1331
+		$retrieve_for_today      = $view === 'today';
1332
+		$retrieve_for_this_month = $view === 'month';
1333
+
1334
+		if ($retrieve_for_today) {
1335
+			$now               = date('Y-m-d', current_time('timestamp'));
1336
+			$where['REG_date'] = array(
1337
+				'BETWEEN',
1338
+				array(
1339
+					EEM_Registration::instance()->convert_datetime_for_query(
1340
+						'REG_date',
1341
+						$now . ' 00:00:00',
1342
+						'Y-m-d H:i:s'
1343
+					),
1344
+					EEM_Registration::instance()->convert_datetime_for_query(
1345
+						'REG_date',
1346
+						$now . ' 23:59:59',
1347
+						'Y-m-d H:i:s'
1348
+					),
1349
+				),
1350
+			);
1351
+		} elseif ($retrieve_for_this_month) {
1352
+			$current_year_and_month = date('Y-m', current_time('timestamp'));
1353
+			$days_this_month        = date('t', current_time('timestamp'));
1354
+			$where['REG_date']      = array(
1355
+				'BETWEEN',
1356
+				array(
1357
+					EEM_Registration::instance()->convert_datetime_for_query(
1358
+						'REG_date',
1359
+						$current_year_and_month . '-01 00:00:00',
1360
+						'Y-m-d H:i:s'
1361
+					),
1362
+					EEM_Registration::instance()->convert_datetime_for_query(
1363
+						'REG_date',
1364
+						$current_year_and_month . '-' . $days_this_month . ' 23:59:59',
1365
+						'Y-m-d H:i:s'
1366
+					),
1367
+				),
1368
+			);
1369
+		} elseif ($month_range) {
1370
+			$pieces          = explode(' ', $month_range, 3);
1371
+			$month_requested = ! empty($pieces[0])
1372
+				? date('m', \EEH_DTT_Helper::first_of_month_timestamp($pieces[0]))
1373
+				: '';
1374
+			$year_requested  = ! empty($pieces[1])
1375
+				? $pieces[1]
1376
+				: '';
1377
+			//if there is not a month or year then we can't go further
1378
+			if ($month_requested && $year_requested) {
1379
+				$days_in_month     = date('t', strtotime($year_requested . '-' . $month_requested . '-' . '01'));
1380
+				$where['REG_date'] = array(
1381
+					'BETWEEN',
1382
+					array(
1383
+						EEM_Registration::instance()->convert_datetime_for_query(
1384
+							'REG_date',
1385
+							$year_requested . '-' . $month_requested . '-01 00:00:00',
1386
+							'Y-m-d H:i:s'
1387
+						),
1388
+						EEM_Registration::instance()->convert_datetime_for_query(
1389
+							'REG_date',
1390
+							$year_requested . '-' . $month_requested . '-' . $days_in_month . ' 23:59:59',
1391
+							'Y-m-d H:i:s'
1392
+						),
1393
+					),
1394
+				);
1395
+			}
1396
+		}
1397
+		return $where;
1398
+	}
1399
+
1400
+
1401
+	/**
1402
+	 * Adds any provided search restraints to the where conditions for the registrations query
1403
+	 *
1404
+	 * @param array $request usually the same as $this->_req_data but not necessarily
1405
+	 * @return array
1406
+	 */
1407
+	protected function _add_search_to_where_conditions(array $request)
1408
+	{
1409
+		$where = array();
1410
+		if (! empty($request['s'])) {
1411
+			$search_string = '%' . sanitize_text_field($request['s']) . '%';
1412
+			$where['OR*search_conditions'] = array(
1413
+				'Event.EVT_name'                          => array('LIKE', $search_string),
1414
+				'Event.EVT_desc'                          => array('LIKE', $search_string),
1415
+				'Event.EVT_short_desc'                    => array('LIKE', $search_string),
1416
+				'Attendee.ATT_full_name'                  => array('LIKE', $search_string),
1417
+				'Attendee.ATT_fname'                      => array('LIKE', $search_string),
1418
+				'Attendee.ATT_lname'                      => array('LIKE', $search_string),
1419
+				'Attendee.ATT_short_bio'                  => array('LIKE', $search_string),
1420
+				'Attendee.ATT_email'                      => array('LIKE', $search_string),
1421
+				'Attendee.ATT_address'                    => array('LIKE', $search_string),
1422
+				'Attendee.ATT_address2'                   => array('LIKE', $search_string),
1423
+				'Attendee.ATT_city'                       => array('LIKE', $search_string),
1424
+				'REG_final_price'                         => array('LIKE', $search_string),
1425
+				'REG_code'                                => array('LIKE', $search_string),
1426
+				'REG_count'                               => array('LIKE', $search_string),
1427
+				'REG_group_size'                          => array('LIKE', $search_string),
1428
+				'Ticket.TKT_name'                         => array('LIKE', $search_string),
1429
+				'Ticket.TKT_description'                  => array('LIKE', $search_string),
1430
+				'Transaction.Payment.PAY_txn_id_chq_nmbr' => array('LIKE', $search_string),
1431
+			);
1432
+		}
1433
+		return $where;
1434
+	}
1435
+
1436
+
1437
+	/**
1438
+	 * Sets up the where conditions for the registrations query.
1439
+	 *
1440
+	 * @param array $request
1441
+	 * @return array
1442
+	 * @throws EE_Error
1443
+	 */
1444
+	protected function _get_where_conditions_for_registrations_query($request)
1445
+	{
1446
+		return apply_filters(
1447
+			'FHEE__Registrations_Admin_Page___get_where_conditions_for_registrations_query',
1448
+			array_merge(
1449
+				$this->addAttendeeIdToWhereConditions($request),
1450
+				$this->_add_event_id_to_where_conditions($request),
1451
+				$this->_add_category_id_to_where_conditions($request),
1452
+				$this->_add_datetime_id_to_where_conditions($request),
1453
+				$this->_add_registration_status_to_where_conditions($request),
1454
+				$this->_add_date_to_where_conditions($request),
1455
+				$this->_add_search_to_where_conditions($request)
1456
+			),
1457
+			$request
1458
+		);
1459
+	}
1460
+
1461
+
1462
+	/**
1463
+	 * Sets up the orderby for the registrations query.
1464
+	 *
1465
+	 * @return array
1466
+	 */
1467
+	protected function _get_orderby_for_registrations_query()
1468
+	{
1469
+		$orderby_field = ! empty($this->_req_data['orderby'])
1470
+			? sanitize_text_field($this->_req_data['orderby'])
1471
+			: '';
1472
+		switch ($orderby_field) {
1473
+			case '_REG_ID':
1474
+				$orderby = array('REG_ID');
1475
+				break;
1476
+			case '_Reg_status':
1477
+				$orderby = array('STS_ID');
1478
+				break;
1479
+			case 'ATT_fname':
1480
+				$orderby = array('Attendee.ATT_fname', 'Attendee.ATT_lname');
1481
+				break;
1482
+			case 'ATT_lname':
1483
+				$orderby = array('Attendee.ATT_lname', 'Attendee.ATT_fname');
1484
+				break;
1485
+			case 'event_name':
1486
+				$orderby = array('Event.EVT_name');
1487
+				break;
1488
+			case 'DTT_EVT_start':
1489
+				$orderby = array('Event.Datetime.DTT_EVT_start');
1490
+				break;
1491
+			default: //'REG_date'
1492
+				$orderby = array('REG_date');
1493
+		}
1494
+
1495
+		//order
1496
+		$order = ! empty($this->_req_data['order'])
1497
+			? sanitize_text_field($this->_req_data['order'])
1498
+			: 'DESC';
1499
+		$orderby = array_combine(
1500
+			$orderby,
1501
+			array_fill(0, count($orderby), $order)
1502
+		);
1503
+		//because there are many registrations with the same date, define
1504
+		//a secondary way to order them, otherwise MySQL seems to be a bit random
1505
+		if (empty($orderby['REG_ID'])) {
1506
+			$orderby['REG_ID'] = $order;
1507
+		}
1508
+		return array('order_by' => $orderby);
1509
+	}
1510
+
1511
+
1512
+	/**
1513
+	 * Sets up the limit for the registrations query.
1514
+	 *
1515
+	 * @param $per_page
1516
+	 * @return array
1517
+	 */
1518
+	protected function _get_limit($per_page)
1519
+	{
1520
+		$current_page = ! empty($this->_req_data['paged'])
1521
+			? absint($this->_req_data['paged'])
1522
+			: 1;
1523
+		$per_page     = ! empty($this->_req_data['perpage'])
1524
+			? $this->_req_data['perpage']
1525
+			: $per_page;
1526
+
1527
+		//-1 means return all results so get out if that's set.
1528
+		if ((int)$per_page === -1) {
1529
+			return array();
1530
+		}
1531
+		$per_page = absint($per_page);
1532
+		$offset   = ($current_page - 1) * $per_page;
1533
+		return array('limit' => array($offset, $per_page));
1534
+	}
1535
+
1536
+
1537
+	public function get_registration_status_array()
1538
+	{
1539
+		return self::$_reg_status;
1540
+	}
1541
+
1542
+
1543
+
1544
+
1545
+	/***************************************        REGISTRATION DETAILS        ***************************************/
1546
+	/**
1547
+	 *        generates HTML for the View Registration Details Admin page
1548
+	 *
1549
+	 * @access protected
1550
+	 * @return void
1551
+	 * @throws DomainException
1552
+	 * @throws EE_Error
1553
+	 * @throws InvalidArgumentException
1554
+	 * @throws InvalidDataTypeException
1555
+	 * @throws InvalidInterfaceException
1556
+	 * @throws EntityNotFoundException
1557
+	 */
1558
+	protected function _registration_details()
1559
+	{
1560
+		$this->_template_args = array();
1561
+		$this->_set_registration_object();
1562
+		if (is_object($this->_registration)) {
1563
+			$transaction                                   = $this->_registration->transaction()
1564
+				? $this->_registration->transaction()
1565
+				: EE_Transaction::new_instance();
1566
+			$this->_session                                = $transaction->session_data();
1567
+			$event_id                                      = $this->_registration->event_ID();
1568
+			$this->_template_args['reg_nmbr']['value']     = $this->_registration->ID();
1569
+			$this->_template_args['reg_nmbr']['label']     = esc_html__('Registration Number', 'event_espresso');
1570
+			$this->_template_args['reg_datetime']['value'] = $this->_registration->get_i18n_datetime('REG_date');
1571
+			$this->_template_args['reg_datetime']['label'] = esc_html__('Date', 'event_espresso');
1572
+			$this->_template_args['grand_total']           = $transaction->total();
1573
+			$this->_template_args['currency_sign']         = EE_Registry::instance()->CFG->currency->sign;
1574
+			// link back to overview
1575
+			$this->_template_args['reg_overview_url']            = REG_ADMIN_URL;
1576
+			$this->_template_args['registration']                = $this->_registration;
1577
+			$this->_template_args['filtered_registrations_link'] = EE_Admin_Page::add_query_args_and_nonce(
1578
+				array(
1579
+					'action'   => 'default',
1580
+					'event_id' => $event_id,
1581
+				),
1582
+				REG_ADMIN_URL
1583
+			);
1584
+			$this->_template_args['filtered_transactions_link']  = EE_Admin_Page::add_query_args_and_nonce(
1585
+				array(
1586
+					'action' => 'default',
1587
+					'EVT_ID' => $event_id,
1588
+					'page'   => 'espresso_transactions',
1589
+				),
1590
+				admin_url('admin.php')
1591
+			);
1592
+			$this->_template_args['event_link']                  = EE_Admin_Page::add_query_args_and_nonce(
1593
+				array(
1594
+					'page'   => 'espresso_events',
1595
+					'action' => 'edit',
1596
+					'post'   => $event_id,
1597
+				),
1598
+				admin_url('admin.php')
1599
+			);
1600
+			//next and previous links
1601
+			$next_reg                                      = $this->_registration->next(
1602
+				null,
1603
+				array(),
1604
+				'REG_ID'
1605
+			);
1606
+			$this->_template_args['next_registration']     = $next_reg
1607
+				? $this->_next_link(
1608
+					EE_Admin_Page::add_query_args_and_nonce(
1609
+						array(
1610
+							'action'  => 'view_registration',
1611
+							'_REG_ID' => $next_reg['REG_ID'],
1612
+						),
1613
+						REG_ADMIN_URL
1614
+					),
1615
+					'dashicons dashicons-arrow-right ee-icon-size-22'
1616
+				)
1617
+				: '';
1618
+			$previous_reg                                  = $this->_registration->previous(
1619
+				null,
1620
+				array(),
1621
+				'REG_ID'
1622
+			);
1623
+			$this->_template_args['previous_registration'] = $previous_reg
1624
+				? $this->_previous_link(
1625
+					EE_Admin_Page::add_query_args_and_nonce(
1626
+						array(
1627
+							'action'  => 'view_registration',
1628
+							'_REG_ID' => $previous_reg['REG_ID'],
1629
+						),
1630
+						REG_ADMIN_URL
1631
+					),
1632
+					'dashicons dashicons-arrow-left ee-icon-size-22'
1633
+				)
1634
+				: '';
1635
+			// grab header
1636
+			$template_path                             = REG_TEMPLATE_PATH . 'reg_admin_details_header.template.php';
1637
+			$this->_template_args['REG_ID']            = $this->_registration->ID();
1638
+			$this->_template_args['admin_page_header'] = EEH_Template::display_template(
1639
+				$template_path,
1640
+				$this->_template_args,
1641
+				true
1642
+			);
1643
+		} else {
1644
+			$this->_template_args['admin_page_header'] = $this->display_espresso_notices();
1645
+		}
1646
+		// the details template wrapper
1647
+		$this->display_admin_page_with_sidebar();
1648
+	}
1649
+
1650
+
1651
+	protected function _registration_details_metaboxes()
1652
+	{
1653
+		do_action('AHEE__Registrations_Admin_Page___registration_details_metabox__start', $this);
1654
+		$this->_set_registration_object();
1655
+		$attendee = $this->_registration instanceof EE_Registration ? $this->_registration->attendee() : null;
1656
+		add_meta_box('edit-reg-status-mbox', esc_html__('Registration Status', 'event_espresso'),
1657
+			array($this, 'set_reg_status_buttons_metabox'), $this->wp_page_slug, 'normal', 'high');
1658
+		add_meta_box('edit-reg-details-mbox', esc_html__('Registration Details', 'event_espresso'),
1659
+			array($this, '_reg_details_meta_box'), $this->wp_page_slug, 'normal', 'high');
1660
+		if ($attendee instanceof EE_Attendee
1661
+			&& EE_Registry::instance()->CAP->current_user_can(
1662
+				'ee_edit_registration',
1663
+				'edit-reg-questions-mbox',
1664
+				$this->_registration->ID()
1665
+			)
1666
+		) {
1667
+			add_meta_box(
1668
+				'edit-reg-questions-mbox',
1669
+				esc_html__('Registration Form Answers', 'event_espresso'),
1670
+				array($this, '_reg_questions_meta_box'),
1671
+				$this->wp_page_slug,
1672
+				'normal',
1673
+				'high'
1674
+			);
1675
+		}
1676
+		add_meta_box(
1677
+			'edit-reg-registrant-mbox',
1678
+			esc_html__('Contact Details', 'event_espresso'),
1679
+			array($this, '_reg_registrant_side_meta_box'),
1680
+			$this->wp_page_slug,
1681
+			'side',
1682
+			'high'
1683
+		);
1684
+		if ($this->_registration->group_size() > 1) {
1685
+			add_meta_box(
1686
+				'edit-reg-attendees-mbox',
1687
+				esc_html__('Other Registrations in this Transaction', 'event_espresso'),
1688
+				array($this, '_reg_attendees_meta_box'),
1689
+				$this->wp_page_slug,
1690
+				'normal',
1691
+				'high'
1692
+			);
1693
+		}
1694
+	}
1695
+
1696
+
1697
+	/**
1698
+	 * set_reg_status_buttons_metabox
1699
+	 *
1700
+	 * @access protected
1701
+	 * @return string
1702
+	 * @throws \EE_Error
1703
+	 */
1704
+	public function set_reg_status_buttons_metabox()
1705
+	{
1706
+		$this->_set_registration_object();
1707
+		$change_reg_status_form = $this->_generate_reg_status_change_form();
1708
+		echo $change_reg_status_form->form_open(
1709
+			self::add_query_args_and_nonce(
1710
+				array(
1711
+					'action' => 'change_reg_status',
1712
+				),
1713
+				REG_ADMIN_URL
1714
+			)
1715
+		);
1716
+		echo $change_reg_status_form->get_html();
1717
+		echo $change_reg_status_form->form_close();
1718
+	}
1719
+
1720
+
1721
+	/**
1722
+	 * @return EE_Form_Section_Proper
1723
+	 * @throws EE_Error
1724
+	 * @throws InvalidArgumentException
1725
+	 * @throws InvalidDataTypeException
1726
+	 * @throws InvalidInterfaceException
1727
+	 * @throws \EventEspresso\core\exceptions\EntityNotFoundException
1728
+	 */
1729
+	protected function _generate_reg_status_change_form()
1730
+	{
1731
+		return new EE_Form_Section_Proper(array(
1732
+			'name'            => 'reg_status_change_form',
1733
+			'html_id'         => 'reg-status-change-form',
1734
+			'layout_strategy' => new EE_Admin_Two_Column_Layout(),
1735
+			'subsections'     => array(
1736
+				'return'             => new EE_Hidden_Input(array(
1737
+					'name'    => 'return',
1738
+					'default' => 'view_registration',
1739
+				)),
1740
+				'REG_ID'             => new EE_Hidden_Input(array(
1741
+					'name'    => 'REG_ID',
1742
+					'default' => $this->_registration->ID(),
1743
+				)),
1744
+				'current_status'     => new EE_Form_Section_HTML(
1745
+					EEH_HTML::tr(
1746
+						EEH_HTML::th(
1747
+							EEH_HTML::label(
1748
+								EEH_HTML::strong(esc_html__('Current Registration Status', 'event_espresso')
1749
+								)
1750
+							)
1751
+						)
1752
+						. EEH_HTML::td(
1753
+							EEH_HTML::strong(
1754
+								$this->_registration->pretty_status(),
1755
+								'',
1756
+								'status-' . $this->_registration->status_ID(),
1757
+								'line-height: 1em; font-size: 1.5em; font-weight: bold;'
1758
+							)
1759
+						)
1760
+					)
1761
+				),
1762
+				'reg_status'         => new EE_Select_Input(
1763
+					$this->_get_reg_statuses(),
1764
+					array(
1765
+						'html_label_text' => esc_html__('Change Registration Status to', 'event_espresso'),
1766
+						'default'         => $this->_registration->status_ID(),
1767
+					)
1768
+				),
1769
+				'send_notifications' => new EE_Yes_No_Input(
1770
+					array(
1771
+						'html_label_text' => esc_html__('Send Related Messages', 'event_espresso'),
1772
+						'default'         => false,
1773
+						'html_help_text'  => esc_html__(
1774
+							'If set to "Yes", then the related messages will be sent to the registrant.',
1775
+							'event_espresso'
1776
+						),
1777
+					)
1778
+				),
1779
+				'submit'             => new EE_Submit_Input(
1780
+					array(
1781
+						'html_class'      => 'button-primary',
1782
+						'html_label_text' => '&nbsp;',
1783
+						'default'         => esc_html__('Update Registration Status', 'event_espresso'),
1784
+					)
1785
+				),
1786
+			),
1787
+		));
1788
+	}
1789
+
1790
+
1791
+	/**
1792
+	 * Returns an array of all the buttons for the various statuses and switch status actions
1793
+	 *
1794
+	 * @return array
1795
+	 * @throws EE_Error
1796
+	 * @throws InvalidArgumentException
1797
+	 * @throws InvalidDataTypeException
1798
+	 * @throws InvalidInterfaceException
1799
+	 * @throws EntityNotFoundException
1800
+	 */
1801
+	protected function _get_reg_statuses()
1802
+	{
1803
+		$reg_status_array = EEM_Registration::instance()->reg_status_array();
1804
+		unset ($reg_status_array[EEM_Registration::status_id_incomplete]);
1805
+		// get current reg status
1806
+		$current_status = $this->_registration->status_ID();
1807
+		// is registration for free event? This will determine whether to display the pending payment option
1808
+		if (
1809
+			$current_status !== EEM_Registration::status_id_pending_payment
1810
+			&& EEH_Money::compare_floats($this->_registration->ticket()->price(), 0.00)
1811
+		) {
1812
+			unset($reg_status_array[EEM_Registration::status_id_pending_payment]);
1813
+		}
1814
+		return EEM_Status::instance()->localized_status($reg_status_array, false, 'sentence');
1815
+	}
1816
+
1817
+
1818
+	/**
1819
+	 * This method is used when using _REG_ID from request which may or may not be an array of reg_ids.
1820
+	 *
1821
+	 * @param bool $status REG status given for changing registrations to.
1822
+	 * @param bool $notify Whether to send messages notifications or not.
1823
+	 * @return array (array with reg_id(s) updated and whether update was successful.
1824
+	 * @throws EE_Error
1825
+	 * @throws InvalidArgumentException
1826
+	 * @throws InvalidDataTypeException
1827
+	 * @throws InvalidInterfaceException
1828
+	 * @throws ReflectionException
1829
+	 * @throws RuntimeException
1830
+	 * @throws EntityNotFoundException
1831
+	 */
1832
+	protected function _set_registration_status_from_request($status = false, $notify = false)
1833
+	{
1834
+		if (isset($this->_req_data['reg_status_change_form'])) {
1835
+			$REG_IDs = isset($this->_req_data['reg_status_change_form']['REG_ID'])
1836
+				? (array)$this->_req_data['reg_status_change_form']['REG_ID']
1837
+				: array();
1838
+		} else {
1839
+			$REG_IDs = isset($this->_req_data['_REG_ID'])
1840
+				? (array)$this->_req_data['_REG_ID']
1841
+				: array();
1842
+		}
1843
+		// sanitize $REG_IDs
1844
+		$REG_IDs = array_map('absint', $REG_IDs);
1845
+		// and remove empty entries
1846
+		$REG_IDs = array_filter($REG_IDs);
1847
+
1848
+		$result = $this->_set_registration_status($REG_IDs, $status, $notify);
1849
+
1850
+		/**
1851
+		 * Set and filter $_req_data['_REG_ID'] for any potential future messages notifications.
1852
+		 * Currently this value is used downstream by the _process_resend_registration method.
1853
+		 *
1854
+		 * @param int|array                $registration_ids The registration ids that have had their status changed successfully.
1855
+		 * @param bool                     $status           The status registrations were changed to.
1856
+		 * @param bool                     $success          If the status was changed successfully for all registrations.
1857
+		 * @param Registrations_Admin_Page $admin_page_object
1858
+		 */
1859
+		$this->_req_data['_REG_ID'] = apply_filters(
1860
+			'FHEE__Registrations_Admin_Page___set_registration_status_from_request__REG_IDs',
1861
+			$result['REG_ID'],
1862
+			$status,
1863
+			$result['success'],
1864
+			$this
1865
+		);
1866
+
1867
+		//notify?
1868
+		if ($notify
1869
+			&& $result['success']
1870
+			&& ! empty($this->_req_data['_REG_ID'])
1871
+			&& EE_Registry::instance()->CAP->current_user_can(
1872
+				'ee_send_message',
1873
+				'espresso_registrations_resend_registration'
1874
+			)
1875
+		) {
1876
+			$this->_process_resend_registration();
1877
+		}
1878
+		return $result;
1879
+	}
1880
+
1881
+
1882
+	/**
1883
+	 * Set the registration status for the given reg_id (which may or may not be an array, it gets typecast to an
1884
+	 * array). Note, this method does NOT take care of possible notifications.  That is required by calling code.
1885
+	 *
1886
+	 * @param array  $REG_IDs
1887
+	 * @param string $status
1888
+	 * @param bool   $notify  Used to indicate whether notification was requested or not.  This determines the context
1889
+	 *                        slug sent with setting the registration status.
1890
+	 * @return array (an array with 'success' key representing whether status change was successful, and 'REG_ID' as
1891
+	 * @throws EE_Error
1892
+	 * @throws InvalidArgumentException
1893
+	 * @throws InvalidDataTypeException
1894
+	 * @throws InvalidInterfaceException
1895
+	 * @throws ReflectionException
1896
+	 * @throws RuntimeException
1897
+	 * @throws EntityNotFoundException
1898
+	 */
1899
+	protected function _set_registration_status($REG_IDs = array(), $status = '', $notify = false)
1900
+	{
1901
+		$success = false;
1902
+		// typecast $REG_IDs
1903
+		$REG_IDs = (array)$REG_IDs;
1904
+		if ( ! empty($REG_IDs)) {
1905
+			$success = true;
1906
+			// set default status if none is passed
1907
+			$status = $status ? $status : EEM_Registration::status_id_pending_payment;
1908
+			$status_context = $notify
1909
+				? Domain::CONTEXT_REGISTRATION_STATUS_CHANGE_REGISTRATION_ADMIN_NOTIFY
1910
+				: Domain::CONTEXT_REGISTRATION_STATUS_CHANGE_REGISTRATION_ADMIN;
1911
+			//loop through REG_ID's and change status
1912
+			foreach ($REG_IDs as $REG_ID) {
1913
+				$registration = EEM_Registration::instance()->get_one_by_ID($REG_ID);
1914
+				if ($registration instanceof EE_Registration) {
1915
+					$registration->set_status(
1916
+						$status,
1917
+						false,
1918
+						new Context(
1919
+							$status_context,
1920
+							esc_html__(
1921
+								'Manually triggered status change on a Registration Admin Page route.',
1922
+								'event_espresso'
1923
+							)
1924
+						)
1925
+					);
1926
+					$result = $registration->save();
1927
+					// verifying explicit fails because update *may* just return 0 for 0 rows affected
1928
+					$success = $result !== false ? $success : false;
1929
+				}
1930
+			}
1931
+		}
1932
+
1933
+		//return $success and processed registrations
1934
+		return array('REG_ID' => $REG_IDs, 'success' => $success);
1935
+	}
1936
+
1937
+
1938
+	/**
1939
+	 * Common logic for setting up success message and redirecting to appropriate route
1940
+	 *
1941
+	 * @param  string $STS_ID status id for the registration changed to
1942
+	 * @param   bool  $notify indicates whether the _set_registration_status_from_request does notifications or not.
1943
+	 * @return void
1944
+	 * @throws EE_Error
1945
+	 */
1946
+	protected function _reg_status_change_return($STS_ID, $notify = false)
1947
+	{
1948
+		$result  = ! empty($STS_ID) ? $this->_set_registration_status_from_request($STS_ID, $notify)
1949
+			: array('success' => false);
1950
+		$success = isset($result['success']) && $result['success'];
1951
+		//setup success message
1952
+		if ($success) {
1953
+			if (is_array($result['REG_ID']) && count($result['REG_ID']) === 1) {
1954
+				$msg = sprintf(esc_html__('Registration status has been set to %s', 'event_espresso'),
1955
+					EEH_Template::pretty_status($STS_ID, false, 'lower'));
1956
+			} else {
1957
+				$msg = sprintf(esc_html__('Registrations have been set to %s.', 'event_espresso'),
1958
+					EEH_Template::pretty_status($STS_ID, false, 'lower'));
1959
+			}
1960
+			EE_Error::add_success($msg);
1961
+		} else {
1962
+			EE_Error::add_error(
1963
+				esc_html__(
1964
+					'Something went wrong, and the status was not changed',
1965
+					'event_espresso'
1966
+				), __FILE__, __LINE__, __FUNCTION__
1967
+			);
1968
+		}
1969
+		if (isset($this->_req_data['return']) && $this->_req_data['return'] == 'view_registration') {
1970
+			$route = array('action' => 'view_registration', '_REG_ID' => reset($result['REG_ID']));
1971
+		} else {
1972
+			$route = array('action' => 'default');
1973
+		}
1974
+		//unset nonces
1975
+		foreach ($this->_req_data as $ref => $value) {
1976
+			if (strpos($ref, 'nonce') !== false) {
1977
+				unset($this->_req_data[$ref]);
1978
+				continue;
1979
+			}
1980
+			$value                 = is_array($value) ? array_map('urlencode', $value) : urlencode($value);
1981
+			$this->_req_data[$ref] = $value;
1982
+		}
1983
+		//merge request vars so that the reloaded list table contains any existing filter query params
1984
+		$route = array_merge($this->_req_data, $route);
1985
+		$this->_redirect_after_action($success, '', '', $route, true);
1986
+	}
1987
+
1988
+
1989
+	/**
1990
+	 * incoming reg status change from reg details page.
1991
+	 *
1992
+	 * @return void
1993
+	 */
1994
+	protected function _change_reg_status()
1995
+	{
1996
+		$this->_req_data['return'] = 'view_registration';
1997
+		//set notify based on whether the send notifications toggle is set or not
1998
+		$notify = ! empty($this->_req_data['reg_status_change_form']['send_notifications']);
1999
+		//$notify = ! empty( $this->_req_data['txn_reg_status_change']['send_notifications'] );
2000
+		$this->_req_data['reg_status_change_form']['reg_status'] = isset($this->_req_data['reg_status_change_form']['reg_status'])
2001
+			? $this->_req_data['reg_status_change_form']['reg_status'] : '';
2002
+		switch ($this->_req_data['reg_status_change_form']['reg_status']) {
2003
+			case EEM_Registration::status_id_approved :
2004
+			case EEH_Template::pretty_status(EEM_Registration::status_id_approved, false, 'sentence') :
2005
+				$this->approve_registration($notify);
2006
+				break;
2007
+			case EEM_Registration::status_id_pending_payment :
2008
+			case EEH_Template::pretty_status(EEM_Registration::status_id_pending_payment, false, 'sentence') :
2009
+				$this->pending_registration($notify);
2010
+				break;
2011
+			case EEM_Registration::status_id_not_approved :
2012
+			case EEH_Template::pretty_status(EEM_Registration::status_id_not_approved, false, 'sentence') :
2013
+				$this->not_approve_registration($notify);
2014
+				break;
2015
+			case EEM_Registration::status_id_declined :
2016
+			case EEH_Template::pretty_status(EEM_Registration::status_id_declined, false, 'sentence') :
2017
+				$this->decline_registration($notify);
2018
+				break;
2019
+			case EEM_Registration::status_id_cancelled :
2020
+			case EEH_Template::pretty_status(EEM_Registration::status_id_cancelled, false, 'sentence') :
2021
+				$this->cancel_registration($notify);
2022
+				break;
2023
+			case EEM_Registration::status_id_wait_list :
2024
+			case EEH_Template::pretty_status(EEM_Registration::status_id_wait_list, false, 'sentence') :
2025
+				$this->wait_list_registration($notify);
2026
+				break;
2027
+			case EEM_Registration::status_id_incomplete :
2028
+			default :
2029
+				$result['success'] = false;
2030
+				unset($this->_req_data['return']);
2031
+				$this->_reg_status_change_return('', false);
2032
+				break;
2033
+		}
2034
+	}
2035
+
2036
+
2037
+	/**
2038
+	 * Callback for bulk action routes.
2039
+	 * Note: although we could just register the singular route callbacks for each bulk action route as well, this
2040
+	 * method was chosen so there is one central place all the registration status bulk actions are going through.
2041
+	 * Potentially, this provides an easier place to locate logic that is specific to these bulk actions (as opposed to
2042
+	 * when an action is happening on just a single registration).
2043
+	 * @param      $action
2044
+	 * @param bool $notify
2045
+	 */
2046
+	protected function bulk_action_on_registrations($action, $notify = false) {
2047
+		do_action(
2048
+			'AHEE__Registrations_Admin_Page__bulk_action_on_registrations__before_execution',
2049
+			$this,
2050
+			$action,
2051
+			$notify
2052
+		);
2053
+		$method = $action . '_registration';
2054
+		if (method_exists($this, $method)) {
2055
+			$this->$method($notify);
2056
+		}
2057
+	}
2058
+
2059
+
2060
+	/**
2061
+	 * approve_registration
2062
+	 *
2063
+	 * @access protected
2064
+	 * @param bool $notify whether or not to notify the registrant about their approval.
2065
+	 * @return void
2066
+	 */
2067
+	protected function approve_registration($notify = false)
2068
+	{
2069
+		$this->_reg_status_change_return(EEM_Registration::status_id_approved, $notify);
2070
+	}
2071
+
2072
+
2073
+	/**
2074
+	 *        decline_registration
2075
+	 *
2076
+	 * @access protected
2077
+	 * @param bool $notify whether or not to notify the registrant about their status change.
2078
+	 * @return void
2079
+	 */
2080
+	protected function decline_registration($notify = false)
2081
+	{
2082
+		$this->_reg_status_change_return(EEM_Registration::status_id_declined, $notify);
2083
+	}
2084
+
2085
+
2086
+	/**
2087
+	 *        cancel_registration
2088
+	 *
2089
+	 * @access protected
2090
+	 * @param bool $notify whether or not to notify the registrant about their status change.
2091
+	 * @return void
2092
+	 */
2093
+	protected function cancel_registration($notify = false)
2094
+	{
2095
+		$this->_reg_status_change_return(EEM_Registration::status_id_cancelled, $notify);
2096
+	}
2097
+
2098
+
2099
+	/**
2100
+	 *        not_approve_registration
2101
+	 *
2102
+	 * @access protected
2103
+	 * @param bool $notify whether or not to notify the registrant about their status change.
2104
+	 * @return void
2105
+	 */
2106
+	protected function not_approve_registration($notify = false)
2107
+	{
2108
+		$this->_reg_status_change_return(EEM_Registration::status_id_not_approved, $notify);
2109
+	}
2110
+
2111
+
2112
+	/**
2113
+	 *        decline_registration
2114
+	 *
2115
+	 * @access protected
2116
+	 * @param bool $notify whether or not to notify the registrant about their status change.
2117
+	 * @return void
2118
+	 */
2119
+	protected function pending_registration($notify = false)
2120
+	{
2121
+		$this->_reg_status_change_return(EEM_Registration::status_id_pending_payment, $notify);
2122
+	}
2123
+
2124
+
2125
+	/**
2126
+	 * waitlist_registration
2127
+	 *
2128
+	 * @access protected
2129
+	 * @param bool $notify whether or not to notify the registrant about their status change.
2130
+	 * @return void
2131
+	 */
2132
+	protected function wait_list_registration($notify = false)
2133
+	{
2134
+		$this->_reg_status_change_return(EEM_Registration::status_id_wait_list, $notify);
2135
+	}
2136
+
2137
+
2138
+	/**
2139
+	 *        generates HTML for the Registration main meta box
2140
+	 *
2141
+	 * @access public
2142
+	 * @return void
2143
+	 * @throws DomainException
2144
+	 * @throws EE_Error
2145
+	 * @throws InvalidArgumentException
2146
+	 * @throws InvalidDataTypeException
2147
+	 * @throws InvalidInterfaceException
2148
+	 * @throws ReflectionException
2149
+	 * @throws EntityNotFoundException
2150
+	 */
2151
+	public function _reg_details_meta_box()
2152
+	{
2153
+		EEH_Autoloader::register_line_item_display_autoloaders();
2154
+		EEH_Autoloader::register_line_item_filter_autoloaders();
2155
+		EE_Registry::instance()->load_helper('Line_Item');
2156
+		$transaction    = $this->_registration->transaction() ? $this->_registration->transaction()
2157
+			: EE_Transaction::new_instance();
2158
+		$this->_session = $transaction->session_data();
2159
+		$filters        = new EE_Line_Item_Filter_Collection();
2160
+		//$filters->add( new EE_Non_Zero_Line_Item_Filter() );
2161
+		$filters->add(new EE_Single_Registration_Line_Item_Filter($this->_registration));
2162
+		$line_item_filter_processor              = new EE_Line_Item_Filter_Processor($filters,
2163
+			$transaction->total_line_item());
2164
+		$filtered_line_item_tree                 = $line_item_filter_processor->process();
2165
+		$line_item_display                       = new EE_Line_Item_Display('reg_admin_table',
2166
+			'EE_Admin_Table_Registration_Line_Item_Display_Strategy');
2167
+		$this->_template_args['line_item_table'] = $line_item_display->display_line_item(
2168
+			$filtered_line_item_tree,
2169
+			array('EE_Registration' => $this->_registration)
2170
+		);
2171
+		$attendee                                = $this->_registration->attendee();
2172
+		if (EE_Registry::instance()->CAP->current_user_can(
2173
+			'ee_read_transaction',
2174
+			'espresso_transactions_view_transaction'
2175
+		)) {
2176
+			$this->_template_args['view_transaction_button'] = EEH_Template::get_button_or_link(
2177
+				EE_Admin_Page::add_query_args_and_nonce(
2178
+					array(
2179
+						'action' => 'view_transaction',
2180
+						'TXN_ID' => $transaction->ID(),
2181
+					),
2182
+					TXN_ADMIN_URL
2183
+				),
2184
+				esc_html__(' View Transaction', 'event_espresso'),
2185
+				'button secondary-button right',
2186
+				'dashicons dashicons-cart'
2187
+			);
2188
+		} else {
2189
+			$this->_template_args['view_transaction_button'] = '';
2190
+		}
2191
+		if ($attendee instanceof EE_Attendee
2192
+			&& EE_Registry::instance()->CAP->current_user_can(
2193
+				'ee_send_message',
2194
+				'espresso_registrations_resend_registration'
2195
+			)
2196
+		) {
2197
+			$this->_template_args['resend_registration_button'] = EEH_Template::get_button_or_link(
2198
+				EE_Admin_Page::add_query_args_and_nonce(
2199
+					array(
2200
+						'action'      => 'resend_registration',
2201
+						'_REG_ID'     => $this->_registration->ID(),
2202
+						'redirect_to' => 'view_registration',
2203
+					),
2204
+					REG_ADMIN_URL
2205
+				),
2206
+				esc_html__(' Resend Registration', 'event_espresso'),
2207
+				'button secondary-button right',
2208
+				'dashicons dashicons-email-alt'
2209
+			);
2210
+		} else {
2211
+			$this->_template_args['resend_registration_button'] = '';
2212
+		}
2213
+		$this->_template_args['currency_sign'] = EE_Registry::instance()->CFG->currency->sign;
2214
+		$payment                               = $transaction->get_first_related('Payment');
2215
+		$payment                               = ! $payment instanceof EE_Payment
2216
+			? EE_Payment::new_instance()
2217
+			: $payment;
2218
+		$payment_method                        = $payment->get_first_related('Payment_Method');
2219
+		$payment_method                        = ! $payment_method instanceof EE_Payment_Method
2220
+			? EE_Payment_Method::new_instance()
2221
+			: $payment_method;
2222
+		$reg_details                           = array(
2223
+			'payment_method'       => $payment_method->name(),
2224
+			'response_msg'         => $payment->gateway_response(),
2225
+			'registration_id'      => $this->_registration->get('REG_code'),
2226
+			'registration_session' => $this->_registration->session_ID(),
2227
+			'ip_address'           => isset($this->_session['ip_address']) ? $this->_session['ip_address'] : '',
2228
+			'user_agent'           => isset($this->_session['user_agent']) ? $this->_session['user_agent'] : '',
2229
+		);
2230
+		if (isset($reg_details['registration_id'])) {
2231
+			$this->_template_args['reg_details']['registration_id']['value'] = $reg_details['registration_id'];
2232
+			$this->_template_args['reg_details']['registration_id']['label'] = esc_html__(
2233
+				'Registration ID',
2234
+				'event_espresso'
2235
+			);
2236
+			$this->_template_args['reg_details']['registration_id']['class'] = 'regular-text';
2237
+		}
2238
+		if (isset($reg_details['payment_method'])) {
2239
+			$this->_template_args['reg_details']['payment_method']['value'] = $reg_details['payment_method'];
2240
+			$this->_template_args['reg_details']['payment_method']['label'] = esc_html__(
2241
+				'Most Recent Payment Method',
2242
+				'event_espresso'
2243
+			);
2244
+			$this->_template_args['reg_details']['payment_method']['class'] = 'regular-text';
2245
+			$this->_template_args['reg_details']['response_msg']['value']   = $reg_details['response_msg'];
2246
+			$this->_template_args['reg_details']['response_msg']['label']   = esc_html__(
2247
+				'Payment method response',
2248
+				'event_espresso'
2249
+			);
2250
+			$this->_template_args['reg_details']['response_msg']['class']   = 'regular-text';
2251
+		}
2252
+		$this->_template_args['reg_details']['registration_session']['value'] = $reg_details['registration_session'];
2253
+		$this->_template_args['reg_details']['registration_session']['label'] = esc_html__(
2254
+			'Registration Session',
2255
+			'event_espresso'
2256
+		);
2257
+		$this->_template_args['reg_details']['registration_session']['class'] = 'regular-text';
2258
+		$this->_template_args['reg_details']['ip_address']['value']           = $reg_details['ip_address'];
2259
+		$this->_template_args['reg_details']['ip_address']['label']           = esc_html__(
2260
+			'Registration placed from IP',
2261
+			'event_espresso'
2262
+		);
2263
+		$this->_template_args['reg_details']['ip_address']['class']           = 'regular-text';
2264
+		$this->_template_args['reg_details']['user_agent']['value']           = $reg_details['user_agent'];
2265
+		$this->_template_args['reg_details']['user_agent']['label']           = esc_html__('Registrant User Agent',
2266
+			'event_espresso');
2267
+		$this->_template_args['reg_details']['user_agent']['class']           = 'large-text';
2268
+		$this->_template_args['event_link']                                   = EE_Admin_Page::add_query_args_and_nonce(
2269
+			array(
2270
+				'action'   => 'default',
2271
+				'event_id' => $this->_registration->event_ID(),
2272
+			),
2273
+			REG_ADMIN_URL
2274
+		);
2275
+		$this->_template_args['REG_ID']                                       = $this->_registration->ID();
2276
+		$this->_template_args['event_id']                                     = $this->_registration->event_ID();
2277
+		$template_path                                                        =
2278
+			REG_TEMPLATE_PATH . 'reg_admin_details_main_meta_box_reg_details.template.php';
2279
+		echo EEH_Template::display_template($template_path, $this->_template_args, true);
2280
+	}
2281
+
2282
+
2283
+	/**
2284
+	 * generates HTML for the Registration Questions meta box.
2285
+	 * If pre-4.8.32.rc.000 hooks are used, uses old methods (with its filters),
2286
+	 * otherwise uses new forms system
2287
+	 *
2288
+	 * @access public
2289
+	 * @return void
2290
+	 * @throws DomainException
2291
+	 * @throws EE_Error
2292
+	 */
2293
+	public function _reg_questions_meta_box()
2294
+	{
2295
+		//allow someone to override this method entirely
2296
+		if (apply_filters('FHEE__Registrations_Admin_Page___reg_questions_meta_box__do_default', true, $this,
2297
+			$this->_registration)) {
2298
+			$form                                              = $this->_get_reg_custom_questions_form(
2299
+				$this->_registration->ID()
2300
+			);
2301
+			$this->_template_args['att_questions']             = count($form->subforms()) > 0
2302
+				? $form->get_html_and_js()
2303
+				: '';
2304
+			$this->_template_args['reg_questions_form_action'] = 'edit_registration';
2305
+			$this->_template_args['REG_ID']                    = $this->_registration->ID();
2306
+			$template_path                                     =
2307
+				REG_TEMPLATE_PATH . 'reg_admin_details_main_meta_box_reg_questions.template.php';
2308
+			echo EEH_Template::display_template($template_path, $this->_template_args, true);
2309
+		}
2310
+	}
2311
+
2312
+
2313
+	/**
2314
+	 * form_before_question_group
2315
+	 *
2316
+	 * @deprecated    as of 4.8.32.rc.000
2317
+	 * @access        public
2318
+	 * @param        string $output
2319
+	 * @return        string
2320
+	 */
2321
+	public function form_before_question_group($output)
2322
+	{
2323
+		EE_Error::doing_it_wrong(
2324
+			__CLASS__ . '::' . __FUNCTION__,
2325
+			esc_html__(
2326
+				'This method would have been protected but was used on a filter callback so needed to be public. Please discontinue usage as it will be removed soon.',
2327
+				'event_espresso'
2328
+			),
2329
+			'4.8.32.rc.000'
2330
+		);
2331
+		return '
2332 2332
 	<table class="form-table ee-width-100">
2333 2333
 		<tbody>
2334 2334
 			';
2335
-    }
2336
-
2337
-
2338
-    /**
2339
-     * form_after_question_group
2340
-     *
2341
-     * @deprecated    as of 4.8.32.rc.000
2342
-     * @access        public
2343
-     * @param        string $output
2344
-     * @return        string
2345
-     */
2346
-    public function form_after_question_group($output)
2347
-    {
2348
-        EE_Error::doing_it_wrong(
2349
-            __CLASS__ . '::' . __FUNCTION__,
2350
-            esc_html__(
2351
-                'This method would have been protected but was used on a filter callback so needed to be public. Please discontinue usage as it will be removed soon.',
2352
-                'event_espresso'
2353
-            ),
2354
-            '4.8.32.rc.000'
2355
-        );
2356
-        return '
2335
+	}
2336
+
2337
+
2338
+	/**
2339
+	 * form_after_question_group
2340
+	 *
2341
+	 * @deprecated    as of 4.8.32.rc.000
2342
+	 * @access        public
2343
+	 * @param        string $output
2344
+	 * @return        string
2345
+	 */
2346
+	public function form_after_question_group($output)
2347
+	{
2348
+		EE_Error::doing_it_wrong(
2349
+			__CLASS__ . '::' . __FUNCTION__,
2350
+			esc_html__(
2351
+				'This method would have been protected but was used on a filter callback so needed to be public. Please discontinue usage as it will be removed soon.',
2352
+				'event_espresso'
2353
+			),
2354
+			'4.8.32.rc.000'
2355
+		);
2356
+		return '
2357 2357
 			<tr class="hide-if-no-js">
2358 2358
 				<th> </th>
2359 2359
 				<td class="reg-admin-edit-attendee-question-td">
2360 2360
 					<a class="reg-admin-edit-attendee-question-lnk" href="#" title="'
2361
-               . esc_attr__('click to edit question', 'event_espresso')
2362
-               . '">
2361
+			   . esc_attr__('click to edit question', 'event_espresso')
2362
+			   . '">
2363 2363
 						<span class="reg-admin-edit-question-group-spn lt-grey-txt">'
2364
-               . esc_html__('edit the above question group', 'event_espresso')
2365
-               . '</span>
2364
+			   . esc_html__('edit the above question group', 'event_espresso')
2365
+			   . '</span>
2366 2366
 						<div class="dashicons dashicons-edit"></div>
2367 2367
 					</a>
2368 2368
 				</td>
@@ -2370,579 +2370,579 @@  discard block
 block discarded – undo
2370 2370
 		</tbody>
2371 2371
 	</table>
2372 2372
 ';
2373
-    }
2374
-
2375
-
2376
-    /**
2377
-     * form_form_field_label_wrap
2378
-     *
2379
-     * @deprecated    as of 4.8.32.rc.000
2380
-     * @access        public
2381
-     * @param        string $label
2382
-     * @return        string
2383
-     */
2384
-    public function form_form_field_label_wrap($label)
2385
-    {
2386
-        EE_Error::doing_it_wrong(
2387
-            __CLASS__ . '::' . __FUNCTION__,
2388
-            esc_html__(
2389
-                'This method would have been protected but was used on a filter callback so needed to be public. Please discontinue usage as it will be removed soon.',
2390
-                'event_espresso'
2391
-            ),
2392
-            '4.8.32.rc.000'
2393
-        );
2394
-        return '
2373
+	}
2374
+
2375
+
2376
+	/**
2377
+	 * form_form_field_label_wrap
2378
+	 *
2379
+	 * @deprecated    as of 4.8.32.rc.000
2380
+	 * @access        public
2381
+	 * @param        string $label
2382
+	 * @return        string
2383
+	 */
2384
+	public function form_form_field_label_wrap($label)
2385
+	{
2386
+		EE_Error::doing_it_wrong(
2387
+			__CLASS__ . '::' . __FUNCTION__,
2388
+			esc_html__(
2389
+				'This method would have been protected but was used on a filter callback so needed to be public. Please discontinue usage as it will be removed soon.',
2390
+				'event_espresso'
2391
+			),
2392
+			'4.8.32.rc.000'
2393
+		);
2394
+		return '
2395 2395
 			<tr>
2396 2396
 				<th>
2397 2397
 					' . $label . '
2398 2398
 				</th>';
2399
-    }
2400
-
2401
-
2402
-    /**
2403
-     * form_form_field_input__wrap
2404
-     *
2405
-     * @deprecated    as of 4.8.32.rc.000
2406
-     * @access        public
2407
-     * @param        string $input
2408
-     * @return        string
2409
-     */
2410
-    public function form_form_field_input__wrap($input)
2411
-    {
2412
-        EE_Error::doing_it_wrong(
2413
-            __CLASS__ . '::' . __FUNCTION__,
2414
-            esc_html__(
2415
-                'This method would have been protected but was used on a filter callback so needed to be public. Please discontinue usage as it will be removed soon.',
2416
-                'event_espresso'
2417
-            ),
2418
-            '4.8.32.rc.000'
2419
-        );
2420
-        return '
2399
+	}
2400
+
2401
+
2402
+	/**
2403
+	 * form_form_field_input__wrap
2404
+	 *
2405
+	 * @deprecated    as of 4.8.32.rc.000
2406
+	 * @access        public
2407
+	 * @param        string $input
2408
+	 * @return        string
2409
+	 */
2410
+	public function form_form_field_input__wrap($input)
2411
+	{
2412
+		EE_Error::doing_it_wrong(
2413
+			__CLASS__ . '::' . __FUNCTION__,
2414
+			esc_html__(
2415
+				'This method would have been protected but was used on a filter callback so needed to be public. Please discontinue usage as it will be removed soon.',
2416
+				'event_espresso'
2417
+			),
2418
+			'4.8.32.rc.000'
2419
+		);
2420
+		return '
2421 2421
 				<td class="reg-admin-attendee-questions-input-td disabled-input">
2422 2422
 					' . $input . '
2423 2423
 				</td>
2424 2424
 			</tr>';
2425
-    }
2426
-
2427
-
2428
-    /**
2429
-     * Updates the registration's custom questions according to the form info, if the form is submitted.
2430
-     * If it's not a post, the "view_registrations" route will be called next on the SAME request
2431
-     * to display the page
2432
-     *
2433
-     * @access protected
2434
-     * @return void
2435
-     * @throws EE_Error
2436
-     */
2437
-    protected function _update_attendee_registration_form()
2438
-    {
2439
-        do_action('AHEE__Registrations_Admin_Page___update_attendee_registration_form__start', $this);
2440
-        if ($_SERVER['REQUEST_METHOD'] == 'POST') {
2441
-            $REG_ID  = isset($this->_req_data['_REG_ID']) ? absint($this->_req_data['_REG_ID']) : false;
2442
-            $success = $this->_save_reg_custom_questions_form($REG_ID);
2443
-            if ($success) {
2444
-                $what  = esc_html__('Registration Form', 'event_espresso');
2445
-                $route = $REG_ID ? array('action' => 'view_registration', '_REG_ID' => $REG_ID)
2446
-                    : array('action' => 'default');
2447
-                $this->_redirect_after_action($success, $what, esc_html__('updated', 'event_espresso'), $route);
2448
-            }
2449
-        }
2450
-    }
2451
-
2452
-
2453
-    /**
2454
-     * Gets the form for saving registrations custom questions (if done
2455
-     * previously retrieves the cached form object, which may have validation errors in it)
2456
-     *
2457
-     * @param int $REG_ID
2458
-     * @return EE_Registration_Custom_Questions_Form
2459
-     * @throws EE_Error
2460
-     * @throws InvalidArgumentException
2461
-     * @throws InvalidDataTypeException
2462
-     * @throws InvalidInterfaceException
2463
-     */
2464
-    protected function _get_reg_custom_questions_form($REG_ID)
2465
-    {
2466
-        if ( ! $this->_reg_custom_questions_form) {
2467
-            require_once(REG_ADMIN . 'form_sections' . DS . 'EE_Registration_Custom_Questions_Form.form.php');
2468
-            $this->_reg_custom_questions_form = new EE_Registration_Custom_Questions_Form(
2469
-                EEM_Registration::instance()->get_one_by_ID($REG_ID)
2470
-            );
2471
-            $this->_reg_custom_questions_form->_construct_finalize(null, null);
2472
-        }
2473
-        return $this->_reg_custom_questions_form;
2474
-    }
2475
-
2476
-
2477
-    /**
2478
-     * Saves
2479
-     *
2480
-     * @access private
2481
-     * @param bool $REG_ID
2482
-     * @return bool
2483
-     * @throws EE_Error
2484
-     * @throws InvalidArgumentException
2485
-     * @throws InvalidDataTypeException
2486
-     * @throws InvalidInterfaceException
2487
-     */
2488
-    private function _save_reg_custom_questions_form($REG_ID = false)
2489
-    {
2490
-        if ( ! $REG_ID) {
2491
-            EE_Error::add_error(
2492
-                esc_html__(
2493
-                    'An error occurred. No registration ID was received.', 'event_espresso'),
2494
-                __FILE__, __FUNCTION__, __LINE__
2495
-            );
2496
-        }
2497
-        $form = $this->_get_reg_custom_questions_form($REG_ID);
2498
-        $form->receive_form_submission($this->_req_data);
2499
-        $success = false;
2500
-        if ($form->is_valid()) {
2501
-            foreach ($form->subforms() as $question_group_id => $question_group_form) {
2502
-                foreach ($question_group_form->inputs() as $question_id => $input) {
2503
-                    $where_conditions    = array(
2504
-                        'QST_ID' => $question_id,
2505
-                        'REG_ID' => $REG_ID,
2506
-                    );
2507
-                    $possibly_new_values = array(
2508
-                        'ANS_value' => $input->normalized_value(),
2509
-                    );
2510
-                    $answer              = EEM_Answer::instance()->get_one(array($where_conditions));
2511
-                    if ($answer instanceof EE_Answer) {
2512
-                        $success = $answer->save($possibly_new_values);
2513
-                    } else {
2514
-                        //insert it then
2515
-                        $cols_n_vals = array_merge($where_conditions, $possibly_new_values);
2516
-                        $answer      = EE_Answer::new_instance($cols_n_vals);
2517
-                        $success     = $answer->save();
2518
-                    }
2519
-                }
2520
-            }
2521
-        } else {
2522
-            EE_Error::add_error($form->get_validation_error_string(), __FILE__, __FUNCTION__, __LINE__);
2523
-        }
2524
-        return $success;
2525
-    }
2526
-
2527
-
2528
-    /**
2529
-     *        generates HTML for the Registration main meta box
2530
-     *
2531
-     * @access public
2532
-     * @return void
2533
-     * @throws DomainException
2534
-     * @throws EE_Error
2535
-     * @throws InvalidArgumentException
2536
-     * @throws InvalidDataTypeException
2537
-     * @throws InvalidInterfaceException
2538
-     */
2539
-    public function _reg_attendees_meta_box()
2540
-    {
2541
-        $REG = EEM_Registration::instance();
2542
-        //get all other registrations on this transaction, and cache
2543
-        //the attendees for them so we don't have to run another query using force_join
2544
-        $registrations                           = $REG->get_all(array(
2545
-            array(
2546
-                'TXN_ID' => $this->_registration->transaction_ID(),
2547
-                'REG_ID' => array('!=', $this->_registration->ID()),
2548
-            ),
2549
-            'force_join' => array('Attendee'),
2550
-        ));
2551
-        $this->_template_args['attendees']       = array();
2552
-        $this->_template_args['attendee_notice'] = '';
2553
-        if (empty($registrations)
2554
-            || (is_array($registrations)
2555
-                && ! EEH_Array::get_one_item_from_array($registrations))
2556
-        ) {
2557
-            EE_Error::add_error(
2558
-                esc_html__(
2559
-                    'There are no records attached to this registration. Something may have gone wrong with the registration',
2560
-                    'event_espresso'
2561
-                ), __FILE__, __FUNCTION__, __LINE__
2562
-            );
2563
-            $this->_template_args['attendee_notice'] = EE_Error::get_notices();
2564
-        } else {
2565
-            $att_nmbr = 1;
2566
-            foreach ($registrations as $registration) {
2567
-                /* @var $registration EE_Registration */
2568
-                $attendee                                                    = $registration->attendee()
2569
-                    ? $registration->attendee()
2570
-                    : EEM_Attendee::instance()
2571
-                                  ->create_default_object();
2572
-                $this->_template_args['attendees'][$att_nmbr]['STS_ID']      = $registration->status_ID();
2573
-                $this->_template_args['attendees'][$att_nmbr]['fname']       = $attendee->fname();
2574
-                $this->_template_args['attendees'][$att_nmbr]['lname']       = $attendee->lname();
2575
-                $this->_template_args['attendees'][$att_nmbr]['email']       = $attendee->email();
2576
-                $this->_template_args['attendees'][$att_nmbr]['final_price'] = $registration->final_price();
2577
-                $this->_template_args['attendees'][$att_nmbr]['address']     = implode(
2578
-                    ', ',
2579
-                    $attendee->full_address_as_array()
2580
-                );
2581
-                $this->_template_args['attendees'][$att_nmbr]['att_link']    = self::add_query_args_and_nonce(
2582
-                    array(
2583
-                        'action' => 'edit_attendee',
2584
-                        'post'   => $attendee->ID(),
2585
-                    ),
2586
-                    REG_ADMIN_URL
2587
-                );
2588
-                $this->_template_args['attendees'][$att_nmbr]['event_name']  = $registration->event_obj()->name();
2589
-                $att_nmbr++;
2590
-            }
2591
-            $this->_template_args['currency_sign'] = EE_Registry::instance()->CFG->currency->sign;
2592
-        }
2593
-        $template_path = REG_TEMPLATE_PATH . 'reg_admin_details_main_meta_box_attendees.template.php';
2594
-        echo EEH_Template::display_template($template_path, $this->_template_args, true);
2595
-    }
2596
-
2597
-
2598
-    /**
2599
-     *        generates HTML for the Edit Registration side meta box
2600
-     *
2601
-     * @access public
2602
-     * @return void
2603
-     * @throws DomainException
2604
-     * @throws EE_Error
2605
-     * @throws InvalidArgumentException
2606
-     * @throws InvalidDataTypeException
2607
-     * @throws InvalidInterfaceException
2608
-     */
2609
-    public function _reg_registrant_side_meta_box()
2610
-    {
2611
-        /*@var $attendee EE_Attendee */
2612
-        $att_check = $this->_registration->attendee();
2613
-        $attendee  = $att_check instanceof EE_Attendee ? $att_check : EEM_Attendee::instance()->create_default_object();
2614
-        //now let's determine if this is not the primary registration.  If it isn't then we set the
2615
-        //primary_registration object for reference BUT ONLY if the Attendee object loaded is not the same as the
2616
-        //primary registration object (that way we know if we need to show create button or not)
2617
-        if ( ! $this->_registration->is_primary_registrant()) {
2618
-            $primary_registration = $this->_registration->get_primary_registration();
2619
-            $primary_attendee     = $primary_registration instanceof EE_Registration ? $primary_registration->attendee()
2620
-                : null;
2621
-            if ( ! $primary_attendee instanceof EE_Attendee || $attendee->ID() !== $primary_attendee->ID()) {
2622
-                //in here?  This means the displayed registration is not the primary registrant but ALREADY HAS its own
2623
-                //custom attendee object so let's not worry about the primary reg.
2624
-                $primary_registration = null;
2625
-            }
2626
-        } else {
2627
-            $primary_registration = null;
2628
-        }
2629
-        $this->_template_args['ATT_ID']            = $attendee->ID();
2630
-        $this->_template_args['fname']             = $attendee->fname();
2631
-        $this->_template_args['lname']             = $attendee->lname();
2632
-        $this->_template_args['email']             = $attendee->email();
2633
-        $this->_template_args['phone']             = $attendee->phone();
2634
-        $this->_template_args['formatted_address'] = EEH_Address::format($attendee);
2635
-        //edit link
2636
-        $this->_template_args['att_edit_link']  = EE_Admin_Page::add_query_args_and_nonce(array(
2637
-            'action' => 'edit_attendee',
2638
-            'post'   => $attendee->ID(),
2639
-        ), REG_ADMIN_URL);
2640
-        $this->_template_args['att_edit_label'] = esc_html__('View/Edit Contact', 'event_espresso');
2641
-        //create link
2642
-        $this->_template_args['create_link']  = $primary_registration instanceof EE_Registration
2643
-            ? EE_Admin_Page::add_query_args_and_nonce(array(
2644
-                'action'  => 'duplicate_attendee',
2645
-                '_REG_ID' => $this->_registration->ID(),
2646
-            ), REG_ADMIN_URL) : '';
2647
-        $this->_template_args['create_label'] = esc_html__('Create Contact', 'event_espresso');
2648
-        $this->_template_args['att_check']    = $att_check;
2649
-        $template_path                        = REG_TEMPLATE_PATH . 'reg_admin_details_side_meta_box_registrant.template.php';
2650
-        echo EEH_Template::display_template($template_path, $this->_template_args, true);
2651
-    }
2652
-
2653
-
2654
-    /**
2655
-     * trash or restore registrations
2656
-     *
2657
-     * @param  boolean $trash whether to archive or restore
2658
-     * @return void
2659
-     * @throws EE_Error
2660
-     * @throws InvalidArgumentException
2661
-     * @throws InvalidDataTypeException
2662
-     * @throws InvalidInterfaceException
2663
-     * @throws RuntimeException
2664
-     * @access protected
2665
-     */
2666
-    protected function _trash_or_restore_registrations($trash = true)
2667
-    {
2668
-        //if empty _REG_ID then get out because there's nothing to do
2669
-        if (empty($this->_req_data['_REG_ID'])) {
2670
-            EE_Error::add_error(
2671
-                sprintf(
2672
-                    esc_html__(
2673
-                        'In order to %1$s registrations you must select which ones you wish to %1$s by clicking the checkboxes.',
2674
-                        'event_espresso'
2675
-                    ),
2676
-                    $trash ? 'trash' : 'restore'
2677
-                ),
2678
-                __FILE__, __LINE__, __FUNCTION__
2679
-            );
2680
-            $this->_redirect_after_action(false, '', '', array(), true);
2681
-        }
2682
-        $success = 0;
2683
-        $overwrite_msgs = false;
2684
-        //Checkboxes
2685
-        if ( ! is_array($this->_req_data['_REG_ID'])) {
2686
-            $this->_req_data['_REG_ID'] = array($this->_req_data['_REG_ID']);
2687
-        }
2688
-        $reg_count = count($this->_req_data['_REG_ID']);
2689
-        // cycle thru checkboxes
2690
-        foreach ($this->_req_data['_REG_ID'] as $REG_ID) {
2691
-            /** @var EE_Registration $REG */
2692
-            $REG = EEM_Registration::instance()->get_one_by_ID($REG_ID);
2693
-            $payments = $REG->registration_payments();
2694
-            if (! empty($payments)) {
2695
-                $name = $REG->attendee() instanceof EE_Attendee
2696
-                    ? $REG->attendee()->full_name()
2697
-                    : esc_html__('Unknown Attendee', 'event_espresso');
2698
-                $overwrite_msgs = true;
2699
-                EE_Error::add_error(
2700
-                    sprintf(
2701
-                        esc_html__(
2702
-                            'The registration for %s could not be trashed because it has payments attached to the related transaction.  If you wish to trash this registration you must first delete the payments on the related transaction.',
2703
-                            'event_espresso'
2704
-                        ),
2705
-                        $name
2706
-                    ),
2707
-                    __FILE__, __FUNCTION__, __LINE__
2708
-                );
2709
-                //can't trash this registration because it has payments.
2710
-                continue;
2711
-            }
2712
-            $updated = $trash ? $REG->delete() : $REG->restore();
2713
-            if ($updated) {
2714
-                $success++;
2715
-            }
2716
-        }
2717
-        $this->_redirect_after_action(
2718
-            $success === $reg_count, // were ALL registrations affected?
2719
-            $success > 1
2720
-                ? esc_html__('Registrations', 'event_espresso')
2721
-                : esc_html__('Registration', 'event_espresso'),
2722
-            $trash
2723
-                ? esc_html__('moved to the trash', 'event_espresso')
2724
-                : esc_html__('restored', 'event_espresso'),
2725
-            array('action' => 'default'),
2726
-            $overwrite_msgs
2727
-        );
2728
-    }
2729
-
2730
-
2731
-    /**
2732
-     * This is used to permanently delete registrations.  Note, this will handle not only deleting permanently the
2733
-     * registration but also.
2734
-     * 1. Removing relations to EE_Attendee
2735
-     * 2. Deleting permanently the related transaction, but ONLY if all related registrations to the transaction are
2736
-     * ALSO trashed.
2737
-     * 3. Deleting permanently any related Line items but only if the above conditions are met.
2738
-     * 4. Removing relationships between all tickets and the related registrations
2739
-     * 5. Deleting permanently any related Answers (and the answers for other related registrations that were deleted.)
2740
-     * 6. Deleting permanently any related Checkins.
2741
-     *
2742
-     * @return void
2743
-     * @throws EE_Error
2744
-     * @throws InvalidArgumentException
2745
-     * @throws InvalidDataTypeException
2746
-     * @throws InvalidInterfaceException
2747
-     */
2748
-    protected function _delete_registrations()
2749
-    {
2750
-        $REG_MDL = EEM_Registration::instance();
2751
-        $success = 1;
2752
-        //Checkboxes
2753
-        if ( ! empty($this->_req_data['_REG_ID']) && is_array($this->_req_data['_REG_ID'])) {
2754
-            // if array has more than one element than success message should be plural
2755
-            $success = count($this->_req_data['_REG_ID']) > 1 ? 2 : 1;
2756
-            // cycle thru checkboxes
2757
-            while (list($ind, $REG_ID) = each($this->_req_data['_REG_ID'])) {
2758
-                $REG = $REG_MDL->get_one_by_ID($REG_ID);
2759
-                if ( ! $REG instanceof EE_Registration) {
2760
-                    continue;
2761
-                }
2762
-                $deleted = $this->_delete_registration($REG);
2763
-                if ( ! $deleted) {
2764
-                    $success = 0;
2765
-                }
2766
-            }
2767
-        } else {
2768
-            // grab single id and delete
2769
-            $REG_ID  = $this->_req_data['_REG_ID'];
2770
-            $REG     = $REG_MDL->get_one_by_ID($REG_ID);
2771
-            $deleted = $this->_delete_registration($REG);
2772
-            if ( ! $deleted) {
2773
-                $success = 0;
2774
-            }
2775
-        }
2776
-        $what        = $success > 1
2777
-            ? esc_html__('Registrations', 'event_espresso')
2778
-            : esc_html__('Registration', 'event_espresso');
2779
-        $action_desc = esc_html__('permanently deleted.', 'event_espresso');
2780
-        $this->_redirect_after_action(
2781
-            $success,
2782
-            $what,
2783
-            $action_desc,
2784
-            array('action' => 'default'),
2785
-            true
2786
-        );
2787
-    }
2788
-
2789
-
2790
-    /**
2791
-     * handles the permanent deletion of a registration.  See comments with _delete_registrations() for details on what
2792
-     * models get affected.
2793
-     *
2794
-     * @param  EE_Registration $REG registration to be deleted permenantly
2795
-     * @return bool true = successful deletion, false = fail.
2796
-     * @throws EE_Error
2797
-     */
2798
-    protected function _delete_registration(EE_Registration $REG)
2799
-    {
2800
-        //first we start with the transaction... ultimately, we WILL not delete permanently if there are any related
2801
-        //registrations on the transaction that are NOT trashed.
2802
-        $TXN         = $REG->get_first_related('Transaction');
2803
-        $REGS        = $TXN->get_many_related('Registration');
2804
-        $all_trashed = true;
2805
-        foreach ($REGS as $registration) {
2806
-            if ( ! $registration->get('REG_deleted')) {
2807
-                $all_trashed = false;
2808
-            }
2809
-        }
2810
-        if ( ! $all_trashed) {
2811
-            EE_Error::add_error(
2812
-                esc_html__(
2813
-                    'Unable to permanently delete this registration. Before this registration can be permanently deleted, all registrations made in the same transaction must be trashed as well.  These registrations will be permanently deleted in the same action.',
2814
-                    'event_espresso'
2815
-                ),
2816
-                __FILE__, __FUNCTION__, __LINE__
2817
-            );
2818
-            return false;
2819
-        }
2820
-        //k made it here so that means we can delete all the related transactions and their answers (but let's do them
2821
-        //separately from THIS one).
2822
-        foreach ($REGS as $registration) {
2823
-            //delete related answers
2824
-            $registration->delete_related_permanently('Answer');
2825
-            //remove relationship to EE_Attendee (but we ALWAYS leave the contact record intact)
2826
-            $attendee = $registration->get_first_related('Attendee');
2827
-            if ($attendee instanceof EE_Attendee) {
2828
-                $registration->_remove_relation_to($attendee, 'Attendee');
2829
-            }
2830
-            //now remove relationships to tickets on this registration.
2831
-            $registration->_remove_relations('Ticket');
2832
-            //now delete permanently the checkins related to this registration.
2833
-            $registration->delete_related_permanently('Checkin');
2834
-            if ($registration->ID() === $REG->ID()) {
2835
-                continue;
2836
-            } //we don't want to delete permanently the existing registration just yet.
2837
-            //remove relation to transaction for these registrations if NOT the existing registrations
2838
-            $registration->_remove_relations('Transaction');
2839
-            //delete permanently any related messages.
2840
-            $registration->delete_related_permanently('Message');
2841
-            //now delete this registration permanently
2842
-            $registration->delete_permanently();
2843
-        }
2844
-        //now all related registrations on the transaction are handled.  So let's just handle this registration itself
2845
-        // (the transaction and line items should be all that's left).
2846
-        // delete the line items related to the transaction for this registration.
2847
-        $TXN->delete_related_permanently('Line_Item');
2848
-        //we need to remove all the relationships on the transaction
2849
-        $TXN->delete_related_permanently('Payment');
2850
-        $TXN->delete_related_permanently('Extra_Meta');
2851
-        $TXN->delete_related_permanently('Message');
2852
-        //now we can delete this REG permanently (and the transaction of course)
2853
-        $REG->delete_related_permanently('Transaction');
2854
-        return $REG->delete_permanently();
2855
-    }
2856
-
2857
-
2858
-    /**
2859
-     *    generates HTML for the Register New Attendee Admin page
2860
-     *
2861
-     * @access private
2862
-     * @throws DomainException
2863
-     * @throws EE_Error
2864
-     */
2865
-    public function new_registration()
2866
-    {
2867
-        if ( ! $this->_set_reg_event()) {
2868
-            throw new EE_Error(
2869
-                esc_html__(
2870
-                    'Unable to continue with registering because there is no Event ID in the request',
2871
-                    'event_espresso'
2872
-                )
2873
-            );
2874
-        }
2875
-        EE_Registry::instance()->REQ->set_espresso_page(true);
2876
-        // gotta start with a clean slate if we're not coming here via ajax
2877
-        if ( ! defined('DOING_AJAX')
2878
-             && ( ! isset($this->_req_data['processing_registration']) || isset($this->_req_data['step_error']))
2879
-        ) {
2880
-            EE_Registry::instance()->SSN->clear_session(__CLASS__, __FUNCTION__);
2881
-        }
2882
-        $this->_template_args['event_name'] = '';
2883
-        // event name
2884
-        if ($this->_reg_event) {
2885
-            $this->_template_args['event_name'] = $this->_reg_event->name();
2886
-            $edit_event_url                     = self::add_query_args_and_nonce(array(
2887
-                'action' => 'edit',
2888
-                'post'   => $this->_reg_event->ID(),
2889
-            ), EVENTS_ADMIN_URL);
2890
-            $edit_event_lnk                     = '<a href="'
2891
-                                                  . $edit_event_url
2892
-                                                  . '" title="'
2893
-                                                  . esc_attr__('Edit ', 'event_espresso')
2894
-                                                  . $this->_reg_event->name()
2895
-                                                  . '">'
2896
-                                                  . esc_html__('Edit Event', 'event_espresso')
2897
-                                                  . '</a>';
2898
-            $this->_template_args['event_name'] .= ' <span class="admin-page-header-edit-lnk not-bold">'
2899
-                                                   . $edit_event_lnk
2900
-                                                   . '</span>';
2901
-        }
2902
-        $this->_template_args['step_content'] = $this->_get_registration_step_content();
2903
-        if (defined('DOING_AJAX')) {
2904
-            $this->_return_json();
2905
-        }
2906
-        // grab header
2907
-        $template_path                              =
2908
-            REG_TEMPLATE_PATH . 'reg_admin_register_new_attendee.template.php';
2909
-        $this->_template_args['admin_page_content'] = EEH_Template::display_template($template_path,
2910
-            $this->_template_args, true);
2911
-        //$this->_set_publish_post_box_vars( NULL, FALSE, FALSE, NULL, FALSE );
2912
-        // the details template wrapper
2913
-        $this->display_admin_page_with_sidebar();
2914
-    }
2915
-
2916
-
2917
-    /**
2918
-     * This returns the content for a registration step
2919
-     *
2920
-     * @access protected
2921
-     * @return string html
2922
-     * @throws DomainException
2923
-     * @throws EE_Error
2924
-     * @throws InvalidArgumentException
2925
-     * @throws InvalidDataTypeException
2926
-     * @throws InvalidInterfaceException
2927
-     */
2928
-    protected function _get_registration_step_content()
2929
-    {
2930
-        if (isset($_COOKIE['ee_registration_added']) && $_COOKIE['ee_registration_added']) {
2931
-            $warning_msg = sprintf(
2932
-                esc_html__(
2933
-                    '%2$sWARNING!!!%3$s%1$sPlease do not use the back button to return to this page for the purpose of adding another registration.%1$sThis can result in lost and/or corrupted data.%1$sIf you wish to add another registration, then please click the%1$s%7$s"Add Another New Registration to Event"%8$s button%1$son the Transaction details page, after you are redirected.%1$s%1$s%4$s redirecting in %5$s seconds %6$s',
2934
-                    'event_espresso'
2935
-                ),
2936
-                '<br />',
2937
-                '<h3 class="important-notice">',
2938
-                '</h3>',
2939
-                '<div class="float-right">',
2940
-                '<span id="redirect_timer" class="important-notice">30</span>',
2941
-                '</div>',
2942
-                '<b>',
2943
-                '</b>'
2944
-            );
2945
-            return '
2425
+	}
2426
+
2427
+
2428
+	/**
2429
+	 * Updates the registration's custom questions according to the form info, if the form is submitted.
2430
+	 * If it's not a post, the "view_registrations" route will be called next on the SAME request
2431
+	 * to display the page
2432
+	 *
2433
+	 * @access protected
2434
+	 * @return void
2435
+	 * @throws EE_Error
2436
+	 */
2437
+	protected function _update_attendee_registration_form()
2438
+	{
2439
+		do_action('AHEE__Registrations_Admin_Page___update_attendee_registration_form__start', $this);
2440
+		if ($_SERVER['REQUEST_METHOD'] == 'POST') {
2441
+			$REG_ID  = isset($this->_req_data['_REG_ID']) ? absint($this->_req_data['_REG_ID']) : false;
2442
+			$success = $this->_save_reg_custom_questions_form($REG_ID);
2443
+			if ($success) {
2444
+				$what  = esc_html__('Registration Form', 'event_espresso');
2445
+				$route = $REG_ID ? array('action' => 'view_registration', '_REG_ID' => $REG_ID)
2446
+					: array('action' => 'default');
2447
+				$this->_redirect_after_action($success, $what, esc_html__('updated', 'event_espresso'), $route);
2448
+			}
2449
+		}
2450
+	}
2451
+
2452
+
2453
+	/**
2454
+	 * Gets the form for saving registrations custom questions (if done
2455
+	 * previously retrieves the cached form object, which may have validation errors in it)
2456
+	 *
2457
+	 * @param int $REG_ID
2458
+	 * @return EE_Registration_Custom_Questions_Form
2459
+	 * @throws EE_Error
2460
+	 * @throws InvalidArgumentException
2461
+	 * @throws InvalidDataTypeException
2462
+	 * @throws InvalidInterfaceException
2463
+	 */
2464
+	protected function _get_reg_custom_questions_form($REG_ID)
2465
+	{
2466
+		if ( ! $this->_reg_custom_questions_form) {
2467
+			require_once(REG_ADMIN . 'form_sections' . DS . 'EE_Registration_Custom_Questions_Form.form.php');
2468
+			$this->_reg_custom_questions_form = new EE_Registration_Custom_Questions_Form(
2469
+				EEM_Registration::instance()->get_one_by_ID($REG_ID)
2470
+			);
2471
+			$this->_reg_custom_questions_form->_construct_finalize(null, null);
2472
+		}
2473
+		return $this->_reg_custom_questions_form;
2474
+	}
2475
+
2476
+
2477
+	/**
2478
+	 * Saves
2479
+	 *
2480
+	 * @access private
2481
+	 * @param bool $REG_ID
2482
+	 * @return bool
2483
+	 * @throws EE_Error
2484
+	 * @throws InvalidArgumentException
2485
+	 * @throws InvalidDataTypeException
2486
+	 * @throws InvalidInterfaceException
2487
+	 */
2488
+	private function _save_reg_custom_questions_form($REG_ID = false)
2489
+	{
2490
+		if ( ! $REG_ID) {
2491
+			EE_Error::add_error(
2492
+				esc_html__(
2493
+					'An error occurred. No registration ID was received.', 'event_espresso'),
2494
+				__FILE__, __FUNCTION__, __LINE__
2495
+			);
2496
+		}
2497
+		$form = $this->_get_reg_custom_questions_form($REG_ID);
2498
+		$form->receive_form_submission($this->_req_data);
2499
+		$success = false;
2500
+		if ($form->is_valid()) {
2501
+			foreach ($form->subforms() as $question_group_id => $question_group_form) {
2502
+				foreach ($question_group_form->inputs() as $question_id => $input) {
2503
+					$where_conditions    = array(
2504
+						'QST_ID' => $question_id,
2505
+						'REG_ID' => $REG_ID,
2506
+					);
2507
+					$possibly_new_values = array(
2508
+						'ANS_value' => $input->normalized_value(),
2509
+					);
2510
+					$answer              = EEM_Answer::instance()->get_one(array($where_conditions));
2511
+					if ($answer instanceof EE_Answer) {
2512
+						$success = $answer->save($possibly_new_values);
2513
+					} else {
2514
+						//insert it then
2515
+						$cols_n_vals = array_merge($where_conditions, $possibly_new_values);
2516
+						$answer      = EE_Answer::new_instance($cols_n_vals);
2517
+						$success     = $answer->save();
2518
+					}
2519
+				}
2520
+			}
2521
+		} else {
2522
+			EE_Error::add_error($form->get_validation_error_string(), __FILE__, __FUNCTION__, __LINE__);
2523
+		}
2524
+		return $success;
2525
+	}
2526
+
2527
+
2528
+	/**
2529
+	 *        generates HTML for the Registration main meta box
2530
+	 *
2531
+	 * @access public
2532
+	 * @return void
2533
+	 * @throws DomainException
2534
+	 * @throws EE_Error
2535
+	 * @throws InvalidArgumentException
2536
+	 * @throws InvalidDataTypeException
2537
+	 * @throws InvalidInterfaceException
2538
+	 */
2539
+	public function _reg_attendees_meta_box()
2540
+	{
2541
+		$REG = EEM_Registration::instance();
2542
+		//get all other registrations on this transaction, and cache
2543
+		//the attendees for them so we don't have to run another query using force_join
2544
+		$registrations                           = $REG->get_all(array(
2545
+			array(
2546
+				'TXN_ID' => $this->_registration->transaction_ID(),
2547
+				'REG_ID' => array('!=', $this->_registration->ID()),
2548
+			),
2549
+			'force_join' => array('Attendee'),
2550
+		));
2551
+		$this->_template_args['attendees']       = array();
2552
+		$this->_template_args['attendee_notice'] = '';
2553
+		if (empty($registrations)
2554
+			|| (is_array($registrations)
2555
+				&& ! EEH_Array::get_one_item_from_array($registrations))
2556
+		) {
2557
+			EE_Error::add_error(
2558
+				esc_html__(
2559
+					'There are no records attached to this registration. Something may have gone wrong with the registration',
2560
+					'event_espresso'
2561
+				), __FILE__, __FUNCTION__, __LINE__
2562
+			);
2563
+			$this->_template_args['attendee_notice'] = EE_Error::get_notices();
2564
+		} else {
2565
+			$att_nmbr = 1;
2566
+			foreach ($registrations as $registration) {
2567
+				/* @var $registration EE_Registration */
2568
+				$attendee                                                    = $registration->attendee()
2569
+					? $registration->attendee()
2570
+					: EEM_Attendee::instance()
2571
+								  ->create_default_object();
2572
+				$this->_template_args['attendees'][$att_nmbr]['STS_ID']      = $registration->status_ID();
2573
+				$this->_template_args['attendees'][$att_nmbr]['fname']       = $attendee->fname();
2574
+				$this->_template_args['attendees'][$att_nmbr]['lname']       = $attendee->lname();
2575
+				$this->_template_args['attendees'][$att_nmbr]['email']       = $attendee->email();
2576
+				$this->_template_args['attendees'][$att_nmbr]['final_price'] = $registration->final_price();
2577
+				$this->_template_args['attendees'][$att_nmbr]['address']     = implode(
2578
+					', ',
2579
+					$attendee->full_address_as_array()
2580
+				);
2581
+				$this->_template_args['attendees'][$att_nmbr]['att_link']    = self::add_query_args_and_nonce(
2582
+					array(
2583
+						'action' => 'edit_attendee',
2584
+						'post'   => $attendee->ID(),
2585
+					),
2586
+					REG_ADMIN_URL
2587
+				);
2588
+				$this->_template_args['attendees'][$att_nmbr]['event_name']  = $registration->event_obj()->name();
2589
+				$att_nmbr++;
2590
+			}
2591
+			$this->_template_args['currency_sign'] = EE_Registry::instance()->CFG->currency->sign;
2592
+		}
2593
+		$template_path = REG_TEMPLATE_PATH . 'reg_admin_details_main_meta_box_attendees.template.php';
2594
+		echo EEH_Template::display_template($template_path, $this->_template_args, true);
2595
+	}
2596
+
2597
+
2598
+	/**
2599
+	 *        generates HTML for the Edit Registration side meta box
2600
+	 *
2601
+	 * @access public
2602
+	 * @return void
2603
+	 * @throws DomainException
2604
+	 * @throws EE_Error
2605
+	 * @throws InvalidArgumentException
2606
+	 * @throws InvalidDataTypeException
2607
+	 * @throws InvalidInterfaceException
2608
+	 */
2609
+	public function _reg_registrant_side_meta_box()
2610
+	{
2611
+		/*@var $attendee EE_Attendee */
2612
+		$att_check = $this->_registration->attendee();
2613
+		$attendee  = $att_check instanceof EE_Attendee ? $att_check : EEM_Attendee::instance()->create_default_object();
2614
+		//now let's determine if this is not the primary registration.  If it isn't then we set the
2615
+		//primary_registration object for reference BUT ONLY if the Attendee object loaded is not the same as the
2616
+		//primary registration object (that way we know if we need to show create button or not)
2617
+		if ( ! $this->_registration->is_primary_registrant()) {
2618
+			$primary_registration = $this->_registration->get_primary_registration();
2619
+			$primary_attendee     = $primary_registration instanceof EE_Registration ? $primary_registration->attendee()
2620
+				: null;
2621
+			if ( ! $primary_attendee instanceof EE_Attendee || $attendee->ID() !== $primary_attendee->ID()) {
2622
+				//in here?  This means the displayed registration is not the primary registrant but ALREADY HAS its own
2623
+				//custom attendee object so let's not worry about the primary reg.
2624
+				$primary_registration = null;
2625
+			}
2626
+		} else {
2627
+			$primary_registration = null;
2628
+		}
2629
+		$this->_template_args['ATT_ID']            = $attendee->ID();
2630
+		$this->_template_args['fname']             = $attendee->fname();
2631
+		$this->_template_args['lname']             = $attendee->lname();
2632
+		$this->_template_args['email']             = $attendee->email();
2633
+		$this->_template_args['phone']             = $attendee->phone();
2634
+		$this->_template_args['formatted_address'] = EEH_Address::format($attendee);
2635
+		//edit link
2636
+		$this->_template_args['att_edit_link']  = EE_Admin_Page::add_query_args_and_nonce(array(
2637
+			'action' => 'edit_attendee',
2638
+			'post'   => $attendee->ID(),
2639
+		), REG_ADMIN_URL);
2640
+		$this->_template_args['att_edit_label'] = esc_html__('View/Edit Contact', 'event_espresso');
2641
+		//create link
2642
+		$this->_template_args['create_link']  = $primary_registration instanceof EE_Registration
2643
+			? EE_Admin_Page::add_query_args_and_nonce(array(
2644
+				'action'  => 'duplicate_attendee',
2645
+				'_REG_ID' => $this->_registration->ID(),
2646
+			), REG_ADMIN_URL) : '';
2647
+		$this->_template_args['create_label'] = esc_html__('Create Contact', 'event_espresso');
2648
+		$this->_template_args['att_check']    = $att_check;
2649
+		$template_path                        = REG_TEMPLATE_PATH . 'reg_admin_details_side_meta_box_registrant.template.php';
2650
+		echo EEH_Template::display_template($template_path, $this->_template_args, true);
2651
+	}
2652
+
2653
+
2654
+	/**
2655
+	 * trash or restore registrations
2656
+	 *
2657
+	 * @param  boolean $trash whether to archive or restore
2658
+	 * @return void
2659
+	 * @throws EE_Error
2660
+	 * @throws InvalidArgumentException
2661
+	 * @throws InvalidDataTypeException
2662
+	 * @throws InvalidInterfaceException
2663
+	 * @throws RuntimeException
2664
+	 * @access protected
2665
+	 */
2666
+	protected function _trash_or_restore_registrations($trash = true)
2667
+	{
2668
+		//if empty _REG_ID then get out because there's nothing to do
2669
+		if (empty($this->_req_data['_REG_ID'])) {
2670
+			EE_Error::add_error(
2671
+				sprintf(
2672
+					esc_html__(
2673
+						'In order to %1$s registrations you must select which ones you wish to %1$s by clicking the checkboxes.',
2674
+						'event_espresso'
2675
+					),
2676
+					$trash ? 'trash' : 'restore'
2677
+				),
2678
+				__FILE__, __LINE__, __FUNCTION__
2679
+			);
2680
+			$this->_redirect_after_action(false, '', '', array(), true);
2681
+		}
2682
+		$success = 0;
2683
+		$overwrite_msgs = false;
2684
+		//Checkboxes
2685
+		if ( ! is_array($this->_req_data['_REG_ID'])) {
2686
+			$this->_req_data['_REG_ID'] = array($this->_req_data['_REG_ID']);
2687
+		}
2688
+		$reg_count = count($this->_req_data['_REG_ID']);
2689
+		// cycle thru checkboxes
2690
+		foreach ($this->_req_data['_REG_ID'] as $REG_ID) {
2691
+			/** @var EE_Registration $REG */
2692
+			$REG = EEM_Registration::instance()->get_one_by_ID($REG_ID);
2693
+			$payments = $REG->registration_payments();
2694
+			if (! empty($payments)) {
2695
+				$name = $REG->attendee() instanceof EE_Attendee
2696
+					? $REG->attendee()->full_name()
2697
+					: esc_html__('Unknown Attendee', 'event_espresso');
2698
+				$overwrite_msgs = true;
2699
+				EE_Error::add_error(
2700
+					sprintf(
2701
+						esc_html__(
2702
+							'The registration for %s could not be trashed because it has payments attached to the related transaction.  If you wish to trash this registration you must first delete the payments on the related transaction.',
2703
+							'event_espresso'
2704
+						),
2705
+						$name
2706
+					),
2707
+					__FILE__, __FUNCTION__, __LINE__
2708
+				);
2709
+				//can't trash this registration because it has payments.
2710
+				continue;
2711
+			}
2712
+			$updated = $trash ? $REG->delete() : $REG->restore();
2713
+			if ($updated) {
2714
+				$success++;
2715
+			}
2716
+		}
2717
+		$this->_redirect_after_action(
2718
+			$success === $reg_count, // were ALL registrations affected?
2719
+			$success > 1
2720
+				? esc_html__('Registrations', 'event_espresso')
2721
+				: esc_html__('Registration', 'event_espresso'),
2722
+			$trash
2723
+				? esc_html__('moved to the trash', 'event_espresso')
2724
+				: esc_html__('restored', 'event_espresso'),
2725
+			array('action' => 'default'),
2726
+			$overwrite_msgs
2727
+		);
2728
+	}
2729
+
2730
+
2731
+	/**
2732
+	 * This is used to permanently delete registrations.  Note, this will handle not only deleting permanently the
2733
+	 * registration but also.
2734
+	 * 1. Removing relations to EE_Attendee
2735
+	 * 2. Deleting permanently the related transaction, but ONLY if all related registrations to the transaction are
2736
+	 * ALSO trashed.
2737
+	 * 3. Deleting permanently any related Line items but only if the above conditions are met.
2738
+	 * 4. Removing relationships between all tickets and the related registrations
2739
+	 * 5. Deleting permanently any related Answers (and the answers for other related registrations that were deleted.)
2740
+	 * 6. Deleting permanently any related Checkins.
2741
+	 *
2742
+	 * @return void
2743
+	 * @throws EE_Error
2744
+	 * @throws InvalidArgumentException
2745
+	 * @throws InvalidDataTypeException
2746
+	 * @throws InvalidInterfaceException
2747
+	 */
2748
+	protected function _delete_registrations()
2749
+	{
2750
+		$REG_MDL = EEM_Registration::instance();
2751
+		$success = 1;
2752
+		//Checkboxes
2753
+		if ( ! empty($this->_req_data['_REG_ID']) && is_array($this->_req_data['_REG_ID'])) {
2754
+			// if array has more than one element than success message should be plural
2755
+			$success = count($this->_req_data['_REG_ID']) > 1 ? 2 : 1;
2756
+			// cycle thru checkboxes
2757
+			while (list($ind, $REG_ID) = each($this->_req_data['_REG_ID'])) {
2758
+				$REG = $REG_MDL->get_one_by_ID($REG_ID);
2759
+				if ( ! $REG instanceof EE_Registration) {
2760
+					continue;
2761
+				}
2762
+				$deleted = $this->_delete_registration($REG);
2763
+				if ( ! $deleted) {
2764
+					$success = 0;
2765
+				}
2766
+			}
2767
+		} else {
2768
+			// grab single id and delete
2769
+			$REG_ID  = $this->_req_data['_REG_ID'];
2770
+			$REG     = $REG_MDL->get_one_by_ID($REG_ID);
2771
+			$deleted = $this->_delete_registration($REG);
2772
+			if ( ! $deleted) {
2773
+				$success = 0;
2774
+			}
2775
+		}
2776
+		$what        = $success > 1
2777
+			? esc_html__('Registrations', 'event_espresso')
2778
+			: esc_html__('Registration', 'event_espresso');
2779
+		$action_desc = esc_html__('permanently deleted.', 'event_espresso');
2780
+		$this->_redirect_after_action(
2781
+			$success,
2782
+			$what,
2783
+			$action_desc,
2784
+			array('action' => 'default'),
2785
+			true
2786
+		);
2787
+	}
2788
+
2789
+
2790
+	/**
2791
+	 * handles the permanent deletion of a registration.  See comments with _delete_registrations() for details on what
2792
+	 * models get affected.
2793
+	 *
2794
+	 * @param  EE_Registration $REG registration to be deleted permenantly
2795
+	 * @return bool true = successful deletion, false = fail.
2796
+	 * @throws EE_Error
2797
+	 */
2798
+	protected function _delete_registration(EE_Registration $REG)
2799
+	{
2800
+		//first we start with the transaction... ultimately, we WILL not delete permanently if there are any related
2801
+		//registrations on the transaction that are NOT trashed.
2802
+		$TXN         = $REG->get_first_related('Transaction');
2803
+		$REGS        = $TXN->get_many_related('Registration');
2804
+		$all_trashed = true;
2805
+		foreach ($REGS as $registration) {
2806
+			if ( ! $registration->get('REG_deleted')) {
2807
+				$all_trashed = false;
2808
+			}
2809
+		}
2810
+		if ( ! $all_trashed) {
2811
+			EE_Error::add_error(
2812
+				esc_html__(
2813
+					'Unable to permanently delete this registration. Before this registration can be permanently deleted, all registrations made in the same transaction must be trashed as well.  These registrations will be permanently deleted in the same action.',
2814
+					'event_espresso'
2815
+				),
2816
+				__FILE__, __FUNCTION__, __LINE__
2817
+			);
2818
+			return false;
2819
+		}
2820
+		//k made it here so that means we can delete all the related transactions and their answers (but let's do them
2821
+		//separately from THIS one).
2822
+		foreach ($REGS as $registration) {
2823
+			//delete related answers
2824
+			$registration->delete_related_permanently('Answer');
2825
+			//remove relationship to EE_Attendee (but we ALWAYS leave the contact record intact)
2826
+			$attendee = $registration->get_first_related('Attendee');
2827
+			if ($attendee instanceof EE_Attendee) {
2828
+				$registration->_remove_relation_to($attendee, 'Attendee');
2829
+			}
2830
+			//now remove relationships to tickets on this registration.
2831
+			$registration->_remove_relations('Ticket');
2832
+			//now delete permanently the checkins related to this registration.
2833
+			$registration->delete_related_permanently('Checkin');
2834
+			if ($registration->ID() === $REG->ID()) {
2835
+				continue;
2836
+			} //we don't want to delete permanently the existing registration just yet.
2837
+			//remove relation to transaction for these registrations if NOT the existing registrations
2838
+			$registration->_remove_relations('Transaction');
2839
+			//delete permanently any related messages.
2840
+			$registration->delete_related_permanently('Message');
2841
+			//now delete this registration permanently
2842
+			$registration->delete_permanently();
2843
+		}
2844
+		//now all related registrations on the transaction are handled.  So let's just handle this registration itself
2845
+		// (the transaction and line items should be all that's left).
2846
+		// delete the line items related to the transaction for this registration.
2847
+		$TXN->delete_related_permanently('Line_Item');
2848
+		//we need to remove all the relationships on the transaction
2849
+		$TXN->delete_related_permanently('Payment');
2850
+		$TXN->delete_related_permanently('Extra_Meta');
2851
+		$TXN->delete_related_permanently('Message');
2852
+		//now we can delete this REG permanently (and the transaction of course)
2853
+		$REG->delete_related_permanently('Transaction');
2854
+		return $REG->delete_permanently();
2855
+	}
2856
+
2857
+
2858
+	/**
2859
+	 *    generates HTML for the Register New Attendee Admin page
2860
+	 *
2861
+	 * @access private
2862
+	 * @throws DomainException
2863
+	 * @throws EE_Error
2864
+	 */
2865
+	public function new_registration()
2866
+	{
2867
+		if ( ! $this->_set_reg_event()) {
2868
+			throw new EE_Error(
2869
+				esc_html__(
2870
+					'Unable to continue with registering because there is no Event ID in the request',
2871
+					'event_espresso'
2872
+				)
2873
+			);
2874
+		}
2875
+		EE_Registry::instance()->REQ->set_espresso_page(true);
2876
+		// gotta start with a clean slate if we're not coming here via ajax
2877
+		if ( ! defined('DOING_AJAX')
2878
+			 && ( ! isset($this->_req_data['processing_registration']) || isset($this->_req_data['step_error']))
2879
+		) {
2880
+			EE_Registry::instance()->SSN->clear_session(__CLASS__, __FUNCTION__);
2881
+		}
2882
+		$this->_template_args['event_name'] = '';
2883
+		// event name
2884
+		if ($this->_reg_event) {
2885
+			$this->_template_args['event_name'] = $this->_reg_event->name();
2886
+			$edit_event_url                     = self::add_query_args_and_nonce(array(
2887
+				'action' => 'edit',
2888
+				'post'   => $this->_reg_event->ID(),
2889
+			), EVENTS_ADMIN_URL);
2890
+			$edit_event_lnk                     = '<a href="'
2891
+												  . $edit_event_url
2892
+												  . '" title="'
2893
+												  . esc_attr__('Edit ', 'event_espresso')
2894
+												  . $this->_reg_event->name()
2895
+												  . '">'
2896
+												  . esc_html__('Edit Event', 'event_espresso')
2897
+												  . '</a>';
2898
+			$this->_template_args['event_name'] .= ' <span class="admin-page-header-edit-lnk not-bold">'
2899
+												   . $edit_event_lnk
2900
+												   . '</span>';
2901
+		}
2902
+		$this->_template_args['step_content'] = $this->_get_registration_step_content();
2903
+		if (defined('DOING_AJAX')) {
2904
+			$this->_return_json();
2905
+		}
2906
+		// grab header
2907
+		$template_path                              =
2908
+			REG_TEMPLATE_PATH . 'reg_admin_register_new_attendee.template.php';
2909
+		$this->_template_args['admin_page_content'] = EEH_Template::display_template($template_path,
2910
+			$this->_template_args, true);
2911
+		//$this->_set_publish_post_box_vars( NULL, FALSE, FALSE, NULL, FALSE );
2912
+		// the details template wrapper
2913
+		$this->display_admin_page_with_sidebar();
2914
+	}
2915
+
2916
+
2917
+	/**
2918
+	 * This returns the content for a registration step
2919
+	 *
2920
+	 * @access protected
2921
+	 * @return string html
2922
+	 * @throws DomainException
2923
+	 * @throws EE_Error
2924
+	 * @throws InvalidArgumentException
2925
+	 * @throws InvalidDataTypeException
2926
+	 * @throws InvalidInterfaceException
2927
+	 */
2928
+	protected function _get_registration_step_content()
2929
+	{
2930
+		if (isset($_COOKIE['ee_registration_added']) && $_COOKIE['ee_registration_added']) {
2931
+			$warning_msg = sprintf(
2932
+				esc_html__(
2933
+					'%2$sWARNING!!!%3$s%1$sPlease do not use the back button to return to this page for the purpose of adding another registration.%1$sThis can result in lost and/or corrupted data.%1$sIf you wish to add another registration, then please click the%1$s%7$s"Add Another New Registration to Event"%8$s button%1$son the Transaction details page, after you are redirected.%1$s%1$s%4$s redirecting in %5$s seconds %6$s',
2934
+					'event_espresso'
2935
+				),
2936
+				'<br />',
2937
+				'<h3 class="important-notice">',
2938
+				'</h3>',
2939
+				'<div class="float-right">',
2940
+				'<span id="redirect_timer" class="important-notice">30</span>',
2941
+				'</div>',
2942
+				'<b>',
2943
+				'</b>'
2944
+			);
2945
+			return '
2946 2946
 	<div id="ee-add-reg-back-button-dv"><p>' . $warning_msg . '</p></div>
2947 2947
 	<script >
2948 2948
 		// WHOAH !!! it appears that someone is using the back button from the Transaction admin page
@@ -2955,841 +2955,841 @@  discard block
 block discarded – undo
2955 2955
 	        }
2956 2956
 	    }, 800 );
2957 2957
 	</script >';
2958
-        }
2959
-        $template_args = array(
2960
-            'title'                    => '',
2961
-            'content'                  => '',
2962
-            'step_button_text'         => '',
2963
-            'show_notification_toggle' => false,
2964
-        );
2965
-        //to indicate we're processing a new registration
2966
-        $hidden_fields = array(
2967
-            'processing_registration' => array(
2968
-                'type'  => 'hidden',
2969
-                'value' => 0,
2970
-            ),
2971
-            'event_id'                => array(
2972
-                'type'  => 'hidden',
2973
-                'value' => $this->_reg_event->ID(),
2974
-            ),
2975
-        );
2976
-        //if the cart is empty then we know we're at step one so we'll display ticket selector
2977
-        $cart = EE_Registry::instance()->SSN->cart();
2978
-        $step = ! $cart instanceof EE_Cart ? 'ticket' : 'questions';
2979
-        switch ($step) {
2980
-            case 'ticket' :
2981
-                $hidden_fields['processing_registration']['value'] = 1;
2982
-                $template_args['title']                            = esc_html__(
2983
-                    'Step One: Select the Ticket for this registration',
2984
-                    'event_espresso'
2985
-                );
2986
-                $template_args['content']                          =
2987
-                    EED_Ticket_Selector::instance()->display_ticket_selector($this->_reg_event);
2988
-                $template_args['step_button_text']                 = esc_html__(
2989
-                    'Add Tickets and Continue to Registrant Details',
2990
-                    'event_espresso'
2991
-                );
2992
-                $template_args['show_notification_toggle']         = false;
2993
-                break;
2994
-            case 'questions' :
2995
-                $hidden_fields['processing_registration']['value'] = 2;
2996
-                $template_args['title']                            = esc_html__(
2997
-                    'Step Two: Add Registrant Details for this Registration',
2998
-                    'event_espresso'
2999
-                );
3000
-                //in theory we should be able to run EED_SPCO at this point because the cart should have been setup
3001
-                // properly by the first process_reg_step run.
3002
-                $template_args['content']                  =
3003
-                    EED_Single_Page_Checkout::registration_checkout_for_admin();
3004
-                $template_args['step_button_text']         = esc_html__(
3005
-                    'Save Registration and Continue to Details',
3006
-                    'event_espresso'
3007
-                );
3008
-                $template_args['show_notification_toggle'] = true;
3009
-                break;
3010
-        }
3011
-        //we come back to the process_registration_step route.
3012
-        $this->_set_add_edit_form_tags('process_reg_step', $hidden_fields);
3013
-        return EEH_Template::display_template(
3014
-            REG_TEMPLATE_PATH . 'reg_admin_register_new_attendee_step_content.template.php',
3015
-            $template_args,
3016
-            true
3017
-        );
3018
-    }
3019
-
3020
-
3021
-    /**
3022
-     *        set_reg_event
3023
-     *
3024
-     * @access private
3025
-     * @return bool
3026
-     * @throws EE_Error
3027
-     * @throws InvalidArgumentException
3028
-     * @throws InvalidDataTypeException
3029
-     * @throws InvalidInterfaceException
3030
-     */
3031
-    private function _set_reg_event()
3032
-    {
3033
-        if (is_object($this->_reg_event)) {
3034
-            return true;
3035
-        }
3036
-        $EVT_ID = (! empty($this->_req_data['event_id'])) ? absint($this->_req_data['event_id']) : false;
3037
-        if ( ! $EVT_ID) {
3038
-            return false;
3039
-        }
3040
-        $this->_reg_event = EEM_Event::instance()->get_one_by_ID($EVT_ID);
3041
-        return true;
3042
-    }
3043
-
3044
-
3045
-    /**
3046
-     * process_reg_step
3047
-     *
3048
-     * @access        public
3049
-     * @return string
3050
-     * @throws DomainException
3051
-     * @throws EE_Error
3052
-     * @throws InvalidArgumentException
3053
-     * @throws InvalidDataTypeException
3054
-     * @throws InvalidInterfaceException
3055
-     * @throws ReflectionException
3056
-     * @throws RuntimeException
3057
-     */
3058
-    public function process_reg_step()
3059
-    {
3060
-        EE_System::do_not_cache();
3061
-        $this->_set_reg_event();
3062
-        EE_Registry::instance()->REQ->set_espresso_page(true);
3063
-        EE_Registry::instance()->REQ->set('uts', time());
3064
-        //what step are we on?
3065
-        $cart = EE_Registry::instance()->SSN->cart();
3066
-        $step = ! $cart instanceof EE_Cart ? 'ticket' : 'questions';
3067
-        //if doing ajax then we need to verify the nonce
3068
-        if (defined('DOING_AJAX')) {
3069
-            $nonce = isset($this->_req_data[$this->_req_nonce])
3070
-                ? sanitize_text_field($this->_req_data[$this->_req_nonce]) : '';
3071
-            $this->_verify_nonce($nonce, $this->_req_nonce);
3072
-        }
3073
-        switch ($step) {
3074
-            case 'ticket' :
3075
-                //process ticket selection
3076
-                $success = EED_Ticket_Selector::instance()->process_ticket_selections();
3077
-                if ($success) {
3078
-                    EE_Error::add_success(
3079
-                        esc_html__(
3080
-                            'Tickets Selected. Now complete the registration.',
3081
-                            'event_espresso'
3082
-                        )
3083
-                    );
3084
-                } else {
3085
-                    $query_args['step_error'] = $this->_req_data['step_error'] = true;
3086
-                }
3087
-                if (defined('DOING_AJAX')) {
3088
-                    $this->new_registration(); //display next step
3089
-                } else {
3090
-                    $query_args = array(
3091
-                        'action'                  => 'new_registration',
3092
-                        'processing_registration' => 1,
3093
-                        'event_id'                => $this->_reg_event->ID(),
3094
-                        'uts'                     => time(),
3095
-                    );
3096
-                    $this->_redirect_after_action(
3097
-                        false,
3098
-                        '',
3099
-                        '',
3100
-                        $query_args,
3101
-                        true
3102
-                    );
3103
-                }
3104
-                break;
3105
-            case 'questions' :
3106
-                if (! isset(
3107
-                    $this->_req_data['txn_reg_status_change'],
3108
-                    $this->_req_data['txn_reg_status_change']['send_notifications'])
3109
-                ) {
3110
-                    add_filter('FHEE__EED_Messages___maybe_registration__deliver_notifications', '__return_false', 15);
3111
-                }
3112
-                //process registration
3113
-                $transaction = EED_Single_Page_Checkout::instance()->process_registration_from_admin();
3114
-                if ($cart instanceof EE_Cart) {
3115
-                    $grand_total = $cart->get_cart_grand_total();
3116
-                    if ($grand_total instanceof EE_Line_Item) {
3117
-                        $grand_total->save_this_and_descendants_to_txn();
3118
-                    }
3119
-                }
3120
-                if ( ! $transaction instanceof EE_Transaction) {
3121
-                    $query_args = array(
3122
-                        'action'                  => 'new_registration',
3123
-                        'processing_registration' => 2,
3124
-                        'event_id'                => $this->_reg_event->ID(),
3125
-                        'uts'                     => time(),
3126
-                    );
3127
-                    if (defined('DOING_AJAX')) {
3128
-                        //display registration form again because there are errors (maybe validation?)
3129
-                        $this->new_registration();
3130
-                        return;
3131
-                    } else {
3132
-                        $this->_redirect_after_action(
3133
-                            false,
3134
-                            '',
3135
-                            '',
3136
-                            $query_args,
3137
-                            true
3138
-                        );
3139
-                        return;
3140
-                    }
3141
-                }
3142
-                // maybe update status, and make sure to save transaction if not done already
3143
-                if ( ! $transaction->update_status_based_on_total_paid()) {
3144
-                    $transaction->save();
3145
-                }
3146
-                EE_Registry::instance()->SSN->clear_session(__CLASS__, __FUNCTION__);
3147
-                $this->_req_data = array();
3148
-                $query_args      = array(
3149
-                    'action'        => 'redirect_to_txn',
3150
-                    'TXN_ID'        => $transaction->ID(),
3151
-                    'EVT_ID'        => $this->_reg_event->ID(),
3152
-                    'event_name'    => urlencode($this->_reg_event->name()),
3153
-                    'redirect_from' => 'new_registration',
3154
-                );
3155
-                $this->_redirect_after_action(false, '', '', $query_args, true);
3156
-                break;
3157
-        }
3158
-        //what are you looking here for?  Should be nothing to do at this point.
3159
-    }
3160
-
3161
-
3162
-    /**
3163
-     * redirect_to_txn
3164
-     *
3165
-     * @access public
3166
-     * @return void
3167
-     * @throws EE_Error
3168
-     * @throws InvalidArgumentException
3169
-     * @throws InvalidDataTypeException
3170
-     * @throws InvalidInterfaceException
3171
-     */
3172
-    public function redirect_to_txn()
3173
-    {
3174
-        EE_System::do_not_cache();
3175
-        EE_Registry::instance()->SSN->clear_session(__CLASS__, __FUNCTION__);
3176
-        $query_args = array(
3177
-            'action' => 'view_transaction',
3178
-            'TXN_ID' => isset($this->_req_data['TXN_ID']) ? absint($this->_req_data['TXN_ID']) : 0,
3179
-            'page'   => 'espresso_transactions',
3180
-        );
3181
-        if (isset($this->_req_data['EVT_ID'], $this->_req_data['redirect_from'])) {
3182
-            $query_args['EVT_ID']        = $this->_req_data['EVT_ID'];
3183
-            $query_args['event_name']    = urlencode($this->_req_data['event_name']);
3184
-            $query_args['redirect_from'] = $this->_req_data['redirect_from'];
3185
-        }
3186
-        EE_Error::add_success(
3187
-            esc_html__(
3188
-                'Registration Created.  Please review the transaction and add any payments as necessary',
3189
-                'event_espresso'
3190
-            )
3191
-        );
3192
-        $this->_redirect_after_action(false, '', '', $query_args, true);
3193
-    }
3194
-
3195
-
3196
-    /**
3197
-     *        generates HTML for the Attendee Contact List
3198
-     *
3199
-     * @access protected
3200
-     * @return void
3201
-     */
3202
-    protected function _attendee_contact_list_table()
3203
-    {
3204
-        do_action('AHEE_log', __FILE__, __FUNCTION__, '');
3205
-        $this->_search_btn_label = esc_html__('Contacts', 'event_espresso');
3206
-        $this->display_admin_list_table_page_with_no_sidebar();
3207
-    }
3208
-
3209
-
3210
-    /**
3211
-     *        get_attendees
3212
-     *
3213
-     * @param      $per_page
3214
-     * @param bool $count whether to return count or data.
3215
-     * @param bool $trash
3216
-     * @return array
3217
-     * @throws EE_Error
3218
-     * @throws InvalidArgumentException
3219
-     * @throws InvalidDataTypeException
3220
-     * @throws InvalidInterfaceException
3221
-     * @access public
3222
-     */
3223
-    public function get_attendees($per_page, $count = false, $trash = false)
3224
-    {
3225
-        do_action('AHEE_log', __FILE__, __FUNCTION__, '');
3226
-        require_once(REG_ADMIN . 'EE_Attendee_Contact_List_Table.class.php');
3227
-        $ATT_MDL                    = EEM_Attendee::instance();
3228
-        $this->_req_data['orderby'] = ! empty($this->_req_data['orderby']) ? $this->_req_data['orderby'] : '';
3229
-        switch ($this->_req_data['orderby']) {
3230
-            case 'ATT_ID':
3231
-                $orderby = 'ATT_ID';
3232
-                break;
3233
-            case 'ATT_fname':
3234
-                $orderby = 'ATT_fname';
3235
-                break;
3236
-            case 'ATT_email':
3237
-                $orderby = 'ATT_email';
3238
-                break;
3239
-            case 'ATT_city':
3240
-                $orderby = 'ATT_city';
3241
-                break;
3242
-            case 'STA_ID':
3243
-                $orderby = 'STA_ID';
3244
-                break;
3245
-            case 'CNT_ID':
3246
-                $orderby = 'CNT_ID';
3247
-                break;
3248
-            case 'Registration_Count':
3249
-                $orderby = 'Registration_Count';
3250
-                break;
3251
-            default:
3252
-                $orderby = 'ATT_lname';
3253
-        }
3254
-        $sort         = (isset($this->_req_data['order']) && ! empty($this->_req_data['order']))
3255
-            ? $this->_req_data['order']
3256
-            : 'ASC';
3257
-        $current_page = isset($this->_req_data['paged']) && ! empty($this->_req_data['paged'])
3258
-            ? $this->_req_data['paged']
3259
-            : 1;
3260
-        $per_page     = isset($per_page) && ! empty($per_page) ? $per_page : 10;
3261
-        $per_page     = isset($this->_req_data['perpage']) && ! empty($this->_req_data['perpage'])
3262
-            ? $this->_req_data['perpage']
3263
-            : $per_page;
3264
-        $_where       = array();
3265
-        if ( ! empty($this->_req_data['s'])) {
3266
-            $sstr         = '%' . $this->_req_data['s'] . '%';
3267
-            $_where['OR'] = array(
3268
-                'Registration.Event.EVT_name'       => array('LIKE', $sstr),
3269
-                'Registration.Event.EVT_desc'       => array('LIKE', $sstr),
3270
-                'Registration.Event.EVT_short_desc' => array('LIKE', $sstr),
3271
-                'ATT_fname'                         => array('LIKE', $sstr),
3272
-                'ATT_lname'                         => array('LIKE', $sstr),
3273
-                'ATT_short_bio'                     => array('LIKE', $sstr),
3274
-                'ATT_email'                         => array('LIKE', $sstr),
3275
-                'ATT_address'                       => array('LIKE', $sstr),
3276
-                'ATT_address2'                      => array('LIKE', $sstr),
3277
-                'ATT_city'                          => array('LIKE', $sstr),
3278
-                'Country.CNT_name'                  => array('LIKE', $sstr),
3279
-                'State.STA_name'                    => array('LIKE', $sstr),
3280
-                'ATT_phone'                         => array('LIKE', $sstr),
3281
-                'Registration.REG_final_price'      => array('LIKE', $sstr),
3282
-                'Registration.REG_code'             => array('LIKE', $sstr),
3283
-                'Registration.REG_group_size'       => array('LIKE', $sstr),
3284
-            );
3285
-        }
3286
-        $offset = ($current_page - 1) * $per_page;
3287
-        $limit  = $count ? null : array($offset, $per_page);
3288
-        $query_args = array(
3289
-            $_where,
3290
-            'extra_selects' => array('Registration_Count' => array('Registration.REG_ID', 'count', '%d')),
3291
-            'limit' => $limit
3292
-        );
3293
-        if (! $count) {
3294
-            $query_args['order_by'] = array($orderby => $sort);
3295
-        }
3296
-        if ($trash) {
3297
-            $query_args[0]['status'] = array('!=', 'publish');
3298
-            $all_attendees    = $count
3299
-                ? $ATT_MDL->count($query_args, 'ATT_ID', true)
3300
-                : $ATT_MDL->get_all($query_args);
3301
-        } else {
3302
-            $query_args[0]['status'] = array('IN', array('publish'));
3303
-            $all_attendees    = $count
3304
-                ? $ATT_MDL->count($query_args, 'ATT_ID', true)
3305
-                : $ATT_MDL->get_all($query_args);
3306
-        }
3307
-        return $all_attendees;
3308
-    }
3309
-
3310
-
3311
-    /**
3312
-     * This is just taking care of resending the registration confirmation
3313
-     *
3314
-     * @access protected
3315
-     * @return void
3316
-     */
3317
-    protected function _resend_registration()
3318
-    {
3319
-        $this->_process_resend_registration();
3320
-        $query_args = isset($this->_req_data['redirect_to'])
3321
-            ? array('action' => $this->_req_data['redirect_to'], '_REG_ID' => $this->_req_data['_REG_ID'])
3322
-            : array('action' => 'default');
3323
-        $this->_redirect_after_action(false, '', '', $query_args, true);
3324
-    }
3325
-
3326
-    /**
3327
-     * Creates a registration report, but accepts the name of a method to use for preparing the query parameters
3328
-     * to use when selecting registrations
3329
-     * @param string $method_name_for_getting_query_params the name of the method (on this class) to use for preparing
3330
-     *                                                     the query parameters from the request
3331
-     * @return void ends the request with a redirect or download
3332
-     */
3333
-    public function _registrations_report_base( $method_name_for_getting_query_params )
3334
-    {
3335
-        if (! defined('EE_USE_OLD_CSV_REPORT_CLASS')) {
3336
-            wp_redirect(EE_Admin_Page::add_query_args_and_nonce(
3337
-                array(
3338
-                    'page'        => 'espresso_batch',
3339
-                    'batch'       => 'file',
3340
-                    'EVT_ID'      => isset($this->_req_data['EVT_ID']) ? $this->_req_data['EVT_ID'] : null,
3341
-                    'filters'     => urlencode(
3342
-                        serialize(
3343
-                            call_user_func(
3344
-                                array( $this, $method_name_for_getting_query_params ),
3345
-                                EEH_Array::is_set(
3346
-                                    $this->_req_data,
3347
-                                    'filters',
3348
-                                    array()
3349
-                                )
3350
-                            )
3351
-                        )
3352
-                ),
3353
-                'use_filters' => EEH_Array::is_set($this->_req_data, 'use_filters', false),
3354
-                'job_handler' => urlencode('EventEspressoBatchRequest\JobHandlers\RegistrationsReport'),
3355
-                'return_url'  => urlencode($this->_req_data['return_url']),
3356
-            )));
3357
-        } else {
3358
-            $new_request_args = array(
3359
-                'export' => 'report',
3360
-                'action' => 'registrations_report_for_event',
3361
-                'EVT_ID' => isset($this->_req_data['EVT_ID']) ? $this->_req_data['EVT_ID'] : null,
3362
-            );
3363
-            $this->_req_data = array_merge($this->_req_data, $new_request_args);
3364
-            if (is_readable(EE_CLASSES . 'EE_Export.class.php')) {
3365
-                require_once(EE_CLASSES . 'EE_Export.class.php');
3366
-                $EE_Export = EE_Export::instance($this->_req_data);
3367
-                $EE_Export->export();
3368
-            }
3369
-        }
3370
-    }
3371
-
3372
-
3373
-
3374
-    /**
3375
-     * Creates a registration report using only query parameters in the request
3376
-     * @return void
3377
-     */
3378
-    public function _registrations_report()
3379
-    {
3380
-        $this->_registrations_report_base('_get_registration_query_parameters');
3381
-    }
3382
-
3383
-
3384
-    public function _contact_list_export()
3385
-    {
3386
-        if (is_readable(EE_CLASSES . 'EE_Export.class.php')) {
3387
-            require_once(EE_CLASSES . 'EE_Export.class.php');
3388
-            $EE_Export = EE_Export::instance($this->_req_data);
3389
-            $EE_Export->export_attendees();
3390
-        }
3391
-    }
3392
-
3393
-
3394
-    public function _contact_list_report()
3395
-    {
3396
-        if ( ! defined('EE_USE_OLD_CSV_REPORT_CLASS')) {
3397
-            wp_redirect(EE_Admin_Page::add_query_args_and_nonce(array(
3398
-                'page'        => 'espresso_batch',
3399
-                'batch'       => 'file',
3400
-                'job_handler' => urlencode('EventEspressoBatchRequest\JobHandlers\AttendeesReport'),
3401
-                'return_url'  => urlencode($this->_req_data['return_url']),
3402
-            )));
3403
-        } else {
3404
-            if (is_readable(EE_CLASSES . 'EE_Export.class.php')) {
3405
-                require_once(EE_CLASSES . 'EE_Export.class.php');
3406
-                $EE_Export = EE_Export::instance($this->_req_data);
3407
-                $EE_Export->report_attendees();
3408
-            }
3409
-        }
3410
-    }
3411
-
3412
-
3413
-
3414
-
3415
-
3416
-    /***************************************        ATTENDEE DETAILS        ***************************************/
3417
-    /**
3418
-     * This duplicates the attendee object for the given incoming registration id and attendee_id.
3419
-     *
3420
-     * @return void
3421
-     * @throws EE_Error
3422
-     * @throws InvalidArgumentException
3423
-     * @throws InvalidDataTypeException
3424
-     * @throws InvalidInterfaceException
3425
-     */
3426
-    protected function _duplicate_attendee()
3427
-    {
3428
-        $action = ! empty($this->_req_data['return']) ? $this->_req_data['return'] : 'default';
3429
-        //verify we have necessary info
3430
-        if (empty($this->_req_data['_REG_ID'])) {
3431
-            EE_Error::add_error(
3432
-                esc_html__(
3433
-                    'Unable to create the contact for the registration because the required parameters are not present (_REG_ID )',
3434
-                    'event_espresso'
3435
-                ), __FILE__, __LINE__, __FUNCTION__
3436
-            );
3437
-            $query_args = array('action' => $action);
3438
-            $this->_redirect_after_action('', '', '', $query_args, true);
3439
-        }
3440
-        //okay necessary deets present... let's dupe the incoming attendee and attach to incoming registration.
3441
-        $registration = EEM_Registration::instance()->get_one_by_ID($this->_req_data['_REG_ID']);
3442
-        $attendee     = $registration->attendee();
3443
-        //remove relation of existing attendee on registration
3444
-        $registration->_remove_relation_to($attendee, 'Attendee');
3445
-        //new attendee
3446
-        $new_attendee = clone $attendee;
3447
-        $new_attendee->set('ATT_ID', 0);
3448
-        $new_attendee->save();
3449
-        //add new attendee to reg
3450
-        $registration->_add_relation_to($new_attendee, 'Attendee');
3451
-        EE_Error::add_success(
3452
-            esc_html__(
3453
-                'New Contact record created.  Now make any edits you wish to make for this contact.',
3454
-                'event_espresso'
3455
-            )
3456
-        );
3457
-        //redirect to edit page for attendee
3458
-        $query_args = array('post' => $new_attendee->ID(), 'action' => 'edit_attendee');
3459
-        $this->_redirect_after_action('', '', '', $query_args, true);
3460
-    }
3461
-
3462
-
3463
-    /**
3464
-     * Callback invoked by parent EE_Admin_CPT class hooked in on `save_post` wp hook.
3465
-     * @param int      $post_id
3466
-     * @param WP_POST $post
3467
-     * @throws DomainException
3468
-     * @throws EE_Error
3469
-     * @throws InvalidArgumentException
3470
-     * @throws InvalidDataTypeException
3471
-     * @throws InvalidInterfaceException
3472
-     * @throws LogicException
3473
-     * @throws InvalidFormSubmissionException
3474
-     */
3475
-    protected function _insert_update_cpt_item($post_id, $post)
3476
-    {
3477
-        $success  = true;
3478
-        $attendee = $post instanceof WP_Post && $post->post_type === 'espresso_attendees'
3479
-            ? EEM_Attendee::instance()->get_one_by_ID($post_id)
3480
-            : null;
3481
-        //for attendee updates
3482
-        if ($attendee instanceof EE_Attendee) {
3483
-            //note we should only be UPDATING attendees at this point.
3484
-            $updated_fields = array(
3485
-                'ATT_fname'     => $this->_req_data['ATT_fname'],
3486
-                'ATT_lname'     => $this->_req_data['ATT_lname'],
3487
-                'ATT_full_name' => $this->_req_data['ATT_fname'] . ' ' . $this->_req_data['ATT_lname'],
3488
-                'ATT_address'   => isset($this->_req_data['ATT_address']) ? $this->_req_data['ATT_address'] : '',
3489
-                'ATT_address2'  => isset($this->_req_data['ATT_address2']) ? $this->_req_data['ATT_address2'] : '',
3490
-                'ATT_city'      => isset($this->_req_data['ATT_city']) ? $this->_req_data['ATT_city'] : '',
3491
-                'STA_ID'        => isset($this->_req_data['STA_ID']) ? $this->_req_data['STA_ID'] : '',
3492
-                'CNT_ISO'       => isset($this->_req_data['CNT_ISO']) ? $this->_req_data['CNT_ISO'] : '',
3493
-                'ATT_zip'       => isset($this->_req_data['ATT_zip']) ? $this->_req_data['ATT_zip'] : '',
3494
-            );
3495
-            foreach ($updated_fields as $field => $value) {
3496
-                $attendee->set($field, $value);
3497
-            }
3498
-
3499
-            //process contact details metabox form handler (which will also save the attendee)
3500
-            $contact_details_form = $this->getAttendeeContactDetailsMetaboxFormHandler($attendee);
3501
-            $success = $contact_details_form->process($this->_req_data);
3502
-
3503
-            $attendee_update_callbacks = apply_filters(
3504
-                'FHEE__Registrations_Admin_Page__insert_update_cpt_item__attendee_update',
3505
-                array()
3506
-            );
3507
-            foreach ($attendee_update_callbacks as $a_callback) {
3508
-                if (false === call_user_func_array($a_callback, array($attendee, $this->_req_data))) {
3509
-                    throw new EE_Error(
3510
-                        sprintf(
3511
-                            esc_html__(
3512
-                                'The %s callback given for the "FHEE__Registrations_Admin_Page__insert_update_cpt_item__attendee_update" filter is not a valid callback.  Please check the spelling.',
3513
-                                'event_espresso'
3514
-                            ),
3515
-                            $a_callback
3516
-                        )
3517
-                    );
3518
-                }
3519
-            }
3520
-        }
3521
-
3522
-        if ($success === false) {
3523
-            EE_Error::add_error(
3524
-                esc_html__(
3525
-                    'Something went wrong with updating the meta table data for the registration.',
3526
-                    'event_espresso'
3527
-                ),
3528
-                __FILE__, __FUNCTION__, __LINE__
3529
-            );
3530
-        }
3531
-    }
3532
-
3533
-
3534
-    public function trash_cpt_item($post_id)
3535
-    {
3536
-    }
3537
-
3538
-
3539
-    public function delete_cpt_item($post_id)
3540
-    {
3541
-    }
3542
-
3543
-
3544
-    public function restore_cpt_item($post_id)
3545
-    {
3546
-    }
3547
-
3548
-
3549
-    protected function _restore_cpt_item($post_id, $revision_id)
3550
-    {
3551
-    }
3552
-
3553
-
3554
-    public function attendee_editor_metaboxes()
3555
-    {
3556
-        $this->verify_cpt_object();
3557
-        remove_meta_box(
3558
-            'postexcerpt',
3559
-            esc_html__('Excerpt', 'event_espresso'),
3560
-            'post_excerpt_meta_box',
3561
-            $this->_cpt_routes[$this->_req_action],
3562
-            'normal',
3563
-            'core'
3564
-        );
3565
-        remove_meta_box('commentstatusdiv', $this->_cpt_routes[$this->_req_action], 'normal', 'core');
3566
-        if (post_type_supports('espresso_attendees', 'excerpt')) {
3567
-            add_meta_box(
3568
-                'postexcerpt',
3569
-                esc_html__('Short Biography', 'event_espresso'),
3570
-                'post_excerpt_meta_box',
3571
-                $this->_cpt_routes[$this->_req_action],
3572
-                'normal'
3573
-            );
3574
-        }
3575
-        if (post_type_supports('espresso_attendees', 'comments')) {
3576
-            add_meta_box(
3577
-                'commentsdiv',
3578
-                esc_html__('Notes on the Contact', 'event_espresso'),
3579
-                'post_comment_meta_box',
3580
-                $this->_cpt_routes[$this->_req_action],
3581
-                'normal',
3582
-                'core'
3583
-            );
3584
-        }
3585
-        add_meta_box(
3586
-            'attendee_contact_info',
3587
-            esc_html__('Contact Info', 'event_espresso'),
3588
-            array($this, 'attendee_contact_info'),
3589
-            $this->_cpt_routes[$this->_req_action],
3590
-            'side',
3591
-            'core'
3592
-        );
3593
-        add_meta_box(
3594
-            'attendee_details_address',
3595
-            esc_html__('Address Details', 'event_espresso'),
3596
-            array($this, 'attendee_address_details'),
3597
-            $this->_cpt_routes[$this->_req_action],
3598
-            'normal',
3599
-            'core'
3600
-        );
3601
-        add_meta_box(
3602
-            'attendee_registrations',
3603
-            esc_html__('Registrations for this Contact', 'event_espresso'),
3604
-            array($this, 'attendee_registrations_meta_box'),
3605
-            $this->_cpt_routes[$this->_req_action],
3606
-            'normal',
3607
-            'high'
3608
-        );
3609
-    }
3610
-
3611
-
3612
-    /**
3613
-     * Metabox for attendee contact info
3614
-     *
3615
-     * @param  WP_Post $post wp post object
3616
-     * @return string attendee contact info ( and form )
3617
-     * @throws EE_Error
3618
-     * @throws InvalidArgumentException
3619
-     * @throws InvalidDataTypeException
3620
-     * @throws InvalidInterfaceException
3621
-     * @throws LogicException
3622
-     * @throws DomainException
3623
-     */
3624
-    public function attendee_contact_info($post)
3625
-    {
3626
-        //get attendee object ( should already have it )
3627
-        $form = $this->getAttendeeContactDetailsMetaboxFormHandler($this->_cpt_model_obj);
3628
-        $form->enqueueStylesAndScripts();
3629
-        echo $form->display();
3630
-    }
3631
-
3632
-
3633
-    /**
3634
-     * Return form handler for the contact details metabox
3635
-     *
3636
-     * @param EE_Attendee $attendee
3637
-     * @return AttendeeContactDetailsMetaboxFormHandler
3638
-     * @throws DomainException
3639
-     * @throws InvalidArgumentException
3640
-     * @throws InvalidDataTypeException
3641
-     * @throws InvalidInterfaceException
3642
-     */
3643
-    protected function getAttendeeContactDetailsMetaboxFormHandler(EE_Attendee $attendee)
3644
-    {
3645
-        return new AttendeeContactDetailsMetaboxFormHandler($attendee, EE_Registry::instance());
3646
-    }
3647
-
3648
-
3649
-    /**
3650
-     * Metabox for attendee details
3651
-     *
3652
-     * @param  WP_Post $post wp post object
3653
-     * @throws DomainException
3654
-     */
3655
-    public function attendee_address_details($post)
3656
-    {
3657
-        //get attendee object (should already have it)
3658
-        $this->_template_args['attendee']     = $this->_cpt_model_obj;
3659
-        $this->_template_args['state_html']   = EEH_Form_Fields::generate_form_input(
3660
-            new EE_Question_Form_Input(
3661
-                EE_Question::new_instance(
3662
-                    array(
3663
-                        'QST_ID'           => 0,
3664
-                        'QST_display_text' => esc_html__('State/Province', 'event_espresso'),
3665
-                        'QST_system'       => 'admin-state',
3666
-                    )
3667
-                ),
3668
-                EE_Answer::new_instance(
3669
-                    array(
3670
-                        'ANS_ID'    => 0,
3671
-                        'ANS_value' => $this->_cpt_model_obj->state_ID(),
3672
-                    )
3673
-                ),
3674
-                array(
3675
-                    'input_id'       => 'STA_ID',
3676
-                    'input_name'     => 'STA_ID',
3677
-                    'input_prefix'   => '',
3678
-                    'append_qstn_id' => false,
3679
-                )
3680
-            )
3681
-        );
3682
-        $this->_template_args['country_html'] = EEH_Form_Fields::generate_form_input(
3683
-            new EE_Question_Form_Input(
3684
-                EE_Question::new_instance(
3685
-                    array(
3686
-                        'QST_ID'           => 0,
3687
-                        'QST_display_text' => esc_html__('Country', 'event_espresso'),
3688
-                        'QST_system'       => 'admin-country',
3689
-                    )
3690
-                ),
3691
-                EE_Answer::new_instance(
3692
-                    array(
3693
-                        'ANS_ID'    => 0,
3694
-                        'ANS_value' => $this->_cpt_model_obj->country_ID(),
3695
-                    )
3696
-                ),
3697
-                array(
3698
-                    'input_id'       => 'CNT_ISO',
3699
-                    'input_name'     => 'CNT_ISO',
3700
-                    'input_prefix'   => '',
3701
-                    'append_qstn_id' => false,
3702
-                )
3703
-            )
3704
-        );
3705
-        $template                             =
3706
-            REG_TEMPLATE_PATH . 'attendee_address_details_metabox_content.template.php';
3707
-        EEH_Template::display_template($template, $this->_template_args);
3708
-    }
3709
-
3710
-
3711
-    /**
3712
-     *        _attendee_details
3713
-     *
3714
-     * @access protected
3715
-     * @param $post
3716
-     * @return void
3717
-     * @throws DomainException
3718
-     * @throws EE_Error
3719
-     */
3720
-    public function attendee_registrations_meta_box($post)
3721
-    {
3722
-        $this->_template_args['attendee']      = $this->_cpt_model_obj;
3723
-        $this->_template_args['registrations'] = $this->_cpt_model_obj->get_many_related('Registration');
3724
-        $template                              =
3725
-            REG_TEMPLATE_PATH . 'attendee_registrations_main_meta_box.template.php';
3726
-        EEH_Template::display_template($template, $this->_template_args);
3727
-    }
3728
-
3729
-
3730
-    /**
3731
-     * add in the form fields for the attendee edit
3732
-     *
3733
-     * @param  WP_Post $post wp post object
3734
-     * @return string html for new form.
3735
-     * @throws DomainException
3736
-     */
3737
-    public function after_title_form_fields($post)
3738
-    {
3739
-        if ($post->post_type == 'espresso_attendees') {
3740
-            $template                  = REG_TEMPLATE_PATH . 'attendee_details_after_title_form_fields.template.php';
3741
-            $template_args['attendee'] = $this->_cpt_model_obj;
3742
-            EEH_Template::display_template($template, $template_args);
3743
-        }
3744
-    }
3745
-
3746
-
3747
-    /**
3748
-     *        _trash_or_restore_attendee
3749
-     *
3750
-     * @param boolean $trash - whether to move item to trash (TRUE) or restore it (FALSE)
3751
-     * @return void
3752
-     * @throws EE_Error
3753
-     * @throws InvalidArgumentException
3754
-     * @throws InvalidDataTypeException
3755
-     * @throws InvalidInterfaceException
3756
-     * @access protected
3757
-     */
3758
-    protected function _trash_or_restore_attendees($trash = true)
3759
-    {
3760
-        do_action('AHEE_log', __FILE__, __FUNCTION__, '');
3761
-        $ATT_MDL = EEM_Attendee::instance();
3762
-        $success = 1;
3763
-        //Checkboxes
3764
-        if ( ! empty($this->_req_data['checkbox']) && is_array($this->_req_data['checkbox'])) {
3765
-            // if array has more than one element than success message should be plural
3766
-            $success = count($this->_req_data['checkbox']) > 1 ? 2 : 1;
3767
-            // cycle thru checkboxes
3768
-            while (list($ATT_ID, $value) = each($this->_req_data['checkbox'])) {
3769
-                $updated = $trash ? $ATT_MDL->update_by_ID(array('status' => 'trash'), $ATT_ID)
3770
-                    : $ATT_MDL->update_by_ID(array('status' => 'publish'), $ATT_ID);
3771
-                if ( ! $updated) {
3772
-                    $success = 0;
3773
-                }
3774
-            }
3775
-        } else {
3776
-            // grab single id and delete
3777
-            $ATT_ID = absint($this->_req_data['ATT_ID']);
3778
-            //get attendee
3779
-            $att     = $ATT_MDL->get_one_by_ID($ATT_ID);
3780
-            $updated = $trash ? $att->set_status('trash') : $att->set_status('publish');
3781
-            $updated = $att->save();
3782
-            if ( ! $updated) {
3783
-                $success = 0;
3784
-            }
3785
-        }
3786
-        $what        = $success > 1
3787
-            ? esc_html__('Contacts', 'event_espresso')
3788
-            : esc_html__('Contact', 'event_espresso');
3789
-        $action_desc = $trash
3790
-            ? esc_html__('moved to the trash', 'event_espresso')
3791
-            : esc_html__('restored', 'event_espresso');
3792
-        $this->_redirect_after_action($success, $what, $action_desc, array('action' => 'contact_list'));
3793
-    }
2958
+		}
2959
+		$template_args = array(
2960
+			'title'                    => '',
2961
+			'content'                  => '',
2962
+			'step_button_text'         => '',
2963
+			'show_notification_toggle' => false,
2964
+		);
2965
+		//to indicate we're processing a new registration
2966
+		$hidden_fields = array(
2967
+			'processing_registration' => array(
2968
+				'type'  => 'hidden',
2969
+				'value' => 0,
2970
+			),
2971
+			'event_id'                => array(
2972
+				'type'  => 'hidden',
2973
+				'value' => $this->_reg_event->ID(),
2974
+			),
2975
+		);
2976
+		//if the cart is empty then we know we're at step one so we'll display ticket selector
2977
+		$cart = EE_Registry::instance()->SSN->cart();
2978
+		$step = ! $cart instanceof EE_Cart ? 'ticket' : 'questions';
2979
+		switch ($step) {
2980
+			case 'ticket' :
2981
+				$hidden_fields['processing_registration']['value'] = 1;
2982
+				$template_args['title']                            = esc_html__(
2983
+					'Step One: Select the Ticket for this registration',
2984
+					'event_espresso'
2985
+				);
2986
+				$template_args['content']                          =
2987
+					EED_Ticket_Selector::instance()->display_ticket_selector($this->_reg_event);
2988
+				$template_args['step_button_text']                 = esc_html__(
2989
+					'Add Tickets and Continue to Registrant Details',
2990
+					'event_espresso'
2991
+				);
2992
+				$template_args['show_notification_toggle']         = false;
2993
+				break;
2994
+			case 'questions' :
2995
+				$hidden_fields['processing_registration']['value'] = 2;
2996
+				$template_args['title']                            = esc_html__(
2997
+					'Step Two: Add Registrant Details for this Registration',
2998
+					'event_espresso'
2999
+				);
3000
+				//in theory we should be able to run EED_SPCO at this point because the cart should have been setup
3001
+				// properly by the first process_reg_step run.
3002
+				$template_args['content']                  =
3003
+					EED_Single_Page_Checkout::registration_checkout_for_admin();
3004
+				$template_args['step_button_text']         = esc_html__(
3005
+					'Save Registration and Continue to Details',
3006
+					'event_espresso'
3007
+				);
3008
+				$template_args['show_notification_toggle'] = true;
3009
+				break;
3010
+		}
3011
+		//we come back to the process_registration_step route.
3012
+		$this->_set_add_edit_form_tags('process_reg_step', $hidden_fields);
3013
+		return EEH_Template::display_template(
3014
+			REG_TEMPLATE_PATH . 'reg_admin_register_new_attendee_step_content.template.php',
3015
+			$template_args,
3016
+			true
3017
+		);
3018
+	}
3019
+
3020
+
3021
+	/**
3022
+	 *        set_reg_event
3023
+	 *
3024
+	 * @access private
3025
+	 * @return bool
3026
+	 * @throws EE_Error
3027
+	 * @throws InvalidArgumentException
3028
+	 * @throws InvalidDataTypeException
3029
+	 * @throws InvalidInterfaceException
3030
+	 */
3031
+	private function _set_reg_event()
3032
+	{
3033
+		if (is_object($this->_reg_event)) {
3034
+			return true;
3035
+		}
3036
+		$EVT_ID = (! empty($this->_req_data['event_id'])) ? absint($this->_req_data['event_id']) : false;
3037
+		if ( ! $EVT_ID) {
3038
+			return false;
3039
+		}
3040
+		$this->_reg_event = EEM_Event::instance()->get_one_by_ID($EVT_ID);
3041
+		return true;
3042
+	}
3043
+
3044
+
3045
+	/**
3046
+	 * process_reg_step
3047
+	 *
3048
+	 * @access        public
3049
+	 * @return string
3050
+	 * @throws DomainException
3051
+	 * @throws EE_Error
3052
+	 * @throws InvalidArgumentException
3053
+	 * @throws InvalidDataTypeException
3054
+	 * @throws InvalidInterfaceException
3055
+	 * @throws ReflectionException
3056
+	 * @throws RuntimeException
3057
+	 */
3058
+	public function process_reg_step()
3059
+	{
3060
+		EE_System::do_not_cache();
3061
+		$this->_set_reg_event();
3062
+		EE_Registry::instance()->REQ->set_espresso_page(true);
3063
+		EE_Registry::instance()->REQ->set('uts', time());
3064
+		//what step are we on?
3065
+		$cart = EE_Registry::instance()->SSN->cart();
3066
+		$step = ! $cart instanceof EE_Cart ? 'ticket' : 'questions';
3067
+		//if doing ajax then we need to verify the nonce
3068
+		if (defined('DOING_AJAX')) {
3069
+			$nonce = isset($this->_req_data[$this->_req_nonce])
3070
+				? sanitize_text_field($this->_req_data[$this->_req_nonce]) : '';
3071
+			$this->_verify_nonce($nonce, $this->_req_nonce);
3072
+		}
3073
+		switch ($step) {
3074
+			case 'ticket' :
3075
+				//process ticket selection
3076
+				$success = EED_Ticket_Selector::instance()->process_ticket_selections();
3077
+				if ($success) {
3078
+					EE_Error::add_success(
3079
+						esc_html__(
3080
+							'Tickets Selected. Now complete the registration.',
3081
+							'event_espresso'
3082
+						)
3083
+					);
3084
+				} else {
3085
+					$query_args['step_error'] = $this->_req_data['step_error'] = true;
3086
+				}
3087
+				if (defined('DOING_AJAX')) {
3088
+					$this->new_registration(); //display next step
3089
+				} else {
3090
+					$query_args = array(
3091
+						'action'                  => 'new_registration',
3092
+						'processing_registration' => 1,
3093
+						'event_id'                => $this->_reg_event->ID(),
3094
+						'uts'                     => time(),
3095
+					);
3096
+					$this->_redirect_after_action(
3097
+						false,
3098
+						'',
3099
+						'',
3100
+						$query_args,
3101
+						true
3102
+					);
3103
+				}
3104
+				break;
3105
+			case 'questions' :
3106
+				if (! isset(
3107
+					$this->_req_data['txn_reg_status_change'],
3108
+					$this->_req_data['txn_reg_status_change']['send_notifications'])
3109
+				) {
3110
+					add_filter('FHEE__EED_Messages___maybe_registration__deliver_notifications', '__return_false', 15);
3111
+				}
3112
+				//process registration
3113
+				$transaction = EED_Single_Page_Checkout::instance()->process_registration_from_admin();
3114
+				if ($cart instanceof EE_Cart) {
3115
+					$grand_total = $cart->get_cart_grand_total();
3116
+					if ($grand_total instanceof EE_Line_Item) {
3117
+						$grand_total->save_this_and_descendants_to_txn();
3118
+					}
3119
+				}
3120
+				if ( ! $transaction instanceof EE_Transaction) {
3121
+					$query_args = array(
3122
+						'action'                  => 'new_registration',
3123
+						'processing_registration' => 2,
3124
+						'event_id'                => $this->_reg_event->ID(),
3125
+						'uts'                     => time(),
3126
+					);
3127
+					if (defined('DOING_AJAX')) {
3128
+						//display registration form again because there are errors (maybe validation?)
3129
+						$this->new_registration();
3130
+						return;
3131
+					} else {
3132
+						$this->_redirect_after_action(
3133
+							false,
3134
+							'',
3135
+							'',
3136
+							$query_args,
3137
+							true
3138
+						);
3139
+						return;
3140
+					}
3141
+				}
3142
+				// maybe update status, and make sure to save transaction if not done already
3143
+				if ( ! $transaction->update_status_based_on_total_paid()) {
3144
+					$transaction->save();
3145
+				}
3146
+				EE_Registry::instance()->SSN->clear_session(__CLASS__, __FUNCTION__);
3147
+				$this->_req_data = array();
3148
+				$query_args      = array(
3149
+					'action'        => 'redirect_to_txn',
3150
+					'TXN_ID'        => $transaction->ID(),
3151
+					'EVT_ID'        => $this->_reg_event->ID(),
3152
+					'event_name'    => urlencode($this->_reg_event->name()),
3153
+					'redirect_from' => 'new_registration',
3154
+				);
3155
+				$this->_redirect_after_action(false, '', '', $query_args, true);
3156
+				break;
3157
+		}
3158
+		//what are you looking here for?  Should be nothing to do at this point.
3159
+	}
3160
+
3161
+
3162
+	/**
3163
+	 * redirect_to_txn
3164
+	 *
3165
+	 * @access public
3166
+	 * @return void
3167
+	 * @throws EE_Error
3168
+	 * @throws InvalidArgumentException
3169
+	 * @throws InvalidDataTypeException
3170
+	 * @throws InvalidInterfaceException
3171
+	 */
3172
+	public function redirect_to_txn()
3173
+	{
3174
+		EE_System::do_not_cache();
3175
+		EE_Registry::instance()->SSN->clear_session(__CLASS__, __FUNCTION__);
3176
+		$query_args = array(
3177
+			'action' => 'view_transaction',
3178
+			'TXN_ID' => isset($this->_req_data['TXN_ID']) ? absint($this->_req_data['TXN_ID']) : 0,
3179
+			'page'   => 'espresso_transactions',
3180
+		);
3181
+		if (isset($this->_req_data['EVT_ID'], $this->_req_data['redirect_from'])) {
3182
+			$query_args['EVT_ID']        = $this->_req_data['EVT_ID'];
3183
+			$query_args['event_name']    = urlencode($this->_req_data['event_name']);
3184
+			$query_args['redirect_from'] = $this->_req_data['redirect_from'];
3185
+		}
3186
+		EE_Error::add_success(
3187
+			esc_html__(
3188
+				'Registration Created.  Please review the transaction and add any payments as necessary',
3189
+				'event_espresso'
3190
+			)
3191
+		);
3192
+		$this->_redirect_after_action(false, '', '', $query_args, true);
3193
+	}
3194
+
3195
+
3196
+	/**
3197
+	 *        generates HTML for the Attendee Contact List
3198
+	 *
3199
+	 * @access protected
3200
+	 * @return void
3201
+	 */
3202
+	protected function _attendee_contact_list_table()
3203
+	{
3204
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
3205
+		$this->_search_btn_label = esc_html__('Contacts', 'event_espresso');
3206
+		$this->display_admin_list_table_page_with_no_sidebar();
3207
+	}
3208
+
3209
+
3210
+	/**
3211
+	 *        get_attendees
3212
+	 *
3213
+	 * @param      $per_page
3214
+	 * @param bool $count whether to return count or data.
3215
+	 * @param bool $trash
3216
+	 * @return array
3217
+	 * @throws EE_Error
3218
+	 * @throws InvalidArgumentException
3219
+	 * @throws InvalidDataTypeException
3220
+	 * @throws InvalidInterfaceException
3221
+	 * @access public
3222
+	 */
3223
+	public function get_attendees($per_page, $count = false, $trash = false)
3224
+	{
3225
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
3226
+		require_once(REG_ADMIN . 'EE_Attendee_Contact_List_Table.class.php');
3227
+		$ATT_MDL                    = EEM_Attendee::instance();
3228
+		$this->_req_data['orderby'] = ! empty($this->_req_data['orderby']) ? $this->_req_data['orderby'] : '';
3229
+		switch ($this->_req_data['orderby']) {
3230
+			case 'ATT_ID':
3231
+				$orderby = 'ATT_ID';
3232
+				break;
3233
+			case 'ATT_fname':
3234
+				$orderby = 'ATT_fname';
3235
+				break;
3236
+			case 'ATT_email':
3237
+				$orderby = 'ATT_email';
3238
+				break;
3239
+			case 'ATT_city':
3240
+				$orderby = 'ATT_city';
3241
+				break;
3242
+			case 'STA_ID':
3243
+				$orderby = 'STA_ID';
3244
+				break;
3245
+			case 'CNT_ID':
3246
+				$orderby = 'CNT_ID';
3247
+				break;
3248
+			case 'Registration_Count':
3249
+				$orderby = 'Registration_Count';
3250
+				break;
3251
+			default:
3252
+				$orderby = 'ATT_lname';
3253
+		}
3254
+		$sort         = (isset($this->_req_data['order']) && ! empty($this->_req_data['order']))
3255
+			? $this->_req_data['order']
3256
+			: 'ASC';
3257
+		$current_page = isset($this->_req_data['paged']) && ! empty($this->_req_data['paged'])
3258
+			? $this->_req_data['paged']
3259
+			: 1;
3260
+		$per_page     = isset($per_page) && ! empty($per_page) ? $per_page : 10;
3261
+		$per_page     = isset($this->_req_data['perpage']) && ! empty($this->_req_data['perpage'])
3262
+			? $this->_req_data['perpage']
3263
+			: $per_page;
3264
+		$_where       = array();
3265
+		if ( ! empty($this->_req_data['s'])) {
3266
+			$sstr         = '%' . $this->_req_data['s'] . '%';
3267
+			$_where['OR'] = array(
3268
+				'Registration.Event.EVT_name'       => array('LIKE', $sstr),
3269
+				'Registration.Event.EVT_desc'       => array('LIKE', $sstr),
3270
+				'Registration.Event.EVT_short_desc' => array('LIKE', $sstr),
3271
+				'ATT_fname'                         => array('LIKE', $sstr),
3272
+				'ATT_lname'                         => array('LIKE', $sstr),
3273
+				'ATT_short_bio'                     => array('LIKE', $sstr),
3274
+				'ATT_email'                         => array('LIKE', $sstr),
3275
+				'ATT_address'                       => array('LIKE', $sstr),
3276
+				'ATT_address2'                      => array('LIKE', $sstr),
3277
+				'ATT_city'                          => array('LIKE', $sstr),
3278
+				'Country.CNT_name'                  => array('LIKE', $sstr),
3279
+				'State.STA_name'                    => array('LIKE', $sstr),
3280
+				'ATT_phone'                         => array('LIKE', $sstr),
3281
+				'Registration.REG_final_price'      => array('LIKE', $sstr),
3282
+				'Registration.REG_code'             => array('LIKE', $sstr),
3283
+				'Registration.REG_group_size'       => array('LIKE', $sstr),
3284
+			);
3285
+		}
3286
+		$offset = ($current_page - 1) * $per_page;
3287
+		$limit  = $count ? null : array($offset, $per_page);
3288
+		$query_args = array(
3289
+			$_where,
3290
+			'extra_selects' => array('Registration_Count' => array('Registration.REG_ID', 'count', '%d')),
3291
+			'limit' => $limit
3292
+		);
3293
+		if (! $count) {
3294
+			$query_args['order_by'] = array($orderby => $sort);
3295
+		}
3296
+		if ($trash) {
3297
+			$query_args[0]['status'] = array('!=', 'publish');
3298
+			$all_attendees    = $count
3299
+				? $ATT_MDL->count($query_args, 'ATT_ID', true)
3300
+				: $ATT_MDL->get_all($query_args);
3301
+		} else {
3302
+			$query_args[0]['status'] = array('IN', array('publish'));
3303
+			$all_attendees    = $count
3304
+				? $ATT_MDL->count($query_args, 'ATT_ID', true)
3305
+				: $ATT_MDL->get_all($query_args);
3306
+		}
3307
+		return $all_attendees;
3308
+	}
3309
+
3310
+
3311
+	/**
3312
+	 * This is just taking care of resending the registration confirmation
3313
+	 *
3314
+	 * @access protected
3315
+	 * @return void
3316
+	 */
3317
+	protected function _resend_registration()
3318
+	{
3319
+		$this->_process_resend_registration();
3320
+		$query_args = isset($this->_req_data['redirect_to'])
3321
+			? array('action' => $this->_req_data['redirect_to'], '_REG_ID' => $this->_req_data['_REG_ID'])
3322
+			: array('action' => 'default');
3323
+		$this->_redirect_after_action(false, '', '', $query_args, true);
3324
+	}
3325
+
3326
+	/**
3327
+	 * Creates a registration report, but accepts the name of a method to use for preparing the query parameters
3328
+	 * to use when selecting registrations
3329
+	 * @param string $method_name_for_getting_query_params the name of the method (on this class) to use for preparing
3330
+	 *                                                     the query parameters from the request
3331
+	 * @return void ends the request with a redirect or download
3332
+	 */
3333
+	public function _registrations_report_base( $method_name_for_getting_query_params )
3334
+	{
3335
+		if (! defined('EE_USE_OLD_CSV_REPORT_CLASS')) {
3336
+			wp_redirect(EE_Admin_Page::add_query_args_and_nonce(
3337
+				array(
3338
+					'page'        => 'espresso_batch',
3339
+					'batch'       => 'file',
3340
+					'EVT_ID'      => isset($this->_req_data['EVT_ID']) ? $this->_req_data['EVT_ID'] : null,
3341
+					'filters'     => urlencode(
3342
+						serialize(
3343
+							call_user_func(
3344
+								array( $this, $method_name_for_getting_query_params ),
3345
+								EEH_Array::is_set(
3346
+									$this->_req_data,
3347
+									'filters',
3348
+									array()
3349
+								)
3350
+							)
3351
+						)
3352
+				),
3353
+				'use_filters' => EEH_Array::is_set($this->_req_data, 'use_filters', false),
3354
+				'job_handler' => urlencode('EventEspressoBatchRequest\JobHandlers\RegistrationsReport'),
3355
+				'return_url'  => urlencode($this->_req_data['return_url']),
3356
+			)));
3357
+		} else {
3358
+			$new_request_args = array(
3359
+				'export' => 'report',
3360
+				'action' => 'registrations_report_for_event',
3361
+				'EVT_ID' => isset($this->_req_data['EVT_ID']) ? $this->_req_data['EVT_ID'] : null,
3362
+			);
3363
+			$this->_req_data = array_merge($this->_req_data, $new_request_args);
3364
+			if (is_readable(EE_CLASSES . 'EE_Export.class.php')) {
3365
+				require_once(EE_CLASSES . 'EE_Export.class.php');
3366
+				$EE_Export = EE_Export::instance($this->_req_data);
3367
+				$EE_Export->export();
3368
+			}
3369
+		}
3370
+	}
3371
+
3372
+
3373
+
3374
+	/**
3375
+	 * Creates a registration report using only query parameters in the request
3376
+	 * @return void
3377
+	 */
3378
+	public function _registrations_report()
3379
+	{
3380
+		$this->_registrations_report_base('_get_registration_query_parameters');
3381
+	}
3382
+
3383
+
3384
+	public function _contact_list_export()
3385
+	{
3386
+		if (is_readable(EE_CLASSES . 'EE_Export.class.php')) {
3387
+			require_once(EE_CLASSES . 'EE_Export.class.php');
3388
+			$EE_Export = EE_Export::instance($this->_req_data);
3389
+			$EE_Export->export_attendees();
3390
+		}
3391
+	}
3392
+
3393
+
3394
+	public function _contact_list_report()
3395
+	{
3396
+		if ( ! defined('EE_USE_OLD_CSV_REPORT_CLASS')) {
3397
+			wp_redirect(EE_Admin_Page::add_query_args_and_nonce(array(
3398
+				'page'        => 'espresso_batch',
3399
+				'batch'       => 'file',
3400
+				'job_handler' => urlencode('EventEspressoBatchRequest\JobHandlers\AttendeesReport'),
3401
+				'return_url'  => urlencode($this->_req_data['return_url']),
3402
+			)));
3403
+		} else {
3404
+			if (is_readable(EE_CLASSES . 'EE_Export.class.php')) {
3405
+				require_once(EE_CLASSES . 'EE_Export.class.php');
3406
+				$EE_Export = EE_Export::instance($this->_req_data);
3407
+				$EE_Export->report_attendees();
3408
+			}
3409
+		}
3410
+	}
3411
+
3412
+
3413
+
3414
+
3415
+
3416
+	/***************************************        ATTENDEE DETAILS        ***************************************/
3417
+	/**
3418
+	 * This duplicates the attendee object for the given incoming registration id and attendee_id.
3419
+	 *
3420
+	 * @return void
3421
+	 * @throws EE_Error
3422
+	 * @throws InvalidArgumentException
3423
+	 * @throws InvalidDataTypeException
3424
+	 * @throws InvalidInterfaceException
3425
+	 */
3426
+	protected function _duplicate_attendee()
3427
+	{
3428
+		$action = ! empty($this->_req_data['return']) ? $this->_req_data['return'] : 'default';
3429
+		//verify we have necessary info
3430
+		if (empty($this->_req_data['_REG_ID'])) {
3431
+			EE_Error::add_error(
3432
+				esc_html__(
3433
+					'Unable to create the contact for the registration because the required parameters are not present (_REG_ID )',
3434
+					'event_espresso'
3435
+				), __FILE__, __LINE__, __FUNCTION__
3436
+			);
3437
+			$query_args = array('action' => $action);
3438
+			$this->_redirect_after_action('', '', '', $query_args, true);
3439
+		}
3440
+		//okay necessary deets present... let's dupe the incoming attendee and attach to incoming registration.
3441
+		$registration = EEM_Registration::instance()->get_one_by_ID($this->_req_data['_REG_ID']);
3442
+		$attendee     = $registration->attendee();
3443
+		//remove relation of existing attendee on registration
3444
+		$registration->_remove_relation_to($attendee, 'Attendee');
3445
+		//new attendee
3446
+		$new_attendee = clone $attendee;
3447
+		$new_attendee->set('ATT_ID', 0);
3448
+		$new_attendee->save();
3449
+		//add new attendee to reg
3450
+		$registration->_add_relation_to($new_attendee, 'Attendee');
3451
+		EE_Error::add_success(
3452
+			esc_html__(
3453
+				'New Contact record created.  Now make any edits you wish to make for this contact.',
3454
+				'event_espresso'
3455
+			)
3456
+		);
3457
+		//redirect to edit page for attendee
3458
+		$query_args = array('post' => $new_attendee->ID(), 'action' => 'edit_attendee');
3459
+		$this->_redirect_after_action('', '', '', $query_args, true);
3460
+	}
3461
+
3462
+
3463
+	/**
3464
+	 * Callback invoked by parent EE_Admin_CPT class hooked in on `save_post` wp hook.
3465
+	 * @param int      $post_id
3466
+	 * @param WP_POST $post
3467
+	 * @throws DomainException
3468
+	 * @throws EE_Error
3469
+	 * @throws InvalidArgumentException
3470
+	 * @throws InvalidDataTypeException
3471
+	 * @throws InvalidInterfaceException
3472
+	 * @throws LogicException
3473
+	 * @throws InvalidFormSubmissionException
3474
+	 */
3475
+	protected function _insert_update_cpt_item($post_id, $post)
3476
+	{
3477
+		$success  = true;
3478
+		$attendee = $post instanceof WP_Post && $post->post_type === 'espresso_attendees'
3479
+			? EEM_Attendee::instance()->get_one_by_ID($post_id)
3480
+			: null;
3481
+		//for attendee updates
3482
+		if ($attendee instanceof EE_Attendee) {
3483
+			//note we should only be UPDATING attendees at this point.
3484
+			$updated_fields = array(
3485
+				'ATT_fname'     => $this->_req_data['ATT_fname'],
3486
+				'ATT_lname'     => $this->_req_data['ATT_lname'],
3487
+				'ATT_full_name' => $this->_req_data['ATT_fname'] . ' ' . $this->_req_data['ATT_lname'],
3488
+				'ATT_address'   => isset($this->_req_data['ATT_address']) ? $this->_req_data['ATT_address'] : '',
3489
+				'ATT_address2'  => isset($this->_req_data['ATT_address2']) ? $this->_req_data['ATT_address2'] : '',
3490
+				'ATT_city'      => isset($this->_req_data['ATT_city']) ? $this->_req_data['ATT_city'] : '',
3491
+				'STA_ID'        => isset($this->_req_data['STA_ID']) ? $this->_req_data['STA_ID'] : '',
3492
+				'CNT_ISO'       => isset($this->_req_data['CNT_ISO']) ? $this->_req_data['CNT_ISO'] : '',
3493
+				'ATT_zip'       => isset($this->_req_data['ATT_zip']) ? $this->_req_data['ATT_zip'] : '',
3494
+			);
3495
+			foreach ($updated_fields as $field => $value) {
3496
+				$attendee->set($field, $value);
3497
+			}
3498
+
3499
+			//process contact details metabox form handler (which will also save the attendee)
3500
+			$contact_details_form = $this->getAttendeeContactDetailsMetaboxFormHandler($attendee);
3501
+			$success = $contact_details_form->process($this->_req_data);
3502
+
3503
+			$attendee_update_callbacks = apply_filters(
3504
+				'FHEE__Registrations_Admin_Page__insert_update_cpt_item__attendee_update',
3505
+				array()
3506
+			);
3507
+			foreach ($attendee_update_callbacks as $a_callback) {
3508
+				if (false === call_user_func_array($a_callback, array($attendee, $this->_req_data))) {
3509
+					throw new EE_Error(
3510
+						sprintf(
3511
+							esc_html__(
3512
+								'The %s callback given for the "FHEE__Registrations_Admin_Page__insert_update_cpt_item__attendee_update" filter is not a valid callback.  Please check the spelling.',
3513
+								'event_espresso'
3514
+							),
3515
+							$a_callback
3516
+						)
3517
+					);
3518
+				}
3519
+			}
3520
+		}
3521
+
3522
+		if ($success === false) {
3523
+			EE_Error::add_error(
3524
+				esc_html__(
3525
+					'Something went wrong with updating the meta table data for the registration.',
3526
+					'event_espresso'
3527
+				),
3528
+				__FILE__, __FUNCTION__, __LINE__
3529
+			);
3530
+		}
3531
+	}
3532
+
3533
+
3534
+	public function trash_cpt_item($post_id)
3535
+	{
3536
+	}
3537
+
3538
+
3539
+	public function delete_cpt_item($post_id)
3540
+	{
3541
+	}
3542
+
3543
+
3544
+	public function restore_cpt_item($post_id)
3545
+	{
3546
+	}
3547
+
3548
+
3549
+	protected function _restore_cpt_item($post_id, $revision_id)
3550
+	{
3551
+	}
3552
+
3553
+
3554
+	public function attendee_editor_metaboxes()
3555
+	{
3556
+		$this->verify_cpt_object();
3557
+		remove_meta_box(
3558
+			'postexcerpt',
3559
+			esc_html__('Excerpt', 'event_espresso'),
3560
+			'post_excerpt_meta_box',
3561
+			$this->_cpt_routes[$this->_req_action],
3562
+			'normal',
3563
+			'core'
3564
+		);
3565
+		remove_meta_box('commentstatusdiv', $this->_cpt_routes[$this->_req_action], 'normal', 'core');
3566
+		if (post_type_supports('espresso_attendees', 'excerpt')) {
3567
+			add_meta_box(
3568
+				'postexcerpt',
3569
+				esc_html__('Short Biography', 'event_espresso'),
3570
+				'post_excerpt_meta_box',
3571
+				$this->_cpt_routes[$this->_req_action],
3572
+				'normal'
3573
+			);
3574
+		}
3575
+		if (post_type_supports('espresso_attendees', 'comments')) {
3576
+			add_meta_box(
3577
+				'commentsdiv',
3578
+				esc_html__('Notes on the Contact', 'event_espresso'),
3579
+				'post_comment_meta_box',
3580
+				$this->_cpt_routes[$this->_req_action],
3581
+				'normal',
3582
+				'core'
3583
+			);
3584
+		}
3585
+		add_meta_box(
3586
+			'attendee_contact_info',
3587
+			esc_html__('Contact Info', 'event_espresso'),
3588
+			array($this, 'attendee_contact_info'),
3589
+			$this->_cpt_routes[$this->_req_action],
3590
+			'side',
3591
+			'core'
3592
+		);
3593
+		add_meta_box(
3594
+			'attendee_details_address',
3595
+			esc_html__('Address Details', 'event_espresso'),
3596
+			array($this, 'attendee_address_details'),
3597
+			$this->_cpt_routes[$this->_req_action],
3598
+			'normal',
3599
+			'core'
3600
+		);
3601
+		add_meta_box(
3602
+			'attendee_registrations',
3603
+			esc_html__('Registrations for this Contact', 'event_espresso'),
3604
+			array($this, 'attendee_registrations_meta_box'),
3605
+			$this->_cpt_routes[$this->_req_action],
3606
+			'normal',
3607
+			'high'
3608
+		);
3609
+	}
3610
+
3611
+
3612
+	/**
3613
+	 * Metabox for attendee contact info
3614
+	 *
3615
+	 * @param  WP_Post $post wp post object
3616
+	 * @return string attendee contact info ( and form )
3617
+	 * @throws EE_Error
3618
+	 * @throws InvalidArgumentException
3619
+	 * @throws InvalidDataTypeException
3620
+	 * @throws InvalidInterfaceException
3621
+	 * @throws LogicException
3622
+	 * @throws DomainException
3623
+	 */
3624
+	public function attendee_contact_info($post)
3625
+	{
3626
+		//get attendee object ( should already have it )
3627
+		$form = $this->getAttendeeContactDetailsMetaboxFormHandler($this->_cpt_model_obj);
3628
+		$form->enqueueStylesAndScripts();
3629
+		echo $form->display();
3630
+	}
3631
+
3632
+
3633
+	/**
3634
+	 * Return form handler for the contact details metabox
3635
+	 *
3636
+	 * @param EE_Attendee $attendee
3637
+	 * @return AttendeeContactDetailsMetaboxFormHandler
3638
+	 * @throws DomainException
3639
+	 * @throws InvalidArgumentException
3640
+	 * @throws InvalidDataTypeException
3641
+	 * @throws InvalidInterfaceException
3642
+	 */
3643
+	protected function getAttendeeContactDetailsMetaboxFormHandler(EE_Attendee $attendee)
3644
+	{
3645
+		return new AttendeeContactDetailsMetaboxFormHandler($attendee, EE_Registry::instance());
3646
+	}
3647
+
3648
+
3649
+	/**
3650
+	 * Metabox for attendee details
3651
+	 *
3652
+	 * @param  WP_Post $post wp post object
3653
+	 * @throws DomainException
3654
+	 */
3655
+	public function attendee_address_details($post)
3656
+	{
3657
+		//get attendee object (should already have it)
3658
+		$this->_template_args['attendee']     = $this->_cpt_model_obj;
3659
+		$this->_template_args['state_html']   = EEH_Form_Fields::generate_form_input(
3660
+			new EE_Question_Form_Input(
3661
+				EE_Question::new_instance(
3662
+					array(
3663
+						'QST_ID'           => 0,
3664
+						'QST_display_text' => esc_html__('State/Province', 'event_espresso'),
3665
+						'QST_system'       => 'admin-state',
3666
+					)
3667
+				),
3668
+				EE_Answer::new_instance(
3669
+					array(
3670
+						'ANS_ID'    => 0,
3671
+						'ANS_value' => $this->_cpt_model_obj->state_ID(),
3672
+					)
3673
+				),
3674
+				array(
3675
+					'input_id'       => 'STA_ID',
3676
+					'input_name'     => 'STA_ID',
3677
+					'input_prefix'   => '',
3678
+					'append_qstn_id' => false,
3679
+				)
3680
+			)
3681
+		);
3682
+		$this->_template_args['country_html'] = EEH_Form_Fields::generate_form_input(
3683
+			new EE_Question_Form_Input(
3684
+				EE_Question::new_instance(
3685
+					array(
3686
+						'QST_ID'           => 0,
3687
+						'QST_display_text' => esc_html__('Country', 'event_espresso'),
3688
+						'QST_system'       => 'admin-country',
3689
+					)
3690
+				),
3691
+				EE_Answer::new_instance(
3692
+					array(
3693
+						'ANS_ID'    => 0,
3694
+						'ANS_value' => $this->_cpt_model_obj->country_ID(),
3695
+					)
3696
+				),
3697
+				array(
3698
+					'input_id'       => 'CNT_ISO',
3699
+					'input_name'     => 'CNT_ISO',
3700
+					'input_prefix'   => '',
3701
+					'append_qstn_id' => false,
3702
+				)
3703
+			)
3704
+		);
3705
+		$template                             =
3706
+			REG_TEMPLATE_PATH . 'attendee_address_details_metabox_content.template.php';
3707
+		EEH_Template::display_template($template, $this->_template_args);
3708
+	}
3709
+
3710
+
3711
+	/**
3712
+	 *        _attendee_details
3713
+	 *
3714
+	 * @access protected
3715
+	 * @param $post
3716
+	 * @return void
3717
+	 * @throws DomainException
3718
+	 * @throws EE_Error
3719
+	 */
3720
+	public function attendee_registrations_meta_box($post)
3721
+	{
3722
+		$this->_template_args['attendee']      = $this->_cpt_model_obj;
3723
+		$this->_template_args['registrations'] = $this->_cpt_model_obj->get_many_related('Registration');
3724
+		$template                              =
3725
+			REG_TEMPLATE_PATH . 'attendee_registrations_main_meta_box.template.php';
3726
+		EEH_Template::display_template($template, $this->_template_args);
3727
+	}
3728
+
3729
+
3730
+	/**
3731
+	 * add in the form fields for the attendee edit
3732
+	 *
3733
+	 * @param  WP_Post $post wp post object
3734
+	 * @return string html for new form.
3735
+	 * @throws DomainException
3736
+	 */
3737
+	public function after_title_form_fields($post)
3738
+	{
3739
+		if ($post->post_type == 'espresso_attendees') {
3740
+			$template                  = REG_TEMPLATE_PATH . 'attendee_details_after_title_form_fields.template.php';
3741
+			$template_args['attendee'] = $this->_cpt_model_obj;
3742
+			EEH_Template::display_template($template, $template_args);
3743
+		}
3744
+	}
3745
+
3746
+
3747
+	/**
3748
+	 *        _trash_or_restore_attendee
3749
+	 *
3750
+	 * @param boolean $trash - whether to move item to trash (TRUE) or restore it (FALSE)
3751
+	 * @return void
3752
+	 * @throws EE_Error
3753
+	 * @throws InvalidArgumentException
3754
+	 * @throws InvalidDataTypeException
3755
+	 * @throws InvalidInterfaceException
3756
+	 * @access protected
3757
+	 */
3758
+	protected function _trash_or_restore_attendees($trash = true)
3759
+	{
3760
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
3761
+		$ATT_MDL = EEM_Attendee::instance();
3762
+		$success = 1;
3763
+		//Checkboxes
3764
+		if ( ! empty($this->_req_data['checkbox']) && is_array($this->_req_data['checkbox'])) {
3765
+			// if array has more than one element than success message should be plural
3766
+			$success = count($this->_req_data['checkbox']) > 1 ? 2 : 1;
3767
+			// cycle thru checkboxes
3768
+			while (list($ATT_ID, $value) = each($this->_req_data['checkbox'])) {
3769
+				$updated = $trash ? $ATT_MDL->update_by_ID(array('status' => 'trash'), $ATT_ID)
3770
+					: $ATT_MDL->update_by_ID(array('status' => 'publish'), $ATT_ID);
3771
+				if ( ! $updated) {
3772
+					$success = 0;
3773
+				}
3774
+			}
3775
+		} else {
3776
+			// grab single id and delete
3777
+			$ATT_ID = absint($this->_req_data['ATT_ID']);
3778
+			//get attendee
3779
+			$att     = $ATT_MDL->get_one_by_ID($ATT_ID);
3780
+			$updated = $trash ? $att->set_status('trash') : $att->set_status('publish');
3781
+			$updated = $att->save();
3782
+			if ( ! $updated) {
3783
+				$success = 0;
3784
+			}
3785
+		}
3786
+		$what        = $success > 1
3787
+			? esc_html__('Contacts', 'event_espresso')
3788
+			: esc_html__('Contact', 'event_espresso');
3789
+		$action_desc = $trash
3790
+			? esc_html__('moved to the trash', 'event_espresso')
3791
+			: esc_html__('restored', 'event_espresso');
3792
+		$this->_redirect_after_action($success, $what, $action_desc, array('action' => 'contact_list'));
3793
+	}
3794 3794
 
3795 3795
 }
Please login to merge, or discard this patch.
Spacing   +93 added lines, -93 removed lines patch added patch discarded remove patch
@@ -76,7 +76,7 @@  discard block
 block discarded – undo
76 76
         // when adding a new registration...
77 77
         if (isset($this->_req_data['action']) && $this->_req_data['action'] === 'new_registration') {
78 78
             EE_System::do_not_cache();
79
-            if (! isset($this->_req_data['processing_registration'])
79
+            if ( ! isset($this->_req_data['processing_registration'])
80 80
                  || absint($this->_req_data['processing_registration']) !== 1
81 81
             ) {
82 82
                 // and it's NOT the attendee information reg step
@@ -171,7 +171,7 @@  discard block
 block discarded – undo
171 171
     public function _set_page_routes()
172 172
     {
173 173
         $this->_get_registration_status_array();
174
-        $reg_id             = ! empty($this->_req_data['_REG_ID']) && ! is_array($this->_req_data['_REG_ID'])
174
+        $reg_id = ! empty($this->_req_data['_REG_ID']) && ! is_array($this->_req_data['_REG_ID'])
175 175
             ? $this->_req_data['_REG_ID'] : 0;
176 176
         $reg_id = empty($reg_id) && ! empty($this->_req_data['reg_status_change_form']['REG_ID'])
177 177
             ? $this->_req_data['reg_status_change_form']['REG_ID']
@@ -669,7 +669,7 @@  discard block
 block discarded – undo
669 669
         //style
670 670
         wp_register_style(
671 671
             'espresso_reg',
672
-            REG_ASSETS_URL . 'espresso_registrations_admin.css',
672
+            REG_ASSETS_URL.'espresso_registrations_admin.css',
673 673
             array('ee-admin-css'),
674 674
             EVENT_ESPRESSO_VERSION
675 675
         );
@@ -677,7 +677,7 @@  discard block
 block discarded – undo
677 677
         //script
678 678
         wp_register_script(
679 679
             'espresso_reg',
680
-            REG_ASSETS_URL . 'espresso_registrations_admin.js',
680
+            REG_ASSETS_URL.'espresso_registrations_admin.js',
681 681
             array('jquery-ui-datepicker', 'jquery-ui-draggable', 'ee_admin_js'),
682 682
             EVENT_ESPRESSO_VERSION,
683 683
             true
@@ -715,7 +715,7 @@  discard block
 block discarded – undo
715 715
         wp_deregister_style('espresso_reg');
716 716
         wp_register_style(
717 717
             'espresso_att',
718
-            REG_ASSETS_URL . 'espresso_attendees_admin.css',
718
+            REG_ASSETS_URL.'espresso_attendees_admin.css',
719 719
             array('ee-admin-css'),
720 720
             EVENT_ESPRESSO_VERSION
721 721
         );
@@ -727,7 +727,7 @@  discard block
 block discarded – undo
727 727
     {
728 728
         wp_register_script(
729 729
             'ee-spco-for-admin',
730
-            REG_ASSETS_URL . 'spco_for_admin.js',
730
+            REG_ASSETS_URL.'spco_for_admin.js',
731 731
             array('underscore', 'jquery'),
732 732
             EVENT_ESPRESSO_VERSION,
733 733
             true
@@ -861,7 +861,7 @@  discard block
 block discarded – undo
861 861
                     'trash_registrations' => esc_html__('Trash Registrations', 'event_espresso'),
862 862
                 ),
863 863
             );
864
-            $this->_views['trash']      = array(
864
+            $this->_views['trash'] = array(
865 865
                 'slug'        => 'trash',
866 866
                 'label'       => esc_html__('Trash', 'event_espresso'),
867 867
                 'count'       => 0,
@@ -950,7 +950,7 @@  discard block
 block discarded – undo
950 950
         }
951 951
         $sc_items = array(
952 952
             'approved_status'   => array(
953
-                'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_approved,
953
+                'class' => 'ee-status-legend ee-status-legend-'.EEM_Registration::status_id_approved,
954 954
                 'desc'  => EEH_Template::pretty_status(
955 955
                     EEM_Registration::status_id_approved,
956 956
                     false,
@@ -958,7 +958,7 @@  discard block
 block discarded – undo
958 958
                 ),
959 959
             ),
960 960
             'pending_status'    => array(
961
-                'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_pending_payment,
961
+                'class' => 'ee-status-legend ee-status-legend-'.EEM_Registration::status_id_pending_payment,
962 962
                 'desc'  => EEH_Template::pretty_status(
963 963
                     EEM_Registration::status_id_pending_payment,
964 964
                     false,
@@ -966,7 +966,7 @@  discard block
 block discarded – undo
966 966
                 ),
967 967
             ),
968 968
             'wait_list'         => array(
969
-                'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_wait_list,
969
+                'class' => 'ee-status-legend ee-status-legend-'.EEM_Registration::status_id_wait_list,
970 970
                 'desc'  => EEH_Template::pretty_status(
971 971
                     EEM_Registration::status_id_wait_list,
972 972
                     false,
@@ -974,7 +974,7 @@  discard block
 block discarded – undo
974 974
                 ),
975 975
             ),
976 976
             'incomplete_status' => array(
977
-                'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_incomplete,
977
+                'class' => 'ee-status-legend ee-status-legend-'.EEM_Registration::status_id_incomplete,
978 978
                 'desc'  => EEH_Template::pretty_status(
979 979
                     EEM_Registration::status_id_incomplete,
980 980
                     false,
@@ -982,7 +982,7 @@  discard block
 block discarded – undo
982 982
                 ),
983 983
             ),
984 984
             'not_approved'      => array(
985
-                'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_not_approved,
985
+                'class' => 'ee-status-legend ee-status-legend-'.EEM_Registration::status_id_not_approved,
986 986
                 'desc'  => EEH_Template::pretty_status(
987 987
                     EEM_Registration::status_id_not_approved,
988 988
                     false,
@@ -990,7 +990,7 @@  discard block
 block discarded – undo
990 990
                 ),
991 991
             ),
992 992
             'declined_status'   => array(
993
-                'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_declined,
993
+                'class' => 'ee-status-legend ee-status-legend-'.EEM_Registration::status_id_declined,
994 994
                 'desc'  => EEH_Template::pretty_status(
995 995
                     EEM_Registration::status_id_declined,
996 996
                     false,
@@ -998,7 +998,7 @@  discard block
 block discarded – undo
998 998
                 ),
999 999
             ),
1000 1000
             'cancelled_status'  => array(
1001
-                'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_cancelled,
1001
+                'class' => 'ee-status-legend ee-status-legend-'.EEM_Registration::status_id_cancelled,
1002 1002
                 'desc'  => EEH_Template::pretty_status(
1003 1003
                     EEM_Registration::status_id_cancelled,
1004 1004
                     false,
@@ -1021,7 +1021,7 @@  discard block
 block discarded – undo
1021 1021
         $EVT_ID                                    = ! empty($this->_req_data['event_id'])
1022 1022
             ? absint($this->_req_data['event_id'])
1023 1023
             : 0;
1024
-        $ATT_ID = !empty($this->_req_data['ATT_ID'])
1024
+        $ATT_ID = ! empty($this->_req_data['ATT_ID'])
1025 1025
             ? absint($this->_req_data['ATT_ID'])
1026 1026
             : 0;
1027 1027
         if ($ATT_ID) {
@@ -1033,13 +1033,13 @@  discard block
 block discarded – undo
1033 1033
                         'event_espresso'
1034 1034
                     ),
1035 1035
                     '<h3 style="line-height:1.5em;">',
1036
-                    '<a href="' . EE_Admin_Page::add_query_args_and_nonce(
1036
+                    '<a href="'.EE_Admin_Page::add_query_args_and_nonce(
1037 1037
                         array(
1038 1038
                             'action' => 'edit_attendee',
1039 1039
                             'post' => $ATT_ID
1040 1040
                         ),
1041 1041
                         REG_ADMIN_URL
1042
-                    ) . '">' . $attendee->full_name() . '</a>',
1042
+                    ).'">'.$attendee->full_name().'</a>',
1043 1043
                     '</h3>'
1044 1044
                 );
1045 1045
             }
@@ -1050,7 +1050,7 @@  discard block
 block discarded – undo
1050 1050
                 'espresso_registrations_new_registration',
1051 1051
                 $EVT_ID
1052 1052
             )) {
1053
-                $this->_admin_page_title .= ' ' . $this->get_action_link_or_button(
1053
+                $this->_admin_page_title .= ' '.$this->get_action_link_or_button(
1054 1054
                     'new_registration',
1055 1055
                     'add-registrant',
1056 1056
                     array('event_id' => $EVT_ID),
@@ -1090,7 +1090,7 @@  discard block
 block discarded – undo
1090 1090
                 $this->_template_args['admin_page_header'] .= ' &nbsp;<span class="drk-grey-text">';
1091 1091
                 $this->_template_args['admin_page_header'] .= '<span class="dashicons dashicons-calendar"></span>';
1092 1092
                 $this->_template_args['admin_page_header'] .= $datetime->name();
1093
-                $this->_template_args['admin_page_header'] .= ' ( ' . $datetime->start_date() . ' )';
1093
+                $this->_template_args['admin_page_header'] .= ' ( '.$datetime->start_date().' )';
1094 1094
                 $this->_template_args['admin_page_header'] .= '</span></h3>';
1095 1095
             }
1096 1096
         }
@@ -1197,7 +1197,7 @@  discard block
 block discarded – undo
1197 1197
             'caps'                     => EEM_Registration::caps_read_admin,
1198 1198
             'default_where_conditions' => 'this_model_only',
1199 1199
         );
1200
-        if (! $count) {
1200
+        if ( ! $count) {
1201 1201
             $query_params = array_merge(
1202 1202
                 $query_params,
1203 1203
                 $this->_get_orderby_for_registrations_query(),
@@ -1218,7 +1218,7 @@  discard block
 block discarded – undo
1218 1218
     protected function addAttendeeIdToWhereConditions(array $request)
1219 1219
     {
1220 1220
         $where = array();
1221
-        if (! empty($request['ATT_ID'])) {
1221
+        if ( ! empty($request['ATT_ID'])) {
1222 1222
             $where['ATT_ID'] = absint($request['ATT_ID']);
1223 1223
         }
1224 1224
         return $where;
@@ -1234,7 +1234,7 @@  discard block
 block discarded – undo
1234 1234
     protected function _add_event_id_to_where_conditions(array $request)
1235 1235
     {
1236 1236
         $where = array();
1237
-        if (! empty($request['event_id'])) {
1237
+        if ( ! empty($request['event_id'])) {
1238 1238
             $where['EVT_ID'] = absint($request['event_id']);
1239 1239
         }
1240 1240
         return $where;
@@ -1250,7 +1250,7 @@  discard block
 block discarded – undo
1250 1250
     protected function _add_category_id_to_where_conditions(array $request)
1251 1251
     {
1252 1252
         $where = array();
1253
-        if (! empty($request['EVT_CAT']) && (int)$request['EVT_CAT'] !== -1) {
1253
+        if ( ! empty($request['EVT_CAT']) && (int) $request['EVT_CAT'] !== -1) {
1254 1254
             $where['Event.Term_Taxonomy.term_id'] = absint($request['EVT_CAT']);
1255 1255
         }
1256 1256
         return $where;
@@ -1266,10 +1266,10 @@  discard block
 block discarded – undo
1266 1266
     protected function _add_datetime_id_to_where_conditions(array $request)
1267 1267
     {
1268 1268
         $where = array();
1269
-        if (! empty($request['datetime_id'])) {
1269
+        if ( ! empty($request['datetime_id'])) {
1270 1270
             $where['Ticket.Datetime.DTT_ID'] = absint($request['datetime_id']);
1271 1271
         }
1272
-        if (! empty($request['DTT_ID'])) {
1272
+        if ( ! empty($request['DTT_ID'])) {
1273 1273
             $where['Ticket.Datetime.DTT_ID'] = absint($request['DTT_ID']);
1274 1274
         }
1275 1275
         return $where;
@@ -1295,7 +1295,7 @@  discard block
 block discarded – undo
1295 1295
          * If not filtering by specified status, then we show all registrations excluding incomplete registrations
1296 1296
          * UNLESS viewing trashed registrations.
1297 1297
          */
1298
-        if (! empty($registration_status)) {
1298
+        if ( ! empty($registration_status)) {
1299 1299
             $where['STS_ID'] = $registration_status;
1300 1300
         } else {
1301 1301
             //make sure we exclude incomplete registrations, but only if not trashed.
@@ -1338,12 +1338,12 @@  discard block
 block discarded – undo
1338 1338
                 array(
1339 1339
                     EEM_Registration::instance()->convert_datetime_for_query(
1340 1340
                         'REG_date',
1341
-                        $now . ' 00:00:00',
1341
+                        $now.' 00:00:00',
1342 1342
                         'Y-m-d H:i:s'
1343 1343
                     ),
1344 1344
                     EEM_Registration::instance()->convert_datetime_for_query(
1345 1345
                         'REG_date',
1346
-                        $now . ' 23:59:59',
1346
+                        $now.' 23:59:59',
1347 1347
                         'Y-m-d H:i:s'
1348 1348
                     ),
1349 1349
                 ),
@@ -1356,12 +1356,12 @@  discard block
 block discarded – undo
1356 1356
                 array(
1357 1357
                     EEM_Registration::instance()->convert_datetime_for_query(
1358 1358
                         'REG_date',
1359
-                        $current_year_and_month . '-01 00:00:00',
1359
+                        $current_year_and_month.'-01 00:00:00',
1360 1360
                         'Y-m-d H:i:s'
1361 1361
                     ),
1362 1362
                     EEM_Registration::instance()->convert_datetime_for_query(
1363 1363
                         'REG_date',
1364
-                        $current_year_and_month . '-' . $days_this_month . ' 23:59:59',
1364
+                        $current_year_and_month.'-'.$days_this_month.' 23:59:59',
1365 1365
                         'Y-m-d H:i:s'
1366 1366
                     ),
1367 1367
                 ),
@@ -1376,18 +1376,18 @@  discard block
 block discarded – undo
1376 1376
                 : '';
1377 1377
             //if there is not a month or year then we can't go further
1378 1378
             if ($month_requested && $year_requested) {
1379
-                $days_in_month     = date('t', strtotime($year_requested . '-' . $month_requested . '-' . '01'));
1379
+                $days_in_month     = date('t', strtotime($year_requested.'-'.$month_requested.'-'.'01'));
1380 1380
                 $where['REG_date'] = array(
1381 1381
                     'BETWEEN',
1382 1382
                     array(
1383 1383
                         EEM_Registration::instance()->convert_datetime_for_query(
1384 1384
                             'REG_date',
1385
-                            $year_requested . '-' . $month_requested . '-01 00:00:00',
1385
+                            $year_requested.'-'.$month_requested.'-01 00:00:00',
1386 1386
                             'Y-m-d H:i:s'
1387 1387
                         ),
1388 1388
                         EEM_Registration::instance()->convert_datetime_for_query(
1389 1389
                             'REG_date',
1390
-                            $year_requested . '-' . $month_requested . '-' . $days_in_month . ' 23:59:59',
1390
+                            $year_requested.'-'.$month_requested.'-'.$days_in_month.' 23:59:59',
1391 1391
                             'Y-m-d H:i:s'
1392 1392
                         ),
1393 1393
                     ),
@@ -1407,8 +1407,8 @@  discard block
 block discarded – undo
1407 1407
     protected function _add_search_to_where_conditions(array $request)
1408 1408
     {
1409 1409
         $where = array();
1410
-        if (! empty($request['s'])) {
1411
-            $search_string = '%' . sanitize_text_field($request['s']) . '%';
1410
+        if ( ! empty($request['s'])) {
1411
+            $search_string = '%'.sanitize_text_field($request['s']).'%';
1412 1412
             $where['OR*search_conditions'] = array(
1413 1413
                 'Event.EVT_name'                          => array('LIKE', $search_string),
1414 1414
                 'Event.EVT_desc'                          => array('LIKE', $search_string),
@@ -1525,7 +1525,7 @@  discard block
 block discarded – undo
1525 1525
             : $per_page;
1526 1526
 
1527 1527
         //-1 means return all results so get out if that's set.
1528
-        if ((int)$per_page === -1) {
1528
+        if ((int) $per_page === -1) {
1529 1529
             return array();
1530 1530
         }
1531 1531
         $per_page = absint($per_page);
@@ -1581,7 +1581,7 @@  discard block
 block discarded – undo
1581 1581
                 ),
1582 1582
                 REG_ADMIN_URL
1583 1583
             );
1584
-            $this->_template_args['filtered_transactions_link']  = EE_Admin_Page::add_query_args_and_nonce(
1584
+            $this->_template_args['filtered_transactions_link'] = EE_Admin_Page::add_query_args_and_nonce(
1585 1585
                 array(
1586 1586
                     'action' => 'default',
1587 1587
                     'EVT_ID' => $event_id,
@@ -1589,7 +1589,7 @@  discard block
 block discarded – undo
1589 1589
                 ),
1590 1590
                 admin_url('admin.php')
1591 1591
             );
1592
-            $this->_template_args['event_link']                  = EE_Admin_Page::add_query_args_and_nonce(
1592
+            $this->_template_args['event_link'] = EE_Admin_Page::add_query_args_and_nonce(
1593 1593
                 array(
1594 1594
                     'page'   => 'espresso_events',
1595 1595
                     'action' => 'edit',
@@ -1598,12 +1598,12 @@  discard block
 block discarded – undo
1598 1598
                 admin_url('admin.php')
1599 1599
             );
1600 1600
             //next and previous links
1601
-            $next_reg                                      = $this->_registration->next(
1601
+            $next_reg = $this->_registration->next(
1602 1602
                 null,
1603 1603
                 array(),
1604 1604
                 'REG_ID'
1605 1605
             );
1606
-            $this->_template_args['next_registration']     = $next_reg
1606
+            $this->_template_args['next_registration'] = $next_reg
1607 1607
                 ? $this->_next_link(
1608 1608
                     EE_Admin_Page::add_query_args_and_nonce(
1609 1609
                         array(
@@ -1615,7 +1615,7 @@  discard block
 block discarded – undo
1615 1615
                     'dashicons dashicons-arrow-right ee-icon-size-22'
1616 1616
                 )
1617 1617
                 : '';
1618
-            $previous_reg                                  = $this->_registration->previous(
1618
+            $previous_reg = $this->_registration->previous(
1619 1619
                 null,
1620 1620
                 array(),
1621 1621
                 'REG_ID'
@@ -1633,7 +1633,7 @@  discard block
 block discarded – undo
1633 1633
                 )
1634 1634
                 : '';
1635 1635
             // grab header
1636
-            $template_path                             = REG_TEMPLATE_PATH . 'reg_admin_details_header.template.php';
1636
+            $template_path                             = REG_TEMPLATE_PATH.'reg_admin_details_header.template.php';
1637 1637
             $this->_template_args['REG_ID']            = $this->_registration->ID();
1638 1638
             $this->_template_args['admin_page_header'] = EEH_Template::display_template(
1639 1639
                 $template_path,
@@ -1753,7 +1753,7 @@  discard block
 block discarded – undo
1753 1753
                             EEH_HTML::strong(
1754 1754
                                 $this->_registration->pretty_status(),
1755 1755
                                 '',
1756
-                                'status-' . $this->_registration->status_ID(),
1756
+                                'status-'.$this->_registration->status_ID(),
1757 1757
                                 'line-height: 1em; font-size: 1.5em; font-weight: bold;'
1758 1758
                             )
1759 1759
                         )
@@ -1833,11 +1833,11 @@  discard block
 block discarded – undo
1833 1833
     {
1834 1834
         if (isset($this->_req_data['reg_status_change_form'])) {
1835 1835
             $REG_IDs = isset($this->_req_data['reg_status_change_form']['REG_ID'])
1836
-                ? (array)$this->_req_data['reg_status_change_form']['REG_ID']
1836
+                ? (array) $this->_req_data['reg_status_change_form']['REG_ID']
1837 1837
                 : array();
1838 1838
         } else {
1839 1839
             $REG_IDs = isset($this->_req_data['_REG_ID'])
1840
-                ? (array)$this->_req_data['_REG_ID']
1840
+                ? (array) $this->_req_data['_REG_ID']
1841 1841
                 : array();
1842 1842
         }
1843 1843
         // sanitize $REG_IDs
@@ -1900,7 +1900,7 @@  discard block
 block discarded – undo
1900 1900
     {
1901 1901
         $success = false;
1902 1902
         // typecast $REG_IDs
1903
-        $REG_IDs = (array)$REG_IDs;
1903
+        $REG_IDs = (array) $REG_IDs;
1904 1904
         if ( ! empty($REG_IDs)) {
1905 1905
             $success = true;
1906 1906
             // set default status if none is passed
@@ -2050,7 +2050,7 @@  discard block
 block discarded – undo
2050 2050
             $action,
2051 2051
             $notify
2052 2052
         );
2053
-        $method = $action . '_registration';
2053
+        $method = $action.'_registration';
2054 2054
         if (method_exists($this, $method)) {
2055 2055
             $this->$method($notify);
2056 2056
         }
@@ -2168,7 +2168,7 @@  discard block
 block discarded – undo
2168 2168
             $filtered_line_item_tree,
2169 2169
             array('EE_Registration' => $this->_registration)
2170 2170
         );
2171
-        $attendee                                = $this->_registration->attendee();
2171
+        $attendee = $this->_registration->attendee();
2172 2172
         if (EE_Registry::instance()->CAP->current_user_can(
2173 2173
             'ee_read_transaction',
2174 2174
             'espresso_transactions_view_transaction'
@@ -2247,7 +2247,7 @@  discard block
 block discarded – undo
2247 2247
                 'Payment method response',
2248 2248
                 'event_espresso'
2249 2249
             );
2250
-            $this->_template_args['reg_details']['response_msg']['class']   = 'regular-text';
2250
+            $this->_template_args['reg_details']['response_msg']['class'] = 'regular-text';
2251 2251
         }
2252 2252
         $this->_template_args['reg_details']['registration_session']['value'] = $reg_details['registration_session'];
2253 2253
         $this->_template_args['reg_details']['registration_session']['label'] = esc_html__(
@@ -2275,7 +2275,7 @@  discard block
 block discarded – undo
2275 2275
         $this->_template_args['REG_ID']                                       = $this->_registration->ID();
2276 2276
         $this->_template_args['event_id']                                     = $this->_registration->event_ID();
2277 2277
         $template_path                                                        =
2278
-            REG_TEMPLATE_PATH . 'reg_admin_details_main_meta_box_reg_details.template.php';
2278
+            REG_TEMPLATE_PATH.'reg_admin_details_main_meta_box_reg_details.template.php';
2279 2279
         echo EEH_Template::display_template($template_path, $this->_template_args, true);
2280 2280
     }
2281 2281
 
@@ -2304,7 +2304,7 @@  discard block
 block discarded – undo
2304 2304
             $this->_template_args['reg_questions_form_action'] = 'edit_registration';
2305 2305
             $this->_template_args['REG_ID']                    = $this->_registration->ID();
2306 2306
             $template_path                                     =
2307
-                REG_TEMPLATE_PATH . 'reg_admin_details_main_meta_box_reg_questions.template.php';
2307
+                REG_TEMPLATE_PATH.'reg_admin_details_main_meta_box_reg_questions.template.php';
2308 2308
             echo EEH_Template::display_template($template_path, $this->_template_args, true);
2309 2309
         }
2310 2310
     }
@@ -2321,7 +2321,7 @@  discard block
 block discarded – undo
2321 2321
     public function form_before_question_group($output)
2322 2322
     {
2323 2323
         EE_Error::doing_it_wrong(
2324
-            __CLASS__ . '::' . __FUNCTION__,
2324
+            __CLASS__.'::'.__FUNCTION__,
2325 2325
             esc_html__(
2326 2326
                 'This method would have been protected but was used on a filter callback so needed to be public. Please discontinue usage as it will be removed soon.',
2327 2327
                 'event_espresso'
@@ -2346,7 +2346,7 @@  discard block
 block discarded – undo
2346 2346
     public function form_after_question_group($output)
2347 2347
     {
2348 2348
         EE_Error::doing_it_wrong(
2349
-            __CLASS__ . '::' . __FUNCTION__,
2349
+            __CLASS__.'::'.__FUNCTION__,
2350 2350
             esc_html__(
2351 2351
                 'This method would have been protected but was used on a filter callback so needed to be public. Please discontinue usage as it will be removed soon.',
2352 2352
                 'event_espresso'
@@ -2384,7 +2384,7 @@  discard block
 block discarded – undo
2384 2384
     public function form_form_field_label_wrap($label)
2385 2385
     {
2386 2386
         EE_Error::doing_it_wrong(
2387
-            __CLASS__ . '::' . __FUNCTION__,
2387
+            __CLASS__.'::'.__FUNCTION__,
2388 2388
             esc_html__(
2389 2389
                 'This method would have been protected but was used on a filter callback so needed to be public. Please discontinue usage as it will be removed soon.',
2390 2390
                 'event_espresso'
@@ -2394,7 +2394,7 @@  discard block
 block discarded – undo
2394 2394
         return '
2395 2395
 			<tr>
2396 2396
 				<th>
2397
-					' . $label . '
2397
+					' . $label.'
2398 2398
 				</th>';
2399 2399
     }
2400 2400
 
@@ -2410,7 +2410,7 @@  discard block
 block discarded – undo
2410 2410
     public function form_form_field_input__wrap($input)
2411 2411
     {
2412 2412
         EE_Error::doing_it_wrong(
2413
-            __CLASS__ . '::' . __FUNCTION__,
2413
+            __CLASS__.'::'.__FUNCTION__,
2414 2414
             esc_html__(
2415 2415
                 'This method would have been protected but was used on a filter callback so needed to be public. Please discontinue usage as it will be removed soon.',
2416 2416
                 'event_espresso'
@@ -2419,7 +2419,7 @@  discard block
 block discarded – undo
2419 2419
         );
2420 2420
         return '
2421 2421
 				<td class="reg-admin-attendee-questions-input-td disabled-input">
2422
-					' . $input . '
2422
+					' . $input.'
2423 2423
 				</td>
2424 2424
 			</tr>';
2425 2425
     }
@@ -2464,7 +2464,7 @@  discard block
 block discarded – undo
2464 2464
     protected function _get_reg_custom_questions_form($REG_ID)
2465 2465
     {
2466 2466
         if ( ! $this->_reg_custom_questions_form) {
2467
-            require_once(REG_ADMIN . 'form_sections' . DS . 'EE_Registration_Custom_Questions_Form.form.php');
2467
+            require_once(REG_ADMIN.'form_sections'.DS.'EE_Registration_Custom_Questions_Form.form.php');
2468 2468
             $this->_reg_custom_questions_form = new EE_Registration_Custom_Questions_Form(
2469 2469
                 EEM_Registration::instance()->get_one_by_ID($REG_ID)
2470 2470
             );
@@ -2500,7 +2500,7 @@  discard block
 block discarded – undo
2500 2500
         if ($form->is_valid()) {
2501 2501
             foreach ($form->subforms() as $question_group_id => $question_group_form) {
2502 2502
                 foreach ($question_group_form->inputs() as $question_id => $input) {
2503
-                    $where_conditions    = array(
2503
+                    $where_conditions = array(
2504 2504
                         'QST_ID' => $question_id,
2505 2505
                         'REG_ID' => $REG_ID,
2506 2506
                     );
@@ -2541,7 +2541,7 @@  discard block
 block discarded – undo
2541 2541
         $REG = EEM_Registration::instance();
2542 2542
         //get all other registrations on this transaction, and cache
2543 2543
         //the attendees for them so we don't have to run another query using force_join
2544
-        $registrations                           = $REG->get_all(array(
2544
+        $registrations = $REG->get_all(array(
2545 2545
             array(
2546 2546
                 'TXN_ID' => $this->_registration->transaction_ID(),
2547 2547
                 'REG_ID' => array('!=', $this->_registration->ID()),
@@ -2565,7 +2565,7 @@  discard block
 block discarded – undo
2565 2565
             $att_nmbr = 1;
2566 2566
             foreach ($registrations as $registration) {
2567 2567
                 /* @var $registration EE_Registration */
2568
-                $attendee                                                    = $registration->attendee()
2568
+                $attendee = $registration->attendee()
2569 2569
                     ? $registration->attendee()
2570 2570
                     : EEM_Attendee::instance()
2571 2571
                                   ->create_default_object();
@@ -2578,19 +2578,19 @@  discard block
 block discarded – undo
2578 2578
                     ', ',
2579 2579
                     $attendee->full_address_as_array()
2580 2580
                 );
2581
-                $this->_template_args['attendees'][$att_nmbr]['att_link']    = self::add_query_args_and_nonce(
2581
+                $this->_template_args['attendees'][$att_nmbr]['att_link'] = self::add_query_args_and_nonce(
2582 2582
                     array(
2583 2583
                         'action' => 'edit_attendee',
2584 2584
                         'post'   => $attendee->ID(),
2585 2585
                     ),
2586 2586
                     REG_ADMIN_URL
2587 2587
                 );
2588
-                $this->_template_args['attendees'][$att_nmbr]['event_name']  = $registration->event_obj()->name();
2588
+                $this->_template_args['attendees'][$att_nmbr]['event_name'] = $registration->event_obj()->name();
2589 2589
                 $att_nmbr++;
2590 2590
             }
2591 2591
             $this->_template_args['currency_sign'] = EE_Registry::instance()->CFG->currency->sign;
2592 2592
         }
2593
-        $template_path = REG_TEMPLATE_PATH . 'reg_admin_details_main_meta_box_attendees.template.php';
2593
+        $template_path = REG_TEMPLATE_PATH.'reg_admin_details_main_meta_box_attendees.template.php';
2594 2594
         echo EEH_Template::display_template($template_path, $this->_template_args, true);
2595 2595
     }
2596 2596
 
@@ -2633,20 +2633,20 @@  discard block
 block discarded – undo
2633 2633
         $this->_template_args['phone']             = $attendee->phone();
2634 2634
         $this->_template_args['formatted_address'] = EEH_Address::format($attendee);
2635 2635
         //edit link
2636
-        $this->_template_args['att_edit_link']  = EE_Admin_Page::add_query_args_and_nonce(array(
2636
+        $this->_template_args['att_edit_link'] = EE_Admin_Page::add_query_args_and_nonce(array(
2637 2637
             'action' => 'edit_attendee',
2638 2638
             'post'   => $attendee->ID(),
2639 2639
         ), REG_ADMIN_URL);
2640 2640
         $this->_template_args['att_edit_label'] = esc_html__('View/Edit Contact', 'event_espresso');
2641 2641
         //create link
2642
-        $this->_template_args['create_link']  = $primary_registration instanceof EE_Registration
2642
+        $this->_template_args['create_link'] = $primary_registration instanceof EE_Registration
2643 2643
             ? EE_Admin_Page::add_query_args_and_nonce(array(
2644 2644
                 'action'  => 'duplicate_attendee',
2645 2645
                 '_REG_ID' => $this->_registration->ID(),
2646 2646
             ), REG_ADMIN_URL) : '';
2647 2647
         $this->_template_args['create_label'] = esc_html__('Create Contact', 'event_espresso');
2648 2648
         $this->_template_args['att_check']    = $att_check;
2649
-        $template_path                        = REG_TEMPLATE_PATH . 'reg_admin_details_side_meta_box_registrant.template.php';
2649
+        $template_path                        = REG_TEMPLATE_PATH.'reg_admin_details_side_meta_box_registrant.template.php';
2650 2650
         echo EEH_Template::display_template($template_path, $this->_template_args, true);
2651 2651
     }
2652 2652
 
@@ -2691,7 +2691,7 @@  discard block
 block discarded – undo
2691 2691
             /** @var EE_Registration $REG */
2692 2692
             $REG = EEM_Registration::instance()->get_one_by_ID($REG_ID);
2693 2693
             $payments = $REG->registration_payments();
2694
-            if (! empty($payments)) {
2694
+            if ( ! empty($payments)) {
2695 2695
                 $name = $REG->attendee() instanceof EE_Attendee
2696 2696
                     ? $REG->attendee()->full_name()
2697 2697
                     : esc_html__('Unknown Attendee', 'event_espresso');
@@ -2887,7 +2887,7 @@  discard block
 block discarded – undo
2887 2887
                 'action' => 'edit',
2888 2888
                 'post'   => $this->_reg_event->ID(),
2889 2889
             ), EVENTS_ADMIN_URL);
2890
-            $edit_event_lnk                     = '<a href="'
2890
+            $edit_event_lnk = '<a href="'
2891 2891
                                                   . $edit_event_url
2892 2892
                                                   . '" title="'
2893 2893
                                                   . esc_attr__('Edit ', 'event_espresso')
@@ -2905,7 +2905,7 @@  discard block
 block discarded – undo
2905 2905
         }
2906 2906
         // grab header
2907 2907
         $template_path                              =
2908
-            REG_TEMPLATE_PATH . 'reg_admin_register_new_attendee.template.php';
2908
+            REG_TEMPLATE_PATH.'reg_admin_register_new_attendee.template.php';
2909 2909
         $this->_template_args['admin_page_content'] = EEH_Template::display_template($template_path,
2910 2910
             $this->_template_args, true);
2911 2911
         //$this->_set_publish_post_box_vars( NULL, FALSE, FALSE, NULL, FALSE );
@@ -2943,7 +2943,7 @@  discard block
 block discarded – undo
2943 2943
                 '</b>'
2944 2944
             );
2945 2945
             return '
2946
-	<div id="ee-add-reg-back-button-dv"><p>' . $warning_msg . '</p></div>
2946
+	<div id="ee-add-reg-back-button-dv"><p>' . $warning_msg.'</p></div>
2947 2947
 	<script >
2948 2948
 		// WHOAH !!! it appears that someone is using the back button from the Transaction admin page
2949 2949
 		// after just adding a new registration... we gotta try to put a stop to that !!!
@@ -3011,7 +3011,7 @@  discard block
 block discarded – undo
3011 3011
         //we come back to the process_registration_step route.
3012 3012
         $this->_set_add_edit_form_tags('process_reg_step', $hidden_fields);
3013 3013
         return EEH_Template::display_template(
3014
-            REG_TEMPLATE_PATH . 'reg_admin_register_new_attendee_step_content.template.php',
3014
+            REG_TEMPLATE_PATH.'reg_admin_register_new_attendee_step_content.template.php',
3015 3015
             $template_args,
3016 3016
             true
3017 3017
         );
@@ -3033,7 +3033,7 @@  discard block
 block discarded – undo
3033 3033
         if (is_object($this->_reg_event)) {
3034 3034
             return true;
3035 3035
         }
3036
-        $EVT_ID = (! empty($this->_req_data['event_id'])) ? absint($this->_req_data['event_id']) : false;
3036
+        $EVT_ID = ( ! empty($this->_req_data['event_id'])) ? absint($this->_req_data['event_id']) : false;
3037 3037
         if ( ! $EVT_ID) {
3038 3038
             return false;
3039 3039
         }
@@ -3103,7 +3103,7 @@  discard block
 block discarded – undo
3103 3103
                 }
3104 3104
                 break;
3105 3105
             case 'questions' :
3106
-                if (! isset(
3106
+                if ( ! isset(
3107 3107
                     $this->_req_data['txn_reg_status_change'],
3108 3108
                     $this->_req_data['txn_reg_status_change']['send_notifications'])
3109 3109
                 ) {
@@ -3223,7 +3223,7 @@  discard block
 block discarded – undo
3223 3223
     public function get_attendees($per_page, $count = false, $trash = false)
3224 3224
     {
3225 3225
         do_action('AHEE_log', __FILE__, __FUNCTION__, '');
3226
-        require_once(REG_ADMIN . 'EE_Attendee_Contact_List_Table.class.php');
3226
+        require_once(REG_ADMIN.'EE_Attendee_Contact_List_Table.class.php');
3227 3227
         $ATT_MDL                    = EEM_Attendee::instance();
3228 3228
         $this->_req_data['orderby'] = ! empty($this->_req_data['orderby']) ? $this->_req_data['orderby'] : '';
3229 3229
         switch ($this->_req_data['orderby']) {
@@ -3263,7 +3263,7 @@  discard block
 block discarded – undo
3263 3263
             : $per_page;
3264 3264
         $_where       = array();
3265 3265
         if ( ! empty($this->_req_data['s'])) {
3266
-            $sstr         = '%' . $this->_req_data['s'] . '%';
3266
+            $sstr         = '%'.$this->_req_data['s'].'%';
3267 3267
             $_where['OR'] = array(
3268 3268
                 'Registration.Event.EVT_name'       => array('LIKE', $sstr),
3269 3269
                 'Registration.Event.EVT_desc'       => array('LIKE', $sstr),
@@ -3290,17 +3290,17 @@  discard block
 block discarded – undo
3290 3290
             'extra_selects' => array('Registration_Count' => array('Registration.REG_ID', 'count', '%d')),
3291 3291
             'limit' => $limit
3292 3292
         );
3293
-        if (! $count) {
3293
+        if ( ! $count) {
3294 3294
             $query_args['order_by'] = array($orderby => $sort);
3295 3295
         }
3296 3296
         if ($trash) {
3297 3297
             $query_args[0]['status'] = array('!=', 'publish');
3298
-            $all_attendees    = $count
3298
+            $all_attendees = $count
3299 3299
                 ? $ATT_MDL->count($query_args, 'ATT_ID', true)
3300 3300
                 : $ATT_MDL->get_all($query_args);
3301 3301
         } else {
3302 3302
             $query_args[0]['status'] = array('IN', array('publish'));
3303
-            $all_attendees    = $count
3303
+            $all_attendees = $count
3304 3304
                 ? $ATT_MDL->count($query_args, 'ATT_ID', true)
3305 3305
                 : $ATT_MDL->get_all($query_args);
3306 3306
         }
@@ -3330,9 +3330,9 @@  discard block
 block discarded – undo
3330 3330
      *                                                     the query parameters from the request
3331 3331
      * @return void ends the request with a redirect or download
3332 3332
      */
3333
-    public function _registrations_report_base( $method_name_for_getting_query_params )
3333
+    public function _registrations_report_base($method_name_for_getting_query_params)
3334 3334
     {
3335
-        if (! defined('EE_USE_OLD_CSV_REPORT_CLASS')) {
3335
+        if ( ! defined('EE_USE_OLD_CSV_REPORT_CLASS')) {
3336 3336
             wp_redirect(EE_Admin_Page::add_query_args_and_nonce(
3337 3337
                 array(
3338 3338
                     'page'        => 'espresso_batch',
@@ -3341,7 +3341,7 @@  discard block
 block discarded – undo
3341 3341
                     'filters'     => urlencode(
3342 3342
                         serialize(
3343 3343
                             call_user_func(
3344
-                                array( $this, $method_name_for_getting_query_params ),
3344
+                                array($this, $method_name_for_getting_query_params),
3345 3345
                                 EEH_Array::is_set(
3346 3346
                                     $this->_req_data,
3347 3347
                                     'filters',
@@ -3361,8 +3361,8 @@  discard block
 block discarded – undo
3361 3361
                 'EVT_ID' => isset($this->_req_data['EVT_ID']) ? $this->_req_data['EVT_ID'] : null,
3362 3362
             );
3363 3363
             $this->_req_data = array_merge($this->_req_data, $new_request_args);
3364
-            if (is_readable(EE_CLASSES . 'EE_Export.class.php')) {
3365
-                require_once(EE_CLASSES . 'EE_Export.class.php');
3364
+            if (is_readable(EE_CLASSES.'EE_Export.class.php')) {
3365
+                require_once(EE_CLASSES.'EE_Export.class.php');
3366 3366
                 $EE_Export = EE_Export::instance($this->_req_data);
3367 3367
                 $EE_Export->export();
3368 3368
             }
@@ -3383,8 +3383,8 @@  discard block
 block discarded – undo
3383 3383
 
3384 3384
     public function _contact_list_export()
3385 3385
     {
3386
-        if (is_readable(EE_CLASSES . 'EE_Export.class.php')) {
3387
-            require_once(EE_CLASSES . 'EE_Export.class.php');
3386
+        if (is_readable(EE_CLASSES.'EE_Export.class.php')) {
3387
+            require_once(EE_CLASSES.'EE_Export.class.php');
3388 3388
             $EE_Export = EE_Export::instance($this->_req_data);
3389 3389
             $EE_Export->export_attendees();
3390 3390
         }
@@ -3401,8 +3401,8 @@  discard block
 block discarded – undo
3401 3401
                 'return_url'  => urlencode($this->_req_data['return_url']),
3402 3402
             )));
3403 3403
         } else {
3404
-            if (is_readable(EE_CLASSES . 'EE_Export.class.php')) {
3405
-                require_once(EE_CLASSES . 'EE_Export.class.php');
3404
+            if (is_readable(EE_CLASSES.'EE_Export.class.php')) {
3405
+                require_once(EE_CLASSES.'EE_Export.class.php');
3406 3406
                 $EE_Export = EE_Export::instance($this->_req_data);
3407 3407
                 $EE_Export->report_attendees();
3408 3408
             }
@@ -3484,7 +3484,7 @@  discard block
 block discarded – undo
3484 3484
             $updated_fields = array(
3485 3485
                 'ATT_fname'     => $this->_req_data['ATT_fname'],
3486 3486
                 'ATT_lname'     => $this->_req_data['ATT_lname'],
3487
-                'ATT_full_name' => $this->_req_data['ATT_fname'] . ' ' . $this->_req_data['ATT_lname'],
3487
+                'ATT_full_name' => $this->_req_data['ATT_fname'].' '.$this->_req_data['ATT_lname'],
3488 3488
                 'ATT_address'   => isset($this->_req_data['ATT_address']) ? $this->_req_data['ATT_address'] : '',
3489 3489
                 'ATT_address2'  => isset($this->_req_data['ATT_address2']) ? $this->_req_data['ATT_address2'] : '',
3490 3490
                 'ATT_city'      => isset($this->_req_data['ATT_city']) ? $this->_req_data['ATT_city'] : '',
@@ -3702,8 +3702,8 @@  discard block
 block discarded – undo
3702 3702
                 )
3703 3703
             )
3704 3704
         );
3705
-        $template                             =
3706
-            REG_TEMPLATE_PATH . 'attendee_address_details_metabox_content.template.php';
3705
+        $template =
3706
+            REG_TEMPLATE_PATH.'attendee_address_details_metabox_content.template.php';
3707 3707
         EEH_Template::display_template($template, $this->_template_args);
3708 3708
     }
3709 3709
 
@@ -3722,7 +3722,7 @@  discard block
 block discarded – undo
3722 3722
         $this->_template_args['attendee']      = $this->_cpt_model_obj;
3723 3723
         $this->_template_args['registrations'] = $this->_cpt_model_obj->get_many_related('Registration');
3724 3724
         $template                              =
3725
-            REG_TEMPLATE_PATH . 'attendee_registrations_main_meta_box.template.php';
3725
+            REG_TEMPLATE_PATH.'attendee_registrations_main_meta_box.template.php';
3726 3726
         EEH_Template::display_template($template, $this->_template_args);
3727 3727
     }
3728 3728
 
@@ -3737,7 +3737,7 @@  discard block
 block discarded – undo
3737 3737
     public function after_title_form_fields($post)
3738 3738
     {
3739 3739
         if ($post->post_type == 'espresso_attendees') {
3740
-            $template                  = REG_TEMPLATE_PATH . 'attendee_details_after_title_form_fields.template.php';
3740
+            $template                  = REG_TEMPLATE_PATH.'attendee_details_after_title_form_fields.template.php';
3741 3741
             $template_args['attendee'] = $this->_cpt_model_obj;
3742 3742
             EEH_Template::display_template($template, $template_args);
3743 3743
         }
Please login to merge, or discard this patch.
widgets/upcoming_events/EEW_Upcoming_Events.widget.php 1 patch
Spacing   +80 added lines, -80 removed lines patch added patch discarded remove patch
@@ -31,8 +31,8 @@  discard block
 block discarded – undo
31 31
 	 */
32 32
 	public function __construct() {
33 33
 		parent::__construct(
34
-			__( 'Event Espresso Upcoming Events', 'event_espresso' ),
35
-			 array( 'description' => __( 'A widget to display your upcoming events.', 'event_espresso' ))
34
+			__('Event Espresso Upcoming Events', 'event_espresso'),
35
+			 array('description' => __('A widget to display your upcoming events.', 'event_espresso'))
36 36
 		);
37 37
 	}
38 38
 
@@ -45,9 +45,9 @@  discard block
 block discarded – undo
45 45
 	 * @param array $instance Previously saved values from database.
46 46
 	 * @return string|void
47 47
 	 */
48
-	public function form( $instance ) {
48
+	public function form($instance) {
49 49
 
50
-		EE_Registry::instance()->load_class( 'Question_Option', array(), FALSE, FALSE, TRUE );
50
+		EE_Registry::instance()->load_class('Question_Option', array(), FALSE, FALSE, TRUE);
51 51
 		// Set up some default widget settings.
52 52
 		$defaults = array(
53 53
 			'title' => __('Upcoming Events', 'event_espresso'),
@@ -63,16 +63,16 @@  discard block
 block discarded – undo
63 63
 			'image_size' => 'medium'
64 64
 		);
65 65
 
66
-		$instance = wp_parse_args( (array) $instance, $defaults );
66
+		$instance = wp_parse_args((array) $instance, $defaults);
67 67
 		// don't add HTML labels for EE_Form_Fields generated inputs
68
-		add_filter( 'FHEE__EEH_Form_Fields__label_html', '__return_empty_string' );
68
+		add_filter('FHEE__EEH_Form_Fields__label_html', '__return_empty_string');
69 69
 		$yes_no_values = array(
70
-			EE_Question_Option::new_instance( array( 'QSO_value' => FALSE, 'QSO_desc' => __('No', 'event_espresso'))),
71
-			EE_Question_Option::new_instance( array( 'QSO_value' => TRUE, 'QSO_desc' => __('Yes', 'event_espresso')))
70
+			EE_Question_Option::new_instance(array('QSO_value' => FALSE, 'QSO_desc' => __('No', 'event_espresso'))),
71
+			EE_Question_Option::new_instance(array('QSO_value' => TRUE, 'QSO_desc' => __('Yes', 'event_espresso')))
72 72
 		);
73 73
 		$sort_values = array(
74
-			EE_Question_Option::new_instance( array( 'QSO_value' => 'ASC', 'QSO_desc' => __('ASC', 'event_espresso'))),
75
-			EE_Question_Option::new_instance( array( 'QSO_value' => 'DESC', 'QSO_desc' => __('DESC', 'event_espresso')))
74
+			EE_Question_Option::new_instance(array('QSO_value' => 'ASC', 'QSO_desc' => __('ASC', 'event_espresso'))),
75
+			EE_Question_Option::new_instance(array('QSO_value' => 'DESC', 'QSO_desc' => __('DESC', 'event_espresso')))
76 76
 		);
77 77
 
78 78
 	?>
@@ -83,7 +83,7 @@  discard block
 block discarded – undo
83 83
 			<label for="<?php echo $this->get_field_id('title'); ?>">
84 84
 				<?php _e('Title:', 'event_espresso'); ?>
85 85
 			</label>
86
-			<input id="<?php echo $this->get_field_id('title'); ?>" class="widefat" name="<?php echo $this->get_field_name('title'); ?>" value="<?php echo esc_attr( $instance['title'] ); ?>" type="text" />
86
+			<input id="<?php echo $this->get_field_id('title'); ?>" class="widefat" name="<?php echo $this->get_field_name('title'); ?>" value="<?php echo esc_attr($instance['title']); ?>" type="text" />
87 87
 		</p>
88 88
 		<p>
89 89
 			<label for="<?php echo $this->get_field_id('category_name'); ?>">
@@ -92,16 +92,16 @@  discard block
 block discarded – undo
92 92
 			<?php
93 93
 			$event_categories = array();
94 94
 			/** @type EEM_Term $EEM_Term */
95
-			$EEM_Term = EE_Registry::instance()->load_model( 'Term' );
96
-			$categories = $EEM_Term->get_all_ee_categories( TRUE );
97
-			if ( $categories ) {
98
-				foreach ( $categories as $category ) {
99
-					if ( $category instanceof EE_Term ) {
100
-						$event_categories[] = EE_Question_Option::new_instance( array( 'QSO_value' => $category->get( 'slug' ), 'QSO_desc' => $category->get( 'name' )));
95
+			$EEM_Term = EE_Registry::instance()->load_model('Term');
96
+			$categories = $EEM_Term->get_all_ee_categories(TRUE);
97
+			if ($categories) {
98
+				foreach ($categories as $category) {
99
+					if ($category instanceof EE_Term) {
100
+						$event_categories[] = EE_Question_Option::new_instance(array('QSO_value' => $category->get('slug'), 'QSO_desc' => $category->get('name')));
101 101
 					}
102 102
 				}
103 103
 			}
104
-			array_unshift( $event_categories, EE_Question_Option::new_instance( array( 'QSO_value' => '', 'QSO_desc' => __(' - display all - ', 'event_espresso'))));
104
+			array_unshift($event_categories, EE_Question_Option::new_instance(array('QSO_value' => '', 'QSO_desc' => __(' - display all - ', 'event_espresso'))));
105 105
 			echo EEH_Form_Fields::select(
106 106
 				 __('Event Category:', 'event_espresso'),
107 107
 				$instance['category_name'],
@@ -126,9 +126,9 @@  discard block
 block discarded – undo
126 126
 				 __('Show Expired Events:', 'event_espresso'),
127 127
 				$instance['show_expired'],
128 128
 				array(
129
-					EE_Question_Option::new_instance( array( 'QSO_value' => 0, 'QSO_desc' => __('No', 'event_espresso'))), 
130
-					EE_Question_Option::new_instance( array( 'QSO_value' => 1, 'QSO_desc' => __('Yes', 'event_espresso'))), 
131
-					EE_Question_Option::new_instance( array( 'QSO_value' => 2, 'QSO_desc' => __('Show Only Expired', 'event_espresso'))), 
129
+					EE_Question_Option::new_instance(array('QSO_value' => 0, 'QSO_desc' => __('No', 'event_espresso'))), 
130
+					EE_Question_Option::new_instance(array('QSO_value' => 1, 'QSO_desc' => __('Yes', 'event_espresso'))), 
131
+					EE_Question_Option::new_instance(array('QSO_value' => 2, 'QSO_desc' => __('Show Only Expired', 'event_espresso'))), 
132 132
 				),
133 133
 				$this->get_field_name('show_expired'),
134 134
 				$this->get_field_id('show_expired')
@@ -156,16 +156,16 @@  discard block
 block discarded – undo
156 156
 			<?php
157 157
 			$image_sizes = array();
158 158
 			$sizes = get_intermediate_image_sizes();
159
-			if ( $sizes ) {
159
+			if ($sizes) {
160 160
 				// loop thru images and create option objects out of them
161
-				foreach ( $sizes as $image_size ) {
162
-					$image_size = trim( $image_size );
161
+				foreach ($sizes as $image_size) {
162
+					$image_size = trim($image_size);
163 163
 					// no big images plz
164
-					if ( ! in_array( $image_size, array( 'large', 'post-thumbnail' ))) {
165
-						$image_sizes[] = EE_Question_Option::new_instance( array( 'QSO_value' => $image_size, 'QSO_desc' => $image_size ));
164
+					if ( ! in_array($image_size, array('large', 'post-thumbnail'))) {
165
+						$image_sizes[] = EE_Question_Option::new_instance(array('QSO_value' => $image_size, 'QSO_desc' => $image_size));
166 166
 					}
167 167
 				}
168
-				$image_sizes[] = EE_Question_Option::new_instance( array( 'QSO_value' => 'none', 'QSO_desc' =>  __('don\'t show images', 'event_espresso') ));
168
+				$image_sizes[] = EE_Question_Option::new_instance(array('QSO_value' => 'none', 'QSO_desc' =>  __('don\'t show images', 'event_espresso')));
169 169
 			}
170 170
 			echo EEH_Form_Fields::select(
171 171
 				 __('Image Size:', 'event_espresso'),
@@ -223,7 +223,7 @@  discard block
 block discarded – undo
223 223
 			<label for="<?php echo $this->get_field_id('date_limit'); ?>">
224 224
 				<?php _e('Number of Dates to Display:', 'event_espresso'); ?>
225 225
 			</label>
226
-			<input id="<?php echo $this->get_field_id('date_limit'); ?>" name="<?php echo $this->get_field_name('date_limit'); ?>" value="<?php echo esc_attr( $instance['date_limit'] ); ?>" size="3" type="text" />
226
+			<input id="<?php echo $this->get_field_id('date_limit'); ?>" name="<?php echo $this->get_field_name('date_limit'); ?>" value="<?php echo esc_attr($instance['date_limit']); ?>" size="3" type="text" />
227 227
 		</p>
228 228
 		<p>
229 229
 			<label for="<?php echo $this->get_field_id('date_range'); ?>">
@@ -255,9 +255,9 @@  discard block
 block discarded – undo
255 255
 	 *
256 256
 	 * @return array Updated safe values to be saved.
257 257
 	 */
258
-	public function update( $new_instance, $old_instance ) {
258
+	public function update($new_instance, $old_instance) {
259 259
 		$instance = $old_instance;
260
-		$instance['title'] = ! empty( $new_instance['title'] ) ? strip_tags( $new_instance['title'] ) : '';
260
+		$instance['title'] = ! empty($new_instance['title']) ? strip_tags($new_instance['title']) : '';
261 261
 		$instance['category_name'] = $new_instance['category_name'];
262 262
 		$instance['show_expired'] = $new_instance['show_expired'];
263 263
 		$instance['limit'] = $new_instance['limit'];
@@ -281,18 +281,18 @@  discard block
 block discarded – undo
281 281
 	 * @param array $args     Widget arguments.
282 282
 	 * @param array $instance Saved values from database.
283 283
 	 */
284
-	public function widget( $args, $instance ) {
284
+	public function widget($args, $instance) {
285 285
 
286 286
 		global $post;
287 287
 		// make sure there is some kinda post object
288
-		if ( $post instanceof WP_Post ) {
288
+		if ($post instanceof WP_Post) {
289 289
 			$before_widget = '';
290 290
 			$before_title = '';
291 291
 			$after_title = '';
292 292
 			$after_widget = '';
293 293
 			// but NOT an events archives page, cuz that would be like two event lists on the same page
294
-			$show_everywhere = isset( $instance['show_everywhere'] ) ? (bool) absint( $instance['show_everywhere'] ) : TRUE;
295
-			if ( $show_everywhere || ! ( $post->post_type == 'espresso_events' && is_archive() )) {
294
+			$show_everywhere = isset($instance['show_everywhere']) ? (bool) absint($instance['show_everywhere']) : TRUE;
295
+			if ($show_everywhere || ! ($post->post_type == 'espresso_events' && is_archive())) {
296 296
 				// let's use some of the event helper functions'
297 297
 				// make separate vars out of attributes
298 298
 
@@ -311,88 +311,88 @@  discard block
 block discarded – undo
311 311
 				// Before widget (defined by themes).
312 312
 				echo $before_widget;
313 313
 				// Display the widget title if one was input (before and after defined by themes).
314
-				if ( ! empty( $title )) {
315
-					echo $before_title . $title . $after_title;
314
+				if ( ! empty($title)) {
315
+					echo $before_title.$title.$after_title;
316 316
 				}
317 317
 				// grab widget settings
318
-				$category = isset( $instance['category_name'] ) && ! empty( $instance['category_name'] ) ? $instance['category_name'] : FALSE;
319
-				$show_expired = isset( $instance['show_expired'] ) ? absint( $instance['show_expired'] ) : 0;
320
-				$image_size = isset( $instance['image_size'] ) && ! empty( $instance['image_size'] ) ? $instance['image_size'] : 'medium';
321
-				$show_desc = isset( $instance['show_desc'] ) ? (bool) absint( $instance['show_desc'] ) : TRUE;
322
-				$show_dates = isset( $instance['show_dates'] ) ? (bool) absint( $instance['show_dates'] ) : TRUE;
323
-				$date_limit = isset( $instance['date_limit'] ) && ! empty( $instance['date_limit'] ) ? $instance['date_limit'] : NULL;
324
-				$date_range = isset( $instance['date_range'] ) && ! empty( $instance['date_range'] ) ? $instance['date_range'] : FALSE;
318
+				$category = isset($instance['category_name']) && ! empty($instance['category_name']) ? $instance['category_name'] : FALSE;
319
+				$show_expired = isset($instance['show_expired']) ? absint($instance['show_expired']) : 0;
320
+				$image_size = isset($instance['image_size']) && ! empty($instance['image_size']) ? $instance['image_size'] : 'medium';
321
+				$show_desc = isset($instance['show_desc']) ? (bool) absint($instance['show_desc']) : TRUE;
322
+				$show_dates = isset($instance['show_dates']) ? (bool) absint($instance['show_dates']) : TRUE;
323
+				$date_limit = isset($instance['date_limit']) && ! empty($instance['date_limit']) ? $instance['date_limit'] : NULL;
324
+				$date_range = isset($instance['date_range']) && ! empty($instance['date_range']) ? $instance['date_range'] : FALSE;
325 325
 				// start to build our where clause
326 326
 				$where = array(
327 327
 //					'Datetime.DTT_is_primary' => 1,
328
-					'status' => array( 'IN', array( 'publish', 'sold_out' ) )
328
+					'status' => array('IN', array('publish', 'sold_out'))
329 329
 				);
330 330
 				// add category
331
-				if ( $category ) {
331
+				if ($category) {
332 332
 					$where['Term_Taxonomy.taxonomy'] = 'espresso_event_categories';
333 333
 					$where['Term_Taxonomy.Term.slug'] = $category;
334 334
 				}
335 335
 				// if NOT expired then we want events that start today or in the future
336 336
 				// if NOT show expired then we want events that start today or in the future 
337
-				if ( $show_expired == 0 ) { 
338
-				 	$where['Datetime.DTT_EVT_end'] = array( '>=', EEM_Datetime::instance()->current_time_for_query( 'DTT_EVT_end' ) ); 
337
+				if ($show_expired == 0) { 
338
+				 	$where['Datetime.DTT_EVT_end'] = array('>=', EEM_Datetime::instance()->current_time_for_query('DTT_EVT_end')); 
339 339
 				} 
340 340
 				// if show ONLY expired we want events that ended prior to today 
341
-				if ( $show_expired == 2 ) { 
342
-					$where['Datetime.DTT_EVT_end'] = array( '<=', EEM_Datetime::instance()->current_time_for_query( 'DTT_EVT_start' ) ); 
341
+				if ($show_expired == 2) { 
342
+					$where['Datetime.DTT_EVT_end'] = array('<=', EEM_Datetime::instance()->current_time_for_query('DTT_EVT_start')); 
343 343
 				}
344 344
 				// allow $where to be filtered
345
-				$where = apply_filters( 'FHEE__EEW_Upcoming_Events__widget__where', $where, $category, $show_expired );
345
+				$where = apply_filters('FHEE__EEW_Upcoming_Events__widget__where', $where, $category, $show_expired);
346 346
 				// run the query
347
-				$events = EE_Registry::instance()->load_model( 'Event' )->get_all( array(
347
+				$events = EE_Registry::instance()->load_model('Event')->get_all(array(
348 348
 					$where,
349
-					'limit' => $instance['limit'] > 0 ? '0,' . $instance['limit'] : '0,10',
349
+					'limit' => $instance['limit'] > 0 ? '0,'.$instance['limit'] : '0,10',
350 350
 					'order_by' => 'Datetime.DTT_EVT_start',
351 351
 					'order' => isset($instance['sort']) ? $instance['sort'] : 'ASC',
352 352
 					'group_by' => 'EVT_ID'
353 353
 				));
354 354
 
355
-				if ( ! empty( $events )) {
355
+				if ( ! empty($events)) {
356 356
 					echo '<ul class="ee-upcoming-events-widget-ul">';
357
-					foreach ( $events as $event ) {
358
-						if ( $event instanceof EE_Event && ( !is_single() || $post->ID != $event->ID() ) ) {
357
+					foreach ($events as $event) {
358
+						if ($event instanceof EE_Event && ( ! is_single() || $post->ID != $event->ID())) {
359 359
 							//printr( $event, '$event  <br /><span style="font-size:10px;font-weight:normal;">' . __FILE__ . '<br />line no: ' . __LINE__ . '</span>', 'auto' );
360
-							echo '<li id="ee-upcoming-events-widget-li-' . $event->ID() . '" class="ee-upcoming-events-widget-li">';
360
+							echo '<li id="ee-upcoming-events-widget-li-'.$event->ID().'" class="ee-upcoming-events-widget-li">';
361 361
 							// how big is the event name ?
362
-							$name_length = strlen( $event->name() );
363
-							switch( $name_length ) {
362
+							$name_length = strlen($event->name());
363
+							switch ($name_length) {
364 364
 								case $name_length > 70 :
365
-									$len_class =  ' three-line';
365
+									$len_class = ' three-line';
366 366
 									break;
367 367
 								case $name_length > 35 :
368
-									$len_class =  ' two-line';
368
+									$len_class = ' two-line';
369 369
 									break;
370 370
 								default :
371
-									$len_class =  ' one-line';
371
+									$len_class = ' one-line';
372 372
 							}
373
-							$event_url = apply_filters( 'FHEE_EEW_Upcoming_Events__widget__event_url', $event->get_permalink(), $event );
374
-							echo '<h5 class="ee-upcoming-events-widget-title-h5"><a class="ee-widget-event-name-a' . $len_class . '" href="' . $event_url . '">' . $event->name() . '</a></h5>';
375
-							if ( post_password_required( $event->ID() ) ) {
376
-								$pswd_form = apply_filters( 'FHEE_EEW_Upcoming_Events__widget__password_form', get_the_password_form( $event->ID() ), $event );
373
+							$event_url = apply_filters('FHEE_EEW_Upcoming_Events__widget__event_url', $event->get_permalink(), $event);
374
+							echo '<h5 class="ee-upcoming-events-widget-title-h5"><a class="ee-widget-event-name-a'.$len_class.'" href="'.$event_url.'">'.$event->name().'</a></h5>';
375
+							if (post_password_required($event->ID())) {
376
+								$pswd_form = apply_filters('FHEE_EEW_Upcoming_Events__widget__password_form', get_the_password_form($event->ID()), $event);
377 377
 								echo $pswd_form;
378 378
 							} else {
379
-								if ( has_post_thumbnail( $event->ID() ) && $image_size != 'none' ) {
380
-									echo '<div class="ee-upcoming-events-widget-img-dv"><a class="ee-upcoming-events-widget-img" href="' . $event_url . '">' . get_the_post_thumbnail( $event->ID(), $image_size ) . '</a></div>';
379
+								if (has_post_thumbnail($event->ID()) && $image_size != 'none') {
380
+									echo '<div class="ee-upcoming-events-widget-img-dv"><a class="ee-upcoming-events-widget-img" href="'.$event_url.'">'.get_the_post_thumbnail($event->ID(), $image_size).'</a></div>';
381 381
 								}
382
-								$desc = $event->short_description( 25 );
383
-								if ( $show_dates ) {
384
-									$date_format = apply_filters( 'FHEE__espresso_event_date_range__date_format', get_option( 'date_format' ));
385
-									$time_format = apply_filters( 'FHEE__espresso_event_date_range__time_format', get_option( 'time_format' ));
386
-									$single_date_format = apply_filters( 'FHEE__espresso_event_date_range__single_date_format', get_option( 'date_format' ));
387
-									$single_time_format = apply_filters( 'FHEE__espresso_event_date_range__single_time_format', get_option( 'time_format' ));
388
-									if ( $date_range == TRUE ) {
389
-										echo espresso_event_date_range( $date_format, $time_format, $single_date_format, $single_time_format, $event->ID() );
390
-									}else{
391
-										echo espresso_list_of_event_dates( $event->ID(), $date_format, $time_format, FALSE, NULL, TRUE, TRUE, $date_limit );
382
+								$desc = $event->short_description(25);
383
+								if ($show_dates) {
384
+									$date_format = apply_filters('FHEE__espresso_event_date_range__date_format', get_option('date_format'));
385
+									$time_format = apply_filters('FHEE__espresso_event_date_range__time_format', get_option('time_format'));
386
+									$single_date_format = apply_filters('FHEE__espresso_event_date_range__single_date_format', get_option('date_format'));
387
+									$single_time_format = apply_filters('FHEE__espresso_event_date_range__single_time_format', get_option('time_format'));
388
+									if ($date_range == TRUE) {
389
+										echo espresso_event_date_range($date_format, $time_format, $single_date_format, $single_time_format, $event->ID());
390
+									} else {
391
+										echo espresso_list_of_event_dates($event->ID(), $date_format, $time_format, FALSE, NULL, TRUE, TRUE, $date_limit);
392 392
 									}
393 393
 								}
394
-								if ( $show_desc && $desc ) {
395
-									echo '<p style="margin-top: .5em">' . $desc . '</p>';
394
+								if ($show_desc && $desc) {
395
+									echo '<p style="margin-top: .5em">'.$desc.'</p>';
396 396
 								}
397 397
 							}
398 398
 							echo '</li>';
@@ -416,7 +416,7 @@  discard block
 block discarded – undo
416 416
 	 * @return string
417 417
 	 */
418 418
 	public function make_the_title_a_link($title) {
419
-	    return '<a href="' . EEH_Event_View::event_archive_url() . '">' . $title . '</a>';
419
+	    return '<a href="'.EEH_Event_View::event_archive_url().'">'.$title.'</a>';
420 420
 	}
421 421
 
422 422
 }
Please login to merge, or discard this patch.
core/EE_Error.core.php 1 patch
Indentation   +1030 added lines, -1030 removed lines patch added patch discarded remove patch
@@ -11,8 +11,8 @@  discard block
 block discarded – undo
11 11
 // if you're a dev and want to receive all errors via email
12 12
 // add this to your wp-config.php: define( 'EE_ERROR_EMAILS', TRUE );
13 13
 if (defined('WP_DEBUG') && WP_DEBUG === true && defined('EE_ERROR_EMAILS') && EE_ERROR_EMAILS === true) {
14
-    set_error_handler(array('EE_Error', 'error_handler'));
15
-    register_shutdown_function(array('EE_Error', 'fatal_error_handler'));
14
+	set_error_handler(array('EE_Error', 'error_handler'));
15
+	register_shutdown_function(array('EE_Error', 'fatal_error_handler'));
16 16
 }
17 17
 
18 18
 
@@ -27,256 +27,256 @@  discard block
 block discarded – undo
27 27
 class EE_Error extends Exception
28 28
 {
29 29
 
30
-    const OPTIONS_KEY_NOTICES = 'ee_notices';
31
-
32
-
33
-    /**
34
-     * name of the file to log exceptions to
35
-     *
36
-     * @var string
37
-     */
38
-    private static $_exception_log_file = 'espresso_error_log.txt';
39
-
40
-    /**
41
-     *    stores details for all exception
42
-     *
43
-     * @var array
44
-     */
45
-    private static $_all_exceptions = array();
46
-
47
-    /**
48
-     *    tracks number of errors
49
-     *
50
-     * @var int
51
-     */
52
-    private static $_error_count = 0;
53
-
54
-    /**
55
-     * @var array $_espresso_notices
56
-     */
57
-    private static $_espresso_notices = array('success' => false, 'errors' => false, 'attention' => false);
58
-
59
-
60
-
61
-    /**
62
-     * @override default exception handling
63
-     * @param string         $message
64
-     * @param int            $code
65
-     * @param Exception|null $previous
66
-     */
67
-    public function __construct($message, $code = 0, Exception $previous = null)
68
-    {
69
-        if (version_compare(PHP_VERSION, '5.3.0', '<')) {
70
-            parent::__construct($message, $code);
71
-        } else {
72
-            parent::__construct($message, $code, $previous);
73
-        }
74
-    }
75
-
76
-
77
-
78
-    /**
79
-     *    error_handler
80
-     *
81
-     * @param $code
82
-     * @param $message
83
-     * @param $file
84
-     * @param $line
85
-     * @return void
86
-     */
87
-    public static function error_handler($code, $message, $file, $line)
88
-    {
89
-        $type = EE_Error::error_type($code);
90
-        $site = site_url();
91
-        switch ($site) {
92
-            case 'http://ee4.eventespresso.com/' :
93
-            case 'http://ee4decaf.eventespresso.com/' :
94
-            case 'http://ee4hf.eventespresso.com/' :
95
-            case 'http://ee4a.eventespresso.com/' :
96
-            case 'http://ee4ad.eventespresso.com/' :
97
-            case 'http://ee4b.eventespresso.com/' :
98
-            case 'http://ee4bd.eventespresso.com/' :
99
-            case 'http://ee4d.eventespresso.com/' :
100
-            case 'http://ee4dd.eventespresso.com/' :
101
-                $to = '[email protected]';
102
-                break;
103
-            default :
104
-                $to = get_option('admin_email');
105
-        }
106
-        $subject = $type . ' ' . $message . ' in ' . EVENT_ESPRESSO_VERSION . ' on ' . site_url();
107
-        $msg = EE_Error::_format_error($type, $message, $file, $line);
108
-        if (function_exists('wp_mail')) {
109
-            add_filter('wp_mail_content_type', array('EE_Error', 'set_content_type'));
110
-            wp_mail($to, $subject, $msg);
111
-        }
112
-        echo '<div id="message" class="espresso-notices error"><p>';
113
-        echo $type . ': ' . $message . '<br />' . $file . ' line ' . $line;
114
-        echo '<br /></p></div>';
115
-    }
116
-
117
-
118
-
119
-    /**
120
-     * error_type
121
-     * http://www.php.net/manual/en/errorfunc.constants.php#109430
122
-     *
123
-     * @param $code
124
-     * @return string
125
-     */
126
-    public static function error_type($code)
127
-    {
128
-        switch ($code) {
129
-            case E_ERROR: // 1 //
130
-                return 'E_ERROR';
131
-            case E_WARNING: // 2 //
132
-                return 'E_WARNING';
133
-            case E_PARSE: // 4 //
134
-                return 'E_PARSE';
135
-            case E_NOTICE: // 8 //
136
-                return 'E_NOTICE';
137
-            case E_CORE_ERROR: // 16 //
138
-                return 'E_CORE_ERROR';
139
-            case E_CORE_WARNING: // 32 //
140
-                return 'E_CORE_WARNING';
141
-            case E_COMPILE_ERROR: // 64 //
142
-                return 'E_COMPILE_ERROR';
143
-            case E_COMPILE_WARNING: // 128 //
144
-                return 'E_COMPILE_WARNING';
145
-            case E_USER_ERROR: // 256 //
146
-                return 'E_USER_ERROR';
147
-            case E_USER_WARNING: // 512 //
148
-                return 'E_USER_WARNING';
149
-            case E_USER_NOTICE: // 1024 //
150
-                return 'E_USER_NOTICE';
151
-            case E_STRICT: // 2048 //
152
-                return 'E_STRICT';
153
-            case E_RECOVERABLE_ERROR: // 4096 //
154
-                return 'E_RECOVERABLE_ERROR';
155
-            case E_DEPRECATED: // 8192 //
156
-                return 'E_DEPRECATED';
157
-            case E_USER_DEPRECATED: // 16384 //
158
-                return 'E_USER_DEPRECATED';
159
-            case E_ALL: // 16384 //
160
-                return 'E_ALL';
161
-        }
162
-        return '';
163
-    }
164
-
165
-
166
-
167
-    /**
168
-     *    fatal_error_handler
169
-     *
170
-     * @return void
171
-     */
172
-    public static function fatal_error_handler()
173
-    {
174
-        $last_error = error_get_last();
175
-        if ($last_error['type'] === E_ERROR) {
176
-            EE_Error::error_handler(E_ERROR, $last_error['message'], $last_error['file'], $last_error['line']);
177
-        }
178
-    }
179
-
180
-
181
-
182
-    /**
183
-     * _format_error
184
-     *
185
-     * @param $code
186
-     * @param $message
187
-     * @param $file
188
-     * @param $line
189
-     * @return string
190
-     */
191
-    private static function _format_error($code, $message, $file, $line)
192
-    {
193
-        $html = "<table cellpadding='5'><thead bgcolor='#f8f8f8'><th>Item</th><th align='left'>Details</th></thead><tbody>";
194
-        $html .= "<tr valign='top'><td><b>Code</b></td><td>$code</td></tr>";
195
-        $html .= "<tr valign='top'><td><b>Error</b></td><td>$message</td></tr>";
196
-        $html .= "<tr valign='top'><td><b>File</b></td><td>$file</td></tr>";
197
-        $html .= "<tr valign='top'><td><b>Line</b></td><td>$line</td></tr>";
198
-        $html .= '</tbody></table>';
199
-        return $html;
200
-    }
201
-
202
-
203
-
204
-    /**
205
-     * set_content_type
206
-     *
207
-     * @param $content_type
208
-     * @return string
209
-     */
210
-    public static function set_content_type($content_type)
211
-    {
212
-        return 'text/html';
213
-    }
214
-
215
-
216
-
217
-    /**
218
-     * @return void
219
-     * @throws EE_Error
220
-     * @throws ReflectionException
221
-     */
222
-    public function get_error()
223
-    {
224
-        if (apply_filters('FHEE__EE_Error__get_error__show_normal_exceptions', false)) {
225
-            throw $this;
226
-        }
227
-        // get separate user and developer messages if they exist
228
-        $msg = explode('||', $this->getMessage());
229
-        $user_msg = $msg[0];
230
-        $dev_msg = isset($msg[1]) ? $msg[1] : $msg[0];
231
-        $msg = WP_DEBUG ? $dev_msg : $user_msg;
232
-        // add details to _all_exceptions array
233
-        $x_time = time();
234
-        self::$_all_exceptions[$x_time]['name'] = get_class($this);
235
-        self::$_all_exceptions[$x_time]['file'] = $this->getFile();
236
-        self::$_all_exceptions[$x_time]['line'] = $this->getLine();
237
-        self::$_all_exceptions[$x_time]['msg'] = $msg;
238
-        self::$_all_exceptions[$x_time]['code'] = $this->getCode();
239
-        self::$_all_exceptions[$x_time]['trace'] = $this->getTrace();
240
-        self::$_all_exceptions[$x_time]['string'] = $this->getTraceAsString();
241
-        self::$_error_count++;
242
-        //add_action( 'shutdown', array( $this, 'display_errors' ));
243
-        $this->display_errors();
244
-    }
245
-
246
-
247
-
248
-    /**
249
-     * @param bool   $check_stored
250
-     * @param string $type_to_check
251
-     * @return bool
252
-     */
253
-    public static function has_error($check_stored = false, $type_to_check = 'errors')
254
-    {
255
-        $has_error = isset(self::$_espresso_notices[$type_to_check])
256
-                     && ! empty(self::$_espresso_notices[$type_to_check])
257
-            ? true
258
-            : false;
259
-        if ($check_stored && ! $has_error) {
260
-            $notices = (array)get_option(EE_Error::OPTIONS_KEY_NOTICES, array());
261
-            foreach ($notices as $type => $notice) {
262
-                if ($type === $type_to_check && $notice) {
263
-                    return true;
264
-                }
265
-            }
266
-        }
267
-        return $has_error;
268
-    }
269
-
270
-
271
-
272
-    /**
273
-     * @echo string
274
-     * @throws \ReflectionException
275
-     */
276
-    public function display_errors()
277
-    {
278
-        $trace_details = '';
279
-        $output = '
30
+	const OPTIONS_KEY_NOTICES = 'ee_notices';
31
+
32
+
33
+	/**
34
+	 * name of the file to log exceptions to
35
+	 *
36
+	 * @var string
37
+	 */
38
+	private static $_exception_log_file = 'espresso_error_log.txt';
39
+
40
+	/**
41
+	 *    stores details for all exception
42
+	 *
43
+	 * @var array
44
+	 */
45
+	private static $_all_exceptions = array();
46
+
47
+	/**
48
+	 *    tracks number of errors
49
+	 *
50
+	 * @var int
51
+	 */
52
+	private static $_error_count = 0;
53
+
54
+	/**
55
+	 * @var array $_espresso_notices
56
+	 */
57
+	private static $_espresso_notices = array('success' => false, 'errors' => false, 'attention' => false);
58
+
59
+
60
+
61
+	/**
62
+	 * @override default exception handling
63
+	 * @param string         $message
64
+	 * @param int            $code
65
+	 * @param Exception|null $previous
66
+	 */
67
+	public function __construct($message, $code = 0, Exception $previous = null)
68
+	{
69
+		if (version_compare(PHP_VERSION, '5.3.0', '<')) {
70
+			parent::__construct($message, $code);
71
+		} else {
72
+			parent::__construct($message, $code, $previous);
73
+		}
74
+	}
75
+
76
+
77
+
78
+	/**
79
+	 *    error_handler
80
+	 *
81
+	 * @param $code
82
+	 * @param $message
83
+	 * @param $file
84
+	 * @param $line
85
+	 * @return void
86
+	 */
87
+	public static function error_handler($code, $message, $file, $line)
88
+	{
89
+		$type = EE_Error::error_type($code);
90
+		$site = site_url();
91
+		switch ($site) {
92
+			case 'http://ee4.eventespresso.com/' :
93
+			case 'http://ee4decaf.eventespresso.com/' :
94
+			case 'http://ee4hf.eventespresso.com/' :
95
+			case 'http://ee4a.eventespresso.com/' :
96
+			case 'http://ee4ad.eventespresso.com/' :
97
+			case 'http://ee4b.eventespresso.com/' :
98
+			case 'http://ee4bd.eventespresso.com/' :
99
+			case 'http://ee4d.eventespresso.com/' :
100
+			case 'http://ee4dd.eventespresso.com/' :
101
+				$to = '[email protected]';
102
+				break;
103
+			default :
104
+				$to = get_option('admin_email');
105
+		}
106
+		$subject = $type . ' ' . $message . ' in ' . EVENT_ESPRESSO_VERSION . ' on ' . site_url();
107
+		$msg = EE_Error::_format_error($type, $message, $file, $line);
108
+		if (function_exists('wp_mail')) {
109
+			add_filter('wp_mail_content_type', array('EE_Error', 'set_content_type'));
110
+			wp_mail($to, $subject, $msg);
111
+		}
112
+		echo '<div id="message" class="espresso-notices error"><p>';
113
+		echo $type . ': ' . $message . '<br />' . $file . ' line ' . $line;
114
+		echo '<br /></p></div>';
115
+	}
116
+
117
+
118
+
119
+	/**
120
+	 * error_type
121
+	 * http://www.php.net/manual/en/errorfunc.constants.php#109430
122
+	 *
123
+	 * @param $code
124
+	 * @return string
125
+	 */
126
+	public static function error_type($code)
127
+	{
128
+		switch ($code) {
129
+			case E_ERROR: // 1 //
130
+				return 'E_ERROR';
131
+			case E_WARNING: // 2 //
132
+				return 'E_WARNING';
133
+			case E_PARSE: // 4 //
134
+				return 'E_PARSE';
135
+			case E_NOTICE: // 8 //
136
+				return 'E_NOTICE';
137
+			case E_CORE_ERROR: // 16 //
138
+				return 'E_CORE_ERROR';
139
+			case E_CORE_WARNING: // 32 //
140
+				return 'E_CORE_WARNING';
141
+			case E_COMPILE_ERROR: // 64 //
142
+				return 'E_COMPILE_ERROR';
143
+			case E_COMPILE_WARNING: // 128 //
144
+				return 'E_COMPILE_WARNING';
145
+			case E_USER_ERROR: // 256 //
146
+				return 'E_USER_ERROR';
147
+			case E_USER_WARNING: // 512 //
148
+				return 'E_USER_WARNING';
149
+			case E_USER_NOTICE: // 1024 //
150
+				return 'E_USER_NOTICE';
151
+			case E_STRICT: // 2048 //
152
+				return 'E_STRICT';
153
+			case E_RECOVERABLE_ERROR: // 4096 //
154
+				return 'E_RECOVERABLE_ERROR';
155
+			case E_DEPRECATED: // 8192 //
156
+				return 'E_DEPRECATED';
157
+			case E_USER_DEPRECATED: // 16384 //
158
+				return 'E_USER_DEPRECATED';
159
+			case E_ALL: // 16384 //
160
+				return 'E_ALL';
161
+		}
162
+		return '';
163
+	}
164
+
165
+
166
+
167
+	/**
168
+	 *    fatal_error_handler
169
+	 *
170
+	 * @return void
171
+	 */
172
+	public static function fatal_error_handler()
173
+	{
174
+		$last_error = error_get_last();
175
+		if ($last_error['type'] === E_ERROR) {
176
+			EE_Error::error_handler(E_ERROR, $last_error['message'], $last_error['file'], $last_error['line']);
177
+		}
178
+	}
179
+
180
+
181
+
182
+	/**
183
+	 * _format_error
184
+	 *
185
+	 * @param $code
186
+	 * @param $message
187
+	 * @param $file
188
+	 * @param $line
189
+	 * @return string
190
+	 */
191
+	private static function _format_error($code, $message, $file, $line)
192
+	{
193
+		$html = "<table cellpadding='5'><thead bgcolor='#f8f8f8'><th>Item</th><th align='left'>Details</th></thead><tbody>";
194
+		$html .= "<tr valign='top'><td><b>Code</b></td><td>$code</td></tr>";
195
+		$html .= "<tr valign='top'><td><b>Error</b></td><td>$message</td></tr>";
196
+		$html .= "<tr valign='top'><td><b>File</b></td><td>$file</td></tr>";
197
+		$html .= "<tr valign='top'><td><b>Line</b></td><td>$line</td></tr>";
198
+		$html .= '</tbody></table>';
199
+		return $html;
200
+	}
201
+
202
+
203
+
204
+	/**
205
+	 * set_content_type
206
+	 *
207
+	 * @param $content_type
208
+	 * @return string
209
+	 */
210
+	public static function set_content_type($content_type)
211
+	{
212
+		return 'text/html';
213
+	}
214
+
215
+
216
+
217
+	/**
218
+	 * @return void
219
+	 * @throws EE_Error
220
+	 * @throws ReflectionException
221
+	 */
222
+	public function get_error()
223
+	{
224
+		if (apply_filters('FHEE__EE_Error__get_error__show_normal_exceptions', false)) {
225
+			throw $this;
226
+		}
227
+		// get separate user and developer messages if they exist
228
+		$msg = explode('||', $this->getMessage());
229
+		$user_msg = $msg[0];
230
+		$dev_msg = isset($msg[1]) ? $msg[1] : $msg[0];
231
+		$msg = WP_DEBUG ? $dev_msg : $user_msg;
232
+		// add details to _all_exceptions array
233
+		$x_time = time();
234
+		self::$_all_exceptions[$x_time]['name'] = get_class($this);
235
+		self::$_all_exceptions[$x_time]['file'] = $this->getFile();
236
+		self::$_all_exceptions[$x_time]['line'] = $this->getLine();
237
+		self::$_all_exceptions[$x_time]['msg'] = $msg;
238
+		self::$_all_exceptions[$x_time]['code'] = $this->getCode();
239
+		self::$_all_exceptions[$x_time]['trace'] = $this->getTrace();
240
+		self::$_all_exceptions[$x_time]['string'] = $this->getTraceAsString();
241
+		self::$_error_count++;
242
+		//add_action( 'shutdown', array( $this, 'display_errors' ));
243
+		$this->display_errors();
244
+	}
245
+
246
+
247
+
248
+	/**
249
+	 * @param bool   $check_stored
250
+	 * @param string $type_to_check
251
+	 * @return bool
252
+	 */
253
+	public static function has_error($check_stored = false, $type_to_check = 'errors')
254
+	{
255
+		$has_error = isset(self::$_espresso_notices[$type_to_check])
256
+					 && ! empty(self::$_espresso_notices[$type_to_check])
257
+			? true
258
+			: false;
259
+		if ($check_stored && ! $has_error) {
260
+			$notices = (array)get_option(EE_Error::OPTIONS_KEY_NOTICES, array());
261
+			foreach ($notices as $type => $notice) {
262
+				if ($type === $type_to_check && $notice) {
263
+					return true;
264
+				}
265
+			}
266
+		}
267
+		return $has_error;
268
+	}
269
+
270
+
271
+
272
+	/**
273
+	 * @echo string
274
+	 * @throws \ReflectionException
275
+	 */
276
+	public function display_errors()
277
+	{
278
+		$trace_details = '';
279
+		$output = '
280 280
 <style type="text/css">
281 281
 	#ee-error-message {
282 282
 		max-width:90% !important;
@@ -332,21 +332,21 @@  discard block
 block discarded – undo
332 332
 	}
333 333
 </style>
334 334
 <div id="ee-error-message" class="error">';
335
-        if (! WP_DEBUG) {
336
-            $output .= '
335
+		if (! WP_DEBUG) {
336
+			$output .= '
337 337
 	<p>';
338
-        }
339
-        // cycle thru errors
340
-        foreach (self::$_all_exceptions as $time => $ex) {
341
-            $error_code = '';
342
-            // process trace info
343
-            if (empty($ex['trace'])) {
344
-                $trace_details .= __(
345
-                    'Sorry, but no trace information was available for this exception.',
346
-                    'event_espresso'
347
-                );
348
-            } else {
349
-                $trace_details .= '
338
+		}
339
+		// cycle thru errors
340
+		foreach (self::$_all_exceptions as $time => $ex) {
341
+			$error_code = '';
342
+			// process trace info
343
+			if (empty($ex['trace'])) {
344
+				$trace_details .= __(
345
+					'Sorry, but no trace information was available for this exception.',
346
+					'event_espresso'
347
+				);
348
+			} else {
349
+				$trace_details .= '
350 350
 			<div id="ee-trace-details">
351 351
 			<table width="100%" border="0" cellpadding="5" cellspacing="0">
352 352
 				<tr>
@@ -356,43 +356,43 @@  discard block
 block discarded – undo
356 356
 					<th scope="col" align="left">Class</th>
357 357
 					<th scope="col" align="left">Method( arguments )</th>
358 358
 				</tr>';
359
-                $last_on_stack = count($ex['trace']) - 1;
360
-                // reverse array so that stack is in proper chronological order
361
-                $sorted_trace = array_reverse($ex['trace']);
362
-                foreach ($sorted_trace as $nmbr => $trace) {
363
-                    $file = isset($trace['file']) ? $trace['file'] : '';
364
-                    $class = isset($trace['class']) ? $trace['class'] : '';
365
-                    $type = isset($trace['type']) ? $trace['type'] : '';
366
-                    $function = isset($trace['function']) ? $trace['function'] : '';
367
-                    $args = isset($trace['args']) ? $this->_convert_args_to_string($trace['args']) : '';
368
-                    $line = isset($trace['line']) ? $trace['line'] : '';
369
-                    $zebra = ($nmbr % 2) ? ' odd' : '';
370
-                    if (empty($file) && ! empty($class)) {
371
-                        $a = new ReflectionClass($class);
372
-                        $file = $a->getFileName();
373
-                        if (empty($line) && ! empty($function)) {
374
-                            try {
375
-                                //if $function is a closure, this throws an exception
376
-                                $b = new ReflectionMethod($class, $function);
377
-                                $line = $b->getStartLine();
378
-                            } catch (Exception $closure_exception) {
379
-                                $line = 'unknown';
380
-                            }
381
-                        }
382
-                    }
383
-                    if ($nmbr === $last_on_stack) {
384
-                        $file = $ex['file'] !== '' ? $ex['file'] : $file;
385
-                        $line = $ex['line'] !== '' ? $ex['line'] : $line;
386
-                        $error_code = self::generate_error_code($file, $trace['function'], $line);
387
-                    }
388
-                    $nmbr_dsply = ! empty($nmbr) ? $nmbr : '&nbsp;';
389
-                    $line_dsply = ! empty($line) ? $line : '&nbsp;';
390
-                    $file_dsply = ! empty($file) ? $file : '&nbsp;';
391
-                    $class_dsply = ! empty($class) ? $class : '&nbsp;';
392
-                    $type_dsply = ! empty($type) ? $type : '&nbsp;';
393
-                    $function_dsply = ! empty($function) ? $function : '&nbsp;';
394
-                    $args_dsply = ! empty($args) ? '( ' . $args . ' )' : '';
395
-                    $trace_details .= '
359
+				$last_on_stack = count($ex['trace']) - 1;
360
+				// reverse array so that stack is in proper chronological order
361
+				$sorted_trace = array_reverse($ex['trace']);
362
+				foreach ($sorted_trace as $nmbr => $trace) {
363
+					$file = isset($trace['file']) ? $trace['file'] : '';
364
+					$class = isset($trace['class']) ? $trace['class'] : '';
365
+					$type = isset($trace['type']) ? $trace['type'] : '';
366
+					$function = isset($trace['function']) ? $trace['function'] : '';
367
+					$args = isset($trace['args']) ? $this->_convert_args_to_string($trace['args']) : '';
368
+					$line = isset($trace['line']) ? $trace['line'] : '';
369
+					$zebra = ($nmbr % 2) ? ' odd' : '';
370
+					if (empty($file) && ! empty($class)) {
371
+						$a = new ReflectionClass($class);
372
+						$file = $a->getFileName();
373
+						if (empty($line) && ! empty($function)) {
374
+							try {
375
+								//if $function is a closure, this throws an exception
376
+								$b = new ReflectionMethod($class, $function);
377
+								$line = $b->getStartLine();
378
+							} catch (Exception $closure_exception) {
379
+								$line = 'unknown';
380
+							}
381
+						}
382
+					}
383
+					if ($nmbr === $last_on_stack) {
384
+						$file = $ex['file'] !== '' ? $ex['file'] : $file;
385
+						$line = $ex['line'] !== '' ? $ex['line'] : $line;
386
+						$error_code = self::generate_error_code($file, $trace['function'], $line);
387
+					}
388
+					$nmbr_dsply = ! empty($nmbr) ? $nmbr : '&nbsp;';
389
+					$line_dsply = ! empty($line) ? $line : '&nbsp;';
390
+					$file_dsply = ! empty($file) ? $file : '&nbsp;';
391
+					$class_dsply = ! empty($class) ? $class : '&nbsp;';
392
+					$type_dsply = ! empty($type) ? $type : '&nbsp;';
393
+					$function_dsply = ! empty($function) ? $function : '&nbsp;';
394
+					$args_dsply = ! empty($args) ? '( ' . $args . ' )' : '';
395
+					$trace_details .= '
396 396
 					<tr>
397 397
 						<td align="right" class="' . $zebra . '">' . $nmbr_dsply . '</td>
398 398
 						<td align="right" class="' . $zebra . '">' . $line_dsply . '</td>
@@ -400,523 +400,523 @@  discard block
 block discarded – undo
400 400
 						<td align="left" class="' . $zebra . '">' . $class_dsply . '</td>
401 401
 						<td align="left" class="' . $zebra . '">' . $type_dsply . $function_dsply . $args_dsply . '</td>
402 402
 					</tr>';
403
-                }
404
-                $trace_details .= '
403
+				}
404
+				$trace_details .= '
405 405
 			 </table>
406 406
 			</div>';
407
-            }
408
-            $ex['code'] = $ex['code'] ? $ex['code'] : $error_code;
409
-            // add generic non-identifying messages for non-privileged users
410
-            if (! WP_DEBUG) {
411
-                $output .= '<span class="ee-error-user-msg-spn">'
412
-                           . trim($ex['msg'])
413
-                           . '</span> &nbsp; <sup>'
414
-                           . $ex['code']
415
-                           . '</sup><br />';
416
-            } else {
417
-                // or helpful developer messages if debugging is on
418
-                $output .= '
407
+			}
408
+			$ex['code'] = $ex['code'] ? $ex['code'] : $error_code;
409
+			// add generic non-identifying messages for non-privileged users
410
+			if (! WP_DEBUG) {
411
+				$output .= '<span class="ee-error-user-msg-spn">'
412
+						   . trim($ex['msg'])
413
+						   . '</span> &nbsp; <sup>'
414
+						   . $ex['code']
415
+						   . '</sup><br />';
416
+			} else {
417
+				// or helpful developer messages if debugging is on
418
+				$output .= '
419 419
 		<div class="ee-error-dev-msg-dv">
420 420
 			<p class="ee-error-dev-msg-pg">
421 421
 				<strong class="ee-error-dev-msg-str">An '
422
-                           . $ex['name']
423
-                           . ' exception was thrown!</strong>  &nbsp; <span>code: '
424
-                           . $ex['code']
425
-                           . '</span><br />
422
+						   . $ex['name']
423
+						   . ' exception was thrown!</strong>  &nbsp; <span>code: '
424
+						   . $ex['code']
425
+						   . '</span><br />
426 426
 				<span class="big-text">"'
427
-                           . trim($ex['msg'])
428
-                           . '"</span><br/>
427
+						   . trim($ex['msg'])
428
+						   . '"</span><br/>
429 429
 				<a id="display-ee-error-trace-'
430
-                           . self::$_error_count
431
-                           . $time
432
-                           . '" class="display-ee-error-trace-lnk small-text" rel="ee-error-trace-'
433
-                           . self::$_error_count
434
-                           . $time
435
-                           . '">
430
+						   . self::$_error_count
431
+						   . $time
432
+						   . '" class="display-ee-error-trace-lnk small-text" rel="ee-error-trace-'
433
+						   . self::$_error_count
434
+						   . $time
435
+						   . '">
436 436
 					'
437
-                           . __('click to view backtrace and class/method details', 'event_espresso')
438
-                           . '
437
+						   . __('click to view backtrace and class/method details', 'event_espresso')
438
+						   . '
439 439
 				</a><br />
440 440
 				<span class="small-text lt-grey-text">'
441
-                           . $ex['file']
442
-                           . ' &nbsp; ( line no: '
443
-                           . $ex['line']
444
-                           . ' )</span>
441
+						   . $ex['file']
442
+						   . ' &nbsp; ( line no: '
443
+						   . $ex['line']
444
+						   . ' )</span>
445 445
 			</p>
446 446
 			<div id="ee-error-trace-'
447
-                           . self::$_error_count
448
-                           . $time
449
-                           . '-dv" class="ee-error-trace-dv" style="display: none;">
447
+						   . self::$_error_count
448
+						   . $time
449
+						   . '-dv" class="ee-error-trace-dv" style="display: none;">
450 450
 				'
451
-                           . $trace_details;
452
-                if (! empty($class)) {
453
-                    $output .= '
451
+						   . $trace_details;
452
+				if (! empty($class)) {
453
+					$output .= '
454 454
 				<div style="padding:3px; margin:0 0 1em; border:1px solid #666; background:#fff; border-radius:3px;">
455 455
 					<div style="padding:1em 2em; border:1px solid #666; background:#f9f9f9;">
456 456
 						<h3>Class Details</h3>';
457
-                    $a = new ReflectionClass($class);
458
-                    $output .= '
457
+					$a = new ReflectionClass($class);
458
+					$output .= '
459 459
 						<pre>' . $a . '</pre>
460 460
 					</div>
461 461
 				</div>';
462
-                }
463
-                $output .= '
462
+				}
463
+				$output .= '
464 464
 			</div>
465 465
 		</div>
466 466
 		<br />';
467
-            }
468
-            $this->write_to_error_log($time, $ex);
469
-        }
470
-        // remove last linebreak
471
-        $output = substr($output, 0, -6);
472
-        if (! WP_DEBUG) {
473
-            $output .= '
467
+			}
468
+			$this->write_to_error_log($time, $ex);
469
+		}
470
+		// remove last linebreak
471
+		$output = substr($output, 0, -6);
472
+		if (! WP_DEBUG) {
473
+			$output .= '
474 474
 	</p>';
475
-        }
476
-        $output .= '
475
+		}
476
+		$output .= '
477 477
 </div>';
478
-        $output .= self::_print_scripts(true);
479
-        if (defined('DOING_AJAX')) {
480
-            echo wp_json_encode(array('error' => $output));
481
-            exit();
482
-        }
483
-        echo $output;
484
-        die();
485
-    }
486
-
487
-
488
-
489
-    /**
490
-     *    generate string from exception trace args
491
-     *
492
-     * @param array $arguments
493
-     * @param bool  $array
494
-     * @return string
495
-     */
496
-    private function _convert_args_to_string($arguments = array(), $array = false)
497
-    {
498
-        $arg_string = '';
499
-        if (! empty($arguments)) {
500
-            $args = array();
501
-            foreach ($arguments as $arg) {
502
-                if (! empty($arg)) {
503
-                    if (is_string($arg)) {
504
-                        $args[] = " '" . $arg . "'";
505
-                    } elseif (is_array($arg)) {
506
-                        $args[] = 'ARRAY(' . $this->_convert_args_to_string($arg, true);
507
-                    } elseif ($arg === null) {
508
-                        $args[] = ' NULL';
509
-                    } elseif (is_bool($arg)) {
510
-                        $args[] = ($arg) ? ' TRUE' : ' FALSE';
511
-                    } elseif (is_object($arg)) {
512
-                        $args[] = ' OBJECT ' . get_class($arg);
513
-                    } elseif (is_resource($arg)) {
514
-                        $args[] = get_resource_type($arg);
515
-                    } else {
516
-                        $args[] = $arg;
517
-                    }
518
-                }
519
-            }
520
-            $arg_string = implode(', ', $args);
521
-        }
522
-        if ($array) {
523
-            $arg_string .= ' )';
524
-        }
525
-        return $arg_string;
526
-    }
527
-
528
-
529
-
530
-    /**
531
-     *    add error message
532
-     *
533
-     * @param        string $msg  the message to display to users or developers - adding a double pipe || (OR) creates
534
-     *                            separate messages for user || dev
535
-     * @param        string $file the file that the error occurred in - just use __FILE__
536
-     * @param        string $func the function/method that the error occurred in - just use __FUNCTION__
537
-     * @param        string $line the line number where the error occurred - just use __LINE__
538
-     * @return        void
539
-     */
540
-    public static function add_error($msg = null, $file = null, $func = null, $line = null)
541
-    {
542
-        self::_add_notice('errors', $msg, $file, $func, $line);
543
-        self::$_error_count++;
544
-    }
545
-
546
-
547
-
548
-    /**
549
-     * If WP_DEBUG is active, throws an exception. If WP_DEBUG is off, just
550
-     * adds an error
551
-     *
552
-     * @param string $msg
553
-     * @param string $file
554
-     * @param string $func
555
-     * @param string $line
556
-     * @throws EE_Error
557
-     */
558
-    public static function throw_exception_if_debugging($msg = null, $file = null, $func = null, $line = null)
559
-    {
560
-        if (WP_DEBUG) {
561
-            throw new EE_Error($msg);
562
-        }
563
-        EE_Error::add_error($msg, $file, $func, $line);
564
-    }
565
-
566
-
567
-
568
-    /**
569
-     *    add success message
570
-     *
571
-     * @param        string $msg  the message to display to users or developers - adding a double pipe || (OR) creates
572
-     *                            separate messages for user || dev
573
-     * @param        string $file the file that the error occurred in - just use __FILE__
574
-     * @param        string $func the function/method that the error occurred in - just use __FUNCTION__
575
-     * @param        string $line the line number where the error occurred - just use __LINE__
576
-     * @return        void
577
-     */
578
-    public static function add_success($msg = null, $file = null, $func = null, $line = null)
579
-    {
580
-        self::_add_notice('success', $msg, $file, $func, $line);
581
-    }
582
-
583
-
584
-
585
-    /**
586
-     *    add attention message
587
-     *
588
-     * @param        string $msg  the message to display to users or developers - adding a double pipe || (OR) creates
589
-     *                            separate messages for user || dev
590
-     * @param        string $file the file that the error occurred in - just use __FILE__
591
-     * @param        string $func the function/method that the error occurred in - just use __FUNCTION__
592
-     * @param        string $line the line number where the error occurred - just use __LINE__
593
-     * @return        void
594
-     */
595
-    public static function add_attention($msg = null, $file = null, $func = null, $line = null)
596
-    {
597
-        self::_add_notice('attention', $msg, $file, $func, $line);
598
-    }
599
-
600
-
601
-
602
-    /**
603
-     * @param string $type whether the message is for a success or error notification
604
-     * @param string $msg the message to display to users or developers
605
-     *                    - adding a double pipe || (OR) creates separate messages for user || dev
606
-     * @param string $file the file that the error occurred in - just use __FILE__
607
-     * @param string $func the function/method that the error occurred in - just use __FUNCTION__
608
-     * @param string $line the line number where the error occurred - just use __LINE__
609
-     * @return void
610
-     */
611
-    private static function _add_notice($type = 'success', $msg = '', $file = '', $func = '', $line = '')
612
-    {
613
-        if (empty($msg)) {
614
-            EE_Error::doing_it_wrong(
615
-                'EE_Error::add_' . $type . '()',
616
-                sprintf(
617
-                    __('Notifications are not much use without a message! Please add a message to the EE_Error::add_%s() call made in %s on line %d',
618
-                        'event_espresso'),
619
-                    $type,
620
-                    $file,
621
-                    $line
622
-                ),
623
-                EVENT_ESPRESSO_VERSION
624
-            );
625
-        }
626
-        if ($type === 'errors' && (empty($file) || empty($func) || empty($line))) {
627
-            EE_Error::doing_it_wrong(
628
-                'EE_Error::add_error()',
629
-                __('You need to provide the file name, function name, and line number that the error occurred on in order to better assist with debugging.',
630
-                    'event_espresso'),
631
-                EVENT_ESPRESSO_VERSION
632
-            );
633
-        }
634
-        // get separate user and developer messages if they exist
635
-        $msg      = explode('||', $msg);
636
-        $user_msg = $msg[0];
637
-        $dev_msg  = isset($msg[1]) ? $msg[1] : $msg[0];
638
-        /**
639
-         * Do an action so other code can be triggered when a notice is created
640
-         *
641
-         * @param string $type     can be 'errors', 'attention', or 'success'
642
-         * @param string $user_msg message displayed to user when WP_DEBUG is off
643
-         * @param string $user_msg message displayed to user when WP_DEBUG is on
644
-         * @param string $file     file where error was generated
645
-         * @param string $func     function where error was generated
646
-         * @param string $line     line where error was generated
647
-         */
648
-        do_action('AHEE__EE_Error___add_notice', $type, $user_msg, $dev_msg, $file, $func, $line);
649
-        $msg = WP_DEBUG ? $dev_msg : $user_msg;
650
-        // add notice if message exists
651
-        if (! empty($msg)) {
652
-            // get error code
653
-            $notice_code = EE_Error::generate_error_code($file, $func, $line);
654
-            if (WP_DEBUG && $type === 'errors') {
655
-                $msg .= '<br/><span class="tiny-text">' . $notice_code . '</span>';
656
-            }
657
-            // add notice. Index by code if it's not blank
658
-            if ($notice_code) {
659
-                self::$_espresso_notices[$type][$notice_code] = $msg;
660
-            } else {
661
-                self::$_espresso_notices[$type][] = $msg;
662
-            }
663
-            add_action('wp_footer', array('EE_Error', 'enqueue_error_scripts'), 1);
664
-        }
665
-    }
666
-
667
-
668
-    /**
669
-     * in some case it may be necessary to overwrite the existing success messages
670
-     *
671
-     * @return        void
672
-     */
673
-    public static function overwrite_success()
674
-    {
675
-        self::$_espresso_notices['success'] = false;
676
-    }
677
-
678
-
679
-
680
-    /**
681
-     * in some case it may be necessary to overwrite the existing attention messages
682
-     *
683
-     * @return void
684
-     */
685
-    public static function overwrite_attention()
686
-    {
687
-        self::$_espresso_notices['attention'] = false;
688
-    }
689
-
690
-
691
-
692
-    /**
693
-     * in some case it may be necessary to overwrite the existing error messages
694
-     *
695
-     * @return void
696
-     */
697
-    public static function overwrite_errors()
698
-    {
699
-        self::$_espresso_notices['errors'] = false;
700
-    }
701
-
702
-
703
-
704
-    /**
705
-     * @return void
706
-     */
707
-    public static function reset_notices()
708
-    {
709
-        self::$_espresso_notices['success']   = false;
710
-        self::$_espresso_notices['attention'] = false;
711
-        self::$_espresso_notices['errors']    = false;
712
-    }
713
-
714
-
715
-
716
-    /**
717
-     * @return int
718
-     */
719
-    public static function has_notices()
720
-    {
721
-        $has_notices = 0;
722
-        // check for success messages
723
-        $has_notices = self::$_espresso_notices['success'] && ! empty(self::$_espresso_notices['success'])
724
-            ? 3
725
-            : $has_notices;
726
-        // check for attention messages
727
-        $has_notices = self::$_espresso_notices['attention'] && ! empty(self::$_espresso_notices['attention'])
728
-            ? 2
729
-            : $has_notices;
730
-        // check for error messages
731
-        $has_notices = self::$_espresso_notices['errors'] && ! empty(self::$_espresso_notices['errors'])
732
-            ? 1
733
-            : $has_notices;
734
-        return $has_notices;
735
-    }
736
-
737
-
738
-    /**
739
-     * This simply returns non formatted error notices as they were sent into the EE_Error object.
740
-     *
741
-     * @since 4.9.0
742
-     * @return array
743
-     */
744
-    public static function get_vanilla_notices()
745
-    {
746
-        return array(
747
-            'success'   => isset(self::$_espresso_notices['success'])
748
-                ? self::$_espresso_notices['success']
749
-                : array(),
750
-            'attention' => isset(self::$_espresso_notices['attention'])
751
-                ? self::$_espresso_notices['attention']
752
-                : array(),
753
-            'errors'    => isset(self::$_espresso_notices['errors'])
754
-                ? self::$_espresso_notices['errors']
755
-                : array(),
756
-        );
757
-    }
758
-
759
-
760
-
761
-    /**
762
-     * compile all error or success messages into one string
763
-     *
764
-     * @see EE_Error::get_raw_notices if you want the raw notices without any preparations made to them
765
-     * @param boolean $format_output     whether or not to format the messages for display in the WP admin
766
-     * @param boolean $save_to_transient whether or not to save notices to the db for retrieval on next request
767
-     *                                          - ONLY do this just before redirecting
768
-     * @param boolean $remove_empty      whether or not to unset empty messages
769
-     * @return array
770
-     */
771
-    public static function get_notices($format_output = true, $save_to_transient = false, $remove_empty = true)
772
-    {
773
-        // do_action('AHEE_log', __FILE__, __FUNCTION__, '');
774
-        $success_messages   = '';
775
-        $attention_messages = '';
776
-        $error_messages     = '';
777
-        $print_scripts      = false;
778
-        // EEH_Debug_Tools::printr( self::$_espresso_notices, 'espresso_notices  <br /><span style="font-size:10px;font-weight:normal;">' . __FILE__ . '<br />line no: ' . __LINE__ . '</span>', 'auto' );
779
-        // either save notices to the db
780
-        if ($save_to_transient || isset($_REQUEST['activate-selected'])) {
781
-            $existing_notices  = get_option(EE_Error::OPTIONS_KEY_NOTICES, array());
782
-            $existing_notices = is_array($existing_notices) ? $existing_notices : array();
783
-            self::$_espresso_notices = array_merge(
784
-                $existing_notices,
785
-                self::$_espresso_notices
786
-            );
787
-            update_option(EE_Error::OPTIONS_KEY_NOTICES, self::$_espresso_notices);
788
-            return array();
789
-        }
790
-        // grab any notices that have been previously saved
791
-        if ($notices = get_option(EE_Error::OPTIONS_KEY_NOTICES, array())) {
792
-            foreach ($notices as $type => $notice) {
793
-                if (is_array($notice) && ! empty($notice)) {
794
-                    // make sure that existing notice type is an array
795
-                    self::$_espresso_notices[$type] = is_array(self::$_espresso_notices[$type])
796
-                                                      && ! empty(self::$_espresso_notices[$type])
797
-                        ? self::$_espresso_notices[$type]
798
-                        : array();
799
-                    // merge stored notices with any newly created ones
800
-                    self::$_espresso_notices[$type] = array_merge(self::$_espresso_notices[$type], $notice);
801
-                    $print_scripts                  = true;
802
-                }
803
-            }
804
-            // now clear any stored notices
805
-            update_option(EE_Error::OPTIONS_KEY_NOTICES, array());
806
-        }
807
-        // check for success messages
808
-        if (self::$_espresso_notices['success'] && ! empty(self::$_espresso_notices['success'])) {
809
-            // combine messages
810
-            $success_messages .= implode(self::$_espresso_notices['success'], '<br />');
811
-            $print_scripts    = true;
812
-        }
813
-        // check for attention messages
814
-        if (self::$_espresso_notices['attention'] && ! empty(self::$_espresso_notices['attention'])) {
815
-            // combine messages
816
-            $attention_messages .= implode(self::$_espresso_notices['attention'], '<br />');
817
-            $print_scripts      = true;
818
-        }
819
-        // check for error messages
820
-        if (self::$_espresso_notices['errors'] && ! empty(self::$_espresso_notices['errors'])) {
821
-            $error_messages .= count(self::$_espresso_notices['errors']) > 1
822
-                ? __('The following errors have occurred:<br />', 'event_espresso')
823
-                : __('An error has occurred:<br />', 'event_espresso');
824
-            // combine messages
825
-            $error_messages .= implode(self::$_espresso_notices['errors'], '<br />');
826
-            $print_scripts  = true;
827
-        }
828
-        if ($format_output) {
829
-
830
-            $notices = '<div id="espresso-notices">';
831
-            $close = is_admin() ? ''
832
-                : '<a class="close-espresso-notice hide-if-no-js"><span class="dashicons dashicons-no"></span></a>';
833
-            if ($success_messages !== '') {
834
-                $css_id    = is_admin() ? 'ee-success-message' : 'espresso-notices-success';
835
-                $css_class = is_admin() ? 'updated fade' : 'success fade-away';
836
-                //showMessage( $success_messages );
837
-                $notices .= '<div id="'
838
-                            . $css_id
839
-                            . '" class="espresso-notices '
840
-                            . $css_class
841
-                            . '" style="display:none;"><p>'
842
-                            . $success_messages
843
-                            . '</p>'
844
-                            . $close
845
-                            . '</div>';
846
-            }
847
-            if ($attention_messages !== '') {
848
-                $css_id    = is_admin() ? 'ee-attention-message' : 'espresso-notices-attention';
849
-                $css_class = is_admin() ? 'updated ee-notices-attention' : 'attention fade-away';
850
-                //showMessage( $error_messages, TRUE );
851
-                $notices .= '<div id="'
852
-                            . $css_id
853
-                            . '" class="espresso-notices '
854
-                            . $css_class
855
-                            . '" style="display:none;"><p>'
856
-                            . $attention_messages
857
-                            . '</p>'
858
-                            . $close
859
-                            . '</div>';
860
-            }
861
-            if ($error_messages !== '') {
862
-                $css_id    = is_admin() ? 'ee-error-message' : 'espresso-notices-error';
863
-                $css_class = is_admin() ? 'error' : 'error fade-away';
864
-                //showMessage( $error_messages, TRUE );
865
-                $notices .= '<div id="'
866
-                            . $css_id
867
-                            . '" class="espresso-notices '
868
-                            . $css_class
869
-                            . '" style="display:none;"><p>'
870
-                            . $error_messages
871
-                            . '</p>'
872
-                            . $close
873
-                            . '</div>';
874
-            }
875
-            $notices .= '</div>';
876
-        } else {
877
-
878
-            $notices = array(
879
-                'success'   => $success_messages,
880
-                'attention' => $attention_messages,
881
-                'errors'    => $error_messages,
882
-            );
883
-            if ($remove_empty) {
884
-                // remove empty notices
885
-                foreach ($notices as $type => $notice) {
886
-                    if (empty($notice)) {
887
-                        unset($notices[$type]);
888
-                    }
889
-                }
890
-            }
891
-        }
892
-        if ($print_scripts) {
893
-            self::_print_scripts();
894
-        }
895
-        return $notices;
896
-    }
897
-
898
-
899
-
900
-    /**
901
-     * _print_scripts
902
-     *
903
-     * @param    bool $force_print
904
-     * @return    string
905
-     */
906
-    private static function _print_scripts($force_print = false)
907
-    {
908
-        if (! $force_print && (did_action('admin_enqueue_scripts') || did_action('wp_enqueue_scripts'))) {
909
-            if (wp_script_is('ee_error_js', 'enqueued')) {
910
-                return '';
911
-            }
912
-            if (wp_script_is('ee_error_js', 'registered')) {
913
-                wp_enqueue_style('espresso_default');
914
-                wp_enqueue_style('espresso_custom_css');
915
-                wp_enqueue_script('ee_error_js');
916
-                wp_localize_script('ee_error_js', 'ee_settings', array('wp_debug' => WP_DEBUG));
917
-            }
918
-        } else {
919
-            return '
478
+		$output .= self::_print_scripts(true);
479
+		if (defined('DOING_AJAX')) {
480
+			echo wp_json_encode(array('error' => $output));
481
+			exit();
482
+		}
483
+		echo $output;
484
+		die();
485
+	}
486
+
487
+
488
+
489
+	/**
490
+	 *    generate string from exception trace args
491
+	 *
492
+	 * @param array $arguments
493
+	 * @param bool  $array
494
+	 * @return string
495
+	 */
496
+	private function _convert_args_to_string($arguments = array(), $array = false)
497
+	{
498
+		$arg_string = '';
499
+		if (! empty($arguments)) {
500
+			$args = array();
501
+			foreach ($arguments as $arg) {
502
+				if (! empty($arg)) {
503
+					if (is_string($arg)) {
504
+						$args[] = " '" . $arg . "'";
505
+					} elseif (is_array($arg)) {
506
+						$args[] = 'ARRAY(' . $this->_convert_args_to_string($arg, true);
507
+					} elseif ($arg === null) {
508
+						$args[] = ' NULL';
509
+					} elseif (is_bool($arg)) {
510
+						$args[] = ($arg) ? ' TRUE' : ' FALSE';
511
+					} elseif (is_object($arg)) {
512
+						$args[] = ' OBJECT ' . get_class($arg);
513
+					} elseif (is_resource($arg)) {
514
+						$args[] = get_resource_type($arg);
515
+					} else {
516
+						$args[] = $arg;
517
+					}
518
+				}
519
+			}
520
+			$arg_string = implode(', ', $args);
521
+		}
522
+		if ($array) {
523
+			$arg_string .= ' )';
524
+		}
525
+		return $arg_string;
526
+	}
527
+
528
+
529
+
530
+	/**
531
+	 *    add error message
532
+	 *
533
+	 * @param        string $msg  the message to display to users or developers - adding a double pipe || (OR) creates
534
+	 *                            separate messages for user || dev
535
+	 * @param        string $file the file that the error occurred in - just use __FILE__
536
+	 * @param        string $func the function/method that the error occurred in - just use __FUNCTION__
537
+	 * @param        string $line the line number where the error occurred - just use __LINE__
538
+	 * @return        void
539
+	 */
540
+	public static function add_error($msg = null, $file = null, $func = null, $line = null)
541
+	{
542
+		self::_add_notice('errors', $msg, $file, $func, $line);
543
+		self::$_error_count++;
544
+	}
545
+
546
+
547
+
548
+	/**
549
+	 * If WP_DEBUG is active, throws an exception. If WP_DEBUG is off, just
550
+	 * adds an error
551
+	 *
552
+	 * @param string $msg
553
+	 * @param string $file
554
+	 * @param string $func
555
+	 * @param string $line
556
+	 * @throws EE_Error
557
+	 */
558
+	public static function throw_exception_if_debugging($msg = null, $file = null, $func = null, $line = null)
559
+	{
560
+		if (WP_DEBUG) {
561
+			throw new EE_Error($msg);
562
+		}
563
+		EE_Error::add_error($msg, $file, $func, $line);
564
+	}
565
+
566
+
567
+
568
+	/**
569
+	 *    add success message
570
+	 *
571
+	 * @param        string $msg  the message to display to users or developers - adding a double pipe || (OR) creates
572
+	 *                            separate messages for user || dev
573
+	 * @param        string $file the file that the error occurred in - just use __FILE__
574
+	 * @param        string $func the function/method that the error occurred in - just use __FUNCTION__
575
+	 * @param        string $line the line number where the error occurred - just use __LINE__
576
+	 * @return        void
577
+	 */
578
+	public static function add_success($msg = null, $file = null, $func = null, $line = null)
579
+	{
580
+		self::_add_notice('success', $msg, $file, $func, $line);
581
+	}
582
+
583
+
584
+
585
+	/**
586
+	 *    add attention message
587
+	 *
588
+	 * @param        string $msg  the message to display to users or developers - adding a double pipe || (OR) creates
589
+	 *                            separate messages for user || dev
590
+	 * @param        string $file the file that the error occurred in - just use __FILE__
591
+	 * @param        string $func the function/method that the error occurred in - just use __FUNCTION__
592
+	 * @param        string $line the line number where the error occurred - just use __LINE__
593
+	 * @return        void
594
+	 */
595
+	public static function add_attention($msg = null, $file = null, $func = null, $line = null)
596
+	{
597
+		self::_add_notice('attention', $msg, $file, $func, $line);
598
+	}
599
+
600
+
601
+
602
+	/**
603
+	 * @param string $type whether the message is for a success or error notification
604
+	 * @param string $msg the message to display to users or developers
605
+	 *                    - adding a double pipe || (OR) creates separate messages for user || dev
606
+	 * @param string $file the file that the error occurred in - just use __FILE__
607
+	 * @param string $func the function/method that the error occurred in - just use __FUNCTION__
608
+	 * @param string $line the line number where the error occurred - just use __LINE__
609
+	 * @return void
610
+	 */
611
+	private static function _add_notice($type = 'success', $msg = '', $file = '', $func = '', $line = '')
612
+	{
613
+		if (empty($msg)) {
614
+			EE_Error::doing_it_wrong(
615
+				'EE_Error::add_' . $type . '()',
616
+				sprintf(
617
+					__('Notifications are not much use without a message! Please add a message to the EE_Error::add_%s() call made in %s on line %d',
618
+						'event_espresso'),
619
+					$type,
620
+					$file,
621
+					$line
622
+				),
623
+				EVENT_ESPRESSO_VERSION
624
+			);
625
+		}
626
+		if ($type === 'errors' && (empty($file) || empty($func) || empty($line))) {
627
+			EE_Error::doing_it_wrong(
628
+				'EE_Error::add_error()',
629
+				__('You need to provide the file name, function name, and line number that the error occurred on in order to better assist with debugging.',
630
+					'event_espresso'),
631
+				EVENT_ESPRESSO_VERSION
632
+			);
633
+		}
634
+		// get separate user and developer messages if they exist
635
+		$msg      = explode('||', $msg);
636
+		$user_msg = $msg[0];
637
+		$dev_msg  = isset($msg[1]) ? $msg[1] : $msg[0];
638
+		/**
639
+		 * Do an action so other code can be triggered when a notice is created
640
+		 *
641
+		 * @param string $type     can be 'errors', 'attention', or 'success'
642
+		 * @param string $user_msg message displayed to user when WP_DEBUG is off
643
+		 * @param string $user_msg message displayed to user when WP_DEBUG is on
644
+		 * @param string $file     file where error was generated
645
+		 * @param string $func     function where error was generated
646
+		 * @param string $line     line where error was generated
647
+		 */
648
+		do_action('AHEE__EE_Error___add_notice', $type, $user_msg, $dev_msg, $file, $func, $line);
649
+		$msg = WP_DEBUG ? $dev_msg : $user_msg;
650
+		// add notice if message exists
651
+		if (! empty($msg)) {
652
+			// get error code
653
+			$notice_code = EE_Error::generate_error_code($file, $func, $line);
654
+			if (WP_DEBUG && $type === 'errors') {
655
+				$msg .= '<br/><span class="tiny-text">' . $notice_code . '</span>';
656
+			}
657
+			// add notice. Index by code if it's not blank
658
+			if ($notice_code) {
659
+				self::$_espresso_notices[$type][$notice_code] = $msg;
660
+			} else {
661
+				self::$_espresso_notices[$type][] = $msg;
662
+			}
663
+			add_action('wp_footer', array('EE_Error', 'enqueue_error_scripts'), 1);
664
+		}
665
+	}
666
+
667
+
668
+	/**
669
+	 * in some case it may be necessary to overwrite the existing success messages
670
+	 *
671
+	 * @return        void
672
+	 */
673
+	public static function overwrite_success()
674
+	{
675
+		self::$_espresso_notices['success'] = false;
676
+	}
677
+
678
+
679
+
680
+	/**
681
+	 * in some case it may be necessary to overwrite the existing attention messages
682
+	 *
683
+	 * @return void
684
+	 */
685
+	public static function overwrite_attention()
686
+	{
687
+		self::$_espresso_notices['attention'] = false;
688
+	}
689
+
690
+
691
+
692
+	/**
693
+	 * in some case it may be necessary to overwrite the existing error messages
694
+	 *
695
+	 * @return void
696
+	 */
697
+	public static function overwrite_errors()
698
+	{
699
+		self::$_espresso_notices['errors'] = false;
700
+	}
701
+
702
+
703
+
704
+	/**
705
+	 * @return void
706
+	 */
707
+	public static function reset_notices()
708
+	{
709
+		self::$_espresso_notices['success']   = false;
710
+		self::$_espresso_notices['attention'] = false;
711
+		self::$_espresso_notices['errors']    = false;
712
+	}
713
+
714
+
715
+
716
+	/**
717
+	 * @return int
718
+	 */
719
+	public static function has_notices()
720
+	{
721
+		$has_notices = 0;
722
+		// check for success messages
723
+		$has_notices = self::$_espresso_notices['success'] && ! empty(self::$_espresso_notices['success'])
724
+			? 3
725
+			: $has_notices;
726
+		// check for attention messages
727
+		$has_notices = self::$_espresso_notices['attention'] && ! empty(self::$_espresso_notices['attention'])
728
+			? 2
729
+			: $has_notices;
730
+		// check for error messages
731
+		$has_notices = self::$_espresso_notices['errors'] && ! empty(self::$_espresso_notices['errors'])
732
+			? 1
733
+			: $has_notices;
734
+		return $has_notices;
735
+	}
736
+
737
+
738
+	/**
739
+	 * This simply returns non formatted error notices as they were sent into the EE_Error object.
740
+	 *
741
+	 * @since 4.9.0
742
+	 * @return array
743
+	 */
744
+	public static function get_vanilla_notices()
745
+	{
746
+		return array(
747
+			'success'   => isset(self::$_espresso_notices['success'])
748
+				? self::$_espresso_notices['success']
749
+				: array(),
750
+			'attention' => isset(self::$_espresso_notices['attention'])
751
+				? self::$_espresso_notices['attention']
752
+				: array(),
753
+			'errors'    => isset(self::$_espresso_notices['errors'])
754
+				? self::$_espresso_notices['errors']
755
+				: array(),
756
+		);
757
+	}
758
+
759
+
760
+
761
+	/**
762
+	 * compile all error or success messages into one string
763
+	 *
764
+	 * @see EE_Error::get_raw_notices if you want the raw notices without any preparations made to them
765
+	 * @param boolean $format_output     whether or not to format the messages for display in the WP admin
766
+	 * @param boolean $save_to_transient whether or not to save notices to the db for retrieval on next request
767
+	 *                                          - ONLY do this just before redirecting
768
+	 * @param boolean $remove_empty      whether or not to unset empty messages
769
+	 * @return array
770
+	 */
771
+	public static function get_notices($format_output = true, $save_to_transient = false, $remove_empty = true)
772
+	{
773
+		// do_action('AHEE_log', __FILE__, __FUNCTION__, '');
774
+		$success_messages   = '';
775
+		$attention_messages = '';
776
+		$error_messages     = '';
777
+		$print_scripts      = false;
778
+		// EEH_Debug_Tools::printr( self::$_espresso_notices, 'espresso_notices  <br /><span style="font-size:10px;font-weight:normal;">' . __FILE__ . '<br />line no: ' . __LINE__ . '</span>', 'auto' );
779
+		// either save notices to the db
780
+		if ($save_to_transient || isset($_REQUEST['activate-selected'])) {
781
+			$existing_notices  = get_option(EE_Error::OPTIONS_KEY_NOTICES, array());
782
+			$existing_notices = is_array($existing_notices) ? $existing_notices : array();
783
+			self::$_espresso_notices = array_merge(
784
+				$existing_notices,
785
+				self::$_espresso_notices
786
+			);
787
+			update_option(EE_Error::OPTIONS_KEY_NOTICES, self::$_espresso_notices);
788
+			return array();
789
+		}
790
+		// grab any notices that have been previously saved
791
+		if ($notices = get_option(EE_Error::OPTIONS_KEY_NOTICES, array())) {
792
+			foreach ($notices as $type => $notice) {
793
+				if (is_array($notice) && ! empty($notice)) {
794
+					// make sure that existing notice type is an array
795
+					self::$_espresso_notices[$type] = is_array(self::$_espresso_notices[$type])
796
+													  && ! empty(self::$_espresso_notices[$type])
797
+						? self::$_espresso_notices[$type]
798
+						: array();
799
+					// merge stored notices with any newly created ones
800
+					self::$_espresso_notices[$type] = array_merge(self::$_espresso_notices[$type], $notice);
801
+					$print_scripts                  = true;
802
+				}
803
+			}
804
+			// now clear any stored notices
805
+			update_option(EE_Error::OPTIONS_KEY_NOTICES, array());
806
+		}
807
+		// check for success messages
808
+		if (self::$_espresso_notices['success'] && ! empty(self::$_espresso_notices['success'])) {
809
+			// combine messages
810
+			$success_messages .= implode(self::$_espresso_notices['success'], '<br />');
811
+			$print_scripts    = true;
812
+		}
813
+		// check for attention messages
814
+		if (self::$_espresso_notices['attention'] && ! empty(self::$_espresso_notices['attention'])) {
815
+			// combine messages
816
+			$attention_messages .= implode(self::$_espresso_notices['attention'], '<br />');
817
+			$print_scripts      = true;
818
+		}
819
+		// check for error messages
820
+		if (self::$_espresso_notices['errors'] && ! empty(self::$_espresso_notices['errors'])) {
821
+			$error_messages .= count(self::$_espresso_notices['errors']) > 1
822
+				? __('The following errors have occurred:<br />', 'event_espresso')
823
+				: __('An error has occurred:<br />', 'event_espresso');
824
+			// combine messages
825
+			$error_messages .= implode(self::$_espresso_notices['errors'], '<br />');
826
+			$print_scripts  = true;
827
+		}
828
+		if ($format_output) {
829
+
830
+			$notices = '<div id="espresso-notices">';
831
+			$close = is_admin() ? ''
832
+				: '<a class="close-espresso-notice hide-if-no-js"><span class="dashicons dashicons-no"></span></a>';
833
+			if ($success_messages !== '') {
834
+				$css_id    = is_admin() ? 'ee-success-message' : 'espresso-notices-success';
835
+				$css_class = is_admin() ? 'updated fade' : 'success fade-away';
836
+				//showMessage( $success_messages );
837
+				$notices .= '<div id="'
838
+							. $css_id
839
+							. '" class="espresso-notices '
840
+							. $css_class
841
+							. '" style="display:none;"><p>'
842
+							. $success_messages
843
+							. '</p>'
844
+							. $close
845
+							. '</div>';
846
+			}
847
+			if ($attention_messages !== '') {
848
+				$css_id    = is_admin() ? 'ee-attention-message' : 'espresso-notices-attention';
849
+				$css_class = is_admin() ? 'updated ee-notices-attention' : 'attention fade-away';
850
+				//showMessage( $error_messages, TRUE );
851
+				$notices .= '<div id="'
852
+							. $css_id
853
+							. '" class="espresso-notices '
854
+							. $css_class
855
+							. '" style="display:none;"><p>'
856
+							. $attention_messages
857
+							. '</p>'
858
+							. $close
859
+							. '</div>';
860
+			}
861
+			if ($error_messages !== '') {
862
+				$css_id    = is_admin() ? 'ee-error-message' : 'espresso-notices-error';
863
+				$css_class = is_admin() ? 'error' : 'error fade-away';
864
+				//showMessage( $error_messages, TRUE );
865
+				$notices .= '<div id="'
866
+							. $css_id
867
+							. '" class="espresso-notices '
868
+							. $css_class
869
+							. '" style="display:none;"><p>'
870
+							. $error_messages
871
+							. '</p>'
872
+							. $close
873
+							. '</div>';
874
+			}
875
+			$notices .= '</div>';
876
+		} else {
877
+
878
+			$notices = array(
879
+				'success'   => $success_messages,
880
+				'attention' => $attention_messages,
881
+				'errors'    => $error_messages,
882
+			);
883
+			if ($remove_empty) {
884
+				// remove empty notices
885
+				foreach ($notices as $type => $notice) {
886
+					if (empty($notice)) {
887
+						unset($notices[$type]);
888
+					}
889
+				}
890
+			}
891
+		}
892
+		if ($print_scripts) {
893
+			self::_print_scripts();
894
+		}
895
+		return $notices;
896
+	}
897
+
898
+
899
+
900
+	/**
901
+	 * _print_scripts
902
+	 *
903
+	 * @param    bool $force_print
904
+	 * @return    string
905
+	 */
906
+	private static function _print_scripts($force_print = false)
907
+	{
908
+		if (! $force_print && (did_action('admin_enqueue_scripts') || did_action('wp_enqueue_scripts'))) {
909
+			if (wp_script_is('ee_error_js', 'enqueued')) {
910
+				return '';
911
+			}
912
+			if (wp_script_is('ee_error_js', 'registered')) {
913
+				wp_enqueue_style('espresso_default');
914
+				wp_enqueue_style('espresso_custom_css');
915
+				wp_enqueue_script('ee_error_js');
916
+				wp_localize_script('ee_error_js', 'ee_settings', array('wp_debug' => WP_DEBUG));
917
+			}
918
+		} else {
919
+			return '
920 920
 <script>
921 921
 /* <![CDATA[ */
922 922
 var ee_settings = {"wp_debug":"' . WP_DEBUG . '"};
@@ -926,223 +926,223 @@  discard block
 block discarded – undo
926 926
 <script src="' . EE_GLOBAL_ASSETS_URL . 'scripts/espresso_core.js' . '?ver=' . espresso_version() . '" type="text/javascript"></script>
927 927
 <script src="' . EE_GLOBAL_ASSETS_URL . 'scripts/EE_Error.js' . '?ver=' . espresso_version() . '" type="text/javascript"></script>
928 928
 ';
929
-        }
930
-        return '';
931
-    }
932
-
933
-
934
-
935
-    /**
936
-     * @return void
937
-     */
938
-    public static function enqueue_error_scripts()
939
-    {
940
-        self::_print_scripts();
941
-    }
942
-
943
-
944
-
945
-    /**
946
-     * create error code from filepath, function name,
947
-     * and line number where exception or error was thrown
948
-     *
949
-     * @param string $file
950
-     * @param string $func
951
-     * @param string $line
952
-     * @return string
953
-     */
954
-    public static function generate_error_code($file = '', $func = '', $line = '')
955
-    {
956
-        $file       = explode('.', basename($file));
957
-        $error_code = ! empty($file[0]) ? $file[0] : '';
958
-        $error_code .= ! empty($func) ? ' - ' . $func : '';
959
-        $error_code .= ! empty($line) ? ' - ' . $line : '';
960
-        return $error_code;
961
-    }
962
-
963
-
964
-
965
-    /**
966
-     * write exception details to log file
967
-     * Since 4.9.53.rc.006 this writes to the standard PHP log file, not EE's custom log file
968
-     *
969
-     * @param int   $time
970
-     * @param array $ex
971
-     * @param bool  $clear
972
-     * @return void
973
-     */
974
-    public function write_to_error_log($time = 0, $ex = array(), $clear = false)
975
-    {
976
-        if (empty($ex)) {
977
-            return;
978
-        }
979
-        if (! $time) {
980
-            $time = time();
981
-        }
982
-        $exception_log = '----------------------------------------------------------------------------------------'
983
-                         . PHP_EOL;
984
-        $exception_log .= '[' . date('Y-m-d H:i:s', $time) . ']  Exception Details' . PHP_EOL;
985
-        $exception_log .= 'Message: ' . $ex['msg'] . PHP_EOL;
986
-        $exception_log .= 'Code: ' . $ex['code'] . PHP_EOL;
987
-        $exception_log .= 'File: ' . $ex['file'] . PHP_EOL;
988
-        $exception_log .= 'Line No: ' . $ex['line'] . PHP_EOL;
989
-        $exception_log .= 'Stack trace: ' . PHP_EOL;
990
-        $exception_log .= $ex['string'] . PHP_EOL;
991
-        $exception_log .= '----------------------------------------------------------------------------------------'
992
-                          . PHP_EOL;
993
-        try {
994
-            error_log($exception_log);
995
-        } catch (EE_Error $e) {
996
-            EE_Error::add_error(sprintf(__('Event Espresso error logging could not be setup because: %s',
997
-                'event_espresso'), $e->getMessage()));
998
-        }
999
-    }
1000
-
1001
-
1002
-
1003
-    /**
1004
-     * This is just a wrapper for the EEH_Debug_Tools::instance()->doing_it_wrong() method.
1005
-     * doing_it_wrong() is used in those cases where a normal PHP error won't get thrown,
1006
-     * but the code execution is done in a manner that could lead to unexpected results
1007
-     * (i.e. running to early, or too late in WP or EE loading process).
1008
-     * A good test for knowing whether to use this method is:
1009
-     * 1. Is there going to be a PHP error if something isn't setup/used correctly?
1010
-     * Yes -> use EE_Error::add_error() or throw new EE_Error()
1011
-     * 2. If this is loaded before something else, it won't break anything,
1012
-     * but just wont' do what its supposed to do? Yes -> use EE_Error::doing_it_wrong()
1013
-     *
1014
-     * @uses   constant WP_DEBUG test if wp_debug is on or not
1015
-     * @param string $function      The function that was called
1016
-     * @param string $message       A message explaining what has been done incorrectly
1017
-     * @param string $version       The version of Event Espresso where the error was added
1018
-     * @param string $applies_when  a version string for when you want the doing_it_wrong notice to begin appearing
1019
-     *                              for a deprecated function. This allows deprecation to occur during one version,
1020
-     *                              but not have any notices appear until a later version. This allows developers
1021
-     *                              extra time to update their code before notices appear.
1022
-     * @param int    $error_type
1023
-     */
1024
-    public static function doing_it_wrong(
1025
-        $function,
1026
-        $message,
1027
-        $version,
1028
-        $applies_when = '',
1029
-        $error_type = null
1030
-    ) {
1031
-        if (defined('WP_DEBUG') && WP_DEBUG) {
1032
-            EEH_Debug_Tools::instance()->doing_it_wrong($function, $message, $version, $applies_when, $error_type);
1033
-        }
1034
-    }
1035
-
1036
-
1037
-
1038
-    /**
1039
-     * Like get_notices, but returns an array of all the notices of the given type.
1040
-     *
1041
-     * @return array {
1042
-     *  @type array $success   all the success messages
1043
-     *  @type array $errors    all the error messages
1044
-     *  @type array $attention all the attention messages
1045
-     * }
1046
-     */
1047
-    public static function get_raw_notices()
1048
-    {
1049
-        return self::$_espresso_notices;
1050
-    }
1051
-
1052
-
1053
-
1054
-    /**
1055
-     * @deprecated 4.9.27
1056
-     * @param string $pan_name     the name, or key of the Persistent Admin Notice to be stored
1057
-     * @param string $pan_message  the message to be stored persistently until dismissed
1058
-     * @param bool   $force_update allows one to enforce the reappearance of a persistent message.
1059
-     * @return void
1060
-     * @throws InvalidDataTypeException
1061
-     */
1062
-    public static function add_persistent_admin_notice($pan_name = '', $pan_message, $force_update = false)
1063
-    {
1064
-        new PersistentAdminNotice(
1065
-            $pan_name,
1066
-            $pan_message,
1067
-            $force_update
1068
-        );
1069
-        EE_Error::doing_it_wrong(
1070
-            __METHOD__,
1071
-            sprintf(
1072
-                __('Usage is deprecated. Use "%1$s" instead.', 'event_espresso'),
1073
-                '\EventEspresso\core\domain\entities\notifications\PersistentAdminNotice'
1074
-            ),
1075
-            '4.9.27'
1076
-        );
1077
-    }
1078
-
1079
-
1080
-
1081
-    /**
1082
-     * @deprecated 4.9.27
1083
-     * @param string $pan_name the name, or key of the Persistent Admin Notice to be dismissed
1084
-     * @param bool   $purge
1085
-     * @param bool   $return
1086
-     * @throws DomainException
1087
-     * @throws InvalidInterfaceException
1088
-     * @throws InvalidDataTypeException
1089
-     * @throws ServiceNotFoundException
1090
-     * @throws InvalidArgumentException
1091
-     */
1092
-    public static function dismiss_persistent_admin_notice($pan_name = '', $purge = false, $return = false)
1093
-    {
1094
-        /** @var PersistentAdminNoticeManager $persistent_admin_notice_manager */
1095
-        $persistent_admin_notice_manager = LoaderFactory::getLoader()->getShared(
1096
-            'EventEspresso\core\services\notifications\PersistentAdminNoticeManager'
1097
-        );
1098
-        $persistent_admin_notice_manager->dismissNotice($pan_name, $purge, $return);
1099
-        EE_Error::doing_it_wrong(
1100
-            __METHOD__,
1101
-            sprintf(
1102
-                __('Usage is deprecated. Use "%1$s" instead.', 'event_espresso'),
1103
-                '\EventEspresso\core\services\notifications\PersistentAdminNoticeManager'
1104
-            ),
1105
-            '4.9.27'
1106
-        );
1107
-    }
1108
-
1109
-
1110
-
1111
-    /**
1112
-     * @deprecated 4.9.27
1113
-     * @param  string $pan_name    the name, or key of the Persistent Admin Notice to be stored
1114
-     * @param  string $pan_message the message to be stored persistently until dismissed
1115
-     * @param  string $return_url  URL to go back to after nag notice is dismissed
1116
-     */
1117
-    public static function display_persistent_admin_notices($pan_name = '', $pan_message = '', $return_url = '')
1118
-    {
1119
-        EE_Error::doing_it_wrong(
1120
-            __METHOD__,
1121
-            sprintf(
1122
-                __('Usage is deprecated. Use "%1$s" instead.', 'event_espresso'),
1123
-                '\EventEspresso\core\services\notifications\PersistentAdminNoticeManager'
1124
-            ),
1125
-            '4.9.27'
1126
-        );
1127
-    }
1128
-
1129
-
1130
-
1131
-    /**
1132
-     * @deprecated 4.9.27
1133
-     * @param string $return_url
1134
-     */
1135
-    public static function get_persistent_admin_notices($return_url = '')
1136
-    {
1137
-        EE_Error::doing_it_wrong(
1138
-            __METHOD__,
1139
-            sprintf(
1140
-                __('Usage is deprecated. Use "%1$s" instead.', 'event_espresso'),
1141
-                '\EventEspresso\core\services\notifications\PersistentAdminNoticeManager'
1142
-            ),
1143
-            '4.9.27'
1144
-        );
1145
-    }
929
+		}
930
+		return '';
931
+	}
932
+
933
+
934
+
935
+	/**
936
+	 * @return void
937
+	 */
938
+	public static function enqueue_error_scripts()
939
+	{
940
+		self::_print_scripts();
941
+	}
942
+
943
+
944
+
945
+	/**
946
+	 * create error code from filepath, function name,
947
+	 * and line number where exception or error was thrown
948
+	 *
949
+	 * @param string $file
950
+	 * @param string $func
951
+	 * @param string $line
952
+	 * @return string
953
+	 */
954
+	public static function generate_error_code($file = '', $func = '', $line = '')
955
+	{
956
+		$file       = explode('.', basename($file));
957
+		$error_code = ! empty($file[0]) ? $file[0] : '';
958
+		$error_code .= ! empty($func) ? ' - ' . $func : '';
959
+		$error_code .= ! empty($line) ? ' - ' . $line : '';
960
+		return $error_code;
961
+	}
962
+
963
+
964
+
965
+	/**
966
+	 * write exception details to log file
967
+	 * Since 4.9.53.rc.006 this writes to the standard PHP log file, not EE's custom log file
968
+	 *
969
+	 * @param int   $time
970
+	 * @param array $ex
971
+	 * @param bool  $clear
972
+	 * @return void
973
+	 */
974
+	public function write_to_error_log($time = 0, $ex = array(), $clear = false)
975
+	{
976
+		if (empty($ex)) {
977
+			return;
978
+		}
979
+		if (! $time) {
980
+			$time = time();
981
+		}
982
+		$exception_log = '----------------------------------------------------------------------------------------'
983
+						 . PHP_EOL;
984
+		$exception_log .= '[' . date('Y-m-d H:i:s', $time) . ']  Exception Details' . PHP_EOL;
985
+		$exception_log .= 'Message: ' . $ex['msg'] . PHP_EOL;
986
+		$exception_log .= 'Code: ' . $ex['code'] . PHP_EOL;
987
+		$exception_log .= 'File: ' . $ex['file'] . PHP_EOL;
988
+		$exception_log .= 'Line No: ' . $ex['line'] . PHP_EOL;
989
+		$exception_log .= 'Stack trace: ' . PHP_EOL;
990
+		$exception_log .= $ex['string'] . PHP_EOL;
991
+		$exception_log .= '----------------------------------------------------------------------------------------'
992
+						  . PHP_EOL;
993
+		try {
994
+			error_log($exception_log);
995
+		} catch (EE_Error $e) {
996
+			EE_Error::add_error(sprintf(__('Event Espresso error logging could not be setup because: %s',
997
+				'event_espresso'), $e->getMessage()));
998
+		}
999
+	}
1000
+
1001
+
1002
+
1003
+	/**
1004
+	 * This is just a wrapper for the EEH_Debug_Tools::instance()->doing_it_wrong() method.
1005
+	 * doing_it_wrong() is used in those cases where a normal PHP error won't get thrown,
1006
+	 * but the code execution is done in a manner that could lead to unexpected results
1007
+	 * (i.e. running to early, or too late in WP or EE loading process).
1008
+	 * A good test for knowing whether to use this method is:
1009
+	 * 1. Is there going to be a PHP error if something isn't setup/used correctly?
1010
+	 * Yes -> use EE_Error::add_error() or throw new EE_Error()
1011
+	 * 2. If this is loaded before something else, it won't break anything,
1012
+	 * but just wont' do what its supposed to do? Yes -> use EE_Error::doing_it_wrong()
1013
+	 *
1014
+	 * @uses   constant WP_DEBUG test if wp_debug is on or not
1015
+	 * @param string $function      The function that was called
1016
+	 * @param string $message       A message explaining what has been done incorrectly
1017
+	 * @param string $version       The version of Event Espresso where the error was added
1018
+	 * @param string $applies_when  a version string for when you want the doing_it_wrong notice to begin appearing
1019
+	 *                              for a deprecated function. This allows deprecation to occur during one version,
1020
+	 *                              but not have any notices appear until a later version. This allows developers
1021
+	 *                              extra time to update their code before notices appear.
1022
+	 * @param int    $error_type
1023
+	 */
1024
+	public static function doing_it_wrong(
1025
+		$function,
1026
+		$message,
1027
+		$version,
1028
+		$applies_when = '',
1029
+		$error_type = null
1030
+	) {
1031
+		if (defined('WP_DEBUG') && WP_DEBUG) {
1032
+			EEH_Debug_Tools::instance()->doing_it_wrong($function, $message, $version, $applies_when, $error_type);
1033
+		}
1034
+	}
1035
+
1036
+
1037
+
1038
+	/**
1039
+	 * Like get_notices, but returns an array of all the notices of the given type.
1040
+	 *
1041
+	 * @return array {
1042
+	 *  @type array $success   all the success messages
1043
+	 *  @type array $errors    all the error messages
1044
+	 *  @type array $attention all the attention messages
1045
+	 * }
1046
+	 */
1047
+	public static function get_raw_notices()
1048
+	{
1049
+		return self::$_espresso_notices;
1050
+	}
1051
+
1052
+
1053
+
1054
+	/**
1055
+	 * @deprecated 4.9.27
1056
+	 * @param string $pan_name     the name, or key of the Persistent Admin Notice to be stored
1057
+	 * @param string $pan_message  the message to be stored persistently until dismissed
1058
+	 * @param bool   $force_update allows one to enforce the reappearance of a persistent message.
1059
+	 * @return void
1060
+	 * @throws InvalidDataTypeException
1061
+	 */
1062
+	public static function add_persistent_admin_notice($pan_name = '', $pan_message, $force_update = false)
1063
+	{
1064
+		new PersistentAdminNotice(
1065
+			$pan_name,
1066
+			$pan_message,
1067
+			$force_update
1068
+		);
1069
+		EE_Error::doing_it_wrong(
1070
+			__METHOD__,
1071
+			sprintf(
1072
+				__('Usage is deprecated. Use "%1$s" instead.', 'event_espresso'),
1073
+				'\EventEspresso\core\domain\entities\notifications\PersistentAdminNotice'
1074
+			),
1075
+			'4.9.27'
1076
+		);
1077
+	}
1078
+
1079
+
1080
+
1081
+	/**
1082
+	 * @deprecated 4.9.27
1083
+	 * @param string $pan_name the name, or key of the Persistent Admin Notice to be dismissed
1084
+	 * @param bool   $purge
1085
+	 * @param bool   $return
1086
+	 * @throws DomainException
1087
+	 * @throws InvalidInterfaceException
1088
+	 * @throws InvalidDataTypeException
1089
+	 * @throws ServiceNotFoundException
1090
+	 * @throws InvalidArgumentException
1091
+	 */
1092
+	public static function dismiss_persistent_admin_notice($pan_name = '', $purge = false, $return = false)
1093
+	{
1094
+		/** @var PersistentAdminNoticeManager $persistent_admin_notice_manager */
1095
+		$persistent_admin_notice_manager = LoaderFactory::getLoader()->getShared(
1096
+			'EventEspresso\core\services\notifications\PersistentAdminNoticeManager'
1097
+		);
1098
+		$persistent_admin_notice_manager->dismissNotice($pan_name, $purge, $return);
1099
+		EE_Error::doing_it_wrong(
1100
+			__METHOD__,
1101
+			sprintf(
1102
+				__('Usage is deprecated. Use "%1$s" instead.', 'event_espresso'),
1103
+				'\EventEspresso\core\services\notifications\PersistentAdminNoticeManager'
1104
+			),
1105
+			'4.9.27'
1106
+		);
1107
+	}
1108
+
1109
+
1110
+
1111
+	/**
1112
+	 * @deprecated 4.9.27
1113
+	 * @param  string $pan_name    the name, or key of the Persistent Admin Notice to be stored
1114
+	 * @param  string $pan_message the message to be stored persistently until dismissed
1115
+	 * @param  string $return_url  URL to go back to after nag notice is dismissed
1116
+	 */
1117
+	public static function display_persistent_admin_notices($pan_name = '', $pan_message = '', $return_url = '')
1118
+	{
1119
+		EE_Error::doing_it_wrong(
1120
+			__METHOD__,
1121
+			sprintf(
1122
+				__('Usage is deprecated. Use "%1$s" instead.', 'event_espresso'),
1123
+				'\EventEspresso\core\services\notifications\PersistentAdminNoticeManager'
1124
+			),
1125
+			'4.9.27'
1126
+		);
1127
+	}
1128
+
1129
+
1130
+
1131
+	/**
1132
+	 * @deprecated 4.9.27
1133
+	 * @param string $return_url
1134
+	 */
1135
+	public static function get_persistent_admin_notices($return_url = '')
1136
+	{
1137
+		EE_Error::doing_it_wrong(
1138
+			__METHOD__,
1139
+			sprintf(
1140
+				__('Usage is deprecated. Use "%1$s" instead.', 'event_espresso'),
1141
+				'\EventEspresso\core\services\notifications\PersistentAdminNoticeManager'
1142
+			),
1143
+			'4.9.27'
1144
+		);
1145
+	}
1146 1146
 
1147 1147
 
1148 1148
 
@@ -1157,27 +1157,27 @@  discard block
 block discarded – undo
1157 1157
  */
1158 1158
 function espresso_error_enqueue_scripts()
1159 1159
 {
1160
-    // js for error handling
1161
-    wp_register_script(
1162
-        'espresso_core',
1163
-        EE_GLOBAL_ASSETS_URL . 'scripts/espresso_core.js',
1164
-        array('jquery'),
1165
-        EVENT_ESPRESSO_VERSION,
1166
-        false
1167
-    );
1168
-    wp_register_script(
1169
-        'ee_error_js',
1170
-        EE_GLOBAL_ASSETS_URL . 'scripts/EE_Error.js',
1171
-        array('espresso_core'),
1172
-        EVENT_ESPRESSO_VERSION,
1173
-        false
1174
-    );
1160
+	// js for error handling
1161
+	wp_register_script(
1162
+		'espresso_core',
1163
+		EE_GLOBAL_ASSETS_URL . 'scripts/espresso_core.js',
1164
+		array('jquery'),
1165
+		EVENT_ESPRESSO_VERSION,
1166
+		false
1167
+	);
1168
+	wp_register_script(
1169
+		'ee_error_js',
1170
+		EE_GLOBAL_ASSETS_URL . 'scripts/EE_Error.js',
1171
+		array('espresso_core'),
1172
+		EVENT_ESPRESSO_VERSION,
1173
+		false
1174
+	);
1175 1175
 }
1176 1176
 
1177 1177
 if (is_admin()) {
1178
-    add_action('admin_enqueue_scripts', 'espresso_error_enqueue_scripts', 2);
1178
+	add_action('admin_enqueue_scripts', 'espresso_error_enqueue_scripts', 2);
1179 1179
 } else {
1180
-    add_action('wp_enqueue_scripts', 'espresso_error_enqueue_scripts', 2);
1180
+	add_action('wp_enqueue_scripts', 'espresso_error_enqueue_scripts', 2);
1181 1181
 }
1182 1182
 
1183 1183
 
Please login to merge, or discard this patch.