Completed
Branch FET-10766-extract-activation-d... (6ba6fc)
by
unknown
84:12 queued 72:44
created
core/EE_Request_Handler.core.php 1 patch
Spacing   +75 added lines, -75 removed lines patch added patch discarded remove patch
@@ -1,6 +1,6 @@  discard block
 block discarded – undo
1 1
 <?php use EventEspresso\core\interfaces\InterminableInterface;
2 2
 
3
-if ( ! defined( 'EVENT_ESPRESSO_VERSION')) {exit('No direct script access allowed');}
3
+if ( ! defined('EVENT_ESPRESSO_VERSION')) {exit('No direct script access allowed'); }
4 4
 /**
5 5
  * class EE_Request_Handler
6 6
  *
@@ -51,13 +51,13 @@  discard block
 block discarded – undo
51 51
 	 * @access public
52 52
 	 * @param  EE_Request $request
53 53
 	 */
54
-	public function __construct( EE_Request $request ) {
54
+	public function __construct(EE_Request $request) {
55 55
 		// grab request vars
56 56
 		$this->_params = $request->params();
57 57
 		// AJAX ???
58
-		$this->ajax = defined( 'DOING_AJAX' ) && DOING_AJAX ? true : false;
59
-		$this->front_ajax = defined( 'EE_FRONT_AJAX' ) && EE_FRONT_AJAX ? true : false;
60
-		do_action( 'AHEE__EE_Request_Handler__construct__complete' );
58
+		$this->ajax = defined('DOING_AJAX') && DOING_AJAX ? true : false;
59
+		$this->front_ajax = defined('EE_FRONT_AJAX') && EE_FRONT_AJAX ? true : false;
60
+		do_action('AHEE__EE_Request_Handler__construct__complete');
61 61
 	}
62 62
 
63 63
 
@@ -69,12 +69,12 @@  discard block
 block discarded – undo
69 69
 	 * @param WP $wp
70 70
 	 * @return void
71 71
 	 */
72
-	public function parse_request( $wp = null ) {
72
+	public function parse_request($wp = null) {
73 73
 		//if somebody forgot to provide us with WP, that's ok because its global
74
-		if ( ! $wp instanceof WP ) {
74
+		if ( ! $wp instanceof WP) {
75 75
 			global $wp;
76 76
 		}
77
-		$this->set_request_vars( $wp );
77
+		$this->set_request_vars($wp);
78 78
 	}
79 79
 
80 80
 
@@ -86,14 +86,14 @@  discard block
 block discarded – undo
86 86
 	 * @param WP $wp
87 87
 	 * @return void
88 88
 	 */
89
-	public function set_request_vars( $wp = null ) {
90
-		if ( ! is_admin() ) {
89
+	public function set_request_vars($wp = null) {
90
+		if ( ! is_admin()) {
91 91
 			// set request post_id
92
-			$this->set( 'post_id', $this->get_post_id_from_request( $wp ));
92
+			$this->set('post_id', $this->get_post_id_from_request($wp));
93 93
 			// set request post name
94
-			$this->set( 'post_name', $this->get_post_name_from_request( $wp ));
94
+			$this->set('post_name', $this->get_post_name_from_request($wp));
95 95
 			// set request post_type
96
-			$this->set( 'post_type', $this->get_post_type_from_request( $wp ));
96
+			$this->set('post_type', $this->get_post_type_from_request($wp));
97 97
 			// true or false ? is this page being used by EE ?
98 98
 			$this->set_espresso_page();
99 99
 		}
@@ -108,19 +108,19 @@  discard block
 block discarded – undo
108 108
 	 * @param WP $wp
109 109
 	 * @return int
110 110
 	 */
111
-	public function get_post_id_from_request( $wp = null ) {
112
-		if ( ! $wp instanceof WP ){
111
+	public function get_post_id_from_request($wp = null) {
112
+		if ( ! $wp instanceof WP) {
113 113
 			global $wp;
114 114
 		}
115 115
 		$post_id = null;
116
-		if ( isset( $wp->query_vars['p'] )) {
116
+		if (isset($wp->query_vars['p'])) {
117 117
 			$post_id = $wp->query_vars['p'];
118 118
 		}
119
-		if ( ! $post_id && isset( $wp->query_vars['page_id'] )) {
119
+		if ( ! $post_id && isset($wp->query_vars['page_id'])) {
120 120
 			$post_id = $wp->query_vars['page_id'];
121 121
 		}
122
-		if ( ! $post_id && isset( $wp->request ) && is_numeric( basename( $wp->request ))) {
123
-			$post_id = basename( $wp->request );
122
+		if ( ! $post_id && isset($wp->request) && is_numeric(basename($wp->request))) {
123
+			$post_id = basename($wp->request);
124 124
 		}
125 125
 		return $post_id;
126 126
 	}
@@ -134,35 +134,35 @@  discard block
 block discarded – undo
134 134
 	 * @param WP $wp
135 135
 	 * @return string
136 136
 	 */
137
-	public function get_post_name_from_request( $wp = null ) {
138
-		if ( ! $wp instanceof WP ){
137
+	public function get_post_name_from_request($wp = null) {
138
+		if ( ! $wp instanceof WP) {
139 139
 			global $wp;
140 140
 		}
141 141
 		$post_name = null;
142
-		if ( isset( $wp->query_vars['name'] ) && ! empty( $wp->query_vars['name'] )) {
142
+		if (isset($wp->query_vars['name']) && ! empty($wp->query_vars['name'])) {
143 143
 			$post_name = $wp->query_vars['name'];
144 144
 		}
145
-		if ( ! $post_name && isset( $wp->query_vars['pagename'] ) && ! empty( $wp->query_vars['pagename'] )) {
145
+		if ( ! $post_name && isset($wp->query_vars['pagename']) && ! empty($wp->query_vars['pagename'])) {
146 146
 			$post_name = $wp->query_vars['pagename'];
147 147
 		}
148
-		if ( ! $post_name && isset( $wp->request ) && ! empty( $wp->request )) {
149
-			$possible_post_name = basename( $wp->request );
150
-			if ( ! is_numeric( $possible_post_name )) {
148
+		if ( ! $post_name && isset($wp->request) && ! empty($wp->request)) {
149
+			$possible_post_name = basename($wp->request);
150
+			if ( ! is_numeric($possible_post_name)) {
151 151
 				/** @type WPDB $wpdb */
152 152
 				global $wpdb;
153 153
 				$SQL = "SELECT ID from {$wpdb->posts} WHERE post_status='publish' AND post_name=%s";
154
-				$possible_post_name = $wpdb->get_var( $wpdb->prepare( $SQL, $possible_post_name ));
155
-				if ( $possible_post_name ) {
154
+				$possible_post_name = $wpdb->get_var($wpdb->prepare($SQL, $possible_post_name));
155
+				if ($possible_post_name) {
156 156
 					$post_name = $possible_post_name;
157 157
 				}
158 158
 			}
159 159
 		}
160
-		if ( ! $post_name && $this->get( 'post_id' )) {
160
+		if ( ! $post_name && $this->get('post_id')) {
161 161
 			/** @type WPDB $wpdb */
162 162
 			global $wpdb;
163 163
 			$SQL = "SELECT post_name from {$wpdb->posts} WHERE post_status='publish' AND ID=%d";
164
-			$possible_post_name = $wpdb->get_var( $wpdb->prepare( $SQL, $this->get( 'post_id' )));
165
-			if( $possible_post_name ) {
164
+			$possible_post_name = $wpdb->get_var($wpdb->prepare($SQL, $this->get('post_id')));
165
+			if ($possible_post_name) {
166 166
 				$post_name = $possible_post_name;
167 167
 			}
168 168
 		}
@@ -178,11 +178,11 @@  discard block
 block discarded – undo
178 178
 	 * @param WP $wp
179 179
 	 * @return mixed
180 180
 	 */
181
-	public function get_post_type_from_request( $wp = null ) {
182
-		if ( ! $wp instanceof WP ){
181
+	public function get_post_type_from_request($wp = null) {
182
+		if ( ! $wp instanceof WP) {
183 183
 			global $wp;
184 184
 		}
185
-		return isset( $wp->query_vars['post_type'] ) ? $wp->query_vars['post_type'] : null;
185
+		return isset($wp->query_vars['post_type']) ? $wp->query_vars['post_type'] : null;
186 186
 	}
187 187
 
188 188
 
@@ -192,18 +192,18 @@  discard block
 block discarded – undo
192 192
 	 * @param  WP $wp
193 193
 	 * @return string
194 194
 	 */
195
-	public function get_current_page_permalink( $wp = null ) {
196
-		$post_id = $this->get_post_id_from_request( $wp );
197
-		if ( $post_id ) {
198
-			$current_page_permalink = get_permalink( $post_id );
195
+	public function get_current_page_permalink($wp = null) {
196
+		$post_id = $this->get_post_id_from_request($wp);
197
+		if ($post_id) {
198
+			$current_page_permalink = get_permalink($post_id);
199 199
 		} else {
200
-			if ( ! $wp instanceof WP ) {
200
+			if ( ! $wp instanceof WP) {
201 201
 				global $wp;
202 202
 			}
203
-			if ( $wp->request ) {
204
-				$current_page_permalink = site_url( $wp->request );
203
+			if ($wp->request) {
204
+				$current_page_permalink = site_url($wp->request);
205 205
 			} else {
206
-				$current_page_permalink = esc_url( site_url( $_SERVER[ 'REQUEST_URI' ] ) );
206
+				$current_page_permalink = esc_url(site_url($_SERVER['REQUEST_URI']));
207 207
 			}
208 208
 		}
209 209
 		return $current_page_permalink;
@@ -220,31 +220,31 @@  discard block
 block discarded – undo
220 220
 	public function test_for_espresso_page() {
221 221
 		global $wp;
222 222
 		/** @type EE_CPT_Strategy $EE_CPT_Strategy */
223
-		$EE_CPT_Strategy = EE_Registry::instance()->load_core( 'CPT_Strategy' );
223
+		$EE_CPT_Strategy = EE_Registry::instance()->load_core('CPT_Strategy');
224 224
 		$espresso_CPT_taxonomies = $EE_CPT_Strategy->get_CPT_taxonomies();
225
-		if ( is_array( $espresso_CPT_taxonomies ) ) {
226
-			foreach ( $espresso_CPT_taxonomies as $espresso_CPT_taxonomy =>$details ) {
227
-				if ( isset( $wp->query_vars, $wp->query_vars[ $espresso_CPT_taxonomy ] ) ) {
225
+		if (is_array($espresso_CPT_taxonomies)) {
226
+			foreach ($espresso_CPT_taxonomies as $espresso_CPT_taxonomy =>$details) {
227
+				if (isset($wp->query_vars, $wp->query_vars[$espresso_CPT_taxonomy])) {
228 228
 					return true;
229 229
 				}
230 230
 			}
231 231
 		}
232 232
 		// load espresso CPT endpoints
233 233
 		$espresso_CPT_endpoints = $EE_CPT_Strategy->get_CPT_endpoints();
234
-		$post_type_CPT_endpoints = array_flip( $espresso_CPT_endpoints );
235
-		$post_types = (array)$this->get( 'post_type' );
236
-		foreach ( $post_types as $post_type ) {
234
+		$post_type_CPT_endpoints = array_flip($espresso_CPT_endpoints);
235
+		$post_types = (array) $this->get('post_type');
236
+		foreach ($post_types as $post_type) {
237 237
 			// was a post name passed ?
238
-			if ( isset( $post_type_CPT_endpoints[ $post_type ] ) ) {
238
+			if (isset($post_type_CPT_endpoints[$post_type])) {
239 239
 				// kk we know this is an espresso page, but is it a specific post ?
240
-				if ( ! $this->get( 'post_name' ) ) {
240
+				if ( ! $this->get('post_name')) {
241 241
 					// there's no specific post name set, so maybe it's one of our endpoints like www.domain.com/events
242
-					$post_name = isset( $post_type_CPT_endpoints[ $this->get( 'post_type' ) ] )
243
-                        ? $post_type_CPT_endpoints[ $this->get( 'post_type' ) ]
242
+					$post_name = isset($post_type_CPT_endpoints[$this->get('post_type')])
243
+                        ? $post_type_CPT_endpoints[$this->get('post_type')]
244 244
                         : '';
245 245
 					// if the post type matches on of our then set the endpoint
246
-					if ( $post_name ) {
247
-						$this->set( 'post_name', $post_name );
246
+					if ($post_name) {
247
+						$this->set('post_name', $post_name);
248 248
 					}
249 249
 				}
250 250
 				return true;
@@ -262,7 +262,7 @@  discard block
 block discarded – undo
262 262
 	 * @param null|bool $value
263 263
 	 * @return    void
264 264
 	 */
265
-	public function set_espresso_page( $value = null ) {
265
+	public function set_espresso_page($value = null) {
266 266
         $this->_params['is_espresso_page'] = ! empty($value) ? $value : $this->test_for_espresso_page();
267 267
 	}
268 268
 
@@ -275,7 +275,7 @@  discard block
 block discarded – undo
275 275
 	 *  @return 	mixed
276 276
 	 */
277 277
 	public function is_espresso_page() {
278
-		return isset( $this->_params['is_espresso_page'] ) ? $this->_params['is_espresso_page'] : false;
278
+		return isset($this->_params['is_espresso_page']) ? $this->_params['is_espresso_page'] : false;
279 279
 	}
280 280
 
281 281
 
@@ -299,14 +299,14 @@  discard block
 block discarded – undo
299 299
 	 * @param bool $override_ee
300 300
 	 * @return    void
301 301
 	 */
302
-	public function set( $key, $value, $override_ee = false ) {
302
+	public function set($key, $value, $override_ee = false) {
303 303
 		// don't allow "ee" to be overwritten unless explicitly instructed to do so
304 304
 		if (
305 305
 			$key !== 'ee' ||
306
-			( $key === 'ee' && empty( $this->_params['ee'] ))
307
-			|| ( $key === 'ee' && ! empty( $this->_params['ee'] ) && $override_ee )
306
+			($key === 'ee' && empty($this->_params['ee']))
307
+			|| ($key === 'ee' && ! empty($this->_params['ee']) && $override_ee)
308 308
 		) {
309
-			$this->_params[ $key ] = $value;
309
+			$this->_params[$key] = $value;
310 310
 		}
311 311
 	}
312 312
 
@@ -320,8 +320,8 @@  discard block
 block discarded – undo
320 320
 	 * @param null $default
321 321
 	 * @return    mixed
322 322
 	 */
323
-	public function get( $key, $default = null ) {
324
-		return isset( $this->_params[ $key ] ) ? $this->_params[ $key ] : $default;
323
+	public function get($key, $default = null) {
324
+		return isset($this->_params[$key]) ? $this->_params[$key] : $default;
325 325
 	}
326 326
 
327 327
 
@@ -333,8 +333,8 @@  discard block
 block discarded – undo
333 333
 	 * @param $key
334 334
 	 * @return    boolean
335 335
 	 */
336
-	public function is_set( $key ) {
337
-		return isset( $this->_params[ $key ] ) ? true : false;
336
+	public function is_set($key) {
337
+		return isset($this->_params[$key]) ? true : false;
338 338
 	}
339 339
 
340 340
 
@@ -346,8 +346,8 @@  discard block
 block discarded – undo
346 346
 	 * @param $key
347 347
 	 * @return    void
348 348
 	 */
349
-	public function un_set( $key ) {
350
-		unset( $this->_params[ $key ] );
349
+	public function un_set($key) {
350
+		unset($this->_params[$key]);
351 351
 	}
352 352
 
353 353
 
@@ -360,8 +360,8 @@  discard block
 block discarded – undo
360 360
 	 * @param $value
361 361
 	 * @return    void
362 362
 	 */
363
-	public function set_notice( $key, $value ) {
364
-		$this->_notice[ $key ] = $value;
363
+	public function set_notice($key, $value) {
364
+		$this->_notice[$key] = $value;
365 365
 	}
366 366
 
367 367
 
@@ -373,8 +373,8 @@  discard block
 block discarded – undo
373 373
 	 * @param $key
374 374
 	 * @return    mixed
375 375
 	 */
376
-	public function get_notice( $key ) {
377
-		return isset( $this->_notice[ $key ] ) ? $this->_notice[ $key ] : null;
376
+	public function get_notice($key) {
377
+		return isset($this->_notice[$key]) ? $this->_notice[$key] : null;
378 378
 	}
379 379
 
380 380
 
@@ -386,7 +386,7 @@  discard block
 block discarded – undo
386 386
 	 * @param $string
387 387
 	 * @return    void
388 388
 	 */
389
-	public function add_output( $string ) {
389
+	public function add_output($string) {
390 390
 		$this->_output .= $string;
391 391
 	}
392 392
 
@@ -408,8 +408,8 @@  discard block
 block discarded – undo
408 408
 	 * @param $item
409 409
 	 * @param $key
410 410
 	 */
411
-	public function sanitize_text_field_for_array_walk( &$item, &$key ) {
412
-		$item = strpos( $item, 'email' ) !== false ? sanitize_email( $item ) : sanitize_text_field( $item );
411
+	public function sanitize_text_field_for_array_walk(&$item, &$key) {
412
+		$item = strpos($item, 'email') !== false ? sanitize_email($item) : sanitize_text_field($item);
413 413
 	}
414 414
 
415 415
 
@@ -419,7 +419,7 @@  discard block
 block discarded – undo
419 419
 	 * @param $b
420 420
 	 * @return bool
421 421
 	 */
422
-	public function __set($a,$b) { return false; }
422
+	public function __set($a, $b) { return false; }
423 423
 
424 424
 
425 425
 
Please login to merge, or discard this patch.
core/EE_Config.core.php 1 patch
Indentation   +3061 added lines, -3061 removed lines patch added patch discarded remove patch
@@ -17,2443 +17,2443 @@  discard block
 block discarded – undo
17 17
 final class EE_Config implements ResettableInterface
18 18
 {
19 19
 
20
-    const OPTION_NAME        = 'ee_config';
20
+	const OPTION_NAME        = 'ee_config';
21
+
22
+	const LOG_NAME           = 'ee_config_log';
23
+
24
+	const LOG_LENGTH         = 100;
25
+
26
+	const ADDON_OPTION_NAMES = 'ee_config_option_names';
27
+
28
+
29
+	/**
30
+	 *    instance of the EE_Config object
31
+	 *
32
+	 * @var    EE_Config $_instance
33
+	 * @access    private
34
+	 */
35
+	private static $_instance;
36
+
37
+	/**
38
+	 * @var boolean $_logging_enabled
39
+	 */
40
+	private static $_logging_enabled = false;
41
+
42
+	/**
43
+	 * @var LegacyShortcodesManager $legacy_shortcodes_manager
44
+	 */
45
+	private $legacy_shortcodes_manager;
46
+
47
+	/**
48
+	 * An StdClass whose property names are addon slugs,
49
+	 * and values are their config classes
50
+	 *
51
+	 * @var StdClass
52
+	 */
53
+	public $addons;
54
+
55
+	/**
56
+	 * @var EE_Admin_Config
57
+	 */
58
+	public $admin;
59
+
60
+	/**
61
+	 * @var EE_Core_Config
62
+	 */
63
+	public $core;
64
+
65
+	/**
66
+	 * @var EE_Currency_Config
67
+	 */
68
+	public $currency;
69
+
70
+	/**
71
+	 * @var EE_Organization_Config
72
+	 */
73
+	public $organization;
74
+
75
+	/**
76
+	 * @var EE_Registration_Config
77
+	 */
78
+	public $registration;
79
+
80
+	/**
81
+	 * @var EE_Template_Config
82
+	 */
83
+	public $template_settings;
84
+
85
+	/**
86
+	 * Holds EE environment values.
87
+	 *
88
+	 * @var EE_Environment_Config
89
+	 */
90
+	public $environment;
91
+
92
+	/**
93
+	 * settings pertaining to Google maps
94
+	 *
95
+	 * @var EE_Map_Config
96
+	 */
97
+	public $map_settings;
98
+
99
+	/**
100
+	 * settings pertaining to Taxes
101
+	 *
102
+	 * @var EE_Tax_Config
103
+	 */
104
+	public $tax_settings;
105
+
106
+
107
+	/**
108
+	 * Settings pertaining to global messages settings.
109
+	 *
110
+	 * @var EE_Messages_Config
111
+	 */
112
+	public $messages;
113
+
114
+	/**
115
+	 * @deprecated
116
+	 * @var EE_Gateway_Config
117
+	 */
118
+	public $gateway;
119
+
120
+	/**
121
+	 * @var    array $_addon_option_names
122
+	 * @access    private
123
+	 */
124
+	private $_addon_option_names = array();
125
+
126
+	/**
127
+	 * @var    array $_module_route_map
128
+	 * @access    private
129
+	 */
130
+	private static $_module_route_map = array();
131
+
132
+	/**
133
+	 * @var    array $_module_forward_map
134
+	 * @access    private
135
+	 */
136
+	private static $_module_forward_map = array();
137
+
138
+	/**
139
+	 * @var    array $_module_view_map
140
+	 * @access    private
141
+	 */
142
+	private static $_module_view_map = array();
143
+
144
+
145
+
146
+	/**
147
+	 * @singleton method used to instantiate class object
148
+	 * @access    public
149
+	 * @return EE_Config instance
150
+	 */
151
+	public static function instance()
152
+	{
153
+		// check if class object is instantiated, and instantiated properly
154
+		if (! self::$_instance instanceof EE_Config) {
155
+			self::$_instance = new self();
156
+		}
157
+		return self::$_instance;
158
+	}
159
+
160
+
161
+
162
+	/**
163
+	 * Resets the config
164
+	 *
165
+	 * @param bool    $hard_reset    if TRUE, sets EE_CONFig back to its original settings in the database. If FALSE
166
+	 *                               (default) leaves the database alone, and merely resets the EE_Config object to
167
+	 *                               reflect its state in the database
168
+	 * @param boolean $reinstantiate if TRUE (default) call instance() and return it. Otherwise, just leave
169
+	 *                               $_instance as NULL. Useful in case you want to forget about the old instance on
170
+	 *                               EE_Config, but might not be ready to instantiate EE_Config currently (eg if the
171
+	 *                               site was put into maintenance mode)
172
+	 * @return EE_Config
173
+	 */
174
+	public static function reset($hard_reset = false, $reinstantiate = true)
175
+	{
176
+		if (self::$_instance instanceof EE_Config) {
177
+			if ($hard_reset) {
178
+				self::$_instance->legacy_shortcodes_manager = null;
179
+				self::$_instance->_addon_option_names = array();
180
+				self::$_instance->_initialize_config();
181
+				self::$_instance->update_espresso_config();
182
+			}
183
+			self::$_instance->update_addon_option_names();
184
+		}
185
+		self::$_instance = null;
186
+		//we don't need to reset the static properties imo because those should
187
+		//only change when a module is added or removed. Currently we don't
188
+		//support removing a module during a request when it previously existed
189
+		if ($reinstantiate) {
190
+			return self::instance();
191
+		} else {
192
+			return null;
193
+		}
194
+	}
195
+
196
+
197
+
198
+	/**
199
+	 *    class constructor
200
+	 *
201
+	 * @access    private
202
+	 */
203
+	private function __construct()
204
+	{
205
+		do_action('AHEE__EE_Config__construct__begin', $this);
206
+		EE_Config::$_logging_enabled = apply_filters('FHEE__EE_Config___construct__logging_enabled', false);
207
+		// setup empty config classes
208
+		$this->_initialize_config();
209
+		// load existing EE site settings
210
+		$this->_load_core_config();
211
+		// confirm everything loaded correctly and set filtered defaults if not
212
+		$this->_verify_config();
213
+		//  register shortcodes and modules
214
+		add_action(
215
+			'AHEE__EE_System__register_shortcodes_modules_and_widgets',
216
+			array($this, 'register_shortcodes_and_modules'),
217
+			999
218
+		);
219
+		//  initialize shortcodes and modules
220
+		add_action('AHEE__EE_System__core_loaded_and_ready', array($this, 'initialize_shortcodes_and_modules'));
221
+		// register widgets
222
+		add_action('widgets_init', array($this, 'widgets_init'), 10);
223
+		// shutdown
224
+		add_action('shutdown', array($this, 'shutdown'), 10);
225
+		// construct__end hook
226
+		do_action('AHEE__EE_Config__construct__end', $this);
227
+		// hardcoded hack
228
+		$this->template_settings->current_espresso_theme = 'Espresso_Arabica_2014';
229
+	}
230
+
231
+
232
+
233
+	/**
234
+	 * @return boolean
235
+	 */
236
+	public static function logging_enabled()
237
+	{
238
+		return self::$_logging_enabled;
239
+	}
240
+
241
+
242
+
243
+	/**
244
+	 * use to get the current theme if needed from static context
245
+	 *
246
+	 * @return string current theme set.
247
+	 */
248
+	public static function get_current_theme()
249
+	{
250
+		return isset(self::$_instance->template_settings->current_espresso_theme)
251
+			? self::$_instance->template_settings->current_espresso_theme : 'Espresso_Arabica_2014';
252
+	}
253
+
254
+
255
+
256
+	/**
257
+	 *        _initialize_config
258
+	 *
259
+	 * @access private
260
+	 * @return void
261
+	 */
262
+	private function _initialize_config()
263
+	{
264
+		EE_Config::trim_log();
265
+		//set defaults
266
+		$this->_addon_option_names = get_option(EE_Config::ADDON_OPTION_NAMES, array());
267
+		$this->addons = new stdClass();
268
+		// set _module_route_map
269
+		EE_Config::$_module_route_map = array();
270
+		// set _module_forward_map
271
+		EE_Config::$_module_forward_map = array();
272
+		// set _module_view_map
273
+		EE_Config::$_module_view_map = array();
274
+	}
275
+
276
+
277
+
278
+	/**
279
+	 *        load core plugin configuration
280
+	 *
281
+	 * @access private
282
+	 * @return void
283
+	 */
284
+	private function _load_core_config()
285
+	{
286
+		// load_core_config__start hook
287
+		do_action('AHEE__EE_Config___load_core_config__start', $this);
288
+		$espresso_config = $this->get_espresso_config();
289
+		foreach ($espresso_config as $config => $settings) {
290
+			// load_core_config__start hook
291
+			$settings = apply_filters(
292
+				'FHEE__EE_Config___load_core_config__config_settings',
293
+				$settings,
294
+				$config,
295
+				$this
296
+			);
297
+			if (is_object($settings) && property_exists($this, $config)) {
298
+				$this->{$config} = apply_filters('FHEE__EE_Config___load_core_config__' . $config, $settings);
299
+				//call configs populate method to ensure any defaults are set for empty values.
300
+				if (method_exists($settings, 'populate')) {
301
+					$this->{$config}->populate();
302
+				}
303
+				if (method_exists($settings, 'do_hooks')) {
304
+					$this->{$config}->do_hooks();
305
+				}
306
+			}
307
+		}
308
+		if (apply_filters('FHEE__EE_Config___load_core_config__update_espresso_config', false)) {
309
+			$this->update_espresso_config();
310
+		}
311
+		// load_core_config__end hook
312
+		do_action('AHEE__EE_Config___load_core_config__end', $this);
313
+	}
314
+
315
+
316
+
317
+	/**
318
+	 *    _verify_config
319
+	 *
320
+	 * @access    protected
321
+	 * @return    void
322
+	 */
323
+	protected function _verify_config()
324
+	{
325
+		$this->core = $this->core instanceof EE_Core_Config
326
+			? $this->core
327
+			: new EE_Core_Config();
328
+		$this->core = apply_filters('FHEE__EE_Config___initialize_config__core', $this->core);
329
+		$this->organization = $this->organization instanceof EE_Organization_Config
330
+			? $this->organization
331
+			: new EE_Organization_Config();
332
+		$this->organization = apply_filters(
333
+			'FHEE__EE_Config___initialize_config__organization',
334
+			$this->organization
335
+		);
336
+		$this->currency = $this->currency instanceof EE_Currency_Config
337
+			? $this->currency
338
+			: new EE_Currency_Config();
339
+		$this->currency = apply_filters('FHEE__EE_Config___initialize_config__currency', $this->currency);
340
+		$this->registration = $this->registration instanceof EE_Registration_Config
341
+			? $this->registration
342
+			: new EE_Registration_Config();
343
+		$this->registration = apply_filters(
344
+			'FHEE__EE_Config___initialize_config__registration',
345
+			$this->registration
346
+		);
347
+		$this->admin = $this->admin instanceof EE_Admin_Config
348
+			? $this->admin
349
+			: new EE_Admin_Config();
350
+		$this->admin = apply_filters('FHEE__EE_Config___initialize_config__admin', $this->admin);
351
+		$this->template_settings = $this->template_settings instanceof EE_Template_Config
352
+			? $this->template_settings
353
+			: new EE_Template_Config();
354
+		$this->template_settings = apply_filters(
355
+			'FHEE__EE_Config___initialize_config__template_settings',
356
+			$this->template_settings
357
+		);
358
+		$this->map_settings = $this->map_settings instanceof EE_Map_Config
359
+			? $this->map_settings
360
+			: new EE_Map_Config();
361
+		$this->map_settings = apply_filters('FHEE__EE_Config___initialize_config__map_settings',
362
+			$this->map_settings);
363
+		$this->environment = $this->environment instanceof EE_Environment_Config
364
+			? $this->environment
365
+			: new EE_Environment_Config();
366
+		$this->environment = apply_filters('FHEE__EE_Config___initialize_config__environment',
367
+			$this->environment);
368
+		$this->tax_settings = $this->tax_settings instanceof EE_Tax_Config
369
+			? $this->tax_settings
370
+			: new EE_Tax_Config();
371
+		$this->tax_settings = apply_filters('FHEE__EE_Config___initialize_config__tax_settings',
372
+			$this->tax_settings);
373
+		$this->messages = apply_filters('FHEE__EE_Config__initialize_config__messages', $this->messages);
374
+		$this->messages = $this->messages instanceof EE_Messages_Config
375
+			? $this->messages
376
+			: new EE_Messages_Config();
377
+		$this->gateway = $this->gateway instanceof EE_Gateway_Config
378
+			? $this->gateway
379
+			: new EE_Gateway_Config();
380
+		$this->gateway = apply_filters('FHEE__EE_Config___initialize_config__gateway', $this->gateway);
381
+		$this->legacy_shortcodes_manager = null;
382
+	}
383
+
384
+
385
+	/**
386
+	 *    get_espresso_config
387
+	 *
388
+	 * @access    public
389
+	 * @return    array of espresso config stuff
390
+	 */
391
+	public function get_espresso_config()
392
+	{
393
+		// grab espresso configuration
394
+		return apply_filters(
395
+			'FHEE__EE_Config__get_espresso_config__CFG',
396
+			get_option(EE_Config::OPTION_NAME, array())
397
+		);
398
+	}
399
+
400
+
401
+
402
+	/**
403
+	 *    double_check_config_comparison
404
+	 *
405
+	 * @access    public
406
+	 * @param string $option
407
+	 * @param        $old_value
408
+	 * @param        $value
409
+	 */
410
+	public function double_check_config_comparison($option = '', $old_value, $value)
411
+	{
412
+		// make sure we're checking the ee config
413
+		if ($option === EE_Config::OPTION_NAME) {
414
+			// run a loose comparison of the old value against the new value for type and properties,
415
+			// but NOT exact instance like WP update_option does (ie: NOT type safe comparison)
416
+			if ($value != $old_value) {
417
+				// if they are NOT the same, then remove the hook,
418
+				// which means the subsequent update results will be based solely on the update query results
419
+				// the reason we do this is because, as stated above,
420
+				// WP update_option performs an exact instance comparison (===) on any update values passed to it
421
+				// this happens PRIOR to serialization and any subsequent update.
422
+				// If values are found to match their previous old value,
423
+				// then WP bails before performing any update.
424
+				// Since we are passing the EE_Config object, it is comparing the EXACT instance of the saved version
425
+				// it just pulled from the db, with the one being passed to it (which will not match).
426
+				// HOWEVER, once the object is serialized and passed off to MySQL to update,
427
+				// MySQL MAY ALSO NOT perform the update because
428
+				// the string it sees in the db looks the same as the new one it has been passed!!!
429
+				// This results in the query returning an "affected rows" value of ZERO,
430
+				// which gets returned immediately by WP update_option and looks like an error.
431
+				remove_action('update_option', array($this, 'check_config_updated'));
432
+			}
433
+		}
434
+	}
435
+
436
+
437
+
438
+	/**
439
+	 *    update_espresso_config
440
+	 *
441
+	 * @access   public
442
+	 */
443
+	protected function _reset_espresso_addon_config()
444
+	{
445
+		$this->_addon_option_names = array();
446
+		foreach ($this->addons as $addon_name => $addon_config_obj) {
447
+			$addon_config_obj = maybe_unserialize($addon_config_obj);
448
+			$config_class = get_class($addon_config_obj);
449
+			if ($addon_config_obj instanceof $config_class && ! $addon_config_obj instanceof __PHP_Incomplete_Class) {
450
+				$this->update_config('addons', $addon_name, $addon_config_obj, false);
451
+			}
452
+			$this->addons->{$addon_name} = null;
453
+		}
454
+	}
455
+
456
+
457
+
458
+	/**
459
+	 *    update_espresso_config
460
+	 *
461
+	 * @access   public
462
+	 * @param   bool $add_success
463
+	 * @param   bool $add_error
464
+	 * @return   bool
465
+	 */
466
+	public function update_espresso_config($add_success = false, $add_error = true)
467
+	{
468
+		// don't allow config updates during WP heartbeats
469
+		if (\EE_Registry::instance()->REQ->get('action', '') === 'heartbeat') {
470
+			return false;
471
+		}
472
+		// commented out the following re: https://events.codebasehq.com/projects/event-espresso/tickets/8197
473
+		//$clone = clone( self::$_instance );
474
+		//self::$_instance = NULL;
475
+		do_action('AHEE__EE_Config__update_espresso_config__begin', $this);
476
+		$this->_reset_espresso_addon_config();
477
+		// hook into update_option because that happens AFTER the ( $value === $old_value ) conditional
478
+		// but BEFORE the actual update occurs
479
+		add_action('update_option', array($this, 'double_check_config_comparison'), 1, 3);
480
+		// don't want to persist legacy_shortcodes_manager, but don't want to lose it either
481
+		$legacy_shortcodes_manager = $this->legacy_shortcodes_manager;
482
+		$this->legacy_shortcodes_manager = null;
483
+		// now update "ee_config"
484
+		$saved = update_option(EE_Config::OPTION_NAME, $this);
485
+		$this->legacy_shortcodes_manager = $legacy_shortcodes_manager;
486
+		EE_Config::log(EE_Config::OPTION_NAME);
487
+		// if not saved... check if the hook we just added still exists;
488
+		// if it does, it means one of two things:
489
+		// 		that update_option bailed at the ( $value === $old_value ) conditional,
490
+		//		 or...
491
+		// 		the db update query returned 0 rows affected
492
+		// 		(probably because the data  value was the same from it's perspective)
493
+		// so the existence of the hook means that a negative result from update_option is NOT an error,
494
+		// but just means no update occurred, so don't display an error to the user.
495
+		// BUT... if update_option returns FALSE, AND the hook is missing,
496
+		// then it means that something truly went wrong
497
+		$saved = ! $saved ? has_action('update_option', array($this, 'double_check_config_comparison')) : $saved;
498
+		// remove our action since we don't want it in the system anymore
499
+		remove_action('update_option', array($this, 'double_check_config_comparison'), 1);
500
+		do_action('AHEE__EE_Config__update_espresso_config__end', $this, $saved);
501
+		//self::$_instance = $clone;
502
+		//unset( $clone );
503
+		// if config remains the same or was updated successfully
504
+		if ($saved) {
505
+			if ($add_success) {
506
+				EE_Error::add_success(
507
+					__('The Event Espresso Configuration Settings have been successfully updated.', 'event_espresso'),
508
+					__FILE__,
509
+					__FUNCTION__,
510
+					__LINE__
511
+				);
512
+			}
513
+			return true;
514
+		} else {
515
+			if ($add_error) {
516
+				EE_Error::add_error(
517
+					__('The Event Espresso Configuration Settings were not updated.', 'event_espresso'),
518
+					__FILE__,
519
+					__FUNCTION__,
520
+					__LINE__
521
+				);
522
+			}
523
+			return false;
524
+		}
525
+	}
526
+
527
+
528
+
529
+	/**
530
+	 *    _verify_config_params
531
+	 *
532
+	 * @access    private
533
+	 * @param    string         $section
534
+	 * @param    string         $name
535
+	 * @param    string         $config_class
536
+	 * @param    EE_Config_Base $config_obj
537
+	 * @param    array          $tests_to_run
538
+	 * @param    bool           $display_errors
539
+	 * @return    bool    TRUE on success, FALSE on fail
540
+	 */
541
+	private function _verify_config_params(
542
+		$section = '',
543
+		$name = '',
544
+		$config_class = '',
545
+		$config_obj = null,
546
+		$tests_to_run = array(1, 2, 3, 4, 5, 6, 7, 8),
547
+		$display_errors = true
548
+	) {
549
+		try {
550
+			foreach ($tests_to_run as $test) {
551
+				switch ($test) {
552
+					// TEST #1 : check that section was set
553
+					case 1 :
554
+						if (empty($section)) {
555
+							if ($display_errors) {
556
+								throw new EE_Error(
557
+									sprintf(
558
+										__(
559
+											'No configuration section has been provided while attempting to save "%s".',
560
+											'event_espresso'
561
+										),
562
+										$config_class
563
+									)
564
+								);
565
+							}
566
+							return false;
567
+						}
568
+						break;
569
+					// TEST #2 : check that settings section exists
570
+					case 2 :
571
+						if (! isset($this->{$section})) {
572
+							if ($display_errors) {
573
+								throw new EE_Error(
574
+									sprintf(
575
+										__('The "%s" configuration section does not exist.', 'event_espresso'),
576
+										$section
577
+									)
578
+								);
579
+							}
580
+							return false;
581
+						}
582
+						break;
583
+					// TEST #3 : check that section is the proper format
584
+					case 3 :
585
+						if (
586
+						! ($this->{$section} instanceof EE_Config_Base || $this->{$section} instanceof stdClass)
587
+						) {
588
+							if ($display_errors) {
589
+								throw new EE_Error(
590
+									sprintf(
591
+										__(
592
+											'The "%s" configuration settings have not been formatted correctly.',
593
+											'event_espresso'
594
+										),
595
+										$section
596
+									)
597
+								);
598
+							}
599
+							return false;
600
+						}
601
+						break;
602
+					// TEST #4 : check that config section name has been set
603
+					case 4 :
604
+						if (empty($name)) {
605
+							if ($display_errors) {
606
+								throw new EE_Error(
607
+									__(
608
+										'No name has been provided for the specific configuration section.',
609
+										'event_espresso'
610
+									)
611
+								);
612
+							}
613
+							return false;
614
+						}
615
+						break;
616
+					// TEST #5 : check that a config class name has been set
617
+					case 5 :
618
+						if (empty($config_class)) {
619
+							if ($display_errors) {
620
+								throw new EE_Error(
621
+									__(
622
+										'No class name has been provided for the specific configuration section.',
623
+										'event_espresso'
624
+									)
625
+								);
626
+							}
627
+							return false;
628
+						}
629
+						break;
630
+					// TEST #6 : verify config class is accessible
631
+					case 6 :
632
+						if (! class_exists($config_class)) {
633
+							if ($display_errors) {
634
+								throw new EE_Error(
635
+									sprintf(
636
+										__(
637
+											'The "%s" class does not exist. Please ensure that an autoloader has been set for it.',
638
+											'event_espresso'
639
+										),
640
+										$config_class
641
+									)
642
+								);
643
+							}
644
+							return false;
645
+						}
646
+						break;
647
+					// TEST #7 : check that config has even been set
648
+					case 7 :
649
+						if (! isset($this->{$section}->{$name})) {
650
+							if ($display_errors) {
651
+								throw new EE_Error(
652
+									sprintf(
653
+										__('No configuration has been set for "%1$s->%2$s".', 'event_espresso'),
654
+										$section,
655
+										$name
656
+									)
657
+								);
658
+							}
659
+							return false;
660
+						} else {
661
+							// and make sure it's not serialized
662
+							$this->{$section}->{$name} = maybe_unserialize($this->{$section}->{$name});
663
+						}
664
+						break;
665
+					// TEST #8 : check that config is the requested type
666
+					case 8 :
667
+						if (! $this->{$section}->{$name} instanceof $config_class) {
668
+							if ($display_errors) {
669
+								throw new EE_Error(
670
+									sprintf(
671
+										__(
672
+											'The configuration for "%1$s->%2$s" is not of the "%3$s" class.',
673
+											'event_espresso'
674
+										),
675
+										$section,
676
+										$name,
677
+										$config_class
678
+									)
679
+								);
680
+							}
681
+							return false;
682
+						}
683
+						break;
684
+					// TEST #9 : verify config object
685
+					case 9 :
686
+						if (! $config_obj instanceof EE_Config_Base) {
687
+							if ($display_errors) {
688
+								throw new EE_Error(
689
+									sprintf(
690
+										__('The "%s" class is not an instance of EE_Config_Base.', 'event_espresso'),
691
+										print_r($config_obj, true)
692
+									)
693
+								);
694
+							}
695
+							return false;
696
+						}
697
+						break;
698
+				}
699
+			}
700
+		} catch (EE_Error $e) {
701
+			$e->get_error();
702
+		}
703
+		// you have successfully run the gauntlet
704
+		return true;
705
+	}
706
+
707
+
708
+
709
+	/**
710
+	 *    _generate_config_option_name
711
+	 *
712
+	 * @access        protected
713
+	 * @param        string $section
714
+	 * @param        string $name
715
+	 * @return        string
716
+	 */
717
+	private function _generate_config_option_name($section = '', $name = '')
718
+	{
719
+		return 'ee_config-' . strtolower($section . '-' . str_replace(array('EE_', 'EED_'), '', $name));
720
+	}
721
+
722
+
723
+
724
+	/**
725
+	 *    _set_config_class
726
+	 * ensures that a config class is set, either from a passed config class or one generated from the config name
727
+	 *
728
+	 * @access    private
729
+	 * @param    string $config_class
730
+	 * @param    string $name
731
+	 * @return    string
732
+	 */
733
+	private function _set_config_class($config_class = '', $name = '')
734
+	{
735
+		return ! empty($config_class)
736
+			? $config_class
737
+			: str_replace(' ', '_', ucwords(str_replace('_', ' ', $name))) . '_Config';
738
+	}
739
+
740
+
741
+
742
+	/**
743
+	 *    set_config
744
+	 *
745
+	 * @access    protected
746
+	 * @param    string         $section
747
+	 * @param    string         $name
748
+	 * @param    string         $config_class
749
+	 * @param    EE_Config_Base $config_obj
750
+	 * @return    EE_Config_Base
751
+	 */
752
+	public function set_config($section = '', $name = '', $config_class = '', EE_Config_Base $config_obj = null)
753
+	{
754
+		// ensure config class is set to something
755
+		$config_class = $this->_set_config_class($config_class, $name);
756
+		// run tests 1-4, 6, and 7 to verify all config params are set and valid
757
+		if (! $this->_verify_config_params($section, $name, $config_class, null, array(1, 2, 3, 4, 5, 6))) {
758
+			return null;
759
+		}
760
+		$config_option_name = $this->_generate_config_option_name($section, $name);
761
+		// if the config option name hasn't been added yet to the list of option names we're tracking, then do so now
762
+		if (! isset($this->_addon_option_names[$config_option_name])) {
763
+			$this->_addon_option_names[$config_option_name] = $config_class;
764
+			$this->update_addon_option_names();
765
+		}
766
+		// verify the incoming config object but suppress errors
767
+		if (! $this->_verify_config_params($section, $name, $config_class, $config_obj, array(9), false)) {
768
+			$config_obj = new $config_class();
769
+		}
770
+		if (get_option($config_option_name)) {
771
+			EE_Config::log($config_option_name);
772
+			update_option($config_option_name, $config_obj);
773
+			$this->{$section}->{$name} = $config_obj;
774
+			return $this->{$section}->{$name};
775
+		} else {
776
+			// create a wp-option for this config
777
+			if (add_option($config_option_name, $config_obj, '', 'no')) {
778
+				$this->{$section}->{$name} = maybe_unserialize($config_obj);
779
+				return $this->{$section}->{$name};
780
+			} else {
781
+				EE_Error::add_error(
782
+					sprintf(__('The "%s" could not be saved to the database.', 'event_espresso'), $config_class),
783
+					__FILE__,
784
+					__FUNCTION__,
785
+					__LINE__
786
+				);
787
+				return null;
788
+			}
789
+		}
790
+	}
791
+
792
+
793
+
794
+	/**
795
+	 *    update_config
796
+	 * Important: the config object must ALREADY be set, otherwise this will produce an error.
797
+	 *
798
+	 * @access    public
799
+	 * @param    string                $section
800
+	 * @param    string                $name
801
+	 * @param    EE_Config_Base|string $config_obj
802
+	 * @param    bool                  $throw_errors
803
+	 * @return    bool
804
+	 */
805
+	public function update_config($section = '', $name = '', $config_obj = '', $throw_errors = true)
806
+	{
807
+		// don't allow config updates during WP heartbeats
808
+		if (\EE_Registry::instance()->REQ->get('action', '') === 'heartbeat') {
809
+			return false;
810
+		}
811
+		$config_obj = maybe_unserialize($config_obj);
812
+		// get class name of the incoming object
813
+		$config_class = get_class($config_obj);
814
+		// run tests 1-5 and 9 to verify config
815
+		if (! $this->_verify_config_params(
816
+			$section,
817
+			$name,
818
+			$config_class,
819
+			$config_obj,
820
+			array(1, 2, 3, 4, 7, 9)
821
+		)
822
+		) {
823
+			return false;
824
+		}
825
+		$config_option_name = $this->_generate_config_option_name($section, $name);
826
+		// check if config object has been added to db by seeing if config option name is in $this->_addon_option_names array
827
+		if (! isset($this->_addon_option_names[$config_option_name])) {
828
+			// save new config to db
829
+			if ($this->set_config($section, $name, $config_class, $config_obj)) {
830
+				return true;
831
+			}
832
+		} else {
833
+			// first check if the record already exists
834
+			$existing_config = get_option($config_option_name);
835
+			$config_obj = serialize($config_obj);
836
+			// just return if db record is already up to date (NOT type safe comparison)
837
+			if ($existing_config == $config_obj) {
838
+				$this->{$section}->{$name} = $config_obj;
839
+				return true;
840
+			} else if (update_option($config_option_name, $config_obj)) {
841
+				EE_Config::log($config_option_name);
842
+				// update wp-option for this config class
843
+				$this->{$section}->{$name} = $config_obj;
844
+				return true;
845
+			} elseif ($throw_errors) {
846
+				EE_Error::add_error(
847
+					sprintf(
848
+						__(
849
+							'The "%1$s" object stored at"%2$s" was not successfully updated in the database.',
850
+							'event_espresso'
851
+						),
852
+						$config_class,
853
+						'EE_Config->' . $section . '->' . $name
854
+					),
855
+					__FILE__,
856
+					__FUNCTION__,
857
+					__LINE__
858
+				);
859
+			}
860
+		}
861
+		return false;
862
+	}
863
+
864
+
865
+
866
+	/**
867
+	 *    get_config
868
+	 *
869
+	 * @access    public
870
+	 * @param    string $section
871
+	 * @param    string $name
872
+	 * @param    string $config_class
873
+	 * @return    mixed EE_Config_Base | NULL
874
+	 */
875
+	public function get_config($section = '', $name = '', $config_class = '')
876
+	{
877
+		// ensure config class is set to something
878
+		$config_class = $this->_set_config_class($config_class, $name);
879
+		// run tests 1-4, 6 and 7 to verify that all params have been set
880
+		if (! $this->_verify_config_params($section, $name, $config_class, null, array(1, 2, 3, 4, 5, 6))) {
881
+			return null;
882
+		}
883
+		// now test if the requested config object exists, but suppress errors
884
+		if ($this->_verify_config_params($section, $name, $config_class, null, array(7, 8), false)) {
885
+			// config already exists, so pass it back
886
+			return $this->{$section}->{$name};
887
+		}
888
+		// load config option from db if it exists
889
+		$config_obj = $this->get_config_option($this->_generate_config_option_name($section, $name));
890
+		// verify the newly retrieved config object, but suppress errors
891
+		if ($this->_verify_config_params($section, $name, $config_class, $config_obj, array(9), false)) {
892
+			// config is good, so set it and pass it back
893
+			$this->{$section}->{$name} = $config_obj;
894
+			return $this->{$section}->{$name};
895
+		}
896
+		// oops! $config_obj is not already set and does not exist in the db, so create a new one
897
+		$config_obj = $this->set_config($section, $name, $config_class);
898
+		// verify the newly created config object
899
+		if ($this->_verify_config_params($section, $name, $config_class, $config_obj, array(9))) {
900
+			return $this->{$section}->{$name};
901
+		} else {
902
+			EE_Error::add_error(
903
+				sprintf(__('The "%s" could not be retrieved from the database.', 'event_espresso'), $config_class),
904
+				__FILE__,
905
+				__FUNCTION__,
906
+				__LINE__
907
+			);
908
+		}
909
+		return null;
910
+	}
911
+
912
+
913
+
914
+	/**
915
+	 *    get_config_option
916
+	 *
917
+	 * @access    public
918
+	 * @param    string $config_option_name
919
+	 * @return    mixed EE_Config_Base | FALSE
920
+	 */
921
+	public function get_config_option($config_option_name = '')
922
+	{
923
+		// retrieve the wp-option for this config class.
924
+		$config_option = maybe_unserialize(get_option($config_option_name, array()));
925
+		if (empty($config_option)) {
926
+			EE_Config::log($config_option_name . '-NOT-FOUND');
927
+		}
928
+		return $config_option;
929
+	}
930
+
931
+
932
+
933
+	/**
934
+	 * log
935
+	 *
936
+	 * @param string $config_option_name
937
+	 */
938
+	public static function log($config_option_name = '')
939
+	{
940
+		if (EE_Config::logging_enabled() && ! empty($config_option_name)) {
941
+			$config_log = get_option(EE_Config::LOG_NAME, array());
942
+			//copy incoming $_REQUEST and sanitize it so we can save it
943
+			$_request = $_REQUEST;
944
+			array_walk_recursive($_request, 'sanitize_text_field');
945
+			$config_log[(string)microtime(true)] = array(
946
+				'config_name' => $config_option_name,
947
+				'request'     => $_request,
948
+			);
949
+			update_option(EE_Config::LOG_NAME, $config_log);
950
+		}
951
+	}
952
+
953
+
954
+
955
+	/**
956
+	 * trim_log
957
+	 * reduces the size of the config log to the length specified by EE_Config::LOG_LENGTH
958
+	 */
959
+	public static function trim_log()
960
+	{
961
+		if (! EE_Config::logging_enabled()) {
962
+			return;
963
+		}
964
+		$config_log = maybe_unserialize(get_option(EE_Config::LOG_NAME, array()));
965
+		$log_length = count($config_log);
966
+		if ($log_length > EE_Config::LOG_LENGTH) {
967
+			ksort($config_log);
968
+			$config_log = array_slice($config_log, $log_length - EE_Config::LOG_LENGTH, null, true);
969
+			update_option(EE_Config::LOG_NAME, $config_log);
970
+		}
971
+	}
972
+
973
+
974
+
975
+	/**
976
+	 *    get_page_for_posts
977
+	 *    if the wp-option "show_on_front" is set to "page", then this is the post_name for the post set in the
978
+	 *    wp-option "page_for_posts", or "posts" if no page is selected
979
+	 *
980
+	 * @access    public
981
+	 * @return    string
982
+	 */
983
+	public static function get_page_for_posts()
984
+	{
985
+		$page_for_posts = get_option('page_for_posts');
986
+		if (! $page_for_posts) {
987
+			return 'posts';
988
+		}
989
+		/** @type WPDB $wpdb */
990
+		global $wpdb;
991
+		$SQL = "SELECT post_name from $wpdb->posts WHERE post_type='posts' OR post_type='page' AND post_status='publish' AND ID=%d";
992
+		return $wpdb->get_var($wpdb->prepare($SQL, $page_for_posts));
993
+	}
994
+
995
+
996
+
997
+	/**
998
+	 *    register_shortcodes_and_modules.
999
+	 *    At this point, it's too early to tell if we're maintenance mode or not.
1000
+	 *    In fact, this is where we give modules a chance to let core know they exist
1001
+	 *    so they can help trigger maintenance mode if it's needed
1002
+	 *
1003
+	 * @access    public
1004
+	 * @return    void
1005
+	 */
1006
+	public function register_shortcodes_and_modules()
1007
+	{
1008
+		// allow modules to set hooks for the rest of the system
1009
+		EE_Registry::instance()->modules = $this->_register_modules();
1010
+	}
1011
+
1012
+
1013
+
1014
+	/**
1015
+	 *    initialize_shortcodes_and_modules
1016
+	 *    meaning they can start adding their hooks to get stuff done
1017
+	 *
1018
+	 * @access    public
1019
+	 * @return    void
1020
+	 */
1021
+	public function initialize_shortcodes_and_modules()
1022
+	{
1023
+		// allow modules to set hooks for the rest of the system
1024
+		$this->_initialize_modules();
1025
+	}
1026
+
1027
+
1028
+
1029
+	/**
1030
+	 *    widgets_init
1031
+	 *
1032
+	 * @access private
1033
+	 * @return void
1034
+	 */
1035
+	public function widgets_init()
1036
+	{
1037
+		//only init widgets on admin pages when not in complete maintenance, and
1038
+		//on frontend when not in any maintenance mode
1039
+		if (
1040
+			! EE_Maintenance_Mode::instance()->level()
1041
+			|| (
1042
+				is_admin()
1043
+				&& EE_Maintenance_Mode::instance()->level() !== EE_Maintenance_Mode::level_2_complete_maintenance
1044
+			)
1045
+		) {
1046
+			// grab list of installed widgets
1047
+			$widgets_to_register = glob(EE_WIDGETS . '*', GLOB_ONLYDIR);
1048
+			// filter list of modules to register
1049
+			$widgets_to_register = apply_filters(
1050
+				'FHEE__EE_Config__register_widgets__widgets_to_register',
1051
+				$widgets_to_register
1052
+			);
1053
+			if (! empty($widgets_to_register)) {
1054
+				// cycle thru widget folders
1055
+				foreach ($widgets_to_register as $widget_path) {
1056
+					// add to list of installed widget modules
1057
+					EE_Config::register_ee_widget($widget_path);
1058
+				}
1059
+			}
1060
+			// filter list of installed modules
1061
+			EE_Registry::instance()->widgets = apply_filters(
1062
+				'FHEE__EE_Config__register_widgets__installed_widgets',
1063
+				EE_Registry::instance()->widgets
1064
+			);
1065
+		}
1066
+	}
1067
+
1068
+
1069
+
1070
+	/**
1071
+	 *    register_ee_widget - makes core aware of this widget
1072
+	 *
1073
+	 * @access    public
1074
+	 * @param    string $widget_path - full path up to and including widget folder
1075
+	 * @return    void
1076
+	 */
1077
+	public static function register_ee_widget($widget_path = null)
1078
+	{
1079
+		do_action('AHEE__EE_Config__register_widget__begin', $widget_path);
1080
+		$widget_ext = '.widget.php';
1081
+		// make all separators match
1082
+		$widget_path = rtrim(str_replace('/\\', DS, $widget_path), DS);
1083
+		// does the file path INCLUDE the actual file name as part of the path ?
1084
+		if (strpos($widget_path, $widget_ext) !== false) {
1085
+			// grab and shortcode file name from directory name and break apart at dots
1086
+			$file_name = explode('.', basename($widget_path));
1087
+			// take first segment from file name pieces and remove class prefix if it exists
1088
+			$widget = strpos($file_name[0], 'EEW_') === 0 ? substr($file_name[0], 4) : $file_name[0];
1089
+			// sanitize shortcode directory name
1090
+			$widget = sanitize_key($widget);
1091
+			// now we need to rebuild the shortcode path
1092
+			$widget_path = explode(DS, $widget_path);
1093
+			// remove last segment
1094
+			array_pop($widget_path);
1095
+			// glue it back together
1096
+			$widget_path = implode(DS, $widget_path);
1097
+		} else {
1098
+			// grab and sanitize widget directory name
1099
+			$widget = sanitize_key(basename($widget_path));
1100
+		}
1101
+		// create classname from widget directory name
1102
+		$widget = str_replace(' ', '_', ucwords(str_replace('_', ' ', $widget)));
1103
+		// add class prefix
1104
+		$widget_class = 'EEW_' . $widget;
1105
+		// does the widget exist ?
1106
+		if (! is_readable($widget_path . DS . $widget_class . $widget_ext)) {
1107
+			$msg = sprintf(
1108
+				__(
1109
+					'The requested %s widget file could not be found or is not readable due to file permissions. Please ensure the following path is correct: %s',
1110
+					'event_espresso'
1111
+				),
1112
+				$widget_class,
1113
+				$widget_path . DS . $widget_class . $widget_ext
1114
+			);
1115
+			EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__);
1116
+			return;
1117
+		}
1118
+		// load the widget class file
1119
+		require_once($widget_path . DS . $widget_class . $widget_ext);
1120
+		// verify that class exists
1121
+		if (! class_exists($widget_class)) {
1122
+			$msg = sprintf(__('The requested %s widget class does not exist.', 'event_espresso'), $widget_class);
1123
+			EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__);
1124
+			return;
1125
+		}
1126
+		register_widget($widget_class);
1127
+		// add to array of registered widgets
1128
+		EE_Registry::instance()->widgets->{$widget_class} = $widget_path . DS . $widget_class . $widget_ext;
1129
+	}
1130
+
1131
+
1132
+
1133
+	/**
1134
+	 *        _register_modules
1135
+	 *
1136
+	 * @access private
1137
+	 * @return array
1138
+	 */
1139
+	private function _register_modules()
1140
+	{
1141
+		// grab list of installed modules
1142
+		$modules_to_register = glob(EE_MODULES . '*', GLOB_ONLYDIR);
1143
+		// filter list of modules to register
1144
+		$modules_to_register = apply_filters(
1145
+			'FHEE__EE_Config__register_modules__modules_to_register',
1146
+			$modules_to_register
1147
+		);
1148
+		if (! empty($modules_to_register)) {
1149
+			// loop through folders
1150
+			foreach ($modules_to_register as $module_path) {
1151
+				/**TEMPORARILY EXCLUDE gateways from modules for time being**/
1152
+				if (
1153
+					$module_path !== EE_MODULES . 'zzz-copy-this-module-template'
1154
+					&& $module_path !== EE_MODULES . 'gateways'
1155
+				) {
1156
+					// add to list of installed modules
1157
+					EE_Config::register_module($module_path);
1158
+				}
1159
+			}
1160
+		}
1161
+		// filter list of installed modules
1162
+		return apply_filters(
1163
+			'FHEE__EE_Config___register_modules__installed_modules',
1164
+			EE_Registry::instance()->modules
1165
+		);
1166
+	}
1167
+
1168
+
1169
+
1170
+	/**
1171
+	 *    register_module - makes core aware of this module
1172
+	 *
1173
+	 * @access    public
1174
+	 * @param    string $module_path - full path up to and including module folder
1175
+	 * @return    bool
1176
+	 */
1177
+	public static function register_module($module_path = null)
1178
+	{
1179
+		do_action('AHEE__EE_Config__register_module__begin', $module_path);
1180
+		$module_ext = '.module.php';
1181
+		// make all separators match
1182
+		$module_path = str_replace(array('\\', '/'), DS, $module_path);
1183
+		// does the file path INCLUDE the actual file name as part of the path ?
1184
+		if (strpos($module_path, $module_ext) !== false) {
1185
+			// grab and shortcode file name from directory name and break apart at dots
1186
+			$module_file = explode('.', basename($module_path));
1187
+			// now we need to rebuild the shortcode path
1188
+			$module_path = explode(DS, $module_path);
1189
+			// remove last segment
1190
+			array_pop($module_path);
1191
+			// glue it back together
1192
+			$module_path = implode(DS, $module_path) . DS;
1193
+			// take first segment from file name pieces and sanitize it
1194
+			$module = preg_replace('/[^a-zA-Z0-9_\-]/', '', $module_file[0]);
1195
+			// ensure class prefix is added
1196
+			$module_class = strpos($module, 'EED_') !== 0 ? 'EED_' . $module : $module;
1197
+		} else {
1198
+			// we need to generate the filename based off of the folder name
1199
+			// grab and sanitize module name
1200
+			$module = strtolower(basename($module_path));
1201
+			$module = preg_replace('/[^a-z0-9_\-]/', '', $module);
1202
+			// like trailingslashit()
1203
+			$module_path = rtrim($module_path, DS) . DS;
1204
+			// create classname from module directory name
1205
+			$module = str_replace(' ', '_', ucwords(str_replace('_', ' ', $module)));
1206
+			// add class prefix
1207
+			$module_class = 'EED_' . $module;
1208
+		}
1209
+		// does the module exist ?
1210
+		if (! is_readable($module_path . DS . $module_class . $module_ext)) {
1211
+			$msg = sprintf(
1212
+				__(
1213
+					'The requested %s module file could not be found or is not readable due to file permissions.',
1214
+					'event_espresso'
1215
+				),
1216
+				$module
1217
+			);
1218
+			EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__);
1219
+			return false;
1220
+		}
1221
+		// load the module class file
1222
+		require_once($module_path . $module_class . $module_ext);
1223
+		// verify that class exists
1224
+		if (! class_exists($module_class)) {
1225
+			$msg = sprintf(__('The requested %s module class does not exist.', 'event_espresso'), $module_class);
1226
+			EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__);
1227
+			return false;
1228
+		}
1229
+		// add to array of registered modules
1230
+		EE_Registry::instance()->modules->{$module_class} = $module_path . $module_class . $module_ext;
1231
+		do_action(
1232
+			'AHEE__EE_Config__register_module__complete',
1233
+			$module_class,
1234
+			EE_Registry::instance()->modules->{$module_class}
1235
+		);
1236
+		return true;
1237
+	}
1238
+
1239
+
1240
+
1241
+	/**
1242
+	 *    _initialize_modules
1243
+	 *    allow modules to set hooks for the rest of the system
1244
+	 *
1245
+	 * @access private
1246
+	 * @return void
1247
+	 */
1248
+	private function _initialize_modules()
1249
+	{
1250
+		// cycle thru shortcode folders
1251
+		foreach (EE_Registry::instance()->modules as $module_class => $module_path) {
1252
+			// fire the shortcode class's set_hooks methods in case it needs to hook into other parts of the system
1253
+			// which set hooks ?
1254
+			if (is_admin()) {
1255
+				// fire immediately
1256
+				call_user_func(array($module_class, 'set_hooks_admin'));
1257
+			} else {
1258
+				// delay until other systems are online
1259
+				add_action(
1260
+					'AHEE__EE_System__set_hooks_for_shortcodes_modules_and_addons',
1261
+					array($module_class, 'set_hooks')
1262
+				);
1263
+			}
1264
+		}
1265
+	}
1266
+
1267
+
1268
+
1269
+	/**
1270
+	 *    register_route - adds module method routes to route_map
1271
+	 *
1272
+	 * @access    public
1273
+	 * @param    string $route       - "pretty" public alias for module method
1274
+	 * @param    string $module      - module name (classname without EED_ prefix)
1275
+	 * @param    string $method_name - the actual module method to be routed to
1276
+	 * @param    string $key         - url param key indicating a route is being called
1277
+	 * @return    bool
1278
+	 */
1279
+	public static function register_route($route = null, $module = null, $method_name = null, $key = 'ee')
1280
+	{
1281
+		do_action('AHEE__EE_Config__register_route__begin', $route, $module, $method_name);
1282
+		$module = str_replace('EED_', '', $module);
1283
+		$module_class = 'EED_' . $module;
1284
+		if (! isset(EE_Registry::instance()->modules->{$module_class})) {
1285
+			$msg = sprintf(__('The module %s has not been registered.', 'event_espresso'), $module);
1286
+			EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__);
1287
+			return false;
1288
+		}
1289
+		if (empty($route)) {
1290
+			$msg = sprintf(__('No route has been supplied.', 'event_espresso'), $route);
1291
+			EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__);
1292
+			return false;
1293
+		}
1294
+		if (! method_exists('EED_' . $module, $method_name)) {
1295
+			$msg = sprintf(
1296
+				__('A valid class method for the %s route has not been supplied.', 'event_espresso'),
1297
+				$route
1298
+			);
1299
+			EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__);
1300
+			return false;
1301
+		}
1302
+		EE_Config::$_module_route_map[$key][$route] = array('EED_' . $module, $method_name);
1303
+		return true;
1304
+	}
1305
+
1306
+
1307
+
1308
+	/**
1309
+	 *    get_route - get module method route
1310
+	 *
1311
+	 * @access    public
1312
+	 * @param    string $route - "pretty" public alias for module method
1313
+	 * @param    string $key   - url param key indicating a route is being called
1314
+	 * @return    string
1315
+	 */
1316
+	public static function get_route($route = null, $key = 'ee')
1317
+	{
1318
+		do_action('AHEE__EE_Config__get_route__begin', $route);
1319
+		$route = (string)apply_filters('FHEE__EE_Config__get_route', $route);
1320
+		if (isset(EE_Config::$_module_route_map[$key][$route])) {
1321
+			return EE_Config::$_module_route_map[$key][$route];
1322
+		}
1323
+		return null;
1324
+	}
1325
+
1326
+
1327
+
1328
+	/**
1329
+	 *    get_routes - get ALL module method routes
1330
+	 *
1331
+	 * @access    public
1332
+	 * @return    array
1333
+	 */
1334
+	public static function get_routes()
1335
+	{
1336
+		return EE_Config::$_module_route_map;
1337
+	}
1338
+
1339
+
1340
+
1341
+	/**
1342
+	 *    register_forward - allows modules to forward request to another module for further processing
1343
+	 *
1344
+	 * @access    public
1345
+	 * @param    string       $route   - "pretty" public alias for module method
1346
+	 * @param    integer      $status  - integer value corresponding  to status constant strings set in module parent
1347
+	 *                                 class, allows different forwards to be served based on status
1348
+	 * @param    array|string $forward - function name or array( class, method )
1349
+	 * @param    string       $key     - url param key indicating a route is being called
1350
+	 * @return    bool
1351
+	 */
1352
+	public static function register_forward($route = null, $status = 0, $forward = null, $key = 'ee')
1353
+	{
1354
+		do_action('AHEE__EE_Config__register_forward', $route, $status, $forward);
1355
+		if (! isset(EE_Config::$_module_route_map[$key][$route]) || empty($route)) {
1356
+			$msg = sprintf(
1357
+				__('The module route %s for this forward has not been registered.', 'event_espresso'),
1358
+				$route
1359
+			);
1360
+			EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__);
1361
+			return false;
1362
+		}
1363
+		if (empty($forward)) {
1364
+			$msg = sprintf(__('No forwarding route has been supplied.', 'event_espresso'), $route);
1365
+			EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__);
1366
+			return false;
1367
+		}
1368
+		if (is_array($forward)) {
1369
+			if (! isset($forward[1])) {
1370
+				$msg = sprintf(
1371
+					__('A class method for the %s forwarding route has not been supplied.', 'event_espresso'),
1372
+					$route
1373
+				);
1374
+				EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__);
1375
+				return false;
1376
+			}
1377
+			if (! method_exists($forward[0], $forward[1])) {
1378
+				$msg = sprintf(
1379
+					__('The class method %s for the %s forwarding route is in invalid.', 'event_espresso'),
1380
+					$forward[1],
1381
+					$route
1382
+				);
1383
+				EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__);
1384
+				return false;
1385
+			}
1386
+		} else if (! function_exists($forward)) {
1387
+			$msg = sprintf(
1388
+				__('The function %s for the %s forwarding route is in invalid.', 'event_espresso'),
1389
+				$forward,
1390
+				$route
1391
+			);
1392
+			EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__);
1393
+			return false;
1394
+		}
1395
+		EE_Config::$_module_forward_map[$key][$route][absint($status)] = $forward;
1396
+		return true;
1397
+	}
1398
+
1399
+
1400
+
1401
+	/**
1402
+	 *    get_forward - get forwarding route
1403
+	 *
1404
+	 * @access    public
1405
+	 * @param    string  $route  - "pretty" public alias for module method
1406
+	 * @param    integer $status - integer value corresponding  to status constant strings set in module parent class,
1407
+	 *                           allows different forwards to be served based on status
1408
+	 * @param    string  $key    - url param key indicating a route is being called
1409
+	 * @return    string
1410
+	 */
1411
+	public static function get_forward($route = null, $status = 0, $key = 'ee')
1412
+	{
1413
+		do_action('AHEE__EE_Config__get_forward__begin', $route, $status);
1414
+		if (isset(EE_Config::$_module_forward_map[$key][$route][$status])) {
1415
+			return apply_filters(
1416
+				'FHEE__EE_Config__get_forward',
1417
+				EE_Config::$_module_forward_map[$key][$route][$status],
1418
+				$route,
1419
+				$status
1420
+			);
1421
+		}
1422
+		return null;
1423
+	}
1424
+
1425
+
1426
+
1427
+	/**
1428
+	 *    register_forward - allows modules to specify different view templates for different method routes and status
1429
+	 *    results
1430
+	 *
1431
+	 * @access    public
1432
+	 * @param    string  $route  - "pretty" public alias for module method
1433
+	 * @param    integer $status - integer value corresponding  to status constant strings set in module parent class,
1434
+	 *                           allows different views to be served based on status
1435
+	 * @param    string  $view
1436
+	 * @param    string  $key    - url param key indicating a route is being called
1437
+	 * @return    bool
1438
+	 */
1439
+	public static function register_view($route = null, $status = 0, $view = null, $key = 'ee')
1440
+	{
1441
+		do_action('AHEE__EE_Config__register_view__begin', $route, $status, $view);
1442
+		if (! isset(EE_Config::$_module_route_map[$key][$route]) || empty($route)) {
1443
+			$msg = sprintf(
1444
+				__('The module route %s for this view has not been registered.', 'event_espresso'),
1445
+				$route
1446
+			);
1447
+			EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__);
1448
+			return false;
1449
+		}
1450
+		if (! is_readable($view)) {
1451
+			$msg = sprintf(
1452
+				__(
1453
+					'The %s view file could not be found or is not readable due to file permissions.',
1454
+					'event_espresso'
1455
+				),
1456
+				$view
1457
+			);
1458
+			EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__);
1459
+			return false;
1460
+		}
1461
+		EE_Config::$_module_view_map[$key][$route][absint($status)] = $view;
1462
+		return true;
1463
+	}
1464
+
1465
+
1466
+
1467
+	/**
1468
+	 *    get_view - get view for route and status
1469
+	 *
1470
+	 * @access    public
1471
+	 * @param    string  $route  - "pretty" public alias for module method
1472
+	 * @param    integer $status - integer value corresponding  to status constant strings set in module parent class,
1473
+	 *                           allows different views to be served based on status
1474
+	 * @param    string  $key    - url param key indicating a route is being called
1475
+	 * @return    string
1476
+	 */
1477
+	public static function get_view($route = null, $status = 0, $key = 'ee')
1478
+	{
1479
+		do_action('AHEE__EE_Config__get_view__begin', $route, $status);
1480
+		if (isset(EE_Config::$_module_view_map[$key][$route][$status])) {
1481
+			return apply_filters(
1482
+				'FHEE__EE_Config__get_view',
1483
+				EE_Config::$_module_view_map[$key][$route][$status],
1484
+				$route,
1485
+				$status
1486
+			);
1487
+		}
1488
+		return null;
1489
+	}
1490
+
1491
+
1492
+
1493
+	public function update_addon_option_names()
1494
+	{
1495
+		update_option(EE_Config::ADDON_OPTION_NAMES, $this->_addon_option_names);
1496
+	}
1497
+
1498
+
1499
+
1500
+	public function shutdown()
1501
+	{
1502
+		$this->update_addon_option_names();
1503
+	}
1504
+
1505
+
1506
+
1507
+	/**
1508
+	 * @return LegacyShortcodesManager
1509
+	 */
1510
+	public static function getLegacyShortcodesManager()
1511
+	{
1512
+
1513
+		if ( ! EE_Config::instance()->legacy_shortcodes_manager instanceof LegacyShortcodesManager) {
1514
+			EE_Config::instance()->legacy_shortcodes_manager = new LegacyShortcodesManager(
1515
+				EE_Registry::instance()
1516
+			);
1517
+		}
1518
+		return EE_Config::instance()->legacy_shortcodes_manager;
1519
+	}
1520
+
1521
+
1522
+
1523
+	/**
1524
+	 * register_shortcode - makes core aware of this shortcode
1525
+	 *
1526
+	 * @deprecated 4.9.26
1527
+	 * @param    string $shortcode_path - full path up to and including shortcode folder
1528
+	 * @return    bool
1529
+	 */
1530
+	public static function register_shortcode($shortcode_path = null)
1531
+	{
1532
+		EE_Error::doing_it_wrong(
1533
+			__METHOD__,
1534
+			__(
1535
+				'Usage is deprecated. Use \EventEspresso\core\services\shortcodes\LegacyShortcodesManager::registerShortcode() as direct replacement, or better yet, please see the new \EventEspresso\core\services\shortcodes\ShortcodesManager class.',
1536
+				'event_espresso'
1537
+			),
1538
+			'4.9.26'
1539
+		);
1540
+		return EE_Config::instance()->getLegacyShortcodesManager()->registerShortcode($shortcode_path);
1541
+	}
21 1542
 
22
-    const LOG_NAME           = 'ee_config_log';
23 1543
 
24
-    const LOG_LENGTH         = 100;
25 1544
 
26
-    const ADDON_OPTION_NAMES = 'ee_config_option_names';
27
-
28
-
29
-    /**
30
-     *    instance of the EE_Config object
31
-     *
32
-     * @var    EE_Config $_instance
33
-     * @access    private
34
-     */
35
-    private static $_instance;
36
-
37
-    /**
38
-     * @var boolean $_logging_enabled
39
-     */
40
-    private static $_logging_enabled = false;
41
-
42
-    /**
43
-     * @var LegacyShortcodesManager $legacy_shortcodes_manager
44
-     */
45
-    private $legacy_shortcodes_manager;
46
-
47
-    /**
48
-     * An StdClass whose property names are addon slugs,
49
-     * and values are their config classes
50
-     *
51
-     * @var StdClass
52
-     */
53
-    public $addons;
54
-
55
-    /**
56
-     * @var EE_Admin_Config
57
-     */
58
-    public $admin;
59
-
60
-    /**
61
-     * @var EE_Core_Config
62
-     */
63
-    public $core;
64
-
65
-    /**
66
-     * @var EE_Currency_Config
67
-     */
68
-    public $currency;
69
-
70
-    /**
71
-     * @var EE_Organization_Config
72
-     */
73
-    public $organization;
74
-
75
-    /**
76
-     * @var EE_Registration_Config
77
-     */
78
-    public $registration;
79
-
80
-    /**
81
-     * @var EE_Template_Config
82
-     */
83
-    public $template_settings;
84
-
85
-    /**
86
-     * Holds EE environment values.
87
-     *
88
-     * @var EE_Environment_Config
89
-     */
90
-    public $environment;
91
-
92
-    /**
93
-     * settings pertaining to Google maps
94
-     *
95
-     * @var EE_Map_Config
96
-     */
97
-    public $map_settings;
98
-
99
-    /**
100
-     * settings pertaining to Taxes
101
-     *
102
-     * @var EE_Tax_Config
103
-     */
104
-    public $tax_settings;
105
-
106
-
107
-    /**
108
-     * Settings pertaining to global messages settings.
109
-     *
110
-     * @var EE_Messages_Config
111
-     */
112
-    public $messages;
113
-
114
-    /**
115
-     * @deprecated
116
-     * @var EE_Gateway_Config
117
-     */
118
-    public $gateway;
119
-
120
-    /**
121
-     * @var    array $_addon_option_names
122
-     * @access    private
123
-     */
124
-    private $_addon_option_names = array();
125
-
126
-    /**
127
-     * @var    array $_module_route_map
128
-     * @access    private
129
-     */
130
-    private static $_module_route_map = array();
131
-
132
-    /**
133
-     * @var    array $_module_forward_map
134
-     * @access    private
135
-     */
136
-    private static $_module_forward_map = array();
137
-
138
-    /**
139
-     * @var    array $_module_view_map
140
-     * @access    private
141
-     */
142
-    private static $_module_view_map = array();
143
-
144
-
145
-
146
-    /**
147
-     * @singleton method used to instantiate class object
148
-     * @access    public
149
-     * @return EE_Config instance
150
-     */
151
-    public static function instance()
152
-    {
153
-        // check if class object is instantiated, and instantiated properly
154
-        if (! self::$_instance instanceof EE_Config) {
155
-            self::$_instance = new self();
156
-        }
157
-        return self::$_instance;
158
-    }
159
-
160
-
161
-
162
-    /**
163
-     * Resets the config
164
-     *
165
-     * @param bool    $hard_reset    if TRUE, sets EE_CONFig back to its original settings in the database. If FALSE
166
-     *                               (default) leaves the database alone, and merely resets the EE_Config object to
167
-     *                               reflect its state in the database
168
-     * @param boolean $reinstantiate if TRUE (default) call instance() and return it. Otherwise, just leave
169
-     *                               $_instance as NULL. Useful in case you want to forget about the old instance on
170
-     *                               EE_Config, but might not be ready to instantiate EE_Config currently (eg if the
171
-     *                               site was put into maintenance mode)
172
-     * @return EE_Config
173
-     */
174
-    public static function reset($hard_reset = false, $reinstantiate = true)
175
-    {
176
-        if (self::$_instance instanceof EE_Config) {
177
-            if ($hard_reset) {
178
-                self::$_instance->legacy_shortcodes_manager = null;
179
-                self::$_instance->_addon_option_names = array();
180
-                self::$_instance->_initialize_config();
181
-                self::$_instance->update_espresso_config();
182
-            }
183
-            self::$_instance->update_addon_option_names();
184
-        }
185
-        self::$_instance = null;
186
-        //we don't need to reset the static properties imo because those should
187
-        //only change when a module is added or removed. Currently we don't
188
-        //support removing a module during a request when it previously existed
189
-        if ($reinstantiate) {
190
-            return self::instance();
191
-        } else {
192
-            return null;
193
-        }
194
-    }
195
-
196
-
197
-
198
-    /**
199
-     *    class constructor
200
-     *
201
-     * @access    private
202
-     */
203
-    private function __construct()
204
-    {
205
-        do_action('AHEE__EE_Config__construct__begin', $this);
206
-        EE_Config::$_logging_enabled = apply_filters('FHEE__EE_Config___construct__logging_enabled', false);
207
-        // setup empty config classes
208
-        $this->_initialize_config();
209
-        // load existing EE site settings
210
-        $this->_load_core_config();
211
-        // confirm everything loaded correctly and set filtered defaults if not
212
-        $this->_verify_config();
213
-        //  register shortcodes and modules
214
-        add_action(
215
-            'AHEE__EE_System__register_shortcodes_modules_and_widgets',
216
-            array($this, 'register_shortcodes_and_modules'),
217
-            999
218
-        );
219
-        //  initialize shortcodes and modules
220
-        add_action('AHEE__EE_System__core_loaded_and_ready', array($this, 'initialize_shortcodes_and_modules'));
221
-        // register widgets
222
-        add_action('widgets_init', array($this, 'widgets_init'), 10);
223
-        // shutdown
224
-        add_action('shutdown', array($this, 'shutdown'), 10);
225
-        // construct__end hook
226
-        do_action('AHEE__EE_Config__construct__end', $this);
227
-        // hardcoded hack
228
-        $this->template_settings->current_espresso_theme = 'Espresso_Arabica_2014';
229
-    }
230
-
231
-
232
-
233
-    /**
234
-     * @return boolean
235
-     */
236
-    public static function logging_enabled()
237
-    {
238
-        return self::$_logging_enabled;
239
-    }
240
-
241
-
242
-
243
-    /**
244
-     * use to get the current theme if needed from static context
245
-     *
246
-     * @return string current theme set.
247
-     */
248
-    public static function get_current_theme()
249
-    {
250
-        return isset(self::$_instance->template_settings->current_espresso_theme)
251
-            ? self::$_instance->template_settings->current_espresso_theme : 'Espresso_Arabica_2014';
252
-    }
253
-
254
-
255
-
256
-    /**
257
-     *        _initialize_config
258
-     *
259
-     * @access private
260
-     * @return void
261
-     */
262
-    private function _initialize_config()
263
-    {
264
-        EE_Config::trim_log();
265
-        //set defaults
266
-        $this->_addon_option_names = get_option(EE_Config::ADDON_OPTION_NAMES, array());
267
-        $this->addons = new stdClass();
268
-        // set _module_route_map
269
-        EE_Config::$_module_route_map = array();
270
-        // set _module_forward_map
271
-        EE_Config::$_module_forward_map = array();
272
-        // set _module_view_map
273
-        EE_Config::$_module_view_map = array();
274
-    }
275
-
276
-
277
-
278
-    /**
279
-     *        load core plugin configuration
280
-     *
281
-     * @access private
282
-     * @return void
283
-     */
284
-    private function _load_core_config()
285
-    {
286
-        // load_core_config__start hook
287
-        do_action('AHEE__EE_Config___load_core_config__start', $this);
288
-        $espresso_config = $this->get_espresso_config();
289
-        foreach ($espresso_config as $config => $settings) {
290
-            // load_core_config__start hook
291
-            $settings = apply_filters(
292
-                'FHEE__EE_Config___load_core_config__config_settings',
293
-                $settings,
294
-                $config,
295
-                $this
296
-            );
297
-            if (is_object($settings) && property_exists($this, $config)) {
298
-                $this->{$config} = apply_filters('FHEE__EE_Config___load_core_config__' . $config, $settings);
299
-                //call configs populate method to ensure any defaults are set for empty values.
300
-                if (method_exists($settings, 'populate')) {
301
-                    $this->{$config}->populate();
302
-                }
303
-                if (method_exists($settings, 'do_hooks')) {
304
-                    $this->{$config}->do_hooks();
305
-                }
306
-            }
307
-        }
308
-        if (apply_filters('FHEE__EE_Config___load_core_config__update_espresso_config', false)) {
309
-            $this->update_espresso_config();
310
-        }
311
-        // load_core_config__end hook
312
-        do_action('AHEE__EE_Config___load_core_config__end', $this);
313
-    }
314
-
315
-
316
-
317
-    /**
318
-     *    _verify_config
319
-     *
320
-     * @access    protected
321
-     * @return    void
322
-     */
323
-    protected function _verify_config()
324
-    {
325
-        $this->core = $this->core instanceof EE_Core_Config
326
-            ? $this->core
327
-            : new EE_Core_Config();
328
-        $this->core = apply_filters('FHEE__EE_Config___initialize_config__core', $this->core);
329
-        $this->organization = $this->organization instanceof EE_Organization_Config
330
-            ? $this->organization
331
-            : new EE_Organization_Config();
332
-        $this->organization = apply_filters(
333
-            'FHEE__EE_Config___initialize_config__organization',
334
-            $this->organization
335
-        );
336
-        $this->currency = $this->currency instanceof EE_Currency_Config
337
-            ? $this->currency
338
-            : new EE_Currency_Config();
339
-        $this->currency = apply_filters('FHEE__EE_Config___initialize_config__currency', $this->currency);
340
-        $this->registration = $this->registration instanceof EE_Registration_Config
341
-            ? $this->registration
342
-            : new EE_Registration_Config();
343
-        $this->registration = apply_filters(
344
-            'FHEE__EE_Config___initialize_config__registration',
345
-            $this->registration
346
-        );
347
-        $this->admin = $this->admin instanceof EE_Admin_Config
348
-            ? $this->admin
349
-            : new EE_Admin_Config();
350
-        $this->admin = apply_filters('FHEE__EE_Config___initialize_config__admin', $this->admin);
351
-        $this->template_settings = $this->template_settings instanceof EE_Template_Config
352
-            ? $this->template_settings
353
-            : new EE_Template_Config();
354
-        $this->template_settings = apply_filters(
355
-            'FHEE__EE_Config___initialize_config__template_settings',
356
-            $this->template_settings
357
-        );
358
-        $this->map_settings = $this->map_settings instanceof EE_Map_Config
359
-            ? $this->map_settings
360
-            : new EE_Map_Config();
361
-        $this->map_settings = apply_filters('FHEE__EE_Config___initialize_config__map_settings',
362
-            $this->map_settings);
363
-        $this->environment = $this->environment instanceof EE_Environment_Config
364
-            ? $this->environment
365
-            : new EE_Environment_Config();
366
-        $this->environment = apply_filters('FHEE__EE_Config___initialize_config__environment',
367
-            $this->environment);
368
-        $this->tax_settings = $this->tax_settings instanceof EE_Tax_Config
369
-            ? $this->tax_settings
370
-            : new EE_Tax_Config();
371
-        $this->tax_settings = apply_filters('FHEE__EE_Config___initialize_config__tax_settings',
372
-            $this->tax_settings);
373
-        $this->messages = apply_filters('FHEE__EE_Config__initialize_config__messages', $this->messages);
374
-        $this->messages = $this->messages instanceof EE_Messages_Config
375
-            ? $this->messages
376
-            : new EE_Messages_Config();
377
-        $this->gateway = $this->gateway instanceof EE_Gateway_Config
378
-            ? $this->gateway
379
-            : new EE_Gateway_Config();
380
-        $this->gateway = apply_filters('FHEE__EE_Config___initialize_config__gateway', $this->gateway);
381
-        $this->legacy_shortcodes_manager = null;
382
-    }
383
-
384
-
385
-    /**
386
-     *    get_espresso_config
387
-     *
388
-     * @access    public
389
-     * @return    array of espresso config stuff
390
-     */
391
-    public function get_espresso_config()
392
-    {
393
-        // grab espresso configuration
394
-        return apply_filters(
395
-            'FHEE__EE_Config__get_espresso_config__CFG',
396
-            get_option(EE_Config::OPTION_NAME, array())
397
-        );
398
-    }
399
-
400
-
401
-
402
-    /**
403
-     *    double_check_config_comparison
404
-     *
405
-     * @access    public
406
-     * @param string $option
407
-     * @param        $old_value
408
-     * @param        $value
409
-     */
410
-    public function double_check_config_comparison($option = '', $old_value, $value)
411
-    {
412
-        // make sure we're checking the ee config
413
-        if ($option === EE_Config::OPTION_NAME) {
414
-            // run a loose comparison of the old value against the new value for type and properties,
415
-            // but NOT exact instance like WP update_option does (ie: NOT type safe comparison)
416
-            if ($value != $old_value) {
417
-                // if they are NOT the same, then remove the hook,
418
-                // which means the subsequent update results will be based solely on the update query results
419
-                // the reason we do this is because, as stated above,
420
-                // WP update_option performs an exact instance comparison (===) on any update values passed to it
421
-                // this happens PRIOR to serialization and any subsequent update.
422
-                // If values are found to match their previous old value,
423
-                // then WP bails before performing any update.
424
-                // Since we are passing the EE_Config object, it is comparing the EXACT instance of the saved version
425
-                // it just pulled from the db, with the one being passed to it (which will not match).
426
-                // HOWEVER, once the object is serialized and passed off to MySQL to update,
427
-                // MySQL MAY ALSO NOT perform the update because
428
-                // the string it sees in the db looks the same as the new one it has been passed!!!
429
-                // This results in the query returning an "affected rows" value of ZERO,
430
-                // which gets returned immediately by WP update_option and looks like an error.
431
-                remove_action('update_option', array($this, 'check_config_updated'));
432
-            }
433
-        }
434
-    }
435
-
436
-
437
-
438
-    /**
439
-     *    update_espresso_config
440
-     *
441
-     * @access   public
442
-     */
443
-    protected function _reset_espresso_addon_config()
444
-    {
445
-        $this->_addon_option_names = array();
446
-        foreach ($this->addons as $addon_name => $addon_config_obj) {
447
-            $addon_config_obj = maybe_unserialize($addon_config_obj);
448
-            $config_class = get_class($addon_config_obj);
449
-            if ($addon_config_obj instanceof $config_class && ! $addon_config_obj instanceof __PHP_Incomplete_Class) {
450
-                $this->update_config('addons', $addon_name, $addon_config_obj, false);
451
-            }
452
-            $this->addons->{$addon_name} = null;
453
-        }
454
-    }
455
-
456
-
457
-
458
-    /**
459
-     *    update_espresso_config
460
-     *
461
-     * @access   public
462
-     * @param   bool $add_success
463
-     * @param   bool $add_error
464
-     * @return   bool
465
-     */
466
-    public function update_espresso_config($add_success = false, $add_error = true)
467
-    {
468
-        // don't allow config updates during WP heartbeats
469
-        if (\EE_Registry::instance()->REQ->get('action', '') === 'heartbeat') {
470
-            return false;
471
-        }
472
-        // commented out the following re: https://events.codebasehq.com/projects/event-espresso/tickets/8197
473
-        //$clone = clone( self::$_instance );
474
-        //self::$_instance = NULL;
475
-        do_action('AHEE__EE_Config__update_espresso_config__begin', $this);
476
-        $this->_reset_espresso_addon_config();
477
-        // hook into update_option because that happens AFTER the ( $value === $old_value ) conditional
478
-        // but BEFORE the actual update occurs
479
-        add_action('update_option', array($this, 'double_check_config_comparison'), 1, 3);
480
-        // don't want to persist legacy_shortcodes_manager, but don't want to lose it either
481
-        $legacy_shortcodes_manager = $this->legacy_shortcodes_manager;
482
-        $this->legacy_shortcodes_manager = null;
483
-        // now update "ee_config"
484
-        $saved = update_option(EE_Config::OPTION_NAME, $this);
485
-        $this->legacy_shortcodes_manager = $legacy_shortcodes_manager;
486
-        EE_Config::log(EE_Config::OPTION_NAME);
487
-        // if not saved... check if the hook we just added still exists;
488
-        // if it does, it means one of two things:
489
-        // 		that update_option bailed at the ( $value === $old_value ) conditional,
490
-        //		 or...
491
-        // 		the db update query returned 0 rows affected
492
-        // 		(probably because the data  value was the same from it's perspective)
493
-        // so the existence of the hook means that a negative result from update_option is NOT an error,
494
-        // but just means no update occurred, so don't display an error to the user.
495
-        // BUT... if update_option returns FALSE, AND the hook is missing,
496
-        // then it means that something truly went wrong
497
-        $saved = ! $saved ? has_action('update_option', array($this, 'double_check_config_comparison')) : $saved;
498
-        // remove our action since we don't want it in the system anymore
499
-        remove_action('update_option', array($this, 'double_check_config_comparison'), 1);
500
-        do_action('AHEE__EE_Config__update_espresso_config__end', $this, $saved);
501
-        //self::$_instance = $clone;
502
-        //unset( $clone );
503
-        // if config remains the same or was updated successfully
504
-        if ($saved) {
505
-            if ($add_success) {
506
-                EE_Error::add_success(
507
-                    __('The Event Espresso Configuration Settings have been successfully updated.', 'event_espresso'),
508
-                    __FILE__,
509
-                    __FUNCTION__,
510
-                    __LINE__
511
-                );
512
-            }
513
-            return true;
514
-        } else {
515
-            if ($add_error) {
516
-                EE_Error::add_error(
517
-                    __('The Event Espresso Configuration Settings were not updated.', 'event_espresso'),
518
-                    __FILE__,
519
-                    __FUNCTION__,
520
-                    __LINE__
521
-                );
522
-            }
523
-            return false;
524
-        }
525
-    }
526
-
527
-
528
-
529
-    /**
530
-     *    _verify_config_params
531
-     *
532
-     * @access    private
533
-     * @param    string         $section
534
-     * @param    string         $name
535
-     * @param    string         $config_class
536
-     * @param    EE_Config_Base $config_obj
537
-     * @param    array          $tests_to_run
538
-     * @param    bool           $display_errors
539
-     * @return    bool    TRUE on success, FALSE on fail
540
-     */
541
-    private function _verify_config_params(
542
-        $section = '',
543
-        $name = '',
544
-        $config_class = '',
545
-        $config_obj = null,
546
-        $tests_to_run = array(1, 2, 3, 4, 5, 6, 7, 8),
547
-        $display_errors = true
548
-    ) {
549
-        try {
550
-            foreach ($tests_to_run as $test) {
551
-                switch ($test) {
552
-                    // TEST #1 : check that section was set
553
-                    case 1 :
554
-                        if (empty($section)) {
555
-                            if ($display_errors) {
556
-                                throw new EE_Error(
557
-                                    sprintf(
558
-                                        __(
559
-                                            'No configuration section has been provided while attempting to save "%s".',
560
-                                            'event_espresso'
561
-                                        ),
562
-                                        $config_class
563
-                                    )
564
-                                );
565
-                            }
566
-                            return false;
567
-                        }
568
-                        break;
569
-                    // TEST #2 : check that settings section exists
570
-                    case 2 :
571
-                        if (! isset($this->{$section})) {
572
-                            if ($display_errors) {
573
-                                throw new EE_Error(
574
-                                    sprintf(
575
-                                        __('The "%s" configuration section does not exist.', 'event_espresso'),
576
-                                        $section
577
-                                    )
578
-                                );
579
-                            }
580
-                            return false;
581
-                        }
582
-                        break;
583
-                    // TEST #3 : check that section is the proper format
584
-                    case 3 :
585
-                        if (
586
-                        ! ($this->{$section} instanceof EE_Config_Base || $this->{$section} instanceof stdClass)
587
-                        ) {
588
-                            if ($display_errors) {
589
-                                throw new EE_Error(
590
-                                    sprintf(
591
-                                        __(
592
-                                            'The "%s" configuration settings have not been formatted correctly.',
593
-                                            'event_espresso'
594
-                                        ),
595
-                                        $section
596
-                                    )
597
-                                );
598
-                            }
599
-                            return false;
600
-                        }
601
-                        break;
602
-                    // TEST #4 : check that config section name has been set
603
-                    case 4 :
604
-                        if (empty($name)) {
605
-                            if ($display_errors) {
606
-                                throw new EE_Error(
607
-                                    __(
608
-                                        'No name has been provided for the specific configuration section.',
609
-                                        'event_espresso'
610
-                                    )
611
-                                );
612
-                            }
613
-                            return false;
614
-                        }
615
-                        break;
616
-                    // TEST #5 : check that a config class name has been set
617
-                    case 5 :
618
-                        if (empty($config_class)) {
619
-                            if ($display_errors) {
620
-                                throw new EE_Error(
621
-                                    __(
622
-                                        'No class name has been provided for the specific configuration section.',
623
-                                        'event_espresso'
624
-                                    )
625
-                                );
626
-                            }
627
-                            return false;
628
-                        }
629
-                        break;
630
-                    // TEST #6 : verify config class is accessible
631
-                    case 6 :
632
-                        if (! class_exists($config_class)) {
633
-                            if ($display_errors) {
634
-                                throw new EE_Error(
635
-                                    sprintf(
636
-                                        __(
637
-                                            'The "%s" class does not exist. Please ensure that an autoloader has been set for it.',
638
-                                            'event_espresso'
639
-                                        ),
640
-                                        $config_class
641
-                                    )
642
-                                );
643
-                            }
644
-                            return false;
645
-                        }
646
-                        break;
647
-                    // TEST #7 : check that config has even been set
648
-                    case 7 :
649
-                        if (! isset($this->{$section}->{$name})) {
650
-                            if ($display_errors) {
651
-                                throw new EE_Error(
652
-                                    sprintf(
653
-                                        __('No configuration has been set for "%1$s->%2$s".', 'event_espresso'),
654
-                                        $section,
655
-                                        $name
656
-                                    )
657
-                                );
658
-                            }
659
-                            return false;
660
-                        } else {
661
-                            // and make sure it's not serialized
662
-                            $this->{$section}->{$name} = maybe_unserialize($this->{$section}->{$name});
663
-                        }
664
-                        break;
665
-                    // TEST #8 : check that config is the requested type
666
-                    case 8 :
667
-                        if (! $this->{$section}->{$name} instanceof $config_class) {
668
-                            if ($display_errors) {
669
-                                throw new EE_Error(
670
-                                    sprintf(
671
-                                        __(
672
-                                            'The configuration for "%1$s->%2$s" is not of the "%3$s" class.',
673
-                                            'event_espresso'
674
-                                        ),
675
-                                        $section,
676
-                                        $name,
677
-                                        $config_class
678
-                                    )
679
-                                );
680
-                            }
681
-                            return false;
682
-                        }
683
-                        break;
684
-                    // TEST #9 : verify config object
685
-                    case 9 :
686
-                        if (! $config_obj instanceof EE_Config_Base) {
687
-                            if ($display_errors) {
688
-                                throw new EE_Error(
689
-                                    sprintf(
690
-                                        __('The "%s" class is not an instance of EE_Config_Base.', 'event_espresso'),
691
-                                        print_r($config_obj, true)
692
-                                    )
693
-                                );
694
-                            }
695
-                            return false;
696
-                        }
697
-                        break;
698
-                }
699
-            }
700
-        } catch (EE_Error $e) {
701
-            $e->get_error();
702
-        }
703
-        // you have successfully run the gauntlet
704
-        return true;
705
-    }
706
-
707
-
708
-
709
-    /**
710
-     *    _generate_config_option_name
711
-     *
712
-     * @access        protected
713
-     * @param        string $section
714
-     * @param        string $name
715
-     * @return        string
716
-     */
717
-    private function _generate_config_option_name($section = '', $name = '')
718
-    {
719
-        return 'ee_config-' . strtolower($section . '-' . str_replace(array('EE_', 'EED_'), '', $name));
720
-    }
721
-
722
-
723
-
724
-    /**
725
-     *    _set_config_class
726
-     * ensures that a config class is set, either from a passed config class or one generated from the config name
727
-     *
728
-     * @access    private
729
-     * @param    string $config_class
730
-     * @param    string $name
731
-     * @return    string
732
-     */
733
-    private function _set_config_class($config_class = '', $name = '')
734
-    {
735
-        return ! empty($config_class)
736
-            ? $config_class
737
-            : str_replace(' ', '_', ucwords(str_replace('_', ' ', $name))) . '_Config';
738
-    }
739
-
740
-
741
-
742
-    /**
743
-     *    set_config
744
-     *
745
-     * @access    protected
746
-     * @param    string         $section
747
-     * @param    string         $name
748
-     * @param    string         $config_class
749
-     * @param    EE_Config_Base $config_obj
750
-     * @return    EE_Config_Base
751
-     */
752
-    public function set_config($section = '', $name = '', $config_class = '', EE_Config_Base $config_obj = null)
753
-    {
754
-        // ensure config class is set to something
755
-        $config_class = $this->_set_config_class($config_class, $name);
756
-        // run tests 1-4, 6, and 7 to verify all config params are set and valid
757
-        if (! $this->_verify_config_params($section, $name, $config_class, null, array(1, 2, 3, 4, 5, 6))) {
758
-            return null;
759
-        }
760
-        $config_option_name = $this->_generate_config_option_name($section, $name);
761
-        // if the config option name hasn't been added yet to the list of option names we're tracking, then do so now
762
-        if (! isset($this->_addon_option_names[$config_option_name])) {
763
-            $this->_addon_option_names[$config_option_name] = $config_class;
764
-            $this->update_addon_option_names();
765
-        }
766
-        // verify the incoming config object but suppress errors
767
-        if (! $this->_verify_config_params($section, $name, $config_class, $config_obj, array(9), false)) {
768
-            $config_obj = new $config_class();
769
-        }
770
-        if (get_option($config_option_name)) {
771
-            EE_Config::log($config_option_name);
772
-            update_option($config_option_name, $config_obj);
773
-            $this->{$section}->{$name} = $config_obj;
774
-            return $this->{$section}->{$name};
775
-        } else {
776
-            // create a wp-option for this config
777
-            if (add_option($config_option_name, $config_obj, '', 'no')) {
778
-                $this->{$section}->{$name} = maybe_unserialize($config_obj);
779
-                return $this->{$section}->{$name};
780
-            } else {
781
-                EE_Error::add_error(
782
-                    sprintf(__('The "%s" could not be saved to the database.', 'event_espresso'), $config_class),
783
-                    __FILE__,
784
-                    __FUNCTION__,
785
-                    __LINE__
786
-                );
787
-                return null;
788
-            }
789
-        }
790
-    }
791
-
792
-
793
-
794
-    /**
795
-     *    update_config
796
-     * Important: the config object must ALREADY be set, otherwise this will produce an error.
797
-     *
798
-     * @access    public
799
-     * @param    string                $section
800
-     * @param    string                $name
801
-     * @param    EE_Config_Base|string $config_obj
802
-     * @param    bool                  $throw_errors
803
-     * @return    bool
804
-     */
805
-    public function update_config($section = '', $name = '', $config_obj = '', $throw_errors = true)
806
-    {
807
-        // don't allow config updates during WP heartbeats
808
-        if (\EE_Registry::instance()->REQ->get('action', '') === 'heartbeat') {
809
-            return false;
810
-        }
811
-        $config_obj = maybe_unserialize($config_obj);
812
-        // get class name of the incoming object
813
-        $config_class = get_class($config_obj);
814
-        // run tests 1-5 and 9 to verify config
815
-        if (! $this->_verify_config_params(
816
-            $section,
817
-            $name,
818
-            $config_class,
819
-            $config_obj,
820
-            array(1, 2, 3, 4, 7, 9)
821
-        )
822
-        ) {
823
-            return false;
824
-        }
825
-        $config_option_name = $this->_generate_config_option_name($section, $name);
826
-        // check if config object has been added to db by seeing if config option name is in $this->_addon_option_names array
827
-        if (! isset($this->_addon_option_names[$config_option_name])) {
828
-            // save new config to db
829
-            if ($this->set_config($section, $name, $config_class, $config_obj)) {
830
-                return true;
831
-            }
832
-        } else {
833
-            // first check if the record already exists
834
-            $existing_config = get_option($config_option_name);
835
-            $config_obj = serialize($config_obj);
836
-            // just return if db record is already up to date (NOT type safe comparison)
837
-            if ($existing_config == $config_obj) {
838
-                $this->{$section}->{$name} = $config_obj;
839
-                return true;
840
-            } else if (update_option($config_option_name, $config_obj)) {
841
-                EE_Config::log($config_option_name);
842
-                // update wp-option for this config class
843
-                $this->{$section}->{$name} = $config_obj;
844
-                return true;
845
-            } elseif ($throw_errors) {
846
-                EE_Error::add_error(
847
-                    sprintf(
848
-                        __(
849
-                            'The "%1$s" object stored at"%2$s" was not successfully updated in the database.',
850
-                            'event_espresso'
851
-                        ),
852
-                        $config_class,
853
-                        'EE_Config->' . $section . '->' . $name
854
-                    ),
855
-                    __FILE__,
856
-                    __FUNCTION__,
857
-                    __LINE__
858
-                );
859
-            }
860
-        }
861
-        return false;
862
-    }
863
-
864
-
865
-
866
-    /**
867
-     *    get_config
868
-     *
869
-     * @access    public
870
-     * @param    string $section
871
-     * @param    string $name
872
-     * @param    string $config_class
873
-     * @return    mixed EE_Config_Base | NULL
874
-     */
875
-    public function get_config($section = '', $name = '', $config_class = '')
876
-    {
877
-        // ensure config class is set to something
878
-        $config_class = $this->_set_config_class($config_class, $name);
879
-        // run tests 1-4, 6 and 7 to verify that all params have been set
880
-        if (! $this->_verify_config_params($section, $name, $config_class, null, array(1, 2, 3, 4, 5, 6))) {
881
-            return null;
882
-        }
883
-        // now test if the requested config object exists, but suppress errors
884
-        if ($this->_verify_config_params($section, $name, $config_class, null, array(7, 8), false)) {
885
-            // config already exists, so pass it back
886
-            return $this->{$section}->{$name};
887
-        }
888
-        // load config option from db if it exists
889
-        $config_obj = $this->get_config_option($this->_generate_config_option_name($section, $name));
890
-        // verify the newly retrieved config object, but suppress errors
891
-        if ($this->_verify_config_params($section, $name, $config_class, $config_obj, array(9), false)) {
892
-            // config is good, so set it and pass it back
893
-            $this->{$section}->{$name} = $config_obj;
894
-            return $this->{$section}->{$name};
895
-        }
896
-        // oops! $config_obj is not already set and does not exist in the db, so create a new one
897
-        $config_obj = $this->set_config($section, $name, $config_class);
898
-        // verify the newly created config object
899
-        if ($this->_verify_config_params($section, $name, $config_class, $config_obj, array(9))) {
900
-            return $this->{$section}->{$name};
901
-        } else {
902
-            EE_Error::add_error(
903
-                sprintf(__('The "%s" could not be retrieved from the database.', 'event_espresso'), $config_class),
904
-                __FILE__,
905
-                __FUNCTION__,
906
-                __LINE__
907
-            );
908
-        }
909
-        return null;
910
-    }
911
-
912
-
913
-
914
-    /**
915
-     *    get_config_option
916
-     *
917
-     * @access    public
918
-     * @param    string $config_option_name
919
-     * @return    mixed EE_Config_Base | FALSE
920
-     */
921
-    public function get_config_option($config_option_name = '')
922
-    {
923
-        // retrieve the wp-option for this config class.
924
-        $config_option = maybe_unserialize(get_option($config_option_name, array()));
925
-        if (empty($config_option)) {
926
-            EE_Config::log($config_option_name . '-NOT-FOUND');
927
-        }
928
-        return $config_option;
929
-    }
930
-
931
-
932
-
933
-    /**
934
-     * log
935
-     *
936
-     * @param string $config_option_name
937
-     */
938
-    public static function log($config_option_name = '')
939
-    {
940
-        if (EE_Config::logging_enabled() && ! empty($config_option_name)) {
941
-            $config_log = get_option(EE_Config::LOG_NAME, array());
942
-            //copy incoming $_REQUEST and sanitize it so we can save it
943
-            $_request = $_REQUEST;
944
-            array_walk_recursive($_request, 'sanitize_text_field');
945
-            $config_log[(string)microtime(true)] = array(
946
-                'config_name' => $config_option_name,
947
-                'request'     => $_request,
948
-            );
949
-            update_option(EE_Config::LOG_NAME, $config_log);
950
-        }
951
-    }
952
-
953
-
954
-
955
-    /**
956
-     * trim_log
957
-     * reduces the size of the config log to the length specified by EE_Config::LOG_LENGTH
958
-     */
959
-    public static function trim_log()
960
-    {
961
-        if (! EE_Config::logging_enabled()) {
962
-            return;
963
-        }
964
-        $config_log = maybe_unserialize(get_option(EE_Config::LOG_NAME, array()));
965
-        $log_length = count($config_log);
966
-        if ($log_length > EE_Config::LOG_LENGTH) {
967
-            ksort($config_log);
968
-            $config_log = array_slice($config_log, $log_length - EE_Config::LOG_LENGTH, null, true);
969
-            update_option(EE_Config::LOG_NAME, $config_log);
970
-        }
971
-    }
972
-
973
-
974
-
975
-    /**
976
-     *    get_page_for_posts
977
-     *    if the wp-option "show_on_front" is set to "page", then this is the post_name for the post set in the
978
-     *    wp-option "page_for_posts", or "posts" if no page is selected
979
-     *
980
-     * @access    public
981
-     * @return    string
982
-     */
983
-    public static function get_page_for_posts()
984
-    {
985
-        $page_for_posts = get_option('page_for_posts');
986
-        if (! $page_for_posts) {
987
-            return 'posts';
988
-        }
989
-        /** @type WPDB $wpdb */
990
-        global $wpdb;
991
-        $SQL = "SELECT post_name from $wpdb->posts WHERE post_type='posts' OR post_type='page' AND post_status='publish' AND ID=%d";
992
-        return $wpdb->get_var($wpdb->prepare($SQL, $page_for_posts));
993
-    }
994
-
995
-
996
-
997
-    /**
998
-     *    register_shortcodes_and_modules.
999
-     *    At this point, it's too early to tell if we're maintenance mode or not.
1000
-     *    In fact, this is where we give modules a chance to let core know they exist
1001
-     *    so they can help trigger maintenance mode if it's needed
1002
-     *
1003
-     * @access    public
1004
-     * @return    void
1005
-     */
1006
-    public function register_shortcodes_and_modules()
1007
-    {
1008
-        // allow modules to set hooks for the rest of the system
1009
-        EE_Registry::instance()->modules = $this->_register_modules();
1010
-    }
1011
-
1012
-
1013
-
1014
-    /**
1015
-     *    initialize_shortcodes_and_modules
1016
-     *    meaning they can start adding their hooks to get stuff done
1017
-     *
1018
-     * @access    public
1019
-     * @return    void
1020
-     */
1021
-    public function initialize_shortcodes_and_modules()
1022
-    {
1023
-        // allow modules to set hooks for the rest of the system
1024
-        $this->_initialize_modules();
1025
-    }
1026
-
1027
-
1028
-
1029
-    /**
1030
-     *    widgets_init
1031
-     *
1032
-     * @access private
1033
-     * @return void
1034
-     */
1035
-    public function widgets_init()
1036
-    {
1037
-        //only init widgets on admin pages when not in complete maintenance, and
1038
-        //on frontend when not in any maintenance mode
1039
-        if (
1040
-            ! EE_Maintenance_Mode::instance()->level()
1041
-            || (
1042
-                is_admin()
1043
-                && EE_Maintenance_Mode::instance()->level() !== EE_Maintenance_Mode::level_2_complete_maintenance
1044
-            )
1045
-        ) {
1046
-            // grab list of installed widgets
1047
-            $widgets_to_register = glob(EE_WIDGETS . '*', GLOB_ONLYDIR);
1048
-            // filter list of modules to register
1049
-            $widgets_to_register = apply_filters(
1050
-                'FHEE__EE_Config__register_widgets__widgets_to_register',
1051
-                $widgets_to_register
1052
-            );
1053
-            if (! empty($widgets_to_register)) {
1054
-                // cycle thru widget folders
1055
-                foreach ($widgets_to_register as $widget_path) {
1056
-                    // add to list of installed widget modules
1057
-                    EE_Config::register_ee_widget($widget_path);
1058
-                }
1059
-            }
1060
-            // filter list of installed modules
1061
-            EE_Registry::instance()->widgets = apply_filters(
1062
-                'FHEE__EE_Config__register_widgets__installed_widgets',
1063
-                EE_Registry::instance()->widgets
1064
-            );
1065
-        }
1066
-    }
1067
-
1068
-
1069
-
1070
-    /**
1071
-     *    register_ee_widget - makes core aware of this widget
1072
-     *
1073
-     * @access    public
1074
-     * @param    string $widget_path - full path up to and including widget folder
1075
-     * @return    void
1076
-     */
1077
-    public static function register_ee_widget($widget_path = null)
1078
-    {
1079
-        do_action('AHEE__EE_Config__register_widget__begin', $widget_path);
1080
-        $widget_ext = '.widget.php';
1081
-        // make all separators match
1082
-        $widget_path = rtrim(str_replace('/\\', DS, $widget_path), DS);
1083
-        // does the file path INCLUDE the actual file name as part of the path ?
1084
-        if (strpos($widget_path, $widget_ext) !== false) {
1085
-            // grab and shortcode file name from directory name and break apart at dots
1086
-            $file_name = explode('.', basename($widget_path));
1087
-            // take first segment from file name pieces and remove class prefix if it exists
1088
-            $widget = strpos($file_name[0], 'EEW_') === 0 ? substr($file_name[0], 4) : $file_name[0];
1089
-            // sanitize shortcode directory name
1090
-            $widget = sanitize_key($widget);
1091
-            // now we need to rebuild the shortcode path
1092
-            $widget_path = explode(DS, $widget_path);
1093
-            // remove last segment
1094
-            array_pop($widget_path);
1095
-            // glue it back together
1096
-            $widget_path = implode(DS, $widget_path);
1097
-        } else {
1098
-            // grab and sanitize widget directory name
1099
-            $widget = sanitize_key(basename($widget_path));
1100
-        }
1101
-        // create classname from widget directory name
1102
-        $widget = str_replace(' ', '_', ucwords(str_replace('_', ' ', $widget)));
1103
-        // add class prefix
1104
-        $widget_class = 'EEW_' . $widget;
1105
-        // does the widget exist ?
1106
-        if (! is_readable($widget_path . DS . $widget_class . $widget_ext)) {
1107
-            $msg = sprintf(
1108
-                __(
1109
-                    'The requested %s widget file could not be found or is not readable due to file permissions. Please ensure the following path is correct: %s',
1110
-                    'event_espresso'
1111
-                ),
1112
-                $widget_class,
1113
-                $widget_path . DS . $widget_class . $widget_ext
1114
-            );
1115
-            EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__);
1116
-            return;
1117
-        }
1118
-        // load the widget class file
1119
-        require_once($widget_path . DS . $widget_class . $widget_ext);
1120
-        // verify that class exists
1121
-        if (! class_exists($widget_class)) {
1122
-            $msg = sprintf(__('The requested %s widget class does not exist.', 'event_espresso'), $widget_class);
1123
-            EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__);
1124
-            return;
1125
-        }
1126
-        register_widget($widget_class);
1127
-        // add to array of registered widgets
1128
-        EE_Registry::instance()->widgets->{$widget_class} = $widget_path . DS . $widget_class . $widget_ext;
1129
-    }
1130
-
1131
-
1132
-
1133
-    /**
1134
-     *        _register_modules
1135
-     *
1136
-     * @access private
1137
-     * @return array
1138
-     */
1139
-    private function _register_modules()
1140
-    {
1141
-        // grab list of installed modules
1142
-        $modules_to_register = glob(EE_MODULES . '*', GLOB_ONLYDIR);
1143
-        // filter list of modules to register
1144
-        $modules_to_register = apply_filters(
1145
-            'FHEE__EE_Config__register_modules__modules_to_register',
1146
-            $modules_to_register
1147
-        );
1148
-        if (! empty($modules_to_register)) {
1149
-            // loop through folders
1150
-            foreach ($modules_to_register as $module_path) {
1151
-                /**TEMPORARILY EXCLUDE gateways from modules for time being**/
1152
-                if (
1153
-                    $module_path !== EE_MODULES . 'zzz-copy-this-module-template'
1154
-                    && $module_path !== EE_MODULES . 'gateways'
1155
-                ) {
1156
-                    // add to list of installed modules
1157
-                    EE_Config::register_module($module_path);
1158
-                }
1159
-            }
1160
-        }
1161
-        // filter list of installed modules
1162
-        return apply_filters(
1163
-            'FHEE__EE_Config___register_modules__installed_modules',
1164
-            EE_Registry::instance()->modules
1165
-        );
1166
-    }
1167
-
1168
-
1169
-
1170
-    /**
1171
-     *    register_module - makes core aware of this module
1172
-     *
1173
-     * @access    public
1174
-     * @param    string $module_path - full path up to and including module folder
1175
-     * @return    bool
1176
-     */
1177
-    public static function register_module($module_path = null)
1178
-    {
1179
-        do_action('AHEE__EE_Config__register_module__begin', $module_path);
1180
-        $module_ext = '.module.php';
1181
-        // make all separators match
1182
-        $module_path = str_replace(array('\\', '/'), DS, $module_path);
1183
-        // does the file path INCLUDE the actual file name as part of the path ?
1184
-        if (strpos($module_path, $module_ext) !== false) {
1185
-            // grab and shortcode file name from directory name and break apart at dots
1186
-            $module_file = explode('.', basename($module_path));
1187
-            // now we need to rebuild the shortcode path
1188
-            $module_path = explode(DS, $module_path);
1189
-            // remove last segment
1190
-            array_pop($module_path);
1191
-            // glue it back together
1192
-            $module_path = implode(DS, $module_path) . DS;
1193
-            // take first segment from file name pieces and sanitize it
1194
-            $module = preg_replace('/[^a-zA-Z0-9_\-]/', '', $module_file[0]);
1195
-            // ensure class prefix is added
1196
-            $module_class = strpos($module, 'EED_') !== 0 ? 'EED_' . $module : $module;
1197
-        } else {
1198
-            // we need to generate the filename based off of the folder name
1199
-            // grab and sanitize module name
1200
-            $module = strtolower(basename($module_path));
1201
-            $module = preg_replace('/[^a-z0-9_\-]/', '', $module);
1202
-            // like trailingslashit()
1203
-            $module_path = rtrim($module_path, DS) . DS;
1204
-            // create classname from module directory name
1205
-            $module = str_replace(' ', '_', ucwords(str_replace('_', ' ', $module)));
1206
-            // add class prefix
1207
-            $module_class = 'EED_' . $module;
1208
-        }
1209
-        // does the module exist ?
1210
-        if (! is_readable($module_path . DS . $module_class . $module_ext)) {
1211
-            $msg = sprintf(
1212
-                __(
1213
-                    'The requested %s module file could not be found or is not readable due to file permissions.',
1214
-                    'event_espresso'
1215
-                ),
1216
-                $module
1217
-            );
1218
-            EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__);
1219
-            return false;
1220
-        }
1221
-        // load the module class file
1222
-        require_once($module_path . $module_class . $module_ext);
1223
-        // verify that class exists
1224
-        if (! class_exists($module_class)) {
1225
-            $msg = sprintf(__('The requested %s module class does not exist.', 'event_espresso'), $module_class);
1226
-            EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__);
1227
-            return false;
1228
-        }
1229
-        // add to array of registered modules
1230
-        EE_Registry::instance()->modules->{$module_class} = $module_path . $module_class . $module_ext;
1231
-        do_action(
1232
-            'AHEE__EE_Config__register_module__complete',
1233
-            $module_class,
1234
-            EE_Registry::instance()->modules->{$module_class}
1235
-        );
1236
-        return true;
1237
-    }
1238
-
1239
-
1240
-
1241
-    /**
1242
-     *    _initialize_modules
1243
-     *    allow modules to set hooks for the rest of the system
1244
-     *
1245
-     * @access private
1246
-     * @return void
1247
-     */
1248
-    private function _initialize_modules()
1249
-    {
1250
-        // cycle thru shortcode folders
1251
-        foreach (EE_Registry::instance()->modules as $module_class => $module_path) {
1252
-            // fire the shortcode class's set_hooks methods in case it needs to hook into other parts of the system
1253
-            // which set hooks ?
1254
-            if (is_admin()) {
1255
-                // fire immediately
1256
-                call_user_func(array($module_class, 'set_hooks_admin'));
1257
-            } else {
1258
-                // delay until other systems are online
1259
-                add_action(
1260
-                    'AHEE__EE_System__set_hooks_for_shortcodes_modules_and_addons',
1261
-                    array($module_class, 'set_hooks')
1262
-                );
1263
-            }
1264
-        }
1265
-    }
1266
-
1267
-
1268
-
1269
-    /**
1270
-     *    register_route - adds module method routes to route_map
1271
-     *
1272
-     * @access    public
1273
-     * @param    string $route       - "pretty" public alias for module method
1274
-     * @param    string $module      - module name (classname without EED_ prefix)
1275
-     * @param    string $method_name - the actual module method to be routed to
1276
-     * @param    string $key         - url param key indicating a route is being called
1277
-     * @return    bool
1278
-     */
1279
-    public static function register_route($route = null, $module = null, $method_name = null, $key = 'ee')
1280
-    {
1281
-        do_action('AHEE__EE_Config__register_route__begin', $route, $module, $method_name);
1282
-        $module = str_replace('EED_', '', $module);
1283
-        $module_class = 'EED_' . $module;
1284
-        if (! isset(EE_Registry::instance()->modules->{$module_class})) {
1285
-            $msg = sprintf(__('The module %s has not been registered.', 'event_espresso'), $module);
1286
-            EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__);
1287
-            return false;
1288
-        }
1289
-        if (empty($route)) {
1290
-            $msg = sprintf(__('No route has been supplied.', 'event_espresso'), $route);
1291
-            EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__);
1292
-            return false;
1293
-        }
1294
-        if (! method_exists('EED_' . $module, $method_name)) {
1295
-            $msg = sprintf(
1296
-                __('A valid class method for the %s route has not been supplied.', 'event_espresso'),
1297
-                $route
1298
-            );
1299
-            EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__);
1300
-            return false;
1301
-        }
1302
-        EE_Config::$_module_route_map[$key][$route] = array('EED_' . $module, $method_name);
1303
-        return true;
1304
-    }
1305
-
1306
-
1307
-
1308
-    /**
1309
-     *    get_route - get module method route
1310
-     *
1311
-     * @access    public
1312
-     * @param    string $route - "pretty" public alias for module method
1313
-     * @param    string $key   - url param key indicating a route is being called
1314
-     * @return    string
1315
-     */
1316
-    public static function get_route($route = null, $key = 'ee')
1317
-    {
1318
-        do_action('AHEE__EE_Config__get_route__begin', $route);
1319
-        $route = (string)apply_filters('FHEE__EE_Config__get_route', $route);
1320
-        if (isset(EE_Config::$_module_route_map[$key][$route])) {
1321
-            return EE_Config::$_module_route_map[$key][$route];
1322
-        }
1323
-        return null;
1324
-    }
1325
-
1326
-
1327
-
1328
-    /**
1329
-     *    get_routes - get ALL module method routes
1330
-     *
1331
-     * @access    public
1332
-     * @return    array
1333
-     */
1334
-    public static function get_routes()
1335
-    {
1336
-        return EE_Config::$_module_route_map;
1337
-    }
1338
-
1339
-
1340
-
1341
-    /**
1342
-     *    register_forward - allows modules to forward request to another module for further processing
1343
-     *
1344
-     * @access    public
1345
-     * @param    string       $route   - "pretty" public alias for module method
1346
-     * @param    integer      $status  - integer value corresponding  to status constant strings set in module parent
1347
-     *                                 class, allows different forwards to be served based on status
1348
-     * @param    array|string $forward - function name or array( class, method )
1349
-     * @param    string       $key     - url param key indicating a route is being called
1350
-     * @return    bool
1351
-     */
1352
-    public static function register_forward($route = null, $status = 0, $forward = null, $key = 'ee')
1353
-    {
1354
-        do_action('AHEE__EE_Config__register_forward', $route, $status, $forward);
1355
-        if (! isset(EE_Config::$_module_route_map[$key][$route]) || empty($route)) {
1356
-            $msg = sprintf(
1357
-                __('The module route %s for this forward has not been registered.', 'event_espresso'),
1358
-                $route
1359
-            );
1360
-            EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__);
1361
-            return false;
1362
-        }
1363
-        if (empty($forward)) {
1364
-            $msg = sprintf(__('No forwarding route has been supplied.', 'event_espresso'), $route);
1365
-            EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__);
1366
-            return false;
1367
-        }
1368
-        if (is_array($forward)) {
1369
-            if (! isset($forward[1])) {
1370
-                $msg = sprintf(
1371
-                    __('A class method for the %s forwarding route has not been supplied.', 'event_espresso'),
1372
-                    $route
1373
-                );
1374
-                EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__);
1375
-                return false;
1376
-            }
1377
-            if (! method_exists($forward[0], $forward[1])) {
1378
-                $msg = sprintf(
1379
-                    __('The class method %s for the %s forwarding route is in invalid.', 'event_espresso'),
1380
-                    $forward[1],
1381
-                    $route
1382
-                );
1383
-                EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__);
1384
-                return false;
1385
-            }
1386
-        } else if (! function_exists($forward)) {
1387
-            $msg = sprintf(
1388
-                __('The function %s for the %s forwarding route is in invalid.', 'event_espresso'),
1389
-                $forward,
1390
-                $route
1391
-            );
1392
-            EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__);
1393
-            return false;
1394
-        }
1395
-        EE_Config::$_module_forward_map[$key][$route][absint($status)] = $forward;
1396
-        return true;
1397
-    }
1398
-
1399
-
1400
-
1401
-    /**
1402
-     *    get_forward - get forwarding route
1403
-     *
1404
-     * @access    public
1405
-     * @param    string  $route  - "pretty" public alias for module method
1406
-     * @param    integer $status - integer value corresponding  to status constant strings set in module parent class,
1407
-     *                           allows different forwards to be served based on status
1408
-     * @param    string  $key    - url param key indicating a route is being called
1409
-     * @return    string
1410
-     */
1411
-    public static function get_forward($route = null, $status = 0, $key = 'ee')
1412
-    {
1413
-        do_action('AHEE__EE_Config__get_forward__begin', $route, $status);
1414
-        if (isset(EE_Config::$_module_forward_map[$key][$route][$status])) {
1415
-            return apply_filters(
1416
-                'FHEE__EE_Config__get_forward',
1417
-                EE_Config::$_module_forward_map[$key][$route][$status],
1418
-                $route,
1419
-                $status
1420
-            );
1421
-        }
1422
-        return null;
1423
-    }
1424
-
1425
-
1426
-
1427
-    /**
1428
-     *    register_forward - allows modules to specify different view templates for different method routes and status
1429
-     *    results
1430
-     *
1431
-     * @access    public
1432
-     * @param    string  $route  - "pretty" public alias for module method
1433
-     * @param    integer $status - integer value corresponding  to status constant strings set in module parent class,
1434
-     *                           allows different views to be served based on status
1435
-     * @param    string  $view
1436
-     * @param    string  $key    - url param key indicating a route is being called
1437
-     * @return    bool
1438
-     */
1439
-    public static function register_view($route = null, $status = 0, $view = null, $key = 'ee')
1440
-    {
1441
-        do_action('AHEE__EE_Config__register_view__begin', $route, $status, $view);
1442
-        if (! isset(EE_Config::$_module_route_map[$key][$route]) || empty($route)) {
1443
-            $msg = sprintf(
1444
-                __('The module route %s for this view has not been registered.', 'event_espresso'),
1445
-                $route
1446
-            );
1447
-            EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__);
1448
-            return false;
1449
-        }
1450
-        if (! is_readable($view)) {
1451
-            $msg = sprintf(
1452
-                __(
1453
-                    'The %s view file could not be found or is not readable due to file permissions.',
1454
-                    'event_espresso'
1455
-                ),
1456
-                $view
1457
-            );
1458
-            EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__);
1459
-            return false;
1460
-        }
1461
-        EE_Config::$_module_view_map[$key][$route][absint($status)] = $view;
1462
-        return true;
1463
-    }
1464
-
1465
-
1466
-
1467
-    /**
1468
-     *    get_view - get view for route and status
1469
-     *
1470
-     * @access    public
1471
-     * @param    string  $route  - "pretty" public alias for module method
1472
-     * @param    integer $status - integer value corresponding  to status constant strings set in module parent class,
1473
-     *                           allows different views to be served based on status
1474
-     * @param    string  $key    - url param key indicating a route is being called
1475
-     * @return    string
1476
-     */
1477
-    public static function get_view($route = null, $status = 0, $key = 'ee')
1478
-    {
1479
-        do_action('AHEE__EE_Config__get_view__begin', $route, $status);
1480
-        if (isset(EE_Config::$_module_view_map[$key][$route][$status])) {
1481
-            return apply_filters(
1482
-                'FHEE__EE_Config__get_view',
1483
-                EE_Config::$_module_view_map[$key][$route][$status],
1484
-                $route,
1485
-                $status
1486
-            );
1487
-        }
1488
-        return null;
1489
-    }
1490
-
1491
-
1492
-
1493
-    public function update_addon_option_names()
1494
-    {
1495
-        update_option(EE_Config::ADDON_OPTION_NAMES, $this->_addon_option_names);
1496
-    }
1497
-
1498
-
1499
-
1500
-    public function shutdown()
1501
-    {
1502
-        $this->update_addon_option_names();
1503
-    }
1504
-
1505
-
1506
-
1507
-    /**
1508
-     * @return LegacyShortcodesManager
1509
-     */
1510
-    public static function getLegacyShortcodesManager()
1511
-    {
1512
-
1513
-        if ( ! EE_Config::instance()->legacy_shortcodes_manager instanceof LegacyShortcodesManager) {
1514
-            EE_Config::instance()->legacy_shortcodes_manager = new LegacyShortcodesManager(
1515
-                EE_Registry::instance()
1516
-            );
1517
-        }
1518
-        return EE_Config::instance()->legacy_shortcodes_manager;
1519
-    }
1520
-
1521
-
1522
-
1523
-    /**
1524
-     * register_shortcode - makes core aware of this shortcode
1525
-     *
1526
-     * @deprecated 4.9.26
1527
-     * @param    string $shortcode_path - full path up to and including shortcode folder
1528
-     * @return    bool
1529
-     */
1530
-    public static function register_shortcode($shortcode_path = null)
1531
-    {
1532
-        EE_Error::doing_it_wrong(
1533
-            __METHOD__,
1534
-            __(
1535
-                'Usage is deprecated. Use \EventEspresso\core\services\shortcodes\LegacyShortcodesManager::registerShortcode() as direct replacement, or better yet, please see the new \EventEspresso\core\services\shortcodes\ShortcodesManager class.',
1536
-                'event_espresso'
1537
-            ),
1538
-            '4.9.26'
1539
-        );
1540
-        return EE_Config::instance()->getLegacyShortcodesManager()->registerShortcode($shortcode_path);
1541
-    }
1542
-
1543
-
1544
-
1545
-}
1546
-
1547
-
1548
-
1549
-/**
1550
- * Base class used for config classes. These classes should generally not have
1551
- * magic functions in use, except we'll allow them to magically set and get stuff...
1552
- * basically, they should just be well-defined stdClasses
1553
- */
1554
-class EE_Config_Base
1555
-{
1556
-
1557
-    /**
1558
-     * Utility function for escaping the value of a property and returning.
1559
-     *
1560
-     * @param string $property property name (checks to see if exists).
1561
-     * @return mixed if a detected type found return the escaped value, otherwise just the raw value is returned.
1562
-     * @throws \EE_Error
1563
-     */
1564
-    public function get_pretty($property)
1565
-    {
1566
-        if (! property_exists($this, $property)) {
1567
-            throw new EE_Error(
1568
-                sprintf(
1569
-                    __(
1570
-                        '%1$s::get_pretty() has been called with the property %2$s which does not exist on the %1$s config class.',
1571
-                        'event_espresso'
1572
-                    ),
1573
-                    get_class($this),
1574
-                    $property
1575
-                )
1576
-            );
1577
-        }
1578
-        //just handling escaping of strings for now.
1579
-        if (is_string($this->{$property})) {
1580
-            return stripslashes($this->{$property});
1581
-        }
1582
-        return $this->{$property};
1583
-    }
1584
-
1585
-
1586
-
1587
-    public function populate()
1588
-    {
1589
-        //grab defaults via a new instance of this class.
1590
-        $class_name = get_class($this);
1591
-        $defaults = new $class_name;
1592
-        //loop through the properties for this class and see if they are set.  If they are NOT, then grab the
1593
-        //default from our $defaults object.
1594
-        foreach (get_object_vars($defaults) as $property => $value) {
1595
-            if ($this->{$property} === null) {
1596
-                $this->{$property} = $value;
1597
-            }
1598
-        }
1599
-        //cleanup
1600
-        unset($defaults);
1601
-    }
1602
-
1603
-
1604
-
1605
-    /**
1606
-     *        __isset
1607
-     *
1608
-     * @param $a
1609
-     * @return bool
1610
-     */
1611
-    public function __isset($a)
1612
-    {
1613
-        return false;
1614
-    }
1615
-
1616
-
1617
-
1618
-    /**
1619
-     *        __unset
1620
-     *
1621
-     * @param $a
1622
-     * @return bool
1623
-     */
1624
-    public function __unset($a)
1625
-    {
1626
-        return false;
1627
-    }
1628
-
1629
-
1630
-
1631
-    /**
1632
-     *        __clone
1633
-     */
1634
-    public function __clone()
1635
-    {
1636
-    }
1637
-
1638
-
1639
-
1640
-    /**
1641
-     *        __wakeup
1642
-     */
1643
-    public function __wakeup()
1644
-    {
1645
-    }
1646
-
1647
-
1648
-
1649
-    /**
1650
-     *        __destruct
1651
-     */
1652
-    public function __destruct()
1653
-    {
1654
-    }
1655
-}
1656
-
1657
-
1658
-
1659
-/**
1660
- * Class for defining what's in the EE_Config relating to registration settings
1661
- */
1662
-class EE_Core_Config extends EE_Config_Base
1663
-{
1664
-
1665
-    public $current_blog_id;
1666
-
1667
-    public $ee_ueip_optin;
1668
-
1669
-    public $ee_ueip_has_notified;
1670
-
1671
-    /**
1672
-     * Not to be confused with the 4 critical page variables (See
1673
-     * get_critical_pages_array()), this is just an array of wp posts that have EE
1674
-     * shortcodes in them. Keys are slugs, values are arrays with only 1 element: where the key is the shortcode
1675
-     * in the page, and the value is the page's ID. The key 'posts' is basically a duplicate of this same array.
1676
-     *
1677
-     * @var array
1678
-     */
1679
-    public $post_shortcodes;
1680
-
1681
-    public $module_route_map;
1682
-
1683
-    public $module_forward_map;
1684
-
1685
-    public $module_view_map;
1686
-
1687
-    /**
1688
-     * The next 4 vars are the IDs of critical EE pages.
1689
-     *
1690
-     * @var int
1691
-     */
1692
-    public $reg_page_id;
1693
-
1694
-    public $txn_page_id;
1695
-
1696
-    public $thank_you_page_id;
1697
-
1698
-    public $cancel_page_id;
1699
-
1700
-    /**
1701
-     * The next 4 vars are the URLs of critical EE pages.
1702
-     *
1703
-     * @var int
1704
-     */
1705
-    public $reg_page_url;
1706
-
1707
-    public $txn_page_url;
1708
-
1709
-    public $thank_you_page_url;
1710
-
1711
-    public $cancel_page_url;
1712
-
1713
-    /**
1714
-     * The next vars relate to the custom slugs for EE CPT routes
1715
-     */
1716
-    public $event_cpt_slug;
1717
-
1718
-
1719
-    /**
1720
-     * This caches the _ee_ueip_option in case this config is reset in the same
1721
-     * request across blog switches in a multisite context.
1722
-     * Avoids extra queries to the db for this option.
1723
-     *
1724
-     * @var bool
1725
-     */
1726
-    public static $ee_ueip_option;
1727
-
1728
-
1729
-
1730
-    /**
1731
-     *    class constructor
1732
-     *
1733
-     * @access    public
1734
-     */
1735
-    public function __construct()
1736
-    {
1737
-        // set default organization settings
1738
-        $this->current_blog_id = get_current_blog_id();
1739
-        $this->current_blog_id = $this->current_blog_id === null ? 1 : $this->current_blog_id;
1740
-        $this->ee_ueip_optin = $this->_get_main_ee_ueip_optin();
1741
-        $this->ee_ueip_has_notified = is_main_site() ? get_option('ee_ueip_has_notified', false) : true;
1742
-        $this->post_shortcodes = array();
1743
-        $this->module_route_map = array();
1744
-        $this->module_forward_map = array();
1745
-        $this->module_view_map = array();
1746
-        // critical EE page IDs
1747
-        $this->reg_page_id = 0;
1748
-        $this->txn_page_id = 0;
1749
-        $this->thank_you_page_id = 0;
1750
-        $this->cancel_page_id = 0;
1751
-        // critical EE page URLs
1752
-        $this->reg_page_url = '';
1753
-        $this->txn_page_url = '';
1754
-        $this->thank_you_page_url = '';
1755
-        $this->cancel_page_url = '';
1756
-        //cpt slugs
1757
-        $this->event_cpt_slug = __('events', 'event_espresso');
1758
-        //ueip constant check
1759
-        if (defined('EE_DISABLE_UXIP') && EE_DISABLE_UXIP) {
1760
-            $this->ee_ueip_optin = false;
1761
-            $this->ee_ueip_has_notified = true;
1762
-        }
1763
-    }
1764
-
1765
-
1766
-
1767
-    /**
1768
-     * @return array
1769
-     */
1770
-    public function get_critical_pages_array()
1771
-    {
1772
-        return array(
1773
-            $this->reg_page_id,
1774
-            $this->txn_page_id,
1775
-            $this->thank_you_page_id,
1776
-            $this->cancel_page_id,
1777
-        );
1778
-    }
1779
-
1780
-
1781
-
1782
-    /**
1783
-     * @return array
1784
-     */
1785
-    public function get_critical_pages_shortcodes_array()
1786
-    {
1787
-        return array(
1788
-            $this->reg_page_id       => 'ESPRESSO_CHECKOUT',
1789
-            $this->txn_page_id       => 'ESPRESSO_TXN_PAGE',
1790
-            $this->thank_you_page_id => 'ESPRESSO_THANK_YOU',
1791
-            $this->cancel_page_id    => 'ESPRESSO_CANCELLED',
1792
-        );
1793
-    }
1794
-
1795
-
1796
-
1797
-    /**
1798
-     *  gets/returns URL for EE reg_page
1799
-     *
1800
-     * @access    public
1801
-     * @return    string
1802
-     */
1803
-    public function reg_page_url()
1804
-    {
1805
-        if (! $this->reg_page_url) {
1806
-            $this->reg_page_url = add_query_arg(
1807
-                                      array('uts' => time()),
1808
-                                      get_permalink($this->reg_page_id)
1809
-                                  ) . '#checkout';
1810
-        }
1811
-        return $this->reg_page_url;
1812
-    }
1813
-
1814
-
1815
-
1816
-    /**
1817
-     *  gets/returns URL for EE txn_page
1818
-     *
1819
-     * @param array $query_args like what gets passed to
1820
-     *                          add_query_arg() as the first argument
1821
-     * @access    public
1822
-     * @return    string
1823
-     */
1824
-    public function txn_page_url($query_args = array())
1825
-    {
1826
-        if (! $this->txn_page_url) {
1827
-            $this->txn_page_url = get_permalink($this->txn_page_id);
1828
-        }
1829
-        if ($query_args) {
1830
-            return add_query_arg($query_args, $this->txn_page_url);
1831
-        } else {
1832
-            return $this->txn_page_url;
1833
-        }
1834
-    }
1835
-
1836
-
1837
-
1838
-    /**
1839
-     *  gets/returns URL for EE thank_you_page
1840
-     *
1841
-     * @param array $query_args like what gets passed to
1842
-     *                          add_query_arg() as the first argument
1843
-     * @access    public
1844
-     * @return    string
1845
-     */
1846
-    public function thank_you_page_url($query_args = array())
1847
-    {
1848
-        if (! $this->thank_you_page_url) {
1849
-            $this->thank_you_page_url = get_permalink($this->thank_you_page_id);
1850
-        }
1851
-        if ($query_args) {
1852
-            return add_query_arg($query_args, $this->thank_you_page_url);
1853
-        } else {
1854
-            return $this->thank_you_page_url;
1855
-        }
1856
-    }
1857
-
1858
-
1859
-
1860
-    /**
1861
-     *  gets/returns URL for EE cancel_page
1862
-     *
1863
-     * @access    public
1864
-     * @return    string
1865
-     */
1866
-    public function cancel_page_url()
1867
-    {
1868
-        if (! $this->cancel_page_url) {
1869
-            $this->cancel_page_url = get_permalink($this->cancel_page_id);
1870
-        }
1871
-        return $this->cancel_page_url;
1872
-    }
1873
-
1874
-
1875
-
1876
-    /**
1877
-     * Resets all critical page urls to their original state.  Used primarily by the __sleep() magic method currently.
1878
-     *
1879
-     * @since 4.7.5
1880
-     */
1881
-    protected function _reset_urls()
1882
-    {
1883
-        $this->reg_page_url = '';
1884
-        $this->txn_page_url = '';
1885
-        $this->cancel_page_url = '';
1886
-        $this->thank_you_page_url = '';
1887
-    }
1888
-
1889
-
1890
-
1891
-    /**
1892
-     * Used to return what the optin value is set for the EE User Experience Program.
1893
-     * This accounts for multisite and this value being requested for a subsite.  In multisite, the value is set
1894
-     * on the main site only.
1895
-     *
1896
-     * @return mixed|void
1897
-     */
1898
-    protected function _get_main_ee_ueip_optin()
1899
-    {
1900
-        //if this is the main site then we can just bypass our direct query.
1901
-        if (is_main_site()) {
1902
-            return get_option('ee_ueip_optin', false);
1903
-        }
1904
-        //is this already cached for this request?  If so use it.
1905
-        if ( ! empty(EE_Core_Config::$ee_ueip_option)) {
1906
-            return EE_Core_Config::$ee_ueip_option;
1907
-        }
1908
-        global $wpdb;
1909
-        $current_network_main_site = is_multisite() ? get_current_site() : null;
1910
-        $current_main_site_id = ! empty($current_network_main_site) ? $current_network_main_site->blog_id : 1;
1911
-        $option = 'ee_ueip_optin';
1912
-        //set correct table for query
1913
-        $table_name = $wpdb->get_blog_prefix($current_main_site_id) . 'options';
1914
-        //rather than getting blog option for the $current_main_site_id, we do a direct $wpdb query because
1915
-        //get_blog_option() does a switch_to_blog an that could cause infinite recursion because EE_Core_Config might be
1916
-        //re-constructed on the blog switch.  Note, we are still executing any core wp filters on this option retrieval.
1917
-        //this bit of code is basically a direct copy of get_option without any caching because we are NOT switched to the blog
1918
-        //for the purpose of caching.
1919
-        $pre = apply_filters('pre_option_' . $option, false, $option);
1920
-        if (false !== $pre) {
1921
-            EE_Core_Config::$ee_ueip_option = $pre;
1922
-            return EE_Core_Config::$ee_ueip_option;
1923
-        }
1924
-        $row = $wpdb->get_row($wpdb->prepare("SELECT option_value FROM $table_name WHERE option_name = %s LIMIT 1",
1925
-            $option));
1926
-        if (is_object($row)) {
1927
-            $value = $row->option_value;
1928
-        } else { //option does not exist so use default.
1929
-            return apply_filters('default_option_' . $option, false, $option);
1930
-        }
1931
-        EE_Core_Config::$ee_ueip_option = apply_filters('option_' . $option, maybe_unserialize($value), $option);
1932
-        return EE_Core_Config::$ee_ueip_option;
1933
-    }
1934
-
1935
-
1936
-
1937
-    /**
1938
-     * Currently used to ensure critical page urls have initial values saved to the db instead of any current set values
1939
-     * on the object.
1940
-     *
1941
-     * @return array
1942
-     */
1943
-    public function __sleep()
1944
-    {
1945
-        //reset all url properties
1946
-        $this->_reset_urls();
1947
-        //return what to save to db
1948
-        return array_keys(get_object_vars($this));
1949
-    }
1950
-
1951
-}
1952
-
1953
-
1954
-
1955
-/**
1956
- * Config class for storing info on the Organization
1957
- */
1958
-class EE_Organization_Config extends EE_Config_Base
1959
-{
1960
-
1961
-    /**
1962
-     * @var string $name
1963
-     * eg EE4.1
1964
-     */
1965
-    public $name;
1966
-
1967
-    /**
1968
-     * @var string $address_1
1969
-     * eg 123 Onna Road
1970
-     */
1971
-    public $address_1;
1972
-
1973
-    /**
1974
-     * @var string $address_2
1975
-     * eg PO Box 123
1976
-     */
1977
-    public $address_2;
1978
-
1979
-    /**
1980
-     * @var string $city
1981
-     * eg Inna City
1982
-     */
1983
-    public $city;
1984
-
1985
-    /**
1986
-     * @var int $STA_ID
1987
-     * eg 4
1988
-     */
1989
-    public $STA_ID;
1990
-
1991
-    /**
1992
-     * @var string $CNT_ISO
1993
-     * eg US
1994
-     */
1995
-    public $CNT_ISO;
1996
-
1997
-    /**
1998
-     * @var string $zip
1999
-     * eg 12345  or V1A 2B3
2000
-     */
2001
-    public $zip;
2002
-
2003
-    /**
2004
-     * @var string $email
2005
-     * eg [email protected]
2006
-     */
2007
-    public $email;
2008
-
2009
-
2010
-    /**
2011
-     * @var string $phone
2012
-     * eg. 111-111-1111
2013
-     */
2014
-    public $phone;
2015
-
2016
-
2017
-    /**
2018
-     * @var string $vat
2019
-     * VAT/Tax Number
2020
-     */
2021
-    public $vat;
2022
-
2023
-    /**
2024
-     * @var string $logo_url
2025
-     * eg http://www.somedomain.com/wp-content/uploads/kittehs.jpg
2026
-     */
2027
-    public $logo_url;
2028
-
2029
-
2030
-    /**
2031
-     * The below are all various properties for holding links to organization social network profiles
2032
-     *
2033
-     * @var string
2034
-     */
2035
-    /**
2036
-     * facebook (facebook.com/profile.name)
2037
-     *
2038
-     * @var string
2039
-     */
2040
-    public $facebook;
2041
-
2042
-
2043
-    /**
2044
-     * twitter (twitter.com/twitter_handle)
2045
-     *
2046
-     * @var string
2047
-     */
2048
-    public $twitter;
2049
-
2050
-
2051
-    /**
2052
-     * linkedin (linkedin.com/in/profile_name)
2053
-     *
2054
-     * @var string
2055
-     */
2056
-    public $linkedin;
2057
-
2058
-
2059
-    /**
2060
-     * pinterest (www.pinterest.com/profile_name)
2061
-     *
2062
-     * @var string
2063
-     */
2064
-    public $pinterest;
2065
-
2066
-
2067
-    /**
2068
-     * google+ (google.com/+profileName)
2069
-     *
2070
-     * @var string
2071
-     */
2072
-    public $google;
2073
-
2074
-
2075
-    /**
2076
-     * instagram (instagram.com/handle)
2077
-     *
2078
-     * @var string
2079
-     */
2080
-    public $instagram;
2081
-
2082
-
2083
-
2084
-    /**
2085
-     *    class constructor
2086
-     *
2087
-     * @access    public
2088
-     */
2089
-    public function __construct()
2090
-    {
2091
-        // set default organization settings
2092
-        $this->name = get_bloginfo('name');
2093
-        $this->address_1 = '123 Onna Road';
2094
-        $this->address_2 = 'PO Box 123';
2095
-        $this->city = 'Inna City';
2096
-        $this->STA_ID = 4;
2097
-        $this->CNT_ISO = 'US';
2098
-        $this->zip = '12345';
2099
-        $this->email = get_bloginfo('admin_email');
2100
-        $this->phone = '';
2101
-        $this->vat = '123456789';
2102
-        $this->logo_url = '';
2103
-        $this->facebook = '';
2104
-        $this->twitter = '';
2105
-        $this->linkedin = '';
2106
-        $this->pinterest = '';
2107
-        $this->google = '';
2108
-        $this->instagram = '';
2109
-    }
2110
-
2111
-}
2112
-
2113
-
2114
-
2115
-/**
2116
- * Class for defining what's in the EE_Config relating to currency
2117
- */
2118
-class EE_Currency_Config extends EE_Config_Base
2119
-{
2120
-
2121
-    /**
2122
-     * @var string $code
2123
-     * eg 'US'
2124
-     */
2125
-    public $code;
2126
-
2127
-    /**
2128
-     * @var string $name
2129
-     * eg 'Dollar'
2130
-     */
2131
-    public $name;
2132
-
2133
-    /**
2134
-     * plural name
2135
-     *
2136
-     * @var string $plural
2137
-     * eg 'Dollars'
2138
-     */
2139
-    public $plural;
2140
-
2141
-    /**
2142
-     * currency sign
2143
-     *
2144
-     * @var string $sign
2145
-     * eg '$'
2146
-     */
2147
-    public $sign;
2148
-
2149
-    /**
2150
-     * Whether the currency sign should come before the number or not
2151
-     *
2152
-     * @var boolean $sign_b4
2153
-     */
2154
-    public $sign_b4;
2155
-
2156
-    /**
2157
-     * How many digits should come after the decimal place
2158
-     *
2159
-     * @var int $dec_plc
2160
-     */
2161
-    public $dec_plc;
2162
-
2163
-    /**
2164
-     * Symbol to use for decimal mark
2165
-     *
2166
-     * @var string $dec_mrk
2167
-     * eg '.'
2168
-     */
2169
-    public $dec_mrk;
2170
-
2171
-    /**
2172
-     * Symbol to use for thousands
2173
-     *
2174
-     * @var string $thsnds
2175
-     * eg ','
2176
-     */
2177
-    public $thsnds;
2178
-
2179
-
2180
-
2181
-    /**
2182
-     *    class constructor
2183
-     *
2184
-     * @access    public
2185
-     * @param string $CNT_ISO
2186
-     * @throws \EE_Error
2187
-     */
2188
-    public function __construct($CNT_ISO = '')
2189
-    {
2190
-        /** @var \EventEspresso\core\services\database\TableAnalysis $table_analysis */
2191
-        $table_analysis = EE_Registry::instance()->create('TableAnalysis', array(), true);
2192
-        // get country code from organization settings or use default
2193
-        $ORG_CNT = isset(EE_Registry::instance()->CFG->organization)
2194
-                   && EE_Registry::instance()->CFG->organization instanceof EE_Organization_Config
2195
-            ? EE_Registry::instance()->CFG->organization->CNT_ISO
2196
-            : '';
2197
-        // but override if requested
2198
-        $CNT_ISO = ! empty($CNT_ISO) ? $CNT_ISO : $ORG_CNT;
2199
-        // so if that all went well, and we are not in M-Mode (cuz you can't query the db in M-Mode) and double-check the countries table exists
2200
-        if (
2201
-            ! empty($CNT_ISO)
2202
-            && EE_Maintenance_Mode::instance()->models_can_query()
2203
-            && $table_analysis->tableExists(EE_Registry::instance()->load_model('Country')->table())
2204
-        ) {
2205
-            // retrieve the country settings from the db, just in case they have been customized
2206
-            $country = EE_Registry::instance()->load_model('Country')->get_one_by_ID($CNT_ISO);
2207
-            if ($country instanceof EE_Country) {
2208
-                $this->code = $country->currency_code();    // currency code: USD, CAD, EUR
2209
-                $this->name = $country->currency_name_single();    // Dollar
2210
-                $this->plural = $country->currency_name_plural();    // Dollars
2211
-                $this->sign = $country->currency_sign();            // currency sign: $
2212
-                $this->sign_b4 = $country->currency_sign_before();        // currency sign before or after: $TRUE  or  FALSE$
2213
-                $this->dec_plc = $country->currency_decimal_places();    // decimal places: 2 = 0.00  3 = 0.000
2214
-                $this->dec_mrk = $country->currency_decimal_mark();    // decimal mark: (comma) ',' = 0,01   or (decimal) '.' = 0.01
2215
-                $this->thsnds = $country->currency_thousands_separator();    // thousands separator: (comma) ',' = 1,000   or (decimal) '.' = 1.000
2216
-            }
2217
-        }
2218
-        // fallback to hardcoded defaults, in case the above failed
2219
-        if (empty($this->code)) {
2220
-            // set default currency settings
2221
-            $this->code = 'USD';    // currency code: USD, CAD, EUR
2222
-            $this->name = __('Dollar', 'event_espresso');    // Dollar
2223
-            $this->plural = __('Dollars', 'event_espresso');    // Dollars
2224
-            $this->sign = '$';    // currency sign: $
2225
-            $this->sign_b4 = true;    // currency sign before or after: $TRUE  or  FALSE$
2226
-            $this->dec_plc = 2;    // decimal places: 2 = 0.00  3 = 0.000
2227
-            $this->dec_mrk = '.';    // decimal mark: (comma) ',' = 0,01   or (decimal) '.' = 0.01
2228
-            $this->thsnds = ',';    // thousands separator: (comma) ',' = 1,000   or (decimal) '.' = 1.000
2229
-        }
2230
-    }
2231
-}
2232
-
2233
-
2234
-
2235
-/**
2236
- * Class for defining what's in the EE_Config relating to registration settings
2237
- */
2238
-class EE_Registration_Config extends EE_Config_Base
2239
-{
2240
-
2241
-    /**
2242
-     * Default registration status
2243
-     *
2244
-     * @var string $default_STS_ID
2245
-     * eg 'RPP'
2246
-     */
2247
-    public $default_STS_ID;
2248
-
2249
-
2250
-    /**
2251
-     * For new events, this will be the default value for the maximum number of tickets (equivalent to maximum number of
2252
-     * registrations)
2253
-     * @var int
2254
-     */
2255
-    public $default_maximum_number_of_tickets;
2256
-
2257
-
2258
-    /**
2259
-     * level of validation to apply to email addresses
2260
-     *
2261
-     * @var string $email_validation_level
2262
-     * options: 'basic', 'wp_default', 'i18n', 'i18n_dns'
2263
-     */
2264
-    public $email_validation_level;
2265
-
2266
-    /**
2267
-     *    whether or not to show alternate payment options during the reg process if payment status is pending
2268
-     *
2269
-     * @var boolean $show_pending_payment_options
2270
-     */
2271
-    public $show_pending_payment_options;
2272
-
2273
-    /**
2274
-     * Whether to skip the registration confirmation page
2275
-     *
2276
-     * @var boolean $skip_reg_confirmation
2277
-     */
2278
-    public $skip_reg_confirmation;
2279
-
2280
-    /**
2281
-     * an array of SPCO reg steps where:
2282
-     *        the keys denotes the reg step order
2283
-     *        each element consists of an array with the following elements:
2284
-     *            "file_path" => the file path to the EE_SPCO_Reg_Step class
2285
-     *            "class_name" => the specific EE_SPCO_Reg_Step child class name
2286
-     *            "slug" => the URL param used to trigger the reg step
2287
-     *
2288
-     * @var array $reg_steps
2289
-     */
2290
-    public $reg_steps;
2291
-
2292
-    /**
2293
-     * Whether registration confirmation should be the last page of SPCO
2294
-     *
2295
-     * @var boolean $reg_confirmation_last
2296
-     */
2297
-    public $reg_confirmation_last;
2298
-
2299
-    /**
2300
-     * Whether or not to enable the EE Bot Trap
2301
-     *
2302
-     * @var boolean $use_bot_trap
2303
-     */
2304
-    public $use_bot_trap;
2305
-
2306
-    /**
2307
-     * Whether or not to encrypt some data sent by the EE Bot Trap
2308
-     *
2309
-     * @var boolean $use_encryption
2310
-     */
2311
-    public $use_encryption;
1545
+}
2312 1546
 
2313
-    /**
2314
-     * Whether or not to use ReCaptcha
2315
-     *
2316
-     * @var boolean $use_captcha
2317
-     */
2318
-    public $use_captcha;
2319 1547
 
2320
-    /**
2321
-     * ReCaptcha Theme
2322
-     *
2323
-     * @var string $recaptcha_theme
2324
-     *    options: 'dark    ', 'light'
2325
-     */
2326
-    public $recaptcha_theme;
2327 1548
 
2328
-    /**
2329
-     * ReCaptcha Type
2330
-     *
2331
-     * @var string $recaptcha_type
2332
-     *    options: 'audio', 'image'
2333
-     */
2334
-    public $recaptcha_type;
1549
+/**
1550
+ * Base class used for config classes. These classes should generally not have
1551
+ * magic functions in use, except we'll allow them to magically set and get stuff...
1552
+ * basically, they should just be well-defined stdClasses
1553
+ */
1554
+class EE_Config_Base
1555
+{
2335 1556
 
2336
-    /**
2337
-     * ReCaptcha language
2338
-     *
2339
-     * @var string $recaptcha_language
2340
-     * eg 'en'
2341
-     */
2342
-    public $recaptcha_language;
1557
+	/**
1558
+	 * Utility function for escaping the value of a property and returning.
1559
+	 *
1560
+	 * @param string $property property name (checks to see if exists).
1561
+	 * @return mixed if a detected type found return the escaped value, otherwise just the raw value is returned.
1562
+	 * @throws \EE_Error
1563
+	 */
1564
+	public function get_pretty($property)
1565
+	{
1566
+		if (! property_exists($this, $property)) {
1567
+			throw new EE_Error(
1568
+				sprintf(
1569
+					__(
1570
+						'%1$s::get_pretty() has been called with the property %2$s which does not exist on the %1$s config class.',
1571
+						'event_espresso'
1572
+					),
1573
+					get_class($this),
1574
+					$property
1575
+				)
1576
+			);
1577
+		}
1578
+		//just handling escaping of strings for now.
1579
+		if (is_string($this->{$property})) {
1580
+			return stripslashes($this->{$property});
1581
+		}
1582
+		return $this->{$property};
1583
+	}
1584
+
1585
+
1586
+
1587
+	public function populate()
1588
+	{
1589
+		//grab defaults via a new instance of this class.
1590
+		$class_name = get_class($this);
1591
+		$defaults = new $class_name;
1592
+		//loop through the properties for this class and see if they are set.  If they are NOT, then grab the
1593
+		//default from our $defaults object.
1594
+		foreach (get_object_vars($defaults) as $property => $value) {
1595
+			if ($this->{$property} === null) {
1596
+				$this->{$property} = $value;
1597
+			}
1598
+		}
1599
+		//cleanup
1600
+		unset($defaults);
1601
+	}
1602
+
1603
+
1604
+
1605
+	/**
1606
+	 *        __isset
1607
+	 *
1608
+	 * @param $a
1609
+	 * @return bool
1610
+	 */
1611
+	public function __isset($a)
1612
+	{
1613
+		return false;
1614
+	}
1615
+
1616
+
1617
+
1618
+	/**
1619
+	 *        __unset
1620
+	 *
1621
+	 * @param $a
1622
+	 * @return bool
1623
+	 */
1624
+	public function __unset($a)
1625
+	{
1626
+		return false;
1627
+	}
1628
+
1629
+
1630
+
1631
+	/**
1632
+	 *        __clone
1633
+	 */
1634
+	public function __clone()
1635
+	{
1636
+	}
1637
+
1638
+
1639
+
1640
+	/**
1641
+	 *        __wakeup
1642
+	 */
1643
+	public function __wakeup()
1644
+	{
1645
+	}
1646
+
1647
+
1648
+
1649
+	/**
1650
+	 *        __destruct
1651
+	 */
1652
+	public function __destruct()
1653
+	{
1654
+	}
1655
+}
2343 1656
 
2344
-    /**
2345
-     * ReCaptcha public key
2346
-     *
2347
-     * @var string $recaptcha_publickey
2348
-     */
2349
-    public $recaptcha_publickey;
2350 1657
 
2351
-    /**
2352
-     * ReCaptcha private key
2353
-     *
2354
-     * @var string $recaptcha_privatekey
2355
-     */
2356
-    public $recaptcha_privatekey;
2357 1658
 
2358
-    /**
2359
-     * ReCaptcha width
2360
-     *
2361
-     * @var int $recaptcha_width
2362
-     * @deprecated
2363
-     */
2364
-    public $recaptcha_width;
1659
+/**
1660
+ * Class for defining what's in the EE_Config relating to registration settings
1661
+ */
1662
+class EE_Core_Config extends EE_Config_Base
1663
+{
2365 1664
 
2366
-    /**
2367
-     * Whether or not invalid attempts to directly access the registration checkout page should be tracked.
2368
-     *
2369
-     * @var boolean $track_invalid_checkout_access
2370
-     */
2371
-    protected $track_invalid_checkout_access = true;
1665
+	public $current_blog_id;
1666
+
1667
+	public $ee_ueip_optin;
1668
+
1669
+	public $ee_ueip_has_notified;
1670
+
1671
+	/**
1672
+	 * Not to be confused with the 4 critical page variables (See
1673
+	 * get_critical_pages_array()), this is just an array of wp posts that have EE
1674
+	 * shortcodes in them. Keys are slugs, values are arrays with only 1 element: where the key is the shortcode
1675
+	 * in the page, and the value is the page's ID. The key 'posts' is basically a duplicate of this same array.
1676
+	 *
1677
+	 * @var array
1678
+	 */
1679
+	public $post_shortcodes;
1680
+
1681
+	public $module_route_map;
1682
+
1683
+	public $module_forward_map;
1684
+
1685
+	public $module_view_map;
1686
+
1687
+	/**
1688
+	 * The next 4 vars are the IDs of critical EE pages.
1689
+	 *
1690
+	 * @var int
1691
+	 */
1692
+	public $reg_page_id;
1693
+
1694
+	public $txn_page_id;
1695
+
1696
+	public $thank_you_page_id;
1697
+
1698
+	public $cancel_page_id;
1699
+
1700
+	/**
1701
+	 * The next 4 vars are the URLs of critical EE pages.
1702
+	 *
1703
+	 * @var int
1704
+	 */
1705
+	public $reg_page_url;
1706
+
1707
+	public $txn_page_url;
1708
+
1709
+	public $thank_you_page_url;
1710
+
1711
+	public $cancel_page_url;
1712
+
1713
+	/**
1714
+	 * The next vars relate to the custom slugs for EE CPT routes
1715
+	 */
1716
+	public $event_cpt_slug;
1717
+
1718
+
1719
+	/**
1720
+	 * This caches the _ee_ueip_option in case this config is reset in the same
1721
+	 * request across blog switches in a multisite context.
1722
+	 * Avoids extra queries to the db for this option.
1723
+	 *
1724
+	 * @var bool
1725
+	 */
1726
+	public static $ee_ueip_option;
1727
+
1728
+
1729
+
1730
+	/**
1731
+	 *    class constructor
1732
+	 *
1733
+	 * @access    public
1734
+	 */
1735
+	public function __construct()
1736
+	{
1737
+		// set default organization settings
1738
+		$this->current_blog_id = get_current_blog_id();
1739
+		$this->current_blog_id = $this->current_blog_id === null ? 1 : $this->current_blog_id;
1740
+		$this->ee_ueip_optin = $this->_get_main_ee_ueip_optin();
1741
+		$this->ee_ueip_has_notified = is_main_site() ? get_option('ee_ueip_has_notified', false) : true;
1742
+		$this->post_shortcodes = array();
1743
+		$this->module_route_map = array();
1744
+		$this->module_forward_map = array();
1745
+		$this->module_view_map = array();
1746
+		// critical EE page IDs
1747
+		$this->reg_page_id = 0;
1748
+		$this->txn_page_id = 0;
1749
+		$this->thank_you_page_id = 0;
1750
+		$this->cancel_page_id = 0;
1751
+		// critical EE page URLs
1752
+		$this->reg_page_url = '';
1753
+		$this->txn_page_url = '';
1754
+		$this->thank_you_page_url = '';
1755
+		$this->cancel_page_url = '';
1756
+		//cpt slugs
1757
+		$this->event_cpt_slug = __('events', 'event_espresso');
1758
+		//ueip constant check
1759
+		if (defined('EE_DISABLE_UXIP') && EE_DISABLE_UXIP) {
1760
+			$this->ee_ueip_optin = false;
1761
+			$this->ee_ueip_has_notified = true;
1762
+		}
1763
+	}
1764
+
1765
+
1766
+
1767
+	/**
1768
+	 * @return array
1769
+	 */
1770
+	public function get_critical_pages_array()
1771
+	{
1772
+		return array(
1773
+			$this->reg_page_id,
1774
+			$this->txn_page_id,
1775
+			$this->thank_you_page_id,
1776
+			$this->cancel_page_id,
1777
+		);
1778
+	}
1779
+
1780
+
1781
+
1782
+	/**
1783
+	 * @return array
1784
+	 */
1785
+	public function get_critical_pages_shortcodes_array()
1786
+	{
1787
+		return array(
1788
+			$this->reg_page_id       => 'ESPRESSO_CHECKOUT',
1789
+			$this->txn_page_id       => 'ESPRESSO_TXN_PAGE',
1790
+			$this->thank_you_page_id => 'ESPRESSO_THANK_YOU',
1791
+			$this->cancel_page_id    => 'ESPRESSO_CANCELLED',
1792
+		);
1793
+	}
1794
+
1795
+
1796
+
1797
+	/**
1798
+	 *  gets/returns URL for EE reg_page
1799
+	 *
1800
+	 * @access    public
1801
+	 * @return    string
1802
+	 */
1803
+	public function reg_page_url()
1804
+	{
1805
+		if (! $this->reg_page_url) {
1806
+			$this->reg_page_url = add_query_arg(
1807
+									  array('uts' => time()),
1808
+									  get_permalink($this->reg_page_id)
1809
+								  ) . '#checkout';
1810
+		}
1811
+		return $this->reg_page_url;
1812
+	}
1813
+
1814
+
1815
+
1816
+	/**
1817
+	 *  gets/returns URL for EE txn_page
1818
+	 *
1819
+	 * @param array $query_args like what gets passed to
1820
+	 *                          add_query_arg() as the first argument
1821
+	 * @access    public
1822
+	 * @return    string
1823
+	 */
1824
+	public function txn_page_url($query_args = array())
1825
+	{
1826
+		if (! $this->txn_page_url) {
1827
+			$this->txn_page_url = get_permalink($this->txn_page_id);
1828
+		}
1829
+		if ($query_args) {
1830
+			return add_query_arg($query_args, $this->txn_page_url);
1831
+		} else {
1832
+			return $this->txn_page_url;
1833
+		}
1834
+	}
1835
+
1836
+
1837
+
1838
+	/**
1839
+	 *  gets/returns URL for EE thank_you_page
1840
+	 *
1841
+	 * @param array $query_args like what gets passed to
1842
+	 *                          add_query_arg() as the first argument
1843
+	 * @access    public
1844
+	 * @return    string
1845
+	 */
1846
+	public function thank_you_page_url($query_args = array())
1847
+	{
1848
+		if (! $this->thank_you_page_url) {
1849
+			$this->thank_you_page_url = get_permalink($this->thank_you_page_id);
1850
+		}
1851
+		if ($query_args) {
1852
+			return add_query_arg($query_args, $this->thank_you_page_url);
1853
+		} else {
1854
+			return $this->thank_you_page_url;
1855
+		}
1856
+	}
1857
+
1858
+
1859
+
1860
+	/**
1861
+	 *  gets/returns URL for EE cancel_page
1862
+	 *
1863
+	 * @access    public
1864
+	 * @return    string
1865
+	 */
1866
+	public function cancel_page_url()
1867
+	{
1868
+		if (! $this->cancel_page_url) {
1869
+			$this->cancel_page_url = get_permalink($this->cancel_page_id);
1870
+		}
1871
+		return $this->cancel_page_url;
1872
+	}
1873
+
1874
+
1875
+
1876
+	/**
1877
+	 * Resets all critical page urls to their original state.  Used primarily by the __sleep() magic method currently.
1878
+	 *
1879
+	 * @since 4.7.5
1880
+	 */
1881
+	protected function _reset_urls()
1882
+	{
1883
+		$this->reg_page_url = '';
1884
+		$this->txn_page_url = '';
1885
+		$this->cancel_page_url = '';
1886
+		$this->thank_you_page_url = '';
1887
+	}
1888
+
1889
+
1890
+
1891
+	/**
1892
+	 * Used to return what the optin value is set for the EE User Experience Program.
1893
+	 * This accounts for multisite and this value being requested for a subsite.  In multisite, the value is set
1894
+	 * on the main site only.
1895
+	 *
1896
+	 * @return mixed|void
1897
+	 */
1898
+	protected function _get_main_ee_ueip_optin()
1899
+	{
1900
+		//if this is the main site then we can just bypass our direct query.
1901
+		if (is_main_site()) {
1902
+			return get_option('ee_ueip_optin', false);
1903
+		}
1904
+		//is this already cached for this request?  If so use it.
1905
+		if ( ! empty(EE_Core_Config::$ee_ueip_option)) {
1906
+			return EE_Core_Config::$ee_ueip_option;
1907
+		}
1908
+		global $wpdb;
1909
+		$current_network_main_site = is_multisite() ? get_current_site() : null;
1910
+		$current_main_site_id = ! empty($current_network_main_site) ? $current_network_main_site->blog_id : 1;
1911
+		$option = 'ee_ueip_optin';
1912
+		//set correct table for query
1913
+		$table_name = $wpdb->get_blog_prefix($current_main_site_id) . 'options';
1914
+		//rather than getting blog option for the $current_main_site_id, we do a direct $wpdb query because
1915
+		//get_blog_option() does a switch_to_blog an that could cause infinite recursion because EE_Core_Config might be
1916
+		//re-constructed on the blog switch.  Note, we are still executing any core wp filters on this option retrieval.
1917
+		//this bit of code is basically a direct copy of get_option without any caching because we are NOT switched to the blog
1918
+		//for the purpose of caching.
1919
+		$pre = apply_filters('pre_option_' . $option, false, $option);
1920
+		if (false !== $pre) {
1921
+			EE_Core_Config::$ee_ueip_option = $pre;
1922
+			return EE_Core_Config::$ee_ueip_option;
1923
+		}
1924
+		$row = $wpdb->get_row($wpdb->prepare("SELECT option_value FROM $table_name WHERE option_name = %s LIMIT 1",
1925
+			$option));
1926
+		if (is_object($row)) {
1927
+			$value = $row->option_value;
1928
+		} else { //option does not exist so use default.
1929
+			return apply_filters('default_option_' . $option, false, $option);
1930
+		}
1931
+		EE_Core_Config::$ee_ueip_option = apply_filters('option_' . $option, maybe_unserialize($value), $option);
1932
+		return EE_Core_Config::$ee_ueip_option;
1933
+	}
1934
+
1935
+
1936
+
1937
+	/**
1938
+	 * Currently used to ensure critical page urls have initial values saved to the db instead of any current set values
1939
+	 * on the object.
1940
+	 *
1941
+	 * @return array
1942
+	 */
1943
+	public function __sleep()
1944
+	{
1945
+		//reset all url properties
1946
+		$this->_reset_urls();
1947
+		//return what to save to db
1948
+		return array_keys(get_object_vars($this));
1949
+	}
2372 1950
 
1951
+}
2373 1952
 
2374 1953
 
2375
-    /**
2376
-     *    class constructor
2377
-     *
2378
-     * @access    public
2379
-     */
2380
-    public function __construct()
2381
-    {
2382
-        // set default registration settings
2383
-        $this->default_STS_ID = EEM_Registration::status_id_pending_payment;
2384
-        $this->email_validation_level = 'wp_default';
2385
-        $this->show_pending_payment_options = true;
2386
-        $this->skip_reg_confirmation = false;
2387
-        $this->reg_steps = array();
2388
-        $this->reg_confirmation_last = false;
2389
-        $this->use_bot_trap = true;
2390
-        $this->use_encryption = true;
2391
-        $this->use_captcha = false;
2392
-        $this->recaptcha_theme = 'light';
2393
-        $this->recaptcha_type = 'image';
2394
-        $this->recaptcha_language = 'en';
2395
-        $this->recaptcha_publickey = null;
2396
-        $this->recaptcha_privatekey = null;
2397
-        $this->recaptcha_width = 500;
2398
-        $this->default_maximum_number_of_tickets = 10;
2399
-    }
2400
-
2401
-
2402
-
2403
-    /**
2404
-     * This is called by the config loader and hooks are initialized AFTER the config has been populated.
2405
-     *
2406
-     * @since 4.8.8.rc.019
2407
-     */
2408
-    public function do_hooks()
2409
-    {
2410
-        add_action('AHEE__EE_Config___load_core_config__end', array($this, 'set_default_reg_status_on_EEM_Event'));
2411
-        add_action('AHEE__EE_Config___load_core_config__end', array($this, 'set_default_max_ticket_on_EEM_Event'));
2412
-    }
2413 1954
 
1955
+/**
1956
+ * Config class for storing info on the Organization
1957
+ */
1958
+class EE_Organization_Config extends EE_Config_Base
1959
+{
2414 1960
 
1961
+	/**
1962
+	 * @var string $name
1963
+	 * eg EE4.1
1964
+	 */
1965
+	public $name;
1966
+
1967
+	/**
1968
+	 * @var string $address_1
1969
+	 * eg 123 Onna Road
1970
+	 */
1971
+	public $address_1;
1972
+
1973
+	/**
1974
+	 * @var string $address_2
1975
+	 * eg PO Box 123
1976
+	 */
1977
+	public $address_2;
1978
+
1979
+	/**
1980
+	 * @var string $city
1981
+	 * eg Inna City
1982
+	 */
1983
+	public $city;
1984
+
1985
+	/**
1986
+	 * @var int $STA_ID
1987
+	 * eg 4
1988
+	 */
1989
+	public $STA_ID;
1990
+
1991
+	/**
1992
+	 * @var string $CNT_ISO
1993
+	 * eg US
1994
+	 */
1995
+	public $CNT_ISO;
1996
+
1997
+	/**
1998
+	 * @var string $zip
1999
+	 * eg 12345  or V1A 2B3
2000
+	 */
2001
+	public $zip;
2002
+
2003
+	/**
2004
+	 * @var string $email
2005
+	 * eg [email protected]
2006
+	 */
2007
+	public $email;
2008
+
2009
+
2010
+	/**
2011
+	 * @var string $phone
2012
+	 * eg. 111-111-1111
2013
+	 */
2014
+	public $phone;
2015
+
2016
+
2017
+	/**
2018
+	 * @var string $vat
2019
+	 * VAT/Tax Number
2020
+	 */
2021
+	public $vat;
2022
+
2023
+	/**
2024
+	 * @var string $logo_url
2025
+	 * eg http://www.somedomain.com/wp-content/uploads/kittehs.jpg
2026
+	 */
2027
+	public $logo_url;
2028
+
2029
+
2030
+	/**
2031
+	 * The below are all various properties for holding links to organization social network profiles
2032
+	 *
2033
+	 * @var string
2034
+	 */
2035
+	/**
2036
+	 * facebook (facebook.com/profile.name)
2037
+	 *
2038
+	 * @var string
2039
+	 */
2040
+	public $facebook;
2041
+
2042
+
2043
+	/**
2044
+	 * twitter (twitter.com/twitter_handle)
2045
+	 *
2046
+	 * @var string
2047
+	 */
2048
+	public $twitter;
2049
+
2050
+
2051
+	/**
2052
+	 * linkedin (linkedin.com/in/profile_name)
2053
+	 *
2054
+	 * @var string
2055
+	 */
2056
+	public $linkedin;
2057
+
2058
+
2059
+	/**
2060
+	 * pinterest (www.pinterest.com/profile_name)
2061
+	 *
2062
+	 * @var string
2063
+	 */
2064
+	public $pinterest;
2065
+
2066
+
2067
+	/**
2068
+	 * google+ (google.com/+profileName)
2069
+	 *
2070
+	 * @var string
2071
+	 */
2072
+	public $google;
2073
+
2074
+
2075
+	/**
2076
+	 * instagram (instagram.com/handle)
2077
+	 *
2078
+	 * @var string
2079
+	 */
2080
+	public $instagram;
2081
+
2082
+
2083
+
2084
+	/**
2085
+	 *    class constructor
2086
+	 *
2087
+	 * @access    public
2088
+	 */
2089
+	public function __construct()
2090
+	{
2091
+		// set default organization settings
2092
+		$this->name = get_bloginfo('name');
2093
+		$this->address_1 = '123 Onna Road';
2094
+		$this->address_2 = 'PO Box 123';
2095
+		$this->city = 'Inna City';
2096
+		$this->STA_ID = 4;
2097
+		$this->CNT_ISO = 'US';
2098
+		$this->zip = '12345';
2099
+		$this->email = get_bloginfo('admin_email');
2100
+		$this->phone = '';
2101
+		$this->vat = '123456789';
2102
+		$this->logo_url = '';
2103
+		$this->facebook = '';
2104
+		$this->twitter = '';
2105
+		$this->linkedin = '';
2106
+		$this->pinterest = '';
2107
+		$this->google = '';
2108
+		$this->instagram = '';
2109
+	}
2415 2110
 
2416
-    /**
2417
-     * Hooked into `AHEE__EE_Config___load_core_config__end` to ensure the default for the EVT_default_registration_status
2418
-     * field matches the config setting for default_STS_ID.
2419
-     */
2420
-    public function set_default_reg_status_on_EEM_Event()
2421
-    {
2422
-        EEM_Event::set_default_reg_status($this->default_STS_ID);
2423
-    }
2111
+}
2424 2112
 
2425 2113
 
2426
-    /**
2427
-     * Hooked into `AHEE__EE_Config___load_core_config__end` to ensure the default for the EVT_additional_limit field
2428
-     * for Events matches the config setting for default_maximum_number_of_tickets
2429
-     */
2430
-    public function set_default_max_ticket_on_EEM_Event()
2431
-    {
2432
-        EEM_Event::set_default_additional_limit($this->default_maximum_number_of_tickets);
2433
-    }
2434 2114
 
2115
+/**
2116
+ * Class for defining what's in the EE_Config relating to currency
2117
+ */
2118
+class EE_Currency_Config extends EE_Config_Base
2119
+{
2435 2120
 
2121
+	/**
2122
+	 * @var string $code
2123
+	 * eg 'US'
2124
+	 */
2125
+	public $code;
2126
+
2127
+	/**
2128
+	 * @var string $name
2129
+	 * eg 'Dollar'
2130
+	 */
2131
+	public $name;
2132
+
2133
+	/**
2134
+	 * plural name
2135
+	 *
2136
+	 * @var string $plural
2137
+	 * eg 'Dollars'
2138
+	 */
2139
+	public $plural;
2140
+
2141
+	/**
2142
+	 * currency sign
2143
+	 *
2144
+	 * @var string $sign
2145
+	 * eg '$'
2146
+	 */
2147
+	public $sign;
2148
+
2149
+	/**
2150
+	 * Whether the currency sign should come before the number or not
2151
+	 *
2152
+	 * @var boolean $sign_b4
2153
+	 */
2154
+	public $sign_b4;
2155
+
2156
+	/**
2157
+	 * How many digits should come after the decimal place
2158
+	 *
2159
+	 * @var int $dec_plc
2160
+	 */
2161
+	public $dec_plc;
2162
+
2163
+	/**
2164
+	 * Symbol to use for decimal mark
2165
+	 *
2166
+	 * @var string $dec_mrk
2167
+	 * eg '.'
2168
+	 */
2169
+	public $dec_mrk;
2170
+
2171
+	/**
2172
+	 * Symbol to use for thousands
2173
+	 *
2174
+	 * @var string $thsnds
2175
+	 * eg ','
2176
+	 */
2177
+	public $thsnds;
2178
+
2179
+
2180
+
2181
+	/**
2182
+	 *    class constructor
2183
+	 *
2184
+	 * @access    public
2185
+	 * @param string $CNT_ISO
2186
+	 * @throws \EE_Error
2187
+	 */
2188
+	public function __construct($CNT_ISO = '')
2189
+	{
2190
+		/** @var \EventEspresso\core\services\database\TableAnalysis $table_analysis */
2191
+		$table_analysis = EE_Registry::instance()->create('TableAnalysis', array(), true);
2192
+		// get country code from organization settings or use default
2193
+		$ORG_CNT = isset(EE_Registry::instance()->CFG->organization)
2194
+				   && EE_Registry::instance()->CFG->organization instanceof EE_Organization_Config
2195
+			? EE_Registry::instance()->CFG->organization->CNT_ISO
2196
+			: '';
2197
+		// but override if requested
2198
+		$CNT_ISO = ! empty($CNT_ISO) ? $CNT_ISO : $ORG_CNT;
2199
+		// so if that all went well, and we are not in M-Mode (cuz you can't query the db in M-Mode) and double-check the countries table exists
2200
+		if (
2201
+			! empty($CNT_ISO)
2202
+			&& EE_Maintenance_Mode::instance()->models_can_query()
2203
+			&& $table_analysis->tableExists(EE_Registry::instance()->load_model('Country')->table())
2204
+		) {
2205
+			// retrieve the country settings from the db, just in case they have been customized
2206
+			$country = EE_Registry::instance()->load_model('Country')->get_one_by_ID($CNT_ISO);
2207
+			if ($country instanceof EE_Country) {
2208
+				$this->code = $country->currency_code();    // currency code: USD, CAD, EUR
2209
+				$this->name = $country->currency_name_single();    // Dollar
2210
+				$this->plural = $country->currency_name_plural();    // Dollars
2211
+				$this->sign = $country->currency_sign();            // currency sign: $
2212
+				$this->sign_b4 = $country->currency_sign_before();        // currency sign before or after: $TRUE  or  FALSE$
2213
+				$this->dec_plc = $country->currency_decimal_places();    // decimal places: 2 = 0.00  3 = 0.000
2214
+				$this->dec_mrk = $country->currency_decimal_mark();    // decimal mark: (comma) ',' = 0,01   or (decimal) '.' = 0.01
2215
+				$this->thsnds = $country->currency_thousands_separator();    // thousands separator: (comma) ',' = 1,000   or (decimal) '.' = 1.000
2216
+			}
2217
+		}
2218
+		// fallback to hardcoded defaults, in case the above failed
2219
+		if (empty($this->code)) {
2220
+			// set default currency settings
2221
+			$this->code = 'USD';    // currency code: USD, CAD, EUR
2222
+			$this->name = __('Dollar', 'event_espresso');    // Dollar
2223
+			$this->plural = __('Dollars', 'event_espresso');    // Dollars
2224
+			$this->sign = '$';    // currency sign: $
2225
+			$this->sign_b4 = true;    // currency sign before or after: $TRUE  or  FALSE$
2226
+			$this->dec_plc = 2;    // decimal places: 2 = 0.00  3 = 0.000
2227
+			$this->dec_mrk = '.';    // decimal mark: (comma) ',' = 0,01   or (decimal) '.' = 0.01
2228
+			$this->thsnds = ',';    // thousands separator: (comma) ',' = 1,000   or (decimal) '.' = 1.000
2229
+		}
2230
+	}
2231
+}
2436 2232
 
2437
-    /**
2438
-     * @return boolean
2439
-     */
2440
-    public function track_invalid_checkout_access()
2441
-    {
2442
-        return $this->track_invalid_checkout_access;
2443
-    }
2444 2233
 
2445 2234
 
2235
+/**
2236
+ * Class for defining what's in the EE_Config relating to registration settings
2237
+ */
2238
+class EE_Registration_Config extends EE_Config_Base
2239
+{
2446 2240
 
2447
-    /**
2448
-     * @param boolean $track_invalid_checkout_access
2449
-     */
2450
-    public function set_track_invalid_checkout_access($track_invalid_checkout_access)
2451
-    {
2452
-        $this->track_invalid_checkout_access = filter_var(
2453
-            $track_invalid_checkout_access,
2454
-            FILTER_VALIDATE_BOOLEAN
2455
-        );
2456
-    }
2241
+	/**
2242
+	 * Default registration status
2243
+	 *
2244
+	 * @var string $default_STS_ID
2245
+	 * eg 'RPP'
2246
+	 */
2247
+	public $default_STS_ID;
2248
+
2249
+
2250
+	/**
2251
+	 * For new events, this will be the default value for the maximum number of tickets (equivalent to maximum number of
2252
+	 * registrations)
2253
+	 * @var int
2254
+	 */
2255
+	public $default_maximum_number_of_tickets;
2256
+
2257
+
2258
+	/**
2259
+	 * level of validation to apply to email addresses
2260
+	 *
2261
+	 * @var string $email_validation_level
2262
+	 * options: 'basic', 'wp_default', 'i18n', 'i18n_dns'
2263
+	 */
2264
+	public $email_validation_level;
2265
+
2266
+	/**
2267
+	 *    whether or not to show alternate payment options during the reg process if payment status is pending
2268
+	 *
2269
+	 * @var boolean $show_pending_payment_options
2270
+	 */
2271
+	public $show_pending_payment_options;
2272
+
2273
+	/**
2274
+	 * Whether to skip the registration confirmation page
2275
+	 *
2276
+	 * @var boolean $skip_reg_confirmation
2277
+	 */
2278
+	public $skip_reg_confirmation;
2279
+
2280
+	/**
2281
+	 * an array of SPCO reg steps where:
2282
+	 *        the keys denotes the reg step order
2283
+	 *        each element consists of an array with the following elements:
2284
+	 *            "file_path" => the file path to the EE_SPCO_Reg_Step class
2285
+	 *            "class_name" => the specific EE_SPCO_Reg_Step child class name
2286
+	 *            "slug" => the URL param used to trigger the reg step
2287
+	 *
2288
+	 * @var array $reg_steps
2289
+	 */
2290
+	public $reg_steps;
2291
+
2292
+	/**
2293
+	 * Whether registration confirmation should be the last page of SPCO
2294
+	 *
2295
+	 * @var boolean $reg_confirmation_last
2296
+	 */
2297
+	public $reg_confirmation_last;
2298
+
2299
+	/**
2300
+	 * Whether or not to enable the EE Bot Trap
2301
+	 *
2302
+	 * @var boolean $use_bot_trap
2303
+	 */
2304
+	public $use_bot_trap;
2305
+
2306
+	/**
2307
+	 * Whether or not to encrypt some data sent by the EE Bot Trap
2308
+	 *
2309
+	 * @var boolean $use_encryption
2310
+	 */
2311
+	public $use_encryption;
2312
+
2313
+	/**
2314
+	 * Whether or not to use ReCaptcha
2315
+	 *
2316
+	 * @var boolean $use_captcha
2317
+	 */
2318
+	public $use_captcha;
2319
+
2320
+	/**
2321
+	 * ReCaptcha Theme
2322
+	 *
2323
+	 * @var string $recaptcha_theme
2324
+	 *    options: 'dark    ', 'light'
2325
+	 */
2326
+	public $recaptcha_theme;
2327
+
2328
+	/**
2329
+	 * ReCaptcha Type
2330
+	 *
2331
+	 * @var string $recaptcha_type
2332
+	 *    options: 'audio', 'image'
2333
+	 */
2334
+	public $recaptcha_type;
2335
+
2336
+	/**
2337
+	 * ReCaptcha language
2338
+	 *
2339
+	 * @var string $recaptcha_language
2340
+	 * eg 'en'
2341
+	 */
2342
+	public $recaptcha_language;
2343
+
2344
+	/**
2345
+	 * ReCaptcha public key
2346
+	 *
2347
+	 * @var string $recaptcha_publickey
2348
+	 */
2349
+	public $recaptcha_publickey;
2350
+
2351
+	/**
2352
+	 * ReCaptcha private key
2353
+	 *
2354
+	 * @var string $recaptcha_privatekey
2355
+	 */
2356
+	public $recaptcha_privatekey;
2357
+
2358
+	/**
2359
+	 * ReCaptcha width
2360
+	 *
2361
+	 * @var int $recaptcha_width
2362
+	 * @deprecated
2363
+	 */
2364
+	public $recaptcha_width;
2365
+
2366
+	/**
2367
+	 * Whether or not invalid attempts to directly access the registration checkout page should be tracked.
2368
+	 *
2369
+	 * @var boolean $track_invalid_checkout_access
2370
+	 */
2371
+	protected $track_invalid_checkout_access = true;
2372
+
2373
+
2374
+
2375
+	/**
2376
+	 *    class constructor
2377
+	 *
2378
+	 * @access    public
2379
+	 */
2380
+	public function __construct()
2381
+	{
2382
+		// set default registration settings
2383
+		$this->default_STS_ID = EEM_Registration::status_id_pending_payment;
2384
+		$this->email_validation_level = 'wp_default';
2385
+		$this->show_pending_payment_options = true;
2386
+		$this->skip_reg_confirmation = false;
2387
+		$this->reg_steps = array();
2388
+		$this->reg_confirmation_last = false;
2389
+		$this->use_bot_trap = true;
2390
+		$this->use_encryption = true;
2391
+		$this->use_captcha = false;
2392
+		$this->recaptcha_theme = 'light';
2393
+		$this->recaptcha_type = 'image';
2394
+		$this->recaptcha_language = 'en';
2395
+		$this->recaptcha_publickey = null;
2396
+		$this->recaptcha_privatekey = null;
2397
+		$this->recaptcha_width = 500;
2398
+		$this->default_maximum_number_of_tickets = 10;
2399
+	}
2400
+
2401
+
2402
+
2403
+	/**
2404
+	 * This is called by the config loader and hooks are initialized AFTER the config has been populated.
2405
+	 *
2406
+	 * @since 4.8.8.rc.019
2407
+	 */
2408
+	public function do_hooks()
2409
+	{
2410
+		add_action('AHEE__EE_Config___load_core_config__end', array($this, 'set_default_reg_status_on_EEM_Event'));
2411
+		add_action('AHEE__EE_Config___load_core_config__end', array($this, 'set_default_max_ticket_on_EEM_Event'));
2412
+	}
2413
+
2414
+
2415
+
2416
+	/**
2417
+	 * Hooked into `AHEE__EE_Config___load_core_config__end` to ensure the default for the EVT_default_registration_status
2418
+	 * field matches the config setting for default_STS_ID.
2419
+	 */
2420
+	public function set_default_reg_status_on_EEM_Event()
2421
+	{
2422
+		EEM_Event::set_default_reg_status($this->default_STS_ID);
2423
+	}
2424
+
2425
+
2426
+	/**
2427
+	 * Hooked into `AHEE__EE_Config___load_core_config__end` to ensure the default for the EVT_additional_limit field
2428
+	 * for Events matches the config setting for default_maximum_number_of_tickets
2429
+	 */
2430
+	public function set_default_max_ticket_on_EEM_Event()
2431
+	{
2432
+		EEM_Event::set_default_additional_limit($this->default_maximum_number_of_tickets);
2433
+	}
2434
+
2435
+
2436
+
2437
+	/**
2438
+	 * @return boolean
2439
+	 */
2440
+	public function track_invalid_checkout_access()
2441
+	{
2442
+		return $this->track_invalid_checkout_access;
2443
+	}
2444
+
2445
+
2446
+
2447
+	/**
2448
+	 * @param boolean $track_invalid_checkout_access
2449
+	 */
2450
+	public function set_track_invalid_checkout_access($track_invalid_checkout_access)
2451
+	{
2452
+		$this->track_invalid_checkout_access = filter_var(
2453
+			$track_invalid_checkout_access,
2454
+			FILTER_VALIDATE_BOOLEAN
2455
+		);
2456
+	}
2457 2457
 
2458 2458
 
2459 2459
 
@@ -2467,160 +2467,160 @@  discard block
 block discarded – undo
2467 2467
 class EE_Admin_Config extends EE_Config_Base
2468 2468
 {
2469 2469
 
2470
-    /**
2471
-     * @var boolean $use_personnel_manager
2472
-     */
2473
-    public $use_personnel_manager;
2474
-
2475
-    /**
2476
-     * @var boolean $use_dashboard_widget
2477
-     */
2478
-    public $use_dashboard_widget;
2479
-
2480
-    /**
2481
-     * @var int $events_in_dashboard
2482
-     */
2483
-    public $events_in_dashboard;
2484
-
2485
-    /**
2486
-     * @var boolean $use_event_timezones
2487
-     */
2488
-    public $use_event_timezones;
2489
-
2490
-    /**
2491
-     * @var boolean $use_full_logging
2492
-     */
2493
-    public $use_full_logging;
2494
-
2495
-    /**
2496
-     * @var string $log_file_name
2497
-     */
2498
-    public $log_file_name;
2499
-
2500
-    /**
2501
-     * @var string $debug_file_name
2502
-     */
2503
-    public $debug_file_name;
2504
-
2505
-    /**
2506
-     * @var boolean $use_remote_logging
2507
-     */
2508
-    public $use_remote_logging;
2509
-
2510
-    /**
2511
-     * @var string $remote_logging_url
2512
-     */
2513
-    public $remote_logging_url;
2514
-
2515
-    /**
2516
-     * @var boolean $show_reg_footer
2517
-     */
2518
-    public $show_reg_footer;
2519
-
2520
-    /**
2521
-     * @var string $affiliate_id
2522
-     */
2523
-    public $affiliate_id;
2524
-
2525
-    /**
2526
-     * help tours on or off (global setting)
2527
-     *
2528
-     * @var boolean
2529
-     */
2530
-    public $help_tour_activation;
2531
-
2532
-    /**
2533
-     * adds extra layer of encoding to session data to prevent serialization errors
2534
-     * but is incompatible with some server configuration errors
2535
-     * if you get "500 internal server errors" during registration, try turning this on
2536
-     * if you get PHP fatal errors regarding base 64 methods not defined, then turn this off
2537
-     *
2538
-     * @var boolean $encode_session_data
2539
-     */
2540
-    private $encode_session_data = false;
2541
-
2542
-
2543
-
2544
-    /**
2545
-     *    class constructor
2546
-     *
2547
-     * @access    public
2548
-     */
2549
-    public function __construct()
2550
-    {
2551
-        // set default general admin settings
2552
-        $this->use_personnel_manager = true;
2553
-        $this->use_dashboard_widget = true;
2554
-        $this->events_in_dashboard = 30;
2555
-        $this->use_event_timezones = false;
2556
-        $this->use_full_logging = false;
2557
-        $this->use_remote_logging = false;
2558
-        $this->remote_logging_url = null;
2559
-        $this->show_reg_footer = true;
2560
-        $this->affiliate_id = 'default';
2561
-        $this->help_tour_activation = true;
2562
-        $this->encode_session_data = false;
2563
-    }
2564
-
2565
-
2566
-
2567
-    /**
2568
-     * @param bool $reset
2569
-     * @return string
2570
-     */
2571
-    public function log_file_name($reset = false)
2572
-    {
2573
-        if (empty($this->log_file_name) || $reset) {
2574
-            $this->log_file_name = sanitize_key('espresso_log_' . md5(uniqid('', true))) . '.txt';
2575
-            EE_Config::instance()->update_espresso_config(false, false);
2576
-        }
2577
-        return $this->log_file_name;
2578
-    }
2579
-
2580
-
2581
-
2582
-    /**
2583
-     * @param bool $reset
2584
-     * @return string
2585
-     */
2586
-    public function debug_file_name($reset = false)
2587
-    {
2588
-        if (empty($this->debug_file_name) || $reset) {
2589
-            $this->debug_file_name = sanitize_key('espresso_debug_' . md5(uniqid('', true))) . '.txt';
2590
-            EE_Config::instance()->update_espresso_config(false, false);
2591
-        }
2592
-        return $this->debug_file_name;
2593
-    }
2594
-
2595
-
2596
-
2597
-    /**
2598
-     * @return string
2599
-     */
2600
-    public function affiliate_id()
2601
-    {
2602
-        return ! empty($this->affiliate_id) ? $this->affiliate_id : 'default';
2603
-    }
2604
-
2605
-
2606
-
2607
-    /**
2608
-     * @return boolean
2609
-     */
2610
-    public function encode_session_data()
2611
-    {
2612
-        return filter_var($this->encode_session_data, FILTER_VALIDATE_BOOLEAN);
2613
-    }
2614
-
2615
-
2616
-
2617
-    /**
2618
-     * @param boolean $encode_session_data
2619
-     */
2620
-    public function set_encode_session_data($encode_session_data)
2621
-    {
2622
-        $this->encode_session_data = filter_var($encode_session_data, FILTER_VALIDATE_BOOLEAN);
2623
-    }
2470
+	/**
2471
+	 * @var boolean $use_personnel_manager
2472
+	 */
2473
+	public $use_personnel_manager;
2474
+
2475
+	/**
2476
+	 * @var boolean $use_dashboard_widget
2477
+	 */
2478
+	public $use_dashboard_widget;
2479
+
2480
+	/**
2481
+	 * @var int $events_in_dashboard
2482
+	 */
2483
+	public $events_in_dashboard;
2484
+
2485
+	/**
2486
+	 * @var boolean $use_event_timezones
2487
+	 */
2488
+	public $use_event_timezones;
2489
+
2490
+	/**
2491
+	 * @var boolean $use_full_logging
2492
+	 */
2493
+	public $use_full_logging;
2494
+
2495
+	/**
2496
+	 * @var string $log_file_name
2497
+	 */
2498
+	public $log_file_name;
2499
+
2500
+	/**
2501
+	 * @var string $debug_file_name
2502
+	 */
2503
+	public $debug_file_name;
2504
+
2505
+	/**
2506
+	 * @var boolean $use_remote_logging
2507
+	 */
2508
+	public $use_remote_logging;
2509
+
2510
+	/**
2511
+	 * @var string $remote_logging_url
2512
+	 */
2513
+	public $remote_logging_url;
2514
+
2515
+	/**
2516
+	 * @var boolean $show_reg_footer
2517
+	 */
2518
+	public $show_reg_footer;
2519
+
2520
+	/**
2521
+	 * @var string $affiliate_id
2522
+	 */
2523
+	public $affiliate_id;
2524
+
2525
+	/**
2526
+	 * help tours on or off (global setting)
2527
+	 *
2528
+	 * @var boolean
2529
+	 */
2530
+	public $help_tour_activation;
2531
+
2532
+	/**
2533
+	 * adds extra layer of encoding to session data to prevent serialization errors
2534
+	 * but is incompatible with some server configuration errors
2535
+	 * if you get "500 internal server errors" during registration, try turning this on
2536
+	 * if you get PHP fatal errors regarding base 64 methods not defined, then turn this off
2537
+	 *
2538
+	 * @var boolean $encode_session_data
2539
+	 */
2540
+	private $encode_session_data = false;
2541
+
2542
+
2543
+
2544
+	/**
2545
+	 *    class constructor
2546
+	 *
2547
+	 * @access    public
2548
+	 */
2549
+	public function __construct()
2550
+	{
2551
+		// set default general admin settings
2552
+		$this->use_personnel_manager = true;
2553
+		$this->use_dashboard_widget = true;
2554
+		$this->events_in_dashboard = 30;
2555
+		$this->use_event_timezones = false;
2556
+		$this->use_full_logging = false;
2557
+		$this->use_remote_logging = false;
2558
+		$this->remote_logging_url = null;
2559
+		$this->show_reg_footer = true;
2560
+		$this->affiliate_id = 'default';
2561
+		$this->help_tour_activation = true;
2562
+		$this->encode_session_data = false;
2563
+	}
2564
+
2565
+
2566
+
2567
+	/**
2568
+	 * @param bool $reset
2569
+	 * @return string
2570
+	 */
2571
+	public function log_file_name($reset = false)
2572
+	{
2573
+		if (empty($this->log_file_name) || $reset) {
2574
+			$this->log_file_name = sanitize_key('espresso_log_' . md5(uniqid('', true))) . '.txt';
2575
+			EE_Config::instance()->update_espresso_config(false, false);
2576
+		}
2577
+		return $this->log_file_name;
2578
+	}
2579
+
2580
+
2581
+
2582
+	/**
2583
+	 * @param bool $reset
2584
+	 * @return string
2585
+	 */
2586
+	public function debug_file_name($reset = false)
2587
+	{
2588
+		if (empty($this->debug_file_name) || $reset) {
2589
+			$this->debug_file_name = sanitize_key('espresso_debug_' . md5(uniqid('', true))) . '.txt';
2590
+			EE_Config::instance()->update_espresso_config(false, false);
2591
+		}
2592
+		return $this->debug_file_name;
2593
+	}
2594
+
2595
+
2596
+
2597
+	/**
2598
+	 * @return string
2599
+	 */
2600
+	public function affiliate_id()
2601
+	{
2602
+		return ! empty($this->affiliate_id) ? $this->affiliate_id : 'default';
2603
+	}
2604
+
2605
+
2606
+
2607
+	/**
2608
+	 * @return boolean
2609
+	 */
2610
+	public function encode_session_data()
2611
+	{
2612
+		return filter_var($this->encode_session_data, FILTER_VALIDATE_BOOLEAN);
2613
+	}
2614
+
2615
+
2616
+
2617
+	/**
2618
+	 * @param boolean $encode_session_data
2619
+	 */
2620
+	public function set_encode_session_data($encode_session_data)
2621
+	{
2622
+		$this->encode_session_data = filter_var($encode_session_data, FILTER_VALIDATE_BOOLEAN);
2623
+	}
2624 2624
 
2625 2625
 
2626 2626
 
@@ -2634,71 +2634,71 @@  discard block
 block discarded – undo
2634 2634
 class EE_Template_Config extends EE_Config_Base
2635 2635
 {
2636 2636
 
2637
-    /**
2638
-     * @var boolean $enable_default_style
2639
-     */
2640
-    public $enable_default_style;
2641
-
2642
-    /**
2643
-     * @var string $custom_style_sheet
2644
-     */
2645
-    public $custom_style_sheet;
2646
-
2647
-    /**
2648
-     * @var boolean $display_address_in_regform
2649
-     */
2650
-    public $display_address_in_regform;
2651
-
2652
-    /**
2653
-     * @var int $display_description_on_multi_reg_page
2654
-     */
2655
-    public $display_description_on_multi_reg_page;
2656
-
2657
-    /**
2658
-     * @var boolean $use_custom_templates
2659
-     */
2660
-    public $use_custom_templates;
2661
-
2662
-    /**
2663
-     * @var string $current_espresso_theme
2664
-     */
2665
-    public $current_espresso_theme;
2666
-
2667
-    /**
2668
-     * @var EE_Ticket_Selector_Config $EED_Ticket_Selector
2669
-     */
2670
-    public $EED_Ticket_Selector;
2671
-
2672
-    /**
2673
-     * @var EE_Event_Single_Config $EED_Event_Single
2674
-     */
2675
-    public $EED_Event_Single;
2676
-
2677
-    /**
2678
-     * @var EE_Events_Archive_Config $EED_Events_Archive
2679
-     */
2680
-    public $EED_Events_Archive;
2681
-
2682
-
2683
-
2684
-    /**
2685
-     *    class constructor
2686
-     *
2687
-     * @access    public
2688
-     */
2689
-    public function __construct()
2690
-    {
2691
-        // set default template settings
2692
-        $this->enable_default_style = true;
2693
-        $this->custom_style_sheet = null;
2694
-        $this->display_address_in_regform = true;
2695
-        $this->display_description_on_multi_reg_page = false;
2696
-        $this->use_custom_templates = false;
2697
-        $this->current_espresso_theme = 'Espresso_Arabica_2014';
2698
-        $this->EED_Event_Single = null;
2699
-        $this->EED_Events_Archive = null;
2700
-        $this->EED_Ticket_Selector = null;
2701
-    }
2637
+	/**
2638
+	 * @var boolean $enable_default_style
2639
+	 */
2640
+	public $enable_default_style;
2641
+
2642
+	/**
2643
+	 * @var string $custom_style_sheet
2644
+	 */
2645
+	public $custom_style_sheet;
2646
+
2647
+	/**
2648
+	 * @var boolean $display_address_in_regform
2649
+	 */
2650
+	public $display_address_in_regform;
2651
+
2652
+	/**
2653
+	 * @var int $display_description_on_multi_reg_page
2654
+	 */
2655
+	public $display_description_on_multi_reg_page;
2656
+
2657
+	/**
2658
+	 * @var boolean $use_custom_templates
2659
+	 */
2660
+	public $use_custom_templates;
2661
+
2662
+	/**
2663
+	 * @var string $current_espresso_theme
2664
+	 */
2665
+	public $current_espresso_theme;
2666
+
2667
+	/**
2668
+	 * @var EE_Ticket_Selector_Config $EED_Ticket_Selector
2669
+	 */
2670
+	public $EED_Ticket_Selector;
2671
+
2672
+	/**
2673
+	 * @var EE_Event_Single_Config $EED_Event_Single
2674
+	 */
2675
+	public $EED_Event_Single;
2676
+
2677
+	/**
2678
+	 * @var EE_Events_Archive_Config $EED_Events_Archive
2679
+	 */
2680
+	public $EED_Events_Archive;
2681
+
2682
+
2683
+
2684
+	/**
2685
+	 *    class constructor
2686
+	 *
2687
+	 * @access    public
2688
+	 */
2689
+	public function __construct()
2690
+	{
2691
+		// set default template settings
2692
+		$this->enable_default_style = true;
2693
+		$this->custom_style_sheet = null;
2694
+		$this->display_address_in_regform = true;
2695
+		$this->display_description_on_multi_reg_page = false;
2696
+		$this->use_custom_templates = false;
2697
+		$this->current_espresso_theme = 'Espresso_Arabica_2014';
2698
+		$this->EED_Event_Single = null;
2699
+		$this->EED_Events_Archive = null;
2700
+		$this->EED_Ticket_Selector = null;
2701
+	}
2702 2702
 
2703 2703
 }
2704 2704
 
@@ -2710,115 +2710,115 @@  discard block
 block discarded – undo
2710 2710
 class EE_Map_Config extends EE_Config_Base
2711 2711
 {
2712 2712
 
2713
-    /**
2714
-     * @var boolean $use_google_maps
2715
-     */
2716
-    public $use_google_maps;
2717
-
2718
-    /**
2719
-     * @var string $api_key
2720
-     */
2721
-    public $google_map_api_key;
2722
-
2723
-    /**
2724
-     * @var int $event_details_map_width
2725
-     */
2726
-    public $event_details_map_width;
2727
-
2728
-    /**
2729
-     * @var int $event_details_map_height
2730
-     */
2731
-    public $event_details_map_height;
2732
-
2733
-    /**
2734
-     * @var int $event_details_map_zoom
2735
-     */
2736
-    public $event_details_map_zoom;
2737
-
2738
-    /**
2739
-     * @var boolean $event_details_display_nav
2740
-     */
2741
-    public $event_details_display_nav;
2742
-
2743
-    /**
2744
-     * @var boolean $event_details_nav_size
2745
-     */
2746
-    public $event_details_nav_size;
2747
-
2748
-    /**
2749
-     * @var string $event_details_control_type
2750
-     */
2751
-    public $event_details_control_type;
2752
-
2753
-    /**
2754
-     * @var string $event_details_map_align
2755
-     */
2756
-    public $event_details_map_align;
2757
-
2758
-    /**
2759
-     * @var int $event_list_map_width
2760
-     */
2761
-    public $event_list_map_width;
2762
-
2763
-    /**
2764
-     * @var int $event_list_map_height
2765
-     */
2766
-    public $event_list_map_height;
2767
-
2768
-    /**
2769
-     * @var int $event_list_map_zoom
2770
-     */
2771
-    public $event_list_map_zoom;
2772
-
2773
-    /**
2774
-     * @var boolean $event_list_display_nav
2775
-     */
2776
-    public $event_list_display_nav;
2777
-
2778
-    /**
2779
-     * @var boolean $event_list_nav_size
2780
-     */
2781
-    public $event_list_nav_size;
2782
-
2783
-    /**
2784
-     * @var string $event_list_control_type
2785
-     */
2786
-    public $event_list_control_type;
2787
-
2788
-    /**
2789
-     * @var string $event_list_map_align
2790
-     */
2791
-    public $event_list_map_align;
2792
-
2793
-
2794
-
2795
-    /**
2796
-     *    class constructor
2797
-     *
2798
-     * @access    public
2799
-     */
2800
-    public function __construct()
2801
-    {
2802
-        // set default map settings
2803
-        $this->use_google_maps = true;
2804
-        $this->google_map_api_key = '';
2805
-        // for event details pages (reg page)
2806
-        $this->event_details_map_width = 585;            // ee_map_width_single
2807
-        $this->event_details_map_height = 362;            // ee_map_height_single
2808
-        $this->event_details_map_zoom = 14;            // ee_map_zoom_single
2809
-        $this->event_details_display_nav = true;            // ee_map_nav_display_single
2810
-        $this->event_details_nav_size = false;            // ee_map_nav_size_single
2811
-        $this->event_details_control_type = 'default';        // ee_map_type_control_single
2812
-        $this->event_details_map_align = 'center';            // ee_map_align_single
2813
-        // for event list pages
2814
-        $this->event_list_map_width = 300;            // ee_map_width
2815
-        $this->event_list_map_height = 185;        // ee_map_height
2816
-        $this->event_list_map_zoom = 12;            // ee_map_zoom
2817
-        $this->event_list_display_nav = false;        // ee_map_nav_display
2818
-        $this->event_list_nav_size = true;            // ee_map_nav_size
2819
-        $this->event_list_control_type = 'dropdown';        // ee_map_type_control
2820
-        $this->event_list_map_align = 'center';            // ee_map_align
2821
-    }
2713
+	/**
2714
+	 * @var boolean $use_google_maps
2715
+	 */
2716
+	public $use_google_maps;
2717
+
2718
+	/**
2719
+	 * @var string $api_key
2720
+	 */
2721
+	public $google_map_api_key;
2722
+
2723
+	/**
2724
+	 * @var int $event_details_map_width
2725
+	 */
2726
+	public $event_details_map_width;
2727
+
2728
+	/**
2729
+	 * @var int $event_details_map_height
2730
+	 */
2731
+	public $event_details_map_height;
2732
+
2733
+	/**
2734
+	 * @var int $event_details_map_zoom
2735
+	 */
2736
+	public $event_details_map_zoom;
2737
+
2738
+	/**
2739
+	 * @var boolean $event_details_display_nav
2740
+	 */
2741
+	public $event_details_display_nav;
2742
+
2743
+	/**
2744
+	 * @var boolean $event_details_nav_size
2745
+	 */
2746
+	public $event_details_nav_size;
2747
+
2748
+	/**
2749
+	 * @var string $event_details_control_type
2750
+	 */
2751
+	public $event_details_control_type;
2752
+
2753
+	/**
2754
+	 * @var string $event_details_map_align
2755
+	 */
2756
+	public $event_details_map_align;
2757
+
2758
+	/**
2759
+	 * @var int $event_list_map_width
2760
+	 */
2761
+	public $event_list_map_width;
2762
+
2763
+	/**
2764
+	 * @var int $event_list_map_height
2765
+	 */
2766
+	public $event_list_map_height;
2767
+
2768
+	/**
2769
+	 * @var int $event_list_map_zoom
2770
+	 */
2771
+	public $event_list_map_zoom;
2772
+
2773
+	/**
2774
+	 * @var boolean $event_list_display_nav
2775
+	 */
2776
+	public $event_list_display_nav;
2777
+
2778
+	/**
2779
+	 * @var boolean $event_list_nav_size
2780
+	 */
2781
+	public $event_list_nav_size;
2782
+
2783
+	/**
2784
+	 * @var string $event_list_control_type
2785
+	 */
2786
+	public $event_list_control_type;
2787
+
2788
+	/**
2789
+	 * @var string $event_list_map_align
2790
+	 */
2791
+	public $event_list_map_align;
2792
+
2793
+
2794
+
2795
+	/**
2796
+	 *    class constructor
2797
+	 *
2798
+	 * @access    public
2799
+	 */
2800
+	public function __construct()
2801
+	{
2802
+		// set default map settings
2803
+		$this->use_google_maps = true;
2804
+		$this->google_map_api_key = '';
2805
+		// for event details pages (reg page)
2806
+		$this->event_details_map_width = 585;            // ee_map_width_single
2807
+		$this->event_details_map_height = 362;            // ee_map_height_single
2808
+		$this->event_details_map_zoom = 14;            // ee_map_zoom_single
2809
+		$this->event_details_display_nav = true;            // ee_map_nav_display_single
2810
+		$this->event_details_nav_size = false;            // ee_map_nav_size_single
2811
+		$this->event_details_control_type = 'default';        // ee_map_type_control_single
2812
+		$this->event_details_map_align = 'center';            // ee_map_align_single
2813
+		// for event list pages
2814
+		$this->event_list_map_width = 300;            // ee_map_width
2815
+		$this->event_list_map_height = 185;        // ee_map_height
2816
+		$this->event_list_map_zoom = 12;            // ee_map_zoom
2817
+		$this->event_list_display_nav = false;        // ee_map_nav_display
2818
+		$this->event_list_nav_size = true;            // ee_map_nav_size
2819
+		$this->event_list_control_type = 'dropdown';        // ee_map_type_control
2820
+		$this->event_list_map_align = 'center';            // ee_map_align
2821
+	}
2822 2822
 
2823 2823
 }
2824 2824
 
@@ -2830,47 +2830,47 @@  discard block
 block discarded – undo
2830 2830
 class EE_Events_Archive_Config extends EE_Config_Base
2831 2831
 {
2832 2832
 
2833
-    public $display_status_banner;
2833
+	public $display_status_banner;
2834 2834
 
2835
-    public $display_description;
2835
+	public $display_description;
2836 2836
 
2837
-    public $display_ticket_selector;
2837
+	public $display_ticket_selector;
2838 2838
 
2839
-    public $display_datetimes;
2839
+	public $display_datetimes;
2840 2840
 
2841
-    public $display_venue;
2841
+	public $display_venue;
2842 2842
 
2843
-    public $display_expired_events;
2843
+	public $display_expired_events;
2844 2844
 
2845
-    public $use_sortable_display_order;
2845
+	public $use_sortable_display_order;
2846 2846
 
2847
-    public $display_order_tickets;
2847
+	public $display_order_tickets;
2848 2848
 
2849
-    public $display_order_datetimes;
2849
+	public $display_order_datetimes;
2850 2850
 
2851
-    public $display_order_event;
2851
+	public $display_order_event;
2852 2852
 
2853
-    public $display_order_venue;
2853
+	public $display_order_venue;
2854 2854
 
2855 2855
 
2856 2856
 
2857
-    /**
2858
-     *    class constructor
2859
-     */
2860
-    public function __construct()
2861
-    {
2862
-        $this->display_status_banner = 0;
2863
-        $this->display_description = 1;
2864
-        $this->display_ticket_selector = 0;
2865
-        $this->display_datetimes = 1;
2866
-        $this->display_venue = 0;
2867
-        $this->display_expired_events = 0;
2868
-        $this->use_sortable_display_order = false;
2869
-        $this->display_order_tickets = 100;
2870
-        $this->display_order_datetimes = 110;
2871
-        $this->display_order_event = 120;
2872
-        $this->display_order_venue = 130;
2873
-    }
2857
+	/**
2858
+	 *    class constructor
2859
+	 */
2860
+	public function __construct()
2861
+	{
2862
+		$this->display_status_banner = 0;
2863
+		$this->display_description = 1;
2864
+		$this->display_ticket_selector = 0;
2865
+		$this->display_datetimes = 1;
2866
+		$this->display_venue = 0;
2867
+		$this->display_expired_events = 0;
2868
+		$this->use_sortable_display_order = false;
2869
+		$this->display_order_tickets = 100;
2870
+		$this->display_order_datetimes = 110;
2871
+		$this->display_order_event = 120;
2872
+		$this->display_order_venue = 130;
2873
+	}
2874 2874
 }
2875 2875
 
2876 2876
 
@@ -2881,35 +2881,35 @@  discard block
 block discarded – undo
2881 2881
 class EE_Event_Single_Config extends EE_Config_Base
2882 2882
 {
2883 2883
 
2884
-    public $display_status_banner_single;
2884
+	public $display_status_banner_single;
2885 2885
 
2886
-    public $display_venue;
2886
+	public $display_venue;
2887 2887
 
2888
-    public $use_sortable_display_order;
2888
+	public $use_sortable_display_order;
2889 2889
 
2890
-    public $display_order_tickets;
2890
+	public $display_order_tickets;
2891 2891
 
2892
-    public $display_order_datetimes;
2892
+	public $display_order_datetimes;
2893 2893
 
2894
-    public $display_order_event;
2894
+	public $display_order_event;
2895 2895
 
2896
-    public $display_order_venue;
2896
+	public $display_order_venue;
2897 2897
 
2898 2898
 
2899 2899
 
2900
-    /**
2901
-     *    class constructor
2902
-     */
2903
-    public function __construct()
2904
-    {
2905
-        $this->display_status_banner_single = 0;
2906
-        $this->display_venue = 1;
2907
-        $this->use_sortable_display_order = false;
2908
-        $this->display_order_tickets = 100;
2909
-        $this->display_order_datetimes = 110;
2910
-        $this->display_order_event = 120;
2911
-        $this->display_order_venue = 130;
2912
-    }
2900
+	/**
2901
+	 *    class constructor
2902
+	 */
2903
+	public function __construct()
2904
+	{
2905
+		$this->display_status_banner_single = 0;
2906
+		$this->display_venue = 1;
2907
+		$this->use_sortable_display_order = false;
2908
+		$this->display_order_tickets = 100;
2909
+		$this->display_order_datetimes = 110;
2910
+		$this->display_order_event = 120;
2911
+		$this->display_order_venue = 130;
2912
+	}
2913 2913
 }
2914 2914
 
2915 2915
 
@@ -2920,152 +2920,152 @@  discard block
 block discarded – undo
2920 2920
 class EE_Ticket_Selector_Config extends EE_Config_Base
2921 2921
 {
2922 2922
 
2923
-    /**
2924
-     * constant to indicate that a datetime selector should NEVER be shown for ticket selectors
2925
-     */
2926
-    const DO_NOT_SHOW_DATETIME_SELECTOR = 'no_datetime_selector';
2927
-
2928
-    /**
2929
-     * constant to indicate that a datetime selector should only be shown for ticket selectors
2930
-     * when the number of datetimes for the event matches the value set for $datetime_selector_threshold
2931
-     */
2932
-    const MAYBE_SHOW_DATETIME_SELECTOR = 'maybe_datetime_selector';
2933
-
2934
-    /**
2935
-     * @var boolean $show_ticket_sale_columns
2936
-     */
2937
-    public $show_ticket_sale_columns;
2938
-
2939
-    /**
2940
-     * @var boolean $show_ticket_details
2941
-     */
2942
-    public $show_ticket_details;
2943
-
2944
-    /**
2945
-     * @var boolean $show_expired_tickets
2946
-     */
2947
-    public $show_expired_tickets;
2948
-
2949
-    /**
2950
-     * whether or not to display a dropdown box populated with event datetimes
2951
-     * that toggles which tickets are displayed for a ticket selector.
2952
-     * uses one of the *_DATETIME_SELECTOR constants defined above
2953
-     *
2954
-     * @var string $show_datetime_selector
2955
-     */
2956
-    private $show_datetime_selector = 'no_datetime_selector';
2957
-
2958
-    /**
2959
-     * the number of datetimes an event has to have before conditionally displaying a datetime selector
2960
-     *
2961
-     * @var int $datetime_selector_threshold
2962
-     */
2963
-    private $datetime_selector_threshold = 3;
2964
-
2965
-
2966
-
2967
-    /**
2968
-     *    class constructor
2969
-     */
2970
-    public function __construct()
2971
-    {
2972
-        $this->show_ticket_sale_columns = true;
2973
-        $this->show_ticket_details = true;
2974
-        $this->show_expired_tickets = true;
2975
-        $this->show_datetime_selector = \EE_Ticket_Selector_Config::DO_NOT_SHOW_DATETIME_SELECTOR;
2976
-        $this->datetime_selector_threshold = 3;
2977
-    }
2978
-
2979
-
2980
-
2981
-    /**
2982
-     * returns true if a datetime selector should be displayed
2983
-     *
2984
-     * @param array $datetimes
2985
-     * @return bool
2986
-     */
2987
-    public function showDatetimeSelector(array $datetimes)
2988
-    {
2989
-        // if the settings are NOT: don't show OR below threshold, THEN active = true
2990
-        return ! (
2991
-            $this->getShowDatetimeSelector() === \EE_Ticket_Selector_Config::DO_NOT_SHOW_DATETIME_SELECTOR
2992
-            || (
2993
-                $this->getShowDatetimeSelector() === \EE_Ticket_Selector_Config::MAYBE_SHOW_DATETIME_SELECTOR
2994
-                && count($datetimes) < $this->getDatetimeSelectorThreshold()
2995
-            )
2996
-        );
2997
-    }
2998
-
2999
-
3000
-
3001
-    /**
3002
-     * @return string
3003
-     */
3004
-    public function getShowDatetimeSelector()
3005
-    {
3006
-        return $this->show_datetime_selector;
3007
-    }
3008
-
3009
-
3010
-
3011
-    /**
3012
-     * @param bool $keys_only
3013
-     * @return array
3014
-     */
3015
-    public function getShowDatetimeSelectorOptions($keys_only = true)
3016
-    {
3017
-        return $keys_only
3018
-            ? array(
3019
-                \EE_Ticket_Selector_Config::DO_NOT_SHOW_DATETIME_SELECTOR,
3020
-                \EE_Ticket_Selector_Config::MAYBE_SHOW_DATETIME_SELECTOR,
3021
-            )
3022
-            : array(
3023
-                \EE_Ticket_Selector_Config::DO_NOT_SHOW_DATETIME_SELECTOR => esc_html__(
3024
-                    'Do not show date & time filter', 'event_espresso'
3025
-                ),
3026
-                \EE_Ticket_Selector_Config::MAYBE_SHOW_DATETIME_SELECTOR  => esc_html__(
3027
-                    'Maybe show date & time filter', 'event_espresso'
3028
-                ),
3029
-            );
3030
-    }
3031
-
3032
-
3033
-
3034
-    /**
3035
-     * @param string $show_datetime_selector
3036
-     */
3037
-    public function setShowDatetimeSelector($show_datetime_selector)
3038
-    {
3039
-        $this->show_datetime_selector = in_array(
3040
-            $show_datetime_selector,
3041
-            $this->getShowDatetimeSelectorOptions(),
3042
-            true
3043
-        )
3044
-            ? $show_datetime_selector
3045
-            : \EE_Ticket_Selector_Config::DO_NOT_SHOW_DATETIME_SELECTOR;
3046
-    }
3047
-
3048
-
3049
-
3050
-    /**
3051
-     * @return int
3052
-     */
3053
-    public function getDatetimeSelectorThreshold()
3054
-    {
3055
-        return $this->datetime_selector_threshold;
3056
-    }
3057
-
3058
-
3059
-
3060
-
3061
-    /**
3062
-     * @param int $datetime_selector_threshold
3063
-     */
3064
-    public function setDatetimeSelectorThreshold($datetime_selector_threshold)
3065
-    {
3066
-        $datetime_selector_threshold = absint($datetime_selector_threshold);
3067
-        $this->datetime_selector_threshold = $datetime_selector_threshold ? $datetime_selector_threshold : 3;
3068
-    }
2923
+	/**
2924
+	 * constant to indicate that a datetime selector should NEVER be shown for ticket selectors
2925
+	 */
2926
+	const DO_NOT_SHOW_DATETIME_SELECTOR = 'no_datetime_selector';
2927
+
2928
+	/**
2929
+	 * constant to indicate that a datetime selector should only be shown for ticket selectors
2930
+	 * when the number of datetimes for the event matches the value set for $datetime_selector_threshold
2931
+	 */
2932
+	const MAYBE_SHOW_DATETIME_SELECTOR = 'maybe_datetime_selector';
2933
+
2934
+	/**
2935
+	 * @var boolean $show_ticket_sale_columns
2936
+	 */
2937
+	public $show_ticket_sale_columns;
2938
+
2939
+	/**
2940
+	 * @var boolean $show_ticket_details
2941
+	 */
2942
+	public $show_ticket_details;
2943
+
2944
+	/**
2945
+	 * @var boolean $show_expired_tickets
2946
+	 */
2947
+	public $show_expired_tickets;
2948
+
2949
+	/**
2950
+	 * whether or not to display a dropdown box populated with event datetimes
2951
+	 * that toggles which tickets are displayed for a ticket selector.
2952
+	 * uses one of the *_DATETIME_SELECTOR constants defined above
2953
+	 *
2954
+	 * @var string $show_datetime_selector
2955
+	 */
2956
+	private $show_datetime_selector = 'no_datetime_selector';
2957
+
2958
+	/**
2959
+	 * the number of datetimes an event has to have before conditionally displaying a datetime selector
2960
+	 *
2961
+	 * @var int $datetime_selector_threshold
2962
+	 */
2963
+	private $datetime_selector_threshold = 3;
2964
+
2965
+
2966
+
2967
+	/**
2968
+	 *    class constructor
2969
+	 */
2970
+	public function __construct()
2971
+	{
2972
+		$this->show_ticket_sale_columns = true;
2973
+		$this->show_ticket_details = true;
2974
+		$this->show_expired_tickets = true;
2975
+		$this->show_datetime_selector = \EE_Ticket_Selector_Config::DO_NOT_SHOW_DATETIME_SELECTOR;
2976
+		$this->datetime_selector_threshold = 3;
2977
+	}
2978
+
2979
+
2980
+
2981
+	/**
2982
+	 * returns true if a datetime selector should be displayed
2983
+	 *
2984
+	 * @param array $datetimes
2985
+	 * @return bool
2986
+	 */
2987
+	public function showDatetimeSelector(array $datetimes)
2988
+	{
2989
+		// if the settings are NOT: don't show OR below threshold, THEN active = true
2990
+		return ! (
2991
+			$this->getShowDatetimeSelector() === \EE_Ticket_Selector_Config::DO_NOT_SHOW_DATETIME_SELECTOR
2992
+			|| (
2993
+				$this->getShowDatetimeSelector() === \EE_Ticket_Selector_Config::MAYBE_SHOW_DATETIME_SELECTOR
2994
+				&& count($datetimes) < $this->getDatetimeSelectorThreshold()
2995
+			)
2996
+		);
2997
+	}
2998
+
2999
+
3000
+
3001
+	/**
3002
+	 * @return string
3003
+	 */
3004
+	public function getShowDatetimeSelector()
3005
+	{
3006
+		return $this->show_datetime_selector;
3007
+	}
3008
+
3009
+
3010
+
3011
+	/**
3012
+	 * @param bool $keys_only
3013
+	 * @return array
3014
+	 */
3015
+	public function getShowDatetimeSelectorOptions($keys_only = true)
3016
+	{
3017
+		return $keys_only
3018
+			? array(
3019
+				\EE_Ticket_Selector_Config::DO_NOT_SHOW_DATETIME_SELECTOR,
3020
+				\EE_Ticket_Selector_Config::MAYBE_SHOW_DATETIME_SELECTOR,
3021
+			)
3022
+			: array(
3023
+				\EE_Ticket_Selector_Config::DO_NOT_SHOW_DATETIME_SELECTOR => esc_html__(
3024
+					'Do not show date & time filter', 'event_espresso'
3025
+				),
3026
+				\EE_Ticket_Selector_Config::MAYBE_SHOW_DATETIME_SELECTOR  => esc_html__(
3027
+					'Maybe show date & time filter', 'event_espresso'
3028
+				),
3029
+			);
3030
+	}
3031
+
3032
+
3033
+
3034
+	/**
3035
+	 * @param string $show_datetime_selector
3036
+	 */
3037
+	public function setShowDatetimeSelector($show_datetime_selector)
3038
+	{
3039
+		$this->show_datetime_selector = in_array(
3040
+			$show_datetime_selector,
3041
+			$this->getShowDatetimeSelectorOptions(),
3042
+			true
3043
+		)
3044
+			? $show_datetime_selector
3045
+			: \EE_Ticket_Selector_Config::DO_NOT_SHOW_DATETIME_SELECTOR;
3046
+	}
3047
+
3048
+
3049
+
3050
+	/**
3051
+	 * @return int
3052
+	 */
3053
+	public function getDatetimeSelectorThreshold()
3054
+	{
3055
+		return $this->datetime_selector_threshold;
3056
+	}
3057
+
3058
+
3059
+
3060
+
3061
+	/**
3062
+	 * @param int $datetime_selector_threshold
3063
+	 */
3064
+	public function setDatetimeSelectorThreshold($datetime_selector_threshold)
3065
+	{
3066
+		$datetime_selector_threshold = absint($datetime_selector_threshold);
3067
+		$this->datetime_selector_threshold = $datetime_selector_threshold ? $datetime_selector_threshold : 3;
3068
+	}
3069 3069
 
3070 3070
 
3071 3071
 
@@ -3083,85 +3083,85 @@  discard block
 block discarded – undo
3083 3083
 class EE_Environment_Config extends EE_Config_Base
3084 3084
 {
3085 3085
 
3086
-    /**
3087
-     * Hold any php environment variables that we want to track.
3088
-     *
3089
-     * @var stdClass;
3090
-     */
3091
-    public $php;
3092
-
3093
-
3094
-
3095
-    /**
3096
-     *    constructor
3097
-     */
3098
-    public function __construct()
3099
-    {
3100
-        $this->php = new stdClass();
3101
-        $this->_set_php_values();
3102
-    }
3103
-
3104
-
3105
-
3106
-    /**
3107
-     * This sets the php environment variables.
3108
-     *
3109
-     * @since 4.4.0
3110
-     * @return void
3111
-     */
3112
-    protected function _set_php_values()
3113
-    {
3114
-        $this->php->max_input_vars = ini_get('max_input_vars');
3115
-        $this->php->version = phpversion();
3116
-    }
3117
-
3118
-
3119
-
3120
-    /**
3121
-     * helper method for determining whether input_count is
3122
-     * reaching the potential maximum the server can handle
3123
-     * according to max_input_vars
3124
-     *
3125
-     * @param int   $input_count the count of input vars.
3126
-     * @return array {
3127
-     *                           An array that represents whether available space and if no available space the error
3128
-     *                           message.
3129
-     * @type bool   $has_space   whether more inputs can be added.
3130
-     * @type string $msg         Any message to be displayed.
3131
-     *                           }
3132
-     */
3133
-    public function max_input_vars_limit_check($input_count = 0)
3134
-    {
3135
-        if (! empty($this->php->max_input_vars)
3136
-            && ($input_count >= $this->php->max_input_vars)
3137
-            && (PHP_MAJOR_VERSION >= 5 && PHP_MINOR_VERSION >= 3 && PHP_RELEASE_VERSION >= 9)
3138
-        ) {
3139
-            return sprintf(
3140
-                __(
3141
-                    'The maximum number of inputs on this page has been exceeded.  You cannot add anymore items (i.e. tickets, datetimes, custom fields) on this page because of your servers PHP "max_input_vars" setting.%1$sThere are %2$d inputs and the maximum amount currently allowed by your server is %3$d.',
3142
-                    'event_espresso'
3143
-                ),
3144
-                '<br>',
3145
-                $input_count,
3146
-                $this->php->max_input_vars
3147
-            );
3148
-        } else {
3149
-            return '';
3150
-        }
3151
-    }
3152
-
3153
-
3154
-
3155
-    /**
3156
-     * The purpose of this method is just to force rechecking php values so if they've changed, they get updated.
3157
-     *
3158
-     * @since 4.4.1
3159
-     * @return void
3160
-     */
3161
-    public function recheck_values()
3162
-    {
3163
-        $this->_set_php_values();
3164
-    }
3086
+	/**
3087
+	 * Hold any php environment variables that we want to track.
3088
+	 *
3089
+	 * @var stdClass;
3090
+	 */
3091
+	public $php;
3092
+
3093
+
3094
+
3095
+	/**
3096
+	 *    constructor
3097
+	 */
3098
+	public function __construct()
3099
+	{
3100
+		$this->php = new stdClass();
3101
+		$this->_set_php_values();
3102
+	}
3103
+
3104
+
3105
+
3106
+	/**
3107
+	 * This sets the php environment variables.
3108
+	 *
3109
+	 * @since 4.4.0
3110
+	 * @return void
3111
+	 */
3112
+	protected function _set_php_values()
3113
+	{
3114
+		$this->php->max_input_vars = ini_get('max_input_vars');
3115
+		$this->php->version = phpversion();
3116
+	}
3117
+
3118
+
3119
+
3120
+	/**
3121
+	 * helper method for determining whether input_count is
3122
+	 * reaching the potential maximum the server can handle
3123
+	 * according to max_input_vars
3124
+	 *
3125
+	 * @param int   $input_count the count of input vars.
3126
+	 * @return array {
3127
+	 *                           An array that represents whether available space and if no available space the error
3128
+	 *                           message.
3129
+	 * @type bool   $has_space   whether more inputs can be added.
3130
+	 * @type string $msg         Any message to be displayed.
3131
+	 *                           }
3132
+	 */
3133
+	public function max_input_vars_limit_check($input_count = 0)
3134
+	{
3135
+		if (! empty($this->php->max_input_vars)
3136
+			&& ($input_count >= $this->php->max_input_vars)
3137
+			&& (PHP_MAJOR_VERSION >= 5 && PHP_MINOR_VERSION >= 3 && PHP_RELEASE_VERSION >= 9)
3138
+		) {
3139
+			return sprintf(
3140
+				__(
3141
+					'The maximum number of inputs on this page has been exceeded.  You cannot add anymore items (i.e. tickets, datetimes, custom fields) on this page because of your servers PHP "max_input_vars" setting.%1$sThere are %2$d inputs and the maximum amount currently allowed by your server is %3$d.',
3142
+					'event_espresso'
3143
+				),
3144
+				'<br>',
3145
+				$input_count,
3146
+				$this->php->max_input_vars
3147
+			);
3148
+		} else {
3149
+			return '';
3150
+		}
3151
+	}
3152
+
3153
+
3154
+
3155
+	/**
3156
+	 * The purpose of this method is just to force rechecking php values so if they've changed, they get updated.
3157
+	 *
3158
+	 * @since 4.4.1
3159
+	 * @return void
3160
+	 */
3161
+	public function recheck_values()
3162
+	{
3163
+		$this->_set_php_values();
3164
+	}
3165 3165
 
3166 3166
 
3167 3167
 
@@ -3179,22 +3179,22 @@  discard block
 block discarded – undo
3179 3179
 class EE_Tax_Config extends EE_Config_Base
3180 3180
 {
3181 3181
 
3182
-    /*
3182
+	/*
3183 3183
      * flag to indicate whether or not to display ticket prices with the taxes included
3184 3184
      *
3185 3185
      * @var boolean $prices_displayed_including_taxes
3186 3186
      */
3187
-    public $prices_displayed_including_taxes;
3187
+	public $prices_displayed_including_taxes;
3188 3188
 
3189 3189
 
3190 3190
 
3191
-    /**
3192
-     *    class constructor
3193
-     */
3194
-    public function __construct()
3195
-    {
3196
-        $this->prices_displayed_including_taxes = true;
3197
-    }
3191
+	/**
3192
+	 *    class constructor
3193
+	 */
3194
+	public function __construct()
3195
+	{
3196
+		$this->prices_displayed_including_taxes = true;
3197
+	}
3198 3198
 }
3199 3199
 
3200 3200
 
@@ -3209,17 +3209,17 @@  discard block
 block discarded – undo
3209 3209
 class EE_Messages_Config extends EE_Config_Base
3210 3210
 {
3211 3211
 
3212
-    /**
3213
-     * This is an integer representing the deletion threshold in months for when old messages will get deleted.
3214
-     * A value of 0 represents never deleting.  Default is 0.
3215
-     *
3216
-     * @var integer
3217
-     */
3218
-    public $delete_threshold;
3219
-
3220
-    public function __construct() {
3221
-        $this->delete_threshold = 0;
3222
-    }
3212
+	/**
3213
+	 * This is an integer representing the deletion threshold in months for when old messages will get deleted.
3214
+	 * A value of 0 represents never deleting.  Default is 0.
3215
+	 *
3216
+	 * @var integer
3217
+	 */
3218
+	public $delete_threshold;
3219
+
3220
+	public function __construct() {
3221
+		$this->delete_threshold = 0;
3222
+	}
3223 3223
 }
3224 3224
 
3225 3225
 
@@ -3231,34 +3231,34 @@  discard block
 block discarded – undo
3231 3231
 class EE_Gateway_Config extends EE_Config_Base
3232 3232
 {
3233 3233
 
3234
-    /**
3235
-     * Array with keys that are payment gateways slugs, and values are arrays
3236
-     * with any config info the gateway wants to store
3237
-     *
3238
-     * @var array
3239
-     */
3240
-    public $payment_settings;
3241
-
3242
-    /**
3243
-     * Where keys are gateway slugs, and values are booleans indicating whether or not
3244
-     * the gateway is stored in the uploads directory
3245
-     *
3246
-     * @var array
3247
-     */
3248
-    public $active_gateways;
3249
-
3250
-
3251
-
3252
-    /**
3253
-     *    class constructor
3254
-     *
3255
-     * @deprecated
3256
-     */
3257
-    public function __construct()
3258
-    {
3259
-        $this->payment_settings = array();
3260
-        $this->active_gateways = array('Invoice' => false);
3261
-    }
3234
+	/**
3235
+	 * Array with keys that are payment gateways slugs, and values are arrays
3236
+	 * with any config info the gateway wants to store
3237
+	 *
3238
+	 * @var array
3239
+	 */
3240
+	public $payment_settings;
3241
+
3242
+	/**
3243
+	 * Where keys are gateway slugs, and values are booleans indicating whether or not
3244
+	 * the gateway is stored in the uploads directory
3245
+	 *
3246
+	 * @var array
3247
+	 */
3248
+	public $active_gateways;
3249
+
3250
+
3251
+
3252
+	/**
3253
+	 *    class constructor
3254
+	 *
3255
+	 * @deprecated
3256
+	 */
3257
+	public function __construct()
3258
+	{
3259
+		$this->payment_settings = array();
3260
+		$this->active_gateways = array('Invoice' => false);
3261
+	}
3262 3262
 }
3263 3263
 
3264 3264
 // End of file EE_Config.core.php
Please login to merge, or discard this patch.
core/EE_Cart.core.php 1 patch
Indentation   +413 added lines, -413 removed lines patch added patch discarded remove patch
@@ -2,7 +2,7 @@  discard block
 block discarded – undo
2 2
 use EventEspresso\core\interfaces\ResettableInterface;
3 3
 
4 4
 if ( ! defined('EVENT_ESPRESSO_VERSION')) {
5
-    exit('No direct script access allowed');
5
+	exit('No direct script access allowed');
6 6
 }
7 7
 do_action('AHEE_log', __FILE__, __FUNCTION__, '');
8 8
 
@@ -23,418 +23,418 @@  discard block
 block discarded – undo
23 23
 class EE_Cart implements ResettableInterface
24 24
 {
25 25
 
26
-    /**
27
-     * instance of the EE_Cart object
28
-     *
29
-     * @access    private
30
-     * @var EE_Cart $_instance
31
-     */
32
-    private static $_instance;
33
-
34
-    /**
35
-     * instance of the EE_Session object
36
-     *
37
-     * @access    protected
38
-     * @var EE_Session $_session
39
-     */
40
-    protected $_session;
41
-
42
-    /**
43
-     * The total Line item which comprises all the children line-item subtotals,
44
-     * which in turn each have their line items.
45
-     * Typically, the line item structure will look like:
46
-     * grand total
47
-     * -tickets-sub-total
48
-     * --ticket1
49
-     * --ticket2
50
-     * --...
51
-     * -taxes-sub-total
52
-     * --tax1
53
-     * --tax2
54
-     *
55
-     * @var EE_Line_Item
56
-     */
57
-    private $_grand_total;
58
-
59
-
60
-
61
-    /**
62
-     * @singleton method used to instantiate class object
63
-     * @access    public
64
-     * @param EE_Line_Item $grand_total
65
-     * @param EE_Session   $session
66
-     * @return \EE_Cart
67
-     * @throws \EE_Error
68
-     */
69
-    public static function instance(EE_Line_Item $grand_total = null, EE_Session $session = null)
70
-    {
71
-        if ( ! empty($grand_total)) {
72
-            self::$_instance = new self($grand_total, $session);
73
-        }
74
-        // or maybe retrieve an existing one ?
75
-        if ( ! self::$_instance instanceof EE_Cart) {
76
-            // try getting the cart out of the session
77
-            $saved_cart = $session instanceof EE_Session ? $session->cart() : null;
78
-            self::$_instance = $saved_cart instanceof EE_Cart ? $saved_cart : new self($grand_total, $session);
79
-            unset($saved_cart);
80
-        }
81
-        // verify that cart is ok and grand total line item exists
82
-        if ( ! self::$_instance instanceof EE_Cart || ! self::$_instance->_grand_total instanceof EE_Line_Item) {
83
-            self::$_instance = new self($grand_total, $session);
84
-        }
85
-        self::$_instance->get_grand_total();
86
-        // once everything is all said and done, save the cart to the EE_Session
87
-        add_action('shutdown', array(self::$_instance, 'save_cart'), 90);
88
-        return self::$_instance;
89
-    }
90
-
91
-
92
-
93
-    /**
94
-     * private constructor to prevent direct creation
95
-     *
96
-     * @Constructor
97
-     * @access private
98
-     * @param EE_Line_Item $grand_total
99
-     * @param EE_Session   $session
100
-     */
101
-    private function __construct(EE_Line_Item $grand_total = null, EE_Session $session = null)
102
-    {
103
-        do_action('AHEE_log', __FILE__, __FUNCTION__, '');
104
-        $this->set_session($session);
105
-        if ($grand_total instanceof EE_Line_Item) {
106
-            $this->set_grand_total_line_item($grand_total);
107
-        }
108
-    }
109
-
110
-
111
-
112
-    /**
113
-     * Resets the cart completely (whereas empty_cart
114
-     *
115
-     * @param EE_Line_Item $grand_total
116
-     * @param EE_Session   $session
117
-     * @return EE_Cart
118
-     * @throws \EE_Error
119
-     */
120
-    public static function reset(EE_Line_Item $grand_total = null, EE_Session $session = null)
121
-    {
122
-        remove_action('shutdown', array(self::$_instance, 'save_cart'), 90);
123
-        if ($session instanceof EE_Session) {
124
-            $session->reset_cart();
125
-        }
126
-        self::$_instance = null;
127
-        return self::instance($grand_total, $session);
128
-    }
129
-
130
-
131
-
132
-    /**
133
-     * @return \EE_Session
134
-     */
135
-    public function session()
136
-    {
137
-        if ( ! $this->_session instanceof EE_Session) {
138
-            $this->set_session();
139
-        }
140
-        return $this->_session;
141
-    }
142
-
143
-
144
-
145
-    /**
146
-     * @param EE_Session $session
147
-     */
148
-    public function set_session(EE_Session $session = null)
149
-    {
150
-        $this->_session = $session instanceof EE_Session ? $session : EE_Registry::instance()->load_core('Session');
151
-    }
152
-
153
-
154
-
155
-    /**
156
-     * Sets the cart to match the line item. Especially handy for loading an old cart where you
157
-     *  know the grand total line item on it
158
-     *
159
-     * @param EE_Line_Item $line_item
160
-     */
161
-    public function set_grand_total_line_item(EE_Line_Item $line_item)
162
-    {
163
-        $this->_grand_total = $line_item;
164
-    }
165
-
166
-
167
-
168
-    /**
169
-     * get_cart_from_reg_url_link
170
-     *
171
-     * @access public
172
-     * @param EE_Transaction $transaction
173
-     * @param EE_Session     $session
174
-     * @return \EE_Cart
175
-     * @throws \EE_Error
176
-     */
177
-    public static function get_cart_from_txn(EE_Transaction $transaction, EE_Session $session = null)
178
-    {
179
-        $grand_total = $transaction->total_line_item();
180
-        $grand_total->get_items();
181
-        $grand_total->tax_descendants();
182
-        return EE_Cart::instance($grand_total, $session);
183
-    }
184
-
185
-
186
-
187
-    /**
188
-     * Creates the total line item, and ensures it has its 'tickets' and 'taxes' sub-items
189
-     *
190
-     * @return EE_Line_Item
191
-     * @throws \EE_Error
192
-     */
193
-    private function _create_grand_total()
194
-    {
195
-        $this->_grand_total = EEH_Line_Item::create_total_line_item();
196
-        return $this->_grand_total;
197
-    }
198
-
199
-
200
-
201
-    /**
202
-     * Gets all the line items of object type Ticket
203
-     *
204
-     * @access public
205
-     * @return \EE_Line_Item[]
206
-     */
207
-    public function get_tickets()
208
-    {
209
-        if ($this->_grand_total === null ) {
210
-            return array();
211
-        }
212
-        return EEH_Line_Item::get_ticket_line_items($this->_grand_total);
213
-    }
214
-
215
-
216
-
217
-    /**
218
-     * returns the total quantity of tickets in the cart
219
-     *
220
-     * @access public
221
-     * @return int
222
-     * @throws \EE_Error
223
-     */
224
-    public function all_ticket_quantity_count()
225
-    {
226
-        $tickets = $this->get_tickets();
227
-        if (empty($tickets)) {
228
-            return 0;
229
-        }
230
-        $count = 0;
231
-        foreach ($tickets as $ticket) {
232
-            $count += $ticket->get('LIN_quantity');
233
-        }
234
-        return $count;
235
-    }
236
-
237
-
238
-
239
-    /**
240
-     * Gets all the tax line items
241
-     *
242
-     * @return \EE_Line_Item[]
243
-     * @throws \EE_Error
244
-     */
245
-    public function get_taxes()
246
-    {
247
-        return EEH_Line_Item::get_taxes_subtotal($this->_grand_total)->children();
248
-    }
249
-
250
-
251
-
252
-    /**
253
-     * Gets the total line item (which is a parent of all other line items) on this cart
254
-     *
255
-     * @return EE_Line_Item
256
-     * @throws \EE_Error
257
-     */
258
-    public function get_grand_total()
259
-    {
260
-        return $this->_grand_total instanceof EE_Line_Item ? $this->_grand_total : $this->_create_grand_total();
261
-    }
262
-
263
-
264
-
265
-    /**
266
-     * @process items for adding to cart
267
-     * @access  public
268
-     * @param EE_Ticket $ticket
269
-     * @param int       $qty
270
-     * @return TRUE on success, FALSE on fail
271
-     * @throws \EE_Error
272
-     */
273
-    public function add_ticket_to_cart(EE_Ticket $ticket, $qty = 1)
274
-    {
275
-        EEH_Line_Item::add_ticket_purchase($this->get_grand_total(), $ticket, $qty);
276
-        return $this->save_cart() ? true : false;
277
-    }
278
-
279
-
280
-
281
-    /**
282
-     * get_cart_total_before_tax
283
-     *
284
-     * @access public
285
-     * @return float
286
-     * @throws \EE_Error
287
-     */
288
-    public function get_cart_total_before_tax()
289
-    {
290
-        return $this->get_grand_total()->recalculate_pre_tax_total();
291
-    }
292
-
293
-
294
-
295
-    /**
296
-     * gets the total amount of tax paid for items in this cart
297
-     *
298
-     * @access public
299
-     * @return float
300
-     * @throws \EE_Error
301
-     */
302
-    public function get_applied_taxes()
303
-    {
304
-        return EEH_Line_Item::ensure_taxes_applied($this->_grand_total);
305
-    }
306
-
307
-
308
-
309
-    /**
310
-     * Gets the total amount to be paid for the items in the cart, including taxes and other modifiers
311
-     *
312
-     * @access public
313
-     * @return float
314
-     * @throws \EE_Error
315
-     */
316
-    public function get_cart_grand_total()
317
-    {
318
-        EEH_Line_Item::ensure_taxes_applied($this->_grand_total);
319
-        return $this->get_grand_total()->total();
320
-    }
321
-
322
-
323
-
324
-    /**
325
-     * Gets the total amount to be paid for the items in the cart, including taxes and other modifiers
326
-     *
327
-     * @access public
328
-     * @return float
329
-     * @throws \EE_Error
330
-     */
331
-    public function recalculate_all_cart_totals()
332
-    {
333
-        $pre_tax_total = $this->get_cart_total_before_tax();
334
-        $taxes_total = EEH_Line_Item::ensure_taxes_applied($this->_grand_total);
335
-        $this->_grand_total->set_total($pre_tax_total + $taxes_total);
336
-        $this->_grand_total->save_this_and_descendants_to_txn();
337
-        return $this->get_grand_total()->total();
338
-    }
339
-
340
-
341
-
342
-    /**
343
-     * deletes an item from the cart
344
-     *
345
-     * @access public
346
-     * @param array|bool|string $line_item_codes
347
-     * @return int on success, FALSE on fail
348
-     * @throws \EE_Error
349
-     */
350
-    public function delete_items($line_item_codes = false)
351
-    {
352
-        do_action('AHEE_log', __FILE__, __FUNCTION__, '');
353
-        return EEH_Line_Item::delete_items($this->get_grand_total(), $line_item_codes);
354
-    }
355
-
356
-
357
-
358
-    /**
359
-     * @remove ALL items from cart and zero ALL totals
360
-     * @access public
361
-     * @return bool
362
-     * @throws \EE_Error
363
-     */
364
-    public function empty_cart()
365
-    {
366
-        do_action('AHEE_log', __FILE__, __FUNCTION__, '');
367
-        $this->_grand_total = $this->_create_grand_total();
368
-        return $this->save_cart(true);
369
-    }
370
-
371
-
372
-
373
-    /**
374
-     * @remove ALL items from cart and delete total as well
375
-     * @access public
376
-     * @return bool
377
-     * @throws \EE_Error
378
-     */
379
-    public function delete_cart()
380
-    {
381
-        $deleted = EEH_Line_Item::delete_all_child_items($this->_grand_total);
382
-        if ($deleted) {
383
-            $deleted += $this->_grand_total->delete();
384
-            $this->_grand_total = null;
385
-        }
386
-        return $deleted;
387
-    }
388
-
389
-
390
-
391
-    /**
392
-     * @save   cart to session
393
-     * @access public
394
-     * @param bool $apply_taxes
395
-     * @return TRUE on success, FALSE on fail
396
-     * @throws \EE_Error
397
-     */
398
-    public function save_cart($apply_taxes = true)
399
-    {
400
-        if ($apply_taxes && $this->_grand_total instanceof EE_Line_Item) {
401
-            EEH_Line_Item::ensure_taxes_applied($this->_grand_total);
402
-            //make sure we don't cache the transaction because it can get stale
403
-            if ($this->_grand_total->get_one_from_cache('Transaction') instanceof EE_Transaction
404
-                && $this->_grand_total->get_one_from_cache('Transaction')->ID()
405
-            ) {
406
-                $this->_grand_total->clear_cache('Transaction', null, true);
407
-            }
408
-        }
409
-        if ($this->session() instanceof EE_Session) {
410
-            return $this->session()->set_cart($this);
411
-        } else {
412
-            return false;
413
-        }
414
-    }
415
-
416
-
417
-
418
-    public function __wakeup()
419
-    {
420
-        if ( ! $this->_grand_total instanceof EE_Line_Item && absint($this->_grand_total) !== 0) {
421
-            // $this->_grand_total is actually just an ID, so use it to get the object from the db
422
-            $this->_grand_total = EEM_Line_Item::instance()->get_one_by_ID($this->_grand_total);
423
-        }
424
-    }
425
-
426
-
427
-
428
-    /**
429
-     * @return array
430
-     */
431
-    public function __sleep()
432
-    {
433
-        if ($this->_grand_total instanceof EE_Line_Item && $this->_grand_total->ID()) {
434
-            $this->_grand_total = $this->_grand_total->ID();
435
-        }
436
-        return array('_grand_total');
437
-    }
26
+	/**
27
+	 * instance of the EE_Cart object
28
+	 *
29
+	 * @access    private
30
+	 * @var EE_Cart $_instance
31
+	 */
32
+	private static $_instance;
33
+
34
+	/**
35
+	 * instance of the EE_Session object
36
+	 *
37
+	 * @access    protected
38
+	 * @var EE_Session $_session
39
+	 */
40
+	protected $_session;
41
+
42
+	/**
43
+	 * The total Line item which comprises all the children line-item subtotals,
44
+	 * which in turn each have their line items.
45
+	 * Typically, the line item structure will look like:
46
+	 * grand total
47
+	 * -tickets-sub-total
48
+	 * --ticket1
49
+	 * --ticket2
50
+	 * --...
51
+	 * -taxes-sub-total
52
+	 * --tax1
53
+	 * --tax2
54
+	 *
55
+	 * @var EE_Line_Item
56
+	 */
57
+	private $_grand_total;
58
+
59
+
60
+
61
+	/**
62
+	 * @singleton method used to instantiate class object
63
+	 * @access    public
64
+	 * @param EE_Line_Item $grand_total
65
+	 * @param EE_Session   $session
66
+	 * @return \EE_Cart
67
+	 * @throws \EE_Error
68
+	 */
69
+	public static function instance(EE_Line_Item $grand_total = null, EE_Session $session = null)
70
+	{
71
+		if ( ! empty($grand_total)) {
72
+			self::$_instance = new self($grand_total, $session);
73
+		}
74
+		// or maybe retrieve an existing one ?
75
+		if ( ! self::$_instance instanceof EE_Cart) {
76
+			// try getting the cart out of the session
77
+			$saved_cart = $session instanceof EE_Session ? $session->cart() : null;
78
+			self::$_instance = $saved_cart instanceof EE_Cart ? $saved_cart : new self($grand_total, $session);
79
+			unset($saved_cart);
80
+		}
81
+		// verify that cart is ok and grand total line item exists
82
+		if ( ! self::$_instance instanceof EE_Cart || ! self::$_instance->_grand_total instanceof EE_Line_Item) {
83
+			self::$_instance = new self($grand_total, $session);
84
+		}
85
+		self::$_instance->get_grand_total();
86
+		// once everything is all said and done, save the cart to the EE_Session
87
+		add_action('shutdown', array(self::$_instance, 'save_cart'), 90);
88
+		return self::$_instance;
89
+	}
90
+
91
+
92
+
93
+	/**
94
+	 * private constructor to prevent direct creation
95
+	 *
96
+	 * @Constructor
97
+	 * @access private
98
+	 * @param EE_Line_Item $grand_total
99
+	 * @param EE_Session   $session
100
+	 */
101
+	private function __construct(EE_Line_Item $grand_total = null, EE_Session $session = null)
102
+	{
103
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
104
+		$this->set_session($session);
105
+		if ($grand_total instanceof EE_Line_Item) {
106
+			$this->set_grand_total_line_item($grand_total);
107
+		}
108
+	}
109
+
110
+
111
+
112
+	/**
113
+	 * Resets the cart completely (whereas empty_cart
114
+	 *
115
+	 * @param EE_Line_Item $grand_total
116
+	 * @param EE_Session   $session
117
+	 * @return EE_Cart
118
+	 * @throws \EE_Error
119
+	 */
120
+	public static function reset(EE_Line_Item $grand_total = null, EE_Session $session = null)
121
+	{
122
+		remove_action('shutdown', array(self::$_instance, 'save_cart'), 90);
123
+		if ($session instanceof EE_Session) {
124
+			$session->reset_cart();
125
+		}
126
+		self::$_instance = null;
127
+		return self::instance($grand_total, $session);
128
+	}
129
+
130
+
131
+
132
+	/**
133
+	 * @return \EE_Session
134
+	 */
135
+	public function session()
136
+	{
137
+		if ( ! $this->_session instanceof EE_Session) {
138
+			$this->set_session();
139
+		}
140
+		return $this->_session;
141
+	}
142
+
143
+
144
+
145
+	/**
146
+	 * @param EE_Session $session
147
+	 */
148
+	public function set_session(EE_Session $session = null)
149
+	{
150
+		$this->_session = $session instanceof EE_Session ? $session : EE_Registry::instance()->load_core('Session');
151
+	}
152
+
153
+
154
+
155
+	/**
156
+	 * Sets the cart to match the line item. Especially handy for loading an old cart where you
157
+	 *  know the grand total line item on it
158
+	 *
159
+	 * @param EE_Line_Item $line_item
160
+	 */
161
+	public function set_grand_total_line_item(EE_Line_Item $line_item)
162
+	{
163
+		$this->_grand_total = $line_item;
164
+	}
165
+
166
+
167
+
168
+	/**
169
+	 * get_cart_from_reg_url_link
170
+	 *
171
+	 * @access public
172
+	 * @param EE_Transaction $transaction
173
+	 * @param EE_Session     $session
174
+	 * @return \EE_Cart
175
+	 * @throws \EE_Error
176
+	 */
177
+	public static function get_cart_from_txn(EE_Transaction $transaction, EE_Session $session = null)
178
+	{
179
+		$grand_total = $transaction->total_line_item();
180
+		$grand_total->get_items();
181
+		$grand_total->tax_descendants();
182
+		return EE_Cart::instance($grand_total, $session);
183
+	}
184
+
185
+
186
+
187
+	/**
188
+	 * Creates the total line item, and ensures it has its 'tickets' and 'taxes' sub-items
189
+	 *
190
+	 * @return EE_Line_Item
191
+	 * @throws \EE_Error
192
+	 */
193
+	private function _create_grand_total()
194
+	{
195
+		$this->_grand_total = EEH_Line_Item::create_total_line_item();
196
+		return $this->_grand_total;
197
+	}
198
+
199
+
200
+
201
+	/**
202
+	 * Gets all the line items of object type Ticket
203
+	 *
204
+	 * @access public
205
+	 * @return \EE_Line_Item[]
206
+	 */
207
+	public function get_tickets()
208
+	{
209
+		if ($this->_grand_total === null ) {
210
+			return array();
211
+		}
212
+		return EEH_Line_Item::get_ticket_line_items($this->_grand_total);
213
+	}
214
+
215
+
216
+
217
+	/**
218
+	 * returns the total quantity of tickets in the cart
219
+	 *
220
+	 * @access public
221
+	 * @return int
222
+	 * @throws \EE_Error
223
+	 */
224
+	public function all_ticket_quantity_count()
225
+	{
226
+		$tickets = $this->get_tickets();
227
+		if (empty($tickets)) {
228
+			return 0;
229
+		}
230
+		$count = 0;
231
+		foreach ($tickets as $ticket) {
232
+			$count += $ticket->get('LIN_quantity');
233
+		}
234
+		return $count;
235
+	}
236
+
237
+
238
+
239
+	/**
240
+	 * Gets all the tax line items
241
+	 *
242
+	 * @return \EE_Line_Item[]
243
+	 * @throws \EE_Error
244
+	 */
245
+	public function get_taxes()
246
+	{
247
+		return EEH_Line_Item::get_taxes_subtotal($this->_grand_total)->children();
248
+	}
249
+
250
+
251
+
252
+	/**
253
+	 * Gets the total line item (which is a parent of all other line items) on this cart
254
+	 *
255
+	 * @return EE_Line_Item
256
+	 * @throws \EE_Error
257
+	 */
258
+	public function get_grand_total()
259
+	{
260
+		return $this->_grand_total instanceof EE_Line_Item ? $this->_grand_total : $this->_create_grand_total();
261
+	}
262
+
263
+
264
+
265
+	/**
266
+	 * @process items for adding to cart
267
+	 * @access  public
268
+	 * @param EE_Ticket $ticket
269
+	 * @param int       $qty
270
+	 * @return TRUE on success, FALSE on fail
271
+	 * @throws \EE_Error
272
+	 */
273
+	public function add_ticket_to_cart(EE_Ticket $ticket, $qty = 1)
274
+	{
275
+		EEH_Line_Item::add_ticket_purchase($this->get_grand_total(), $ticket, $qty);
276
+		return $this->save_cart() ? true : false;
277
+	}
278
+
279
+
280
+
281
+	/**
282
+	 * get_cart_total_before_tax
283
+	 *
284
+	 * @access public
285
+	 * @return float
286
+	 * @throws \EE_Error
287
+	 */
288
+	public function get_cart_total_before_tax()
289
+	{
290
+		return $this->get_grand_total()->recalculate_pre_tax_total();
291
+	}
292
+
293
+
294
+
295
+	/**
296
+	 * gets the total amount of tax paid for items in this cart
297
+	 *
298
+	 * @access public
299
+	 * @return float
300
+	 * @throws \EE_Error
301
+	 */
302
+	public function get_applied_taxes()
303
+	{
304
+		return EEH_Line_Item::ensure_taxes_applied($this->_grand_total);
305
+	}
306
+
307
+
308
+
309
+	/**
310
+	 * Gets the total amount to be paid for the items in the cart, including taxes and other modifiers
311
+	 *
312
+	 * @access public
313
+	 * @return float
314
+	 * @throws \EE_Error
315
+	 */
316
+	public function get_cart_grand_total()
317
+	{
318
+		EEH_Line_Item::ensure_taxes_applied($this->_grand_total);
319
+		return $this->get_grand_total()->total();
320
+	}
321
+
322
+
323
+
324
+	/**
325
+	 * Gets the total amount to be paid for the items in the cart, including taxes and other modifiers
326
+	 *
327
+	 * @access public
328
+	 * @return float
329
+	 * @throws \EE_Error
330
+	 */
331
+	public function recalculate_all_cart_totals()
332
+	{
333
+		$pre_tax_total = $this->get_cart_total_before_tax();
334
+		$taxes_total = EEH_Line_Item::ensure_taxes_applied($this->_grand_total);
335
+		$this->_grand_total->set_total($pre_tax_total + $taxes_total);
336
+		$this->_grand_total->save_this_and_descendants_to_txn();
337
+		return $this->get_grand_total()->total();
338
+	}
339
+
340
+
341
+
342
+	/**
343
+	 * deletes an item from the cart
344
+	 *
345
+	 * @access public
346
+	 * @param array|bool|string $line_item_codes
347
+	 * @return int on success, FALSE on fail
348
+	 * @throws \EE_Error
349
+	 */
350
+	public function delete_items($line_item_codes = false)
351
+	{
352
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
353
+		return EEH_Line_Item::delete_items($this->get_grand_total(), $line_item_codes);
354
+	}
355
+
356
+
357
+
358
+	/**
359
+	 * @remove ALL items from cart and zero ALL totals
360
+	 * @access public
361
+	 * @return bool
362
+	 * @throws \EE_Error
363
+	 */
364
+	public function empty_cart()
365
+	{
366
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
367
+		$this->_grand_total = $this->_create_grand_total();
368
+		return $this->save_cart(true);
369
+	}
370
+
371
+
372
+
373
+	/**
374
+	 * @remove ALL items from cart and delete total as well
375
+	 * @access public
376
+	 * @return bool
377
+	 * @throws \EE_Error
378
+	 */
379
+	public function delete_cart()
380
+	{
381
+		$deleted = EEH_Line_Item::delete_all_child_items($this->_grand_total);
382
+		if ($deleted) {
383
+			$deleted += $this->_grand_total->delete();
384
+			$this->_grand_total = null;
385
+		}
386
+		return $deleted;
387
+	}
388
+
389
+
390
+
391
+	/**
392
+	 * @save   cart to session
393
+	 * @access public
394
+	 * @param bool $apply_taxes
395
+	 * @return TRUE on success, FALSE on fail
396
+	 * @throws \EE_Error
397
+	 */
398
+	public function save_cart($apply_taxes = true)
399
+	{
400
+		if ($apply_taxes && $this->_grand_total instanceof EE_Line_Item) {
401
+			EEH_Line_Item::ensure_taxes_applied($this->_grand_total);
402
+			//make sure we don't cache the transaction because it can get stale
403
+			if ($this->_grand_total->get_one_from_cache('Transaction') instanceof EE_Transaction
404
+				&& $this->_grand_total->get_one_from_cache('Transaction')->ID()
405
+			) {
406
+				$this->_grand_total->clear_cache('Transaction', null, true);
407
+			}
408
+		}
409
+		if ($this->session() instanceof EE_Session) {
410
+			return $this->session()->set_cart($this);
411
+		} else {
412
+			return false;
413
+		}
414
+	}
415
+
416
+
417
+
418
+	public function __wakeup()
419
+	{
420
+		if ( ! $this->_grand_total instanceof EE_Line_Item && absint($this->_grand_total) !== 0) {
421
+			// $this->_grand_total is actually just an ID, so use it to get the object from the db
422
+			$this->_grand_total = EEM_Line_Item::instance()->get_one_by_ID($this->_grand_total);
423
+		}
424
+	}
425
+
426
+
427
+
428
+	/**
429
+	 * @return array
430
+	 */
431
+	public function __sleep()
432
+	{
433
+		if ($this->_grand_total instanceof EE_Line_Item && $this->_grand_total->ID()) {
434
+			$this->_grand_total = $this->_grand_total->ID();
435
+		}
436
+		return array('_grand_total');
437
+	}
438 438
 
439 439
 
440 440
 }
Please login to merge, or discard this patch.
core/EE_Payment_Processor.core.php 1 patch
Indentation   +745 added lines, -745 removed lines patch added patch discarded remove patch
@@ -1,7 +1,7 @@  discard block
 block discarded – undo
1 1
 <?php use EventEspresso\core\interfaces\ResettableInterface;
2 2
 
3 3
 if ( ! defined('EVENT_ESPRESSO_VERSION')) {
4
-    exit('No direct script access allowed');
4
+	exit('No direct script access allowed');
5 5
 }
6 6
 EE_Registry::instance()->load_class('Processor_Base');
7 7
 
@@ -18,748 +18,748 @@  discard block
 block discarded – undo
18 18
 class EE_Payment_Processor extends EE_Processor_Base implements ResettableInterface
19 19
 {
20 20
 
21
-    /**
22
-     * @var EE_Payment_Processor $_instance
23
-     * @access    private
24
-     */
25
-    private static $_instance;
26
-
27
-
28
-
29
-    /**
30
-     * @singleton method used to instantiate class object
31
-     * @access    public
32
-     * @return EE_Payment_Processor instance
33
-     */
34
-    public static function instance()
35
-    {
36
-        // check if class object is instantiated
37
-        if ( ! self::$_instance instanceof EE_Payment_Processor) {
38
-            self::$_instance = new self();
39
-        }
40
-        return self::$_instance;
41
-    }
42
-
43
-
44
-
45
-    /**
46
-     * @return EE_Payment_Processor
47
-     */
48
-    public static function reset()
49
-    {
50
-        self::$_instance = null;
51
-        return self::instance();
52
-    }
53
-
54
-
55
-
56
-    /**
57
-     *private constructor to prevent direct creation
58
-     *
59
-     * @Constructor
60
-     * @access private
61
-     */
62
-    private function __construct()
63
-    {
64
-        do_action('AHEE__EE_Payment_Processor__construct');
65
-        add_action('http_api_curl', array($this, '_curl_requests_to_paypal_use_tls'), 10, 3);
66
-    }
67
-
68
-
69
-
70
-    /**
71
-     * Using the selected gateway, processes the payment for that transaction, and updates the transaction
72
-     * appropriately. Saves the payment that is generated
73
-     *
74
-     * @param EE_Payment_Method    $payment_method
75
-     * @param EE_Transaction       $transaction
76
-     * @param float                $amount       if only part of the transaction is to be paid for, how much.
77
-     *                                           Leave null if payment is for the full amount owing
78
-     * @param EE_Billing_Info_Form $billing_form (or probably null, if it's an offline or offsite payment method).
79
-     *                                           Receive_form_submission() should have
80
-     *                                           already been called on the billing form
81
-     *                                           (ie, its inputs should have their normalized values set).
82
-     * @param string               $return_url   string used mostly by offsite gateways to specify
83
-     *                                           where to go AFTER the offsite gateway
84
-     * @param string               $method       like 'CART', indicates who the client who called this was
85
-     * @param bool                 $by_admin     TRUE if payment is being attempted from the admin
86
-     * @param boolean              $update_txn   whether or not to call
87
-     *                                           EE_Transaction_Processor::update_transaction_and_registrations_after_checkout_or_payment()
88
-     * @param string               $cancel_url   URL to return to if off-site payments are cancelled
89
-     * @return \EE_Payment
90
-     * @throws \EE_Error
91
-     */
92
-    public function process_payment(
93
-        EE_Payment_Method $payment_method,
94
-        EE_Transaction $transaction,
95
-        $amount = null,
96
-        $billing_form = null,
97
-        $return_url = null,
98
-        $method = 'CART',
99
-        $by_admin = false,
100
-        $update_txn = true,
101
-        $cancel_url = ''
102
-    ) {
103
-        if ((float)$amount < 0) {
104
-            throw new EE_Error(
105
-                sprintf(
106
-                    __(
107
-                        'Attempting to make a payment for a negative amount of %1$d for transaction %2$d. That should be a refund',
108
-                        'event_espresso'
109
-                    ),
110
-                    $amount,
111
-                    $transaction->ID()
112
-                )
113
-            );
114
-        }
115
-        // verify payment method
116
-        $payment_method = EEM_Payment_Method::instance()->ensure_is_obj($payment_method, true);
117
-        // verify transaction
118
-        EEM_Transaction::instance()->ensure_is_obj($transaction);
119
-        $transaction->set_payment_method_ID($payment_method->ID());
120
-        // verify payment method type
121
-        if ($payment_method->type_obj() instanceof EE_PMT_Base) {
122
-            $payment = $payment_method->type_obj()->process_payment(
123
-                $transaction,
124
-                min($amount, $transaction->remaining()),//make sure we don't overcharge
125
-                $billing_form,
126
-                $return_url,
127
-                add_query_arg(array('ee_cancel_payment' => true), $cancel_url),
128
-                $method,
129
-                $by_admin
130
-            );
131
-            // check if payment method uses an off-site gateway
132
-            if ($payment_method->type_obj()->payment_occurs() !== EE_PMT_Base::offsite) {
133
-                // don't process payments for off-site gateways yet because no payment has occurred yet
134
-                $this->update_txn_based_on_payment($transaction, $payment, $update_txn);
135
-            }
136
-            return $payment;
137
-        } else {
138
-            EE_Error::add_error(
139
-                sprintf(
140
-                    __('A valid payment method could not be determined due to a technical issue.%sPlease try again or contact %s for assistance.', 'event_espresso'),
141
-                    '<br/>',
142
-                    EE_Registry::instance()->CFG->organization->get_pretty('email')
143
-                ), __FILE__, __FUNCTION__, __LINE__
144
-            );
145
-            return null;
146
-        }
147
-    }
148
-
149
-
150
-
151
-    /**
152
-     * @param EE_Transaction|int $transaction
153
-     * @param EE_Payment_Method  $payment_method
154
-     * @throws EE_Error
155
-     * @return string
156
-     */
157
-    public function get_ipn_url_for_payment_method($transaction, $payment_method)
158
-    {
159
-        /** @type \EE_Transaction $transaction */
160
-        $transaction = EEM_Transaction::instance()->ensure_is_obj($transaction);
161
-        $primary_reg = $transaction->primary_registration();
162
-        if ( ! $primary_reg instanceof EE_Registration) {
163
-            throw new EE_Error(
164
-                sprintf(
165
-                    __(
166
-                        "Cannot get IPN URL for transaction with ID %d because it has no primary registration",
167
-                        "event_espresso"
168
-                    ),
169
-                    $transaction->ID()
170
-                )
171
-            );
172
-        }
173
-        $payment_method = EEM_Payment_Method::instance()->ensure_is_obj($payment_method, true);
174
-        $url = add_query_arg(
175
-            array(
176
-                'e_reg_url_link'    => $primary_reg->reg_url_link(),
177
-                'ee_payment_method' => $payment_method->slug(),
178
-            ),
179
-            EE_Registry::instance()->CFG->core->txn_page_url()
180
-        );
181
-        return $url;
182
-    }
183
-
184
-
185
-
186
-    /**
187
-     * Process the IPN. Firstly, we'll hope we put the standard args into the IPN URL so
188
-     * we can easily find what registration the IPN is for and what payment method.
189
-     * However, if not, we'll give all payment methods a chance to claim it and process it.
190
-     * If a payment is found for the IPN info, it is saved.
191
-     *
192
-     * @param array              $_req_data            eg $_REQUEST
193
-     * @param EE_Transaction|int $transaction          optional (or a transactions id)
194
-     * @param EE_Payment_Method  $payment_method       (or a slug or id of one)
195
-     * @param boolean            $update_txn           whether or not to call
196
-     *                                                 EE_Transaction_Processor::update_transaction_and_registrations_after_checkout_or_payment()
197
-     * @param bool               $separate_IPN_request whether the IPN uses a separate request ( true like PayPal )
198
-     *                                                 or is processed manually ( false like Mijireh )
199
-     * @throws EE_Error
200
-     * @throws Exception
201
-     * @return EE_Payment
202
-     */
203
-    public function process_ipn(
204
-        $_req_data,
205
-        $transaction = null,
206
-        $payment_method = null,
207
-        $update_txn = true,
208
-        $separate_IPN_request = true
209
-    ) {
210
-        EE_Registry::instance()->load_model('Change_Log');
211
-        $_req_data = $this->_remove_unusable_characters_from_array((array)$_req_data);
212
-        EE_Processor_Base::set_IPN($separate_IPN_request);
213
-        $obj_for_log = null;
214
-        if ($transaction instanceof EE_Transaction) {
215
-            $obj_for_log = $transaction;
216
-            if ($payment_method instanceof EE_Payment_Method) {
217
-                $obj_for_log = EEM_Payment::instance()->get_one(
218
-                    array(
219
-                        array('TXN_ID' => $transaction->ID(), 'PMD_ID' => $payment_method->ID()),
220
-                        'order_by' => array('PAY_timestamp' => 'desc'),
221
-                    )
222
-                );
223
-            }
224
-        } else if ($payment_method instanceof EE_Payment) {
225
-            $obj_for_log = $payment_method;
226
-        }
227
-        $log = EEM_Change_Log::instance()->log(
228
-            EEM_Change_Log::type_gateway,
229
-            array('IPN data received' => $_req_data),
230
-            $obj_for_log
231
-        );
232
-        try {
233
-            /**
234
-             * @var EE_Payment $payment
235
-             */
236
-            $payment = null;
237
-            if ($transaction && $payment_method) {
238
-                /** @type EE_Transaction $transaction */
239
-                $transaction = EEM_Transaction::instance()->ensure_is_obj($transaction);
240
-                /** @type EE_Payment_Method $payment_method */
241
-                $payment_method = EEM_Payment_Method::instance()->ensure_is_obj($payment_method);
242
-                if ($payment_method->type_obj() instanceof EE_PMT_Base) {
243
-                    try {
244
-                        $payment = $payment_method->type_obj()->handle_ipn($_req_data, $transaction);
245
-                        $log->set_object($payment);
246
-                    } catch (EventEspresso\core\exceptions\IpnException $e) {
247
-                        EEM_Change_Log::instance()->log(
248
-                            EEM_Change_Log::type_gateway,
249
-                            array(
250
-                                'message'     => 'IPN Exception: ' . $e->getMessage(),
251
-                                'current_url' => EEH_URL::current_url(),
252
-                                'payment'     => $e->getPaymentProperties(),
253
-                                'IPN_data'    => $e->getIpnData(),
254
-                            ),
255
-                            $obj_for_log
256
-                        );
257
-                        return $e->getPayment();
258
-                    }
259
-                } else {
260
-                    // not a payment
261
-                    EE_Error::add_error(
262
-                        sprintf(
263
-                            __('A valid payment method could not be determined due to a technical issue.%sPlease refresh your browser and try again or contact %s for assistance.', 'event_espresso'),
264
-                            '<br/>',
265
-                            EE_Registry::instance()->CFG->organization->get_pretty('email')
266
-                        ),
267
-                        __FILE__, __FUNCTION__, __LINE__
268
-                    );
269
-                }
270
-            } else {
271
-                //that's actually pretty ok. The IPN just wasn't able
272
-                //to identify which transaction or payment method this was for
273
-                // give all active payment methods a chance to claim it
274
-                $active_payment_methods = EEM_Payment_Method::instance()->get_all_active();
275
-                foreach ($active_payment_methods as $active_payment_method) {
276
-                    try {
277
-                        $payment = $active_payment_method->type_obj()->handle_unclaimed_ipn($_req_data);
278
-                        $payment_method = $active_payment_method;
279
-                        EEM_Change_Log::instance()->log(
280
-                            EEM_Change_Log::type_gateway, array('IPN data' => $_req_data), $payment
281
-                        );
282
-                        break;
283
-                    } catch (EventEspresso\core\exceptions\IpnException $e) {
284
-                        EEM_Change_Log::instance()->log(
285
-                            EEM_Change_Log::type_gateway,
286
-                            array(
287
-                                'message'     => 'IPN Exception: ' . $e->getMessage(),
288
-                                'current_url' => EEH_URL::current_url(),
289
-                                'payment'     => $e->getPaymentProperties(),
290
-                                'IPN_data'    => $e->getIpnData(),
291
-                            ),
292
-                            $obj_for_log
293
-                        );
294
-                        return $e->getPayment();
295
-                    } catch (EE_Error $e) {
296
-                        //that's fine- it apparently couldn't handle the IPN
297
-                    }
298
-                }
299
-            }
300
-            // 			EEM_Payment_Log::instance()->log("got to 7",$transaction,$payment_method);
301
-            if ($payment instanceof EE_Payment) {
302
-                $payment->save();
303
-                //  update the TXN
304
-                $this->update_txn_based_on_payment($transaction, $payment, $update_txn, $separate_IPN_request);
305
-            } else {
306
-                //we couldn't find the payment for this IPN... let's try and log at least SOMETHING
307
-                if ($payment_method) {
308
-                    EEM_Change_Log::instance()->log(EEM_Change_Log::type_gateway, array('IPN data' => $_req_data), $payment_method);
309
-                } elseif ($transaction) {
310
-                    EEM_Change_Log::instance()->log(EEM_Change_Log::type_gateway, array('IPN data' => $_req_data), $transaction);
311
-                }
312
-            }
313
-            return $payment;
314
-        } catch (EE_Error $e) {
315
-            do_action(
316
-                'AHEE__log', __FILE__, __FUNCTION__, sprintf(
317
-                    __('Error occurred while receiving IPN. Transaction: %1$s, req data: %2$s. The error was "%3$s"', 'event_espresso'),
318
-                    print_r($transaction, true),
319
-                    print_r($_req_data, true),
320
-                    $e->getMessage()
321
-                )
322
-            );
323
-            throw $e;
324
-        }
325
-    }
326
-
327
-
328
-
329
-    /**
330
-     * Removes any non-printable illegal characters from the input,
331
-     * which might cause a raucous when trying to insert into the database
332
-     *
333
-     * @param  array $request_data
334
-     * @return array
335
-     */
336
-    protected function _remove_unusable_characters_from_array(array $request_data)
337
-    {
338
-        $return_data = array();
339
-        foreach ($request_data as $key => $value) {
340
-            $return_data[$this->_remove_unusable_characters($key)] = $this->_remove_unusable_characters($value);
341
-        }
342
-        return $return_data;
343
-    }
344
-
345
-
346
-
347
-    /**
348
-     * Removes any non-printable illegal characters from the input,
349
-     * which might cause a raucous when trying to insert into the database
350
-     *
351
-     * @param string $request_data
352
-     * @return string
353
-     */
354
-    protected function _remove_unusable_characters($request_data)
355
-    {
356
-        return preg_replace('/[^[:print:]]/', '', $request_data);
357
-    }
358
-
359
-
360
-
361
-    /**
362
-     * Should be called just before displaying the payment attempt results to the user,
363
-     * when the payment attempt has finished. Some payment methods may have special
364
-     * logic to perform here. For example, if process_payment() happens on a special request
365
-     * and then the user is redirected to a page that displays the payment's status, this
366
-     * should be called while loading the page that displays the payment's status. If the user is
367
-     * sent to an offsite payment provider, this should be called upon returning from that offsite payment
368
-     * provider.
369
-     *
370
-     * @param EE_Transaction|int $transaction
371
-     * @param bool               $update_txn whether or not to call
372
-     *                                       EE_Transaction_Processor::update_transaction_and_registrations_after_checkout_or_payment()
373
-     * @throws \EE_Error
374
-     * @return EE_Payment
375
-     * @deprecated 4.6.24 method is no longer used. Instead it is up to client code, like SPCO,
376
-     *                                       to call handle_ipn() for offsite gateways that don't receive separate IPNs
377
-     */
378
-    public function finalize_payment_for($transaction, $update_txn = true)
379
-    {
380
-        /** @var $transaction EE_Transaction */
381
-        $transaction = EEM_Transaction::instance()->ensure_is_obj($transaction);
382
-        $last_payment_method = $transaction->payment_method();
383
-        if ($last_payment_method instanceof EE_Payment_Method) {
384
-            $payment = $last_payment_method->type_obj()->finalize_payment_for($transaction);
385
-            $this->update_txn_based_on_payment($transaction, $payment, $update_txn);
386
-            return $payment;
387
-        } else {
388
-            return null;
389
-        }
390
-    }
391
-
392
-
393
-
394
-    /**
395
-     * Processes a direct refund request, saves the payment, and updates the transaction appropriately.
396
-     *
397
-     * @param EE_Payment_Method $payment_method
398
-     * @param EE_Payment        $payment_to_refund
399
-     * @param array             $refund_info
400
-     * @return EE_Payment
401
-     * @throws \EE_Error
402
-     */
403
-    public function process_refund(
404
-        EE_Payment_Method $payment_method,
405
-        EE_Payment $payment_to_refund,
406
-        $refund_info = array()
407
-    ) {
408
-        if ($payment_method instanceof EE_Payment_Method && $payment_method->type_obj()->supports_sending_refunds()) {
409
-            $payment_method->type_obj()->process_refund($payment_to_refund, $refund_info);
410
-            $this->update_txn_based_on_payment($payment_to_refund->transaction(), $payment_to_refund);
411
-        }
412
-        return $payment_to_refund;
413
-    }
414
-
415
-
416
-
417
-    /**
418
-     * This should be called each time there may have been an update to a
419
-     * payment on a transaction (ie, we asked for a payment to process a
420
-     * payment for a transaction, or we told a payment method about an IPN, or
421
-     * we told a payment method to
422
-     * "finalize_payment_for" (a transaction), or we told a payment method to
423
-     * process a refund. This should handle firing the correct hooks to
424
-     * indicate
425
-     * what exactly happened and updating the transaction appropriately). This
426
-     * could be integrated directly into EE_Transaction upon save, but we want
427
-     * this logic to be separate from 'normal' plain-jane saving and updating
428
-     * of transactions and payments, and to be tied to payment processing.
429
-     * Note: this method DOES NOT save the payment passed into it. It is the responsibility
430
-     * of previous code to decide whether or not to save (because the payment passed into
431
-     * this method might be a temporary, never-to-be-saved payment from an offline gateway,
432
-     * in which case we only want that payment object for some temporary usage during this request,
433
-     * but we don't want it to be saved).
434
-     *
435
-     * @param EE_Transaction|int $transaction
436
-     * @param EE_Payment         $payment
437
-     * @param boolean            $update_txn
438
-     *                        whether or not to call
439
-     *                        EE_Transaction_Processor::
440
-     *                        update_transaction_and_registrations_after_checkout_or_payment()
441
-     *                        (you can save 1 DB query if you know you're going
442
-     *                        to save it later instead)
443
-     * @param bool               $IPN
444
-     *                        if processing IPNs or other similar payment
445
-     *                        related activities that occur in alternate
446
-     *                        requests than the main one that is processing the
447
-     *                        TXN, then set this to true to check whether the
448
-     *                        TXN is locked before updating
449
-     * @throws \EE_Error
450
-     */
451
-    public function update_txn_based_on_payment($transaction, $payment, $update_txn = true, $IPN = false)
452
-    {
453
-        $do_action = 'AHEE__EE_Payment_Processor__update_txn_based_on_payment__not_successful';
454
-        /** @type EE_Transaction $transaction */
455
-        $transaction = EEM_Transaction::instance()->ensure_is_obj($transaction);
456
-        // can we freely update the TXN at this moment?
457
-        if ($IPN && $transaction->is_locked()) {
458
-            // don't update the transaction at this exact moment
459
-            // because the TXN is active in another request
460
-            EE_Cron_Tasks::schedule_update_transaction_with_payment(
461
-                time(),
462
-                $transaction->ID(),
463
-                $payment->ID()
464
-            );
465
-        } else {
466
-            // verify payment and that it has been saved
467
-            if ($payment instanceof EE_Payment && $payment->ID()) {
468
-                if (
469
-                    $payment->payment_method() instanceof EE_Payment_Method
470
-                    && $payment->payment_method()->type_obj() instanceof EE_PMT_Base
471
-                ) {
472
-                    $payment->payment_method()->type_obj()->update_txn_based_on_payment($payment);
473
-                    // update TXN registrations with payment info
474
-                    $this->process_registration_payments($transaction, $payment);
475
-                }
476
-                $do_action = $payment->just_approved()
477
-                    ? 'AHEE__EE_Payment_Processor__update_txn_based_on_payment__successful'
478
-                    : $do_action;
479
-            } else {
480
-                // send out notifications
481
-                add_filter('FHEE__EED_Messages___maybe_registration__deliver_notifications', '__return_true');
482
-                $do_action = 'AHEE__EE_Payment_Processor__update_txn_based_on_payment__no_payment_made';
483
-            }
484
-            if ($payment instanceof EE_Payment && $payment->status() !== EEM_Payment::status_id_failed) {
485
-                /** @type EE_Transaction_Payments $transaction_payments */
486
-                $transaction_payments = EE_Registry::instance()->load_class('Transaction_Payments');
487
-                // set new value for total paid
488
-                $transaction_payments->calculate_total_payments_and_update_status($transaction);
489
-                // call EE_Transaction_Processor::update_transaction_and_registrations_after_checkout_or_payment() ???
490
-                if ($update_txn) {
491
-                    $this->_post_payment_processing($transaction, $payment, $IPN);
492
-                }
493
-            }
494
-            // granular hook for others to use.
495
-            do_action($do_action, $transaction, $payment);
496
-            do_action('AHEE_log', __CLASS__, __FUNCTION__, $do_action, '$do_action');
497
-            //global hook for others to use.
498
-            do_action('AHEE__EE_Payment_Processor__update_txn_based_on_payment', $transaction, $payment);
499
-        }
500
-    }
501
-
502
-
503
-
504
-    /**
505
-     * update registrations REG_paid field after successful payment and link registrations with payment
506
-     *
507
-     * @param EE_Transaction    $transaction
508
-     * @param EE_Payment        $payment
509
-     * @param EE_Registration[] $registrations
510
-     * @throws \EE_Error
511
-     */
512
-    public function process_registration_payments(
513
-        EE_Transaction $transaction,
514
-        EE_Payment $payment,
515
-        $registrations = array()
516
-    ) {
517
-        // only process if payment was successful
518
-        if ($payment->status() !== EEM_Payment::status_id_approved) {
519
-            return;
520
-        }
521
-        //EEM_Registration::instance()->show_next_x_db_queries();
522
-        if (empty($registrations)) {
523
-            // find registrations with monies owing that can receive a payment
524
-            $registrations = $transaction->registrations(
525
-                array(
526
-                    array(
527
-                        // only these reg statuses can receive payments
528
-                        'STS_ID'           => array('IN', EEM_Registration::reg_statuses_that_allow_payment()),
529
-                        'REG_final_price'  => array('!=', 0),
530
-                        'REG_final_price*' => array('!=', 'REG_paid', true),
531
-                    ),
532
-                )
533
-            );
534
-        }
535
-        // still nothing ??!??
536
-        if (empty($registrations)) {
537
-            return;
538
-        }
539
-        // todo: break out the following logic into a separate strategy class
540
-        // todo: named something like "Sequential_Reg_Payment_Strategy"
541
-        // todo: which would apply payments using the capitalist "first come first paid" approach
542
-        // todo: then have another strategy class like "Distributed_Reg_Payment_Strategy"
543
-        // todo: which would be the socialist "everybody gets a piece of pie" approach,
544
-        // todo: which would be better for deposits, where you want a bit of the payment applied to each registration
545
-        $refund = $payment->is_a_refund();
546
-        // how much is available to apply to registrations?
547
-        $available_payment_amount = abs($payment->amount());
548
-        foreach ($registrations as $registration) {
549
-            if ($registration instanceof EE_Registration) {
550
-                // nothing left?
551
-                if ($available_payment_amount <= 0) {
552
-                    break;
553
-                }
554
-                if ($refund) {
555
-                    $available_payment_amount = $this->process_registration_refund($registration, $payment, $available_payment_amount);
556
-                } else {
557
-                    $available_payment_amount = $this->process_registration_payment($registration, $payment, $available_payment_amount);
558
-                }
559
-            }
560
-        }
561
-        if ($available_payment_amount > 0 && apply_filters('FHEE__EE_Payment_Processor__process_registration_payments__display_notifications', false)) {
562
-            EE_Error::add_attention(
563
-                sprintf(
564
-                    __('A remainder of %1$s exists after applying this payment to Registration(s) %2$s.%3$sPlease verify that the original payment amount of %4$s is correct. If so, you should edit this payment and select at least one additional registration in the "Registrations to Apply Payment to" section, so that the remainder of this payment can be applied to the additional registration(s).',
565
-                        'event_espresso'),
566
-                    EEH_Template::format_currency($available_payment_amount),
567
-                    implode(', ', array_keys($registrations)),
568
-                    '<br/>',
569
-                    EEH_Template::format_currency($payment->amount())
570
-                ),
571
-                __FILE__, __FUNCTION__, __LINE__
572
-            );
573
-        }
574
-    }
575
-
576
-
577
-
578
-    /**
579
-     * update registration REG_paid field after successful payment and link registration with payment
580
-     *
581
-     * @param EE_Registration $registration
582
-     * @param EE_Payment      $payment
583
-     * @param float           $available_payment_amount
584
-     * @return float
585
-     * @throws \EE_Error
586
-     */
587
-    public function process_registration_payment(
588
-        EE_Registration $registration,
589
-        EE_Payment $payment,
590
-        $available_payment_amount = 0.00
591
-    ) {
592
-        $owing = $registration->final_price() - $registration->paid();
593
-        if ($owing > 0) {
594
-            // don't allow payment amount to exceed the available payment amount, OR the amount owing
595
-            $payment_amount = min($available_payment_amount, $owing);
596
-            // update $available_payment_amount
597
-            $available_payment_amount -= $payment_amount;
598
-            //calculate and set new REG_paid
599
-            $registration->set_paid($registration->paid() + $payment_amount);
600
-            // now save it
601
-            $this->_apply_registration_payment($registration, $payment, $payment_amount);
602
-        }
603
-        return $available_payment_amount;
604
-    }
605
-
606
-
607
-
608
-    /**
609
-     * update registration REG_paid field after successful payment and link registration with payment
610
-     *
611
-     * @param EE_Registration $registration
612
-     * @param EE_Payment      $payment
613
-     * @param float           $payment_amount
614
-     * @return void
615
-     * @throws \EE_Error
616
-     */
617
-    protected function _apply_registration_payment(
618
-        EE_Registration $registration,
619
-        EE_Payment $payment,
620
-        $payment_amount = 0.00
621
-    ) {
622
-        // find any existing reg payment records for this registration and payment
623
-        $existing_reg_payment = EEM_Registration_Payment::instance()->get_one(
624
-            array(array('REG_ID' => $registration->ID(), 'PAY_ID' => $payment->ID()))
625
-        );
626
-        // if existing registration payment exists
627
-        if ($existing_reg_payment instanceof EE_Registration_Payment) {
628
-            // then update that record
629
-            $existing_reg_payment->set_amount($payment_amount);
630
-            $existing_reg_payment->save();
631
-        } else {
632
-            // or add new relation between registration and payment and set amount
633
-            $registration->_add_relation_to($payment, 'Payment', array('RPY_amount' => $payment_amount));
634
-            // make it stick
635
-            $registration->save();
636
-        }
637
-    }
638
-
639
-
640
-
641
-    /**
642
-     * update registration REG_paid field after refund and link registration with payment
643
-     *
644
-     * @param EE_Registration $registration
645
-     * @param EE_Payment      $payment
646
-     * @param float           $available_refund_amount - IMPORTANT !!! SEND AVAILABLE REFUND AMOUNT AS A POSITIVE NUMBER
647
-     * @return float
648
-     * @throws \EE_Error
649
-     */
650
-    public function process_registration_refund(
651
-        EE_Registration $registration,
652
-        EE_Payment $payment,
653
-        $available_refund_amount = 0.00
654
-    ) {
655
-        //EEH_Debug_Tools::printr( $payment->amount(), '$payment->amount()', __FILE__, __LINE__ );
656
-        if ($registration->paid() > 0) {
657
-            // ensure $available_refund_amount is NOT negative
658
-            $available_refund_amount = (float)abs($available_refund_amount);
659
-            // don't allow refund amount to exceed the available payment amount, OR the amount paid
660
-            $refund_amount = min($available_refund_amount, (float)$registration->paid());
661
-            // update $available_payment_amount
662
-            $available_refund_amount -= $refund_amount;
663
-            //calculate and set new REG_paid
664
-            $registration->set_paid($registration->paid() - $refund_amount);
665
-            // convert payment amount back to a negative value for storage in the db
666
-            $refund_amount = (float)abs($refund_amount) * -1;
667
-            // now save it
668
-            $this->_apply_registration_payment($registration, $payment, $refund_amount);
669
-        }
670
-        return $available_refund_amount;
671
-    }
672
-
673
-
674
-
675
-    /**
676
-     * Process payments and transaction after payment process completed.
677
-     * ultimately this will send the TXN and payment details off so that notifications can be sent out.
678
-     * if this request happens to be processing an IPN,
679
-     * then we will also set the Payment Options Reg Step to completed,
680
-     * and attempt to completely finalize the TXN if all of the other Reg Steps are completed as well.
681
-     *
682
-     * @param EE_Transaction $transaction
683
-     * @param EE_Payment     $payment
684
-     * @param bool           $IPN
685
-     * @throws \EE_Error
686
-     */
687
-    protected function _post_payment_processing(EE_Transaction $transaction, EE_Payment $payment, $IPN = false)
688
-    {
689
-        /** @type EE_Transaction_Processor $transaction_processor */
690
-        $transaction_processor = EE_Registry::instance()->load_class('Transaction_Processor');
691
-        // is the Payment Options Reg Step completed ?
692
-        $payment_options_step_completed = $transaction->reg_step_completed('payment_options');
693
-        // if the Payment Options Reg Step is completed...
694
-        $revisit = $payment_options_step_completed === true ? true : false;
695
-        // then this is kinda sorta a revisit with regards to payments at least
696
-        $transaction_processor->set_revisit($revisit);
697
-        // if this is an IPN, let's consider the Payment Options Reg Step completed if not already
698
-        if (
699
-            $IPN
700
-            && $payment_options_step_completed !== true
701
-            && ($payment->is_approved() || $payment->is_pending())
702
-        ) {
703
-            $payment_options_step_completed = $transaction->set_reg_step_completed(
704
-                'payment_options'
705
-            );
706
-        }
707
-        // maybe update status, but don't save transaction just yet
708
-        $transaction->update_status_based_on_total_paid(false);
709
-        // check if 'finalize_registration' step has been completed...
710
-        $finalized = $transaction->reg_step_completed('finalize_registration');
711
-        //  if this is an IPN and the final step has not been initiated
712
-        if ($IPN && $payment_options_step_completed && $finalized === false) {
713
-            // and if it hasn't already been set as being started...
714
-            $finalized = $transaction->set_reg_step_initiated('finalize_registration');
715
-        }
716
-        $transaction->save();
717
-        // because the above will return false if the final step was not fully completed, we need to check again...
718
-        if ($IPN && $finalized !== false) {
719
-            // and if we are all good to go, then send out notifications
720
-            add_filter('FHEE__EED_Messages___maybe_registration__deliver_notifications', '__return_true');
721
-            //ok, now process the transaction according to the payment
722
-            $transaction_processor->update_transaction_and_registrations_after_checkout_or_payment($transaction, $payment);
723
-        }
724
-        // DEBUG LOG
725
-        $payment_method = $payment->payment_method();
726
-        if ($payment_method instanceof EE_Payment_Method) {
727
-            $payment_method_type_obj = $payment_method->type_obj();
728
-            if ($payment_method_type_obj instanceof EE_PMT_Base) {
729
-                $gateway = $payment_method_type_obj->get_gateway();
730
-                if ($gateway instanceof EE_Gateway) {
731
-                    $gateway->log(
732
-                        array(
733
-                            'message'               => __('Post Payment Transaction Details', 'event_espresso'),
734
-                            'transaction'           => $transaction->model_field_array(),
735
-                            'finalized'             => $finalized,
736
-                            'IPN'                   => $IPN,
737
-                            'deliver_notifications' => has_filter(
738
-                                'FHEE__EED_Messages___maybe_registration__deliver_notifications'
739
-                            ),
740
-                        ),
741
-                        $payment
742
-                    );
743
-                }
744
-            }
745
-        }
746
-    }
747
-
748
-
749
-
750
-    /**
751
-     * Force posts to PayPal to use TLS v1.2. See:
752
-     * https://core.trac.wordpress.org/ticket/36320
753
-     * https://core.trac.wordpress.org/ticket/34924#comment:15
754
-     * https://www.paypal-knowledge.com/infocenter/index?page=content&widgetview=true&id=FAQ1914&viewlocale=en_US
755
-     * This will affect paypal standard, pro, express, and payflow.
756
-     */
757
-    public static function _curl_requests_to_paypal_use_tls($handle, $r, $url)
758
-    {
759
-        if (strstr($url, 'https://') && strstr($url, '.paypal.com')) {
760
-            //Use the value of the constant CURL_SSLVERSION_TLSv1 = 1
761
-            //instead of the constant because it might not be defined
762
-            curl_setopt($handle, CURLOPT_SSLVERSION, 1);
763
-        }
764
-    }
21
+	/**
22
+	 * @var EE_Payment_Processor $_instance
23
+	 * @access    private
24
+	 */
25
+	private static $_instance;
26
+
27
+
28
+
29
+	/**
30
+	 * @singleton method used to instantiate class object
31
+	 * @access    public
32
+	 * @return EE_Payment_Processor instance
33
+	 */
34
+	public static function instance()
35
+	{
36
+		// check if class object is instantiated
37
+		if ( ! self::$_instance instanceof EE_Payment_Processor) {
38
+			self::$_instance = new self();
39
+		}
40
+		return self::$_instance;
41
+	}
42
+
43
+
44
+
45
+	/**
46
+	 * @return EE_Payment_Processor
47
+	 */
48
+	public static function reset()
49
+	{
50
+		self::$_instance = null;
51
+		return self::instance();
52
+	}
53
+
54
+
55
+
56
+	/**
57
+	 *private constructor to prevent direct creation
58
+	 *
59
+	 * @Constructor
60
+	 * @access private
61
+	 */
62
+	private function __construct()
63
+	{
64
+		do_action('AHEE__EE_Payment_Processor__construct');
65
+		add_action('http_api_curl', array($this, '_curl_requests_to_paypal_use_tls'), 10, 3);
66
+	}
67
+
68
+
69
+
70
+	/**
71
+	 * Using the selected gateway, processes the payment for that transaction, and updates the transaction
72
+	 * appropriately. Saves the payment that is generated
73
+	 *
74
+	 * @param EE_Payment_Method    $payment_method
75
+	 * @param EE_Transaction       $transaction
76
+	 * @param float                $amount       if only part of the transaction is to be paid for, how much.
77
+	 *                                           Leave null if payment is for the full amount owing
78
+	 * @param EE_Billing_Info_Form $billing_form (or probably null, if it's an offline or offsite payment method).
79
+	 *                                           Receive_form_submission() should have
80
+	 *                                           already been called on the billing form
81
+	 *                                           (ie, its inputs should have their normalized values set).
82
+	 * @param string               $return_url   string used mostly by offsite gateways to specify
83
+	 *                                           where to go AFTER the offsite gateway
84
+	 * @param string               $method       like 'CART', indicates who the client who called this was
85
+	 * @param bool                 $by_admin     TRUE if payment is being attempted from the admin
86
+	 * @param boolean              $update_txn   whether or not to call
87
+	 *                                           EE_Transaction_Processor::update_transaction_and_registrations_after_checkout_or_payment()
88
+	 * @param string               $cancel_url   URL to return to if off-site payments are cancelled
89
+	 * @return \EE_Payment
90
+	 * @throws \EE_Error
91
+	 */
92
+	public function process_payment(
93
+		EE_Payment_Method $payment_method,
94
+		EE_Transaction $transaction,
95
+		$amount = null,
96
+		$billing_form = null,
97
+		$return_url = null,
98
+		$method = 'CART',
99
+		$by_admin = false,
100
+		$update_txn = true,
101
+		$cancel_url = ''
102
+	) {
103
+		if ((float)$amount < 0) {
104
+			throw new EE_Error(
105
+				sprintf(
106
+					__(
107
+						'Attempting to make a payment for a negative amount of %1$d for transaction %2$d. That should be a refund',
108
+						'event_espresso'
109
+					),
110
+					$amount,
111
+					$transaction->ID()
112
+				)
113
+			);
114
+		}
115
+		// verify payment method
116
+		$payment_method = EEM_Payment_Method::instance()->ensure_is_obj($payment_method, true);
117
+		// verify transaction
118
+		EEM_Transaction::instance()->ensure_is_obj($transaction);
119
+		$transaction->set_payment_method_ID($payment_method->ID());
120
+		// verify payment method type
121
+		if ($payment_method->type_obj() instanceof EE_PMT_Base) {
122
+			$payment = $payment_method->type_obj()->process_payment(
123
+				$transaction,
124
+				min($amount, $transaction->remaining()),//make sure we don't overcharge
125
+				$billing_form,
126
+				$return_url,
127
+				add_query_arg(array('ee_cancel_payment' => true), $cancel_url),
128
+				$method,
129
+				$by_admin
130
+			);
131
+			// check if payment method uses an off-site gateway
132
+			if ($payment_method->type_obj()->payment_occurs() !== EE_PMT_Base::offsite) {
133
+				// don't process payments for off-site gateways yet because no payment has occurred yet
134
+				$this->update_txn_based_on_payment($transaction, $payment, $update_txn);
135
+			}
136
+			return $payment;
137
+		} else {
138
+			EE_Error::add_error(
139
+				sprintf(
140
+					__('A valid payment method could not be determined due to a technical issue.%sPlease try again or contact %s for assistance.', 'event_espresso'),
141
+					'<br/>',
142
+					EE_Registry::instance()->CFG->organization->get_pretty('email')
143
+				), __FILE__, __FUNCTION__, __LINE__
144
+			);
145
+			return null;
146
+		}
147
+	}
148
+
149
+
150
+
151
+	/**
152
+	 * @param EE_Transaction|int $transaction
153
+	 * @param EE_Payment_Method  $payment_method
154
+	 * @throws EE_Error
155
+	 * @return string
156
+	 */
157
+	public function get_ipn_url_for_payment_method($transaction, $payment_method)
158
+	{
159
+		/** @type \EE_Transaction $transaction */
160
+		$transaction = EEM_Transaction::instance()->ensure_is_obj($transaction);
161
+		$primary_reg = $transaction->primary_registration();
162
+		if ( ! $primary_reg instanceof EE_Registration) {
163
+			throw new EE_Error(
164
+				sprintf(
165
+					__(
166
+						"Cannot get IPN URL for transaction with ID %d because it has no primary registration",
167
+						"event_espresso"
168
+					),
169
+					$transaction->ID()
170
+				)
171
+			);
172
+		}
173
+		$payment_method = EEM_Payment_Method::instance()->ensure_is_obj($payment_method, true);
174
+		$url = add_query_arg(
175
+			array(
176
+				'e_reg_url_link'    => $primary_reg->reg_url_link(),
177
+				'ee_payment_method' => $payment_method->slug(),
178
+			),
179
+			EE_Registry::instance()->CFG->core->txn_page_url()
180
+		);
181
+		return $url;
182
+	}
183
+
184
+
185
+
186
+	/**
187
+	 * Process the IPN. Firstly, we'll hope we put the standard args into the IPN URL so
188
+	 * we can easily find what registration the IPN is for and what payment method.
189
+	 * However, if not, we'll give all payment methods a chance to claim it and process it.
190
+	 * If a payment is found for the IPN info, it is saved.
191
+	 *
192
+	 * @param array              $_req_data            eg $_REQUEST
193
+	 * @param EE_Transaction|int $transaction          optional (or a transactions id)
194
+	 * @param EE_Payment_Method  $payment_method       (or a slug or id of one)
195
+	 * @param boolean            $update_txn           whether or not to call
196
+	 *                                                 EE_Transaction_Processor::update_transaction_and_registrations_after_checkout_or_payment()
197
+	 * @param bool               $separate_IPN_request whether the IPN uses a separate request ( true like PayPal )
198
+	 *                                                 or is processed manually ( false like Mijireh )
199
+	 * @throws EE_Error
200
+	 * @throws Exception
201
+	 * @return EE_Payment
202
+	 */
203
+	public function process_ipn(
204
+		$_req_data,
205
+		$transaction = null,
206
+		$payment_method = null,
207
+		$update_txn = true,
208
+		$separate_IPN_request = true
209
+	) {
210
+		EE_Registry::instance()->load_model('Change_Log');
211
+		$_req_data = $this->_remove_unusable_characters_from_array((array)$_req_data);
212
+		EE_Processor_Base::set_IPN($separate_IPN_request);
213
+		$obj_for_log = null;
214
+		if ($transaction instanceof EE_Transaction) {
215
+			$obj_for_log = $transaction;
216
+			if ($payment_method instanceof EE_Payment_Method) {
217
+				$obj_for_log = EEM_Payment::instance()->get_one(
218
+					array(
219
+						array('TXN_ID' => $transaction->ID(), 'PMD_ID' => $payment_method->ID()),
220
+						'order_by' => array('PAY_timestamp' => 'desc'),
221
+					)
222
+				);
223
+			}
224
+		} else if ($payment_method instanceof EE_Payment) {
225
+			$obj_for_log = $payment_method;
226
+		}
227
+		$log = EEM_Change_Log::instance()->log(
228
+			EEM_Change_Log::type_gateway,
229
+			array('IPN data received' => $_req_data),
230
+			$obj_for_log
231
+		);
232
+		try {
233
+			/**
234
+			 * @var EE_Payment $payment
235
+			 */
236
+			$payment = null;
237
+			if ($transaction && $payment_method) {
238
+				/** @type EE_Transaction $transaction */
239
+				$transaction = EEM_Transaction::instance()->ensure_is_obj($transaction);
240
+				/** @type EE_Payment_Method $payment_method */
241
+				$payment_method = EEM_Payment_Method::instance()->ensure_is_obj($payment_method);
242
+				if ($payment_method->type_obj() instanceof EE_PMT_Base) {
243
+					try {
244
+						$payment = $payment_method->type_obj()->handle_ipn($_req_data, $transaction);
245
+						$log->set_object($payment);
246
+					} catch (EventEspresso\core\exceptions\IpnException $e) {
247
+						EEM_Change_Log::instance()->log(
248
+							EEM_Change_Log::type_gateway,
249
+							array(
250
+								'message'     => 'IPN Exception: ' . $e->getMessage(),
251
+								'current_url' => EEH_URL::current_url(),
252
+								'payment'     => $e->getPaymentProperties(),
253
+								'IPN_data'    => $e->getIpnData(),
254
+							),
255
+							$obj_for_log
256
+						);
257
+						return $e->getPayment();
258
+					}
259
+				} else {
260
+					// not a payment
261
+					EE_Error::add_error(
262
+						sprintf(
263
+							__('A valid payment method could not be determined due to a technical issue.%sPlease refresh your browser and try again or contact %s for assistance.', 'event_espresso'),
264
+							'<br/>',
265
+							EE_Registry::instance()->CFG->organization->get_pretty('email')
266
+						),
267
+						__FILE__, __FUNCTION__, __LINE__
268
+					);
269
+				}
270
+			} else {
271
+				//that's actually pretty ok. The IPN just wasn't able
272
+				//to identify which transaction or payment method this was for
273
+				// give all active payment methods a chance to claim it
274
+				$active_payment_methods = EEM_Payment_Method::instance()->get_all_active();
275
+				foreach ($active_payment_methods as $active_payment_method) {
276
+					try {
277
+						$payment = $active_payment_method->type_obj()->handle_unclaimed_ipn($_req_data);
278
+						$payment_method = $active_payment_method;
279
+						EEM_Change_Log::instance()->log(
280
+							EEM_Change_Log::type_gateway, array('IPN data' => $_req_data), $payment
281
+						);
282
+						break;
283
+					} catch (EventEspresso\core\exceptions\IpnException $e) {
284
+						EEM_Change_Log::instance()->log(
285
+							EEM_Change_Log::type_gateway,
286
+							array(
287
+								'message'     => 'IPN Exception: ' . $e->getMessage(),
288
+								'current_url' => EEH_URL::current_url(),
289
+								'payment'     => $e->getPaymentProperties(),
290
+								'IPN_data'    => $e->getIpnData(),
291
+							),
292
+							$obj_for_log
293
+						);
294
+						return $e->getPayment();
295
+					} catch (EE_Error $e) {
296
+						//that's fine- it apparently couldn't handle the IPN
297
+					}
298
+				}
299
+			}
300
+			// 			EEM_Payment_Log::instance()->log("got to 7",$transaction,$payment_method);
301
+			if ($payment instanceof EE_Payment) {
302
+				$payment->save();
303
+				//  update the TXN
304
+				$this->update_txn_based_on_payment($transaction, $payment, $update_txn, $separate_IPN_request);
305
+			} else {
306
+				//we couldn't find the payment for this IPN... let's try and log at least SOMETHING
307
+				if ($payment_method) {
308
+					EEM_Change_Log::instance()->log(EEM_Change_Log::type_gateway, array('IPN data' => $_req_data), $payment_method);
309
+				} elseif ($transaction) {
310
+					EEM_Change_Log::instance()->log(EEM_Change_Log::type_gateway, array('IPN data' => $_req_data), $transaction);
311
+				}
312
+			}
313
+			return $payment;
314
+		} catch (EE_Error $e) {
315
+			do_action(
316
+				'AHEE__log', __FILE__, __FUNCTION__, sprintf(
317
+					__('Error occurred while receiving IPN. Transaction: %1$s, req data: %2$s. The error was "%3$s"', 'event_espresso'),
318
+					print_r($transaction, true),
319
+					print_r($_req_data, true),
320
+					$e->getMessage()
321
+				)
322
+			);
323
+			throw $e;
324
+		}
325
+	}
326
+
327
+
328
+
329
+	/**
330
+	 * Removes any non-printable illegal characters from the input,
331
+	 * which might cause a raucous when trying to insert into the database
332
+	 *
333
+	 * @param  array $request_data
334
+	 * @return array
335
+	 */
336
+	protected function _remove_unusable_characters_from_array(array $request_data)
337
+	{
338
+		$return_data = array();
339
+		foreach ($request_data as $key => $value) {
340
+			$return_data[$this->_remove_unusable_characters($key)] = $this->_remove_unusable_characters($value);
341
+		}
342
+		return $return_data;
343
+	}
344
+
345
+
346
+
347
+	/**
348
+	 * Removes any non-printable illegal characters from the input,
349
+	 * which might cause a raucous when trying to insert into the database
350
+	 *
351
+	 * @param string $request_data
352
+	 * @return string
353
+	 */
354
+	protected function _remove_unusable_characters($request_data)
355
+	{
356
+		return preg_replace('/[^[:print:]]/', '', $request_data);
357
+	}
358
+
359
+
360
+
361
+	/**
362
+	 * Should be called just before displaying the payment attempt results to the user,
363
+	 * when the payment attempt has finished. Some payment methods may have special
364
+	 * logic to perform here. For example, if process_payment() happens on a special request
365
+	 * and then the user is redirected to a page that displays the payment's status, this
366
+	 * should be called while loading the page that displays the payment's status. If the user is
367
+	 * sent to an offsite payment provider, this should be called upon returning from that offsite payment
368
+	 * provider.
369
+	 *
370
+	 * @param EE_Transaction|int $transaction
371
+	 * @param bool               $update_txn whether or not to call
372
+	 *                                       EE_Transaction_Processor::update_transaction_and_registrations_after_checkout_or_payment()
373
+	 * @throws \EE_Error
374
+	 * @return EE_Payment
375
+	 * @deprecated 4.6.24 method is no longer used. Instead it is up to client code, like SPCO,
376
+	 *                                       to call handle_ipn() for offsite gateways that don't receive separate IPNs
377
+	 */
378
+	public function finalize_payment_for($transaction, $update_txn = true)
379
+	{
380
+		/** @var $transaction EE_Transaction */
381
+		$transaction = EEM_Transaction::instance()->ensure_is_obj($transaction);
382
+		$last_payment_method = $transaction->payment_method();
383
+		if ($last_payment_method instanceof EE_Payment_Method) {
384
+			$payment = $last_payment_method->type_obj()->finalize_payment_for($transaction);
385
+			$this->update_txn_based_on_payment($transaction, $payment, $update_txn);
386
+			return $payment;
387
+		} else {
388
+			return null;
389
+		}
390
+	}
391
+
392
+
393
+
394
+	/**
395
+	 * Processes a direct refund request, saves the payment, and updates the transaction appropriately.
396
+	 *
397
+	 * @param EE_Payment_Method $payment_method
398
+	 * @param EE_Payment        $payment_to_refund
399
+	 * @param array             $refund_info
400
+	 * @return EE_Payment
401
+	 * @throws \EE_Error
402
+	 */
403
+	public function process_refund(
404
+		EE_Payment_Method $payment_method,
405
+		EE_Payment $payment_to_refund,
406
+		$refund_info = array()
407
+	) {
408
+		if ($payment_method instanceof EE_Payment_Method && $payment_method->type_obj()->supports_sending_refunds()) {
409
+			$payment_method->type_obj()->process_refund($payment_to_refund, $refund_info);
410
+			$this->update_txn_based_on_payment($payment_to_refund->transaction(), $payment_to_refund);
411
+		}
412
+		return $payment_to_refund;
413
+	}
414
+
415
+
416
+
417
+	/**
418
+	 * This should be called each time there may have been an update to a
419
+	 * payment on a transaction (ie, we asked for a payment to process a
420
+	 * payment for a transaction, or we told a payment method about an IPN, or
421
+	 * we told a payment method to
422
+	 * "finalize_payment_for" (a transaction), or we told a payment method to
423
+	 * process a refund. This should handle firing the correct hooks to
424
+	 * indicate
425
+	 * what exactly happened and updating the transaction appropriately). This
426
+	 * could be integrated directly into EE_Transaction upon save, but we want
427
+	 * this logic to be separate from 'normal' plain-jane saving and updating
428
+	 * of transactions and payments, and to be tied to payment processing.
429
+	 * Note: this method DOES NOT save the payment passed into it. It is the responsibility
430
+	 * of previous code to decide whether or not to save (because the payment passed into
431
+	 * this method might be a temporary, never-to-be-saved payment from an offline gateway,
432
+	 * in which case we only want that payment object for some temporary usage during this request,
433
+	 * but we don't want it to be saved).
434
+	 *
435
+	 * @param EE_Transaction|int $transaction
436
+	 * @param EE_Payment         $payment
437
+	 * @param boolean            $update_txn
438
+	 *                        whether or not to call
439
+	 *                        EE_Transaction_Processor::
440
+	 *                        update_transaction_and_registrations_after_checkout_or_payment()
441
+	 *                        (you can save 1 DB query if you know you're going
442
+	 *                        to save it later instead)
443
+	 * @param bool               $IPN
444
+	 *                        if processing IPNs or other similar payment
445
+	 *                        related activities that occur in alternate
446
+	 *                        requests than the main one that is processing the
447
+	 *                        TXN, then set this to true to check whether the
448
+	 *                        TXN is locked before updating
449
+	 * @throws \EE_Error
450
+	 */
451
+	public function update_txn_based_on_payment($transaction, $payment, $update_txn = true, $IPN = false)
452
+	{
453
+		$do_action = 'AHEE__EE_Payment_Processor__update_txn_based_on_payment__not_successful';
454
+		/** @type EE_Transaction $transaction */
455
+		$transaction = EEM_Transaction::instance()->ensure_is_obj($transaction);
456
+		// can we freely update the TXN at this moment?
457
+		if ($IPN && $transaction->is_locked()) {
458
+			// don't update the transaction at this exact moment
459
+			// because the TXN is active in another request
460
+			EE_Cron_Tasks::schedule_update_transaction_with_payment(
461
+				time(),
462
+				$transaction->ID(),
463
+				$payment->ID()
464
+			);
465
+		} else {
466
+			// verify payment and that it has been saved
467
+			if ($payment instanceof EE_Payment && $payment->ID()) {
468
+				if (
469
+					$payment->payment_method() instanceof EE_Payment_Method
470
+					&& $payment->payment_method()->type_obj() instanceof EE_PMT_Base
471
+				) {
472
+					$payment->payment_method()->type_obj()->update_txn_based_on_payment($payment);
473
+					// update TXN registrations with payment info
474
+					$this->process_registration_payments($transaction, $payment);
475
+				}
476
+				$do_action = $payment->just_approved()
477
+					? 'AHEE__EE_Payment_Processor__update_txn_based_on_payment__successful'
478
+					: $do_action;
479
+			} else {
480
+				// send out notifications
481
+				add_filter('FHEE__EED_Messages___maybe_registration__deliver_notifications', '__return_true');
482
+				$do_action = 'AHEE__EE_Payment_Processor__update_txn_based_on_payment__no_payment_made';
483
+			}
484
+			if ($payment instanceof EE_Payment && $payment->status() !== EEM_Payment::status_id_failed) {
485
+				/** @type EE_Transaction_Payments $transaction_payments */
486
+				$transaction_payments = EE_Registry::instance()->load_class('Transaction_Payments');
487
+				// set new value for total paid
488
+				$transaction_payments->calculate_total_payments_and_update_status($transaction);
489
+				// call EE_Transaction_Processor::update_transaction_and_registrations_after_checkout_or_payment() ???
490
+				if ($update_txn) {
491
+					$this->_post_payment_processing($transaction, $payment, $IPN);
492
+				}
493
+			}
494
+			// granular hook for others to use.
495
+			do_action($do_action, $transaction, $payment);
496
+			do_action('AHEE_log', __CLASS__, __FUNCTION__, $do_action, '$do_action');
497
+			//global hook for others to use.
498
+			do_action('AHEE__EE_Payment_Processor__update_txn_based_on_payment', $transaction, $payment);
499
+		}
500
+	}
501
+
502
+
503
+
504
+	/**
505
+	 * update registrations REG_paid field after successful payment and link registrations with payment
506
+	 *
507
+	 * @param EE_Transaction    $transaction
508
+	 * @param EE_Payment        $payment
509
+	 * @param EE_Registration[] $registrations
510
+	 * @throws \EE_Error
511
+	 */
512
+	public function process_registration_payments(
513
+		EE_Transaction $transaction,
514
+		EE_Payment $payment,
515
+		$registrations = array()
516
+	) {
517
+		// only process if payment was successful
518
+		if ($payment->status() !== EEM_Payment::status_id_approved) {
519
+			return;
520
+		}
521
+		//EEM_Registration::instance()->show_next_x_db_queries();
522
+		if (empty($registrations)) {
523
+			// find registrations with monies owing that can receive a payment
524
+			$registrations = $transaction->registrations(
525
+				array(
526
+					array(
527
+						// only these reg statuses can receive payments
528
+						'STS_ID'           => array('IN', EEM_Registration::reg_statuses_that_allow_payment()),
529
+						'REG_final_price'  => array('!=', 0),
530
+						'REG_final_price*' => array('!=', 'REG_paid', true),
531
+					),
532
+				)
533
+			);
534
+		}
535
+		// still nothing ??!??
536
+		if (empty($registrations)) {
537
+			return;
538
+		}
539
+		// todo: break out the following logic into a separate strategy class
540
+		// todo: named something like "Sequential_Reg_Payment_Strategy"
541
+		// todo: which would apply payments using the capitalist "first come first paid" approach
542
+		// todo: then have another strategy class like "Distributed_Reg_Payment_Strategy"
543
+		// todo: which would be the socialist "everybody gets a piece of pie" approach,
544
+		// todo: which would be better for deposits, where you want a bit of the payment applied to each registration
545
+		$refund = $payment->is_a_refund();
546
+		// how much is available to apply to registrations?
547
+		$available_payment_amount = abs($payment->amount());
548
+		foreach ($registrations as $registration) {
549
+			if ($registration instanceof EE_Registration) {
550
+				// nothing left?
551
+				if ($available_payment_amount <= 0) {
552
+					break;
553
+				}
554
+				if ($refund) {
555
+					$available_payment_amount = $this->process_registration_refund($registration, $payment, $available_payment_amount);
556
+				} else {
557
+					$available_payment_amount = $this->process_registration_payment($registration, $payment, $available_payment_amount);
558
+				}
559
+			}
560
+		}
561
+		if ($available_payment_amount > 0 && apply_filters('FHEE__EE_Payment_Processor__process_registration_payments__display_notifications', false)) {
562
+			EE_Error::add_attention(
563
+				sprintf(
564
+					__('A remainder of %1$s exists after applying this payment to Registration(s) %2$s.%3$sPlease verify that the original payment amount of %4$s is correct. If so, you should edit this payment and select at least one additional registration in the "Registrations to Apply Payment to" section, so that the remainder of this payment can be applied to the additional registration(s).',
565
+						'event_espresso'),
566
+					EEH_Template::format_currency($available_payment_amount),
567
+					implode(', ', array_keys($registrations)),
568
+					'<br/>',
569
+					EEH_Template::format_currency($payment->amount())
570
+				),
571
+				__FILE__, __FUNCTION__, __LINE__
572
+			);
573
+		}
574
+	}
575
+
576
+
577
+
578
+	/**
579
+	 * update registration REG_paid field after successful payment and link registration with payment
580
+	 *
581
+	 * @param EE_Registration $registration
582
+	 * @param EE_Payment      $payment
583
+	 * @param float           $available_payment_amount
584
+	 * @return float
585
+	 * @throws \EE_Error
586
+	 */
587
+	public function process_registration_payment(
588
+		EE_Registration $registration,
589
+		EE_Payment $payment,
590
+		$available_payment_amount = 0.00
591
+	) {
592
+		$owing = $registration->final_price() - $registration->paid();
593
+		if ($owing > 0) {
594
+			// don't allow payment amount to exceed the available payment amount, OR the amount owing
595
+			$payment_amount = min($available_payment_amount, $owing);
596
+			// update $available_payment_amount
597
+			$available_payment_amount -= $payment_amount;
598
+			//calculate and set new REG_paid
599
+			$registration->set_paid($registration->paid() + $payment_amount);
600
+			// now save it
601
+			$this->_apply_registration_payment($registration, $payment, $payment_amount);
602
+		}
603
+		return $available_payment_amount;
604
+	}
605
+
606
+
607
+
608
+	/**
609
+	 * update registration REG_paid field after successful payment and link registration with payment
610
+	 *
611
+	 * @param EE_Registration $registration
612
+	 * @param EE_Payment      $payment
613
+	 * @param float           $payment_amount
614
+	 * @return void
615
+	 * @throws \EE_Error
616
+	 */
617
+	protected function _apply_registration_payment(
618
+		EE_Registration $registration,
619
+		EE_Payment $payment,
620
+		$payment_amount = 0.00
621
+	) {
622
+		// find any existing reg payment records for this registration and payment
623
+		$existing_reg_payment = EEM_Registration_Payment::instance()->get_one(
624
+			array(array('REG_ID' => $registration->ID(), 'PAY_ID' => $payment->ID()))
625
+		);
626
+		// if existing registration payment exists
627
+		if ($existing_reg_payment instanceof EE_Registration_Payment) {
628
+			// then update that record
629
+			$existing_reg_payment->set_amount($payment_amount);
630
+			$existing_reg_payment->save();
631
+		} else {
632
+			// or add new relation between registration and payment and set amount
633
+			$registration->_add_relation_to($payment, 'Payment', array('RPY_amount' => $payment_amount));
634
+			// make it stick
635
+			$registration->save();
636
+		}
637
+	}
638
+
639
+
640
+
641
+	/**
642
+	 * update registration REG_paid field after refund and link registration with payment
643
+	 *
644
+	 * @param EE_Registration $registration
645
+	 * @param EE_Payment      $payment
646
+	 * @param float           $available_refund_amount - IMPORTANT !!! SEND AVAILABLE REFUND AMOUNT AS A POSITIVE NUMBER
647
+	 * @return float
648
+	 * @throws \EE_Error
649
+	 */
650
+	public function process_registration_refund(
651
+		EE_Registration $registration,
652
+		EE_Payment $payment,
653
+		$available_refund_amount = 0.00
654
+	) {
655
+		//EEH_Debug_Tools::printr( $payment->amount(), '$payment->amount()', __FILE__, __LINE__ );
656
+		if ($registration->paid() > 0) {
657
+			// ensure $available_refund_amount is NOT negative
658
+			$available_refund_amount = (float)abs($available_refund_amount);
659
+			// don't allow refund amount to exceed the available payment amount, OR the amount paid
660
+			$refund_amount = min($available_refund_amount, (float)$registration->paid());
661
+			// update $available_payment_amount
662
+			$available_refund_amount -= $refund_amount;
663
+			//calculate and set new REG_paid
664
+			$registration->set_paid($registration->paid() - $refund_amount);
665
+			// convert payment amount back to a negative value for storage in the db
666
+			$refund_amount = (float)abs($refund_amount) * -1;
667
+			// now save it
668
+			$this->_apply_registration_payment($registration, $payment, $refund_amount);
669
+		}
670
+		return $available_refund_amount;
671
+	}
672
+
673
+
674
+
675
+	/**
676
+	 * Process payments and transaction after payment process completed.
677
+	 * ultimately this will send the TXN and payment details off so that notifications can be sent out.
678
+	 * if this request happens to be processing an IPN,
679
+	 * then we will also set the Payment Options Reg Step to completed,
680
+	 * and attempt to completely finalize the TXN if all of the other Reg Steps are completed as well.
681
+	 *
682
+	 * @param EE_Transaction $transaction
683
+	 * @param EE_Payment     $payment
684
+	 * @param bool           $IPN
685
+	 * @throws \EE_Error
686
+	 */
687
+	protected function _post_payment_processing(EE_Transaction $transaction, EE_Payment $payment, $IPN = false)
688
+	{
689
+		/** @type EE_Transaction_Processor $transaction_processor */
690
+		$transaction_processor = EE_Registry::instance()->load_class('Transaction_Processor');
691
+		// is the Payment Options Reg Step completed ?
692
+		$payment_options_step_completed = $transaction->reg_step_completed('payment_options');
693
+		// if the Payment Options Reg Step is completed...
694
+		$revisit = $payment_options_step_completed === true ? true : false;
695
+		// then this is kinda sorta a revisit with regards to payments at least
696
+		$transaction_processor->set_revisit($revisit);
697
+		// if this is an IPN, let's consider the Payment Options Reg Step completed if not already
698
+		if (
699
+			$IPN
700
+			&& $payment_options_step_completed !== true
701
+			&& ($payment->is_approved() || $payment->is_pending())
702
+		) {
703
+			$payment_options_step_completed = $transaction->set_reg_step_completed(
704
+				'payment_options'
705
+			);
706
+		}
707
+		// maybe update status, but don't save transaction just yet
708
+		$transaction->update_status_based_on_total_paid(false);
709
+		// check if 'finalize_registration' step has been completed...
710
+		$finalized = $transaction->reg_step_completed('finalize_registration');
711
+		//  if this is an IPN and the final step has not been initiated
712
+		if ($IPN && $payment_options_step_completed && $finalized === false) {
713
+			// and if it hasn't already been set as being started...
714
+			$finalized = $transaction->set_reg_step_initiated('finalize_registration');
715
+		}
716
+		$transaction->save();
717
+		// because the above will return false if the final step was not fully completed, we need to check again...
718
+		if ($IPN && $finalized !== false) {
719
+			// and if we are all good to go, then send out notifications
720
+			add_filter('FHEE__EED_Messages___maybe_registration__deliver_notifications', '__return_true');
721
+			//ok, now process the transaction according to the payment
722
+			$transaction_processor->update_transaction_and_registrations_after_checkout_or_payment($transaction, $payment);
723
+		}
724
+		// DEBUG LOG
725
+		$payment_method = $payment->payment_method();
726
+		if ($payment_method instanceof EE_Payment_Method) {
727
+			$payment_method_type_obj = $payment_method->type_obj();
728
+			if ($payment_method_type_obj instanceof EE_PMT_Base) {
729
+				$gateway = $payment_method_type_obj->get_gateway();
730
+				if ($gateway instanceof EE_Gateway) {
731
+					$gateway->log(
732
+						array(
733
+							'message'               => __('Post Payment Transaction Details', 'event_espresso'),
734
+							'transaction'           => $transaction->model_field_array(),
735
+							'finalized'             => $finalized,
736
+							'IPN'                   => $IPN,
737
+							'deliver_notifications' => has_filter(
738
+								'FHEE__EED_Messages___maybe_registration__deliver_notifications'
739
+							),
740
+						),
741
+						$payment
742
+					);
743
+				}
744
+			}
745
+		}
746
+	}
747
+
748
+
749
+
750
+	/**
751
+	 * Force posts to PayPal to use TLS v1.2. See:
752
+	 * https://core.trac.wordpress.org/ticket/36320
753
+	 * https://core.trac.wordpress.org/ticket/34924#comment:15
754
+	 * https://www.paypal-knowledge.com/infocenter/index?page=content&widgetview=true&id=FAQ1914&viewlocale=en_US
755
+	 * This will affect paypal standard, pro, express, and payflow.
756
+	 */
757
+	public static function _curl_requests_to_paypal_use_tls($handle, $r, $url)
758
+	{
759
+		if (strstr($url, 'https://') && strstr($url, '.paypal.com')) {
760
+			//Use the value of the constant CURL_SSLVERSION_TLSv1 = 1
761
+			//instead of the constant because it might not be defined
762
+			curl_setopt($handle, CURLOPT_SSLVERSION, 1);
763
+		}
764
+	}
765 765
 }
Please login to merge, or discard this patch.
core/EE_Encryption.core.php 1 patch
Unused Use Statements   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -1,4 +1,4 @@
 block discarded – undo
1
-<?php use EventEspresso\core\interfaces\InterminableInterface;
1
+<?php 
2 2
 
3 3
 defined('EVENT_ESPRESSO_VERSION') || exit('No direct script access allowed');
4 4
 
Please login to merge, or discard this patch.
core/exceptions/ExceptionStackTraceDisplay.php 2 patches
Indentation   +275 added lines, -275 removed lines patch added patch discarded remove patch
@@ -7,7 +7,7 @@  discard block
 block discarded – undo
7 7
 use ReflectionException;
8 8
 
9 9
 if (! defined('EVENT_ESPRESSO_VERSION')) {
10
-    exit('No direct script access allowed');
10
+	exit('No direct script access allowed');
11 11
 }
12 12
 
13 13
 
@@ -25,53 +25,53 @@  discard block
 block discarded – undo
25 25
 
26 26
 
27 27
 
28
-    /**
29
-     * @param Exception $exception
30
-     * @throws Exception
31
-     */
32
-    public function __construct(Exception $exception)
33
-    {
34
-        if (WP_DEBUG && ! defined('EE_TESTS_DIR')) {
35
-            $this->displayException($exception);
36
-        } else {
37
-            throw $exception;
38
-        }
39
-    }
28
+	/**
29
+	 * @param Exception $exception
30
+	 * @throws Exception
31
+	 */
32
+	public function __construct(Exception $exception)
33
+	{
34
+		if (WP_DEBUG && ! defined('EE_TESTS_DIR')) {
35
+			$this->displayException($exception);
36
+		} else {
37
+			throw $exception;
38
+		}
39
+	}
40 40
 
41 41
 
42 42
 
43
-    /**
44
-     * @access protected
45
-     * @param Exception $exception
46
-     * @throws ReflectionException
47
-     */
48
-    protected function displayException(Exception $exception)
49
-    {
50
-        $error_code = '';
51
-        $trace_details = '';
52
-        $time = time();
53
-        $trace = $exception->getTrace();
54
-        // get separate user and developer messages if they exist
55
-        $msg = explode('||', $exception->getMessage());
56
-        $user_msg = $msg[0];
57
-        $dev_msg = isset($msg[1]) ? $msg[1] : $msg[0];
58
-        $msg = WP_DEBUG ? $dev_msg : $user_msg;
59
-        // start gathering output
60
-        $output = $this->exceptionStyles();
61
-        $output .= '
43
+	/**
44
+	 * @access protected
45
+	 * @param Exception $exception
46
+	 * @throws ReflectionException
47
+	 */
48
+	protected function displayException(Exception $exception)
49
+	{
50
+		$error_code = '';
51
+		$trace_details = '';
52
+		$time = time();
53
+		$trace = $exception->getTrace();
54
+		// get separate user and developer messages if they exist
55
+		$msg = explode('||', $exception->getMessage());
56
+		$user_msg = $msg[0];
57
+		$dev_msg = isset($msg[1]) ? $msg[1] : $msg[0];
58
+		$msg = WP_DEBUG ? $dev_msg : $user_msg;
59
+		// start gathering output
60
+		$output = $this->exceptionStyles();
61
+		$output .= '
62 62
 <div id="ee-error-message" class="error">';
63
-        if (! WP_DEBUG) {
64
-            $output .= '
63
+		if (! WP_DEBUG) {
64
+			$output .= '
65 65
 	<p>';
66
-        }
67
-        // process trace info
68
-        if (empty($trace)) {
69
-            $trace_details .= __(
70
-                'Sorry, but no trace information was available for this exception.',
71
-                'event_espresso'
72
-            );
73
-        } else {
74
-            $trace_details .= '
66
+		}
67
+		// process trace info
68
+		if (empty($trace)) {
69
+			$trace_details .= __(
70
+				'Sorry, but no trace information was available for this exception.',
71
+				'event_espresso'
72
+			);
73
+		} else {
74
+			$trace_details .= '
75 75
 			<div id="ee-trace-details">
76 76
 			<table width="100%" border="0" cellpadding="5" cellspacing="0">
77 77
 				<tr>
@@ -79,255 +79,255 @@  discard block
 block discarded – undo
79 79
 					<th scope="col" align="right" style="width:3.5%;">Line</th>
80 80
 					<th scope="col" align="left" style="width:40%;">File</th>
81 81
 					<th scope="col" align="left">' . __('Class', 'event_espresso') . '->' . __('Method( arguments )',
82
-                    'event_espresso') . '</th>
82
+					'event_espresso') . '</th>
83 83
 				</tr>';
84
-            $last_on_stack = count($trace) - 1;
85
-            // reverse array so that stack is in proper chronological order
86
-            $sorted_trace = array_reverse($trace);
87
-            foreach ($sorted_trace as $nmbr => $trace) {
88
-                $file = isset($trace['file']) ? $trace['file'] : '';
89
-                $class = isset($trace['class']) ? $trace['class'] : '';
90
-                $type = isset($trace['type']) ? $trace['type'] : '';
91
-                $function = isset($trace['function']) ? $trace['function'] : '';
92
-                $args = isset($trace['args']) ? $this->_convert_args_to_string($trace['args']) : '';
93
-                $args = isset($trace['args']) && count($trace['args']) > 4 ? ' <br />' . $args . '<br />' : $args;
94
-                $line = isset($trace['line']) ? $trace['line'] : '';
95
-                $zebra = $nmbr % 2 !== 0 ? ' odd' : '';
96
-                if (empty($file) && ! empty($class)) {
97
-                    $a = new ReflectionClass($class);
98
-                    $file = $a->getFileName();
99
-                    if (empty($line) && ! empty($function)) {
100
-                        $b = new \ReflectionMethod($class, $function);
101
-                        $line = $b->getStartLine();
102
-                    }
103
-                }
104
-                if ($nmbr === $last_on_stack) {
105
-                    $file = $exception->getFile() !== '' ? $exception->getFile() : $file;
106
-                    $line = $exception->getLine() !== '' ? $exception->getLine() : $line;
107
-                    $error_code = $this->generate_error_code($file, $trace['function'], $line);
108
-                }
109
-                $file = \EEH_File::standardise_directory_separators($file);
110
-                $nmbr = ! empty($nmbr) ? $nmbr : '&nbsp;';
111
-                $line = ! empty($line) ? $line : '&nbsp;';
112
-                $file = ! empty($file) ? $file : '&nbsp;';
113
-                $class_display = ! empty($class) ? $class : '';
114
-                $type = ! empty($type) ? $type : '';
115
-                $function = ! empty($function) ? $function : '';
116
-                $args = ! empty($args) ? '( ' . $args . ' )' : '()';
117
-                $trace_details .= '
84
+			$last_on_stack = count($trace) - 1;
85
+			// reverse array so that stack is in proper chronological order
86
+			$sorted_trace = array_reverse($trace);
87
+			foreach ($sorted_trace as $nmbr => $trace) {
88
+				$file = isset($trace['file']) ? $trace['file'] : '';
89
+				$class = isset($trace['class']) ? $trace['class'] : '';
90
+				$type = isset($trace['type']) ? $trace['type'] : '';
91
+				$function = isset($trace['function']) ? $trace['function'] : '';
92
+				$args = isset($trace['args']) ? $this->_convert_args_to_string($trace['args']) : '';
93
+				$args = isset($trace['args']) && count($trace['args']) > 4 ? ' <br />' . $args . '<br />' : $args;
94
+				$line = isset($trace['line']) ? $trace['line'] : '';
95
+				$zebra = $nmbr % 2 !== 0 ? ' odd' : '';
96
+				if (empty($file) && ! empty($class)) {
97
+					$a = new ReflectionClass($class);
98
+					$file = $a->getFileName();
99
+					if (empty($line) && ! empty($function)) {
100
+						$b = new \ReflectionMethod($class, $function);
101
+						$line = $b->getStartLine();
102
+					}
103
+				}
104
+				if ($nmbr === $last_on_stack) {
105
+					$file = $exception->getFile() !== '' ? $exception->getFile() : $file;
106
+					$line = $exception->getLine() !== '' ? $exception->getLine() : $line;
107
+					$error_code = $this->generate_error_code($file, $trace['function'], $line);
108
+				}
109
+				$file = \EEH_File::standardise_directory_separators($file);
110
+				$nmbr = ! empty($nmbr) ? $nmbr : '&nbsp;';
111
+				$line = ! empty($line) ? $line : '&nbsp;';
112
+				$file = ! empty($file) ? $file : '&nbsp;';
113
+				$class_display = ! empty($class) ? $class : '';
114
+				$type = ! empty($type) ? $type : '';
115
+				$function = ! empty($function) ? $function : '';
116
+				$args = ! empty($args) ? '( ' . $args . ' )' : '()';
117
+				$trace_details .= '
118 118
 					<tr>
119 119
 						<td align="right" valign="top" class="'
120
-                                  . $zebra
121
-                                  . '">'
122
-                                  . $nmbr
123
-                                  . '</td>
120
+								  . $zebra
121
+								  . '">'
122
+								  . $nmbr
123
+								  . '</td>
124 124
 						<td align="right" valign="top" class="'
125
-                                  . $zebra
126
-                                  . '">'
127
-                                  . $line
128
-                                  . '</td>
125
+								  . $zebra
126
+								  . '">'
127
+								  . $line
128
+								  . '</td>
129 129
 						<td align="left" valign="top" class="'
130
-                                  . $zebra
131
-                                  . '">'
132
-                                  . $file
133
-                                  . '</td>
130
+								  . $zebra
131
+								  . '">'
132
+								  . $file
133
+								  . '</td>
134 134
 						<td align="left" valign="top" class="'
135
-                                  . $zebra
136
-                                  . '">'
137
-                                  . $class_display
138
-                                  . $type
139
-                                  . $function
140
-                                  . $args
141
-                                  . '</td>
135
+								  . $zebra
136
+								  . '">'
137
+								  . $class_display
138
+								  . $type
139
+								  . $function
140
+								  . $args
141
+								  . '</td>
142 142
 					</tr>';
143
-            }
144
-            $trace_details .= '
143
+			}
144
+			$trace_details .= '
145 145
 			 </table>
146 146
 			</div>';
147
-        }
148
-        $code = $exception->getCode() ? $exception->getCode() : $error_code;
149
-        // add generic non-identifying messages for non-privileged users
150
-        if (! WP_DEBUG) {
151
-            $output .= '<span class="ee-error-user-msg-spn">'
152
-                       . trim($msg)
153
-                       . '</span> &nbsp; <sup>'
154
-                       . $code
155
-                       . '</sup><br />';
156
-        } else {
157
-            // or helpful developer messages if debugging is on
158
-            $output .= '
147
+		}
148
+		$code = $exception->getCode() ? $exception->getCode() : $error_code;
149
+		// add generic non-identifying messages for non-privileged users
150
+		if (! WP_DEBUG) {
151
+			$output .= '<span class="ee-error-user-msg-spn">'
152
+					   . trim($msg)
153
+					   . '</span> &nbsp; <sup>'
154
+					   . $code
155
+					   . '</sup><br />';
156
+		} else {
157
+			// or helpful developer messages if debugging is on
158
+			$output .= '
159 159
 		<div class="ee-error-dev-msg-dv">
160 160
 			<p class="ee-error-dev-msg-pg">
161 161
 				'
162
-                       . sprintf(
163
-                           __('%1$sAn %2$s was thrown!%3$s code: %4$s', 'event_espresso'),
164
-                           '<strong class="ee-error-dev-msg-str">',
165
-                           get_class($exception),
166
-                           '</strong>  &nbsp; <span>',
167
-                           $code . '</span>'
168
-                       )
169
-                       . '<br />
162
+					   . sprintf(
163
+						   __('%1$sAn %2$s was thrown!%3$s code: %4$s', 'event_espresso'),
164
+						   '<strong class="ee-error-dev-msg-str">',
165
+						   get_class($exception),
166
+						   '</strong>  &nbsp; <span>',
167
+						   $code . '</span>'
168
+					   )
169
+					   . '<br />
170 170
 				<span class="big-text">"'
171
-                       . trim($msg)
172
-                       . '"</span><br/>
171
+					   . trim($msg)
172
+					   . '"</span><br/>
173 173
 				<a id="display-ee-error-trace-1'
174
-                       . $time
175
-                       . '" class="display-ee-error-trace-lnk small-text" rel="ee-error-trace-1'
176
-                       . $time
177
-                       . '">
174
+					   . $time
175
+					   . '" class="display-ee-error-trace-lnk small-text" rel="ee-error-trace-1'
176
+					   . $time
177
+					   . '">
178 178
 					'
179
-                       . __('click to view backtrace and class/method details', 'event_espresso')
180
-                       . '
179
+					   . __('click to view backtrace and class/method details', 'event_espresso')
180
+					   . '
181 181
 				</a><br />
182 182
 				'
183
-                       . $exception->getFile()
184
-                       . sprintf(
185
-                           __('%1$s( line no: %2$s )%3$s', 'event_espresso'),
186
-                           ' &nbsp; <span class="small-text lt-grey-text">',
187
-                           $exception->getLine(),
188
-                           '</span>'
189
-                       )
190
-                       . '
183
+					   . $exception->getFile()
184
+					   . sprintf(
185
+						   __('%1$s( line no: %2$s )%3$s', 'event_espresso'),
186
+						   ' &nbsp; <span class="small-text lt-grey-text">',
187
+						   $exception->getLine(),
188
+						   '</span>'
189
+					   )
190
+					   . '
191 191
 			</p>
192 192
 			<div id="ee-error-trace-1'
193
-                       . $time
194
-                       . '-dv" class="ee-error-trace-dv" style="display: none;">
193
+					   . $time
194
+					   . '-dv" class="ee-error-trace-dv" style="display: none;">
195 195
 				'
196
-                       . $trace_details;
197
-            if (! empty($class)) {
198
-                $output .= '
196
+					   . $trace_details;
197
+			if (! empty($class)) {
198
+				$output .= '
199 199
 				<div style="padding:3px; margin:0 0 1em; border:1px solid #999; background:#fff; border-radius:3px;">
200 200
 					<div style="padding:1em 2em; border:1px solid #999; background:#fcfcfc;">
201 201
 						<h3>' . __('Class Details', 'event_espresso') . '</h3>';
202
-                $a = new ReflectionClass($class);
203
-                $output .= '
202
+				$a = new ReflectionClass($class);
203
+				$output .= '
204 204
 						<pre>' . $a . '</pre>
205 205
 					</div>
206 206
 				</div>';
207
-            }
208
-            $output .= '
207
+			}
208
+			$output .= '
209 209
 			</div>
210 210
 		</div>
211 211
 		<br />';
212
-        }
213
-        // remove last linebreak
214
-        $output = substr($output, 0, -6);
215
-        if (! WP_DEBUG) {
216
-            $output .= '
212
+		}
213
+		// remove last linebreak
214
+		$output = substr($output, 0, -6);
215
+		if (! WP_DEBUG) {
216
+			$output .= '
217 217
 	</p>';
218
-        }
219
-        $output .= '
218
+		}
219
+		$output .= '
220 220
 </div>';
221
-        $output .= $this->printScripts(true);
222
-        if (defined('DOING_AJAX')) {
223
-            echo wp_json_encode(array('error' => $output));
224
-            exit();
225
-        }
226
-        echo $output;
227
-    }
221
+		$output .= $this->printScripts(true);
222
+		if (defined('DOING_AJAX')) {
223
+			echo wp_json_encode(array('error' => $output));
224
+			exit();
225
+		}
226
+		echo $output;
227
+	}
228 228
 
229 229
 
230 230
 
231
-    /**
232
-     * generate string from exception trace args
233
-     *
234
-     * @param array $arguments
235
-     * @param int   $indent
236
-     * @param bool  $array
237
-     * @return string
238
-     */
239
-    private function _convert_args_to_string($arguments = array(), $indent = 0, $array = false)
240
-    {
241
-        $args = array();
242
-        $args_count = count($arguments);
243
-        if ($args_count > 2) {
244
-            $indent++;
245
-            $args[] = '<br />';
246
-        }
247
-        $x = 0;
248
-        foreach ($arguments as $arg) {
249
-            $x++;
250
-            for ($i = 0; $i < $indent; $i++) {
251
-                $args[] = ' &nbsp;&nbsp; ';
252
-            }
253
-            if (is_string($arg)) {
254
-                if (! $array && strlen($arg) > 75) {
255
-                    $args[] = '<br />';
256
-                    for ($i = 0; $i <= $indent; $i++) {
257
-                        $args[] = ' &nbsp;&nbsp; ';
258
-                    }
259
-                    $args[] = "'" . $arg . "'<br />";
260
-                } else {
261
-                    $args[] = " '" . $arg . "'";
262
-                }
263
-            } elseif (is_array($arg)) {
264
-                $arg_count = count($arg);
265
-                if ($arg_count > 2) {
266
-                    $indent++;
267
-                    $args[] = ' array(' . $this->_convert_args_to_string($arg, $indent, true) . ')';
268
-                    $indent--;
269
-                } else if ($arg_count === 0) {
270
-                    $args[] = ' array()';
271
-                } else {
272
-                    $args[] = ' array( ' . $this->_convert_args_to_string($arg) . ' )';
273
-                }
274
-            } elseif ($arg === null) {
275
-                $args[] = ' null';
276
-            } elseif (is_bool($arg)) {
277
-                $args[] = $arg ? ' true' : ' false';
278
-            } elseif (is_object($arg)) {
279
-                $args[] = get_class($arg);
280
-            } elseif (is_resource($arg)) {
281
-                $args[] = get_resource_type($arg);
282
-            } else {
283
-                $args[] = $arg;
284
-            }
285
-            if ($x === $args_count) {
286
-                if ($args_count > 2) {
287
-                    $args[] = '<br />';
288
-                    $indent--;
289
-                    for ($i = 1; $i < $indent; $i++) {
290
-                        $args[] = ' &nbsp;&nbsp; ';
291
-                    }
292
-                }
293
-            } else {
294
-                $args[] = $args_count > 2 ? ',<br />' : ', ';
295
-            }
296
-        }
297
-        return implode('', $args);
298
-    }
231
+	/**
232
+	 * generate string from exception trace args
233
+	 *
234
+	 * @param array $arguments
235
+	 * @param int   $indent
236
+	 * @param bool  $array
237
+	 * @return string
238
+	 */
239
+	private function _convert_args_to_string($arguments = array(), $indent = 0, $array = false)
240
+	{
241
+		$args = array();
242
+		$args_count = count($arguments);
243
+		if ($args_count > 2) {
244
+			$indent++;
245
+			$args[] = '<br />';
246
+		}
247
+		$x = 0;
248
+		foreach ($arguments as $arg) {
249
+			$x++;
250
+			for ($i = 0; $i < $indent; $i++) {
251
+				$args[] = ' &nbsp;&nbsp; ';
252
+			}
253
+			if (is_string($arg)) {
254
+				if (! $array && strlen($arg) > 75) {
255
+					$args[] = '<br />';
256
+					for ($i = 0; $i <= $indent; $i++) {
257
+						$args[] = ' &nbsp;&nbsp; ';
258
+					}
259
+					$args[] = "'" . $arg . "'<br />";
260
+				} else {
261
+					$args[] = " '" . $arg . "'";
262
+				}
263
+			} elseif (is_array($arg)) {
264
+				$arg_count = count($arg);
265
+				if ($arg_count > 2) {
266
+					$indent++;
267
+					$args[] = ' array(' . $this->_convert_args_to_string($arg, $indent, true) . ')';
268
+					$indent--;
269
+				} else if ($arg_count === 0) {
270
+					$args[] = ' array()';
271
+				} else {
272
+					$args[] = ' array( ' . $this->_convert_args_to_string($arg) . ' )';
273
+				}
274
+			} elseif ($arg === null) {
275
+				$args[] = ' null';
276
+			} elseif (is_bool($arg)) {
277
+				$args[] = $arg ? ' true' : ' false';
278
+			} elseif (is_object($arg)) {
279
+				$args[] = get_class($arg);
280
+			} elseif (is_resource($arg)) {
281
+				$args[] = get_resource_type($arg);
282
+			} else {
283
+				$args[] = $arg;
284
+			}
285
+			if ($x === $args_count) {
286
+				if ($args_count > 2) {
287
+					$args[] = '<br />';
288
+					$indent--;
289
+					for ($i = 1; $i < $indent; $i++) {
290
+						$args[] = ' &nbsp;&nbsp; ';
291
+					}
292
+				}
293
+			} else {
294
+				$args[] = $args_count > 2 ? ',<br />' : ', ';
295
+			}
296
+		}
297
+		return implode('', $args);
298
+	}
299 299
 
300 300
 
301 301
 
302
-    /**
303
-     * create error code from filepath, function name,
304
-     * and line number where exception or error was thrown
305
-     *
306
-     * @access protected
307
-     * @param string $file
308
-     * @param string $func
309
-     * @param string $line
310
-     * @return string
311
-     */
312
-    protected function generate_error_code($file = '', $func = '', $line = '')
313
-    {
314
-        $file_bits = explode('.', basename($file));
315
-        $error_code = ! empty($file_bits[0]) ? $file_bits[0] : '';
316
-        $error_code .= ! empty($func) ? ' - ' . $func : '';
317
-        $error_code .= ! empty($line) ? ' - ' . $line : '';
318
-        return $error_code;
319
-    }
302
+	/**
303
+	 * create error code from filepath, function name,
304
+	 * and line number where exception or error was thrown
305
+	 *
306
+	 * @access protected
307
+	 * @param string $file
308
+	 * @param string $func
309
+	 * @param string $line
310
+	 * @return string
311
+	 */
312
+	protected function generate_error_code($file = '', $func = '', $line = '')
313
+	{
314
+		$file_bits = explode('.', basename($file));
315
+		$error_code = ! empty($file_bits[0]) ? $file_bits[0] : '';
316
+		$error_code .= ! empty($func) ? ' - ' . $func : '';
317
+		$error_code .= ! empty($line) ? ' - ' . $line : '';
318
+		return $error_code;
319
+	}
320 320
 
321 321
 
322 322
 
323
-    /**
324
-     * _exception_styles
325
-     *
326
-     * @return string
327
-     */
328
-    private function exceptionStyles()
329
-    {
330
-        return '
323
+	/**
324
+	 * _exception_styles
325
+	 *
326
+	 * @return string
327
+	 */
328
+	private function exceptionStyles()
329
+	{
330
+		return '
331 331
 <style type="text/css">
332 332
 	#ee-error-message {
333 333
 		max-width:90% !important;
@@ -384,30 +384,30 @@  discard block
 block discarded – undo
384 384
 		color: #999;
385 385
 	}
386 386
 </style>';
387
-    }
387
+	}
388 388
 
389 389
 
390 390
 
391
-    /**
392
-     * _print_scripts
393
-     *
394
-     * @param bool $force_print
395
-     * @return string
396
-     */
397
-    private function printScripts($force_print = false)
398
-    {
399
-        if (! $force_print && (did_action('admin_enqueue_scripts') || did_action('wp_enqueue_scripts'))) {
400
-            if (wp_script_is('ee_error_js', 'enqueued')) {
401
-                return '';
402
-            }
403
-            if (wp_script_is('ee_error_js', 'registered')) {
404
-                wp_enqueue_style('espresso_default');
405
-                wp_enqueue_style('espresso_custom_css');
406
-                wp_enqueue_script( 'ee_error_js' );
391
+	/**
392
+	 * _print_scripts
393
+	 *
394
+	 * @param bool $force_print
395
+	 * @return string
396
+	 */
397
+	private function printScripts($force_print = false)
398
+	{
399
+		if (! $force_print && (did_action('admin_enqueue_scripts') || did_action('wp_enqueue_scripts'))) {
400
+			if (wp_script_is('ee_error_js', 'enqueued')) {
401
+				return '';
402
+			}
403
+			if (wp_script_is('ee_error_js', 'registered')) {
404
+				wp_enqueue_style('espresso_default');
405
+				wp_enqueue_style('espresso_custom_css');
406
+				wp_enqueue_script( 'ee_error_js' );
407 407
 				wp_localize_script( 'ee_error_js', 'ee_settings', array( 'wp_debug' => WP_DEBUG ) );
408
-            }
409
-        } else {
410
-            return '
408
+			}
409
+		} else {
410
+			return '
411 411
 <script>
412 412
 /* <![CDATA[ */
413 413
 var ee_settings = {"wp_debug":"' . WP_DEBUG . '"};
@@ -417,9 +417,9 @@  discard block
 block discarded – undo
417 417
 <script src="' . EE_GLOBAL_ASSETS_URL . 'scripts/espresso_core.js' . '?ver=' . espresso_version() . '" type="text/javascript"></script>
418 418
 <script src="' . EE_GLOBAL_ASSETS_URL . 'scripts/EE_Error.js' . '?ver=' . espresso_version() . '" type="text/javascript"></script>
419 419
 ';
420
-        }
421
-        return '';
422
-    }
420
+		}
421
+		return '';
422
+	}
423 423
 
424 424
 
425 425
 
Please login to merge, or discard this patch.
Spacing   +26 added lines, -26 removed lines patch added patch discarded remove patch
@@ -6,7 +6,7 @@  discard block
 block discarded – undo
6 6
 use ReflectionClass;
7 7
 use ReflectionException;
8 8
 
9
-if (! defined('EVENT_ESPRESSO_VERSION')) {
9
+if ( ! defined('EVENT_ESPRESSO_VERSION')) {
10 10
     exit('No direct script access allowed');
11 11
 }
12 12
 
@@ -60,7 +60,7 @@  discard block
 block discarded – undo
60 60
         $output = $this->exceptionStyles();
61 61
         $output .= '
62 62
 <div id="ee-error-message" class="error">';
63
-        if (! WP_DEBUG) {
63
+        if ( ! WP_DEBUG) {
64 64
             $output .= '
65 65
 	<p>';
66 66
         }
@@ -78,8 +78,8 @@  discard block
 block discarded – undo
78 78
 					<th scope="col" align="right" style="width:2.5%;">#</th>
79 79
 					<th scope="col" align="right" style="width:3.5%;">Line</th>
80 80
 					<th scope="col" align="left" style="width:40%;">File</th>
81
-					<th scope="col" align="left">' . __('Class', 'event_espresso') . '->' . __('Method( arguments )',
82
-                    'event_espresso') . '</th>
81
+					<th scope="col" align="left">' . __('Class', 'event_espresso').'->'.__('Method( arguments )',
82
+                    'event_espresso').'</th>
83 83
 				</tr>';
84 84
             $last_on_stack = count($trace) - 1;
85 85
             // reverse array so that stack is in proper chronological order
@@ -90,7 +90,7 @@  discard block
 block discarded – undo
90 90
                 $type = isset($trace['type']) ? $trace['type'] : '';
91 91
                 $function = isset($trace['function']) ? $trace['function'] : '';
92 92
                 $args = isset($trace['args']) ? $this->_convert_args_to_string($trace['args']) : '';
93
-                $args = isset($trace['args']) && count($trace['args']) > 4 ? ' <br />' . $args . '<br />' : $args;
93
+                $args = isset($trace['args']) && count($trace['args']) > 4 ? ' <br />'.$args.'<br />' : $args;
94 94
                 $line = isset($trace['line']) ? $trace['line'] : '';
95 95
                 $zebra = $nmbr % 2 !== 0 ? ' odd' : '';
96 96
                 if (empty($file) && ! empty($class)) {
@@ -113,7 +113,7 @@  discard block
 block discarded – undo
113 113
                 $class_display = ! empty($class) ? $class : '';
114 114
                 $type = ! empty($type) ? $type : '';
115 115
                 $function = ! empty($function) ? $function : '';
116
-                $args = ! empty($args) ? '( ' . $args . ' )' : '()';
116
+                $args = ! empty($args) ? '( '.$args.' )' : '()';
117 117
                 $trace_details .= '
118 118
 					<tr>
119 119
 						<td align="right" valign="top" class="'
@@ -147,7 +147,7 @@  discard block
 block discarded – undo
147 147
         }
148 148
         $code = $exception->getCode() ? $exception->getCode() : $error_code;
149 149
         // add generic non-identifying messages for non-privileged users
150
-        if (! WP_DEBUG) {
150
+        if ( ! WP_DEBUG) {
151 151
             $output .= '<span class="ee-error-user-msg-spn">'
152 152
                        . trim($msg)
153 153
                        . '</span> &nbsp; <sup>'
@@ -164,7 +164,7 @@  discard block
 block discarded – undo
164 164
                            '<strong class="ee-error-dev-msg-str">',
165 165
                            get_class($exception),
166 166
                            '</strong>  &nbsp; <span>',
167
-                           $code . '</span>'
167
+                           $code.'</span>'
168 168
                        )
169 169
                        . '<br />
170 170
 				<span class="big-text">"'
@@ -194,14 +194,14 @@  discard block
 block discarded – undo
194 194
                        . '-dv" class="ee-error-trace-dv" style="display: none;">
195 195
 				'
196 196
                        . $trace_details;
197
-            if (! empty($class)) {
197
+            if ( ! empty($class)) {
198 198
                 $output .= '
199 199
 				<div style="padding:3px; margin:0 0 1em; border:1px solid #999; background:#fff; border-radius:3px;">
200 200
 					<div style="padding:1em 2em; border:1px solid #999; background:#fcfcfc;">
201
-						<h3>' . __('Class Details', 'event_espresso') . '</h3>';
201
+						<h3>' . __('Class Details', 'event_espresso').'</h3>';
202 202
                 $a = new ReflectionClass($class);
203 203
                 $output .= '
204
-						<pre>' . $a . '</pre>
204
+						<pre>' . $a.'</pre>
205 205
 					</div>
206 206
 				</div>';
207 207
             }
@@ -212,7 +212,7 @@  discard block
 block discarded – undo
212 212
         }
213 213
         // remove last linebreak
214 214
         $output = substr($output, 0, -6);
215
-        if (! WP_DEBUG) {
215
+        if ( ! WP_DEBUG) {
216 216
             $output .= '
217 217
 	</p>';
218 218
         }
@@ -251,25 +251,25 @@  discard block
 block discarded – undo
251 251
                 $args[] = ' &nbsp;&nbsp; ';
252 252
             }
253 253
             if (is_string($arg)) {
254
-                if (! $array && strlen($arg) > 75) {
254
+                if ( ! $array && strlen($arg) > 75) {
255 255
                     $args[] = '<br />';
256 256
                     for ($i = 0; $i <= $indent; $i++) {
257 257
                         $args[] = ' &nbsp;&nbsp; ';
258 258
                     }
259
-                    $args[] = "'" . $arg . "'<br />";
259
+                    $args[] = "'".$arg."'<br />";
260 260
                 } else {
261
-                    $args[] = " '" . $arg . "'";
261
+                    $args[] = " '".$arg."'";
262 262
                 }
263 263
             } elseif (is_array($arg)) {
264 264
                 $arg_count = count($arg);
265 265
                 if ($arg_count > 2) {
266 266
                     $indent++;
267
-                    $args[] = ' array(' . $this->_convert_args_to_string($arg, $indent, true) . ')';
267
+                    $args[] = ' array('.$this->_convert_args_to_string($arg, $indent, true).')';
268 268
                     $indent--;
269 269
                 } else if ($arg_count === 0) {
270 270
                     $args[] = ' array()';
271 271
                 } else {
272
-                    $args[] = ' array( ' . $this->_convert_args_to_string($arg) . ' )';
272
+                    $args[] = ' array( '.$this->_convert_args_to_string($arg).' )';
273 273
                 }
274 274
             } elseif ($arg === null) {
275 275
                 $args[] = ' null';
@@ -313,8 +313,8 @@  discard block
 block discarded – undo
313 313
     {
314 314
         $file_bits = explode('.', basename($file));
315 315
         $error_code = ! empty($file_bits[0]) ? $file_bits[0] : '';
316
-        $error_code .= ! empty($func) ? ' - ' . $func : '';
317
-        $error_code .= ! empty($line) ? ' - ' . $line : '';
316
+        $error_code .= ! empty($func) ? ' - '.$func : '';
317
+        $error_code .= ! empty($line) ? ' - '.$line : '';
318 318
         return $error_code;
319 319
     }
320 320
 
@@ -396,26 +396,26 @@  discard block
 block discarded – undo
396 396
      */
397 397
     private function printScripts($force_print = false)
398 398
     {
399
-        if (! $force_print && (did_action('admin_enqueue_scripts') || did_action('wp_enqueue_scripts'))) {
399
+        if ( ! $force_print && (did_action('admin_enqueue_scripts') || did_action('wp_enqueue_scripts'))) {
400 400
             if (wp_script_is('ee_error_js', 'enqueued')) {
401 401
                 return '';
402 402
             }
403 403
             if (wp_script_is('ee_error_js', 'registered')) {
404 404
                 wp_enqueue_style('espresso_default');
405 405
                 wp_enqueue_style('espresso_custom_css');
406
-                wp_enqueue_script( 'ee_error_js' );
407
-				wp_localize_script( 'ee_error_js', 'ee_settings', array( 'wp_debug' => WP_DEBUG ) );
406
+                wp_enqueue_script('ee_error_js');
407
+				wp_localize_script('ee_error_js', 'ee_settings', array('wp_debug' => WP_DEBUG));
408 408
             }
409 409
         } else {
410 410
             return '
411 411
 <script>
412 412
 /* <![CDATA[ */
413
-var ee_settings = {"wp_debug":"' . WP_DEBUG . '"};
413
+var ee_settings = {"wp_debug":"' . WP_DEBUG.'"};
414 414
 /* ]]> */
415 415
 </script>
416
-<script src="' . includes_url() . 'js/jquery/jquery.js" type="text/javascript"></script>
417
-<script src="' . EE_GLOBAL_ASSETS_URL . 'scripts/espresso_core.js' . '?ver=' . espresso_version() . '" type="text/javascript"></script>
418
-<script src="' . EE_GLOBAL_ASSETS_URL . 'scripts/EE_Error.js' . '?ver=' . espresso_version() . '" type="text/javascript"></script>
416
+<script src="' . includes_url().'js/jquery/jquery.js" type="text/javascript"></script>
417
+<script src="' . EE_GLOBAL_ASSETS_URL.'scripts/espresso_core.js'.'?ver='.espresso_version().'" type="text/javascript"></script>
418
+<script src="' . EE_GLOBAL_ASSETS_URL.'scripts/EE_Error.js'.'?ver='.espresso_version().'" type="text/javascript"></script>
419 419
 ';
420 420
         }
421 421
         return '';
Please login to merge, or discard this patch.
form_sections/strategies/layout/EE_Div_Per_Section_Layout.strategy.php 2 patches
Indentation   +126 added lines, -126 removed lines patch added patch discarded remove patch
@@ -14,132 +14,132 @@
 block discarded – undo
14 14
 class EE_Div_Per_Section_Layout extends EE_Form_Section_Layout_Base
15 15
 {
16 16
 
17
-    /**
18
-     * opening div tag for a form
19
-     *
20
-     * @return string
21
-     */
22
-    public function layout_form_begin()
23
-    {
24
-        return EEH_HTML::div(
25
-            '',
26
-            $this->_form_section->html_id(),
27
-            $this->_form_section->html_class(),
28
-            $this->_form_section->html_style()
29
-        );
30
-    }
31
-
32
-
33
-
34
-    /**
35
-     * Lays out the row for the input, including label and errors
36
-     *
37
-     * @param EE_Form_Input_Base $input
38
-     * @return string
39
-     * @throws \EE_Error
40
-     */
41
-    public function layout_input($input)
42
-    {
43
-        $html = '';
44
-        // set something unique for the id
45
-        $html_id = (string)$input->html_id() !== ''
46
-            ? (string)$input->html_id()
47
-            : spl_object_hash($input);
48
-        // and add a generic class
49
-        $html_class = sanitize_key(str_replace('_', '-', get_class($input))) . '-dv';
50
-        if ($input instanceof EE_Hidden_Input) {
51
-            $html .= EEH_HTML::nl() . $input->get_html_for_input();
52
-        } else if ($input instanceof EE_Submit_Input) {
53
-            $html .= EEH_HTML::div(
54
-                $input->get_html_for_input(),
55
-                $html_id . '-submit-dv',
56
-                $html_class
57
-            );
58
-        } else if ($input instanceof EE_Select_Input) {
59
-            $html .= EEH_HTML::div(
60
-                EEH_HTML::nl(1) . $input->get_html_for_label() .
61
-                EEH_HTML::nl() . $input->get_html_for_errors() .
62
-                EEH_HTML::nl() . $input->get_html_for_input() .
63
-                EEH_HTML::nl() . $input->get_html_for_help(),
64
-                $html_id . '-input-dv',
65
-                $html_class
66
-            );
67
-        } else if ($input instanceof EE_Form_Input_With_Options_Base) {
68
-            $html .= EEH_HTML::div(
69
-                EEH_HTML::nl() . $this->_display_label_for_option_type_question($input) .
70
-                EEH_HTML::nl() . $input->get_html_for_errors() .
71
-                EEH_HTML::nl() . $input->get_html_for_input() .
72
-                EEH_HTML::nl() . $input->get_html_for_help(),
73
-                $html_id . '-input-dv',
74
-                $html_class
75
-            );
76
-        } else {
77
-            $html .= EEH_HTML::div(
78
-                EEH_HTML::nl(1) . $input->get_html_for_label() .
79
-                EEH_HTML::nl() . $input->get_html_for_errors() .
80
-                EEH_HTML::nl() . $input->get_html_for_input() .
81
-                EEH_HTML::nl() . $input->get_html_for_help(),
82
-                $html_id . '-input-dv',
83
-                $html_class
84
-            );
85
-        }
86
-        return $html;
87
-    }
88
-
89
-
90
-
91
-    /**
92
-     *
93
-     * _display_label_for_option_type_question
94
-     * Gets the HTML for the 'label', which is just text for this (because labels
95
-     * should be for each input)
96
-     *
97
-     * @param EE_Form_Input_With_Options_Base $input
98
-     * @return string
99
-     */
100
-    protected function _display_label_for_option_type_question(EE_Form_Input_With_Options_Base $input)
101
-    {
102
-        if ($input->display_html_label_text() !== '') {
103
-            return EEH_HTML::div(
104
-                $input->required()
105
-                    ? $input->html_label_text() . EEH_HTML::span('*', '', 'ee-asterisk')
106
-                    : $input->html_label_text(),
107
-                $input->html_label_id(),
108
-                $input->required()
109
-                    ? 'ee-required-label ' . $input->html_label_class()
110
-                    : $input->html_label_class(),
111
-                $input->html_label_style(),
112
-                $input->html_other_attributes()
113
-            );
114
-        }
115
-        return '';
116
-    }
117
-
118
-
119
-
120
-    /**
121
-     * Lays out a row for the subsection
122
-     *
123
-     * @param EE_Form_Section_Proper $form_section
124
-     * @return string
125
-     */
126
-    public function layout_subsection($form_section)
127
-    {
128
-        //		d( $form_section );
129
-        return EEH_HTML::nl(1) . $form_section->get_html() . EEH_HTML::nl(-1);
130
-    }
131
-
132
-
133
-
134
-    /**
135
-     * closing div tag for a form
136
-     *
137
-     * @return string
138
-     */
139
-    public function layout_form_end()
140
-    {
141
-        return EEH_HTML::divx($this->_form_section->html_id(), $this->_form_section->html_class());
142
-    }
17
+	/**
18
+	 * opening div tag for a form
19
+	 *
20
+	 * @return string
21
+	 */
22
+	public function layout_form_begin()
23
+	{
24
+		return EEH_HTML::div(
25
+			'',
26
+			$this->_form_section->html_id(),
27
+			$this->_form_section->html_class(),
28
+			$this->_form_section->html_style()
29
+		);
30
+	}
31
+
32
+
33
+
34
+	/**
35
+	 * Lays out the row for the input, including label and errors
36
+	 *
37
+	 * @param EE_Form_Input_Base $input
38
+	 * @return string
39
+	 * @throws \EE_Error
40
+	 */
41
+	public function layout_input($input)
42
+	{
43
+		$html = '';
44
+		// set something unique for the id
45
+		$html_id = (string)$input->html_id() !== ''
46
+			? (string)$input->html_id()
47
+			: spl_object_hash($input);
48
+		// and add a generic class
49
+		$html_class = sanitize_key(str_replace('_', '-', get_class($input))) . '-dv';
50
+		if ($input instanceof EE_Hidden_Input) {
51
+			$html .= EEH_HTML::nl() . $input->get_html_for_input();
52
+		} else if ($input instanceof EE_Submit_Input) {
53
+			$html .= EEH_HTML::div(
54
+				$input->get_html_for_input(),
55
+				$html_id . '-submit-dv',
56
+				$html_class
57
+			);
58
+		} else if ($input instanceof EE_Select_Input) {
59
+			$html .= EEH_HTML::div(
60
+				EEH_HTML::nl(1) . $input->get_html_for_label() .
61
+				EEH_HTML::nl() . $input->get_html_for_errors() .
62
+				EEH_HTML::nl() . $input->get_html_for_input() .
63
+				EEH_HTML::nl() . $input->get_html_for_help(),
64
+				$html_id . '-input-dv',
65
+				$html_class
66
+			);
67
+		} else if ($input instanceof EE_Form_Input_With_Options_Base) {
68
+			$html .= EEH_HTML::div(
69
+				EEH_HTML::nl() . $this->_display_label_for_option_type_question($input) .
70
+				EEH_HTML::nl() . $input->get_html_for_errors() .
71
+				EEH_HTML::nl() . $input->get_html_for_input() .
72
+				EEH_HTML::nl() . $input->get_html_for_help(),
73
+				$html_id . '-input-dv',
74
+				$html_class
75
+			);
76
+		} else {
77
+			$html .= EEH_HTML::div(
78
+				EEH_HTML::nl(1) . $input->get_html_for_label() .
79
+				EEH_HTML::nl() . $input->get_html_for_errors() .
80
+				EEH_HTML::nl() . $input->get_html_for_input() .
81
+				EEH_HTML::nl() . $input->get_html_for_help(),
82
+				$html_id . '-input-dv',
83
+				$html_class
84
+			);
85
+		}
86
+		return $html;
87
+	}
88
+
89
+
90
+
91
+	/**
92
+	 *
93
+	 * _display_label_for_option_type_question
94
+	 * Gets the HTML for the 'label', which is just text for this (because labels
95
+	 * should be for each input)
96
+	 *
97
+	 * @param EE_Form_Input_With_Options_Base $input
98
+	 * @return string
99
+	 */
100
+	protected function _display_label_for_option_type_question(EE_Form_Input_With_Options_Base $input)
101
+	{
102
+		if ($input->display_html_label_text() !== '') {
103
+			return EEH_HTML::div(
104
+				$input->required()
105
+					? $input->html_label_text() . EEH_HTML::span('*', '', 'ee-asterisk')
106
+					: $input->html_label_text(),
107
+				$input->html_label_id(),
108
+				$input->required()
109
+					? 'ee-required-label ' . $input->html_label_class()
110
+					: $input->html_label_class(),
111
+				$input->html_label_style(),
112
+				$input->html_other_attributes()
113
+			);
114
+		}
115
+		return '';
116
+	}
117
+
118
+
119
+
120
+	/**
121
+	 * Lays out a row for the subsection
122
+	 *
123
+	 * @param EE_Form_Section_Proper $form_section
124
+	 * @return string
125
+	 */
126
+	public function layout_subsection($form_section)
127
+	{
128
+		//		d( $form_section );
129
+		return EEH_HTML::nl(1) . $form_section->get_html() . EEH_HTML::nl(-1);
130
+	}
131
+
132
+
133
+
134
+	/**
135
+	 * closing div tag for a form
136
+	 *
137
+	 * @return string
138
+	 */
139
+	public function layout_form_end()
140
+	{
141
+		return EEH_HTML::divx($this->_form_section->html_id(), $this->_form_section->html_class());
142
+	}
143 143
 
144 144
 
145 145
 
Please login to merge, or discard this patch.
Spacing   +23 added lines, -23 removed lines patch added patch discarded remove patch
@@ -42,44 +42,44 @@  discard block
 block discarded – undo
42 42
     {
43 43
         $html = '';
44 44
         // set something unique for the id
45
-        $html_id = (string)$input->html_id() !== ''
46
-            ? (string)$input->html_id()
45
+        $html_id = (string) $input->html_id() !== ''
46
+            ? (string) $input->html_id()
47 47
             : spl_object_hash($input);
48 48
         // and add a generic class
49
-        $html_class = sanitize_key(str_replace('_', '-', get_class($input))) . '-dv';
49
+        $html_class = sanitize_key(str_replace('_', '-', get_class($input))).'-dv';
50 50
         if ($input instanceof EE_Hidden_Input) {
51
-            $html .= EEH_HTML::nl() . $input->get_html_for_input();
51
+            $html .= EEH_HTML::nl().$input->get_html_for_input();
52 52
         } else if ($input instanceof EE_Submit_Input) {
53 53
             $html .= EEH_HTML::div(
54 54
                 $input->get_html_for_input(),
55
-                $html_id . '-submit-dv',
55
+                $html_id.'-submit-dv',
56 56
                 $html_class
57 57
             );
58 58
         } else if ($input instanceof EE_Select_Input) {
59 59
             $html .= EEH_HTML::div(
60
-                EEH_HTML::nl(1) . $input->get_html_for_label() .
61
-                EEH_HTML::nl() . $input->get_html_for_errors() .
62
-                EEH_HTML::nl() . $input->get_html_for_input() .
63
-                EEH_HTML::nl() . $input->get_html_for_help(),
64
-                $html_id . '-input-dv',
60
+                EEH_HTML::nl(1).$input->get_html_for_label().
61
+                EEH_HTML::nl().$input->get_html_for_errors().
62
+                EEH_HTML::nl().$input->get_html_for_input().
63
+                EEH_HTML::nl().$input->get_html_for_help(),
64
+                $html_id.'-input-dv',
65 65
                 $html_class
66 66
             );
67 67
         } else if ($input instanceof EE_Form_Input_With_Options_Base) {
68 68
             $html .= EEH_HTML::div(
69
-                EEH_HTML::nl() . $this->_display_label_for_option_type_question($input) .
70
-                EEH_HTML::nl() . $input->get_html_for_errors() .
71
-                EEH_HTML::nl() . $input->get_html_for_input() .
72
-                EEH_HTML::nl() . $input->get_html_for_help(),
73
-                $html_id . '-input-dv',
69
+                EEH_HTML::nl().$this->_display_label_for_option_type_question($input).
70
+                EEH_HTML::nl().$input->get_html_for_errors().
71
+                EEH_HTML::nl().$input->get_html_for_input().
72
+                EEH_HTML::nl().$input->get_html_for_help(),
73
+                $html_id.'-input-dv',
74 74
                 $html_class
75 75
             );
76 76
         } else {
77 77
             $html .= EEH_HTML::div(
78
-                EEH_HTML::nl(1) . $input->get_html_for_label() .
79
-                EEH_HTML::nl() . $input->get_html_for_errors() .
80
-                EEH_HTML::nl() . $input->get_html_for_input() .
81
-                EEH_HTML::nl() . $input->get_html_for_help(),
82
-                $html_id . '-input-dv',
78
+                EEH_HTML::nl(1).$input->get_html_for_label().
79
+                EEH_HTML::nl().$input->get_html_for_errors().
80
+                EEH_HTML::nl().$input->get_html_for_input().
81
+                EEH_HTML::nl().$input->get_html_for_help(),
82
+                $html_id.'-input-dv',
83 83
                 $html_class
84 84
             );
85 85
         }
@@ -102,11 +102,11 @@  discard block
 block discarded – undo
102 102
         if ($input->display_html_label_text() !== '') {
103 103
             return EEH_HTML::div(
104 104
                 $input->required()
105
-                    ? $input->html_label_text() . EEH_HTML::span('*', '', 'ee-asterisk')
105
+                    ? $input->html_label_text().EEH_HTML::span('*', '', 'ee-asterisk')
106 106
                     : $input->html_label_text(),
107 107
                 $input->html_label_id(),
108 108
                 $input->required()
109
-                    ? 'ee-required-label ' . $input->html_label_class()
109
+                    ? 'ee-required-label '.$input->html_label_class()
110 110
                     : $input->html_label_class(),
111 111
                 $input->html_label_style(),
112 112
                 $input->html_other_attributes()
@@ -126,7 +126,7 @@  discard block
 block discarded – undo
126 126
     public function layout_subsection($form_section)
127 127
     {
128 128
         //		d( $form_section );
129
-        return EEH_HTML::nl(1) . $form_section->get_html() . EEH_HTML::nl(-1);
129
+        return EEH_HTML::nl(1).$form_section->get_html().EEH_HTML::nl(-1);
130 130
     }
131 131
 
132 132
 
Please login to merge, or discard this patch.
core/EE_Deprecated.core.php 2 patches
Indentation   +87 added lines, -87 removed lines patch added patch discarded remove patch
@@ -1047,11 +1047,11 @@  discard block
 block discarded – undo
1047 1047
 			'filter'
1048 1048
 		);
1049 1049
 		return apply_filters(
1050
-            'FHEE_EE_Single_Page_Checkout__save_registration_items__find_existing_attendee',
1051
-            $existing_attendee, $registration, $attendee_data
1052
-        );
1050
+			'FHEE_EE_Single_Page_Checkout__save_registration_items__find_existing_attendee',
1051
+			$existing_attendee, $registration, $attendee_data
1052
+		);
1053 1053
 	},
1054
-    10,3
1054
+	10,3
1055 1055
 );
1056 1056
 
1057 1057
 
@@ -1064,88 +1064,88 @@  discard block
 block discarded – undo
1064 1064
 class EE_Event_List_Query extends WP_Query
1065 1065
 {
1066 1066
 
1067
-    private $title;
1068
-
1069
-    private $css_class;
1070
-
1071
-    private $category_slug;
1072
-
1073
-    /**
1074
-     * EE_Event_List_Query constructor.
1075
-     *
1076
-     * @param array $args
1077
-     */
1078
-    public function __construct($args = array())
1079
-    {
1080
-        \EE_Error::doing_it_wrong(
1081
-            __METHOD__,
1082
-            __(
1083
-                'Usage is deprecated. Please use \EventEspresso\core\domain\services\wp_queries\EventListQuery instead.',
1084
-                'event_espresso'
1085
-            ),
1086
-            '4.9.27',
1087
-            '5.0.0'
1088
-        );
1089
-        $this->title = isset($args['title']) ? $args['title'] : '';
1090
-        $this->css_class = isset($args['css_class']) ? $args['css_class'] : '';
1091
-        $this->category_slug = isset($args['category_slug']) ? $args['category_slug'] : '';
1092
-        $limit = isset($args['limit']) && absint($args['limit']) ? $args['limit'] : 10;
1093
-        // the current "page" we are viewing
1094
-        $paged = max(1, get_query_var('paged'));
1095
-        // Force these args
1096
-        $args = array_merge(
1097
-            $args, array(
1098
-            'post_type'              => 'espresso_events',
1099
-            'posts_per_page'         => $limit,
1100
-            'update_post_term_cache' => false,
1101
-            'update_post_meta_cache' => false,
1102
-            'paged'                  => $paged,
1103
-            'offset'                 => ($paged - 1) * $limit
1104
-        )
1105
-        );
1106
-        // run the query
1107
-        parent::__construct($args);
1108
-    }
1109
-
1110
-
1111
-
1112
-    /**
1113
-     * event_list_title
1114
-     *
1115
-     * @param string $event_list_title
1116
-     * @return string
1117
-     */
1118
-    public function event_list_title($event_list_title = '')
1119
-    {
1120
-        if (! empty($this->title)) {
1121
-            return $this->title;
1122
-        }
1123
-        return $event_list_title;
1124
-    }
1125
-
1126
-
1127
-
1128
-    /**
1129
-     * event_list_css
1130
-     *
1131
-     * @param string $event_list_css
1132
-     * @return string
1133
-     */
1134
-    public function event_list_css($event_list_css = '')
1135
-    {
1136
-        $event_list_css .= ! empty($event_list_css)
1137
-            ? ' '
1138
-            : '';
1139
-        $event_list_css .= ! empty($this->css_class)
1140
-            ? $this->css_class
1141
-            : '';
1142
-        $event_list_css .= ! empty($event_list_css)
1143
-            ? ' '
1144
-            : '';
1145
-        $event_list_css .= ! empty($this->category_slug)
1146
-            ? $this->category_slug
1147
-            : '';
1148
-        return $event_list_css;
1149
-    }
1067
+	private $title;
1068
+
1069
+	private $css_class;
1070
+
1071
+	private $category_slug;
1072
+
1073
+	/**
1074
+	 * EE_Event_List_Query constructor.
1075
+	 *
1076
+	 * @param array $args
1077
+	 */
1078
+	public function __construct($args = array())
1079
+	{
1080
+		\EE_Error::doing_it_wrong(
1081
+			__METHOD__,
1082
+			__(
1083
+				'Usage is deprecated. Please use \EventEspresso\core\domain\services\wp_queries\EventListQuery instead.',
1084
+				'event_espresso'
1085
+			),
1086
+			'4.9.27',
1087
+			'5.0.0'
1088
+		);
1089
+		$this->title = isset($args['title']) ? $args['title'] : '';
1090
+		$this->css_class = isset($args['css_class']) ? $args['css_class'] : '';
1091
+		$this->category_slug = isset($args['category_slug']) ? $args['category_slug'] : '';
1092
+		$limit = isset($args['limit']) && absint($args['limit']) ? $args['limit'] : 10;
1093
+		// the current "page" we are viewing
1094
+		$paged = max(1, get_query_var('paged'));
1095
+		// Force these args
1096
+		$args = array_merge(
1097
+			$args, array(
1098
+			'post_type'              => 'espresso_events',
1099
+			'posts_per_page'         => $limit,
1100
+			'update_post_term_cache' => false,
1101
+			'update_post_meta_cache' => false,
1102
+			'paged'                  => $paged,
1103
+			'offset'                 => ($paged - 1) * $limit
1104
+		)
1105
+		);
1106
+		// run the query
1107
+		parent::__construct($args);
1108
+	}
1109
+
1110
+
1111
+
1112
+	/**
1113
+	 * event_list_title
1114
+	 *
1115
+	 * @param string $event_list_title
1116
+	 * @return string
1117
+	 */
1118
+	public function event_list_title($event_list_title = '')
1119
+	{
1120
+		if (! empty($this->title)) {
1121
+			return $this->title;
1122
+		}
1123
+		return $event_list_title;
1124
+	}
1125
+
1126
+
1127
+
1128
+	/**
1129
+	 * event_list_css
1130
+	 *
1131
+	 * @param string $event_list_css
1132
+	 * @return string
1133
+	 */
1134
+	public function event_list_css($event_list_css = '')
1135
+	{
1136
+		$event_list_css .= ! empty($event_list_css)
1137
+			? ' '
1138
+			: '';
1139
+		$event_list_css .= ! empty($this->css_class)
1140
+			? $this->css_class
1141
+			: '';
1142
+		$event_list_css .= ! empty($event_list_css)
1143
+			? ' '
1144
+			: '';
1145
+		$event_list_css .= ! empty($this->category_slug)
1146
+			? $this->category_slug
1147
+			: '';
1148
+		return $event_list_css;
1149
+	}
1150 1150
 
1151 1151
 }
Please login to merge, or discard this patch.
Spacing   +177 added lines, -177 removed lines patch added patch discarded remove patch
@@ -1,6 +1,6 @@  discard block
 block discarded – undo
1 1
 <?php
2
-if ( ! defined( 'EVENT_ESPRESSO_VERSION' ) ) {
3
-	exit( 'No direct script access allowed' );
2
+if ( ! defined('EVENT_ESPRESSO_VERSION')) {
3
+	exit('No direct script access allowed');
4 4
 }
5 5
 /**
6 6
  * ************************************************************************
@@ -43,8 +43,8 @@  discard block
 block discarded – undo
43 43
 	$action_or_filter = 'action'
44 44
 ) {
45 45
 	$action_or_filter = $action_or_filter === 'action'
46
-		? esc_html__( 'action', 'event_espresso' )
47
-		: esc_html__( 'filter', 'event_espresso' );
46
+		? esc_html__('action', 'event_espresso')
47
+		: esc_html__('filter', 'event_espresso');
48 48
 	EE_Error::doing_it_wrong(
49 49
 		$deprecated_filter,
50 50
 		sprintf(
@@ -68,7 +68,7 @@  discard block
 block discarded – undo
68 68
  * @param \EE_Checkout $checkout
69 69
  * @return string
70 70
  */
71
-function ee_deprecated__registration_checkout__button_text( $submit_button_text, EE_Checkout $checkout ) {
71
+function ee_deprecated__registration_checkout__button_text($submit_button_text, EE_Checkout $checkout) {
72 72
 	// list of old filters
73 73
 	$deprecated_filters = array(
74 74
 		'update_registration_details' => true,
@@ -78,16 +78,16 @@  discard block
 block discarded – undo
78 78
 		'proceed_to' => true,
79 79
 	);
80 80
 	// loop thru and call doing_it_wrong() or remove any that aren't being used
81
-	foreach ( $deprecated_filters as $deprecated_filter => $on ) {
81
+	foreach ($deprecated_filters as $deprecated_filter => $on) {
82 82
 		// was this filter called ?
83
-		if ( has_action( 'FHEE__EED_Single_Page_Checkout__registration_checkout__button_text__' . $deprecated_filter )) {
83
+		if (has_action('FHEE__EED_Single_Page_Checkout__registration_checkout__button_text__'.$deprecated_filter)) {
84 84
 			// only display doing_it_wrong() notice to Event Admins during non-AJAX requests
85
-			if ( EE_Registry::instance()->CAP->current_user_can( 'ee_read_ee', 'hide_doing_it_wrong_for_deprecated_SPCO_filter' ) && ! defined( 'DOING_AJAX' ) ) {
85
+			if (EE_Registry::instance()->CAP->current_user_can('ee_read_ee', 'hide_doing_it_wrong_for_deprecated_SPCO_filter') && ! defined('DOING_AJAX')) {
86 86
 				EE_Error::doing_it_wrong(
87
-					'FHEE__EED_Single_Page_Checkout__registration_checkout__button_text__' . $deprecated_filter,
87
+					'FHEE__EED_Single_Page_Checkout__registration_checkout__button_text__'.$deprecated_filter,
88 88
 					sprintf(
89
-						__( 'The %1$s filter is deprecated.  It *may* work as an attempt to build in backwards compatibility.  However, it is recommended to use the following new filter: %2$s"%3$s" found in "%4$s"', 'event_espresso' ),
90
-						'FHEE__EED_Single_Page_Checkout__registration_checkout__button_text__' . $deprecated_filter,
89
+						__('The %1$s filter is deprecated.  It *may* work as an attempt to build in backwards compatibility.  However, it is recommended to use the following new filter: %2$s"%3$s" found in "%4$s"', 'event_espresso'),
90
+						'FHEE__EED_Single_Page_Checkout__registration_checkout__button_text__'.$deprecated_filter,
91 91
 						'<br />',
92 92
 						'FHEE__EE_SPCO_Reg_Step__set_submit_button_text___submit_button_text',
93 93
 						'/modules/single_page_checkout/inc/EE_SPCO_Reg_Step.class.php'
@@ -96,24 +96,24 @@  discard block
 block discarded – undo
96 96
 				);
97 97
 			}
98 98
 		} else {
99
-			unset( $deprecated_filters[ $deprecated_filter ] );
99
+			unset($deprecated_filters[$deprecated_filter]);
100 100
 		}
101 101
 	}
102
-	if ( ! empty( $deprecated_filters )) {
103
-
104
-		if ( $checkout->current_step->slug() == 'attendee_information' && $checkout->revisit && isset( $deprecated_filters[ 'update_registration_details' ] )) {
105
-			$submit_button_text = apply_filters( 'FHEE__EED_Single_Page_Checkout__registration_checkout__button_text__update_registration_details', $submit_button_text );
106
-		} else if ( $checkout->current_step->slug() == 'payment_options' && $checkout->revisit && isset( $deprecated_filters[ 'process_payment' ] ) ) {
107
-			$submit_button_text = apply_filters( 'FHEE__EED_Single_Page_Checkout__registration_checkout__button_text__process_payment', $submit_button_text );
108
-		} else if ( $checkout->next_step instanceof EE_SPCO_Reg_Step && $checkout->next_step->slug() == 'finalize_registration' && isset( $deprecated_filters[ 'finalize_registration' ] ) ) {
109
-			$submit_button_text = apply_filters( 'FHEE__EED_Single_Page_Checkout__registration_checkout__button_text__finalize_registration', $submit_button_text );
102
+	if ( ! empty($deprecated_filters)) {
103
+
104
+		if ($checkout->current_step->slug() == 'attendee_information' && $checkout->revisit && isset($deprecated_filters['update_registration_details'])) {
105
+			$submit_button_text = apply_filters('FHEE__EED_Single_Page_Checkout__registration_checkout__button_text__update_registration_details', $submit_button_text);
106
+		} else if ($checkout->current_step->slug() == 'payment_options' && $checkout->revisit && isset($deprecated_filters['process_payment'])) {
107
+			$submit_button_text = apply_filters('FHEE__EED_Single_Page_Checkout__registration_checkout__button_text__process_payment', $submit_button_text);
108
+		} else if ($checkout->next_step instanceof EE_SPCO_Reg_Step && $checkout->next_step->slug() == 'finalize_registration' && isset($deprecated_filters['finalize_registration'])) {
109
+			$submit_button_text = apply_filters('FHEE__EED_Single_Page_Checkout__registration_checkout__button_text__finalize_registration', $submit_button_text);
110 110
 		}
111
-		if ( $checkout->next_step instanceof EE_SPCO_Reg_Step ) {
112
-			if ( $checkout->payment_required() && $checkout->next_step->slug() == 'payment_options' && isset( $deprecated_filters[ 'and_proceed_to_payment' ] ) ) {
113
-				$submit_button_text .= apply_filters( 'FHEE__EED_Single_Page_Checkout__registration_checkout__button_text__and_proceed_to_payment', $submit_button_text );
111
+		if ($checkout->next_step instanceof EE_SPCO_Reg_Step) {
112
+			if ($checkout->payment_required() && $checkout->next_step->slug() == 'payment_options' && isset($deprecated_filters['and_proceed_to_payment'])) {
113
+				$submit_button_text .= apply_filters('FHEE__EED_Single_Page_Checkout__registration_checkout__button_text__and_proceed_to_payment', $submit_button_text);
114 114
 			}
115
-			if ( $checkout->next_step->slug() != 'finalize_registration' && ! $checkout->revisit && isset( $deprecated_filters[ 'proceed_to' ] ) ) {
116
-				$submit_button_text = apply_filters( 'FHEE__EED_Single_Page_Checkout__registration_checkout__button_text__proceed_to', $submit_button_text ) . $checkout->next_step->name();
115
+			if ($checkout->next_step->slug() != 'finalize_registration' && ! $checkout->revisit && isset($deprecated_filters['proceed_to'])) {
116
+				$submit_button_text = apply_filters('FHEE__EED_Single_Page_Checkout__registration_checkout__button_text__proceed_to', $submit_button_text).$checkout->next_step->name();
117 117
 			}
118 118
 		}
119 119
 
@@ -121,7 +121,7 @@  discard block
 block discarded – undo
121 121
 	return $submit_button_text;
122 122
 
123 123
 }
124
-add_filter( 'FHEE__EE_SPCO_Reg_Step__set_submit_button_text___submit_button_text', 'ee_deprecated__registration_checkout__button_text', 10, 2 );
124
+add_filter('FHEE__EE_SPCO_Reg_Step__set_submit_button_text___submit_button_text', 'ee_deprecated__registration_checkout__button_text', 10, 2);
125 125
 
126 126
 
127 127
 
@@ -132,16 +132,16 @@  discard block
 block discarded – undo
132 132
  * @param \EE_Checkout $checkout
133 133
  * @param boolean $status_updates
134 134
  */
135
-function ee_deprecated_finalize_transaction( EE_Checkout $checkout, $status_updates ) {
135
+function ee_deprecated_finalize_transaction(EE_Checkout $checkout, $status_updates) {
136 136
 	$action_ref = NULL;
137
-	$action_ref = has_action( 'AHEE__EE_Transaction__finalize__new_transaction' ) ? 'AHEE__EE_Transaction__finalize__new_transaction' : $action_ref;
138
-	$action_ref = has_action( 'AHEE__EE_Transaction__finalize__all_transaction' ) ? 'AHEE__EE_Transaction__finalize__all_transaction' : $action_ref;
139
-	if ( $action_ref ) {
137
+	$action_ref = has_action('AHEE__EE_Transaction__finalize__new_transaction') ? 'AHEE__EE_Transaction__finalize__new_transaction' : $action_ref;
138
+	$action_ref = has_action('AHEE__EE_Transaction__finalize__all_transaction') ? 'AHEE__EE_Transaction__finalize__all_transaction' : $action_ref;
139
+	if ($action_ref) {
140 140
 
141 141
 		EE_Error::doing_it_wrong(
142 142
 			$action_ref,
143 143
 			sprintf(
144
-				__( 'This action is deprecated.  It *may* work as an attempt to build in backwards compatibility.  However, it is recommended to use one of the following new actions: %1$s"%3$s" found in "%2$s" %1$s"%4$s" found in "%2$s" %1$s"%5$s" found in "%2$s" %1$s"%6$s" found in "%2$s"', 'event_espresso' ),
144
+				__('This action is deprecated.  It *may* work as an attempt to build in backwards compatibility.  However, it is recommended to use one of the following new actions: %1$s"%3$s" found in "%2$s" %1$s"%4$s" found in "%2$s" %1$s"%5$s" found in "%2$s" %1$s"%6$s" found in "%2$s"', 'event_espresso'),
145 145
 				'<br />',
146 146
 				'/core/business/EE_Transaction_Processor.class.php',
147 147
 				'AHEE__EE_Transaction_Processor__finalize',
@@ -151,39 +151,39 @@  discard block
 block discarded – undo
151 151
 			),
152 152
 			'4.6.0'
153 153
 		);
154
-		switch ( $action_ref ) {
154
+		switch ($action_ref) {
155 155
 			case 'AHEE__EE_Transaction__finalize__new_transaction' :
156
-				do_action( 'AHEE__EE_Transaction__finalize__new_transaction', $checkout->transaction, $checkout->admin_request );
156
+				do_action('AHEE__EE_Transaction__finalize__new_transaction', $checkout->transaction, $checkout->admin_request);
157 157
 				break;
158 158
 			case 'AHEE__EE_Transaction__finalize__all_transaction' :
159
-				do_action( 'AHEE__EE_Transaction__finalize__new_transaction', $checkout->transaction, array( 'new_reg' => ! $checkout->revisit, 'to_approved' => $status_updates ), $checkout->admin_request );
159
+				do_action('AHEE__EE_Transaction__finalize__new_transaction', $checkout->transaction, array('new_reg' => ! $checkout->revisit, 'to_approved' => $status_updates), $checkout->admin_request);
160 160
 				break;
161 161
 		}
162 162
 	}
163 163
 }
164
-add_action( 'AHEE__EE_SPCO_Reg_Step_Finalize_Registration__process_reg_step__completed', 'ee_deprecated_finalize_transaction', 10, 2 );
164
+add_action('AHEE__EE_SPCO_Reg_Step_Finalize_Registration__process_reg_step__completed', 'ee_deprecated_finalize_transaction', 10, 2);
165 165
 /**
166 166
  * ee_deprecated_finalize_registration
167 167
  *
168 168
  * @param EE_Registration $registration
169 169
  */
170
-function ee_deprecated_finalize_registration( EE_Registration $registration ) {
171
-	$action_ref = has_action( 'AHEE__EE_Registration__finalize__update_and_new_reg' ) ? 'AHEE__EE_Registration__finalize__update_and_new_reg' : NULL;
172
-	if ( $action_ref ) {
170
+function ee_deprecated_finalize_registration(EE_Registration $registration) {
171
+	$action_ref = has_action('AHEE__EE_Registration__finalize__update_and_new_reg') ? 'AHEE__EE_Registration__finalize__update_and_new_reg' : NULL;
172
+	if ($action_ref) {
173 173
 		EE_Error::doing_it_wrong(
174 174
 			$action_ref,
175 175
 			sprintf(
176
-				__( 'This action is deprecated.  It *may* work as an attempt to build in backwards compatibility.  However, it is recommended to use the following new action: %1$s"%3$s" found in "%2$s"', 'event_espresso' ),
176
+				__('This action is deprecated.  It *may* work as an attempt to build in backwards compatibility.  However, it is recommended to use the following new action: %1$s"%3$s" found in "%2$s"', 'event_espresso'),
177 177
 				'<br />',
178 178
 				'/core/business/EE_Registration_Processor.class.php',
179 179
 				'AHEE__EE_Registration_Processor__trigger_registration_status_changed_hook'
180 180
 			),
181 181
 			'4.6.0'
182 182
 		);
183
-		do_action( 'AHEE__EE_Registration__finalize__update_and_new_reg', $registration, ( is_admin() && ! ( defined( 'DOING_AJAX' ) && DOING_AJAX )));
183
+		do_action('AHEE__EE_Registration__finalize__update_and_new_reg', $registration, (is_admin() && ! (defined('DOING_AJAX') && DOING_AJAX)));
184 184
 	}
185 185
 }
186
-add_action( 'AHEE__EE_Registration_Processor__trigger_registration_update_notifications', 'ee_deprecated_finalize_registration', 10, 1 );
186
+add_action('AHEE__EE_Registration_Processor__trigger_registration_update_notifications', 'ee_deprecated_finalize_registration', 10, 1);
187 187
 
188 188
 
189 189
 
@@ -191,7 +191,7 @@  discard block
 block discarded – undo
191 191
  * Called after EED_Module::set_hooks() and EED_Module::set_admin_hooks() was called.
192 192
  * Checks if any deprecated hooks were hooked-into and provide doing_it_wrong messages appropriately.
193 193
  */
194
-function ee_deprecated_hooks(){
194
+function ee_deprecated_hooks() {
195 195
 	/**
196 196
 	 * @var $hooks array where keys are hook names, and their values are array{
197 197
 	 *			@type string $version  when deprecated
@@ -202,25 +202,25 @@  discard block
 block discarded – undo
202 202
 	$hooks = array(
203 203
 		'AHEE__EE_System___do_setup_validations' => array(
204 204
 			'version' => '4.6.0',
205
-			'alternative' => __( 'Instead use "AHEE__EEH_Activation__validate_messages_system" which is called after validating messages (done on every new install, upgrade, reactivation, and downgrade)', 'event_espresso' ),
205
+			'alternative' => __('Instead use "AHEE__EEH_Activation__validate_messages_system" which is called after validating messages (done on every new install, upgrade, reactivation, and downgrade)', 'event_espresso'),
206 206
 			'still_works' => FALSE
207 207
 		)
208 208
 	);
209
-	foreach( $hooks as $name => $deprecation_info ){
210
-		if( has_action( $name ) ){
209
+	foreach ($hooks as $name => $deprecation_info) {
210
+		if (has_action($name)) {
211 211
 			EE_Error::doing_it_wrong(
212 212
 				$name,
213 213
 				sprintf(
214
-					__('This filter is deprecated. %1$s%2$s','event_espresso'),
215
-					$deprecation_info[ 'still_works' ] ?  __('It *may* work as an attempt to build in backwards compatibility.', 'event_espresso') : __( 'It has been completely removed.', 'event_espresso' ),
216
-					isset( $deprecation_info[ 'alternative' ] ) ? $deprecation_info[ 'alternative' ] : __( 'Please read the current EE4 documentation further or contact Support.', 'event_espresso' )
214
+					__('This filter is deprecated. %1$s%2$s', 'event_espresso'),
215
+					$deprecation_info['still_works'] ? __('It *may* work as an attempt to build in backwards compatibility.', 'event_espresso') : __('It has been completely removed.', 'event_espresso'),
216
+					isset($deprecation_info['alternative']) ? $deprecation_info['alternative'] : __('Please read the current EE4 documentation further or contact Support.', 'event_espresso')
217 217
 				),
218
-				isset( $deprecation_info[ 'version' ] ) ? $deprecation_info[ 'version' ] : __( 'recently', 'event_espresso' )
218
+				isset($deprecation_info['version']) ? $deprecation_info['version'] : __('recently', 'event_espresso')
219 219
 			);
220 220
 		}
221 221
 	}
222 222
 }
223
-add_action( 'AHEE__EE_System__set_hooks_for_shortcodes_modules_and_addons', 'ee_deprecated_hooks' );
223
+add_action('AHEE__EE_System__set_hooks_for_shortcodes_modules_and_addons', 'ee_deprecated_hooks');
224 224
 
225 225
 
226 226
 
@@ -231,9 +231,9 @@  discard block
 block discarded – undo
231 231
  * @return boolean
232 232
  */
233 233
 function ee_deprecated_using_old_registration_admin_custom_questions_form_hooks() {
234
-	$in_use =  has_filter( 'FHEE__Registrations_Admin_Page___update_attendee_registration_form__qstns' )
235
-			|| has_action( 'AHEE__Registrations_Admin_Page___save_attendee_registration_form__after_reg_and_attendee_save' );
236
-	if( $in_use ) {
234
+	$in_use = has_filter('FHEE__Registrations_Admin_Page___update_attendee_registration_form__qstns')
235
+			|| has_action('AHEE__Registrations_Admin_Page___save_attendee_registration_form__after_reg_and_attendee_save');
236
+	if ($in_use) {
237 237
 		$msg = __(
238 238
 			'We detected you are using the filter FHEE__Registrations_Admin_Page___update_attendee_registration_form__qstns or AHEE__Registrations_Admin_Page___save_attendee_registration_form__after_reg_and_attendee_save.'
239 239
 			. 'Both of these have been deprecated and should not be used anymore. You should instead use FHEE__EE_Form_Section_Proper___construct__options_array to customize the contents of the form,'
@@ -242,18 +242,18 @@  discard block
 block discarded – undo
242 242
 			'event_espresso' )
243 243
 		;
244 244
 		EE_Error::doing_it_wrong(
245
-			__CLASS__ . '::' . __FUNCTION__,
245
+			__CLASS__.'::'.__FUNCTION__,
246 246
 			$msg,
247 247
 			'4.8.32.rc.000'
248 248
 		);
249 249
 		//it seems the doing_it_wrong messages get output during some hidden html tags, so add an error to make sure this gets noticed
250
-		if ( is_admin() && ! defined( 'DOING_AJAX' ) ) {
251
-			EE_Error::add_error( $msg, __FILE__, __FUNCTION__, __LINE__ );
250
+		if (is_admin() && ! defined('DOING_AJAX')) {
251
+			EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
252 252
 		}
253 253
 	}
254 254
 	return $in_use;
255 255
 }
256
-add_action( 'AHEE__Registrations_Admin_Page___registration_details_metabox__start', 'ee_deprecated_using_old_registration_admin_custom_questions_form_hooks' );
256
+add_action('AHEE__Registrations_Admin_Page___registration_details_metabox__start', 'ee_deprecated_using_old_registration_admin_custom_questions_form_hooks');
257 257
 
258 258
 /**
259 259
  * @deprecated since 4.8.32.rc.000 because it has issues on https://events.codebasehq.com/projects/event-espresso/tickets/9165
@@ -262,34 +262,34 @@  discard block
 block discarded – undo
262 262
  * @param EE_Admin_Page $admin_page
263 263
  * @return void
264 264
  */
265
-function ee_deprecated_update_attendee_registration_form_old( $admin_page ) {
265
+function ee_deprecated_update_attendee_registration_form_old($admin_page) {
266 266
 	//check if the old hooks are in use. If not, do the default
267
-	if( ! ee_deprecated_using_old_registration_admin_custom_questions_form_hooks()
268
-		|| ! $admin_page instanceof EE_Admin_Page ) {
267
+	if ( ! ee_deprecated_using_old_registration_admin_custom_questions_form_hooks()
268
+		|| ! $admin_page instanceof EE_Admin_Page) {
269 269
 		return;
270 270
 	}
271 271
 	$req_data = $admin_page->get_request_data();
272
-	$qstns = isset( $req_data['qstn'] ) ? $req_data['qstn'] : FALSE;
273
-	$REG_ID = isset( $req_data['_REG_ID'] ) ? absint( $req_data['_REG_ID'] ) : FALSE;
274
-	$qstns = apply_filters( 'FHEE__Registrations_Admin_Page___update_attendee_registration_form__qstns', $qstns );
275
-	if ( ! $REG_ID || ! $qstns ) {
276
-		EE_Error::add_error( __('An error occurred. No registration ID and/or registration questions were received.', 'event_espresso'), __FILE__, __FUNCTION__, __LINE__ );
272
+	$qstns = isset($req_data['qstn']) ? $req_data['qstn'] : FALSE;
273
+	$REG_ID = isset($req_data['_REG_ID']) ? absint($req_data['_REG_ID']) : FALSE;
274
+	$qstns = apply_filters('FHEE__Registrations_Admin_Page___update_attendee_registration_form__qstns', $qstns);
275
+	if ( ! $REG_ID || ! $qstns) {
276
+		EE_Error::add_error(__('An error occurred. No registration ID and/or registration questions were received.', 'event_espresso'), __FILE__, __FUNCTION__, __LINE__);
277 277
 	}
278 278
 	$success = TRUE;
279 279
 
280 280
 	// allow others to get in on this awesome fun   :D
281
-	do_action( 'AHEE__Registrations_Admin_Page___save_attendee_registration_form__after_reg_and_attendee_save', $REG_ID, $qstns );
281
+	do_action('AHEE__Registrations_Admin_Page___save_attendee_registration_form__after_reg_and_attendee_save', $REG_ID, $qstns);
282 282
 	// loop thru questions... FINALLY!!!
283 283
 
284
-	foreach ( $qstns as $QST_ID => $qstn ) {
284
+	foreach ($qstns as $QST_ID => $qstn) {
285 285
 		//if $qstn isn't an array then it doesn't already have an answer, so let's create the answer
286
-		if ( !is_array($qstn) ) {
287
-			$success = $this->_save_new_answer( $REG_ID, $QST_ID, $qstn);
286
+		if ( ! is_array($qstn)) {
287
+			$success = $this->_save_new_answer($REG_ID, $QST_ID, $qstn);
288 288
 			continue;
289 289
 		}
290 290
 
291 291
 
292
-		foreach ( $qstn as $ANS_ID => $ANS_value ) {
292
+		foreach ($qstn as $ANS_ID => $ANS_value) {
293 293
 			//get answer
294 294
 			$query_params = array(
295 295
 				0 => array(
@@ -300,7 +300,7 @@  discard block
 block discarded – undo
300 300
 				);
301 301
 			$answer = EEM_Answer::instance()->get_one($query_params);
302 302
 			//this MAY be an array but NOT have an answer because its multi select.  If so then we need to create the answer
303
-			if ( ! $answer instanceof EE_Answer ) {
303
+			if ( ! $answer instanceof EE_Answer) {
304 304
 				$set_values = array(
305 305
 					'QST_ID' => $QST_ID,
306 306
 					'REG_ID' => $REG_ID,
@@ -315,11 +315,11 @@  discard block
 block discarded – undo
315 315
 		}
316 316
 	}
317 317
 	$what = __('Registration Form', 'event_espresso');
318
-	$route = $REG_ID ? array( 'action' => 'view_registration', '_REG_ID' => $REG_ID ) : array( 'action' => 'default' );
319
-	$admin_page->redirect_after_action( $success, $what, __('updated', 'event_espresso'), $route );
318
+	$route = $REG_ID ? array('action' => 'view_registration', '_REG_ID' => $REG_ID) : array('action' => 'default');
319
+	$admin_page->redirect_after_action($success, $what, __('updated', 'event_espresso'), $route);
320 320
 	exit;
321 321
 }
322
-add_action( 'AHEE__Registrations_Admin_Page___update_attendee_registration_form__start', 'ee_deprecated_update_attendee_registration_form_old', 10, 1 );
322
+add_action('AHEE__Registrations_Admin_Page___update_attendee_registration_form__start', 'ee_deprecated_update_attendee_registration_form_old', 10, 1);
323 323
 /**
324 324
  * Render the registration admin page's custom questions area in the old fashion
325 325
  * and firing the old hooks. When this method is removed, we can probably also
@@ -332,31 +332,31 @@  discard block
 block discarded – undo
332 332
  * @return bool
333 333
  * @throws \EE_Error
334 334
  */
335
-function ee_deprecated_reg_questions_meta_box_old( $do_default_action, $admin_page, $registration ) {
335
+function ee_deprecated_reg_questions_meta_box_old($do_default_action, $admin_page, $registration) {
336 336
 	//check if the old hooks are in use. If not, do the default
337
-	if( ! ee_deprecated_using_old_registration_admin_custom_questions_form_hooks()
338
-		|| ! $admin_page instanceof EE_Admin_Page ) {
337
+	if ( ! ee_deprecated_using_old_registration_admin_custom_questions_form_hooks()
338
+		|| ! $admin_page instanceof EE_Admin_Page) {
339 339
 		return $do_default_action;
340 340
 	}
341
-	add_filter( 'FHEE__EEH_Form_Fields__generate_question_groups_html__before_question_group_questions', array( $admin_page, 'form_before_question_group' ), 10, 1 );
342
-	add_filter( 'FHEE__EEH_Form_Fields__generate_question_groups_html__after_question_group_questions', array( $admin_page, 'form_after_question_group' ), 10, 1 );
343
-	add_filter( 'FHEE__EEH_Form_Fields__label_html', array( $admin_page, 'form_form_field_label_wrap' ), 10, 1 );
344
-	add_filter( 'FHEE__EEH_Form_Fields__input_html', array( $admin_page, 'form_form_field_input__wrap' ), 10, 1 );
341
+	add_filter('FHEE__EEH_Form_Fields__generate_question_groups_html__before_question_group_questions', array($admin_page, 'form_before_question_group'), 10, 1);
342
+	add_filter('FHEE__EEH_Form_Fields__generate_question_groups_html__after_question_group_questions', array($admin_page, 'form_after_question_group'), 10, 1);
343
+	add_filter('FHEE__EEH_Form_Fields__label_html', array($admin_page, 'form_form_field_label_wrap'), 10, 1);
344
+	add_filter('FHEE__EEH_Form_Fields__input_html', array($admin_page, 'form_form_field_input__wrap'), 10, 1);
345 345
 
346
-	$question_groups = EEM_Event::instance()->assemble_array_of_groups_questions_and_options( $registration, $registration->get('EVT_ID') );
346
+	$question_groups = EEM_Event::instance()->assemble_array_of_groups_questions_and_options($registration, $registration->get('EVT_ID'));
347 347
 
348
-	EE_Registry::instance()->load_helper( 'Form_Fields' );
348
+	EE_Registry::instance()->load_helper('Form_Fields');
349 349
 	$template_args = array(
350
-		'att_questions' => EEH_Form_Fields::generate_question_groups_html( $question_groups ),
350
+		'att_questions' => EEH_Form_Fields::generate_question_groups_html($question_groups),
351 351
 		'reg_questions_form_action' => 'edit_registration',
352 352
 		'REG_ID' => $registration->ID()
353 353
 	);
354
-	$template_path = REG_TEMPLATE_PATH . 'reg_admin_details_main_meta_box_reg_questions.template.php';
355
-	echo EEH_Template::display_template( $template_path, $template_args, TRUE );
354
+	$template_path = REG_TEMPLATE_PATH.'reg_admin_details_main_meta_box_reg_questions.template.php';
355
+	echo EEH_Template::display_template($template_path, $template_args, TRUE);
356 356
 	//indicate that we should not do the default admin page code
357 357
 	return false;
358 358
 }
359
-add_action( 'FHEE__Registrations_Admin_Page___reg_questions_meta_box__do_default', 'ee_deprecated_reg_questions_meta_box_old', 10, 3 );
359
+add_action('FHEE__Registrations_Admin_Page___reg_questions_meta_box__do_default', 'ee_deprecated_reg_questions_meta_box_old', 10, 3);
360 360
 
361 361
 
362 362
 
@@ -397,9 +397,9 @@  discard block
 block discarded – undo
397 397
 			'4.9.0'
398 398
 		);
399 399
 		/** @var EE_Message_Resource_Manager $message_resource_manager */
400
-		$message_resource_manager = EE_Registry::instance()->load_lib( 'Message_Resource_Manager' );
401
-		$messenger = $message_resource_manager->get_messenger( $messenger_name );
402
-		$message_type = $message_resource_manager->get_message_type( $message_type_name );
400
+		$message_resource_manager = EE_Registry::instance()->load_lib('Message_Resource_Manager');
401
+		$messenger = $message_resource_manager->get_messenger($messenger_name);
402
+		$message_type = $message_resource_manager->get_message_type($message_type_name);
403 403
 		return EE_Registry::instance()->load_lib(
404 404
 			'Messages_Template_Defaults',
405 405
 			array(
@@ -464,15 +464,15 @@  discard block
 block discarded – undo
464 464
 	/**
465 465
 	 * @param string $method
466 466
 	 */
467
-	public function _class_is_deprecated( $method ) {
467
+	public function _class_is_deprecated($method) {
468 468
 		EE_Error::doing_it_wrong(
469
-			'EE_messages::' . $method,
470
-			__( 'EE_messages has been deprecated.  Please use EE_Message_Resource_Manager instead.' ),
469
+			'EE_messages::'.$method,
470
+			__('EE_messages has been deprecated.  Please use EE_Message_Resource_Manager instead.'),
471 471
 			'4.9.0',
472 472
 			'4.10.0.p'
473 473
 		);
474 474
 		// Please use EE_Message_Resource_Manager instead
475
-		$this->_message_resource_manager = EE_Registry::instance()->load_lib( 'Message_Resource_Manager' );
475
+		$this->_message_resource_manager = EE_Registry::instance()->load_lib('Message_Resource_Manager');
476 476
 	}
477 477
 
478 478
 
@@ -482,10 +482,10 @@  discard block
 block discarded – undo
482 482
 	 * @param string $messenger_name
483 483
 	 * @return boolean TRUE if it was PREVIOUSLY active, and FALSE if it was previously inactive
484 484
 	 */
485
-	public function ensure_messenger_is_active( $messenger_name ) {
485
+	public function ensure_messenger_is_active($messenger_name) {
486 486
 		// EE_messages has been deprecated
487
-		$this->_class_is_deprecated( __FUNCTION__ );
488
-		return $this->_message_resource_manager->ensure_messenger_is_active( $messenger_name );
487
+		$this->_class_is_deprecated(__FUNCTION__);
488
+		return $this->_message_resource_manager->ensure_messenger_is_active($messenger_name);
489 489
 	}
490 490
 
491 491
 
@@ -497,10 +497,10 @@  discard block
 block discarded – undo
497 497
 	 * @return bool true if it got activated (or was active) and false if not.
498 498
 	 * @throws \EE_Error
499 499
 	 */
500
-	public function ensure_message_type_is_active( $message_type, $messenger ) {
500
+	public function ensure_message_type_is_active($message_type, $messenger) {
501 501
 		// EE_messages has been deprecated
502
-		$this->_class_is_deprecated( __FUNCTION__ );
503
-		return $this->_message_resource_manager->ensure_message_type_is_active( $message_type, $messenger );
502
+		$this->_class_is_deprecated(__FUNCTION__);
503
+		return $this->_message_resource_manager->ensure_message_type_is_active($message_type, $messenger);
504 504
 	}
505 505
 
506 506
 
@@ -513,10 +513,10 @@  discard block
 block discarded – undo
513 513
 	 *                                            they are already setup.)
514 514
 	 * @return boolean an array of generated templates or false if nothing generated/activated.
515 515
 	 */
516
-	public function activate_messenger( $messenger_name, $mts_to_activate = array() ) {
516
+	public function activate_messenger($messenger_name, $mts_to_activate = array()) {
517 517
 		// EE_messages has been deprecated
518
-		$this->_class_is_deprecated( __FUNCTION__ );
519
-		return $this->_message_resource_manager->activate_messenger( $messenger_name, $mts_to_activate );
518
+		$this->_class_is_deprecated(__FUNCTION__);
519
+		return $this->_message_resource_manager->activate_messenger($messenger_name, $mts_to_activate);
520 520
 	}
521 521
 
522 522
 
@@ -528,10 +528,10 @@  discard block
 block discarded – undo
528 528
 	 *
529 529
 	 * @return bool true is a generating messenger and can be sent OR FALSE meaning cannot send.
530 530
 	 */
531
-	public function is_generating_messenger_and_active( EE_messenger $messenger, EE_message_type $message_type ) {
531
+	public function is_generating_messenger_and_active(EE_messenger $messenger, EE_message_type $message_type) {
532 532
 		// EE_messages has been deprecated
533
-		$this->_class_is_deprecated( __FUNCTION__ );
534
-		return $this->_message_resource_manager->is_generating_messenger_and_active( $messenger, $message_type );
533
+		$this->_class_is_deprecated(__FUNCTION__);
534
+		return $this->_message_resource_manager->is_generating_messenger_and_active($messenger, $message_type);
535 535
 	}
536 536
 
537 537
 
@@ -541,10 +541,10 @@  discard block
 block discarded – undo
541 541
 	 * @param string $messenger
542 542
 	 * @return EE_messenger | null
543 543
 	 */
544
-	public function get_messenger_if_active( $messenger ) {
544
+	public function get_messenger_if_active($messenger) {
545 545
 		// EE_messages has been deprecated
546
-		$this->_class_is_deprecated( __FUNCTION__ );
547
-		return $this->_message_resource_manager->get_active_messenger( $messenger );
546
+		$this->_class_is_deprecated(__FUNCTION__);
547
+		return $this->_message_resource_manager->get_active_messenger($messenger);
548 548
 	}
549 549
 
550 550
 
@@ -565,9 +565,9 @@  discard block
 block discarded – undo
565 565
 	 *                  'message_type' => null
566 566
 	 *                  )
567 567
 	 */
568
-	public function validate_for_use( EE_Message $message ) {
568
+	public function validate_for_use(EE_Message $message) {
569 569
 		// EE_messages has been deprecated
570
-		$this->_class_is_deprecated( __FUNCTION__ );
570
+		$this->_class_is_deprecated(__FUNCTION__);
571 571
 		return array(
572 572
 			'messenger'    => $message->messenger_object(),
573 573
 			'message_type' => $message->message_type_object(),
@@ -595,41 +595,41 @@  discard block
 block discarded – undo
595 595
 		$send = true
596 596
 	) {
597 597
 		// EE_messages has been deprecated
598
-		$this->_class_is_deprecated( __FUNCTION__ );
598
+		$this->_class_is_deprecated(__FUNCTION__);
599 599
 		/** @type EE_Messages_Processor $processor */
600
-		$processor = EE_Registry::instance()->load_lib( 'Messages_Processor' );
600
+		$processor = EE_Registry::instance()->load_lib('Messages_Processor');
601 601
 		$error = false;
602 602
 		//try to intelligently determine what method we'll call based on the incoming data.
603 603
 		//if generating and sending are different then generate and send immediately.
604
-		if ( ! empty( $sending_messenger ) && $sending_messenger != $generating_messenger && $send ) {
604
+		if ( ! empty($sending_messenger) && $sending_messenger != $generating_messenger && $send) {
605 605
 			//in the legacy system, when generating and sending were different, that means all the
606 606
 			//vars are already in the request object.  So let's just use that.
607 607
 			try {
608 608
 				/** @type EE_Message_To_Generate_From_Request $mtg */
609
-				$mtg = EE_Registry::instance()->load_lib( 'Message_To_Generate_From_Request' );
610
-				$processor->generate_and_send_now( $mtg );
611
-			} catch ( EE_Error $e ) {
609
+				$mtg = EE_Registry::instance()->load_lib('Message_To_Generate_From_Request');
610
+				$processor->generate_and_send_now($mtg);
611
+			} catch (EE_Error $e) {
612 612
 				$error_msg = __(
613 613
 					'Please note that a system message failed to send due to a technical issue.',
614 614
 					'event_espresso'
615 615
 				);
616 616
 				// add specific message for developers if WP_DEBUG in on
617
-				$error_msg .= '||' . $e->getMessage();
618
-				EE_Error::add_error( $error_msg, __FILE__, __FUNCTION__, __LINE__ );
617
+				$error_msg .= '||'.$e->getMessage();
618
+				EE_Error::add_error($error_msg, __FILE__, __FUNCTION__, __LINE__);
619 619
 				$error = true;
620 620
 			}
621 621
 		} else {
622
-			$processor->generate_for_all_active_messengers( $type, $vars, $send );
622
+			$processor->generate_for_all_active_messengers($type, $vars, $send);
623 623
 			//let's find out if there were any errors and how many successfully were queued.
624 624
 			$count_errors = $processor->get_queue()->count_STS_in_queue(
625
-				array( EEM_Message::status_failed, EEM_Message::status_debug_only )
625
+				array(EEM_Message::status_failed, EEM_Message::status_debug_only)
626 626
 			);
627
-			$count_queued = $processor->get_queue()->count_STS_in_queue( EEM_Message::status_incomplete );
628
-			$count_retry = $processor->get_queue()->count_STS_in_queue( EEM_Message::status_retry );
627
+			$count_queued = $processor->get_queue()->count_STS_in_queue(EEM_Message::status_incomplete);
628
+			$count_retry = $processor->get_queue()->count_STS_in_queue(EEM_Message::status_retry);
629 629
 			$count_errors = $count_errors + $count_retry;
630
-			if ( $count_errors > 0 ) {
630
+			if ($count_errors > 0) {
631 631
 				$error = true;
632
-				if ( $count_errors > 1 && $count_retry > 1 && $count_queued > 1 ) {
632
+				if ($count_errors > 1 && $count_retry > 1 && $count_queued > 1) {
633 633
 					$message = sprintf(
634 634
 						__(
635 635
 							'There were %d errors and %d messages successfully queued for generation and sending',
@@ -638,7 +638,7 @@  discard block
 block discarded – undo
638 638
 						$count_errors,
639 639
 						$count_queued
640 640
 					);
641
-				} elseif ( $count_errors > 1 && $count_queued === 1 ) {
641
+				} elseif ($count_errors > 1 && $count_queued === 1) {
642 642
 					$message = sprintf(
643 643
 						__(
644 644
 							'There were %d errors and %d message successfully queued for generation.',
@@ -647,7 +647,7 @@  discard block
 block discarded – undo
647 647
 						$count_errors,
648 648
 						$count_queued
649 649
 					);
650
-				} elseif ( $count_errors === 1 && $count_queued > 1 ) {
650
+				} elseif ($count_errors === 1 && $count_queued > 1) {
651 651
 					$message = sprintf(
652 652
 						__(
653 653
 							'There was %d error and %d messages successfully queued for generation.',
@@ -665,9 +665,9 @@  discard block
 block discarded – undo
665 665
 						$count_errors
666 666
 					);
667 667
 				}
668
-				EE_Error::add_error( $message, __FILE__, __FUNCTION__, __LINE__ );
668
+				EE_Error::add_error($message, __FILE__, __FUNCTION__, __LINE__);
669 669
 			} else {
670
-				if ( $count_queued === 1 ) {
670
+				if ($count_queued === 1) {
671 671
 					$message = sprintf(
672 672
 						__(
673 673
 							'%d message successfully queued for generation.',
@@ -684,18 +684,18 @@  discard block
 block discarded – undo
684 684
 						$count_queued
685 685
 					);
686 686
 				}
687
-				EE_Error::add_success( $message );
687
+				EE_Error::add_success($message);
688 688
 			}
689 689
 		}
690 690
 		//if no error then return the generated message(s).
691
-		if ( ! $error && ! $send ) {
692
-			$generated_queue = $processor->generate_queue( false );
691
+		if ( ! $error && ! $send) {
692
+			$generated_queue = $processor->generate_queue(false);
693 693
 			//get message and return.
694 694
 			$generated_queue->get_message_repository()->rewind();
695 695
 			$messages = array();
696
-			while ( $generated_queue->get_message_repository()->valid() ) {
696
+			while ($generated_queue->get_message_repository()->valid()) {
697 697
 				$message = $generated_queue->get_message_repository()->current();
698
-				if ( $message instanceof EE_Message ) {
698
+				if ($message instanceof EE_Message) {
699 699
 					//set properties that might be expected by add-ons (backward compat)
700 700
 					$message->content = $message->content();
701 701
 					$message->template_pack = $message->get_template_pack();
@@ -720,10 +720,10 @@  discard block
 block discarded – undo
720 720
 	 * @param bool    $send      true we will do a test send using the messenger delivery, false we just do a regular preview
721 721
 	 * @return string          The body of the message.
722 722
 	 */
723
-	public function preview_message( $type, $context, $messenger, $send = false ) {
723
+	public function preview_message($type, $context, $messenger, $send = false) {
724 724
 		// EE_messages has been deprecated
725
-		$this->_class_is_deprecated( __FUNCTION__ );
726
-		return EED_Messages::preview_message( $type, $context, $messenger, $send );
725
+		$this->_class_is_deprecated(__FUNCTION__);
726
+		return EED_Messages::preview_message($type, $context, $messenger, $send);
727 727
 	}
728 728
 
729 729
 
@@ -737,14 +737,14 @@  discard block
 block discarded – undo
737 737
 	 *
738 738
 	 * @return bool          success or fail.
739 739
 	 */
740
-	public function send_message_with_messenger_only( $messenger, $message_type, $message ) {
740
+	public function send_message_with_messenger_only($messenger, $message_type, $message) {
741 741
 		// EE_messages has been deprecated
742
-		$this->_class_is_deprecated( __FUNCTION__ );
742
+		$this->_class_is_deprecated(__FUNCTION__);
743 743
 		//setup for sending to new method.
744 744
 		/** @type EE_Messages_Queue $queue */
745
-		$queue = EE_Registry::instance()->load_lib( 'Messages_Queue' );
745
+		$queue = EE_Registry::instance()->load_lib('Messages_Queue');
746 746
 		//make sure we have a proper message object
747
-		if ( ! $message instanceof EE_Message && is_object( $message ) && isset( $message->content ) ) {
747
+		if ( ! $message instanceof EE_Message && is_object($message) && isset($message->content)) {
748 748
 			$msg = EE_Message_Factory::create(
749 749
 				array(
750 750
 					'MSG_messenger'    => $messenger,
@@ -756,15 +756,15 @@  discard block
 block discarded – undo
756 756
 		} else {
757 757
 			$msg = $message;
758 758
 		}
759
-		if ( ! $msg instanceof EE_Message ) {
759
+		if ( ! $msg instanceof EE_Message) {
760 760
 			return false;
761 761
 		}
762 762
 		//make sure any content in a content property (if not empty) is set on the MSG_content.
763
-		if ( ! empty( $msg->content ) ) {
764
-			$msg->set( 'MSG_content', $msg->content );
763
+		if ( ! empty($msg->content)) {
764
+			$msg->set('MSG_content', $msg->content);
765 765
 		}
766
-		$queue->add( $msg );
767
-		return EED_Messages::send_message_with_messenger_only( $messenger, $message_type, $queue );
766
+		$queue->add($msg);
767
+		return EED_Messages::send_message_with_messenger_only($messenger, $message_type, $queue);
768 768
 	}
769 769
 
770 770
 
@@ -778,11 +778,11 @@  discard block
 block discarded – undo
778 778
 	 * @return array|object if creation is successful then we return an array of info, otherwise an error_object is returned.
779 779
 	 * @throws \EE_Error
780 780
 	 */
781
-	public function create_new_templates( $messenger, $message_type, $GRP_ID = 0, $is_global = false ) {
781
+	public function create_new_templates($messenger, $message_type, $GRP_ID = 0, $is_global = false) {
782 782
 		// EE_messages has been deprecated
783
-		$this->_class_is_deprecated( __FUNCTION__ );
784
-		EE_Registry::instance()->load_helper( 'MSG_Template' );
785
-		return EEH_MSG_Template::create_new_templates( $messenger, $message_type, $GRP_ID, $is_global );
783
+		$this->_class_is_deprecated(__FUNCTION__);
784
+		EE_Registry::instance()->load_helper('MSG_Template');
785
+		return EEH_MSG_Template::create_new_templates($messenger, $message_type, $GRP_ID, $is_global);
786 786
 	}
787 787
 
788 788
 
@@ -793,11 +793,11 @@  discard block
 block discarded – undo
793 793
 	 * @param  string $message_type_name name of EE_message_type
794 794
 	 * @return array
795 795
 	 */
796
-	public function get_fields( $messenger_name, $message_type_name ) {
796
+	public function get_fields($messenger_name, $message_type_name) {
797 797
 		// EE_messages has been deprecated
798
-		$this->_class_is_deprecated( __FUNCTION__ );
799
-		EE_Registry::instance()->load_helper( 'MSG_Template' );
800
-		return EEH_MSG_Template::get_fields( $messenger_name, $message_type_name );
798
+		$this->_class_is_deprecated(__FUNCTION__);
799
+		EE_Registry::instance()->load_helper('MSG_Template');
800
+		return EEH_MSG_Template::get_fields($messenger_name, $message_type_name);
801 801
 	}
802 802
 
803 803
 
@@ -811,13 +811,13 @@  discard block
 block discarded – undo
811 811
 	 * @return array                    multidimensional array of messenger and message_type objects
812 812
 	 *                                    (messengers index, and message_type index);
813 813
 	 */
814
-	public function get_installed( $type = 'all', $skip_cache = false ) {
814
+	public function get_installed($type = 'all', $skip_cache = false) {
815 815
 		// EE_messages has been deprecated
816
-		$this->_class_is_deprecated( __FUNCTION__ );
817
-		if ( $skip_cache ) {
816
+		$this->_class_is_deprecated(__FUNCTION__);
817
+		if ($skip_cache) {
818 818
 			$this->_message_resource_manager->reset_active_messengers_and_message_types();
819 819
 		}
820
-		switch ( $type ) {
820
+		switch ($type) {
821 821
 			case 'messengers' :
822 822
 				return array(
823 823
 					'messenger' => $this->_message_resource_manager->installed_messengers(),
@@ -846,7 +846,7 @@  discard block
 block discarded – undo
846 846
 	 */
847 847
 	public function get_active_messengers() {
848 848
 		// EE_messages has been deprecated
849
-		$this->_class_is_deprecated( __FUNCTION__ );
849
+		$this->_class_is_deprecated(__FUNCTION__);
850 850
 		return $this->_message_resource_manager->active_messengers();
851 851
 	}
852 852
 
@@ -858,7 +858,7 @@  discard block
 block discarded – undo
858 858
 	 */
859 859
 	public function get_active_message_types() {
860 860
 		// EE_messages has been deprecated
861
-		$this->_class_is_deprecated( __FUNCTION__ );
861
+		$this->_class_is_deprecated(__FUNCTION__);
862 862
 		return $this->_message_resource_manager->list_of_active_message_types();
863 863
 	}
864 864
 
@@ -870,7 +870,7 @@  discard block
 block discarded – undo
870 870
 	 */
871 871
 	public function get_active_message_type_objects() {
872 872
 		// EE_messages has been deprecated
873
-		$this->_class_is_deprecated( __FUNCTION__ );
873
+		$this->_class_is_deprecated(__FUNCTION__);
874 874
 		return $this->_message_resource_manager->get_active_message_type_objects();
875 875
 	}
876 876
 
@@ -882,10 +882,10 @@  discard block
 block discarded – undo
882 882
 	 * @param string $messenger The messenger being checked
883 883
 	 * @return EE_message_type[]    (or empty array if none present)
884 884
 	 */
885
-	public function get_active_message_types_per_messenger( $messenger ) {
885
+	public function get_active_message_types_per_messenger($messenger) {
886 886
 		// EE_messages has been deprecated
887
-		$this->_class_is_deprecated( __FUNCTION__ );
888
-		return $this->_message_resource_manager->get_active_message_types_for_messenger( $messenger );
887
+		$this->_class_is_deprecated(__FUNCTION__);
888
+		return $this->_message_resource_manager->get_active_message_types_for_messenger($messenger);
889 889
 	}
890 890
 
891 891
 
@@ -896,10 +896,10 @@  discard block
 block discarded – undo
896 896
 	 * @param string $message_type The string should correspond to a message type.
897 897
 	 * @return EE_message_type|null
898 898
 	 */
899
-	public function get_active_message_type( $messenger, $message_type ) {
899
+	public function get_active_message_type($messenger, $message_type) {
900 900
 		// EE_messages has been deprecated
901
-		$this->_class_is_deprecated( __FUNCTION__ );
902
-		return $this->_message_resource_manager->get_active_message_type_for_messenger( $messenger, $message_type );
901
+		$this->_class_is_deprecated(__FUNCTION__);
902
+		return $this->_message_resource_manager->get_active_message_type_for_messenger($messenger, $message_type);
903 903
 	}
904 904
 
905 905
 
@@ -910,7 +910,7 @@  discard block
 block discarded – undo
910 910
 	 */
911 911
 	public function get_installed_message_types() {
912 912
 		// EE_messages has been deprecated
913
-		$this->_class_is_deprecated( __FUNCTION__ );
913
+		$this->_class_is_deprecated(__FUNCTION__);
914 914
 		return $this->_message_resource_manager->installed_message_types();
915 915
 	}
916 916
 
@@ -922,7 +922,7 @@  discard block
 block discarded – undo
922 922
 	 */
923 923
 	public function get_installed_messengers() {
924 924
 		// EE_messages has been deprecated
925
-		$this->_class_is_deprecated( __FUNCTION__ );
925
+		$this->_class_is_deprecated(__FUNCTION__);
926 926
 		return $this->_message_resource_manager->installed_messengers();
927 927
 	}
928 928
 
@@ -933,10 +933,10 @@  discard block
 block discarded – undo
933 933
 	 * @param   bool $slugs_only Whether to return an array of just slugs and labels (true) or all contexts indexed by message type.
934 934
 	 * @return array
935 935
 	 */
936
-	public function get_all_contexts( $slugs_only = true ) {
936
+	public function get_all_contexts($slugs_only = true) {
937 937
 		// EE_messages has been deprecated
938
-		$this->_class_is_deprecated( __FUNCTION__ );
939
-		return $this->_message_resource_manager->get_all_contexts( $slugs_only );
938
+		$this->_class_is_deprecated(__FUNCTION__);
939
+		return $this->_message_resource_manager->get_all_contexts($slugs_only);
940 940
 	}
941 941
 
942 942
 
@@ -995,7 +995,7 @@  discard block
 block discarded – undo
995 995
 add_filter(
996 996
 	'FHEE__EventEspresso_modules_events_archive_EventsArchiveIframe__display__css',
997 997
 	function($event_list_iframe_css) {
998
-		if ( ! has_filter( 'FHEE__EventsArchiveIframe__event_list_iframe__css' )) {
998
+		if ( ! has_filter('FHEE__EventsArchiveIframe__event_list_iframe__css')) {
999 999
 			return $event_list_iframe_css;
1000 1000
 		}
1001 1001
 		deprecated_espresso_action_or_filter_doing_it_wrong(
@@ -1015,7 +1015,7 @@  discard block
 block discarded – undo
1015 1015
 add_filter(
1016 1016
 	'FHEE__EventEspresso_modules_events_archive_EventsArchiveIframe__display__js',
1017 1017
 	function($event_list_iframe_js) {
1018
-		if ( ! has_filter( 'FHEE__EED_Ticket_Selector__ticket_selector_iframe__js' )) {
1018
+		if ( ! has_filter('FHEE__EED_Ticket_Selector__ticket_selector_iframe__js')) {
1019 1019
 			return $event_list_iframe_js;
1020 1020
 		}
1021 1021
 		deprecated_espresso_action_or_filter_doing_it_wrong(
@@ -1035,7 +1035,7 @@  discard block
 block discarded – undo
1035 1035
 add_filter(
1036 1036
 	'FHEE_EventEspresso_core_services_commands_attendee_CreateAttendeeCommandHandler__findExistingAttendee__existing_attendee',
1037 1037
 	function($existing_attendee, $registration, $attendee_data) {
1038
-		if ( ! has_filter( 'FHEE_EE_Single_Page_Checkout__save_registration_items__find_existing_attendee' )) {
1038
+		if ( ! has_filter('FHEE_EE_Single_Page_Checkout__save_registration_items__find_existing_attendee')) {
1039 1039
 			return $existing_attendee;
1040 1040
 		}
1041 1041
 		deprecated_espresso_action_or_filter_doing_it_wrong(
@@ -1051,7 +1051,7 @@  discard block
 block discarded – undo
1051 1051
             $existing_attendee, $registration, $attendee_data
1052 1052
         );
1053 1053
 	},
1054
-    10,3
1054
+    10, 3
1055 1055
 );
1056 1056
 
1057 1057
 
@@ -1117,7 +1117,7 @@  discard block
 block discarded – undo
1117 1117
      */
1118 1118
     public function event_list_title($event_list_title = '')
1119 1119
     {
1120
-        if (! empty($this->title)) {
1120
+        if ( ! empty($this->title)) {
1121 1121
             return $this->title;
1122 1122
         }
1123 1123
         return $event_list_title;
Please login to merge, or discard this patch.
core/db_classes/EE_Registration.class.php 1 patch
Indentation   +1685 added lines, -1685 removed lines patch added patch discarded remove patch
@@ -1,7 +1,7 @@  discard block
 block discarded – undo
1 1
 <?php use EventEspresso\core\exceptions\EntityNotFoundException;
2 2
 
3 3
 if (! defined('EVENT_ESPRESSO_VERSION')) {
4
-    exit('No direct script access allowed');
4
+	exit('No direct script access allowed');
5 5
 }
6 6
 
7 7
 /**
@@ -15,1690 +15,1690 @@  discard block
 block discarded – undo
15 15
 {
16 16
 
17 17
 
18
-    /**
19
-     * Used to reference when a registration has never been checked in.
20
-     *
21
-     * @type int
22
-     */
23
-    const checkin_status_never = 2;
24
-
25
-    /**
26
-     * Used to reference when a registration has been checked in.
27
-     *
28
-     * @type int
29
-     */
30
-    const checkin_status_in = 1;
31
-
32
-
33
-    /**
34
-     * Used to reference when a registration has been checked out.
35
-     *
36
-     * @type int
37
-     */
38
-    const checkin_status_out = 0;
39
-
40
-
41
-    /**
42
-     * extra meta key for tracking reg status os trashed registrations
43
-     *
44
-     * @type string
45
-     */
46
-    const PRE_TRASH_REG_STATUS_KEY = 'pre_trash_registration_status';
47
-
48
-
49
-    /**
50
-     * extra meta key for tracking if registration has reserved ticket
51
-     *
52
-     * @type string
53
-     */
54
-    const HAS_RESERVED_TICKET_KEY = 'has_reserved_ticket';
55
-
56
-
57
-    /**
58
-     * @param array  $props_n_values          incoming values
59
-     * @param string $timezone                incoming timezone (if not set the timezone set for the website will be
60
-     *                                        used.)
61
-     * @param array  $date_formats            incoming date_formats in an array where the first value is the
62
-     *                                        date_format and the second value is the time format
63
-     * @return EE_Registration
64
-     */
65
-    public static function new_instance($props_n_values = array(), $timezone = null, $date_formats = array())
66
-    {
67
-        $has_object = parent::_check_for_object($props_n_values, __CLASS__, $timezone, $date_formats);
68
-        return $has_object ? $has_object : new self($props_n_values, false, $timezone, $date_formats);
69
-    }
70
-
71
-
72
-    /**
73
-     * @param array  $props_n_values  incoming values from the database
74
-     * @param string $timezone        incoming timezone as set by the model.  If not set the timezone for
75
-     *                                the website will be used.
76
-     * @return EE_Registration
77
-     */
78
-    public static function new_instance_from_db($props_n_values = array(), $timezone = null)
79
-    {
80
-        return new self($props_n_values, true, $timezone);
81
-    }
82
-
83
-
84
-    /**
85
-     *        Set Event ID
86
-     *
87
-     * @param        int $EVT_ID Event ID
88
-     */
89
-    public function set_event($EVT_ID = 0)
90
-    {
91
-        $this->set('EVT_ID', $EVT_ID);
92
-    }
93
-
94
-
95
-    /**
96
-     * Overrides parent set() method so that all calls to set( 'REG_code', $REG_code ) OR set( 'STS_ID', $STS_ID ) can
97
-     * be routed to internal methods
98
-     *
99
-     * @param string $field_name
100
-     * @param mixed  $field_value
101
-     * @param bool   $use_default
102
-     * @throws \EE_Error
103
-     * @throws \RuntimeException
104
-     */
105
-    public function set($field_name, $field_value, $use_default = false)
106
-    {
107
-        switch ($field_name) {
108
-            case 'REG_code' :
109
-                if (! empty($field_value) && $this->reg_code() === null) {
110
-                    $this->set_reg_code($field_value, $use_default);
111
-                }
112
-                break;
113
-            case 'STS_ID' :
114
-                $this->set_status($field_value, $use_default);
115
-                break;
116
-            default :
117
-                parent::set($field_name, $field_value, $use_default);
118
-        }
119
-    }
120
-
121
-
122
-    /**
123
-     * Set Status ID
124
-     * updates the registration status and ALSO...
125
-     * calls reserve_registration_space() if the reg status changes TO approved from any other reg status
126
-     * calls release_registration_space() if the reg status changes FROM approved to any other reg status
127
-     *
128
-     * @param string  $new_STS_ID
129
-     * @param boolean $use_default
130
-     * @return bool
131
-     * @throws \RuntimeException
132
-     * @throws \EE_Error
133
-     */
134
-    public function set_status($new_STS_ID = null, $use_default = false)
135
-    {
136
-        // get current REG_Status
137
-        $old_STS_ID = $this->status_ID();
138
-        // if status has changed
139
-        if (
140
-            $old_STS_ID !== $new_STS_ID // and that status has actually changed
141
-            && ! empty($old_STS_ID) // and that old status is actually set
142
-            && ! empty($new_STS_ID) // as well as the new status
143
-            && $this->ID() // ensure registration is in the db
144
-        ) {
145
-            // TO approved
146
-            if ($new_STS_ID === EEM_Registration::status_id_approved) {
147
-                // reserve a space by incrementing ticket and datetime sold values
148
-                $this->_reserve_registration_space();
149
-                do_action('AHEE__EE_Registration__set_status__to_approved', $this, $old_STS_ID, $new_STS_ID);
150
-                // OR FROM  approved
151
-            } else if ($old_STS_ID === EEM_Registration::status_id_approved) {
152
-                // release a space by decrementing ticket and datetime sold values
153
-                $this->_release_registration_space();
154
-                do_action('AHEE__EE_Registration__set_status__from_approved', $this, $old_STS_ID, $new_STS_ID);
155
-            }
156
-            // update status
157
-            parent::set('STS_ID', $new_STS_ID, $use_default);
158
-            $this->_update_if_canceled_or_declined($new_STS_ID, $old_STS_ID);
159
-            /** @type EE_Transaction_Payments $transaction_payments */
160
-            $transaction_payments = EE_Registry::instance()->load_class('Transaction_Payments');
161
-            $transaction_payments->recalculate_transaction_total($this->transaction(), false);
162
-            $this->transaction()->update_status_based_on_total_paid(true);
163
-            do_action('AHEE__EE_Registration__set_status__after_update', $this, $old_STS_ID, $new_STS_ID);
164
-            return true;
165
-        }
166
-        //even though the old value matches the new value, it's still good to
167
-        //allow the parent set method to have a say
168
-        parent::set('STS_ID', $new_STS_ID, $use_default);
169
-        return true;
170
-    }
171
-
172
-
173
-    /**
174
-     * update REGs and TXN when cancelled or declined registrations involved
175
-     *
176
-     * @param string $new_STS_ID
177
-     * @param string $old_STS_ID
178
-     * @throws \EE_Error
179
-     */
180
-    private function _update_if_canceled_or_declined($new_STS_ID, $old_STS_ID)
181
-    {
182
-        // these reg statuses should not be considered in any calculations involving monies owing
183
-        $closed_reg_statuses = EEM_Registration::closed_reg_statuses();
184
-        // true if registration has been cancelled or declined
185
-        if (
186
-            in_array($new_STS_ID, $closed_reg_statuses, true)
187
-            && ! in_array($old_STS_ID, $closed_reg_statuses, true)
188
-        ) {
189
-            /** @type EE_Registration_Processor $registration_processor */
190
-            $registration_processor = EE_Registry::instance()->load_class('Registration_Processor');
191
-            /** @type EE_Transaction_Processor $transaction_processor */
192
-            $transaction_processor = EE_Registry::instance()->load_class('Transaction_Processor');
193
-            // cancelled or declined registration
194
-            $registration_processor->update_registration_after_being_canceled_or_declined(
195
-                $this,
196
-                $closed_reg_statuses
197
-            );
198
-            $transaction_processor->update_transaction_after_canceled_or_declined_registration(
199
-                $this,
200
-                $closed_reg_statuses,
201
-                false
202
-            );
203
-            do_action('AHEE__EE_Registration__set_status__canceled_or_declined', $this, $old_STS_ID, $new_STS_ID);
204
-            return;
205
-        }
206
-        // true if reinstating cancelled or declined registration
207
-        if (
208
-            in_array($old_STS_ID, $closed_reg_statuses, true)
209
-            && ! in_array($new_STS_ID, $closed_reg_statuses, true)
210
-        ) {
211
-            /** @type EE_Registration_Processor $registration_processor */
212
-            $registration_processor = EE_Registry::instance()->load_class('Registration_Processor');
213
-            /** @type EE_Transaction_Processor $transaction_processor */
214
-            $transaction_processor = EE_Registry::instance()->load_class('Transaction_Processor');
215
-            // reinstating cancelled or declined registration
216
-            $registration_processor->update_canceled_or_declined_registration_after_being_reinstated(
217
-                $this,
218
-                $closed_reg_statuses
219
-            );
220
-            $transaction_processor->update_transaction_after_reinstating_canceled_registration(
221
-                $this,
222
-                $closed_reg_statuses,
223
-                false
224
-            );
225
-            do_action('AHEE__EE_Registration__set_status__after_reinstated', $this, $old_STS_ID, $new_STS_ID);
226
-        }
227
-    }
228
-
229
-
230
-    /**
231
-     *        get Status ID
232
-     */
233
-    public function status_ID()
234
-    {
235
-        return $this->get('STS_ID');
236
-    }
237
-
238
-
239
-    /**
240
-     * increments this registration's related ticket sold and corresponding datetime sold values
241
-     *
242
-     * @return void
243
-     * @throws \EE_Error
244
-     */
245
-    private function _reserve_registration_space()
246
-    {
247
-        // reserved ticket and datetime counts will be decremented as sold counts are incremented
248
-        // so stop tracking that this reg has a ticket reserved
249
-        $this->release_reserved_ticket();
250
-        $ticket = $this->ticket();
251
-        $ticket->increase_sold();
252
-        $ticket->save();
253
-        // possibly set event status to sold out
254
-        $this->event()->perform_sold_out_status_check();
255
-    }
256
-
257
-
258
-    /**
259
-     * Gets the ticket this registration is for
260
-     *
261
-     * @param boolean $include_archived whether to include archived tickets or not.
262
-     * @return EE_Ticket|EE_Base_Class
263
-     * @throws \EE_Error
264
-     */
265
-    public function ticket($include_archived = true)
266
-    {
267
-        $query_params = array();
268
-        if ($include_archived) {
269
-            $query_params['default_where_conditions'] = 'none';
270
-        }
271
-        return $this->get_first_related('Ticket', $query_params);
272
-    }
273
-
274
-
275
-    /**
276
-     * Gets the event this registration is for
277
-     *
278
-     * @return EE_Event
279
-     */
280
-    public function event()
281
-    {
282
-        $event = $this->get_first_related('Event');
283
-        if (! $event instanceof \EE_Event) {
284
-            throw new EntityNotFoundException('Event ID', $this->event_ID());
285
-        }
286
-        return $event;
287
-    }
288
-
289
-
290
-    /**
291
-     * Gets the "author" of the registration.  Note that for the purposes of registrations, the author will correspond
292
-     * with the author of the event this registration is for.
293
-     *
294
-     * @since 4.5.0
295
-     * @return int
296
-     */
297
-    public function wp_user()
298
-    {
299
-        $event = $this->event();
300
-        if ($event instanceof EE_Event) {
301
-            return $event->wp_user();
302
-        }
303
-        return 0;
304
-    }
305
-
306
-
307
-    /**
308
-     * decrements (subtracts) this registration's related ticket sold and corresponding datetime sold values
309
-     *
310
-     * @return void
311
-     * @throws \EE_Error
312
-     */
313
-    private function _release_registration_space()
314
-    {
315
-        $ticket = $this->ticket();
316
-        $ticket->decrease_sold();
317
-        $ticket->save();
318
-    }
319
-
320
-
321
-    /**
322
-     * tracks this registration's ticket reservation in extra meta
323
-     * and can increment related ticket reserved and corresponding datetime reserved values
324
-     *
325
-     * @param bool $update_ticket if true, will increment ticket and datetime reserved count
326
-     * @return void
327
-     * @throws \EE_Error
328
-     */
329
-    public function reserve_ticket($update_ticket = false)
330
-    {
331
-        if ($this->get_extra_meta(EE_Registration::HAS_RESERVED_TICKET_KEY, true, false) === false) {
332
-            // PLZ NOTE: although checking $update_ticket first would be more efficient,
333
-            // we NEED to ALWAYS call update_extra_meta(), which is why that is done first
334
-            if ($this->update_extra_meta(EE_Registration::HAS_RESERVED_TICKET_KEY, true, false) && $update_ticket) {
335
-                $ticket = $this->ticket();
336
-                $ticket->increase_reserved();
337
-                $ticket->save();
338
-            }
339
-        }
340
-    }
341
-
342
-
343
-    /**
344
-     * stops tracking this registration's ticket reservation in extra meta
345
-     * decrements (subtracts) related ticket reserved and corresponding datetime reserved values
346
-     *
347
-     * @param bool $update_ticket if true, will decrement ticket and datetime reserved count
348
-     * @return void
349
-     * @throws \EE_Error
350
-     */
351
-    public function release_reserved_ticket($update_ticket = false)
352
-    {
353
-        if ($this->get_extra_meta(EE_Registration::HAS_RESERVED_TICKET_KEY, true, false) !== false) {
354
-            // PLZ NOTE: although checking $update_ticket first would be more efficient,
355
-            // we NEED to ALWAYS call delete_extra_meta(), which is why that is done first
356
-            if ($this->delete_extra_meta(EE_Registration::HAS_RESERVED_TICKET_KEY) && $update_ticket) {
357
-                $ticket = $this->ticket();
358
-                $ticket->decrease_reserved();
359
-                $ticket->save();
360
-            }
361
-        }
362
-    }
363
-
364
-
365
-    /**
366
-     * Set Attendee ID
367
-     *
368
-     * @param        int $ATT_ID Attendee ID
369
-     */
370
-    public function set_attendee_id($ATT_ID = 0)
371
-    {
372
-        $this->set('ATT_ID', $ATT_ID);
373
-    }
374
-
375
-
376
-    /**
377
-     *        Set Transaction ID
378
-     *
379
-     * @param        int $TXN_ID Transaction ID
380
-     */
381
-    public function set_transaction_id($TXN_ID = 0)
382
-    {
383
-        $this->set('TXN_ID', $TXN_ID);
384
-    }
385
-
386
-
387
-    /**
388
-     *        Set Session
389
-     *
390
-     * @param    string $REG_session PHP Session ID
391
-     */
392
-    public function set_session($REG_session = '')
393
-    {
394
-        $this->set('REG_session', $REG_session);
395
-    }
396
-
397
-
398
-    /**
399
-     *        Set Registration URL Link
400
-     *
401
-     * @param    string $REG_url_link Registration URL Link
402
-     */
403
-    public function set_reg_url_link($REG_url_link = '')
404
-    {
405
-        $this->set('REG_url_link', $REG_url_link);
406
-    }
407
-
408
-
409
-    /**
410
-     *        Set Attendee Counter
411
-     *
412
-     * @param        int $REG_count Primary Attendee
413
-     */
414
-    public function set_count($REG_count = 1)
415
-    {
416
-        $this->set('REG_count', $REG_count);
417
-    }
418
-
419
-
420
-    /**
421
-     *        Set Group Size
422
-     *
423
-     * @param        boolean $REG_group_size Group Registration
424
-     */
425
-    public function set_group_size($REG_group_size = false)
426
-    {
427
-        $this->set('REG_group_size', $REG_group_size);
428
-    }
429
-
430
-
431
-    /**
432
-     *    is_not_approved -  convenience method that returns TRUE if REG status ID ==
433
-     *    EEM_Registration::status_id_not_approved
434
-     *
435
-     * @return        boolean
436
-     */
437
-    public function is_not_approved()
438
-    {
439
-        return $this->status_ID() == EEM_Registration::status_id_not_approved ? true : false;
440
-    }
441
-
442
-
443
-    /**
444
-     *    is_pending_payment -  convenience method that returns TRUE if REG status ID ==
445
-     *    EEM_Registration::status_id_pending_payment
446
-     *
447
-     * @return        boolean
448
-     */
449
-    public function is_pending_payment()
450
-    {
451
-        return $this->status_ID() == EEM_Registration::status_id_pending_payment ? true : false;
452
-    }
453
-
454
-
455
-    /**
456
-     *    is_approved -  convenience method that returns TRUE if REG status ID == EEM_Registration::status_id_approved
457
-     *
458
-     * @return        boolean
459
-     */
460
-    public function is_approved()
461
-    {
462
-        return $this->status_ID() == EEM_Registration::status_id_approved ? true : false;
463
-    }
464
-
465
-
466
-    /**
467
-     *    is_cancelled -  convenience method that returns TRUE if REG status ID == EEM_Registration::status_id_cancelled
468
-     *
469
-     * @return        boolean
470
-     */
471
-    public function is_cancelled()
472
-    {
473
-        return $this->status_ID() == EEM_Registration::status_id_cancelled ? true : false;
474
-    }
475
-
476
-
477
-    /**
478
-     *    is_declined -  convenience method that returns TRUE if REG status ID == EEM_Registration::status_id_declined
479
-     *
480
-     * @return        boolean
481
-     */
482
-    public function is_declined()
483
-    {
484
-        return $this->status_ID() == EEM_Registration::status_id_declined ? true : false;
485
-    }
486
-
487
-
488
-    /**
489
-     *    is_incomplete -  convenience method that returns TRUE if REG status ID ==
490
-     *    EEM_Registration::status_id_incomplete
491
-     *
492
-     * @return        boolean
493
-     */
494
-    public function is_incomplete()
495
-    {
496
-        return $this->status_ID() == EEM_Registration::status_id_incomplete ? true : false;
497
-    }
498
-
499
-
500
-    /**
501
-     *        Set Registration Date
502
-     *
503
-     * @param        mixed ( int or string ) $REG_date Registration Date - Unix timestamp or string representation of
504
-     *                       Date
505
-     */
506
-    public function set_reg_date($REG_date = false)
507
-    {
508
-        $this->set('REG_date', $REG_date);
509
-    }
510
-
511
-
512
-    /**
513
-     *    Set final price owing for this registration after all ticket/price modifications
514
-     *
515
-     * @access    public
516
-     * @param    float $REG_final_price
517
-     */
518
-    public function set_final_price($REG_final_price = 0.00)
519
-    {
520
-        $this->set('REG_final_price', $REG_final_price);
521
-    }
522
-
523
-
524
-    /**
525
-     *    Set amount paid towards this registration's final price
526
-     *
527
-     * @access    public
528
-     * @param    float $REG_paid
529
-     */
530
-    public function set_paid($REG_paid = 0.00)
531
-    {
532
-        $this->set('REG_paid', $REG_paid);
533
-    }
534
-
535
-
536
-    /**
537
-     *        Attendee Is Going
538
-     *
539
-     * @param        boolean $REG_att_is_going Attendee Is Going
540
-     */
541
-    public function set_att_is_going($REG_att_is_going = false)
542
-    {
543
-        $this->set('REG_att_is_going', $REG_att_is_going);
544
-    }
545
-
546
-
547
-    /**
548
-     * Gets the related attendee
549
-     *
550
-     * @return EE_Attendee
551
-     */
552
-    public function attendee()
553
-    {
554
-        return $this->get_first_related('Attendee');
555
-    }
556
-
557
-
558
-    /**
559
-     *        get Event ID
560
-     */
561
-    public function event_ID()
562
-    {
563
-        return $this->get('EVT_ID');
564
-    }
565
-
566
-
567
-    /**
568
-     *        get Event ID
569
-     */
570
-    public function event_name()
571
-    {
572
-        $event = $this->event_obj();
573
-        if ($event) {
574
-            return $event->name();
575
-        } else {
576
-            return null;
577
-        }
578
-    }
579
-
580
-
581
-    /**
582
-     * Fetches the event this registration is for
583
-     *
584
-     * @return EE_Event
585
-     */
586
-    public function event_obj()
587
-    {
588
-        return $this->get_first_related('Event');
589
-    }
590
-
591
-
592
-    /**
593
-     *        get Attendee ID
594
-     */
595
-    public function attendee_ID()
596
-    {
597
-        return $this->get('ATT_ID');
598
-    }
599
-
600
-
601
-    /**
602
-     *        get PHP Session ID
603
-     */
604
-    public function session_ID()
605
-    {
606
-        return $this->get('REG_session');
607
-    }
608
-
609
-
610
-    /**
611
-     * Gets the string which represents the URL trigger for the receipt template in the message template system.
612
-     *
613
-     * @param string $messenger 'pdf' or 'html'.  Default 'html'.
614
-     * @return string
615
-     */
616
-    public function receipt_url($messenger = 'html')
617
-    {
618
-
619
-        /**
620
-         * The below will be deprecated one version after this.  We check first if there is a custom receipt template already in use on old system.  If there is then we just return the standard url for it.
621
-         *
622
-         * @since 4.5.0
623
-         */
624
-        $template_relative_path = 'modules/gateways/Invoice/lib/templates/receipt_body.template.php';
625
-        $has_custom             = EEH_Template::locate_template($template_relative_path, array(), true, true, true);
626
-
627
-        if ($has_custom) {
628
-            return add_query_arg(array('receipt' => 'true'), $this->invoice_url('launch'));
629
-        }
630
-        return apply_filters('FHEE__EE_Registration__receipt_url__receipt_url', '', $this, $messenger, 'receipt');
631
-    }
632
-
633
-
634
-    /**
635
-     * Gets the string which represents the URL trigger for the invoice template in the message template system.
636
-     *
637
-     * @param string $messenger 'pdf' or 'html'.  Default 'html'.
638
-     * @return string
639
-     */
640
-    public function invoice_url($messenger = 'html')
641
-    {
642
-        /**
643
-         * The below will be deprecated one version after this.  We check first if there is a custom invoice template already in use on old system.  If there is then we just return the standard url for it.
644
-         *
645
-         * @since 4.5.0
646
-         */
647
-        $template_relative_path = 'modules/gateways/Invoice/lib/templates/invoice_body.template.php';
648
-        $has_custom             = EEH_Template::locate_template($template_relative_path, array(), true, true, true);
649
-
650
-        if ($has_custom) {
651
-            if ($messenger == 'html') {
652
-                return $this->invoice_url('launch');
653
-            }
654
-            $route = $messenger == 'download' || $messenger == 'pdf' ? 'download_invoice' : 'launch_invoice';
655
-
656
-            $query_args = array('ee' => $route, 'id' => $this->reg_url_link());
657
-            if ($messenger == 'html') {
658
-                $query_args['html'] = true;
659
-            }
660
-            return add_query_arg($query_args, get_permalink(EE_Registry::instance()->CFG->core->thank_you_page_id));
661
-        }
662
-        return apply_filters('FHEE__EE_Registration__invoice_url__invoice_url', '', $this, $messenger, 'invoice');
663
-    }
664
-
665
-
666
-    /**
667
-     * get Registration URL Link
668
-     *
669
-     * @access public
670
-     * @return string
671
-     * @throws \EE_Error
672
-     */
673
-    public function reg_url_link()
674
-    {
675
-        return (string)$this->get('REG_url_link');
676
-    }
677
-
678
-
679
-    /**
680
-     * Echoes out invoice_url()
681
-     *
682
-     * @param string $type 'download','launch', or 'html' (default is 'launch')
683
-     * @return void
684
-     */
685
-    public function e_invoice_url($type = 'launch')
686
-    {
687
-        echo $this->invoice_url($type);
688
-    }
689
-
690
-
691
-    /**
692
-     * Echoes out payment_overview_url
693
-     */
694
-    public function e_payment_overview_url()
695
-    {
696
-        echo $this->payment_overview_url();
697
-    }
698
-
699
-
700
-    /**
701
-     * Gets the URL of the thank you page with this registration REG_url_link added as
702
-     * a query parameter
703
-     *
704
-     * @return string
705
-     */
706
-    public function payment_overview_url()
707
-    {
708
-        return add_query_arg(array(
709
-            'e_reg_url_link' => $this->reg_url_link(),
710
-            'step'           => 'payment_options',
711
-            'revisit'        => true,
712
-        ), EE_Registry::instance()->CFG->core->reg_page_url());
713
-    }
714
-
715
-
716
-    /**
717
-     * Gets the URL of the thank you page with this registration REG_url_link added as
718
-     * a query parameter
719
-     *
720
-     * @return string
721
-     */
722
-    public function edit_attendee_information_url()
723
-    {
724
-        return add_query_arg(array(
725
-            'e_reg_url_link' => $this->reg_url_link(),
726
-            'step'           => 'attendee_information',
727
-            'revisit'        => true,
728
-        ), EE_Registry::instance()->CFG->core->reg_page_url());
729
-    }
730
-
731
-
732
-    /**
733
-     * Simply generates and returns the appropriate admin_url link to edit this registration
734
-     *
735
-     * @return string
736
-     */
737
-    public function get_admin_edit_url()
738
-    {
739
-        return EEH_URL::add_query_args_and_nonce(array(
740
-            'page'    => 'espresso_registrations',
741
-            'action'  => 'view_registration',
742
-            '_REG_ID' => $this->ID(),
743
-        ), admin_url('admin.php'));
744
-    }
745
-
746
-
747
-    /**
748
-     *    is_primary_registrant?
749
-     */
750
-    public function is_primary_registrant()
751
-    {
752
-        return $this->get('REG_count') == 1 ? true : false;
753
-    }
754
-
755
-
756
-    /**
757
-     * This returns the primary registration object for this registration group (which may be this object).
758
-     *
759
-     * @return EE_Registration
760
-     */
761
-    public function get_primary_registration()
762
-    {
763
-        if ($this->is_primary_registrant()) {
764
-            return $this;
765
-        }
766
-
767
-        //k reg_count !== 1 so let's get the EE_Registration object matching this txn_id and reg_count == 1
768
-        $primary_registrant = EEM_Registration::instance()->get_one(array(
769
-            array(
770
-                'TXN_ID'    => $this->transaction_ID(),
771
-                'REG_count' => 1,
772
-            ),
773
-        ));
774
-        return $primary_registrant;
775
-    }
776
-
777
-
778
-    /**
779
-     *        get  Attendee Number
780
-     *
781
-     * @access        public
782
-     */
783
-    public function count()
784
-    {
785
-        return $this->get('REG_count');
786
-    }
787
-
788
-
789
-    /**
790
-     *        get Group Size
791
-     */
792
-    public function group_size()
793
-    {
794
-        return $this->get('REG_group_size');
795
-    }
796
-
797
-
798
-    /**
799
-     *        get Registration Date
800
-     */
801
-    public function date()
802
-    {
803
-        return $this->get('REG_date');
804
-    }
805
-
806
-
807
-    /**
808
-     * gets a pretty date
809
-     *
810
-     * @param string $date_format
811
-     * @param string $time_format
812
-     * @return string
813
-     */
814
-    public function pretty_date($date_format = null, $time_format = null)
815
-    {
816
-        return $this->get_datetime('REG_date', $date_format, $time_format);
817
-    }
818
-
819
-
820
-    /**
821
-     * final_price
822
-     * the registration's share of the transaction total, so that the
823
-     * sum of all the transaction's REG_final_prices equal the transaction's total
824
-     *
825
-     * @return    float
826
-     */
827
-    public function final_price()
828
-    {
829
-        return $this->get('REG_final_price');
830
-    }
831
-
832
-
833
-    /**
834
-     * pretty_final_price
835
-     *  final price as formatted string, with correct decimal places and currency symbol
836
-     *
837
-     * @return string
838
-     */
839
-    public function pretty_final_price()
840
-    {
841
-        return $this->get_pretty('REG_final_price');
842
-    }
843
-
844
-
845
-    /**
846
-     * get paid (yeah)
847
-     *
848
-     * @return    float
849
-     */
850
-    public function paid()
851
-    {
852
-        return $this->get('REG_paid');
853
-    }
854
-
855
-
856
-    /**
857
-     * pretty_paid
858
-     *
859
-     * @return    float
860
-     */
861
-    public function pretty_paid()
862
-    {
863
-        return $this->get_pretty('REG_paid');
864
-    }
865
-
866
-
867
-    /**
868
-     * owes_monies_and_can_pay
869
-     * whether or not this registration has monies owing and it's' status allows payment
870
-     *
871
-     * @param array $requires_payment
872
-     * @return bool
873
-     */
874
-    public function owes_monies_and_can_pay($requires_payment = array())
875
-    {
876
-        // these reg statuses require payment (if event is not free)
877
-        $requires_payment = ! empty($requires_payment) ? $requires_payment : EEM_Registration::reg_statuses_that_allow_payment();
878
-        if (
879
-            in_array($this->status_ID(), $requires_payment) &&
880
-            $this->final_price() != 0 &&
881
-            $this->final_price() != $this->paid()
882
-        ) {
883
-            return true;
884
-        } else {
885
-            return false;
886
-        }
887
-    }
888
-
889
-
890
-    /**
891
-     * Prints out the return value of $this->pretty_status()
892
-     *
893
-     * @param bool $show_icons
894
-     * @return void
895
-     */
896
-    public function e_pretty_status($show_icons = false)
897
-    {
898
-        echo $this->pretty_status($show_icons);
899
-    }
900
-
901
-
902
-    /**
903
-     * Returns a nice version of the status for displaying to customers
904
-     *
905
-     * @param bool $show_icons
906
-     * @return string
907
-     */
908
-    public function pretty_status($show_icons = false)
909
-    {
910
-        $status = EEM_Status::instance()->localized_status(array($this->status_ID() => __('unknown', 'event_espresso')),
911
-            false, 'sentence');
912
-        $icon   = '';
913
-        switch ($this->status_ID()) {
914
-            case EEM_Registration::status_id_approved:
915
-                $icon = $show_icons ? '<span class="dashicons dashicons-star-filled ee-icon-size-16 green-text"></span>' : '';
916
-                break;
917
-            case EEM_Registration::status_id_pending_payment:
918
-                $icon = $show_icons ? '<span class="dashicons dashicons-star-half ee-icon-size-16 orange-text"></span>' : '';
919
-                break;
920
-            case EEM_Registration::status_id_not_approved:
921
-                $icon = $show_icons ? '<span class="dashicons dashicons-marker ee-icon-size-16 orange-text"></span>' : '';
922
-                break;
923
-            case EEM_Registration::status_id_cancelled:
924
-                $icon = $show_icons ? '<span class="dashicons dashicons-no ee-icon-size-16 lt-grey-text"></span>' : '';
925
-                break;
926
-            case EEM_Registration::status_id_incomplete:
927
-                $icon = $show_icons ? '<span class="dashicons dashicons-no ee-icon-size-16 lt-orange-text"></span>' : '';
928
-                break;
929
-            case EEM_Registration::status_id_declined:
930
-                $icon = $show_icons ? '<span class="dashicons dashicons-no ee-icon-size-16 red-text"></span>' : '';
931
-                break;
932
-            case EEM_Registration::status_id_wait_list:
933
-                $icon = $show_icons ? '<span class="dashicons dashicons-clipboard ee-icon-size-16 purple-text"></span>' : '';
934
-                break;
935
-        }
936
-        return $icon . $status[$this->status_ID()];
937
-    }
938
-
939
-
940
-    /**
941
-     *        get Attendee Is Going
942
-     */
943
-    public function att_is_going()
944
-    {
945
-        return $this->get('REG_att_is_going');
946
-    }
947
-
948
-
949
-    /**
950
-     * Gets related answers
951
-     *
952
-     * @param array $query_params like EEM_Base::get_all
953
-     * @return EE_Answer[]
954
-     */
955
-    public function answers($query_params = null)
956
-    {
957
-        return $this->get_many_related('Answer', $query_params);
958
-    }
959
-
960
-
961
-    /**
962
-     * Gets the registration's answer value to the specified question
963
-     * (either the question's ID or a question object)
964
-     *
965
-     * @param EE_Question|int $question
966
-     * @param bool            $pretty_value
967
-     * @return array|string if pretty_value= true, the result will always be a string
968
-     * (because the answer might be an array of answer values, so passing pretty_value=true
969
-     * will convert it into some kind of string)
970
-     */
971
-    public function answer_value_to_question($question, $pretty_value = true)
972
-    {
973
-        $question_id = EEM_Question::instance()->ensure_is_ID($question);
974
-        return EEM_Answer::instance()->get_answer_value_to_question($this, $question_id, $pretty_value);
975
-    }
976
-
977
-
978
-    /**
979
-     * question_groups
980
-     * returns an array of EE_Question_Group objects for this registration
981
-     *
982
-     * @return EE_Question_Group[]
983
-     */
984
-    public function question_groups()
985
-    {
986
-        $question_groups = array();
987
-        if ($this->event() instanceof EE_Event) {
988
-            $question_groups = $this->event()->question_groups(
989
-                array(
990
-                    array(
991
-                        'Event_Question_Group.EQG_primary' => $this->count() == 1 ? true : false,
992
-                    ),
993
-                    'order_by' => array('QSG_order' => 'ASC'),
994
-                )
995
-            );
996
-        }
997
-        return $question_groups;
998
-    }
999
-
1000
-
1001
-    /**
1002
-     * count_question_groups
1003
-     * returns a count of the number of EE_Question_Group objects for this registration
1004
-     *
1005
-     * @return int
1006
-     */
1007
-    public function count_question_groups()
1008
-    {
1009
-        $qg_count = 0;
1010
-        if ($this->event() instanceof EE_Event) {
1011
-            $qg_count = $this->event()->count_related(
1012
-                'Question_Group',
1013
-                array(
1014
-                    array(
1015
-                        'Event_Question_Group.EQG_primary' => $this->count() == 1 ? true : false,
1016
-                    ),
1017
-                )
1018
-            );
1019
-        }
1020
-        return $qg_count;
1021
-    }
1022
-
1023
-
1024
-    /**
1025
-     * Returns the registration date in the 'standard' string format
1026
-     * (function may be improved in the future to allow for different formats and timezones)
1027
-     *
1028
-     * @return string
1029
-     */
1030
-    public function reg_date()
1031
-    {
1032
-        return $this->get_datetime('REG_date');
1033
-    }
1034
-
1035
-
1036
-    /**
1037
-     * Gets the datetime-ticket for this registration (ie, it can be used to isolate
1038
-     * the ticket this registration purchased, or the datetime they have registered
1039
-     * to attend)
1040
-     *
1041
-     * @return EE_Datetime_Ticket
1042
-     */
1043
-    public function datetime_ticket()
1044
-    {
1045
-        return $this->get_first_related('Datetime_Ticket');
1046
-    }
1047
-
1048
-
1049
-    /**
1050
-     * Sets the registration's datetime_ticket.
1051
-     *
1052
-     * @param EE_Datetime_Ticket $datetime_ticket
1053
-     * @return EE_Datetime_Ticket
1054
-     */
1055
-    public function set_datetime_ticket($datetime_ticket)
1056
-    {
1057
-        return $this->_add_relation_to($datetime_ticket, 'Datetime_Ticket');
1058
-    }
1059
-
1060
-    /**
1061
-     * Gets deleted
1062
-     *
1063
-     * @return boolean
1064
-     */
1065
-    public function deleted()
1066
-    {
1067
-        return $this->get('REG_deleted');
1068
-    }
1069
-
1070
-    /**
1071
-     * Sets deleted
1072
-     *
1073
-     * @param boolean $deleted
1074
-     * @return boolean
1075
-     */
1076
-    public function set_deleted($deleted)
1077
-    {
1078
-        if ($deleted) {
1079
-            $this->delete();
1080
-        } else {
1081
-            $this->restore();
1082
-        }
1083
-    }
1084
-
1085
-
1086
-    /**
1087
-     * Get the status object of this object
1088
-     *
1089
-     * @return EE_Status
1090
-     */
1091
-    public function status_obj()
1092
-    {
1093
-        return $this->get_first_related('Status');
1094
-    }
1095
-
1096
-
1097
-    /**
1098
-     * Returns the number of times this registration has checked into any of the datetimes
1099
-     * its available for
1100
-     *
1101
-     * @return int
1102
-     */
1103
-    public function count_checkins()
1104
-    {
1105
-        return $this->get_model()->count_related($this, 'Checkin');
1106
-    }
1107
-
1108
-
1109
-    /**
1110
-     * Returns the number of current Check-ins this registration is checked into for any of the datetimes the
1111
-     * registration is for.  Note, this is ONLY checked in (does not include checkedout)
1112
-     *
1113
-     * @return int
1114
-     */
1115
-    public function count_checkins_not_checkedout()
1116
-    {
1117
-        return $this->get_model()->count_related($this, 'Checkin', array(array('CHK_in' => 1)));
1118
-    }
1119
-
1120
-
1121
-    /**
1122
-     * The purpose of this method is simply to check whether this registration can checkin to the given datetime.
1123
-     *
1124
-     * @param int | EE_Datetime $DTT_OR_ID      The datetime the registration is being checked against
1125
-     * @param bool              $check_approved This is used to indicate whether the caller wants can_checkin to also
1126
-     *                                          consider registration status as well as datetime access.
1127
-     * @return bool
1128
-     */
1129
-    public function can_checkin($DTT_OR_ID, $check_approved = true)
1130
-    {
1131
-        $DTT_ID = EEM_Datetime::instance()->ensure_is_ID($DTT_OR_ID);
1132
-
1133
-        //first check registration status
1134
-        if (($check_approved && ! $this->is_approved()) || ! $DTT_ID) {
1135
-            return false;
1136
-        }
1137
-        //is there a datetime ticket that matches this dtt_ID?
1138
-        if (! (EEM_Datetime_Ticket::instance()->exists(array(
1139
-            array(
1140
-                'TKT_ID' => $this->get('TKT_ID'),
1141
-                'DTT_ID' => $DTT_ID,
1142
-            ),
1143
-        )))
1144
-        ) {
1145
-            return false;
1146
-        }
1147
-
1148
-        //final check is against TKT_uses
1149
-        return $this->verify_can_checkin_against_TKT_uses($DTT_ID);
1150
-    }
1151
-
1152
-
1153
-    /**
1154
-     * This method verifies whether the user can checkin for the given datetime considering the max uses value set on
1155
-     * the ticket. To do this,  a query is done to get the count of the datetime records already checked into.  If the
1156
-     * datetime given does not have a check-in record and checking in for that datetime will exceed the allowed uses,
1157
-     * then return false.  Otherwise return true.
1158
-     *
1159
-     * @param int | EE_Datetime $DTT_OR_ID The datetime the registration is being checked against
1160
-     * @return bool   true means can checkin.  false means cannot checkin.
1161
-     */
1162
-    public function verify_can_checkin_against_TKT_uses($DTT_OR_ID)
1163
-    {
1164
-        $DTT_ID = EEM_Datetime::instance()->ensure_is_ID($DTT_OR_ID);
1165
-
1166
-        if (! $DTT_ID) {
1167
-            return false;
1168
-        }
1169
-
1170
-        $max_uses = $this->ticket() instanceof EE_Ticket ? $this->ticket()->uses() : EE_INF;
1171
-
1172
-        // if max uses is not set or equals infinity then return true cause its not a factor for whether user can check-in
1173
-        // or not.
1174
-        if (! $max_uses || $max_uses === EE_INF) {
1175
-            return true;
1176
-        }
1177
-
1178
-        //does this datetime have a checkin record?  If so, then the dtt count has already been verified so we can just
1179
-        //go ahead and toggle.
1180
-        if (EEM_Checkin::instance()->exists(array(array('REG_ID' => $this->ID(), 'DTT_ID' => $DTT_ID)))) {
1181
-            return true;
1182
-        }
1183
-
1184
-        //made it here so the last check is whether the number of checkins per unique datetime on this registration
1185
-        //disallows further check-ins.
1186
-        $count_unique_dtt_checkins = EEM_Checkin::instance()->count(array(
1187
-            array(
1188
-                'REG_ID' => $this->ID(),
1189
-                'CHK_in' => true,
1190
-            ),
1191
-        ), 'DTT_ID', true);
1192
-        // checkins have already reached their max number of uses
1193
-        // so registrant can NOT checkin
1194
-        if ($count_unique_dtt_checkins >= $max_uses) {
1195
-            EE_Error::add_error(__('Check-in denied because number of datetime uses for the ticket has been reached or exceeded.',
1196
-                'event_espresso'), __FILE__, __FUNCTION__, __LINE__);
1197
-            return false;
1198
-        }
1199
-        return true;
1200
-    }
1201
-
1202
-
1203
-    /**
1204
-     * toggle Check-in status for this registration
1205
-     * Check-ins are toggled in the following order:
1206
-     * never checked in -> checked in
1207
-     * checked in -> checked out
1208
-     * checked out -> checked in
1209
-     *
1210
-     * @param  int $DTT_ID  include specific datetime to toggle Check-in for.
1211
-     *                      If not included or null, then it is assumed latest datetime is being toggled.
1212
-     * @param bool $verify  If true then can_checkin() is used to verify whether the person
1213
-     *                      can be checked in or not.  Otherwise this forces change in checkin status.
1214
-     * @return bool|int     the chk_in status toggled to OR false if nothing got changed.
1215
-     * @throws EE_Error
1216
-     */
1217
-    public function toggle_checkin_status($DTT_ID = null, $verify = false)
1218
-    {
1219
-        if (empty($DTT_ID)) {
1220
-            $datetime = $this->get_latest_related_datetime();
1221
-            $DTT_ID   = $datetime instanceof EE_Datetime ? $datetime->ID() : 0;
1222
-            // verify the registration can checkin for the given DTT_ID
1223
-        } elseif (! $this->can_checkin($DTT_ID, $verify)) {
1224
-            EE_Error::add_error(
1225
-                sprintf(
1226
-                    __('The given registration (ID:%1$d) can not be checked in to the given DTT_ID (%2$d), because the registration does not have access',
1227
-                        'event_espresso'),
1228
-                    $this->ID(),
1229
-                    $DTT_ID
1230
-                ),
1231
-                __FILE__, __FUNCTION__, __LINE__
1232
-            );
1233
-            return false;
1234
-        }
1235
-        $status_paths = array(
1236
-            EE_Registration::checkin_status_never => EE_Registration::checkin_status_in,
1237
-            EE_Registration::checkin_status_in    => EE_Registration::checkin_status_out,
1238
-            EE_Registration::checkin_status_out   => EE_Registration::checkin_status_in,
1239
-        );
1240
-        //start by getting the current status so we know what status we'll be changing to.
1241
-        $cur_status = $this->check_in_status_for_datetime($DTT_ID, null);
1242
-        $status_to  = $status_paths[$cur_status];
1243
-        // database only records true for checked IN or false for checked OUT
1244
-        // no record ( null ) means checked in NEVER, but we obviously don't save that
1245
-        $new_status = $status_to === EE_Registration::checkin_status_in ? true : false;
1246
-        // add relation - note Check-ins are always creating new rows
1247
-        // because we are keeping track of Check-ins over time.
1248
-        // Eventually we'll probably want to show a list table
1249
-        // for the individual Check-ins so that they can be managed.
1250
-        $checkin = EE_Checkin::new_instance(array(
1251
-            'REG_ID' => $this->ID(),
1252
-            'DTT_ID' => $DTT_ID,
1253
-            'CHK_in' => $new_status,
1254
-        ));
1255
-        // if the record could not be saved then return false
1256
-        if ($checkin->save() === 0) {
1257
-            if (WP_DEBUG) {
1258
-                global $wpdb;
1259
-                $error = sprintf(
1260
-                    __('Registration check in update failed because of the following database error: %1$s%2$s',
1261
-                        'event_espresso'),
1262
-                    '<br />',
1263
-                    $wpdb->last_error
1264
-                );
1265
-            } else {
1266
-                $error = __('Registration check in update failed because of an unknown database error',
1267
-                    'event_espresso');
1268
-            }
1269
-            EE_Error::add_error($error, __FILE__, __FUNCTION__, __LINE__);
1270
-            return false;
1271
-        }
1272
-        return $status_to;
1273
-    }
1274
-
1275
-
1276
-    /**
1277
-     * Returns the latest datetime related to this registration (via the ticket attached to the registration).
1278
-     * "Latest" is defined by the `DTT_EVT_start` column.
1279
-     *
1280
-     * @return EE_Datetime|null
1281
-     * @throws \EE_Error
1282
-     */
1283
-    public function get_latest_related_datetime()
1284
-    {
1285
-        return EEM_Datetime::instance()->get_one(
1286
-            array(
1287
-                array(
1288
-                    'Ticket.Registration.REG_ID' => $this->ID(),
1289
-                ),
1290
-                'order_by' => array('DTT_EVT_start' => 'DESC'),
1291
-            )
1292
-        );
1293
-    }
1294
-
1295
-
1296
-    /**
1297
-     * Returns the earliest datetime related to this registration (via the ticket attached to the registration).
1298
-     * "Earliest" is defined by the `DTT_EVT_start` column.
1299
-     *
1300
-     * @throws \EE_Error
1301
-     */
1302
-    public function get_earliest_related_datetime()
1303
-    {
1304
-        return EEM_Datetime::instance()->get_one(
1305
-            array(
1306
-                array(
1307
-                    'Ticket.Registration.REG_ID' => $this->ID(),
1308
-                ),
1309
-                'order_by' => array('DTT_EVT_start' => 'ASC'),
1310
-            )
1311
-        );
1312
-    }
1313
-
1314
-
1315
-    /**
1316
-     * This method simply returns the check-in status for this registration and the given datetime.
1317
-     * If neither the datetime nor the checkin values are provided as arguments,
1318
-     * then this will return the LATEST check-in status for the registration across all datetimes it belongs to.
1319
-     *
1320
-     * @param  int       $DTT_ID  The ID of the datetime we're checking against
1321
-     *                            (if empty we'll get the primary datetime for
1322
-     *                            this registration (via event) and use it's ID);
1323
-     * @param EE_Checkin $checkin If present, we use the given checkin object rather than the dtt_id.
1324
-     * @return int                Integer representing Check-in status.
1325
-     * @throws \EE_Error
1326
-     */
1327
-    public function check_in_status_for_datetime($DTT_ID = 0, $checkin = null)
1328
-    {
1329
-        $checkin_query_params = array(
1330
-            'order_by' => array('CHK_timestamp' => 'DESC'),
1331
-        );
1332
-
1333
-        if ($DTT_ID > 0) {
1334
-            $checkin_query_params[0] = array('DTT_ID' => $DTT_ID);
1335
-        }
1336
-
1337
-        //get checkin object (if exists)
1338
-        $checkin = $checkin instanceof EE_Checkin
1339
-            ? $checkin
1340
-            : $this->get_first_related('Checkin', $checkin_query_params);
1341
-        if ($checkin instanceof EE_Checkin) {
1342
-            if ($checkin->get('CHK_in')) {
1343
-                return EE_Registration::checkin_status_in; //checked in
1344
-            }
1345
-            return EE_Registration::checkin_status_out; //had checked in but is now checked out.
1346
-        }
1347
-        return EE_Registration::checkin_status_never; //never been checked in
1348
-    }
1349
-
1350
-
1351
-    /**
1352
-     * This method returns a localized message for the toggled Check-in message.
1353
-     *
1354
-     * @param  int $DTT_ID include specific datetime to get the correct Check-in message.  If not included or null,
1355
-     *                     then it is assumed Check-in for primary datetime was toggled.
1356
-     * @param bool $error  This just flags that you want an error message returned. This is put in so that the error
1357
-     *                     message can be customized with the attendee name.
1358
-     * @return string         internationalized message
1359
-     */
1360
-    public function get_checkin_msg($DTT_ID, $error = false)
1361
-    {
1362
-        //let's get the attendee first so we can include the name of the attendee
1363
-        $attendee = $this->get_first_related('Attendee');
1364
-        if ($attendee instanceof EE_Attendee) {
1365
-            if ($error) {
1366
-                return sprintf(__("%s's check-in status was not changed.", "event_espresso"), $attendee->full_name());
1367
-            }
1368
-            $cur_status = $this->check_in_status_for_datetime($DTT_ID);
1369
-            //what is the status message going to be?
1370
-            switch ($cur_status) {
1371
-                case EE_Registration::checkin_status_never :
1372
-                    return sprintf(__("%s has been removed from Check-in records", "event_espresso"),
1373
-                        $attendee->full_name());
1374
-                    break;
1375
-                case EE_Registration::checkin_status_in :
1376
-                    return sprintf(__('%s has been checked in', 'event_espresso'), $attendee->full_name());
1377
-                    break;
1378
-                case EE_Registration::checkin_status_out :
1379
-                    return sprintf(__('%s has been checked out', 'event_espresso'), $attendee->full_name());
1380
-                    break;
1381
-            }
1382
-        }
1383
-        return __("The check-in status could not be determined.", "event_espresso");
1384
-    }
1385
-
1386
-
1387
-    /**
1388
-     * Returns the related EE_Transaction to this registration
1389
-     *
1390
-     * @return EE_Transaction
1391
-     */
1392
-    public function transaction()
1393
-    {
1394
-        $transaction = $this->get_first_related('Transaction');
1395
-        if (! $transaction instanceof \EE_Transaction) {
1396
-            throw new EntityNotFoundException('Transaction ID', $this->transaction_ID());
1397
-        }
1398
-        return $transaction;
1399
-    }
1400
-
1401
-
1402
-    /**
1403
-     *        get Registration Code
1404
-     */
1405
-    public function reg_code()
1406
-    {
1407
-        return $this->get('REG_code');
1408
-    }
1409
-
1410
-
1411
-    /**
1412
-     *        get Transaction ID
1413
-     */
1414
-    public function transaction_ID()
1415
-    {
1416
-        return $this->get('TXN_ID');
1417
-    }
1418
-
1419
-
1420
-    /**
1421
-     * @return int
1422
-     */
1423
-    public function ticket_ID()
1424
-    {
1425
-        return $this->get('TKT_ID');
1426
-    }
1427
-
1428
-
1429
-    /**
1430
-     *        Set Registration Code
1431
-     *
1432
-     * @access    public
1433
-     * @param    string  $REG_code Registration Code
1434
-     * @param    boolean $use_default
1435
-     */
1436
-    public function set_reg_code($REG_code, $use_default = false)
1437
-    {
1438
-        if (empty($REG_code)) {
1439
-            EE_Error::add_error(__('REG_code can not be empty.', 'event_espresso'), __FILE__, __FUNCTION__, __LINE__);
1440
-            return;
1441
-        }
1442
-        if (! $this->reg_code()) {
1443
-            parent::set('REG_code', $REG_code, $use_default);
1444
-        } else {
1445
-            EE_Error::doing_it_wrong(
1446
-                __CLASS__ . '::' . __FUNCTION__,
1447
-                __('Can not change a registration REG_code once it has been set.', 'event_espresso'),
1448
-                '4.6.0'
1449
-            );
1450
-        }
1451
-    }
1452
-
1453
-
1454
-    /**
1455
-     * Returns all other registrations in the same group as this registrant who have the same ticket option.
1456
-     * Note, if you want to just get all registrations in the same transaction (group), use:
1457
-     *    $registration->transaction()->registrations();
1458
-     *
1459
-     * @since 4.5.0
1460
-     * @return EE_Registration[]  or empty array if this isn't a group registration.
1461
-     */
1462
-    public function get_all_other_registrations_in_group()
1463
-    {
1464
-        if ($this->group_size() < 2) {
1465
-            return array();
1466
-        }
1467
-
1468
-        $query[0] = array(
1469
-            'TXN_ID' => $this->transaction_ID(),
1470
-            'REG_ID' => array('!=', $this->ID()),
1471
-            'TKT_ID' => $this->ticket_ID(),
1472
-        );
1473
-
1474
-        $registrations = $this->get_model()->get_all($query);
1475
-        return $registrations;
1476
-    }
1477
-
1478
-    /**
1479
-     * Return the link to the admin details for the object.
1480
-     *
1481
-     * @return string
1482
-     */
1483
-    public function get_admin_details_link()
1484
-    {
1485
-        EE_Registry::instance()->load_helper('URL');
1486
-        return EEH_URL::add_query_args_and_nonce(
1487
-            array(
1488
-                'page'    => 'espresso_registrations',
1489
-                'action'  => 'view_registration',
1490
-                '_REG_ID' => $this->ID(),
1491
-            ),
1492
-            admin_url('admin.php')
1493
-        );
1494
-    }
1495
-
1496
-    /**
1497
-     * Returns the link to the editor for the object.  Sometimes this is the same as the details.
1498
-     *
1499
-     * @return string
1500
-     */
1501
-    public function get_admin_edit_link()
1502
-    {
1503
-        return $this->get_admin_details_link();
1504
-    }
1505
-
1506
-    /**
1507
-     * Returns the link to a settings page for the object.
1508
-     *
1509
-     * @return string
1510
-     */
1511
-    public function get_admin_settings_link()
1512
-    {
1513
-        return $this->get_admin_details_link();
1514
-    }
1515
-
1516
-    /**
1517
-     * Returns the link to the "overview" for the object (typically the "list table" view).
1518
-     *
1519
-     * @return string
1520
-     */
1521
-    public function get_admin_overview_link()
1522
-    {
1523
-        EE_Registry::instance()->load_helper('URL');
1524
-        return EEH_URL::add_query_args_and_nonce(
1525
-            array(
1526
-                'page' => 'espresso_registrations',
1527
-            ),
1528
-            admin_url('admin.php')
1529
-        );
1530
-    }
1531
-
1532
-
1533
-    /**
1534
-     * @param array $query_params
1535
-     * @return \EE_Registration[]
1536
-     * @throws \EE_Error
1537
-     */
1538
-    public function payments($query_params = array())
1539
-    {
1540
-        return $this->get_many_related('Payment', $query_params);
1541
-    }
1542
-
1543
-
1544
-    /**
1545
-     * @param array $query_params
1546
-     * @return \EE_Registration_Payment[]
1547
-     * @throws \EE_Error
1548
-     */
1549
-    public function registration_payments($query_params = array())
1550
-    {
1551
-        return $this->get_many_related('Registration_Payment', $query_params);
1552
-    }
1553
-
1554
-
1555
-    /**
1556
-     * This grabs the payment method corresponding to the last payment made for the amount owing on the registration.
1557
-     * Note: if there are no payments on the registration there will be no payment method returned.
1558
-     *
1559
-     * @return EE_Payment_Method|null
1560
-     */
1561
-    public function payment_method()
1562
-    {
1563
-        return EEM_Payment_Method::instance()->get_last_used_for_registration($this);
1564
-    }
1565
-
1566
-
1567
-    /**
1568
-     * @return \EE_Line_Item
1569
-     * @throws EntityNotFoundException
1570
-     * @throws \EE_Error
1571
-     */
1572
-    public function ticket_line_item()
1573
-    {
1574
-        $ticket            = $this->ticket();
1575
-        $transaction       = $this->transaction();
1576
-        $line_item         = null;
1577
-        $ticket_line_items = \EEH_Line_Item::get_line_items_by_object_type_and_IDs(
1578
-            $transaction->total_line_item(),
1579
-            'Ticket',
1580
-            array($ticket->ID())
1581
-        );
1582
-        foreach ($ticket_line_items as $ticket_line_item) {
1583
-            if (
1584
-                $ticket_line_item instanceof \EE_Line_Item
1585
-                && $ticket_line_item->OBJ_type() === 'Ticket'
1586
-                && $ticket_line_item->OBJ_ID() === $ticket->ID()
1587
-            ) {
1588
-                $line_item = $ticket_line_item;
1589
-                break;
1590
-            }
1591
-        }
1592
-        if (! ($line_item instanceof \EE_Line_Item && $line_item->OBJ_type() === 'Ticket')) {
1593
-            throw new EntityNotFoundException('Line Item Ticket ID', $ticket->ID());
1594
-        }
1595
-        return $line_item;
1596
-    }
1597
-
1598
-
1599
-    /**
1600
-     * Soft Deletes this model object.
1601
-     *
1602
-     * @return boolean | int
1603
-     * @throws \RuntimeException
1604
-     * @throws \EE_Error
1605
-     */
1606
-    public function delete()
1607
-    {
1608
-        if ($this->update_extra_meta(EE_Registration::PRE_TRASH_REG_STATUS_KEY, $this->status_ID()) === true) {
1609
-            $this->set_status(EEM_Registration::status_id_cancelled);
1610
-        }
1611
-        return parent::delete();
1612
-    }
1613
-
1614
-
1615
-    /**
1616
-     * Restores whatever the previous status was on a registration before it was trashed (if possible)
1617
-     *
1618
-     * @throws \EE_Error
1619
-     * @throws \RuntimeException
1620
-     */
1621
-    public function restore()
1622
-    {
1623
-        $previous_status = $this->get_extra_meta(
1624
-            EE_Registration::PRE_TRASH_REG_STATUS_KEY,
1625
-            true,
1626
-            EEM_Registration::status_id_cancelled
1627
-        );
1628
-        if ($previous_status) {
1629
-            $this->delete_extra_meta(EE_Registration::PRE_TRASH_REG_STATUS_KEY);
1630
-            $this->set_status($previous_status);
1631
-        }
1632
-        return parent::restore();
1633
-    }
1634
-
1635
-
1636
-
1637
-    /*************************** DEPRECATED ***************************/
1638
-
1639
-
1640
-    /**
1641
-     * @deprecated
1642
-     * @since     4.7.0
1643
-     * @access    public
1644
-     */
1645
-    public function price_paid()
1646
-    {
1647
-        EE_Error::doing_it_wrong('EE_Registration::price_paid()',
1648
-            __('This method is deprecated, please use EE_Registration::final_price() instead.', 'event_espresso'),
1649
-            '4.7.0');
1650
-        return $this->final_price();
1651
-    }
1652
-
1653
-
1654
-    /**
1655
-     * @deprecated
1656
-     * @since     4.7.0
1657
-     * @access    public
1658
-     * @param    float $REG_final_price
1659
-     */
1660
-    public function set_price_paid($REG_final_price = 0.00)
1661
-    {
1662
-        EE_Error::doing_it_wrong('EE_Registration::set_price_paid()',
1663
-            __('This method is deprecated, please use EE_Registration::set_final_price() instead.', 'event_espresso'),
1664
-            '4.7.0');
1665
-        $this->set_final_price($REG_final_price);
1666
-    }
1667
-
1668
-
1669
-    /**
1670
-     * @deprecated
1671
-     * @since 4.7.0
1672
-     * @return string
1673
-     */
1674
-    public function pretty_price_paid()
1675
-    {
1676
-        EE_Error::doing_it_wrong('EE_Registration::pretty_price_paid()',
1677
-            __('This method is deprecated, please use EE_Registration::pretty_final_price() instead.',
1678
-                'event_espresso'), '4.7.0');
1679
-        return $this->pretty_final_price();
1680
-    }
1681
-
1682
-
1683
-    /**
1684
-     * Gets the primary datetime related to this registration via the related Event to this registration
1685
-     *
1686
-     * @deprecated 4.9.17
1687
-     * @return EE_Datetime
1688
-     */
1689
-    public function get_related_primary_datetime()
1690
-    {
1691
-        EE_Error::doing_it_wrong(
1692
-            __METHOD__,
1693
-            esc_html__(
1694
-                'Use EE_Registration::get_latest_related_datetime() or EE_Registration::get_earliest_related_datetime()',
1695
-                'event_espresso'
1696
-            ),
1697
-            '4.9.17',
1698
-            '5.0.0'
1699
-        );
1700
-        return $this->event()->primary_datetime();
1701
-    }
18
+	/**
19
+	 * Used to reference when a registration has never been checked in.
20
+	 *
21
+	 * @type int
22
+	 */
23
+	const checkin_status_never = 2;
24
+
25
+	/**
26
+	 * Used to reference when a registration has been checked in.
27
+	 *
28
+	 * @type int
29
+	 */
30
+	const checkin_status_in = 1;
31
+
32
+
33
+	/**
34
+	 * Used to reference when a registration has been checked out.
35
+	 *
36
+	 * @type int
37
+	 */
38
+	const checkin_status_out = 0;
39
+
40
+
41
+	/**
42
+	 * extra meta key for tracking reg status os trashed registrations
43
+	 *
44
+	 * @type string
45
+	 */
46
+	const PRE_TRASH_REG_STATUS_KEY = 'pre_trash_registration_status';
47
+
48
+
49
+	/**
50
+	 * extra meta key for tracking if registration has reserved ticket
51
+	 *
52
+	 * @type string
53
+	 */
54
+	const HAS_RESERVED_TICKET_KEY = 'has_reserved_ticket';
55
+
56
+
57
+	/**
58
+	 * @param array  $props_n_values          incoming values
59
+	 * @param string $timezone                incoming timezone (if not set the timezone set for the website will be
60
+	 *                                        used.)
61
+	 * @param array  $date_formats            incoming date_formats in an array where the first value is the
62
+	 *                                        date_format and the second value is the time format
63
+	 * @return EE_Registration
64
+	 */
65
+	public static function new_instance($props_n_values = array(), $timezone = null, $date_formats = array())
66
+	{
67
+		$has_object = parent::_check_for_object($props_n_values, __CLASS__, $timezone, $date_formats);
68
+		return $has_object ? $has_object : new self($props_n_values, false, $timezone, $date_formats);
69
+	}
70
+
71
+
72
+	/**
73
+	 * @param array  $props_n_values  incoming values from the database
74
+	 * @param string $timezone        incoming timezone as set by the model.  If not set the timezone for
75
+	 *                                the website will be used.
76
+	 * @return EE_Registration
77
+	 */
78
+	public static function new_instance_from_db($props_n_values = array(), $timezone = null)
79
+	{
80
+		return new self($props_n_values, true, $timezone);
81
+	}
82
+
83
+
84
+	/**
85
+	 *        Set Event ID
86
+	 *
87
+	 * @param        int $EVT_ID Event ID
88
+	 */
89
+	public function set_event($EVT_ID = 0)
90
+	{
91
+		$this->set('EVT_ID', $EVT_ID);
92
+	}
93
+
94
+
95
+	/**
96
+	 * Overrides parent set() method so that all calls to set( 'REG_code', $REG_code ) OR set( 'STS_ID', $STS_ID ) can
97
+	 * be routed to internal methods
98
+	 *
99
+	 * @param string $field_name
100
+	 * @param mixed  $field_value
101
+	 * @param bool   $use_default
102
+	 * @throws \EE_Error
103
+	 * @throws \RuntimeException
104
+	 */
105
+	public function set($field_name, $field_value, $use_default = false)
106
+	{
107
+		switch ($field_name) {
108
+			case 'REG_code' :
109
+				if (! empty($field_value) && $this->reg_code() === null) {
110
+					$this->set_reg_code($field_value, $use_default);
111
+				}
112
+				break;
113
+			case 'STS_ID' :
114
+				$this->set_status($field_value, $use_default);
115
+				break;
116
+			default :
117
+				parent::set($field_name, $field_value, $use_default);
118
+		}
119
+	}
120
+
121
+
122
+	/**
123
+	 * Set Status ID
124
+	 * updates the registration status and ALSO...
125
+	 * calls reserve_registration_space() if the reg status changes TO approved from any other reg status
126
+	 * calls release_registration_space() if the reg status changes FROM approved to any other reg status
127
+	 *
128
+	 * @param string  $new_STS_ID
129
+	 * @param boolean $use_default
130
+	 * @return bool
131
+	 * @throws \RuntimeException
132
+	 * @throws \EE_Error
133
+	 */
134
+	public function set_status($new_STS_ID = null, $use_default = false)
135
+	{
136
+		// get current REG_Status
137
+		$old_STS_ID = $this->status_ID();
138
+		// if status has changed
139
+		if (
140
+			$old_STS_ID !== $new_STS_ID // and that status has actually changed
141
+			&& ! empty($old_STS_ID) // and that old status is actually set
142
+			&& ! empty($new_STS_ID) // as well as the new status
143
+			&& $this->ID() // ensure registration is in the db
144
+		) {
145
+			// TO approved
146
+			if ($new_STS_ID === EEM_Registration::status_id_approved) {
147
+				// reserve a space by incrementing ticket and datetime sold values
148
+				$this->_reserve_registration_space();
149
+				do_action('AHEE__EE_Registration__set_status__to_approved', $this, $old_STS_ID, $new_STS_ID);
150
+				// OR FROM  approved
151
+			} else if ($old_STS_ID === EEM_Registration::status_id_approved) {
152
+				// release a space by decrementing ticket and datetime sold values
153
+				$this->_release_registration_space();
154
+				do_action('AHEE__EE_Registration__set_status__from_approved', $this, $old_STS_ID, $new_STS_ID);
155
+			}
156
+			// update status
157
+			parent::set('STS_ID', $new_STS_ID, $use_default);
158
+			$this->_update_if_canceled_or_declined($new_STS_ID, $old_STS_ID);
159
+			/** @type EE_Transaction_Payments $transaction_payments */
160
+			$transaction_payments = EE_Registry::instance()->load_class('Transaction_Payments');
161
+			$transaction_payments->recalculate_transaction_total($this->transaction(), false);
162
+			$this->transaction()->update_status_based_on_total_paid(true);
163
+			do_action('AHEE__EE_Registration__set_status__after_update', $this, $old_STS_ID, $new_STS_ID);
164
+			return true;
165
+		}
166
+		//even though the old value matches the new value, it's still good to
167
+		//allow the parent set method to have a say
168
+		parent::set('STS_ID', $new_STS_ID, $use_default);
169
+		return true;
170
+	}
171
+
172
+
173
+	/**
174
+	 * update REGs and TXN when cancelled or declined registrations involved
175
+	 *
176
+	 * @param string $new_STS_ID
177
+	 * @param string $old_STS_ID
178
+	 * @throws \EE_Error
179
+	 */
180
+	private function _update_if_canceled_or_declined($new_STS_ID, $old_STS_ID)
181
+	{
182
+		// these reg statuses should not be considered in any calculations involving monies owing
183
+		$closed_reg_statuses = EEM_Registration::closed_reg_statuses();
184
+		// true if registration has been cancelled or declined
185
+		if (
186
+			in_array($new_STS_ID, $closed_reg_statuses, true)
187
+			&& ! in_array($old_STS_ID, $closed_reg_statuses, true)
188
+		) {
189
+			/** @type EE_Registration_Processor $registration_processor */
190
+			$registration_processor = EE_Registry::instance()->load_class('Registration_Processor');
191
+			/** @type EE_Transaction_Processor $transaction_processor */
192
+			$transaction_processor = EE_Registry::instance()->load_class('Transaction_Processor');
193
+			// cancelled or declined registration
194
+			$registration_processor->update_registration_after_being_canceled_or_declined(
195
+				$this,
196
+				$closed_reg_statuses
197
+			);
198
+			$transaction_processor->update_transaction_after_canceled_or_declined_registration(
199
+				$this,
200
+				$closed_reg_statuses,
201
+				false
202
+			);
203
+			do_action('AHEE__EE_Registration__set_status__canceled_or_declined', $this, $old_STS_ID, $new_STS_ID);
204
+			return;
205
+		}
206
+		// true if reinstating cancelled or declined registration
207
+		if (
208
+			in_array($old_STS_ID, $closed_reg_statuses, true)
209
+			&& ! in_array($new_STS_ID, $closed_reg_statuses, true)
210
+		) {
211
+			/** @type EE_Registration_Processor $registration_processor */
212
+			$registration_processor = EE_Registry::instance()->load_class('Registration_Processor');
213
+			/** @type EE_Transaction_Processor $transaction_processor */
214
+			$transaction_processor = EE_Registry::instance()->load_class('Transaction_Processor');
215
+			// reinstating cancelled or declined registration
216
+			$registration_processor->update_canceled_or_declined_registration_after_being_reinstated(
217
+				$this,
218
+				$closed_reg_statuses
219
+			);
220
+			$transaction_processor->update_transaction_after_reinstating_canceled_registration(
221
+				$this,
222
+				$closed_reg_statuses,
223
+				false
224
+			);
225
+			do_action('AHEE__EE_Registration__set_status__after_reinstated', $this, $old_STS_ID, $new_STS_ID);
226
+		}
227
+	}
228
+
229
+
230
+	/**
231
+	 *        get Status ID
232
+	 */
233
+	public function status_ID()
234
+	{
235
+		return $this->get('STS_ID');
236
+	}
237
+
238
+
239
+	/**
240
+	 * increments this registration's related ticket sold and corresponding datetime sold values
241
+	 *
242
+	 * @return void
243
+	 * @throws \EE_Error
244
+	 */
245
+	private function _reserve_registration_space()
246
+	{
247
+		// reserved ticket and datetime counts will be decremented as sold counts are incremented
248
+		// so stop tracking that this reg has a ticket reserved
249
+		$this->release_reserved_ticket();
250
+		$ticket = $this->ticket();
251
+		$ticket->increase_sold();
252
+		$ticket->save();
253
+		// possibly set event status to sold out
254
+		$this->event()->perform_sold_out_status_check();
255
+	}
256
+
257
+
258
+	/**
259
+	 * Gets the ticket this registration is for
260
+	 *
261
+	 * @param boolean $include_archived whether to include archived tickets or not.
262
+	 * @return EE_Ticket|EE_Base_Class
263
+	 * @throws \EE_Error
264
+	 */
265
+	public function ticket($include_archived = true)
266
+	{
267
+		$query_params = array();
268
+		if ($include_archived) {
269
+			$query_params['default_where_conditions'] = 'none';
270
+		}
271
+		return $this->get_first_related('Ticket', $query_params);
272
+	}
273
+
274
+
275
+	/**
276
+	 * Gets the event this registration is for
277
+	 *
278
+	 * @return EE_Event
279
+	 */
280
+	public function event()
281
+	{
282
+		$event = $this->get_first_related('Event');
283
+		if (! $event instanceof \EE_Event) {
284
+			throw new EntityNotFoundException('Event ID', $this->event_ID());
285
+		}
286
+		return $event;
287
+	}
288
+
289
+
290
+	/**
291
+	 * Gets the "author" of the registration.  Note that for the purposes of registrations, the author will correspond
292
+	 * with the author of the event this registration is for.
293
+	 *
294
+	 * @since 4.5.0
295
+	 * @return int
296
+	 */
297
+	public function wp_user()
298
+	{
299
+		$event = $this->event();
300
+		if ($event instanceof EE_Event) {
301
+			return $event->wp_user();
302
+		}
303
+		return 0;
304
+	}
305
+
306
+
307
+	/**
308
+	 * decrements (subtracts) this registration's related ticket sold and corresponding datetime sold values
309
+	 *
310
+	 * @return void
311
+	 * @throws \EE_Error
312
+	 */
313
+	private function _release_registration_space()
314
+	{
315
+		$ticket = $this->ticket();
316
+		$ticket->decrease_sold();
317
+		$ticket->save();
318
+	}
319
+
320
+
321
+	/**
322
+	 * tracks this registration's ticket reservation in extra meta
323
+	 * and can increment related ticket reserved and corresponding datetime reserved values
324
+	 *
325
+	 * @param bool $update_ticket if true, will increment ticket and datetime reserved count
326
+	 * @return void
327
+	 * @throws \EE_Error
328
+	 */
329
+	public function reserve_ticket($update_ticket = false)
330
+	{
331
+		if ($this->get_extra_meta(EE_Registration::HAS_RESERVED_TICKET_KEY, true, false) === false) {
332
+			// PLZ NOTE: although checking $update_ticket first would be more efficient,
333
+			// we NEED to ALWAYS call update_extra_meta(), which is why that is done first
334
+			if ($this->update_extra_meta(EE_Registration::HAS_RESERVED_TICKET_KEY, true, false) && $update_ticket) {
335
+				$ticket = $this->ticket();
336
+				$ticket->increase_reserved();
337
+				$ticket->save();
338
+			}
339
+		}
340
+	}
341
+
342
+
343
+	/**
344
+	 * stops tracking this registration's ticket reservation in extra meta
345
+	 * decrements (subtracts) related ticket reserved and corresponding datetime reserved values
346
+	 *
347
+	 * @param bool $update_ticket if true, will decrement ticket and datetime reserved count
348
+	 * @return void
349
+	 * @throws \EE_Error
350
+	 */
351
+	public function release_reserved_ticket($update_ticket = false)
352
+	{
353
+		if ($this->get_extra_meta(EE_Registration::HAS_RESERVED_TICKET_KEY, true, false) !== false) {
354
+			// PLZ NOTE: although checking $update_ticket first would be more efficient,
355
+			// we NEED to ALWAYS call delete_extra_meta(), which is why that is done first
356
+			if ($this->delete_extra_meta(EE_Registration::HAS_RESERVED_TICKET_KEY) && $update_ticket) {
357
+				$ticket = $this->ticket();
358
+				$ticket->decrease_reserved();
359
+				$ticket->save();
360
+			}
361
+		}
362
+	}
363
+
364
+
365
+	/**
366
+	 * Set Attendee ID
367
+	 *
368
+	 * @param        int $ATT_ID Attendee ID
369
+	 */
370
+	public function set_attendee_id($ATT_ID = 0)
371
+	{
372
+		$this->set('ATT_ID', $ATT_ID);
373
+	}
374
+
375
+
376
+	/**
377
+	 *        Set Transaction ID
378
+	 *
379
+	 * @param        int $TXN_ID Transaction ID
380
+	 */
381
+	public function set_transaction_id($TXN_ID = 0)
382
+	{
383
+		$this->set('TXN_ID', $TXN_ID);
384
+	}
385
+
386
+
387
+	/**
388
+	 *        Set Session
389
+	 *
390
+	 * @param    string $REG_session PHP Session ID
391
+	 */
392
+	public function set_session($REG_session = '')
393
+	{
394
+		$this->set('REG_session', $REG_session);
395
+	}
396
+
397
+
398
+	/**
399
+	 *        Set Registration URL Link
400
+	 *
401
+	 * @param    string $REG_url_link Registration URL Link
402
+	 */
403
+	public function set_reg_url_link($REG_url_link = '')
404
+	{
405
+		$this->set('REG_url_link', $REG_url_link);
406
+	}
407
+
408
+
409
+	/**
410
+	 *        Set Attendee Counter
411
+	 *
412
+	 * @param        int $REG_count Primary Attendee
413
+	 */
414
+	public function set_count($REG_count = 1)
415
+	{
416
+		$this->set('REG_count', $REG_count);
417
+	}
418
+
419
+
420
+	/**
421
+	 *        Set Group Size
422
+	 *
423
+	 * @param        boolean $REG_group_size Group Registration
424
+	 */
425
+	public function set_group_size($REG_group_size = false)
426
+	{
427
+		$this->set('REG_group_size', $REG_group_size);
428
+	}
429
+
430
+
431
+	/**
432
+	 *    is_not_approved -  convenience method that returns TRUE if REG status ID ==
433
+	 *    EEM_Registration::status_id_not_approved
434
+	 *
435
+	 * @return        boolean
436
+	 */
437
+	public function is_not_approved()
438
+	{
439
+		return $this->status_ID() == EEM_Registration::status_id_not_approved ? true : false;
440
+	}
441
+
442
+
443
+	/**
444
+	 *    is_pending_payment -  convenience method that returns TRUE if REG status ID ==
445
+	 *    EEM_Registration::status_id_pending_payment
446
+	 *
447
+	 * @return        boolean
448
+	 */
449
+	public function is_pending_payment()
450
+	{
451
+		return $this->status_ID() == EEM_Registration::status_id_pending_payment ? true : false;
452
+	}
453
+
454
+
455
+	/**
456
+	 *    is_approved -  convenience method that returns TRUE if REG status ID == EEM_Registration::status_id_approved
457
+	 *
458
+	 * @return        boolean
459
+	 */
460
+	public function is_approved()
461
+	{
462
+		return $this->status_ID() == EEM_Registration::status_id_approved ? true : false;
463
+	}
464
+
465
+
466
+	/**
467
+	 *    is_cancelled -  convenience method that returns TRUE if REG status ID == EEM_Registration::status_id_cancelled
468
+	 *
469
+	 * @return        boolean
470
+	 */
471
+	public function is_cancelled()
472
+	{
473
+		return $this->status_ID() == EEM_Registration::status_id_cancelled ? true : false;
474
+	}
475
+
476
+
477
+	/**
478
+	 *    is_declined -  convenience method that returns TRUE if REG status ID == EEM_Registration::status_id_declined
479
+	 *
480
+	 * @return        boolean
481
+	 */
482
+	public function is_declined()
483
+	{
484
+		return $this->status_ID() == EEM_Registration::status_id_declined ? true : false;
485
+	}
486
+
487
+
488
+	/**
489
+	 *    is_incomplete -  convenience method that returns TRUE if REG status ID ==
490
+	 *    EEM_Registration::status_id_incomplete
491
+	 *
492
+	 * @return        boolean
493
+	 */
494
+	public function is_incomplete()
495
+	{
496
+		return $this->status_ID() == EEM_Registration::status_id_incomplete ? true : false;
497
+	}
498
+
499
+
500
+	/**
501
+	 *        Set Registration Date
502
+	 *
503
+	 * @param        mixed ( int or string ) $REG_date Registration Date - Unix timestamp or string representation of
504
+	 *                       Date
505
+	 */
506
+	public function set_reg_date($REG_date = false)
507
+	{
508
+		$this->set('REG_date', $REG_date);
509
+	}
510
+
511
+
512
+	/**
513
+	 *    Set final price owing for this registration after all ticket/price modifications
514
+	 *
515
+	 * @access    public
516
+	 * @param    float $REG_final_price
517
+	 */
518
+	public function set_final_price($REG_final_price = 0.00)
519
+	{
520
+		$this->set('REG_final_price', $REG_final_price);
521
+	}
522
+
523
+
524
+	/**
525
+	 *    Set amount paid towards this registration's final price
526
+	 *
527
+	 * @access    public
528
+	 * @param    float $REG_paid
529
+	 */
530
+	public function set_paid($REG_paid = 0.00)
531
+	{
532
+		$this->set('REG_paid', $REG_paid);
533
+	}
534
+
535
+
536
+	/**
537
+	 *        Attendee Is Going
538
+	 *
539
+	 * @param        boolean $REG_att_is_going Attendee Is Going
540
+	 */
541
+	public function set_att_is_going($REG_att_is_going = false)
542
+	{
543
+		$this->set('REG_att_is_going', $REG_att_is_going);
544
+	}
545
+
546
+
547
+	/**
548
+	 * Gets the related attendee
549
+	 *
550
+	 * @return EE_Attendee
551
+	 */
552
+	public function attendee()
553
+	{
554
+		return $this->get_first_related('Attendee');
555
+	}
556
+
557
+
558
+	/**
559
+	 *        get Event ID
560
+	 */
561
+	public function event_ID()
562
+	{
563
+		return $this->get('EVT_ID');
564
+	}
565
+
566
+
567
+	/**
568
+	 *        get Event ID
569
+	 */
570
+	public function event_name()
571
+	{
572
+		$event = $this->event_obj();
573
+		if ($event) {
574
+			return $event->name();
575
+		} else {
576
+			return null;
577
+		}
578
+	}
579
+
580
+
581
+	/**
582
+	 * Fetches the event this registration is for
583
+	 *
584
+	 * @return EE_Event
585
+	 */
586
+	public function event_obj()
587
+	{
588
+		return $this->get_first_related('Event');
589
+	}
590
+
591
+
592
+	/**
593
+	 *        get Attendee ID
594
+	 */
595
+	public function attendee_ID()
596
+	{
597
+		return $this->get('ATT_ID');
598
+	}
599
+
600
+
601
+	/**
602
+	 *        get PHP Session ID
603
+	 */
604
+	public function session_ID()
605
+	{
606
+		return $this->get('REG_session');
607
+	}
608
+
609
+
610
+	/**
611
+	 * Gets the string which represents the URL trigger for the receipt template in the message template system.
612
+	 *
613
+	 * @param string $messenger 'pdf' or 'html'.  Default 'html'.
614
+	 * @return string
615
+	 */
616
+	public function receipt_url($messenger = 'html')
617
+	{
618
+
619
+		/**
620
+		 * The below will be deprecated one version after this.  We check first if there is a custom receipt template already in use on old system.  If there is then we just return the standard url for it.
621
+		 *
622
+		 * @since 4.5.0
623
+		 */
624
+		$template_relative_path = 'modules/gateways/Invoice/lib/templates/receipt_body.template.php';
625
+		$has_custom             = EEH_Template::locate_template($template_relative_path, array(), true, true, true);
626
+
627
+		if ($has_custom) {
628
+			return add_query_arg(array('receipt' => 'true'), $this->invoice_url('launch'));
629
+		}
630
+		return apply_filters('FHEE__EE_Registration__receipt_url__receipt_url', '', $this, $messenger, 'receipt');
631
+	}
632
+
633
+
634
+	/**
635
+	 * Gets the string which represents the URL trigger for the invoice template in the message template system.
636
+	 *
637
+	 * @param string $messenger 'pdf' or 'html'.  Default 'html'.
638
+	 * @return string
639
+	 */
640
+	public function invoice_url($messenger = 'html')
641
+	{
642
+		/**
643
+		 * The below will be deprecated one version after this.  We check first if there is a custom invoice template already in use on old system.  If there is then we just return the standard url for it.
644
+		 *
645
+		 * @since 4.5.0
646
+		 */
647
+		$template_relative_path = 'modules/gateways/Invoice/lib/templates/invoice_body.template.php';
648
+		$has_custom             = EEH_Template::locate_template($template_relative_path, array(), true, true, true);
649
+
650
+		if ($has_custom) {
651
+			if ($messenger == 'html') {
652
+				return $this->invoice_url('launch');
653
+			}
654
+			$route = $messenger == 'download' || $messenger == 'pdf' ? 'download_invoice' : 'launch_invoice';
655
+
656
+			$query_args = array('ee' => $route, 'id' => $this->reg_url_link());
657
+			if ($messenger == 'html') {
658
+				$query_args['html'] = true;
659
+			}
660
+			return add_query_arg($query_args, get_permalink(EE_Registry::instance()->CFG->core->thank_you_page_id));
661
+		}
662
+		return apply_filters('FHEE__EE_Registration__invoice_url__invoice_url', '', $this, $messenger, 'invoice');
663
+	}
664
+
665
+
666
+	/**
667
+	 * get Registration URL Link
668
+	 *
669
+	 * @access public
670
+	 * @return string
671
+	 * @throws \EE_Error
672
+	 */
673
+	public function reg_url_link()
674
+	{
675
+		return (string)$this->get('REG_url_link');
676
+	}
677
+
678
+
679
+	/**
680
+	 * Echoes out invoice_url()
681
+	 *
682
+	 * @param string $type 'download','launch', or 'html' (default is 'launch')
683
+	 * @return void
684
+	 */
685
+	public function e_invoice_url($type = 'launch')
686
+	{
687
+		echo $this->invoice_url($type);
688
+	}
689
+
690
+
691
+	/**
692
+	 * Echoes out payment_overview_url
693
+	 */
694
+	public function e_payment_overview_url()
695
+	{
696
+		echo $this->payment_overview_url();
697
+	}
698
+
699
+
700
+	/**
701
+	 * Gets the URL of the thank you page with this registration REG_url_link added as
702
+	 * a query parameter
703
+	 *
704
+	 * @return string
705
+	 */
706
+	public function payment_overview_url()
707
+	{
708
+		return add_query_arg(array(
709
+			'e_reg_url_link' => $this->reg_url_link(),
710
+			'step'           => 'payment_options',
711
+			'revisit'        => true,
712
+		), EE_Registry::instance()->CFG->core->reg_page_url());
713
+	}
714
+
715
+
716
+	/**
717
+	 * Gets the URL of the thank you page with this registration REG_url_link added as
718
+	 * a query parameter
719
+	 *
720
+	 * @return string
721
+	 */
722
+	public function edit_attendee_information_url()
723
+	{
724
+		return add_query_arg(array(
725
+			'e_reg_url_link' => $this->reg_url_link(),
726
+			'step'           => 'attendee_information',
727
+			'revisit'        => true,
728
+		), EE_Registry::instance()->CFG->core->reg_page_url());
729
+	}
730
+
731
+
732
+	/**
733
+	 * Simply generates and returns the appropriate admin_url link to edit this registration
734
+	 *
735
+	 * @return string
736
+	 */
737
+	public function get_admin_edit_url()
738
+	{
739
+		return EEH_URL::add_query_args_and_nonce(array(
740
+			'page'    => 'espresso_registrations',
741
+			'action'  => 'view_registration',
742
+			'_REG_ID' => $this->ID(),
743
+		), admin_url('admin.php'));
744
+	}
745
+
746
+
747
+	/**
748
+	 *    is_primary_registrant?
749
+	 */
750
+	public function is_primary_registrant()
751
+	{
752
+		return $this->get('REG_count') == 1 ? true : false;
753
+	}
754
+
755
+
756
+	/**
757
+	 * This returns the primary registration object for this registration group (which may be this object).
758
+	 *
759
+	 * @return EE_Registration
760
+	 */
761
+	public function get_primary_registration()
762
+	{
763
+		if ($this->is_primary_registrant()) {
764
+			return $this;
765
+		}
766
+
767
+		//k reg_count !== 1 so let's get the EE_Registration object matching this txn_id and reg_count == 1
768
+		$primary_registrant = EEM_Registration::instance()->get_one(array(
769
+			array(
770
+				'TXN_ID'    => $this->transaction_ID(),
771
+				'REG_count' => 1,
772
+			),
773
+		));
774
+		return $primary_registrant;
775
+	}
776
+
777
+
778
+	/**
779
+	 *        get  Attendee Number
780
+	 *
781
+	 * @access        public
782
+	 */
783
+	public function count()
784
+	{
785
+		return $this->get('REG_count');
786
+	}
787
+
788
+
789
+	/**
790
+	 *        get Group Size
791
+	 */
792
+	public function group_size()
793
+	{
794
+		return $this->get('REG_group_size');
795
+	}
796
+
797
+
798
+	/**
799
+	 *        get Registration Date
800
+	 */
801
+	public function date()
802
+	{
803
+		return $this->get('REG_date');
804
+	}
805
+
806
+
807
+	/**
808
+	 * gets a pretty date
809
+	 *
810
+	 * @param string $date_format
811
+	 * @param string $time_format
812
+	 * @return string
813
+	 */
814
+	public function pretty_date($date_format = null, $time_format = null)
815
+	{
816
+		return $this->get_datetime('REG_date', $date_format, $time_format);
817
+	}
818
+
819
+
820
+	/**
821
+	 * final_price
822
+	 * the registration's share of the transaction total, so that the
823
+	 * sum of all the transaction's REG_final_prices equal the transaction's total
824
+	 *
825
+	 * @return    float
826
+	 */
827
+	public function final_price()
828
+	{
829
+		return $this->get('REG_final_price');
830
+	}
831
+
832
+
833
+	/**
834
+	 * pretty_final_price
835
+	 *  final price as formatted string, with correct decimal places and currency symbol
836
+	 *
837
+	 * @return string
838
+	 */
839
+	public function pretty_final_price()
840
+	{
841
+		return $this->get_pretty('REG_final_price');
842
+	}
843
+
844
+
845
+	/**
846
+	 * get paid (yeah)
847
+	 *
848
+	 * @return    float
849
+	 */
850
+	public function paid()
851
+	{
852
+		return $this->get('REG_paid');
853
+	}
854
+
855
+
856
+	/**
857
+	 * pretty_paid
858
+	 *
859
+	 * @return    float
860
+	 */
861
+	public function pretty_paid()
862
+	{
863
+		return $this->get_pretty('REG_paid');
864
+	}
865
+
866
+
867
+	/**
868
+	 * owes_monies_and_can_pay
869
+	 * whether or not this registration has monies owing and it's' status allows payment
870
+	 *
871
+	 * @param array $requires_payment
872
+	 * @return bool
873
+	 */
874
+	public function owes_monies_and_can_pay($requires_payment = array())
875
+	{
876
+		// these reg statuses require payment (if event is not free)
877
+		$requires_payment = ! empty($requires_payment) ? $requires_payment : EEM_Registration::reg_statuses_that_allow_payment();
878
+		if (
879
+			in_array($this->status_ID(), $requires_payment) &&
880
+			$this->final_price() != 0 &&
881
+			$this->final_price() != $this->paid()
882
+		) {
883
+			return true;
884
+		} else {
885
+			return false;
886
+		}
887
+	}
888
+
889
+
890
+	/**
891
+	 * Prints out the return value of $this->pretty_status()
892
+	 *
893
+	 * @param bool $show_icons
894
+	 * @return void
895
+	 */
896
+	public function e_pretty_status($show_icons = false)
897
+	{
898
+		echo $this->pretty_status($show_icons);
899
+	}
900
+
901
+
902
+	/**
903
+	 * Returns a nice version of the status for displaying to customers
904
+	 *
905
+	 * @param bool $show_icons
906
+	 * @return string
907
+	 */
908
+	public function pretty_status($show_icons = false)
909
+	{
910
+		$status = EEM_Status::instance()->localized_status(array($this->status_ID() => __('unknown', 'event_espresso')),
911
+			false, 'sentence');
912
+		$icon   = '';
913
+		switch ($this->status_ID()) {
914
+			case EEM_Registration::status_id_approved:
915
+				$icon = $show_icons ? '<span class="dashicons dashicons-star-filled ee-icon-size-16 green-text"></span>' : '';
916
+				break;
917
+			case EEM_Registration::status_id_pending_payment:
918
+				$icon = $show_icons ? '<span class="dashicons dashicons-star-half ee-icon-size-16 orange-text"></span>' : '';
919
+				break;
920
+			case EEM_Registration::status_id_not_approved:
921
+				$icon = $show_icons ? '<span class="dashicons dashicons-marker ee-icon-size-16 orange-text"></span>' : '';
922
+				break;
923
+			case EEM_Registration::status_id_cancelled:
924
+				$icon = $show_icons ? '<span class="dashicons dashicons-no ee-icon-size-16 lt-grey-text"></span>' : '';
925
+				break;
926
+			case EEM_Registration::status_id_incomplete:
927
+				$icon = $show_icons ? '<span class="dashicons dashicons-no ee-icon-size-16 lt-orange-text"></span>' : '';
928
+				break;
929
+			case EEM_Registration::status_id_declined:
930
+				$icon = $show_icons ? '<span class="dashicons dashicons-no ee-icon-size-16 red-text"></span>' : '';
931
+				break;
932
+			case EEM_Registration::status_id_wait_list:
933
+				$icon = $show_icons ? '<span class="dashicons dashicons-clipboard ee-icon-size-16 purple-text"></span>' : '';
934
+				break;
935
+		}
936
+		return $icon . $status[$this->status_ID()];
937
+	}
938
+
939
+
940
+	/**
941
+	 *        get Attendee Is Going
942
+	 */
943
+	public function att_is_going()
944
+	{
945
+		return $this->get('REG_att_is_going');
946
+	}
947
+
948
+
949
+	/**
950
+	 * Gets related answers
951
+	 *
952
+	 * @param array $query_params like EEM_Base::get_all
953
+	 * @return EE_Answer[]
954
+	 */
955
+	public function answers($query_params = null)
956
+	{
957
+		return $this->get_many_related('Answer', $query_params);
958
+	}
959
+
960
+
961
+	/**
962
+	 * Gets the registration's answer value to the specified question
963
+	 * (either the question's ID or a question object)
964
+	 *
965
+	 * @param EE_Question|int $question
966
+	 * @param bool            $pretty_value
967
+	 * @return array|string if pretty_value= true, the result will always be a string
968
+	 * (because the answer might be an array of answer values, so passing pretty_value=true
969
+	 * will convert it into some kind of string)
970
+	 */
971
+	public function answer_value_to_question($question, $pretty_value = true)
972
+	{
973
+		$question_id = EEM_Question::instance()->ensure_is_ID($question);
974
+		return EEM_Answer::instance()->get_answer_value_to_question($this, $question_id, $pretty_value);
975
+	}
976
+
977
+
978
+	/**
979
+	 * question_groups
980
+	 * returns an array of EE_Question_Group objects for this registration
981
+	 *
982
+	 * @return EE_Question_Group[]
983
+	 */
984
+	public function question_groups()
985
+	{
986
+		$question_groups = array();
987
+		if ($this->event() instanceof EE_Event) {
988
+			$question_groups = $this->event()->question_groups(
989
+				array(
990
+					array(
991
+						'Event_Question_Group.EQG_primary' => $this->count() == 1 ? true : false,
992
+					),
993
+					'order_by' => array('QSG_order' => 'ASC'),
994
+				)
995
+			);
996
+		}
997
+		return $question_groups;
998
+	}
999
+
1000
+
1001
+	/**
1002
+	 * count_question_groups
1003
+	 * returns a count of the number of EE_Question_Group objects for this registration
1004
+	 *
1005
+	 * @return int
1006
+	 */
1007
+	public function count_question_groups()
1008
+	{
1009
+		$qg_count = 0;
1010
+		if ($this->event() instanceof EE_Event) {
1011
+			$qg_count = $this->event()->count_related(
1012
+				'Question_Group',
1013
+				array(
1014
+					array(
1015
+						'Event_Question_Group.EQG_primary' => $this->count() == 1 ? true : false,
1016
+					),
1017
+				)
1018
+			);
1019
+		}
1020
+		return $qg_count;
1021
+	}
1022
+
1023
+
1024
+	/**
1025
+	 * Returns the registration date in the 'standard' string format
1026
+	 * (function may be improved in the future to allow for different formats and timezones)
1027
+	 *
1028
+	 * @return string
1029
+	 */
1030
+	public function reg_date()
1031
+	{
1032
+		return $this->get_datetime('REG_date');
1033
+	}
1034
+
1035
+
1036
+	/**
1037
+	 * Gets the datetime-ticket for this registration (ie, it can be used to isolate
1038
+	 * the ticket this registration purchased, or the datetime they have registered
1039
+	 * to attend)
1040
+	 *
1041
+	 * @return EE_Datetime_Ticket
1042
+	 */
1043
+	public function datetime_ticket()
1044
+	{
1045
+		return $this->get_first_related('Datetime_Ticket');
1046
+	}
1047
+
1048
+
1049
+	/**
1050
+	 * Sets the registration's datetime_ticket.
1051
+	 *
1052
+	 * @param EE_Datetime_Ticket $datetime_ticket
1053
+	 * @return EE_Datetime_Ticket
1054
+	 */
1055
+	public function set_datetime_ticket($datetime_ticket)
1056
+	{
1057
+		return $this->_add_relation_to($datetime_ticket, 'Datetime_Ticket');
1058
+	}
1059
+
1060
+	/**
1061
+	 * Gets deleted
1062
+	 *
1063
+	 * @return boolean
1064
+	 */
1065
+	public function deleted()
1066
+	{
1067
+		return $this->get('REG_deleted');
1068
+	}
1069
+
1070
+	/**
1071
+	 * Sets deleted
1072
+	 *
1073
+	 * @param boolean $deleted
1074
+	 * @return boolean
1075
+	 */
1076
+	public function set_deleted($deleted)
1077
+	{
1078
+		if ($deleted) {
1079
+			$this->delete();
1080
+		} else {
1081
+			$this->restore();
1082
+		}
1083
+	}
1084
+
1085
+
1086
+	/**
1087
+	 * Get the status object of this object
1088
+	 *
1089
+	 * @return EE_Status
1090
+	 */
1091
+	public function status_obj()
1092
+	{
1093
+		return $this->get_first_related('Status');
1094
+	}
1095
+
1096
+
1097
+	/**
1098
+	 * Returns the number of times this registration has checked into any of the datetimes
1099
+	 * its available for
1100
+	 *
1101
+	 * @return int
1102
+	 */
1103
+	public function count_checkins()
1104
+	{
1105
+		return $this->get_model()->count_related($this, 'Checkin');
1106
+	}
1107
+
1108
+
1109
+	/**
1110
+	 * Returns the number of current Check-ins this registration is checked into for any of the datetimes the
1111
+	 * registration is for.  Note, this is ONLY checked in (does not include checkedout)
1112
+	 *
1113
+	 * @return int
1114
+	 */
1115
+	public function count_checkins_not_checkedout()
1116
+	{
1117
+		return $this->get_model()->count_related($this, 'Checkin', array(array('CHK_in' => 1)));
1118
+	}
1119
+
1120
+
1121
+	/**
1122
+	 * The purpose of this method is simply to check whether this registration can checkin to the given datetime.
1123
+	 *
1124
+	 * @param int | EE_Datetime $DTT_OR_ID      The datetime the registration is being checked against
1125
+	 * @param bool              $check_approved This is used to indicate whether the caller wants can_checkin to also
1126
+	 *                                          consider registration status as well as datetime access.
1127
+	 * @return bool
1128
+	 */
1129
+	public function can_checkin($DTT_OR_ID, $check_approved = true)
1130
+	{
1131
+		$DTT_ID = EEM_Datetime::instance()->ensure_is_ID($DTT_OR_ID);
1132
+
1133
+		//first check registration status
1134
+		if (($check_approved && ! $this->is_approved()) || ! $DTT_ID) {
1135
+			return false;
1136
+		}
1137
+		//is there a datetime ticket that matches this dtt_ID?
1138
+		if (! (EEM_Datetime_Ticket::instance()->exists(array(
1139
+			array(
1140
+				'TKT_ID' => $this->get('TKT_ID'),
1141
+				'DTT_ID' => $DTT_ID,
1142
+			),
1143
+		)))
1144
+		) {
1145
+			return false;
1146
+		}
1147
+
1148
+		//final check is against TKT_uses
1149
+		return $this->verify_can_checkin_against_TKT_uses($DTT_ID);
1150
+	}
1151
+
1152
+
1153
+	/**
1154
+	 * This method verifies whether the user can checkin for the given datetime considering the max uses value set on
1155
+	 * the ticket. To do this,  a query is done to get the count of the datetime records already checked into.  If the
1156
+	 * datetime given does not have a check-in record and checking in for that datetime will exceed the allowed uses,
1157
+	 * then return false.  Otherwise return true.
1158
+	 *
1159
+	 * @param int | EE_Datetime $DTT_OR_ID The datetime the registration is being checked against
1160
+	 * @return bool   true means can checkin.  false means cannot checkin.
1161
+	 */
1162
+	public function verify_can_checkin_against_TKT_uses($DTT_OR_ID)
1163
+	{
1164
+		$DTT_ID = EEM_Datetime::instance()->ensure_is_ID($DTT_OR_ID);
1165
+
1166
+		if (! $DTT_ID) {
1167
+			return false;
1168
+		}
1169
+
1170
+		$max_uses = $this->ticket() instanceof EE_Ticket ? $this->ticket()->uses() : EE_INF;
1171
+
1172
+		// if max uses is not set or equals infinity then return true cause its not a factor for whether user can check-in
1173
+		// or not.
1174
+		if (! $max_uses || $max_uses === EE_INF) {
1175
+			return true;
1176
+		}
1177
+
1178
+		//does this datetime have a checkin record?  If so, then the dtt count has already been verified so we can just
1179
+		//go ahead and toggle.
1180
+		if (EEM_Checkin::instance()->exists(array(array('REG_ID' => $this->ID(), 'DTT_ID' => $DTT_ID)))) {
1181
+			return true;
1182
+		}
1183
+
1184
+		//made it here so the last check is whether the number of checkins per unique datetime on this registration
1185
+		//disallows further check-ins.
1186
+		$count_unique_dtt_checkins = EEM_Checkin::instance()->count(array(
1187
+			array(
1188
+				'REG_ID' => $this->ID(),
1189
+				'CHK_in' => true,
1190
+			),
1191
+		), 'DTT_ID', true);
1192
+		// checkins have already reached their max number of uses
1193
+		// so registrant can NOT checkin
1194
+		if ($count_unique_dtt_checkins >= $max_uses) {
1195
+			EE_Error::add_error(__('Check-in denied because number of datetime uses for the ticket has been reached or exceeded.',
1196
+				'event_espresso'), __FILE__, __FUNCTION__, __LINE__);
1197
+			return false;
1198
+		}
1199
+		return true;
1200
+	}
1201
+
1202
+
1203
+	/**
1204
+	 * toggle Check-in status for this registration
1205
+	 * Check-ins are toggled in the following order:
1206
+	 * never checked in -> checked in
1207
+	 * checked in -> checked out
1208
+	 * checked out -> checked in
1209
+	 *
1210
+	 * @param  int $DTT_ID  include specific datetime to toggle Check-in for.
1211
+	 *                      If not included or null, then it is assumed latest datetime is being toggled.
1212
+	 * @param bool $verify  If true then can_checkin() is used to verify whether the person
1213
+	 *                      can be checked in or not.  Otherwise this forces change in checkin status.
1214
+	 * @return bool|int     the chk_in status toggled to OR false if nothing got changed.
1215
+	 * @throws EE_Error
1216
+	 */
1217
+	public function toggle_checkin_status($DTT_ID = null, $verify = false)
1218
+	{
1219
+		if (empty($DTT_ID)) {
1220
+			$datetime = $this->get_latest_related_datetime();
1221
+			$DTT_ID   = $datetime instanceof EE_Datetime ? $datetime->ID() : 0;
1222
+			// verify the registration can checkin for the given DTT_ID
1223
+		} elseif (! $this->can_checkin($DTT_ID, $verify)) {
1224
+			EE_Error::add_error(
1225
+				sprintf(
1226
+					__('The given registration (ID:%1$d) can not be checked in to the given DTT_ID (%2$d), because the registration does not have access',
1227
+						'event_espresso'),
1228
+					$this->ID(),
1229
+					$DTT_ID
1230
+				),
1231
+				__FILE__, __FUNCTION__, __LINE__
1232
+			);
1233
+			return false;
1234
+		}
1235
+		$status_paths = array(
1236
+			EE_Registration::checkin_status_never => EE_Registration::checkin_status_in,
1237
+			EE_Registration::checkin_status_in    => EE_Registration::checkin_status_out,
1238
+			EE_Registration::checkin_status_out   => EE_Registration::checkin_status_in,
1239
+		);
1240
+		//start by getting the current status so we know what status we'll be changing to.
1241
+		$cur_status = $this->check_in_status_for_datetime($DTT_ID, null);
1242
+		$status_to  = $status_paths[$cur_status];
1243
+		// database only records true for checked IN or false for checked OUT
1244
+		// no record ( null ) means checked in NEVER, but we obviously don't save that
1245
+		$new_status = $status_to === EE_Registration::checkin_status_in ? true : false;
1246
+		// add relation - note Check-ins are always creating new rows
1247
+		// because we are keeping track of Check-ins over time.
1248
+		// Eventually we'll probably want to show a list table
1249
+		// for the individual Check-ins so that they can be managed.
1250
+		$checkin = EE_Checkin::new_instance(array(
1251
+			'REG_ID' => $this->ID(),
1252
+			'DTT_ID' => $DTT_ID,
1253
+			'CHK_in' => $new_status,
1254
+		));
1255
+		// if the record could not be saved then return false
1256
+		if ($checkin->save() === 0) {
1257
+			if (WP_DEBUG) {
1258
+				global $wpdb;
1259
+				$error = sprintf(
1260
+					__('Registration check in update failed because of the following database error: %1$s%2$s',
1261
+						'event_espresso'),
1262
+					'<br />',
1263
+					$wpdb->last_error
1264
+				);
1265
+			} else {
1266
+				$error = __('Registration check in update failed because of an unknown database error',
1267
+					'event_espresso');
1268
+			}
1269
+			EE_Error::add_error($error, __FILE__, __FUNCTION__, __LINE__);
1270
+			return false;
1271
+		}
1272
+		return $status_to;
1273
+	}
1274
+
1275
+
1276
+	/**
1277
+	 * Returns the latest datetime related to this registration (via the ticket attached to the registration).
1278
+	 * "Latest" is defined by the `DTT_EVT_start` column.
1279
+	 *
1280
+	 * @return EE_Datetime|null
1281
+	 * @throws \EE_Error
1282
+	 */
1283
+	public function get_latest_related_datetime()
1284
+	{
1285
+		return EEM_Datetime::instance()->get_one(
1286
+			array(
1287
+				array(
1288
+					'Ticket.Registration.REG_ID' => $this->ID(),
1289
+				),
1290
+				'order_by' => array('DTT_EVT_start' => 'DESC'),
1291
+			)
1292
+		);
1293
+	}
1294
+
1295
+
1296
+	/**
1297
+	 * Returns the earliest datetime related to this registration (via the ticket attached to the registration).
1298
+	 * "Earliest" is defined by the `DTT_EVT_start` column.
1299
+	 *
1300
+	 * @throws \EE_Error
1301
+	 */
1302
+	public function get_earliest_related_datetime()
1303
+	{
1304
+		return EEM_Datetime::instance()->get_one(
1305
+			array(
1306
+				array(
1307
+					'Ticket.Registration.REG_ID' => $this->ID(),
1308
+				),
1309
+				'order_by' => array('DTT_EVT_start' => 'ASC'),
1310
+			)
1311
+		);
1312
+	}
1313
+
1314
+
1315
+	/**
1316
+	 * This method simply returns the check-in status for this registration and the given datetime.
1317
+	 * If neither the datetime nor the checkin values are provided as arguments,
1318
+	 * then this will return the LATEST check-in status for the registration across all datetimes it belongs to.
1319
+	 *
1320
+	 * @param  int       $DTT_ID  The ID of the datetime we're checking against
1321
+	 *                            (if empty we'll get the primary datetime for
1322
+	 *                            this registration (via event) and use it's ID);
1323
+	 * @param EE_Checkin $checkin If present, we use the given checkin object rather than the dtt_id.
1324
+	 * @return int                Integer representing Check-in status.
1325
+	 * @throws \EE_Error
1326
+	 */
1327
+	public function check_in_status_for_datetime($DTT_ID = 0, $checkin = null)
1328
+	{
1329
+		$checkin_query_params = array(
1330
+			'order_by' => array('CHK_timestamp' => 'DESC'),
1331
+		);
1332
+
1333
+		if ($DTT_ID > 0) {
1334
+			$checkin_query_params[0] = array('DTT_ID' => $DTT_ID);
1335
+		}
1336
+
1337
+		//get checkin object (if exists)
1338
+		$checkin = $checkin instanceof EE_Checkin
1339
+			? $checkin
1340
+			: $this->get_first_related('Checkin', $checkin_query_params);
1341
+		if ($checkin instanceof EE_Checkin) {
1342
+			if ($checkin->get('CHK_in')) {
1343
+				return EE_Registration::checkin_status_in; //checked in
1344
+			}
1345
+			return EE_Registration::checkin_status_out; //had checked in but is now checked out.
1346
+		}
1347
+		return EE_Registration::checkin_status_never; //never been checked in
1348
+	}
1349
+
1350
+
1351
+	/**
1352
+	 * This method returns a localized message for the toggled Check-in message.
1353
+	 *
1354
+	 * @param  int $DTT_ID include specific datetime to get the correct Check-in message.  If not included or null,
1355
+	 *                     then it is assumed Check-in for primary datetime was toggled.
1356
+	 * @param bool $error  This just flags that you want an error message returned. This is put in so that the error
1357
+	 *                     message can be customized with the attendee name.
1358
+	 * @return string         internationalized message
1359
+	 */
1360
+	public function get_checkin_msg($DTT_ID, $error = false)
1361
+	{
1362
+		//let's get the attendee first so we can include the name of the attendee
1363
+		$attendee = $this->get_first_related('Attendee');
1364
+		if ($attendee instanceof EE_Attendee) {
1365
+			if ($error) {
1366
+				return sprintf(__("%s's check-in status was not changed.", "event_espresso"), $attendee->full_name());
1367
+			}
1368
+			$cur_status = $this->check_in_status_for_datetime($DTT_ID);
1369
+			//what is the status message going to be?
1370
+			switch ($cur_status) {
1371
+				case EE_Registration::checkin_status_never :
1372
+					return sprintf(__("%s has been removed from Check-in records", "event_espresso"),
1373
+						$attendee->full_name());
1374
+					break;
1375
+				case EE_Registration::checkin_status_in :
1376
+					return sprintf(__('%s has been checked in', 'event_espresso'), $attendee->full_name());
1377
+					break;
1378
+				case EE_Registration::checkin_status_out :
1379
+					return sprintf(__('%s has been checked out', 'event_espresso'), $attendee->full_name());
1380
+					break;
1381
+			}
1382
+		}
1383
+		return __("The check-in status could not be determined.", "event_espresso");
1384
+	}
1385
+
1386
+
1387
+	/**
1388
+	 * Returns the related EE_Transaction to this registration
1389
+	 *
1390
+	 * @return EE_Transaction
1391
+	 */
1392
+	public function transaction()
1393
+	{
1394
+		$transaction = $this->get_first_related('Transaction');
1395
+		if (! $transaction instanceof \EE_Transaction) {
1396
+			throw new EntityNotFoundException('Transaction ID', $this->transaction_ID());
1397
+		}
1398
+		return $transaction;
1399
+	}
1400
+
1401
+
1402
+	/**
1403
+	 *        get Registration Code
1404
+	 */
1405
+	public function reg_code()
1406
+	{
1407
+		return $this->get('REG_code');
1408
+	}
1409
+
1410
+
1411
+	/**
1412
+	 *        get Transaction ID
1413
+	 */
1414
+	public function transaction_ID()
1415
+	{
1416
+		return $this->get('TXN_ID');
1417
+	}
1418
+
1419
+
1420
+	/**
1421
+	 * @return int
1422
+	 */
1423
+	public function ticket_ID()
1424
+	{
1425
+		return $this->get('TKT_ID');
1426
+	}
1427
+
1428
+
1429
+	/**
1430
+	 *        Set Registration Code
1431
+	 *
1432
+	 * @access    public
1433
+	 * @param    string  $REG_code Registration Code
1434
+	 * @param    boolean $use_default
1435
+	 */
1436
+	public function set_reg_code($REG_code, $use_default = false)
1437
+	{
1438
+		if (empty($REG_code)) {
1439
+			EE_Error::add_error(__('REG_code can not be empty.', 'event_espresso'), __FILE__, __FUNCTION__, __LINE__);
1440
+			return;
1441
+		}
1442
+		if (! $this->reg_code()) {
1443
+			parent::set('REG_code', $REG_code, $use_default);
1444
+		} else {
1445
+			EE_Error::doing_it_wrong(
1446
+				__CLASS__ . '::' . __FUNCTION__,
1447
+				__('Can not change a registration REG_code once it has been set.', 'event_espresso'),
1448
+				'4.6.0'
1449
+			);
1450
+		}
1451
+	}
1452
+
1453
+
1454
+	/**
1455
+	 * Returns all other registrations in the same group as this registrant who have the same ticket option.
1456
+	 * Note, if you want to just get all registrations in the same transaction (group), use:
1457
+	 *    $registration->transaction()->registrations();
1458
+	 *
1459
+	 * @since 4.5.0
1460
+	 * @return EE_Registration[]  or empty array if this isn't a group registration.
1461
+	 */
1462
+	public function get_all_other_registrations_in_group()
1463
+	{
1464
+		if ($this->group_size() < 2) {
1465
+			return array();
1466
+		}
1467
+
1468
+		$query[0] = array(
1469
+			'TXN_ID' => $this->transaction_ID(),
1470
+			'REG_ID' => array('!=', $this->ID()),
1471
+			'TKT_ID' => $this->ticket_ID(),
1472
+		);
1473
+
1474
+		$registrations = $this->get_model()->get_all($query);
1475
+		return $registrations;
1476
+	}
1477
+
1478
+	/**
1479
+	 * Return the link to the admin details for the object.
1480
+	 *
1481
+	 * @return string
1482
+	 */
1483
+	public function get_admin_details_link()
1484
+	{
1485
+		EE_Registry::instance()->load_helper('URL');
1486
+		return EEH_URL::add_query_args_and_nonce(
1487
+			array(
1488
+				'page'    => 'espresso_registrations',
1489
+				'action'  => 'view_registration',
1490
+				'_REG_ID' => $this->ID(),
1491
+			),
1492
+			admin_url('admin.php')
1493
+		);
1494
+	}
1495
+
1496
+	/**
1497
+	 * Returns the link to the editor for the object.  Sometimes this is the same as the details.
1498
+	 *
1499
+	 * @return string
1500
+	 */
1501
+	public function get_admin_edit_link()
1502
+	{
1503
+		return $this->get_admin_details_link();
1504
+	}
1505
+
1506
+	/**
1507
+	 * Returns the link to a settings page for the object.
1508
+	 *
1509
+	 * @return string
1510
+	 */
1511
+	public function get_admin_settings_link()
1512
+	{
1513
+		return $this->get_admin_details_link();
1514
+	}
1515
+
1516
+	/**
1517
+	 * Returns the link to the "overview" for the object (typically the "list table" view).
1518
+	 *
1519
+	 * @return string
1520
+	 */
1521
+	public function get_admin_overview_link()
1522
+	{
1523
+		EE_Registry::instance()->load_helper('URL');
1524
+		return EEH_URL::add_query_args_and_nonce(
1525
+			array(
1526
+				'page' => 'espresso_registrations',
1527
+			),
1528
+			admin_url('admin.php')
1529
+		);
1530
+	}
1531
+
1532
+
1533
+	/**
1534
+	 * @param array $query_params
1535
+	 * @return \EE_Registration[]
1536
+	 * @throws \EE_Error
1537
+	 */
1538
+	public function payments($query_params = array())
1539
+	{
1540
+		return $this->get_many_related('Payment', $query_params);
1541
+	}
1542
+
1543
+
1544
+	/**
1545
+	 * @param array $query_params
1546
+	 * @return \EE_Registration_Payment[]
1547
+	 * @throws \EE_Error
1548
+	 */
1549
+	public function registration_payments($query_params = array())
1550
+	{
1551
+		return $this->get_many_related('Registration_Payment', $query_params);
1552
+	}
1553
+
1554
+
1555
+	/**
1556
+	 * This grabs the payment method corresponding to the last payment made for the amount owing on the registration.
1557
+	 * Note: if there are no payments on the registration there will be no payment method returned.
1558
+	 *
1559
+	 * @return EE_Payment_Method|null
1560
+	 */
1561
+	public function payment_method()
1562
+	{
1563
+		return EEM_Payment_Method::instance()->get_last_used_for_registration($this);
1564
+	}
1565
+
1566
+
1567
+	/**
1568
+	 * @return \EE_Line_Item
1569
+	 * @throws EntityNotFoundException
1570
+	 * @throws \EE_Error
1571
+	 */
1572
+	public function ticket_line_item()
1573
+	{
1574
+		$ticket            = $this->ticket();
1575
+		$transaction       = $this->transaction();
1576
+		$line_item         = null;
1577
+		$ticket_line_items = \EEH_Line_Item::get_line_items_by_object_type_and_IDs(
1578
+			$transaction->total_line_item(),
1579
+			'Ticket',
1580
+			array($ticket->ID())
1581
+		);
1582
+		foreach ($ticket_line_items as $ticket_line_item) {
1583
+			if (
1584
+				$ticket_line_item instanceof \EE_Line_Item
1585
+				&& $ticket_line_item->OBJ_type() === 'Ticket'
1586
+				&& $ticket_line_item->OBJ_ID() === $ticket->ID()
1587
+			) {
1588
+				$line_item = $ticket_line_item;
1589
+				break;
1590
+			}
1591
+		}
1592
+		if (! ($line_item instanceof \EE_Line_Item && $line_item->OBJ_type() === 'Ticket')) {
1593
+			throw new EntityNotFoundException('Line Item Ticket ID', $ticket->ID());
1594
+		}
1595
+		return $line_item;
1596
+	}
1597
+
1598
+
1599
+	/**
1600
+	 * Soft Deletes this model object.
1601
+	 *
1602
+	 * @return boolean | int
1603
+	 * @throws \RuntimeException
1604
+	 * @throws \EE_Error
1605
+	 */
1606
+	public function delete()
1607
+	{
1608
+		if ($this->update_extra_meta(EE_Registration::PRE_TRASH_REG_STATUS_KEY, $this->status_ID()) === true) {
1609
+			$this->set_status(EEM_Registration::status_id_cancelled);
1610
+		}
1611
+		return parent::delete();
1612
+	}
1613
+
1614
+
1615
+	/**
1616
+	 * Restores whatever the previous status was on a registration before it was trashed (if possible)
1617
+	 *
1618
+	 * @throws \EE_Error
1619
+	 * @throws \RuntimeException
1620
+	 */
1621
+	public function restore()
1622
+	{
1623
+		$previous_status = $this->get_extra_meta(
1624
+			EE_Registration::PRE_TRASH_REG_STATUS_KEY,
1625
+			true,
1626
+			EEM_Registration::status_id_cancelled
1627
+		);
1628
+		if ($previous_status) {
1629
+			$this->delete_extra_meta(EE_Registration::PRE_TRASH_REG_STATUS_KEY);
1630
+			$this->set_status($previous_status);
1631
+		}
1632
+		return parent::restore();
1633
+	}
1634
+
1635
+
1636
+
1637
+	/*************************** DEPRECATED ***************************/
1638
+
1639
+
1640
+	/**
1641
+	 * @deprecated
1642
+	 * @since     4.7.0
1643
+	 * @access    public
1644
+	 */
1645
+	public function price_paid()
1646
+	{
1647
+		EE_Error::doing_it_wrong('EE_Registration::price_paid()',
1648
+			__('This method is deprecated, please use EE_Registration::final_price() instead.', 'event_espresso'),
1649
+			'4.7.0');
1650
+		return $this->final_price();
1651
+	}
1652
+
1653
+
1654
+	/**
1655
+	 * @deprecated
1656
+	 * @since     4.7.0
1657
+	 * @access    public
1658
+	 * @param    float $REG_final_price
1659
+	 */
1660
+	public function set_price_paid($REG_final_price = 0.00)
1661
+	{
1662
+		EE_Error::doing_it_wrong('EE_Registration::set_price_paid()',
1663
+			__('This method is deprecated, please use EE_Registration::set_final_price() instead.', 'event_espresso'),
1664
+			'4.7.0');
1665
+		$this->set_final_price($REG_final_price);
1666
+	}
1667
+
1668
+
1669
+	/**
1670
+	 * @deprecated
1671
+	 * @since 4.7.0
1672
+	 * @return string
1673
+	 */
1674
+	public function pretty_price_paid()
1675
+	{
1676
+		EE_Error::doing_it_wrong('EE_Registration::pretty_price_paid()',
1677
+			__('This method is deprecated, please use EE_Registration::pretty_final_price() instead.',
1678
+				'event_espresso'), '4.7.0');
1679
+		return $this->pretty_final_price();
1680
+	}
1681
+
1682
+
1683
+	/**
1684
+	 * Gets the primary datetime related to this registration via the related Event to this registration
1685
+	 *
1686
+	 * @deprecated 4.9.17
1687
+	 * @return EE_Datetime
1688
+	 */
1689
+	public function get_related_primary_datetime()
1690
+	{
1691
+		EE_Error::doing_it_wrong(
1692
+			__METHOD__,
1693
+			esc_html__(
1694
+				'Use EE_Registration::get_latest_related_datetime() or EE_Registration::get_earliest_related_datetime()',
1695
+				'event_espresso'
1696
+			),
1697
+			'4.9.17',
1698
+			'5.0.0'
1699
+		);
1700
+		return $this->event()->primary_datetime();
1701
+	}
1702 1702
 
1703 1703
 
1704 1704
 }
Please login to merge, or discard this patch.