@@ -48,7 +48,7 @@ discard block |
||
48 | 48 | protected static $_incompatible_addons = array( |
49 | 49 | 'Multi_Event_Registration' => '2.0.11.rc.002', |
50 | 50 | 'Promotions' => '1.0.0.rc.084', |
51 | - ); |
|
51 | + ); |
|
52 | 52 | |
53 | 53 | |
54 | 54 | |
@@ -219,660 +219,660 @@ discard block |
||
219 | 219 | */ |
220 | 220 | public static function register( $addon_name = '', $setup_args = array() ) { |
221 | 221 | // required fields MUST be present, so let's make sure they are. |
222 | - \EE_Register_Addon::_verify_parameters($addon_name, $setup_args); |
|
223 | - // get class name for addon |
|
222 | + \EE_Register_Addon::_verify_parameters($addon_name, $setup_args); |
|
223 | + // get class name for addon |
|
224 | 224 | $class_name = \EE_Register_Addon::_parse_class_name($addon_name, $setup_args); |
225 | 225 | //setup $_settings array from incoming values. |
226 | - $addon_settings = \EE_Register_Addon::_get_addon_settings($class_name, $setup_args); |
|
227 | - // setup PUE |
|
228 | - \EE_Register_Addon::_parse_pue_options($addon_name, $class_name, $setup_args); |
|
229 | - // does this addon work with this version of core or WordPress ? |
|
230 | - if ( ! \EE_Register_Addon::_addon_is_compatible($addon_name, $addon_settings) ) { |
|
231 | - return; |
|
226 | + $addon_settings = \EE_Register_Addon::_get_addon_settings($class_name, $setup_args); |
|
227 | + // setup PUE |
|
228 | + \EE_Register_Addon::_parse_pue_options($addon_name, $class_name, $setup_args); |
|
229 | + // does this addon work with this version of core or WordPress ? |
|
230 | + if ( ! \EE_Register_Addon::_addon_is_compatible($addon_name, $addon_settings) ) { |
|
231 | + return; |
|
232 | 232 | } |
233 | 233 | // register namespaces |
234 | - \EE_Register_Addon::_setup_namespaces($addon_settings); |
|
235 | - // check if this is an activation request |
|
236 | - if ( \EE_Register_Addon::_addon_activation($addon_name, $addon_settings)) { |
|
237 | - // dont bother setting up the rest of the addon atm |
|
238 | - return; |
|
239 | - } |
|
240 | - // we need cars |
|
241 | - \EE_Register_Addon::_setup_autoloaders($addon_name); |
|
242 | - // register new models and extensions |
|
243 | - \EE_Register_Addon::_register_models_and_extensions($addon_name); |
|
244 | - // setup DMS |
|
245 | - \EE_Register_Addon::_register_data_migration_scripts($addon_name); |
|
246 | - // if config_class is present let's register config. |
|
247 | - \EE_Register_Addon::_register_config($addon_name); |
|
248 | - // register admin pages |
|
249 | - \EE_Register_Addon::_register_admin_pages($addon_name); |
|
250 | - // add to list of modules to be registered |
|
251 | - \EE_Register_Addon::_register_modules($addon_name); |
|
252 | - // add to list of shortcodes to be registered |
|
253 | - \EE_Register_Addon::_register_shortcodes($addon_name); |
|
254 | - // add to list of widgets to be registered |
|
255 | - \EE_Register_Addon::_register_widgets($addon_name); |
|
256 | - // register capability related stuff. |
|
257 | - \EE_Register_Addon::_register_capabilities($addon_name); |
|
258 | - // any message type to register? |
|
259 | - \EE_Register_Addon::_register_message_types($addon_name); |
|
234 | + \EE_Register_Addon::_setup_namespaces($addon_settings); |
|
235 | + // check if this is an activation request |
|
236 | + if ( \EE_Register_Addon::_addon_activation($addon_name, $addon_settings)) { |
|
237 | + // dont bother setting up the rest of the addon atm |
|
238 | + return; |
|
239 | + } |
|
240 | + // we need cars |
|
241 | + \EE_Register_Addon::_setup_autoloaders($addon_name); |
|
242 | + // register new models and extensions |
|
243 | + \EE_Register_Addon::_register_models_and_extensions($addon_name); |
|
244 | + // setup DMS |
|
245 | + \EE_Register_Addon::_register_data_migration_scripts($addon_name); |
|
246 | + // if config_class is present let's register config. |
|
247 | + \EE_Register_Addon::_register_config($addon_name); |
|
248 | + // register admin pages |
|
249 | + \EE_Register_Addon::_register_admin_pages($addon_name); |
|
250 | + // add to list of modules to be registered |
|
251 | + \EE_Register_Addon::_register_modules($addon_name); |
|
252 | + // add to list of shortcodes to be registered |
|
253 | + \EE_Register_Addon::_register_shortcodes($addon_name); |
|
254 | + // add to list of widgets to be registered |
|
255 | + \EE_Register_Addon::_register_widgets($addon_name); |
|
256 | + // register capability related stuff. |
|
257 | + \EE_Register_Addon::_register_capabilities($addon_name); |
|
258 | + // any message type to register? |
|
259 | + \EE_Register_Addon::_register_message_types($addon_name); |
|
260 | 260 | // any custom post type/ custom capabilities or default terms to register |
261 | - \EE_Register_Addon::_register_custom_post_types($addon_name); |
|
262 | - // and any payment methods |
|
263 | - \EE_Register_Addon::_register_payment_methods($addon_name); |
|
261 | + \EE_Register_Addon::_register_custom_post_types($addon_name); |
|
262 | + // and any payment methods |
|
263 | + \EE_Register_Addon::_register_payment_methods($addon_name); |
|
264 | 264 | // load and instantiate main addon class |
265 | - $addon = \EE_Register_Addon::_load_and_init_addon_class($addon_name); |
|
266 | - $addon->after_registration(); |
|
267 | - } |
|
268 | - |
|
269 | - |
|
270 | - |
|
271 | - /** |
|
272 | - * @param string $addon_name |
|
273 | - * @param array $setup_args |
|
274 | - * @return void |
|
275 | - * @throws \EE_Error |
|
276 | - */ |
|
277 | - private static function _verify_parameters($addon_name, array $setup_args) |
|
278 | - { |
|
279 | - // required fields MUST be present, so let's make sure they are. |
|
280 | - if (empty($addon_name) || ! is_array($setup_args)) { |
|
281 | - throw new EE_Error( |
|
282 | - __( |
|
283 | - 'In order to register an EE_Addon with EE_Register_Addon::register(), you must include the "addon_name" (the name of the addon), and an array of arguments.', |
|
284 | - 'event_espresso' |
|
285 | - ) |
|
286 | - ); |
|
287 | - } |
|
288 | - if ( ! isset($setup_args['main_file_path']) || empty($setup_args['main_file_path'])) { |
|
289 | - throw new EE_Error( |
|
290 | - sprintf( |
|
291 | - __( |
|
292 | - 'When registering an addon, you didn\'t provide the "main_file_path", which is the full path to the main file loaded directly by Wordpress. You only provided %s', |
|
293 | - 'event_espresso' |
|
294 | - ), |
|
295 | - implode(',', array_keys($setup_args)) |
|
296 | - ) |
|
297 | - ); |
|
298 | - } |
|
299 | - // check that addon has not already been registered with that name |
|
300 | - if (isset(self::$_settings[$addon_name]) && ! did_action('activate_plugin')) { |
|
301 | - throw new EE_Error( |
|
302 | - sprintf( |
|
303 | - __( |
|
304 | - 'An EE_Addon with the name "%s" has already been registered and each EE_Addon requires a unique name.', |
|
305 | - 'event_espresso' |
|
306 | - ), |
|
307 | - $addon_name |
|
308 | - ) |
|
309 | - ); |
|
310 | - } |
|
265 | + $addon = \EE_Register_Addon::_load_and_init_addon_class($addon_name); |
|
266 | + $addon->after_registration(); |
|
267 | + } |
|
268 | + |
|
269 | + |
|
270 | + |
|
271 | + /** |
|
272 | + * @param string $addon_name |
|
273 | + * @param array $setup_args |
|
274 | + * @return void |
|
275 | + * @throws \EE_Error |
|
276 | + */ |
|
277 | + private static function _verify_parameters($addon_name, array $setup_args) |
|
278 | + { |
|
279 | + // required fields MUST be present, so let's make sure they are. |
|
280 | + if (empty($addon_name) || ! is_array($setup_args)) { |
|
281 | + throw new EE_Error( |
|
282 | + __( |
|
283 | + 'In order to register an EE_Addon with EE_Register_Addon::register(), you must include the "addon_name" (the name of the addon), and an array of arguments.', |
|
284 | + 'event_espresso' |
|
285 | + ) |
|
286 | + ); |
|
287 | + } |
|
288 | + if ( ! isset($setup_args['main_file_path']) || empty($setup_args['main_file_path'])) { |
|
289 | + throw new EE_Error( |
|
290 | + sprintf( |
|
291 | + __( |
|
292 | + 'When registering an addon, you didn\'t provide the "main_file_path", which is the full path to the main file loaded directly by Wordpress. You only provided %s', |
|
293 | + 'event_espresso' |
|
294 | + ), |
|
295 | + implode(',', array_keys($setup_args)) |
|
296 | + ) |
|
297 | + ); |
|
298 | + } |
|
299 | + // check that addon has not already been registered with that name |
|
300 | + if (isset(self::$_settings[$addon_name]) && ! did_action('activate_plugin')) { |
|
301 | + throw new EE_Error( |
|
302 | + sprintf( |
|
303 | + __( |
|
304 | + 'An EE_Addon with the name "%s" has already been registered and each EE_Addon requires a unique name.', |
|
305 | + 'event_espresso' |
|
306 | + ), |
|
307 | + $addon_name |
|
308 | + ) |
|
309 | + ); |
|
310 | + } |
|
311 | 311 | } |
312 | 312 | |
313 | 313 | |
314 | 314 | |
315 | - /** |
|
316 | - * @param string $addon_name |
|
317 | - * @param array $setup_args |
|
318 | - * @return string |
|
319 | - */ |
|
320 | - private static function _parse_class_name($addon_name, array $setup_args) |
|
321 | - { |
|
322 | - if (empty($setup_args['class_name'])) { |
|
323 | - // generate one by first separating name with spaces |
|
324 | - $class_name = str_replace(array('-', '_'), ' ', trim($addon_name)); |
|
325 | - //capitalize, then replace spaces with underscores |
|
326 | - $class_name = str_replace(' ', '_', ucwords($class_name)); |
|
327 | - } else { |
|
328 | - $class_name = $setup_args['class_name']; |
|
329 | - } |
|
330 | - return strpos($class_name, 'EE_') === 0 ? $class_name : 'EE_' . $class_name; |
|
331 | - } |
|
332 | - |
|
333 | - |
|
334 | - |
|
335 | - /** |
|
336 | - * @param string $class_name |
|
337 | - * @param array $setup_args |
|
338 | - * @return array |
|
339 | - */ |
|
340 | - private static function _get_addon_settings($class_name, array $setup_args) |
|
341 | - { |
|
342 | - //setup $_settings array from incoming values. |
|
343 | - $addon_settings = array( |
|
344 | - // generated from the addon name, changes something like "calendar" to "EE_Calendar" |
|
345 | - 'class_name' => $class_name, |
|
346 | - // the addon slug for use in URLs, etc |
|
347 | - 'plugin_slug' => isset($setup_args['plugin_slug']) |
|
348 | - ? (string)$setup_args['plugin_slug'] |
|
349 | - : '', |
|
350 | - // page slug to be used when generating the "Settings" link on the WP plugin page |
|
351 | - 'plugin_action_slug' => isset($setup_args['plugin_action_slug']) |
|
352 | - ? (string)$setup_args['plugin_action_slug'] |
|
353 | - : '', |
|
354 | - // the "software" version for the addon |
|
355 | - 'version' => isset($setup_args['version']) |
|
356 | - ? (string)$setup_args['version'] |
|
357 | - : '', |
|
358 | - // the minimum version of EE Core that the addon will work with |
|
359 | - 'min_core_version' => isset($setup_args['min_core_version']) |
|
360 | - ? (string)$setup_args['min_core_version'] |
|
361 | - : '', |
|
362 | - // the minimum version of WordPress that the addon will work with |
|
363 | - 'min_wp_version' => isset($setup_args['min_wp_version']) |
|
364 | - ? (string)$setup_args['min_wp_version'] |
|
365 | - : EE_MIN_WP_VER_REQUIRED, |
|
366 | - // full server path to main file (file loaded directly by WP) |
|
367 | - 'main_file_path' => isset($setup_args['main_file_path']) |
|
368 | - ? (string)$setup_args['main_file_path'] |
|
369 | - : '', |
|
370 | - // path to folder containing files for integrating with the EE core admin and/or setting up EE admin pages |
|
371 | - 'admin_path' => isset($setup_args['admin_path']) |
|
372 | - ? (string)$setup_args['admin_path'] : '', |
|
373 | - // a method to be called when the EE Admin is first invoked, can be used for hooking into any admin page |
|
374 | - 'admin_callback' => isset($setup_args['admin_callback']) |
|
375 | - ? (string)$setup_args['admin_callback'] |
|
376 | - : '', |
|
377 | - // the section name for this addon's configuration settings section (defaults to "addons") |
|
378 | - 'config_section' => isset($setup_args['config_section']) |
|
379 | - ? (string)$setup_args['config_section'] |
|
380 | - : 'addons', |
|
381 | - // the class name for this addon's configuration settings object |
|
382 | - 'config_class' => isset($setup_args['config_class']) |
|
383 | - ? (string)$setup_args['config_class'] : '', |
|
384 | - //the name given to the config for this addons' configuration settings object (optional) |
|
385 | - 'config_name' => isset($setup_args['config_name']) |
|
386 | - ? (string)$setup_args['config_name'] : '', |
|
387 | - // an array of "class names" => "full server paths" for any classes that might be invoked by the addon |
|
388 | - 'autoloader_paths' => isset($setup_args['autoloader_paths']) |
|
389 | - ? (array)$setup_args['autoloader_paths'] |
|
390 | - : array(), |
|
391 | - // an array of "full server paths" for any folders containing classes that might be invoked by the addon |
|
392 | - 'autoloader_folders' => isset($setup_args['autoloader_folders']) |
|
393 | - ? (array)$setup_args['autoloader_folders'] |
|
394 | - : array(), |
|
395 | - // array of full server paths to any EE_DMS data migration scripts used by the addon |
|
396 | - 'dms_paths' => isset($setup_args['dms_paths']) |
|
397 | - ? (array)$setup_args['dms_paths'] |
|
398 | - : array(), |
|
399 | - // array of full server paths to any EED_Modules used by the addon |
|
400 | - 'module_paths' => isset($setup_args['module_paths']) |
|
401 | - ? (array)$setup_args['module_paths'] |
|
402 | - : array(), |
|
403 | - // array of full server paths to any EES_Shortcodes used by the addon |
|
404 | - 'shortcode_paths' => isset($setup_args['shortcode_paths']) |
|
405 | - ? (array)$setup_args['shortcode_paths'] |
|
406 | - : array(), |
|
407 | - // array of full server paths to any WP_Widgets used by the addon |
|
408 | - 'widget_paths' => isset($setup_args['widget_paths']) |
|
409 | - ? (array)$setup_args['widget_paths'] |
|
410 | - : array(), |
|
411 | - // array of PUE options used by the addon |
|
412 | - 'pue_options' => isset($setup_args['pue_options']) |
|
413 | - ? (array)$setup_args['pue_options'] |
|
414 | - : array(), |
|
415 | - 'message_types' => isset($setup_args['message_types']) |
|
416 | - ? (array)$setup_args['message_types'] |
|
417 | - : array(), |
|
418 | - 'capabilities' => isset($setup_args['capabilities']) |
|
419 | - ? (array)$setup_args['capabilities'] |
|
420 | - : array(), |
|
421 | - 'capability_maps' => isset($setup_args['capability_maps']) |
|
422 | - ? (array)$setup_args['capability_maps'] |
|
423 | - : array(), |
|
424 | - 'model_paths' => isset($setup_args['model_paths']) |
|
425 | - ? (array)$setup_args['model_paths'] |
|
426 | - : array(), |
|
427 | - 'class_paths' => isset($setup_args['class_paths']) |
|
428 | - ? (array)$setup_args['class_paths'] |
|
429 | - : array(), |
|
430 | - 'model_extension_paths' => isset($setup_args['model_extension_paths']) |
|
431 | - ? (array)$setup_args['model_extension_paths'] |
|
432 | - : array(), |
|
433 | - 'class_extension_paths' => isset($setup_args['class_extension_paths']) |
|
434 | - ? (array)$setup_args['class_extension_paths'] |
|
435 | - : array(), |
|
436 | - 'custom_post_types' => isset($setup_args['custom_post_types']) |
|
437 | - ? (array)$setup_args['custom_post_types'] |
|
438 | - : array(), |
|
439 | - 'custom_taxonomies' => isset($setup_args['custom_taxonomies']) |
|
440 | - ? (array)$setup_args['custom_taxonomies'] |
|
441 | - : array(), |
|
442 | - 'payment_method_paths' => isset($setup_args['payment_method_paths']) |
|
443 | - ? (array)$setup_args['payment_method_paths'] |
|
444 | - : array(), |
|
445 | - 'default_terms' => isset($setup_args['default_terms']) |
|
446 | - ? (array)$setup_args['default_terms'] |
|
447 | - : array(), |
|
448 | - // if not empty, inserts a new table row after this plugin's row on the WP Plugins page |
|
449 | - // that can be used for adding upgrading/marketing info |
|
450 | - 'plugins_page_row' => isset($setup_args['plugins_page_row']) |
|
451 | - ? $setup_args['plugins_page_row'] |
|
452 | - : '', |
|
453 | - 'namespace' => isset( |
|
454 | - $setup_args['namespace'], |
|
455 | - $setup_args['namespace']['FQNS'], |
|
456 | - $setup_args['namespace']['DIR'] |
|
457 | - ) |
|
458 | - ? (array)$setup_args['namespace'] |
|
459 | - : array(), |
|
460 | - ); |
|
461 | - // if plugin_action_slug is NOT set, but an admin page path IS set, |
|
462 | - // then let's just use the plugin_slug since that will be used for linking to the admin page |
|
463 | - $addon_settings['plugin_action_slug'] = empty($addon_settings['plugin_action_slug']) |
|
464 | - && ! empty($addon_settings['admin_path']) |
|
465 | - ? $addon_settings['plugin_slug'] |
|
466 | - : $addon_settings['plugin_action_slug']; |
|
467 | - // full server path to main file (file loaded directly by WP) |
|
468 | - $addon_settings['plugin_basename'] = plugin_basename($addon_settings['main_file_path']); |
|
469 | - return $addon_settings; |
|
315 | + /** |
|
316 | + * @param string $addon_name |
|
317 | + * @param array $setup_args |
|
318 | + * @return string |
|
319 | + */ |
|
320 | + private static function _parse_class_name($addon_name, array $setup_args) |
|
321 | + { |
|
322 | + if (empty($setup_args['class_name'])) { |
|
323 | + // generate one by first separating name with spaces |
|
324 | + $class_name = str_replace(array('-', '_'), ' ', trim($addon_name)); |
|
325 | + //capitalize, then replace spaces with underscores |
|
326 | + $class_name = str_replace(' ', '_', ucwords($class_name)); |
|
327 | + } else { |
|
328 | + $class_name = $setup_args['class_name']; |
|
329 | + } |
|
330 | + return strpos($class_name, 'EE_') === 0 ? $class_name : 'EE_' . $class_name; |
|
470 | 331 | } |
471 | 332 | |
472 | 333 | |
473 | 334 | |
474 | - /** |
|
475 | - * @param string $addon_name |
|
476 | - * @param array $addon_settings |
|
477 | - * @return boolean |
|
478 | - */ |
|
335 | + /** |
|
336 | + * @param string $class_name |
|
337 | + * @param array $setup_args |
|
338 | + * @return array |
|
339 | + */ |
|
340 | + private static function _get_addon_settings($class_name, array $setup_args) |
|
341 | + { |
|
342 | + //setup $_settings array from incoming values. |
|
343 | + $addon_settings = array( |
|
344 | + // generated from the addon name, changes something like "calendar" to "EE_Calendar" |
|
345 | + 'class_name' => $class_name, |
|
346 | + // the addon slug for use in URLs, etc |
|
347 | + 'plugin_slug' => isset($setup_args['plugin_slug']) |
|
348 | + ? (string)$setup_args['plugin_slug'] |
|
349 | + : '', |
|
350 | + // page slug to be used when generating the "Settings" link on the WP plugin page |
|
351 | + 'plugin_action_slug' => isset($setup_args['plugin_action_slug']) |
|
352 | + ? (string)$setup_args['plugin_action_slug'] |
|
353 | + : '', |
|
354 | + // the "software" version for the addon |
|
355 | + 'version' => isset($setup_args['version']) |
|
356 | + ? (string)$setup_args['version'] |
|
357 | + : '', |
|
358 | + // the minimum version of EE Core that the addon will work with |
|
359 | + 'min_core_version' => isset($setup_args['min_core_version']) |
|
360 | + ? (string)$setup_args['min_core_version'] |
|
361 | + : '', |
|
362 | + // the minimum version of WordPress that the addon will work with |
|
363 | + 'min_wp_version' => isset($setup_args['min_wp_version']) |
|
364 | + ? (string)$setup_args['min_wp_version'] |
|
365 | + : EE_MIN_WP_VER_REQUIRED, |
|
366 | + // full server path to main file (file loaded directly by WP) |
|
367 | + 'main_file_path' => isset($setup_args['main_file_path']) |
|
368 | + ? (string)$setup_args['main_file_path'] |
|
369 | + : '', |
|
370 | + // path to folder containing files for integrating with the EE core admin and/or setting up EE admin pages |
|
371 | + 'admin_path' => isset($setup_args['admin_path']) |
|
372 | + ? (string)$setup_args['admin_path'] : '', |
|
373 | + // a method to be called when the EE Admin is first invoked, can be used for hooking into any admin page |
|
374 | + 'admin_callback' => isset($setup_args['admin_callback']) |
|
375 | + ? (string)$setup_args['admin_callback'] |
|
376 | + : '', |
|
377 | + // the section name for this addon's configuration settings section (defaults to "addons") |
|
378 | + 'config_section' => isset($setup_args['config_section']) |
|
379 | + ? (string)$setup_args['config_section'] |
|
380 | + : 'addons', |
|
381 | + // the class name for this addon's configuration settings object |
|
382 | + 'config_class' => isset($setup_args['config_class']) |
|
383 | + ? (string)$setup_args['config_class'] : '', |
|
384 | + //the name given to the config for this addons' configuration settings object (optional) |
|
385 | + 'config_name' => isset($setup_args['config_name']) |
|
386 | + ? (string)$setup_args['config_name'] : '', |
|
387 | + // an array of "class names" => "full server paths" for any classes that might be invoked by the addon |
|
388 | + 'autoloader_paths' => isset($setup_args['autoloader_paths']) |
|
389 | + ? (array)$setup_args['autoloader_paths'] |
|
390 | + : array(), |
|
391 | + // an array of "full server paths" for any folders containing classes that might be invoked by the addon |
|
392 | + 'autoloader_folders' => isset($setup_args['autoloader_folders']) |
|
393 | + ? (array)$setup_args['autoloader_folders'] |
|
394 | + : array(), |
|
395 | + // array of full server paths to any EE_DMS data migration scripts used by the addon |
|
396 | + 'dms_paths' => isset($setup_args['dms_paths']) |
|
397 | + ? (array)$setup_args['dms_paths'] |
|
398 | + : array(), |
|
399 | + // array of full server paths to any EED_Modules used by the addon |
|
400 | + 'module_paths' => isset($setup_args['module_paths']) |
|
401 | + ? (array)$setup_args['module_paths'] |
|
402 | + : array(), |
|
403 | + // array of full server paths to any EES_Shortcodes used by the addon |
|
404 | + 'shortcode_paths' => isset($setup_args['shortcode_paths']) |
|
405 | + ? (array)$setup_args['shortcode_paths'] |
|
406 | + : array(), |
|
407 | + // array of full server paths to any WP_Widgets used by the addon |
|
408 | + 'widget_paths' => isset($setup_args['widget_paths']) |
|
409 | + ? (array)$setup_args['widget_paths'] |
|
410 | + : array(), |
|
411 | + // array of PUE options used by the addon |
|
412 | + 'pue_options' => isset($setup_args['pue_options']) |
|
413 | + ? (array)$setup_args['pue_options'] |
|
414 | + : array(), |
|
415 | + 'message_types' => isset($setup_args['message_types']) |
|
416 | + ? (array)$setup_args['message_types'] |
|
417 | + : array(), |
|
418 | + 'capabilities' => isset($setup_args['capabilities']) |
|
419 | + ? (array)$setup_args['capabilities'] |
|
420 | + : array(), |
|
421 | + 'capability_maps' => isset($setup_args['capability_maps']) |
|
422 | + ? (array)$setup_args['capability_maps'] |
|
423 | + : array(), |
|
424 | + 'model_paths' => isset($setup_args['model_paths']) |
|
425 | + ? (array)$setup_args['model_paths'] |
|
426 | + : array(), |
|
427 | + 'class_paths' => isset($setup_args['class_paths']) |
|
428 | + ? (array)$setup_args['class_paths'] |
|
429 | + : array(), |
|
430 | + 'model_extension_paths' => isset($setup_args['model_extension_paths']) |
|
431 | + ? (array)$setup_args['model_extension_paths'] |
|
432 | + : array(), |
|
433 | + 'class_extension_paths' => isset($setup_args['class_extension_paths']) |
|
434 | + ? (array)$setup_args['class_extension_paths'] |
|
435 | + : array(), |
|
436 | + 'custom_post_types' => isset($setup_args['custom_post_types']) |
|
437 | + ? (array)$setup_args['custom_post_types'] |
|
438 | + : array(), |
|
439 | + 'custom_taxonomies' => isset($setup_args['custom_taxonomies']) |
|
440 | + ? (array)$setup_args['custom_taxonomies'] |
|
441 | + : array(), |
|
442 | + 'payment_method_paths' => isset($setup_args['payment_method_paths']) |
|
443 | + ? (array)$setup_args['payment_method_paths'] |
|
444 | + : array(), |
|
445 | + 'default_terms' => isset($setup_args['default_terms']) |
|
446 | + ? (array)$setup_args['default_terms'] |
|
447 | + : array(), |
|
448 | + // if not empty, inserts a new table row after this plugin's row on the WP Plugins page |
|
449 | + // that can be used for adding upgrading/marketing info |
|
450 | + 'plugins_page_row' => isset($setup_args['plugins_page_row']) |
|
451 | + ? $setup_args['plugins_page_row'] |
|
452 | + : '', |
|
453 | + 'namespace' => isset( |
|
454 | + $setup_args['namespace'], |
|
455 | + $setup_args['namespace']['FQNS'], |
|
456 | + $setup_args['namespace']['DIR'] |
|
457 | + ) |
|
458 | + ? (array)$setup_args['namespace'] |
|
459 | + : array(), |
|
460 | + ); |
|
461 | + // if plugin_action_slug is NOT set, but an admin page path IS set, |
|
462 | + // then let's just use the plugin_slug since that will be used for linking to the admin page |
|
463 | + $addon_settings['plugin_action_slug'] = empty($addon_settings['plugin_action_slug']) |
|
464 | + && ! empty($addon_settings['admin_path']) |
|
465 | + ? $addon_settings['plugin_slug'] |
|
466 | + : $addon_settings['plugin_action_slug']; |
|
467 | + // full server path to main file (file loaded directly by WP) |
|
468 | + $addon_settings['plugin_basename'] = plugin_basename($addon_settings['main_file_path']); |
|
469 | + return $addon_settings; |
|
470 | + } |
|
471 | + |
|
472 | + |
|
473 | + |
|
474 | + /** |
|
475 | + * @param string $addon_name |
|
476 | + * @param array $addon_settings |
|
477 | + * @return boolean |
|
478 | + */ |
|
479 | 479 | private static function _addon_is_compatible( $addon_name, array $addon_settings ) { |
480 | - global $wp_version; |
|
481 | - $incompatibility_message = ''; |
|
482 | - //check whether this addon version is compatible with EE core |
|
483 | - if ( |
|
484 | - isset(EE_Register_Addon::$_incompatible_addons[$addon_name]) |
|
485 | - && ! self::_meets_min_core_version_requirement( |
|
486 | - EE_Register_Addon::$_incompatible_addons[$addon_name], |
|
487 | - $addon_settings['version'] |
|
488 | - ) |
|
489 | - ) { |
|
490 | - $incompatibility_message = sprintf( |
|
491 | - __( |
|
492 | - '%4$sIMPORTANT!%5$sThe Event Espresso "%1$s" addon is not compatible with this version of Event Espresso.%2$sPlease upgrade your "%1$s" addon to version %3$s or newer to resolve this issue.' |
|
493 | - ), |
|
494 | - $addon_name, |
|
495 | - '<br />', |
|
496 | - EE_Register_Addon::$_incompatible_addons[$addon_name], |
|
497 | - '<span style="font-weight: bold; color: #D54E21;">', |
|
498 | - '</span><br />' |
|
499 | - ); |
|
500 | - } else if ( |
|
501 | - ! self::_meets_min_core_version_requirement($addon_settings['min_core_version'], espresso_version()) |
|
502 | - ) { |
|
503 | - $incompatibility_message = sprintf( |
|
504 | - __( |
|
505 | - '%5$sIMPORTANT!%6$sThe Event Espresso "%1$s" addon requires Event Espresso Core version "%2$s" or higher in order to run.%4$sYour version of Event Espresso Core is currently at "%3$s". Please upgrade Event Espresso Core first and then re-activate "%1$s".', |
|
506 | - 'event_espresso' |
|
507 | - ), |
|
508 | - $addon_name, |
|
509 | - self::_effective_version($addon_settings['min_core_version']), |
|
510 | - self::_effective_version(espresso_version()), |
|
511 | - '<br />', |
|
512 | - '<span style="font-weight: bold; color: #D54E21;">', |
|
513 | - '</span><br />' |
|
514 | - ); |
|
515 | - } else if (version_compare($wp_version, $addon_settings['min_wp_version'], '<')) { |
|
516 | - $incompatibility_message = sprintf( |
|
517 | - __( |
|
518 | - '%4$sIMPORTANT!%5$sThe Event Espresso "%1$s" addon requires WordPress version "%2$s" or greater.%3$sPlease update your version of WordPress to use the "%1$s" addon and to keep your site secure.', |
|
519 | - 'event_espresso' |
|
520 | - ), |
|
521 | - $addon_name, |
|
522 | - $addon_settings['min_wp_version'], |
|
523 | - '<br />', |
|
524 | - '<span style="font-weight: bold; color: #D54E21;">', |
|
525 | - '</span><br />' |
|
526 | - ); |
|
527 | - } |
|
528 | - if ( ! empty($incompatibility_message)) { |
|
529 | - // remove 'activate' from the REQUEST |
|
530 | - // so WP doesn't erroneously tell the user the plugin activated fine when it didn't |
|
531 | - unset($_GET['activate'], $_REQUEST['activate']); |
|
532 | - if (current_user_can('activate_plugins')) { |
|
533 | - // show an error message indicating the plugin didn't activate properly |
|
534 | - EE_Error::add_error($incompatibility_message, __FILE__, __FUNCTION__, __LINE__); |
|
535 | - } |
|
536 | - // BAIL FROM THE ADDON REGISTRATION PROCESS |
|
537 | - return false; |
|
538 | - } |
|
539 | - // addon IS compatible |
|
540 | - return true; |
|
480 | + global $wp_version; |
|
481 | + $incompatibility_message = ''; |
|
482 | + //check whether this addon version is compatible with EE core |
|
483 | + if ( |
|
484 | + isset(EE_Register_Addon::$_incompatible_addons[$addon_name]) |
|
485 | + && ! self::_meets_min_core_version_requirement( |
|
486 | + EE_Register_Addon::$_incompatible_addons[$addon_name], |
|
487 | + $addon_settings['version'] |
|
488 | + ) |
|
489 | + ) { |
|
490 | + $incompatibility_message = sprintf( |
|
491 | + __( |
|
492 | + '%4$sIMPORTANT!%5$sThe Event Espresso "%1$s" addon is not compatible with this version of Event Espresso.%2$sPlease upgrade your "%1$s" addon to version %3$s or newer to resolve this issue.' |
|
493 | + ), |
|
494 | + $addon_name, |
|
495 | + '<br />', |
|
496 | + EE_Register_Addon::$_incompatible_addons[$addon_name], |
|
497 | + '<span style="font-weight: bold; color: #D54E21;">', |
|
498 | + '</span><br />' |
|
499 | + ); |
|
500 | + } else if ( |
|
501 | + ! self::_meets_min_core_version_requirement($addon_settings['min_core_version'], espresso_version()) |
|
502 | + ) { |
|
503 | + $incompatibility_message = sprintf( |
|
504 | + __( |
|
505 | + '%5$sIMPORTANT!%6$sThe Event Espresso "%1$s" addon requires Event Espresso Core version "%2$s" or higher in order to run.%4$sYour version of Event Espresso Core is currently at "%3$s". Please upgrade Event Espresso Core first and then re-activate "%1$s".', |
|
506 | + 'event_espresso' |
|
507 | + ), |
|
508 | + $addon_name, |
|
509 | + self::_effective_version($addon_settings['min_core_version']), |
|
510 | + self::_effective_version(espresso_version()), |
|
511 | + '<br />', |
|
512 | + '<span style="font-weight: bold; color: #D54E21;">', |
|
513 | + '</span><br />' |
|
514 | + ); |
|
515 | + } else if (version_compare($wp_version, $addon_settings['min_wp_version'], '<')) { |
|
516 | + $incompatibility_message = sprintf( |
|
517 | + __( |
|
518 | + '%4$sIMPORTANT!%5$sThe Event Espresso "%1$s" addon requires WordPress version "%2$s" or greater.%3$sPlease update your version of WordPress to use the "%1$s" addon and to keep your site secure.', |
|
519 | + 'event_espresso' |
|
520 | + ), |
|
521 | + $addon_name, |
|
522 | + $addon_settings['min_wp_version'], |
|
523 | + '<br />', |
|
524 | + '<span style="font-weight: bold; color: #D54E21;">', |
|
525 | + '</span><br />' |
|
526 | + ); |
|
527 | + } |
|
528 | + if ( ! empty($incompatibility_message)) { |
|
529 | + // remove 'activate' from the REQUEST |
|
530 | + // so WP doesn't erroneously tell the user the plugin activated fine when it didn't |
|
531 | + unset($_GET['activate'], $_REQUEST['activate']); |
|
532 | + if (current_user_can('activate_plugins')) { |
|
533 | + // show an error message indicating the plugin didn't activate properly |
|
534 | + EE_Error::add_error($incompatibility_message, __FILE__, __FUNCTION__, __LINE__); |
|
535 | + } |
|
536 | + // BAIL FROM THE ADDON REGISTRATION PROCESS |
|
537 | + return false; |
|
538 | + } |
|
539 | + // addon IS compatible |
|
540 | + return true; |
|
541 | 541 | } |
542 | 542 | |
543 | 543 | |
544 | 544 | |
545 | - /** |
|
546 | - * if plugin update engine is being used for auto-updates, |
|
547 | - * then let's set that up now before going any further so that ALL addons can be updated |
|
548 | - * (not needed if PUE is not being used) |
|
549 | - * |
|
550 | - * @param string $addon_name |
|
551 | - * @param string $class_name |
|
552 | - * @param array $setup_args |
|
553 | - * @return void |
|
554 | - */ |
|
545 | + /** |
|
546 | + * if plugin update engine is being used for auto-updates, |
|
547 | + * then let's set that up now before going any further so that ALL addons can be updated |
|
548 | + * (not needed if PUE is not being used) |
|
549 | + * |
|
550 | + * @param string $addon_name |
|
551 | + * @param string $class_name |
|
552 | + * @param array $setup_args |
|
553 | + * @return void |
|
554 | + */ |
|
555 | 555 | private static function _parse_pue_options( $addon_name, $class_name, array $setup_args ) { |
556 | - if ( ! empty($setup_args['pue_options'])) { |
|
557 | - self::$_settings[$addon_name]['pue_options'] = array( |
|
558 | - 'pue_plugin_slug' => isset($setup_args['pue_options']['pue_plugin_slug']) |
|
559 | - ? (string)$setup_args['pue_options']['pue_plugin_slug'] |
|
560 | - : 'espresso_' . strtolower($class_name), |
|
561 | - 'plugin_basename' => isset($setup_args['pue_options']['plugin_basename']) |
|
562 | - ? (string)$setup_args['pue_options']['plugin_basename'] |
|
563 | - : plugin_basename($setup_args['main_file_path']), |
|
564 | - 'checkPeriod' => isset($setup_args['pue_options']['checkPeriod']) |
|
565 | - ? (string)$setup_args['pue_options']['checkPeriod'] |
|
566 | - : '24', |
|
567 | - 'use_wp_update' => isset($setup_args['pue_options']['use_wp_update']) |
|
568 | - ? (string)$setup_args['pue_options']['use_wp_update'] |
|
569 | - : false, |
|
570 | - ); |
|
571 | - add_action( |
|
572 | - 'AHEE__EE_System__brew_espresso__after_pue_init', |
|
573 | - array('EE_Register_Addon', 'load_pue_update') |
|
574 | - ); |
|
575 | - } |
|
556 | + if ( ! empty($setup_args['pue_options'])) { |
|
557 | + self::$_settings[$addon_name]['pue_options'] = array( |
|
558 | + 'pue_plugin_slug' => isset($setup_args['pue_options']['pue_plugin_slug']) |
|
559 | + ? (string)$setup_args['pue_options']['pue_plugin_slug'] |
|
560 | + : 'espresso_' . strtolower($class_name), |
|
561 | + 'plugin_basename' => isset($setup_args['pue_options']['plugin_basename']) |
|
562 | + ? (string)$setup_args['pue_options']['plugin_basename'] |
|
563 | + : plugin_basename($setup_args['main_file_path']), |
|
564 | + 'checkPeriod' => isset($setup_args['pue_options']['checkPeriod']) |
|
565 | + ? (string)$setup_args['pue_options']['checkPeriod'] |
|
566 | + : '24', |
|
567 | + 'use_wp_update' => isset($setup_args['pue_options']['use_wp_update']) |
|
568 | + ? (string)$setup_args['pue_options']['use_wp_update'] |
|
569 | + : false, |
|
570 | + ); |
|
571 | + add_action( |
|
572 | + 'AHEE__EE_System__brew_espresso__after_pue_init', |
|
573 | + array('EE_Register_Addon', 'load_pue_update') |
|
574 | + ); |
|
575 | + } |
|
576 | 576 | } |
577 | 577 | |
578 | 578 | |
579 | 579 | |
580 | - /** |
|
581 | - * register namespaces right away before any other files or classes get loaded, but AFTER the version checks |
|
582 | - * |
|
583 | - * @param array $addon_settings |
|
584 | - * @return void |
|
585 | - */ |
|
586 | - private static function _setup_namespaces(array $addon_settings) |
|
587 | - { |
|
588 | - // |
|
589 | - if ( |
|
590 | - isset( |
|
591 | - $addon_settings['namespace'], |
|
592 | - $addon_settings['namespace']['FQNS'], |
|
593 | - $addon_settings['namespace']['DIR'] |
|
594 | - ) |
|
595 | - ) { |
|
596 | - EE_Psr4AutoloaderInit::psr4_loader()->addNamespace( |
|
597 | - $addon_settings['namespace']['FQNS'], |
|
598 | - $addon_settings['namespace']['DIR'] |
|
599 | - ); |
|
600 | - } |
|
601 | - } |
|
602 | - |
|
603 | - |
|
604 | - |
|
605 | - /** |
|
606 | - * @param string $addon_name |
|
607 | - * @param array $addon_settings |
|
608 | - * @return bool |
|
609 | - */ |
|
580 | + /** |
|
581 | + * register namespaces right away before any other files or classes get loaded, but AFTER the version checks |
|
582 | + * |
|
583 | + * @param array $addon_settings |
|
584 | + * @return void |
|
585 | + */ |
|
586 | + private static function _setup_namespaces(array $addon_settings) |
|
587 | + { |
|
588 | + // |
|
589 | + if ( |
|
590 | + isset( |
|
591 | + $addon_settings['namespace'], |
|
592 | + $addon_settings['namespace']['FQNS'], |
|
593 | + $addon_settings['namespace']['DIR'] |
|
594 | + ) |
|
595 | + ) { |
|
596 | + EE_Psr4AutoloaderInit::psr4_loader()->addNamespace( |
|
597 | + $addon_settings['namespace']['FQNS'], |
|
598 | + $addon_settings['namespace']['DIR'] |
|
599 | + ); |
|
600 | + } |
|
601 | + } |
|
602 | + |
|
603 | + |
|
604 | + |
|
605 | + /** |
|
606 | + * @param string $addon_name |
|
607 | + * @param array $addon_settings |
|
608 | + * @return bool |
|
609 | + */ |
|
610 | 610 | private static function _addon_activation( $addon_name, array $addon_settings ) { |
611 | - // this is an activation request |
|
612 | - if (did_action('activate_plugin')) { |
|
613 | - //to find if THIS is the addon that was activated, |
|
614 | - //just check if we have already registered it or not |
|
615 | - //(as the newly-activated addon wasn't around the first time addons were registered) |
|
616 | - if ( ! isset(self::$_settings[$addon_name])) { |
|
617 | - self::$_settings[$addon_name] = $addon_settings; |
|
618 | - $addon = self::_load_and_init_addon_class($addon_name); |
|
619 | - $addon->set_activation_indicator_option(); |
|
620 | - // dont bother setting up the rest of the addon. |
|
621 | - // we know it was just activated and the request will end soon |
|
622 | - } |
|
623 | - return true; |
|
624 | - } else { |
|
625 | - // make sure this was called in the right place! |
|
626 | - if ( |
|
627 | - ! did_action('AHEE__EE_System__load_espresso_addons') |
|
628 | - || did_action('AHEE__EE_System___detect_if_activation_or_upgrade__begin') |
|
629 | - ) { |
|
630 | - EE_Error::doing_it_wrong( |
|
631 | - __METHOD__, |
|
632 | - sprintf( |
|
633 | - __( |
|
634 | - 'An attempt to register an EE_Addon named "%s" has failed because it was not registered at the correct time. Please use the "AHEE__EE_System__load_espresso_addons" hook to register addons.', |
|
635 | - 'event_espresso' |
|
636 | - ), |
|
637 | - $addon_name |
|
638 | - ), |
|
639 | - '4.3.0' |
|
640 | - ); |
|
641 | - } |
|
642 | - // make sure addon settings are set correctly without overwriting anything existing |
|
643 | - if (isset(self::$_settings[$addon_name])) { |
|
644 | - self::$_settings[$addon_name] += $addon_settings; |
|
645 | - } else { |
|
646 | - self::$_settings[$addon_name] = $addon_settings; |
|
647 | - } |
|
648 | - } |
|
649 | - return false; |
|
650 | - } |
|
651 | - |
|
652 | - |
|
653 | - |
|
654 | - /** |
|
655 | - * @param string $addon_name |
|
656 | - * @return void |
|
657 | - * @throws \EE_Error |
|
658 | - */ |
|
659 | - private static function _setup_autoloaders($addon_name) |
|
660 | - { |
|
661 | - if ( ! empty(self::$_settings[$addon_name]['autoloader_paths'])) { |
|
662 | - // setup autoloader for single file |
|
663 | - EEH_Autoloader::instance()->register_autoloader(self::$_settings[$addon_name]['autoloader_paths']); |
|
664 | - } |
|
665 | - // setup autoloaders for folders |
|
666 | - if ( ! empty(self::$_settings[$addon_name]['autoloader_folders'])) { |
|
667 | - foreach ((array)self::$_settings[$addon_name]['autoloader_folders'] as $autoloader_folder) { |
|
668 | - EEH_Autoloader::register_autoloaders_for_each_file_in_folder($autoloader_folder); |
|
669 | - } |
|
670 | - } |
|
671 | - } |
|
672 | - |
|
673 | - |
|
674 | - |
|
675 | - /** |
|
676 | - * register new models and extensions |
|
677 | - * |
|
678 | - * @param string $addon_name |
|
679 | - * @return void |
|
680 | - * @throws \EE_Error |
|
681 | - */ |
|
611 | + // this is an activation request |
|
612 | + if (did_action('activate_plugin')) { |
|
613 | + //to find if THIS is the addon that was activated, |
|
614 | + //just check if we have already registered it or not |
|
615 | + //(as the newly-activated addon wasn't around the first time addons were registered) |
|
616 | + if ( ! isset(self::$_settings[$addon_name])) { |
|
617 | + self::$_settings[$addon_name] = $addon_settings; |
|
618 | + $addon = self::_load_and_init_addon_class($addon_name); |
|
619 | + $addon->set_activation_indicator_option(); |
|
620 | + // dont bother setting up the rest of the addon. |
|
621 | + // we know it was just activated and the request will end soon |
|
622 | + } |
|
623 | + return true; |
|
624 | + } else { |
|
625 | + // make sure this was called in the right place! |
|
626 | + if ( |
|
627 | + ! did_action('AHEE__EE_System__load_espresso_addons') |
|
628 | + || did_action('AHEE__EE_System___detect_if_activation_or_upgrade__begin') |
|
629 | + ) { |
|
630 | + EE_Error::doing_it_wrong( |
|
631 | + __METHOD__, |
|
632 | + sprintf( |
|
633 | + __( |
|
634 | + 'An attempt to register an EE_Addon named "%s" has failed because it was not registered at the correct time. Please use the "AHEE__EE_System__load_espresso_addons" hook to register addons.', |
|
635 | + 'event_espresso' |
|
636 | + ), |
|
637 | + $addon_name |
|
638 | + ), |
|
639 | + '4.3.0' |
|
640 | + ); |
|
641 | + } |
|
642 | + // make sure addon settings are set correctly without overwriting anything existing |
|
643 | + if (isset(self::$_settings[$addon_name])) { |
|
644 | + self::$_settings[$addon_name] += $addon_settings; |
|
645 | + } else { |
|
646 | + self::$_settings[$addon_name] = $addon_settings; |
|
647 | + } |
|
648 | + } |
|
649 | + return false; |
|
650 | + } |
|
651 | + |
|
652 | + |
|
653 | + |
|
654 | + /** |
|
655 | + * @param string $addon_name |
|
656 | + * @return void |
|
657 | + * @throws \EE_Error |
|
658 | + */ |
|
659 | + private static function _setup_autoloaders($addon_name) |
|
660 | + { |
|
661 | + if ( ! empty(self::$_settings[$addon_name]['autoloader_paths'])) { |
|
662 | + // setup autoloader for single file |
|
663 | + EEH_Autoloader::instance()->register_autoloader(self::$_settings[$addon_name]['autoloader_paths']); |
|
664 | + } |
|
665 | + // setup autoloaders for folders |
|
666 | + if ( ! empty(self::$_settings[$addon_name]['autoloader_folders'])) { |
|
667 | + foreach ((array)self::$_settings[$addon_name]['autoloader_folders'] as $autoloader_folder) { |
|
668 | + EEH_Autoloader::register_autoloaders_for_each_file_in_folder($autoloader_folder); |
|
669 | + } |
|
670 | + } |
|
671 | + } |
|
672 | + |
|
673 | + |
|
674 | + |
|
675 | + /** |
|
676 | + * register new models and extensions |
|
677 | + * |
|
678 | + * @param string $addon_name |
|
679 | + * @return void |
|
680 | + * @throws \EE_Error |
|
681 | + */ |
|
682 | 682 | private static function _register_models_and_extensions( $addon_name ) { |
683 | - // register new models |
|
684 | - if ( |
|
685 | - ! empty(self::$_settings[$addon_name]['model_paths']) |
|
686 | - || ! empty(self::$_settings[$addon_name]['class_paths']) |
|
687 | - ) { |
|
688 | - EE_Register_Model::register( |
|
689 | - $addon_name, |
|
690 | - array( |
|
691 | - 'model_paths' => self::$_settings[$addon_name]['model_paths'], |
|
692 | - 'class_paths' => self::$_settings[$addon_name]['class_paths'], |
|
693 | - ) |
|
694 | - ); |
|
695 | - } |
|
696 | - // register model extensions |
|
697 | - if ( |
|
698 | - ! empty(self::$_settings[$addon_name]['model_extension_paths']) |
|
699 | - || ! empty(self::$_settings[$addon_name]['class_extension_paths']) |
|
700 | - ) { |
|
701 | - EE_Register_Model_Extensions::register( |
|
702 | - $addon_name, |
|
703 | - array( |
|
704 | - 'model_extension_paths' => self::$_settings[$addon_name]['model_extension_paths'], |
|
705 | - 'class_extension_paths' => self::$_settings[$addon_name]['class_extension_paths'], |
|
706 | - ) |
|
707 | - ); |
|
708 | - } |
|
709 | - } |
|
710 | - |
|
711 | - |
|
712 | - |
|
713 | - /** |
|
714 | - * @param string $addon_name |
|
715 | - * @return void |
|
716 | - * @throws \EE_Error |
|
717 | - */ |
|
683 | + // register new models |
|
684 | + if ( |
|
685 | + ! empty(self::$_settings[$addon_name]['model_paths']) |
|
686 | + || ! empty(self::$_settings[$addon_name]['class_paths']) |
|
687 | + ) { |
|
688 | + EE_Register_Model::register( |
|
689 | + $addon_name, |
|
690 | + array( |
|
691 | + 'model_paths' => self::$_settings[$addon_name]['model_paths'], |
|
692 | + 'class_paths' => self::$_settings[$addon_name]['class_paths'], |
|
693 | + ) |
|
694 | + ); |
|
695 | + } |
|
696 | + // register model extensions |
|
697 | + if ( |
|
698 | + ! empty(self::$_settings[$addon_name]['model_extension_paths']) |
|
699 | + || ! empty(self::$_settings[$addon_name]['class_extension_paths']) |
|
700 | + ) { |
|
701 | + EE_Register_Model_Extensions::register( |
|
702 | + $addon_name, |
|
703 | + array( |
|
704 | + 'model_extension_paths' => self::$_settings[$addon_name]['model_extension_paths'], |
|
705 | + 'class_extension_paths' => self::$_settings[$addon_name]['class_extension_paths'], |
|
706 | + ) |
|
707 | + ); |
|
708 | + } |
|
709 | + } |
|
710 | + |
|
711 | + |
|
712 | + |
|
713 | + /** |
|
714 | + * @param string $addon_name |
|
715 | + * @return void |
|
716 | + * @throws \EE_Error |
|
717 | + */ |
|
718 | 718 | private static function _register_data_migration_scripts( $addon_name ) { |
719 | - // setup DMS |
|
720 | - if ( ! empty(self::$_settings[$addon_name]['dms_paths'])) { |
|
721 | - EE_Register_Data_Migration_Scripts::register( |
|
722 | - $addon_name, |
|
723 | - array('dms_paths' => self::$_settings[$addon_name]['dms_paths']) |
|
724 | - ); |
|
725 | - } |
|
726 | - } |
|
727 | - |
|
728 | - |
|
729 | - /** |
|
730 | - * @param string $addon_name |
|
731 | - * @return void |
|
732 | - * @throws \EE_Error |
|
733 | - */ |
|
719 | + // setup DMS |
|
720 | + if ( ! empty(self::$_settings[$addon_name]['dms_paths'])) { |
|
721 | + EE_Register_Data_Migration_Scripts::register( |
|
722 | + $addon_name, |
|
723 | + array('dms_paths' => self::$_settings[$addon_name]['dms_paths']) |
|
724 | + ); |
|
725 | + } |
|
726 | + } |
|
727 | + |
|
728 | + |
|
729 | + /** |
|
730 | + * @param string $addon_name |
|
731 | + * @return void |
|
732 | + * @throws \EE_Error |
|
733 | + */ |
|
734 | 734 | private static function _register_config( $addon_name ) { |
735 | - // if config_class is present let's register config. |
|
736 | - if ( ! empty(self::$_settings[$addon_name]['config_class'])) { |
|
737 | - EE_Register_Config::register( |
|
738 | - self::$_settings[$addon_name]['config_class'], |
|
739 | - array( |
|
740 | - 'config_section' => self::$_settings[$addon_name]['config_section'], |
|
741 | - 'config_name' => self::$_settings[$addon_name]['config_name'], |
|
742 | - ) |
|
743 | - ); |
|
744 | - } |
|
745 | - } |
|
746 | - |
|
747 | - |
|
748 | - /** |
|
749 | - * @param string $addon_name |
|
750 | - * @return void |
|
751 | - * @throws \EE_Error |
|
752 | - */ |
|
735 | + // if config_class is present let's register config. |
|
736 | + if ( ! empty(self::$_settings[$addon_name]['config_class'])) { |
|
737 | + EE_Register_Config::register( |
|
738 | + self::$_settings[$addon_name]['config_class'], |
|
739 | + array( |
|
740 | + 'config_section' => self::$_settings[$addon_name]['config_section'], |
|
741 | + 'config_name' => self::$_settings[$addon_name]['config_name'], |
|
742 | + ) |
|
743 | + ); |
|
744 | + } |
|
745 | + } |
|
746 | + |
|
747 | + |
|
748 | + /** |
|
749 | + * @param string $addon_name |
|
750 | + * @return void |
|
751 | + * @throws \EE_Error |
|
752 | + */ |
|
753 | 753 | private static function _register_admin_pages( $addon_name ) { |
754 | - if ( ! empty(self::$_settings[$addon_name]['admin_path'])) { |
|
755 | - EE_Register_Admin_Page::register( |
|
756 | - $addon_name, |
|
757 | - array('page_path' => self::$_settings[$addon_name]['admin_path']) |
|
758 | - ); |
|
759 | - } |
|
760 | - } |
|
761 | - |
|
762 | - |
|
763 | - /** |
|
764 | - * @param string $addon_name |
|
765 | - * @return void |
|
766 | - * @throws \EE_Error |
|
767 | - */ |
|
754 | + if ( ! empty(self::$_settings[$addon_name]['admin_path'])) { |
|
755 | + EE_Register_Admin_Page::register( |
|
756 | + $addon_name, |
|
757 | + array('page_path' => self::$_settings[$addon_name]['admin_path']) |
|
758 | + ); |
|
759 | + } |
|
760 | + } |
|
761 | + |
|
762 | + |
|
763 | + /** |
|
764 | + * @param string $addon_name |
|
765 | + * @return void |
|
766 | + * @throws \EE_Error |
|
767 | + */ |
|
768 | 768 | private static function _register_modules( $addon_name ) { |
769 | - if ( ! empty(self::$_settings[$addon_name]['module_paths'])) { |
|
770 | - EE_Register_Module::register( |
|
771 | - $addon_name, |
|
772 | - array('module_paths' => self::$_settings[$addon_name]['module_paths']) |
|
773 | - ); |
|
774 | - } |
|
775 | - } |
|
776 | - |
|
777 | - |
|
778 | - /** |
|
779 | - * @param string $addon_name |
|
780 | - * @return void |
|
781 | - * @throws \EE_Error |
|
782 | - */ |
|
769 | + if ( ! empty(self::$_settings[$addon_name]['module_paths'])) { |
|
770 | + EE_Register_Module::register( |
|
771 | + $addon_name, |
|
772 | + array('module_paths' => self::$_settings[$addon_name]['module_paths']) |
|
773 | + ); |
|
774 | + } |
|
775 | + } |
|
776 | + |
|
777 | + |
|
778 | + /** |
|
779 | + * @param string $addon_name |
|
780 | + * @return void |
|
781 | + * @throws \EE_Error |
|
782 | + */ |
|
783 | 783 | private static function _register_shortcodes( $addon_name ) { |
784 | - if ( ! empty(self::$_settings[$addon_name]['shortcode_paths'])) { |
|
785 | - EE_Register_Shortcode::register( |
|
786 | - $addon_name, |
|
787 | - array('shortcode_paths' => self::$_settings[$addon_name]['shortcode_paths']) |
|
788 | - ); |
|
789 | - } |
|
790 | - } |
|
791 | - |
|
792 | - |
|
793 | - /** |
|
794 | - * @param string $addon_name |
|
795 | - * @return void |
|
796 | - * @throws \EE_Error |
|
797 | - */ |
|
784 | + if ( ! empty(self::$_settings[$addon_name]['shortcode_paths'])) { |
|
785 | + EE_Register_Shortcode::register( |
|
786 | + $addon_name, |
|
787 | + array('shortcode_paths' => self::$_settings[$addon_name]['shortcode_paths']) |
|
788 | + ); |
|
789 | + } |
|
790 | + } |
|
791 | + |
|
792 | + |
|
793 | + /** |
|
794 | + * @param string $addon_name |
|
795 | + * @return void |
|
796 | + * @throws \EE_Error |
|
797 | + */ |
|
798 | 798 | private static function _register_widgets( $addon_name ) { |
799 | - if ( ! empty(self::$_settings[$addon_name]['widget_paths'])) { |
|
800 | - EE_Register_Widget::register( |
|
801 | - $addon_name, |
|
802 | - array('widget_paths' => self::$_settings[$addon_name]['widget_paths']) |
|
803 | - ); |
|
804 | - } |
|
805 | - } |
|
806 | - |
|
807 | - |
|
808 | - /** |
|
809 | - * @param string $addon_name |
|
810 | - * @return void |
|
811 | - * @throws \EE_Error |
|
812 | - */ |
|
799 | + if ( ! empty(self::$_settings[$addon_name]['widget_paths'])) { |
|
800 | + EE_Register_Widget::register( |
|
801 | + $addon_name, |
|
802 | + array('widget_paths' => self::$_settings[$addon_name]['widget_paths']) |
|
803 | + ); |
|
804 | + } |
|
805 | + } |
|
806 | + |
|
807 | + |
|
808 | + /** |
|
809 | + * @param string $addon_name |
|
810 | + * @return void |
|
811 | + * @throws \EE_Error |
|
812 | + */ |
|
813 | 813 | private static function _register_capabilities( $addon_name ) { |
814 | - if ( ! empty(self::$_settings[$addon_name]['capabilities'])) { |
|
815 | - EE_Register_Capabilities::register( |
|
816 | - $addon_name, |
|
817 | - array( |
|
818 | - 'capabilities' => self::$_settings[$addon_name]['capabilities'], |
|
819 | - 'capability_maps' => self::$_settings[$addon_name]['capability_maps'], |
|
820 | - ) |
|
821 | - ); |
|
822 | - } |
|
823 | - } |
|
824 | - |
|
825 | - |
|
826 | - /** |
|
827 | - * @param string $addon_name |
|
828 | - * @return void |
|
829 | - * @throws \EE_Error |
|
830 | - */ |
|
814 | + if ( ! empty(self::$_settings[$addon_name]['capabilities'])) { |
|
815 | + EE_Register_Capabilities::register( |
|
816 | + $addon_name, |
|
817 | + array( |
|
818 | + 'capabilities' => self::$_settings[$addon_name]['capabilities'], |
|
819 | + 'capability_maps' => self::$_settings[$addon_name]['capability_maps'], |
|
820 | + ) |
|
821 | + ); |
|
822 | + } |
|
823 | + } |
|
824 | + |
|
825 | + |
|
826 | + /** |
|
827 | + * @param string $addon_name |
|
828 | + * @return void |
|
829 | + * @throws \EE_Error |
|
830 | + */ |
|
831 | 831 | private static function _register_message_types( $addon_name ) { |
832 | - if ( ! empty(self::$_settings[$addon_name]['message_types'])) { |
|
833 | - add_action( |
|
834 | - 'EE_Brewing_Regular___messages_caf', |
|
835 | - array('EE_Register_Addon', 'register_message_types') |
|
836 | - ); |
|
837 | - } |
|
838 | - } |
|
839 | - |
|
840 | - |
|
841 | - /** |
|
842 | - * @param string $addon_name |
|
843 | - * @return void |
|
844 | - * @throws \EE_Error |
|
845 | - */ |
|
832 | + if ( ! empty(self::$_settings[$addon_name]['message_types'])) { |
|
833 | + add_action( |
|
834 | + 'EE_Brewing_Regular___messages_caf', |
|
835 | + array('EE_Register_Addon', 'register_message_types') |
|
836 | + ); |
|
837 | + } |
|
838 | + } |
|
839 | + |
|
840 | + |
|
841 | + /** |
|
842 | + * @param string $addon_name |
|
843 | + * @return void |
|
844 | + * @throws \EE_Error |
|
845 | + */ |
|
846 | 846 | private static function _register_custom_post_types( $addon_name ) { |
847 | - if ( |
|
848 | - ! empty(self::$_settings[$addon_name]['custom_post_types']) |
|
849 | - || ! empty(self::$_settings[$addon_name]['custom_taxonomies']) |
|
850 | - ) { |
|
851 | - EE_Register_CPT::register( |
|
852 | - $addon_name, |
|
853 | - array( |
|
854 | - 'cpts' => self::$_settings[$addon_name]['custom_post_types'], |
|
855 | - 'cts' => self::$_settings[$addon_name]['custom_taxonomies'], |
|
856 | - 'default_terms' => self::$_settings[$addon_name]['default_terms'], |
|
857 | - ) |
|
858 | - ); |
|
859 | - } |
|
860 | - } |
|
861 | - |
|
862 | - |
|
863 | - /** |
|
864 | - * @param string $addon_name |
|
865 | - * @return void |
|
866 | - * @throws \EE_Error |
|
867 | - */ |
|
847 | + if ( |
|
848 | + ! empty(self::$_settings[$addon_name]['custom_post_types']) |
|
849 | + || ! empty(self::$_settings[$addon_name]['custom_taxonomies']) |
|
850 | + ) { |
|
851 | + EE_Register_CPT::register( |
|
852 | + $addon_name, |
|
853 | + array( |
|
854 | + 'cpts' => self::$_settings[$addon_name]['custom_post_types'], |
|
855 | + 'cts' => self::$_settings[$addon_name]['custom_taxonomies'], |
|
856 | + 'default_terms' => self::$_settings[$addon_name]['default_terms'], |
|
857 | + ) |
|
858 | + ); |
|
859 | + } |
|
860 | + } |
|
861 | + |
|
862 | + |
|
863 | + /** |
|
864 | + * @param string $addon_name |
|
865 | + * @return void |
|
866 | + * @throws \EE_Error |
|
867 | + */ |
|
868 | 868 | private static function _register_payment_methods( $addon_name ) { |
869 | - if ( ! empty(self::$_settings[$addon_name]['payment_method_paths'])) { |
|
870 | - EE_Register_Payment_Method::register( |
|
871 | - $addon_name, |
|
872 | - array('payment_method_paths' => self::$_settings[$addon_name]['payment_method_paths']) |
|
873 | - ); |
|
874 | - } |
|
875 | - } |
|
869 | + if ( ! empty(self::$_settings[$addon_name]['payment_method_paths'])) { |
|
870 | + EE_Register_Payment_Method::register( |
|
871 | + $addon_name, |
|
872 | + array('payment_method_paths' => self::$_settings[$addon_name]['payment_method_paths']) |
|
873 | + ); |
|
874 | + } |
|
875 | + } |
|
876 | 876 | |
877 | 877 | |
878 | 878 | |
@@ -901,14 +901,14 @@ discard block |
||
901 | 901 | //unfortunately this can't be hooked in upon construction, because we don't have |
902 | 902 | //the plugin mainfile's path upon construction. |
903 | 903 | register_deactivation_hook( $addon->get_main_plugin_file(), array( $addon, 'deactivation' ) ); |
904 | - // call any additional admin_callback functions during load_admin_controller hook |
|
905 | - if ( ! empty(self::$_settings[$addon_name]['admin_callback'])) { |
|
906 | - add_action( |
|
907 | - 'AHEE__EE_System__load_controllers__load_admin_controllers', |
|
908 | - array($addon, self::$_settings[$addon_name]['admin_callback']) |
|
909 | - ); |
|
910 | - } |
|
911 | - return $addon; |
|
904 | + // call any additional admin_callback functions during load_admin_controller hook |
|
905 | + if ( ! empty(self::$_settings[$addon_name]['admin_callback'])) { |
|
906 | + add_action( |
|
907 | + 'AHEE__EE_System__load_controllers__load_admin_controllers', |
|
908 | + array($addon, self::$_settings[$addon_name]['admin_callback']) |
|
909 | + ); |
|
910 | + } |
|
911 | + return $addon; |
|
912 | 912 | } |
913 | 913 | |
914 | 914 | |
@@ -924,7 +924,7 @@ discard block |
||
924 | 924 | // cycle thru settings |
925 | 925 | foreach ( self::$_settings as $settings ) { |
926 | 926 | if ( ! empty( $settings['pue_options'] ) ) { |
927 | - // initiate the class and start the plugin update engine! |
|
927 | + // initiate the class and start the plugin update engine! |
|
928 | 928 | new PluginUpdateEngineChecker( |
929 | 929 | // host file URL |
930 | 930 | 'https://eventespresso.com', |
@@ -960,11 +960,11 @@ discard block |
||
960 | 960 | */ |
961 | 961 | public static function register_message_types() { |
962 | 962 | foreach ( self::$_settings as $addon_name => $settings ) { |
963 | - if ( ! empty($settings['message_types'])) { |
|
964 | - foreach ((array)$settings['message_types'] as $message_type => $message_type_settings) { |
|
965 | - EE_Register_Message_Type::register($message_type, $message_type_settings); |
|
966 | - } |
|
967 | - } |
|
963 | + if ( ! empty($settings['message_types'])) { |
|
964 | + foreach ((array)$settings['message_types'] as $message_type => $message_type_settings) { |
|
965 | + EE_Register_Message_Type::register($message_type, $message_type_settings); |
|
966 | + } |
|
967 | + } |
|
968 | 968 | } |
969 | 969 | } |
970 | 970 | |
@@ -980,7 +980,7 @@ discard block |
||
980 | 980 | */ |
981 | 981 | public static function deregister( $addon_name = null ) { |
982 | 982 | if ( isset( self::$_settings[ $addon_name ] ) ) { |
983 | - do_action('AHEE__EE_Register_Addon__deregister__before', $addon_name); |
|
983 | + do_action('AHEE__EE_Register_Addon__deregister__before', $addon_name); |
|
984 | 984 | $class_name = self::$_settings[ $addon_name ]['class_name']; |
985 | 985 | if ( ! empty( self::$_settings[ $addon_name ]['dms_paths'] ) ) { |
986 | 986 | // setup DMS |
@@ -1007,15 +1007,15 @@ discard block |
||
1007 | 1007 | EE_Register_Widget::deregister( $addon_name ); |
1008 | 1008 | } |
1009 | 1009 | if ( ! empty( self::$_settings[ $addon_name ]['model_paths'] ) |
1010 | - || |
|
1011 | - ! empty( self::$_settings[ $addon_name ]['class_paths'] ) |
|
1010 | + || |
|
1011 | + ! empty( self::$_settings[ $addon_name ]['class_paths'] ) |
|
1012 | 1012 | ) { |
1013 | 1013 | // add to list of shortcodes to be registered |
1014 | 1014 | EE_Register_Model::deregister( $addon_name ); |
1015 | 1015 | } |
1016 | 1016 | if ( ! empty( self::$_settings[ $addon_name ]['model_extension_paths'] ) |
1017 | - || |
|
1018 | - ! empty( self::$_settings[ $addon_name ]['class_extension_paths'] ) |
|
1017 | + || |
|
1018 | + ! empty( self::$_settings[ $addon_name ]['class_extension_paths'] ) |
|
1019 | 1019 | ) { |
1020 | 1020 | // add to list of shortcodes to be registered |
1021 | 1021 | EE_Register_Model_Extensions::deregister( $addon_name ); |
@@ -1046,7 +1046,7 @@ discard block |
||
1046 | 1046 | array( EE_Registry::instance()->addons->{$class_name}, 'initialize_db_if_no_migrations_required' ) |
1047 | 1047 | ); |
1048 | 1048 | unset( EE_Registry::instance()->addons->{$class_name}, self::$_settings[ $addon_name ] ); |
1049 | - do_action('AHEE__EE_Register_Addon__deregister__after', $addon_name); |
|
1049 | + do_action('AHEE__EE_Register_Addon__deregister__after', $addon_name); |
|
1050 | 1050 | } |
1051 | 1051 | } |
1052 | 1052 |
@@ -1,5 +1,5 @@ discard block |
||
1 | -<?php if ( ! defined( 'EVENT_ESPRESSO_VERSION' ) ) { |
|
2 | - exit( 'No direct script access allowed' ); |
|
1 | +<?php if ( ! defined('EVENT_ESPRESSO_VERSION')) { |
|
2 | + exit('No direct script access allowed'); |
|
3 | 3 | } |
4 | 4 | |
5 | 5 | |
@@ -61,23 +61,23 @@ discard block |
||
61 | 61 | * @param string $min_core_version |
62 | 62 | * @return string always like '4.3.0.rc.000' |
63 | 63 | */ |
64 | - protected static function _effective_version( $min_core_version ) { |
|
64 | + protected static function _effective_version($min_core_version) { |
|
65 | 65 | // versions: 4 . 3 . 1 . p . 123 |
66 | 66 | // offsets: 0 . 1 . 2 . 3 . 4 |
67 | - $version_parts = explode( '.', $min_core_version ); |
|
67 | + $version_parts = explode('.', $min_core_version); |
|
68 | 68 | //check they specified the micro version (after 2nd period) |
69 | - if ( ! isset( $version_parts[2] ) ) { |
|
69 | + if ( ! isset($version_parts[2])) { |
|
70 | 70 | $version_parts[2] = '0'; |
71 | 71 | } |
72 | 72 | //if they didn't specify the 'p', or 'rc' part. Just assume the lowest possible |
73 | 73 | //soon we can assume that's 'rc', but this current version is 'alpha' |
74 | - if ( ! isset( $version_parts[3] ) ) { |
|
74 | + if ( ! isset($version_parts[3])) { |
|
75 | 75 | $version_parts[3] = 'dev'; |
76 | 76 | } |
77 | - if ( ! isset( $version_parts[4] ) ) { |
|
77 | + if ( ! isset($version_parts[4])) { |
|
78 | 78 | $version_parts[4] = '000'; |
79 | 79 | } |
80 | - return implode( '.', $version_parts ); |
|
80 | + return implode('.', $version_parts); |
|
81 | 81 | } |
82 | 82 | |
83 | 83 | |
@@ -94,8 +94,8 @@ discard block |
||
94 | 94 | $actual_core_version = EVENT_ESPRESSO_VERSION |
95 | 95 | ) { |
96 | 96 | return version_compare( |
97 | - self::_effective_version( $actual_core_version ), |
|
98 | - self::_effective_version( $min_core_version ), |
|
97 | + self::_effective_version($actual_core_version), |
|
98 | + self::_effective_version($min_core_version), |
|
99 | 99 | '>=' |
100 | 100 | ); |
101 | 101 | } |
@@ -217,7 +217,7 @@ discard block |
||
217 | 217 | * @throws EE_Error |
218 | 218 | * @return void |
219 | 219 | */ |
220 | - public static function register( $addon_name = '', $setup_args = array() ) { |
|
220 | + public static function register($addon_name = '', $setup_args = array()) { |
|
221 | 221 | // required fields MUST be present, so let's make sure they are. |
222 | 222 | \EE_Register_Addon::_verify_parameters($addon_name, $setup_args); |
223 | 223 | // get class name for addon |
@@ -227,13 +227,13 @@ discard block |
||
227 | 227 | // setup PUE |
228 | 228 | \EE_Register_Addon::_parse_pue_options($addon_name, $class_name, $setup_args); |
229 | 229 | // does this addon work with this version of core or WordPress ? |
230 | - if ( ! \EE_Register_Addon::_addon_is_compatible($addon_name, $addon_settings) ) { |
|
230 | + if ( ! \EE_Register_Addon::_addon_is_compatible($addon_name, $addon_settings)) { |
|
231 | 231 | return; |
232 | 232 | } |
233 | 233 | // register namespaces |
234 | 234 | \EE_Register_Addon::_setup_namespaces($addon_settings); |
235 | 235 | // check if this is an activation request |
236 | - if ( \EE_Register_Addon::_addon_activation($addon_name, $addon_settings)) { |
|
236 | + if (\EE_Register_Addon::_addon_activation($addon_name, $addon_settings)) { |
|
237 | 237 | // dont bother setting up the rest of the addon atm |
238 | 238 | return; |
239 | 239 | } |
@@ -327,7 +327,7 @@ discard block |
||
327 | 327 | } else { |
328 | 328 | $class_name = $setup_args['class_name']; |
329 | 329 | } |
330 | - return strpos($class_name, 'EE_') === 0 ? $class_name : 'EE_' . $class_name; |
|
330 | + return strpos($class_name, 'EE_') === 0 ? $class_name : 'EE_'.$class_name; |
|
331 | 331 | } |
332 | 332 | |
333 | 333 | |
@@ -345,105 +345,105 @@ discard block |
||
345 | 345 | 'class_name' => $class_name, |
346 | 346 | // the addon slug for use in URLs, etc |
347 | 347 | 'plugin_slug' => isset($setup_args['plugin_slug']) |
348 | - ? (string)$setup_args['plugin_slug'] |
|
348 | + ? (string) $setup_args['plugin_slug'] |
|
349 | 349 | : '', |
350 | 350 | // page slug to be used when generating the "Settings" link on the WP plugin page |
351 | 351 | 'plugin_action_slug' => isset($setup_args['plugin_action_slug']) |
352 | - ? (string)$setup_args['plugin_action_slug'] |
|
352 | + ? (string) $setup_args['plugin_action_slug'] |
|
353 | 353 | : '', |
354 | 354 | // the "software" version for the addon |
355 | 355 | 'version' => isset($setup_args['version']) |
356 | - ? (string)$setup_args['version'] |
|
356 | + ? (string) $setup_args['version'] |
|
357 | 357 | : '', |
358 | 358 | // the minimum version of EE Core that the addon will work with |
359 | 359 | 'min_core_version' => isset($setup_args['min_core_version']) |
360 | - ? (string)$setup_args['min_core_version'] |
|
360 | + ? (string) $setup_args['min_core_version'] |
|
361 | 361 | : '', |
362 | 362 | // the minimum version of WordPress that the addon will work with |
363 | 363 | 'min_wp_version' => isset($setup_args['min_wp_version']) |
364 | - ? (string)$setup_args['min_wp_version'] |
|
364 | + ? (string) $setup_args['min_wp_version'] |
|
365 | 365 | : EE_MIN_WP_VER_REQUIRED, |
366 | 366 | // full server path to main file (file loaded directly by WP) |
367 | 367 | 'main_file_path' => isset($setup_args['main_file_path']) |
368 | - ? (string)$setup_args['main_file_path'] |
|
368 | + ? (string) $setup_args['main_file_path'] |
|
369 | 369 | : '', |
370 | 370 | // path to folder containing files for integrating with the EE core admin and/or setting up EE admin pages |
371 | 371 | 'admin_path' => isset($setup_args['admin_path']) |
372 | - ? (string)$setup_args['admin_path'] : '', |
|
372 | + ? (string) $setup_args['admin_path'] : '', |
|
373 | 373 | // a method to be called when the EE Admin is first invoked, can be used for hooking into any admin page |
374 | 374 | 'admin_callback' => isset($setup_args['admin_callback']) |
375 | - ? (string)$setup_args['admin_callback'] |
|
375 | + ? (string) $setup_args['admin_callback'] |
|
376 | 376 | : '', |
377 | 377 | // the section name for this addon's configuration settings section (defaults to "addons") |
378 | 378 | 'config_section' => isset($setup_args['config_section']) |
379 | - ? (string)$setup_args['config_section'] |
|
379 | + ? (string) $setup_args['config_section'] |
|
380 | 380 | : 'addons', |
381 | 381 | // the class name for this addon's configuration settings object |
382 | 382 | 'config_class' => isset($setup_args['config_class']) |
383 | - ? (string)$setup_args['config_class'] : '', |
|
383 | + ? (string) $setup_args['config_class'] : '', |
|
384 | 384 | //the name given to the config for this addons' configuration settings object (optional) |
385 | 385 | 'config_name' => isset($setup_args['config_name']) |
386 | - ? (string)$setup_args['config_name'] : '', |
|
386 | + ? (string) $setup_args['config_name'] : '', |
|
387 | 387 | // an array of "class names" => "full server paths" for any classes that might be invoked by the addon |
388 | 388 | 'autoloader_paths' => isset($setup_args['autoloader_paths']) |
389 | - ? (array)$setup_args['autoloader_paths'] |
|
389 | + ? (array) $setup_args['autoloader_paths'] |
|
390 | 390 | : array(), |
391 | 391 | // an array of "full server paths" for any folders containing classes that might be invoked by the addon |
392 | 392 | 'autoloader_folders' => isset($setup_args['autoloader_folders']) |
393 | - ? (array)$setup_args['autoloader_folders'] |
|
393 | + ? (array) $setup_args['autoloader_folders'] |
|
394 | 394 | : array(), |
395 | 395 | // array of full server paths to any EE_DMS data migration scripts used by the addon |
396 | 396 | 'dms_paths' => isset($setup_args['dms_paths']) |
397 | - ? (array)$setup_args['dms_paths'] |
|
397 | + ? (array) $setup_args['dms_paths'] |
|
398 | 398 | : array(), |
399 | 399 | // array of full server paths to any EED_Modules used by the addon |
400 | 400 | 'module_paths' => isset($setup_args['module_paths']) |
401 | - ? (array)$setup_args['module_paths'] |
|
401 | + ? (array) $setup_args['module_paths'] |
|
402 | 402 | : array(), |
403 | 403 | // array of full server paths to any EES_Shortcodes used by the addon |
404 | 404 | 'shortcode_paths' => isset($setup_args['shortcode_paths']) |
405 | - ? (array)$setup_args['shortcode_paths'] |
|
405 | + ? (array) $setup_args['shortcode_paths'] |
|
406 | 406 | : array(), |
407 | 407 | // array of full server paths to any WP_Widgets used by the addon |
408 | 408 | 'widget_paths' => isset($setup_args['widget_paths']) |
409 | - ? (array)$setup_args['widget_paths'] |
|
409 | + ? (array) $setup_args['widget_paths'] |
|
410 | 410 | : array(), |
411 | 411 | // array of PUE options used by the addon |
412 | 412 | 'pue_options' => isset($setup_args['pue_options']) |
413 | - ? (array)$setup_args['pue_options'] |
|
413 | + ? (array) $setup_args['pue_options'] |
|
414 | 414 | : array(), |
415 | 415 | 'message_types' => isset($setup_args['message_types']) |
416 | - ? (array)$setup_args['message_types'] |
|
416 | + ? (array) $setup_args['message_types'] |
|
417 | 417 | : array(), |
418 | 418 | 'capabilities' => isset($setup_args['capabilities']) |
419 | - ? (array)$setup_args['capabilities'] |
|
419 | + ? (array) $setup_args['capabilities'] |
|
420 | 420 | : array(), |
421 | 421 | 'capability_maps' => isset($setup_args['capability_maps']) |
422 | - ? (array)$setup_args['capability_maps'] |
|
422 | + ? (array) $setup_args['capability_maps'] |
|
423 | 423 | : array(), |
424 | 424 | 'model_paths' => isset($setup_args['model_paths']) |
425 | - ? (array)$setup_args['model_paths'] |
|
425 | + ? (array) $setup_args['model_paths'] |
|
426 | 426 | : array(), |
427 | 427 | 'class_paths' => isset($setup_args['class_paths']) |
428 | - ? (array)$setup_args['class_paths'] |
|
428 | + ? (array) $setup_args['class_paths'] |
|
429 | 429 | : array(), |
430 | 430 | 'model_extension_paths' => isset($setup_args['model_extension_paths']) |
431 | - ? (array)$setup_args['model_extension_paths'] |
|
431 | + ? (array) $setup_args['model_extension_paths'] |
|
432 | 432 | : array(), |
433 | 433 | 'class_extension_paths' => isset($setup_args['class_extension_paths']) |
434 | - ? (array)$setup_args['class_extension_paths'] |
|
434 | + ? (array) $setup_args['class_extension_paths'] |
|
435 | 435 | : array(), |
436 | 436 | 'custom_post_types' => isset($setup_args['custom_post_types']) |
437 | - ? (array)$setup_args['custom_post_types'] |
|
437 | + ? (array) $setup_args['custom_post_types'] |
|
438 | 438 | : array(), |
439 | 439 | 'custom_taxonomies' => isset($setup_args['custom_taxonomies']) |
440 | - ? (array)$setup_args['custom_taxonomies'] |
|
440 | + ? (array) $setup_args['custom_taxonomies'] |
|
441 | 441 | : array(), |
442 | 442 | 'payment_method_paths' => isset($setup_args['payment_method_paths']) |
443 | - ? (array)$setup_args['payment_method_paths'] |
|
443 | + ? (array) $setup_args['payment_method_paths'] |
|
444 | 444 | : array(), |
445 | 445 | 'default_terms' => isset($setup_args['default_terms']) |
446 | - ? (array)$setup_args['default_terms'] |
|
446 | + ? (array) $setup_args['default_terms'] |
|
447 | 447 | : array(), |
448 | 448 | // if not empty, inserts a new table row after this plugin's row on the WP Plugins page |
449 | 449 | // that can be used for adding upgrading/marketing info |
@@ -455,7 +455,7 @@ discard block |
||
455 | 455 | $setup_args['namespace']['FQNS'], |
456 | 456 | $setup_args['namespace']['DIR'] |
457 | 457 | ) |
458 | - ? (array)$setup_args['namespace'] |
|
458 | + ? (array) $setup_args['namespace'] |
|
459 | 459 | : array(), |
460 | 460 | ); |
461 | 461 | // if plugin_action_slug is NOT set, but an admin page path IS set, |
@@ -476,7 +476,7 @@ discard block |
||
476 | 476 | * @param array $addon_settings |
477 | 477 | * @return boolean |
478 | 478 | */ |
479 | - private static function _addon_is_compatible( $addon_name, array $addon_settings ) { |
|
479 | + private static function _addon_is_compatible($addon_name, array $addon_settings) { |
|
480 | 480 | global $wp_version; |
481 | 481 | $incompatibility_message = ''; |
482 | 482 | //check whether this addon version is compatible with EE core |
@@ -552,20 +552,20 @@ discard block |
||
552 | 552 | * @param array $setup_args |
553 | 553 | * @return void |
554 | 554 | */ |
555 | - private static function _parse_pue_options( $addon_name, $class_name, array $setup_args ) { |
|
555 | + private static function _parse_pue_options($addon_name, $class_name, array $setup_args) { |
|
556 | 556 | if ( ! empty($setup_args['pue_options'])) { |
557 | 557 | self::$_settings[$addon_name]['pue_options'] = array( |
558 | 558 | 'pue_plugin_slug' => isset($setup_args['pue_options']['pue_plugin_slug']) |
559 | - ? (string)$setup_args['pue_options']['pue_plugin_slug'] |
|
560 | - : 'espresso_' . strtolower($class_name), |
|
559 | + ? (string) $setup_args['pue_options']['pue_plugin_slug'] |
|
560 | + : 'espresso_'.strtolower($class_name), |
|
561 | 561 | 'plugin_basename' => isset($setup_args['pue_options']['plugin_basename']) |
562 | - ? (string)$setup_args['pue_options']['plugin_basename'] |
|
562 | + ? (string) $setup_args['pue_options']['plugin_basename'] |
|
563 | 563 | : plugin_basename($setup_args['main_file_path']), |
564 | 564 | 'checkPeriod' => isset($setup_args['pue_options']['checkPeriod']) |
565 | - ? (string)$setup_args['pue_options']['checkPeriod'] |
|
565 | + ? (string) $setup_args['pue_options']['checkPeriod'] |
|
566 | 566 | : '24', |
567 | 567 | 'use_wp_update' => isset($setup_args['pue_options']['use_wp_update']) |
568 | - ? (string)$setup_args['pue_options']['use_wp_update'] |
|
568 | + ? (string) $setup_args['pue_options']['use_wp_update'] |
|
569 | 569 | : false, |
570 | 570 | ); |
571 | 571 | add_action( |
@@ -607,7 +607,7 @@ discard block |
||
607 | 607 | * @param array $addon_settings |
608 | 608 | * @return bool |
609 | 609 | */ |
610 | - private static function _addon_activation( $addon_name, array $addon_settings ) { |
|
610 | + private static function _addon_activation($addon_name, array $addon_settings) { |
|
611 | 611 | // this is an activation request |
612 | 612 | if (did_action('activate_plugin')) { |
613 | 613 | //to find if THIS is the addon that was activated, |
@@ -664,7 +664,7 @@ discard block |
||
664 | 664 | } |
665 | 665 | // setup autoloaders for folders |
666 | 666 | if ( ! empty(self::$_settings[$addon_name]['autoloader_folders'])) { |
667 | - foreach ((array)self::$_settings[$addon_name]['autoloader_folders'] as $autoloader_folder) { |
|
667 | + foreach ((array) self::$_settings[$addon_name]['autoloader_folders'] as $autoloader_folder) { |
|
668 | 668 | EEH_Autoloader::register_autoloaders_for_each_file_in_folder($autoloader_folder); |
669 | 669 | } |
670 | 670 | } |
@@ -679,7 +679,7 @@ discard block |
||
679 | 679 | * @return void |
680 | 680 | * @throws \EE_Error |
681 | 681 | */ |
682 | - private static function _register_models_and_extensions( $addon_name ) { |
|
682 | + private static function _register_models_and_extensions($addon_name) { |
|
683 | 683 | // register new models |
684 | 684 | if ( |
685 | 685 | ! empty(self::$_settings[$addon_name]['model_paths']) |
@@ -715,7 +715,7 @@ discard block |
||
715 | 715 | * @return void |
716 | 716 | * @throws \EE_Error |
717 | 717 | */ |
718 | - private static function _register_data_migration_scripts( $addon_name ) { |
|
718 | + private static function _register_data_migration_scripts($addon_name) { |
|
719 | 719 | // setup DMS |
720 | 720 | if ( ! empty(self::$_settings[$addon_name]['dms_paths'])) { |
721 | 721 | EE_Register_Data_Migration_Scripts::register( |
@@ -731,7 +731,7 @@ discard block |
||
731 | 731 | * @return void |
732 | 732 | * @throws \EE_Error |
733 | 733 | */ |
734 | - private static function _register_config( $addon_name ) { |
|
734 | + private static function _register_config($addon_name) { |
|
735 | 735 | // if config_class is present let's register config. |
736 | 736 | if ( ! empty(self::$_settings[$addon_name]['config_class'])) { |
737 | 737 | EE_Register_Config::register( |
@@ -750,7 +750,7 @@ discard block |
||
750 | 750 | * @return void |
751 | 751 | * @throws \EE_Error |
752 | 752 | */ |
753 | - private static function _register_admin_pages( $addon_name ) { |
|
753 | + private static function _register_admin_pages($addon_name) { |
|
754 | 754 | if ( ! empty(self::$_settings[$addon_name]['admin_path'])) { |
755 | 755 | EE_Register_Admin_Page::register( |
756 | 756 | $addon_name, |
@@ -765,7 +765,7 @@ discard block |
||
765 | 765 | * @return void |
766 | 766 | * @throws \EE_Error |
767 | 767 | */ |
768 | - private static function _register_modules( $addon_name ) { |
|
768 | + private static function _register_modules($addon_name) { |
|
769 | 769 | if ( ! empty(self::$_settings[$addon_name]['module_paths'])) { |
770 | 770 | EE_Register_Module::register( |
771 | 771 | $addon_name, |
@@ -780,7 +780,7 @@ discard block |
||
780 | 780 | * @return void |
781 | 781 | * @throws \EE_Error |
782 | 782 | */ |
783 | - private static function _register_shortcodes( $addon_name ) { |
|
783 | + private static function _register_shortcodes($addon_name) { |
|
784 | 784 | if ( ! empty(self::$_settings[$addon_name]['shortcode_paths'])) { |
785 | 785 | EE_Register_Shortcode::register( |
786 | 786 | $addon_name, |
@@ -795,7 +795,7 @@ discard block |
||
795 | 795 | * @return void |
796 | 796 | * @throws \EE_Error |
797 | 797 | */ |
798 | - private static function _register_widgets( $addon_name ) { |
|
798 | + private static function _register_widgets($addon_name) { |
|
799 | 799 | if ( ! empty(self::$_settings[$addon_name]['widget_paths'])) { |
800 | 800 | EE_Register_Widget::register( |
801 | 801 | $addon_name, |
@@ -810,7 +810,7 @@ discard block |
||
810 | 810 | * @return void |
811 | 811 | * @throws \EE_Error |
812 | 812 | */ |
813 | - private static function _register_capabilities( $addon_name ) { |
|
813 | + private static function _register_capabilities($addon_name) { |
|
814 | 814 | if ( ! empty(self::$_settings[$addon_name]['capabilities'])) { |
815 | 815 | EE_Register_Capabilities::register( |
816 | 816 | $addon_name, |
@@ -828,7 +828,7 @@ discard block |
||
828 | 828 | * @return void |
829 | 829 | * @throws \EE_Error |
830 | 830 | */ |
831 | - private static function _register_message_types( $addon_name ) { |
|
831 | + private static function _register_message_types($addon_name) { |
|
832 | 832 | if ( ! empty(self::$_settings[$addon_name]['message_types'])) { |
833 | 833 | add_action( |
834 | 834 | 'EE_Brewing_Regular___messages_caf', |
@@ -843,7 +843,7 @@ discard block |
||
843 | 843 | * @return void |
844 | 844 | * @throws \EE_Error |
845 | 845 | */ |
846 | - private static function _register_custom_post_types( $addon_name ) { |
|
846 | + private static function _register_custom_post_types($addon_name) { |
|
847 | 847 | if ( |
848 | 848 | ! empty(self::$_settings[$addon_name]['custom_post_types']) |
849 | 849 | || ! empty(self::$_settings[$addon_name]['custom_taxonomies']) |
@@ -865,7 +865,7 @@ discard block |
||
865 | 865 | * @return void |
866 | 866 | * @throws \EE_Error |
867 | 867 | */ |
868 | - private static function _register_payment_methods( $addon_name ) { |
|
868 | + private static function _register_payment_methods($addon_name) { |
|
869 | 869 | if ( ! empty(self::$_settings[$addon_name]['payment_method_paths'])) { |
870 | 870 | EE_Register_Payment_Method::register( |
871 | 871 | $addon_name, |
@@ -882,25 +882,25 @@ discard block |
||
882 | 882 | * @param string $addon_name |
883 | 883 | * @return EE_Addon |
884 | 884 | */ |
885 | - private static function _load_and_init_addon_class( $addon_name ) { |
|
885 | + private static function _load_and_init_addon_class($addon_name) { |
|
886 | 886 | $addon = EE_Registry::instance()->load_addon( |
887 | - dirname( self::$_settings[ $addon_name ]['main_file_path'] ), |
|
888 | - self::$_settings[ $addon_name ]['class_name'] |
|
887 | + dirname(self::$_settings[$addon_name]['main_file_path']), |
|
888 | + self::$_settings[$addon_name]['class_name'] |
|
889 | 889 | ); |
890 | - $addon->set_name( $addon_name ); |
|
891 | - $addon->set_plugin_slug( self::$_settings[ $addon_name ]['plugin_slug'] ); |
|
892 | - $addon->set_plugin_basename( self::$_settings[ $addon_name ]['plugin_basename'] ); |
|
893 | - $addon->set_main_plugin_file( self::$_settings[ $addon_name ]['main_file_path'] ); |
|
894 | - $addon->set_plugin_action_slug( self::$_settings[ $addon_name ]['plugin_action_slug'] ); |
|
895 | - $addon->set_plugins_page_row( self::$_settings[ $addon_name ]['plugins_page_row'] ); |
|
896 | - $addon->set_version( self::$_settings[ $addon_name ]['version'] ); |
|
897 | - $addon->set_min_core_version( self::_effective_version( self::$_settings[ $addon_name ]['min_core_version'] ) ); |
|
898 | - $addon->set_config_section( self::$_settings[ $addon_name ]['config_section'] ); |
|
899 | - $addon->set_config_class( self::$_settings[ $addon_name ]['config_class'] ); |
|
900 | - $addon->set_config_name( self::$_settings[ $addon_name ]['config_name'] ); |
|
890 | + $addon->set_name($addon_name); |
|
891 | + $addon->set_plugin_slug(self::$_settings[$addon_name]['plugin_slug']); |
|
892 | + $addon->set_plugin_basename(self::$_settings[$addon_name]['plugin_basename']); |
|
893 | + $addon->set_main_plugin_file(self::$_settings[$addon_name]['main_file_path']); |
|
894 | + $addon->set_plugin_action_slug(self::$_settings[$addon_name]['plugin_action_slug']); |
|
895 | + $addon->set_plugins_page_row(self::$_settings[$addon_name]['plugins_page_row']); |
|
896 | + $addon->set_version(self::$_settings[$addon_name]['version']); |
|
897 | + $addon->set_min_core_version(self::_effective_version(self::$_settings[$addon_name]['min_core_version'])); |
|
898 | + $addon->set_config_section(self::$_settings[$addon_name]['config_section']); |
|
899 | + $addon->set_config_class(self::$_settings[$addon_name]['config_class']); |
|
900 | + $addon->set_config_name(self::$_settings[$addon_name]['config_name']); |
|
901 | 901 | //unfortunately this can't be hooked in upon construction, because we don't have |
902 | 902 | //the plugin mainfile's path upon construction. |
903 | - register_deactivation_hook( $addon->get_main_plugin_file(), array( $addon, 'deactivation' ) ); |
|
903 | + register_deactivation_hook($addon->get_main_plugin_file(), array($addon, 'deactivation')); |
|
904 | 904 | // call any additional admin_callback functions during load_admin_controller hook |
905 | 905 | if ( ! empty(self::$_settings[$addon_name]['admin_callback'])) { |
906 | 906 | add_action( |
@@ -920,18 +920,18 @@ discard block |
||
920 | 920 | */ |
921 | 921 | public static function load_pue_update() { |
922 | 922 | // load PUE client |
923 | - require_once EE_THIRD_PARTY . 'pue' . DS . 'pue-client.php'; |
|
923 | + require_once EE_THIRD_PARTY.'pue'.DS.'pue-client.php'; |
|
924 | 924 | // cycle thru settings |
925 | - foreach ( self::$_settings as $settings ) { |
|
926 | - if ( ! empty( $settings['pue_options'] ) ) { |
|
925 | + foreach (self::$_settings as $settings) { |
|
926 | + if ( ! empty($settings['pue_options'])) { |
|
927 | 927 | // initiate the class and start the plugin update engine! |
928 | 928 | new PluginUpdateEngineChecker( |
929 | 929 | // host file URL |
930 | 930 | 'https://eventespresso.com', |
931 | 931 | // plugin slug(s) |
932 | 932 | array( |
933 | - 'premium' => array( 'p' => $settings['pue_options']['pue_plugin_slug'] ), |
|
934 | - 'prerelease' => array( 'beta' => $settings['pue_options']['pue_plugin_slug'] . '-pr' ), |
|
933 | + 'premium' => array('p' => $settings['pue_options']['pue_plugin_slug']), |
|
934 | + 'prerelease' => array('beta' => $settings['pue_options']['pue_plugin_slug'].'-pr'), |
|
935 | 935 | ), |
936 | 936 | // options |
937 | 937 | array( |
@@ -959,9 +959,9 @@ discard block |
||
959 | 959 | * @throws \EE_Error |
960 | 960 | */ |
961 | 961 | public static function register_message_types() { |
962 | - foreach ( self::$_settings as $addon_name => $settings ) { |
|
962 | + foreach (self::$_settings as $addon_name => $settings) { |
|
963 | 963 | if ( ! empty($settings['message_types'])) { |
964 | - foreach ((array)$settings['message_types'] as $message_type => $message_type_settings) { |
|
964 | + foreach ((array) $settings['message_types'] as $message_type => $message_type_settings) { |
|
965 | 965 | EE_Register_Message_Type::register($message_type, $message_type_settings); |
966 | 966 | } |
967 | 967 | } |
@@ -978,74 +978,74 @@ discard block |
||
978 | 978 | * @throws EE_Error |
979 | 979 | * @return void |
980 | 980 | */ |
981 | - public static function deregister( $addon_name = null ) { |
|
982 | - if ( isset( self::$_settings[ $addon_name ] ) ) { |
|
981 | + public static function deregister($addon_name = null) { |
|
982 | + if (isset(self::$_settings[$addon_name])) { |
|
983 | 983 | do_action('AHEE__EE_Register_Addon__deregister__before', $addon_name); |
984 | - $class_name = self::$_settings[ $addon_name ]['class_name']; |
|
985 | - if ( ! empty( self::$_settings[ $addon_name ]['dms_paths'] ) ) { |
|
984 | + $class_name = self::$_settings[$addon_name]['class_name']; |
|
985 | + if ( ! empty(self::$_settings[$addon_name]['dms_paths'])) { |
|
986 | 986 | // setup DMS |
987 | - EE_Register_Data_Migration_Scripts::deregister( $addon_name ); |
|
987 | + EE_Register_Data_Migration_Scripts::deregister($addon_name); |
|
988 | 988 | } |
989 | - if ( ! empty( self::$_settings[ $addon_name ]['admin_path'] ) ) { |
|
989 | + if ( ! empty(self::$_settings[$addon_name]['admin_path'])) { |
|
990 | 990 | // register admin page |
991 | - EE_Register_Admin_Page::deregister( $addon_name ); |
|
991 | + EE_Register_Admin_Page::deregister($addon_name); |
|
992 | 992 | } |
993 | - if ( ! empty( self::$_settings[ $addon_name ]['module_paths'] ) ) { |
|
993 | + if ( ! empty(self::$_settings[$addon_name]['module_paths'])) { |
|
994 | 994 | // add to list of modules to be registered |
995 | - EE_Register_Module::deregister( $addon_name ); |
|
995 | + EE_Register_Module::deregister($addon_name); |
|
996 | 996 | } |
997 | - if ( ! empty( self::$_settings[ $addon_name ]['shortcode_paths'] ) ) { |
|
997 | + if ( ! empty(self::$_settings[$addon_name]['shortcode_paths'])) { |
|
998 | 998 | // add to list of shortcodes to be registered |
999 | - EE_Register_Shortcode::deregister( $addon_name ); |
|
999 | + EE_Register_Shortcode::deregister($addon_name); |
|
1000 | 1000 | } |
1001 | - if ( ! empty( self::$_settings[ $addon_name ]['config_class'] ) ) { |
|
1001 | + if ( ! empty(self::$_settings[$addon_name]['config_class'])) { |
|
1002 | 1002 | // if config_class present let's register config. |
1003 | - EE_Register_Config::deregister( self::$_settings[ $addon_name ]['config_class'] ); |
|
1003 | + EE_Register_Config::deregister(self::$_settings[$addon_name]['config_class']); |
|
1004 | 1004 | } |
1005 | - if ( ! empty( self::$_settings[ $addon_name ]['widget_paths'] ) ) { |
|
1005 | + if ( ! empty(self::$_settings[$addon_name]['widget_paths'])) { |
|
1006 | 1006 | // add to list of widgets to be registered |
1007 | - EE_Register_Widget::deregister( $addon_name ); |
|
1007 | + EE_Register_Widget::deregister($addon_name); |
|
1008 | 1008 | } |
1009 | - if ( ! empty( self::$_settings[ $addon_name ]['model_paths'] ) |
|
1009 | + if ( ! empty(self::$_settings[$addon_name]['model_paths']) |
|
1010 | 1010 | || |
1011 | - ! empty( self::$_settings[ $addon_name ]['class_paths'] ) |
|
1011 | + ! empty(self::$_settings[$addon_name]['class_paths']) |
|
1012 | 1012 | ) { |
1013 | 1013 | // add to list of shortcodes to be registered |
1014 | - EE_Register_Model::deregister( $addon_name ); |
|
1014 | + EE_Register_Model::deregister($addon_name); |
|
1015 | 1015 | } |
1016 | - if ( ! empty( self::$_settings[ $addon_name ]['model_extension_paths'] ) |
|
1016 | + if ( ! empty(self::$_settings[$addon_name]['model_extension_paths']) |
|
1017 | 1017 | || |
1018 | - ! empty( self::$_settings[ $addon_name ]['class_extension_paths'] ) |
|
1018 | + ! empty(self::$_settings[$addon_name]['class_extension_paths']) |
|
1019 | 1019 | ) { |
1020 | 1020 | // add to list of shortcodes to be registered |
1021 | - EE_Register_Model_Extensions::deregister( $addon_name ); |
|
1021 | + EE_Register_Model_Extensions::deregister($addon_name); |
|
1022 | 1022 | } |
1023 | - if ( ! empty( self::$_settings[ $addon_name ]['message_types'] ) ) { |
|
1024 | - foreach ((array)self::$_settings[ $addon_name ]['message_types'] as $message_type => $message_type_settings ) |
|
1023 | + if ( ! empty(self::$_settings[$addon_name]['message_types'])) { |
|
1024 | + foreach ((array) self::$_settings[$addon_name]['message_types'] as $message_type => $message_type_settings) |
|
1025 | 1025 | { |
1026 | - EE_Register_Message_Type::deregister( $message_type ); |
|
1026 | + EE_Register_Message_Type::deregister($message_type); |
|
1027 | 1027 | } |
1028 | 1028 | } |
1029 | 1029 | //deregister capabilities for addon |
1030 | 1030 | if ( |
1031 | - ! empty( self::$_settings[ $addon_name ]['capabilities'] ) |
|
1032 | - || ! empty( self::$_settings[ $addon_name ]['capability_maps'] ) |
|
1031 | + ! empty(self::$_settings[$addon_name]['capabilities']) |
|
1032 | + || ! empty(self::$_settings[$addon_name]['capability_maps']) |
|
1033 | 1033 | ) { |
1034 | - EE_Register_Capabilities::deregister( $addon_name ); |
|
1034 | + EE_Register_Capabilities::deregister($addon_name); |
|
1035 | 1035 | } |
1036 | 1036 | //deregister custom_post_types for addon |
1037 | - if ( ! empty( self::$_settings[ $addon_name ]['custom_post_types'] ) ) { |
|
1038 | - EE_Register_CPT::deregister( $addon_name ); |
|
1037 | + if ( ! empty(self::$_settings[$addon_name]['custom_post_types'])) { |
|
1038 | + EE_Register_CPT::deregister($addon_name); |
|
1039 | 1039 | } |
1040 | 1040 | remove_action( |
1041 | - 'deactivate_' . EE_Registry::instance()->addons->{$class_name}->get_main_plugin_file_basename(), |
|
1042 | - array( EE_Registry::instance()->addons->{$class_name}, 'deactivation' ) |
|
1041 | + 'deactivate_'.EE_Registry::instance()->addons->{$class_name}->get_main_plugin_file_basename(), |
|
1042 | + array(EE_Registry::instance()->addons->{$class_name}, 'deactivation') |
|
1043 | 1043 | ); |
1044 | 1044 | remove_action( |
1045 | 1045 | 'AHEE__EE_System__perform_activations_upgrades_and_migrations', |
1046 | - array( EE_Registry::instance()->addons->{$class_name}, 'initialize_db_if_no_migrations_required' ) |
|
1046 | + array(EE_Registry::instance()->addons->{$class_name}, 'initialize_db_if_no_migrations_required') |
|
1047 | 1047 | ); |
1048 | - unset( EE_Registry::instance()->addons->{$class_name}, self::$_settings[ $addon_name ] ); |
|
1048 | + unset(EE_Registry::instance()->addons->{$class_name}, self::$_settings[$addon_name]); |
|
1049 | 1049 | do_action('AHEE__EE_Register_Addon__deregister__after', $addon_name); |
1050 | 1050 | } |
1051 | 1051 | } |
@@ -2,7 +2,7 @@ discard block |
||
2 | 2 | use EventEspresso\core\exceptions\UnexpectedEntityException; |
3 | 3 | |
4 | 4 | if ( ! defined('EVENT_ESPRESSO_VERSION')) { |
5 | - exit('No direct script access allowed'); |
|
5 | + exit('No direct script access allowed'); |
|
6 | 6 | } |
7 | 7 | |
8 | 8 | |
@@ -21,920 +21,920 @@ discard block |
||
21 | 21 | class EED_Ticket_Sales_Monitor extends EED_Module |
22 | 22 | { |
23 | 23 | |
24 | - const debug = false; // true false |
|
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 | - /** |
|
59 | - * set_hooks - for hooking into EE Core, other modules, etc |
|
60 | - * |
|
61 | - * @access public |
|
62 | - * @return void |
|
63 | - */ |
|
64 | - public static function set_hooks() |
|
65 | - { |
|
66 | - // release tickets for expired carts |
|
67 | - add_action('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('FHEE__EE_Ticket_Selector___add_ticket_to_cart__ticket_qty', |
|
73 | - array('EED_Ticket_Sales_Monitor', 'validate_ticket_sale'), |
|
74 | - 20, 3 |
|
75 | - ); |
|
76 | - // add notices for sold out tickets |
|
77 | - add_action('AHEE__EE_Ticket_Selector__process_ticket_selections__after_tickets_added_to_cart', |
|
78 | - array('EED_Ticket_Sales_Monitor', 'post_notices'), |
|
79 | - 10 |
|
80 | - ); |
|
81 | - // handle ticket quantities adjusted in cart |
|
82 | - //add_action( |
|
83 | - // 'FHEE__EED_Multi_Event_Registration__adjust_line_item_quantity__line_item_quantity_updated', |
|
84 | - // array( 'EED_Ticket_Sales_Monitor', 'ticket_quantity_updated' ), |
|
85 | - // 10, 2 |
|
86 | - //); |
|
87 | - // handle tickets deleted from cart |
|
88 | - add_action( |
|
89 | - 'FHEE__EED_Multi_Event_Registration__delete_ticket__ticket_removed_from_cart', |
|
90 | - array('EED_Ticket_Sales_Monitor', 'ticket_removed_from_cart'), |
|
91 | - 10, 2 |
|
92 | - ); |
|
93 | - // handle emptied carts |
|
94 | - add_action( |
|
95 | - 'AHEE__EE_Session__reset_cart__before_reset', |
|
96 | - array('EED_Ticket_Sales_Monitor', 'session_cart_reset'), |
|
97 | - 10, 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, 1 |
|
103 | - ); |
|
104 | - // handle cancelled registrations |
|
105 | - add_action( |
|
106 | - 'AHEE__EE_Session__reset_checkout__before_reset', |
|
107 | - array('EED_Ticket_Sales_Monitor', 'session_checkout_reset'), |
|
108 | - 10, 1 |
|
109 | - ); |
|
110 | - // cron tasks |
|
111 | - add_action( |
|
112 | - 'AHEE__EE_Cron_Tasks__finalize_abandoned_transactions__abandoned_transaction', |
|
113 | - array('EED_Ticket_Sales_Monitor', 'process_abandoned_transactions'), |
|
114 | - 10, 1 |
|
115 | - ); |
|
116 | - add_action( |
|
117 | - 'AHEE__EE_Cron_Tasks__process_expired_transactions__incomplete_transaction', |
|
118 | - array('EED_Ticket_Sales_Monitor', 'process_abandoned_transactions'), |
|
119 | - 10, 1 |
|
120 | - ); |
|
121 | - add_action( |
|
122 | - 'AHEE__EE_Cron_Tasks__process_expired_transactions__failed_transaction', |
|
123 | - array('EED_Ticket_Sales_Monitor', 'process_failed_transactions'), |
|
124 | - 10, 1 |
|
125 | - ); |
|
126 | - } |
|
127 | - |
|
128 | - |
|
129 | - |
|
130 | - /** |
|
131 | - * set_hooks_admin - for hooking into EE Admin Core, other modules, etc |
|
132 | - * |
|
133 | - * @access public |
|
134 | - * @return void |
|
135 | - */ |
|
136 | - public static function set_hooks_admin() |
|
137 | - { |
|
138 | - EED_Ticket_Sales_Monitor::set_hooks(); |
|
139 | - } |
|
140 | - |
|
141 | - |
|
142 | - |
|
143 | - /** |
|
144 | - * @return EED_Ticket_Sales_Monitor|EED_Module |
|
145 | - */ |
|
146 | - public static function instance() |
|
147 | - { |
|
148 | - return parent::get_instance(__CLASS__); |
|
149 | - } |
|
150 | - |
|
151 | - |
|
152 | - |
|
153 | - /** |
|
154 | - * run |
|
155 | - * |
|
156 | - * @access public |
|
157 | - * @param WP_Query $WP_Query |
|
158 | - * @return void |
|
159 | - */ |
|
160 | - public function run($WP_Query) |
|
161 | - { |
|
162 | - } |
|
163 | - |
|
164 | - |
|
165 | - |
|
166 | - /********************************** PRE_TICKET_SALES **********************************/ |
|
167 | - |
|
168 | - |
|
169 | - |
|
170 | - /** |
|
171 | - * Retrieves grand totals from the line items that have no TXN ID |
|
172 | - * and timestamps less than the current time minus the session lifespan. |
|
173 | - * These are carts that have been abandoned before the "registrant" even attempted to checkout. |
|
174 | - * We're going to release the tickets for these line items before attempting to add more to the cart. |
|
175 | - * |
|
176 | - * @return void |
|
177 | - * @throws \EE_Error |
|
178 | - */ |
|
179 | - public static function release_tickets_for_expired_carts() |
|
180 | - { |
|
181 | - $expired_ticket_IDs = array(); |
|
182 | - $valid_ticket_line_items = array(); |
|
183 | - $total_line_items = EEM_Line_Item::instance()->get_total_line_items_with_no_transaction(); |
|
184 | - if(empty($total_line_items)){ |
|
185 | - return; |
|
186 | - } |
|
187 | - $expired = current_time('timestamp') - EE_Registry::instance()->SSN->lifespan(); |
|
188 | - foreach ($total_line_items as $total_line_item) { |
|
189 | - /** @var EE_Line_Item $total_line_item */ |
|
190 | - $ticket_line_items = EED_Ticket_Sales_Monitor::get_ticket_line_items_for_grand_total($total_line_item); |
|
191 | - foreach ($ticket_line_items as $ticket_line_item) { |
|
192 | - if(! $ticket_line_item instanceof EE_Line_Item) { |
|
193 | - continue; |
|
194 | - } |
|
195 | - if ($total_line_item->timestamp(true) <= $expired ) { |
|
196 | - $expired_ticket_IDs[$ticket_line_item->OBJ_ID()] = $ticket_line_item->OBJ_ID(); |
|
197 | - } else { |
|
198 | - $valid_ticket_line_items[$ticket_line_item->OBJ_ID()] = $ticket_line_item; |
|
199 | - } |
|
200 | - } |
|
201 | - } |
|
202 | - EED_Ticket_Sales_Monitor::release_reservations_for_tickets( |
|
203 | - \EEM_Ticket::instance()->get_tickets_with_IDs($expired_ticket_IDs), |
|
204 | - $valid_ticket_line_items |
|
205 | - ); |
|
206 | - } |
|
207 | - |
|
208 | - |
|
209 | - |
|
210 | - /********************************** VALIDATE_TICKET_SALE **********************************/ |
|
211 | - |
|
212 | - |
|
213 | - |
|
214 | - /** |
|
215 | - * validate_ticket_sales |
|
216 | - * callback for 'FHEE__EED_Ticket_Selector__process_ticket_selections__valid_post_data' |
|
217 | - * |
|
218 | - * @access public |
|
219 | - * @param int $qty |
|
220 | - * @param \EE_Ticket $ticket |
|
221 | - * @return bool |
|
222 | - * @throws UnexpectedEntityException |
|
223 | - * @throws EE_Error |
|
224 | - */ |
|
225 | - public static function validate_ticket_sale($qty = 1, EE_Ticket $ticket) |
|
226 | - { |
|
227 | - $qty = absint($qty); |
|
228 | - if ($qty > 0) { |
|
229 | - $qty = EED_Ticket_Sales_Monitor::instance()->_validate_ticket_sale($ticket, $qty); |
|
230 | - } |
|
231 | - if (self::debug) { |
|
232 | - echo '<br /><br /> ' . __LINE__ . ') ' . __METHOD__ . '()'; |
|
233 | - echo '<br /><br /><b> RETURNED QTY: ' . $qty . '</b>'; |
|
234 | - } |
|
235 | - return $qty; |
|
236 | - } |
|
237 | - |
|
238 | - |
|
239 | - |
|
240 | - /** |
|
241 | - * _validate_ticket_sale |
|
242 | - * checks whether an individual ticket is available for purchase based on datetime, and ticket details |
|
243 | - * |
|
244 | - * @access protected |
|
245 | - * @param \EE_Ticket $ticket |
|
246 | - * @param int $qty |
|
247 | - * @return int |
|
248 | - * @throws UnexpectedEntityException |
|
249 | - * @throws EE_Error |
|
250 | - */ |
|
251 | - protected function _validate_ticket_sale(EE_Ticket $ticket, $qty = 1) |
|
252 | - { |
|
253 | - if (self::debug) { |
|
254 | - echo '<br /><br /> ' . __LINE__ . ') ' . __METHOD__ . '() '; |
|
255 | - } |
|
256 | - if ( ! $ticket instanceof EE_Ticket) { |
|
257 | - return 0; |
|
258 | - } |
|
259 | - if (self::debug) { |
|
260 | - echo '<br /><b> . ticket->ID: ' . $ticket->ID() . '</b>'; |
|
261 | - echo '<br /> . original ticket->reserved: ' . $ticket->reserved(); |
|
262 | - } |
|
263 | - $ticket->refresh_from_db(); |
|
264 | - // first let's determine the ticket availability based on sales |
|
265 | - $available = $ticket->qty('saleable'); |
|
266 | - if (self::debug) { |
|
267 | - echo '<br /> . . . ticket->qty: ' . $ticket->qty(); |
|
268 | - echo '<br /> . . . ticket->sold: ' . $ticket->sold(); |
|
269 | - echo '<br /> . . . ticket->reserved: ' . $ticket->reserved(); |
|
270 | - echo '<br /> . . . ticket->qty(saleable): ' . $ticket->qty('saleable'); |
|
271 | - echo '<br /> . . . available: ' . $available; |
|
272 | - } |
|
273 | - if ($available < 1) { |
|
274 | - $this->_ticket_sold_out($ticket); |
|
275 | - return 0; |
|
276 | - } |
|
277 | - if (self::debug) { |
|
278 | - echo '<br /> . . . qty: ' . $qty; |
|
279 | - } |
|
280 | - if ($available < $qty) { |
|
281 | - $qty = $available; |
|
282 | - if (self::debug) { |
|
283 | - echo '<br /> . . . QTY ADJUSTED: ' . $qty; |
|
284 | - } |
|
285 | - $this->_ticket_quantity_decremented($ticket); |
|
286 | - } |
|
287 | - $this->_reserve_ticket($ticket, $qty); |
|
288 | - return $qty; |
|
289 | - } |
|
290 | - |
|
291 | - |
|
292 | - |
|
293 | - /** |
|
294 | - * _reserve_ticket |
|
295 | - * increments ticket reserved based on quantity passed |
|
296 | - * |
|
297 | - * @access protected |
|
298 | - * @param \EE_Ticket $ticket |
|
299 | - * @param int $quantity |
|
300 | - * @return bool |
|
301 | - * @throws EE_Error |
|
302 | - */ |
|
303 | - protected function _reserve_ticket(EE_Ticket $ticket, $quantity = 1) |
|
304 | - { |
|
305 | - if (self::debug) { |
|
306 | - echo '<br /><br /> . . . INCREASE RESERVED: ' . $quantity; |
|
307 | - } |
|
308 | - $ticket->increase_reserved($quantity); |
|
309 | - return $ticket->save(); |
|
310 | - } |
|
311 | - |
|
312 | - |
|
313 | - |
|
314 | - /** |
|
315 | - * _release_reserved_ticket |
|
316 | - * |
|
317 | - * @access protected |
|
318 | - * @param EE_Ticket $ticket |
|
319 | - * @param int $quantity |
|
320 | - * @return bool |
|
321 | - * @throws EE_Error |
|
322 | - */ |
|
323 | - protected function _release_reserved_ticket(EE_Ticket $ticket, $quantity = 1) |
|
324 | - { |
|
325 | - if (self::debug) { |
|
326 | - echo '<br /> . . . ticket->ID: ' . $ticket->ID(); |
|
327 | - echo '<br /> . . . ticket->reserved: ' . $ticket->reserved(); |
|
328 | - } |
|
329 | - $ticket->decrease_reserved($quantity); |
|
330 | - if (self::debug) { |
|
331 | - echo '<br /> . . . ticket->reserved: ' . $ticket->reserved(); |
|
332 | - } |
|
333 | - return $ticket->save() ? 1 : 0; |
|
334 | - } |
|
335 | - |
|
336 | - |
|
337 | - |
|
338 | - /** |
|
339 | - * _ticket_sold_out |
|
340 | - * removes quantities within the ticket selector based on zero ticket availability |
|
341 | - * |
|
342 | - * @access protected |
|
343 | - * @param \EE_Ticket $ticket |
|
344 | - * @return void |
|
345 | - * @throws UnexpectedEntityException |
|
346 | - * @throws EE_Error |
|
347 | - */ |
|
348 | - protected function _ticket_sold_out(EE_Ticket $ticket) |
|
349 | - { |
|
350 | - if (self::debug) { |
|
351 | - echo '<br /><br /> ' . __LINE__ . ') ' . __METHOD__ . '() '; |
|
352 | - echo '<br /> . . ticket->name: ' . $this->_get_ticket_and_event_name($ticket); |
|
353 | - } |
|
354 | - $this->sold_out_tickets[] = $this->_get_ticket_and_event_name($ticket); |
|
355 | - } |
|
356 | - |
|
357 | - |
|
358 | - |
|
359 | - /** |
|
360 | - * _ticket_quantity_decremented |
|
361 | - * adjusts quantities within the ticket selector based on decreased ticket availability |
|
362 | - * |
|
363 | - * @access protected |
|
364 | - * @param \EE_Ticket $ticket |
|
365 | - * @return void |
|
366 | - * @throws UnexpectedEntityException |
|
367 | - * @throws EE_Error |
|
368 | - */ |
|
369 | - protected function _ticket_quantity_decremented(EE_Ticket $ticket) |
|
370 | - { |
|
371 | - if (self::debug) { |
|
372 | - echo '<br /><br /> ' . __LINE__ . ') ' . __METHOD__ . '() '; |
|
373 | - echo '<br /> . . ticket->name: ' . $this->_get_ticket_and_event_name($ticket); |
|
374 | - } |
|
375 | - $this->decremented_tickets[] = $this->_get_ticket_and_event_name($ticket); |
|
376 | - } |
|
377 | - |
|
378 | - |
|
379 | - |
|
380 | - /** |
|
381 | - * _get_ticket_and_event_name |
|
382 | - * builds string out of ticket and event name |
|
383 | - * |
|
384 | - * @access protected |
|
385 | - * @param \EE_Ticket $ticket |
|
386 | - * @return string |
|
387 | - * @throws UnexpectedEntityException |
|
388 | - * @throws EE_Error |
|
389 | - */ |
|
390 | - protected function _get_ticket_and_event_name(EE_Ticket $ticket) |
|
391 | - { |
|
392 | - $event = $ticket->get_related_event(); |
|
393 | - if ($event instanceof EE_Event) { |
|
394 | - $ticket_name = sprintf( |
|
395 | - _x('%1$s for %2$s', 'ticket name for event name', 'event_espresso'), |
|
396 | - $ticket->name(), |
|
397 | - $event->name() |
|
398 | - ); |
|
399 | - } else { |
|
400 | - $ticket_name = $ticket->name(); |
|
401 | - } |
|
402 | - return $ticket_name; |
|
403 | - } |
|
404 | - |
|
405 | - |
|
406 | - |
|
407 | - /********************************** EVENT CART **********************************/ |
|
408 | - |
|
409 | - |
|
410 | - |
|
411 | - /** |
|
412 | - * ticket_quantity_updated |
|
413 | - * releases or reserves ticket(s) based on quantity passed |
|
414 | - * |
|
415 | - * @access public |
|
416 | - * @param EE_Line_Item $line_item |
|
417 | - * @param int $quantity |
|
418 | - * @return void |
|
419 | - * @throws EE_Error |
|
420 | - */ |
|
421 | - public static function ticket_quantity_updated(EE_Line_Item $line_item, $quantity = 1) |
|
422 | - { |
|
423 | - $ticket = EEM_Ticket::instance()->get_one_by_ID(absint($line_item->OBJ_ID())); |
|
424 | - if ($ticket instanceof EE_Ticket) { |
|
425 | - if ($quantity > 0) { |
|
426 | - EED_Ticket_Sales_Monitor::instance()->_reserve_ticket($ticket, $quantity); |
|
427 | - } else { |
|
428 | - EED_Ticket_Sales_Monitor::instance()->_release_reserved_ticket($ticket, $quantity); |
|
429 | - } |
|
430 | - } |
|
431 | - } |
|
432 | - |
|
433 | - |
|
434 | - |
|
435 | - /** |
|
436 | - * ticket_removed_from_cart |
|
437 | - * releases reserved ticket(s) based on quantity passed |
|
438 | - * |
|
439 | - * @access public |
|
440 | - * @param EE_Ticket $ticket |
|
441 | - * @param int $quantity |
|
442 | - * @return void |
|
443 | - * @throws EE_Error |
|
444 | - */ |
|
445 | - public static function ticket_removed_from_cart(EE_Ticket $ticket, $quantity = 1) |
|
446 | - { |
|
447 | - EED_Ticket_Sales_Monitor::instance()->_release_reserved_ticket($ticket, $quantity); |
|
448 | - } |
|
449 | - |
|
450 | - |
|
451 | - |
|
452 | - /********************************** POST_NOTICES **********************************/ |
|
453 | - |
|
454 | - |
|
455 | - |
|
456 | - /** |
|
457 | - * post_notices |
|
458 | - * |
|
459 | - * @access public |
|
460 | - * @return void |
|
461 | - * @throws EE_Error |
|
462 | - */ |
|
463 | - public static function post_notices() |
|
464 | - { |
|
465 | - EED_Ticket_Sales_Monitor::instance()->_post_notices(); |
|
466 | - } |
|
467 | - |
|
468 | - |
|
469 | - |
|
470 | - /** |
|
471 | - * _post_notices |
|
472 | - * |
|
473 | - * @access protected |
|
474 | - * @return void |
|
475 | - * @throws EE_Error |
|
476 | - */ |
|
477 | - protected function _post_notices() |
|
478 | - { |
|
479 | - if (self::debug) { |
|
480 | - echo '<br /><br /> ' . __LINE__ . ') ' . __METHOD__ . '() '; |
|
481 | - } |
|
482 | - $refresh_msg = ''; |
|
483 | - $none_added_msg = ''; |
|
484 | - if (defined('DOING_AJAX') && DOING_AJAX) { |
|
485 | - $refresh_msg = __('Please refresh the page to view updated ticket quantities.', |
|
486 | - 'event_espresso'); |
|
487 | - $none_added_msg = __('No tickets were added for the event.', 'event_espresso'); |
|
488 | - } |
|
489 | - if ( ! empty($this->sold_out_tickets)) { |
|
490 | - EE_Error::add_attention( |
|
491 | - sprintf( |
|
492 | - apply_filters( |
|
493 | - 'FHEE__EED_Ticket_Sales_Monitor___post_notices__sold_out_tickets_notice', |
|
494 | - __('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', |
|
495 | - 'event_espresso') |
|
496 | - ), |
|
497 | - '<br />', |
|
498 | - implode('<br />', $this->sold_out_tickets), |
|
499 | - $none_added_msg, |
|
500 | - $refresh_msg |
|
501 | - ) |
|
502 | - ); |
|
503 | - // alter code flow in the Ticket Selector for better UX |
|
504 | - add_filter('FHEE__EED_Ticket_Selector__process_ticket_selections__tckts_slctd', '__return_true'); |
|
505 | - add_filter('FHEE__EED_Ticket_Selector__process_ticket_selections__success', '__return_false'); |
|
506 | - $this->sold_out_tickets = array(); |
|
507 | - // and reset the cart |
|
508 | - EED_Ticket_Sales_Monitor::session_cart_reset(EE_Registry::instance()->SSN); |
|
509 | - } |
|
510 | - if ( ! empty($this->decremented_tickets)) { |
|
511 | - EE_Error::add_attention( |
|
512 | - sprintf( |
|
513 | - apply_filters( |
|
514 | - 'FHEE__EED_Ticket_Sales_Monitor___ticket_quantity_decremented__notice', |
|
515 | - __('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', |
|
516 | - 'event_espresso') |
|
517 | - ), |
|
518 | - '<br />', |
|
519 | - implode('<br />', $this->decremented_tickets), |
|
520 | - $none_added_msg, |
|
521 | - $refresh_msg |
|
522 | - ) |
|
523 | - ); |
|
524 | - $this->decremented_tickets = array(); |
|
525 | - } |
|
526 | - } |
|
527 | - |
|
528 | - |
|
529 | - |
|
530 | - /********************************** RELEASE_ALL_RESERVED_TICKETS_FOR_TRANSACTION **********************************/ |
|
531 | - |
|
532 | - |
|
533 | - |
|
534 | - /** |
|
535 | - * _release_all_reserved_tickets_for_transaction |
|
536 | - * releases reserved tickets for all registrations of an EE_Transaction |
|
537 | - * by default, will NOT release tickets for finalized transactions |
|
538 | - * |
|
539 | - * @access protected |
|
540 | - * @param EE_Transaction $transaction |
|
541 | - * @return int |
|
542 | - * @throws EE_Error |
|
543 | - */ |
|
544 | - protected function _release_all_reserved_tickets_for_transaction(EE_Transaction $transaction) |
|
545 | - { |
|
546 | - if (self::debug) { |
|
547 | - echo '<br /><br /> ' . __LINE__ . ') ' . __METHOD__ . '() '; |
|
548 | - echo '<br /> . transaction->ID: ' . $transaction->ID(); |
|
549 | - } |
|
550 | - // check if 'finalize_registration' step has been completed... |
|
551 | - $finalized = $transaction->reg_step_completed('finalize_registration'); |
|
552 | - if (self::debug) { |
|
553 | - // DEBUG LOG |
|
554 | - EEH_Debug_Tools::log( |
|
555 | - __CLASS__, __FUNCTION__, __LINE__, |
|
556 | - array('finalized' => $finalized), |
|
557 | - false, 'EE_Transaction: ' . $transaction->ID() |
|
558 | - ); |
|
559 | - } |
|
560 | - // how many tickets were released |
|
561 | - $count = 0; |
|
562 | - if (self::debug) { |
|
563 | - echo '<br /> . . . finalized: ' . $finalized; |
|
564 | - } |
|
565 | - $release_tickets_with_TXN_status = array( |
|
566 | - EEM_Transaction::failed_status_code, |
|
567 | - EEM_Transaction::abandoned_status_code, |
|
568 | - EEM_Transaction::incomplete_status_code, |
|
569 | - ); |
|
570 | - // if the session is getting cleared BEFORE the TXN has been finalized |
|
571 | - if ( ! $finalized || in_array($transaction->status_ID(), $release_tickets_with_TXN_status, true)) { |
|
572 | - // let's cancel any reserved tickets |
|
573 | - $registrations = $transaction->registrations(); |
|
574 | - if ( ! empty($registrations)) { |
|
575 | - foreach ($registrations as $registration) { |
|
576 | - if ($registration instanceof EE_Registration) { |
|
577 | - $count += $this->_release_reserved_ticket_for_registration($registration, $transaction); |
|
578 | - } |
|
579 | - } |
|
580 | - } |
|
581 | - } |
|
582 | - return $count; |
|
583 | - } |
|
584 | - |
|
585 | - |
|
586 | - |
|
587 | - /** |
|
588 | - * _release_reserved_ticket_for_registration |
|
589 | - * releases reserved tickets for an EE_Registration |
|
590 | - * by default, will NOT release tickets for APPROVED registrations |
|
591 | - * |
|
592 | - * @access protected |
|
593 | - * @param EE_Registration $registration |
|
594 | - * @param EE_Transaction $transaction |
|
595 | - * @return int |
|
596 | - * @throws EE_Error |
|
597 | - */ |
|
598 | - protected function _release_reserved_ticket_for_registration( |
|
599 | - EE_Registration $registration, |
|
600 | - EE_Transaction $transaction |
|
601 | - ) { |
|
602 | - $STS_ID = $transaction->status_ID(); |
|
603 | - if (self::debug) { |
|
604 | - echo '<br /><br /> ' . __LINE__ . ') ' . __METHOD__ . '() '; |
|
605 | - echo '<br /> . . registration->ID: ' . $registration->ID(); |
|
606 | - echo '<br /> . . registration->status_ID: ' . $registration->status_ID(); |
|
607 | - echo '<br /> . . transaction->status_ID(): ' . $STS_ID; |
|
608 | - } |
|
609 | - if ( |
|
610 | - // release Tickets for Failed Transactions and Abandoned Transactions |
|
611 | - $STS_ID === EEM_Transaction::failed_status_code |
|
612 | - || $STS_ID === EEM_Transaction::abandoned_status_code |
|
613 | - || ( |
|
614 | - // also release Tickets for Incomplete Transactions, but ONLY if the Registrations are NOT Approved |
|
615 | - $STS_ID === EEM_Transaction::incomplete_status_code |
|
616 | - && $registration->status_ID() !== EEM_Registration::status_id_approved |
|
617 | - ) |
|
618 | - ) { |
|
619 | - $ticket = $registration->ticket(); |
|
620 | - if ($ticket instanceof EE_Ticket) { |
|
621 | - return $this->_release_reserved_ticket($ticket); |
|
622 | - } |
|
623 | - } |
|
624 | - return 0; |
|
625 | - } |
|
626 | - |
|
627 | - |
|
628 | - |
|
629 | - /********************************** SESSION_CART_RESET **********************************/ |
|
630 | - |
|
631 | - |
|
632 | - |
|
633 | - /** |
|
634 | - * session_cart_reset |
|
635 | - * callback hooked into 'AHEE__EE_Session__reset_cart__before_reset' |
|
636 | - * |
|
637 | - * @access public |
|
638 | - * @param EE_Session $session |
|
639 | - * @return void |
|
640 | - * @throws EE_Error |
|
641 | - */ |
|
642 | - public static function session_cart_reset(EE_Session $session) |
|
643 | - { |
|
644 | - if (self::debug) { |
|
645 | - echo '<br /><br /> ' . __LINE__ . ') ' . __METHOD__ . '() '; |
|
646 | - } |
|
647 | - $cart = $session->cart(); |
|
648 | - if ($cart instanceof EE_Cart) { |
|
649 | - if (self::debug) { |
|
650 | - echo '<br /><br /> cart instance of EE_Cart: '; |
|
651 | - } |
|
652 | - EED_Ticket_Sales_Monitor::instance()->_session_cart_reset($cart); |
|
653 | - } else { |
|
654 | - if (self::debug) { |
|
655 | - echo '<br /><br /> invalid EE_Cart: '; |
|
656 | - var_dump($cart); |
|
657 | - } |
|
658 | - } |
|
659 | - } |
|
660 | - |
|
661 | - |
|
662 | - |
|
663 | - /** |
|
664 | - * _session_cart_reset |
|
665 | - * releases reserved tickets in the EE_Cart |
|
666 | - * |
|
667 | - * @access protected |
|
668 | - * @param EE_Cart $cart |
|
669 | - * @return void |
|
670 | - * @throws EE_Error |
|
671 | - */ |
|
672 | - protected function _session_cart_reset(EE_Cart $cart) |
|
673 | - { |
|
674 | - if (self::debug) { |
|
675 | - echo '<br /><br /> ' . __LINE__ . ') ' . __METHOD__ . '() '; |
|
676 | - } |
|
677 | - EE_Registry::instance()->load_helper('Line_Item'); |
|
678 | - $ticket_line_items = $cart->get_tickets(); |
|
679 | - if (empty($ticket_line_items)) { |
|
680 | - return; |
|
681 | - } |
|
682 | - foreach ($ticket_line_items as $ticket_line_item) { |
|
683 | - if (self::debug) { |
|
684 | - echo '<br /> . ticket_line_item->ID(): ' . $ticket_line_item->ID(); |
|
685 | - } |
|
686 | - if ($ticket_line_item instanceof EE_Line_Item && $ticket_line_item->OBJ_type() === 'Ticket') { |
|
687 | - if (self::debug) { |
|
688 | - echo '<br /> . . ticket_line_item->OBJ_ID(): ' . $ticket_line_item->OBJ_ID(); |
|
689 | - } |
|
690 | - $ticket = EEM_Ticket::instance()->get_one_by_ID($ticket_line_item->OBJ_ID()); |
|
691 | - if ($ticket instanceof EE_Ticket) { |
|
692 | - if (self::debug) { |
|
693 | - echo '<br /> . . ticket->ID(): ' . $ticket->ID(); |
|
694 | - echo '<br /> . . ticket_line_item->quantity(): ' . $ticket_line_item->quantity(); |
|
695 | - } |
|
696 | - $this->_release_reserved_ticket($ticket, $ticket_line_item->quantity()); |
|
697 | - } |
|
698 | - } |
|
699 | - } |
|
700 | - if (self::debug) { |
|
701 | - echo '<br /><br /> RESET COMPLETED '; |
|
702 | - } |
|
703 | - } |
|
704 | - |
|
705 | - |
|
706 | - |
|
707 | - /********************************** SESSION_CHECKOUT_RESET **********************************/ |
|
708 | - |
|
709 | - |
|
710 | - |
|
711 | - /** |
|
712 | - * session_checkout_reset |
|
713 | - * callback hooked into 'AHEE__EE_Session__reset_checkout__before_reset' |
|
714 | - * |
|
715 | - * @access public |
|
716 | - * @param EE_Session $session |
|
717 | - * @return void |
|
718 | - * @throws EE_Error |
|
719 | - */ |
|
720 | - public static function session_checkout_reset(EE_Session $session) |
|
721 | - { |
|
722 | - $checkout = $session->checkout(); |
|
723 | - if ($checkout instanceof EE_Checkout) { |
|
724 | - EED_Ticket_Sales_Monitor::instance()->_session_checkout_reset($checkout); |
|
725 | - } |
|
726 | - } |
|
727 | - |
|
728 | - |
|
729 | - |
|
730 | - /** |
|
731 | - * _session_checkout_reset |
|
732 | - * releases reserved tickets for the EE_Checkout->transaction |
|
733 | - * |
|
734 | - * @access protected |
|
735 | - * @param EE_Checkout $checkout |
|
736 | - * @return void |
|
737 | - * @throws EE_Error |
|
738 | - */ |
|
739 | - protected function _session_checkout_reset(EE_Checkout $checkout) |
|
740 | - { |
|
741 | - if (self::debug) { |
|
742 | - echo '<br /><br /> ' . __LINE__ . ') ' . __METHOD__ . '() '; |
|
743 | - } |
|
744 | - // we want to release the each registration's reserved tickets if the session was cleared, but not if this is a revisit |
|
745 | - if ($checkout->revisit || ! $checkout->transaction instanceof EE_Transaction) { |
|
746 | - return; |
|
747 | - } |
|
748 | - $this->_release_all_reserved_tickets_for_transaction($checkout->transaction); |
|
749 | - } |
|
750 | - |
|
751 | - |
|
752 | - |
|
753 | - /********************************** SESSION_EXPIRED_RESET **********************************/ |
|
754 | - |
|
755 | - |
|
756 | - |
|
757 | - /** |
|
758 | - * session_expired_reset |
|
759 | - * |
|
760 | - * @access public |
|
761 | - * @param EE_Session $session |
|
762 | - * @return void |
|
763 | - */ |
|
764 | - public static function session_expired_reset(EE_Session $session) |
|
765 | - { |
|
766 | - } |
|
767 | - |
|
768 | - |
|
769 | - |
|
770 | - /********************************** PROCESS_ABANDONED_TRANSACTIONS **********************************/ |
|
771 | - |
|
772 | - |
|
773 | - |
|
774 | - /** |
|
775 | - * process_abandoned_transactions |
|
776 | - * releases reserved tickets for all registrations of an ABANDONED EE_Transaction |
|
777 | - * by default, will NOT release tickets for free transactions, or any that have received a payment |
|
778 | - * |
|
779 | - * @access public |
|
780 | - * @param EE_Transaction $transaction |
|
781 | - * @return void |
|
782 | - * @throws EE_Error |
|
783 | - */ |
|
784 | - public static function process_abandoned_transactions(EE_Transaction $transaction) |
|
785 | - { |
|
786 | - // is this TXN free or has any money been paid towards this TXN? If so, then leave it alone |
|
787 | - if ($transaction->is_free() || $transaction->paid() > 0) { |
|
788 | - if (self::debug) { |
|
789 | - // DEBUG LOG |
|
790 | - EEH_Debug_Tools::log( |
|
791 | - __CLASS__, __FUNCTION__, __LINE__, |
|
792 | - array($transaction), |
|
793 | - false, 'EE_Transaction: ' . $transaction->ID() |
|
794 | - ); |
|
795 | - } |
|
796 | - return; |
|
797 | - } |
|
798 | - // have their been any successful payments made ? |
|
799 | - $payments = $transaction->payments(); |
|
800 | - foreach ($payments as $payment) { |
|
801 | - if ($payment instanceof EE_Payment && $payment->status() === EEM_Payment::status_id_approved) { |
|
802 | - if (self::debug) { |
|
803 | - // DEBUG LOG |
|
804 | - EEH_Debug_Tools::log( |
|
805 | - __CLASS__, __FUNCTION__, __LINE__, |
|
806 | - array($payment), |
|
807 | - false, 'EE_Transaction: ' . $transaction->ID() |
|
808 | - ); |
|
809 | - } |
|
810 | - return; |
|
811 | - } |
|
812 | - } |
|
813 | - // since you haven't even attempted to pay for your ticket... |
|
814 | - EED_Ticket_Sales_Monitor::instance()->_release_all_reserved_tickets_for_transaction($transaction); |
|
815 | - } |
|
816 | - |
|
817 | - |
|
818 | - |
|
819 | - /********************************** PROCESS_FAILED_TRANSACTIONS **********************************/ |
|
820 | - |
|
821 | - |
|
822 | - |
|
823 | - /** |
|
824 | - * process_abandoned_transactions |
|
825 | - * releases reserved tickets for absolutely ALL registrations of a FAILED EE_Transaction |
|
826 | - * |
|
827 | - * @access public |
|
828 | - * @param EE_Transaction $transaction |
|
829 | - * @return void |
|
830 | - * @throws EE_Error |
|
831 | - */ |
|
832 | - public static function process_failed_transactions(EE_Transaction $transaction) |
|
833 | - { |
|
834 | - // since you haven't even attempted to pay for your ticket... |
|
835 | - EED_Ticket_Sales_Monitor::instance()->_release_all_reserved_tickets_for_transaction($transaction); |
|
836 | - } |
|
837 | - |
|
838 | - |
|
839 | - |
|
840 | - /********************************** RESET RESERVATION COUNTS *********************************/ |
|
841 | - |
|
842 | - |
|
843 | - |
|
844 | - /** |
|
845 | - * Resets all ticket and datetime reserved counts to zero |
|
846 | - * Tickets that are currently associated with a Transaction that is in progress |
|
847 | - * |
|
848 | - * @throws \EE_Error |
|
849 | - * @throws \DomainException |
|
850 | - */ |
|
851 | - public static function reset_reservation_counts() |
|
852 | - { |
|
853 | - /** @var EE_Line_Item[] $valid_reserved_tickets */ |
|
854 | - $valid_reserved_tickets = array(); |
|
855 | - $transactions_in_progress = EEM_Transaction::instance()->get_transactions_in_progress(); |
|
856 | - foreach ($transactions_in_progress as $transaction_in_progress) { |
|
857 | - // if this TXN has been fully completed, then skip it |
|
858 | - if ($transaction_in_progress->reg_step_completed('finalize_registration')) { |
|
859 | - continue; |
|
860 | - } |
|
861 | - /** @var EE_Transaction $transaction_in_progress */ |
|
862 | - $total_line_item = $transaction_in_progress->total_line_item(); |
|
863 | - // $transaction_in_progress->line |
|
864 | - if (! $total_line_item instanceof EE_Line_Item) { |
|
865 | - throw new DomainException( |
|
866 | - esc_html__('Transaction does not have a valid Total Line Item associated with it.', 'event_espresso') |
|
867 | - ); |
|
868 | - } |
|
869 | - $valid_reserved_tickets += EED_Ticket_Sales_Monitor::get_ticket_line_items_for_grand_total( |
|
870 | - $total_line_item |
|
871 | - ); |
|
872 | - } |
|
873 | - $total_line_items = EEM_Line_Item::instance()->get_total_line_items_just_added_to_cart(); |
|
874 | - foreach ($total_line_items as $total_line_item) { |
|
875 | - $valid_reserved_tickets += EED_Ticket_Sales_Monitor::get_ticket_line_items_for_grand_total( |
|
876 | - $total_line_item |
|
877 | - ); |
|
878 | - } |
|
879 | - return EED_Ticket_Sales_Monitor::release_reservations_for_tickets( |
|
880 | - EEM_Ticket::instance()->get_tickets_with_reservations(), |
|
881 | - $valid_reserved_tickets |
|
882 | - ); |
|
883 | - } |
|
884 | - |
|
885 | - |
|
886 | - |
|
887 | - /** |
|
888 | - * @param EE_Line_Item $total_line_item |
|
889 | - * @return EE_Line_Item[] |
|
890 | - */ |
|
891 | - private static function get_ticket_line_items_for_grand_total(EE_Line_Item $total_line_item) |
|
892 | - { |
|
893 | - /** @var EE_Line_Item[] $valid_reserved_tickets */ |
|
894 | - $valid_reserved_tickets = array(); |
|
895 | - $ticket_line_items = EEH_Line_Item::get_ticket_line_items($total_line_item); |
|
896 | - foreach ($ticket_line_items as $ticket_line_item) { |
|
897 | - if ($ticket_line_item instanceof EE_Line_Item) { |
|
898 | - $valid_reserved_tickets[] = $ticket_line_item; |
|
899 | - } |
|
900 | - } |
|
901 | - return $valid_reserved_tickets; |
|
902 | - } |
|
903 | - |
|
904 | - |
|
905 | - |
|
906 | - /** |
|
907 | - * @param EE_Ticket[] $tickets_with_reservations |
|
908 | - * @param EE_Line_Item[] $valid_reserved_ticket_line_items |
|
909 | - * @return int |
|
910 | - * @throws \EE_Error |
|
911 | - */ |
|
912 | - private static function release_reservations_for_tickets( |
|
913 | - array $tickets_with_reservations, |
|
914 | - $valid_reserved_ticket_line_items = array() |
|
915 | - ) { |
|
916 | - $total_tickets_released = 0; |
|
917 | - foreach ($tickets_with_reservations as $ticket_with_reservations) { |
|
918 | - if (! $ticket_with_reservations instanceof EE_Ticket) { |
|
919 | - continue; |
|
920 | - } |
|
921 | - $reserved_qty = $ticket_with_reservations->reserved(); |
|
922 | - foreach ($valid_reserved_ticket_line_items as $valid_reserved_ticket_line_item) { |
|
923 | - if ( |
|
924 | - $valid_reserved_ticket_line_item instanceof EE_Line_Item |
|
925 | - && $valid_reserved_ticket_line_item->OBJ_ID() === $ticket_with_reservations->ID() |
|
926 | - ) { |
|
927 | - $reserved_qty -= $valid_reserved_ticket_line_item->quantity(); |
|
928 | - } |
|
929 | - } |
|
930 | - if ($reserved_qty > 0) { |
|
931 | - $ticket_with_reservations->decrease_reserved($reserved_qty); |
|
932 | - $ticket_with_reservations->save(); |
|
933 | - $total_tickets_released += $reserved_qty; |
|
934 | - } |
|
935 | - } |
|
936 | - return $total_tickets_released; |
|
937 | - } |
|
24 | + const debug = false; // true false |
|
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 | + /** |
|
59 | + * set_hooks - for hooking into EE Core, other modules, etc |
|
60 | + * |
|
61 | + * @access public |
|
62 | + * @return void |
|
63 | + */ |
|
64 | + public static function set_hooks() |
|
65 | + { |
|
66 | + // release tickets for expired carts |
|
67 | + add_action('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('FHEE__EE_Ticket_Selector___add_ticket_to_cart__ticket_qty', |
|
73 | + array('EED_Ticket_Sales_Monitor', 'validate_ticket_sale'), |
|
74 | + 20, 3 |
|
75 | + ); |
|
76 | + // add notices for sold out tickets |
|
77 | + add_action('AHEE__EE_Ticket_Selector__process_ticket_selections__after_tickets_added_to_cart', |
|
78 | + array('EED_Ticket_Sales_Monitor', 'post_notices'), |
|
79 | + 10 |
|
80 | + ); |
|
81 | + // handle ticket quantities adjusted in cart |
|
82 | + //add_action( |
|
83 | + // 'FHEE__EED_Multi_Event_Registration__adjust_line_item_quantity__line_item_quantity_updated', |
|
84 | + // array( 'EED_Ticket_Sales_Monitor', 'ticket_quantity_updated' ), |
|
85 | + // 10, 2 |
|
86 | + //); |
|
87 | + // handle tickets deleted from cart |
|
88 | + add_action( |
|
89 | + 'FHEE__EED_Multi_Event_Registration__delete_ticket__ticket_removed_from_cart', |
|
90 | + array('EED_Ticket_Sales_Monitor', 'ticket_removed_from_cart'), |
|
91 | + 10, 2 |
|
92 | + ); |
|
93 | + // handle emptied carts |
|
94 | + add_action( |
|
95 | + 'AHEE__EE_Session__reset_cart__before_reset', |
|
96 | + array('EED_Ticket_Sales_Monitor', 'session_cart_reset'), |
|
97 | + 10, 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, 1 |
|
103 | + ); |
|
104 | + // handle cancelled registrations |
|
105 | + add_action( |
|
106 | + 'AHEE__EE_Session__reset_checkout__before_reset', |
|
107 | + array('EED_Ticket_Sales_Monitor', 'session_checkout_reset'), |
|
108 | + 10, 1 |
|
109 | + ); |
|
110 | + // cron tasks |
|
111 | + add_action( |
|
112 | + 'AHEE__EE_Cron_Tasks__finalize_abandoned_transactions__abandoned_transaction', |
|
113 | + array('EED_Ticket_Sales_Monitor', 'process_abandoned_transactions'), |
|
114 | + 10, 1 |
|
115 | + ); |
|
116 | + add_action( |
|
117 | + 'AHEE__EE_Cron_Tasks__process_expired_transactions__incomplete_transaction', |
|
118 | + array('EED_Ticket_Sales_Monitor', 'process_abandoned_transactions'), |
|
119 | + 10, 1 |
|
120 | + ); |
|
121 | + add_action( |
|
122 | + 'AHEE__EE_Cron_Tasks__process_expired_transactions__failed_transaction', |
|
123 | + array('EED_Ticket_Sales_Monitor', 'process_failed_transactions'), |
|
124 | + 10, 1 |
|
125 | + ); |
|
126 | + } |
|
127 | + |
|
128 | + |
|
129 | + |
|
130 | + /** |
|
131 | + * set_hooks_admin - for hooking into EE Admin Core, other modules, etc |
|
132 | + * |
|
133 | + * @access public |
|
134 | + * @return void |
|
135 | + */ |
|
136 | + public static function set_hooks_admin() |
|
137 | + { |
|
138 | + EED_Ticket_Sales_Monitor::set_hooks(); |
|
139 | + } |
|
140 | + |
|
141 | + |
|
142 | + |
|
143 | + /** |
|
144 | + * @return EED_Ticket_Sales_Monitor|EED_Module |
|
145 | + */ |
|
146 | + public static function instance() |
|
147 | + { |
|
148 | + return parent::get_instance(__CLASS__); |
|
149 | + } |
|
150 | + |
|
151 | + |
|
152 | + |
|
153 | + /** |
|
154 | + * run |
|
155 | + * |
|
156 | + * @access public |
|
157 | + * @param WP_Query $WP_Query |
|
158 | + * @return void |
|
159 | + */ |
|
160 | + public function run($WP_Query) |
|
161 | + { |
|
162 | + } |
|
163 | + |
|
164 | + |
|
165 | + |
|
166 | + /********************************** PRE_TICKET_SALES **********************************/ |
|
167 | + |
|
168 | + |
|
169 | + |
|
170 | + /** |
|
171 | + * Retrieves grand totals from the line items that have no TXN ID |
|
172 | + * and timestamps less than the current time minus the session lifespan. |
|
173 | + * These are carts that have been abandoned before the "registrant" even attempted to checkout. |
|
174 | + * We're going to release the tickets for these line items before attempting to add more to the cart. |
|
175 | + * |
|
176 | + * @return void |
|
177 | + * @throws \EE_Error |
|
178 | + */ |
|
179 | + public static function release_tickets_for_expired_carts() |
|
180 | + { |
|
181 | + $expired_ticket_IDs = array(); |
|
182 | + $valid_ticket_line_items = array(); |
|
183 | + $total_line_items = EEM_Line_Item::instance()->get_total_line_items_with_no_transaction(); |
|
184 | + if(empty($total_line_items)){ |
|
185 | + return; |
|
186 | + } |
|
187 | + $expired = current_time('timestamp') - EE_Registry::instance()->SSN->lifespan(); |
|
188 | + foreach ($total_line_items as $total_line_item) { |
|
189 | + /** @var EE_Line_Item $total_line_item */ |
|
190 | + $ticket_line_items = EED_Ticket_Sales_Monitor::get_ticket_line_items_for_grand_total($total_line_item); |
|
191 | + foreach ($ticket_line_items as $ticket_line_item) { |
|
192 | + if(! $ticket_line_item instanceof EE_Line_Item) { |
|
193 | + continue; |
|
194 | + } |
|
195 | + if ($total_line_item->timestamp(true) <= $expired ) { |
|
196 | + $expired_ticket_IDs[$ticket_line_item->OBJ_ID()] = $ticket_line_item->OBJ_ID(); |
|
197 | + } else { |
|
198 | + $valid_ticket_line_items[$ticket_line_item->OBJ_ID()] = $ticket_line_item; |
|
199 | + } |
|
200 | + } |
|
201 | + } |
|
202 | + EED_Ticket_Sales_Monitor::release_reservations_for_tickets( |
|
203 | + \EEM_Ticket::instance()->get_tickets_with_IDs($expired_ticket_IDs), |
|
204 | + $valid_ticket_line_items |
|
205 | + ); |
|
206 | + } |
|
207 | + |
|
208 | + |
|
209 | + |
|
210 | + /********************************** VALIDATE_TICKET_SALE **********************************/ |
|
211 | + |
|
212 | + |
|
213 | + |
|
214 | + /** |
|
215 | + * validate_ticket_sales |
|
216 | + * callback for 'FHEE__EED_Ticket_Selector__process_ticket_selections__valid_post_data' |
|
217 | + * |
|
218 | + * @access public |
|
219 | + * @param int $qty |
|
220 | + * @param \EE_Ticket $ticket |
|
221 | + * @return bool |
|
222 | + * @throws UnexpectedEntityException |
|
223 | + * @throws EE_Error |
|
224 | + */ |
|
225 | + public static function validate_ticket_sale($qty = 1, EE_Ticket $ticket) |
|
226 | + { |
|
227 | + $qty = absint($qty); |
|
228 | + if ($qty > 0) { |
|
229 | + $qty = EED_Ticket_Sales_Monitor::instance()->_validate_ticket_sale($ticket, $qty); |
|
230 | + } |
|
231 | + if (self::debug) { |
|
232 | + echo '<br /><br /> ' . __LINE__ . ') ' . __METHOD__ . '()'; |
|
233 | + echo '<br /><br /><b> RETURNED QTY: ' . $qty . '</b>'; |
|
234 | + } |
|
235 | + return $qty; |
|
236 | + } |
|
237 | + |
|
238 | + |
|
239 | + |
|
240 | + /** |
|
241 | + * _validate_ticket_sale |
|
242 | + * checks whether an individual ticket is available for purchase based on datetime, and ticket details |
|
243 | + * |
|
244 | + * @access protected |
|
245 | + * @param \EE_Ticket $ticket |
|
246 | + * @param int $qty |
|
247 | + * @return int |
|
248 | + * @throws UnexpectedEntityException |
|
249 | + * @throws EE_Error |
|
250 | + */ |
|
251 | + protected function _validate_ticket_sale(EE_Ticket $ticket, $qty = 1) |
|
252 | + { |
|
253 | + if (self::debug) { |
|
254 | + echo '<br /><br /> ' . __LINE__ . ') ' . __METHOD__ . '() '; |
|
255 | + } |
|
256 | + if ( ! $ticket instanceof EE_Ticket) { |
|
257 | + return 0; |
|
258 | + } |
|
259 | + if (self::debug) { |
|
260 | + echo '<br /><b> . ticket->ID: ' . $ticket->ID() . '</b>'; |
|
261 | + echo '<br /> . original ticket->reserved: ' . $ticket->reserved(); |
|
262 | + } |
|
263 | + $ticket->refresh_from_db(); |
|
264 | + // first let's determine the ticket availability based on sales |
|
265 | + $available = $ticket->qty('saleable'); |
|
266 | + if (self::debug) { |
|
267 | + echo '<br /> . . . ticket->qty: ' . $ticket->qty(); |
|
268 | + echo '<br /> . . . ticket->sold: ' . $ticket->sold(); |
|
269 | + echo '<br /> . . . ticket->reserved: ' . $ticket->reserved(); |
|
270 | + echo '<br /> . . . ticket->qty(saleable): ' . $ticket->qty('saleable'); |
|
271 | + echo '<br /> . . . available: ' . $available; |
|
272 | + } |
|
273 | + if ($available < 1) { |
|
274 | + $this->_ticket_sold_out($ticket); |
|
275 | + return 0; |
|
276 | + } |
|
277 | + if (self::debug) { |
|
278 | + echo '<br /> . . . qty: ' . $qty; |
|
279 | + } |
|
280 | + if ($available < $qty) { |
|
281 | + $qty = $available; |
|
282 | + if (self::debug) { |
|
283 | + echo '<br /> . . . QTY ADJUSTED: ' . $qty; |
|
284 | + } |
|
285 | + $this->_ticket_quantity_decremented($ticket); |
|
286 | + } |
|
287 | + $this->_reserve_ticket($ticket, $qty); |
|
288 | + return $qty; |
|
289 | + } |
|
290 | + |
|
291 | + |
|
292 | + |
|
293 | + /** |
|
294 | + * _reserve_ticket |
|
295 | + * increments ticket reserved based on quantity passed |
|
296 | + * |
|
297 | + * @access protected |
|
298 | + * @param \EE_Ticket $ticket |
|
299 | + * @param int $quantity |
|
300 | + * @return bool |
|
301 | + * @throws EE_Error |
|
302 | + */ |
|
303 | + protected function _reserve_ticket(EE_Ticket $ticket, $quantity = 1) |
|
304 | + { |
|
305 | + if (self::debug) { |
|
306 | + echo '<br /><br /> . . . INCREASE RESERVED: ' . $quantity; |
|
307 | + } |
|
308 | + $ticket->increase_reserved($quantity); |
|
309 | + return $ticket->save(); |
|
310 | + } |
|
311 | + |
|
312 | + |
|
313 | + |
|
314 | + /** |
|
315 | + * _release_reserved_ticket |
|
316 | + * |
|
317 | + * @access protected |
|
318 | + * @param EE_Ticket $ticket |
|
319 | + * @param int $quantity |
|
320 | + * @return bool |
|
321 | + * @throws EE_Error |
|
322 | + */ |
|
323 | + protected function _release_reserved_ticket(EE_Ticket $ticket, $quantity = 1) |
|
324 | + { |
|
325 | + if (self::debug) { |
|
326 | + echo '<br /> . . . ticket->ID: ' . $ticket->ID(); |
|
327 | + echo '<br /> . . . ticket->reserved: ' . $ticket->reserved(); |
|
328 | + } |
|
329 | + $ticket->decrease_reserved($quantity); |
|
330 | + if (self::debug) { |
|
331 | + echo '<br /> . . . ticket->reserved: ' . $ticket->reserved(); |
|
332 | + } |
|
333 | + return $ticket->save() ? 1 : 0; |
|
334 | + } |
|
335 | + |
|
336 | + |
|
337 | + |
|
338 | + /** |
|
339 | + * _ticket_sold_out |
|
340 | + * removes quantities within the ticket selector based on zero ticket availability |
|
341 | + * |
|
342 | + * @access protected |
|
343 | + * @param \EE_Ticket $ticket |
|
344 | + * @return void |
|
345 | + * @throws UnexpectedEntityException |
|
346 | + * @throws EE_Error |
|
347 | + */ |
|
348 | + protected function _ticket_sold_out(EE_Ticket $ticket) |
|
349 | + { |
|
350 | + if (self::debug) { |
|
351 | + echo '<br /><br /> ' . __LINE__ . ') ' . __METHOD__ . '() '; |
|
352 | + echo '<br /> . . ticket->name: ' . $this->_get_ticket_and_event_name($ticket); |
|
353 | + } |
|
354 | + $this->sold_out_tickets[] = $this->_get_ticket_and_event_name($ticket); |
|
355 | + } |
|
356 | + |
|
357 | + |
|
358 | + |
|
359 | + /** |
|
360 | + * _ticket_quantity_decremented |
|
361 | + * adjusts quantities within the ticket selector based on decreased ticket availability |
|
362 | + * |
|
363 | + * @access protected |
|
364 | + * @param \EE_Ticket $ticket |
|
365 | + * @return void |
|
366 | + * @throws UnexpectedEntityException |
|
367 | + * @throws EE_Error |
|
368 | + */ |
|
369 | + protected function _ticket_quantity_decremented(EE_Ticket $ticket) |
|
370 | + { |
|
371 | + if (self::debug) { |
|
372 | + echo '<br /><br /> ' . __LINE__ . ') ' . __METHOD__ . '() '; |
|
373 | + echo '<br /> . . ticket->name: ' . $this->_get_ticket_and_event_name($ticket); |
|
374 | + } |
|
375 | + $this->decremented_tickets[] = $this->_get_ticket_and_event_name($ticket); |
|
376 | + } |
|
377 | + |
|
378 | + |
|
379 | + |
|
380 | + /** |
|
381 | + * _get_ticket_and_event_name |
|
382 | + * builds string out of ticket and event name |
|
383 | + * |
|
384 | + * @access protected |
|
385 | + * @param \EE_Ticket $ticket |
|
386 | + * @return string |
|
387 | + * @throws UnexpectedEntityException |
|
388 | + * @throws EE_Error |
|
389 | + */ |
|
390 | + protected function _get_ticket_and_event_name(EE_Ticket $ticket) |
|
391 | + { |
|
392 | + $event = $ticket->get_related_event(); |
|
393 | + if ($event instanceof EE_Event) { |
|
394 | + $ticket_name = sprintf( |
|
395 | + _x('%1$s for %2$s', 'ticket name for event name', 'event_espresso'), |
|
396 | + $ticket->name(), |
|
397 | + $event->name() |
|
398 | + ); |
|
399 | + } else { |
|
400 | + $ticket_name = $ticket->name(); |
|
401 | + } |
|
402 | + return $ticket_name; |
|
403 | + } |
|
404 | + |
|
405 | + |
|
406 | + |
|
407 | + /********************************** EVENT CART **********************************/ |
|
408 | + |
|
409 | + |
|
410 | + |
|
411 | + /** |
|
412 | + * ticket_quantity_updated |
|
413 | + * releases or reserves ticket(s) based on quantity passed |
|
414 | + * |
|
415 | + * @access public |
|
416 | + * @param EE_Line_Item $line_item |
|
417 | + * @param int $quantity |
|
418 | + * @return void |
|
419 | + * @throws EE_Error |
|
420 | + */ |
|
421 | + public static function ticket_quantity_updated(EE_Line_Item $line_item, $quantity = 1) |
|
422 | + { |
|
423 | + $ticket = EEM_Ticket::instance()->get_one_by_ID(absint($line_item->OBJ_ID())); |
|
424 | + if ($ticket instanceof EE_Ticket) { |
|
425 | + if ($quantity > 0) { |
|
426 | + EED_Ticket_Sales_Monitor::instance()->_reserve_ticket($ticket, $quantity); |
|
427 | + } else { |
|
428 | + EED_Ticket_Sales_Monitor::instance()->_release_reserved_ticket($ticket, $quantity); |
|
429 | + } |
|
430 | + } |
|
431 | + } |
|
432 | + |
|
433 | + |
|
434 | + |
|
435 | + /** |
|
436 | + * ticket_removed_from_cart |
|
437 | + * releases reserved ticket(s) based on quantity passed |
|
438 | + * |
|
439 | + * @access public |
|
440 | + * @param EE_Ticket $ticket |
|
441 | + * @param int $quantity |
|
442 | + * @return void |
|
443 | + * @throws EE_Error |
|
444 | + */ |
|
445 | + public static function ticket_removed_from_cart(EE_Ticket $ticket, $quantity = 1) |
|
446 | + { |
|
447 | + EED_Ticket_Sales_Monitor::instance()->_release_reserved_ticket($ticket, $quantity); |
|
448 | + } |
|
449 | + |
|
450 | + |
|
451 | + |
|
452 | + /********************************** POST_NOTICES **********************************/ |
|
453 | + |
|
454 | + |
|
455 | + |
|
456 | + /** |
|
457 | + * post_notices |
|
458 | + * |
|
459 | + * @access public |
|
460 | + * @return void |
|
461 | + * @throws EE_Error |
|
462 | + */ |
|
463 | + public static function post_notices() |
|
464 | + { |
|
465 | + EED_Ticket_Sales_Monitor::instance()->_post_notices(); |
|
466 | + } |
|
467 | + |
|
468 | + |
|
469 | + |
|
470 | + /** |
|
471 | + * _post_notices |
|
472 | + * |
|
473 | + * @access protected |
|
474 | + * @return void |
|
475 | + * @throws EE_Error |
|
476 | + */ |
|
477 | + protected function _post_notices() |
|
478 | + { |
|
479 | + if (self::debug) { |
|
480 | + echo '<br /><br /> ' . __LINE__ . ') ' . __METHOD__ . '() '; |
|
481 | + } |
|
482 | + $refresh_msg = ''; |
|
483 | + $none_added_msg = ''; |
|
484 | + if (defined('DOING_AJAX') && DOING_AJAX) { |
|
485 | + $refresh_msg = __('Please refresh the page to view updated ticket quantities.', |
|
486 | + 'event_espresso'); |
|
487 | + $none_added_msg = __('No tickets were added for the event.', 'event_espresso'); |
|
488 | + } |
|
489 | + if ( ! empty($this->sold_out_tickets)) { |
|
490 | + EE_Error::add_attention( |
|
491 | + sprintf( |
|
492 | + apply_filters( |
|
493 | + 'FHEE__EED_Ticket_Sales_Monitor___post_notices__sold_out_tickets_notice', |
|
494 | + __('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', |
|
495 | + 'event_espresso') |
|
496 | + ), |
|
497 | + '<br />', |
|
498 | + implode('<br />', $this->sold_out_tickets), |
|
499 | + $none_added_msg, |
|
500 | + $refresh_msg |
|
501 | + ) |
|
502 | + ); |
|
503 | + // alter code flow in the Ticket Selector for better UX |
|
504 | + add_filter('FHEE__EED_Ticket_Selector__process_ticket_selections__tckts_slctd', '__return_true'); |
|
505 | + add_filter('FHEE__EED_Ticket_Selector__process_ticket_selections__success', '__return_false'); |
|
506 | + $this->sold_out_tickets = array(); |
|
507 | + // and reset the cart |
|
508 | + EED_Ticket_Sales_Monitor::session_cart_reset(EE_Registry::instance()->SSN); |
|
509 | + } |
|
510 | + if ( ! empty($this->decremented_tickets)) { |
|
511 | + EE_Error::add_attention( |
|
512 | + sprintf( |
|
513 | + apply_filters( |
|
514 | + 'FHEE__EED_Ticket_Sales_Monitor___ticket_quantity_decremented__notice', |
|
515 | + __('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', |
|
516 | + 'event_espresso') |
|
517 | + ), |
|
518 | + '<br />', |
|
519 | + implode('<br />', $this->decremented_tickets), |
|
520 | + $none_added_msg, |
|
521 | + $refresh_msg |
|
522 | + ) |
|
523 | + ); |
|
524 | + $this->decremented_tickets = array(); |
|
525 | + } |
|
526 | + } |
|
527 | + |
|
528 | + |
|
529 | + |
|
530 | + /********************************** RELEASE_ALL_RESERVED_TICKETS_FOR_TRANSACTION **********************************/ |
|
531 | + |
|
532 | + |
|
533 | + |
|
534 | + /** |
|
535 | + * _release_all_reserved_tickets_for_transaction |
|
536 | + * releases reserved tickets for all registrations of an EE_Transaction |
|
537 | + * by default, will NOT release tickets for finalized transactions |
|
538 | + * |
|
539 | + * @access protected |
|
540 | + * @param EE_Transaction $transaction |
|
541 | + * @return int |
|
542 | + * @throws EE_Error |
|
543 | + */ |
|
544 | + protected function _release_all_reserved_tickets_for_transaction(EE_Transaction $transaction) |
|
545 | + { |
|
546 | + if (self::debug) { |
|
547 | + echo '<br /><br /> ' . __LINE__ . ') ' . __METHOD__ . '() '; |
|
548 | + echo '<br /> . transaction->ID: ' . $transaction->ID(); |
|
549 | + } |
|
550 | + // check if 'finalize_registration' step has been completed... |
|
551 | + $finalized = $transaction->reg_step_completed('finalize_registration'); |
|
552 | + if (self::debug) { |
|
553 | + // DEBUG LOG |
|
554 | + EEH_Debug_Tools::log( |
|
555 | + __CLASS__, __FUNCTION__, __LINE__, |
|
556 | + array('finalized' => $finalized), |
|
557 | + false, 'EE_Transaction: ' . $transaction->ID() |
|
558 | + ); |
|
559 | + } |
|
560 | + // how many tickets were released |
|
561 | + $count = 0; |
|
562 | + if (self::debug) { |
|
563 | + echo '<br /> . . . finalized: ' . $finalized; |
|
564 | + } |
|
565 | + $release_tickets_with_TXN_status = array( |
|
566 | + EEM_Transaction::failed_status_code, |
|
567 | + EEM_Transaction::abandoned_status_code, |
|
568 | + EEM_Transaction::incomplete_status_code, |
|
569 | + ); |
|
570 | + // if the session is getting cleared BEFORE the TXN has been finalized |
|
571 | + if ( ! $finalized || in_array($transaction->status_ID(), $release_tickets_with_TXN_status, true)) { |
|
572 | + // let's cancel any reserved tickets |
|
573 | + $registrations = $transaction->registrations(); |
|
574 | + if ( ! empty($registrations)) { |
|
575 | + foreach ($registrations as $registration) { |
|
576 | + if ($registration instanceof EE_Registration) { |
|
577 | + $count += $this->_release_reserved_ticket_for_registration($registration, $transaction); |
|
578 | + } |
|
579 | + } |
|
580 | + } |
|
581 | + } |
|
582 | + return $count; |
|
583 | + } |
|
584 | + |
|
585 | + |
|
586 | + |
|
587 | + /** |
|
588 | + * _release_reserved_ticket_for_registration |
|
589 | + * releases reserved tickets for an EE_Registration |
|
590 | + * by default, will NOT release tickets for APPROVED registrations |
|
591 | + * |
|
592 | + * @access protected |
|
593 | + * @param EE_Registration $registration |
|
594 | + * @param EE_Transaction $transaction |
|
595 | + * @return int |
|
596 | + * @throws EE_Error |
|
597 | + */ |
|
598 | + protected function _release_reserved_ticket_for_registration( |
|
599 | + EE_Registration $registration, |
|
600 | + EE_Transaction $transaction |
|
601 | + ) { |
|
602 | + $STS_ID = $transaction->status_ID(); |
|
603 | + if (self::debug) { |
|
604 | + echo '<br /><br /> ' . __LINE__ . ') ' . __METHOD__ . '() '; |
|
605 | + echo '<br /> . . registration->ID: ' . $registration->ID(); |
|
606 | + echo '<br /> . . registration->status_ID: ' . $registration->status_ID(); |
|
607 | + echo '<br /> . . transaction->status_ID(): ' . $STS_ID; |
|
608 | + } |
|
609 | + if ( |
|
610 | + // release Tickets for Failed Transactions and Abandoned Transactions |
|
611 | + $STS_ID === EEM_Transaction::failed_status_code |
|
612 | + || $STS_ID === EEM_Transaction::abandoned_status_code |
|
613 | + || ( |
|
614 | + // also release Tickets for Incomplete Transactions, but ONLY if the Registrations are NOT Approved |
|
615 | + $STS_ID === EEM_Transaction::incomplete_status_code |
|
616 | + && $registration->status_ID() !== EEM_Registration::status_id_approved |
|
617 | + ) |
|
618 | + ) { |
|
619 | + $ticket = $registration->ticket(); |
|
620 | + if ($ticket instanceof EE_Ticket) { |
|
621 | + return $this->_release_reserved_ticket($ticket); |
|
622 | + } |
|
623 | + } |
|
624 | + return 0; |
|
625 | + } |
|
626 | + |
|
627 | + |
|
628 | + |
|
629 | + /********************************** SESSION_CART_RESET **********************************/ |
|
630 | + |
|
631 | + |
|
632 | + |
|
633 | + /** |
|
634 | + * session_cart_reset |
|
635 | + * callback hooked into 'AHEE__EE_Session__reset_cart__before_reset' |
|
636 | + * |
|
637 | + * @access public |
|
638 | + * @param EE_Session $session |
|
639 | + * @return void |
|
640 | + * @throws EE_Error |
|
641 | + */ |
|
642 | + public static function session_cart_reset(EE_Session $session) |
|
643 | + { |
|
644 | + if (self::debug) { |
|
645 | + echo '<br /><br /> ' . __LINE__ . ') ' . __METHOD__ . '() '; |
|
646 | + } |
|
647 | + $cart = $session->cart(); |
|
648 | + if ($cart instanceof EE_Cart) { |
|
649 | + if (self::debug) { |
|
650 | + echo '<br /><br /> cart instance of EE_Cart: '; |
|
651 | + } |
|
652 | + EED_Ticket_Sales_Monitor::instance()->_session_cart_reset($cart); |
|
653 | + } else { |
|
654 | + if (self::debug) { |
|
655 | + echo '<br /><br /> invalid EE_Cart: '; |
|
656 | + var_dump($cart); |
|
657 | + } |
|
658 | + } |
|
659 | + } |
|
660 | + |
|
661 | + |
|
662 | + |
|
663 | + /** |
|
664 | + * _session_cart_reset |
|
665 | + * releases reserved tickets in the EE_Cart |
|
666 | + * |
|
667 | + * @access protected |
|
668 | + * @param EE_Cart $cart |
|
669 | + * @return void |
|
670 | + * @throws EE_Error |
|
671 | + */ |
|
672 | + protected function _session_cart_reset(EE_Cart $cart) |
|
673 | + { |
|
674 | + if (self::debug) { |
|
675 | + echo '<br /><br /> ' . __LINE__ . ') ' . __METHOD__ . '() '; |
|
676 | + } |
|
677 | + EE_Registry::instance()->load_helper('Line_Item'); |
|
678 | + $ticket_line_items = $cart->get_tickets(); |
|
679 | + if (empty($ticket_line_items)) { |
|
680 | + return; |
|
681 | + } |
|
682 | + foreach ($ticket_line_items as $ticket_line_item) { |
|
683 | + if (self::debug) { |
|
684 | + echo '<br /> . ticket_line_item->ID(): ' . $ticket_line_item->ID(); |
|
685 | + } |
|
686 | + if ($ticket_line_item instanceof EE_Line_Item && $ticket_line_item->OBJ_type() === 'Ticket') { |
|
687 | + if (self::debug) { |
|
688 | + echo '<br /> . . ticket_line_item->OBJ_ID(): ' . $ticket_line_item->OBJ_ID(); |
|
689 | + } |
|
690 | + $ticket = EEM_Ticket::instance()->get_one_by_ID($ticket_line_item->OBJ_ID()); |
|
691 | + if ($ticket instanceof EE_Ticket) { |
|
692 | + if (self::debug) { |
|
693 | + echo '<br /> . . ticket->ID(): ' . $ticket->ID(); |
|
694 | + echo '<br /> . . ticket_line_item->quantity(): ' . $ticket_line_item->quantity(); |
|
695 | + } |
|
696 | + $this->_release_reserved_ticket($ticket, $ticket_line_item->quantity()); |
|
697 | + } |
|
698 | + } |
|
699 | + } |
|
700 | + if (self::debug) { |
|
701 | + echo '<br /><br /> RESET COMPLETED '; |
|
702 | + } |
|
703 | + } |
|
704 | + |
|
705 | + |
|
706 | + |
|
707 | + /********************************** SESSION_CHECKOUT_RESET **********************************/ |
|
708 | + |
|
709 | + |
|
710 | + |
|
711 | + /** |
|
712 | + * session_checkout_reset |
|
713 | + * callback hooked into 'AHEE__EE_Session__reset_checkout__before_reset' |
|
714 | + * |
|
715 | + * @access public |
|
716 | + * @param EE_Session $session |
|
717 | + * @return void |
|
718 | + * @throws EE_Error |
|
719 | + */ |
|
720 | + public static function session_checkout_reset(EE_Session $session) |
|
721 | + { |
|
722 | + $checkout = $session->checkout(); |
|
723 | + if ($checkout instanceof EE_Checkout) { |
|
724 | + EED_Ticket_Sales_Monitor::instance()->_session_checkout_reset($checkout); |
|
725 | + } |
|
726 | + } |
|
727 | + |
|
728 | + |
|
729 | + |
|
730 | + /** |
|
731 | + * _session_checkout_reset |
|
732 | + * releases reserved tickets for the EE_Checkout->transaction |
|
733 | + * |
|
734 | + * @access protected |
|
735 | + * @param EE_Checkout $checkout |
|
736 | + * @return void |
|
737 | + * @throws EE_Error |
|
738 | + */ |
|
739 | + protected function _session_checkout_reset(EE_Checkout $checkout) |
|
740 | + { |
|
741 | + if (self::debug) { |
|
742 | + echo '<br /><br /> ' . __LINE__ . ') ' . __METHOD__ . '() '; |
|
743 | + } |
|
744 | + // we want to release the each registration's reserved tickets if the session was cleared, but not if this is a revisit |
|
745 | + if ($checkout->revisit || ! $checkout->transaction instanceof EE_Transaction) { |
|
746 | + return; |
|
747 | + } |
|
748 | + $this->_release_all_reserved_tickets_for_transaction($checkout->transaction); |
|
749 | + } |
|
750 | + |
|
751 | + |
|
752 | + |
|
753 | + /********************************** SESSION_EXPIRED_RESET **********************************/ |
|
754 | + |
|
755 | + |
|
756 | + |
|
757 | + /** |
|
758 | + * session_expired_reset |
|
759 | + * |
|
760 | + * @access public |
|
761 | + * @param EE_Session $session |
|
762 | + * @return void |
|
763 | + */ |
|
764 | + public static function session_expired_reset(EE_Session $session) |
|
765 | + { |
|
766 | + } |
|
767 | + |
|
768 | + |
|
769 | + |
|
770 | + /********************************** PROCESS_ABANDONED_TRANSACTIONS **********************************/ |
|
771 | + |
|
772 | + |
|
773 | + |
|
774 | + /** |
|
775 | + * process_abandoned_transactions |
|
776 | + * releases reserved tickets for all registrations of an ABANDONED EE_Transaction |
|
777 | + * by default, will NOT release tickets for free transactions, or any that have received a payment |
|
778 | + * |
|
779 | + * @access public |
|
780 | + * @param EE_Transaction $transaction |
|
781 | + * @return void |
|
782 | + * @throws EE_Error |
|
783 | + */ |
|
784 | + public static function process_abandoned_transactions(EE_Transaction $transaction) |
|
785 | + { |
|
786 | + // is this TXN free or has any money been paid towards this TXN? If so, then leave it alone |
|
787 | + if ($transaction->is_free() || $transaction->paid() > 0) { |
|
788 | + if (self::debug) { |
|
789 | + // DEBUG LOG |
|
790 | + EEH_Debug_Tools::log( |
|
791 | + __CLASS__, __FUNCTION__, __LINE__, |
|
792 | + array($transaction), |
|
793 | + false, 'EE_Transaction: ' . $transaction->ID() |
|
794 | + ); |
|
795 | + } |
|
796 | + return; |
|
797 | + } |
|
798 | + // have their been any successful payments made ? |
|
799 | + $payments = $transaction->payments(); |
|
800 | + foreach ($payments as $payment) { |
|
801 | + if ($payment instanceof EE_Payment && $payment->status() === EEM_Payment::status_id_approved) { |
|
802 | + if (self::debug) { |
|
803 | + // DEBUG LOG |
|
804 | + EEH_Debug_Tools::log( |
|
805 | + __CLASS__, __FUNCTION__, __LINE__, |
|
806 | + array($payment), |
|
807 | + false, 'EE_Transaction: ' . $transaction->ID() |
|
808 | + ); |
|
809 | + } |
|
810 | + return; |
|
811 | + } |
|
812 | + } |
|
813 | + // since you haven't even attempted to pay for your ticket... |
|
814 | + EED_Ticket_Sales_Monitor::instance()->_release_all_reserved_tickets_for_transaction($transaction); |
|
815 | + } |
|
816 | + |
|
817 | + |
|
818 | + |
|
819 | + /********************************** PROCESS_FAILED_TRANSACTIONS **********************************/ |
|
820 | + |
|
821 | + |
|
822 | + |
|
823 | + /** |
|
824 | + * process_abandoned_transactions |
|
825 | + * releases reserved tickets for absolutely ALL registrations of a FAILED EE_Transaction |
|
826 | + * |
|
827 | + * @access public |
|
828 | + * @param EE_Transaction $transaction |
|
829 | + * @return void |
|
830 | + * @throws EE_Error |
|
831 | + */ |
|
832 | + public static function process_failed_transactions(EE_Transaction $transaction) |
|
833 | + { |
|
834 | + // since you haven't even attempted to pay for your ticket... |
|
835 | + EED_Ticket_Sales_Monitor::instance()->_release_all_reserved_tickets_for_transaction($transaction); |
|
836 | + } |
|
837 | + |
|
838 | + |
|
839 | + |
|
840 | + /********************************** RESET RESERVATION COUNTS *********************************/ |
|
841 | + |
|
842 | + |
|
843 | + |
|
844 | + /** |
|
845 | + * Resets all ticket and datetime reserved counts to zero |
|
846 | + * Tickets that are currently associated with a Transaction that is in progress |
|
847 | + * |
|
848 | + * @throws \EE_Error |
|
849 | + * @throws \DomainException |
|
850 | + */ |
|
851 | + public static function reset_reservation_counts() |
|
852 | + { |
|
853 | + /** @var EE_Line_Item[] $valid_reserved_tickets */ |
|
854 | + $valid_reserved_tickets = array(); |
|
855 | + $transactions_in_progress = EEM_Transaction::instance()->get_transactions_in_progress(); |
|
856 | + foreach ($transactions_in_progress as $transaction_in_progress) { |
|
857 | + // if this TXN has been fully completed, then skip it |
|
858 | + if ($transaction_in_progress->reg_step_completed('finalize_registration')) { |
|
859 | + continue; |
|
860 | + } |
|
861 | + /** @var EE_Transaction $transaction_in_progress */ |
|
862 | + $total_line_item = $transaction_in_progress->total_line_item(); |
|
863 | + // $transaction_in_progress->line |
|
864 | + if (! $total_line_item instanceof EE_Line_Item) { |
|
865 | + throw new DomainException( |
|
866 | + esc_html__('Transaction does not have a valid Total Line Item associated with it.', 'event_espresso') |
|
867 | + ); |
|
868 | + } |
|
869 | + $valid_reserved_tickets += EED_Ticket_Sales_Monitor::get_ticket_line_items_for_grand_total( |
|
870 | + $total_line_item |
|
871 | + ); |
|
872 | + } |
|
873 | + $total_line_items = EEM_Line_Item::instance()->get_total_line_items_just_added_to_cart(); |
|
874 | + foreach ($total_line_items as $total_line_item) { |
|
875 | + $valid_reserved_tickets += EED_Ticket_Sales_Monitor::get_ticket_line_items_for_grand_total( |
|
876 | + $total_line_item |
|
877 | + ); |
|
878 | + } |
|
879 | + return EED_Ticket_Sales_Monitor::release_reservations_for_tickets( |
|
880 | + EEM_Ticket::instance()->get_tickets_with_reservations(), |
|
881 | + $valid_reserved_tickets |
|
882 | + ); |
|
883 | + } |
|
884 | + |
|
885 | + |
|
886 | + |
|
887 | + /** |
|
888 | + * @param EE_Line_Item $total_line_item |
|
889 | + * @return EE_Line_Item[] |
|
890 | + */ |
|
891 | + private static function get_ticket_line_items_for_grand_total(EE_Line_Item $total_line_item) |
|
892 | + { |
|
893 | + /** @var EE_Line_Item[] $valid_reserved_tickets */ |
|
894 | + $valid_reserved_tickets = array(); |
|
895 | + $ticket_line_items = EEH_Line_Item::get_ticket_line_items($total_line_item); |
|
896 | + foreach ($ticket_line_items as $ticket_line_item) { |
|
897 | + if ($ticket_line_item instanceof EE_Line_Item) { |
|
898 | + $valid_reserved_tickets[] = $ticket_line_item; |
|
899 | + } |
|
900 | + } |
|
901 | + return $valid_reserved_tickets; |
|
902 | + } |
|
903 | + |
|
904 | + |
|
905 | + |
|
906 | + /** |
|
907 | + * @param EE_Ticket[] $tickets_with_reservations |
|
908 | + * @param EE_Line_Item[] $valid_reserved_ticket_line_items |
|
909 | + * @return int |
|
910 | + * @throws \EE_Error |
|
911 | + */ |
|
912 | + private static function release_reservations_for_tickets( |
|
913 | + array $tickets_with_reservations, |
|
914 | + $valid_reserved_ticket_line_items = array() |
|
915 | + ) { |
|
916 | + $total_tickets_released = 0; |
|
917 | + foreach ($tickets_with_reservations as $ticket_with_reservations) { |
|
918 | + if (! $ticket_with_reservations instanceof EE_Ticket) { |
|
919 | + continue; |
|
920 | + } |
|
921 | + $reserved_qty = $ticket_with_reservations->reserved(); |
|
922 | + foreach ($valid_reserved_ticket_line_items as $valid_reserved_ticket_line_item) { |
|
923 | + if ( |
|
924 | + $valid_reserved_ticket_line_item instanceof EE_Line_Item |
|
925 | + && $valid_reserved_ticket_line_item->OBJ_ID() === $ticket_with_reservations->ID() |
|
926 | + ) { |
|
927 | + $reserved_qty -= $valid_reserved_ticket_line_item->quantity(); |
|
928 | + } |
|
929 | + } |
|
930 | + if ($reserved_qty > 0) { |
|
931 | + $ticket_with_reservations->decrease_reserved($reserved_qty); |
|
932 | + $ticket_with_reservations->save(); |
|
933 | + $total_tickets_released += $reserved_qty; |
|
934 | + } |
|
935 | + } |
|
936 | + return $total_tickets_released; |
|
937 | + } |
|
938 | 938 | |
939 | 939 | } |
940 | 940 | // End of file EED_Ticket_Sales_Monitor.module.php |
@@ -21,7 +21,7 @@ discard block |
||
21 | 21 | class EED_Ticket_Sales_Monitor extends EED_Module |
22 | 22 | { |
23 | 23 | |
24 | - const debug = false; // true false |
|
24 | + const debug = false; // true false |
|
25 | 25 | |
26 | 26 | /** |
27 | 27 | * an array of raw ticket data from EED_Ticket_Selector |
@@ -181,7 +181,7 @@ discard block |
||
181 | 181 | $expired_ticket_IDs = array(); |
182 | 182 | $valid_ticket_line_items = array(); |
183 | 183 | $total_line_items = EEM_Line_Item::instance()->get_total_line_items_with_no_transaction(); |
184 | - if(empty($total_line_items)){ |
|
184 | + if (empty($total_line_items)) { |
|
185 | 185 | return; |
186 | 186 | } |
187 | 187 | $expired = current_time('timestamp') - EE_Registry::instance()->SSN->lifespan(); |
@@ -189,10 +189,10 @@ discard block |
||
189 | 189 | /** @var EE_Line_Item $total_line_item */ |
190 | 190 | $ticket_line_items = EED_Ticket_Sales_Monitor::get_ticket_line_items_for_grand_total($total_line_item); |
191 | 191 | foreach ($ticket_line_items as $ticket_line_item) { |
192 | - if(! $ticket_line_item instanceof EE_Line_Item) { |
|
192 | + if ( ! $ticket_line_item instanceof EE_Line_Item) { |
|
193 | 193 | continue; |
194 | 194 | } |
195 | - if ($total_line_item->timestamp(true) <= $expired ) { |
|
195 | + if ($total_line_item->timestamp(true) <= $expired) { |
|
196 | 196 | $expired_ticket_IDs[$ticket_line_item->OBJ_ID()] = $ticket_line_item->OBJ_ID(); |
197 | 197 | } else { |
198 | 198 | $valid_ticket_line_items[$ticket_line_item->OBJ_ID()] = $ticket_line_item; |
@@ -229,8 +229,8 @@ discard block |
||
229 | 229 | $qty = EED_Ticket_Sales_Monitor::instance()->_validate_ticket_sale($ticket, $qty); |
230 | 230 | } |
231 | 231 | if (self::debug) { |
232 | - echo '<br /><br /> ' . __LINE__ . ') ' . __METHOD__ . '()'; |
|
233 | - echo '<br /><br /><b> RETURNED QTY: ' . $qty . '</b>'; |
|
232 | + echo '<br /><br /> '.__LINE__.') '.__METHOD__.'()'; |
|
233 | + echo '<br /><br /><b> RETURNED QTY: '.$qty.'</b>'; |
|
234 | 234 | } |
235 | 235 | return $qty; |
236 | 236 | } |
@@ -251,36 +251,36 @@ discard block |
||
251 | 251 | protected function _validate_ticket_sale(EE_Ticket $ticket, $qty = 1) |
252 | 252 | { |
253 | 253 | if (self::debug) { |
254 | - echo '<br /><br /> ' . __LINE__ . ') ' . __METHOD__ . '() '; |
|
254 | + echo '<br /><br /> '.__LINE__.') '.__METHOD__.'() '; |
|
255 | 255 | } |
256 | 256 | if ( ! $ticket instanceof EE_Ticket) { |
257 | 257 | return 0; |
258 | 258 | } |
259 | 259 | if (self::debug) { |
260 | - echo '<br /><b> . ticket->ID: ' . $ticket->ID() . '</b>'; |
|
261 | - echo '<br /> . original ticket->reserved: ' . $ticket->reserved(); |
|
260 | + echo '<br /><b> . ticket->ID: '.$ticket->ID().'</b>'; |
|
261 | + echo '<br /> . original ticket->reserved: '.$ticket->reserved(); |
|
262 | 262 | } |
263 | 263 | $ticket->refresh_from_db(); |
264 | 264 | // first let's determine the ticket availability based on sales |
265 | 265 | $available = $ticket->qty('saleable'); |
266 | 266 | if (self::debug) { |
267 | - echo '<br /> . . . ticket->qty: ' . $ticket->qty(); |
|
268 | - echo '<br /> . . . ticket->sold: ' . $ticket->sold(); |
|
269 | - echo '<br /> . . . ticket->reserved: ' . $ticket->reserved(); |
|
270 | - echo '<br /> . . . ticket->qty(saleable): ' . $ticket->qty('saleable'); |
|
271 | - echo '<br /> . . . available: ' . $available; |
|
267 | + echo '<br /> . . . ticket->qty: '.$ticket->qty(); |
|
268 | + echo '<br /> . . . ticket->sold: '.$ticket->sold(); |
|
269 | + echo '<br /> . . . ticket->reserved: '.$ticket->reserved(); |
|
270 | + echo '<br /> . . . ticket->qty(saleable): '.$ticket->qty('saleable'); |
|
271 | + echo '<br /> . . . available: '.$available; |
|
272 | 272 | } |
273 | 273 | if ($available < 1) { |
274 | 274 | $this->_ticket_sold_out($ticket); |
275 | 275 | return 0; |
276 | 276 | } |
277 | 277 | if (self::debug) { |
278 | - echo '<br /> . . . qty: ' . $qty; |
|
278 | + echo '<br /> . . . qty: '.$qty; |
|
279 | 279 | } |
280 | 280 | if ($available < $qty) { |
281 | 281 | $qty = $available; |
282 | 282 | if (self::debug) { |
283 | - echo '<br /> . . . QTY ADJUSTED: ' . $qty; |
|
283 | + echo '<br /> . . . QTY ADJUSTED: '.$qty; |
|
284 | 284 | } |
285 | 285 | $this->_ticket_quantity_decremented($ticket); |
286 | 286 | } |
@@ -303,7 +303,7 @@ discard block |
||
303 | 303 | protected function _reserve_ticket(EE_Ticket $ticket, $quantity = 1) |
304 | 304 | { |
305 | 305 | if (self::debug) { |
306 | - echo '<br /><br /> . . . INCREASE RESERVED: ' . $quantity; |
|
306 | + echo '<br /><br /> . . . INCREASE RESERVED: '.$quantity; |
|
307 | 307 | } |
308 | 308 | $ticket->increase_reserved($quantity); |
309 | 309 | return $ticket->save(); |
@@ -323,12 +323,12 @@ discard block |
||
323 | 323 | protected function _release_reserved_ticket(EE_Ticket $ticket, $quantity = 1) |
324 | 324 | { |
325 | 325 | if (self::debug) { |
326 | - echo '<br /> . . . ticket->ID: ' . $ticket->ID(); |
|
327 | - echo '<br /> . . . ticket->reserved: ' . $ticket->reserved(); |
|
326 | + echo '<br /> . . . ticket->ID: '.$ticket->ID(); |
|
327 | + echo '<br /> . . . ticket->reserved: '.$ticket->reserved(); |
|
328 | 328 | } |
329 | 329 | $ticket->decrease_reserved($quantity); |
330 | 330 | if (self::debug) { |
331 | - echo '<br /> . . . ticket->reserved: ' . $ticket->reserved(); |
|
331 | + echo '<br /> . . . ticket->reserved: '.$ticket->reserved(); |
|
332 | 332 | } |
333 | 333 | return $ticket->save() ? 1 : 0; |
334 | 334 | } |
@@ -348,8 +348,8 @@ discard block |
||
348 | 348 | protected function _ticket_sold_out(EE_Ticket $ticket) |
349 | 349 | { |
350 | 350 | if (self::debug) { |
351 | - echo '<br /><br /> ' . __LINE__ . ') ' . __METHOD__ . '() '; |
|
352 | - echo '<br /> . . ticket->name: ' . $this->_get_ticket_and_event_name($ticket); |
|
351 | + echo '<br /><br /> '.__LINE__.') '.__METHOD__.'() '; |
|
352 | + echo '<br /> . . ticket->name: '.$this->_get_ticket_and_event_name($ticket); |
|
353 | 353 | } |
354 | 354 | $this->sold_out_tickets[] = $this->_get_ticket_and_event_name($ticket); |
355 | 355 | } |
@@ -369,8 +369,8 @@ discard block |
||
369 | 369 | protected function _ticket_quantity_decremented(EE_Ticket $ticket) |
370 | 370 | { |
371 | 371 | if (self::debug) { |
372 | - echo '<br /><br /> ' . __LINE__ . ') ' . __METHOD__ . '() '; |
|
373 | - echo '<br /> . . ticket->name: ' . $this->_get_ticket_and_event_name($ticket); |
|
372 | + echo '<br /><br /> '.__LINE__.') '.__METHOD__.'() '; |
|
373 | + echo '<br /> . . ticket->name: '.$this->_get_ticket_and_event_name($ticket); |
|
374 | 374 | } |
375 | 375 | $this->decremented_tickets[] = $this->_get_ticket_and_event_name($ticket); |
376 | 376 | } |
@@ -477,7 +477,7 @@ discard block |
||
477 | 477 | protected function _post_notices() |
478 | 478 | { |
479 | 479 | if (self::debug) { |
480 | - echo '<br /><br /> ' . __LINE__ . ') ' . __METHOD__ . '() '; |
|
480 | + echo '<br /><br /> '.__LINE__.') '.__METHOD__.'() '; |
|
481 | 481 | } |
482 | 482 | $refresh_msg = ''; |
483 | 483 | $none_added_msg = ''; |
@@ -544,8 +544,8 @@ discard block |
||
544 | 544 | protected function _release_all_reserved_tickets_for_transaction(EE_Transaction $transaction) |
545 | 545 | { |
546 | 546 | if (self::debug) { |
547 | - echo '<br /><br /> ' . __LINE__ . ') ' . __METHOD__ . '() '; |
|
548 | - echo '<br /> . transaction->ID: ' . $transaction->ID(); |
|
547 | + echo '<br /><br /> '.__LINE__.') '.__METHOD__.'() '; |
|
548 | + echo '<br /> . transaction->ID: '.$transaction->ID(); |
|
549 | 549 | } |
550 | 550 | // check if 'finalize_registration' step has been completed... |
551 | 551 | $finalized = $transaction->reg_step_completed('finalize_registration'); |
@@ -554,13 +554,13 @@ discard block |
||
554 | 554 | EEH_Debug_Tools::log( |
555 | 555 | __CLASS__, __FUNCTION__, __LINE__, |
556 | 556 | array('finalized' => $finalized), |
557 | - false, 'EE_Transaction: ' . $transaction->ID() |
|
557 | + false, 'EE_Transaction: '.$transaction->ID() |
|
558 | 558 | ); |
559 | 559 | } |
560 | 560 | // how many tickets were released |
561 | 561 | $count = 0; |
562 | 562 | if (self::debug) { |
563 | - echo '<br /> . . . finalized: ' . $finalized; |
|
563 | + echo '<br /> . . . finalized: '.$finalized; |
|
564 | 564 | } |
565 | 565 | $release_tickets_with_TXN_status = array( |
566 | 566 | EEM_Transaction::failed_status_code, |
@@ -601,10 +601,10 @@ discard block |
||
601 | 601 | ) { |
602 | 602 | $STS_ID = $transaction->status_ID(); |
603 | 603 | if (self::debug) { |
604 | - echo '<br /><br /> ' . __LINE__ . ') ' . __METHOD__ . '() '; |
|
605 | - echo '<br /> . . registration->ID: ' . $registration->ID(); |
|
606 | - echo '<br /> . . registration->status_ID: ' . $registration->status_ID(); |
|
607 | - echo '<br /> . . transaction->status_ID(): ' . $STS_ID; |
|
604 | + echo '<br /><br /> '.__LINE__.') '.__METHOD__.'() '; |
|
605 | + echo '<br /> . . registration->ID: '.$registration->ID(); |
|
606 | + echo '<br /> . . registration->status_ID: '.$registration->status_ID(); |
|
607 | + echo '<br /> . . transaction->status_ID(): '.$STS_ID; |
|
608 | 608 | } |
609 | 609 | if ( |
610 | 610 | // release Tickets for Failed Transactions and Abandoned Transactions |
@@ -642,7 +642,7 @@ discard block |
||
642 | 642 | public static function session_cart_reset(EE_Session $session) |
643 | 643 | { |
644 | 644 | if (self::debug) { |
645 | - echo '<br /><br /> ' . __LINE__ . ') ' . __METHOD__ . '() '; |
|
645 | + echo '<br /><br /> '.__LINE__.') '.__METHOD__.'() '; |
|
646 | 646 | } |
647 | 647 | $cart = $session->cart(); |
648 | 648 | if ($cart instanceof EE_Cart) { |
@@ -672,7 +672,7 @@ discard block |
||
672 | 672 | protected function _session_cart_reset(EE_Cart $cart) |
673 | 673 | { |
674 | 674 | if (self::debug) { |
675 | - echo '<br /><br /> ' . __LINE__ . ') ' . __METHOD__ . '() '; |
|
675 | + echo '<br /><br /> '.__LINE__.') '.__METHOD__.'() '; |
|
676 | 676 | } |
677 | 677 | EE_Registry::instance()->load_helper('Line_Item'); |
678 | 678 | $ticket_line_items = $cart->get_tickets(); |
@@ -681,17 +681,17 @@ discard block |
||
681 | 681 | } |
682 | 682 | foreach ($ticket_line_items as $ticket_line_item) { |
683 | 683 | if (self::debug) { |
684 | - echo '<br /> . ticket_line_item->ID(): ' . $ticket_line_item->ID(); |
|
684 | + echo '<br /> . ticket_line_item->ID(): '.$ticket_line_item->ID(); |
|
685 | 685 | } |
686 | 686 | if ($ticket_line_item instanceof EE_Line_Item && $ticket_line_item->OBJ_type() === 'Ticket') { |
687 | 687 | if (self::debug) { |
688 | - echo '<br /> . . ticket_line_item->OBJ_ID(): ' . $ticket_line_item->OBJ_ID(); |
|
688 | + echo '<br /> . . ticket_line_item->OBJ_ID(): '.$ticket_line_item->OBJ_ID(); |
|
689 | 689 | } |
690 | 690 | $ticket = EEM_Ticket::instance()->get_one_by_ID($ticket_line_item->OBJ_ID()); |
691 | 691 | if ($ticket instanceof EE_Ticket) { |
692 | 692 | if (self::debug) { |
693 | - echo '<br /> . . ticket->ID(): ' . $ticket->ID(); |
|
694 | - echo '<br /> . . ticket_line_item->quantity(): ' . $ticket_line_item->quantity(); |
|
693 | + echo '<br /> . . ticket->ID(): '.$ticket->ID(); |
|
694 | + echo '<br /> . . ticket_line_item->quantity(): '.$ticket_line_item->quantity(); |
|
695 | 695 | } |
696 | 696 | $this->_release_reserved_ticket($ticket, $ticket_line_item->quantity()); |
697 | 697 | } |
@@ -739,7 +739,7 @@ discard block |
||
739 | 739 | protected function _session_checkout_reset(EE_Checkout $checkout) |
740 | 740 | { |
741 | 741 | if (self::debug) { |
742 | - echo '<br /><br /> ' . __LINE__ . ') ' . __METHOD__ . '() '; |
|
742 | + echo '<br /><br /> '.__LINE__.') '.__METHOD__.'() '; |
|
743 | 743 | } |
744 | 744 | // we want to release the each registration's reserved tickets if the session was cleared, but not if this is a revisit |
745 | 745 | if ($checkout->revisit || ! $checkout->transaction instanceof EE_Transaction) { |
@@ -790,7 +790,7 @@ discard block |
||
790 | 790 | EEH_Debug_Tools::log( |
791 | 791 | __CLASS__, __FUNCTION__, __LINE__, |
792 | 792 | array($transaction), |
793 | - false, 'EE_Transaction: ' . $transaction->ID() |
|
793 | + false, 'EE_Transaction: '.$transaction->ID() |
|
794 | 794 | ); |
795 | 795 | } |
796 | 796 | return; |
@@ -804,7 +804,7 @@ discard block |
||
804 | 804 | EEH_Debug_Tools::log( |
805 | 805 | __CLASS__, __FUNCTION__, __LINE__, |
806 | 806 | array($payment), |
807 | - false, 'EE_Transaction: ' . $transaction->ID() |
|
807 | + false, 'EE_Transaction: '.$transaction->ID() |
|
808 | 808 | ); |
809 | 809 | } |
810 | 810 | return; |
@@ -861,7 +861,7 @@ discard block |
||
861 | 861 | /** @var EE_Transaction $transaction_in_progress */ |
862 | 862 | $total_line_item = $transaction_in_progress->total_line_item(); |
863 | 863 | // $transaction_in_progress->line |
864 | - if (! $total_line_item instanceof EE_Line_Item) { |
|
864 | + if ( ! $total_line_item instanceof EE_Line_Item) { |
|
865 | 865 | throw new DomainException( |
866 | 866 | esc_html__('Transaction does not have a valid Total Line Item associated with it.', 'event_espresso') |
867 | 867 | ); |
@@ -915,7 +915,7 @@ discard block |
||
915 | 915 | ) { |
916 | 916 | $total_tickets_released = 0; |
917 | 917 | foreach ($tickets_with_reservations as $ticket_with_reservations) { |
918 | - if (! $ticket_with_reservations instanceof EE_Ticket) { |
|
918 | + if ( ! $ticket_with_reservations instanceof EE_Ticket) { |
|
919 | 919 | continue; |
920 | 920 | } |
921 | 921 | $reserved_qty = $ticket_with_reservations->reserved(); |
@@ -18,807 +18,807 @@ |
||
18 | 18 | class EED_Core_Rest_Api extends \EED_Module |
19 | 19 | { |
20 | 20 | |
21 | - const ee_api_namespace = 'ee/v'; |
|
21 | + const ee_api_namespace = 'ee/v'; |
|
22 | 22 | |
23 | - const ee_api_namespace_for_regex = 'ee\/v([^/]*)\/'; |
|
23 | + const ee_api_namespace_for_regex = 'ee\/v([^/]*)\/'; |
|
24 | 24 | |
25 | - const saved_routes_option_names = 'ee_core_routes'; |
|
25 | + const saved_routes_option_names = 'ee_core_routes'; |
|
26 | 26 | |
27 | - /** |
|
28 | - * string used in _links response bodies to make them globally unique. |
|
29 | - * |
|
30 | - * @see http://v2.wp-api.org/extending/linking/ |
|
31 | - */ |
|
32 | - const ee_api_link_namespace = 'https://api.eventespresso.com/'; |
|
27 | + /** |
|
28 | + * string used in _links response bodies to make them globally unique. |
|
29 | + * |
|
30 | + * @see http://v2.wp-api.org/extending/linking/ |
|
31 | + */ |
|
32 | + const ee_api_link_namespace = 'https://api.eventespresso.com/'; |
|
33 | 33 | |
34 | - /** |
|
35 | - * @var Calculated_Model_Fields |
|
36 | - */ |
|
37 | - protected static $_field_calculator = null; |
|
34 | + /** |
|
35 | + * @var Calculated_Model_Fields |
|
36 | + */ |
|
37 | + protected static $_field_calculator = null; |
|
38 | 38 | |
39 | 39 | |
40 | 40 | |
41 | - /** |
|
42 | - * @return EED_Core_Rest_Api |
|
43 | - */ |
|
44 | - public static function instance() |
|
45 | - { |
|
46 | - self::$_field_calculator = new Calculated_Model_Fields(); |
|
47 | - return parent::get_instance(__CLASS__); |
|
48 | - } |
|
41 | + /** |
|
42 | + * @return EED_Core_Rest_Api |
|
43 | + */ |
|
44 | + public static function instance() |
|
45 | + { |
|
46 | + self::$_field_calculator = new Calculated_Model_Fields(); |
|
47 | + return parent::get_instance(__CLASS__); |
|
48 | + } |
|
49 | 49 | |
50 | 50 | |
51 | 51 | |
52 | - /** |
|
53 | - * set_hooks - for hooking into EE Core, other modules, etc |
|
54 | - * |
|
55 | - * @access public |
|
56 | - * @return void |
|
57 | - */ |
|
58 | - public static function set_hooks() |
|
59 | - { |
|
60 | - self::set_hooks_both(); |
|
61 | - } |
|
62 | - |
|
63 | - |
|
64 | - |
|
65 | - /** |
|
66 | - * set_hooks_admin - for hooking into EE Admin Core, other modules, etc |
|
67 | - * |
|
68 | - * @access public |
|
69 | - * @return void |
|
70 | - */ |
|
71 | - public static function set_hooks_admin() |
|
72 | - { |
|
73 | - self::set_hooks_both(); |
|
74 | - } |
|
75 | - |
|
76 | - |
|
77 | - |
|
78 | - public static function set_hooks_both() |
|
79 | - { |
|
80 | - add_action('rest_api_init', array('EED_Core_Rest_Api', 'register_routes'), 10); |
|
81 | - add_action('rest_api_init', array('EED_Core_Rest_Api', 'set_hooks_rest_api'), 5); |
|
82 | - add_filter('rest_route_data', array('EED_Core_Rest_Api', 'hide_old_endpoints'), 10, 2); |
|
83 | - add_filter('rest_index', |
|
84 | - array('EventEspresso\core\libraries\rest_api\controllers\model\Meta', 'filter_ee_metadata_into_index')); |
|
85 | - EED_Core_Rest_Api::invalidate_cached_route_data_on_version_change(); |
|
86 | - } |
|
87 | - |
|
88 | - |
|
89 | - |
|
90 | - /** |
|
91 | - * sets up hooks which only need to be included as part of REST API requests; |
|
92 | - * other requests like to the frontend or admin etc don't need them |
|
93 | - */ |
|
94 | - public static function set_hooks_rest_api() |
|
95 | - { |
|
96 | - //set hooks which account for changes made to the API |
|
97 | - EED_Core_Rest_Api::_set_hooks_for_changes(); |
|
98 | - } |
|
99 | - |
|
100 | - |
|
101 | - |
|
102 | - /** |
|
103 | - * public wrapper of _set_hooks_for_changes. |
|
104 | - * Loads all the hooks which make requests to old versions of the API |
|
105 | - * appear the same as they always did |
|
106 | - */ |
|
107 | - public static function set_hooks_for_changes() |
|
108 | - { |
|
109 | - self::_set_hooks_for_changes(); |
|
110 | - } |
|
111 | - |
|
112 | - |
|
113 | - |
|
114 | - |
|
115 | - |
|
116 | - |
|
117 | - |
|
118 | - /** |
|
119 | - * Loads all the hooks which make requests to old versions of the API |
|
120 | - * appear the same as they always did |
|
121 | - */ |
|
122 | - protected static function _set_hooks_for_changes() |
|
123 | - { |
|
124 | - $folder_contents = EEH_File::get_contents_of_folders(array(EE_LIBRARIES . 'rest_api' . DS . 'changes'), false); |
|
125 | - foreach ($folder_contents as $classname_in_namespace => $filepath) { |
|
126 | - //ignore the base parent class |
|
127 | - if ($classname_in_namespace === 'Changes_In_Base') { |
|
128 | - continue; |
|
129 | - } |
|
130 | - $full_classname = 'EventEspresso\core\libraries\rest_api\changes\\' . $classname_in_namespace; |
|
131 | - if (class_exists($full_classname)) { |
|
132 | - $instance_of_class = new $full_classname; |
|
133 | - if ($instance_of_class instanceof Changes_In_Base) { |
|
134 | - $instance_of_class->set_hooks(); |
|
135 | - } |
|
136 | - } |
|
137 | - } |
|
138 | - } |
|
139 | - |
|
140 | - |
|
141 | - |
|
142 | - /** |
|
143 | - * Filters the WP routes to add our EE-related ones. This takes a bit of time |
|
144 | - * so we actually prefer to only do it when an EE plugin is activated or upgraded |
|
145 | - */ |
|
146 | - public static function register_routes() |
|
147 | - { |
|
148 | - foreach (EED_Core_Rest_Api::get_ee_route_data() as $namespace => $relative_urls) { |
|
149 | - foreach ($relative_urls as $endpoint => $routes) { |
|
150 | - foreach ($routes as $route) { |
|
151 | - $route_args = array( |
|
152 | - array( |
|
153 | - 'callback' => $route['callback'], |
|
154 | - 'methods' => $route['methods'], |
|
155 | - 'args' => isset($route['args']) ? $route['args'] : array(), |
|
156 | - ) |
|
157 | - ); |
|
158 | - if (isset($route['schema_callback'])) { |
|
159 | - $model_name = isset($route['schema_callback'][0]) |
|
160 | - ? $route['schema_callback'][0] |
|
161 | - : ''; |
|
162 | - $version = isset( $route['schema_callback'][1]) |
|
163 | - ? $route['schema_callback'][1] |
|
164 | - : ''; |
|
165 | - if (! empty($model_name) && ! empty($version)) { |
|
166 | - $route_args['schema'] = function () use ($model_name, $version) { |
|
167 | - return ModelRead::handle_schema_request( |
|
168 | - $model_name, |
|
169 | - $version |
|
170 | - ); |
|
171 | - }; |
|
172 | - } |
|
173 | - } |
|
174 | - register_rest_route( |
|
175 | - $namespace, |
|
176 | - $endpoint, |
|
177 | - $route_args |
|
178 | - ); |
|
179 | - } |
|
180 | - } |
|
181 | - } |
|
182 | - } |
|
183 | - |
|
184 | - |
|
185 | - |
|
186 | - /** |
|
187 | - * Checks if there was a version change or something that merits invalidating the cached |
|
188 | - * route data. If so, invalidates the cached route data so that it gets refreshed |
|
189 | - * next time the WP API is used |
|
190 | - */ |
|
191 | - public static function invalidate_cached_route_data_on_version_change() |
|
192 | - { |
|
193 | - if (EE_System::instance()->detect_req_type() != EE_System::req_type_normal) { |
|
194 | - EED_Core_Rest_Api::invalidate_cached_route_data(); |
|
195 | - } |
|
196 | - foreach (EE_Registry::instance()->addons as $addon) { |
|
197 | - if ($addon instanceof EE_Addon && $addon->detect_req_type() != EE_System::req_type_normal) { |
|
198 | - EED_Core_Rest_Api::invalidate_cached_route_data(); |
|
199 | - } |
|
200 | - } |
|
201 | - } |
|
202 | - |
|
203 | - |
|
204 | - |
|
205 | - /** |
|
206 | - * Removes the cached route data so it will get refreshed next time the WP API is used |
|
207 | - */ |
|
208 | - public static function invalidate_cached_route_data() |
|
209 | - { |
|
210 | - //delete the saved EE REST API routes |
|
211 | - foreach (EED_Core_Rest_Api::versions_served() as $version => $hidden) { |
|
212 | - delete_option(EED_Core_Rest_Api::saved_routes_option_names . $version); |
|
213 | - } |
|
214 | - } |
|
215 | - |
|
216 | - |
|
217 | - |
|
218 | - /** |
|
219 | - * Gets the EE route data |
|
220 | - * |
|
221 | - * @return array top-level key is the namespace, next-level key is the route and its value is array{ |
|
222 | - * @type string|array $callback |
|
223 | - * @type string $methods |
|
224 | - * @type boolean $hidden_endpoint |
|
225 | - * } |
|
226 | - */ |
|
227 | - public static function get_ee_route_data() |
|
228 | - { |
|
229 | - $ee_routes = array(); |
|
230 | - foreach (self::versions_served() as $version => $hidden_endpoints) { |
|
231 | - $ee_routes[self::ee_api_namespace . $version] = self::_get_ee_route_data_for_version($version, |
|
232 | - $hidden_endpoints); |
|
233 | - } |
|
234 | - return $ee_routes; |
|
235 | - } |
|
236 | - |
|
237 | - |
|
238 | - |
|
239 | - /** |
|
240 | - * Gets the EE route data from the wp options if it exists already, |
|
241 | - * otherwise re-generates it and saves it to the option |
|
242 | - * |
|
243 | - * @param string $version |
|
244 | - * @param boolean $hidden_endpoints |
|
245 | - * @return array |
|
246 | - */ |
|
247 | - protected static function _get_ee_route_data_for_version($version, $hidden_endpoints = false) |
|
248 | - { |
|
249 | - $ee_routes = get_option(self::saved_routes_option_names . $version, null); |
|
250 | - if ( ! $ee_routes || (defined('EE_REST_API_DEBUG_MODE') && EE_REST_API_DEBUG_MODE)) { |
|
251 | - $ee_routes = self::_save_ee_route_data_for_version($version, $hidden_endpoints); |
|
252 | - } |
|
253 | - return $ee_routes; |
|
254 | - } |
|
255 | - |
|
256 | - |
|
257 | - |
|
258 | - /** |
|
259 | - * Saves the EE REST API route data to a wp option and returns it |
|
260 | - * |
|
261 | - * @param string $version |
|
262 | - * @param boolean $hidden_endpoints |
|
263 | - * @return mixed|null|void |
|
264 | - */ |
|
265 | - protected static function _save_ee_route_data_for_version($version, $hidden_endpoints = false) |
|
266 | - { |
|
267 | - $instance = self::instance(); |
|
268 | - $routes = apply_filters( |
|
269 | - 'EED_Core_Rest_Api__save_ee_route_data_for_version__routes', |
|
270 | - array_replace_recursive( |
|
271 | - $instance->_get_config_route_data_for_version($version, $hidden_endpoints), |
|
272 | - $instance->_get_meta_route_data_for_version($version, $hidden_endpoints), |
|
273 | - $instance->_get_model_route_data_for_version($version, $hidden_endpoints), |
|
274 | - $instance->_get_rpc_route_data_for_version($version, $hidden_endpoints) |
|
275 | - ) |
|
276 | - ); |
|
277 | - $option_name = self::saved_routes_option_names . $version; |
|
278 | - if (get_option($option_name)) { |
|
279 | - update_option($option_name, $routes, true); |
|
280 | - } else { |
|
281 | - add_option($option_name, $routes, null, 'no'); |
|
282 | - } |
|
283 | - return $routes; |
|
284 | - } |
|
285 | - |
|
286 | - |
|
287 | - |
|
288 | - /** |
|
289 | - * Calculates all the EE routes and saves it to a wordpress option so we don't |
|
290 | - * need to calculate it on every request |
|
291 | - * |
|
292 | - * @deprecated since version 4.9.1 |
|
293 | - * @return void |
|
294 | - */ |
|
295 | - public static function save_ee_routes() |
|
296 | - { |
|
297 | - if (EE_Maintenance_Mode::instance()->models_can_query()) { |
|
298 | - $instance = self::instance(); |
|
299 | - $routes = apply_filters( |
|
300 | - 'EED_Core_Rest_Api__save_ee_routes__routes', |
|
301 | - array_replace_recursive( |
|
302 | - $instance->_register_config_routes(), |
|
303 | - $instance->_register_meta_routes(), |
|
304 | - $instance->_register_model_routes(), |
|
305 | - $instance->_register_rpc_routes() |
|
306 | - ) |
|
307 | - ); |
|
308 | - update_option(self::saved_routes_option_names, $routes, true); |
|
309 | - } |
|
310 | - } |
|
311 | - |
|
312 | - |
|
313 | - |
|
314 | - /** |
|
315 | - * Gets all the route information relating to EE models |
|
316 | - * |
|
317 | - * @return array @see get_ee_route_data |
|
318 | - * @deprecated since version 4.9.1 |
|
319 | - */ |
|
320 | - protected function _register_model_routes() |
|
321 | - { |
|
322 | - $model_routes = array(); |
|
323 | - foreach (self::versions_served() as $version => $hidden_endpoint) { |
|
324 | - $model_routes[EED_Core_Rest_Api::ee_api_namespace |
|
325 | - . $version] = $this->_get_config_route_data_for_version($version, $hidden_endpoint); |
|
326 | - } |
|
327 | - return $model_routes; |
|
328 | - } |
|
329 | - |
|
330 | - |
|
331 | - |
|
332 | - /** |
|
333 | - * Gets the route data for EE models in the specified version |
|
334 | - * |
|
335 | - * @param string $version |
|
336 | - * @param boolean $hidden_endpoint |
|
337 | - * @return array |
|
338 | - */ |
|
339 | - protected function _get_model_route_data_for_version($version, $hidden_endpoint = false) |
|
340 | - { |
|
341 | - $model_version_info = new Model_Version_Info($version); |
|
342 | - $models_to_register = apply_filters( |
|
343 | - 'FHEE__EED_Core_REST_API___register_model_routes', |
|
344 | - $model_version_info->models_for_requested_version() |
|
345 | - ); |
|
346 | - //let's not bother having endpoints for extra metas |
|
347 | - unset($models_to_register['Extra_Meta']); |
|
348 | - unset($models_to_register['Extra_Join']); |
|
349 | - $model_routes = array(); |
|
350 | - foreach ($models_to_register as $model_name => $model_classname) { |
|
351 | - $model = \EE_Registry::instance()->load_model($model_name); |
|
352 | - |
|
353 | - //if this isn't a valid model then let's skip iterate to the next item in the loop. |
|
354 | - if (! $model instanceof EEM_Base) { |
|
355 | - continue; |
|
356 | - } |
|
357 | - |
|
358 | - //yes we could just register one route for ALL models, but then they wouldn't show up in the index |
|
359 | - $plural_model_route = EEH_Inflector::pluralize_and_lower($model_name); |
|
360 | - $singular_model_route = $plural_model_route . '/(?P<id>\d+)'; |
|
361 | - $model_routes[$plural_model_route] = array( |
|
362 | - array( |
|
363 | - 'callback' => array( |
|
364 | - 'EventEspresso\core\libraries\rest_api\controllers\model\Read', |
|
365 | - 'handle_request_get_all', |
|
366 | - ), |
|
367 | - 'methods' => WP_REST_Server::READABLE, |
|
368 | - 'hidden_endpoint' => $hidden_endpoint, |
|
369 | - 'args' => $this->_get_read_query_params($model, $version), |
|
370 | - '_links' => array( |
|
371 | - 'self' => rest_url(EED_Core_Rest_Api::ee_api_namespace . $version . $singular_model_route), |
|
372 | - ), |
|
373 | - 'schema_callback' => array($model_name, $version) |
|
374 | - ), |
|
375 | - // array( |
|
376 | - // 'callback' => array( |
|
377 | - // 'EventEspresso\core\libraries\rest_api\controllers\model\Write', |
|
378 | - // 'handle_request_create_one' ), |
|
379 | - // 'methods' => WP_REST_Server::CREATABLE, |
|
380 | - // 'hidden_endpoint' => $hidden_endpoint |
|
381 | - // ) |
|
382 | - ); |
|
383 | - $model_routes[$singular_model_route] = array( |
|
384 | - array( |
|
385 | - 'callback' => array( |
|
386 | - 'EventEspresso\core\libraries\rest_api\controllers\model\Read', |
|
387 | - 'handle_request_get_one', |
|
388 | - ), |
|
389 | - 'methods' => WP_REST_Server::READABLE, |
|
390 | - 'hidden_endpoint' => $hidden_endpoint, |
|
391 | - 'args' => $this->_get_response_selection_query_params($model, $version), |
|
392 | - ), |
|
393 | - // array( |
|
394 | - // 'callback' => array( |
|
395 | - // 'EventEspresso\core\libraries\rest_api\controllers\model\Write', |
|
396 | - // 'handle_request_edit_one' ), |
|
397 | - // 'methods' => WP_REST_Server::EDITABLE, |
|
398 | - // 'hidden_endpoint' => $hidden_endpoint |
|
399 | - // ), |
|
400 | - ); |
|
401 | - //@todo: also handle DELETE for a single item |
|
402 | - foreach ($model_version_info->relation_settings($model) as $relation_name => $relation_obj) { |
|
403 | - $related_model_name_endpoint_part = ModelRead::get_related_entity_name( |
|
404 | - $relation_name, |
|
405 | - $relation_obj |
|
406 | - ); |
|
407 | - $model_routes[$singular_model_route . '/' . $related_model_name_endpoint_part] = array( |
|
408 | - array( |
|
409 | - 'callback' => array( |
|
410 | - 'EventEspresso\core\libraries\rest_api\controllers\model\Read', |
|
411 | - 'handle_request_get_related', |
|
412 | - ), |
|
413 | - 'methods' => WP_REST_Server::READABLE, |
|
414 | - 'hidden_endpoint' => $hidden_endpoint, |
|
415 | - 'args' => $this->_get_read_query_params($relation_obj->get_other_model(), $version), |
|
416 | - ), |
|
417 | - // array( |
|
418 | - // 'callback' => array( |
|
419 | - // 'EventEspresso\core\libraries\rest_api\controllers\model\Write', |
|
420 | - // 'handle_request_create_or_update_related' ), |
|
421 | - // 'methods' => WP_REST_Server::EDITABLE, |
|
422 | - // 'hidden_endpoint' => $hidden_endpoint |
|
423 | - // ) |
|
424 | - ); |
|
425 | - //@todo: handle delete related and possibly remove relation (not sure hwo to distinguish) |
|
426 | - } |
|
427 | - } |
|
428 | - return $model_routes; |
|
429 | - } |
|
430 | - |
|
431 | - |
|
432 | - |
|
433 | - /** |
|
434 | - * Adds all the RPC-style routes (remote procedure call-like routes, ie |
|
435 | - * routes that don't conform to the traditional REST CRUD-style). |
|
436 | - * |
|
437 | - * @deprecated since 4.9.1 |
|
438 | - */ |
|
439 | - protected function _register_rpc_routes() |
|
440 | - { |
|
441 | - $routes = array(); |
|
442 | - foreach (self::versions_served() as $version => $hidden_endpoint) { |
|
443 | - $routes[self::ee_api_namespace . $version] = $this->_get_rpc_route_data_for_version($version, |
|
444 | - $hidden_endpoint); |
|
445 | - } |
|
446 | - return $routes; |
|
447 | - } |
|
448 | - |
|
449 | - |
|
450 | - |
|
451 | - /** |
|
452 | - * @param string $version |
|
453 | - * @param boolean $hidden_endpoint |
|
454 | - * @return array |
|
455 | - */ |
|
456 | - protected function _get_rpc_route_data_for_version($version, $hidden_endpoint = false) |
|
457 | - { |
|
458 | - $this_versions_routes = array(); |
|
459 | - //checkin endpoint |
|
460 | - $this_versions_routes['registrations/(?P<REG_ID>\d+)/toggle_checkin_for_datetime/(?P<DTT_ID>\d+)'] = array( |
|
461 | - array( |
|
462 | - 'callback' => array( |
|
463 | - 'EventEspresso\core\libraries\rest_api\controllers\rpc\Checkin', |
|
464 | - 'handle_request_toggle_checkin', |
|
465 | - ), |
|
466 | - 'methods' => WP_REST_Server::CREATABLE, |
|
467 | - 'hidden_endpoint' => $hidden_endpoint, |
|
468 | - 'args' => array( |
|
469 | - 'force' => array( |
|
470 | - 'required' => false, |
|
471 | - 'default' => false, |
|
472 | - 'description' => __('Whether to force toggle checkin, or to verify the registration status and allowed ticket uses', |
|
473 | - 'event_espresso'), |
|
474 | - ), |
|
475 | - ), |
|
476 | - ), |
|
477 | - ); |
|
478 | - return apply_filters( |
|
479 | - 'FHEE__EED_Core_Rest_Api___register_rpc_routes__this_versions_routes', |
|
480 | - $this_versions_routes, |
|
481 | - $version, |
|
482 | - $hidden_endpoint |
|
483 | - ); |
|
484 | - } |
|
485 | - |
|
486 | - |
|
487 | - |
|
488 | - /** |
|
489 | - * Gets the query params that can be used when request one or many |
|
490 | - * |
|
491 | - * @param EEM_Base $model |
|
492 | - * @param string $version |
|
493 | - * @return array |
|
494 | - */ |
|
495 | - protected function _get_response_selection_query_params(\EEM_Base $model, $version) |
|
496 | - { |
|
497 | - return apply_filters( |
|
498 | - 'FHEE__EED_Core_Rest_Api___get_response_selection_query_params', |
|
499 | - array( |
|
500 | - 'include' => array( |
|
501 | - 'required' => false, |
|
502 | - 'default' => '*', |
|
503 | - ), |
|
504 | - 'calculate' => array( |
|
505 | - 'required' => false, |
|
506 | - 'default' => '', |
|
507 | - 'enum' => self::$_field_calculator->retrieve_calculated_fields_for_model($model), |
|
508 | - ), |
|
509 | - ), |
|
510 | - $model, |
|
511 | - $version |
|
512 | - ); |
|
513 | - } |
|
514 | - |
|
515 | - |
|
516 | - |
|
517 | - /** |
|
518 | - * Gets info about reading query params that are acceptable |
|
519 | - * |
|
520 | - * @param \EEM_Base $model eg 'Event' or 'Venue' |
|
521 | - * @param string $version |
|
522 | - * @return array describing the args acceptable when querying this model |
|
523 | - * @throws \EE_Error |
|
524 | - */ |
|
525 | - protected function _get_read_query_params(\EEM_Base $model, $version) |
|
526 | - { |
|
527 | - $default_orderby = array(); |
|
528 | - foreach ($model->get_combined_primary_key_fields() as $key_field) { |
|
529 | - $default_orderby[$key_field->get_name()] = 'ASC'; |
|
530 | - } |
|
531 | - return array_merge( |
|
532 | - $this->_get_response_selection_query_params($model, $version), |
|
533 | - array( |
|
534 | - 'where' => array( |
|
535 | - 'required' => false, |
|
536 | - 'default' => array(), |
|
537 | - ), |
|
538 | - 'limit' => array( |
|
539 | - 'required' => false, |
|
540 | - 'default' => EED_Core_Rest_Api::get_default_query_limit(), |
|
541 | - ), |
|
542 | - 'order_by' => array( |
|
543 | - 'required' => false, |
|
544 | - 'default' => $default_orderby, |
|
545 | - ), |
|
546 | - 'group_by' => array( |
|
547 | - 'required' => false, |
|
548 | - 'default' => null, |
|
549 | - ), |
|
550 | - 'having' => array( |
|
551 | - 'required' => false, |
|
552 | - 'default' => null, |
|
553 | - ), |
|
554 | - 'caps' => array( |
|
555 | - 'required' => false, |
|
556 | - 'default' => EEM_Base::caps_read, |
|
557 | - ), |
|
558 | - ) |
|
559 | - ); |
|
560 | - } |
|
561 | - |
|
562 | - |
|
563 | - |
|
564 | - /** |
|
565 | - * Gets routes for the config |
|
566 | - * |
|
567 | - * @return array @see _register_model_routes |
|
568 | - * @deprecated since version 4.9.1 |
|
569 | - */ |
|
570 | - protected function _register_config_routes() |
|
571 | - { |
|
572 | - $config_routes = array(); |
|
573 | - foreach (self::versions_served() as $version => $hidden_endpoint) { |
|
574 | - $config_routes[self::ee_api_namespace . $version] = $this->_get_config_route_data_for_version($version, |
|
575 | - $hidden_endpoint); |
|
576 | - } |
|
577 | - return $config_routes; |
|
578 | - } |
|
579 | - |
|
580 | - |
|
581 | - |
|
582 | - /** |
|
583 | - * Gets routes for the config for the specified version |
|
584 | - * |
|
585 | - * @param string $version |
|
586 | - * @param boolean $hidden_endpoint |
|
587 | - * @return array |
|
588 | - */ |
|
589 | - protected function _get_config_route_data_for_version($version, $hidden_endpoint) |
|
590 | - { |
|
591 | - return array( |
|
592 | - 'config' => array( |
|
593 | - array( |
|
594 | - 'callback' => array( |
|
595 | - 'EventEspresso\core\libraries\rest_api\controllers\config\Read', |
|
596 | - 'handle_request', |
|
597 | - ), |
|
598 | - 'methods' => WP_REST_Server::READABLE, |
|
599 | - 'hidden_endpoint' => $hidden_endpoint, |
|
600 | - ), |
|
601 | - ), |
|
602 | - 'site_info' => array( |
|
603 | - array( |
|
604 | - 'callback' => array( |
|
605 | - 'EventEspresso\core\libraries\rest_api\controllers\config\Read', |
|
606 | - 'handle_request_site_info', |
|
607 | - ), |
|
608 | - 'methods' => WP_REST_Server::READABLE, |
|
609 | - 'hidden_endpoint' => $hidden_endpoint, |
|
610 | - ), |
|
611 | - ), |
|
612 | - ); |
|
613 | - } |
|
614 | - |
|
615 | - |
|
616 | - |
|
617 | - /** |
|
618 | - * Gets the meta info routes |
|
619 | - * |
|
620 | - * @return array @see _register_model_routes |
|
621 | - * @deprecated since version 4.9.1 |
|
622 | - */ |
|
623 | - protected function _register_meta_routes() |
|
624 | - { |
|
625 | - $meta_routes = array(); |
|
626 | - foreach (self::versions_served() as $version => $hidden_endpoint) { |
|
627 | - $meta_routes[self::ee_api_namespace . $version] = $this->_get_meta_route_data_for_version($version, |
|
628 | - $hidden_endpoint); |
|
629 | - } |
|
630 | - return $meta_routes; |
|
631 | - } |
|
632 | - |
|
633 | - |
|
634 | - |
|
635 | - /** |
|
636 | - * @param string $version |
|
637 | - * @param boolean $hidden_endpoint |
|
638 | - * @return array |
|
639 | - */ |
|
640 | - protected function _get_meta_route_data_for_version($version, $hidden_endpoint = false) |
|
641 | - { |
|
642 | - return array( |
|
643 | - 'resources' => array( |
|
644 | - array( |
|
645 | - 'callback' => array( |
|
646 | - 'EventEspresso\core\libraries\rest_api\controllers\model\Meta', |
|
647 | - 'handle_request_models_meta', |
|
648 | - ), |
|
649 | - 'methods' => WP_REST_Server::READABLE, |
|
650 | - 'hidden_endpoint' => $hidden_endpoint, |
|
651 | - ), |
|
652 | - ), |
|
653 | - ); |
|
654 | - } |
|
655 | - |
|
656 | - |
|
657 | - |
|
658 | - /** |
|
659 | - * Tries to hide old 4.6 endpoints from the |
|
660 | - * |
|
661 | - * @param array $route_data |
|
662 | - * @return array |
|
663 | - */ |
|
664 | - public static function hide_old_endpoints($route_data) |
|
665 | - { |
|
666 | - //allow API clients to override which endpoints get hidden, in case |
|
667 | - //they want to discover particular endpoints |
|
668 | - //also, we don't have access to the request so we have to just grab it from the superglobal |
|
669 | - $force_show_ee_namespace = ltrim( |
|
670 | - EEH_Array::is_set($_REQUEST, 'force_show_ee_namespace', ''), |
|
671 | - '/' |
|
672 | - ); |
|
673 | - foreach (EED_Core_Rest_Api::get_ee_route_data() as $namespace => $relative_urls) { |
|
674 | - foreach ($relative_urls as $endpoint => $routes) { |
|
675 | - foreach ($routes as $route) { |
|
676 | - //by default, hide "hidden_endpoint"s, unless the request indicates |
|
677 | - //to $force_show_ee_namespace, in which case only show that one |
|
678 | - //namespace's endpoints (and hide all others) |
|
679 | - if (($route['hidden_endpoint'] && $force_show_ee_namespace === '') |
|
680 | - || ($force_show_ee_namespace !== '' && $force_show_ee_namespace !== $namespace) |
|
681 | - ) { |
|
682 | - $full_route = '/' . ltrim($namespace, '/') . '/' . ltrim($endpoint, '/'); |
|
683 | - unset($route_data[$full_route]); |
|
684 | - } |
|
685 | - } |
|
686 | - } |
|
687 | - } |
|
688 | - return $route_data; |
|
689 | - } |
|
690 | - |
|
691 | - |
|
692 | - |
|
693 | - /** |
|
694 | - * Returns an array describing which versions of core support serving requests for. |
|
695 | - * Keys are core versions' major and minor version, and values are the |
|
696 | - * LOWEST requested version they can serve. Eg, 4.7 can serve requests for 4.6-like |
|
697 | - * data by just removing a few models and fields from the responses. However, 4.15 might remove |
|
698 | - * the answers table entirely, in which case it would be very difficult for |
|
699 | - * it to serve 4.6-style responses. |
|
700 | - * Versions of core that are missing from this array are unknowns. |
|
701 | - * previous ver |
|
702 | - * |
|
703 | - * @return array |
|
704 | - */ |
|
705 | - public static function version_compatibilities() |
|
706 | - { |
|
707 | - return apply_filters( |
|
708 | - 'FHEE__EED_Core_REST_API__version_compatibilities', |
|
709 | - array( |
|
710 | - '4.8.29' => '4.8.29', |
|
711 | - '4.8.33' => '4.8.29', |
|
712 | - '4.8.34' => '4.8.29', |
|
713 | - '4.8.36' => '4.8.29', |
|
714 | - ) |
|
715 | - ); |
|
716 | - } |
|
717 | - |
|
718 | - |
|
719 | - |
|
720 | - /** |
|
721 | - * Gets the latest API version served. Eg if there |
|
722 | - * are two versions served of the API, 4.8.29 and 4.8.32, and |
|
723 | - * we are on core version 4.8.34, it will return the string "4.8.32" |
|
724 | - * |
|
725 | - * @return string |
|
726 | - */ |
|
727 | - public static function latest_rest_api_version() |
|
728 | - { |
|
729 | - $versions_served = \EED_Core_Rest_Api::versions_served(); |
|
730 | - $versions_served_keys = array_keys($versions_served); |
|
731 | - return end($versions_served_keys); |
|
732 | - } |
|
733 | - |
|
734 | - |
|
735 | - |
|
736 | - /** |
|
737 | - * Using EED_Core_Rest_Api::version_compatibilities(), determines what version of |
|
738 | - * EE the API can serve requests for. Eg, if we are on 4.15 of core, and |
|
739 | - * we can serve requests from 4.12 or later, this will return array( '4.12', '4.13', '4.14', '4.15' ). |
|
740 | - * We also indicate whether or not this version should be put in the index or not |
|
741 | - * |
|
742 | - * @return array keys are API version numbers (just major and minor numbers), and values |
|
743 | - * are whether or not they should be hidden |
|
744 | - */ |
|
745 | - public static function versions_served() |
|
746 | - { |
|
747 | - $versions_served = array(); |
|
748 | - $possibly_served_versions = EED_Core_Rest_Api::version_compatibilities(); |
|
749 | - $lowest_compatible_version = end($possibly_served_versions); |
|
750 | - reset($possibly_served_versions); |
|
751 | - $versions_served_historically = array_keys($possibly_served_versions); |
|
752 | - $latest_version = end($versions_served_historically); |
|
753 | - reset($versions_served_historically); |
|
754 | - //for each version of core we have ever served: |
|
755 | - foreach ($versions_served_historically as $key_versioned_endpoint) { |
|
756 | - //if it's not above the current core version, and it's compatible with the current version of core |
|
757 | - if ($key_versioned_endpoint == $latest_version) { |
|
758 | - //don't hide the latest version in the index |
|
759 | - $versions_served[$key_versioned_endpoint] = false; |
|
760 | - } else if ( |
|
761 | - $key_versioned_endpoint < EED_Core_Rest_Api::core_version() |
|
762 | - && $key_versioned_endpoint >= $lowest_compatible_version |
|
763 | - ) { |
|
764 | - //include, but hide, previous versions which are still supported |
|
765 | - $versions_served[$key_versioned_endpoint] = true; |
|
766 | - } elseif ( |
|
767 | - apply_filters( |
|
768 | - 'FHEE__EED_Core_Rest_Api__versions_served__include_incompatible_versions', |
|
769 | - false, |
|
770 | - $possibly_served_versions |
|
771 | - ) |
|
772 | - ) { |
|
773 | - //if a version is no longer supported, don't include it in index or list of versions served |
|
774 | - $versions_served[$key_versioned_endpoint] = true; |
|
775 | - } |
|
776 | - } |
|
777 | - return $versions_served; |
|
778 | - } |
|
779 | - |
|
780 | - |
|
781 | - |
|
782 | - /** |
|
783 | - * Gets the major and minor version of EE core's version string |
|
784 | - * |
|
785 | - * @return string |
|
786 | - */ |
|
787 | - public static function core_version() |
|
788 | - { |
|
789 | - return apply_filters('FHEE__EED_Core_REST_API__core_version', |
|
790 | - implode('.', array_slice(explode('.', espresso_version()), 0, 3))); |
|
791 | - } |
|
792 | - |
|
793 | - |
|
794 | - |
|
795 | - /** |
|
796 | - * Gets the default limit that should be used when querying for resources |
|
797 | - * |
|
798 | - * @return int |
|
799 | - */ |
|
800 | - public static function get_default_query_limit() |
|
801 | - { |
|
802 | - //we actually don't use a const because we want folks to always use |
|
803 | - //this method, not the const directly |
|
804 | - return apply_filters( |
|
805 | - 'FHEE__EED_Core_Rest_Api__get_default_query_limit', |
|
806 | - 50 |
|
807 | - ); |
|
808 | - } |
|
809 | - |
|
810 | - |
|
811 | - |
|
812 | - /** |
|
813 | - * run - initial module setup |
|
814 | - * |
|
815 | - * @access public |
|
816 | - * @param WP $WP |
|
817 | - * @return void |
|
818 | - */ |
|
819 | - public function run($WP) |
|
820 | - { |
|
821 | - } |
|
52 | + /** |
|
53 | + * set_hooks - for hooking into EE Core, other modules, etc |
|
54 | + * |
|
55 | + * @access public |
|
56 | + * @return void |
|
57 | + */ |
|
58 | + public static function set_hooks() |
|
59 | + { |
|
60 | + self::set_hooks_both(); |
|
61 | + } |
|
62 | + |
|
63 | + |
|
64 | + |
|
65 | + /** |
|
66 | + * set_hooks_admin - for hooking into EE Admin Core, other modules, etc |
|
67 | + * |
|
68 | + * @access public |
|
69 | + * @return void |
|
70 | + */ |
|
71 | + public static function set_hooks_admin() |
|
72 | + { |
|
73 | + self::set_hooks_both(); |
|
74 | + } |
|
75 | + |
|
76 | + |
|
77 | + |
|
78 | + public static function set_hooks_both() |
|
79 | + { |
|
80 | + add_action('rest_api_init', array('EED_Core_Rest_Api', 'register_routes'), 10); |
|
81 | + add_action('rest_api_init', array('EED_Core_Rest_Api', 'set_hooks_rest_api'), 5); |
|
82 | + add_filter('rest_route_data', array('EED_Core_Rest_Api', 'hide_old_endpoints'), 10, 2); |
|
83 | + add_filter('rest_index', |
|
84 | + array('EventEspresso\core\libraries\rest_api\controllers\model\Meta', 'filter_ee_metadata_into_index')); |
|
85 | + EED_Core_Rest_Api::invalidate_cached_route_data_on_version_change(); |
|
86 | + } |
|
87 | + |
|
88 | + |
|
89 | + |
|
90 | + /** |
|
91 | + * sets up hooks which only need to be included as part of REST API requests; |
|
92 | + * other requests like to the frontend or admin etc don't need them |
|
93 | + */ |
|
94 | + public static function set_hooks_rest_api() |
|
95 | + { |
|
96 | + //set hooks which account for changes made to the API |
|
97 | + EED_Core_Rest_Api::_set_hooks_for_changes(); |
|
98 | + } |
|
99 | + |
|
100 | + |
|
101 | + |
|
102 | + /** |
|
103 | + * public wrapper of _set_hooks_for_changes. |
|
104 | + * Loads all the hooks which make requests to old versions of the API |
|
105 | + * appear the same as they always did |
|
106 | + */ |
|
107 | + public static function set_hooks_for_changes() |
|
108 | + { |
|
109 | + self::_set_hooks_for_changes(); |
|
110 | + } |
|
111 | + |
|
112 | + |
|
113 | + |
|
114 | + |
|
115 | + |
|
116 | + |
|
117 | + |
|
118 | + /** |
|
119 | + * Loads all the hooks which make requests to old versions of the API |
|
120 | + * appear the same as they always did |
|
121 | + */ |
|
122 | + protected static function _set_hooks_for_changes() |
|
123 | + { |
|
124 | + $folder_contents = EEH_File::get_contents_of_folders(array(EE_LIBRARIES . 'rest_api' . DS . 'changes'), false); |
|
125 | + foreach ($folder_contents as $classname_in_namespace => $filepath) { |
|
126 | + //ignore the base parent class |
|
127 | + if ($classname_in_namespace === 'Changes_In_Base') { |
|
128 | + continue; |
|
129 | + } |
|
130 | + $full_classname = 'EventEspresso\core\libraries\rest_api\changes\\' . $classname_in_namespace; |
|
131 | + if (class_exists($full_classname)) { |
|
132 | + $instance_of_class = new $full_classname; |
|
133 | + if ($instance_of_class instanceof Changes_In_Base) { |
|
134 | + $instance_of_class->set_hooks(); |
|
135 | + } |
|
136 | + } |
|
137 | + } |
|
138 | + } |
|
139 | + |
|
140 | + |
|
141 | + |
|
142 | + /** |
|
143 | + * Filters the WP routes to add our EE-related ones. This takes a bit of time |
|
144 | + * so we actually prefer to only do it when an EE plugin is activated or upgraded |
|
145 | + */ |
|
146 | + public static function register_routes() |
|
147 | + { |
|
148 | + foreach (EED_Core_Rest_Api::get_ee_route_data() as $namespace => $relative_urls) { |
|
149 | + foreach ($relative_urls as $endpoint => $routes) { |
|
150 | + foreach ($routes as $route) { |
|
151 | + $route_args = array( |
|
152 | + array( |
|
153 | + 'callback' => $route['callback'], |
|
154 | + 'methods' => $route['methods'], |
|
155 | + 'args' => isset($route['args']) ? $route['args'] : array(), |
|
156 | + ) |
|
157 | + ); |
|
158 | + if (isset($route['schema_callback'])) { |
|
159 | + $model_name = isset($route['schema_callback'][0]) |
|
160 | + ? $route['schema_callback'][0] |
|
161 | + : ''; |
|
162 | + $version = isset( $route['schema_callback'][1]) |
|
163 | + ? $route['schema_callback'][1] |
|
164 | + : ''; |
|
165 | + if (! empty($model_name) && ! empty($version)) { |
|
166 | + $route_args['schema'] = function () use ($model_name, $version) { |
|
167 | + return ModelRead::handle_schema_request( |
|
168 | + $model_name, |
|
169 | + $version |
|
170 | + ); |
|
171 | + }; |
|
172 | + } |
|
173 | + } |
|
174 | + register_rest_route( |
|
175 | + $namespace, |
|
176 | + $endpoint, |
|
177 | + $route_args |
|
178 | + ); |
|
179 | + } |
|
180 | + } |
|
181 | + } |
|
182 | + } |
|
183 | + |
|
184 | + |
|
185 | + |
|
186 | + /** |
|
187 | + * Checks if there was a version change or something that merits invalidating the cached |
|
188 | + * route data. If so, invalidates the cached route data so that it gets refreshed |
|
189 | + * next time the WP API is used |
|
190 | + */ |
|
191 | + public static function invalidate_cached_route_data_on_version_change() |
|
192 | + { |
|
193 | + if (EE_System::instance()->detect_req_type() != EE_System::req_type_normal) { |
|
194 | + EED_Core_Rest_Api::invalidate_cached_route_data(); |
|
195 | + } |
|
196 | + foreach (EE_Registry::instance()->addons as $addon) { |
|
197 | + if ($addon instanceof EE_Addon && $addon->detect_req_type() != EE_System::req_type_normal) { |
|
198 | + EED_Core_Rest_Api::invalidate_cached_route_data(); |
|
199 | + } |
|
200 | + } |
|
201 | + } |
|
202 | + |
|
203 | + |
|
204 | + |
|
205 | + /** |
|
206 | + * Removes the cached route data so it will get refreshed next time the WP API is used |
|
207 | + */ |
|
208 | + public static function invalidate_cached_route_data() |
|
209 | + { |
|
210 | + //delete the saved EE REST API routes |
|
211 | + foreach (EED_Core_Rest_Api::versions_served() as $version => $hidden) { |
|
212 | + delete_option(EED_Core_Rest_Api::saved_routes_option_names . $version); |
|
213 | + } |
|
214 | + } |
|
215 | + |
|
216 | + |
|
217 | + |
|
218 | + /** |
|
219 | + * Gets the EE route data |
|
220 | + * |
|
221 | + * @return array top-level key is the namespace, next-level key is the route and its value is array{ |
|
222 | + * @type string|array $callback |
|
223 | + * @type string $methods |
|
224 | + * @type boolean $hidden_endpoint |
|
225 | + * } |
|
226 | + */ |
|
227 | + public static function get_ee_route_data() |
|
228 | + { |
|
229 | + $ee_routes = array(); |
|
230 | + foreach (self::versions_served() as $version => $hidden_endpoints) { |
|
231 | + $ee_routes[self::ee_api_namespace . $version] = self::_get_ee_route_data_for_version($version, |
|
232 | + $hidden_endpoints); |
|
233 | + } |
|
234 | + return $ee_routes; |
|
235 | + } |
|
236 | + |
|
237 | + |
|
238 | + |
|
239 | + /** |
|
240 | + * Gets the EE route data from the wp options if it exists already, |
|
241 | + * otherwise re-generates it and saves it to the option |
|
242 | + * |
|
243 | + * @param string $version |
|
244 | + * @param boolean $hidden_endpoints |
|
245 | + * @return array |
|
246 | + */ |
|
247 | + protected static function _get_ee_route_data_for_version($version, $hidden_endpoints = false) |
|
248 | + { |
|
249 | + $ee_routes = get_option(self::saved_routes_option_names . $version, null); |
|
250 | + if ( ! $ee_routes || (defined('EE_REST_API_DEBUG_MODE') && EE_REST_API_DEBUG_MODE)) { |
|
251 | + $ee_routes = self::_save_ee_route_data_for_version($version, $hidden_endpoints); |
|
252 | + } |
|
253 | + return $ee_routes; |
|
254 | + } |
|
255 | + |
|
256 | + |
|
257 | + |
|
258 | + /** |
|
259 | + * Saves the EE REST API route data to a wp option and returns it |
|
260 | + * |
|
261 | + * @param string $version |
|
262 | + * @param boolean $hidden_endpoints |
|
263 | + * @return mixed|null|void |
|
264 | + */ |
|
265 | + protected static function _save_ee_route_data_for_version($version, $hidden_endpoints = false) |
|
266 | + { |
|
267 | + $instance = self::instance(); |
|
268 | + $routes = apply_filters( |
|
269 | + 'EED_Core_Rest_Api__save_ee_route_data_for_version__routes', |
|
270 | + array_replace_recursive( |
|
271 | + $instance->_get_config_route_data_for_version($version, $hidden_endpoints), |
|
272 | + $instance->_get_meta_route_data_for_version($version, $hidden_endpoints), |
|
273 | + $instance->_get_model_route_data_for_version($version, $hidden_endpoints), |
|
274 | + $instance->_get_rpc_route_data_for_version($version, $hidden_endpoints) |
|
275 | + ) |
|
276 | + ); |
|
277 | + $option_name = self::saved_routes_option_names . $version; |
|
278 | + if (get_option($option_name)) { |
|
279 | + update_option($option_name, $routes, true); |
|
280 | + } else { |
|
281 | + add_option($option_name, $routes, null, 'no'); |
|
282 | + } |
|
283 | + return $routes; |
|
284 | + } |
|
285 | + |
|
286 | + |
|
287 | + |
|
288 | + /** |
|
289 | + * Calculates all the EE routes and saves it to a wordpress option so we don't |
|
290 | + * need to calculate it on every request |
|
291 | + * |
|
292 | + * @deprecated since version 4.9.1 |
|
293 | + * @return void |
|
294 | + */ |
|
295 | + public static function save_ee_routes() |
|
296 | + { |
|
297 | + if (EE_Maintenance_Mode::instance()->models_can_query()) { |
|
298 | + $instance = self::instance(); |
|
299 | + $routes = apply_filters( |
|
300 | + 'EED_Core_Rest_Api__save_ee_routes__routes', |
|
301 | + array_replace_recursive( |
|
302 | + $instance->_register_config_routes(), |
|
303 | + $instance->_register_meta_routes(), |
|
304 | + $instance->_register_model_routes(), |
|
305 | + $instance->_register_rpc_routes() |
|
306 | + ) |
|
307 | + ); |
|
308 | + update_option(self::saved_routes_option_names, $routes, true); |
|
309 | + } |
|
310 | + } |
|
311 | + |
|
312 | + |
|
313 | + |
|
314 | + /** |
|
315 | + * Gets all the route information relating to EE models |
|
316 | + * |
|
317 | + * @return array @see get_ee_route_data |
|
318 | + * @deprecated since version 4.9.1 |
|
319 | + */ |
|
320 | + protected function _register_model_routes() |
|
321 | + { |
|
322 | + $model_routes = array(); |
|
323 | + foreach (self::versions_served() as $version => $hidden_endpoint) { |
|
324 | + $model_routes[EED_Core_Rest_Api::ee_api_namespace |
|
325 | + . $version] = $this->_get_config_route_data_for_version($version, $hidden_endpoint); |
|
326 | + } |
|
327 | + return $model_routes; |
|
328 | + } |
|
329 | + |
|
330 | + |
|
331 | + |
|
332 | + /** |
|
333 | + * Gets the route data for EE models in the specified version |
|
334 | + * |
|
335 | + * @param string $version |
|
336 | + * @param boolean $hidden_endpoint |
|
337 | + * @return array |
|
338 | + */ |
|
339 | + protected function _get_model_route_data_for_version($version, $hidden_endpoint = false) |
|
340 | + { |
|
341 | + $model_version_info = new Model_Version_Info($version); |
|
342 | + $models_to_register = apply_filters( |
|
343 | + 'FHEE__EED_Core_REST_API___register_model_routes', |
|
344 | + $model_version_info->models_for_requested_version() |
|
345 | + ); |
|
346 | + //let's not bother having endpoints for extra metas |
|
347 | + unset($models_to_register['Extra_Meta']); |
|
348 | + unset($models_to_register['Extra_Join']); |
|
349 | + $model_routes = array(); |
|
350 | + foreach ($models_to_register as $model_name => $model_classname) { |
|
351 | + $model = \EE_Registry::instance()->load_model($model_name); |
|
352 | + |
|
353 | + //if this isn't a valid model then let's skip iterate to the next item in the loop. |
|
354 | + if (! $model instanceof EEM_Base) { |
|
355 | + continue; |
|
356 | + } |
|
357 | + |
|
358 | + //yes we could just register one route for ALL models, but then they wouldn't show up in the index |
|
359 | + $plural_model_route = EEH_Inflector::pluralize_and_lower($model_name); |
|
360 | + $singular_model_route = $plural_model_route . '/(?P<id>\d+)'; |
|
361 | + $model_routes[$plural_model_route] = array( |
|
362 | + array( |
|
363 | + 'callback' => array( |
|
364 | + 'EventEspresso\core\libraries\rest_api\controllers\model\Read', |
|
365 | + 'handle_request_get_all', |
|
366 | + ), |
|
367 | + 'methods' => WP_REST_Server::READABLE, |
|
368 | + 'hidden_endpoint' => $hidden_endpoint, |
|
369 | + 'args' => $this->_get_read_query_params($model, $version), |
|
370 | + '_links' => array( |
|
371 | + 'self' => rest_url(EED_Core_Rest_Api::ee_api_namespace . $version . $singular_model_route), |
|
372 | + ), |
|
373 | + 'schema_callback' => array($model_name, $version) |
|
374 | + ), |
|
375 | + // array( |
|
376 | + // 'callback' => array( |
|
377 | + // 'EventEspresso\core\libraries\rest_api\controllers\model\Write', |
|
378 | + // 'handle_request_create_one' ), |
|
379 | + // 'methods' => WP_REST_Server::CREATABLE, |
|
380 | + // 'hidden_endpoint' => $hidden_endpoint |
|
381 | + // ) |
|
382 | + ); |
|
383 | + $model_routes[$singular_model_route] = array( |
|
384 | + array( |
|
385 | + 'callback' => array( |
|
386 | + 'EventEspresso\core\libraries\rest_api\controllers\model\Read', |
|
387 | + 'handle_request_get_one', |
|
388 | + ), |
|
389 | + 'methods' => WP_REST_Server::READABLE, |
|
390 | + 'hidden_endpoint' => $hidden_endpoint, |
|
391 | + 'args' => $this->_get_response_selection_query_params($model, $version), |
|
392 | + ), |
|
393 | + // array( |
|
394 | + // 'callback' => array( |
|
395 | + // 'EventEspresso\core\libraries\rest_api\controllers\model\Write', |
|
396 | + // 'handle_request_edit_one' ), |
|
397 | + // 'methods' => WP_REST_Server::EDITABLE, |
|
398 | + // 'hidden_endpoint' => $hidden_endpoint |
|
399 | + // ), |
|
400 | + ); |
|
401 | + //@todo: also handle DELETE for a single item |
|
402 | + foreach ($model_version_info->relation_settings($model) as $relation_name => $relation_obj) { |
|
403 | + $related_model_name_endpoint_part = ModelRead::get_related_entity_name( |
|
404 | + $relation_name, |
|
405 | + $relation_obj |
|
406 | + ); |
|
407 | + $model_routes[$singular_model_route . '/' . $related_model_name_endpoint_part] = array( |
|
408 | + array( |
|
409 | + 'callback' => array( |
|
410 | + 'EventEspresso\core\libraries\rest_api\controllers\model\Read', |
|
411 | + 'handle_request_get_related', |
|
412 | + ), |
|
413 | + 'methods' => WP_REST_Server::READABLE, |
|
414 | + 'hidden_endpoint' => $hidden_endpoint, |
|
415 | + 'args' => $this->_get_read_query_params($relation_obj->get_other_model(), $version), |
|
416 | + ), |
|
417 | + // array( |
|
418 | + // 'callback' => array( |
|
419 | + // 'EventEspresso\core\libraries\rest_api\controllers\model\Write', |
|
420 | + // 'handle_request_create_or_update_related' ), |
|
421 | + // 'methods' => WP_REST_Server::EDITABLE, |
|
422 | + // 'hidden_endpoint' => $hidden_endpoint |
|
423 | + // ) |
|
424 | + ); |
|
425 | + //@todo: handle delete related and possibly remove relation (not sure hwo to distinguish) |
|
426 | + } |
|
427 | + } |
|
428 | + return $model_routes; |
|
429 | + } |
|
430 | + |
|
431 | + |
|
432 | + |
|
433 | + /** |
|
434 | + * Adds all the RPC-style routes (remote procedure call-like routes, ie |
|
435 | + * routes that don't conform to the traditional REST CRUD-style). |
|
436 | + * |
|
437 | + * @deprecated since 4.9.1 |
|
438 | + */ |
|
439 | + protected function _register_rpc_routes() |
|
440 | + { |
|
441 | + $routes = array(); |
|
442 | + foreach (self::versions_served() as $version => $hidden_endpoint) { |
|
443 | + $routes[self::ee_api_namespace . $version] = $this->_get_rpc_route_data_for_version($version, |
|
444 | + $hidden_endpoint); |
|
445 | + } |
|
446 | + return $routes; |
|
447 | + } |
|
448 | + |
|
449 | + |
|
450 | + |
|
451 | + /** |
|
452 | + * @param string $version |
|
453 | + * @param boolean $hidden_endpoint |
|
454 | + * @return array |
|
455 | + */ |
|
456 | + protected function _get_rpc_route_data_for_version($version, $hidden_endpoint = false) |
|
457 | + { |
|
458 | + $this_versions_routes = array(); |
|
459 | + //checkin endpoint |
|
460 | + $this_versions_routes['registrations/(?P<REG_ID>\d+)/toggle_checkin_for_datetime/(?P<DTT_ID>\d+)'] = array( |
|
461 | + array( |
|
462 | + 'callback' => array( |
|
463 | + 'EventEspresso\core\libraries\rest_api\controllers\rpc\Checkin', |
|
464 | + 'handle_request_toggle_checkin', |
|
465 | + ), |
|
466 | + 'methods' => WP_REST_Server::CREATABLE, |
|
467 | + 'hidden_endpoint' => $hidden_endpoint, |
|
468 | + 'args' => array( |
|
469 | + 'force' => array( |
|
470 | + 'required' => false, |
|
471 | + 'default' => false, |
|
472 | + 'description' => __('Whether to force toggle checkin, or to verify the registration status and allowed ticket uses', |
|
473 | + 'event_espresso'), |
|
474 | + ), |
|
475 | + ), |
|
476 | + ), |
|
477 | + ); |
|
478 | + return apply_filters( |
|
479 | + 'FHEE__EED_Core_Rest_Api___register_rpc_routes__this_versions_routes', |
|
480 | + $this_versions_routes, |
|
481 | + $version, |
|
482 | + $hidden_endpoint |
|
483 | + ); |
|
484 | + } |
|
485 | + |
|
486 | + |
|
487 | + |
|
488 | + /** |
|
489 | + * Gets the query params that can be used when request one or many |
|
490 | + * |
|
491 | + * @param EEM_Base $model |
|
492 | + * @param string $version |
|
493 | + * @return array |
|
494 | + */ |
|
495 | + protected function _get_response_selection_query_params(\EEM_Base $model, $version) |
|
496 | + { |
|
497 | + return apply_filters( |
|
498 | + 'FHEE__EED_Core_Rest_Api___get_response_selection_query_params', |
|
499 | + array( |
|
500 | + 'include' => array( |
|
501 | + 'required' => false, |
|
502 | + 'default' => '*', |
|
503 | + ), |
|
504 | + 'calculate' => array( |
|
505 | + 'required' => false, |
|
506 | + 'default' => '', |
|
507 | + 'enum' => self::$_field_calculator->retrieve_calculated_fields_for_model($model), |
|
508 | + ), |
|
509 | + ), |
|
510 | + $model, |
|
511 | + $version |
|
512 | + ); |
|
513 | + } |
|
514 | + |
|
515 | + |
|
516 | + |
|
517 | + /** |
|
518 | + * Gets info about reading query params that are acceptable |
|
519 | + * |
|
520 | + * @param \EEM_Base $model eg 'Event' or 'Venue' |
|
521 | + * @param string $version |
|
522 | + * @return array describing the args acceptable when querying this model |
|
523 | + * @throws \EE_Error |
|
524 | + */ |
|
525 | + protected function _get_read_query_params(\EEM_Base $model, $version) |
|
526 | + { |
|
527 | + $default_orderby = array(); |
|
528 | + foreach ($model->get_combined_primary_key_fields() as $key_field) { |
|
529 | + $default_orderby[$key_field->get_name()] = 'ASC'; |
|
530 | + } |
|
531 | + return array_merge( |
|
532 | + $this->_get_response_selection_query_params($model, $version), |
|
533 | + array( |
|
534 | + 'where' => array( |
|
535 | + 'required' => false, |
|
536 | + 'default' => array(), |
|
537 | + ), |
|
538 | + 'limit' => array( |
|
539 | + 'required' => false, |
|
540 | + 'default' => EED_Core_Rest_Api::get_default_query_limit(), |
|
541 | + ), |
|
542 | + 'order_by' => array( |
|
543 | + 'required' => false, |
|
544 | + 'default' => $default_orderby, |
|
545 | + ), |
|
546 | + 'group_by' => array( |
|
547 | + 'required' => false, |
|
548 | + 'default' => null, |
|
549 | + ), |
|
550 | + 'having' => array( |
|
551 | + 'required' => false, |
|
552 | + 'default' => null, |
|
553 | + ), |
|
554 | + 'caps' => array( |
|
555 | + 'required' => false, |
|
556 | + 'default' => EEM_Base::caps_read, |
|
557 | + ), |
|
558 | + ) |
|
559 | + ); |
|
560 | + } |
|
561 | + |
|
562 | + |
|
563 | + |
|
564 | + /** |
|
565 | + * Gets routes for the config |
|
566 | + * |
|
567 | + * @return array @see _register_model_routes |
|
568 | + * @deprecated since version 4.9.1 |
|
569 | + */ |
|
570 | + protected function _register_config_routes() |
|
571 | + { |
|
572 | + $config_routes = array(); |
|
573 | + foreach (self::versions_served() as $version => $hidden_endpoint) { |
|
574 | + $config_routes[self::ee_api_namespace . $version] = $this->_get_config_route_data_for_version($version, |
|
575 | + $hidden_endpoint); |
|
576 | + } |
|
577 | + return $config_routes; |
|
578 | + } |
|
579 | + |
|
580 | + |
|
581 | + |
|
582 | + /** |
|
583 | + * Gets routes for the config for the specified version |
|
584 | + * |
|
585 | + * @param string $version |
|
586 | + * @param boolean $hidden_endpoint |
|
587 | + * @return array |
|
588 | + */ |
|
589 | + protected function _get_config_route_data_for_version($version, $hidden_endpoint) |
|
590 | + { |
|
591 | + return array( |
|
592 | + 'config' => array( |
|
593 | + array( |
|
594 | + 'callback' => array( |
|
595 | + 'EventEspresso\core\libraries\rest_api\controllers\config\Read', |
|
596 | + 'handle_request', |
|
597 | + ), |
|
598 | + 'methods' => WP_REST_Server::READABLE, |
|
599 | + 'hidden_endpoint' => $hidden_endpoint, |
|
600 | + ), |
|
601 | + ), |
|
602 | + 'site_info' => array( |
|
603 | + array( |
|
604 | + 'callback' => array( |
|
605 | + 'EventEspresso\core\libraries\rest_api\controllers\config\Read', |
|
606 | + 'handle_request_site_info', |
|
607 | + ), |
|
608 | + 'methods' => WP_REST_Server::READABLE, |
|
609 | + 'hidden_endpoint' => $hidden_endpoint, |
|
610 | + ), |
|
611 | + ), |
|
612 | + ); |
|
613 | + } |
|
614 | + |
|
615 | + |
|
616 | + |
|
617 | + /** |
|
618 | + * Gets the meta info routes |
|
619 | + * |
|
620 | + * @return array @see _register_model_routes |
|
621 | + * @deprecated since version 4.9.1 |
|
622 | + */ |
|
623 | + protected function _register_meta_routes() |
|
624 | + { |
|
625 | + $meta_routes = array(); |
|
626 | + foreach (self::versions_served() as $version => $hidden_endpoint) { |
|
627 | + $meta_routes[self::ee_api_namespace . $version] = $this->_get_meta_route_data_for_version($version, |
|
628 | + $hidden_endpoint); |
|
629 | + } |
|
630 | + return $meta_routes; |
|
631 | + } |
|
632 | + |
|
633 | + |
|
634 | + |
|
635 | + /** |
|
636 | + * @param string $version |
|
637 | + * @param boolean $hidden_endpoint |
|
638 | + * @return array |
|
639 | + */ |
|
640 | + protected function _get_meta_route_data_for_version($version, $hidden_endpoint = false) |
|
641 | + { |
|
642 | + return array( |
|
643 | + 'resources' => array( |
|
644 | + array( |
|
645 | + 'callback' => array( |
|
646 | + 'EventEspresso\core\libraries\rest_api\controllers\model\Meta', |
|
647 | + 'handle_request_models_meta', |
|
648 | + ), |
|
649 | + 'methods' => WP_REST_Server::READABLE, |
|
650 | + 'hidden_endpoint' => $hidden_endpoint, |
|
651 | + ), |
|
652 | + ), |
|
653 | + ); |
|
654 | + } |
|
655 | + |
|
656 | + |
|
657 | + |
|
658 | + /** |
|
659 | + * Tries to hide old 4.6 endpoints from the |
|
660 | + * |
|
661 | + * @param array $route_data |
|
662 | + * @return array |
|
663 | + */ |
|
664 | + public static function hide_old_endpoints($route_data) |
|
665 | + { |
|
666 | + //allow API clients to override which endpoints get hidden, in case |
|
667 | + //they want to discover particular endpoints |
|
668 | + //also, we don't have access to the request so we have to just grab it from the superglobal |
|
669 | + $force_show_ee_namespace = ltrim( |
|
670 | + EEH_Array::is_set($_REQUEST, 'force_show_ee_namespace', ''), |
|
671 | + '/' |
|
672 | + ); |
|
673 | + foreach (EED_Core_Rest_Api::get_ee_route_data() as $namespace => $relative_urls) { |
|
674 | + foreach ($relative_urls as $endpoint => $routes) { |
|
675 | + foreach ($routes as $route) { |
|
676 | + //by default, hide "hidden_endpoint"s, unless the request indicates |
|
677 | + //to $force_show_ee_namespace, in which case only show that one |
|
678 | + //namespace's endpoints (and hide all others) |
|
679 | + if (($route['hidden_endpoint'] && $force_show_ee_namespace === '') |
|
680 | + || ($force_show_ee_namespace !== '' && $force_show_ee_namespace !== $namespace) |
|
681 | + ) { |
|
682 | + $full_route = '/' . ltrim($namespace, '/') . '/' . ltrim($endpoint, '/'); |
|
683 | + unset($route_data[$full_route]); |
|
684 | + } |
|
685 | + } |
|
686 | + } |
|
687 | + } |
|
688 | + return $route_data; |
|
689 | + } |
|
690 | + |
|
691 | + |
|
692 | + |
|
693 | + /** |
|
694 | + * Returns an array describing which versions of core support serving requests for. |
|
695 | + * Keys are core versions' major and minor version, and values are the |
|
696 | + * LOWEST requested version they can serve. Eg, 4.7 can serve requests for 4.6-like |
|
697 | + * data by just removing a few models and fields from the responses. However, 4.15 might remove |
|
698 | + * the answers table entirely, in which case it would be very difficult for |
|
699 | + * it to serve 4.6-style responses. |
|
700 | + * Versions of core that are missing from this array are unknowns. |
|
701 | + * previous ver |
|
702 | + * |
|
703 | + * @return array |
|
704 | + */ |
|
705 | + public static function version_compatibilities() |
|
706 | + { |
|
707 | + return apply_filters( |
|
708 | + 'FHEE__EED_Core_REST_API__version_compatibilities', |
|
709 | + array( |
|
710 | + '4.8.29' => '4.8.29', |
|
711 | + '4.8.33' => '4.8.29', |
|
712 | + '4.8.34' => '4.8.29', |
|
713 | + '4.8.36' => '4.8.29', |
|
714 | + ) |
|
715 | + ); |
|
716 | + } |
|
717 | + |
|
718 | + |
|
719 | + |
|
720 | + /** |
|
721 | + * Gets the latest API version served. Eg if there |
|
722 | + * are two versions served of the API, 4.8.29 and 4.8.32, and |
|
723 | + * we are on core version 4.8.34, it will return the string "4.8.32" |
|
724 | + * |
|
725 | + * @return string |
|
726 | + */ |
|
727 | + public static function latest_rest_api_version() |
|
728 | + { |
|
729 | + $versions_served = \EED_Core_Rest_Api::versions_served(); |
|
730 | + $versions_served_keys = array_keys($versions_served); |
|
731 | + return end($versions_served_keys); |
|
732 | + } |
|
733 | + |
|
734 | + |
|
735 | + |
|
736 | + /** |
|
737 | + * Using EED_Core_Rest_Api::version_compatibilities(), determines what version of |
|
738 | + * EE the API can serve requests for. Eg, if we are on 4.15 of core, and |
|
739 | + * we can serve requests from 4.12 or later, this will return array( '4.12', '4.13', '4.14', '4.15' ). |
|
740 | + * We also indicate whether or not this version should be put in the index or not |
|
741 | + * |
|
742 | + * @return array keys are API version numbers (just major and minor numbers), and values |
|
743 | + * are whether or not they should be hidden |
|
744 | + */ |
|
745 | + public static function versions_served() |
|
746 | + { |
|
747 | + $versions_served = array(); |
|
748 | + $possibly_served_versions = EED_Core_Rest_Api::version_compatibilities(); |
|
749 | + $lowest_compatible_version = end($possibly_served_versions); |
|
750 | + reset($possibly_served_versions); |
|
751 | + $versions_served_historically = array_keys($possibly_served_versions); |
|
752 | + $latest_version = end($versions_served_historically); |
|
753 | + reset($versions_served_historically); |
|
754 | + //for each version of core we have ever served: |
|
755 | + foreach ($versions_served_historically as $key_versioned_endpoint) { |
|
756 | + //if it's not above the current core version, and it's compatible with the current version of core |
|
757 | + if ($key_versioned_endpoint == $latest_version) { |
|
758 | + //don't hide the latest version in the index |
|
759 | + $versions_served[$key_versioned_endpoint] = false; |
|
760 | + } else if ( |
|
761 | + $key_versioned_endpoint < EED_Core_Rest_Api::core_version() |
|
762 | + && $key_versioned_endpoint >= $lowest_compatible_version |
|
763 | + ) { |
|
764 | + //include, but hide, previous versions which are still supported |
|
765 | + $versions_served[$key_versioned_endpoint] = true; |
|
766 | + } elseif ( |
|
767 | + apply_filters( |
|
768 | + 'FHEE__EED_Core_Rest_Api__versions_served__include_incompatible_versions', |
|
769 | + false, |
|
770 | + $possibly_served_versions |
|
771 | + ) |
|
772 | + ) { |
|
773 | + //if a version is no longer supported, don't include it in index or list of versions served |
|
774 | + $versions_served[$key_versioned_endpoint] = true; |
|
775 | + } |
|
776 | + } |
|
777 | + return $versions_served; |
|
778 | + } |
|
779 | + |
|
780 | + |
|
781 | + |
|
782 | + /** |
|
783 | + * Gets the major and minor version of EE core's version string |
|
784 | + * |
|
785 | + * @return string |
|
786 | + */ |
|
787 | + public static function core_version() |
|
788 | + { |
|
789 | + return apply_filters('FHEE__EED_Core_REST_API__core_version', |
|
790 | + implode('.', array_slice(explode('.', espresso_version()), 0, 3))); |
|
791 | + } |
|
792 | + |
|
793 | + |
|
794 | + |
|
795 | + /** |
|
796 | + * Gets the default limit that should be used when querying for resources |
|
797 | + * |
|
798 | + * @return int |
|
799 | + */ |
|
800 | + public static function get_default_query_limit() |
|
801 | + { |
|
802 | + //we actually don't use a const because we want folks to always use |
|
803 | + //this method, not the const directly |
|
804 | + return apply_filters( |
|
805 | + 'FHEE__EED_Core_Rest_Api__get_default_query_limit', |
|
806 | + 50 |
|
807 | + ); |
|
808 | + } |
|
809 | + |
|
810 | + |
|
811 | + |
|
812 | + /** |
|
813 | + * run - initial module setup |
|
814 | + * |
|
815 | + * @access public |
|
816 | + * @param WP $WP |
|
817 | + * @return void |
|
818 | + */ |
|
819 | + public function run($WP) |
|
820 | + { |
|
821 | + } |
|
822 | 822 | |
823 | 823 | |
824 | 824 |
@@ -172,7 +172,7 @@ discard block |
||
172 | 172 | * Sets quantity |
173 | 173 | * @param int $quantity |
174 | 174 | */ |
175 | - public function set_quantity( $quantity ) { |
|
175 | + public function set_quantity( $quantity ) { |
|
176 | 176 | $this->set( 'LIN_quantity', max( $quantity, 0 ) ); |
177 | 177 | } |
178 | 178 | |
@@ -212,25 +212,25 @@ discard block |
||
212 | 212 | * Gets item_type |
213 | 213 | * @return string |
214 | 214 | */ |
215 | - public function OBJ_type_i18n() { |
|
216 | - $obj_type = $this->OBJ_type(); |
|
217 | - switch ($obj_type) { |
|
218 | - case 'Event': |
|
219 | - $obj_type = __('Event', 'event_espresso'); |
|
220 | - break; |
|
221 | - case 'Price': |
|
222 | - $obj_type = __('Price', 'event_espresso'); |
|
223 | - break; |
|
224 | - case 'Promotion': |
|
225 | - $obj_type = __('Promotion', 'event_espresso'); |
|
226 | - break; |
|
227 | - case 'Ticket': |
|
228 | - $obj_type = __('Ticket', 'event_espresso'); |
|
229 | - break; |
|
230 | - case 'Transaction': |
|
231 | - $obj_type = __('Transaction', 'event_espresso'); |
|
232 | - break; |
|
233 | - } |
|
215 | + public function OBJ_type_i18n() { |
|
216 | + $obj_type = $this->OBJ_type(); |
|
217 | + switch ($obj_type) { |
|
218 | + case 'Event': |
|
219 | + $obj_type = __('Event', 'event_espresso'); |
|
220 | + break; |
|
221 | + case 'Price': |
|
222 | + $obj_type = __('Price', 'event_espresso'); |
|
223 | + break; |
|
224 | + case 'Promotion': |
|
225 | + $obj_type = __('Promotion', 'event_espresso'); |
|
226 | + break; |
|
227 | + case 'Ticket': |
|
228 | + $obj_type = __('Ticket', 'event_espresso'); |
|
229 | + break; |
|
230 | + case 'Transaction': |
|
231 | + $obj_type = __('Transaction', 'event_espresso'); |
|
232 | + break; |
|
233 | + } |
|
234 | 234 | return apply_filters('FHEE__EE_Line_Item__OBJ_type_i18n', $obj_type, $this); |
235 | 235 | } |
236 | 236 | |
@@ -1244,48 +1244,48 @@ discard block |
||
1244 | 1244 | |
1245 | 1245 | |
1246 | 1246 | |
1247 | - /** |
|
1248 | - * @param bool $raw |
|
1249 | - * @return int |
|
1250 | - * @throws \EE_Error |
|
1251 | - */ |
|
1252 | - public function timestamp($raw = false) |
|
1253 | - { |
|
1254 | - return $raw ? $this->get_raw('LIN_timestamp') : $this->get('LIN_timestamp'); |
|
1255 | - } |
|
1247 | + /** |
|
1248 | + * @param bool $raw |
|
1249 | + * @return int |
|
1250 | + * @throws \EE_Error |
|
1251 | + */ |
|
1252 | + public function timestamp($raw = false) |
|
1253 | + { |
|
1254 | + return $raw ? $this->get_raw('LIN_timestamp') : $this->get('LIN_timestamp'); |
|
1255 | + } |
|
1256 | 1256 | |
1257 | 1257 | |
1258 | 1258 | |
1259 | 1259 | |
1260 | - /************************* DEPRECATED *************************/ |
|
1260 | + /************************* DEPRECATED *************************/ |
|
1261 | 1261 | |
1262 | 1262 | |
1263 | 1263 | |
1264 | - /** |
|
1265 | - * @deprecated |
|
1266 | - * @param string $type one of the constants on EEM_Line_Item |
|
1267 | - * @return EE_Line_Item[] |
|
1268 | - */ |
|
1269 | - protected function _get_descendants_of_type($type) |
|
1270 | - { |
|
1271 | - EE_Error::doing_it_wrong('EE_Line_Item::_get_descendants_of_type()', |
|
1272 | - __('Method replaced with EEH_Line_Item::get_descendants_of_type()', 'event_espresso'), '4.6.0'); |
|
1273 | - return EEH_Line_Item::get_descendants_of_type($this, $type); |
|
1274 | - } |
|
1264 | + /** |
|
1265 | + * @deprecated |
|
1266 | + * @param string $type one of the constants on EEM_Line_Item |
|
1267 | + * @return EE_Line_Item[] |
|
1268 | + */ |
|
1269 | + protected function _get_descendants_of_type($type) |
|
1270 | + { |
|
1271 | + EE_Error::doing_it_wrong('EE_Line_Item::_get_descendants_of_type()', |
|
1272 | + __('Method replaced with EEH_Line_Item::get_descendants_of_type()', 'event_espresso'), '4.6.0'); |
|
1273 | + return EEH_Line_Item::get_descendants_of_type($this, $type); |
|
1274 | + } |
|
1275 | 1275 | |
1276 | 1276 | |
1277 | 1277 | |
1278 | - /** |
|
1279 | - * @deprecated |
|
1280 | - * @param string $type like one of the EEM_Line_Item::type_* |
|
1281 | - * @return EE_Line_Item |
|
1282 | - */ |
|
1283 | - public function get_nearest_descendant_of_type($type) |
|
1284 | - { |
|
1285 | - EE_Error::doing_it_wrong('EE_Line_Item::get_nearest_descendant_of_type()', |
|
1286 | - __('Method replaced with EEH_Line_Item::get_nearest_descendant_of_type()', 'event_espresso'), '4.6.0'); |
|
1287 | - return EEH_Line_Item::get_nearest_descendant_of_type($this, $type); |
|
1288 | - } |
|
1278 | + /** |
|
1279 | + * @deprecated |
|
1280 | + * @param string $type like one of the EEM_Line_Item::type_* |
|
1281 | + * @return EE_Line_Item |
|
1282 | + */ |
|
1283 | + public function get_nearest_descendant_of_type($type) |
|
1284 | + { |
|
1285 | + EE_Error::doing_it_wrong('EE_Line_Item::get_nearest_descendant_of_type()', |
|
1286 | + __('Method replaced with EEH_Line_Item::get_nearest_descendant_of_type()', 'event_espresso'), '4.6.0'); |
|
1287 | + return EEH_Line_Item::get_nearest_descendant_of_type($this, $type); |
|
1288 | + } |
|
1289 | 1289 | |
1290 | 1290 | |
1291 | 1291 |
@@ -1,5 +1,5 @@ discard block |
||
1 | -<?php if ( !defined( 'EVENT_ESPRESSO_VERSION' ) ) { |
|
2 | - exit( 'No direct script access allowed' ); |
|
1 | +<?php if ( ! defined('EVENT_ESPRESSO_VERSION')) { |
|
2 | + exit('No direct script access allowed'); |
|
3 | 3 | } |
4 | 4 | /** |
5 | 5 | * Event Espresso |
@@ -50,9 +50,9 @@ discard block |
||
50 | 50 | * date_format and the second value is the time format |
51 | 51 | * @return EE_Line_Item |
52 | 52 | */ |
53 | - public static function new_instance( $props_n_values = array(), $timezone = null, $date_formats = array() ) { |
|
54 | - $has_object = parent::_check_for_object( $props_n_values, __CLASS__, $timezone, $date_formats ); |
|
55 | - return $has_object ? $has_object : new self( $props_n_values, false, $timezone, $date_formats ); |
|
53 | + public static function new_instance($props_n_values = array(), $timezone = null, $date_formats = array()) { |
|
54 | + $has_object = parent::_check_for_object($props_n_values, __CLASS__, $timezone, $date_formats); |
|
55 | + return $has_object ? $has_object : new self($props_n_values, false, $timezone, $date_formats); |
|
56 | 56 | } |
57 | 57 | |
58 | 58 | |
@@ -63,8 +63,8 @@ discard block |
||
63 | 63 | * the website will be used. |
64 | 64 | * @return EE_Line_Item |
65 | 65 | */ |
66 | - public static function new_instance_from_db( $props_n_values = array(), $timezone = null ) { |
|
67 | - return new self( $props_n_values, TRUE, $timezone ); |
|
66 | + public static function new_instance_from_db($props_n_values = array(), $timezone = null) { |
|
67 | + return new self($props_n_values, TRUE, $timezone); |
|
68 | 68 | } |
69 | 69 | |
70 | 70 | |
@@ -75,10 +75,10 @@ discard block |
||
75 | 75 | * @param bool $bydb |
76 | 76 | * @param string $timezone |
77 | 77 | */ |
78 | - protected function __construct( $fieldValues = array(), $bydb = FALSE, $timezone = '' ) { |
|
79 | - parent::__construct( $fieldValues, $bydb, $timezone ); |
|
80 | - if ( ! $this->get( 'LIN_code' ) ) { |
|
81 | - $this->set_code( $this->generate_code() ); |
|
78 | + protected function __construct($fieldValues = array(), $bydb = FALSE, $timezone = '') { |
|
79 | + parent::__construct($fieldValues, $bydb, $timezone); |
|
80 | + if ( ! $this->get('LIN_code')) { |
|
81 | + $this->set_code($this->generate_code()); |
|
82 | 82 | } |
83 | 83 | } |
84 | 84 | |
@@ -89,7 +89,7 @@ discard block |
||
89 | 89 | * @return int |
90 | 90 | */ |
91 | 91 | public function ID() { |
92 | - return $this->get( 'LIN_ID' ); |
|
92 | + return $this->get('LIN_ID'); |
|
93 | 93 | } |
94 | 94 | |
95 | 95 | |
@@ -99,7 +99,7 @@ discard block |
||
99 | 99 | * @return int |
100 | 100 | */ |
101 | 101 | public function TXN_ID() { |
102 | - return $this->get( 'TXN_ID' ); |
|
102 | + return $this->get('TXN_ID'); |
|
103 | 103 | } |
104 | 104 | |
105 | 105 | |
@@ -108,8 +108,8 @@ discard block |
||
108 | 108 | * Sets TXN_ID |
109 | 109 | * @param int $TXN_ID |
110 | 110 | */ |
111 | - public function set_TXN_ID( $TXN_ID ) { |
|
112 | - $this->set( 'TXN_ID', $TXN_ID ); |
|
111 | + public function set_TXN_ID($TXN_ID) { |
|
112 | + $this->set('TXN_ID', $TXN_ID); |
|
113 | 113 | } |
114 | 114 | |
115 | 115 | |
@@ -119,9 +119,9 @@ discard block |
||
119 | 119 | * @return string |
120 | 120 | */ |
121 | 121 | public function name() { |
122 | - $name = $this->get( 'LIN_name' ); |
|
123 | - if( ! $name ){ |
|
124 | - $name = ucwords( str_replace( '-', ' ', $this->type() ) ); |
|
122 | + $name = $this->get('LIN_name'); |
|
123 | + if ( ! $name) { |
|
124 | + $name = ucwords(str_replace('-', ' ', $this->type())); |
|
125 | 125 | } |
126 | 126 | return $name; |
127 | 127 | } |
@@ -132,8 +132,8 @@ discard block |
||
132 | 132 | * Sets name |
133 | 133 | * @param string $name |
134 | 134 | */ |
135 | - public function set_name( $name ) { |
|
136 | - $this->set( 'LIN_name', $name ); |
|
135 | + public function set_name($name) { |
|
136 | + $this->set('LIN_name', $name); |
|
137 | 137 | } |
138 | 138 | |
139 | 139 | |
@@ -143,7 +143,7 @@ discard block |
||
143 | 143 | * @return string |
144 | 144 | */ |
145 | 145 | public function desc() { |
146 | - return $this->get( 'LIN_desc' ); |
|
146 | + return $this->get('LIN_desc'); |
|
147 | 147 | } |
148 | 148 | |
149 | 149 | |
@@ -152,8 +152,8 @@ discard block |
||
152 | 152 | * Sets desc |
153 | 153 | * @param string $desc |
154 | 154 | */ |
155 | - public function set_desc( $desc ) { |
|
156 | - $this->set( 'LIN_desc', $desc ); |
|
155 | + public function set_desc($desc) { |
|
156 | + $this->set('LIN_desc', $desc); |
|
157 | 157 | } |
158 | 158 | |
159 | 159 | |
@@ -163,7 +163,7 @@ discard block |
||
163 | 163 | * @return int |
164 | 164 | */ |
165 | 165 | public function quantity() { |
166 | - return $this->get( 'LIN_quantity' ); |
|
166 | + return $this->get('LIN_quantity'); |
|
167 | 167 | } |
168 | 168 | |
169 | 169 | |
@@ -172,8 +172,8 @@ discard block |
||
172 | 172 | * Sets quantity |
173 | 173 | * @param int $quantity |
174 | 174 | */ |
175 | - public function set_quantity( $quantity ) { |
|
176 | - $this->set( 'LIN_quantity', max( $quantity, 0 ) ); |
|
175 | + public function set_quantity($quantity) { |
|
176 | + $this->set('LIN_quantity', max($quantity, 0)); |
|
177 | 177 | } |
178 | 178 | |
179 | 179 | |
@@ -183,7 +183,7 @@ discard block |
||
183 | 183 | * @return string |
184 | 184 | */ |
185 | 185 | public function OBJ_ID() { |
186 | - return $this->get( 'OBJ_ID' ); |
|
186 | + return $this->get('OBJ_ID'); |
|
187 | 187 | } |
188 | 188 | |
189 | 189 | |
@@ -192,8 +192,8 @@ discard block |
||
192 | 192 | * Sets item_id |
193 | 193 | * @param string $item_id |
194 | 194 | */ |
195 | - public function set_OBJ_ID( $item_id ) { |
|
196 | - $this->set( 'OBJ_ID', $item_id ); |
|
195 | + public function set_OBJ_ID($item_id) { |
|
196 | + $this->set('OBJ_ID', $item_id); |
|
197 | 197 | } |
198 | 198 | |
199 | 199 | |
@@ -203,7 +203,7 @@ discard block |
||
203 | 203 | * @return string |
204 | 204 | */ |
205 | 205 | public function OBJ_type() { |
206 | - return $this->get( 'OBJ_type' ); |
|
206 | + return $this->get('OBJ_type'); |
|
207 | 207 | } |
208 | 208 | |
209 | 209 | |
@@ -240,8 +240,8 @@ discard block |
||
240 | 240 | * Sets item_type |
241 | 241 | * @param string $OBJ_type |
242 | 242 | */ |
243 | - public function set_OBJ_type( $OBJ_type ) { |
|
244 | - $this->set( 'OBJ_type', $OBJ_type ); |
|
243 | + public function set_OBJ_type($OBJ_type) { |
|
244 | + $this->set('OBJ_type', $OBJ_type); |
|
245 | 245 | } |
246 | 246 | |
247 | 247 | |
@@ -251,7 +251,7 @@ discard block |
||
251 | 251 | * @return float |
252 | 252 | */ |
253 | 253 | public function unit_price() { |
254 | - return $this->get( 'LIN_unit_price' ); |
|
254 | + return $this->get('LIN_unit_price'); |
|
255 | 255 | } |
256 | 256 | |
257 | 257 | |
@@ -261,8 +261,8 @@ discard block |
||
261 | 261 | * |
262 | 262 | * @param float $unit_price |
263 | 263 | */ |
264 | - public function set_unit_price( $unit_price ) { |
|
265 | - $this->set( 'LIN_unit_price', $unit_price ); |
|
264 | + public function set_unit_price($unit_price) { |
|
265 | + $this->set('LIN_unit_price', $unit_price); |
|
266 | 266 | } |
267 | 267 | |
268 | 268 | |
@@ -273,19 +273,19 @@ discard block |
||
273 | 273 | * @return boolean |
274 | 274 | */ |
275 | 275 | public function is_percent() { |
276 | - if( $this->is_tax_sub_total() ) { |
|
276 | + if ($this->is_tax_sub_total()) { |
|
277 | 277 | //tax subtotals HAVE a percent on them, that percentage only applies |
278 | 278 | //to taxable items, so its' an exception. Treat it like a flat line item |
279 | 279 | return false; |
280 | 280 | } |
281 | - $unit_price = abs( $this->get( 'LIN_unit_price' ) ); |
|
282 | - $percent = abs( $this->get( 'LIN_percent' ) ); |
|
283 | - if ( $unit_price < .001 && $percent ) { |
|
281 | + $unit_price = abs($this->get('LIN_unit_price')); |
|
282 | + $percent = abs($this->get('LIN_percent')); |
|
283 | + if ($unit_price < .001 && $percent) { |
|
284 | 284 | return TRUE; |
285 | - } elseif ( $unit_price >= .001 && !$percent ) { |
|
285 | + } elseif ($unit_price >= .001 && ! $percent) { |
|
286 | 286 | return FALSE; |
287 | - } elseif ( $unit_price >= .001 && $percent ) { |
|
288 | - throw new EE_Error( sprintf( __( "A Line Item can not have a unit price of (%s) AND a percent (%s)!", "event_espresso" ), $unit_price, $percent ) ); |
|
287 | + } elseif ($unit_price >= .001 && $percent) { |
|
288 | + throw new EE_Error(sprintf(__("A Line Item can not have a unit price of (%s) AND a percent (%s)!", "event_espresso"), $unit_price, $percent)); |
|
289 | 289 | } else { |
290 | 290 | // if they're both 0, assume its not a percent item |
291 | 291 | return FALSE; |
@@ -299,7 +299,7 @@ discard block |
||
299 | 299 | * @return float |
300 | 300 | */ |
301 | 301 | public function percent() { |
302 | - return $this->get( 'LIN_percent' ); |
|
302 | + return $this->get('LIN_percent'); |
|
303 | 303 | } |
304 | 304 | |
305 | 305 | |
@@ -308,8 +308,8 @@ discard block |
||
308 | 308 | * Sets percent (between 100-0.01) |
309 | 309 | * @param float $percent |
310 | 310 | */ |
311 | - public function set_percent( $percent ) { |
|
312 | - $this->set( 'LIN_percent', $percent ); |
|
311 | + public function set_percent($percent) { |
|
312 | + $this->set('LIN_percent', $percent); |
|
313 | 313 | } |
314 | 314 | |
315 | 315 | |
@@ -319,7 +319,7 @@ discard block |
||
319 | 319 | * @return float |
320 | 320 | */ |
321 | 321 | public function total() { |
322 | - return $this->get( 'LIN_total' ); |
|
322 | + return $this->get('LIN_total'); |
|
323 | 323 | } |
324 | 324 | |
325 | 325 | |
@@ -328,8 +328,8 @@ discard block |
||
328 | 328 | * Sets total |
329 | 329 | * @param float $total |
330 | 330 | */ |
331 | - public function set_total( $total ) { |
|
332 | - $this->set( 'LIN_total', $total ); |
|
331 | + public function set_total($total) { |
|
332 | + $this->set('LIN_total', $total); |
|
333 | 333 | } |
334 | 334 | |
335 | 335 | |
@@ -339,7 +339,7 @@ discard block |
||
339 | 339 | * @return int |
340 | 340 | */ |
341 | 341 | public function order() { |
342 | - return $this->get( 'LIN_order' ); |
|
342 | + return $this->get('LIN_order'); |
|
343 | 343 | } |
344 | 344 | |
345 | 345 | |
@@ -348,8 +348,8 @@ discard block |
||
348 | 348 | * Sets order |
349 | 349 | * @param int $order |
350 | 350 | */ |
351 | - public function set_order( $order ) { |
|
352 | - $this->set( 'LIN_order', $order ); |
|
351 | + public function set_order($order) { |
|
352 | + $this->set('LIN_order', $order); |
|
353 | 353 | } |
354 | 354 | |
355 | 355 | |
@@ -359,7 +359,7 @@ discard block |
||
359 | 359 | * @return int |
360 | 360 | */ |
361 | 361 | public function parent_ID() { |
362 | - return $this->get( 'LIN_parent' ); |
|
362 | + return $this->get('LIN_parent'); |
|
363 | 363 | } |
364 | 364 | |
365 | 365 | |
@@ -368,8 +368,8 @@ discard block |
||
368 | 368 | * Sets parent |
369 | 369 | * @param int $parent |
370 | 370 | */ |
371 | - public function set_parent_ID( $parent ) { |
|
372 | - $this->set( 'LIN_parent', $parent ); |
|
371 | + public function set_parent_ID($parent) { |
|
372 | + $this->set('LIN_parent', $parent); |
|
373 | 373 | } |
374 | 374 | |
375 | 375 | |
@@ -379,7 +379,7 @@ discard block |
||
379 | 379 | * @return string |
380 | 380 | */ |
381 | 381 | public function type() { |
382 | - return $this->get( 'LIN_type' ); |
|
382 | + return $this->get('LIN_type'); |
|
383 | 383 | } |
384 | 384 | |
385 | 385 | |
@@ -388,8 +388,8 @@ discard block |
||
388 | 388 | * Sets type |
389 | 389 | * @param string $type |
390 | 390 | */ |
391 | - public function set_type( $type ) { |
|
392 | - $this->set( 'LIN_type', $type ); |
|
391 | + public function set_type($type) { |
|
392 | + $this->set('LIN_type', $type); |
|
393 | 393 | } |
394 | 394 | |
395 | 395 | |
@@ -402,8 +402,8 @@ discard block |
||
402 | 402 | * @return EE_Line_Item |
403 | 403 | */ |
404 | 404 | public function parent() { |
405 | - if( $this->ID() ) { |
|
406 | - return $this->get_model()->get_one_by_ID( $this->parent_ID() ); |
|
405 | + if ($this->ID()) { |
|
406 | + return $this->get_model()->get_one_by_ID($this->parent_ID()); |
|
407 | 407 | } else { |
408 | 408 | return $this->_parent; |
409 | 409 | } |
@@ -416,13 +416,13 @@ discard block |
||
416 | 416 | * @return EE_Line_Item[] |
417 | 417 | */ |
418 | 418 | public function children() { |
419 | - if ( $this->ID() ) { |
|
419 | + if ($this->ID()) { |
|
420 | 420 | return $this->get_model()->get_all( |
421 | 421 | array( |
422 | - array( 'LIN_parent' => $this->ID() ), |
|
423 | - 'order_by' => array( 'LIN_order' => 'ASC' ) ) ); |
|
422 | + array('LIN_parent' => $this->ID()), |
|
423 | + 'order_by' => array('LIN_order' => 'ASC') ) ); |
|
424 | 424 | } else { |
425 | - if ( ! is_array( $this->_children ) ) { |
|
425 | + if ( ! is_array($this->_children)) { |
|
426 | 426 | $this->_children = array(); |
427 | 427 | } |
428 | 428 | return $this->_children; |
@@ -436,7 +436,7 @@ discard block |
||
436 | 436 | * @return string |
437 | 437 | */ |
438 | 438 | public function code() { |
439 | - return $this->get( 'LIN_code' ); |
|
439 | + return $this->get('LIN_code'); |
|
440 | 440 | } |
441 | 441 | |
442 | 442 | |
@@ -445,8 +445,8 @@ discard block |
||
445 | 445 | * Sets code |
446 | 446 | * @param string $code |
447 | 447 | */ |
448 | - public function set_code( $code ) { |
|
449 | - $this->set( 'LIN_code', $code ); |
|
448 | + public function set_code($code) { |
|
449 | + $this->set('LIN_code', $code); |
|
450 | 450 | } |
451 | 451 | |
452 | 452 | |
@@ -456,7 +456,7 @@ discard block |
||
456 | 456 | * @return boolean |
457 | 457 | */ |
458 | 458 | public function is_taxable() { |
459 | - return $this->get( 'LIN_is_taxable' ); |
|
459 | + return $this->get('LIN_is_taxable'); |
|
460 | 460 | } |
461 | 461 | |
462 | 462 | |
@@ -465,8 +465,8 @@ discard block |
||
465 | 465 | * Sets is_taxable |
466 | 466 | * @param boolean $is_taxable |
467 | 467 | */ |
468 | - public function set_is_taxable( $is_taxable ) { |
|
469 | - $this->set( 'LIN_is_taxable', $is_taxable ); |
|
468 | + public function set_is_taxable($is_taxable) { |
|
469 | + $this->set('LIN_is_taxable', $is_taxable); |
|
470 | 470 | } |
471 | 471 | |
472 | 472 | |
@@ -481,7 +481,7 @@ discard block |
||
481 | 481 | */ |
482 | 482 | public function get_object() { |
483 | 483 | $model_name_of_related_obj = $this->OBJ_type(); |
484 | - return $this->get_model()->has_relation( $model_name_of_related_obj ) ? $this->get_first_related( $model_name_of_related_obj ) : NULL; |
|
484 | + return $this->get_model()->has_relation($model_name_of_related_obj) ? $this->get_first_related($model_name_of_related_obj) : NULL; |
|
485 | 485 | } |
486 | 486 | |
487 | 487 | |
@@ -492,11 +492,11 @@ discard block |
||
492 | 492 | * @param array $query_params |
493 | 493 | * @return EE_Ticket |
494 | 494 | */ |
495 | - public function ticket( $query_params = array() ) { |
|
495 | + public function ticket($query_params = array()) { |
|
496 | 496 | //we're going to assume that when this method is called we always want to receive the attached ticket EVEN if that ticket is archived. This can be overridden via the incoming $query_params argument |
497 | - $remove_defaults = array( 'default_where_conditions' => 'none' ); |
|
498 | - $query_params = array_merge( $remove_defaults, $query_params ); |
|
499 | - return $this->get_first_related( 'Ticket', $query_params ); |
|
497 | + $remove_defaults = array('default_where_conditions' => 'none'); |
|
498 | + $query_params = array_merge($remove_defaults, $query_params); |
|
499 | + return $this->get_first_related('Ticket', $query_params); |
|
500 | 500 | } |
501 | 501 | |
502 | 502 | |
@@ -506,11 +506,11 @@ discard block |
||
506 | 506 | * @return EE_Datetime | NULL |
507 | 507 | */ |
508 | 508 | public function get_ticket_datetime() { |
509 | - if ( $this->OBJ_type() === 'Ticket' ) { |
|
509 | + if ($this->OBJ_type() === 'Ticket') { |
|
510 | 510 | $ticket = $this->ticket(); |
511 | - if ( $ticket instanceof EE_Ticket ) { |
|
511 | + if ($ticket instanceof EE_Ticket) { |
|
512 | 512 | $datetime = $ticket->first_datetime(); |
513 | - if ( $datetime instanceof EE_Datetime ) { |
|
513 | + if ($datetime instanceof EE_Datetime) { |
|
514 | 514 | return $datetime; |
515 | 515 | } |
516 | 516 | } |
@@ -526,9 +526,9 @@ discard block |
||
526 | 526 | * @return string |
527 | 527 | */ |
528 | 528 | public function ticket_event_name() { |
529 | - $event_name = __( "Unknown", "event_espresso" ); |
|
529 | + $event_name = __("Unknown", "event_espresso"); |
|
530 | 530 | $event = $this->ticket_event(); |
531 | - if ( $event instanceof EE_Event ) { |
|
531 | + if ($event instanceof EE_Event) { |
|
532 | 532 | $event_name = $event->name(); |
533 | 533 | } |
534 | 534 | return $event_name; |
@@ -542,9 +542,9 @@ discard block |
||
542 | 542 | public function ticket_event() { |
543 | 543 | $event = null; |
544 | 544 | $ticket = $this->ticket(); |
545 | - if ( $ticket instanceof EE_Ticket ) { |
|
545 | + if ($ticket instanceof EE_Ticket) { |
|
546 | 546 | $datetime = $ticket->first_datetime(); |
547 | - if ( $datetime instanceof EE_Datetime ) { |
|
547 | + if ($datetime instanceof EE_Datetime) { |
|
548 | 548 | $event = $datetime->event(); |
549 | 549 | } |
550 | 550 | } |
@@ -559,11 +559,11 @@ discard block |
||
559 | 559 | * @param string $time_format |
560 | 560 | * @return string |
561 | 561 | */ |
562 | - public function ticket_datetime_start( $date_format = '', $time_format = '' ) { |
|
563 | - $first_datetime_string = __( "Unknown", "event_espresso" ); |
|
562 | + public function ticket_datetime_start($date_format = '', $time_format = '') { |
|
563 | + $first_datetime_string = __("Unknown", "event_espresso"); |
|
564 | 564 | $datetime = $this->get_ticket_datetime(); |
565 | - if ( $datetime ) { |
|
566 | - $first_datetime_string = $datetime->start_date_and_time( $date_format, $time_format ); |
|
565 | + if ($datetime) { |
|
566 | + $first_datetime_string = $datetime->start_date_and_time($date_format, $time_format); |
|
567 | 567 | } |
568 | 568 | return $first_datetime_string; |
569 | 569 | } |
@@ -578,26 +578,26 @@ discard block |
||
578 | 578 | * @return bool success |
579 | 579 | * @throws \EE_Error |
580 | 580 | */ |
581 | - public function add_child_line_item( EEI_Line_Item $line_item, $set_order = true ) { |
|
581 | + public function add_child_line_item(EEI_Line_Item $line_item, $set_order = true) { |
|
582 | 582 | // should we calculate the LIN_order for this line item ? |
583 | - if ( $set_order || $line_item->order() === null ) { |
|
584 | - $line_item->set_order( count( $this->children() ) ); |
|
583 | + if ($set_order || $line_item->order() === null) { |
|
584 | + $line_item->set_order(count($this->children())); |
|
585 | 585 | } |
586 | - if ( $this->ID() ) { |
|
586 | + if ($this->ID()) { |
|
587 | 587 | //check for any duplicate line items (with the same code), if so, this replaces it |
588 | - $line_item_with_same_code = $this->get_child_line_item( $line_item->code() ); |
|
589 | - if( $line_item_with_same_code instanceof EE_Line_Item && $line_item_with_same_code !== $line_item ) { |
|
590 | - $this->delete_child_line_item( $line_item_with_same_code->code() ); |
|
588 | + $line_item_with_same_code = $this->get_child_line_item($line_item->code()); |
|
589 | + if ($line_item_with_same_code instanceof EE_Line_Item && $line_item_with_same_code !== $line_item) { |
|
590 | + $this->delete_child_line_item($line_item_with_same_code->code()); |
|
591 | 591 | } |
592 | - $line_item->set_parent_ID( $this->ID() ); |
|
593 | - if( $this->TXN_ID() ){ |
|
594 | - $line_item->set_TXN_ID( $this->TXN_ID() ); |
|
592 | + $line_item->set_parent_ID($this->ID()); |
|
593 | + if ($this->TXN_ID()) { |
|
594 | + $line_item->set_TXN_ID($this->TXN_ID()); |
|
595 | 595 | } |
596 | 596 | return $line_item->save(); |
597 | 597 | } else { |
598 | - $this->_children[ $line_item->code() ] = $line_item; |
|
599 | - if( $line_item->parent() != $this ) { |
|
600 | - $line_item->set_parent( $this ); |
|
598 | + $this->_children[$line_item->code()] = $line_item; |
|
599 | + if ($line_item->parent() != $this) { |
|
600 | + $line_item->set_parent($this); |
|
601 | 601 | } |
602 | 602 | return TRUE; |
603 | 603 | } |
@@ -611,16 +611,16 @@ discard block |
||
611 | 611 | * @param EE_Line_Item $line_item |
612 | 612 | * |
613 | 613 | */ |
614 | - public function set_parent( $line_item ) { |
|
615 | - if ( $this->ID() ) { |
|
616 | - if( ! $line_item->ID() ) { |
|
614 | + public function set_parent($line_item) { |
|
615 | + if ($this->ID()) { |
|
616 | + if ( ! $line_item->ID()) { |
|
617 | 617 | $line_item->save(); |
618 | 618 | } |
619 | - $this->set_parent_ID( $line_item->ID() ); |
|
619 | + $this->set_parent_ID($line_item->ID()); |
|
620 | 620 | $this->save(); |
621 | 621 | } else { |
622 | 622 | $this->_parent = $line_item; |
623 | - $this->set_parent_ID( $line_item->ID() ); |
|
623 | + $this->set_parent_ID($line_item->ID()); |
|
624 | 624 | } |
625 | 625 | } |
626 | 626 | |
@@ -633,11 +633,11 @@ discard block |
||
633 | 633 | * @param string $code |
634 | 634 | * @return EE_Line_Item |
635 | 635 | */ |
636 | - public function get_child_line_item( $code ) { |
|
637 | - if ( $this->ID() ) { |
|
638 | - return $this->get_model()->get_one( array( array( 'LIN_parent' => $this->ID(), 'LIN_code' => $code ) ) ); |
|
636 | + public function get_child_line_item($code) { |
|
637 | + if ($this->ID()) { |
|
638 | + return $this->get_model()->get_one(array(array('LIN_parent' => $this->ID(), 'LIN_code' => $code))); |
|
639 | 639 | } else { |
640 | - return isset( $this->_children[ $code ] ) ? $this->_children[ $code ] : null; |
|
640 | + return isset($this->_children[$code]) ? $this->_children[$code] : null; |
|
641 | 641 | } |
642 | 642 | } |
643 | 643 | |
@@ -648,10 +648,10 @@ discard block |
||
648 | 648 | * @return int |
649 | 649 | */ |
650 | 650 | public function delete_children_line_items() { |
651 | - if ( $this->ID() ) { |
|
652 | - return $this->get_model()->delete( array( array( 'LIN_parent' => $this->ID() ) ) ); |
|
651 | + if ($this->ID()) { |
|
652 | + return $this->get_model()->delete(array(array('LIN_parent' => $this->ID()))); |
|
653 | 653 | } else { |
654 | - $count = count( $this->_children ); |
|
654 | + $count = count($this->_children); |
|
655 | 655 | $this->_children = array(); |
656 | 656 | return $count; |
657 | 657 | } |
@@ -668,25 +668,25 @@ discard block |
||
668 | 668 | * @param bool $stop_search_once_found |
669 | 669 | * @return int count of items deleted (or simply removed from the line item's cache, if not has not been saved to the DB yet) |
670 | 670 | */ |
671 | - public function delete_child_line_item( $code, $stop_search_once_found = true ) { |
|
672 | - if ( $this->ID() ) { |
|
671 | + public function delete_child_line_item($code, $stop_search_once_found = true) { |
|
672 | + if ($this->ID()) { |
|
673 | 673 | $items_deleted = 0; |
674 | - if( $this->code() == $code ) { |
|
675 | - $items_deleted += EEH_Line_Item::delete_all_child_items( $this ); |
|
674 | + if ($this->code() == $code) { |
|
675 | + $items_deleted += EEH_Line_Item::delete_all_child_items($this); |
|
676 | 676 | $items_deleted += (int) $this->delete(); |
677 | - if( $stop_search_once_found ){ |
|
677 | + if ($stop_search_once_found) { |
|
678 | 678 | return $items_deleted; |
679 | 679 | } |
680 | 680 | } |
681 | - foreach( $this->children() as $child_line_item ) { |
|
682 | - $items_deleted += $child_line_item->delete_child_line_item( $code, $stop_search_once_found ); |
|
681 | + foreach ($this->children() as $child_line_item) { |
|
682 | + $items_deleted += $child_line_item->delete_child_line_item($code, $stop_search_once_found); |
|
683 | 683 | } |
684 | 684 | return $items_deleted; |
685 | 685 | } else { |
686 | - if( isset( $this->_children[ $code ] ) ) { |
|
687 | - unset( $this->_children[ $code ] ); |
|
686 | + if (isset($this->_children[$code])) { |
|
687 | + unset($this->_children[$code]); |
|
688 | 688 | return 1; |
689 | - }else{ |
|
689 | + } else { |
|
690 | 690 | return 0; |
691 | 691 | } |
692 | 692 | } |
@@ -699,9 +699,9 @@ discard block |
||
699 | 699 | * @return boolean |
700 | 700 | */ |
701 | 701 | public function delete_if_childless_subtotal() { |
702 | - if( $this->ID() && |
|
702 | + if ($this->ID() && |
|
703 | 703 | $this->type() == EEM_Line_Item::type_sub_total && |
704 | - ! $this->children() ) { |
|
704 | + ! $this->children()) { |
|
705 | 705 | return $this->delete(); |
706 | 706 | } else { |
707 | 707 | return false; |
@@ -716,7 +716,7 @@ discard block |
||
716 | 716 | */ |
717 | 717 | public function generate_code() { |
718 | 718 | // each line item in the cart requires a unique identifier |
719 | - return md5( $this->get( 'OBJ_type' ) . $this->get( 'OBJ_ID' ) . microtime() ); |
|
719 | + return md5($this->get('OBJ_type').$this->get('OBJ_ID').microtime()); |
|
720 | 720 | } |
721 | 721 | |
722 | 722 | |
@@ -799,7 +799,7 @@ discard block |
||
799 | 799 | * @return string like '2, 004.00', formatted according to the localized currency |
800 | 800 | */ |
801 | 801 | public function unit_price_no_code() { |
802 | - return $this->get_pretty( 'LIN_unit_price', 'no_currency_code' ); |
|
802 | + return $this->get_pretty('LIN_unit_price', 'no_currency_code'); |
|
803 | 803 | } |
804 | 804 | |
805 | 805 | |
@@ -809,7 +809,7 @@ discard block |
||
809 | 809 | * @return string like '2, 004.00', formatted according to the localized currency |
810 | 810 | */ |
811 | 811 | public function total_no_code() { |
812 | - return $this->get_pretty( 'LIN_total', 'no_currency_code' ); |
|
812 | + return $this->get_pretty('LIN_total', 'no_currency_code'); |
|
813 | 813 | } |
814 | 814 | |
815 | 815 | |
@@ -829,17 +829,17 @@ discard block |
||
829 | 829 | $tax_total = $this->recalculate_taxes_and_tax_total(); |
830 | 830 | $total = $pre_tax_total + $tax_total; |
831 | 831 | // no negative totals plz |
832 | - $total = max( $total, 0 ); |
|
833 | - $this->set_total( $total ); |
|
832 | + $total = max($total, 0); |
|
833 | + $this->set_total($total); |
|
834 | 834 | //only update the related transaction's total |
835 | 835 | //if we intend to save this line item and its a grand total |
836 | - if( |
|
836 | + if ( |
|
837 | 837 | $this->allow_persist() && |
838 | 838 | $this->type() === EEM_Line_Item::type_total && |
839 | 839 | $this->transaction() instanceof EE_Transaction |
840 | - ){ |
|
841 | - $this->transaction()->set_total( $total ); |
|
842 | - if ( $this->transaction()->ID() ) { |
|
840 | + ) { |
|
841 | + $this->transaction()->set_total($total); |
|
842 | + if ($this->transaction()->ID()) { |
|
843 | 843 | $this->transaction()->save(); |
844 | 844 | } |
845 | 845 | } |
@@ -858,47 +858,47 @@ discard block |
||
858 | 858 | public function recalculate_pre_tax_total() { |
859 | 859 | $total = 0; |
860 | 860 | $my_children = $this->children(); |
861 | - $has_children = ! empty( $my_children ); |
|
862 | - if ( $has_children && $this->is_line_item() ) { |
|
863 | - $total = $this->_recalculate_pretax_total_for_line_item( $total, $my_children ); |
|
864 | - } elseif ( ! $has_children && ( $this->is_sub_line_item() || $this->is_line_item() ) ) { |
|
861 | + $has_children = ! empty($my_children); |
|
862 | + if ($has_children && $this->is_line_item()) { |
|
863 | + $total = $this->_recalculate_pretax_total_for_line_item($total, $my_children); |
|
864 | + } elseif ( ! $has_children && ($this->is_sub_line_item() || $this->is_line_item())) { |
|
865 | 865 | $total = $this->unit_price() * $this->quantity(); |
866 | - } elseif( $this->is_sub_total() || $this->is_total() ) { |
|
867 | - $total = $this->_recalculate_pretax_total_for_subtotal( $total, $my_children ); |
|
868 | - } elseif ( $this->is_tax_sub_total() || $this->is_tax() || $this->is_cancelled() ) { |
|
866 | + } elseif ($this->is_sub_total() || $this->is_total()) { |
|
867 | + $total = $this->_recalculate_pretax_total_for_subtotal($total, $my_children); |
|
868 | + } elseif ($this->is_tax_sub_total() || $this->is_tax() || $this->is_cancelled()) { |
|
869 | 869 | // completely ignore tax totals, tax sub-totals, and cancelled line items, when calculating the pre-tax-total |
870 | 870 | return 0; |
871 | 871 | } |
872 | 872 | // ensure all non-line items and non-sub-line-items have a quantity of 1 (except for Events) |
873 | - if( |
|
873 | + if ( |
|
874 | 874 | ! $this->is_line_item() && |
875 | 875 | ! $this->is_sub_line_item() && |
876 | 876 | ! $this->is_cancellation() |
877 | 877 | ) { |
878 | - if ( $this->OBJ_type() !== 'Event' ) { |
|
879 | - $this->set_quantity( 1 ); |
|
878 | + if ($this->OBJ_type() !== 'Event') { |
|
879 | + $this->set_quantity(1); |
|
880 | 880 | } |
881 | - if( ! $this->is_percent() ) { |
|
882 | - $this->set_unit_price( $this->total() ); |
|
881 | + if ( ! $this->is_percent()) { |
|
882 | + $this->set_unit_price($this->total()); |
|
883 | 883 | } |
884 | 884 | } |
885 | 885 | |
886 | 886 | //we don't want to bother saving grand totals, because that needs to factor in taxes anyways |
887 | 887 | //so it ought to be |
888 | - if( ! $this->is_total() ) { |
|
889 | - $this->set_total( $total ); |
|
888 | + if ( ! $this->is_total()) { |
|
889 | + $this->set_total($total); |
|
890 | 890 | //if not a percent line item, make sure we keep the unit price in sync |
891 | - if( |
|
891 | + if ( |
|
892 | 892 | $has_children |
893 | 893 | && $this->is_line_item() |
894 | 894 | && ! $this->is_percent() |
895 | 895 | ) { |
896 | - if( $this->quantity() === 0 ){ |
|
896 | + if ($this->quantity() === 0) { |
|
897 | 897 | $new_unit_price = 0; |
898 | 898 | } else { |
899 | 899 | $new_unit_price = $this->total() / $this->quantity(); |
900 | 900 | } |
901 | - $this->set_unit_price( $new_unit_price ); |
|
901 | + $this->set_unit_price($new_unit_price); |
|
902 | 902 | } |
903 | 903 | $this->maybe_save(); |
904 | 904 | } |
@@ -918,39 +918,39 @@ discard block |
||
918 | 918 | * @return float |
919 | 919 | * @throws \EE_Error |
920 | 920 | */ |
921 | - protected function _recalculate_pretax_total_for_subtotal( $calculated_total_so_far, $my_children = null ) { |
|
922 | - if( $my_children === null ) { |
|
921 | + protected function _recalculate_pretax_total_for_subtotal($calculated_total_so_far, $my_children = null) { |
|
922 | + if ($my_children === null) { |
|
923 | 923 | $my_children = $this->children(); |
924 | 924 | } |
925 | 925 | //get the total of all its children |
926 | - foreach ( $my_children as $child_line_item ) { |
|
927 | - if ( $child_line_item instanceof EE_Line_Item && ! $child_line_item->is_cancellation() ) { |
|
926 | + foreach ($my_children as $child_line_item) { |
|
927 | + if ($child_line_item instanceof EE_Line_Item && ! $child_line_item->is_cancellation()) { |
|
928 | 928 | // percentage line items are based on total so far |
929 | - if ( $child_line_item->is_percent() ) { |
|
929 | + if ($child_line_item->is_percent()) { |
|
930 | 930 | //round as we go so that the line items add up ok |
931 | 931 | $percent_total = round( |
932 | 932 | $calculated_total_so_far * $child_line_item->percent() / 100, |
933 | 933 | EE_Registry::instance()->CFG->currency->dec_plc |
934 | 934 | ); |
935 | - $child_line_item->set_total( $percent_total ); |
|
935 | + $child_line_item->set_total($percent_total); |
|
936 | 936 | //so far all percent line items should have a quantity of 1 |
937 | 937 | //(ie, no double percent discounts. Although that might be requested someday) |
938 | - $child_line_item->set_quantity( 1 ); |
|
938 | + $child_line_item->set_quantity(1); |
|
939 | 939 | $child_line_item->maybe_save(); |
940 | 940 | $calculated_total_so_far += $percent_total; |
941 | 941 | } else { |
942 | 942 | //verify flat sub-line-item quantities match their parent |
943 | - if( $child_line_item->is_sub_line_item() ) { |
|
944 | - $child_line_item->set_quantity( $this->quantity() ); |
|
943 | + if ($child_line_item->is_sub_line_item()) { |
|
944 | + $child_line_item->set_quantity($this->quantity()); |
|
945 | 945 | } |
946 | 946 | $calculated_total_so_far += $child_line_item->recalculate_pre_tax_total(); |
947 | 947 | } |
948 | 948 | } |
949 | 949 | } |
950 | 950 | |
951 | - if( $this->is_sub_total() ){ |
|
951 | + if ($this->is_sub_total()) { |
|
952 | 952 | // no negative totals plz |
953 | - $calculated_total_so_far = max( $calculated_total_so_far, 0 ); |
|
953 | + $calculated_total_so_far = max($calculated_total_so_far, 0); |
|
954 | 954 | } |
955 | 955 | return $calculated_total_so_far; |
956 | 956 | } |
@@ -968,8 +968,8 @@ discard block |
||
968 | 968 | * @return float |
969 | 969 | * @throws \EE_Error |
970 | 970 | */ |
971 | - protected function _recalculate_pretax_total_for_line_item( $calculated_total_so_far, $my_children = null ) { |
|
972 | - if( $my_children === null ) { |
|
971 | + protected function _recalculate_pretax_total_for_line_item($calculated_total_so_far, $my_children = null) { |
|
972 | + if ($my_children === null) { |
|
973 | 973 | $my_children = $this->children(); |
974 | 974 | } |
975 | 975 | //we need to keep track of the running total for a single item, |
@@ -977,10 +977,10 @@ discard block |
||
977 | 977 | $unit_price_for_total = 0; |
978 | 978 | $quantity_for_total = 1; |
979 | 979 | //get the total of all its children |
980 | - foreach ( $my_children as $child_line_item ) { |
|
981 | - if ( $child_line_item instanceof EE_Line_Item && |
|
980 | + foreach ($my_children as $child_line_item) { |
|
981 | + if ($child_line_item instanceof EE_Line_Item && |
|
982 | 982 | ! $child_line_item->is_cancellation()) { |
983 | - if ( $child_line_item->is_percent() ) { |
|
983 | + if ($child_line_item->is_percent()) { |
|
984 | 984 | //it should be the unit-price-so-far multiplied by teh percent multiplied by the quantity |
985 | 985 | //not total multiplied by percent, because that ignores rounding along-the-way |
986 | 986 | $percent_unit_price = round( |
@@ -988,17 +988,17 @@ discard block |
||
988 | 988 | EE_Registry::instance()->CFG->currency->dec_plc |
989 | 989 | ); |
990 | 990 | $percent_total = $percent_unit_price * $quantity_for_total; |
991 | - $child_line_item->set_total( $percent_total ); |
|
991 | + $child_line_item->set_total($percent_total); |
|
992 | 992 | //so far all percent line items should have a quantity of 1 |
993 | 993 | //(ie, no double percent discounts. Although that might be requested someday) |
994 | - $child_line_item->set_quantity( 1 ); |
|
994 | + $child_line_item->set_quantity(1); |
|
995 | 995 | $child_line_item->maybe_save(); |
996 | 996 | $calculated_total_so_far += $percent_total; |
997 | 997 | $unit_price_for_total += $percent_unit_price; |
998 | 998 | } else { |
999 | 999 | //verify flat sub-line-item quantities match their parent |
1000 | - if( $child_line_item->is_sub_line_item() ) { |
|
1001 | - $child_line_item->set_quantity( $this->quantity() ); |
|
1000 | + if ($child_line_item->is_sub_line_item()) { |
|
1001 | + $child_line_item->set_quantity($this->quantity()); |
|
1002 | 1002 | } |
1003 | 1003 | $quantity_for_total = $child_line_item->quantity(); |
1004 | 1004 | $calculated_total_so_far += $child_line_item->recalculate_pre_tax_total(); |
@@ -1022,10 +1022,10 @@ discard block |
||
1022 | 1022 | //calculate the pretax total |
1023 | 1023 | $taxable_total = $this->taxable_total(); |
1024 | 1024 | $tax_total = 0; |
1025 | - foreach ( $taxes as $tax ) { |
|
1025 | + foreach ($taxes as $tax) { |
|
1026 | 1026 | $total_on_this_tax = $taxable_total * $tax->percent() / 100; |
1027 | 1027 | //remember the total on this line item |
1028 | - $tax->set_total( $total_on_this_tax ); |
|
1028 | + $tax->set_total($total_on_this_tax); |
|
1029 | 1029 | $tax_total += $tax->total(); |
1030 | 1030 | } |
1031 | 1031 | $this->_recalculate_tax_sub_total(); |
@@ -1039,21 +1039,21 @@ discard block |
||
1039 | 1039 | * @return void |
1040 | 1040 | */ |
1041 | 1041 | private function _recalculate_tax_sub_total() { |
1042 | - if ( $this->is_tax_sub_total() ) { |
|
1042 | + if ($this->is_tax_sub_total()) { |
|
1043 | 1043 | $total = 0; |
1044 | 1044 | $total_percent = 0; |
1045 | 1045 | //simply loop through all its children (which should be taxes) and sum their total |
1046 | - foreach ( $this->children() as $child_tax ) { |
|
1047 | - if ( $child_tax instanceof EE_Line_Item ) { |
|
1046 | + foreach ($this->children() as $child_tax) { |
|
1047 | + if ($child_tax instanceof EE_Line_Item) { |
|
1048 | 1048 | $total += $child_tax->total(); |
1049 | 1049 | $total_percent += $child_tax->percent(); |
1050 | 1050 | } |
1051 | 1051 | } |
1052 | - $this->set_total( $total ); |
|
1053 | - $this->set_percent( $total_percent ); |
|
1054 | - } elseif ( $this->is_total() ) { |
|
1055 | - foreach ( $this->children() as $maybe_tax_subtotal ) { |
|
1056 | - if ( $maybe_tax_subtotal instanceof EE_Line_Item ) { |
|
1052 | + $this->set_total($total); |
|
1053 | + $this->set_percent($total_percent); |
|
1054 | + } elseif ($this->is_total()) { |
|
1055 | + foreach ($this->children() as $maybe_tax_subtotal) { |
|
1056 | + if ($maybe_tax_subtotal instanceof EE_Line_Item) { |
|
1057 | 1057 | $maybe_tax_subtotal->_recalculate_tax_sub_total(); |
1058 | 1058 | } |
1059 | 1059 | } |
@@ -1069,8 +1069,8 @@ discard block |
||
1069 | 1069 | public function get_total_tax() { |
1070 | 1070 | $this->_recalculate_tax_sub_total(); |
1071 | 1071 | $total = 0; |
1072 | - foreach ( $this->tax_descendants() as $tax_line_item ) { |
|
1073 | - if ( $tax_line_item instanceof EE_Line_Item ) { |
|
1072 | + foreach ($this->tax_descendants() as $tax_line_item) { |
|
1073 | + if ($tax_line_item instanceof EE_Line_Item) { |
|
1074 | 1074 | $total += $tax_line_item->total(); |
1075 | 1075 | } |
1076 | 1076 | } |
@@ -1084,15 +1084,15 @@ discard block |
||
1084 | 1084 | */ |
1085 | 1085 | public function get_items_total() { |
1086 | 1086 | //by default, let's make sure we're consistent with the existing line item |
1087 | - if( $this->is_total() ) { |
|
1088 | - $pretax_subtotal_li = EEH_Line_Item::get_pre_tax_subtotal( $this ); |
|
1089 | - if( $pretax_subtotal_li instanceof EE_Line_Item ) { |
|
1087 | + if ($this->is_total()) { |
|
1088 | + $pretax_subtotal_li = EEH_Line_Item::get_pre_tax_subtotal($this); |
|
1089 | + if ($pretax_subtotal_li instanceof EE_Line_Item) { |
|
1090 | 1090 | return $pretax_subtotal_li->total(); |
1091 | 1091 | } |
1092 | 1092 | } |
1093 | 1093 | $total = 0; |
1094 | - foreach ( $this->get_items() as $item ) { |
|
1095 | - if ( $item instanceof EE_Line_Item ) { |
|
1094 | + foreach ($this->get_items() as $item) { |
|
1095 | + if ($item instanceof EE_Line_Item) { |
|
1096 | 1096 | $total += $item->total(); |
1097 | 1097 | } |
1098 | 1098 | } |
@@ -1107,7 +1107,7 @@ discard block |
||
1107 | 1107 | * @return EE_Line_Item[] |
1108 | 1108 | */ |
1109 | 1109 | public function tax_descendants() { |
1110 | - return EEH_Line_Item::get_tax_descendants( $this ); |
|
1110 | + return EEH_Line_Item::get_tax_descendants($this); |
|
1111 | 1111 | } |
1112 | 1112 | |
1113 | 1113 | |
@@ -1117,7 +1117,7 @@ discard block |
||
1117 | 1117 | * @return EE_Line_Item[] |
1118 | 1118 | */ |
1119 | 1119 | public function get_items() { |
1120 | - return EEH_Line_Item::get_line_item_descendants( $this ); |
|
1120 | + return EEH_Line_Item::get_line_item_descendants($this); |
|
1121 | 1121 | } |
1122 | 1122 | |
1123 | 1123 | |
@@ -1133,22 +1133,22 @@ discard block |
||
1133 | 1133 | */ |
1134 | 1134 | public function taxable_total() { |
1135 | 1135 | $total = 0; |
1136 | - if ( $this->children() ) { |
|
1137 | - foreach ( $this->children() as $child_line_item ) { |
|
1138 | - if ( $child_line_item->type() === EEM_Line_Item::type_line_item && $child_line_item->is_taxable()) { |
|
1136 | + if ($this->children()) { |
|
1137 | + foreach ($this->children() as $child_line_item) { |
|
1138 | + if ($child_line_item->type() === EEM_Line_Item::type_line_item && $child_line_item->is_taxable()) { |
|
1139 | 1139 | //if it's a percent item, only take into account the percent |
1140 | 1140 | //that's taxable too (the taxable total so far) |
1141 | - if( $child_line_item->is_percent() ) { |
|
1142 | - $total = $total + ( $total * $child_line_item->percent() / 100 ); |
|
1143 | - }else{ |
|
1141 | + if ($child_line_item->is_percent()) { |
|
1142 | + $total = $total + ($total * $child_line_item->percent() / 100); |
|
1143 | + } else { |
|
1144 | 1144 | $total += $child_line_item->total(); |
1145 | 1145 | } |
1146 | - }elseif( $child_line_item->type() === EEM_Line_Item::type_sub_total ){ |
|
1146 | + }elseif ($child_line_item->type() === EEM_Line_Item::type_sub_total) { |
|
1147 | 1147 | $total += $child_line_item->taxable_total(); |
1148 | 1148 | } |
1149 | 1149 | } |
1150 | 1150 | } |
1151 | - return max( $total, 0 ); |
|
1151 | + return max($total, 0); |
|
1152 | 1152 | } |
1153 | 1153 | |
1154 | 1154 | |
@@ -1158,7 +1158,7 @@ discard block |
||
1158 | 1158 | * @return EE_Transaction |
1159 | 1159 | */ |
1160 | 1160 | public function transaction() { |
1161 | - return $this->get_first_related( 'Transaction' ); |
|
1161 | + return $this->get_first_related('Transaction'); |
|
1162 | 1162 | } |
1163 | 1163 | |
1164 | 1164 | |
@@ -1171,18 +1171,18 @@ discard block |
||
1171 | 1171 | * @param int $txn_id if none is provided, assumes $this->TXN_ID() |
1172 | 1172 | * @return int count of items saved |
1173 | 1173 | */ |
1174 | - public function save_this_and_descendants_to_txn( $txn_id = NULL ) { |
|
1174 | + public function save_this_and_descendants_to_txn($txn_id = NULL) { |
|
1175 | 1175 | $count = 0; |
1176 | - if ( ! $txn_id ) { |
|
1176 | + if ( ! $txn_id) { |
|
1177 | 1177 | $txn_id = $this->TXN_ID(); |
1178 | 1178 | } |
1179 | - $this->set_TXN_ID( $txn_id ); |
|
1179 | + $this->set_TXN_ID($txn_id); |
|
1180 | 1180 | $children = $this->children(); |
1181 | 1181 | $count += $this->save() ? 1 : 0; |
1182 | - foreach ( $children as $child_line_item ) { |
|
1183 | - if ( $child_line_item instanceof EE_Line_Item ) { |
|
1184 | - $child_line_item->set_parent_ID( $this->ID() ); |
|
1185 | - $count += $child_line_item->save_this_and_descendants_to_txn( $txn_id ); |
|
1182 | + foreach ($children as $child_line_item) { |
|
1183 | + if ($child_line_item instanceof EE_Line_Item) { |
|
1184 | + $child_line_item->set_parent_ID($this->ID()); |
|
1185 | + $count += $child_line_item->save_this_and_descendants_to_txn($txn_id); |
|
1186 | 1186 | } |
1187 | 1187 | } |
1188 | 1188 | return $count; |
@@ -1199,9 +1199,9 @@ discard block |
||
1199 | 1199 | $count = 0; |
1200 | 1200 | $children = $this->children(); |
1201 | 1201 | $count += $this->save() ? 1 : 0; |
1202 | - foreach ( $children as $child_line_item ) { |
|
1203 | - if ( $child_line_item instanceof EE_Line_Item ) { |
|
1204 | - $child_line_item->set_parent_ID( $this->ID() ); |
|
1202 | + foreach ($children as $child_line_item) { |
|
1203 | + if ($child_line_item instanceof EE_Line_Item) { |
|
1204 | + $child_line_item->set_parent_ID($this->ID()); |
|
1205 | 1205 | $count += $child_line_item->save_this_and_descendants(); |
1206 | 1206 | } |
1207 | 1207 | } |
@@ -1215,8 +1215,8 @@ discard block |
||
1215 | 1215 | * @return EE_Line_Item[] |
1216 | 1216 | */ |
1217 | 1217 | public function get_cancellations() { |
1218 | - EE_Registry::instance()->load_helper( 'Line_Item' ); |
|
1219 | - return EEH_Line_Item::get_descendants_of_type( $this, EEM_Line_Item::type_cancellation ); |
|
1218 | + EE_Registry::instance()->load_helper('Line_Item'); |
|
1219 | + return EEH_Line_Item::get_descendants_of_type($this, EEM_Line_Item::type_cancellation); |
|
1220 | 1220 | } |
1221 | 1221 | |
1222 | 1222 | |
@@ -1227,7 +1227,7 @@ discard block |
||
1227 | 1227 | * @return int count of items saved |
1228 | 1228 | */ |
1229 | 1229 | public function maybe_save() { |
1230 | - if ( $this->ID() ) { |
|
1230 | + if ($this->ID()) { |
|
1231 | 1231 | return $this->save(); |
1232 | 1232 | } |
1233 | 1233 | return false; |
@@ -362,59 +362,59 @@ |
||
362 | 362 | |
363 | 363 | |
364 | 364 | |
365 | - /** |
|
366 | - * @return EE_Base_Class[]|EE_Line_Item[] |
|
367 | - * @throws \EE_Error |
|
368 | - */ |
|
369 | - public function get_total_line_items_with_no_transaction() |
|
370 | - { |
|
371 | - return $this->get_total_line_items_for_carts(false, true); |
|
372 | - } |
|
373 | - |
|
374 | - |
|
375 | - |
|
376 | - /** |
|
377 | - * @return EE_Base_Class[]|EE_Line_Item[] |
|
378 | - * @throws \EE_Error |
|
379 | - */ |
|
380 | - public function get_total_line_items_just_added_to_cart() |
|
381 | - { |
|
382 | - return $this->get_total_line_items_for_carts(); |
|
383 | - } |
|
384 | - |
|
385 | - |
|
386 | - |
|
387 | - /** |
|
388 | - * @return EE_Base_Class[]|EE_Line_Item[] |
|
389 | - * @throws \EE_Error |
|
390 | - */ |
|
391 | - public function get_total_line_items_for_expired_carts() |
|
392 | - { |
|
393 | - return $this->get_total_line_items_for_carts(true); |
|
394 | - } |
|
395 | - |
|
396 | - |
|
397 | - |
|
398 | - /** |
|
399 | - * @param bool $expired |
|
400 | - * @param bool $all |
|
401 | - * @return EE_Base_Class[]|EE_Line_Item[] |
|
402 | - * @throws \EE_Error |
|
403 | - */ |
|
404 | - private function get_total_line_items_for_carts($expired = false, $all = false) |
|
405 | - { |
|
406 | - $where_params = array( |
|
407 | - 'TXN_ID' => 0, |
|
408 | - 'LIN_type' => 'total', |
|
409 | - ); |
|
410 | - if (! $all) { |
|
411 | - $where_params['LIN_timestamp'] = array( |
|
412 | - $expired ? '<=' : '>', |
|
413 | - time() - EE_Registry::instance()->SSN->lifespan(), |
|
414 | - ); |
|
415 | - } |
|
416 | - return $this->get_all(array($where_params)); |
|
417 | - } |
|
365 | + /** |
|
366 | + * @return EE_Base_Class[]|EE_Line_Item[] |
|
367 | + * @throws \EE_Error |
|
368 | + */ |
|
369 | + public function get_total_line_items_with_no_transaction() |
|
370 | + { |
|
371 | + return $this->get_total_line_items_for_carts(false, true); |
|
372 | + } |
|
373 | + |
|
374 | + |
|
375 | + |
|
376 | + /** |
|
377 | + * @return EE_Base_Class[]|EE_Line_Item[] |
|
378 | + * @throws \EE_Error |
|
379 | + */ |
|
380 | + public function get_total_line_items_just_added_to_cart() |
|
381 | + { |
|
382 | + return $this->get_total_line_items_for_carts(); |
|
383 | + } |
|
384 | + |
|
385 | + |
|
386 | + |
|
387 | + /** |
|
388 | + * @return EE_Base_Class[]|EE_Line_Item[] |
|
389 | + * @throws \EE_Error |
|
390 | + */ |
|
391 | + public function get_total_line_items_for_expired_carts() |
|
392 | + { |
|
393 | + return $this->get_total_line_items_for_carts(true); |
|
394 | + } |
|
395 | + |
|
396 | + |
|
397 | + |
|
398 | + /** |
|
399 | + * @param bool $expired |
|
400 | + * @param bool $all |
|
401 | + * @return EE_Base_Class[]|EE_Line_Item[] |
|
402 | + * @throws \EE_Error |
|
403 | + */ |
|
404 | + private function get_total_line_items_for_carts($expired = false, $all = false) |
|
405 | + { |
|
406 | + $where_params = array( |
|
407 | + 'TXN_ID' => 0, |
|
408 | + 'LIN_type' => 'total', |
|
409 | + ); |
|
410 | + if (! $all) { |
|
411 | + $where_params['LIN_timestamp'] = array( |
|
412 | + $expired ? '<=' : '>', |
|
413 | + time() - EE_Registry::instance()->SSN->lifespan(), |
|
414 | + ); |
|
415 | + } |
|
416 | + return $this->get_all(array($where_params)); |
|
417 | + } |
|
418 | 418 | |
419 | 419 | |
420 | 420 |
@@ -105,41 +105,41 @@ discard block |
||
105 | 105 | * @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) |
106 | 106 | * @return \EEM_Line_Item |
107 | 107 | */ |
108 | - protected function __construct( $timezone ) { |
|
109 | - $this->singular_item = __('Line Item','event_espresso'); |
|
110 | - $this->plural_item = __('Line Items','event_espresso'); |
|
108 | + protected function __construct($timezone) { |
|
109 | + $this->singular_item = __('Line Item', 'event_espresso'); |
|
110 | + $this->plural_item = __('Line Items', 'event_espresso'); |
|
111 | 111 | |
112 | 112 | $this->_tables = array( |
113 | - 'Line_Item'=>new EE_Primary_Table('esp_line_item','LIN_ID') |
|
113 | + 'Line_Item'=>new EE_Primary_Table('esp_line_item', 'LIN_ID') |
|
114 | 114 | ); |
115 | - $line_items_can_be_for = apply_filters( 'FHEE__EEM_Line_Item__line_items_can_be_for', array('Ticket','Price', 'Event' ) ); |
|
115 | + $line_items_can_be_for = apply_filters('FHEE__EEM_Line_Item__line_items_can_be_for', array('Ticket', 'Price', 'Event')); |
|
116 | 116 | $this->_fields = array( |
117 | 117 | 'Line_Item' => array( |
118 | - 'LIN_ID' => new EE_Primary_Key_Int_Field( 'LIN_ID', __( "ID", "event_espresso" ) ), |
|
119 | - 'LIN_code' => new EE_Slug_Field( 'LIN_code', __( "Code for index into Cart", "event_espresso" ), TRUE ), |
|
120 | - 'TXN_ID' => new EE_Foreign_Key_Int_Field( 'TXN_ID', __( "Transaction ID", "event_espresso" ), TRUE, NULL, 'Transaction' ), |
|
121 | - 'LIN_name' => new EE_Full_HTML_Field( 'LIN_name', __( "Line Item Name", "event_espresso" ), FALSE, '' ), |
|
122 | - 'LIN_desc' => new EE_Full_HTML_Field( 'LIN_desc', __( "Line Item Description", "event_espresso" ), TRUE ), |
|
123 | - 'LIN_unit_price' => new EE_Money_Field( 'LIN_unit_price', __( "Unit Price", "event_espresso" ), FALSE, 0 ), |
|
124 | - 'LIN_percent' => new EE_Float_Field( 'LIN_percent', __( "Percent", "event_espresso" ), FALSE, 0 ), |
|
125 | - 'LIN_is_taxable' => new EE_Boolean_Field( 'LIN_is_taxable', __( "Taxable", "event_espresso" ), FALSE, FALSE ), |
|
126 | - 'LIN_order' => new EE_Integer_Field( 'LIN_order', __( "Order of Application towards total of parent", "event_espresso" ), FALSE, 1 ), |
|
127 | - 'LIN_total' => new EE_Money_Field( 'LIN_total', __( "Total (unit price x quantity)", "event_espresso" ), FALSE, 0 ), |
|
128 | - 'LIN_quantity' => new EE_Integer_Field( 'LIN_quantity', __( "Quantity", "event_espresso" ), TRUE, 1 ), |
|
129 | - 'LIN_parent' => new EE_Integer_Field( 'LIN_parent', __( "Parent ID (this item goes towards that Line Item's total)", "event_espresso" ), TRUE, NULL ), |
|
130 | - 'LIN_type' => new EE_Enum_Text_Field( 'LIN_type', __( "Type", "event_espresso" ), FALSE, 'line-item', array( |
|
118 | + 'LIN_ID' => new EE_Primary_Key_Int_Field('LIN_ID', __("ID", "event_espresso")), |
|
119 | + 'LIN_code' => new EE_Slug_Field('LIN_code', __("Code for index into Cart", "event_espresso"), TRUE), |
|
120 | + 'TXN_ID' => new EE_Foreign_Key_Int_Field('TXN_ID', __("Transaction ID", "event_espresso"), TRUE, NULL, 'Transaction'), |
|
121 | + 'LIN_name' => new EE_Full_HTML_Field('LIN_name', __("Line Item Name", "event_espresso"), FALSE, ''), |
|
122 | + 'LIN_desc' => new EE_Full_HTML_Field('LIN_desc', __("Line Item Description", "event_espresso"), TRUE), |
|
123 | + 'LIN_unit_price' => new EE_Money_Field('LIN_unit_price', __("Unit Price", "event_espresso"), FALSE, 0), |
|
124 | + 'LIN_percent' => new EE_Float_Field('LIN_percent', __("Percent", "event_espresso"), FALSE, 0), |
|
125 | + 'LIN_is_taxable' => new EE_Boolean_Field('LIN_is_taxable', __("Taxable", "event_espresso"), FALSE, FALSE), |
|
126 | + 'LIN_order' => new EE_Integer_Field('LIN_order', __("Order of Application towards total of parent", "event_espresso"), FALSE, 1), |
|
127 | + 'LIN_total' => new EE_Money_Field('LIN_total', __("Total (unit price x quantity)", "event_espresso"), FALSE, 0), |
|
128 | + 'LIN_quantity' => new EE_Integer_Field('LIN_quantity', __("Quantity", "event_espresso"), TRUE, 1), |
|
129 | + 'LIN_parent' => new EE_Integer_Field('LIN_parent', __("Parent ID (this item goes towards that Line Item's total)", "event_espresso"), TRUE, NULL), |
|
130 | + 'LIN_type' => new EE_Enum_Text_Field('LIN_type', __("Type", "event_espresso"), FALSE, 'line-item', array( |
|
131 | 131 | self::type_line_item => __("Line Item", "event_espresso"), |
132 | 132 | self::type_sub_line_item => __("Sub-Item", "event_espresso"), |
133 | 133 | self::type_sub_total => __("Subtotal", "event_espresso"), |
134 | 134 | self::type_tax_sub_total => __("Tax Subtotal", "event_espresso"), |
135 | 135 | self::type_tax => __("Tax", "event_espresso"), |
136 | 136 | self::type_total => __("Total", "event_espresso"), |
137 | - self::type_cancellation => __( 'Cancellation', 'event_espresso' ) |
|
137 | + self::type_cancellation => __('Cancellation', 'event_espresso') |
|
138 | 138 | ) |
139 | 139 | ), |
140 | - 'OBJ_ID' => new EE_Foreign_Key_Int_Field( 'OBJ_ID', __( 'ID of Item purchased.', 'event_espresso' ), TRUE, NULL, $line_items_can_be_for ), |
|
141 | - 'OBJ_type' =>new EE_Any_Foreign_Model_Name_Field( 'OBJ_type', __( "Model Name this Line Item is for", "event_espresso" ), TRUE, NULL, $line_items_can_be_for ), |
|
142 | - 'LIN_timestamp' => new EE_Datetime_Field('LIN_timestamp', __('When the line item was created','event_espresso'), false, EE_Datetime_Field::now, $timezone ), |
|
140 | + 'OBJ_ID' => new EE_Foreign_Key_Int_Field('OBJ_ID', __('ID of Item purchased.', 'event_espresso'), TRUE, NULL, $line_items_can_be_for), |
|
141 | + 'OBJ_type' =>new EE_Any_Foreign_Model_Name_Field('OBJ_type', __("Model Name this Line Item is for", "event_espresso"), TRUE, NULL, $line_items_can_be_for), |
|
142 | + 'LIN_timestamp' => new EE_Datetime_Field('LIN_timestamp', __('When the line item was created', 'event_espresso'), false, EE_Datetime_Field::now, $timezone), |
|
143 | 143 | ) |
144 | 144 | ); |
145 | 145 | $this->_model_relations = array( |
@@ -150,7 +150,7 @@ discard block |
||
150 | 150 | ); |
151 | 151 | $this->_model_chain_to_wp_user = 'Transaction.Registration.Event'; |
152 | 152 | $this->_caps_slug = 'transactions'; |
153 | - parent::__construct( $timezone ); |
|
153 | + parent::__construct($timezone); |
|
154 | 154 | } |
155 | 155 | |
156 | 156 | |
@@ -161,9 +161,9 @@ discard block |
||
161 | 161 | * @param EE_Transaction|int $transaction |
162 | 162 | * @return EE_Line_Item[] |
163 | 163 | */ |
164 | - public function get_all_of_type_for_transaction( $line_item_type, $transaction ){ |
|
165 | - $transaction = EEM_Transaction::instance()->ensure_is_ID( $transaction ); |
|
166 | - return $this->get_all( array( array( |
|
164 | + public function get_all_of_type_for_transaction($line_item_type, $transaction) { |
|
165 | + $transaction = EEM_Transaction::instance()->ensure_is_ID($transaction); |
|
166 | + return $this->get_all(array(array( |
|
167 | 167 | 'LIN_type' => $line_item_type, |
168 | 168 | 'TXN_ID' => $transaction |
169 | 169 | ))); |
@@ -177,14 +177,14 @@ discard block |
||
177 | 177 | * @param EE_Transaction|int $transaction |
178 | 178 | * @return EE_Line_Item[] |
179 | 179 | */ |
180 | - public function get_all_non_ticket_line_items_for_transaction( $transaction ) { |
|
181 | - $transaction = EEM_Transaction::instance()->ensure_is_ID( $transaction ); |
|
182 | - return $this->get_all( array( array( |
|
180 | + public function get_all_non_ticket_line_items_for_transaction($transaction) { |
|
181 | + $transaction = EEM_Transaction::instance()->ensure_is_ID($transaction); |
|
182 | + return $this->get_all(array(array( |
|
183 | 183 | 'LIN_type' => self::type_line_item, |
184 | 184 | 'TXN_ID' => $transaction, |
185 | 185 | 'OR' => array( |
186 | - 'OBJ_type*notticket' => array( '!=', 'Ticket'), |
|
187 | - 'OBJ_type*null' => array( 'IS_NULL' )) |
|
186 | + 'OBJ_type*notticket' => array('!=', 'Ticket'), |
|
187 | + 'OBJ_type*null' => array('IS_NULL')) |
|
188 | 188 | ))); |
189 | 189 | } |
190 | 190 | |
@@ -194,7 +194,7 @@ discard block |
||
194 | 194 | * because if there are spam bots afoot there will be LOTS of line items |
195 | 195 | * @return int count of how many deleted |
196 | 196 | */ |
197 | - public function delete_line_items_with_no_transaction(){ |
|
197 | + public function delete_line_items_with_no_transaction() { |
|
198 | 198 | /** @type WPDB $wpdb */ |
199 | 199 | global $wpdb; |
200 | 200 | $time_to_leave_alone = apply_filters( |
@@ -202,13 +202,13 @@ discard block |
||
202 | 202 | ); |
203 | 203 | $query = $wpdb->prepare( |
204 | 204 | 'DELETE li |
205 | - FROM ' . $this->table() . ' li |
|
206 | - LEFT JOIN ' . EEM_Transaction::instance()->table(). ' t ON li.TXN_ID = t.TXN_ID |
|
205 | + FROM ' . $this->table().' li |
|
206 | + LEFT JOIN ' . EEM_Transaction::instance()->table().' t ON li.TXN_ID = t.TXN_ID |
|
207 | 207 | WHERE t.TXN_ID IS NULL AND li.LIN_timestamp < %s', |
208 | 208 | // use GMT time because that's what TXN_timestamps are in |
209 | - date( 'Y-m-d H:i:s', time() - $time_to_leave_alone ) |
|
209 | + date('Y-m-d H:i:s', time() - $time_to_leave_alone) |
|
210 | 210 | ); |
211 | - return $wpdb->query( $query ); |
|
211 | + return $wpdb->query($query); |
|
212 | 212 | } |
213 | 213 | |
214 | 214 | |
@@ -221,10 +221,10 @@ discard block |
||
221 | 221 | * @param \EE_Base_Class $object |
222 | 222 | * @return EE_Line_Item[] |
223 | 223 | */ |
224 | - public function get_line_item_for_transaction_object( $TXN_ID, EE_Base_Class $object ){ |
|
225 | - return $this->get_all( array( array( |
|
224 | + public function get_line_item_for_transaction_object($TXN_ID, EE_Base_Class $object) { |
|
225 | + return $this->get_all(array(array( |
|
226 | 226 | 'TXN_ID' => $TXN_ID, |
227 | - 'OBJ_type' => str_replace( 'EE_', '', get_class( $object )), |
|
227 | + 'OBJ_type' => str_replace('EE_', '', get_class($object)), |
|
228 | 228 | 'OBJ_ID' => $object->ID() |
229 | 229 | ))); |
230 | 230 | } |
@@ -240,16 +240,16 @@ discard block |
||
240 | 240 | * @param array $OBJ_IDs |
241 | 241 | * @return EE_Line_Item[] |
242 | 242 | */ |
243 | - public function get_object_line_items_for_transaction( $TXN_ID, $OBJ_type = 'Event', $OBJ_IDs = array() ){ |
|
243 | + public function get_object_line_items_for_transaction($TXN_ID, $OBJ_type = 'Event', $OBJ_IDs = array()) { |
|
244 | 244 | $query_params = array( |
245 | 245 | 'OBJ_type' => $OBJ_type, |
246 | 246 | // if incoming $OBJ_IDs is an array, then make sure it is formatted correctly for the query |
247 | - 'OBJ_ID' => is_array( $OBJ_IDs ) && ! isset( $OBJ_IDs['IN'] ) ? array( 'IN', $OBJ_IDs ) : $OBJ_IDs |
|
247 | + 'OBJ_ID' => is_array($OBJ_IDs) && ! isset($OBJ_IDs['IN']) ? array('IN', $OBJ_IDs) : $OBJ_IDs |
|
248 | 248 | ); |
249 | - if ( $TXN_ID ) { |
|
249 | + if ($TXN_ID) { |
|
250 | 250 | $query_params['TXN_ID'] = $TXN_ID; |
251 | 251 | } |
252 | - return $this->get_all( array( $query_params )); |
|
252 | + return $this->get_all(array($query_params)); |
|
253 | 253 | } |
254 | 254 | |
255 | 255 | |
@@ -260,13 +260,13 @@ discard block |
||
260 | 260 | * @param EE_Transaction $transaction |
261 | 261 | * @return EE_Line_Item[] |
262 | 262 | */ |
263 | - public function get_all_ticket_line_items_for_transaction( EE_Transaction $transaction ) { |
|
264 | - return $this->get_all( array( |
|
263 | + public function get_all_ticket_line_items_for_transaction(EE_Transaction $transaction) { |
|
264 | + return $this->get_all(array( |
|
265 | 265 | array( |
266 | 266 | 'TXN_ID' => $transaction->ID(), |
267 | 267 | 'OBJ_type' => 'Ticket', |
268 | 268 | ) |
269 | - ) ); |
|
269 | + )); |
|
270 | 270 | } |
271 | 271 | |
272 | 272 | |
@@ -278,14 +278,14 @@ discard block |
||
278 | 278 | * @param int $TKT_ID |
279 | 279 | * @return \EE_Line_Item |
280 | 280 | */ |
281 | - public function get_ticket_line_item_for_transaction( $TXN_ID, $TKT_ID ) { |
|
282 | - return $this->get_one( array( |
|
281 | + public function get_ticket_line_item_for_transaction($TXN_ID, $TKT_ID) { |
|
282 | + return $this->get_one(array( |
|
283 | 283 | array( |
284 | - 'TXN_ID' => EEM_Transaction::instance()->ensure_is_ID( $TXN_ID ), |
|
284 | + 'TXN_ID' => EEM_Transaction::instance()->ensure_is_ID($TXN_ID), |
|
285 | 285 | 'OBJ_ID' => $TKT_ID, |
286 | 286 | 'OBJ_type' => 'Ticket', |
287 | 287 | ) |
288 | - ) ); |
|
288 | + )); |
|
289 | 289 | } |
290 | 290 | |
291 | 291 | |
@@ -300,8 +300,8 @@ discard block |
||
300 | 300 | * @param EE_Promotion $promotion |
301 | 301 | * @return EE_Line_Item |
302 | 302 | */ |
303 | - public function get_existing_promotion_line_item( EE_Line_Item $parent_line_item, EE_Promotion $promotion ) { |
|
304 | - return $this->get_one( array( |
|
303 | + public function get_existing_promotion_line_item(EE_Line_Item $parent_line_item, EE_Promotion $promotion) { |
|
304 | + return $this->get_one(array( |
|
305 | 305 | array( |
306 | 306 | 'TXN_ID' => $parent_line_item->TXN_ID(), |
307 | 307 | 'LIN_parent' => $parent_line_item->ID(), |
@@ -322,8 +322,8 @@ discard block |
||
322 | 322 | * @param EE_Line_Item $parent_line_item |
323 | 323 | * @return EE_Line_Item[] |
324 | 324 | */ |
325 | - public function get_all_promotion_line_items( EE_Line_Item $parent_line_item ) { |
|
326 | - return $this->get_all( array( |
|
325 | + public function get_all_promotion_line_items(EE_Line_Item $parent_line_item) { |
|
326 | + return $this->get_all(array( |
|
327 | 327 | array( |
328 | 328 | 'TXN_ID' => $parent_line_item->TXN_ID(), |
329 | 329 | 'LIN_parent' => $parent_line_item->ID(), |
@@ -340,8 +340,8 @@ discard block |
||
340 | 340 | * @param EE_Registration $registration |
341 | 341 | * @return EE_Line_ITem |
342 | 342 | */ |
343 | - public function get_line_item_for_registration( EE_Registration $registration ) { |
|
344 | - return $this->get_one( $this->line_item_for_registration_query_params( $registration )); |
|
343 | + public function get_line_item_for_registration(EE_Registration $registration) { |
|
344 | + return $this->get_one($this->line_item_for_registration_query_params($registration)); |
|
345 | 345 | } |
346 | 346 | |
347 | 347 | /** |
@@ -350,14 +350,14 @@ discard block |
||
350 | 350 | * @param array $original_query_params any extra query params you'd like to be merged with |
351 | 351 | * @return array like EEM_Base::get_all()'s $query_params |
352 | 352 | */ |
353 | - public function line_item_for_registration_query_params( EE_Registration $registration, $original_query_params = array() ) { |
|
354 | - return array_replace_recursive( $original_query_params, array( |
|
353 | + public function line_item_for_registration_query_params(EE_Registration $registration, $original_query_params = array()) { |
|
354 | + return array_replace_recursive($original_query_params, array( |
|
355 | 355 | array( |
356 | 356 | 'OBJ_ID' => $registration->ticket_ID(), |
357 | 357 | 'OBJ_type' => 'Ticket', |
358 | 358 | 'TXN_ID' => $registration->transaction_ID() |
359 | 359 | ) |
360 | - ) ); |
|
360 | + )); |
|
361 | 361 | } |
362 | 362 | |
363 | 363 | |
@@ -407,7 +407,7 @@ discard block |
||
407 | 407 | 'TXN_ID' => 0, |
408 | 408 | 'LIN_type' => 'total', |
409 | 409 | ); |
410 | - if (! $all) { |
|
410 | + if ( ! $all) { |
|
411 | 411 | $where_params['LIN_timestamp'] = array( |
412 | 412 | $expired ? '<=' : '>', |
413 | 413 | time() - EE_Registry::instance()->SSN->lifespan(), |
@@ -1,5 +1,5 @@ discard block |
||
1 | 1 | <?php if ( ! defined('ABSPATH')) { |
2 | - exit('No direct script access allowed'); |
|
2 | + exit('No direct script access allowed'); |
|
3 | 3 | } |
4 | 4 | /* |
5 | 5 | Plugin Name: Event Espresso |
@@ -40,243 +40,243 @@ discard block |
||
40 | 40 | * @since 4.0 |
41 | 41 | */ |
42 | 42 | if (function_exists('espresso_version')) { |
43 | - /** |
|
44 | - * espresso_duplicate_plugin_error |
|
45 | - * displays if more than one version of EE is activated at the same time |
|
46 | - */ |
|
47 | - function espresso_duplicate_plugin_error() |
|
48 | - { |
|
49 | - ?> |
|
43 | + /** |
|
44 | + * espresso_duplicate_plugin_error |
|
45 | + * displays if more than one version of EE is activated at the same time |
|
46 | + */ |
|
47 | + function espresso_duplicate_plugin_error() |
|
48 | + { |
|
49 | + ?> |
|
50 | 50 | <div class="error"> |
51 | 51 | <p> |
52 | 52 | <?php echo esc_html__( |
53 | - 'Can not run multiple versions of Event Espresso! One version has been automatically deactivated. Please verify that you have the correct version you want still active.', |
|
54 | - 'event_espresso' |
|
55 | - ); ?> |
|
53 | + 'Can not run multiple versions of Event Espresso! One version has been automatically deactivated. Please verify that you have the correct version you want still active.', |
|
54 | + 'event_espresso' |
|
55 | + ); ?> |
|
56 | 56 | </p> |
57 | 57 | </div> |
58 | 58 | <?php |
59 | - espresso_deactivate_plugin(plugin_basename(__FILE__)); |
|
60 | - } |
|
59 | + espresso_deactivate_plugin(plugin_basename(__FILE__)); |
|
60 | + } |
|
61 | 61 | |
62 | - add_action('admin_notices', 'espresso_duplicate_plugin_error', 1); |
|
62 | + add_action('admin_notices', 'espresso_duplicate_plugin_error', 1); |
|
63 | 63 | } else { |
64 | - define('EE_MIN_PHP_VER_REQUIRED', '5.3.9'); |
|
65 | - if ( ! version_compare(PHP_VERSION, EE_MIN_PHP_VER_REQUIRED, '>=')) { |
|
66 | - /** |
|
67 | - * espresso_minimum_php_version_error |
|
68 | - * |
|
69 | - * @return void |
|
70 | - */ |
|
71 | - function espresso_minimum_php_version_error() |
|
72 | - { |
|
73 | - ?> |
|
64 | + define('EE_MIN_PHP_VER_REQUIRED', '5.3.9'); |
|
65 | + if ( ! version_compare(PHP_VERSION, EE_MIN_PHP_VER_REQUIRED, '>=')) { |
|
66 | + /** |
|
67 | + * espresso_minimum_php_version_error |
|
68 | + * |
|
69 | + * @return void |
|
70 | + */ |
|
71 | + function espresso_minimum_php_version_error() |
|
72 | + { |
|
73 | + ?> |
|
74 | 74 | <div class="error"> |
75 | 75 | <p> |
76 | 76 | <?php |
77 | - printf( |
|
78 | - esc_html__( |
|
79 | - 'We\'re sorry, but Event Espresso requires PHP version %1$s or greater in order to operate. You are currently running version %2$s.%3$sIn order to update your version of PHP, you will need to contact your current hosting provider.%3$sFor information on stable PHP versions, please go to %4$s.', |
|
80 | - 'event_espresso' |
|
81 | - ), |
|
82 | - EE_MIN_PHP_VER_REQUIRED, |
|
83 | - PHP_VERSION, |
|
84 | - '<br/>', |
|
85 | - '<a href="http://php.net/downloads.php">http://php.net/downloads.php</a>' |
|
86 | - ); |
|
87 | - ?> |
|
77 | + printf( |
|
78 | + esc_html__( |
|
79 | + 'We\'re sorry, but Event Espresso requires PHP version %1$s or greater in order to operate. You are currently running version %2$s.%3$sIn order to update your version of PHP, you will need to contact your current hosting provider.%3$sFor information on stable PHP versions, please go to %4$s.', |
|
80 | + 'event_espresso' |
|
81 | + ), |
|
82 | + EE_MIN_PHP_VER_REQUIRED, |
|
83 | + PHP_VERSION, |
|
84 | + '<br/>', |
|
85 | + '<a href="http://php.net/downloads.php">http://php.net/downloads.php</a>' |
|
86 | + ); |
|
87 | + ?> |
|
88 | 88 | </p> |
89 | 89 | </div> |
90 | 90 | <?php |
91 | - espresso_deactivate_plugin(plugin_basename(__FILE__)); |
|
92 | - } |
|
91 | + espresso_deactivate_plugin(plugin_basename(__FILE__)); |
|
92 | + } |
|
93 | 93 | |
94 | - add_action('admin_notices', 'espresso_minimum_php_version_error', 1); |
|
95 | - } else { |
|
96 | - /** |
|
97 | - * espresso_version |
|
98 | - * Returns the plugin version |
|
99 | - * |
|
100 | - * @return string |
|
101 | - */ |
|
102 | - function espresso_version() |
|
103 | - { |
|
104 | - return apply_filters('FHEE__espresso__espresso_version', '4.9.32.rc.025'); |
|
105 | - } |
|
94 | + add_action('admin_notices', 'espresso_minimum_php_version_error', 1); |
|
95 | + } else { |
|
96 | + /** |
|
97 | + * espresso_version |
|
98 | + * Returns the plugin version |
|
99 | + * |
|
100 | + * @return string |
|
101 | + */ |
|
102 | + function espresso_version() |
|
103 | + { |
|
104 | + return apply_filters('FHEE__espresso__espresso_version', '4.9.32.rc.025'); |
|
105 | + } |
|
106 | 106 | |
107 | - // define versions |
|
108 | - define('EVENT_ESPRESSO_VERSION', espresso_version()); |
|
109 | - define('EE_MIN_WP_VER_REQUIRED', '4.1'); |
|
110 | - define('EE_MIN_WP_VER_RECOMMENDED', '4.4.2'); |
|
111 | - define('EE_MIN_PHP_VER_RECOMMENDED', '5.4.44'); |
|
112 | - define('EVENT_ESPRESSO_MAIN_FILE', __FILE__); |
|
113 | - //used to be DIRECTORY_SEPARATOR, but that caused issues on windows |
|
114 | - if ( ! defined('DS')) { |
|
115 | - define('DS', '/'); |
|
116 | - } |
|
117 | - if ( ! defined('PS')) { |
|
118 | - define('PS', PATH_SEPARATOR); |
|
119 | - } |
|
120 | - if ( ! defined('SP')) { |
|
121 | - define('SP', ' '); |
|
122 | - } |
|
123 | - if ( ! defined('EENL')) { |
|
124 | - define('EENL', "\n"); |
|
125 | - } |
|
126 | - define('EE_SUPPORT_EMAIL', '[email protected]'); |
|
127 | - // define the plugin directory and URL |
|
128 | - define('EE_PLUGIN_BASENAME', plugin_basename(EVENT_ESPRESSO_MAIN_FILE)); |
|
129 | - define('EE_PLUGIN_DIR_PATH', plugin_dir_path(EVENT_ESPRESSO_MAIN_FILE)); |
|
130 | - define('EE_PLUGIN_DIR_URL', plugin_dir_url(EVENT_ESPRESSO_MAIN_FILE)); |
|
131 | - // main root folder paths |
|
132 | - define('EE_ADMIN_PAGES', EE_PLUGIN_DIR_PATH . 'admin_pages' . DS); |
|
133 | - define('EE_CORE', EE_PLUGIN_DIR_PATH . 'core' . DS); |
|
134 | - define('EE_MODULES', EE_PLUGIN_DIR_PATH . 'modules' . DS); |
|
135 | - define('EE_PUBLIC', EE_PLUGIN_DIR_PATH . 'public' . DS); |
|
136 | - define('EE_SHORTCODES', EE_PLUGIN_DIR_PATH . 'shortcodes' . DS); |
|
137 | - define('EE_WIDGETS', EE_PLUGIN_DIR_PATH . 'widgets' . DS); |
|
138 | - define('EE_PAYMENT_METHODS', EE_PLUGIN_DIR_PATH . 'payment_methods' . DS); |
|
139 | - define('EE_CAFF_PATH', EE_PLUGIN_DIR_PATH . 'caffeinated' . DS); |
|
140 | - // core system paths |
|
141 | - define('EE_ADMIN', EE_CORE . 'admin' . DS); |
|
142 | - define('EE_CPTS', EE_CORE . 'CPTs' . DS); |
|
143 | - define('EE_CLASSES', EE_CORE . 'db_classes' . DS); |
|
144 | - define('EE_INTERFACES', EE_CORE . 'interfaces' . DS); |
|
145 | - define('EE_BUSINESS', EE_CORE . 'business' . DS); |
|
146 | - define('EE_MODELS', EE_CORE . 'db_models' . DS); |
|
147 | - define('EE_HELPERS', EE_CORE . 'helpers' . DS); |
|
148 | - define('EE_LIBRARIES', EE_CORE . 'libraries' . DS); |
|
149 | - define('EE_TEMPLATES', EE_CORE . 'templates' . DS); |
|
150 | - define('EE_THIRD_PARTY', EE_CORE . 'third_party_libs' . DS); |
|
151 | - define('EE_GLOBAL_ASSETS', EE_TEMPLATES . 'global_assets' . DS); |
|
152 | - define('EE_FORM_SECTIONS', EE_LIBRARIES . 'form_sections' . DS); |
|
153 | - // gateways |
|
154 | - define('EE_GATEWAYS', EE_MODULES . 'gateways' . DS); |
|
155 | - define('EE_GATEWAYS_URL', EE_PLUGIN_DIR_URL . 'modules' . DS . 'gateways' . DS); |
|
156 | - // asset URL paths |
|
157 | - define('EE_TEMPLATES_URL', EE_PLUGIN_DIR_URL . 'core' . DS . 'templates' . DS); |
|
158 | - define('EE_GLOBAL_ASSETS_URL', EE_TEMPLATES_URL . 'global_assets' . DS); |
|
159 | - define('EE_IMAGES_URL', EE_GLOBAL_ASSETS_URL . 'images' . DS); |
|
160 | - define('EE_THIRD_PARTY_URL', EE_PLUGIN_DIR_URL . 'core' . DS . 'third_party_libs' . DS); |
|
161 | - define('EE_HELPERS_ASSETS', EE_PLUGIN_DIR_URL . 'core/helpers/assets/'); |
|
162 | - define('EE_LIBRARIES_URL', EE_PLUGIN_DIR_URL . 'core/libraries/'); |
|
163 | - // define upload paths |
|
164 | - $uploads = wp_upload_dir(); |
|
165 | - // define the uploads directory and URL |
|
166 | - define('EVENT_ESPRESSO_UPLOAD_DIR', $uploads['basedir'] . DS . 'espresso' . DS); |
|
167 | - define('EVENT_ESPRESSO_UPLOAD_URL', $uploads['baseurl'] . DS . 'espresso' . DS); |
|
168 | - // define the templates directory and URL |
|
169 | - define('EVENT_ESPRESSO_TEMPLATE_DIR', $uploads['basedir'] . DS . 'espresso' . DS . 'templates' . DS); |
|
170 | - define('EVENT_ESPRESSO_TEMPLATE_URL', $uploads['baseurl'] . DS . 'espresso' . DS . 'templates' . DS); |
|
171 | - // define the gateway directory and URL |
|
172 | - define('EVENT_ESPRESSO_GATEWAY_DIR', $uploads['basedir'] . DS . 'espresso' . DS . 'gateways' . DS); |
|
173 | - define('EVENT_ESPRESSO_GATEWAY_URL', $uploads['baseurl'] . DS . 'espresso' . DS . 'gateways' . DS); |
|
174 | - // languages folder/path |
|
175 | - define('EE_LANGUAGES_SAFE_LOC', '..' . DS . 'uploads' . DS . 'espresso' . DS . 'languages' . DS); |
|
176 | - define('EE_LANGUAGES_SAFE_DIR', EVENT_ESPRESSO_UPLOAD_DIR . 'languages' . DS); |
|
177 | - //check for dompdf fonts in uploads |
|
178 | - if (file_exists(EVENT_ESPRESSO_UPLOAD_DIR . 'fonts' . DS)) { |
|
179 | - define('DOMPDF_FONT_DIR', EVENT_ESPRESSO_UPLOAD_DIR . 'fonts' . DS); |
|
180 | - } |
|
181 | - //ajax constants |
|
182 | - define( |
|
183 | - 'EE_FRONT_AJAX', |
|
184 | - isset($_REQUEST['ee_front_ajax']) || isset($_REQUEST['data']['ee_front_ajax']) ? true : false |
|
185 | - ); |
|
186 | - define( |
|
187 | - 'EE_ADMIN_AJAX', |
|
188 | - isset($_REQUEST['ee_admin_ajax']) || isset($_REQUEST['data']['ee_admin_ajax']) ? true : false |
|
189 | - ); |
|
190 | - //just a handy constant occasionally needed for finding values representing infinity in the DB |
|
191 | - //you're better to use this than its straight value (currently -1) in case you ever |
|
192 | - //want to change its default value! or find when -1 means infinity |
|
193 | - define('EE_INF_IN_DB', -1); |
|
194 | - define('EE_INF', INF > (float)PHP_INT_MAX ? INF : PHP_INT_MAX); |
|
195 | - define('EE_DEBUG', false); |
|
196 | - // for older WP versions |
|
197 | - if ( ! defined('MONTH_IN_SECONDS')) { |
|
198 | - define('MONTH_IN_SECONDS', DAY_IN_SECONDS * 30); |
|
199 | - } |
|
200 | - /** |
|
201 | - * espresso_plugin_activation |
|
202 | - * adds a wp-option to indicate that EE has been activated via the WP admin plugins page |
|
203 | - */ |
|
204 | - function espresso_plugin_activation() |
|
205 | - { |
|
206 | - update_option('ee_espresso_activation', true); |
|
207 | - } |
|
107 | + // define versions |
|
108 | + define('EVENT_ESPRESSO_VERSION', espresso_version()); |
|
109 | + define('EE_MIN_WP_VER_REQUIRED', '4.1'); |
|
110 | + define('EE_MIN_WP_VER_RECOMMENDED', '4.4.2'); |
|
111 | + define('EE_MIN_PHP_VER_RECOMMENDED', '5.4.44'); |
|
112 | + define('EVENT_ESPRESSO_MAIN_FILE', __FILE__); |
|
113 | + //used to be DIRECTORY_SEPARATOR, but that caused issues on windows |
|
114 | + if ( ! defined('DS')) { |
|
115 | + define('DS', '/'); |
|
116 | + } |
|
117 | + if ( ! defined('PS')) { |
|
118 | + define('PS', PATH_SEPARATOR); |
|
119 | + } |
|
120 | + if ( ! defined('SP')) { |
|
121 | + define('SP', ' '); |
|
122 | + } |
|
123 | + if ( ! defined('EENL')) { |
|
124 | + define('EENL', "\n"); |
|
125 | + } |
|
126 | + define('EE_SUPPORT_EMAIL', '[email protected]'); |
|
127 | + // define the plugin directory and URL |
|
128 | + define('EE_PLUGIN_BASENAME', plugin_basename(EVENT_ESPRESSO_MAIN_FILE)); |
|
129 | + define('EE_PLUGIN_DIR_PATH', plugin_dir_path(EVENT_ESPRESSO_MAIN_FILE)); |
|
130 | + define('EE_PLUGIN_DIR_URL', plugin_dir_url(EVENT_ESPRESSO_MAIN_FILE)); |
|
131 | + // main root folder paths |
|
132 | + define('EE_ADMIN_PAGES', EE_PLUGIN_DIR_PATH . 'admin_pages' . DS); |
|
133 | + define('EE_CORE', EE_PLUGIN_DIR_PATH . 'core' . DS); |
|
134 | + define('EE_MODULES', EE_PLUGIN_DIR_PATH . 'modules' . DS); |
|
135 | + define('EE_PUBLIC', EE_PLUGIN_DIR_PATH . 'public' . DS); |
|
136 | + define('EE_SHORTCODES', EE_PLUGIN_DIR_PATH . 'shortcodes' . DS); |
|
137 | + define('EE_WIDGETS', EE_PLUGIN_DIR_PATH . 'widgets' . DS); |
|
138 | + define('EE_PAYMENT_METHODS', EE_PLUGIN_DIR_PATH . 'payment_methods' . DS); |
|
139 | + define('EE_CAFF_PATH', EE_PLUGIN_DIR_PATH . 'caffeinated' . DS); |
|
140 | + // core system paths |
|
141 | + define('EE_ADMIN', EE_CORE . 'admin' . DS); |
|
142 | + define('EE_CPTS', EE_CORE . 'CPTs' . DS); |
|
143 | + define('EE_CLASSES', EE_CORE . 'db_classes' . DS); |
|
144 | + define('EE_INTERFACES', EE_CORE . 'interfaces' . DS); |
|
145 | + define('EE_BUSINESS', EE_CORE . 'business' . DS); |
|
146 | + define('EE_MODELS', EE_CORE . 'db_models' . DS); |
|
147 | + define('EE_HELPERS', EE_CORE . 'helpers' . DS); |
|
148 | + define('EE_LIBRARIES', EE_CORE . 'libraries' . DS); |
|
149 | + define('EE_TEMPLATES', EE_CORE . 'templates' . DS); |
|
150 | + define('EE_THIRD_PARTY', EE_CORE . 'third_party_libs' . DS); |
|
151 | + define('EE_GLOBAL_ASSETS', EE_TEMPLATES . 'global_assets' . DS); |
|
152 | + define('EE_FORM_SECTIONS', EE_LIBRARIES . 'form_sections' . DS); |
|
153 | + // gateways |
|
154 | + define('EE_GATEWAYS', EE_MODULES . 'gateways' . DS); |
|
155 | + define('EE_GATEWAYS_URL', EE_PLUGIN_DIR_URL . 'modules' . DS . 'gateways' . DS); |
|
156 | + // asset URL paths |
|
157 | + define('EE_TEMPLATES_URL', EE_PLUGIN_DIR_URL . 'core' . DS . 'templates' . DS); |
|
158 | + define('EE_GLOBAL_ASSETS_URL', EE_TEMPLATES_URL . 'global_assets' . DS); |
|
159 | + define('EE_IMAGES_URL', EE_GLOBAL_ASSETS_URL . 'images' . DS); |
|
160 | + define('EE_THIRD_PARTY_URL', EE_PLUGIN_DIR_URL . 'core' . DS . 'third_party_libs' . DS); |
|
161 | + define('EE_HELPERS_ASSETS', EE_PLUGIN_DIR_URL . 'core/helpers/assets/'); |
|
162 | + define('EE_LIBRARIES_URL', EE_PLUGIN_DIR_URL . 'core/libraries/'); |
|
163 | + // define upload paths |
|
164 | + $uploads = wp_upload_dir(); |
|
165 | + // define the uploads directory and URL |
|
166 | + define('EVENT_ESPRESSO_UPLOAD_DIR', $uploads['basedir'] . DS . 'espresso' . DS); |
|
167 | + define('EVENT_ESPRESSO_UPLOAD_URL', $uploads['baseurl'] . DS . 'espresso' . DS); |
|
168 | + // define the templates directory and URL |
|
169 | + define('EVENT_ESPRESSO_TEMPLATE_DIR', $uploads['basedir'] . DS . 'espresso' . DS . 'templates' . DS); |
|
170 | + define('EVENT_ESPRESSO_TEMPLATE_URL', $uploads['baseurl'] . DS . 'espresso' . DS . 'templates' . DS); |
|
171 | + // define the gateway directory and URL |
|
172 | + define('EVENT_ESPRESSO_GATEWAY_DIR', $uploads['basedir'] . DS . 'espresso' . DS . 'gateways' . DS); |
|
173 | + define('EVENT_ESPRESSO_GATEWAY_URL', $uploads['baseurl'] . DS . 'espresso' . DS . 'gateways' . DS); |
|
174 | + // languages folder/path |
|
175 | + define('EE_LANGUAGES_SAFE_LOC', '..' . DS . 'uploads' . DS . 'espresso' . DS . 'languages' . DS); |
|
176 | + define('EE_LANGUAGES_SAFE_DIR', EVENT_ESPRESSO_UPLOAD_DIR . 'languages' . DS); |
|
177 | + //check for dompdf fonts in uploads |
|
178 | + if (file_exists(EVENT_ESPRESSO_UPLOAD_DIR . 'fonts' . DS)) { |
|
179 | + define('DOMPDF_FONT_DIR', EVENT_ESPRESSO_UPLOAD_DIR . 'fonts' . DS); |
|
180 | + } |
|
181 | + //ajax constants |
|
182 | + define( |
|
183 | + 'EE_FRONT_AJAX', |
|
184 | + isset($_REQUEST['ee_front_ajax']) || isset($_REQUEST['data']['ee_front_ajax']) ? true : false |
|
185 | + ); |
|
186 | + define( |
|
187 | + 'EE_ADMIN_AJAX', |
|
188 | + isset($_REQUEST['ee_admin_ajax']) || isset($_REQUEST['data']['ee_admin_ajax']) ? true : false |
|
189 | + ); |
|
190 | + //just a handy constant occasionally needed for finding values representing infinity in the DB |
|
191 | + //you're better to use this than its straight value (currently -1) in case you ever |
|
192 | + //want to change its default value! or find when -1 means infinity |
|
193 | + define('EE_INF_IN_DB', -1); |
|
194 | + define('EE_INF', INF > (float)PHP_INT_MAX ? INF : PHP_INT_MAX); |
|
195 | + define('EE_DEBUG', false); |
|
196 | + // for older WP versions |
|
197 | + if ( ! defined('MONTH_IN_SECONDS')) { |
|
198 | + define('MONTH_IN_SECONDS', DAY_IN_SECONDS * 30); |
|
199 | + } |
|
200 | + /** |
|
201 | + * espresso_plugin_activation |
|
202 | + * adds a wp-option to indicate that EE has been activated via the WP admin plugins page |
|
203 | + */ |
|
204 | + function espresso_plugin_activation() |
|
205 | + { |
|
206 | + update_option('ee_espresso_activation', true); |
|
207 | + } |
|
208 | 208 | |
209 | - register_activation_hook(EVENT_ESPRESSO_MAIN_FILE, 'espresso_plugin_activation'); |
|
210 | - /** |
|
211 | - * espresso_load_error_handling |
|
212 | - * this function loads EE's class for handling exceptions and errors |
|
213 | - */ |
|
214 | - function espresso_load_error_handling() |
|
215 | - { |
|
216 | - // load debugging tools |
|
217 | - if (WP_DEBUG === true && is_readable(EE_HELPERS . 'EEH_Debug_Tools.helper.php')) { |
|
218 | - require_once(EE_HELPERS . 'EEH_Debug_Tools.helper.php'); |
|
219 | - EEH_Debug_Tools::instance(); |
|
220 | - } |
|
221 | - // load error handling |
|
222 | - if (is_readable(EE_CORE . 'EE_Error.core.php')) { |
|
223 | - require_once(EE_CORE . 'EE_Error.core.php'); |
|
224 | - } else { |
|
225 | - wp_die(esc_html__('The EE_Error core class could not be loaded.', 'event_espresso')); |
|
226 | - } |
|
227 | - } |
|
209 | + register_activation_hook(EVENT_ESPRESSO_MAIN_FILE, 'espresso_plugin_activation'); |
|
210 | + /** |
|
211 | + * espresso_load_error_handling |
|
212 | + * this function loads EE's class for handling exceptions and errors |
|
213 | + */ |
|
214 | + function espresso_load_error_handling() |
|
215 | + { |
|
216 | + // load debugging tools |
|
217 | + if (WP_DEBUG === true && is_readable(EE_HELPERS . 'EEH_Debug_Tools.helper.php')) { |
|
218 | + require_once(EE_HELPERS . 'EEH_Debug_Tools.helper.php'); |
|
219 | + EEH_Debug_Tools::instance(); |
|
220 | + } |
|
221 | + // load error handling |
|
222 | + if (is_readable(EE_CORE . 'EE_Error.core.php')) { |
|
223 | + require_once(EE_CORE . 'EE_Error.core.php'); |
|
224 | + } else { |
|
225 | + wp_die(esc_html__('The EE_Error core class could not be loaded.', 'event_espresso')); |
|
226 | + } |
|
227 | + } |
|
228 | 228 | |
229 | - /** |
|
230 | - * espresso_load_required |
|
231 | - * given a class name and path, this function will load that file or throw an exception |
|
232 | - * |
|
233 | - * @param string $classname |
|
234 | - * @param string $full_path_to_file |
|
235 | - * @throws EE_Error |
|
236 | - */ |
|
237 | - function espresso_load_required($classname, $full_path_to_file) |
|
238 | - { |
|
239 | - static $error_handling_loaded = false; |
|
240 | - if ( ! $error_handling_loaded) { |
|
241 | - espresso_load_error_handling(); |
|
242 | - $error_handling_loaded = true; |
|
243 | - } |
|
244 | - if (is_readable($full_path_to_file)) { |
|
245 | - require_once($full_path_to_file); |
|
246 | - } else { |
|
247 | - throw new EE_Error ( |
|
248 | - sprintf( |
|
249 | - esc_html__( |
|
250 | - 'The %s class file could not be located or is not readable due to file permissions.', |
|
251 | - 'event_espresso' |
|
252 | - ), |
|
253 | - $classname |
|
254 | - ) |
|
255 | - ); |
|
256 | - } |
|
257 | - } |
|
229 | + /** |
|
230 | + * espresso_load_required |
|
231 | + * given a class name and path, this function will load that file or throw an exception |
|
232 | + * |
|
233 | + * @param string $classname |
|
234 | + * @param string $full_path_to_file |
|
235 | + * @throws EE_Error |
|
236 | + */ |
|
237 | + function espresso_load_required($classname, $full_path_to_file) |
|
238 | + { |
|
239 | + static $error_handling_loaded = false; |
|
240 | + if ( ! $error_handling_loaded) { |
|
241 | + espresso_load_error_handling(); |
|
242 | + $error_handling_loaded = true; |
|
243 | + } |
|
244 | + if (is_readable($full_path_to_file)) { |
|
245 | + require_once($full_path_to_file); |
|
246 | + } else { |
|
247 | + throw new EE_Error ( |
|
248 | + sprintf( |
|
249 | + esc_html__( |
|
250 | + 'The %s class file could not be located or is not readable due to file permissions.', |
|
251 | + 'event_espresso' |
|
252 | + ), |
|
253 | + $classname |
|
254 | + ) |
|
255 | + ); |
|
256 | + } |
|
257 | + } |
|
258 | 258 | |
259 | - espresso_load_required('EEH_Base', EE_CORE . 'helpers' . DS . 'EEH_Base.helper.php'); |
|
260 | - espresso_load_required('EEH_File', EE_CORE . 'helpers' . DS . 'EEH_File.helper.php'); |
|
261 | - espresso_load_required('EE_Bootstrap', EE_CORE . 'EE_Bootstrap.core.php'); |
|
262 | - new EE_Bootstrap(); |
|
263 | - } |
|
259 | + espresso_load_required('EEH_Base', EE_CORE . 'helpers' . DS . 'EEH_Base.helper.php'); |
|
260 | + espresso_load_required('EEH_File', EE_CORE . 'helpers' . DS . 'EEH_File.helper.php'); |
|
261 | + espresso_load_required('EE_Bootstrap', EE_CORE . 'EE_Bootstrap.core.php'); |
|
262 | + new EE_Bootstrap(); |
|
263 | + } |
|
264 | 264 | } |
265 | 265 | if ( ! function_exists('espresso_deactivate_plugin')) { |
266 | - /** |
|
267 | - * deactivate_plugin |
|
268 | - * usage: espresso_deactivate_plugin( plugin_basename( __FILE__ )); |
|
269 | - * |
|
270 | - * @access public |
|
271 | - * @param string $plugin_basename - the results of plugin_basename( __FILE__ ) for the plugin's main file |
|
272 | - * @return void |
|
273 | - */ |
|
274 | - function espresso_deactivate_plugin($plugin_basename = '') |
|
275 | - { |
|
276 | - if ( ! function_exists('deactivate_plugins')) { |
|
277 | - require_once(ABSPATH . 'wp-admin/includes/plugin.php'); |
|
278 | - } |
|
279 | - unset($_GET['activate'], $_REQUEST['activate']); |
|
280 | - deactivate_plugins($plugin_basename); |
|
281 | - } |
|
266 | + /** |
|
267 | + * deactivate_plugin |
|
268 | + * usage: espresso_deactivate_plugin( plugin_basename( __FILE__ )); |
|
269 | + * |
|
270 | + * @access public |
|
271 | + * @param string $plugin_basename - the results of plugin_basename( __FILE__ ) for the plugin's main file |
|
272 | + * @return void |
|
273 | + */ |
|
274 | + function espresso_deactivate_plugin($plugin_basename = '') |
|
275 | + { |
|
276 | + if ( ! function_exists('deactivate_plugins')) { |
|
277 | + require_once(ABSPATH . 'wp-admin/includes/plugin.php'); |
|
278 | + } |
|
279 | + unset($_GET['activate'], $_REQUEST['activate']); |
|
280 | + deactivate_plugins($plugin_basename); |
|
281 | + } |
|
282 | 282 | } |
283 | 283 | \ No newline at end of file |