@@ -59,7 +59,7 @@ discard block |
||
59 | 59 | public static function instance() |
60 | 60 | { |
61 | 61 | // check if class object is instantiated |
62 | - if (! self::$_instance instanceof EE_Maintenance_Mode) { |
|
62 | + if ( ! self::$_instance instanceof EE_Maintenance_Mode) { |
|
63 | 63 | self::$_instance = new self(); |
64 | 64 | } |
65 | 65 | return self::$_instance; |
@@ -184,7 +184,7 @@ discard block |
||
184 | 184 | */ |
185 | 185 | public static function disable_frontend_for_maintenance() |
186 | 186 | { |
187 | - return (! is_admin() && EE_Maintenance_Mode::instance()->level()); |
|
187 | + return ( ! is_admin() && EE_Maintenance_Mode::instance()->level()); |
|
188 | 188 | } |
189 | 189 | |
190 | 190 | |
@@ -199,14 +199,14 @@ discard block |
||
199 | 199 | ) { |
200 | 200 | wp_register_style( |
201 | 201 | 'espresso_default', |
202 | - EE_GLOBAL_ASSETS_URL . 'css/espresso_default.css', |
|
202 | + EE_GLOBAL_ASSETS_URL.'css/espresso_default.css', |
|
203 | 203 | ['dashicons'], |
204 | 204 | EVENT_ESPRESSO_VERSION |
205 | 205 | ); |
206 | 206 | wp_enqueue_style('espresso_default'); |
207 | 207 | wp_register_script( |
208 | 208 | 'espresso_core', |
209 | - EE_GLOBAL_ASSETS_URL . 'scripts/espresso_core.js', |
|
209 | + EE_GLOBAL_ASSETS_URL.'scripts/espresso_core.js', |
|
210 | 210 | ['jquery'], |
211 | 211 | EVENT_ESPRESSO_VERSION, |
212 | 212 | true |
@@ -226,7 +226,7 @@ discard block |
||
226 | 226 | public static function template_include() |
227 | 227 | { |
228 | 228 | // shut 'er down for maintenance ? then don't use any of our templates for our endpoints |
229 | - return get_template_directory() . '/index.php'; |
|
229 | + return get_template_directory().'/index.php'; |
|
230 | 230 | } |
231 | 231 | |
232 | 232 | |
@@ -278,10 +278,10 @@ discard block |
||
278 | 278 | ), |
279 | 279 | '<div id="ee-m-mode-admin-notice-dv" class="ee-really-important-notice-dv"><a class="close-espresso-notice" title="', |
280 | 280 | '"><span class="dashicons dashicons-no"></span></a><p>', |
281 | - ' » <a href="' . add_query_arg( |
|
281 | + ' » <a href="'.add_query_arg( |
|
282 | 282 | ['page' => 'espresso_maintenance_settings'], |
283 | 283 | admin_url('admin.php') |
284 | - ) . '">', |
|
284 | + ).'">', |
|
285 | 285 | '</a></p></div>' |
286 | 286 | ); |
287 | 287 | } |
@@ -15,340 +15,340 @@ |
||
15 | 15 | */ |
16 | 16 | class EE_Maintenance_Mode implements ResettableInterface |
17 | 17 | { |
18 | - /** |
|
19 | - * constants available to client code for interpreting the values of EE_Maintenance_Mode::level(). |
|
20 | - * level_0_not_in_maintenance means the site is NOT in maintenance mode (so everything's normal) |
|
21 | - */ |
|
22 | - const level_0_not_in_maintenance = 0; |
|
23 | - |
|
24 | - /** |
|
25 | - * level_1_frontend_only_maintenance means that the site's frontend EE code should be completely disabled |
|
26 | - * but the admin backend should be running as normal. Maybe an admin can view the frontend though |
|
27 | - */ |
|
28 | - const level_1_frontend_only_maintenance = 1; |
|
29 | - |
|
30 | - /** |
|
31 | - * level_2_complete_maintenance means the frontend AND EE backend code are disabled. The only system running |
|
32 | - * is the maintenance mode stuff, which will require users to update all addons, and then finish running all |
|
33 | - * migration scripts before taking the site out of maintenance mode |
|
34 | - */ |
|
35 | - const level_2_complete_maintenance = 2; |
|
36 | - |
|
37 | - /** |
|
38 | - * the name of the option which stores the current level of maintenance mode |
|
39 | - */ |
|
40 | - const option_name_maintenance_mode = 'ee_maintenance_mode'; |
|
41 | - |
|
42 | - |
|
43 | - /** |
|
44 | - * @var EE_Maintenance_Mode $_instance |
|
45 | - */ |
|
46 | - private static $_instance; |
|
47 | - |
|
48 | - /** |
|
49 | - * @var EE_Registry $EE |
|
50 | - */ |
|
51 | - protected $EE; |
|
52 | - |
|
53 | - |
|
54 | - /** |
|
55 | - * @singleton method used to instantiate class object |
|
56 | - * @return EE_Maintenance_Mode |
|
57 | - */ |
|
58 | - public static function instance() |
|
59 | - { |
|
60 | - // check if class object is instantiated |
|
61 | - if (! self::$_instance instanceof EE_Maintenance_Mode) { |
|
62 | - self::$_instance = new self(); |
|
63 | - } |
|
64 | - return self::$_instance; |
|
65 | - } |
|
66 | - |
|
67 | - |
|
68 | - /** |
|
69 | - * Resets maintenance mode (mostly just re-checks whether we should be in maintenance mode) |
|
70 | - * |
|
71 | - * @return EE_Maintenance_Mode |
|
72 | - * @throws EE_Error |
|
73 | - */ |
|
74 | - public static function reset() |
|
75 | - { |
|
76 | - self::instance()->set_maintenance_mode_if_db_old(); |
|
77 | - return self::instance(); |
|
78 | - } |
|
79 | - |
|
80 | - |
|
81 | - /** |
|
82 | - *private constructor to prevent direct creation |
|
83 | - */ |
|
84 | - private function __construct() |
|
85 | - { |
|
86 | - // if M-Mode level 2 is engaged, we still need basic assets loaded |
|
87 | - add_action('wp_enqueue_scripts', [$this, 'load_assets_required_for_m_mode']); |
|
88 | - // shut 'er down for maintenance ? |
|
89 | - add_filter('the_content', [$this, 'the_content'], 2); |
|
90 | - // add powered by EE msg |
|
91 | - add_action('shutdown', [$this, 'display_maintenance_mode_notice'], 10); |
|
92 | - } |
|
93 | - |
|
94 | - |
|
95 | - /** |
|
96 | - * retrieves the maintenance mode option value from the db |
|
97 | - * |
|
98 | - * @return int |
|
99 | - */ |
|
100 | - public function real_level() |
|
101 | - { |
|
102 | - return (int) get_option(self::option_name_maintenance_mode, EE_Maintenance_Mode::level_0_not_in_maintenance); |
|
103 | - } |
|
104 | - |
|
105 | - |
|
106 | - /** |
|
107 | - * Returns whether the models reportedly are able to run queries or not |
|
108 | - * (ie, if the system thinks their tables are present and up-to-date). |
|
109 | - * |
|
110 | - * @return boolean |
|
111 | - */ |
|
112 | - public function models_can_query() |
|
113 | - { |
|
114 | - return $this->real_level() !== EE_Maintenance_Mode::level_2_complete_maintenance; |
|
115 | - } |
|
116 | - |
|
117 | - |
|
118 | - /** |
|
119 | - * Determines whether we're in maintenance mode and what level. However, while the site |
|
120 | - * is in level 1 maintenance, and an admin visits the frontend, this function makes it appear |
|
121 | - * to them as if teh site isn't in maintenance mode. |
|
122 | - * EE_Maintenance_Mode::level_0_not_in_maintenance => not in maintenance mode (in normal mode) |
|
123 | - * EE_Maintenance_Mode::level_1_frontend_only_maintenance=> frontend-only maintenance mode |
|
124 | - * EE_Maintenance_Mode::level_2_complete_maintenance => frontend and backend maintenance mode |
|
125 | - * |
|
126 | - * @return int |
|
127 | - */ |
|
128 | - public function level() |
|
129 | - { |
|
130 | - $maintenance_mode_level = $this->real_level(); |
|
131 | - // if this is an admin request, we'll be honest... except if it's ajax, because that might be from the frontend |
|
132 | - if ( |
|
133 | - $maintenance_mode_level === EE_Maintenance_Mode::level_1_frontend_only_maintenance// we're in level 1 |
|
134 | - && ((defined('DOING_AJAX') && DOING_AJAX) || ! is_admin()) // on non-ajax frontend requests |
|
135 | - && current_user_can('administrator') // when the user is an admin |
|
136 | - ) { |
|
137 | - $maintenance_mode_level = EE_Maintenance_Mode::level_0_not_in_maintenance; |
|
138 | - } |
|
139 | - return $maintenance_mode_level; |
|
140 | - } |
|
141 | - |
|
142 | - |
|
143 | - /** |
|
144 | - * Determines if we need to put EE in maintenance mode because the database needs updating |
|
145 | - * |
|
146 | - * @return boolean true if DB is old and maintenance mode was triggered; false otherwise |
|
147 | - * @throws EE_Error |
|
148 | - */ |
|
149 | - public function set_maintenance_mode_if_db_old() |
|
150 | - { |
|
151 | - LoaderFactory::getLoader()->getShared('Data_Migration_Manager'); |
|
152 | - if (EE_Data_Migration_Manager::instance()->check_for_applicable_data_migration_scripts()) { |
|
153 | - update_option(self::option_name_maintenance_mode, self::level_2_complete_maintenance); |
|
154 | - return true; |
|
155 | - } |
|
156 | - if ($this->level() === self::level_2_complete_maintenance) { |
|
157 | - // we also want to handle the opposite: if the site is mm2, but there aren't any migrations to run |
|
158 | - // then we shouldn't be in mm2. (Maybe an addon got deactivated?) |
|
159 | - update_option(self::option_name_maintenance_mode, self::level_0_not_in_maintenance); |
|
160 | - return false; |
|
161 | - } |
|
162 | - return false; |
|
163 | - } |
|
164 | - |
|
165 | - |
|
166 | - /** |
|
167 | - * Updates the maintenance level on the site |
|
168 | - * |
|
169 | - * @param int $level |
|
170 | - * @return void |
|
171 | - */ |
|
172 | - public function set_maintenance_level($level) |
|
173 | - { |
|
174 | - do_action('AHEE__EE_Maintenance_Mode__set_maintenance_level', $level); |
|
175 | - update_option(self::option_name_maintenance_mode, (int) $level); |
|
176 | - } |
|
177 | - |
|
178 | - |
|
179 | - /** |
|
180 | - * returns TRUE if M-Mode is engaged and the current request is not for the admin |
|
181 | - * |
|
182 | - * @return bool |
|
183 | - */ |
|
184 | - public static function disable_frontend_for_maintenance() |
|
185 | - { |
|
186 | - return (! is_admin() && EE_Maintenance_Mode::instance()->level()); |
|
187 | - } |
|
188 | - |
|
189 | - |
|
190 | - /** |
|
191 | - * @return void |
|
192 | - */ |
|
193 | - public function load_assets_required_for_m_mode() |
|
194 | - { |
|
195 | - if ( |
|
196 | - $this->real_level() === EE_Maintenance_Mode::level_2_complete_maintenance |
|
197 | - && ! wp_script_is('espresso_core') |
|
198 | - ) { |
|
199 | - wp_register_style( |
|
200 | - 'espresso_default', |
|
201 | - EE_GLOBAL_ASSETS_URL . 'css/espresso_default.css', |
|
202 | - ['dashicons'], |
|
203 | - EVENT_ESPRESSO_VERSION |
|
204 | - ); |
|
205 | - wp_enqueue_style('espresso_default'); |
|
206 | - wp_register_script( |
|
207 | - 'espresso_core', |
|
208 | - EE_GLOBAL_ASSETS_URL . 'scripts/espresso_core.js', |
|
209 | - ['jquery'], |
|
210 | - EVENT_ESPRESSO_VERSION, |
|
211 | - true |
|
212 | - ); |
|
213 | - wp_enqueue_script('espresso_core'); |
|
214 | - } |
|
215 | - } |
|
216 | - |
|
217 | - |
|
218 | - /** |
|
219 | - * replacement EE CPT template that displays message notifying site visitors |
|
220 | - * that EE has been temporarily placed into maintenance mode |
|
221 | - * does NOT get called on non-EE-CPT requests |
|
222 | - * |
|
223 | - * @return string |
|
224 | - */ |
|
225 | - public static function template_include() |
|
226 | - { |
|
227 | - // shut 'er down for maintenance ? then don't use any of our templates for our endpoints |
|
228 | - return get_template_directory() . '/index.php'; |
|
229 | - } |
|
230 | - |
|
231 | - |
|
232 | - /** |
|
233 | - * displays message notifying site visitors that EE has been temporarily |
|
234 | - * placed into maintenance mode when post_type != EE CPT |
|
235 | - * |
|
236 | - * @param string $the_content |
|
237 | - * @return string |
|
238 | - */ |
|
239 | - public function the_content($the_content) |
|
240 | - { |
|
241 | - // check if M-mode is engaged and for EE shortcode |
|
242 | - if ($this->level() && strpos($the_content, '[ESPRESSO_') !== false) { |
|
243 | - // this can eventually be moved to a template, or edited via admin. But for now... |
|
244 | - $the_content = sprintf( |
|
245 | - esc_html__( |
|
246 | - '%sMaintenance Mode%sEvent Registration has been temporarily closed while system maintenance is being performed. We\'re sorry for any inconveniences this may have caused. Please try back again later.%s', |
|
247 | - 'event_espresso' |
|
248 | - ), |
|
249 | - '<h3>', |
|
250 | - '</h3><p>', |
|
251 | - '</p>' |
|
252 | - ); |
|
253 | - } |
|
254 | - return $the_content; |
|
255 | - } |
|
256 | - |
|
257 | - |
|
258 | - /** |
|
259 | - * displays message on frontend of site notifying admin that EE has been temporarily placed into maintenance mode |
|
260 | - */ |
|
261 | - public function display_maintenance_mode_notice() |
|
262 | - { |
|
263 | - /** @var CurrentPage $current_page */ |
|
264 | - $current_page = LoaderFactory::getLoader()->getShared(CurrentPage::class); |
|
265 | - // check if M-mode is engaged and for EE shortcode |
|
266 | - if ( |
|
267 | - ! (defined('DOING_AJAX') && DOING_AJAX) |
|
268 | - && $this->real_level() |
|
269 | - && ! is_admin() |
|
270 | - && current_user_can('administrator') |
|
271 | - && $current_page->isEspressoPage() |
|
272 | - ) { |
|
273 | - printf( |
|
274 | - esc_html__( |
|
275 | - '%sclose%sEvent Registration is currently disabled because Event Espresso has been placed into Maintenance Mode. To change Maintenance Mode settings, click here %sEE Maintenance Mode Admin Page%s', |
|
276 | - 'event_espresso' |
|
277 | - ), |
|
278 | - '<div id="ee-m-mode-admin-notice-dv" class="ee-really-important-notice-dv"><a class="close-espresso-notice" title="', |
|
279 | - '"><span class="dashicons dashicons-no"></span></a><p>', |
|
280 | - ' » <a href="' . add_query_arg( |
|
281 | - ['page' => 'espresso_maintenance_settings'], |
|
282 | - admin_url('admin.php') |
|
283 | - ) . '">', |
|
284 | - '</a></p></div>' |
|
285 | - ); |
|
286 | - } |
|
287 | - } |
|
288 | - // espresso-notices important-notice ee-attention |
|
289 | - |
|
290 | - |
|
291 | - /** |
|
292 | - * override magic methods |
|
293 | - */ |
|
294 | - final public function __destruct() |
|
295 | - { |
|
296 | - } |
|
297 | - |
|
298 | - |
|
299 | - final public function __call($a, $b) |
|
300 | - { |
|
301 | - } |
|
302 | - |
|
303 | - |
|
304 | - final public function __get($a) |
|
305 | - { |
|
306 | - } |
|
307 | - |
|
308 | - |
|
309 | - final public function __set($a, $b) |
|
310 | - { |
|
311 | - } |
|
312 | - |
|
313 | - |
|
314 | - final public function __isset($a) |
|
315 | - { |
|
316 | - } |
|
317 | - |
|
318 | - |
|
319 | - final public function __unset($a) |
|
320 | - { |
|
321 | - } |
|
322 | - |
|
323 | - |
|
324 | - final public function __sleep() |
|
325 | - { |
|
326 | - return []; |
|
327 | - } |
|
328 | - |
|
329 | - |
|
330 | - final public function __wakeup() |
|
331 | - { |
|
332 | - } |
|
333 | - |
|
334 | - |
|
335 | - final public function __invoke() |
|
336 | - { |
|
337 | - } |
|
338 | - |
|
339 | - |
|
340 | - final public static function __set_state($a = null) |
|
341 | - { |
|
342 | - return EE_Maintenance_Mode::instance(); |
|
343 | - } |
|
344 | - |
|
345 | - |
|
346 | - final public function __clone() |
|
347 | - { |
|
348 | - } |
|
18 | + /** |
|
19 | + * constants available to client code for interpreting the values of EE_Maintenance_Mode::level(). |
|
20 | + * level_0_not_in_maintenance means the site is NOT in maintenance mode (so everything's normal) |
|
21 | + */ |
|
22 | + const level_0_not_in_maintenance = 0; |
|
23 | + |
|
24 | + /** |
|
25 | + * level_1_frontend_only_maintenance means that the site's frontend EE code should be completely disabled |
|
26 | + * but the admin backend should be running as normal. Maybe an admin can view the frontend though |
|
27 | + */ |
|
28 | + const level_1_frontend_only_maintenance = 1; |
|
29 | + |
|
30 | + /** |
|
31 | + * level_2_complete_maintenance means the frontend AND EE backend code are disabled. The only system running |
|
32 | + * is the maintenance mode stuff, which will require users to update all addons, and then finish running all |
|
33 | + * migration scripts before taking the site out of maintenance mode |
|
34 | + */ |
|
35 | + const level_2_complete_maintenance = 2; |
|
36 | + |
|
37 | + /** |
|
38 | + * the name of the option which stores the current level of maintenance mode |
|
39 | + */ |
|
40 | + const option_name_maintenance_mode = 'ee_maintenance_mode'; |
|
41 | + |
|
42 | + |
|
43 | + /** |
|
44 | + * @var EE_Maintenance_Mode $_instance |
|
45 | + */ |
|
46 | + private static $_instance; |
|
47 | + |
|
48 | + /** |
|
49 | + * @var EE_Registry $EE |
|
50 | + */ |
|
51 | + protected $EE; |
|
52 | + |
|
53 | + |
|
54 | + /** |
|
55 | + * @singleton method used to instantiate class object |
|
56 | + * @return EE_Maintenance_Mode |
|
57 | + */ |
|
58 | + public static function instance() |
|
59 | + { |
|
60 | + // check if class object is instantiated |
|
61 | + if (! self::$_instance instanceof EE_Maintenance_Mode) { |
|
62 | + self::$_instance = new self(); |
|
63 | + } |
|
64 | + return self::$_instance; |
|
65 | + } |
|
66 | + |
|
67 | + |
|
68 | + /** |
|
69 | + * Resets maintenance mode (mostly just re-checks whether we should be in maintenance mode) |
|
70 | + * |
|
71 | + * @return EE_Maintenance_Mode |
|
72 | + * @throws EE_Error |
|
73 | + */ |
|
74 | + public static function reset() |
|
75 | + { |
|
76 | + self::instance()->set_maintenance_mode_if_db_old(); |
|
77 | + return self::instance(); |
|
78 | + } |
|
79 | + |
|
80 | + |
|
81 | + /** |
|
82 | + *private constructor to prevent direct creation |
|
83 | + */ |
|
84 | + private function __construct() |
|
85 | + { |
|
86 | + // if M-Mode level 2 is engaged, we still need basic assets loaded |
|
87 | + add_action('wp_enqueue_scripts', [$this, 'load_assets_required_for_m_mode']); |
|
88 | + // shut 'er down for maintenance ? |
|
89 | + add_filter('the_content', [$this, 'the_content'], 2); |
|
90 | + // add powered by EE msg |
|
91 | + add_action('shutdown', [$this, 'display_maintenance_mode_notice'], 10); |
|
92 | + } |
|
93 | + |
|
94 | + |
|
95 | + /** |
|
96 | + * retrieves the maintenance mode option value from the db |
|
97 | + * |
|
98 | + * @return int |
|
99 | + */ |
|
100 | + public function real_level() |
|
101 | + { |
|
102 | + return (int) get_option(self::option_name_maintenance_mode, EE_Maintenance_Mode::level_0_not_in_maintenance); |
|
103 | + } |
|
104 | + |
|
105 | + |
|
106 | + /** |
|
107 | + * Returns whether the models reportedly are able to run queries or not |
|
108 | + * (ie, if the system thinks their tables are present and up-to-date). |
|
109 | + * |
|
110 | + * @return boolean |
|
111 | + */ |
|
112 | + public function models_can_query() |
|
113 | + { |
|
114 | + return $this->real_level() !== EE_Maintenance_Mode::level_2_complete_maintenance; |
|
115 | + } |
|
116 | + |
|
117 | + |
|
118 | + /** |
|
119 | + * Determines whether we're in maintenance mode and what level. However, while the site |
|
120 | + * is in level 1 maintenance, and an admin visits the frontend, this function makes it appear |
|
121 | + * to them as if teh site isn't in maintenance mode. |
|
122 | + * EE_Maintenance_Mode::level_0_not_in_maintenance => not in maintenance mode (in normal mode) |
|
123 | + * EE_Maintenance_Mode::level_1_frontend_only_maintenance=> frontend-only maintenance mode |
|
124 | + * EE_Maintenance_Mode::level_2_complete_maintenance => frontend and backend maintenance mode |
|
125 | + * |
|
126 | + * @return int |
|
127 | + */ |
|
128 | + public function level() |
|
129 | + { |
|
130 | + $maintenance_mode_level = $this->real_level(); |
|
131 | + // if this is an admin request, we'll be honest... except if it's ajax, because that might be from the frontend |
|
132 | + if ( |
|
133 | + $maintenance_mode_level === EE_Maintenance_Mode::level_1_frontend_only_maintenance// we're in level 1 |
|
134 | + && ((defined('DOING_AJAX') && DOING_AJAX) || ! is_admin()) // on non-ajax frontend requests |
|
135 | + && current_user_can('administrator') // when the user is an admin |
|
136 | + ) { |
|
137 | + $maintenance_mode_level = EE_Maintenance_Mode::level_0_not_in_maintenance; |
|
138 | + } |
|
139 | + return $maintenance_mode_level; |
|
140 | + } |
|
141 | + |
|
142 | + |
|
143 | + /** |
|
144 | + * Determines if we need to put EE in maintenance mode because the database needs updating |
|
145 | + * |
|
146 | + * @return boolean true if DB is old and maintenance mode was triggered; false otherwise |
|
147 | + * @throws EE_Error |
|
148 | + */ |
|
149 | + public function set_maintenance_mode_if_db_old() |
|
150 | + { |
|
151 | + LoaderFactory::getLoader()->getShared('Data_Migration_Manager'); |
|
152 | + if (EE_Data_Migration_Manager::instance()->check_for_applicable_data_migration_scripts()) { |
|
153 | + update_option(self::option_name_maintenance_mode, self::level_2_complete_maintenance); |
|
154 | + return true; |
|
155 | + } |
|
156 | + if ($this->level() === self::level_2_complete_maintenance) { |
|
157 | + // we also want to handle the opposite: if the site is mm2, but there aren't any migrations to run |
|
158 | + // then we shouldn't be in mm2. (Maybe an addon got deactivated?) |
|
159 | + update_option(self::option_name_maintenance_mode, self::level_0_not_in_maintenance); |
|
160 | + return false; |
|
161 | + } |
|
162 | + return false; |
|
163 | + } |
|
164 | + |
|
165 | + |
|
166 | + /** |
|
167 | + * Updates the maintenance level on the site |
|
168 | + * |
|
169 | + * @param int $level |
|
170 | + * @return void |
|
171 | + */ |
|
172 | + public function set_maintenance_level($level) |
|
173 | + { |
|
174 | + do_action('AHEE__EE_Maintenance_Mode__set_maintenance_level', $level); |
|
175 | + update_option(self::option_name_maintenance_mode, (int) $level); |
|
176 | + } |
|
177 | + |
|
178 | + |
|
179 | + /** |
|
180 | + * returns TRUE if M-Mode is engaged and the current request is not for the admin |
|
181 | + * |
|
182 | + * @return bool |
|
183 | + */ |
|
184 | + public static function disable_frontend_for_maintenance() |
|
185 | + { |
|
186 | + return (! is_admin() && EE_Maintenance_Mode::instance()->level()); |
|
187 | + } |
|
188 | + |
|
189 | + |
|
190 | + /** |
|
191 | + * @return void |
|
192 | + */ |
|
193 | + public function load_assets_required_for_m_mode() |
|
194 | + { |
|
195 | + if ( |
|
196 | + $this->real_level() === EE_Maintenance_Mode::level_2_complete_maintenance |
|
197 | + && ! wp_script_is('espresso_core') |
|
198 | + ) { |
|
199 | + wp_register_style( |
|
200 | + 'espresso_default', |
|
201 | + EE_GLOBAL_ASSETS_URL . 'css/espresso_default.css', |
|
202 | + ['dashicons'], |
|
203 | + EVENT_ESPRESSO_VERSION |
|
204 | + ); |
|
205 | + wp_enqueue_style('espresso_default'); |
|
206 | + wp_register_script( |
|
207 | + 'espresso_core', |
|
208 | + EE_GLOBAL_ASSETS_URL . 'scripts/espresso_core.js', |
|
209 | + ['jquery'], |
|
210 | + EVENT_ESPRESSO_VERSION, |
|
211 | + true |
|
212 | + ); |
|
213 | + wp_enqueue_script('espresso_core'); |
|
214 | + } |
|
215 | + } |
|
216 | + |
|
217 | + |
|
218 | + /** |
|
219 | + * replacement EE CPT template that displays message notifying site visitors |
|
220 | + * that EE has been temporarily placed into maintenance mode |
|
221 | + * does NOT get called on non-EE-CPT requests |
|
222 | + * |
|
223 | + * @return string |
|
224 | + */ |
|
225 | + public static function template_include() |
|
226 | + { |
|
227 | + // shut 'er down for maintenance ? then don't use any of our templates for our endpoints |
|
228 | + return get_template_directory() . '/index.php'; |
|
229 | + } |
|
230 | + |
|
231 | + |
|
232 | + /** |
|
233 | + * displays message notifying site visitors that EE has been temporarily |
|
234 | + * placed into maintenance mode when post_type != EE CPT |
|
235 | + * |
|
236 | + * @param string $the_content |
|
237 | + * @return string |
|
238 | + */ |
|
239 | + public function the_content($the_content) |
|
240 | + { |
|
241 | + // check if M-mode is engaged and for EE shortcode |
|
242 | + if ($this->level() && strpos($the_content, '[ESPRESSO_') !== false) { |
|
243 | + // this can eventually be moved to a template, or edited via admin. But for now... |
|
244 | + $the_content = sprintf( |
|
245 | + esc_html__( |
|
246 | + '%sMaintenance Mode%sEvent Registration has been temporarily closed while system maintenance is being performed. We\'re sorry for any inconveniences this may have caused. Please try back again later.%s', |
|
247 | + 'event_espresso' |
|
248 | + ), |
|
249 | + '<h3>', |
|
250 | + '</h3><p>', |
|
251 | + '</p>' |
|
252 | + ); |
|
253 | + } |
|
254 | + return $the_content; |
|
255 | + } |
|
256 | + |
|
257 | + |
|
258 | + /** |
|
259 | + * displays message on frontend of site notifying admin that EE has been temporarily placed into maintenance mode |
|
260 | + */ |
|
261 | + public function display_maintenance_mode_notice() |
|
262 | + { |
|
263 | + /** @var CurrentPage $current_page */ |
|
264 | + $current_page = LoaderFactory::getLoader()->getShared(CurrentPage::class); |
|
265 | + // check if M-mode is engaged and for EE shortcode |
|
266 | + if ( |
|
267 | + ! (defined('DOING_AJAX') && DOING_AJAX) |
|
268 | + && $this->real_level() |
|
269 | + && ! is_admin() |
|
270 | + && current_user_can('administrator') |
|
271 | + && $current_page->isEspressoPage() |
|
272 | + ) { |
|
273 | + printf( |
|
274 | + esc_html__( |
|
275 | + '%sclose%sEvent Registration is currently disabled because Event Espresso has been placed into Maintenance Mode. To change Maintenance Mode settings, click here %sEE Maintenance Mode Admin Page%s', |
|
276 | + 'event_espresso' |
|
277 | + ), |
|
278 | + '<div id="ee-m-mode-admin-notice-dv" class="ee-really-important-notice-dv"><a class="close-espresso-notice" title="', |
|
279 | + '"><span class="dashicons dashicons-no"></span></a><p>', |
|
280 | + ' » <a href="' . add_query_arg( |
|
281 | + ['page' => 'espresso_maintenance_settings'], |
|
282 | + admin_url('admin.php') |
|
283 | + ) . '">', |
|
284 | + '</a></p></div>' |
|
285 | + ); |
|
286 | + } |
|
287 | + } |
|
288 | + // espresso-notices important-notice ee-attention |
|
289 | + |
|
290 | + |
|
291 | + /** |
|
292 | + * override magic methods |
|
293 | + */ |
|
294 | + final public function __destruct() |
|
295 | + { |
|
296 | + } |
|
297 | + |
|
298 | + |
|
299 | + final public function __call($a, $b) |
|
300 | + { |
|
301 | + } |
|
302 | + |
|
303 | + |
|
304 | + final public function __get($a) |
|
305 | + { |
|
306 | + } |
|
307 | + |
|
308 | + |
|
309 | + final public function __set($a, $b) |
|
310 | + { |
|
311 | + } |
|
312 | + |
|
313 | + |
|
314 | + final public function __isset($a) |
|
315 | + { |
|
316 | + } |
|
317 | + |
|
318 | + |
|
319 | + final public function __unset($a) |
|
320 | + { |
|
321 | + } |
|
322 | + |
|
323 | + |
|
324 | + final public function __sleep() |
|
325 | + { |
|
326 | + return []; |
|
327 | + } |
|
328 | + |
|
329 | + |
|
330 | + final public function __wakeup() |
|
331 | + { |
|
332 | + } |
|
333 | + |
|
334 | + |
|
335 | + final public function __invoke() |
|
336 | + { |
|
337 | + } |
|
338 | + |
|
339 | + |
|
340 | + final public static function __set_state($a = null) |
|
341 | + { |
|
342 | + return EE_Maintenance_Mode::instance(); |
|
343 | + } |
|
344 | + |
|
345 | + |
|
346 | + final public function __clone() |
|
347 | + { |
|
348 | + } |
|
349 | 349 | |
350 | 350 | |
351 | - final public static function __callStatic($a, $b) |
|
352 | - { |
|
353 | - } |
|
351 | + final public static function __callStatic($a, $b) |
|
352 | + { |
|
353 | + } |
|
354 | 354 | } |
@@ -97,9 +97,9 @@ discard block |
||
97 | 97 | $active_plugins = array_map('strtolower', $active_plugins); |
98 | 98 | $plugin_info = array(); |
99 | 99 | foreach ($active_plugins as $plugin) { |
100 | - $plugin_data = @get_plugin_data(WP_PLUGIN_DIR . '/' . $plugin); |
|
100 | + $plugin_data = @get_plugin_data(WP_PLUGIN_DIR.'/'.$plugin); |
|
101 | 101 | |
102 | - $plugin_info[ $plugin ] = $plugin_data; |
|
102 | + $plugin_info[$plugin] = $plugin_data; |
|
103 | 103 | } |
104 | 104 | return $plugin_info; |
105 | 105 | } |
@@ -124,7 +124,7 @@ discard block |
||
124 | 124 | ); |
125 | 125 | $wp_memory_to_display .= '</mark>'; |
126 | 126 | } else { |
127 | - $wp_memory_to_display = '<mark class="yes">' . size_format($wp_memory_int) . '</mark>'; |
|
127 | + $wp_memory_to_display = '<mark class="yes">'.size_format($wp_memory_int).'</mark>'; |
|
128 | 128 | } |
129 | 129 | return array( |
130 | 130 | 'name' => get_bloginfo('name', 'display'), |
@@ -163,7 +163,7 @@ discard block |
||
163 | 163 | $options = EE_Data_Migration_Manager::instance()->get_all_migration_script_options(); |
164 | 164 | $presentable_migration_scripts = array(); |
165 | 165 | foreach ($options as $option_array) { |
166 | - $presentable_migration_scripts[ str_replace(EE_Data_Migration_Manager::data_migration_script_option_prefix, "", $option_array['option_name']) ] = maybe_unserialize($option_array['option_value']); |
|
166 | + $presentable_migration_scripts[str_replace(EE_Data_Migration_Manager::data_migration_script_option_prefix, "", $option_array['option_name'])] = maybe_unserialize($option_array['option_value']); |
|
167 | 167 | } |
168 | 168 | return $presentable_migration_scripts; |
169 | 169 | // return get_option(EE_Data_Migration_Manager::data_migrations_option_name);//EE_Data_Migration_Manager::instance()->get_data_migrations_ran(); |
@@ -189,18 +189,18 @@ discard block |
||
189 | 189 | |
190 | 190 | $pi = preg_replace( |
191 | 191 | array('#^.*<body>(.*)</body>.*$#ms', '#<h2>PHP License</h2>.*$#ms', |
192 | - '#<h1>Configuration</h1>#', "#\r?\n#", "#</(h1|h2|h3|tr)>#", '# +<#', |
|
192 | + '#<h1>Configuration</h1>#', "#\r?\n#", "#</(h1|h2|h3|tr)>#", '# +<#', |
|
193 | 193 | "#[ \t]+#", '# #', '# +#', '# class=".*?"#', '%'%', |
194 | 194 | '#<tr>(?:.*?)" src="(?:.*?)=(.*?)" alt="PHP Logo" /></a>' |
195 | 195 | . '<h1>PHP Version (.*?)</h1>(?:\n+?)</td></tr>#', |
196 | 196 | '#<h1><a href="(?:.*?)\?=(.*?)">PHP Credits</a></h1>#', |
197 | 197 | '#<tr>(?:.*?)" src="(?:.*?)=(.*?)"(?:.*?)Zend Engine (.*?),(?:.*?)</tr>#', |
198 | 198 | "# +#", '#<tr>#', '#</tr>#'), |
199 | - array('$1', '', '', '', '</$1>' . "\n", '<', ' ', ' ', ' ', '', ' ', |
|
200 | - '<h2>PHP Configuration</h2>' . "\n" . '<tr><td>PHP Version</td><td>$2</td></tr>' . |
|
201 | - "\n" . '<tr><td>PHP Egg</td><td>$1</td></tr>', |
|
199 | + array('$1', '', '', '', '</$1>'."\n", '<', ' ', ' ', ' ', '', ' ', |
|
200 | + '<h2>PHP Configuration</h2>'."\n".'<tr><td>PHP Version</td><td>$2</td></tr>'. |
|
201 | + "\n".'<tr><td>PHP Egg</td><td>$1</td></tr>', |
|
202 | 202 | '<tr><td>PHP Credits Egg</td><td>$1</td></tr>', |
203 | - '<tr><td>Zend Engine</td><td>$2</td></tr>' . "\n" . |
|
203 | + '<tr><td>Zend Engine</td><td>$2</td></tr>'."\n". |
|
204 | 204 | '<tr><td>Zend Egg</td><td>$1</td></tr>', ' ', '%S%', '%E%'), |
205 | 205 | ob_get_clean() |
206 | 206 | ); |
@@ -220,7 +220,7 @@ discard block |
||
220 | 220 | foreach ($askapache as $m) { |
221 | 221 | $m2 = isset($m[2]) ? $m[2] : null; |
222 | 222 | } |
223 | - $pi[ $n ][ $m[1] ] = (!isset($m[3]) || $m2 == $m[3]) ? $m2 : array_slice($m, 2); |
|
223 | + $pi[$n][$m[1]] = ( ! isset($m[3]) || $m2 == $m[3]) ? $m2 : array_slice($m, 2); |
|
224 | 224 | } |
225 | 225 | |
226 | 226 | return $pi; |
@@ -237,7 +237,7 @@ discard block |
||
237 | 237 | if ($response instanceof WP_Error) { |
238 | 238 | $error_string = ''; |
239 | 239 | foreach ($response->errors as $short_name => $description_array) { |
240 | - $error_string .= "<b>$short_name</b>: " . implode(", ", $description_array); |
|
240 | + $error_string .= "<b>$short_name</b>: ".implode(", ", $description_array); |
|
241 | 241 | } |
242 | 242 | return $error_string; |
243 | 243 | } |
@@ -249,8 +249,8 @@ discard block |
||
249 | 249 | */ |
250 | 250 | public function get_wp_maintenance_mode() |
251 | 251 | { |
252 | - $opened = file_exists(ABSPATH . '.maintenance'); |
|
253 | - return $opened ? sprintf(esc_html__('%s.maintenance file detected.%s Wordpress may have a failed auto-update which could prevent Event Espresso from updating the database correctly.', 'event_espresso'), '<strong>', '</strong>') : esc_html__('.maintenance file not detected. WordPress is not in maintenance mode.', 'event_espresso') ; |
|
252 | + $opened = file_exists(ABSPATH.'.maintenance'); |
|
253 | + return $opened ? sprintf(esc_html__('%s.maintenance file detected.%s Wordpress may have a failed auto-update which could prevent Event Espresso from updating the database correctly.', 'event_espresso'), '<strong>', '</strong>') : esc_html__('.maintenance file not detected. WordPress is not in maintenance mode.', 'event_espresso'); |
|
254 | 254 | } |
255 | 255 | /** |
256 | 256 | * Whether or not logging is enabled |
@@ -258,8 +258,8 @@ discard block |
||
258 | 258 | */ |
259 | 259 | public function get_logging_enabled() |
260 | 260 | { |
261 | - $opened = @fopen(EVENT_ESPRESSO_UPLOAD_DIR . '/logs/espresso_log.txt', 'a'); |
|
262 | - return $opened ? esc_html__('Log Directory is writable', 'event_espresso') : sprintf(esc_html__('%sLog directory is NOT writable%s', 'event_espresso'), '<mark class="error"', '</mark>') ; |
|
261 | + $opened = @fopen(EVENT_ESPRESSO_UPLOAD_DIR.'/logs/espresso_log.txt', 'a'); |
|
262 | + return $opened ? esc_html__('Log Directory is writable', 'event_espresso') : sprintf(esc_html__('%sLog directory is NOT writable%s', 'event_espresso'), '<mark class="error"', '</mark>'); |
|
263 | 263 | } |
264 | 264 | /** |
265 | 265 | * Whether curl ro fsock works |
@@ -276,7 +276,7 @@ discard block |
||
276 | 276 | } elseif ($curl_works) { |
277 | 277 | $status = esc_html__('Your server has cURL enabled, fsockopen is disabled.', 'event_espresso'); |
278 | 278 | } else { |
279 | - $status = esc_html__('Your server does not have fsockopen or cURL enabled - PayPal IPN and other scripts which communicate with other servers will not work. Contact your hosting provider.', 'event_espresso') . '</mark>'; |
|
279 | + $status = esc_html__('Your server does not have fsockopen or cURL enabled - PayPal IPN and other scripts which communicate with other servers will not work. Contact your hosting provider.', 'event_espresso').'</mark>'; |
|
280 | 280 | } |
281 | 281 | return $status; |
282 | 282 | } |
@@ -5,79 +5,79 @@ discard block |
||
5 | 5 | */ |
6 | 6 | class EEM_System_Status |
7 | 7 | { |
8 | - // private instance of the EEM_System_Status object |
|
9 | - protected static $_instance = null; |
|
8 | + // private instance of the EEM_System_Status object |
|
9 | + protected static $_instance = null; |
|
10 | 10 | |
11 | 11 | |
12 | 12 | |
13 | - /** |
|
14 | - * This function is a singleton method used to instantiate the EEM_Attendee object |
|
15 | - * |
|
16 | - * @access public |
|
17 | - * @param string $timezone string representing the timezone we want to set for returned Date Time Strings (and any incoming timezone data that gets saved). Note this just sends the timezone info to the date time model field objects. Default is NULL (and will be assumed using the set timezone in the 'timezone_string' wp option) |
|
18 | - * @return EEM_System_Status |
|
19 | - */ |
|
20 | - public static function instance() |
|
21 | - { |
|
13 | + /** |
|
14 | + * This function is a singleton method used to instantiate the EEM_Attendee object |
|
15 | + * |
|
16 | + * @access public |
|
17 | + * @param string $timezone string representing the timezone we want to set for returned Date Time Strings (and any incoming timezone data that gets saved). Note this just sends the timezone info to the date time model field objects. Default is NULL (and will be assumed using the set timezone in the 'timezone_string' wp option) |
|
18 | + * @return EEM_System_Status |
|
19 | + */ |
|
20 | + public static function instance() |
|
21 | + { |
|
22 | 22 | |
23 | - // check if instance of EEM_System_Status already exists |
|
24 | - if (self::$_instance === null) { |
|
25 | - // instantiate EEM_System_Status |
|
26 | - self::$_instance = new self(); |
|
27 | - } |
|
28 | - return self::$_instance; |
|
29 | - } |
|
30 | - private function __construct() |
|
31 | - { |
|
32 | - } |
|
33 | - /** |
|
34 | - * |
|
35 | - * @return array where each key is a function name on this class, and each value is SOMETHING-- |
|
36 | - * it might be a value, an array, or an object |
|
37 | - */ |
|
38 | - public function get_system_stati() |
|
39 | - { |
|
40 | - return apply_filters( |
|
41 | - 'FHEE__EEM_System_Status__get_system_stati', |
|
42 | - array( |
|
43 | - 'ee_version' => $this->get_ee_version(), |
|
44 | - 'ee_activation_history' => $this->get_ee_activation_history(), |
|
45 | - 'ee_config' => $this->get_ee_config(), |
|
46 | - 'ee_migration_history' => $this->get_ee_migration_history(), |
|
47 | - 'active_plugins' => $this->get_active_plugins(), |
|
48 | - 'wp_settings' => $this->get_wp_settings(), |
|
49 | - 'wp_maintenance_mode' => $this->get_wp_maintenance_mode(), |
|
50 | - 'https_enabled' => $this->get_https_enabled(), |
|
51 | - 'logging_enabled' => $this->get_logging_enabled(), |
|
52 | - 'remote_posting' => $this->get_remote_posting(), |
|
53 | - 'php_version' => $this->php_version(), |
|
54 | - 'php.ini_settings' => $this->get_php_ini_all(), |
|
55 | - 'php_info' => $this->get_php_info(), |
|
56 | - ), |
|
57 | - $this |
|
58 | - ); |
|
59 | - } |
|
60 | - /** |
|
61 | - * |
|
62 | - * @return string |
|
63 | - */ |
|
64 | - public function get_ee_version() |
|
65 | - { |
|
66 | - return espresso_version(); |
|
67 | - } |
|
68 | - /** |
|
69 | - * |
|
70 | - * @return string |
|
71 | - */ |
|
72 | - public function php_version() |
|
73 | - { |
|
74 | - return phpversion(); |
|
75 | - } |
|
76 | - /** |
|
77 | - * |
|
78 | - * @return array, where each key is a plugin name (lower-cased), values are sub-arrays. |
|
79 | - * Sub-arrays like described in wp function get_plugin_data. Ie, * |
|
80 | - * 'Name' => 'Plugin Name', |
|
23 | + // check if instance of EEM_System_Status already exists |
|
24 | + if (self::$_instance === null) { |
|
25 | + // instantiate EEM_System_Status |
|
26 | + self::$_instance = new self(); |
|
27 | + } |
|
28 | + return self::$_instance; |
|
29 | + } |
|
30 | + private function __construct() |
|
31 | + { |
|
32 | + } |
|
33 | + /** |
|
34 | + * |
|
35 | + * @return array where each key is a function name on this class, and each value is SOMETHING-- |
|
36 | + * it might be a value, an array, or an object |
|
37 | + */ |
|
38 | + public function get_system_stati() |
|
39 | + { |
|
40 | + return apply_filters( |
|
41 | + 'FHEE__EEM_System_Status__get_system_stati', |
|
42 | + array( |
|
43 | + 'ee_version' => $this->get_ee_version(), |
|
44 | + 'ee_activation_history' => $this->get_ee_activation_history(), |
|
45 | + 'ee_config' => $this->get_ee_config(), |
|
46 | + 'ee_migration_history' => $this->get_ee_migration_history(), |
|
47 | + 'active_plugins' => $this->get_active_plugins(), |
|
48 | + 'wp_settings' => $this->get_wp_settings(), |
|
49 | + 'wp_maintenance_mode' => $this->get_wp_maintenance_mode(), |
|
50 | + 'https_enabled' => $this->get_https_enabled(), |
|
51 | + 'logging_enabled' => $this->get_logging_enabled(), |
|
52 | + 'remote_posting' => $this->get_remote_posting(), |
|
53 | + 'php_version' => $this->php_version(), |
|
54 | + 'php.ini_settings' => $this->get_php_ini_all(), |
|
55 | + 'php_info' => $this->get_php_info(), |
|
56 | + ), |
|
57 | + $this |
|
58 | + ); |
|
59 | + } |
|
60 | + /** |
|
61 | + * |
|
62 | + * @return string |
|
63 | + */ |
|
64 | + public function get_ee_version() |
|
65 | + { |
|
66 | + return espresso_version(); |
|
67 | + } |
|
68 | + /** |
|
69 | + * |
|
70 | + * @return string |
|
71 | + */ |
|
72 | + public function php_version() |
|
73 | + { |
|
74 | + return phpversion(); |
|
75 | + } |
|
76 | + /** |
|
77 | + * |
|
78 | + * @return array, where each key is a plugin name (lower-cased), values are sub-arrays. |
|
79 | + * Sub-arrays like described in wp function get_plugin_data. Ie, * |
|
80 | + * 'Name' => 'Plugin Name', |
|
81 | 81 | 'PluginURI' => 'Plugin URI', |
82 | 82 | 'Version' => 'Version', |
83 | 83 | 'Description' => 'Description', |
@@ -86,231 +86,231 @@ discard block |
||
86 | 86 | 'TextDomain' => 'Text Domain', |
87 | 87 | 'DomainPath' => 'Domain Path', |
88 | 88 | 'Network' => 'Network', |
89 | - */ |
|
90 | - public function get_active_plugins() |
|
91 | - { |
|
92 | - $active_plugins = (array) get_option('active_plugins', array()); |
|
93 | - if (is_multisite()) { |
|
94 | - $active_plugins = array_merge($active_plugins, get_site_option('active_sitewide_plugins', array())); |
|
95 | - } |
|
96 | - $active_plugins = array_map('strtolower', $active_plugins); |
|
97 | - $plugin_info = array(); |
|
98 | - foreach ($active_plugins as $plugin) { |
|
99 | - $plugin_data = @get_plugin_data(WP_PLUGIN_DIR . '/' . $plugin); |
|
89 | + */ |
|
90 | + public function get_active_plugins() |
|
91 | + { |
|
92 | + $active_plugins = (array) get_option('active_plugins', array()); |
|
93 | + if (is_multisite()) { |
|
94 | + $active_plugins = array_merge($active_plugins, get_site_option('active_sitewide_plugins', array())); |
|
95 | + } |
|
96 | + $active_plugins = array_map('strtolower', $active_plugins); |
|
97 | + $plugin_info = array(); |
|
98 | + foreach ($active_plugins as $plugin) { |
|
99 | + $plugin_data = @get_plugin_data(WP_PLUGIN_DIR . '/' . $plugin); |
|
100 | 100 | |
101 | - $plugin_info[ $plugin ] = $plugin_data; |
|
102 | - } |
|
103 | - return $plugin_info; |
|
104 | - } |
|
101 | + $plugin_info[ $plugin ] = $plugin_data; |
|
102 | + } |
|
103 | + return $plugin_info; |
|
104 | + } |
|
105 | 105 | |
106 | - /** |
|
107 | - * |
|
108 | - * @return array with keys 'home_url' and 'site_url' |
|
109 | - */ |
|
110 | - public function get_wp_settings() |
|
111 | - { |
|
112 | - $wp_memory_int = $this->let_to_num(WP_MEMORY_LIMIT); |
|
113 | - if ($wp_memory_int < 67108864) { |
|
114 | - $wp_memory_to_display = '<mark class="error">'; |
|
115 | - $wp_memory_to_display .= sprintf( |
|
116 | - esc_html__( |
|
117 | - '%s - We recommend setting memory to at least 64MB. See: %s Increasing memory allocated to PHP %s', |
|
118 | - 'event_espresso' |
|
119 | - ), |
|
120 | - WP_MEMORY_LIMIT, |
|
121 | - '<a href="http://codex.wordpress.org/Editing_wp-config.php#Increasing_memory_allocated_to_PHP">', |
|
122 | - '</a>"' |
|
123 | - ); |
|
124 | - $wp_memory_to_display .= '</mark>'; |
|
125 | - } else { |
|
126 | - $wp_memory_to_display = '<mark class="yes">' . size_format($wp_memory_int) . '</mark>'; |
|
127 | - } |
|
128 | - return array( |
|
129 | - 'name' => get_bloginfo('name', 'display'), |
|
130 | - 'is_multisite' => is_multisite(), |
|
131 | - 'version' => get_bloginfo('version', 'display'), |
|
132 | - 'home_url' => home_url(), |
|
133 | - 'site_url' => site_url(), |
|
134 | - 'WP_DEBUG' => WP_DEBUG, |
|
135 | - 'permalink_structure' => get_option('permalink_structure'), |
|
136 | - 'theme' => wp_get_theme(), |
|
137 | - 'gmt_offset' => get_option('gmt_offset'), |
|
138 | - 'timezone_string' => get_option('timezone_string'), |
|
139 | - 'admin_email' => get_bloginfo('admin_email', 'display'), |
|
140 | - 'language' => get_bloginfo('language', 'display'), |
|
141 | - 'wp_max_upload_size' => size_format(wp_max_upload_size()), |
|
142 | - 'wp_memory' => $wp_memory_to_display |
|
143 | - ); |
|
144 | - } |
|
106 | + /** |
|
107 | + * |
|
108 | + * @return array with keys 'home_url' and 'site_url' |
|
109 | + */ |
|
110 | + public function get_wp_settings() |
|
111 | + { |
|
112 | + $wp_memory_int = $this->let_to_num(WP_MEMORY_LIMIT); |
|
113 | + if ($wp_memory_int < 67108864) { |
|
114 | + $wp_memory_to_display = '<mark class="error">'; |
|
115 | + $wp_memory_to_display .= sprintf( |
|
116 | + esc_html__( |
|
117 | + '%s - We recommend setting memory to at least 64MB. See: %s Increasing memory allocated to PHP %s', |
|
118 | + 'event_espresso' |
|
119 | + ), |
|
120 | + WP_MEMORY_LIMIT, |
|
121 | + '<a href="http://codex.wordpress.org/Editing_wp-config.php#Increasing_memory_allocated_to_PHP">', |
|
122 | + '</a>"' |
|
123 | + ); |
|
124 | + $wp_memory_to_display .= '</mark>'; |
|
125 | + } else { |
|
126 | + $wp_memory_to_display = '<mark class="yes">' . size_format($wp_memory_int) . '</mark>'; |
|
127 | + } |
|
128 | + return array( |
|
129 | + 'name' => get_bloginfo('name', 'display'), |
|
130 | + 'is_multisite' => is_multisite(), |
|
131 | + 'version' => get_bloginfo('version', 'display'), |
|
132 | + 'home_url' => home_url(), |
|
133 | + 'site_url' => site_url(), |
|
134 | + 'WP_DEBUG' => WP_DEBUG, |
|
135 | + 'permalink_structure' => get_option('permalink_structure'), |
|
136 | + 'theme' => wp_get_theme(), |
|
137 | + 'gmt_offset' => get_option('gmt_offset'), |
|
138 | + 'timezone_string' => get_option('timezone_string'), |
|
139 | + 'admin_email' => get_bloginfo('admin_email', 'display'), |
|
140 | + 'language' => get_bloginfo('language', 'display'), |
|
141 | + 'wp_max_upload_size' => size_format(wp_max_upload_size()), |
|
142 | + 'wp_memory' => $wp_memory_to_display |
|
143 | + ); |
|
144 | + } |
|
145 | 145 | |
146 | - /** |
|
147 | - * Gets an array of information about the history of ee versions installed |
|
148 | - * @return array |
|
149 | - */ |
|
150 | - public function get_ee_activation_history() |
|
151 | - { |
|
152 | - return get_option('espresso_db_update'); |
|
153 | - } |
|
146 | + /** |
|
147 | + * Gets an array of information about the history of ee versions installed |
|
148 | + * @return array |
|
149 | + */ |
|
150 | + public function get_ee_activation_history() |
|
151 | + { |
|
152 | + return get_option('espresso_db_update'); |
|
153 | + } |
|
154 | 154 | |
155 | 155 | |
156 | - /** |
|
157 | - * Gets an array where keys are ee versions, and their values are arrays indicating all the different times that version was installed |
|
158 | - * @return EE_Data_Migration_Script_Base[] |
|
159 | - */ |
|
160 | - public function get_ee_migration_history() |
|
161 | - { |
|
162 | - $options = EE_Data_Migration_Manager::instance()->get_all_migration_script_options(); |
|
163 | - $presentable_migration_scripts = array(); |
|
164 | - foreach ($options as $option_array) { |
|
165 | - $presentable_migration_scripts[ str_replace(EE_Data_Migration_Manager::data_migration_script_option_prefix, "", $option_array['option_name']) ] = maybe_unserialize($option_array['option_value']); |
|
166 | - } |
|
167 | - return $presentable_migration_scripts; |
|
156 | + /** |
|
157 | + * Gets an array where keys are ee versions, and their values are arrays indicating all the different times that version was installed |
|
158 | + * @return EE_Data_Migration_Script_Base[] |
|
159 | + */ |
|
160 | + public function get_ee_migration_history() |
|
161 | + { |
|
162 | + $options = EE_Data_Migration_Manager::instance()->get_all_migration_script_options(); |
|
163 | + $presentable_migration_scripts = array(); |
|
164 | + foreach ($options as $option_array) { |
|
165 | + $presentable_migration_scripts[ str_replace(EE_Data_Migration_Manager::data_migration_script_option_prefix, "", $option_array['option_name']) ] = maybe_unserialize($option_array['option_value']); |
|
166 | + } |
|
167 | + return $presentable_migration_scripts; |
|
168 | 168 | // return get_option(EE_Data_Migration_Manager::data_migrations_option_name);//EE_Data_Migration_Manager::instance()->get_data_migrations_ran(); |
169 | - } |
|
169 | + } |
|
170 | 170 | |
171 | - /** |
|
172 | - * |
|
173 | - * @return array like EE_Config class |
|
174 | - */ |
|
175 | - public function get_ee_config() |
|
176 | - { |
|
177 | - return EE_Config::instance(); |
|
178 | - } |
|
171 | + /** |
|
172 | + * |
|
173 | + * @return array like EE_Config class |
|
174 | + */ |
|
175 | + public function get_ee_config() |
|
176 | + { |
|
177 | + return EE_Config::instance(); |
|
178 | + } |
|
179 | 179 | |
180 | - /** |
|
181 | - * Gets an array of php setup info, pilfered from http://www.php.net/manual/en/function.phpinfo.php#87463 |
|
182 | - * @return array like the output of phpinfo(), but in an array |
|
183 | - */ |
|
184 | - public function get_php_info() |
|
185 | - { |
|
186 | - ob_start(); |
|
187 | - phpinfo(-1); |
|
180 | + /** |
|
181 | + * Gets an array of php setup info, pilfered from http://www.php.net/manual/en/function.phpinfo.php#87463 |
|
182 | + * @return array like the output of phpinfo(), but in an array |
|
183 | + */ |
|
184 | + public function get_php_info() |
|
185 | + { |
|
186 | + ob_start(); |
|
187 | + phpinfo(-1); |
|
188 | 188 | |
189 | - $pi = preg_replace( |
|
190 | - array('#^.*<body>(.*)</body>.*$#ms', '#<h2>PHP License</h2>.*$#ms', |
|
191 | - '#<h1>Configuration</h1>#', "#\r?\n#", "#</(h1|h2|h3|tr)>#", '# +<#', |
|
192 | - "#[ \t]+#", '# #', '# +#', '# class=".*?"#', '%'%', |
|
193 | - '#<tr>(?:.*?)" src="(?:.*?)=(.*?)" alt="PHP Logo" /></a>' |
|
194 | - . '<h1>PHP Version (.*?)</h1>(?:\n+?)</td></tr>#', |
|
195 | - '#<h1><a href="(?:.*?)\?=(.*?)">PHP Credits</a></h1>#', |
|
196 | - '#<tr>(?:.*?)" src="(?:.*?)=(.*?)"(?:.*?)Zend Engine (.*?),(?:.*?)</tr>#', |
|
197 | - "# +#", '#<tr>#', '#</tr>#'), |
|
198 | - array('$1', '', '', '', '</$1>' . "\n", '<', ' ', ' ', ' ', '', ' ', |
|
199 | - '<h2>PHP Configuration</h2>' . "\n" . '<tr><td>PHP Version</td><td>$2</td></tr>' . |
|
200 | - "\n" . '<tr><td>PHP Egg</td><td>$1</td></tr>', |
|
201 | - '<tr><td>PHP Credits Egg</td><td>$1</td></tr>', |
|
202 | - '<tr><td>Zend Engine</td><td>$2</td></tr>' . "\n" . |
|
203 | - '<tr><td>Zend Egg</td><td>$1</td></tr>', ' ', '%S%', '%E%'), |
|
204 | - ob_get_clean() |
|
205 | - ); |
|
189 | + $pi = preg_replace( |
|
190 | + array('#^.*<body>(.*)</body>.*$#ms', '#<h2>PHP License</h2>.*$#ms', |
|
191 | + '#<h1>Configuration</h1>#', "#\r?\n#", "#</(h1|h2|h3|tr)>#", '# +<#', |
|
192 | + "#[ \t]+#", '# #', '# +#', '# class=".*?"#', '%'%', |
|
193 | + '#<tr>(?:.*?)" src="(?:.*?)=(.*?)" alt="PHP Logo" /></a>' |
|
194 | + . '<h1>PHP Version (.*?)</h1>(?:\n+?)</td></tr>#', |
|
195 | + '#<h1><a href="(?:.*?)\?=(.*?)">PHP Credits</a></h1>#', |
|
196 | + '#<tr>(?:.*?)" src="(?:.*?)=(.*?)"(?:.*?)Zend Engine (.*?),(?:.*?)</tr>#', |
|
197 | + "# +#", '#<tr>#', '#</tr>#'), |
|
198 | + array('$1', '', '', '', '</$1>' . "\n", '<', ' ', ' ', ' ', '', ' ', |
|
199 | + '<h2>PHP Configuration</h2>' . "\n" . '<tr><td>PHP Version</td><td>$2</td></tr>' . |
|
200 | + "\n" . '<tr><td>PHP Egg</td><td>$1</td></tr>', |
|
201 | + '<tr><td>PHP Credits Egg</td><td>$1</td></tr>', |
|
202 | + '<tr><td>Zend Engine</td><td>$2</td></tr>' . "\n" . |
|
203 | + '<tr><td>Zend Egg</td><td>$1</td></tr>', ' ', '%S%', '%E%'), |
|
204 | + ob_get_clean() |
|
205 | + ); |
|
206 | 206 | |
207 | - $sections = explode('<h2>', strip_tags($pi, '<h2><th><td>')); |
|
208 | - unset($sections[0]); |
|
207 | + $sections = explode('<h2>', strip_tags($pi, '<h2><th><td>')); |
|
208 | + unset($sections[0]); |
|
209 | 209 | |
210 | - $pi = array(); |
|
211 | - foreach ($sections as $section) { |
|
212 | - $n = substr($section, 0, strpos($section, '</h2>')); |
|
213 | - preg_match_all( |
|
214 | - '#%S%(?:<td>(.*?)</td>)?(?:<td>(.*?)</td>)?(?:<td>(.*?)</td>)?%E%#', |
|
215 | - $section, |
|
216 | - $askapache, |
|
217 | - PREG_SET_ORDER |
|
218 | - ); |
|
219 | - foreach ($askapache as $m) { |
|
220 | - $m2 = isset($m[2]) ? $m[2] : null; |
|
221 | - } |
|
222 | - $pi[ $n ][ $m[1] ] = (!isset($m[3]) || $m2 == $m[3]) ? $m2 : array_slice($m, 2); |
|
223 | - } |
|
210 | + $pi = array(); |
|
211 | + foreach ($sections as $section) { |
|
212 | + $n = substr($section, 0, strpos($section, '</h2>')); |
|
213 | + preg_match_all( |
|
214 | + '#%S%(?:<td>(.*?)</td>)?(?:<td>(.*?)</td>)?(?:<td>(.*?)</td>)?%E%#', |
|
215 | + $section, |
|
216 | + $askapache, |
|
217 | + PREG_SET_ORDER |
|
218 | + ); |
|
219 | + foreach ($askapache as $m) { |
|
220 | + $m2 = isset($m[2]) ? $m[2] : null; |
|
221 | + } |
|
222 | + $pi[ $n ][ $m[1] ] = (!isset($m[3]) || $m2 == $m[3]) ? $m2 : array_slice($m, 2); |
|
223 | + } |
|
224 | 224 | |
225 | - return $pi; |
|
226 | - } |
|
225 | + return $pi; |
|
226 | + } |
|
227 | 227 | |
228 | - /** |
|
229 | - * Checks if site responds ot HTTPS |
|
230 | - * @return boolean |
|
231 | - */ |
|
232 | - public function get_https_enabled() |
|
233 | - { |
|
234 | - $home = str_replace("http://", "https://", home_url()); |
|
235 | - $response = wp_remote_get($home); |
|
236 | - if ($response instanceof WP_Error) { |
|
237 | - $error_string = ''; |
|
238 | - foreach ($response->errors as $short_name => $description_array) { |
|
239 | - $error_string .= "<b>$short_name</b>: " . implode(", ", $description_array); |
|
240 | - } |
|
241 | - return $error_string; |
|
242 | - } |
|
243 | - return "ok!"; |
|
244 | - } |
|
245 | - /** |
|
246 | - * Whether or not a .maintenance file is detected |
|
247 | - * @return string descripting wp_maintenance_mode status |
|
248 | - */ |
|
249 | - public function get_wp_maintenance_mode() |
|
250 | - { |
|
251 | - $opened = file_exists(ABSPATH . '.maintenance'); |
|
252 | - return $opened ? sprintf(esc_html__('%s.maintenance file detected.%s Wordpress may have a failed auto-update which could prevent Event Espresso from updating the database correctly.', 'event_espresso'), '<strong>', '</strong>') : esc_html__('.maintenance file not detected. WordPress is not in maintenance mode.', 'event_espresso') ; |
|
253 | - } |
|
254 | - /** |
|
255 | - * Whether or not logging is enabled |
|
256 | - * @return string descripting logging's status |
|
257 | - */ |
|
258 | - public function get_logging_enabled() |
|
259 | - { |
|
260 | - $opened = @fopen(EVENT_ESPRESSO_UPLOAD_DIR . '/logs/espresso_log.txt', 'a'); |
|
261 | - return $opened ? esc_html__('Log Directory is writable', 'event_espresso') : sprintf(esc_html__('%sLog directory is NOT writable%s', 'event_espresso'), '<mark class="error"', '</mark>') ; |
|
262 | - } |
|
263 | - /** |
|
264 | - * Whether curl ro fsock works |
|
265 | - * @return string describing posting's status |
|
266 | - */ |
|
267 | - public function get_remote_posting() |
|
268 | - { |
|
269 | - $fsock_works = function_exists('fsockopen'); |
|
270 | - $curl_works = function_exists('curl_init'); |
|
271 | - if ($fsock_works && $curl_works) { |
|
272 | - $status = esc_html__('Your server has fsockopen and cURL enabled.', 'event_espresso'); |
|
273 | - } elseif ($fsock_works) { |
|
274 | - $status = esc_html__('Your server has fsockopen enabled, cURL is disabled.', 'event_espresso'); |
|
275 | - } elseif ($curl_works) { |
|
276 | - $status = esc_html__('Your server has cURL enabled, fsockopen is disabled.', 'event_espresso'); |
|
277 | - } else { |
|
278 | - $status = esc_html__('Your server does not have fsockopen or cURL enabled - PayPal IPN and other scripts which communicate with other servers will not work. Contact your hosting provider.', 'event_espresso') . '</mark>'; |
|
279 | - } |
|
280 | - return $status; |
|
281 | - } |
|
282 | - /** |
|
283 | - * Gets all the php.ini settings |
|
284 | - * @return array |
|
285 | - */ |
|
286 | - public function get_php_ini_all() |
|
287 | - { |
|
288 | - return ini_get_all(); |
|
289 | - } |
|
290 | - /** |
|
291 | - * Transforms the php.ini notation for numbers (like '2M') to an integer. |
|
292 | - * |
|
293 | - * @param type $size |
|
294 | - * @return int |
|
295 | - */ |
|
296 | - public function let_to_num($size) |
|
297 | - { |
|
298 | - $l = substr($size, -1); |
|
299 | - $ret = substr($size, 0, -1); |
|
300 | - // phpcs:disable PSR2.ControlStructures.SwitchDeclaration.TerminatingComment |
|
301 | - switch (strtoupper($l)) { |
|
302 | - case 'P': |
|
303 | - $ret *= 1024; |
|
304 | - case 'T': |
|
305 | - $ret *= 1024; |
|
306 | - case 'G': |
|
307 | - $ret *= 1024; |
|
308 | - case 'M': |
|
309 | - $ret *= 1024; |
|
310 | - case 'K': |
|
311 | - $ret *= 1024; |
|
312 | - } |
|
313 | - // phpcs:enable |
|
314 | - return $ret; |
|
315 | - } |
|
228 | + /** |
|
229 | + * Checks if site responds ot HTTPS |
|
230 | + * @return boolean |
|
231 | + */ |
|
232 | + public function get_https_enabled() |
|
233 | + { |
|
234 | + $home = str_replace("http://", "https://", home_url()); |
|
235 | + $response = wp_remote_get($home); |
|
236 | + if ($response instanceof WP_Error) { |
|
237 | + $error_string = ''; |
|
238 | + foreach ($response->errors as $short_name => $description_array) { |
|
239 | + $error_string .= "<b>$short_name</b>: " . implode(", ", $description_array); |
|
240 | + } |
|
241 | + return $error_string; |
|
242 | + } |
|
243 | + return "ok!"; |
|
244 | + } |
|
245 | + /** |
|
246 | + * Whether or not a .maintenance file is detected |
|
247 | + * @return string descripting wp_maintenance_mode status |
|
248 | + */ |
|
249 | + public function get_wp_maintenance_mode() |
|
250 | + { |
|
251 | + $opened = file_exists(ABSPATH . '.maintenance'); |
|
252 | + return $opened ? sprintf(esc_html__('%s.maintenance file detected.%s Wordpress may have a failed auto-update which could prevent Event Espresso from updating the database correctly.', 'event_espresso'), '<strong>', '</strong>') : esc_html__('.maintenance file not detected. WordPress is not in maintenance mode.', 'event_espresso') ; |
|
253 | + } |
|
254 | + /** |
|
255 | + * Whether or not logging is enabled |
|
256 | + * @return string descripting logging's status |
|
257 | + */ |
|
258 | + public function get_logging_enabled() |
|
259 | + { |
|
260 | + $opened = @fopen(EVENT_ESPRESSO_UPLOAD_DIR . '/logs/espresso_log.txt', 'a'); |
|
261 | + return $opened ? esc_html__('Log Directory is writable', 'event_espresso') : sprintf(esc_html__('%sLog directory is NOT writable%s', 'event_espresso'), '<mark class="error"', '</mark>') ; |
|
262 | + } |
|
263 | + /** |
|
264 | + * Whether curl ro fsock works |
|
265 | + * @return string describing posting's status |
|
266 | + */ |
|
267 | + public function get_remote_posting() |
|
268 | + { |
|
269 | + $fsock_works = function_exists('fsockopen'); |
|
270 | + $curl_works = function_exists('curl_init'); |
|
271 | + if ($fsock_works && $curl_works) { |
|
272 | + $status = esc_html__('Your server has fsockopen and cURL enabled.', 'event_espresso'); |
|
273 | + } elseif ($fsock_works) { |
|
274 | + $status = esc_html__('Your server has fsockopen enabled, cURL is disabled.', 'event_espresso'); |
|
275 | + } elseif ($curl_works) { |
|
276 | + $status = esc_html__('Your server has cURL enabled, fsockopen is disabled.', 'event_espresso'); |
|
277 | + } else { |
|
278 | + $status = esc_html__('Your server does not have fsockopen or cURL enabled - PayPal IPN and other scripts which communicate with other servers will not work. Contact your hosting provider.', 'event_espresso') . '</mark>'; |
|
279 | + } |
|
280 | + return $status; |
|
281 | + } |
|
282 | + /** |
|
283 | + * Gets all the php.ini settings |
|
284 | + * @return array |
|
285 | + */ |
|
286 | + public function get_php_ini_all() |
|
287 | + { |
|
288 | + return ini_get_all(); |
|
289 | + } |
|
290 | + /** |
|
291 | + * Transforms the php.ini notation for numbers (like '2M') to an integer. |
|
292 | + * |
|
293 | + * @param type $size |
|
294 | + * @return int |
|
295 | + */ |
|
296 | + public function let_to_num($size) |
|
297 | + { |
|
298 | + $l = substr($size, -1); |
|
299 | + $ret = substr($size, 0, -1); |
|
300 | + // phpcs:disable PSR2.ControlStructures.SwitchDeclaration.TerminatingComment |
|
301 | + switch (strtoupper($l)) { |
|
302 | + case 'P': |
|
303 | + $ret *= 1024; |
|
304 | + case 'T': |
|
305 | + $ret *= 1024; |
|
306 | + case 'G': |
|
307 | + $ret *= 1024; |
|
308 | + case 'M': |
|
309 | + $ret *= 1024; |
|
310 | + case 'K': |
|
311 | + $ret *= 1024; |
|
312 | + } |
|
313 | + // phpcs:enable |
|
314 | + return $ret; |
|
315 | + } |
|
316 | 316 | } |
@@ -183,7 +183,7 @@ discard block |
||
183 | 183 | { |
184 | 184 | // self::debug hardcoded to false |
185 | 185 | if (self::debug) { |
186 | - echo self::$nl . self::$nl . __LINE__ . ') ' . __METHOD__ . '()'; |
|
186 | + echo self::$nl.self::$nl.__LINE__.') '.__METHOD__.'()'; |
|
187 | 187 | } |
188 | 188 | do_action('AHEE__EED_Ticket_Sales_Monitor__release_tickets_for_expired_carts__begin'); |
189 | 189 | $expired_ticket_IDs = array(); |
@@ -194,29 +194,29 @@ discard block |
||
194 | 194 | $timestamp = $session_lifespan->expiration(); |
195 | 195 | $expired_ticket_line_items = EEM_Line_Item::instance()->getTicketLineItemsForExpiredCarts($timestamp); |
196 | 196 | if (self::debug) { |
197 | - echo self::$nl . ' . time(): ' . time(); |
|
198 | - echo self::$nl . ' . time() as date: ' . date('Y-m-d H:i a'); |
|
199 | - echo self::$nl . ' . session expiration: ' . $session_lifespan->expiration(); |
|
200 | - echo self::$nl . ' . session expiration as date: ' . date('Y-m-d H:i a', $session_lifespan->expiration()); |
|
201 | - echo self::$nl . ' . timestamp: ' . $timestamp; |
|
202 | - echo self::$nl . ' . $expired_ticket_line_items: ' . count($expired_ticket_line_items); |
|
197 | + echo self::$nl.' . time(): '.time(); |
|
198 | + echo self::$nl.' . time() as date: '.date('Y-m-d H:i a'); |
|
199 | + echo self::$nl.' . session expiration: '.$session_lifespan->expiration(); |
|
200 | + echo self::$nl.' . session expiration as date: '.date('Y-m-d H:i a', $session_lifespan->expiration()); |
|
201 | + echo self::$nl.' . timestamp: '.$timestamp; |
|
202 | + echo self::$nl.' . $expired_ticket_line_items: '.count($expired_ticket_line_items); |
|
203 | 203 | } |
204 | - if (! empty($expired_ticket_line_items)) { |
|
204 | + if ( ! empty($expired_ticket_line_items)) { |
|
205 | 205 | foreach ($expired_ticket_line_items as $expired_ticket_line_item) { |
206 | - if (! $expired_ticket_line_item instanceof EE_Line_Item) { |
|
206 | + if ( ! $expired_ticket_line_item instanceof EE_Line_Item) { |
|
207 | 207 | continue; |
208 | 208 | } |
209 | - $expired_ticket_IDs[ $expired_ticket_line_item->OBJ_ID() ] = $expired_ticket_line_item->OBJ_ID(); |
|
209 | + $expired_ticket_IDs[$expired_ticket_line_item->OBJ_ID()] = $expired_ticket_line_item->OBJ_ID(); |
|
210 | 210 | if (self::debug) { |
211 | - echo self::$nl . ' . $expired_ticket_line_item->OBJ_ID(): ' . $expired_ticket_line_item->OBJ_ID(); |
|
212 | - echo self::$nl . ' . $expired_ticket_line_item->timestamp(): ' |
|
211 | + echo self::$nl.' . $expired_ticket_line_item->OBJ_ID(): '.$expired_ticket_line_item->OBJ_ID(); |
|
212 | + echo self::$nl.' . $expired_ticket_line_item->timestamp(): ' |
|
213 | 213 | . date( |
214 | 214 | 'Y-m-d h:i a', |
215 | 215 | $expired_ticket_line_item->timestamp(true) |
216 | 216 | ); |
217 | 217 | } |
218 | 218 | } |
219 | - if (! empty($expired_ticket_IDs)) { |
|
219 | + if ( ! empty($expired_ticket_IDs)) { |
|
220 | 220 | EED_Ticket_Sales_Monitor::release_reservations_for_tickets( |
221 | 221 | \EEM_Ticket::instance()->get_tickets_with_IDs($expired_ticket_IDs), |
222 | 222 | array(), |
@@ -255,8 +255,8 @@ discard block |
||
255 | 255 | } |
256 | 256 | // self::debug hardcoded to false |
257 | 257 | if (self::debug) { |
258 | - echo self::$nl . self::$nl . __LINE__ . ') ' . __METHOD__ . '()'; |
|
259 | - echo self::$nl . self::$nl . '<b> RETURNED QTY: ' . $qty . '</b>'; |
|
258 | + echo self::$nl.self::$nl.__LINE__.') '.__METHOD__.'()'; |
|
259 | + echo self::$nl.self::$nl.'<b> RETURNED QTY: '.$qty.'</b>'; |
|
260 | 260 | } |
261 | 261 | return $qty; |
262 | 262 | } |
@@ -275,36 +275,36 @@ discard block |
||
275 | 275 | { |
276 | 276 | // self::debug hardcoded to false |
277 | 277 | if (self::debug) { |
278 | - echo self::$nl . self::$nl . __LINE__ . ') ' . __METHOD__ . '() '; |
|
278 | + echo self::$nl.self::$nl.__LINE__.') '.__METHOD__.'() '; |
|
279 | 279 | } |
280 | - if (! $ticket instanceof EE_Ticket) { |
|
280 | + if ( ! $ticket instanceof EE_Ticket) { |
|
281 | 281 | return 0; |
282 | 282 | } |
283 | 283 | if (self::debug) { |
284 | - echo self::$nl . '<b> . ticket->ID: ' . $ticket->ID() . '</b>'; |
|
285 | - echo self::$nl . ' . original ticket->reserved: ' . $ticket->reserved(); |
|
284 | + echo self::$nl.'<b> . ticket->ID: '.$ticket->ID().'</b>'; |
|
285 | + echo self::$nl.' . original ticket->reserved: '.$ticket->reserved(); |
|
286 | 286 | } |
287 | 287 | $ticket->refresh_from_db(); |
288 | 288 | // first let's determine the ticket availability based on sales |
289 | 289 | $available = $ticket->qty('saleable'); |
290 | 290 | if (self::debug) { |
291 | - echo self::$nl . ' . . . ticket->qty: ' . $ticket->qty(); |
|
292 | - echo self::$nl . ' . . . ticket->sold: ' . $ticket->sold(); |
|
293 | - echo self::$nl . ' . . . ticket->reserved: ' . $ticket->reserved(); |
|
294 | - echo self::$nl . ' . . . ticket->qty(saleable): ' . $ticket->qty('saleable'); |
|
295 | - echo self::$nl . ' . . . available: ' . $available; |
|
291 | + echo self::$nl.' . . . ticket->qty: '.$ticket->qty(); |
|
292 | + echo self::$nl.' . . . ticket->sold: '.$ticket->sold(); |
|
293 | + echo self::$nl.' . . . ticket->reserved: '.$ticket->reserved(); |
|
294 | + echo self::$nl.' . . . ticket->qty(saleable): '.$ticket->qty('saleable'); |
|
295 | + echo self::$nl.' . . . available: '.$available; |
|
296 | 296 | } |
297 | 297 | if ($available < 1) { |
298 | 298 | $this->_ticket_sold_out($ticket); |
299 | 299 | return 0; |
300 | 300 | } |
301 | 301 | if (self::debug) { |
302 | - echo self::$nl . ' . . . qty: ' . $qty; |
|
302 | + echo self::$nl.' . . . qty: '.$qty; |
|
303 | 303 | } |
304 | 304 | if ($available < $qty) { |
305 | 305 | $qty = $available; |
306 | 306 | if (self::debug) { |
307 | - echo self::$nl . ' . . . QTY ADJUSTED: ' . $qty; |
|
307 | + echo self::$nl.' . . . QTY ADJUSTED: '.$qty; |
|
308 | 308 | } |
309 | 309 | $this->_ticket_quantity_decremented($ticket); |
310 | 310 | } |
@@ -328,9 +328,9 @@ discard block |
||
328 | 328 | { |
329 | 329 | // self::debug hardcoded to false |
330 | 330 | if (self::debug) { |
331 | - echo self::$nl . self::$nl . ' . . . INCREASE RESERVED: ' . $quantity; |
|
331 | + echo self::$nl.self::$nl.' . . . INCREASE RESERVED: '.$quantity; |
|
332 | 332 | } |
333 | - return $ticket->increaseReserved($quantity, 'TicketSalesMonitor:' . __LINE__); |
|
333 | + return $ticket->increaseReserved($quantity, 'TicketSalesMonitor:'.__LINE__); |
|
334 | 334 | } |
335 | 335 | |
336 | 336 | |
@@ -344,12 +344,12 @@ discard block |
||
344 | 344 | { |
345 | 345 | // self::debug hardcoded to false |
346 | 346 | if (self::debug) { |
347 | - echo self::$nl . ' . . . ticket->ID: ' . $ticket->ID(); |
|
348 | - echo self::$nl . ' . . . ticket->reserved before: ' . $ticket->reserved(); |
|
347 | + echo self::$nl.' . . . ticket->ID: '.$ticket->ID(); |
|
348 | + echo self::$nl.' . . . ticket->reserved before: '.$ticket->reserved(); |
|
349 | 349 | } |
350 | - $ticket->decreaseReserved($quantity, true, 'TicketSalesMonitor:' . __LINE__); |
|
350 | + $ticket->decreaseReserved($quantity, true, 'TicketSalesMonitor:'.__LINE__); |
|
351 | 351 | if (self::debug) { |
352 | - echo self::$nl . ' . . . ticket->reserved after: ' . $ticket->reserved(); |
|
352 | + echo self::$nl.' . . . ticket->reserved after: '.$ticket->reserved(); |
|
353 | 353 | } |
354 | 354 | return $ticket->save() ? 1 : 0; |
355 | 355 | } |
@@ -367,8 +367,8 @@ discard block |
||
367 | 367 | { |
368 | 368 | // self::debug hardcoded to false |
369 | 369 | if (self::debug) { |
370 | - echo self::$nl . self::$nl . __LINE__ . ') ' . __METHOD__ . '() '; |
|
371 | - echo self::$nl . ' . . ticket->name: ' . $this->_get_ticket_and_event_name($ticket); |
|
370 | + echo self::$nl.self::$nl.__LINE__.') '.__METHOD__.'() '; |
|
371 | + echo self::$nl.' . . ticket->name: '.$this->_get_ticket_and_event_name($ticket); |
|
372 | 372 | } |
373 | 373 | $this->sold_out_tickets[] = $this->_get_ticket_and_event_name($ticket); |
374 | 374 | } |
@@ -386,8 +386,8 @@ discard block |
||
386 | 386 | { |
387 | 387 | // self::debug hardcoded to false |
388 | 388 | if (self::debug) { |
389 | - echo self::$nl . self::$nl . __LINE__ . ') ' . __METHOD__ . '() '; |
|
390 | - echo self::$nl . ' . . ticket->name: ' . $this->_get_ticket_and_event_name($ticket); |
|
389 | + echo self::$nl.self::$nl.__LINE__.') '.__METHOD__.'() '; |
|
390 | + echo self::$nl.' . . ticket->name: '.$this->_get_ticket_and_event_name($ticket); |
|
391 | 391 | } |
392 | 392 | $this->decremented_tickets[] = $this->_get_ticket_and_event_name($ticket); |
393 | 393 | } |
@@ -438,7 +438,7 @@ discard block |
||
438 | 438 | if ($ticket instanceof EE_Ticket) { |
439 | 439 | $ticket->add_extra_meta( |
440 | 440 | EE_Ticket::META_KEY_TICKET_RESERVATIONS, |
441 | - __LINE__ . ') ' . __METHOD__ . '()' |
|
441 | + __LINE__.') '.__METHOD__.'()' |
|
442 | 442 | ); |
443 | 443 | if ($quantity > 0) { |
444 | 444 | EED_Ticket_Sales_Monitor::instance()->_reserve_ticket($ticket, $quantity); |
@@ -461,7 +461,7 @@ discard block |
||
461 | 461 | { |
462 | 462 | $ticket->add_extra_meta( |
463 | 463 | EE_Ticket::META_KEY_TICKET_RESERVATIONS, |
464 | - __LINE__ . ') ' . __METHOD__ . '()' |
|
464 | + __LINE__.') '.__METHOD__.'()' |
|
465 | 465 | ); |
466 | 466 | EED_Ticket_Sales_Monitor::instance()->_release_reserved_ticket($ticket, $quantity); |
467 | 467 | } |
@@ -497,7 +497,7 @@ discard block |
||
497 | 497 | { |
498 | 498 | // self::debug hardcoded to false |
499 | 499 | if (self::debug) { |
500 | - echo self::$nl . self::$nl . __LINE__ . ') ' . __METHOD__ . '() '; |
|
500 | + echo self::$nl.self::$nl.__LINE__.') '.__METHOD__.'() '; |
|
501 | 501 | } |
502 | 502 | $refresh_msg = ''; |
503 | 503 | $none_added_msg = ''; |
@@ -508,7 +508,7 @@ discard block |
||
508 | 508 | ); |
509 | 509 | $none_added_msg = esc_html__('No tickets were added for the event.', 'event_espresso'); |
510 | 510 | } |
511 | - if (! empty($this->sold_out_tickets)) { |
|
511 | + if ( ! empty($this->sold_out_tickets)) { |
|
512 | 512 | EE_Error::add_attention( |
513 | 513 | sprintf( |
514 | 514 | apply_filters( |
@@ -531,7 +531,7 @@ discard block |
||
531 | 531 | // and reset the cart |
532 | 532 | EED_Ticket_Sales_Monitor::session_cart_reset(EE_Registry::instance()->SSN); |
533 | 533 | } |
534 | - if (! empty($this->decremented_tickets)) { |
|
534 | + if ( ! empty($this->decremented_tickets)) { |
|
535 | 535 | EE_Error::add_attention( |
536 | 536 | sprintf( |
537 | 537 | apply_filters( |
@@ -569,9 +569,9 @@ discard block |
||
569 | 569 | { |
570 | 570 | // self::debug hardcoded to false |
571 | 571 | if (self::debug) { |
572 | - echo self::$nl . self::$nl . __LINE__ . ') ' . __METHOD__ . '() '; |
|
573 | - echo self::$nl . ' . transaction->ID: ' . $transaction->ID(); |
|
574 | - echo self::$nl . ' . TXN status_ID: ' . $transaction->status_ID(); |
|
572 | + echo self::$nl.self::$nl.__LINE__.') '.__METHOD__.'() '; |
|
573 | + echo self::$nl.' . transaction->ID: '.$transaction->ID(); |
|
574 | + echo self::$nl.' . TXN status_ID: '.$transaction->status_ID(); |
|
575 | 575 | } |
576 | 576 | // check if 'finalize_registration' step has been completed... |
577 | 577 | $finalized = $transaction->reg_step_completed('finalize_registration'); |
@@ -583,13 +583,13 @@ discard block |
||
583 | 583 | __LINE__, |
584 | 584 | array('finalized' => $finalized), |
585 | 585 | false, |
586 | - 'EE_Transaction: ' . $transaction->ID() |
|
586 | + 'EE_Transaction: '.$transaction->ID() |
|
587 | 587 | ); |
588 | 588 | } |
589 | 589 | // how many tickets were released |
590 | 590 | $count = 0; |
591 | 591 | if (self::debug) { |
592 | - echo self::$nl . ' . . . TXN finalized: ' . $finalized; |
|
592 | + echo self::$nl.' . . . TXN finalized: '.$finalized; |
|
593 | 593 | } |
594 | 594 | $release_tickets_with_TXN_status = array( |
595 | 595 | EEM_Transaction::failed_status_code, |
@@ -598,28 +598,28 @@ discard block |
||
598 | 598 | ); |
599 | 599 | $events = array(); |
600 | 600 | // if the session is getting cleared BEFORE the TXN has been finalized or the transaction is not completed |
601 | - if (! $finalized || in_array($transaction->status_ID(), $release_tickets_with_TXN_status, true)) { |
|
601 | + if ( ! $finalized || in_array($transaction->status_ID(), $release_tickets_with_TXN_status, true)) { |
|
602 | 602 | // cancel any reserved tickets for registrations that were not approved |
603 | 603 | $registrations = $transaction->registrations(); |
604 | 604 | if (self::debug) { |
605 | - echo self::$nl . ' . . . # registrations: ' . count($registrations); |
|
605 | + echo self::$nl.' . . . # registrations: '.count($registrations); |
|
606 | 606 | $reg = reset($registrations); |
607 | 607 | $ticket = $reg->ticket(); |
608 | 608 | if ($ticket instanceof EE_Ticket) { |
609 | 609 | $ticket->add_extra_meta( |
610 | 610 | EE_Ticket::META_KEY_TICKET_RESERVATIONS, |
611 | - __LINE__ . ') Release All Tickets TXN:' . $transaction->ID() |
|
611 | + __LINE__.') Release All Tickets TXN:'.$transaction->ID() |
|
612 | 612 | ); |
613 | 613 | } |
614 | 614 | } |
615 | - if (! empty($registrations)) { |
|
615 | + if ( ! empty($registrations)) { |
|
616 | 616 | foreach ($registrations as $registration) { |
617 | 617 | if ( |
618 | 618 | $registration instanceof EE_Registration |
619 | 619 | && $this->_release_reserved_ticket_for_registration($registration, $transaction) |
620 | 620 | ) { |
621 | 621 | $count++; |
622 | - $events[ $registration->event_ID() ] = $registration->event(); |
|
622 | + $events[$registration->event_ID()] = $registration->event(); |
|
623 | 623 | } |
624 | 624 | } |
625 | 625 | } |
@@ -650,10 +650,10 @@ discard block |
||
650 | 650 | $STS_ID = $transaction->status_ID(); |
651 | 651 | // self::debug hardcoded to false |
652 | 652 | if (self::debug) { |
653 | - echo self::$nl . self::$nl . __LINE__ . ') ' . __METHOD__ . '() '; |
|
654 | - echo self::$nl . ' . . registration->ID: ' . $registration->ID(); |
|
655 | - echo self::$nl . ' . . registration->status_ID: ' . $registration->status_ID(); |
|
656 | - echo self::$nl . ' . . transaction->status_ID(): ' . $STS_ID; |
|
653 | + echo self::$nl.self::$nl.__LINE__.') '.__METHOD__.'() '; |
|
654 | + echo self::$nl.' . . registration->ID: '.$registration->ID(); |
|
655 | + echo self::$nl.' . . registration->status_ID: '.$registration->status_ID(); |
|
656 | + echo self::$nl.' . . transaction->status_ID(): '.$STS_ID; |
|
657 | 657 | } |
658 | 658 | if ( |
659 | 659 | // release Tickets for Failed Transactions and Abandoned Transactions |
@@ -666,12 +666,12 @@ discard block |
||
666 | 666 | ) |
667 | 667 | ) { |
668 | 668 | if (self::debug) { |
669 | - echo self::$nl . self::$nl . ' . . RELEASE RESERVED TICKET'; |
|
669 | + echo self::$nl.self::$nl.' . . RELEASE RESERVED TICKET'; |
|
670 | 670 | $rsrvd = $registration->get_extra_meta(EE_Registration::HAS_RESERVED_TICKET_KEY, true); |
671 | - echo self::$nl . ' . . . registration HAS_RESERVED_TICKET_KEY: '; |
|
671 | + echo self::$nl.' . . . registration HAS_RESERVED_TICKET_KEY: '; |
|
672 | 672 | var_dump($rsrvd); |
673 | 673 | } |
674 | - $registration->release_reserved_ticket(true, 'TicketSalesMonitor:' . __LINE__); |
|
674 | + $registration->release_reserved_ticket(true, 'TicketSalesMonitor:'.__LINE__); |
|
675 | 675 | return 1; |
676 | 676 | } |
677 | 677 | return 0; |
@@ -701,7 +701,7 @@ discard block |
||
701 | 701 | } |
702 | 702 | // self::debug hardcoded to false |
703 | 703 | if (self::debug) { |
704 | - echo self::$nl . self::$nl . __LINE__ . ') ' . __METHOD__ . '() '; |
|
704 | + echo self::$nl.self::$nl.__LINE__.') '.__METHOD__.'() '; |
|
705 | 705 | } |
706 | 706 | // first check of the session has a valid Checkout object |
707 | 707 | $checkout = $session->checkout(); |
@@ -713,12 +713,12 @@ discard block |
||
713 | 713 | $cart = $session->cart(); |
714 | 714 | if ($cart instanceof EE_Cart) { |
715 | 715 | if (self::debug) { |
716 | - echo self::$nl . self::$nl . ' cart instance of EE_Cart: '; |
|
716 | + echo self::$nl.self::$nl.' cart instance of EE_Cart: '; |
|
717 | 717 | } |
718 | 718 | EED_Ticket_Sales_Monitor::instance()->_session_cart_reset($cart, $session); |
719 | 719 | } else { |
720 | 720 | if (self::debug) { |
721 | - echo self::$nl . self::$nl . ' invalid EE_Cart: '; |
|
721 | + echo self::$nl.self::$nl.' invalid EE_Cart: '; |
|
722 | 722 | var_export($cart, true); |
723 | 723 | } |
724 | 724 | } |
@@ -740,39 +740,39 @@ discard block |
||
740 | 740 | { |
741 | 741 | // self::debug hardcoded to false |
742 | 742 | if (self::debug) { |
743 | - echo self::$nl . self::$nl . __LINE__ . ') ' . __METHOD__ . '() '; |
|
743 | + echo self::$nl.self::$nl.__LINE__.') '.__METHOD__.'() '; |
|
744 | 744 | } |
745 | 745 | $ticket_line_items = $cart->get_tickets(); |
746 | 746 | if (empty($ticket_line_items)) { |
747 | 747 | return; |
748 | 748 | } |
749 | 749 | if (self::debug) { |
750 | - echo '<br /> . ticket_line_item count: ' . count($ticket_line_items); |
|
750 | + echo '<br /> . ticket_line_item count: '.count($ticket_line_items); |
|
751 | 751 | } |
752 | 752 | foreach ($ticket_line_items as $ticket_line_item) { |
753 | 753 | if (self::debug) { |
754 | - echo self::$nl . ' . ticket_line_item->ID(): ' . $ticket_line_item->ID(); |
|
754 | + echo self::$nl.' . ticket_line_item->ID(): '.$ticket_line_item->ID(); |
|
755 | 755 | } |
756 | 756 | if ($ticket_line_item instanceof EE_Line_Item && $ticket_line_item->OBJ_type() === 'Ticket') { |
757 | 757 | if (self::debug) { |
758 | - echo self::$nl . ' . . ticket_line_item->OBJ_ID(): ' . $ticket_line_item->OBJ_ID(); |
|
758 | + echo self::$nl.' . . ticket_line_item->OBJ_ID(): '.$ticket_line_item->OBJ_ID(); |
|
759 | 759 | } |
760 | 760 | $ticket = EEM_Ticket::instance()->get_one_by_ID($ticket_line_item->OBJ_ID()); |
761 | 761 | if ($ticket instanceof EE_Ticket) { |
762 | 762 | if (self::debug) { |
763 | - echo self::$nl . ' . . ticket->ID(): ' . $ticket->ID(); |
|
764 | - echo self::$nl . ' . . ticket_line_item->quantity(): ' . $ticket_line_item->quantity(); |
|
763 | + echo self::$nl.' . . ticket->ID(): '.$ticket->ID(); |
|
764 | + echo self::$nl.' . . ticket_line_item->quantity(): '.$ticket_line_item->quantity(); |
|
765 | 765 | } |
766 | 766 | $ticket->add_extra_meta( |
767 | 767 | EE_Ticket::META_KEY_TICKET_RESERVATIONS, |
768 | - __LINE__ . ') ' . __METHOD__ . '() SID = ' . $session->id() |
|
768 | + __LINE__.') '.__METHOD__.'() SID = '.$session->id() |
|
769 | 769 | ); |
770 | 770 | $this->_release_reserved_ticket($ticket, $ticket_line_item->quantity()); |
771 | 771 | } |
772 | 772 | } |
773 | 773 | } |
774 | 774 | if (self::debug) { |
775 | - echo self::$nl . self::$nl . ' RESET COMPLETED '; |
|
775 | + echo self::$nl.self::$nl.' RESET COMPLETED '; |
|
776 | 776 | } |
777 | 777 | } |
778 | 778 | |
@@ -814,7 +814,7 @@ discard block |
||
814 | 814 | { |
815 | 815 | // self::debug hardcoded to false |
816 | 816 | if (self::debug) { |
817 | - echo self::$nl . self::$nl . __LINE__ . ') ' . __METHOD__ . '() '; |
|
817 | + echo self::$nl.self::$nl.__LINE__.') '.__METHOD__.'() '; |
|
818 | 818 | } |
819 | 819 | // we want to release the each registration's reserved tickets if the session was cleared, but not if this is a revisit |
820 | 820 | if ($checkout->revisit || ! $checkout->transaction instanceof EE_Transaction) { |
@@ -863,7 +863,7 @@ discard block |
||
863 | 863 | __LINE__, |
864 | 864 | array($transaction), |
865 | 865 | false, |
866 | - 'EE_Transaction: ' . $transaction->ID() |
|
866 | + 'EE_Transaction: '.$transaction->ID() |
|
867 | 867 | ); |
868 | 868 | } |
869 | 869 | return; |
@@ -880,7 +880,7 @@ discard block |
||
880 | 880 | __LINE__, |
881 | 881 | array($payment), |
882 | 882 | false, |
883 | - 'EE_Transaction: ' . $transaction->ID() |
|
883 | + 'EE_Transaction: '.$transaction->ID() |
|
884 | 884 | ); |
885 | 885 | } |
886 | 886 | return; |
@@ -942,7 +942,7 @@ discard block |
||
942 | 942 | } |
943 | 943 | $total_line_item = $transaction->total_line_item(); |
944 | 944 | // $transaction_in_progress->line |
945 | - if (! $total_line_item instanceof EE_Line_Item) { |
|
945 | + if ( ! $total_line_item instanceof EE_Line_Item) { |
|
946 | 946 | throw new DomainException( |
947 | 947 | esc_html__( |
948 | 948 | 'Transaction does not have a valid Total Line Item associated with it.', |
@@ -980,7 +980,7 @@ discard block |
||
980 | 980 | $ticket_line_items = EEH_Line_Item::get_ticket_line_items($total_line_item); |
981 | 981 | foreach ($ticket_line_items as $ticket_line_item) { |
982 | 982 | if ($ticket_line_item instanceof EE_Line_Item) { |
983 | - $valid_reserved_tickets[ $ticket_line_item->ID() ] = $ticket_line_item; |
|
983 | + $valid_reserved_tickets[$ticket_line_item->ID()] = $ticket_line_item; |
|
984 | 984 | } |
985 | 985 | } |
986 | 986 | return $valid_reserved_tickets; |
@@ -1013,7 +1013,7 @@ discard block |
||
1013 | 1013 | $total_tickets_released = 0; |
1014 | 1014 | $sold_out_events = array(); |
1015 | 1015 | foreach ($tickets_with_reservations as $ticket_with_reservations) { |
1016 | - if (! $ticket_with_reservations instanceof EE_Ticket) { |
|
1016 | + if ( ! $ticket_with_reservations instanceof EE_Ticket) { |
|
1017 | 1017 | continue; |
1018 | 1018 | } |
1019 | 1019 | // The $valid_reserved_ticket_line_items tells us what the reserved count on their tickets (and datetimes) |
@@ -1035,9 +1035,9 @@ discard block |
||
1035 | 1035 | if ($expired_reservations_count > 0) { |
1036 | 1036 | $ticket_with_reservations->add_extra_meta( |
1037 | 1037 | EE_Ticket::META_KEY_TICKET_RESERVATIONS, |
1038 | - __LINE__ . ') ' . $source . '()' |
|
1038 | + __LINE__.') '.$source.'()' |
|
1039 | 1039 | ); |
1040 | - $ticket_with_reservations->decreaseReserved($expired_reservations_count, true, 'TicketSalesMonitor:' . __LINE__); |
|
1040 | + $ticket_with_reservations->decreaseReserved($expired_reservations_count, true, 'TicketSalesMonitor:'.__LINE__); |
|
1041 | 1041 | $total_tickets_released += $expired_reservations_count; |
1042 | 1042 | $event = $ticket_with_reservations->get_related_event(); |
1043 | 1043 | // track sold out events |
@@ -1073,7 +1073,7 @@ discard block |
||
1073 | 1073 | { |
1074 | 1074 | /** @type WPDB $wpdb */ |
1075 | 1075 | global $wpdb; |
1076 | - if (! absint($timestamp)) { |
|
1076 | + if ( ! absint($timestamp)) { |
|
1077 | 1077 | /** @var EventEspresso\core\domain\values\session\SessionLifespan $session_lifespan */ |
1078 | 1078 | $session_lifespan = LoaderFactory::getLoader()->getShared( |
1079 | 1079 | 'EventEspresso\core\domain\values\session\SessionLifespan' |
@@ -1082,7 +1082,7 @@ discard block |
||
1082 | 1082 | } |
1083 | 1083 | return $wpdb->query( |
1084 | 1084 | $wpdb->prepare( |
1085 | - 'DELETE FROM ' . EEM_Line_Item::instance()->table() . ' |
|
1085 | + 'DELETE FROM '.EEM_Line_Item::instance()->table().' |
|
1086 | 1086 | WHERE TXN_ID = 0 AND LIN_timestamp <= %s', |
1087 | 1087 | // use GMT time because that's what LIN_timestamps are in |
1088 | 1088 | date('Y-m-d H:i:s', $timestamp) |
@@ -19,1073 +19,1073 @@ |
||
19 | 19 | */ |
20 | 20 | class EED_Ticket_Sales_Monitor extends EED_Module |
21 | 21 | { |
22 | - const debug = false; |
|
23 | - |
|
24 | - private static $nl = ''; |
|
25 | - |
|
26 | - /** |
|
27 | - * an array of raw ticket data from EED_Ticket_Selector |
|
28 | - * |
|
29 | - * @var array $ticket_selections |
|
30 | - */ |
|
31 | - protected $ticket_selections = array(); |
|
32 | - |
|
33 | - /** |
|
34 | - * the raw ticket data from EED_Ticket_Selector is organized in rows |
|
35 | - * according to how they are displayed in the actual Ticket_Selector |
|
36 | - * this tracks the current row being processed |
|
37 | - * |
|
38 | - * @var int $current_row |
|
39 | - */ |
|
40 | - protected $current_row = 0; |
|
41 | - |
|
42 | - /** |
|
43 | - * an array for tracking names of tickets that have sold out |
|
44 | - * |
|
45 | - * @var array $sold_out_tickets |
|
46 | - */ |
|
47 | - protected $sold_out_tickets = array(); |
|
48 | - |
|
49 | - /** |
|
50 | - * an array for tracking names of tickets that have had their quantities reduced |
|
51 | - * |
|
52 | - * @var array $decremented_tickets |
|
53 | - */ |
|
54 | - protected $decremented_tickets = array(); |
|
55 | - |
|
56 | - |
|
57 | - /** |
|
58 | - * set_hooks - for hooking into EE Core, other modules, etc |
|
59 | - * |
|
60 | - * @return void |
|
61 | - */ |
|
62 | - public static function set_hooks() |
|
63 | - { |
|
64 | - self::$nl = defined('EE_TESTS_DIR') ? "\n" : '<br />'; |
|
65 | - // release tickets for expired carts |
|
66 | - add_action( |
|
67 | - 'EED_Ticket_Selector__process_ticket_selections__before', |
|
68 | - array('EED_Ticket_Sales_Monitor', 'release_tickets_for_expired_carts'), |
|
69 | - 1 |
|
70 | - ); |
|
71 | - // check ticket reserves AFTER MER does it's check (hence priority 20) |
|
72 | - add_filter( |
|
73 | - 'FHEE__EE_Ticket_Selector___add_ticket_to_cart__ticket_qty', |
|
74 | - array('EED_Ticket_Sales_Monitor', 'validate_ticket_sale'), |
|
75 | - 20, |
|
76 | - 3 |
|
77 | - ); |
|
78 | - // add notices for sold out tickets |
|
79 | - add_action( |
|
80 | - 'AHEE__EE_Ticket_Selector__process_ticket_selections__after_tickets_added_to_cart', |
|
81 | - array('EED_Ticket_Sales_Monitor', 'post_notices'), |
|
82 | - 10 |
|
83 | - ); |
|
84 | - |
|
85 | - // handle tickets deleted from cart |
|
86 | - add_action( |
|
87 | - 'FHEE__EED_Multi_Event_Registration__delete_ticket__ticket_removed_from_cart', |
|
88 | - array('EED_Ticket_Sales_Monitor', 'ticket_removed_from_cart'), |
|
89 | - 10, |
|
90 | - 2 |
|
91 | - ); |
|
92 | - // handle emptied carts |
|
93 | - add_action( |
|
94 | - 'AHEE__EE_Session__reset_cart__before_reset', |
|
95 | - array('EED_Ticket_Sales_Monitor', 'session_cart_reset'), |
|
96 | - 10, |
|
97 | - 1 |
|
98 | - ); |
|
99 | - add_action( |
|
100 | - 'AHEE__EED_Multi_Event_Registration__empty_event_cart__before_delete_cart', |
|
101 | - array('EED_Ticket_Sales_Monitor', 'session_cart_reset'), |
|
102 | - 10, |
|
103 | - 1 |
|
104 | - ); |
|
105 | - // handle cancelled registrations |
|
106 | - add_action( |
|
107 | - 'AHEE__EE_Session__reset_checkout__before_reset', |
|
108 | - array('EED_Ticket_Sales_Monitor', 'session_checkout_reset'), |
|
109 | - 10, |
|
110 | - 1 |
|
111 | - ); |
|
112 | - // cron tasks |
|
113 | - add_action( |
|
114 | - 'AHEE__EE_Cron_Tasks__process_expired_transactions__abandoned_transaction', |
|
115 | - array('EED_Ticket_Sales_Monitor', 'process_abandoned_transactions'), |
|
116 | - 10, |
|
117 | - 1 |
|
118 | - ); |
|
119 | - add_action( |
|
120 | - 'AHEE__EE_Cron_Tasks__process_expired_transactions__incomplete_transaction', |
|
121 | - array('EED_Ticket_Sales_Monitor', 'process_abandoned_transactions'), |
|
122 | - 10, |
|
123 | - 1 |
|
124 | - ); |
|
125 | - add_action( |
|
126 | - 'AHEE__EE_Cron_Tasks__process_expired_transactions__failed_transaction', |
|
127 | - array('EED_Ticket_Sales_Monitor', 'process_failed_transactions'), |
|
128 | - 10, |
|
129 | - 1 |
|
130 | - ); |
|
131 | - } |
|
132 | - |
|
133 | - |
|
134 | - /** |
|
135 | - * set_hooks_admin - for hooking into EE Admin Core, other modules, etc |
|
136 | - * |
|
137 | - * @return void |
|
138 | - */ |
|
139 | - public static function set_hooks_admin() |
|
140 | - { |
|
141 | - EED_Ticket_Sales_Monitor::set_hooks(); |
|
142 | - } |
|
143 | - |
|
144 | - |
|
145 | - /** |
|
146 | - * @return EED_Ticket_Sales_Monitor|EED_Module |
|
147 | - */ |
|
148 | - public static function instance() |
|
149 | - { |
|
150 | - return parent::get_instance(__CLASS__); |
|
151 | - } |
|
152 | - |
|
153 | - |
|
154 | - /** |
|
155 | - * @param WP_Query $WP_Query |
|
156 | - * @return void |
|
157 | - */ |
|
158 | - public function run($WP_Query) |
|
159 | - { |
|
160 | - } |
|
161 | - |
|
162 | - |
|
163 | - |
|
164 | - /********************************** PRE_TICKET_SALES **********************************/ |
|
165 | - |
|
166 | - |
|
167 | - /** |
|
168 | - * Retrieves grand totals from the line items that have no TXN ID |
|
169 | - * and timestamps less than the current time minus the session lifespan. |
|
170 | - * These are carts that have been abandoned before the "registrant" even attempted to checkout. |
|
171 | - * We're going to release the tickets for these line items before attempting to add more to the cart. |
|
172 | - * |
|
173 | - * @return void |
|
174 | - * @throws DomainException |
|
175 | - * @throws EE_Error |
|
176 | - * @throws InvalidArgumentException |
|
177 | - * @throws InvalidDataTypeException |
|
178 | - * @throws InvalidInterfaceException |
|
179 | - * @throws UnexpectedEntityException |
|
180 | - */ |
|
181 | - public static function release_tickets_for_expired_carts() |
|
182 | - { |
|
183 | - // self::debug hardcoded to false |
|
184 | - if (self::debug) { |
|
185 | - echo self::$nl . self::$nl . __LINE__ . ') ' . __METHOD__ . '()'; |
|
186 | - } |
|
187 | - do_action('AHEE__EED_Ticket_Sales_Monitor__release_tickets_for_expired_carts__begin'); |
|
188 | - $expired_ticket_IDs = array(); |
|
189 | - /** @var EventEspresso\core\domain\values\session\SessionLifespan $session_lifespan */ |
|
190 | - $session_lifespan = LoaderFactory::getLoader()->getShared( |
|
191 | - 'EventEspresso\core\domain\values\session\SessionLifespan' |
|
192 | - ); |
|
193 | - $timestamp = $session_lifespan->expiration(); |
|
194 | - $expired_ticket_line_items = EEM_Line_Item::instance()->getTicketLineItemsForExpiredCarts($timestamp); |
|
195 | - if (self::debug) { |
|
196 | - echo self::$nl . ' . time(): ' . time(); |
|
197 | - echo self::$nl . ' . time() as date: ' . date('Y-m-d H:i a'); |
|
198 | - echo self::$nl . ' . session expiration: ' . $session_lifespan->expiration(); |
|
199 | - echo self::$nl . ' . session expiration as date: ' . date('Y-m-d H:i a', $session_lifespan->expiration()); |
|
200 | - echo self::$nl . ' . timestamp: ' . $timestamp; |
|
201 | - echo self::$nl . ' . $expired_ticket_line_items: ' . count($expired_ticket_line_items); |
|
202 | - } |
|
203 | - if (! empty($expired_ticket_line_items)) { |
|
204 | - foreach ($expired_ticket_line_items as $expired_ticket_line_item) { |
|
205 | - if (! $expired_ticket_line_item instanceof EE_Line_Item) { |
|
206 | - continue; |
|
207 | - } |
|
208 | - $expired_ticket_IDs[ $expired_ticket_line_item->OBJ_ID() ] = $expired_ticket_line_item->OBJ_ID(); |
|
209 | - if (self::debug) { |
|
210 | - echo self::$nl . ' . $expired_ticket_line_item->OBJ_ID(): ' . $expired_ticket_line_item->OBJ_ID(); |
|
211 | - echo self::$nl . ' . $expired_ticket_line_item->timestamp(): ' |
|
212 | - . date( |
|
213 | - 'Y-m-d h:i a', |
|
214 | - $expired_ticket_line_item->timestamp(true) |
|
215 | - ); |
|
216 | - } |
|
217 | - } |
|
218 | - if (! empty($expired_ticket_IDs)) { |
|
219 | - EED_Ticket_Sales_Monitor::release_reservations_for_tickets( |
|
220 | - \EEM_Ticket::instance()->get_tickets_with_IDs($expired_ticket_IDs), |
|
221 | - array(), |
|
222 | - __FUNCTION__ |
|
223 | - ); |
|
224 | - // now let's get rid of expired line items so that they can't interfere with tracking |
|
225 | - EED_Ticket_Sales_Monitor::clear_expired_line_items_with_no_transaction($timestamp); |
|
226 | - } |
|
227 | - } |
|
228 | - do_action( |
|
229 | - 'AHEE__EED_Ticket_Sales_Monitor__release_tickets_for_expired_carts__end', |
|
230 | - $expired_ticket_IDs, |
|
231 | - $expired_ticket_line_items |
|
232 | - ); |
|
233 | - } |
|
234 | - |
|
235 | - |
|
236 | - |
|
237 | - /********************************** VALIDATE_TICKET_SALE **********************************/ |
|
238 | - |
|
239 | - |
|
240 | - /** |
|
241 | - * callback for 'FHEE__EED_Ticket_Selector__process_ticket_selections__valid_post_data' |
|
242 | - * |
|
243 | - * @param int $qty |
|
244 | - * @param EE_Ticket $ticket |
|
245 | - * @return bool |
|
246 | - * @throws UnexpectedEntityException |
|
247 | - * @throws EE_Error |
|
248 | - */ |
|
249 | - public static function validate_ticket_sale($qty = 1, EE_Ticket $ticket) |
|
250 | - { |
|
251 | - $qty = absint($qty); |
|
252 | - if ($qty > 0) { |
|
253 | - $qty = EED_Ticket_Sales_Monitor::instance()->_validate_ticket_sale($ticket, $qty); |
|
254 | - } |
|
255 | - // self::debug hardcoded to false |
|
256 | - if (self::debug) { |
|
257 | - echo self::$nl . self::$nl . __LINE__ . ') ' . __METHOD__ . '()'; |
|
258 | - echo self::$nl . self::$nl . '<b> RETURNED QTY: ' . $qty . '</b>'; |
|
259 | - } |
|
260 | - return $qty; |
|
261 | - } |
|
262 | - |
|
263 | - |
|
264 | - /** |
|
265 | - * checks whether an individual ticket is available for purchase based on datetime, and ticket details |
|
266 | - * |
|
267 | - * @param EE_Ticket $ticket |
|
268 | - * @param int $qty |
|
269 | - * @return int |
|
270 | - * @throws UnexpectedEntityException |
|
271 | - * @throws EE_Error |
|
272 | - */ |
|
273 | - protected function _validate_ticket_sale(EE_Ticket $ticket, $qty = 1) |
|
274 | - { |
|
275 | - // self::debug hardcoded to false |
|
276 | - if (self::debug) { |
|
277 | - echo self::$nl . self::$nl . __LINE__ . ') ' . __METHOD__ . '() '; |
|
278 | - } |
|
279 | - if (! $ticket instanceof EE_Ticket) { |
|
280 | - return 0; |
|
281 | - } |
|
282 | - if (self::debug) { |
|
283 | - echo self::$nl . '<b> . ticket->ID: ' . $ticket->ID() . '</b>'; |
|
284 | - echo self::$nl . ' . original ticket->reserved: ' . $ticket->reserved(); |
|
285 | - } |
|
286 | - $ticket->refresh_from_db(); |
|
287 | - // first let's determine the ticket availability based on sales |
|
288 | - $available = $ticket->qty('saleable'); |
|
289 | - if (self::debug) { |
|
290 | - echo self::$nl . ' . . . ticket->qty: ' . $ticket->qty(); |
|
291 | - echo self::$nl . ' . . . ticket->sold: ' . $ticket->sold(); |
|
292 | - echo self::$nl . ' . . . ticket->reserved: ' . $ticket->reserved(); |
|
293 | - echo self::$nl . ' . . . ticket->qty(saleable): ' . $ticket->qty('saleable'); |
|
294 | - echo self::$nl . ' . . . available: ' . $available; |
|
295 | - } |
|
296 | - if ($available < 1) { |
|
297 | - $this->_ticket_sold_out($ticket); |
|
298 | - return 0; |
|
299 | - } |
|
300 | - if (self::debug) { |
|
301 | - echo self::$nl . ' . . . qty: ' . $qty; |
|
302 | - } |
|
303 | - if ($available < $qty) { |
|
304 | - $qty = $available; |
|
305 | - if (self::debug) { |
|
306 | - echo self::$nl . ' . . . QTY ADJUSTED: ' . $qty; |
|
307 | - } |
|
308 | - $this->_ticket_quantity_decremented($ticket); |
|
309 | - } |
|
310 | - if ($this->_reserve_ticket($ticket, $qty)) { |
|
311 | - return $qty; |
|
312 | - } else { |
|
313 | - return 0; |
|
314 | - } |
|
315 | - } |
|
316 | - |
|
317 | - |
|
318 | - /** |
|
319 | - * increments ticket reserved based on quantity passed |
|
320 | - * |
|
321 | - * @param EE_Ticket $ticket |
|
322 | - * @param int $quantity |
|
323 | - * @return bool indicating success or failure |
|
324 | - * @throws EE_Error |
|
325 | - */ |
|
326 | - protected function _reserve_ticket(EE_Ticket $ticket, $quantity = 1) |
|
327 | - { |
|
328 | - // self::debug hardcoded to false |
|
329 | - if (self::debug) { |
|
330 | - echo self::$nl . self::$nl . ' . . . INCREASE RESERVED: ' . $quantity; |
|
331 | - } |
|
332 | - return $ticket->increaseReserved($quantity, 'TicketSalesMonitor:' . __LINE__); |
|
333 | - } |
|
334 | - |
|
335 | - |
|
336 | - /** |
|
337 | - * @param EE_Ticket $ticket |
|
338 | - * @param int $quantity |
|
339 | - * @return bool |
|
340 | - * @throws EE_Error |
|
341 | - */ |
|
342 | - protected function _release_reserved_ticket(EE_Ticket $ticket, $quantity = 1) |
|
343 | - { |
|
344 | - // self::debug hardcoded to false |
|
345 | - if (self::debug) { |
|
346 | - echo self::$nl . ' . . . ticket->ID: ' . $ticket->ID(); |
|
347 | - echo self::$nl . ' . . . ticket->reserved before: ' . $ticket->reserved(); |
|
348 | - } |
|
349 | - $ticket->decreaseReserved($quantity, true, 'TicketSalesMonitor:' . __LINE__); |
|
350 | - if (self::debug) { |
|
351 | - echo self::$nl . ' . . . ticket->reserved after: ' . $ticket->reserved(); |
|
352 | - } |
|
353 | - return $ticket->save() ? 1 : 0; |
|
354 | - } |
|
355 | - |
|
356 | - |
|
357 | - /** |
|
358 | - * removes quantities within the ticket selector based on zero ticket availability |
|
359 | - * |
|
360 | - * @param EE_Ticket $ticket |
|
361 | - * @return void |
|
362 | - * @throws UnexpectedEntityException |
|
363 | - * @throws EE_Error |
|
364 | - */ |
|
365 | - protected function _ticket_sold_out(EE_Ticket $ticket) |
|
366 | - { |
|
367 | - // self::debug hardcoded to false |
|
368 | - if (self::debug) { |
|
369 | - echo self::$nl . self::$nl . __LINE__ . ') ' . __METHOD__ . '() '; |
|
370 | - echo self::$nl . ' . . ticket->name: ' . $this->_get_ticket_and_event_name($ticket); |
|
371 | - } |
|
372 | - $this->sold_out_tickets[] = $this->_get_ticket_and_event_name($ticket); |
|
373 | - } |
|
374 | - |
|
375 | - |
|
376 | - /** |
|
377 | - * adjusts quantities within the ticket selector based on decreased ticket availability |
|
378 | - * |
|
379 | - * @param EE_Ticket $ticket |
|
380 | - * @return void |
|
381 | - * @throws UnexpectedEntityException |
|
382 | - * @throws EE_Error |
|
383 | - */ |
|
384 | - protected function _ticket_quantity_decremented(EE_Ticket $ticket) |
|
385 | - { |
|
386 | - // self::debug hardcoded to false |
|
387 | - if (self::debug) { |
|
388 | - echo self::$nl . self::$nl . __LINE__ . ') ' . __METHOD__ . '() '; |
|
389 | - echo self::$nl . ' . . ticket->name: ' . $this->_get_ticket_and_event_name($ticket); |
|
390 | - } |
|
391 | - $this->decremented_tickets[] = $this->_get_ticket_and_event_name($ticket); |
|
392 | - } |
|
393 | - |
|
394 | - |
|
395 | - /** |
|
396 | - * builds string out of ticket and event name |
|
397 | - * |
|
398 | - * @param EE_Ticket $ticket |
|
399 | - * @return string |
|
400 | - * @throws UnexpectedEntityException |
|
401 | - * @throws EE_Error |
|
402 | - */ |
|
403 | - protected function _get_ticket_and_event_name(EE_Ticket $ticket) |
|
404 | - { |
|
405 | - $event = $ticket->get_related_event(); |
|
406 | - if ($event instanceof EE_Event) { |
|
407 | - $ticket_name = sprintf( |
|
408 | - _x('%1$s for %2$s', 'ticket name for event name', 'event_espresso'), |
|
409 | - $ticket->name(), |
|
410 | - $event->name() |
|
411 | - ); |
|
412 | - } else { |
|
413 | - $ticket_name = $ticket->name(); |
|
414 | - } |
|
415 | - return $ticket_name; |
|
416 | - } |
|
417 | - |
|
418 | - |
|
419 | - |
|
420 | - /********************************** EVENT CART **********************************/ |
|
421 | - |
|
422 | - |
|
423 | - /** |
|
424 | - * releases or reserves ticket(s) based on quantity passed |
|
425 | - * |
|
426 | - * @param EE_Line_Item $line_item |
|
427 | - * @param int $quantity |
|
428 | - * @return void |
|
429 | - * @throws EE_Error |
|
430 | - * @throws InvalidArgumentException |
|
431 | - * @throws InvalidDataTypeException |
|
432 | - * @throws InvalidInterfaceException |
|
433 | - */ |
|
434 | - public static function ticket_quantity_updated(EE_Line_Item $line_item, $quantity = 1) |
|
435 | - { |
|
436 | - $ticket = EEM_Ticket::instance()->get_one_by_ID(absint($line_item->OBJ_ID())); |
|
437 | - if ($ticket instanceof EE_Ticket) { |
|
438 | - $ticket->add_extra_meta( |
|
439 | - EE_Ticket::META_KEY_TICKET_RESERVATIONS, |
|
440 | - __LINE__ . ') ' . __METHOD__ . '()' |
|
441 | - ); |
|
442 | - if ($quantity > 0) { |
|
443 | - EED_Ticket_Sales_Monitor::instance()->_reserve_ticket($ticket, $quantity); |
|
444 | - } else { |
|
445 | - EED_Ticket_Sales_Monitor::instance()->_release_reserved_ticket($ticket, $quantity); |
|
446 | - } |
|
447 | - } |
|
448 | - } |
|
449 | - |
|
450 | - |
|
451 | - /** |
|
452 | - * releases reserved ticket(s) based on quantity passed |
|
453 | - * |
|
454 | - * @param EE_Ticket $ticket |
|
455 | - * @param int $quantity |
|
456 | - * @return void |
|
457 | - * @throws EE_Error |
|
458 | - */ |
|
459 | - public static function ticket_removed_from_cart(EE_Ticket $ticket, $quantity = 1) |
|
460 | - { |
|
461 | - $ticket->add_extra_meta( |
|
462 | - EE_Ticket::META_KEY_TICKET_RESERVATIONS, |
|
463 | - __LINE__ . ') ' . __METHOD__ . '()' |
|
464 | - ); |
|
465 | - EED_Ticket_Sales_Monitor::instance()->_release_reserved_ticket($ticket, $quantity); |
|
466 | - } |
|
467 | - |
|
468 | - |
|
469 | - |
|
470 | - /********************************** POST_NOTICES **********************************/ |
|
471 | - |
|
472 | - |
|
473 | - /** |
|
474 | - * @return void |
|
475 | - * @throws EE_Error |
|
476 | - * @throws InvalidArgumentException |
|
477 | - * @throws ReflectionException |
|
478 | - * @throws InvalidDataTypeException |
|
479 | - * @throws InvalidInterfaceException |
|
480 | - */ |
|
481 | - public static function post_notices() |
|
482 | - { |
|
483 | - EED_Ticket_Sales_Monitor::instance()->_post_notices(); |
|
484 | - } |
|
485 | - |
|
486 | - |
|
487 | - /** |
|
488 | - * @return void |
|
489 | - * @throws EE_Error |
|
490 | - * @throws InvalidArgumentException |
|
491 | - * @throws ReflectionException |
|
492 | - * @throws InvalidDataTypeException |
|
493 | - * @throws InvalidInterfaceException |
|
494 | - */ |
|
495 | - protected function _post_notices() |
|
496 | - { |
|
497 | - // self::debug hardcoded to false |
|
498 | - if (self::debug) { |
|
499 | - echo self::$nl . self::$nl . __LINE__ . ') ' . __METHOD__ . '() '; |
|
500 | - } |
|
501 | - $refresh_msg = ''; |
|
502 | - $none_added_msg = ''; |
|
503 | - if (defined('DOING_AJAX') && DOING_AJAX) { |
|
504 | - $refresh_msg = esc_html__( |
|
505 | - 'Please refresh the page to view updated ticket quantities.', |
|
506 | - 'event_espresso' |
|
507 | - ); |
|
508 | - $none_added_msg = esc_html__('No tickets were added for the event.', 'event_espresso'); |
|
509 | - } |
|
510 | - if (! empty($this->sold_out_tickets)) { |
|
511 | - EE_Error::add_attention( |
|
512 | - sprintf( |
|
513 | - apply_filters( |
|
514 | - 'FHEE__EED_Ticket_Sales_Monitor___post_notices__sold_out_tickets_notice', |
|
515 | - esc_html__( |
|
516 | - 'We\'re sorry...%1$sThe following items have sold out since you first viewed this page, and can no longer be registered for:%1$s%1$s%2$s%1$s%1$sPlease note that availability can change at any time due to cancellations, so please check back again later if registration for this event(s) is important to you.%1$s%1$s%3$s%1$s%4$s%1$s', |
|
517 | - 'event_espresso' |
|
518 | - ) |
|
519 | - ), |
|
520 | - '<br />', |
|
521 | - implode('<br />', $this->sold_out_tickets), |
|
522 | - $none_added_msg, |
|
523 | - $refresh_msg |
|
524 | - ) |
|
525 | - ); |
|
526 | - // alter code flow in the Ticket Selector for better UX |
|
527 | - add_filter('FHEE__EED_Ticket_Selector__process_ticket_selections__tckts_slctd', '__return_true'); |
|
528 | - add_filter('FHEE__EED_Ticket_Selector__process_ticket_selections__success', '__return_false'); |
|
529 | - $this->sold_out_tickets = array(); |
|
530 | - // and reset the cart |
|
531 | - EED_Ticket_Sales_Monitor::session_cart_reset(EE_Registry::instance()->SSN); |
|
532 | - } |
|
533 | - if (! empty($this->decremented_tickets)) { |
|
534 | - EE_Error::add_attention( |
|
535 | - sprintf( |
|
536 | - apply_filters( |
|
537 | - 'FHEE__EED_Ticket_Sales_Monitor___ticket_quantity_decremented__notice', |
|
538 | - esc_html__( |
|
539 | - 'We\'re sorry...%1$sDue to sales that have occurred since you first viewed the last page, the following items have had their quantities adjusted to match the current available amount:%1$s%1$s%2$s%1$s%1$sPlease note that availability can change at any time due to cancellations, so please check back again later if registration for this event(s) is important to you.%1$s%1$s%3$s%1$s%4$s%1$s', |
|
540 | - 'event_espresso' |
|
541 | - ) |
|
542 | - ), |
|
543 | - '<br />', |
|
544 | - implode('<br />', $this->decremented_tickets), |
|
545 | - $none_added_msg, |
|
546 | - $refresh_msg |
|
547 | - ) |
|
548 | - ); |
|
549 | - $this->decremented_tickets = array(); |
|
550 | - } |
|
551 | - } |
|
552 | - |
|
553 | - |
|
554 | - |
|
555 | - /********************************** RELEASE_ALL_RESERVED_TICKETS_FOR_TRANSACTION **********************************/ |
|
556 | - |
|
557 | - |
|
558 | - /** |
|
559 | - * releases reserved tickets for all registrations of an EE_Transaction |
|
560 | - * by default, will NOT release tickets for finalized transactions |
|
561 | - * |
|
562 | - * @param EE_Transaction $transaction |
|
563 | - * @return int |
|
564 | - * @throws EE_Error |
|
565 | - * @throws InvalidSessionDataException |
|
566 | - */ |
|
567 | - protected function _release_all_reserved_tickets_for_transaction(EE_Transaction $transaction) |
|
568 | - { |
|
569 | - // self::debug hardcoded to false |
|
570 | - if (self::debug) { |
|
571 | - echo self::$nl . self::$nl . __LINE__ . ') ' . __METHOD__ . '() '; |
|
572 | - echo self::$nl . ' . transaction->ID: ' . $transaction->ID(); |
|
573 | - echo self::$nl . ' . TXN status_ID: ' . $transaction->status_ID(); |
|
574 | - } |
|
575 | - // check if 'finalize_registration' step has been completed... |
|
576 | - $finalized = $transaction->reg_step_completed('finalize_registration'); |
|
577 | - if (self::debug) { |
|
578 | - // DEBUG LOG |
|
579 | - EEH_Debug_Tools::log( |
|
580 | - __CLASS__, |
|
581 | - __FUNCTION__, |
|
582 | - __LINE__, |
|
583 | - array('finalized' => $finalized), |
|
584 | - false, |
|
585 | - 'EE_Transaction: ' . $transaction->ID() |
|
586 | - ); |
|
587 | - } |
|
588 | - // how many tickets were released |
|
589 | - $count = 0; |
|
590 | - if (self::debug) { |
|
591 | - echo self::$nl . ' . . . TXN finalized: ' . $finalized; |
|
592 | - } |
|
593 | - $release_tickets_with_TXN_status = array( |
|
594 | - EEM_Transaction::failed_status_code, |
|
595 | - EEM_Transaction::abandoned_status_code, |
|
596 | - EEM_Transaction::incomplete_status_code, |
|
597 | - ); |
|
598 | - $events = array(); |
|
599 | - // if the session is getting cleared BEFORE the TXN has been finalized or the transaction is not completed |
|
600 | - if (! $finalized || in_array($transaction->status_ID(), $release_tickets_with_TXN_status, true)) { |
|
601 | - // cancel any reserved tickets for registrations that were not approved |
|
602 | - $registrations = $transaction->registrations(); |
|
603 | - if (self::debug) { |
|
604 | - echo self::$nl . ' . . . # registrations: ' . count($registrations); |
|
605 | - $reg = reset($registrations); |
|
606 | - $ticket = $reg->ticket(); |
|
607 | - if ($ticket instanceof EE_Ticket) { |
|
608 | - $ticket->add_extra_meta( |
|
609 | - EE_Ticket::META_KEY_TICKET_RESERVATIONS, |
|
610 | - __LINE__ . ') Release All Tickets TXN:' . $transaction->ID() |
|
611 | - ); |
|
612 | - } |
|
613 | - } |
|
614 | - if (! empty($registrations)) { |
|
615 | - foreach ($registrations as $registration) { |
|
616 | - if ( |
|
617 | - $registration instanceof EE_Registration |
|
618 | - && $this->_release_reserved_ticket_for_registration($registration, $transaction) |
|
619 | - ) { |
|
620 | - $count++; |
|
621 | - $events[ $registration->event_ID() ] = $registration->event(); |
|
622 | - } |
|
623 | - } |
|
624 | - } |
|
625 | - } |
|
626 | - if ($events !== array()) { |
|
627 | - foreach ($events as $event) { |
|
628 | - /** @var EE_Event $event */ |
|
629 | - $event->perform_sold_out_status_check(); |
|
630 | - } |
|
631 | - } |
|
632 | - return $count; |
|
633 | - } |
|
634 | - |
|
635 | - |
|
636 | - /** |
|
637 | - * releases reserved tickets for an EE_Registration |
|
638 | - * by default, will NOT release tickets for APPROVED registrations |
|
639 | - * |
|
640 | - * @param EE_Registration $registration |
|
641 | - * @param EE_Transaction $transaction |
|
642 | - * @return int |
|
643 | - * @throws EE_Error |
|
644 | - */ |
|
645 | - protected function _release_reserved_ticket_for_registration( |
|
646 | - EE_Registration $registration, |
|
647 | - EE_Transaction $transaction |
|
648 | - ) { |
|
649 | - $STS_ID = $transaction->status_ID(); |
|
650 | - // self::debug hardcoded to false |
|
651 | - if (self::debug) { |
|
652 | - echo self::$nl . self::$nl . __LINE__ . ') ' . __METHOD__ . '() '; |
|
653 | - echo self::$nl . ' . . registration->ID: ' . $registration->ID(); |
|
654 | - echo self::$nl . ' . . registration->status_ID: ' . $registration->status_ID(); |
|
655 | - echo self::$nl . ' . . transaction->status_ID(): ' . $STS_ID; |
|
656 | - } |
|
657 | - if ( |
|
22 | + const debug = false; |
|
23 | + |
|
24 | + private static $nl = ''; |
|
25 | + |
|
26 | + /** |
|
27 | + * an array of raw ticket data from EED_Ticket_Selector |
|
28 | + * |
|
29 | + * @var array $ticket_selections |
|
30 | + */ |
|
31 | + protected $ticket_selections = array(); |
|
32 | + |
|
33 | + /** |
|
34 | + * the raw ticket data from EED_Ticket_Selector is organized in rows |
|
35 | + * according to how they are displayed in the actual Ticket_Selector |
|
36 | + * this tracks the current row being processed |
|
37 | + * |
|
38 | + * @var int $current_row |
|
39 | + */ |
|
40 | + protected $current_row = 0; |
|
41 | + |
|
42 | + /** |
|
43 | + * an array for tracking names of tickets that have sold out |
|
44 | + * |
|
45 | + * @var array $sold_out_tickets |
|
46 | + */ |
|
47 | + protected $sold_out_tickets = array(); |
|
48 | + |
|
49 | + /** |
|
50 | + * an array for tracking names of tickets that have had their quantities reduced |
|
51 | + * |
|
52 | + * @var array $decremented_tickets |
|
53 | + */ |
|
54 | + protected $decremented_tickets = array(); |
|
55 | + |
|
56 | + |
|
57 | + /** |
|
58 | + * set_hooks - for hooking into EE Core, other modules, etc |
|
59 | + * |
|
60 | + * @return void |
|
61 | + */ |
|
62 | + public static function set_hooks() |
|
63 | + { |
|
64 | + self::$nl = defined('EE_TESTS_DIR') ? "\n" : '<br />'; |
|
65 | + // release tickets for expired carts |
|
66 | + add_action( |
|
67 | + 'EED_Ticket_Selector__process_ticket_selections__before', |
|
68 | + array('EED_Ticket_Sales_Monitor', 'release_tickets_for_expired_carts'), |
|
69 | + 1 |
|
70 | + ); |
|
71 | + // check ticket reserves AFTER MER does it's check (hence priority 20) |
|
72 | + add_filter( |
|
73 | + 'FHEE__EE_Ticket_Selector___add_ticket_to_cart__ticket_qty', |
|
74 | + array('EED_Ticket_Sales_Monitor', 'validate_ticket_sale'), |
|
75 | + 20, |
|
76 | + 3 |
|
77 | + ); |
|
78 | + // add notices for sold out tickets |
|
79 | + add_action( |
|
80 | + 'AHEE__EE_Ticket_Selector__process_ticket_selections__after_tickets_added_to_cart', |
|
81 | + array('EED_Ticket_Sales_Monitor', 'post_notices'), |
|
82 | + 10 |
|
83 | + ); |
|
84 | + |
|
85 | + // handle tickets deleted from cart |
|
86 | + add_action( |
|
87 | + 'FHEE__EED_Multi_Event_Registration__delete_ticket__ticket_removed_from_cart', |
|
88 | + array('EED_Ticket_Sales_Monitor', 'ticket_removed_from_cart'), |
|
89 | + 10, |
|
90 | + 2 |
|
91 | + ); |
|
92 | + // handle emptied carts |
|
93 | + add_action( |
|
94 | + 'AHEE__EE_Session__reset_cart__before_reset', |
|
95 | + array('EED_Ticket_Sales_Monitor', 'session_cart_reset'), |
|
96 | + 10, |
|
97 | + 1 |
|
98 | + ); |
|
99 | + add_action( |
|
100 | + 'AHEE__EED_Multi_Event_Registration__empty_event_cart__before_delete_cart', |
|
101 | + array('EED_Ticket_Sales_Monitor', 'session_cart_reset'), |
|
102 | + 10, |
|
103 | + 1 |
|
104 | + ); |
|
105 | + // handle cancelled registrations |
|
106 | + add_action( |
|
107 | + 'AHEE__EE_Session__reset_checkout__before_reset', |
|
108 | + array('EED_Ticket_Sales_Monitor', 'session_checkout_reset'), |
|
109 | + 10, |
|
110 | + 1 |
|
111 | + ); |
|
112 | + // cron tasks |
|
113 | + add_action( |
|
114 | + 'AHEE__EE_Cron_Tasks__process_expired_transactions__abandoned_transaction', |
|
115 | + array('EED_Ticket_Sales_Monitor', 'process_abandoned_transactions'), |
|
116 | + 10, |
|
117 | + 1 |
|
118 | + ); |
|
119 | + add_action( |
|
120 | + 'AHEE__EE_Cron_Tasks__process_expired_transactions__incomplete_transaction', |
|
121 | + array('EED_Ticket_Sales_Monitor', 'process_abandoned_transactions'), |
|
122 | + 10, |
|
123 | + 1 |
|
124 | + ); |
|
125 | + add_action( |
|
126 | + 'AHEE__EE_Cron_Tasks__process_expired_transactions__failed_transaction', |
|
127 | + array('EED_Ticket_Sales_Monitor', 'process_failed_transactions'), |
|
128 | + 10, |
|
129 | + 1 |
|
130 | + ); |
|
131 | + } |
|
132 | + |
|
133 | + |
|
134 | + /** |
|
135 | + * set_hooks_admin - for hooking into EE Admin Core, other modules, etc |
|
136 | + * |
|
137 | + * @return void |
|
138 | + */ |
|
139 | + public static function set_hooks_admin() |
|
140 | + { |
|
141 | + EED_Ticket_Sales_Monitor::set_hooks(); |
|
142 | + } |
|
143 | + |
|
144 | + |
|
145 | + /** |
|
146 | + * @return EED_Ticket_Sales_Monitor|EED_Module |
|
147 | + */ |
|
148 | + public static function instance() |
|
149 | + { |
|
150 | + return parent::get_instance(__CLASS__); |
|
151 | + } |
|
152 | + |
|
153 | + |
|
154 | + /** |
|
155 | + * @param WP_Query $WP_Query |
|
156 | + * @return void |
|
157 | + */ |
|
158 | + public function run($WP_Query) |
|
159 | + { |
|
160 | + } |
|
161 | + |
|
162 | + |
|
163 | + |
|
164 | + /********************************** PRE_TICKET_SALES **********************************/ |
|
165 | + |
|
166 | + |
|
167 | + /** |
|
168 | + * Retrieves grand totals from the line items that have no TXN ID |
|
169 | + * and timestamps less than the current time minus the session lifespan. |
|
170 | + * These are carts that have been abandoned before the "registrant" even attempted to checkout. |
|
171 | + * We're going to release the tickets for these line items before attempting to add more to the cart. |
|
172 | + * |
|
173 | + * @return void |
|
174 | + * @throws DomainException |
|
175 | + * @throws EE_Error |
|
176 | + * @throws InvalidArgumentException |
|
177 | + * @throws InvalidDataTypeException |
|
178 | + * @throws InvalidInterfaceException |
|
179 | + * @throws UnexpectedEntityException |
|
180 | + */ |
|
181 | + public static function release_tickets_for_expired_carts() |
|
182 | + { |
|
183 | + // self::debug hardcoded to false |
|
184 | + if (self::debug) { |
|
185 | + echo self::$nl . self::$nl . __LINE__ . ') ' . __METHOD__ . '()'; |
|
186 | + } |
|
187 | + do_action('AHEE__EED_Ticket_Sales_Monitor__release_tickets_for_expired_carts__begin'); |
|
188 | + $expired_ticket_IDs = array(); |
|
189 | + /** @var EventEspresso\core\domain\values\session\SessionLifespan $session_lifespan */ |
|
190 | + $session_lifespan = LoaderFactory::getLoader()->getShared( |
|
191 | + 'EventEspresso\core\domain\values\session\SessionLifespan' |
|
192 | + ); |
|
193 | + $timestamp = $session_lifespan->expiration(); |
|
194 | + $expired_ticket_line_items = EEM_Line_Item::instance()->getTicketLineItemsForExpiredCarts($timestamp); |
|
195 | + if (self::debug) { |
|
196 | + echo self::$nl . ' . time(): ' . time(); |
|
197 | + echo self::$nl . ' . time() as date: ' . date('Y-m-d H:i a'); |
|
198 | + echo self::$nl . ' . session expiration: ' . $session_lifespan->expiration(); |
|
199 | + echo self::$nl . ' . session expiration as date: ' . date('Y-m-d H:i a', $session_lifespan->expiration()); |
|
200 | + echo self::$nl . ' . timestamp: ' . $timestamp; |
|
201 | + echo self::$nl . ' . $expired_ticket_line_items: ' . count($expired_ticket_line_items); |
|
202 | + } |
|
203 | + if (! empty($expired_ticket_line_items)) { |
|
204 | + foreach ($expired_ticket_line_items as $expired_ticket_line_item) { |
|
205 | + if (! $expired_ticket_line_item instanceof EE_Line_Item) { |
|
206 | + continue; |
|
207 | + } |
|
208 | + $expired_ticket_IDs[ $expired_ticket_line_item->OBJ_ID() ] = $expired_ticket_line_item->OBJ_ID(); |
|
209 | + if (self::debug) { |
|
210 | + echo self::$nl . ' . $expired_ticket_line_item->OBJ_ID(): ' . $expired_ticket_line_item->OBJ_ID(); |
|
211 | + echo self::$nl . ' . $expired_ticket_line_item->timestamp(): ' |
|
212 | + . date( |
|
213 | + 'Y-m-d h:i a', |
|
214 | + $expired_ticket_line_item->timestamp(true) |
|
215 | + ); |
|
216 | + } |
|
217 | + } |
|
218 | + if (! empty($expired_ticket_IDs)) { |
|
219 | + EED_Ticket_Sales_Monitor::release_reservations_for_tickets( |
|
220 | + \EEM_Ticket::instance()->get_tickets_with_IDs($expired_ticket_IDs), |
|
221 | + array(), |
|
222 | + __FUNCTION__ |
|
223 | + ); |
|
224 | + // now let's get rid of expired line items so that they can't interfere with tracking |
|
225 | + EED_Ticket_Sales_Monitor::clear_expired_line_items_with_no_transaction($timestamp); |
|
226 | + } |
|
227 | + } |
|
228 | + do_action( |
|
229 | + 'AHEE__EED_Ticket_Sales_Monitor__release_tickets_for_expired_carts__end', |
|
230 | + $expired_ticket_IDs, |
|
231 | + $expired_ticket_line_items |
|
232 | + ); |
|
233 | + } |
|
234 | + |
|
235 | + |
|
236 | + |
|
237 | + /********************************** VALIDATE_TICKET_SALE **********************************/ |
|
238 | + |
|
239 | + |
|
240 | + /** |
|
241 | + * callback for 'FHEE__EED_Ticket_Selector__process_ticket_selections__valid_post_data' |
|
242 | + * |
|
243 | + * @param int $qty |
|
244 | + * @param EE_Ticket $ticket |
|
245 | + * @return bool |
|
246 | + * @throws UnexpectedEntityException |
|
247 | + * @throws EE_Error |
|
248 | + */ |
|
249 | + public static function validate_ticket_sale($qty = 1, EE_Ticket $ticket) |
|
250 | + { |
|
251 | + $qty = absint($qty); |
|
252 | + if ($qty > 0) { |
|
253 | + $qty = EED_Ticket_Sales_Monitor::instance()->_validate_ticket_sale($ticket, $qty); |
|
254 | + } |
|
255 | + // self::debug hardcoded to false |
|
256 | + if (self::debug) { |
|
257 | + echo self::$nl . self::$nl . __LINE__ . ') ' . __METHOD__ . '()'; |
|
258 | + echo self::$nl . self::$nl . '<b> RETURNED QTY: ' . $qty . '</b>'; |
|
259 | + } |
|
260 | + return $qty; |
|
261 | + } |
|
262 | + |
|
263 | + |
|
264 | + /** |
|
265 | + * checks whether an individual ticket is available for purchase based on datetime, and ticket details |
|
266 | + * |
|
267 | + * @param EE_Ticket $ticket |
|
268 | + * @param int $qty |
|
269 | + * @return int |
|
270 | + * @throws UnexpectedEntityException |
|
271 | + * @throws EE_Error |
|
272 | + */ |
|
273 | + protected function _validate_ticket_sale(EE_Ticket $ticket, $qty = 1) |
|
274 | + { |
|
275 | + // self::debug hardcoded to false |
|
276 | + if (self::debug) { |
|
277 | + echo self::$nl . self::$nl . __LINE__ . ') ' . __METHOD__ . '() '; |
|
278 | + } |
|
279 | + if (! $ticket instanceof EE_Ticket) { |
|
280 | + return 0; |
|
281 | + } |
|
282 | + if (self::debug) { |
|
283 | + echo self::$nl . '<b> . ticket->ID: ' . $ticket->ID() . '</b>'; |
|
284 | + echo self::$nl . ' . original ticket->reserved: ' . $ticket->reserved(); |
|
285 | + } |
|
286 | + $ticket->refresh_from_db(); |
|
287 | + // first let's determine the ticket availability based on sales |
|
288 | + $available = $ticket->qty('saleable'); |
|
289 | + if (self::debug) { |
|
290 | + echo self::$nl . ' . . . ticket->qty: ' . $ticket->qty(); |
|
291 | + echo self::$nl . ' . . . ticket->sold: ' . $ticket->sold(); |
|
292 | + echo self::$nl . ' . . . ticket->reserved: ' . $ticket->reserved(); |
|
293 | + echo self::$nl . ' . . . ticket->qty(saleable): ' . $ticket->qty('saleable'); |
|
294 | + echo self::$nl . ' . . . available: ' . $available; |
|
295 | + } |
|
296 | + if ($available < 1) { |
|
297 | + $this->_ticket_sold_out($ticket); |
|
298 | + return 0; |
|
299 | + } |
|
300 | + if (self::debug) { |
|
301 | + echo self::$nl . ' . . . qty: ' . $qty; |
|
302 | + } |
|
303 | + if ($available < $qty) { |
|
304 | + $qty = $available; |
|
305 | + if (self::debug) { |
|
306 | + echo self::$nl . ' . . . QTY ADJUSTED: ' . $qty; |
|
307 | + } |
|
308 | + $this->_ticket_quantity_decremented($ticket); |
|
309 | + } |
|
310 | + if ($this->_reserve_ticket($ticket, $qty)) { |
|
311 | + return $qty; |
|
312 | + } else { |
|
313 | + return 0; |
|
314 | + } |
|
315 | + } |
|
316 | + |
|
317 | + |
|
318 | + /** |
|
319 | + * increments ticket reserved based on quantity passed |
|
320 | + * |
|
321 | + * @param EE_Ticket $ticket |
|
322 | + * @param int $quantity |
|
323 | + * @return bool indicating success or failure |
|
324 | + * @throws EE_Error |
|
325 | + */ |
|
326 | + protected function _reserve_ticket(EE_Ticket $ticket, $quantity = 1) |
|
327 | + { |
|
328 | + // self::debug hardcoded to false |
|
329 | + if (self::debug) { |
|
330 | + echo self::$nl . self::$nl . ' . . . INCREASE RESERVED: ' . $quantity; |
|
331 | + } |
|
332 | + return $ticket->increaseReserved($quantity, 'TicketSalesMonitor:' . __LINE__); |
|
333 | + } |
|
334 | + |
|
335 | + |
|
336 | + /** |
|
337 | + * @param EE_Ticket $ticket |
|
338 | + * @param int $quantity |
|
339 | + * @return bool |
|
340 | + * @throws EE_Error |
|
341 | + */ |
|
342 | + protected function _release_reserved_ticket(EE_Ticket $ticket, $quantity = 1) |
|
343 | + { |
|
344 | + // self::debug hardcoded to false |
|
345 | + if (self::debug) { |
|
346 | + echo self::$nl . ' . . . ticket->ID: ' . $ticket->ID(); |
|
347 | + echo self::$nl . ' . . . ticket->reserved before: ' . $ticket->reserved(); |
|
348 | + } |
|
349 | + $ticket->decreaseReserved($quantity, true, 'TicketSalesMonitor:' . __LINE__); |
|
350 | + if (self::debug) { |
|
351 | + echo self::$nl . ' . . . ticket->reserved after: ' . $ticket->reserved(); |
|
352 | + } |
|
353 | + return $ticket->save() ? 1 : 0; |
|
354 | + } |
|
355 | + |
|
356 | + |
|
357 | + /** |
|
358 | + * removes quantities within the ticket selector based on zero ticket availability |
|
359 | + * |
|
360 | + * @param EE_Ticket $ticket |
|
361 | + * @return void |
|
362 | + * @throws UnexpectedEntityException |
|
363 | + * @throws EE_Error |
|
364 | + */ |
|
365 | + protected function _ticket_sold_out(EE_Ticket $ticket) |
|
366 | + { |
|
367 | + // self::debug hardcoded to false |
|
368 | + if (self::debug) { |
|
369 | + echo self::$nl . self::$nl . __LINE__ . ') ' . __METHOD__ . '() '; |
|
370 | + echo self::$nl . ' . . ticket->name: ' . $this->_get_ticket_and_event_name($ticket); |
|
371 | + } |
|
372 | + $this->sold_out_tickets[] = $this->_get_ticket_and_event_name($ticket); |
|
373 | + } |
|
374 | + |
|
375 | + |
|
376 | + /** |
|
377 | + * adjusts quantities within the ticket selector based on decreased ticket availability |
|
378 | + * |
|
379 | + * @param EE_Ticket $ticket |
|
380 | + * @return void |
|
381 | + * @throws UnexpectedEntityException |
|
382 | + * @throws EE_Error |
|
383 | + */ |
|
384 | + protected function _ticket_quantity_decremented(EE_Ticket $ticket) |
|
385 | + { |
|
386 | + // self::debug hardcoded to false |
|
387 | + if (self::debug) { |
|
388 | + echo self::$nl . self::$nl . __LINE__ . ') ' . __METHOD__ . '() '; |
|
389 | + echo self::$nl . ' . . ticket->name: ' . $this->_get_ticket_and_event_name($ticket); |
|
390 | + } |
|
391 | + $this->decremented_tickets[] = $this->_get_ticket_and_event_name($ticket); |
|
392 | + } |
|
393 | + |
|
394 | + |
|
395 | + /** |
|
396 | + * builds string out of ticket and event name |
|
397 | + * |
|
398 | + * @param EE_Ticket $ticket |
|
399 | + * @return string |
|
400 | + * @throws UnexpectedEntityException |
|
401 | + * @throws EE_Error |
|
402 | + */ |
|
403 | + protected function _get_ticket_and_event_name(EE_Ticket $ticket) |
|
404 | + { |
|
405 | + $event = $ticket->get_related_event(); |
|
406 | + if ($event instanceof EE_Event) { |
|
407 | + $ticket_name = sprintf( |
|
408 | + _x('%1$s for %2$s', 'ticket name for event name', 'event_espresso'), |
|
409 | + $ticket->name(), |
|
410 | + $event->name() |
|
411 | + ); |
|
412 | + } else { |
|
413 | + $ticket_name = $ticket->name(); |
|
414 | + } |
|
415 | + return $ticket_name; |
|
416 | + } |
|
417 | + |
|
418 | + |
|
419 | + |
|
420 | + /********************************** EVENT CART **********************************/ |
|
421 | + |
|
422 | + |
|
423 | + /** |
|
424 | + * releases or reserves ticket(s) based on quantity passed |
|
425 | + * |
|
426 | + * @param EE_Line_Item $line_item |
|
427 | + * @param int $quantity |
|
428 | + * @return void |
|
429 | + * @throws EE_Error |
|
430 | + * @throws InvalidArgumentException |
|
431 | + * @throws InvalidDataTypeException |
|
432 | + * @throws InvalidInterfaceException |
|
433 | + */ |
|
434 | + public static function ticket_quantity_updated(EE_Line_Item $line_item, $quantity = 1) |
|
435 | + { |
|
436 | + $ticket = EEM_Ticket::instance()->get_one_by_ID(absint($line_item->OBJ_ID())); |
|
437 | + if ($ticket instanceof EE_Ticket) { |
|
438 | + $ticket->add_extra_meta( |
|
439 | + EE_Ticket::META_KEY_TICKET_RESERVATIONS, |
|
440 | + __LINE__ . ') ' . __METHOD__ . '()' |
|
441 | + ); |
|
442 | + if ($quantity > 0) { |
|
443 | + EED_Ticket_Sales_Monitor::instance()->_reserve_ticket($ticket, $quantity); |
|
444 | + } else { |
|
445 | + EED_Ticket_Sales_Monitor::instance()->_release_reserved_ticket($ticket, $quantity); |
|
446 | + } |
|
447 | + } |
|
448 | + } |
|
449 | + |
|
450 | + |
|
451 | + /** |
|
452 | + * releases reserved ticket(s) based on quantity passed |
|
453 | + * |
|
454 | + * @param EE_Ticket $ticket |
|
455 | + * @param int $quantity |
|
456 | + * @return void |
|
457 | + * @throws EE_Error |
|
458 | + */ |
|
459 | + public static function ticket_removed_from_cart(EE_Ticket $ticket, $quantity = 1) |
|
460 | + { |
|
461 | + $ticket->add_extra_meta( |
|
462 | + EE_Ticket::META_KEY_TICKET_RESERVATIONS, |
|
463 | + __LINE__ . ') ' . __METHOD__ . '()' |
|
464 | + ); |
|
465 | + EED_Ticket_Sales_Monitor::instance()->_release_reserved_ticket($ticket, $quantity); |
|
466 | + } |
|
467 | + |
|
468 | + |
|
469 | + |
|
470 | + /********************************** POST_NOTICES **********************************/ |
|
471 | + |
|
472 | + |
|
473 | + /** |
|
474 | + * @return void |
|
475 | + * @throws EE_Error |
|
476 | + * @throws InvalidArgumentException |
|
477 | + * @throws ReflectionException |
|
478 | + * @throws InvalidDataTypeException |
|
479 | + * @throws InvalidInterfaceException |
|
480 | + */ |
|
481 | + public static function post_notices() |
|
482 | + { |
|
483 | + EED_Ticket_Sales_Monitor::instance()->_post_notices(); |
|
484 | + } |
|
485 | + |
|
486 | + |
|
487 | + /** |
|
488 | + * @return void |
|
489 | + * @throws EE_Error |
|
490 | + * @throws InvalidArgumentException |
|
491 | + * @throws ReflectionException |
|
492 | + * @throws InvalidDataTypeException |
|
493 | + * @throws InvalidInterfaceException |
|
494 | + */ |
|
495 | + protected function _post_notices() |
|
496 | + { |
|
497 | + // self::debug hardcoded to false |
|
498 | + if (self::debug) { |
|
499 | + echo self::$nl . self::$nl . __LINE__ . ') ' . __METHOD__ . '() '; |
|
500 | + } |
|
501 | + $refresh_msg = ''; |
|
502 | + $none_added_msg = ''; |
|
503 | + if (defined('DOING_AJAX') && DOING_AJAX) { |
|
504 | + $refresh_msg = esc_html__( |
|
505 | + 'Please refresh the page to view updated ticket quantities.', |
|
506 | + 'event_espresso' |
|
507 | + ); |
|
508 | + $none_added_msg = esc_html__('No tickets were added for the event.', 'event_espresso'); |
|
509 | + } |
|
510 | + if (! empty($this->sold_out_tickets)) { |
|
511 | + EE_Error::add_attention( |
|
512 | + sprintf( |
|
513 | + apply_filters( |
|
514 | + 'FHEE__EED_Ticket_Sales_Monitor___post_notices__sold_out_tickets_notice', |
|
515 | + esc_html__( |
|
516 | + 'We\'re sorry...%1$sThe following items have sold out since you first viewed this page, and can no longer be registered for:%1$s%1$s%2$s%1$s%1$sPlease note that availability can change at any time due to cancellations, so please check back again later if registration for this event(s) is important to you.%1$s%1$s%3$s%1$s%4$s%1$s', |
|
517 | + 'event_espresso' |
|
518 | + ) |
|
519 | + ), |
|
520 | + '<br />', |
|
521 | + implode('<br />', $this->sold_out_tickets), |
|
522 | + $none_added_msg, |
|
523 | + $refresh_msg |
|
524 | + ) |
|
525 | + ); |
|
526 | + // alter code flow in the Ticket Selector for better UX |
|
527 | + add_filter('FHEE__EED_Ticket_Selector__process_ticket_selections__tckts_slctd', '__return_true'); |
|
528 | + add_filter('FHEE__EED_Ticket_Selector__process_ticket_selections__success', '__return_false'); |
|
529 | + $this->sold_out_tickets = array(); |
|
530 | + // and reset the cart |
|
531 | + EED_Ticket_Sales_Monitor::session_cart_reset(EE_Registry::instance()->SSN); |
|
532 | + } |
|
533 | + if (! empty($this->decremented_tickets)) { |
|
534 | + EE_Error::add_attention( |
|
535 | + sprintf( |
|
536 | + apply_filters( |
|
537 | + 'FHEE__EED_Ticket_Sales_Monitor___ticket_quantity_decremented__notice', |
|
538 | + esc_html__( |
|
539 | + 'We\'re sorry...%1$sDue to sales that have occurred since you first viewed the last page, the following items have had their quantities adjusted to match the current available amount:%1$s%1$s%2$s%1$s%1$sPlease note that availability can change at any time due to cancellations, so please check back again later if registration for this event(s) is important to you.%1$s%1$s%3$s%1$s%4$s%1$s', |
|
540 | + 'event_espresso' |
|
541 | + ) |
|
542 | + ), |
|
543 | + '<br />', |
|
544 | + implode('<br />', $this->decremented_tickets), |
|
545 | + $none_added_msg, |
|
546 | + $refresh_msg |
|
547 | + ) |
|
548 | + ); |
|
549 | + $this->decremented_tickets = array(); |
|
550 | + } |
|
551 | + } |
|
552 | + |
|
553 | + |
|
554 | + |
|
555 | + /********************************** RELEASE_ALL_RESERVED_TICKETS_FOR_TRANSACTION **********************************/ |
|
556 | + |
|
557 | + |
|
558 | + /** |
|
559 | + * releases reserved tickets for all registrations of an EE_Transaction |
|
560 | + * by default, will NOT release tickets for finalized transactions |
|
561 | + * |
|
562 | + * @param EE_Transaction $transaction |
|
563 | + * @return int |
|
564 | + * @throws EE_Error |
|
565 | + * @throws InvalidSessionDataException |
|
566 | + */ |
|
567 | + protected function _release_all_reserved_tickets_for_transaction(EE_Transaction $transaction) |
|
568 | + { |
|
569 | + // self::debug hardcoded to false |
|
570 | + if (self::debug) { |
|
571 | + echo self::$nl . self::$nl . __LINE__ . ') ' . __METHOD__ . '() '; |
|
572 | + echo self::$nl . ' . transaction->ID: ' . $transaction->ID(); |
|
573 | + echo self::$nl . ' . TXN status_ID: ' . $transaction->status_ID(); |
|
574 | + } |
|
575 | + // check if 'finalize_registration' step has been completed... |
|
576 | + $finalized = $transaction->reg_step_completed('finalize_registration'); |
|
577 | + if (self::debug) { |
|
578 | + // DEBUG LOG |
|
579 | + EEH_Debug_Tools::log( |
|
580 | + __CLASS__, |
|
581 | + __FUNCTION__, |
|
582 | + __LINE__, |
|
583 | + array('finalized' => $finalized), |
|
584 | + false, |
|
585 | + 'EE_Transaction: ' . $transaction->ID() |
|
586 | + ); |
|
587 | + } |
|
588 | + // how many tickets were released |
|
589 | + $count = 0; |
|
590 | + if (self::debug) { |
|
591 | + echo self::$nl . ' . . . TXN finalized: ' . $finalized; |
|
592 | + } |
|
593 | + $release_tickets_with_TXN_status = array( |
|
594 | + EEM_Transaction::failed_status_code, |
|
595 | + EEM_Transaction::abandoned_status_code, |
|
596 | + EEM_Transaction::incomplete_status_code, |
|
597 | + ); |
|
598 | + $events = array(); |
|
599 | + // if the session is getting cleared BEFORE the TXN has been finalized or the transaction is not completed |
|
600 | + if (! $finalized || in_array($transaction->status_ID(), $release_tickets_with_TXN_status, true)) { |
|
601 | + // cancel any reserved tickets for registrations that were not approved |
|
602 | + $registrations = $transaction->registrations(); |
|
603 | + if (self::debug) { |
|
604 | + echo self::$nl . ' . . . # registrations: ' . count($registrations); |
|
605 | + $reg = reset($registrations); |
|
606 | + $ticket = $reg->ticket(); |
|
607 | + if ($ticket instanceof EE_Ticket) { |
|
608 | + $ticket->add_extra_meta( |
|
609 | + EE_Ticket::META_KEY_TICKET_RESERVATIONS, |
|
610 | + __LINE__ . ') Release All Tickets TXN:' . $transaction->ID() |
|
611 | + ); |
|
612 | + } |
|
613 | + } |
|
614 | + if (! empty($registrations)) { |
|
615 | + foreach ($registrations as $registration) { |
|
616 | + if ( |
|
617 | + $registration instanceof EE_Registration |
|
618 | + && $this->_release_reserved_ticket_for_registration($registration, $transaction) |
|
619 | + ) { |
|
620 | + $count++; |
|
621 | + $events[ $registration->event_ID() ] = $registration->event(); |
|
622 | + } |
|
623 | + } |
|
624 | + } |
|
625 | + } |
|
626 | + if ($events !== array()) { |
|
627 | + foreach ($events as $event) { |
|
628 | + /** @var EE_Event $event */ |
|
629 | + $event->perform_sold_out_status_check(); |
|
630 | + } |
|
631 | + } |
|
632 | + return $count; |
|
633 | + } |
|
634 | + |
|
635 | + |
|
636 | + /** |
|
637 | + * releases reserved tickets for an EE_Registration |
|
638 | + * by default, will NOT release tickets for APPROVED registrations |
|
639 | + * |
|
640 | + * @param EE_Registration $registration |
|
641 | + * @param EE_Transaction $transaction |
|
642 | + * @return int |
|
643 | + * @throws EE_Error |
|
644 | + */ |
|
645 | + protected function _release_reserved_ticket_for_registration( |
|
646 | + EE_Registration $registration, |
|
647 | + EE_Transaction $transaction |
|
648 | + ) { |
|
649 | + $STS_ID = $transaction->status_ID(); |
|
650 | + // self::debug hardcoded to false |
|
651 | + if (self::debug) { |
|
652 | + echo self::$nl . self::$nl . __LINE__ . ') ' . __METHOD__ . '() '; |
|
653 | + echo self::$nl . ' . . registration->ID: ' . $registration->ID(); |
|
654 | + echo self::$nl . ' . . registration->status_ID: ' . $registration->status_ID(); |
|
655 | + echo self::$nl . ' . . transaction->status_ID(): ' . $STS_ID; |
|
656 | + } |
|
657 | + if ( |
|
658 | 658 | // release Tickets for Failed Transactions and Abandoned Transactions |
659 | - $STS_ID === EEM_Transaction::failed_status_code |
|
660 | - || $STS_ID === EEM_Transaction::abandoned_status_code |
|
661 | - || ( |
|
662 | - // also release Tickets for Incomplete Transactions, but ONLY if the Registrations are NOT Approved |
|
663 | - $STS_ID === EEM_Transaction::incomplete_status_code |
|
664 | - && $registration->status_ID() !== EEM_Registration::status_id_approved |
|
665 | - ) |
|
666 | - ) { |
|
667 | - if (self::debug) { |
|
668 | - echo self::$nl . self::$nl . ' . . RELEASE RESERVED TICKET'; |
|
669 | - $rsrvd = $registration->get_extra_meta(EE_Registration::HAS_RESERVED_TICKET_KEY, true); |
|
670 | - echo self::$nl . ' . . . registration HAS_RESERVED_TICKET_KEY: '; |
|
671 | - var_dump($rsrvd); |
|
672 | - } |
|
673 | - $registration->release_reserved_ticket(true, 'TicketSalesMonitor:' . __LINE__); |
|
674 | - return 1; |
|
675 | - } |
|
676 | - return 0; |
|
677 | - } |
|
678 | - |
|
679 | - |
|
680 | - |
|
681 | - /********************************** SESSION_CART_RESET **********************************/ |
|
682 | - |
|
683 | - |
|
684 | - /** |
|
685 | - * callback hooked into 'AHEE__EE_Session__reset_cart__before_reset' |
|
686 | - * |
|
687 | - * @param EE_Session $session |
|
688 | - * @return void |
|
689 | - * @throws EE_Error |
|
690 | - * @throws InvalidArgumentException |
|
691 | - * @throws ReflectionException |
|
692 | - * @throws InvalidDataTypeException |
|
693 | - * @throws InvalidInterfaceException |
|
694 | - */ |
|
695 | - public static function session_cart_reset(EE_Session $session) |
|
696 | - { |
|
697 | - // don't release tickets if checkout was already reset |
|
698 | - if (did_action('AHEE__EE_Session__reset_checkout__before_reset')) { |
|
699 | - return; |
|
700 | - } |
|
701 | - // self::debug hardcoded to false |
|
702 | - if (self::debug) { |
|
703 | - echo self::$nl . self::$nl . __LINE__ . ') ' . __METHOD__ . '() '; |
|
704 | - } |
|
705 | - // first check of the session has a valid Checkout object |
|
706 | - $checkout = $session->checkout(); |
|
707 | - if ($checkout instanceof EE_Checkout) { |
|
708 | - // and use that to clear ticket reservations because it will update the associated registration meta data |
|
709 | - EED_Ticket_Sales_Monitor::instance()->_session_checkout_reset($checkout); |
|
710 | - return; |
|
711 | - } |
|
712 | - $cart = $session->cart(); |
|
713 | - if ($cart instanceof EE_Cart) { |
|
714 | - if (self::debug) { |
|
715 | - echo self::$nl . self::$nl . ' cart instance of EE_Cart: '; |
|
716 | - } |
|
717 | - EED_Ticket_Sales_Monitor::instance()->_session_cart_reset($cart, $session); |
|
718 | - } else { |
|
719 | - if (self::debug) { |
|
720 | - echo self::$nl . self::$nl . ' invalid EE_Cart: '; |
|
721 | - var_export($cart, true); |
|
722 | - } |
|
723 | - } |
|
724 | - } |
|
725 | - |
|
726 | - |
|
727 | - /** |
|
728 | - * releases reserved tickets in the EE_Cart |
|
729 | - * |
|
730 | - * @param EE_Cart $cart |
|
731 | - * @return void |
|
732 | - * @throws EE_Error |
|
733 | - * @throws InvalidArgumentException |
|
734 | - * @throws ReflectionException |
|
735 | - * @throws InvalidDataTypeException |
|
736 | - * @throws InvalidInterfaceException |
|
737 | - */ |
|
738 | - protected function _session_cart_reset(EE_Cart $cart, EE_Session $session) |
|
739 | - { |
|
740 | - // self::debug hardcoded to false |
|
741 | - if (self::debug) { |
|
742 | - echo self::$nl . self::$nl . __LINE__ . ') ' . __METHOD__ . '() '; |
|
743 | - } |
|
744 | - $ticket_line_items = $cart->get_tickets(); |
|
745 | - if (empty($ticket_line_items)) { |
|
746 | - return; |
|
747 | - } |
|
748 | - if (self::debug) { |
|
749 | - echo '<br /> . ticket_line_item count: ' . count($ticket_line_items); |
|
750 | - } |
|
751 | - foreach ($ticket_line_items as $ticket_line_item) { |
|
752 | - if (self::debug) { |
|
753 | - echo self::$nl . ' . ticket_line_item->ID(): ' . $ticket_line_item->ID(); |
|
754 | - } |
|
755 | - if ($ticket_line_item instanceof EE_Line_Item && $ticket_line_item->OBJ_type() === 'Ticket') { |
|
756 | - if (self::debug) { |
|
757 | - echo self::$nl . ' . . ticket_line_item->OBJ_ID(): ' . $ticket_line_item->OBJ_ID(); |
|
758 | - } |
|
759 | - $ticket = EEM_Ticket::instance()->get_one_by_ID($ticket_line_item->OBJ_ID()); |
|
760 | - if ($ticket instanceof EE_Ticket) { |
|
761 | - if (self::debug) { |
|
762 | - echo self::$nl . ' . . ticket->ID(): ' . $ticket->ID(); |
|
763 | - echo self::$nl . ' . . ticket_line_item->quantity(): ' . $ticket_line_item->quantity(); |
|
764 | - } |
|
765 | - $ticket->add_extra_meta( |
|
766 | - EE_Ticket::META_KEY_TICKET_RESERVATIONS, |
|
767 | - __LINE__ . ') ' . __METHOD__ . '() SID = ' . $session->id() |
|
768 | - ); |
|
769 | - $this->_release_reserved_ticket($ticket, $ticket_line_item->quantity()); |
|
770 | - } |
|
771 | - } |
|
772 | - } |
|
773 | - if (self::debug) { |
|
774 | - echo self::$nl . self::$nl . ' RESET COMPLETED '; |
|
775 | - } |
|
776 | - } |
|
777 | - |
|
778 | - |
|
779 | - |
|
780 | - /********************************** SESSION_CHECKOUT_RESET **********************************/ |
|
781 | - |
|
782 | - |
|
783 | - /** |
|
784 | - * callback hooked into 'AHEE__EE_Session__reset_checkout__before_reset' |
|
785 | - * |
|
786 | - * @param EE_Session $session |
|
787 | - * @return void |
|
788 | - * @throws EE_Error |
|
789 | - * @throws InvalidSessionDataException |
|
790 | - */ |
|
791 | - public static function session_checkout_reset(EE_Session $session) |
|
792 | - { |
|
793 | - // don't release tickets if cart was already reset |
|
794 | - if (did_action('AHEE__EE_Session__reset_cart__before_reset')) { |
|
795 | - return; |
|
796 | - } |
|
797 | - $checkout = $session->checkout(); |
|
798 | - if ($checkout instanceof EE_Checkout) { |
|
799 | - EED_Ticket_Sales_Monitor::instance()->_session_checkout_reset($checkout); |
|
800 | - } |
|
801 | - } |
|
802 | - |
|
803 | - |
|
804 | - /** |
|
805 | - * releases reserved tickets for the EE_Checkout->transaction |
|
806 | - * |
|
807 | - * @param EE_Checkout $checkout |
|
808 | - * @return void |
|
809 | - * @throws EE_Error |
|
810 | - * @throws InvalidSessionDataException |
|
811 | - */ |
|
812 | - protected function _session_checkout_reset(EE_Checkout $checkout) |
|
813 | - { |
|
814 | - // self::debug hardcoded to false |
|
815 | - if (self::debug) { |
|
816 | - echo self::$nl . self::$nl . __LINE__ . ') ' . __METHOD__ . '() '; |
|
817 | - } |
|
818 | - // we want to release the each registration's reserved tickets if the session was cleared, but not if this is a revisit |
|
819 | - if ($checkout->revisit || ! $checkout->transaction instanceof EE_Transaction) { |
|
820 | - return; |
|
821 | - } |
|
822 | - $this->_release_all_reserved_tickets_for_transaction($checkout->transaction); |
|
823 | - } |
|
824 | - |
|
825 | - |
|
826 | - |
|
827 | - /********************************** SESSION_EXPIRED_RESET **********************************/ |
|
828 | - |
|
829 | - |
|
830 | - /** |
|
831 | - * @param EE_Session $session |
|
832 | - * @return void |
|
833 | - */ |
|
834 | - public static function session_expired_reset(EE_Session $session) |
|
835 | - { |
|
836 | - } |
|
837 | - |
|
838 | - |
|
839 | - |
|
840 | - /********************************** PROCESS_ABANDONED_TRANSACTIONS **********************************/ |
|
841 | - |
|
842 | - |
|
843 | - /** |
|
844 | - * releases reserved tickets for all registrations of an ABANDONED EE_Transaction |
|
845 | - * by default, will NOT release tickets for free transactions, or any that have received a payment |
|
846 | - * |
|
847 | - * @param EE_Transaction $transaction |
|
848 | - * @return void |
|
849 | - * @throws EE_Error |
|
850 | - * @throws InvalidSessionDataException |
|
851 | - */ |
|
852 | - public static function process_abandoned_transactions(EE_Transaction $transaction) |
|
853 | - { |
|
854 | - // is this TXN free or has any money been paid towards this TXN? If so, then leave it alone |
|
855 | - if ($transaction->is_free() || $transaction->paid() > 0) { |
|
856 | - // self::debug hardcoded to false |
|
857 | - if (self::debug) { |
|
858 | - // DEBUG LOG |
|
859 | - EEH_Debug_Tools::log( |
|
860 | - __CLASS__, |
|
861 | - __FUNCTION__, |
|
862 | - __LINE__, |
|
863 | - array($transaction), |
|
864 | - false, |
|
865 | - 'EE_Transaction: ' . $transaction->ID() |
|
866 | - ); |
|
867 | - } |
|
868 | - return; |
|
869 | - } |
|
870 | - // have their been any successful payments made ? |
|
871 | - $payments = $transaction->payments(); |
|
872 | - foreach ($payments as $payment) { |
|
873 | - if ($payment instanceof EE_Payment && $payment->status() === EEM_Payment::status_id_approved) { |
|
874 | - if (self::debug) { |
|
875 | - // DEBUG LOG |
|
876 | - EEH_Debug_Tools::log( |
|
877 | - __CLASS__, |
|
878 | - __FUNCTION__, |
|
879 | - __LINE__, |
|
880 | - array($payment), |
|
881 | - false, |
|
882 | - 'EE_Transaction: ' . $transaction->ID() |
|
883 | - ); |
|
884 | - } |
|
885 | - return; |
|
886 | - } |
|
887 | - } |
|
888 | - // since you haven't even attempted to pay for your ticket... |
|
889 | - EED_Ticket_Sales_Monitor::instance()->_release_all_reserved_tickets_for_transaction($transaction); |
|
890 | - } |
|
891 | - |
|
892 | - |
|
893 | - |
|
894 | - /********************************** PROCESS_FAILED_TRANSACTIONS **********************************/ |
|
895 | - |
|
896 | - |
|
897 | - /** |
|
898 | - * releases reserved tickets for absolutely ALL registrations of a FAILED EE_Transaction |
|
899 | - * |
|
900 | - * @param EE_Transaction $transaction |
|
901 | - * @return void |
|
902 | - * @throws EE_Error |
|
903 | - * @throws InvalidSessionDataException |
|
904 | - */ |
|
905 | - public static function process_failed_transactions(EE_Transaction $transaction) |
|
906 | - { |
|
907 | - // since you haven't even attempted to pay for your ticket... |
|
908 | - EED_Ticket_Sales_Monitor::instance()->_release_all_reserved_tickets_for_transaction($transaction); |
|
909 | - } |
|
910 | - |
|
911 | - |
|
912 | - |
|
913 | - /********************************** RESET RESERVATION COUNTS *********************************/ |
|
914 | - |
|
915 | - |
|
916 | - /** |
|
917 | - * Resets the ticket and datetime reserved counts. |
|
918 | - * |
|
919 | - * For all the tickets with reservations, recalculates what their actual reserved counts should be based |
|
920 | - * on the valid transactions. |
|
921 | - * |
|
922 | - * @return int number of tickets whose reservations were released. |
|
923 | - * @throws EE_Error |
|
924 | - * @throws DomainException |
|
925 | - * @throws InvalidDataTypeException |
|
926 | - * @throws InvalidInterfaceException |
|
927 | - * @throws InvalidArgumentException |
|
928 | - * @throws UnexpectedEntityException |
|
929 | - * @throws ReflectionException |
|
930 | - */ |
|
931 | - public static function reset_reservation_counts() |
|
932 | - { |
|
933 | - /** @var EE_Line_Item[] $valid_reserved_tickets */ |
|
934 | - $valid_reserved_tickets = array(); |
|
935 | - /** @var EE_Transaction[] $transactions_in_progress */ |
|
936 | - $transactions_in_progress = EEM_Transaction::instance()->get_transactions_in_progress(); |
|
937 | - foreach ($transactions_in_progress as $transaction) { |
|
938 | - // if this TXN has been fully completed, then skip it |
|
939 | - if ($transaction->reg_step_completed('finalize_registration')) { |
|
940 | - continue; |
|
941 | - } |
|
942 | - $total_line_item = $transaction->total_line_item(); |
|
943 | - // $transaction_in_progress->line |
|
944 | - if (! $total_line_item instanceof EE_Line_Item) { |
|
945 | - throw new DomainException( |
|
946 | - esc_html__( |
|
947 | - 'Transaction does not have a valid Total Line Item associated with it.', |
|
948 | - 'event_espresso' |
|
949 | - ) |
|
950 | - ); |
|
951 | - } |
|
952 | - $valid_reserved_tickets += EED_Ticket_Sales_Monitor::get_ticket_line_items_for_grand_total( |
|
953 | - $total_line_item |
|
954 | - ); |
|
955 | - } |
|
956 | - $total_line_items = EEM_Line_Item::instance()->get_total_line_items_for_active_carts(); |
|
957 | - foreach ($total_line_items as $total_line_item) { |
|
958 | - $valid_reserved_tickets += EED_Ticket_Sales_Monitor::get_ticket_line_items_for_grand_total( |
|
959 | - $total_line_item |
|
960 | - ); |
|
961 | - } |
|
962 | - $tickets_with_reservations = EEM_Ticket::instance()->get_tickets_with_reservations(); |
|
963 | - return EED_Ticket_Sales_Monitor::release_reservations_for_tickets( |
|
964 | - $tickets_with_reservations, |
|
965 | - $valid_reserved_tickets, |
|
966 | - __FUNCTION__ |
|
967 | - ); |
|
968 | - } |
|
969 | - |
|
970 | - |
|
971 | - /** |
|
972 | - * @param EE_Line_Item $total_line_item |
|
973 | - * @return EE_Line_Item[] |
|
974 | - */ |
|
975 | - private static function get_ticket_line_items_for_grand_total(EE_Line_Item $total_line_item) |
|
976 | - { |
|
977 | - /** @var EE_Line_Item[] $valid_reserved_tickets */ |
|
978 | - $valid_reserved_tickets = array(); |
|
979 | - $ticket_line_items = EEH_Line_Item::get_ticket_line_items($total_line_item); |
|
980 | - foreach ($ticket_line_items as $ticket_line_item) { |
|
981 | - if ($ticket_line_item instanceof EE_Line_Item) { |
|
982 | - $valid_reserved_tickets[ $ticket_line_item->ID() ] = $ticket_line_item; |
|
983 | - } |
|
984 | - } |
|
985 | - return $valid_reserved_tickets; |
|
986 | - } |
|
987 | - |
|
988 | - |
|
989 | - /** |
|
990 | - * Releases ticket and datetime reservations (ie, reduces the number of reserved spots on them). |
|
991 | - * |
|
992 | - * Given the list of tickets which have reserved spots on them, uses the complete list of line items for tickets |
|
993 | - * whose transactions aren't complete and also aren't yet expired (ie, they're incomplete and younger than the |
|
994 | - * session's expiry time) to update the ticket (and their datetimes') reserved counts. |
|
995 | - * |
|
996 | - * @param EE_Ticket[] $tickets_with_reservations all tickets with TKT_reserved > 0 |
|
997 | - * @param EE_Line_Item[] $valid_reserved_ticket_line_items all line items for tickets and incomplete transactions |
|
998 | - * whose session has NOT expired. We will use these to determine the number of ticket |
|
999 | - * reservations are now invalid. We don't use the list of invalid ticket line items because |
|
1000 | - * we don't know which of those have already been taken into account when reducing ticket |
|
1001 | - * reservation counts, and which haven't. |
|
1002 | - * @return int |
|
1003 | - * @throws UnexpectedEntityException |
|
1004 | - * @throws DomainException |
|
1005 | - * @throws EE_Error |
|
1006 | - */ |
|
1007 | - protected static function release_reservations_for_tickets( |
|
1008 | - array $tickets_with_reservations, |
|
1009 | - array $valid_reserved_ticket_line_items = array(), |
|
1010 | - $source |
|
1011 | - ) { |
|
1012 | - $total_tickets_released = 0; |
|
1013 | - $sold_out_events = array(); |
|
1014 | - foreach ($tickets_with_reservations as $ticket_with_reservations) { |
|
1015 | - if (! $ticket_with_reservations instanceof EE_Ticket) { |
|
1016 | - continue; |
|
1017 | - } |
|
1018 | - // The $valid_reserved_ticket_line_items tells us what the reserved count on their tickets (and datetimes) |
|
1019 | - // SHOULD be. Instead of just directly updating the list, we're going to use EE_Ticket::decreaseReserved() |
|
1020 | - // to try to avoid race conditions, so instead of just finding the number to update TO, we're going to find |
|
1021 | - // the number to RELEASE. It's the same end result, just different path. |
|
1022 | - // Begin by assuming we're going to release all the reservations on this ticket. |
|
1023 | - $expired_reservations_count = $ticket_with_reservations->reserved(); |
|
1024 | - // Now reduce that number using the list of current valid reservations. |
|
1025 | - foreach ($valid_reserved_ticket_line_items as $valid_reserved_ticket_line_item) { |
|
1026 | - if ( |
|
1027 | - $valid_reserved_ticket_line_item instanceof EE_Line_Item |
|
1028 | - && $valid_reserved_ticket_line_item->OBJ_ID() === $ticket_with_reservations->ID() |
|
1029 | - ) { |
|
1030 | - $expired_reservations_count -= $valid_reserved_ticket_line_item->quantity(); |
|
1031 | - } |
|
1032 | - } |
|
1033 | - // Only bother saving the tickets and datetimes if we're actually going to release some spots. |
|
1034 | - if ($expired_reservations_count > 0) { |
|
1035 | - $ticket_with_reservations->add_extra_meta( |
|
1036 | - EE_Ticket::META_KEY_TICKET_RESERVATIONS, |
|
1037 | - __LINE__ . ') ' . $source . '()' |
|
1038 | - ); |
|
1039 | - $ticket_with_reservations->decreaseReserved($expired_reservations_count, true, 'TicketSalesMonitor:' . __LINE__); |
|
1040 | - $total_tickets_released += $expired_reservations_count; |
|
1041 | - $event = $ticket_with_reservations->get_related_event(); |
|
1042 | - // track sold out events |
|
1043 | - if ($event instanceof EE_Event && $event->is_sold_out()) { |
|
1044 | - $sold_out_events[] = $event; |
|
1045 | - } |
|
1046 | - } |
|
1047 | - } |
|
1048 | - // Double check whether sold out events should remain sold out after releasing tickets |
|
1049 | - if ($sold_out_events !== array()) { |
|
1050 | - foreach ($sold_out_events as $sold_out_event) { |
|
1051 | - /** @var EE_Event $sold_out_event */ |
|
1052 | - $sold_out_event->perform_sold_out_status_check(); |
|
1053 | - } |
|
1054 | - } |
|
1055 | - return $total_tickets_released; |
|
1056 | - } |
|
1057 | - |
|
1058 | - |
|
1059 | - |
|
1060 | - /********************************** SHUTDOWN **********************************/ |
|
1061 | - |
|
1062 | - |
|
1063 | - /** |
|
1064 | - * @param int $timestamp |
|
1065 | - * @return false|int |
|
1066 | - * @throws EE_Error |
|
1067 | - * @throws InvalidArgumentException |
|
1068 | - * @throws InvalidDataTypeException |
|
1069 | - * @throws InvalidInterfaceException |
|
1070 | - */ |
|
1071 | - public static function clear_expired_line_items_with_no_transaction($timestamp = 0) |
|
1072 | - { |
|
1073 | - /** @type WPDB $wpdb */ |
|
1074 | - global $wpdb; |
|
1075 | - if (! absint($timestamp)) { |
|
1076 | - /** @var EventEspresso\core\domain\values\session\SessionLifespan $session_lifespan */ |
|
1077 | - $session_lifespan = LoaderFactory::getLoader()->getShared( |
|
1078 | - 'EventEspresso\core\domain\values\session\SessionLifespan' |
|
1079 | - ); |
|
1080 | - $timestamp = $session_lifespan->expiration(); |
|
1081 | - } |
|
1082 | - return $wpdb->query( |
|
1083 | - $wpdb->prepare( |
|
1084 | - 'DELETE FROM ' . EEM_Line_Item::instance()->table() . ' |
|
659 | + $STS_ID === EEM_Transaction::failed_status_code |
|
660 | + || $STS_ID === EEM_Transaction::abandoned_status_code |
|
661 | + || ( |
|
662 | + // also release Tickets for Incomplete Transactions, but ONLY if the Registrations are NOT Approved |
|
663 | + $STS_ID === EEM_Transaction::incomplete_status_code |
|
664 | + && $registration->status_ID() !== EEM_Registration::status_id_approved |
|
665 | + ) |
|
666 | + ) { |
|
667 | + if (self::debug) { |
|
668 | + echo self::$nl . self::$nl . ' . . RELEASE RESERVED TICKET'; |
|
669 | + $rsrvd = $registration->get_extra_meta(EE_Registration::HAS_RESERVED_TICKET_KEY, true); |
|
670 | + echo self::$nl . ' . . . registration HAS_RESERVED_TICKET_KEY: '; |
|
671 | + var_dump($rsrvd); |
|
672 | + } |
|
673 | + $registration->release_reserved_ticket(true, 'TicketSalesMonitor:' . __LINE__); |
|
674 | + return 1; |
|
675 | + } |
|
676 | + return 0; |
|
677 | + } |
|
678 | + |
|
679 | + |
|
680 | + |
|
681 | + /********************************** SESSION_CART_RESET **********************************/ |
|
682 | + |
|
683 | + |
|
684 | + /** |
|
685 | + * callback hooked into 'AHEE__EE_Session__reset_cart__before_reset' |
|
686 | + * |
|
687 | + * @param EE_Session $session |
|
688 | + * @return void |
|
689 | + * @throws EE_Error |
|
690 | + * @throws InvalidArgumentException |
|
691 | + * @throws ReflectionException |
|
692 | + * @throws InvalidDataTypeException |
|
693 | + * @throws InvalidInterfaceException |
|
694 | + */ |
|
695 | + public static function session_cart_reset(EE_Session $session) |
|
696 | + { |
|
697 | + // don't release tickets if checkout was already reset |
|
698 | + if (did_action('AHEE__EE_Session__reset_checkout__before_reset')) { |
|
699 | + return; |
|
700 | + } |
|
701 | + // self::debug hardcoded to false |
|
702 | + if (self::debug) { |
|
703 | + echo self::$nl . self::$nl . __LINE__ . ') ' . __METHOD__ . '() '; |
|
704 | + } |
|
705 | + // first check of the session has a valid Checkout object |
|
706 | + $checkout = $session->checkout(); |
|
707 | + if ($checkout instanceof EE_Checkout) { |
|
708 | + // and use that to clear ticket reservations because it will update the associated registration meta data |
|
709 | + EED_Ticket_Sales_Monitor::instance()->_session_checkout_reset($checkout); |
|
710 | + return; |
|
711 | + } |
|
712 | + $cart = $session->cart(); |
|
713 | + if ($cart instanceof EE_Cart) { |
|
714 | + if (self::debug) { |
|
715 | + echo self::$nl . self::$nl . ' cart instance of EE_Cart: '; |
|
716 | + } |
|
717 | + EED_Ticket_Sales_Monitor::instance()->_session_cart_reset($cart, $session); |
|
718 | + } else { |
|
719 | + if (self::debug) { |
|
720 | + echo self::$nl . self::$nl . ' invalid EE_Cart: '; |
|
721 | + var_export($cart, true); |
|
722 | + } |
|
723 | + } |
|
724 | + } |
|
725 | + |
|
726 | + |
|
727 | + /** |
|
728 | + * releases reserved tickets in the EE_Cart |
|
729 | + * |
|
730 | + * @param EE_Cart $cart |
|
731 | + * @return void |
|
732 | + * @throws EE_Error |
|
733 | + * @throws InvalidArgumentException |
|
734 | + * @throws ReflectionException |
|
735 | + * @throws InvalidDataTypeException |
|
736 | + * @throws InvalidInterfaceException |
|
737 | + */ |
|
738 | + protected function _session_cart_reset(EE_Cart $cart, EE_Session $session) |
|
739 | + { |
|
740 | + // self::debug hardcoded to false |
|
741 | + if (self::debug) { |
|
742 | + echo self::$nl . self::$nl . __LINE__ . ') ' . __METHOD__ . '() '; |
|
743 | + } |
|
744 | + $ticket_line_items = $cart->get_tickets(); |
|
745 | + if (empty($ticket_line_items)) { |
|
746 | + return; |
|
747 | + } |
|
748 | + if (self::debug) { |
|
749 | + echo '<br /> . ticket_line_item count: ' . count($ticket_line_items); |
|
750 | + } |
|
751 | + foreach ($ticket_line_items as $ticket_line_item) { |
|
752 | + if (self::debug) { |
|
753 | + echo self::$nl . ' . ticket_line_item->ID(): ' . $ticket_line_item->ID(); |
|
754 | + } |
|
755 | + if ($ticket_line_item instanceof EE_Line_Item && $ticket_line_item->OBJ_type() === 'Ticket') { |
|
756 | + if (self::debug) { |
|
757 | + echo self::$nl . ' . . ticket_line_item->OBJ_ID(): ' . $ticket_line_item->OBJ_ID(); |
|
758 | + } |
|
759 | + $ticket = EEM_Ticket::instance()->get_one_by_ID($ticket_line_item->OBJ_ID()); |
|
760 | + if ($ticket instanceof EE_Ticket) { |
|
761 | + if (self::debug) { |
|
762 | + echo self::$nl . ' . . ticket->ID(): ' . $ticket->ID(); |
|
763 | + echo self::$nl . ' . . ticket_line_item->quantity(): ' . $ticket_line_item->quantity(); |
|
764 | + } |
|
765 | + $ticket->add_extra_meta( |
|
766 | + EE_Ticket::META_KEY_TICKET_RESERVATIONS, |
|
767 | + __LINE__ . ') ' . __METHOD__ . '() SID = ' . $session->id() |
|
768 | + ); |
|
769 | + $this->_release_reserved_ticket($ticket, $ticket_line_item->quantity()); |
|
770 | + } |
|
771 | + } |
|
772 | + } |
|
773 | + if (self::debug) { |
|
774 | + echo self::$nl . self::$nl . ' RESET COMPLETED '; |
|
775 | + } |
|
776 | + } |
|
777 | + |
|
778 | + |
|
779 | + |
|
780 | + /********************************** SESSION_CHECKOUT_RESET **********************************/ |
|
781 | + |
|
782 | + |
|
783 | + /** |
|
784 | + * callback hooked into 'AHEE__EE_Session__reset_checkout__before_reset' |
|
785 | + * |
|
786 | + * @param EE_Session $session |
|
787 | + * @return void |
|
788 | + * @throws EE_Error |
|
789 | + * @throws InvalidSessionDataException |
|
790 | + */ |
|
791 | + public static function session_checkout_reset(EE_Session $session) |
|
792 | + { |
|
793 | + // don't release tickets if cart was already reset |
|
794 | + if (did_action('AHEE__EE_Session__reset_cart__before_reset')) { |
|
795 | + return; |
|
796 | + } |
|
797 | + $checkout = $session->checkout(); |
|
798 | + if ($checkout instanceof EE_Checkout) { |
|
799 | + EED_Ticket_Sales_Monitor::instance()->_session_checkout_reset($checkout); |
|
800 | + } |
|
801 | + } |
|
802 | + |
|
803 | + |
|
804 | + /** |
|
805 | + * releases reserved tickets for the EE_Checkout->transaction |
|
806 | + * |
|
807 | + * @param EE_Checkout $checkout |
|
808 | + * @return void |
|
809 | + * @throws EE_Error |
|
810 | + * @throws InvalidSessionDataException |
|
811 | + */ |
|
812 | + protected function _session_checkout_reset(EE_Checkout $checkout) |
|
813 | + { |
|
814 | + // self::debug hardcoded to false |
|
815 | + if (self::debug) { |
|
816 | + echo self::$nl . self::$nl . __LINE__ . ') ' . __METHOD__ . '() '; |
|
817 | + } |
|
818 | + // we want to release the each registration's reserved tickets if the session was cleared, but not if this is a revisit |
|
819 | + if ($checkout->revisit || ! $checkout->transaction instanceof EE_Transaction) { |
|
820 | + return; |
|
821 | + } |
|
822 | + $this->_release_all_reserved_tickets_for_transaction($checkout->transaction); |
|
823 | + } |
|
824 | + |
|
825 | + |
|
826 | + |
|
827 | + /********************************** SESSION_EXPIRED_RESET **********************************/ |
|
828 | + |
|
829 | + |
|
830 | + /** |
|
831 | + * @param EE_Session $session |
|
832 | + * @return void |
|
833 | + */ |
|
834 | + public static function session_expired_reset(EE_Session $session) |
|
835 | + { |
|
836 | + } |
|
837 | + |
|
838 | + |
|
839 | + |
|
840 | + /********************************** PROCESS_ABANDONED_TRANSACTIONS **********************************/ |
|
841 | + |
|
842 | + |
|
843 | + /** |
|
844 | + * releases reserved tickets for all registrations of an ABANDONED EE_Transaction |
|
845 | + * by default, will NOT release tickets for free transactions, or any that have received a payment |
|
846 | + * |
|
847 | + * @param EE_Transaction $transaction |
|
848 | + * @return void |
|
849 | + * @throws EE_Error |
|
850 | + * @throws InvalidSessionDataException |
|
851 | + */ |
|
852 | + public static function process_abandoned_transactions(EE_Transaction $transaction) |
|
853 | + { |
|
854 | + // is this TXN free or has any money been paid towards this TXN? If so, then leave it alone |
|
855 | + if ($transaction->is_free() || $transaction->paid() > 0) { |
|
856 | + // self::debug hardcoded to false |
|
857 | + if (self::debug) { |
|
858 | + // DEBUG LOG |
|
859 | + EEH_Debug_Tools::log( |
|
860 | + __CLASS__, |
|
861 | + __FUNCTION__, |
|
862 | + __LINE__, |
|
863 | + array($transaction), |
|
864 | + false, |
|
865 | + 'EE_Transaction: ' . $transaction->ID() |
|
866 | + ); |
|
867 | + } |
|
868 | + return; |
|
869 | + } |
|
870 | + // have their been any successful payments made ? |
|
871 | + $payments = $transaction->payments(); |
|
872 | + foreach ($payments as $payment) { |
|
873 | + if ($payment instanceof EE_Payment && $payment->status() === EEM_Payment::status_id_approved) { |
|
874 | + if (self::debug) { |
|
875 | + // DEBUG LOG |
|
876 | + EEH_Debug_Tools::log( |
|
877 | + __CLASS__, |
|
878 | + __FUNCTION__, |
|
879 | + __LINE__, |
|
880 | + array($payment), |
|
881 | + false, |
|
882 | + 'EE_Transaction: ' . $transaction->ID() |
|
883 | + ); |
|
884 | + } |
|
885 | + return; |
|
886 | + } |
|
887 | + } |
|
888 | + // since you haven't even attempted to pay for your ticket... |
|
889 | + EED_Ticket_Sales_Monitor::instance()->_release_all_reserved_tickets_for_transaction($transaction); |
|
890 | + } |
|
891 | + |
|
892 | + |
|
893 | + |
|
894 | + /********************************** PROCESS_FAILED_TRANSACTIONS **********************************/ |
|
895 | + |
|
896 | + |
|
897 | + /** |
|
898 | + * releases reserved tickets for absolutely ALL registrations of a FAILED EE_Transaction |
|
899 | + * |
|
900 | + * @param EE_Transaction $transaction |
|
901 | + * @return void |
|
902 | + * @throws EE_Error |
|
903 | + * @throws InvalidSessionDataException |
|
904 | + */ |
|
905 | + public static function process_failed_transactions(EE_Transaction $transaction) |
|
906 | + { |
|
907 | + // since you haven't even attempted to pay for your ticket... |
|
908 | + EED_Ticket_Sales_Monitor::instance()->_release_all_reserved_tickets_for_transaction($transaction); |
|
909 | + } |
|
910 | + |
|
911 | + |
|
912 | + |
|
913 | + /********************************** RESET RESERVATION COUNTS *********************************/ |
|
914 | + |
|
915 | + |
|
916 | + /** |
|
917 | + * Resets the ticket and datetime reserved counts. |
|
918 | + * |
|
919 | + * For all the tickets with reservations, recalculates what their actual reserved counts should be based |
|
920 | + * on the valid transactions. |
|
921 | + * |
|
922 | + * @return int number of tickets whose reservations were released. |
|
923 | + * @throws EE_Error |
|
924 | + * @throws DomainException |
|
925 | + * @throws InvalidDataTypeException |
|
926 | + * @throws InvalidInterfaceException |
|
927 | + * @throws InvalidArgumentException |
|
928 | + * @throws UnexpectedEntityException |
|
929 | + * @throws ReflectionException |
|
930 | + */ |
|
931 | + public static function reset_reservation_counts() |
|
932 | + { |
|
933 | + /** @var EE_Line_Item[] $valid_reserved_tickets */ |
|
934 | + $valid_reserved_tickets = array(); |
|
935 | + /** @var EE_Transaction[] $transactions_in_progress */ |
|
936 | + $transactions_in_progress = EEM_Transaction::instance()->get_transactions_in_progress(); |
|
937 | + foreach ($transactions_in_progress as $transaction) { |
|
938 | + // if this TXN has been fully completed, then skip it |
|
939 | + if ($transaction->reg_step_completed('finalize_registration')) { |
|
940 | + continue; |
|
941 | + } |
|
942 | + $total_line_item = $transaction->total_line_item(); |
|
943 | + // $transaction_in_progress->line |
|
944 | + if (! $total_line_item instanceof EE_Line_Item) { |
|
945 | + throw new DomainException( |
|
946 | + esc_html__( |
|
947 | + 'Transaction does not have a valid Total Line Item associated with it.', |
|
948 | + 'event_espresso' |
|
949 | + ) |
|
950 | + ); |
|
951 | + } |
|
952 | + $valid_reserved_tickets += EED_Ticket_Sales_Monitor::get_ticket_line_items_for_grand_total( |
|
953 | + $total_line_item |
|
954 | + ); |
|
955 | + } |
|
956 | + $total_line_items = EEM_Line_Item::instance()->get_total_line_items_for_active_carts(); |
|
957 | + foreach ($total_line_items as $total_line_item) { |
|
958 | + $valid_reserved_tickets += EED_Ticket_Sales_Monitor::get_ticket_line_items_for_grand_total( |
|
959 | + $total_line_item |
|
960 | + ); |
|
961 | + } |
|
962 | + $tickets_with_reservations = EEM_Ticket::instance()->get_tickets_with_reservations(); |
|
963 | + return EED_Ticket_Sales_Monitor::release_reservations_for_tickets( |
|
964 | + $tickets_with_reservations, |
|
965 | + $valid_reserved_tickets, |
|
966 | + __FUNCTION__ |
|
967 | + ); |
|
968 | + } |
|
969 | + |
|
970 | + |
|
971 | + /** |
|
972 | + * @param EE_Line_Item $total_line_item |
|
973 | + * @return EE_Line_Item[] |
|
974 | + */ |
|
975 | + private static function get_ticket_line_items_for_grand_total(EE_Line_Item $total_line_item) |
|
976 | + { |
|
977 | + /** @var EE_Line_Item[] $valid_reserved_tickets */ |
|
978 | + $valid_reserved_tickets = array(); |
|
979 | + $ticket_line_items = EEH_Line_Item::get_ticket_line_items($total_line_item); |
|
980 | + foreach ($ticket_line_items as $ticket_line_item) { |
|
981 | + if ($ticket_line_item instanceof EE_Line_Item) { |
|
982 | + $valid_reserved_tickets[ $ticket_line_item->ID() ] = $ticket_line_item; |
|
983 | + } |
|
984 | + } |
|
985 | + return $valid_reserved_tickets; |
|
986 | + } |
|
987 | + |
|
988 | + |
|
989 | + /** |
|
990 | + * Releases ticket and datetime reservations (ie, reduces the number of reserved spots on them). |
|
991 | + * |
|
992 | + * Given the list of tickets which have reserved spots on them, uses the complete list of line items for tickets |
|
993 | + * whose transactions aren't complete and also aren't yet expired (ie, they're incomplete and younger than the |
|
994 | + * session's expiry time) to update the ticket (and their datetimes') reserved counts. |
|
995 | + * |
|
996 | + * @param EE_Ticket[] $tickets_with_reservations all tickets with TKT_reserved > 0 |
|
997 | + * @param EE_Line_Item[] $valid_reserved_ticket_line_items all line items for tickets and incomplete transactions |
|
998 | + * whose session has NOT expired. We will use these to determine the number of ticket |
|
999 | + * reservations are now invalid. We don't use the list of invalid ticket line items because |
|
1000 | + * we don't know which of those have already been taken into account when reducing ticket |
|
1001 | + * reservation counts, and which haven't. |
|
1002 | + * @return int |
|
1003 | + * @throws UnexpectedEntityException |
|
1004 | + * @throws DomainException |
|
1005 | + * @throws EE_Error |
|
1006 | + */ |
|
1007 | + protected static function release_reservations_for_tickets( |
|
1008 | + array $tickets_with_reservations, |
|
1009 | + array $valid_reserved_ticket_line_items = array(), |
|
1010 | + $source |
|
1011 | + ) { |
|
1012 | + $total_tickets_released = 0; |
|
1013 | + $sold_out_events = array(); |
|
1014 | + foreach ($tickets_with_reservations as $ticket_with_reservations) { |
|
1015 | + if (! $ticket_with_reservations instanceof EE_Ticket) { |
|
1016 | + continue; |
|
1017 | + } |
|
1018 | + // The $valid_reserved_ticket_line_items tells us what the reserved count on their tickets (and datetimes) |
|
1019 | + // SHOULD be. Instead of just directly updating the list, we're going to use EE_Ticket::decreaseReserved() |
|
1020 | + // to try to avoid race conditions, so instead of just finding the number to update TO, we're going to find |
|
1021 | + // the number to RELEASE. It's the same end result, just different path. |
|
1022 | + // Begin by assuming we're going to release all the reservations on this ticket. |
|
1023 | + $expired_reservations_count = $ticket_with_reservations->reserved(); |
|
1024 | + // Now reduce that number using the list of current valid reservations. |
|
1025 | + foreach ($valid_reserved_ticket_line_items as $valid_reserved_ticket_line_item) { |
|
1026 | + if ( |
|
1027 | + $valid_reserved_ticket_line_item instanceof EE_Line_Item |
|
1028 | + && $valid_reserved_ticket_line_item->OBJ_ID() === $ticket_with_reservations->ID() |
|
1029 | + ) { |
|
1030 | + $expired_reservations_count -= $valid_reserved_ticket_line_item->quantity(); |
|
1031 | + } |
|
1032 | + } |
|
1033 | + // Only bother saving the tickets and datetimes if we're actually going to release some spots. |
|
1034 | + if ($expired_reservations_count > 0) { |
|
1035 | + $ticket_with_reservations->add_extra_meta( |
|
1036 | + EE_Ticket::META_KEY_TICKET_RESERVATIONS, |
|
1037 | + __LINE__ . ') ' . $source . '()' |
|
1038 | + ); |
|
1039 | + $ticket_with_reservations->decreaseReserved($expired_reservations_count, true, 'TicketSalesMonitor:' . __LINE__); |
|
1040 | + $total_tickets_released += $expired_reservations_count; |
|
1041 | + $event = $ticket_with_reservations->get_related_event(); |
|
1042 | + // track sold out events |
|
1043 | + if ($event instanceof EE_Event && $event->is_sold_out()) { |
|
1044 | + $sold_out_events[] = $event; |
|
1045 | + } |
|
1046 | + } |
|
1047 | + } |
|
1048 | + // Double check whether sold out events should remain sold out after releasing tickets |
|
1049 | + if ($sold_out_events !== array()) { |
|
1050 | + foreach ($sold_out_events as $sold_out_event) { |
|
1051 | + /** @var EE_Event $sold_out_event */ |
|
1052 | + $sold_out_event->perform_sold_out_status_check(); |
|
1053 | + } |
|
1054 | + } |
|
1055 | + return $total_tickets_released; |
|
1056 | + } |
|
1057 | + |
|
1058 | + |
|
1059 | + |
|
1060 | + /********************************** SHUTDOWN **********************************/ |
|
1061 | + |
|
1062 | + |
|
1063 | + /** |
|
1064 | + * @param int $timestamp |
|
1065 | + * @return false|int |
|
1066 | + * @throws EE_Error |
|
1067 | + * @throws InvalidArgumentException |
|
1068 | + * @throws InvalidDataTypeException |
|
1069 | + * @throws InvalidInterfaceException |
|
1070 | + */ |
|
1071 | + public static function clear_expired_line_items_with_no_transaction($timestamp = 0) |
|
1072 | + { |
|
1073 | + /** @type WPDB $wpdb */ |
|
1074 | + global $wpdb; |
|
1075 | + if (! absint($timestamp)) { |
|
1076 | + /** @var EventEspresso\core\domain\values\session\SessionLifespan $session_lifespan */ |
|
1077 | + $session_lifespan = LoaderFactory::getLoader()->getShared( |
|
1078 | + 'EventEspresso\core\domain\values\session\SessionLifespan' |
|
1079 | + ); |
|
1080 | + $timestamp = $session_lifespan->expiration(); |
|
1081 | + } |
|
1082 | + return $wpdb->query( |
|
1083 | + $wpdb->prepare( |
|
1084 | + 'DELETE FROM ' . EEM_Line_Item::instance()->table() . ' |
|
1085 | 1085 | WHERE TXN_ID = 0 AND LIN_timestamp <= %s', |
1086 | - // use GMT time because that's what LIN_timestamps are in |
|
1087 | - date('Y-m-d H:i:s', $timestamp) |
|
1088 | - ) |
|
1089 | - ); |
|
1090 | - } |
|
1086 | + // use GMT time because that's what LIN_timestamps are in |
|
1087 | + date('Y-m-d H:i:s', $timestamp) |
|
1088 | + ) |
|
1089 | + ); |
|
1090 | + } |
|
1091 | 1091 | } |
@@ -21,7 +21,7 @@ discard block |
||
21 | 21 | $event_name = ''; |
22 | 22 | $wait_list = false; |
23 | 23 | foreach ($registrations as $registration) { |
24 | - if (! $registration instanceof EE_Registration) { |
|
24 | + if ( ! $registration instanceof EE_Registration) { |
|
25 | 25 | continue; |
26 | 26 | } |
27 | 27 | if ($event_name != $registration->event_name() && ! empty($event_name)) { ?> |
@@ -55,7 +55,7 @@ discard block |
||
55 | 55 | <tbody> |
56 | 56 | <?php |
57 | 57 | } |
58 | - if ($is_primary || (! $is_primary && $reg_url_link == $registration->reg_url_link())) { ?> |
|
58 | + if ($is_primary || ( ! $is_primary && $reg_url_link == $registration->reg_url_link())) { ?> |
|
59 | 59 | <tr> |
60 | 60 | <td width="40%"> |
61 | 61 | <?php |
@@ -14,24 +14,24 @@ discard block |
||
14 | 14 | |
15 | 15 | <div class="ee-registration-details-dv"> |
16 | 16 | <?php |
17 | - $registrations = $transaction->registrations(); |
|
18 | - $registrations = is_array($registrations) ? $registrations : []; |
|
19 | - $reg_count = count($registrations); |
|
20 | - $reg_cntr = 0; |
|
21 | - $event_name = ''; |
|
22 | - $wait_list = false; |
|
23 | - foreach ($registrations as $registration) { |
|
24 | - if (! $registration instanceof EE_Registration) { |
|
25 | - continue; |
|
26 | - } |
|
27 | - if ($event_name != $registration->event_name() && ! empty($event_name)) { ?> |
|
17 | + $registrations = $transaction->registrations(); |
|
18 | + $registrations = is_array($registrations) ? $registrations : []; |
|
19 | + $reg_count = count($registrations); |
|
20 | + $reg_cntr = 0; |
|
21 | + $event_name = ''; |
|
22 | + $wait_list = false; |
|
23 | + foreach ($registrations as $registration) { |
|
24 | + if (! $registration instanceof EE_Registration) { |
|
25 | + continue; |
|
26 | + } |
|
27 | + if ($event_name != $registration->event_name() && ! empty($event_name)) { ?> |
|
28 | 28 | </tbody> |
29 | 29 | </table> |
30 | 30 | <?php |
31 | - } |
|
32 | - $reg_cntr++; |
|
33 | - if ($event_name != $registration->event_name()) { |
|
34 | - ?> |
|
31 | + } |
|
32 | + $reg_cntr++; |
|
33 | + if ($event_name != $registration->event_name()) { |
|
34 | + ?> |
|
35 | 35 | <h5> |
36 | 36 | <span class="smaller-text grey-text"> |
37 | 37 | <?php esc_html_e('for', 'event_espresso'); ?> : |
@@ -54,23 +54,23 @@ discard block |
||
54 | 54 | </thead> |
55 | 55 | <tbody> |
56 | 56 | <?php |
57 | - } |
|
58 | - if ($is_primary || (! $is_primary && $reg_url_link == $registration->reg_url_link())) { ?> |
|
57 | + } |
|
58 | + if ($is_primary || (! $is_primary && $reg_url_link == $registration->reg_url_link())) { ?> |
|
59 | 59 | <tr> |
60 | 60 | <td width="40%"> |
61 | 61 | <?php |
62 | - if ($registration->attendee() instanceof EE_Attendee) { |
|
63 | - echo esc_html($registration->attendee()->full_name(true)); |
|
64 | - } |
|
65 | - ?> |
|
62 | + if ($registration->attendee() instanceof EE_Attendee) { |
|
63 | + echo esc_html($registration->attendee()->full_name(true)); |
|
64 | + } |
|
65 | + ?> |
|
66 | 66 | <p class="tiny-text" style="margin: .75em 0 0;"> |
67 | 67 | <?php if ($registration->count_question_groups()) { ?> |
68 | 68 | <a class="ee-icon-only-lnk" |
69 | 69 | href="<?php echo esc_url_raw($registration->edit_attendee_information_url()); ?>" |
70 | 70 | title="<?php esc_attr_e( |
71 | - 'Click here to edit Attendee Information', |
|
72 | - 'event_espresso' |
|
73 | - ); ?>" |
|
71 | + 'Click here to edit Attendee Information', |
|
72 | + 'event_espresso' |
|
73 | + ); ?>" |
|
74 | 74 | > |
75 | 75 | <span class="dashicons dashicons-groups"></span> |
76 | 76 | <?php esc_html_e('edit info', 'event_espresso'); ?> |
@@ -78,15 +78,15 @@ discard block |
||
78 | 78 | <?php } ?> |
79 | 79 | <a class="ee-resend-reg-confirmation-email ee-icon-only-lnk" |
80 | 80 | href="<?php echo esc_url_raw( |
81 | - add_query_arg( |
|
82 | - ['token' => $registration->reg_url_link(), 'resend_reg_confirmation' => 'true'], |
|
83 | - EE_Registry::instance()->CFG->core->thank_you_page_url() |
|
84 | - ) |
|
85 | - ); ?>" |
|
81 | + add_query_arg( |
|
82 | + ['token' => $registration->reg_url_link(), 'resend_reg_confirmation' => 'true'], |
|
83 | + EE_Registry::instance()->CFG->core->thank_you_page_url() |
|
84 | + ) |
|
85 | + ); ?>" |
|
86 | 86 | title="<?php esc_attr_e( |
87 | - 'Click here to resend the Registration Confirmation email', |
|
88 | - 'event_espresso' |
|
89 | - ); ?>" |
|
87 | + 'Click here to resend the Registration Confirmation email', |
|
88 | + 'event_espresso' |
|
89 | + ); ?>" |
|
90 | 90 | rel="<?php echo esc_attr($registration->reg_url_link()); ?>" |
91 | 91 | > |
92 | 92 | <span class="dashicons dashicons-email-alt"></span> |
@@ -100,27 +100,27 @@ discard block |
||
100 | 100 | <td width="35%" class="jst-left"> |
101 | 101 | <?php $registration->e_pretty_status(true) ?> |
102 | 102 | <?php |
103 | - if ($registration->status_ID() === EEM_Registration::status_id_wait_list) { |
|
104 | - $wait_list = true; |
|
105 | - } |
|
106 | - ?> |
|
103 | + if ($registration->status_ID() === EEM_Registration::status_id_wait_list) { |
|
104 | + $wait_list = true; |
|
105 | + } |
|
106 | + ?> |
|
107 | 107 | </td> |
108 | 108 | </tr> |
109 | 109 | <?php do_action( |
110 | - 'AHEE__thank_you_page_registration_details_template__after_registration_table_row', |
|
111 | - $registration |
|
112 | - ); ?> |
|
110 | + 'AHEE__thank_you_page_registration_details_template__after_registration_table_row', |
|
111 | + $registration |
|
112 | + ); ?> |
|
113 | 113 | <?php |
114 | - $event_name = $registration->event_name(); |
|
115 | - } |
|
116 | - if ($reg_cntr >= $reg_count) { |
|
117 | - ?> |
|
114 | + $event_name = $registration->event_name(); |
|
115 | + } |
|
116 | + if ($reg_cntr >= $reg_count) { |
|
117 | + ?> |
|
118 | 118 | </tbody> |
119 | 119 | </table> |
120 | 120 | <?php |
121 | - } |
|
122 | - } |
|
123 | - ?> |
|
121 | + } |
|
122 | + } |
|
123 | + ?> |
|
124 | 124 | <?php if ($is_primary && $SPCO_attendee_information_url) { ?> |
125 | 125 | <p class="small-text jst-rght"> |
126 | 126 | <a href='<?php echo esc_url_raw($SPCO_attendee_information_url) ?>'> |
@@ -129,22 +129,22 @@ discard block |
||
129 | 129 | </p> |
130 | 130 | <?php } ?> |
131 | 131 | <?php |
132 | - if ($wait_list) { |
|
133 | - echo apply_filters( |
|
134 | - 'AFEE__thank_you_page_registration_details_template__wait_list_notice', |
|
135 | - sprintf( |
|
136 | - esc_html__( |
|
137 | - '%1$sre: Wait List Registrations%2$sPlease note that the total cost listed below in the Transaction Details is for ALL registrations, including those that are on the wait list, even though they can not be currently paid for. If any spaces become available however, you may be notified by the Event admin and have the opportunity to secure the remaining tickets by making a payment for them.%3$s', |
|
138 | - 'event_espresso' |
|
139 | - ), |
|
140 | - '<h6 class="" style="margin-bottom:.25em;"><span class="dashicons dashicons-clipboard ee-icon-size-16 purple-text"></span>', |
|
141 | - '</h6 ><p class="ee-wait-list-notice">', |
|
142 | - '</p ><br />' |
|
143 | - ) |
|
144 | - ); |
|
145 | - } |
|
146 | - do_action('AHEE__thank_you_page_registration_details_template__after_registration_details'); |
|
147 | - ?> |
|
132 | + if ($wait_list) { |
|
133 | + echo apply_filters( |
|
134 | + 'AFEE__thank_you_page_registration_details_template__wait_list_notice', |
|
135 | + sprintf( |
|
136 | + esc_html__( |
|
137 | + '%1$sre: Wait List Registrations%2$sPlease note that the total cost listed below in the Transaction Details is for ALL registrations, including those that are on the wait list, even though they can not be currently paid for. If any spaces become available however, you may be notified by the Event admin and have the opportunity to secure the remaining tickets by making a payment for them.%3$s', |
|
138 | + 'event_espresso' |
|
139 | + ), |
|
140 | + '<h6 class="" style="margin-bottom:.25em;"><span class="dashicons dashicons-clipboard ee-icon-size-16 purple-text"></span>', |
|
141 | + '</h6 ><p class="ee-wait-list-notice">', |
|
142 | + '</p ><br />' |
|
143 | + ) |
|
144 | + ); |
|
145 | + } |
|
146 | + do_action('AHEE__thank_you_page_registration_details_template__after_registration_details'); |
|
147 | + ?> |
|
148 | 148 | |
149 | 149 | </div> |
150 | 150 | <!-- end of .registration-details --> |
@@ -28,8 +28,8 @@ discard block |
||
28 | 28 | <label><?php esc_html_e('Amount Owing: ', 'event_espresso'); ?></label> |
29 | 29 | </td> |
30 | 30 | <td class="<?php echo ($transaction->paid() == $transaction->total()) |
31 | - ? 'ee-transaction-paid' |
|
32 | - : 'ee-transaction-unpaid' ?>"> |
|
31 | + ? 'ee-transaction-paid' |
|
32 | + : 'ee-transaction-unpaid' ?>"> |
|
33 | 33 | <?php echo EEH_Template::format_currency($transaction->remaining()); // already escaped ?> |
34 | 34 | </td> |
35 | 35 | </tr> |
@@ -39,7 +39,7 @@ discard block |
||
39 | 39 | </td> |
40 | 40 | <td> |
41 | 41 | <?php $transaction->e_pretty_status(true); |
42 | - if ($show_try_pay_again_link && ! $transaction->is_completed()) { ?> |
|
42 | + if ($show_try_pay_again_link && ! $transaction->is_completed()) { ?> |
|
43 | 43 | <span class="small-text"> |
44 | 44 | <a href='<?php echo esc_url_raw($SPCO_payment_options_url) ?>'> |
45 | 45 | <?php esc_html_e('View Payment Options', 'event_espresso'); ?> |
@@ -57,9 +57,9 @@ discard block |
||
57 | 57 | </td> |
58 | 58 | </tr> |
59 | 59 | <?php do_action( |
60 | - 'AHEE__thank_you_page_transaction_details_template__after_transaction_table_row', |
|
61 | - $transaction |
|
62 | - ); ?> |
|
60 | + 'AHEE__thank_you_page_transaction_details_template__after_transaction_table_row', |
|
61 | + $transaction |
|
62 | + ); ?> |
|
63 | 63 | </tbody> |
64 | 64 | </table> |
65 | 65 |
@@ -129,8 +129,8 @@ discard block |
||
129 | 129 | */ |
130 | 130 | public static function set_definitions() |
131 | 131 | { |
132 | - define('THANK_YOU_ASSETS_URL', plugin_dir_url(__FILE__) . 'assets/'); |
|
133 | - define('THANK_YOU_TEMPLATES_PATH', str_replace('\\', '/', plugin_dir_path(__FILE__)) . 'templates/'); |
|
132 | + define('THANK_YOU_ASSETS_URL', plugin_dir_url(__FILE__).'assets/'); |
|
133 | + define('THANK_YOU_TEMPLATES_PATH', str_replace('\\', '/', plugin_dir_path(__FILE__)).'templates/'); |
|
134 | 134 | } |
135 | 135 | |
136 | 136 | |
@@ -147,7 +147,7 @@ discard block |
||
147 | 147 | return $this->_current_txn; |
148 | 148 | } |
149 | 149 | $TXN_model = EE_Registry::instance()->load_model('Transaction'); |
150 | - if (! $TXN_model instanceof EEM_Transaction) { |
|
150 | + if ( ! $TXN_model instanceof EEM_Transaction) { |
|
151 | 151 | EE_Error::add_error( |
152 | 152 | esc_html__('The transaction model could not be established.', 'event_espresso'), |
153 | 153 | __FILE__, |
@@ -185,7 +185,7 @@ discard block |
||
185 | 185 | */ |
186 | 186 | public function get_txn_payments($since = 0) |
187 | 187 | { |
188 | - if (! $this->get_txn()) { |
|
188 | + if ( ! $this->get_txn()) { |
|
189 | 189 | return []; |
190 | 190 | } |
191 | 191 | $args = array('order_by' => array('PAY_timestamp' => 'ASC')); |
@@ -327,7 +327,7 @@ discard block |
||
327 | 327 | { |
328 | 328 | wp_register_script( |
329 | 329 | 'thank_you_page', |
330 | - THANK_YOU_ASSETS_URL . 'thank_you_page.js', |
|
330 | + THANK_YOU_ASSETS_URL.'thank_you_page.js', |
|
331 | 331 | array('espresso_core', 'heartbeat'), |
332 | 332 | EVENT_ESPRESSO_VERSION, |
333 | 333 | true |
@@ -347,9 +347,9 @@ discard block |
||
347 | 347 | public function init() |
348 | 348 | { |
349 | 349 | $this->_get_reg_url_link(); |
350 | - if (! $this->get_txn()) { |
|
350 | + if ( ! $this->get_txn()) { |
|
351 | 351 | echo EEH_HTML::div( |
352 | - EEH_HTML::h4(esc_html__('We\'re sorry...', 'event_espresso')) . |
|
352 | + EEH_HTML::h4(esc_html__('We\'re sorry...', 'event_espresso')). |
|
353 | 353 | sprintf( |
354 | 354 | esc_html__( |
355 | 355 | 'This is a system page for displaying transaction information after a purchase.%1$sYou are most likely seeing this notice because you have navigated to this page%1$sthrough some means other than completing a transaction.%1$sSorry for the disappointment, but you will most likely find nothing of interest here.%1$s%1$s', |
@@ -440,12 +440,12 @@ discard block |
||
440 | 440 | public function thank_you_page_results() |
441 | 441 | { |
442 | 442 | $this->init(); |
443 | - if (! $this->_current_txn instanceof EE_Transaction) { |
|
443 | + if ( ! $this->_current_txn instanceof EE_Transaction) { |
|
444 | 444 | return EE_Error::get_notices(); |
445 | 445 | } |
446 | 446 | // link to receipt |
447 | 447 | $template_args['TXN_receipt_url'] = $this->_current_txn->receipt_url(); |
448 | - if (! empty($template_args['TXN_receipt_url'])) { |
|
448 | + if ( ! empty($template_args['TXN_receipt_url'])) { |
|
449 | 449 | $template_args['order_conf_desc'] = esc_html__( |
450 | 450 | '%1$sCongratulations%2$sYour registration has been successfully processed.%3$sCheck your email for your registration confirmation or click the button below to view / download / print a full description of your purchases and registration information.', |
451 | 451 | 'event_espresso' |
@@ -463,7 +463,7 @@ discard block |
||
463 | 463 | add_action('AHEE__thank_you_page_overview_template__content', array($this, 'get_ajax_content')); |
464 | 464 | } |
465 | 465 | return EEH_Template::locate_template( |
466 | - THANK_YOU_TEMPLATES_PATH . 'thank-you-page-overview.template.php', |
|
466 | + THANK_YOU_TEMPLATES_PATH.'thank-you-page-overview.template.php', |
|
467 | 467 | $template_args |
468 | 468 | ); |
469 | 469 | } |
@@ -513,7 +513,7 @@ discard block |
||
513 | 513 | '$SPCO_attendee_information_url' |
514 | 514 | ); |
515 | 515 | echo EEH_Template::locate_template( |
516 | - THANK_YOU_TEMPLATES_PATH . 'thank-you-page-registration-details.template.php', |
|
516 | + THANK_YOU_TEMPLATES_PATH.'thank-you-page-registration-details.template.php', |
|
517 | 517 | $template_args |
518 | 518 | ); |
519 | 519 | } |
@@ -585,7 +585,7 @@ discard block |
||
585 | 585 | */ |
586 | 586 | public function get_ajax_content() |
587 | 587 | { |
588 | - if (! $this->get_txn()) { |
|
588 | + if ( ! $this->get_txn()) { |
|
589 | 589 | return; |
590 | 590 | } |
591 | 591 | // first determine which event(s) require pre-approval or not |
@@ -596,9 +596,9 @@ discard block |
||
596 | 596 | $event = $registration->event(); |
597 | 597 | if ($event instanceof EE_Event) { |
598 | 598 | if ($registration->is_not_approved() && $registration->event() instanceof EE_Event) { |
599 | - $events_requiring_pre_approval[ $event->ID() ] = $event; |
|
599 | + $events_requiring_pre_approval[$event->ID()] = $event; |
|
600 | 600 | } else { |
601 | - $events[ $event->ID() ] = $event; |
|
601 | + $events[$event->ID()] = $event; |
|
602 | 602 | } |
603 | 603 | } |
604 | 604 | } |
@@ -616,7 +616,7 @@ discard block |
||
616 | 616 | */ |
617 | 617 | public function display_details_for_events($events = array()) |
618 | 618 | { |
619 | - if (! empty($events)) { |
|
619 | + if ( ! empty($events)) { |
|
620 | 620 | ?> |
621 | 621 | <div id="espresso-thank-you-page-ajax-content-dv"> |
622 | 622 | <div id="espresso-thank-you-page-ajax-transaction-dv"></div> |
@@ -629,7 +629,7 @@ discard block |
||
629 | 629 | 'event_espresso' |
630 | 630 | ); ?></span> |
631 | 631 | </div> |
632 | - <?php if (! $this->_is_offline_payment_method && ! $this->_payments_closed) : ?> |
|
632 | + <?php if ( ! $this->_is_offline_payment_method && ! $this->_payments_closed) : ?> |
|
633 | 633 | <p id="ee-ajax-loading-pg" class="highlight-bg small-text clear"> |
634 | 634 | <?php echo apply_filters( |
635 | 635 | 'EED_Thank_You_Page__get_ajax_content__waiting_for_IPN_msg', |
@@ -662,7 +662,7 @@ discard block |
||
662 | 662 | */ |
663 | 663 | public function display_details_for_events_requiring_pre_approval($events = array()) |
664 | 664 | { |
665 | - if (! empty($events)) { |
|
665 | + if ( ! empty($events)) { |
|
666 | 666 | ?> |
667 | 667 | <div id="espresso-thank-you-page-not-approved-message-dv"> |
668 | 668 | <h4 class="orange-text"><?php esc_html_e('Important Notice:', 'event_espresso'); ?></h4> |
@@ -719,7 +719,7 @@ discard block |
||
719 | 719 | '$SPCO_payment_options_url' |
720 | 720 | ); |
721 | 721 | return EEH_Template::locate_template( |
722 | - THANK_YOU_TEMPLATES_PATH . 'thank-you-page-transaction-details.template.php', |
|
722 | + THANK_YOU_TEMPLATES_PATH.'thank-you-page-transaction-details.template.php', |
|
723 | 723 | $template_args |
724 | 724 | ); |
725 | 725 | } |
@@ -735,7 +735,7 @@ discard block |
||
735 | 735 | public function get_payment_row_html(EE_Payment $payment = null) |
736 | 736 | { |
737 | 737 | $html = ''; |
738 | - if (! $payment instanceof EE_Payment) { |
|
738 | + if ( ! $payment instanceof EE_Payment) { |
|
739 | 739 | return ''; |
740 | 740 | } |
741 | 741 | if ( |
@@ -749,25 +749,25 @@ discard block |
||
749 | 749 | $payment->set_status(EEM_Payment::status_id_pending); |
750 | 750 | } |
751 | 751 | $payment_declined_msg = $payment->STS_ID() === EEM_Payment::status_id_declined |
752 | - ? '<br /><span class="small-text">' . esc_html($payment->gateway_response()) . '</span>' |
|
752 | + ? '<br /><span class="small-text">'.esc_html($payment->gateway_response()).'</span>' |
|
753 | 753 | : ''; |
754 | 754 | $html .= ' |
755 | 755 | <tr> |
756 | 756 | <td> |
757 | - ' . esc_html($payment->timestamp()) . ' |
|
757 | + ' . esc_html($payment->timestamp()).' |
|
758 | 758 | </td> |
759 | 759 | <td> |
760 | 760 | ' . ( |
761 | 761 | $payment->payment_method() instanceof EE_Payment_Method |
762 | 762 | ? esc_html($payment->payment_method()->name()) |
763 | 763 | : esc_html__('Unknown', 'event_espresso') |
764 | - ) . ' |
|
764 | + ).' |
|
765 | 765 | </td> |
766 | 766 | <td class="jst-rght"> |
767 | - ' . EEH_Template::format_currency($payment->amount()) . ' |
|
767 | + ' . EEH_Template::format_currency($payment->amount()).' |
|
768 | 768 | </td> |
769 | 769 | <td class="jst-rght" style="line-height:1;"> |
770 | - ' . $payment->pretty_status(true) . $payment_declined_msg . ' |
|
770 | + ' . $payment->pretty_status(true).$payment_declined_msg.' |
|
771 | 771 | </td> |
772 | 772 | </tr>'; |
773 | 773 | do_action('AHEE__thank_you_page_payment_details_template__after_each_payment', $payment); |
@@ -825,7 +825,7 @@ discard block |
||
825 | 825 | '$SPCO_payment_options_url' |
826 | 826 | ); |
827 | 827 | return EEH_Template::locate_template( |
828 | - THANK_YOU_TEMPLATES_PATH . 'thank-you-page-payment-details.template.php', |
|
828 | + THANK_YOU_TEMPLATES_PATH.'thank-you-page-payment-details.template.php', |
|
829 | 829 | $template_args |
830 | 830 | ); |
831 | 831 | } |
@@ -10,613 +10,613 @@ discard block |
||
10 | 10 | */ |
11 | 11 | class EED_Thank_You_Page extends EED_Module |
12 | 12 | { |
13 | - /** |
|
14 | - * time in seconds to wait for the IPN to arrive before telling the registrant to bugger off ( 1200s = 20 minutes ) |
|
15 | - */ |
|
16 | - const IPN_wait_time = 1200; |
|
17 | - |
|
18 | - /** |
|
19 | - * The transaction specified by the reg_url_link passed from the Request, or from the Session |
|
20 | - * |
|
21 | - * @var EE_Transaction $_current_txn |
|
22 | - */ |
|
23 | - private $_current_txn; |
|
24 | - |
|
25 | - /** |
|
26 | - * @var EE_Registration $_primary_registrant |
|
27 | - */ |
|
28 | - private $_primary_registrant; |
|
29 | - |
|
30 | - /** |
|
31 | - * The reg_url_link passed from the Request, or from the Session |
|
32 | - * |
|
33 | - * @var string $_reg_url_link |
|
34 | - */ |
|
35 | - private $_reg_url_link; |
|
36 | - |
|
37 | - /** |
|
38 | - * whether the incoming reg_url_link is for the primary registrant or not |
|
39 | - * |
|
40 | - * @var boolean $_is_primary |
|
41 | - */ |
|
42 | - private $_is_primary; |
|
43 | - |
|
44 | - /** |
|
45 | - * The URL for revisiting the SPCO attendee information step |
|
46 | - * |
|
47 | - * @var string $_SPCO_attendee_information_url |
|
48 | - */ |
|
49 | - private $_SPCO_attendee_information_url; |
|
50 | - |
|
51 | - /** |
|
52 | - * The URL for revisiting the SPCO payment options step |
|
53 | - * |
|
54 | - * @var string $_SPCO_payment_options_url |
|
55 | - */ |
|
56 | - private $_SPCO_payment_options_url; |
|
57 | - |
|
58 | - /** |
|
59 | - * whether to display the Payment Options link |
|
60 | - * |
|
61 | - * @var boolean $_show_try_pay_again_link |
|
62 | - */ |
|
63 | - private $_show_try_pay_again_link = false; |
|
64 | - |
|
65 | - /** |
|
66 | - * whether payments are allowed at this time |
|
67 | - * |
|
68 | - * @var boolean $_payments_closed |
|
69 | - */ |
|
70 | - private $_payments_closed = false; |
|
71 | - |
|
72 | - /** |
|
73 | - * whether the selected payment method is Bank, Check , Invoice, etc |
|
74 | - * |
|
75 | - * @var boolean $_is_offline_payment_method |
|
76 | - */ |
|
77 | - private $_is_offline_payment_method = true; |
|
78 | - |
|
79 | - |
|
80 | - /** |
|
81 | - * @return EED_Module|EED_Thank_You_Page |
|
82 | - * @throws EE_Error |
|
83 | - * @throws ReflectionException |
|
84 | - */ |
|
85 | - public static function instance() |
|
86 | - { |
|
87 | - return parent::get_instance(__CLASS__); |
|
88 | - } |
|
89 | - |
|
90 | - |
|
91 | - /** |
|
92 | - * set_hooks - for hooking into EE Core, modules, etc |
|
93 | - * |
|
94 | - * @return void |
|
95 | - */ |
|
96 | - public static function set_hooks() |
|
97 | - { |
|
98 | - add_action('wp_loaded', array('EED_Thank_You_Page', 'set_definitions'), 2); |
|
99 | - } |
|
100 | - |
|
101 | - |
|
102 | - /** |
|
103 | - * set_hooks_admin - for hooking into EE Admin Core, modules, etc |
|
104 | - * |
|
105 | - * @return void |
|
106 | - */ |
|
107 | - public static function set_hooks_admin() |
|
108 | - { |
|
109 | - add_action( |
|
110 | - 'wp_ajax_espresso_resend_reg_confirmation_email', |
|
111 | - array('EED_Thank_You_Page', 'resend_reg_confirmation_email'), |
|
112 | - 10, |
|
113 | - 2 |
|
114 | - ); |
|
115 | - add_action( |
|
116 | - 'wp_ajax_nopriv_espresso_resend_reg_confirmation_email', |
|
117 | - array('EED_Thank_You_Page', 'resend_reg_confirmation_email'), |
|
118 | - 10, |
|
119 | - 2 |
|
120 | - ); |
|
121 | - } |
|
122 | - |
|
123 | - |
|
124 | - /** |
|
125 | - * set_definitions |
|
126 | - * |
|
127 | - * @return void |
|
128 | - */ |
|
129 | - public static function set_definitions() |
|
130 | - { |
|
131 | - define('THANK_YOU_ASSETS_URL', plugin_dir_url(__FILE__) . 'assets/'); |
|
132 | - define('THANK_YOU_TEMPLATES_PATH', str_replace('\\', '/', plugin_dir_path(__FILE__)) . 'templates/'); |
|
133 | - } |
|
134 | - |
|
135 | - |
|
136 | - /** |
|
137 | - * get_txn |
|
138 | - * |
|
139 | - * @return EE_Transaction |
|
140 | - * @throws EE_Error |
|
141 | - * @throws ReflectionException |
|
142 | - */ |
|
143 | - public function get_txn() |
|
144 | - { |
|
145 | - if ($this->_current_txn instanceof EE_Transaction) { |
|
146 | - return $this->_current_txn; |
|
147 | - } |
|
148 | - $TXN_model = EE_Registry::instance()->load_model('Transaction'); |
|
149 | - if (! $TXN_model instanceof EEM_Transaction) { |
|
150 | - EE_Error::add_error( |
|
151 | - esc_html__('The transaction model could not be established.', 'event_espresso'), |
|
152 | - __FILE__, |
|
153 | - __FUNCTION__, |
|
154 | - __LINE__ |
|
155 | - ); |
|
156 | - return null; |
|
157 | - } |
|
158 | - // get the transaction. yes, we may have just loaded it, but it may have been updated, or this may be via an ajax request |
|
159 | - $this->_current_txn = $TXN_model->get_transaction_from_reg_url_link($this->_reg_url_link); |
|
160 | - // verify TXN |
|
161 | - if (WP_DEBUG && ! $this->_current_txn instanceof EE_Transaction) { |
|
162 | - EE_Error::add_error( |
|
163 | - esc_html__( |
|
164 | - 'No transaction information could be retrieved or the transaction data is not of the correct type.', |
|
165 | - 'event_espresso' |
|
166 | - ), |
|
167 | - __FILE__, |
|
168 | - __FUNCTION__, |
|
169 | - __LINE__ |
|
170 | - ); |
|
171 | - return null; |
|
172 | - } |
|
173 | - return $this->_current_txn; |
|
174 | - } |
|
175 | - |
|
176 | - |
|
177 | - /** |
|
178 | - * get_txn_payments |
|
179 | - * |
|
180 | - * @param int $since |
|
181 | - * @return EE_Payment[] |
|
182 | - * @throws EE_Error |
|
183 | - * @throws ReflectionException |
|
184 | - */ |
|
185 | - public function get_txn_payments($since = 0) |
|
186 | - { |
|
187 | - if (! $this->get_txn()) { |
|
188 | - return []; |
|
189 | - } |
|
190 | - $args = array('order_by' => array('PAY_timestamp' => 'ASC')); |
|
191 | - if ($since > 0) { |
|
192 | - $args[0] = array('PAY_timestamp' => array('>', $since)); |
|
193 | - } |
|
194 | - // get array of payments with most recent first |
|
195 | - return $this->_current_txn->payments($args); |
|
196 | - } |
|
197 | - |
|
198 | - |
|
199 | - /** |
|
200 | - * @return bool |
|
201 | - */ |
|
202 | - public function isOfflinePaymentMethod() |
|
203 | - { |
|
204 | - return $this->_is_offline_payment_method; |
|
205 | - } |
|
206 | - |
|
207 | - |
|
208 | - |
|
209 | - |
|
210 | - /** |
|
211 | - * get_reg_url_link |
|
212 | - * |
|
213 | - * @return void |
|
214 | - */ |
|
215 | - private function _get_reg_url_link() |
|
216 | - { |
|
217 | - if ($this->_reg_url_link) { |
|
218 | - return; |
|
219 | - } |
|
220 | - // check for reg_url_link |
|
221 | - $reg_url_link = self::getRequest()->getRequestParam('e_reg_url_link'); |
|
222 | - // only do thank you page stuff if we have a REG_url_link in the url |
|
223 | - if (WP_DEBUG && ! $reg_url_link) { |
|
224 | - EE_Error::add_error( |
|
225 | - esc_html__( |
|
226 | - 'No transaction information could be retrieved because the registration URL link is missing or invalid.', |
|
227 | - 'event_espresso' |
|
228 | - ), |
|
229 | - __FILE__, |
|
230 | - __FUNCTION__, |
|
231 | - __LINE__ |
|
232 | - ); |
|
233 | - } |
|
234 | - $this->set_reg_url_link($reg_url_link); |
|
235 | - } |
|
236 | - |
|
237 | - |
|
238 | - /** |
|
239 | - * set_reg_url_link |
|
240 | - * |
|
241 | - * @param string $reg_url_link |
|
242 | - */ |
|
243 | - public function set_reg_url_link($reg_url_link = null) |
|
244 | - { |
|
245 | - $this->_reg_url_link = ! empty($reg_url_link) ? $reg_url_link : $this->_reg_url_link; |
|
246 | - } |
|
247 | - |
|
248 | - |
|
249 | - /** |
|
250 | - * run - initial module setup |
|
251 | - * this method is primarily used for activating resources in the EE_Front_Controller thru the use of filters |
|
252 | - * |
|
253 | - * @param WP $WP |
|
254 | - * @return void |
|
255 | - */ |
|
256 | - public function run($WP) |
|
257 | - { |
|
258 | - } |
|
259 | - |
|
260 | - |
|
261 | - /** |
|
262 | - * load_resources |
|
263 | - * |
|
264 | - * @return void |
|
265 | - * @throws EE_Error |
|
266 | - * @throws ReflectionException |
|
267 | - */ |
|
268 | - public function load_resources() |
|
269 | - { |
|
270 | - $this->_get_reg_url_link(); |
|
271 | - // resend_reg_confirmation_email ? |
|
272 | - if (self::getRequest()->requestParamIsSet('resend')) { |
|
273 | - EED_Thank_You_Page::resend_reg_confirmation_email(); |
|
274 | - } |
|
275 | - EE_Registry::instance()->SSN->clear_session(__CLASS__, __FUNCTION__); |
|
276 | - $this->_translate_strings(); |
|
277 | - // load assets |
|
278 | - add_action('wp_enqueue_scripts', array($this, 'load_js'), 10); |
|
279 | - } |
|
280 | - |
|
281 | - |
|
282 | - /** |
|
283 | - * load_js |
|
284 | - * |
|
285 | - * @return void |
|
286 | - */ |
|
287 | - protected function _translate_strings() |
|
288 | - { |
|
289 | - EE_Registry::$i18n_js_strings['e_reg_url_link'] = $this->_reg_url_link; |
|
290 | - EE_Registry::$i18n_js_strings['initial_access'] = time(); |
|
291 | - EE_Registry::$i18n_js_strings['IPN_wait_time'] = EED_Thank_You_Page::IPN_wait_time; |
|
292 | - EE_Registry::$i18n_js_strings['TXN_complete'] = EEM_Transaction::complete_status_code; |
|
293 | - EE_Registry::$i18n_js_strings['TXN_incomplete'] = EEM_Transaction::incomplete_status_code; |
|
294 | - EE_Registry::$i18n_js_strings['checking_for_new_payments'] = __( |
|
295 | - 'checking for new payments...', |
|
296 | - 'event_espresso' |
|
297 | - ); |
|
298 | - EE_Registry::$i18n_js_strings['loading_payment_info'] = __( |
|
299 | - 'loading payment information...', |
|
300 | - 'event_espresso' |
|
301 | - ); |
|
302 | - EE_Registry::$i18n_js_strings['server_error'] = __( |
|
303 | - 'An unknown error occurred on the server while attempting to process your request. Please refresh the page and try again.', |
|
304 | - 'event_espresso' |
|
305 | - ); |
|
306 | - EE_Registry::$i18n_js_strings['slow_IPN'] = apply_filters( |
|
307 | - 'EED_Thank_You_Page__load_js__slow_IPN', |
|
308 | - sprintf( |
|
309 | - __( |
|
310 | - '%sThe Payment Notification appears to be taking longer than usual to arrive. Maybe check back later or just wait for your payment and registration confirmation results to be sent to you via email. We apologize for any inconvenience this may have caused.%s', |
|
311 | - 'event_espresso' |
|
312 | - ), |
|
313 | - '<div id="espresso-thank-you-page-slow-IPN-dv" class="ee-attention jst-left">', |
|
314 | - '</div>' |
|
315 | - ) |
|
316 | - ); |
|
317 | - } |
|
318 | - |
|
319 | - |
|
320 | - /** |
|
321 | - * load_js |
|
322 | - * |
|
323 | - * @return void |
|
324 | - */ |
|
325 | - public function load_js() |
|
326 | - { |
|
327 | - wp_register_script( |
|
328 | - 'thank_you_page', |
|
329 | - THANK_YOU_ASSETS_URL . 'thank_you_page.js', |
|
330 | - array('espresso_core', 'heartbeat'), |
|
331 | - EVENT_ESPRESSO_VERSION, |
|
332 | - true |
|
333 | - ); |
|
334 | - wp_enqueue_script('thank_you_page'); |
|
335 | - wp_enqueue_style('espresso_default'); |
|
336 | - } |
|
337 | - |
|
338 | - |
|
339 | - /** |
|
340 | - * init |
|
341 | - * |
|
342 | - * @return void |
|
343 | - * @throws EE_Error |
|
344 | - * @throws ReflectionException |
|
345 | - */ |
|
346 | - public function init() |
|
347 | - { |
|
348 | - $this->_get_reg_url_link(); |
|
349 | - if (! $this->get_txn()) { |
|
350 | - echo EEH_HTML::div( |
|
351 | - EEH_HTML::h4(esc_html__('We\'re sorry...', 'event_espresso')) . |
|
352 | - sprintf( |
|
353 | - esc_html__( |
|
354 | - 'This is a system page for displaying transaction information after a purchase.%1$sYou are most likely seeing this notice because you have navigated to this page%1$sthrough some means other than completing a transaction.%1$sSorry for the disappointment, but you will most likely find nothing of interest here.%1$s%1$s', |
|
355 | - 'event_espresso' |
|
356 | - ), |
|
357 | - '<br/>' |
|
358 | - ), |
|
359 | - '', |
|
360 | - 'ee-attention' |
|
361 | - ); |
|
362 | - return; |
|
363 | - } |
|
364 | - // if we've made it to the Thank You page, then let's toggle any "Failed" transactions to "Incomplete" |
|
365 | - if ($this->_current_txn->status_ID() === EEM_Transaction::failed_status_code) { |
|
366 | - $this->_current_txn->set_status(EEM_Transaction::incomplete_status_code); |
|
367 | - $this->_current_txn->save(); |
|
368 | - } |
|
369 | - $this->_primary_registrant = $this->_current_txn->primary_registration() instanceof EE_Registration |
|
370 | - ? $this->_current_txn->primary_registration() |
|
371 | - : null; |
|
372 | - $this->_is_primary = $this->_primary_registrant->reg_url_link() === $this->_reg_url_link; |
|
373 | - $show_try_pay_again_link_default = apply_filters( |
|
374 | - 'AFEE__EED_Thank_You_Page__init__show_try_pay_again_link_default', |
|
375 | - true |
|
376 | - ); |
|
377 | - $this->_show_try_pay_again_link = $show_try_pay_again_link_default; |
|
378 | - // txn status ? |
|
379 | - if ($this->_current_txn->is_completed()) { |
|
380 | - $this->_show_try_pay_again_link = $show_try_pay_again_link_default; |
|
381 | - } elseif ( |
|
382 | - $this->_current_txn->is_incomplete() |
|
383 | - && ($this->_primary_registrant->is_approved() |
|
384 | - || $this->_primary_registrant->is_pending_payment()) |
|
385 | - ) { |
|
386 | - $this->_show_try_pay_again_link = true; |
|
387 | - } elseif ($this->_primary_registrant->is_approved() || $this->_primary_registrant->is_pending_payment()) { |
|
388 | - // its pending |
|
389 | - $this->_show_try_pay_again_link = isset( |
|
390 | - EE_Registry::instance()->CFG->registration->show_pending_payment_options |
|
391 | - ) |
|
392 | - && EE_Registry::instance()->CFG |
|
393 | - ->registration->show_pending_payment_options |
|
394 | - ? true |
|
395 | - : $show_try_pay_again_link_default; |
|
396 | - } |
|
397 | - $this->_payments_closed = ! $this->_current_txn->payment_method() instanceof EE_Payment_Method; |
|
398 | - $this->_is_offline_payment_method = false; |
|
399 | - if ( |
|
13 | + /** |
|
14 | + * time in seconds to wait for the IPN to arrive before telling the registrant to bugger off ( 1200s = 20 minutes ) |
|
15 | + */ |
|
16 | + const IPN_wait_time = 1200; |
|
17 | + |
|
18 | + /** |
|
19 | + * The transaction specified by the reg_url_link passed from the Request, or from the Session |
|
20 | + * |
|
21 | + * @var EE_Transaction $_current_txn |
|
22 | + */ |
|
23 | + private $_current_txn; |
|
24 | + |
|
25 | + /** |
|
26 | + * @var EE_Registration $_primary_registrant |
|
27 | + */ |
|
28 | + private $_primary_registrant; |
|
29 | + |
|
30 | + /** |
|
31 | + * The reg_url_link passed from the Request, or from the Session |
|
32 | + * |
|
33 | + * @var string $_reg_url_link |
|
34 | + */ |
|
35 | + private $_reg_url_link; |
|
36 | + |
|
37 | + /** |
|
38 | + * whether the incoming reg_url_link is for the primary registrant or not |
|
39 | + * |
|
40 | + * @var boolean $_is_primary |
|
41 | + */ |
|
42 | + private $_is_primary; |
|
43 | + |
|
44 | + /** |
|
45 | + * The URL for revisiting the SPCO attendee information step |
|
46 | + * |
|
47 | + * @var string $_SPCO_attendee_information_url |
|
48 | + */ |
|
49 | + private $_SPCO_attendee_information_url; |
|
50 | + |
|
51 | + /** |
|
52 | + * The URL for revisiting the SPCO payment options step |
|
53 | + * |
|
54 | + * @var string $_SPCO_payment_options_url |
|
55 | + */ |
|
56 | + private $_SPCO_payment_options_url; |
|
57 | + |
|
58 | + /** |
|
59 | + * whether to display the Payment Options link |
|
60 | + * |
|
61 | + * @var boolean $_show_try_pay_again_link |
|
62 | + */ |
|
63 | + private $_show_try_pay_again_link = false; |
|
64 | + |
|
65 | + /** |
|
66 | + * whether payments are allowed at this time |
|
67 | + * |
|
68 | + * @var boolean $_payments_closed |
|
69 | + */ |
|
70 | + private $_payments_closed = false; |
|
71 | + |
|
72 | + /** |
|
73 | + * whether the selected payment method is Bank, Check , Invoice, etc |
|
74 | + * |
|
75 | + * @var boolean $_is_offline_payment_method |
|
76 | + */ |
|
77 | + private $_is_offline_payment_method = true; |
|
78 | + |
|
79 | + |
|
80 | + /** |
|
81 | + * @return EED_Module|EED_Thank_You_Page |
|
82 | + * @throws EE_Error |
|
83 | + * @throws ReflectionException |
|
84 | + */ |
|
85 | + public static function instance() |
|
86 | + { |
|
87 | + return parent::get_instance(__CLASS__); |
|
88 | + } |
|
89 | + |
|
90 | + |
|
91 | + /** |
|
92 | + * set_hooks - for hooking into EE Core, modules, etc |
|
93 | + * |
|
94 | + * @return void |
|
95 | + */ |
|
96 | + public static function set_hooks() |
|
97 | + { |
|
98 | + add_action('wp_loaded', array('EED_Thank_You_Page', 'set_definitions'), 2); |
|
99 | + } |
|
100 | + |
|
101 | + |
|
102 | + /** |
|
103 | + * set_hooks_admin - for hooking into EE Admin Core, modules, etc |
|
104 | + * |
|
105 | + * @return void |
|
106 | + */ |
|
107 | + public static function set_hooks_admin() |
|
108 | + { |
|
109 | + add_action( |
|
110 | + 'wp_ajax_espresso_resend_reg_confirmation_email', |
|
111 | + array('EED_Thank_You_Page', 'resend_reg_confirmation_email'), |
|
112 | + 10, |
|
113 | + 2 |
|
114 | + ); |
|
115 | + add_action( |
|
116 | + 'wp_ajax_nopriv_espresso_resend_reg_confirmation_email', |
|
117 | + array('EED_Thank_You_Page', 'resend_reg_confirmation_email'), |
|
118 | + 10, |
|
119 | + 2 |
|
120 | + ); |
|
121 | + } |
|
122 | + |
|
123 | + |
|
124 | + /** |
|
125 | + * set_definitions |
|
126 | + * |
|
127 | + * @return void |
|
128 | + */ |
|
129 | + public static function set_definitions() |
|
130 | + { |
|
131 | + define('THANK_YOU_ASSETS_URL', plugin_dir_url(__FILE__) . 'assets/'); |
|
132 | + define('THANK_YOU_TEMPLATES_PATH', str_replace('\\', '/', plugin_dir_path(__FILE__)) . 'templates/'); |
|
133 | + } |
|
134 | + |
|
135 | + |
|
136 | + /** |
|
137 | + * get_txn |
|
138 | + * |
|
139 | + * @return EE_Transaction |
|
140 | + * @throws EE_Error |
|
141 | + * @throws ReflectionException |
|
142 | + */ |
|
143 | + public function get_txn() |
|
144 | + { |
|
145 | + if ($this->_current_txn instanceof EE_Transaction) { |
|
146 | + return $this->_current_txn; |
|
147 | + } |
|
148 | + $TXN_model = EE_Registry::instance()->load_model('Transaction'); |
|
149 | + if (! $TXN_model instanceof EEM_Transaction) { |
|
150 | + EE_Error::add_error( |
|
151 | + esc_html__('The transaction model could not be established.', 'event_espresso'), |
|
152 | + __FILE__, |
|
153 | + __FUNCTION__, |
|
154 | + __LINE__ |
|
155 | + ); |
|
156 | + return null; |
|
157 | + } |
|
158 | + // get the transaction. yes, we may have just loaded it, but it may have been updated, or this may be via an ajax request |
|
159 | + $this->_current_txn = $TXN_model->get_transaction_from_reg_url_link($this->_reg_url_link); |
|
160 | + // verify TXN |
|
161 | + if (WP_DEBUG && ! $this->_current_txn instanceof EE_Transaction) { |
|
162 | + EE_Error::add_error( |
|
163 | + esc_html__( |
|
164 | + 'No transaction information could be retrieved or the transaction data is not of the correct type.', |
|
165 | + 'event_espresso' |
|
166 | + ), |
|
167 | + __FILE__, |
|
168 | + __FUNCTION__, |
|
169 | + __LINE__ |
|
170 | + ); |
|
171 | + return null; |
|
172 | + } |
|
173 | + return $this->_current_txn; |
|
174 | + } |
|
175 | + |
|
176 | + |
|
177 | + /** |
|
178 | + * get_txn_payments |
|
179 | + * |
|
180 | + * @param int $since |
|
181 | + * @return EE_Payment[] |
|
182 | + * @throws EE_Error |
|
183 | + * @throws ReflectionException |
|
184 | + */ |
|
185 | + public function get_txn_payments($since = 0) |
|
186 | + { |
|
187 | + if (! $this->get_txn()) { |
|
188 | + return []; |
|
189 | + } |
|
190 | + $args = array('order_by' => array('PAY_timestamp' => 'ASC')); |
|
191 | + if ($since > 0) { |
|
192 | + $args[0] = array('PAY_timestamp' => array('>', $since)); |
|
193 | + } |
|
194 | + // get array of payments with most recent first |
|
195 | + return $this->_current_txn->payments($args); |
|
196 | + } |
|
197 | + |
|
198 | + |
|
199 | + /** |
|
200 | + * @return bool |
|
201 | + */ |
|
202 | + public function isOfflinePaymentMethod() |
|
203 | + { |
|
204 | + return $this->_is_offline_payment_method; |
|
205 | + } |
|
206 | + |
|
207 | + |
|
208 | + |
|
209 | + |
|
210 | + /** |
|
211 | + * get_reg_url_link |
|
212 | + * |
|
213 | + * @return void |
|
214 | + */ |
|
215 | + private function _get_reg_url_link() |
|
216 | + { |
|
217 | + if ($this->_reg_url_link) { |
|
218 | + return; |
|
219 | + } |
|
220 | + // check for reg_url_link |
|
221 | + $reg_url_link = self::getRequest()->getRequestParam('e_reg_url_link'); |
|
222 | + // only do thank you page stuff if we have a REG_url_link in the url |
|
223 | + if (WP_DEBUG && ! $reg_url_link) { |
|
224 | + EE_Error::add_error( |
|
225 | + esc_html__( |
|
226 | + 'No transaction information could be retrieved because the registration URL link is missing or invalid.', |
|
227 | + 'event_espresso' |
|
228 | + ), |
|
229 | + __FILE__, |
|
230 | + __FUNCTION__, |
|
231 | + __LINE__ |
|
232 | + ); |
|
233 | + } |
|
234 | + $this->set_reg_url_link($reg_url_link); |
|
235 | + } |
|
236 | + |
|
237 | + |
|
238 | + /** |
|
239 | + * set_reg_url_link |
|
240 | + * |
|
241 | + * @param string $reg_url_link |
|
242 | + */ |
|
243 | + public function set_reg_url_link($reg_url_link = null) |
|
244 | + { |
|
245 | + $this->_reg_url_link = ! empty($reg_url_link) ? $reg_url_link : $this->_reg_url_link; |
|
246 | + } |
|
247 | + |
|
248 | + |
|
249 | + /** |
|
250 | + * run - initial module setup |
|
251 | + * this method is primarily used for activating resources in the EE_Front_Controller thru the use of filters |
|
252 | + * |
|
253 | + * @param WP $WP |
|
254 | + * @return void |
|
255 | + */ |
|
256 | + public function run($WP) |
|
257 | + { |
|
258 | + } |
|
259 | + |
|
260 | + |
|
261 | + /** |
|
262 | + * load_resources |
|
263 | + * |
|
264 | + * @return void |
|
265 | + * @throws EE_Error |
|
266 | + * @throws ReflectionException |
|
267 | + */ |
|
268 | + public function load_resources() |
|
269 | + { |
|
270 | + $this->_get_reg_url_link(); |
|
271 | + // resend_reg_confirmation_email ? |
|
272 | + if (self::getRequest()->requestParamIsSet('resend')) { |
|
273 | + EED_Thank_You_Page::resend_reg_confirmation_email(); |
|
274 | + } |
|
275 | + EE_Registry::instance()->SSN->clear_session(__CLASS__, __FUNCTION__); |
|
276 | + $this->_translate_strings(); |
|
277 | + // load assets |
|
278 | + add_action('wp_enqueue_scripts', array($this, 'load_js'), 10); |
|
279 | + } |
|
280 | + |
|
281 | + |
|
282 | + /** |
|
283 | + * load_js |
|
284 | + * |
|
285 | + * @return void |
|
286 | + */ |
|
287 | + protected function _translate_strings() |
|
288 | + { |
|
289 | + EE_Registry::$i18n_js_strings['e_reg_url_link'] = $this->_reg_url_link; |
|
290 | + EE_Registry::$i18n_js_strings['initial_access'] = time(); |
|
291 | + EE_Registry::$i18n_js_strings['IPN_wait_time'] = EED_Thank_You_Page::IPN_wait_time; |
|
292 | + EE_Registry::$i18n_js_strings['TXN_complete'] = EEM_Transaction::complete_status_code; |
|
293 | + EE_Registry::$i18n_js_strings['TXN_incomplete'] = EEM_Transaction::incomplete_status_code; |
|
294 | + EE_Registry::$i18n_js_strings['checking_for_new_payments'] = __( |
|
295 | + 'checking for new payments...', |
|
296 | + 'event_espresso' |
|
297 | + ); |
|
298 | + EE_Registry::$i18n_js_strings['loading_payment_info'] = __( |
|
299 | + 'loading payment information...', |
|
300 | + 'event_espresso' |
|
301 | + ); |
|
302 | + EE_Registry::$i18n_js_strings['server_error'] = __( |
|
303 | + 'An unknown error occurred on the server while attempting to process your request. Please refresh the page and try again.', |
|
304 | + 'event_espresso' |
|
305 | + ); |
|
306 | + EE_Registry::$i18n_js_strings['slow_IPN'] = apply_filters( |
|
307 | + 'EED_Thank_You_Page__load_js__slow_IPN', |
|
308 | + sprintf( |
|
309 | + __( |
|
310 | + '%sThe Payment Notification appears to be taking longer than usual to arrive. Maybe check back later or just wait for your payment and registration confirmation results to be sent to you via email. We apologize for any inconvenience this may have caused.%s', |
|
311 | + 'event_espresso' |
|
312 | + ), |
|
313 | + '<div id="espresso-thank-you-page-slow-IPN-dv" class="ee-attention jst-left">', |
|
314 | + '</div>' |
|
315 | + ) |
|
316 | + ); |
|
317 | + } |
|
318 | + |
|
319 | + |
|
320 | + /** |
|
321 | + * load_js |
|
322 | + * |
|
323 | + * @return void |
|
324 | + */ |
|
325 | + public function load_js() |
|
326 | + { |
|
327 | + wp_register_script( |
|
328 | + 'thank_you_page', |
|
329 | + THANK_YOU_ASSETS_URL . 'thank_you_page.js', |
|
330 | + array('espresso_core', 'heartbeat'), |
|
331 | + EVENT_ESPRESSO_VERSION, |
|
332 | + true |
|
333 | + ); |
|
334 | + wp_enqueue_script('thank_you_page'); |
|
335 | + wp_enqueue_style('espresso_default'); |
|
336 | + } |
|
337 | + |
|
338 | + |
|
339 | + /** |
|
340 | + * init |
|
341 | + * |
|
342 | + * @return void |
|
343 | + * @throws EE_Error |
|
344 | + * @throws ReflectionException |
|
345 | + */ |
|
346 | + public function init() |
|
347 | + { |
|
348 | + $this->_get_reg_url_link(); |
|
349 | + if (! $this->get_txn()) { |
|
350 | + echo EEH_HTML::div( |
|
351 | + EEH_HTML::h4(esc_html__('We\'re sorry...', 'event_espresso')) . |
|
352 | + sprintf( |
|
353 | + esc_html__( |
|
354 | + 'This is a system page for displaying transaction information after a purchase.%1$sYou are most likely seeing this notice because you have navigated to this page%1$sthrough some means other than completing a transaction.%1$sSorry for the disappointment, but you will most likely find nothing of interest here.%1$s%1$s', |
|
355 | + 'event_espresso' |
|
356 | + ), |
|
357 | + '<br/>' |
|
358 | + ), |
|
359 | + '', |
|
360 | + 'ee-attention' |
|
361 | + ); |
|
362 | + return; |
|
363 | + } |
|
364 | + // if we've made it to the Thank You page, then let's toggle any "Failed" transactions to "Incomplete" |
|
365 | + if ($this->_current_txn->status_ID() === EEM_Transaction::failed_status_code) { |
|
366 | + $this->_current_txn->set_status(EEM_Transaction::incomplete_status_code); |
|
367 | + $this->_current_txn->save(); |
|
368 | + } |
|
369 | + $this->_primary_registrant = $this->_current_txn->primary_registration() instanceof EE_Registration |
|
370 | + ? $this->_current_txn->primary_registration() |
|
371 | + : null; |
|
372 | + $this->_is_primary = $this->_primary_registrant->reg_url_link() === $this->_reg_url_link; |
|
373 | + $show_try_pay_again_link_default = apply_filters( |
|
374 | + 'AFEE__EED_Thank_You_Page__init__show_try_pay_again_link_default', |
|
375 | + true |
|
376 | + ); |
|
377 | + $this->_show_try_pay_again_link = $show_try_pay_again_link_default; |
|
378 | + // txn status ? |
|
379 | + if ($this->_current_txn->is_completed()) { |
|
380 | + $this->_show_try_pay_again_link = $show_try_pay_again_link_default; |
|
381 | + } elseif ( |
|
382 | + $this->_current_txn->is_incomplete() |
|
383 | + && ($this->_primary_registrant->is_approved() |
|
384 | + || $this->_primary_registrant->is_pending_payment()) |
|
385 | + ) { |
|
386 | + $this->_show_try_pay_again_link = true; |
|
387 | + } elseif ($this->_primary_registrant->is_approved() || $this->_primary_registrant->is_pending_payment()) { |
|
388 | + // its pending |
|
389 | + $this->_show_try_pay_again_link = isset( |
|
390 | + EE_Registry::instance()->CFG->registration->show_pending_payment_options |
|
391 | + ) |
|
392 | + && EE_Registry::instance()->CFG |
|
393 | + ->registration->show_pending_payment_options |
|
394 | + ? true |
|
395 | + : $show_try_pay_again_link_default; |
|
396 | + } |
|
397 | + $this->_payments_closed = ! $this->_current_txn->payment_method() instanceof EE_Payment_Method; |
|
398 | + $this->_is_offline_payment_method = false; |
|
399 | + if ( |
|
400 | 400 | // if payment method is unknown |
401 | - ! $this->_current_txn->payment_method() instanceof EE_Payment_Method |
|
402 | - || ( |
|
403 | - // or is an offline payment method |
|
404 | - $this->_current_txn->payment_method() instanceof EE_Payment_Method |
|
405 | - && $this->_current_txn->payment_method()->is_off_line() |
|
406 | - ) |
|
407 | - ) { |
|
408 | - $this->_is_offline_payment_method = true; |
|
409 | - } |
|
410 | - // link to SPCO |
|
411 | - $revisit_spco_url = add_query_arg( |
|
412 | - array('ee' => '_register', 'revisit' => true, 'e_reg_url_link' => $this->_reg_url_link), |
|
413 | - EE_Registry::instance()->CFG->core->reg_page_url() |
|
414 | - ); |
|
415 | - // link to SPCO payment_options |
|
416 | - $this->_SPCO_payment_options_url = $this->_primary_registrant instanceof EE_Registration |
|
417 | - ? $this->_primary_registrant->payment_overview_url() |
|
418 | - : add_query_arg( |
|
419 | - array('step' => 'payment_options'), |
|
420 | - $revisit_spco_url |
|
421 | - ); |
|
422 | - // link to SPCO attendee_information |
|
423 | - $this->_SPCO_attendee_information_url = $this->_primary_registrant instanceof EE_Registration |
|
424 | - ? $this->_primary_registrant->edit_attendee_information_url() |
|
425 | - : false; |
|
426 | - do_action('AHEE__EED_Thank_You_Page__init_end', $this->_current_txn); |
|
427 | - // set no cache headers and constants |
|
428 | - EE_System::do_not_cache(); |
|
429 | - } |
|
430 | - |
|
431 | - |
|
432 | - /** |
|
433 | - * display_thank_you_page_results |
|
434 | - * |
|
435 | - * @return string |
|
436 | - * @throws EE_Error |
|
437 | - * @throws ReflectionException |
|
438 | - */ |
|
439 | - public function thank_you_page_results() |
|
440 | - { |
|
441 | - $this->init(); |
|
442 | - if (! $this->_current_txn instanceof EE_Transaction) { |
|
443 | - return EE_Error::get_notices(); |
|
444 | - } |
|
445 | - // link to receipt |
|
446 | - $template_args['TXN_receipt_url'] = $this->_current_txn->receipt_url(); |
|
447 | - if (! empty($template_args['TXN_receipt_url'])) { |
|
448 | - $template_args['order_conf_desc'] = esc_html__( |
|
449 | - '%1$sCongratulations%2$sYour registration has been successfully processed.%3$sCheck your email for your registration confirmation or click the button below to view / download / print a full description of your purchases and registration information.', |
|
450 | - 'event_espresso' |
|
451 | - ); |
|
452 | - } else { |
|
453 | - $template_args['order_conf_desc'] = esc_html__( |
|
454 | - '%1$sCongratulations%2$sYour registration has been successfully processed.%3$sCheck your email for your registration confirmation.', |
|
455 | - 'event_espresso' |
|
456 | - ); |
|
457 | - } |
|
458 | - $template_args['transaction'] = $this->_current_txn; |
|
459 | - $template_args['revisit'] = self::getRequest()->getRequestParam('revisit', false, 'bool'); |
|
460 | - add_action('AHEE__thank_you_page_overview_template__content', array($this, 'get_registration_details')); |
|
461 | - if ($this->_is_primary && ! $this->_current_txn->is_free()) { |
|
462 | - add_action('AHEE__thank_you_page_overview_template__content', array($this, 'get_ajax_content')); |
|
463 | - } |
|
464 | - return EEH_Template::locate_template( |
|
465 | - THANK_YOU_TEMPLATES_PATH . 'thank-you-page-overview.template.php', |
|
466 | - $template_args |
|
467 | - ); |
|
468 | - } |
|
469 | - |
|
470 | - |
|
471 | - /** |
|
472 | - * _update_server_wait_time |
|
473 | - * |
|
474 | - * @param array $thank_you_page_data thank you page portion of the incoming JSON array from the WP heartbeat data |
|
475 | - * @return array |
|
476 | - * @throws EE_Error |
|
477 | - * @throws ReflectionException |
|
478 | - */ |
|
479 | - private function _update_server_wait_time($thank_you_page_data = array()) |
|
480 | - { |
|
481 | - $response['espresso_thank_you_page'] = array( |
|
482 | - 'still_waiting' => isset($thank_you_page_data['initial_access']) |
|
483 | - ? time() - $thank_you_page_data['initial_access'] |
|
484 | - : 0, |
|
485 | - 'txn_status' => $this->_current_txn->status_ID(), |
|
486 | - ); |
|
487 | - return $response; |
|
488 | - } |
|
489 | - |
|
490 | - |
|
491 | - /** |
|
492 | - * get_registration_details |
|
493 | - * |
|
494 | - * @throws EE_Error |
|
495 | - */ |
|
496 | - public function get_registration_details() |
|
497 | - { |
|
498 | - // prepare variables for displaying |
|
499 | - $template_args = array(); |
|
500 | - $template_args['transaction'] = $this->_current_txn; |
|
501 | - $template_args['reg_url_link'] = $this->_reg_url_link; |
|
502 | - $template_args['is_primary'] = $this->_is_primary; |
|
503 | - $template_args['SPCO_attendee_information_url'] = $this->_SPCO_attendee_information_url; |
|
504 | - $template_args['resend_reg_confirmation_url'] = add_query_arg( |
|
505 | - array('token' => $this->_reg_url_link, 'resend_reg_confirmation' => 'true'), |
|
506 | - EE_Registry::instance()->CFG->core->thank_you_page_url() |
|
507 | - ); |
|
508 | - // verify template arguments |
|
509 | - EEH_Template_Validator::verify_instanceof($template_args['transaction'], '$transaction', 'EE_Transaction'); |
|
510 | - EEH_Template_Validator::verify_isnt_null( |
|
511 | - $template_args['SPCO_attendee_information_url'], |
|
512 | - '$SPCO_attendee_information_url' |
|
513 | - ); |
|
514 | - echo EEH_Template::locate_template( |
|
515 | - THANK_YOU_TEMPLATES_PATH . 'thank-you-page-registration-details.template.php', |
|
516 | - $template_args |
|
517 | - ); |
|
518 | - } |
|
519 | - |
|
520 | - |
|
521 | - /** |
|
522 | - * resend_reg_confirmation_email |
|
523 | - * |
|
524 | - * @throws EE_Error |
|
525 | - * @throws ReflectionException |
|
526 | - */ |
|
527 | - public static function resend_reg_confirmation_email() |
|
528 | - { |
|
529 | - $reg_url_link = self::getRequest()->getRequestParam('token'); |
|
530 | - // was a REG_ID passed ? |
|
531 | - if ($reg_url_link) { |
|
532 | - $registration = EEM_Registration::instance()->get_one( |
|
533 | - array(array('REG_url_link' => $reg_url_link)) |
|
534 | - ); |
|
535 | - if ($registration instanceof EE_Registration) { |
|
536 | - // resend email |
|
537 | - EED_Messages::process_resend(array('_REG_ID' => $registration->ID())); |
|
538 | - } else { |
|
539 | - EE_Error::add_error( |
|
540 | - esc_html__( |
|
541 | - 'The Registration Confirmation email could not be sent because a valid Registration could not be retrieved from the database.', |
|
542 | - 'event_espresso' |
|
543 | - ), |
|
544 | - __FILE__, |
|
545 | - __FUNCTION__, |
|
546 | - __LINE__ |
|
547 | - ); |
|
548 | - } |
|
549 | - } else { |
|
550 | - EE_Error::add_error( |
|
551 | - esc_html__( |
|
552 | - 'The Registration Confirmation email could not be sent because a registration token is missing or invalid.', |
|
553 | - 'event_espresso' |
|
554 | - ), |
|
555 | - __FILE__, |
|
556 | - __FUNCTION__, |
|
557 | - __LINE__ |
|
558 | - ); |
|
559 | - } |
|
560 | - // request sent via AJAX ? |
|
561 | - if (EE_FRONT_AJAX) { |
|
562 | - echo wp_json_encode(EE_Error::get_notices(false)); |
|
563 | - die(); |
|
564 | - // or was JS disabled ? |
|
565 | - } else { |
|
566 | - // save errors so that they get picked up on the next request |
|
567 | - EE_Error::get_notices(true, true); |
|
568 | - wp_safe_redirect( |
|
569 | - add_query_arg( |
|
570 | - array('e_reg_url_link' => $reg_url_link), |
|
571 | - EE_Registry::instance()->CFG->core->thank_you_page_url() |
|
572 | - ) |
|
573 | - ); |
|
574 | - } |
|
575 | - } |
|
576 | - |
|
577 | - |
|
578 | - /** |
|
579 | - * get_ajax_content |
|
580 | - * |
|
581 | - * @return void |
|
582 | - * @throws EE_Error |
|
583 | - * @throws ReflectionException |
|
584 | - */ |
|
585 | - public function get_ajax_content() |
|
586 | - { |
|
587 | - if (! $this->get_txn()) { |
|
588 | - return; |
|
589 | - } |
|
590 | - // first determine which event(s) require pre-approval or not |
|
591 | - $events = array(); |
|
592 | - $events_requiring_pre_approval = array(); |
|
593 | - foreach ($this->_current_txn->registrations() as $registration) { |
|
594 | - if ($registration instanceof EE_Registration) { |
|
595 | - $event = $registration->event(); |
|
596 | - if ($event instanceof EE_Event) { |
|
597 | - if ($registration->is_not_approved() && $registration->event() instanceof EE_Event) { |
|
598 | - $events_requiring_pre_approval[ $event->ID() ] = $event; |
|
599 | - } else { |
|
600 | - $events[ $event->ID() ] = $event; |
|
601 | - } |
|
602 | - } |
|
603 | - } |
|
604 | - } |
|
605 | - $this->display_details_for_events_requiring_pre_approval($events_requiring_pre_approval); |
|
606 | - $this->display_details_for_events($events); |
|
607 | - } |
|
608 | - |
|
609 | - |
|
610 | - /** |
|
611 | - * display_details_for_events |
|
612 | - * |
|
613 | - * @param EE_Event[] $events |
|
614 | - * @return void |
|
615 | - */ |
|
616 | - public function display_details_for_events($events = array()) |
|
617 | - { |
|
618 | - if (! empty($events)) { |
|
619 | - ?> |
|
401 | + ! $this->_current_txn->payment_method() instanceof EE_Payment_Method |
|
402 | + || ( |
|
403 | + // or is an offline payment method |
|
404 | + $this->_current_txn->payment_method() instanceof EE_Payment_Method |
|
405 | + && $this->_current_txn->payment_method()->is_off_line() |
|
406 | + ) |
|
407 | + ) { |
|
408 | + $this->_is_offline_payment_method = true; |
|
409 | + } |
|
410 | + // link to SPCO |
|
411 | + $revisit_spco_url = add_query_arg( |
|
412 | + array('ee' => '_register', 'revisit' => true, 'e_reg_url_link' => $this->_reg_url_link), |
|
413 | + EE_Registry::instance()->CFG->core->reg_page_url() |
|
414 | + ); |
|
415 | + // link to SPCO payment_options |
|
416 | + $this->_SPCO_payment_options_url = $this->_primary_registrant instanceof EE_Registration |
|
417 | + ? $this->_primary_registrant->payment_overview_url() |
|
418 | + : add_query_arg( |
|
419 | + array('step' => 'payment_options'), |
|
420 | + $revisit_spco_url |
|
421 | + ); |
|
422 | + // link to SPCO attendee_information |
|
423 | + $this->_SPCO_attendee_information_url = $this->_primary_registrant instanceof EE_Registration |
|
424 | + ? $this->_primary_registrant->edit_attendee_information_url() |
|
425 | + : false; |
|
426 | + do_action('AHEE__EED_Thank_You_Page__init_end', $this->_current_txn); |
|
427 | + // set no cache headers and constants |
|
428 | + EE_System::do_not_cache(); |
|
429 | + } |
|
430 | + |
|
431 | + |
|
432 | + /** |
|
433 | + * display_thank_you_page_results |
|
434 | + * |
|
435 | + * @return string |
|
436 | + * @throws EE_Error |
|
437 | + * @throws ReflectionException |
|
438 | + */ |
|
439 | + public function thank_you_page_results() |
|
440 | + { |
|
441 | + $this->init(); |
|
442 | + if (! $this->_current_txn instanceof EE_Transaction) { |
|
443 | + return EE_Error::get_notices(); |
|
444 | + } |
|
445 | + // link to receipt |
|
446 | + $template_args['TXN_receipt_url'] = $this->_current_txn->receipt_url(); |
|
447 | + if (! empty($template_args['TXN_receipt_url'])) { |
|
448 | + $template_args['order_conf_desc'] = esc_html__( |
|
449 | + '%1$sCongratulations%2$sYour registration has been successfully processed.%3$sCheck your email for your registration confirmation or click the button below to view / download / print a full description of your purchases and registration information.', |
|
450 | + 'event_espresso' |
|
451 | + ); |
|
452 | + } else { |
|
453 | + $template_args['order_conf_desc'] = esc_html__( |
|
454 | + '%1$sCongratulations%2$sYour registration has been successfully processed.%3$sCheck your email for your registration confirmation.', |
|
455 | + 'event_espresso' |
|
456 | + ); |
|
457 | + } |
|
458 | + $template_args['transaction'] = $this->_current_txn; |
|
459 | + $template_args['revisit'] = self::getRequest()->getRequestParam('revisit', false, 'bool'); |
|
460 | + add_action('AHEE__thank_you_page_overview_template__content', array($this, 'get_registration_details')); |
|
461 | + if ($this->_is_primary && ! $this->_current_txn->is_free()) { |
|
462 | + add_action('AHEE__thank_you_page_overview_template__content', array($this, 'get_ajax_content')); |
|
463 | + } |
|
464 | + return EEH_Template::locate_template( |
|
465 | + THANK_YOU_TEMPLATES_PATH . 'thank-you-page-overview.template.php', |
|
466 | + $template_args |
|
467 | + ); |
|
468 | + } |
|
469 | + |
|
470 | + |
|
471 | + /** |
|
472 | + * _update_server_wait_time |
|
473 | + * |
|
474 | + * @param array $thank_you_page_data thank you page portion of the incoming JSON array from the WP heartbeat data |
|
475 | + * @return array |
|
476 | + * @throws EE_Error |
|
477 | + * @throws ReflectionException |
|
478 | + */ |
|
479 | + private function _update_server_wait_time($thank_you_page_data = array()) |
|
480 | + { |
|
481 | + $response['espresso_thank_you_page'] = array( |
|
482 | + 'still_waiting' => isset($thank_you_page_data['initial_access']) |
|
483 | + ? time() - $thank_you_page_data['initial_access'] |
|
484 | + : 0, |
|
485 | + 'txn_status' => $this->_current_txn->status_ID(), |
|
486 | + ); |
|
487 | + return $response; |
|
488 | + } |
|
489 | + |
|
490 | + |
|
491 | + /** |
|
492 | + * get_registration_details |
|
493 | + * |
|
494 | + * @throws EE_Error |
|
495 | + */ |
|
496 | + public function get_registration_details() |
|
497 | + { |
|
498 | + // prepare variables for displaying |
|
499 | + $template_args = array(); |
|
500 | + $template_args['transaction'] = $this->_current_txn; |
|
501 | + $template_args['reg_url_link'] = $this->_reg_url_link; |
|
502 | + $template_args['is_primary'] = $this->_is_primary; |
|
503 | + $template_args['SPCO_attendee_information_url'] = $this->_SPCO_attendee_information_url; |
|
504 | + $template_args['resend_reg_confirmation_url'] = add_query_arg( |
|
505 | + array('token' => $this->_reg_url_link, 'resend_reg_confirmation' => 'true'), |
|
506 | + EE_Registry::instance()->CFG->core->thank_you_page_url() |
|
507 | + ); |
|
508 | + // verify template arguments |
|
509 | + EEH_Template_Validator::verify_instanceof($template_args['transaction'], '$transaction', 'EE_Transaction'); |
|
510 | + EEH_Template_Validator::verify_isnt_null( |
|
511 | + $template_args['SPCO_attendee_information_url'], |
|
512 | + '$SPCO_attendee_information_url' |
|
513 | + ); |
|
514 | + echo EEH_Template::locate_template( |
|
515 | + THANK_YOU_TEMPLATES_PATH . 'thank-you-page-registration-details.template.php', |
|
516 | + $template_args |
|
517 | + ); |
|
518 | + } |
|
519 | + |
|
520 | + |
|
521 | + /** |
|
522 | + * resend_reg_confirmation_email |
|
523 | + * |
|
524 | + * @throws EE_Error |
|
525 | + * @throws ReflectionException |
|
526 | + */ |
|
527 | + public static function resend_reg_confirmation_email() |
|
528 | + { |
|
529 | + $reg_url_link = self::getRequest()->getRequestParam('token'); |
|
530 | + // was a REG_ID passed ? |
|
531 | + if ($reg_url_link) { |
|
532 | + $registration = EEM_Registration::instance()->get_one( |
|
533 | + array(array('REG_url_link' => $reg_url_link)) |
|
534 | + ); |
|
535 | + if ($registration instanceof EE_Registration) { |
|
536 | + // resend email |
|
537 | + EED_Messages::process_resend(array('_REG_ID' => $registration->ID())); |
|
538 | + } else { |
|
539 | + EE_Error::add_error( |
|
540 | + esc_html__( |
|
541 | + 'The Registration Confirmation email could not be sent because a valid Registration could not be retrieved from the database.', |
|
542 | + 'event_espresso' |
|
543 | + ), |
|
544 | + __FILE__, |
|
545 | + __FUNCTION__, |
|
546 | + __LINE__ |
|
547 | + ); |
|
548 | + } |
|
549 | + } else { |
|
550 | + EE_Error::add_error( |
|
551 | + esc_html__( |
|
552 | + 'The Registration Confirmation email could not be sent because a registration token is missing or invalid.', |
|
553 | + 'event_espresso' |
|
554 | + ), |
|
555 | + __FILE__, |
|
556 | + __FUNCTION__, |
|
557 | + __LINE__ |
|
558 | + ); |
|
559 | + } |
|
560 | + // request sent via AJAX ? |
|
561 | + if (EE_FRONT_AJAX) { |
|
562 | + echo wp_json_encode(EE_Error::get_notices(false)); |
|
563 | + die(); |
|
564 | + // or was JS disabled ? |
|
565 | + } else { |
|
566 | + // save errors so that they get picked up on the next request |
|
567 | + EE_Error::get_notices(true, true); |
|
568 | + wp_safe_redirect( |
|
569 | + add_query_arg( |
|
570 | + array('e_reg_url_link' => $reg_url_link), |
|
571 | + EE_Registry::instance()->CFG->core->thank_you_page_url() |
|
572 | + ) |
|
573 | + ); |
|
574 | + } |
|
575 | + } |
|
576 | + |
|
577 | + |
|
578 | + /** |
|
579 | + * get_ajax_content |
|
580 | + * |
|
581 | + * @return void |
|
582 | + * @throws EE_Error |
|
583 | + * @throws ReflectionException |
|
584 | + */ |
|
585 | + public function get_ajax_content() |
|
586 | + { |
|
587 | + if (! $this->get_txn()) { |
|
588 | + return; |
|
589 | + } |
|
590 | + // first determine which event(s) require pre-approval or not |
|
591 | + $events = array(); |
|
592 | + $events_requiring_pre_approval = array(); |
|
593 | + foreach ($this->_current_txn->registrations() as $registration) { |
|
594 | + if ($registration instanceof EE_Registration) { |
|
595 | + $event = $registration->event(); |
|
596 | + if ($event instanceof EE_Event) { |
|
597 | + if ($registration->is_not_approved() && $registration->event() instanceof EE_Event) { |
|
598 | + $events_requiring_pre_approval[ $event->ID() ] = $event; |
|
599 | + } else { |
|
600 | + $events[ $event->ID() ] = $event; |
|
601 | + } |
|
602 | + } |
|
603 | + } |
|
604 | + } |
|
605 | + $this->display_details_for_events_requiring_pre_approval($events_requiring_pre_approval); |
|
606 | + $this->display_details_for_events($events); |
|
607 | + } |
|
608 | + |
|
609 | + |
|
610 | + /** |
|
611 | + * display_details_for_events |
|
612 | + * |
|
613 | + * @param EE_Event[] $events |
|
614 | + * @return void |
|
615 | + */ |
|
616 | + public function display_details_for_events($events = array()) |
|
617 | + { |
|
618 | + if (! empty($events)) { |
|
619 | + ?> |
|
620 | 620 | <div id="espresso-thank-you-page-ajax-content-dv"> |
621 | 621 | <div id="espresso-thank-you-page-ajax-transaction-dv"></div> |
622 | 622 | <div id="espresso-thank-you-page-ajax-payment-dv"></div> |
@@ -624,19 +624,19 @@ discard block |
||
624 | 624 | <div id="ee-ajax-loading-dv" class="float-left lt-blue-text"> |
625 | 625 | <span class="dashicons dashicons-upload"></span><span id="ee-ajax-loading-msg-spn"> |
626 | 626 | <?php esc_html_e( |
627 | - 'loading transaction and payment information...', |
|
628 | - 'event_espresso' |
|
629 | - ); ?></span> |
|
627 | + 'loading transaction and payment information...', |
|
628 | + 'event_espresso' |
|
629 | + ); ?></span> |
|
630 | 630 | </div> |
631 | 631 | <?php if (! $this->_is_offline_payment_method && ! $this->_payments_closed) : ?> |
632 | 632 | <p id="ee-ajax-loading-pg" class="highlight-bg small-text clear"> |
633 | 633 | <?php echo apply_filters( |
634 | - 'EED_Thank_You_Page__get_ajax_content__waiting_for_IPN_msg', |
|
635 | - esc_html__( |
|
636 | - 'Some payment gateways can take 15 minutes or more to return their payment notification, so please be patient if you require payment confirmation as soon as possible. Please note that as soon as everything is finalized, we will send your full payment and registration confirmation results to you via email.', |
|
637 | - 'event_espresso' |
|
638 | - ) |
|
639 | - ); ?> |
|
634 | + 'EED_Thank_You_Page__get_ajax_content__waiting_for_IPN_msg', |
|
635 | + esc_html__( |
|
636 | + 'Some payment gateways can take 15 minutes or more to return their payment notification, so please be patient if you require payment confirmation as soon as possible. Please note that as soon as everything is finalized, we will send your full payment and registration confirmation results to you via email.', |
|
637 | + 'event_espresso' |
|
638 | + ) |
|
639 | + ); ?> |
|
640 | 640 | <br/> |
641 | 641 | <span class="jst-rght ee-block small-text lt-grey-text"> |
642 | 642 | <?php esc_html_e('current wait time ', 'event_espresso'); ?> |
@@ -647,120 +647,120 @@ discard block |
||
647 | 647 | <div class="clear"></div> |
648 | 648 | </div> |
649 | 649 | <?php |
650 | - } |
|
651 | - } |
|
652 | - |
|
653 | - |
|
654 | - /** |
|
655 | - * display_details_for_events_requiring_pre_approval |
|
656 | - * |
|
657 | - * @param EE_Event[] $events |
|
658 | - * @return void |
|
659 | - * @throws EE_Error |
|
660 | - * @throws EE_Error |
|
661 | - */ |
|
662 | - public function display_details_for_events_requiring_pre_approval($events = array()) |
|
663 | - { |
|
664 | - if (! empty($events)) { |
|
665 | - ?> |
|
650 | + } |
|
651 | + } |
|
652 | + |
|
653 | + |
|
654 | + /** |
|
655 | + * display_details_for_events_requiring_pre_approval |
|
656 | + * |
|
657 | + * @param EE_Event[] $events |
|
658 | + * @return void |
|
659 | + * @throws EE_Error |
|
660 | + * @throws EE_Error |
|
661 | + */ |
|
662 | + public function display_details_for_events_requiring_pre_approval($events = array()) |
|
663 | + { |
|
664 | + if (! empty($events)) { |
|
665 | + ?> |
|
666 | 666 | <div id="espresso-thank-you-page-not-approved-message-dv"> |
667 | 667 | <h4 class="orange-text"><?php esc_html_e('Important Notice:', 'event_espresso'); ?></h4> |
668 | 668 | <p id="events-requiring-pre-approval-pg" class="small-text"> |
669 | 669 | <?php echo apply_filters( |
670 | - 'AHEE__EED_Thank_You_Page__get_ajax_content__not_approved_message', |
|
671 | - esc_html__( |
|
672 | - 'The following Event(s) you have registered for do not require payment at this time and will not be billed for during this transaction. Billing will only occur after all attendees have been approved by the event organizer. You will be notified when your registration has been processed. If this is a free event, then no billing will occur.', |
|
673 | - 'event_espresso' |
|
674 | - ) |
|
675 | - ); ?> |
|
670 | + 'AHEE__EED_Thank_You_Page__get_ajax_content__not_approved_message', |
|
671 | + esc_html__( |
|
672 | + 'The following Event(s) you have registered for do not require payment at this time and will not be billed for during this transaction. Billing will only occur after all attendees have been approved by the event organizer. You will be notified when your registration has been processed. If this is a free event, then no billing will occur.', |
|
673 | + 'event_espresso' |
|
674 | + ) |
|
675 | + ); ?> |
|
676 | 676 | </p> |
677 | 677 | <ul class="events-requiring-pre-approval-ul"> |
678 | 678 | <?php |
679 | - foreach ($events as $event) { |
|
680 | - if ($event instanceof EE_Event) { |
|
681 | - echo '<li><span class="dashicons dashicons-marker ee-icon-size-16 orange-text"></span>', |
|
682 | - esc_html($event->name()), |
|
683 | - '</li>'; |
|
684 | - } |
|
685 | - } ?> |
|
679 | + foreach ($events as $event) { |
|
680 | + if ($event instanceof EE_Event) { |
|
681 | + echo '<li><span class="dashicons dashicons-marker ee-icon-size-16 orange-text"></span>', |
|
682 | + esc_html($event->name()), |
|
683 | + '</li>'; |
|
684 | + } |
|
685 | + } ?> |
|
686 | 686 | </ul> |
687 | 687 | <div class="clear"></div> |
688 | 688 | </div> |
689 | 689 | <?php |
690 | - } |
|
691 | - } |
|
692 | - |
|
693 | - |
|
694 | - /** |
|
695 | - * get_transaction_details |
|
696 | - * |
|
697 | - * @return string |
|
698 | - * @throws EE_Error |
|
699 | - */ |
|
700 | - public function get_transaction_details() |
|
701 | - { |
|
702 | - // prepare variables for displaying |
|
703 | - $template_args = array(); |
|
704 | - $template_args['transaction'] = $this->_current_txn; |
|
705 | - $template_args['reg_url_link'] = $this->_reg_url_link; |
|
706 | - $template_args['primary_registrant_name'] = $this->_primary_registrant->attendee()->full_name(true); |
|
707 | - // link to SPCO payment_options |
|
708 | - $template_args['show_try_pay_again_link'] = $this->_show_try_pay_again_link; |
|
709 | - $template_args['SPCO_payment_options_url'] = $this->_SPCO_payment_options_url; |
|
710 | - // verify template arguments |
|
711 | - EEH_Template_Validator::verify_instanceof($template_args['transaction'], '$transaction', 'EE_Transaction'); |
|
712 | - EEH_Template_Validator::verify_isnt_null( |
|
713 | - $template_args['show_try_pay_again_link'], |
|
714 | - '$show_try_pay_again_link' |
|
715 | - ); |
|
716 | - EEH_Template_Validator::verify_isnt_null( |
|
717 | - $template_args['SPCO_payment_options_url'], |
|
718 | - '$SPCO_payment_options_url' |
|
719 | - ); |
|
720 | - return EEH_Template::locate_template( |
|
721 | - THANK_YOU_TEMPLATES_PATH . 'thank-you-page-transaction-details.template.php', |
|
722 | - $template_args |
|
723 | - ); |
|
724 | - } |
|
725 | - |
|
726 | - |
|
727 | - /** |
|
728 | - * get_payment_row_html |
|
729 | - * |
|
730 | - * @param EE_Payment $payment |
|
731 | - * @return string |
|
732 | - * @throws EE_Error |
|
733 | - */ |
|
734 | - public function get_payment_row_html(EE_Payment $payment = null) |
|
735 | - { |
|
736 | - $html = ''; |
|
737 | - if (! $payment instanceof EE_Payment) { |
|
738 | - return ''; |
|
739 | - } |
|
740 | - if ( |
|
741 | - $payment->payment_method() instanceof EE_Payment_Method |
|
742 | - && $payment->status() === EEM_Payment::status_id_failed |
|
743 | - && $payment->payment_method()->is_off_site() |
|
744 | - ) { |
|
745 | - // considering the registrant has made it to the Thank You page, |
|
746 | - // any failed payments may actually be pending and the IPN is just slow |
|
747 | - // so let's |
|
748 | - $payment->set_status(EEM_Payment::status_id_pending); |
|
749 | - } |
|
750 | - $payment_declined_msg = $payment->STS_ID() === EEM_Payment::status_id_declined |
|
751 | - ? '<br /><span class="small-text">' . esc_html($payment->gateway_response()) . '</span>' |
|
752 | - : ''; |
|
753 | - $html .= ' |
|
690 | + } |
|
691 | + } |
|
692 | + |
|
693 | + |
|
694 | + /** |
|
695 | + * get_transaction_details |
|
696 | + * |
|
697 | + * @return string |
|
698 | + * @throws EE_Error |
|
699 | + */ |
|
700 | + public function get_transaction_details() |
|
701 | + { |
|
702 | + // prepare variables for displaying |
|
703 | + $template_args = array(); |
|
704 | + $template_args['transaction'] = $this->_current_txn; |
|
705 | + $template_args['reg_url_link'] = $this->_reg_url_link; |
|
706 | + $template_args['primary_registrant_name'] = $this->_primary_registrant->attendee()->full_name(true); |
|
707 | + // link to SPCO payment_options |
|
708 | + $template_args['show_try_pay_again_link'] = $this->_show_try_pay_again_link; |
|
709 | + $template_args['SPCO_payment_options_url'] = $this->_SPCO_payment_options_url; |
|
710 | + // verify template arguments |
|
711 | + EEH_Template_Validator::verify_instanceof($template_args['transaction'], '$transaction', 'EE_Transaction'); |
|
712 | + EEH_Template_Validator::verify_isnt_null( |
|
713 | + $template_args['show_try_pay_again_link'], |
|
714 | + '$show_try_pay_again_link' |
|
715 | + ); |
|
716 | + EEH_Template_Validator::verify_isnt_null( |
|
717 | + $template_args['SPCO_payment_options_url'], |
|
718 | + '$SPCO_payment_options_url' |
|
719 | + ); |
|
720 | + return EEH_Template::locate_template( |
|
721 | + THANK_YOU_TEMPLATES_PATH . 'thank-you-page-transaction-details.template.php', |
|
722 | + $template_args |
|
723 | + ); |
|
724 | + } |
|
725 | + |
|
726 | + |
|
727 | + /** |
|
728 | + * get_payment_row_html |
|
729 | + * |
|
730 | + * @param EE_Payment $payment |
|
731 | + * @return string |
|
732 | + * @throws EE_Error |
|
733 | + */ |
|
734 | + public function get_payment_row_html(EE_Payment $payment = null) |
|
735 | + { |
|
736 | + $html = ''; |
|
737 | + if (! $payment instanceof EE_Payment) { |
|
738 | + return ''; |
|
739 | + } |
|
740 | + if ( |
|
741 | + $payment->payment_method() instanceof EE_Payment_Method |
|
742 | + && $payment->status() === EEM_Payment::status_id_failed |
|
743 | + && $payment->payment_method()->is_off_site() |
|
744 | + ) { |
|
745 | + // considering the registrant has made it to the Thank You page, |
|
746 | + // any failed payments may actually be pending and the IPN is just slow |
|
747 | + // so let's |
|
748 | + $payment->set_status(EEM_Payment::status_id_pending); |
|
749 | + } |
|
750 | + $payment_declined_msg = $payment->STS_ID() === EEM_Payment::status_id_declined |
|
751 | + ? '<br /><span class="small-text">' . esc_html($payment->gateway_response()) . '</span>' |
|
752 | + : ''; |
|
753 | + $html .= ' |
|
754 | 754 | <tr> |
755 | 755 | <td> |
756 | 756 | ' . esc_html($payment->timestamp()) . ' |
757 | 757 | </td> |
758 | 758 | <td> |
759 | 759 | ' . ( |
760 | - $payment->payment_method() instanceof EE_Payment_Method |
|
761 | - ? esc_html($payment->payment_method()->name()) |
|
762 | - : esc_html__('Unknown', 'event_espresso') |
|
763 | - ) . ' |
|
760 | + $payment->payment_method() instanceof EE_Payment_Method |
|
761 | + ? esc_html($payment->payment_method()->name()) |
|
762 | + : esc_html__('Unknown', 'event_espresso') |
|
763 | + ) . ' |
|
764 | 764 | </td> |
765 | 765 | <td class="jst-rght"> |
766 | 766 | ' . EEH_Template::format_currency($payment->amount()) . ' |
@@ -769,81 +769,81 @@ discard block |
||
769 | 769 | ' . $payment->pretty_status(true) . $payment_declined_msg . ' |
770 | 770 | </td> |
771 | 771 | </tr>'; |
772 | - do_action('AHEE__thank_you_page_payment_details_template__after_each_payment', $payment); |
|
773 | - return $html; |
|
774 | - } |
|
775 | - |
|
776 | - |
|
777 | - /** |
|
778 | - * get_payment_details |
|
779 | - * |
|
780 | - * @param EE_Payment[] $payments |
|
781 | - * @return string |
|
782 | - * @throws EE_Error |
|
783 | - * @throws ReflectionException |
|
784 | - */ |
|
785 | - public function get_payment_details($payments = array()) |
|
786 | - { |
|
787 | - // prepare variables for displaying |
|
788 | - $template_args = array(); |
|
789 | - $template_args['transaction'] = $this->_current_txn; |
|
790 | - $template_args['reg_url_link'] = $this->_reg_url_link; |
|
791 | - $template_args['payments'] = array(); |
|
792 | - foreach ($payments as $payment) { |
|
793 | - $template_args['payments'][] = $this->get_payment_row_html($payment); |
|
794 | - } |
|
795 | - // create a hacky payment object, but dont save it |
|
796 | - $payment = EE_Payment::new_instance( |
|
797 | - array( |
|
798 | - 'TXN_ID' => $this->_current_txn->ID(), |
|
799 | - 'STS_ID' => EEM_Payment::status_id_pending, |
|
800 | - 'PAY_timestamp' => time(), |
|
801 | - 'PAY_amount' => $this->_current_txn->total(), |
|
802 | - 'PMD_ID' => $this->_current_txn->payment_method_ID(), |
|
803 | - ) |
|
804 | - ); |
|
805 | - $payment_method = $this->_current_txn->payment_method(); |
|
806 | - if ($payment_method instanceof EE_Payment_Method && $payment_method->type_obj() instanceof EE_PMT_Base) { |
|
807 | - $template_args['gateway_content'] = $payment_method->type_obj()->payment_overview_content($payment); |
|
808 | - } else { |
|
809 | - $template_args['gateway_content'] = ''; |
|
810 | - } |
|
811 | - // link to SPCO payment_options |
|
812 | - $template_args['show_try_pay_again_link'] = $this->_show_try_pay_again_link; |
|
813 | - $template_args['SPCO_payment_options_url'] = $this->_SPCO_payment_options_url; |
|
814 | - // verify template arguments |
|
815 | - EEH_Template_Validator::verify_instanceof($template_args['transaction'], '$transaction', 'EE_Transaction'); |
|
816 | - EEH_Template_Validator::verify_isnt_null($template_args['payments'], '$payments'); |
|
817 | - EEH_Template_Validator::verify_isnt_null( |
|
818 | - $template_args['show_try_pay_again_link'], |
|
819 | - '$show_try_pay_again_link' |
|
820 | - ); |
|
821 | - EEH_Template_Validator::verify_isnt_null($template_args['gateway_content'], '$gateway_content'); |
|
822 | - EEH_Template_Validator::verify_isnt_null( |
|
823 | - $template_args['SPCO_payment_options_url'], |
|
824 | - '$SPCO_payment_options_url' |
|
825 | - ); |
|
826 | - return EEH_Template::locate_template( |
|
827 | - THANK_YOU_TEMPLATES_PATH . 'thank-you-page-payment-details.template.php', |
|
828 | - $template_args |
|
829 | - ); |
|
830 | - } |
|
831 | - |
|
832 | - |
|
833 | - /** |
|
834 | - * get_payment_details |
|
835 | - * |
|
836 | - * @param array $payments |
|
837 | - * @return string |
|
838 | - * @throws EE_Error |
|
839 | - */ |
|
840 | - public function get_new_payments($payments = array()) |
|
841 | - { |
|
842 | - $payments_html = ''; |
|
843 | - // prepare variables for displaying |
|
844 | - foreach ($payments as $payment) { |
|
845 | - $payments_html .= $this->get_payment_row_html($payment); |
|
846 | - } |
|
847 | - return $payments_html; |
|
848 | - } |
|
772 | + do_action('AHEE__thank_you_page_payment_details_template__after_each_payment', $payment); |
|
773 | + return $html; |
|
774 | + } |
|
775 | + |
|
776 | + |
|
777 | + /** |
|
778 | + * get_payment_details |
|
779 | + * |
|
780 | + * @param EE_Payment[] $payments |
|
781 | + * @return string |
|
782 | + * @throws EE_Error |
|
783 | + * @throws ReflectionException |
|
784 | + */ |
|
785 | + public function get_payment_details($payments = array()) |
|
786 | + { |
|
787 | + // prepare variables for displaying |
|
788 | + $template_args = array(); |
|
789 | + $template_args['transaction'] = $this->_current_txn; |
|
790 | + $template_args['reg_url_link'] = $this->_reg_url_link; |
|
791 | + $template_args['payments'] = array(); |
|
792 | + foreach ($payments as $payment) { |
|
793 | + $template_args['payments'][] = $this->get_payment_row_html($payment); |
|
794 | + } |
|
795 | + // create a hacky payment object, but dont save it |
|
796 | + $payment = EE_Payment::new_instance( |
|
797 | + array( |
|
798 | + 'TXN_ID' => $this->_current_txn->ID(), |
|
799 | + 'STS_ID' => EEM_Payment::status_id_pending, |
|
800 | + 'PAY_timestamp' => time(), |
|
801 | + 'PAY_amount' => $this->_current_txn->total(), |
|
802 | + 'PMD_ID' => $this->_current_txn->payment_method_ID(), |
|
803 | + ) |
|
804 | + ); |
|
805 | + $payment_method = $this->_current_txn->payment_method(); |
|
806 | + if ($payment_method instanceof EE_Payment_Method && $payment_method->type_obj() instanceof EE_PMT_Base) { |
|
807 | + $template_args['gateway_content'] = $payment_method->type_obj()->payment_overview_content($payment); |
|
808 | + } else { |
|
809 | + $template_args['gateway_content'] = ''; |
|
810 | + } |
|
811 | + // link to SPCO payment_options |
|
812 | + $template_args['show_try_pay_again_link'] = $this->_show_try_pay_again_link; |
|
813 | + $template_args['SPCO_payment_options_url'] = $this->_SPCO_payment_options_url; |
|
814 | + // verify template arguments |
|
815 | + EEH_Template_Validator::verify_instanceof($template_args['transaction'], '$transaction', 'EE_Transaction'); |
|
816 | + EEH_Template_Validator::verify_isnt_null($template_args['payments'], '$payments'); |
|
817 | + EEH_Template_Validator::verify_isnt_null( |
|
818 | + $template_args['show_try_pay_again_link'], |
|
819 | + '$show_try_pay_again_link' |
|
820 | + ); |
|
821 | + EEH_Template_Validator::verify_isnt_null($template_args['gateway_content'], '$gateway_content'); |
|
822 | + EEH_Template_Validator::verify_isnt_null( |
|
823 | + $template_args['SPCO_payment_options_url'], |
|
824 | + '$SPCO_payment_options_url' |
|
825 | + ); |
|
826 | + return EEH_Template::locate_template( |
|
827 | + THANK_YOU_TEMPLATES_PATH . 'thank-you-page-payment-details.template.php', |
|
828 | + $template_args |
|
829 | + ); |
|
830 | + } |
|
831 | + |
|
832 | + |
|
833 | + /** |
|
834 | + * get_payment_details |
|
835 | + * |
|
836 | + * @param array $payments |
|
837 | + * @return string |
|
838 | + * @throws EE_Error |
|
839 | + */ |
|
840 | + public function get_new_payments($payments = array()) |
|
841 | + { |
|
842 | + $payments_html = ''; |
|
843 | + // prepare variables for displaying |
|
844 | + foreach ($payments as $payment) { |
|
845 | + $payments_html .= $this->get_payment_row_html($payment); |
|
846 | + } |
|
847 | + return $payments_html; |
|
848 | + } |
|
849 | 849 | } |
@@ -14,7 +14,7 @@ discard block |
||
14 | 14 | |
15 | 15 | <div id="ee-single-page-checkout-dv" class=""> |
16 | 16 | <?php |
17 | - if (! $empty_cart) { |
|
17 | + if ( ! $empty_cart) { |
|
18 | 18 | if (apply_filters('FHEE__registration_page_wrapper_template__display_time_limit', false)) { ?> |
19 | 19 | <p id="spco-registration-time-limit-pg" class="spco-steps-pg ee-attention important-notice" |
20 | 20 | style="display: none;"> |
@@ -31,7 +31,7 @@ discard block |
||
31 | 31 | <span id="spco-registration-expiration-spn" class="" style="display:none;"></span> |
32 | 32 | </p> |
33 | 33 | <?php } |
34 | - if (! $revisit && apply_filters('FHEE__registration_page_wrapper_template__steps_display', true)) { |
|
34 | + if ( ! $revisit && apply_filters('FHEE__registration_page_wrapper_template__steps_display', true)) { |
|
35 | 35 | ?> |
36 | 36 | <h2 id="spco-steps-big-hdr" class="spco-steps-big-hdr"> |
37 | 37 | <?php esc_html_e(' Steps', 'event_espresso'); ?> |
@@ -77,7 +77,7 @@ discard block |
||
77 | 77 | foreach ($reg_steps as $reg_step) { |
78 | 78 | if ($reg_step instanceof EE_SPCO_Reg_Step && $reg_step->slug() != 'finalize_registration') { |
79 | 79 | $slug = $reg_step->slug(); |
80 | - do_action('AHEE__' . $slug . '__reg_step_start', $reg_step); |
|
80 | + do_action('AHEE__'.$slug.'__reg_step_start', $reg_step); |
|
81 | 81 | // todo: deprecate hook AHEE__registration_page_attendee_information__start |
82 | 82 | ?> |
83 | 83 | <div id="spco-<?php echo esc_attr($slug); ?>-dv" |
@@ -16,38 +16,38 @@ discard block |
||
16 | 16 | |
17 | 17 | <div id="ee-single-page-checkout-dv" class=""> |
18 | 18 | <?php |
19 | - if (! $empty_cart) { |
|
20 | - if (apply_filters('FHEE__registration_page_wrapper_template__display_time_limit', false)) { ?> |
|
19 | + if (! $empty_cart) { |
|
20 | + if (apply_filters('FHEE__registration_page_wrapper_template__display_time_limit', false)) { ?> |
|
21 | 21 | <p id="spco-registration-time-limit-pg" class="spco-steps-pg ee-attention important-notice" |
22 | 22 | style="display: none;"> |
23 | 23 | <?php echo sprintf( |
24 | - apply_filters( |
|
25 | - 'FHEE__registration_page_wrapper_template___time_limit', |
|
26 | - esc_html__('You have %1$s to complete your registration.', 'event_espresso') |
|
27 | - ), |
|
28 | - '<span id="spco-registration-time-limit-spn" class="spco-registration-time-limit-spn">' |
|
29 | - . $registration_time_limit |
|
30 | - . '</span>' |
|
31 | - ); |
|
32 | - ?> |
|
24 | + apply_filters( |
|
25 | + 'FHEE__registration_page_wrapper_template___time_limit', |
|
26 | + esc_html__('You have %1$s to complete your registration.', 'event_espresso') |
|
27 | + ), |
|
28 | + '<span id="spco-registration-time-limit-spn" class="spco-registration-time-limit-spn">' |
|
29 | + . $registration_time_limit |
|
30 | + . '</span>' |
|
31 | + ); |
|
32 | + ?> |
|
33 | 33 | <span id="spco-registration-expiration-spn" class="" style="display:none;"></span> |
34 | 34 | </p> |
35 | 35 | <?php } |
36 | - if (! $revisit && apply_filters('FHEE__registration_page_wrapper_template__steps_display', true)) { |
|
37 | - ?> |
|
36 | + if (! $revisit && apply_filters('FHEE__registration_page_wrapper_template__steps_display', true)) { |
|
37 | + ?> |
|
38 | 38 | <h2 id="spco-steps-big-hdr" class="spco-steps-big-hdr"> |
39 | 39 | <?php esc_html_e(' Steps', 'event_espresso'); ?> |
40 | 40 | </h2> |
41 | 41 | |
42 | 42 | <div id="spco-steps-display-dv"> |
43 | 43 | <?php |
44 | - $step_nmbr = 1; |
|
45 | - $total_steps = count($reg_steps) - 1; |
|
46 | - foreach ($reg_steps as $reg_step) { |
|
47 | - if ($reg_step instanceof EE_SPCO_Reg_Step && $reg_step->slug() != 'finalize_registration') { |
|
48 | - $slug = $reg_step->slug(); |
|
49 | - $step_display_dv_class = $reg_step->is_current_step() ? 'active-step' : 'inactive-step'; |
|
50 | - ?> |
|
44 | + $step_nmbr = 1; |
|
45 | + $total_steps = count($reg_steps) - 1; |
|
46 | + foreach ($reg_steps as $reg_step) { |
|
47 | + if ($reg_step instanceof EE_SPCO_Reg_Step && $reg_step->slug() != 'finalize_registration') { |
|
48 | + $slug = $reg_step->slug(); |
|
49 | + $step_display_dv_class = $reg_step->is_current_step() ? 'active-step' : 'inactive-step'; |
|
50 | + ?> |
|
51 | 51 | <div id="spco-step-<?php echo esc_attr($slug); ?>-display-dv" |
52 | 52 | class="spco-step-display-dv <?php echo esc_attr($step_display_dv_class); ?> steps-<?php echo esc_attr($total_steps); ?>" |
53 | 53 | > |
@@ -60,28 +60,28 @@ discard block |
||
60 | 60 | </div> |
61 | 61 | |
62 | 62 | <?php |
63 | - if ($step_nmbr < $total_steps) { ?> |
|
63 | + if ($step_nmbr < $total_steps) { ?> |
|
64 | 64 | <div class="spco-step-arrow-dv">»</div> |
65 | 65 | <?php |
66 | - } |
|
67 | - $step_nmbr++; |
|
68 | - } |
|
69 | - } |
|
70 | - ?> |
|
66 | + } |
|
67 | + $step_nmbr++; |
|
68 | + } |
|
69 | + } |
|
70 | + ?> |
|
71 | 71 | <div class="clear-float"></div> |
72 | 72 | </div> |
73 | 73 | |
74 | 74 | <?php |
75 | - } |
|
75 | + } |
|
76 | 76 | |
77 | - do_action('AHEE__SPCO__before_registration_steps'); |
|
78 | - $step_nmbr = 1; |
|
79 | - foreach ($reg_steps as $reg_step) { |
|
80 | - if ($reg_step instanceof EE_SPCO_Reg_Step && $reg_step->slug() != 'finalize_registration') { |
|
81 | - $slug = $reg_step->slug(); |
|
82 | - do_action('AHEE__' . $slug . '__reg_step_start', $reg_step); |
|
83 | - // todo: deprecate hook AHEE__registration_page_attendee_information__start |
|
84 | - ?> |
|
77 | + do_action('AHEE__SPCO__before_registration_steps'); |
|
78 | + $step_nmbr = 1; |
|
79 | + foreach ($reg_steps as $reg_step) { |
|
80 | + if ($reg_step instanceof EE_SPCO_Reg_Step && $reg_step->slug() != 'finalize_registration') { |
|
81 | + $slug = $reg_step->slug(); |
|
82 | + do_action('AHEE__' . $slug . '__reg_step_start', $reg_step); |
|
83 | + // todo: deprecate hook AHEE__registration_page_attendee_information__start |
|
84 | + ?> |
|
85 | 85 | <div id="spco-<?php echo esc_attr($slug); ?>-dv" |
86 | 86 | class="spco-step-dv <?php echo esc_attr($reg_step->div_class()); ?>" |
87 | 87 | > |
@@ -89,20 +89,20 @@ discard block |
||
89 | 89 | <?php do_action('AHEE__SPCO_after_reg_step_form', $slug, $next_step); ?> |
90 | 90 | </div> |
91 | 91 | <?php $step_nmbr++; |
92 | - } |
|
93 | - } |
|
94 | - do_action('AHEE__SPCO__after_registration_steps'); |
|
95 | - } else { |
|
96 | - ?> |
|
92 | + } |
|
93 | + } |
|
94 | + do_action('AHEE__SPCO__after_registration_steps'); |
|
95 | + } else { |
|
96 | + ?> |
|
97 | 97 | <h3 id="spco-empty-cart-hdr" class="spco-step-title-hdr"> |
98 | 98 | <?php esc_html_e('Nothing in your Event Queue', 'event_espresso'); ?> |
99 | 99 | </h3> |
100 | 100 | <p><?php echo wp_kses($empty_msg, AllowedTags::getWithFormTags()); ?></p> |
101 | 101 | <?php echo wp_kses($cookies_not_set_msg, AllowedTags::getWithFormTags()); ?> |
102 | 102 | <?php |
103 | - } |
|
104 | - do_action('AHEE__SPCO__reg_form_footer'); |
|
105 | - ?> |
|
103 | + } |
|
104 | + do_action('AHEE__SPCO__reg_form_footer'); |
|
105 | + ?> |
|
106 | 106 | |
107 | 107 | </div> |
108 | 108 |
@@ -3,36 +3,36 @@ |
||
3 | 3 | /** @type array $registrations_for_free_events */ |
4 | 4 | |
5 | 5 | if (is_array($registrations_for_free_events) && ! empty($registrations_for_free_events)) { |
6 | - echo apply_filters( |
|
7 | - 'FHEE__registration_page_payment_options__no_payment_required_hdr', |
|
8 | - sprintf( |
|
9 | - esc_html__('%1$sNo Payment Required%2$s', 'event_espresso'), |
|
10 | - '<h6>', |
|
11 | - '</h6>' |
|
12 | - ) |
|
13 | - ); |
|
14 | - foreach ($registrations_for_free_events as $registration_for_free_event) { |
|
15 | - if ( |
|
16 | - $registration_for_free_event instanceof EE_Registration |
|
17 | - && $registration_for_free_event->ticket()->is_free() |
|
18 | - ) { |
|
19 | - if ($registration_for_free_event->event() instanceof EE_Event) { |
|
20 | - ?> |
|
6 | + echo apply_filters( |
|
7 | + 'FHEE__registration_page_payment_options__no_payment_required_hdr', |
|
8 | + sprintf( |
|
9 | + esc_html__('%1$sNo Payment Required%2$s', 'event_espresso'), |
|
10 | + '<h6>', |
|
11 | + '</h6>' |
|
12 | + ) |
|
13 | + ); |
|
14 | + foreach ($registrations_for_free_events as $registration_for_free_event) { |
|
15 | + if ( |
|
16 | + $registration_for_free_event instanceof EE_Registration |
|
17 | + && $registration_for_free_event->ticket()->is_free() |
|
18 | + ) { |
|
19 | + if ($registration_for_free_event->event() instanceof EE_Event) { |
|
20 | + ?> |
|
21 | 21 | <p> |
22 | 22 | <?php echo apply_filters( |
23 | - 'FHEE__registration_page_payment_options__no_payment_required_pg', |
|
24 | - sprintf( |
|
25 | - esc_html__( |
|
26 | - '"%1$s" for "%2$s" is free, so no payment is required and no billing will occur.', |
|
27 | - 'event_espresso' |
|
28 | - ), |
|
29 | - $registration_for_free_event->ticket()->name(), |
|
30 | - $registration_for_free_event->event()->name() |
|
31 | - ) |
|
32 | - ); ?> |
|
23 | + 'FHEE__registration_page_payment_options__no_payment_required_pg', |
|
24 | + sprintf( |
|
25 | + esc_html__( |
|
26 | + '"%1$s" for "%2$s" is free, so no payment is required and no billing will occur.', |
|
27 | + 'event_espresso' |
|
28 | + ), |
|
29 | + $registration_for_free_event->ticket()->name(), |
|
30 | + $registration_for_free_event->event()->name() |
|
31 | + ) |
|
32 | + ); ?> |
|
33 | 33 | </p> |
34 | 34 | <?php |
35 | - } |
|
36 | - } |
|
37 | - } |
|
35 | + } |
|
36 | + } |
|
37 | + } |
|
38 | 38 | } |
@@ -91,7 +91,7 @@ discard block |
||
91 | 91 | $ticket_price_includes_taxes = esc_html__('* price does not include taxes', 'event_espresso'); |
92 | 92 | } |
93 | 93 | echo '<p class="small-text lt-grey-text" style="text-align:right; margin: -1em 0 1em;"> |
94 | - ' . $ticket_price_includes_taxes . ' |
|
94 | + ' . $ticket_price_includes_taxes.' |
|
95 | 95 | </p>'; |
96 | 96 | } |
97 | 97 | ?> |
@@ -105,7 +105,7 @@ discard block |
||
105 | 105 | esc_html('') |
106 | 106 | ); |
107 | 107 | } |
108 | -if (! apply_filters('FHEE__EE_Ticket_Selector__display_ticket_selector_submit', false)) { |
|
108 | +if ( ! apply_filters('FHEE__EE_Ticket_Selector__display_ticket_selector_submit', false)) { |
|
109 | 109 | add_filter('FHEE__EE_Ticket_Selector__no_ticket_selector_submit', '__return_true'); |
110 | 110 | } |
111 | 111 | do_action('AHEE__ticket_selector_chart__template__after_ticket_selector', $EVT_ID, $event); |
@@ -29,12 +29,12 @@ discard block |
||
29 | 29 | <tr> |
30 | 30 | <th id="details-<?php echo esc_attr($EVT_ID); ?>" scope="col" class="ee-ticket-selector-ticket-details-th"> |
31 | 31 | <?php |
32 | - echo apply_filters( |
|
33 | - 'FHEE__ticket_selector_chart_template__table_header_available_tickets', |
|
34 | - esc_html__('Details', 'event_espresso'), |
|
35 | - $EVT_ID |
|
36 | - ); |
|
37 | - ?> |
|
32 | + echo apply_filters( |
|
33 | + 'FHEE__ticket_selector_chart_template__table_header_available_tickets', |
|
34 | + esc_html__('Details', 'event_espresso'), |
|
35 | + $EVT_ID |
|
36 | + ); |
|
37 | + ?> |
|
38 | 38 | </th> |
39 | 39 | <?php if (apply_filters('FHEE__ticket_selector_chart_template__display_ticket_price_details', true)) { ?> |
40 | 40 | <th id="price-<?php echo esc_attr($EVT_ID); ?>" scope="col" class="ee-ticket-selector-ticket-price-th |
@@ -53,12 +53,12 @@ discard block |
||
53 | 53 | </table> |
54 | 54 | <?php |
55 | 55 | if ($taxable_tickets && apply_filters('FHEE__ticket_selector_chart_template__display_ticket_price_details', true)) { |
56 | - if ($prices_displayed_including_taxes) { |
|
57 | - $ticket_price_includes_taxes = esc_html__('* price includes taxes', 'event_espresso'); |
|
58 | - } else { |
|
59 | - $ticket_price_includes_taxes = esc_html__('* price does not include taxes', 'event_espresso'); |
|
60 | - } |
|
61 | - echo '<p class="small-text lt-grey-text" style="text-align:right; margin: -1em 0 1em;"> |
|
56 | + if ($prices_displayed_including_taxes) { |
|
57 | + $ticket_price_includes_taxes = esc_html__('* price includes taxes', 'event_espresso'); |
|
58 | + } else { |
|
59 | + $ticket_price_includes_taxes = esc_html__('* price does not include taxes', 'event_espresso'); |
|
60 | + } |
|
61 | + echo '<p class="small-text lt-grey-text" style="text-align:right; margin: -1em 0 1em;"> |
|
62 | 62 | ' . $ticket_price_includes_taxes . ' |
63 | 63 | </p>'; |
64 | 64 | } |
@@ -68,12 +68,12 @@ discard block |
||
68 | 68 | |
69 | 69 | <?php |
70 | 70 | if ($max_atndz > 0) { |
71 | - echo apply_filters( |
|
72 | - 'FHEE__ticket_selector_chart_template__maximum_tickets_purchased_footnote', |
|
73 | - esc_html('') |
|
74 | - ); |
|
71 | + echo apply_filters( |
|
72 | + 'FHEE__ticket_selector_chart_template__maximum_tickets_purchased_footnote', |
|
73 | + esc_html('') |
|
74 | + ); |
|
75 | 75 | } |
76 | 76 | if (! apply_filters('FHEE__EE_Ticket_Selector__display_ticket_selector_submit', false)) { |
77 | - add_filter('FHEE__EE_Ticket_Selector__no_ticket_selector_submit', '__return_true'); |
|
77 | + add_filter('FHEE__EE_Ticket_Selector__no_ticket_selector_submit', '__return_true'); |
|
78 | 78 | } |
79 | 79 | do_action('AHEE__ticket_selector_chart__template__after_ticket_selector', $EVT_ID, $event); |