| @@ -2,9 +2,6 @@ | ||
| 2 | 2 | |
| 3 | 3 | use EventEspresso\core\domain\Domain; | 
| 4 | 4 | use EventEspresso\core\domain\DomainFactory; | 
| 5 | -use EventEspresso\core\domain\values\FilePath; | |
| 6 | -use EventEspresso\core\domain\values\FullyQualifiedName; | |
| 7 | -use EventEspresso\core\domain\values\Version; | |
| 8 | 5 | use EventEspresso\core\exceptions\ExceptionStackTraceDisplay; | 
| 9 | 6 | use EventEspresso\core\exceptions\InvalidClassException; | 
| 10 | 7 | use EventEspresso\core\exceptions\InvalidDataTypeException; | 
| @@ -27,1236 +27,1236 @@ | ||
| 27 | 27 | final class EE_System implements ResettableInterface | 
| 28 | 28 |  { | 
| 29 | 29 | |
| 30 | - /** | |
| 31 | - * indicates this is a 'normal' request. Ie, not activation, nor upgrade, nor activation. | |
| 32 | - * So examples of this would be a normal GET request on the frontend or backend, or a POST, etc | |
| 33 | - */ | |
| 34 | - const req_type_normal = 0; | |
| 35 | - | |
| 36 | - /** | |
| 37 | - * Indicates this is a brand new installation of EE so we should install | |
| 38 | - * tables and default data etc | |
| 39 | - */ | |
| 40 | - const req_type_new_activation = 1; | |
| 41 | - | |
| 42 | - /** | |
| 43 | - * we've detected that EE has been reactivated (or EE was activated during maintenance mode, | |
| 44 | - * and we just exited maintenance mode). We MUST check the database is setup properly | |
| 45 | - * and that default data is setup too | |
| 46 | - */ | |
| 47 | - const req_type_reactivation = 2; | |
| 48 | - | |
| 49 | - /** | |
| 50 | - * indicates that EE has been upgraded since its previous request. | |
| 51 | - * We may have data migration scripts to call and will want to trigger maintenance mode | |
| 52 | - */ | |
| 53 | - const req_type_upgrade = 3; | |
| 54 | - | |
| 55 | - /** | |
| 56 | - * TODO will detect that EE has been DOWNGRADED. We probably don't want to run in this case... | |
| 57 | - */ | |
| 58 | - const req_type_downgrade = 4; | |
| 59 | - | |
| 60 | - /** | |
| 61 | - * @deprecated since version 4.6.0.dev.006 | |
| 62 | - * Now whenever a new_activation is detected the request type is still just | |
| 63 | - * new_activation (same for reactivation, upgrade, downgrade etc), but if we'r ein maintenance mode | |
| 64 | - * EE_System::initialize_db_if_no_migrations_required and EE_Addon::initialize_db_if_no_migrations_required | |
| 65 | - * will instead enqueue that EE plugin's db initialization for when we're taken out of maintenance mode. | |
| 66 | - * (Specifically, when the migration manager indicates migrations are finished | |
| 67 | - * EE_Data_Migration_Manager::initialize_db_for_enqueued_ee_plugins() will be called) | |
| 68 | - */ | |
| 69 | - const req_type_activation_but_not_installed = 5; | |
| 70 | - | |
| 71 | - /** | |
| 72 | - * option prefix for recording the activation history (like core's "espresso_db_update") of addons | |
| 73 | - */ | |
| 74 | - const addon_activation_history_option_prefix = 'ee_addon_activation_history_'; | |
| 75 | - | |
| 76 | - /** | |
| 77 | - * @var EE_System $_instance | |
| 78 | - */ | |
| 79 | - private static $_instance; | |
| 80 | - | |
| 81 | - /** | |
| 82 | - * @var EE_Registry $registry | |
| 83 | - */ | |
| 84 | - private $registry; | |
| 85 | - | |
| 86 | - /** | |
| 87 | - * @var LoaderInterface $loader | |
| 88 | - */ | |
| 89 | - private $loader; | |
| 90 | - | |
| 91 | - /** | |
| 92 | - * @var EE_Capabilities $capabilities | |
| 93 | - */ | |
| 94 | - private $capabilities; | |
| 95 | - | |
| 96 | - /** | |
| 97 | - * @var EE_Maintenance_Mode $maintenance_mode | |
| 98 | - */ | |
| 99 | - private $maintenance_mode; | |
| 100 | - | |
| 101 | - /** | |
| 102 | - * @var RequestInterface $request | |
| 103 | - */ | |
| 104 | - private $request; | |
| 105 | - | |
| 106 | - /** | |
| 107 | - * Stores which type of request this is, options being one of the constants on EE_System starting with req_type_*. | |
| 108 | - * It can be a brand-new activation, a reactivation, an upgrade, a downgrade, or a normal request. | |
| 109 | - * | |
| 110 | - * @var int $_req_type | |
| 111 | - */ | |
| 112 | - private $_req_type; | |
| 113 | - | |
| 114 | - /** | |
| 115 | - * Whether or not there was a non-micro version change in EE core version during this request | |
| 116 | - * | |
| 117 | - * @var boolean $_major_version_change | |
| 118 | - */ | |
| 119 | - private $_major_version_change = false; | |
| 120 | - | |
| 121 | - /** | |
| 122 | - * @var Router $router | |
| 123 | - */ | |
| 124 | - private $router; | |
| 125 | - | |
| 126 | - | |
| 127 | - /** | |
| 128 | - * @singleton method used to instantiate class object | |
| 129 | - * @param LoaderInterface $loader | |
| 130 | - * @param EE_Maintenance_Mode $maintenance_mode | |
| 131 | - * @param EE_Registry $registry | |
| 132 | - * @param RequestInterface $request | |
| 133 | - * @param Router $router | |
| 134 | - * @return EE_System | |
| 135 | - */ | |
| 136 | - public static function instance( | |
| 137 | - LoaderInterface $loader = null, | |
| 138 | - EE_Maintenance_Mode $maintenance_mode = null, | |
| 139 | - EE_Registry $registry = null, | |
| 140 | - RequestInterface $request = null, | |
| 141 | - Router $router = null | |
| 142 | -    ) { | |
| 143 | - // check if class object is instantiated | |
| 144 | -        if (! self::$_instance instanceof EE_System) { | |
| 145 | - self::$_instance = new self($loader, $maintenance_mode, $registry, $request, $router); | |
| 146 | - } | |
| 147 | - return self::$_instance; | |
| 148 | - } | |
| 149 | - | |
| 150 | - | |
| 151 | - /** | |
| 152 | - * resets the instance and returns it | |
| 153 | - * | |
| 154 | - * @return EE_System | |
| 155 | - */ | |
| 156 | - public static function reset() | |
| 157 | -    { | |
| 158 | - self::$_instance->_req_type = null; | |
| 159 | - // make sure none of the old hooks are left hanging around | |
| 160 | -        remove_all_actions('AHEE__EE_System__perform_activations_upgrades_and_migrations'); | |
| 161 | - // we need to reset the migration manager in order for it to detect DMSs properly | |
| 162 | - EE_Data_Migration_Manager::reset(); | |
| 163 | - self::instance()->detect_activations_or_upgrades(); | |
| 164 | - self::instance()->perform_activations_upgrades_and_migrations(); | |
| 165 | - return self::instance(); | |
| 166 | - } | |
| 167 | - | |
| 168 | - | |
| 169 | - /** | |
| 170 | - * sets hooks for running rest of system | |
| 171 | - * provides "AHEE__EE_System__construct__complete" hook for EE Addons to use as their starting point | |
| 172 | - * starting EE Addons from any other point may lead to problems | |
| 173 | - * | |
| 174 | - * @param LoaderInterface $loader | |
| 175 | - * @param EE_Maintenance_Mode $maintenance_mode | |
| 176 | - * @param EE_Registry $registry | |
| 177 | - * @param RequestInterface $request | |
| 178 | - * @param Router $router | |
| 179 | - */ | |
| 180 | - private function __construct( | |
| 181 | - LoaderInterface $loader, | |
| 182 | - EE_Maintenance_Mode $maintenance_mode, | |
| 183 | - EE_Registry $registry, | |
| 184 | - RequestInterface $request, | |
| 185 | - Router $router | |
| 186 | -    ) { | |
| 187 | - $this->registry = $registry; | |
| 188 | - $this->loader = $loader; | |
| 189 | - $this->request = $request; | |
| 190 | - $this->router = $router; | |
| 191 | - $this->maintenance_mode = $maintenance_mode; | |
| 192 | -        do_action('AHEE__EE_System__construct__begin', $this); | |
| 193 | - add_action( | |
| 194 | - 'AHEE__EE_Bootstrap__load_espresso_addons', | |
| 195 | - array($this, 'loadCapabilities'), | |
| 196 | - 5 | |
| 197 | - ); | |
| 198 | - add_action( | |
| 199 | - 'AHEE__EE_Bootstrap__load_espresso_addons', | |
| 200 | - array($this, 'loadCommandBus'), | |
| 201 | - 7 | |
| 202 | - ); | |
| 203 | - add_action( | |
| 204 | - 'AHEE__EE_Bootstrap__load_espresso_addons', | |
| 205 | - array($this, 'loadPluginApi'), | |
| 206 | - 9 | |
| 207 | - ); | |
| 208 | - // allow addons to load first so that they can register autoloaders, set hooks for running DMS's, etc | |
| 209 | - add_action( | |
| 210 | - 'AHEE__EE_Bootstrap__load_espresso_addons', | |
| 211 | - array($this, 'load_espresso_addons') | |
| 212 | - ); | |
| 213 | - // when an ee addon is activated, we want to call the core hook(s) again | |
| 214 | - // because the newly-activated addon didn't get a chance to run at all | |
| 215 | -        add_action('activate_plugin', array($this, 'load_espresso_addons'), 1); | |
| 216 | - // detect whether install or upgrade | |
| 217 | - add_action( | |
| 218 | - 'AHEE__EE_Bootstrap__detect_activations_or_upgrades', | |
| 219 | - array($this, 'detect_activations_or_upgrades'), | |
| 220 | - 3 | |
| 221 | - ); | |
| 222 | - // load EE_Config, EE_Textdomain, etc | |
| 223 | - add_action( | |
| 224 | - 'AHEE__EE_Bootstrap__load_core_configuration', | |
| 225 | - array($this, 'load_core_configuration'), | |
| 226 | - 5 | |
| 227 | - ); | |
| 228 | - // load specifications for matching routes to current request | |
| 229 | - add_action( | |
| 230 | - 'AHEE__EE_Bootstrap__load_core_configuration', | |
| 231 | - array($this, 'loadRouteMatchSpecifications') | |
| 232 | - ); | |
| 233 | - // load EE_Config, EE_Textdomain, etc | |
| 234 | - add_action( | |
| 235 | - 'AHEE__EE_Bootstrap__register_shortcodes_modules_and_widgets', | |
| 236 | - array($this, 'register_shortcodes_modules_and_widgets'), | |
| 237 | - 7 | |
| 238 | - ); | |
| 239 | - // you wanna get going? I wanna get going... let's get going! | |
| 240 | - add_action( | |
| 241 | - 'AHEE__EE_Bootstrap__brew_espresso', | |
| 242 | - array($this, 'brew_espresso'), | |
| 243 | - 9 | |
| 244 | - ); | |
| 245 | - // other housekeeping | |
| 246 | - // exclude EE critical pages from wp_list_pages | |
| 247 | - add_filter( | |
| 248 | - 'wp_list_pages_excludes', | |
| 249 | - array($this, 'remove_pages_from_wp_list_pages'), | |
| 250 | - 10 | |
| 251 | - ); | |
| 252 | - // ALL EE Addons should use the following hook point to attach their initial setup too | |
| 253 | - // it's extremely important for EE Addons to register any class autoloaders so that they can be available when the EE_Config loads | |
| 254 | -        do_action('AHEE__EE_System__construct__complete', $this); | |
| 255 | - } | |
| 256 | - | |
| 257 | - | |
| 258 | - /** | |
| 259 | - * load and setup EE_Capabilities | |
| 260 | - * | |
| 261 | - * @return void | |
| 262 | - */ | |
| 263 | - public function loadCapabilities() | |
| 264 | -    { | |
| 265 | -        $this->capabilities = $this->loader->getShared('EE_Capabilities'); | |
| 266 | - add_action( | |
| 267 | - 'AHEE__EE_Capabilities__init_caps__before_initialization', | |
| 268 | -            function () { | |
| 269 | -                LoaderFactory::getLoader()->getShared('EE_Payment_Method_Manager'); | |
| 270 | - } | |
| 271 | - ); | |
| 272 | - } | |
| 273 | - | |
| 274 | - | |
| 275 | - /** | |
| 276 | - * create and cache the CommandBus, and also add middleware | |
| 277 | - * The CapChecker middleware requires the use of EE_Capabilities | |
| 278 | - * which is why we need to load the CommandBus after Caps are set up | |
| 279 | - * | |
| 280 | - * @return void | |
| 281 | - */ | |
| 282 | - public function loadCommandBus() | |
| 283 | -    { | |
| 284 | - $this->loader->getShared( | |
| 285 | - 'CommandBusInterface', | |
| 286 | - array( | |
| 287 | - null, | |
| 288 | - apply_filters( | |
| 289 | - 'FHEE__EE_Load_Espresso_Core__handle_request__CommandBus_middleware', | |
| 290 | - array( | |
| 291 | -                        $this->loader->getShared('EventEspresso\core\services\commands\middleware\CapChecker'), | |
| 292 | -                        $this->loader->getShared('EventEspresso\core\services\commands\middleware\AddActionHook'), | |
| 293 | - ) | |
| 294 | - ), | |
| 295 | - ) | |
| 296 | - ); | |
| 297 | - } | |
| 298 | - | |
| 299 | - | |
| 300 | - /** | |
| 301 | - * @return void | |
| 302 | - * @throws EE_Error | |
| 303 | - */ | |
| 304 | - public function loadPluginApi() | |
| 305 | -    { | |
| 306 | - // set autoloaders for all of the classes implementing EEI_Plugin_API | |
| 307 | - // which provide helpers for EE plugin authors to more easily register certain components with EE. | |
| 308 | - EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_LIBRARIES . 'plugin_api'); | |
| 309 | -        $this->loader->getShared('EE_Request_Handler'); | |
| 310 | - } | |
| 311 | - | |
| 312 | - | |
| 313 | - /** | |
| 314 | - * @param string $addon_name | |
| 315 | - * @param string $version_constant | |
| 316 | - * @param string $min_version_required | |
| 317 | - * @param string $load_callback | |
| 318 | - * @param string $plugin_file_constant | |
| 319 | - * @return void | |
| 320 | - */ | |
| 321 | - private function deactivateIncompatibleAddon( | |
| 322 | - $addon_name, | |
| 323 | - $version_constant, | |
| 324 | - $min_version_required, | |
| 325 | - $load_callback, | |
| 326 | - $plugin_file_constant | |
| 327 | -    ) { | |
| 328 | -        if (! defined($version_constant)) { | |
| 329 | - return; | |
| 330 | - } | |
| 331 | - $addon_version = constant($version_constant); | |
| 332 | -        if ($addon_version && version_compare($addon_version, $min_version_required, '<')) { | |
| 333 | -            remove_action('AHEE__EE_System__load_espresso_addons', $load_callback); | |
| 334 | -            if (! function_exists('deactivate_plugins')) { | |
| 335 | - require_once ABSPATH . 'wp-admin/includes/plugin.php'; | |
| 336 | - } | |
| 337 | - deactivate_plugins(plugin_basename(constant($plugin_file_constant))); | |
| 338 | - unset($_GET['activate'], $_REQUEST['activate'], $_GET['activate-multi'], $_REQUEST['activate-multi']); | |
| 339 | - EE_Error::add_error( | |
| 340 | - sprintf( | |
| 341 | - esc_html__( | |
| 342 | - 'We\'re sorry, but the Event Espresso %1$s addon was deactivated because version %2$s or higher is required with this version of Event Espresso core.', | |
| 343 | - 'event_espresso' | |
| 344 | - ), | |
| 345 | - $addon_name, | |
| 346 | - $min_version_required | |
| 347 | - ), | |
| 348 | - __FILE__, | |
| 349 | -                __FUNCTION__ . "({$addon_name})", | |
| 350 | - __LINE__ | |
| 351 | - ); | |
| 352 | - EE_Error::get_notices(false, true); | |
| 353 | - } | |
| 354 | - } | |
| 355 | - | |
| 356 | - | |
| 357 | - /** | |
| 358 | - * load_espresso_addons | |
| 359 | - * allow addons to load first so that they can set hooks for running DMS's, etc | |
| 360 | - * this is hooked into both: | |
| 361 | - * 'AHEE__EE_Bootstrap__load_core_configuration' | |
| 362 | - * which runs during the WP 'plugins_loaded' action at priority 5 | |
| 363 | - * and the WP 'activate_plugin' hook point | |
| 364 | - * | |
| 365 | - * @access public | |
| 366 | - * @return void | |
| 367 | - */ | |
| 368 | - public function load_espresso_addons() | |
| 369 | -    { | |
| 370 | - $this->deactivateIncompatibleAddon( | |
| 371 | - 'Wait Lists', | |
| 372 | - 'EE_WAIT_LISTS_VERSION', | |
| 373 | - '1.0.0.beta.074', | |
| 374 | - 'load_espresso_wait_lists', | |
| 375 | - 'EE_WAIT_LISTS_PLUGIN_FILE' | |
| 376 | - ); | |
| 377 | - $this->deactivateIncompatibleAddon( | |
| 378 | - 'Automated Upcoming Event Notifications', | |
| 379 | - 'EE_AUTOMATED_UPCOMING_EVENT_NOTIFICATION_VERSION', | |
| 380 | - '1.0.0.beta.091', | |
| 381 | - 'load_espresso_automated_upcoming_event_notification', | |
| 382 | - 'EE_AUTOMATED_UPCOMING_EVENT_NOTIFICATION_PLUGIN_FILE' | |
| 383 | - ); | |
| 384 | -        do_action('AHEE__EE_System__load_espresso_addons'); | |
| 385 | - // if the WP API basic auth plugin isn't already loaded, load it now. | |
| 386 | - // We want it for mobile apps. Just include the entire plugin | |
| 387 | - // also, don't load the basic auth when a plugin is getting activated, because | |
| 388 | - // it could be the basic auth plugin, and it doesn't check if its methods are already defined | |
| 389 | - // and causes a fatal error | |
| 390 | - if (($this->request->isWordPressApi() || $this->request->isApi()) | |
| 391 | - && ! $this->request->isActivation() | |
| 392 | -            && ! function_exists('json_basic_auth_handler') | |
| 393 | -            && ! function_exists('json_basic_auth_error') | |
| 394 | -        ) { | |
| 395 | - include_once EE_THIRD_PARTY . 'wp-api-basic-auth/basic-auth.php'; | |
| 396 | - } | |
| 397 | -        do_action('AHEE__EE_System__load_espresso_addons__complete'); | |
| 398 | - } | |
| 399 | - | |
| 400 | - | |
| 401 | - /** | |
| 402 | - * detect_activations_or_upgrades | |
| 403 | - * Checks for activation or upgrade of core first; | |
| 404 | - * then also checks if any registered addons have been activated or upgraded | |
| 405 | - * This is hooked into 'AHEE__EE_Bootstrap__detect_activations_or_upgrades' | |
| 406 | - * which runs during the WP 'plugins_loaded' action at priority 3 | |
| 407 | - * | |
| 408 | - * @access public | |
| 409 | - * @return void | |
| 410 | - */ | |
| 411 | - public function detect_activations_or_upgrades() | |
| 412 | -    { | |
| 413 | - // first off: let's make sure to handle core | |
| 414 | - $this->detect_if_activation_or_upgrade(); | |
| 415 | -        foreach ($this->registry->addons as $addon) { | |
| 416 | -            if ($addon instanceof EE_Addon) { | |
| 417 | - // detect teh request type for that addon | |
| 418 | - $addon->detect_activation_or_upgrade(); | |
| 419 | - } | |
| 420 | - } | |
| 421 | - } | |
| 422 | - | |
| 423 | - | |
| 424 | - /** | |
| 425 | - * detect_if_activation_or_upgrade | |
| 426 | - * Takes care of detecting whether this is a brand new install or code upgrade, | |
| 427 | - * and either setting up the DB or setting up maintenance mode etc. | |
| 428 | - * | |
| 429 | - * @access public | |
| 430 | - * @return void | |
| 431 | - */ | |
| 432 | - public function detect_if_activation_or_upgrade() | |
| 433 | -    { | |
| 434 | -        do_action('AHEE__EE_System___detect_if_activation_or_upgrade__begin'); | |
| 435 | - // check if db has been updated, or if its a brand-new installation | |
| 436 | - $espresso_db_update = $this->fix_espresso_db_upgrade_option(); | |
| 437 | - $request_type = $this->detect_req_type($espresso_db_update); | |
| 438 | - // EEH_Debug_Tools::printr( $request_type, '$request_type', __FILE__, __LINE__ ); | |
| 439 | -        switch ($request_type) { | |
| 440 | - case EE_System::req_type_new_activation: | |
| 441 | -                do_action('AHEE__EE_System__detect_if_activation_or_upgrade__new_activation'); | |
| 442 | - $this->_handle_core_version_change($espresso_db_update); | |
| 443 | - break; | |
| 444 | - case EE_System::req_type_reactivation: | |
| 445 | -                do_action('AHEE__EE_System__detect_if_activation_or_upgrade__reactivation'); | |
| 446 | - $this->_handle_core_version_change($espresso_db_update); | |
| 447 | - break; | |
| 448 | - case EE_System::req_type_upgrade: | |
| 449 | -                do_action('AHEE__EE_System__detect_if_activation_or_upgrade__upgrade'); | |
| 450 | - // migrations may be required now that we've upgraded | |
| 451 | - $this->maintenance_mode->set_maintenance_mode_if_db_old(); | |
| 452 | - $this->_handle_core_version_change($espresso_db_update); | |
| 453 | - break; | |
| 454 | - case EE_System::req_type_downgrade: | |
| 455 | -                do_action('AHEE__EE_System__detect_if_activation_or_upgrade__downgrade'); | |
| 456 | - // its possible migrations are no longer required | |
| 457 | - $this->maintenance_mode->set_maintenance_mode_if_db_old(); | |
| 458 | - $this->_handle_core_version_change($espresso_db_update); | |
| 459 | - break; | |
| 460 | - case EE_System::req_type_normal: | |
| 461 | - default: | |
| 462 | - break; | |
| 463 | - } | |
| 464 | -        do_action('AHEE__EE_System__detect_if_activation_or_upgrade__complete'); | |
| 465 | - } | |
| 466 | - | |
| 467 | - | |
| 468 | - /** | |
| 469 | - * Updates the list of installed versions and sets hooks for | |
| 470 | - * initializing the database later during the request | |
| 471 | - * | |
| 472 | - * @param array $espresso_db_update | |
| 473 | - */ | |
| 474 | - private function _handle_core_version_change($espresso_db_update) | |
| 475 | -    { | |
| 476 | - $this->update_list_of_installed_versions($espresso_db_update); | |
| 477 | - // get ready to verify the DB is ok (provided we aren't in maintenance mode, of course) | |
| 478 | - add_action( | |
| 479 | - 'AHEE__EE_System__perform_activations_upgrades_and_migrations', | |
| 480 | - array($this, 'initialize_db_if_no_migrations_required') | |
| 481 | - ); | |
| 482 | - } | |
| 483 | - | |
| 484 | - | |
| 485 | - /** | |
| 486 | - * standardizes the wp option 'espresso_db_upgrade' which actually stores | |
| 487 | - * information about what versions of EE have been installed and activated, | |
| 488 | - * NOT necessarily the state of the database | |
| 489 | - * | |
| 490 | - * @param mixed $espresso_db_update the value of the WordPress option. | |
| 491 | - * If not supplied, fetches it from the options table | |
| 492 | - * @return array the correct value of 'espresso_db_upgrade', after saving it, if it needed correction | |
| 493 | - */ | |
| 494 | - private function fix_espresso_db_upgrade_option($espresso_db_update = null) | |
| 495 | -    { | |
| 496 | -        do_action('FHEE__EE_System__manage_fix_espresso_db_upgrade_option__begin', $espresso_db_update); | |
| 497 | -        if (! $espresso_db_update) { | |
| 498 | -            $espresso_db_update = get_option('espresso_db_update'); | |
| 499 | - } | |
| 500 | - // check that option is an array | |
| 501 | -        if (! is_array($espresso_db_update)) { | |
| 502 | - // if option is FALSE, then it never existed | |
| 503 | -            if ($espresso_db_update === false) { | |
| 504 | - // make $espresso_db_update an array and save option with autoload OFF | |
| 505 | - $espresso_db_update = array(); | |
| 506 | -                add_option('espresso_db_update', $espresso_db_update, '', 'no'); | |
| 507 | -            } else { | |
| 508 | - // option is NOT FALSE but also is NOT an array, so make it an array and save it | |
| 509 | - $espresso_db_update = array($espresso_db_update => array()); | |
| 510 | -                update_option('espresso_db_update', $espresso_db_update); | |
| 511 | - } | |
| 512 | -        } else { | |
| 513 | - $corrected_db_update = array(); | |
| 514 | - // if IS an array, but is it an array where KEYS are version numbers, and values are arrays? | |
| 515 | -            foreach ($espresso_db_update as $should_be_version_string => $should_be_array) { | |
| 516 | -                if (is_int($should_be_version_string) && ! is_array($should_be_array)) { | |
| 517 | - // the key is an int, and the value IS NOT an array | |
| 518 | - // so it must be numerically-indexed, where values are versions installed... | |
| 519 | - // fix it! | |
| 520 | - $version_string = $should_be_array; | |
| 521 | -                    $corrected_db_update[ $version_string ] = array('unknown-date'); | |
| 522 | -                } else { | |
| 523 | - // ok it checks out | |
| 524 | - $corrected_db_update[ $should_be_version_string ] = $should_be_array; | |
| 525 | - } | |
| 526 | - } | |
| 527 | - $espresso_db_update = $corrected_db_update; | |
| 528 | -            update_option('espresso_db_update', $espresso_db_update); | |
| 529 | - } | |
| 530 | -        do_action('FHEE__EE_System__manage_fix_espresso_db_upgrade_option__complete', $espresso_db_update); | |
| 531 | - return $espresso_db_update; | |
| 532 | - } | |
| 533 | - | |
| 534 | - | |
| 535 | - /** | |
| 536 | - * Does the traditional work of setting up the plugin's database and adding default data. | |
| 537 | - * If migration script/process did not exist, this is what would happen on every activation/reactivation/upgrade. | |
| 538 | - * NOTE: if we're in maintenance mode (which would be the case if we detect there are data | |
| 539 | - * migration scripts that need to be run and a version change happens), enqueues core for database initialization, | |
| 540 | - * so that it will be done when migrations are finished | |
| 541 | - * | |
| 542 | - * @param boolean $initialize_addons_too if true, we double-check addons' database tables etc too; | |
| 543 | - * @param boolean $verify_schema if true will re-check the database tables have the correct schema. | |
| 544 | - * This is a resource-intensive job | |
| 545 | - * so we prefer to only do it when necessary | |
| 546 | - * @return void | |
| 547 | - * @throws EE_Error | |
| 548 | - */ | |
| 549 | - public function initialize_db_if_no_migrations_required($initialize_addons_too = false, $verify_schema = true) | |
| 550 | -    { | |
| 551 | - $request_type = $this->detect_req_type(); | |
| 552 | - // only initialize system if we're not in maintenance mode. | |
| 553 | -        if ($this->maintenance_mode->level() !== EE_Maintenance_Mode::level_2_complete_maintenance) { | |
| 554 | - /** @var EventEspresso\core\domain\services\custom_post_types\RewriteRules $rewrite_rules */ | |
| 555 | - $rewrite_rules = $this->loader->getShared( | |
| 556 | - 'EventEspresso\core\domain\services\custom_post_types\RewriteRules' | |
| 557 | - ); | |
| 558 | - $rewrite_rules->flush(); | |
| 559 | -            if ($verify_schema) { | |
| 560 | - EEH_Activation::initialize_db_and_folders(); | |
| 561 | - } | |
| 562 | - EEH_Activation::initialize_db_content(); | |
| 563 | - EEH_Activation::system_initialization(); | |
| 564 | -            if ($initialize_addons_too) { | |
| 565 | - $this->initialize_addons(); | |
| 566 | - } | |
| 567 | -        } else { | |
| 568 | -            EE_Data_Migration_Manager::instance()->enqueue_db_initialization_for('Core'); | |
| 569 | - } | |
| 570 | - if ($request_type === EE_System::req_type_new_activation | |
| 571 | - || $request_type === EE_System::req_type_reactivation | |
| 572 | - || ( | |
| 573 | - $request_type === EE_System::req_type_upgrade | |
| 574 | - && $this->is_major_version_change() | |
| 575 | - ) | |
| 576 | -        ) { | |
| 577 | -            add_action('AHEE__EE_System__initialize_last', array($this, 'redirect_to_about_ee'), 9); | |
| 578 | - } | |
| 579 | - } | |
| 580 | - | |
| 581 | - | |
| 582 | - /** | |
| 583 | - * Initializes the db for all registered addons | |
| 584 | - * | |
| 585 | - * @throws EE_Error | |
| 586 | - */ | |
| 587 | - public function initialize_addons() | |
| 588 | -    { | |
| 589 | - // foreach registered addon, make sure its db is up-to-date too | |
| 590 | -        foreach ($this->registry->addons as $addon) { | |
| 591 | -            if ($addon instanceof EE_Addon) { | |
| 592 | - $addon->initialize_db_if_no_migrations_required(); | |
| 593 | - } | |
| 594 | - } | |
| 595 | - } | |
| 596 | - | |
| 597 | - | |
| 598 | - /** | |
| 599 | - * Adds the current code version to the saved wp option which stores a list of all ee versions ever installed. | |
| 600 | - * | |
| 601 | - * @param array $version_history | |
| 602 | - * @param string $current_version_to_add version to be added to the version history | |
| 603 | - * @return boolean success as to whether or not this option was changed | |
| 604 | - */ | |
| 605 | - public function update_list_of_installed_versions($version_history = null, $current_version_to_add = null) | |
| 606 | -    { | |
| 607 | -        if (! $version_history) { | |
| 608 | - $version_history = $this->fix_espresso_db_upgrade_option($version_history); | |
| 609 | - } | |
| 610 | -        if ($current_version_to_add === null) { | |
| 611 | - $current_version_to_add = espresso_version(); | |
| 612 | - } | |
| 613 | -        $version_history[ $current_version_to_add ][] = date('Y-m-d H:i:s', time()); | |
| 614 | - // re-save | |
| 615 | -        return update_option('espresso_db_update', $version_history); | |
| 616 | - } | |
| 617 | - | |
| 618 | - | |
| 619 | - /** | |
| 620 | - * Detects if the current version indicated in the has existed in the list of | |
| 621 | - * previously-installed versions of EE (espresso_db_update). Does NOT modify it (ie, no side-effect) | |
| 622 | - * | |
| 623 | - * @param array $espresso_db_update array from the wp option stored under the name 'espresso_db_update'. | |
| 624 | - * If not supplied, fetches it from the options table. | |
| 625 | - * Also, caches its result so later parts of the code can also know whether | |
| 626 | - * there's been an update or not. This way we can add the current version to | |
| 627 | - * espresso_db_update, but still know if this is a new install or not | |
| 628 | - * @return int one of the constants on EE_System::req_type_ | |
| 629 | - */ | |
| 630 | - public function detect_req_type($espresso_db_update = null) | |
| 631 | -    { | |
| 632 | -        if ($this->_req_type === null) { | |
| 633 | - $espresso_db_update = ! empty($espresso_db_update) | |
| 634 | - ? $espresso_db_update | |
| 635 | - : $this->fix_espresso_db_upgrade_option(); | |
| 636 | - $this->_req_type = EE_System::detect_req_type_given_activation_history( | |
| 637 | - $espresso_db_update, | |
| 638 | - 'ee_espresso_activation', | |
| 639 | - espresso_version() | |
| 640 | - ); | |
| 641 | - $this->_major_version_change = $this->_detect_major_version_change($espresso_db_update); | |
| 642 | - $this->request->setIsActivation($this->_req_type !== EE_System::req_type_normal); | |
| 643 | - } | |
| 644 | - return $this->_req_type; | |
| 645 | - } | |
| 646 | - | |
| 647 | - | |
| 648 | - /** | |
| 649 | - * Returns whether or not there was a non-micro version change (ie, change in either | |
| 650 | - * the first or second number in the version. Eg 4.9.0.rc.001 to 4.10.0.rc.000, | |
| 651 | - * but not 4.9.0.rc.0001 to 4.9.1.rc.0001 | |
| 652 | - * | |
| 653 | - * @param $activation_history | |
| 654 | - * @return bool | |
| 655 | - */ | |
| 656 | - private function _detect_major_version_change($activation_history) | |
| 657 | -    { | |
| 658 | - $previous_version = EE_System::_get_most_recently_active_version_from_activation_history($activation_history); | |
| 659 | -        $previous_version_parts = explode('.', $previous_version); | |
| 660 | -        $current_version_parts = explode('.', espresso_version()); | |
| 661 | - return isset($previous_version_parts[0], $previous_version_parts[1], $current_version_parts[0], $current_version_parts[1]) | |
| 662 | - && ( | |
| 663 | - $previous_version_parts[0] !== $current_version_parts[0] | |
| 664 | - || $previous_version_parts[1] !== $current_version_parts[1] | |
| 665 | - ); | |
| 666 | - } | |
| 667 | - | |
| 668 | - | |
| 669 | - /** | |
| 670 | - * Returns true if either the major or minor version of EE changed during this request. | |
| 671 | - * Eg 4.9.0.rc.001 to 4.10.0.rc.000, but not 4.9.0.rc.0001 to 4.9.1.rc.0001 | |
| 672 | - * | |
| 673 | - * @return bool | |
| 674 | - */ | |
| 675 | - public function is_major_version_change() | |
| 676 | -    { | |
| 677 | - return $this->_major_version_change; | |
| 678 | - } | |
| 679 | - | |
| 680 | - | |
| 681 | - /** | |
| 682 | - * Determines the request type for any ee addon, given three piece of info: the current array of activation | |
| 683 | - * histories (for core that' 'espresso_db_update' wp option); the name of the WordPress option which is temporarily | |
| 684 | - * set upon activation of the plugin (for core it's 'ee_espresso_activation'); and the version that this plugin was | |
| 685 | - * just activated to (for core that will always be espresso_version()) | |
| 686 | - * | |
| 687 | - * @param array $activation_history_for_addon the option's value which stores the activation history for this | |
| 688 | - * ee plugin. for core that's 'espresso_db_update' | |
| 689 | - * @param string $activation_indicator_option_name the name of the WordPress option that is temporarily set to | |
| 690 | - * indicate that this plugin was just activated | |
| 691 | - * @param string $version_to_upgrade_to the version that was just upgraded to (for core that will be | |
| 692 | - * espresso_version()) | |
| 693 | - * @return int one of the constants on EE_System::req_type_* | |
| 694 | - */ | |
| 695 | - public static function detect_req_type_given_activation_history( | |
| 696 | - $activation_history_for_addon, | |
| 697 | - $activation_indicator_option_name, | |
| 698 | - $version_to_upgrade_to | |
| 699 | -    ) { | |
| 700 | - $version_is_higher = self::_new_version_is_higher($activation_history_for_addon, $version_to_upgrade_to); | |
| 701 | -        if ($activation_history_for_addon) { | |
| 702 | - // it exists, so this isn't a completely new install | |
| 703 | - // check if this version already in that list of previously installed versions | |
| 704 | -            if (! isset($activation_history_for_addon[ $version_to_upgrade_to ])) { | |
| 705 | - // it a version we haven't seen before | |
| 706 | -                if ($version_is_higher === 1) { | |
| 707 | - $req_type = EE_System::req_type_upgrade; | |
| 708 | -                } else { | |
| 709 | - $req_type = EE_System::req_type_downgrade; | |
| 710 | - } | |
| 711 | - delete_option($activation_indicator_option_name); | |
| 712 | -            } else { | |
| 713 | - // its not an update. maybe a reactivation? | |
| 714 | -                if (get_option($activation_indicator_option_name, false)) { | |
| 715 | -                    if ($version_is_higher === -1) { | |
| 716 | - $req_type = EE_System::req_type_downgrade; | |
| 717 | -                    } elseif ($version_is_higher === 0) { | |
| 718 | - // we've seen this version before, but it's an activation. must be a reactivation | |
| 719 | - $req_type = EE_System::req_type_reactivation; | |
| 720 | -                    } else {// $version_is_higher === 1 | |
| 721 | - $req_type = EE_System::req_type_upgrade; | |
| 722 | - } | |
| 723 | - delete_option($activation_indicator_option_name); | |
| 724 | -                } else { | |
| 725 | - // we've seen this version before and the activation indicate doesn't show it was just activated | |
| 726 | -                    if ($version_is_higher === -1) { | |
| 727 | - $req_type = EE_System::req_type_downgrade; | |
| 728 | -                    } elseif ($version_is_higher === 0) { | |
| 729 | - // we've seen this version before and it's not an activation. its normal request | |
| 730 | - $req_type = EE_System::req_type_normal; | |
| 731 | -                    } else {// $version_is_higher === 1 | |
| 732 | - $req_type = EE_System::req_type_upgrade; | |
| 733 | - } | |
| 734 | - } | |
| 735 | - } | |
| 736 | -        } else { | |
| 737 | - // brand new install | |
| 738 | - $req_type = EE_System::req_type_new_activation; | |
| 739 | - delete_option($activation_indicator_option_name); | |
| 740 | - } | |
| 741 | - return $req_type; | |
| 742 | - } | |
| 743 | - | |
| 744 | - | |
| 745 | - /** | |
| 746 | - * Detects if the $version_to_upgrade_to is higher than the most recent version in | |
| 747 | - * the $activation_history_for_addon | |
| 748 | - * | |
| 749 | - * @param array $activation_history_for_addon (keys are versions, values are arrays of times activated, | |
| 750 | - * sometimes containing 'unknown-date' | |
| 751 | - * @param string $version_to_upgrade_to (current version) | |
| 752 | - * @return int results of version_compare( $version_to_upgrade_to, $most_recently_active_version ). | |
| 753 | - * ie, -1 if $version_to_upgrade_to is LOWER (downgrade); | |
| 754 | - * 0 if $version_to_upgrade_to MATCHES (reactivation or normal request); | |
| 755 | - * 1 if $version_to_upgrade_to is HIGHER (upgrade) ; | |
| 756 | - */ | |
| 757 | - private static function _new_version_is_higher($activation_history_for_addon, $version_to_upgrade_to) | |
| 758 | -    { | |
| 759 | - // find the most recently-activated version | |
| 760 | - $most_recently_active_version = | |
| 761 | - EE_System::_get_most_recently_active_version_from_activation_history($activation_history_for_addon); | |
| 762 | - return version_compare($version_to_upgrade_to, $most_recently_active_version); | |
| 763 | - } | |
| 764 | - | |
| 765 | - | |
| 766 | - /** | |
| 767 | - * Gets the most recently active version listed in the activation history, | |
| 768 | - * and if none are found (ie, it's a brand new install) returns '0.0.0.dev.000'. | |
| 769 | - * | |
| 770 | - * @param array $activation_history (keys are versions, values are arrays of times activated, | |
| 771 | - * sometimes containing 'unknown-date' | |
| 772 | - * @return string | |
| 773 | - */ | |
| 774 | - private static function _get_most_recently_active_version_from_activation_history($activation_history) | |
| 775 | -    { | |
| 776 | - $most_recently_active_version_activation = '1970-01-01 00:00:00'; | |
| 777 | - $most_recently_active_version = '0.0.0.dev.000'; | |
| 778 | -        if (is_array($activation_history)) { | |
| 779 | -            foreach ($activation_history as $version => $times_activated) { | |
| 780 | - // check there is a record of when this version was activated. Otherwise, | |
| 781 | - // mark it as unknown | |
| 782 | -                if (! $times_activated) { | |
| 783 | -                    $times_activated = array('unknown-date'); | |
| 784 | - } | |
| 785 | -                if (is_string($times_activated)) { | |
| 786 | - $times_activated = array($times_activated); | |
| 787 | - } | |
| 788 | -                foreach ($times_activated as $an_activation) { | |
| 789 | - if ($an_activation !== 'unknown-date' | |
| 790 | - && $an_activation | |
| 791 | -                           > $most_recently_active_version_activation) { | |
| 792 | - $most_recently_active_version = $version; | |
| 793 | - $most_recently_active_version_activation = $an_activation === 'unknown-date' | |
| 794 | - ? '1970-01-01 00:00:00' | |
| 795 | - : $an_activation; | |
| 796 | - } | |
| 797 | - } | |
| 798 | - } | |
| 799 | - } | |
| 800 | - return $most_recently_active_version; | |
| 801 | - } | |
| 802 | - | |
| 803 | - | |
| 804 | - /** | |
| 805 | - * This redirects to the about EE page after activation | |
| 806 | - * | |
| 807 | - * @return void | |
| 808 | - */ | |
| 809 | - public function redirect_to_about_ee() | |
| 810 | -    { | |
| 811 | - $notices = EE_Error::get_notices(false); | |
| 812 | - // if current user is an admin and it's not an ajax or rest request | |
| 813 | - if (! isset($notices['errors']) | |
| 814 | - && $this->request->isAdmin() | |
| 815 | - && apply_filters( | |
| 816 | - 'FHEE__EE_System__redirect_to_about_ee__do_redirect', | |
| 817 | -                $this->capabilities->current_user_can('manage_options', 'espresso_about_default') | |
| 818 | - ) | |
| 819 | -        ) { | |
| 820 | -            $query_params = array('page' => 'espresso_about'); | |
| 821 | -            if (EE_System::instance()->detect_req_type() === EE_System::req_type_new_activation) { | |
| 822 | - $query_params['new_activation'] = true; | |
| 823 | - } | |
| 824 | -            if (EE_System::instance()->detect_req_type() === EE_System::req_type_reactivation) { | |
| 825 | - $query_params['reactivation'] = true; | |
| 826 | - } | |
| 827 | -            $url = add_query_arg($query_params, admin_url('admin.php')); | |
| 828 | - wp_safe_redirect($url); | |
| 829 | - exit(); | |
| 830 | - } | |
| 831 | - } | |
| 832 | - | |
| 833 | - | |
| 834 | - /** | |
| 835 | - * load_core_configuration | |
| 836 | - * this is hooked into 'AHEE__EE_Bootstrap__load_core_configuration' | |
| 837 | - * which runs during the WP 'plugins_loaded' action at priority 5 | |
| 838 | - * | |
| 839 | - * @return void | |
| 840 | - * @throws ReflectionException | |
| 841 | - * @throws Exception | |
| 842 | - */ | |
| 843 | - public function load_core_configuration() | |
| 844 | -    { | |
| 845 | -        do_action('AHEE__EE_System__load_core_configuration__begin', $this); | |
| 846 | -        $this->loader->getShared('EE_Load_Textdomain'); | |
| 847 | - // load textdomain | |
| 848 | - EE_Load_Textdomain::load_textdomain(); | |
| 849 | - // load caf stuff a chance to play during the activation process too. | |
| 850 | - $this->_maybe_brew_regular(); | |
| 851 | - // load and setup EE_Config and EE_Network_Config | |
| 852 | -        $config = $this->loader->getShared('EE_Config'); | |
| 853 | -        $this->loader->getShared('EE_Network_Config'); | |
| 854 | - // setup autoloaders | |
| 855 | - // enable logging? | |
| 856 | -        if ($config->admin->use_remote_logging) { | |
| 857 | -            $this->loader->getShared('EE_Log'); | |
| 858 | - } | |
| 859 | - // check for activation errors | |
| 860 | -        $activation_errors = get_option('ee_plugin_activation_errors', false); | |
| 861 | -        if ($activation_errors) { | |
| 862 | - EE_Error::add_error($activation_errors, __FILE__, __FUNCTION__, __LINE__); | |
| 863 | -            update_option('ee_plugin_activation_errors', false); | |
| 864 | - } | |
| 865 | - // get model names | |
| 866 | - $this->_parse_model_names(); | |
| 867 | - // configure custom post type definitions | |
| 868 | -        $this->loader->getShared('EventEspresso\core\domain\entities\custom_post_types\CustomTaxonomyDefinitions'); | |
| 869 | -        $this->loader->getShared('EventEspresso\core\domain\entities\custom_post_types\CustomPostTypeDefinitions'); | |
| 870 | -        do_action('AHEE__EE_System__load_core_configuration__complete', $this); | |
| 871 | - } | |
| 872 | - | |
| 873 | - | |
| 874 | - /** | |
| 875 | - * cycles through all of the models/*.model.php files, and assembles an array of model names | |
| 876 | - * | |
| 877 | - * @return void | |
| 878 | - * @throws ReflectionException | |
| 879 | - */ | |
| 880 | - private function _parse_model_names() | |
| 881 | -    { | |
| 882 | - // get all the files in the EE_MODELS folder that end in .model.php | |
| 883 | - $models = glob(EE_MODELS . '*.model.php'); | |
| 884 | - $model_names = array(); | |
| 885 | - $non_abstract_db_models = array(); | |
| 886 | -        foreach ($models as $model) { | |
| 887 | - // get model classname | |
| 888 | - $classname = EEH_File::get_classname_from_filepath_with_standard_filename($model); | |
| 889 | -            $short_name = str_replace('EEM_', '', $classname); | |
| 890 | - $reflectionClass = new ReflectionClass($classname); | |
| 891 | -            if ($reflectionClass->isSubclassOf('EEM_Base') && ! $reflectionClass->isAbstract()) { | |
| 892 | - $non_abstract_db_models[ $short_name ] = $classname; | |
| 893 | - } | |
| 894 | - $model_names[ $short_name ] = $classname; | |
| 895 | - } | |
| 896 | -        $this->registry->models = apply_filters('FHEE__EE_System__parse_model_names', $model_names); | |
| 897 | - $this->registry->non_abstract_db_models = apply_filters( | |
| 898 | - 'FHEE__EE_System__parse_implemented_model_names', | |
| 899 | - $non_abstract_db_models | |
| 900 | - ); | |
| 901 | - } | |
| 902 | - | |
| 903 | - | |
| 904 | - /** | |
| 905 | - * The purpose of this method is to simply check for a file named "caffeinated/brewing_regular.php" for any hooks | |
| 906 | - * that need to be setup before our EE_System launches. | |
| 907 | - * | |
| 908 | - * @return void | |
| 909 | - * @throws DomainException | |
| 910 | - * @throws InvalidArgumentException | |
| 911 | - * @throws InvalidDataTypeException | |
| 912 | - * @throws InvalidInterfaceException | |
| 913 | - * @throws InvalidClassException | |
| 914 | - * @throws InvalidFilePathException | |
| 915 | - */ | |
| 916 | - private function _maybe_brew_regular() | |
| 917 | -    { | |
| 918 | - /** @var Domain $domain */ | |
| 919 | - $domain = DomainFactory::getEventEspressoCoreDomain(); | |
| 920 | -        if ($domain->isCaffeinated()) { | |
| 921 | - require_once EE_CAFF_PATH . 'brewing_regular.php'; | |
| 922 | - } | |
| 923 | - } | |
| 924 | - | |
| 925 | - | |
| 926 | - /** | |
| 927 | - * @since 4.9.71.p | |
| 928 | - * @throws Exception | |
| 929 | - */ | |
| 930 | - public function loadRouteMatchSpecifications() | |
| 931 | -    { | |
| 932 | -        try { | |
| 933 | -            $this->loader->getShared('EventEspresso\core\services\routing\RouteMatchSpecificationManager'); | |
| 934 | -            $this->loader->getShared('EventEspresso\core\services\routing\RouteCollection'); | |
| 935 | - $this->router->loadPrimaryRoutes(); | |
| 936 | -        } catch (Exception $exception) { | |
| 937 | - new ExceptionStackTraceDisplay($exception); | |
| 938 | - } | |
| 939 | -        do_action('AHEE__EE_System__loadRouteMatchSpecifications'); | |
| 940 | - } | |
| 941 | - | |
| 942 | - | |
| 943 | - /** | |
| 944 | - * register_shortcodes_modules_and_widgets | |
| 945 | - * generate lists of shortcodes and modules, then verify paths and classes | |
| 946 | - * This is hooked into 'AHEE__EE_Bootstrap__register_shortcodes_modules_and_widgets' | |
| 947 | - * which runs during the WP 'plugins_loaded' action at priority 7 | |
| 948 | - * | |
| 949 | - * @access public | |
| 950 | - * @return void | |
| 951 | - * @throws Exception | |
| 952 | - */ | |
| 953 | - public function register_shortcodes_modules_and_widgets() | |
| 954 | -    { | |
| 955 | - $this->router->registerShortcodesModulesAndWidgets(); | |
| 956 | -        do_action('AHEE__EE_System__register_shortcodes_modules_and_widgets'); | |
| 957 | - // check for addons using old hook point | |
| 958 | -        if (has_action('AHEE__EE_System__register_shortcodes_modules_and_addons')) { | |
| 959 | - $this->_incompatible_addon_error(); | |
| 960 | - } | |
| 961 | - } | |
| 962 | - | |
| 963 | - | |
| 964 | - /** | |
| 965 | - * _incompatible_addon_error | |
| 966 | - * | |
| 967 | - * @access public | |
| 968 | - * @return void | |
| 969 | - */ | |
| 970 | - private function _incompatible_addon_error() | |
| 971 | -    { | |
| 972 | - // get array of classes hooking into here | |
| 973 | - $class_names = EEH_Class_Tools::get_class_names_for_all_callbacks_on_hook( | |
| 974 | - 'AHEE__EE_System__register_shortcodes_modules_and_addons' | |
| 975 | - ); | |
| 976 | -        if (! empty($class_names)) { | |
| 977 | - $msg = __( | |
| 978 | - 'The following plugins, addons, or modules appear to be incompatible with this version of Event Espresso and were automatically deactivated to avoid fatal errors:', | |
| 979 | - 'event_espresso' | |
| 980 | - ); | |
| 981 | - $msg .= '<ul>'; | |
| 982 | -            foreach ($class_names as $class_name) { | |
| 983 | - $msg .= '<li><b>Event Espresso - ' | |
| 984 | - . str_replace( | |
| 985 | -                            array('EE_', 'EEM_', 'EED_', 'EES_', 'EEW_'), | |
| 986 | - '', | |
| 987 | - $class_name | |
| 988 | - ) . '</b></li>'; | |
| 989 | - } | |
| 990 | - $msg .= '</ul>'; | |
| 991 | - $msg .= __( | |
| 992 | - 'Compatibility issues can be avoided and/or resolved by keeping addons and plugins updated to the latest version.', | |
| 993 | - 'event_espresso' | |
| 994 | - ); | |
| 995 | - // save list of incompatible addons to wp-options for later use | |
| 996 | -            add_option('ee_incompatible_addons', $class_names, '', 'no'); | |
| 997 | -            if (is_admin()) { | |
| 998 | - EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); | |
| 999 | - } | |
| 1000 | - } | |
| 1001 | - } | |
| 1002 | - | |
| 1003 | - | |
| 1004 | - /** | |
| 1005 | - * brew_espresso | |
| 1006 | - * begins the process of setting hooks for initializing EE in the correct order | |
| 1007 | - * This is happening on the 'AHEE__EE_Bootstrap__brew_espresso' hook point | |
| 1008 | - * which runs during the WP 'plugins_loaded' action at priority 9 | |
| 1009 | - * | |
| 1010 | - * @return void | |
| 1011 | - * @throws Exception | |
| 1012 | - */ | |
| 1013 | - public function brew_espresso() | |
| 1014 | -    { | |
| 1015 | -        do_action('AHEE__EE_System__brew_espresso__begin', $this); | |
| 1016 | - // load some final core systems | |
| 1017 | -        add_action('init', array($this, 'set_hooks_for_core'), 1); | |
| 1018 | -        add_action('init', array($this, 'perform_activations_upgrades_and_migrations'), 3); | |
| 1019 | -        add_action('init', array($this, 'load_CPTs_and_session'), 5); | |
| 1020 | -        add_action('init', array($this, 'load_controllers'), 7); | |
| 1021 | -        add_action('init', array($this, 'core_loaded_and_ready'), 9); | |
| 1022 | -        add_action('init', array($this, 'initialize'), 10); | |
| 1023 | -        add_action('init', array($this, 'initialize_last'), 100); | |
| 1024 | - $this->router->brewEspresso(); | |
| 1025 | -        do_action('AHEE__EE_System__brew_espresso__complete', $this); | |
| 1026 | - } | |
| 1027 | - | |
| 1028 | - | |
| 1029 | - /** | |
| 1030 | - * set_hooks_for_core | |
| 1031 | - * | |
| 1032 | - * @access public | |
| 1033 | - * @return void | |
| 1034 | - * @throws EE_Error | |
| 1035 | - */ | |
| 1036 | - public function set_hooks_for_core() | |
| 1037 | -    { | |
| 1038 | - $this->_deactivate_incompatible_addons(); | |
| 1039 | -        do_action('AHEE__EE_System__set_hooks_for_core'); | |
| 1040 | -        $this->loader->getShared('EventEspresso\core\domain\values\session\SessionLifespan'); | |
| 1041 | - // caps need to be initialized on every request so that capability maps are set. | |
| 1042 | - // @see https://events.codebasehq.com/projects/event-espresso/tickets/8674 | |
| 1043 | - $this->registry->CAP->init_caps(); | |
| 1044 | - } | |
| 1045 | - | |
| 1046 | - | |
| 1047 | - /** | |
| 1048 | - * Using the information gathered in EE_System::_incompatible_addon_error, | |
| 1049 | - * deactivates any addons considered incompatible with the current version of EE | |
| 1050 | - */ | |
| 1051 | - private function _deactivate_incompatible_addons() | |
| 1052 | -    { | |
| 1053 | -        $incompatible_addons = get_option('ee_incompatible_addons', array()); | |
| 1054 | -        if (! empty($incompatible_addons)) { | |
| 1055 | -            $active_plugins = get_option('active_plugins', array()); | |
| 1056 | -            foreach ($active_plugins as $active_plugin) { | |
| 1057 | -                foreach ($incompatible_addons as $incompatible_addon) { | |
| 1058 | -                    if (strpos($active_plugin, $incompatible_addon) !== false) { | |
| 1059 | - unset($_GET['activate']); | |
| 1060 | - espresso_deactivate_plugin($active_plugin); | |
| 1061 | - } | |
| 1062 | - } | |
| 1063 | - } | |
| 1064 | - } | |
| 1065 | - } | |
| 1066 | - | |
| 1067 | - | |
| 1068 | - /** | |
| 1069 | - * perform_activations_upgrades_and_migrations | |
| 1070 | - * | |
| 1071 | - * @access public | |
| 1072 | - * @return void | |
| 1073 | - */ | |
| 1074 | - public function perform_activations_upgrades_and_migrations() | |
| 1075 | -    { | |
| 1076 | -        do_action('AHEE__EE_System__perform_activations_upgrades_and_migrations'); | |
| 1077 | - } | |
| 1078 | - | |
| 1079 | - | |
| 1080 | - /** | |
| 1081 | - * @return void | |
| 1082 | - * @throws DomainException | |
| 1083 | - */ | |
| 1084 | - public function load_CPTs_and_session() | |
| 1085 | -    { | |
| 1086 | -        do_action('AHEE__EE_System__load_CPTs_and_session__start'); | |
| 1087 | - /** @var EventEspresso\core\domain\services\custom_post_types\RegisterCustomTaxonomies $register_custom_taxonomies */ | |
| 1088 | - $register_custom_taxonomies = $this->loader->getShared( | |
| 1089 | - 'EventEspresso\core\domain\services\custom_post_types\RegisterCustomTaxonomies' | |
| 1090 | - ); | |
| 1091 | - $register_custom_taxonomies->registerCustomTaxonomies(); | |
| 1092 | - /** @var EventEspresso\core\domain\services\custom_post_types\RegisterCustomPostTypes $register_custom_post_types */ | |
| 1093 | - $register_custom_post_types = $this->loader->getShared( | |
| 1094 | - 'EventEspresso\core\domain\services\custom_post_types\RegisterCustomPostTypes' | |
| 1095 | - ); | |
| 1096 | - $register_custom_post_types->registerCustomPostTypes(); | |
| 1097 | - /** @var EventEspresso\core\domain\services\custom_post_types\RegisterCustomTaxonomyTerms $register_custom_taxonomy_terms */ | |
| 1098 | - $register_custom_taxonomy_terms = $this->loader->getShared( | |
| 1099 | - 'EventEspresso\core\domain\services\custom_post_types\RegisterCustomTaxonomyTerms' | |
| 1100 | - ); | |
| 1101 | - $register_custom_taxonomy_terms->registerCustomTaxonomyTerms(); | |
| 1102 | - // load legacy Custom Post Types and Taxonomies | |
| 1103 | -        $this->loader->getShared('EE_Register_CPTs'); | |
| 1104 | -        do_action('AHEE__EE_System__load_CPTs_and_session__complete'); | |
| 1105 | - } | |
| 1106 | - | |
| 1107 | - | |
| 1108 | - /** | |
| 1109 | - * load_controllers | |
| 1110 | - * this is the best place to load any additional controllers that needs access to EE core. | |
| 1111 | - * it is expected that all basic core EE systems, that are not dependant on the current request are loaded at this | |
| 1112 | - * time | |
| 1113 | - * | |
| 1114 | - * @access public | |
| 1115 | - * @return void | |
| 1116 | - * @throws Exception | |
| 1117 | - */ | |
| 1118 | - public function load_controllers() | |
| 1119 | -    { | |
| 1120 | -        do_action('AHEE__EE_System__load_controllers__start'); | |
| 1121 | - $this->router->loadControllers(); | |
| 1122 | -        do_action('AHEE__EE_System__load_controllers__complete'); | |
| 1123 | - } | |
| 1124 | - | |
| 1125 | - | |
| 1126 | - /** | |
| 1127 | - * core_loaded_and_ready | |
| 1128 | - * all of the basic EE core should be loaded at this point and available regardless of M-Mode | |
| 1129 | - * | |
| 1130 | - * @access public | |
| 1131 | - * @return void | |
| 1132 | - * @throws Exception | |
| 1133 | - */ | |
| 1134 | - public function core_loaded_and_ready() | |
| 1135 | -    { | |
| 1136 | - $this->router->coreLoadedAndReady(); | |
| 1137 | - // integrate WP_Query with the EE models | |
| 1138 | -        $this->loader->getShared('EE_CPT_Strategy'); | |
| 1139 | -        do_action('AHEE__EE_System__core_loaded_and_ready'); | |
| 1140 | - // always load template tags, because it's faster than checking if it's a front-end request, and many page | |
| 1141 | - // builders require these even on the front-end | |
| 1142 | - require_once EE_PUBLIC . 'template_tags.php'; | |
| 1143 | -        do_action('AHEE__EE_System__set_hooks_for_shortcodes_modules_and_addons'); | |
| 1144 | - } | |
| 1145 | - | |
| 1146 | - | |
| 1147 | - /** | |
| 1148 | - * initialize | |
| 1149 | - * this is the best place to begin initializing client code | |
| 1150 | - * | |
| 1151 | - * @access public | |
| 1152 | - * @return void | |
| 1153 | - */ | |
| 1154 | - public function initialize() | |
| 1155 | -    { | |
| 1156 | -        do_action('AHEE__EE_System__initialize'); | |
| 1157 | - } | |
| 1158 | - | |
| 1159 | - | |
| 1160 | - /** | |
| 1161 | - * initialize_last | |
| 1162 | - * this is run really late during the WP init hook point, and ensures that mostly everything else that needs to | |
| 1163 | - * initialize has done so | |
| 1164 | - * | |
| 1165 | - * @access public | |
| 1166 | - * @return void | |
| 1167 | - * @throws Exception | |
| 1168 | - */ | |
| 1169 | - public function initialize_last() | |
| 1170 | -    { | |
| 1171 | -        do_action('AHEE__EE_System__initialize_last'); | |
| 1172 | - /** @var EventEspresso\core\domain\services\custom_post_types\RewriteRules $rewrite_rules */ | |
| 1173 | - $rewrite_rules = $this->loader->getShared( | |
| 1174 | - 'EventEspresso\core\domain\services\custom_post_types\RewriteRules' | |
| 1175 | - ); | |
| 1176 | - $rewrite_rules->flushRewriteRules(); | |
| 1177 | - $this->router->initializeLast(); | |
| 1178 | -        add_action('admin_bar_init', array($this, 'addEspressoToolbar')); | |
| 1179 | - } | |
| 1180 | - | |
| 1181 | - | |
| 1182 | - /** | |
| 1183 | - * @return void | |
| 1184 | - */ | |
| 1185 | - public function addEspressoToolbar() | |
| 1186 | -    { | |
| 1187 | - $this->loader->getShared( | |
| 1188 | - 'EventEspresso\core\domain\services\admin\AdminToolBar', | |
| 1189 | - array($this->registry->CAP) | |
| 1190 | - ); | |
| 1191 | - } | |
| 1192 | - | |
| 1193 | - | |
| 1194 | - /** | |
| 1195 | - * do_not_cache | |
| 1196 | - * sets no cache headers and defines no cache constants for WP plugins | |
| 1197 | - * | |
| 1198 | - * @access public | |
| 1199 | - * @return void | |
| 1200 | - */ | |
| 1201 | - public static function do_not_cache() | |
| 1202 | -    { | |
| 1203 | - // set no cache constants | |
| 1204 | -        if (! defined('DONOTCACHEPAGE')) { | |
| 1205 | -            define('DONOTCACHEPAGE', true); | |
| 1206 | - } | |
| 1207 | -        if (! defined('DONOTCACHCEOBJECT')) { | |
| 1208 | -            define('DONOTCACHCEOBJECT', true); | |
| 1209 | - } | |
| 1210 | -        if (! defined('DONOTCACHEDB')) { | |
| 1211 | -            define('DONOTCACHEDB', true); | |
| 1212 | - } | |
| 1213 | - // add no cache headers | |
| 1214 | -        add_action('send_headers', array('EE_System', 'nocache_headers'), 10); | |
| 1215 | - // plus a little extra for nginx and Google Chrome | |
| 1216 | -        add_filter('nocache_headers', array('EE_System', 'extra_nocache_headers'), 10, 1); | |
| 1217 | - // prevent browsers from prefetching of the rel='next' link, because it may contain content that interferes with the registration process | |
| 1218 | -        remove_action('wp_head', 'adjacent_posts_rel_link_wp_head'); | |
| 1219 | - } | |
| 1220 | - | |
| 1221 | - | |
| 1222 | - /** | |
| 1223 | - * extra_nocache_headers | |
| 1224 | - * | |
| 1225 | - * @access public | |
| 1226 | - * @param $headers | |
| 1227 | - * @return array | |
| 1228 | - */ | |
| 1229 | - public static function extra_nocache_headers($headers) | |
| 1230 | -    { | |
| 1231 | - // for NGINX | |
| 1232 | - $headers['X-Accel-Expires'] = 0; | |
| 1233 | - // plus extra for Google Chrome since it doesn't seem to respect "no-cache", but WILL respect "no-store" | |
| 1234 | - $headers['Cache-Control'] = 'no-store, no-cache, must-revalidate, max-age=0'; | |
| 1235 | - return $headers; | |
| 1236 | - } | |
| 1237 | - | |
| 1238 | - | |
| 1239 | - /** | |
| 1240 | - * nocache_headers | |
| 1241 | - * | |
| 1242 | - * @access public | |
| 1243 | - * @return void | |
| 1244 | - */ | |
| 1245 | - public static function nocache_headers() | |
| 1246 | -    { | |
| 1247 | - nocache_headers(); | |
| 1248 | - } | |
| 1249 | - | |
| 1250 | - | |
| 1251 | - /** | |
| 1252 | - * simply hooks into "wp_list_pages_exclude" filter (for wp_list_pages method) and makes sure EE critical pages are | |
| 1253 | - * never returned with the function. | |
| 1254 | - * | |
| 1255 | - * @param array $exclude_array any existing pages being excluded are in this array. | |
| 1256 | - * @return array | |
| 1257 | - */ | |
| 1258 | - public function remove_pages_from_wp_list_pages($exclude_array) | |
| 1259 | -    { | |
| 1260 | - return array_merge($exclude_array, $this->registry->CFG->core->get_critical_pages_array()); | |
| 1261 | - } | |
| 30 | + /** | |
| 31 | + * indicates this is a 'normal' request. Ie, not activation, nor upgrade, nor activation. | |
| 32 | + * So examples of this would be a normal GET request on the frontend or backend, or a POST, etc | |
| 33 | + */ | |
| 34 | + const req_type_normal = 0; | |
| 35 | + | |
| 36 | + /** | |
| 37 | + * Indicates this is a brand new installation of EE so we should install | |
| 38 | + * tables and default data etc | |
| 39 | + */ | |
| 40 | + const req_type_new_activation = 1; | |
| 41 | + | |
| 42 | + /** | |
| 43 | + * we've detected that EE has been reactivated (or EE was activated during maintenance mode, | |
| 44 | + * and we just exited maintenance mode). We MUST check the database is setup properly | |
| 45 | + * and that default data is setup too | |
| 46 | + */ | |
| 47 | + const req_type_reactivation = 2; | |
| 48 | + | |
| 49 | + /** | |
| 50 | + * indicates that EE has been upgraded since its previous request. | |
| 51 | + * We may have data migration scripts to call and will want to trigger maintenance mode | |
| 52 | + */ | |
| 53 | + const req_type_upgrade = 3; | |
| 54 | + | |
| 55 | + /** | |
| 56 | + * TODO will detect that EE has been DOWNGRADED. We probably don't want to run in this case... | |
| 57 | + */ | |
| 58 | + const req_type_downgrade = 4; | |
| 59 | + | |
| 60 | + /** | |
| 61 | + * @deprecated since version 4.6.0.dev.006 | |
| 62 | + * Now whenever a new_activation is detected the request type is still just | |
| 63 | + * new_activation (same for reactivation, upgrade, downgrade etc), but if we'r ein maintenance mode | |
| 64 | + * EE_System::initialize_db_if_no_migrations_required and EE_Addon::initialize_db_if_no_migrations_required | |
| 65 | + * will instead enqueue that EE plugin's db initialization for when we're taken out of maintenance mode. | |
| 66 | + * (Specifically, when the migration manager indicates migrations are finished | |
| 67 | + * EE_Data_Migration_Manager::initialize_db_for_enqueued_ee_plugins() will be called) | |
| 68 | + */ | |
| 69 | + const req_type_activation_but_not_installed = 5; | |
| 70 | + | |
| 71 | + /** | |
| 72 | + * option prefix for recording the activation history (like core's "espresso_db_update") of addons | |
| 73 | + */ | |
| 74 | + const addon_activation_history_option_prefix = 'ee_addon_activation_history_'; | |
| 75 | + | |
| 76 | + /** | |
| 77 | + * @var EE_System $_instance | |
| 78 | + */ | |
| 79 | + private static $_instance; | |
| 80 | + | |
| 81 | + /** | |
| 82 | + * @var EE_Registry $registry | |
| 83 | + */ | |
| 84 | + private $registry; | |
| 85 | + | |
| 86 | + /** | |
| 87 | + * @var LoaderInterface $loader | |
| 88 | + */ | |
| 89 | + private $loader; | |
| 90 | + | |
| 91 | + /** | |
| 92 | + * @var EE_Capabilities $capabilities | |
| 93 | + */ | |
| 94 | + private $capabilities; | |
| 95 | + | |
| 96 | + /** | |
| 97 | + * @var EE_Maintenance_Mode $maintenance_mode | |
| 98 | + */ | |
| 99 | + private $maintenance_mode; | |
| 100 | + | |
| 101 | + /** | |
| 102 | + * @var RequestInterface $request | |
| 103 | + */ | |
| 104 | + private $request; | |
| 105 | + | |
| 106 | + /** | |
| 107 | + * Stores which type of request this is, options being one of the constants on EE_System starting with req_type_*. | |
| 108 | + * It can be a brand-new activation, a reactivation, an upgrade, a downgrade, or a normal request. | |
| 109 | + * | |
| 110 | + * @var int $_req_type | |
| 111 | + */ | |
| 112 | + private $_req_type; | |
| 113 | + | |
| 114 | + /** | |
| 115 | + * Whether or not there was a non-micro version change in EE core version during this request | |
| 116 | + * | |
| 117 | + * @var boolean $_major_version_change | |
| 118 | + */ | |
| 119 | + private $_major_version_change = false; | |
| 120 | + | |
| 121 | + /** | |
| 122 | + * @var Router $router | |
| 123 | + */ | |
| 124 | + private $router; | |
| 125 | + | |
| 126 | + | |
| 127 | + /** | |
| 128 | + * @singleton method used to instantiate class object | |
| 129 | + * @param LoaderInterface $loader | |
| 130 | + * @param EE_Maintenance_Mode $maintenance_mode | |
| 131 | + * @param EE_Registry $registry | |
| 132 | + * @param RequestInterface $request | |
| 133 | + * @param Router $router | |
| 134 | + * @return EE_System | |
| 135 | + */ | |
| 136 | + public static function instance( | |
| 137 | + LoaderInterface $loader = null, | |
| 138 | + EE_Maintenance_Mode $maintenance_mode = null, | |
| 139 | + EE_Registry $registry = null, | |
| 140 | + RequestInterface $request = null, | |
| 141 | + Router $router = null | |
| 142 | +	) { | |
| 143 | + // check if class object is instantiated | |
| 144 | +		if (! self::$_instance instanceof EE_System) { | |
| 145 | + self::$_instance = new self($loader, $maintenance_mode, $registry, $request, $router); | |
| 146 | + } | |
| 147 | + return self::$_instance; | |
| 148 | + } | |
| 149 | + | |
| 150 | + | |
| 151 | + /** | |
| 152 | + * resets the instance and returns it | |
| 153 | + * | |
| 154 | + * @return EE_System | |
| 155 | + */ | |
| 156 | + public static function reset() | |
| 157 | +	{ | |
| 158 | + self::$_instance->_req_type = null; | |
| 159 | + // make sure none of the old hooks are left hanging around | |
| 160 | +		remove_all_actions('AHEE__EE_System__perform_activations_upgrades_and_migrations'); | |
| 161 | + // we need to reset the migration manager in order for it to detect DMSs properly | |
| 162 | + EE_Data_Migration_Manager::reset(); | |
| 163 | + self::instance()->detect_activations_or_upgrades(); | |
| 164 | + self::instance()->perform_activations_upgrades_and_migrations(); | |
| 165 | + return self::instance(); | |
| 166 | + } | |
| 167 | + | |
| 168 | + | |
| 169 | + /** | |
| 170 | + * sets hooks for running rest of system | |
| 171 | + * provides "AHEE__EE_System__construct__complete" hook for EE Addons to use as their starting point | |
| 172 | + * starting EE Addons from any other point may lead to problems | |
| 173 | + * | |
| 174 | + * @param LoaderInterface $loader | |
| 175 | + * @param EE_Maintenance_Mode $maintenance_mode | |
| 176 | + * @param EE_Registry $registry | |
| 177 | + * @param RequestInterface $request | |
| 178 | + * @param Router $router | |
| 179 | + */ | |
| 180 | + private function __construct( | |
| 181 | + LoaderInterface $loader, | |
| 182 | + EE_Maintenance_Mode $maintenance_mode, | |
| 183 | + EE_Registry $registry, | |
| 184 | + RequestInterface $request, | |
| 185 | + Router $router | |
| 186 | +	) { | |
| 187 | + $this->registry = $registry; | |
| 188 | + $this->loader = $loader; | |
| 189 | + $this->request = $request; | |
| 190 | + $this->router = $router; | |
| 191 | + $this->maintenance_mode = $maintenance_mode; | |
| 192 | +		do_action('AHEE__EE_System__construct__begin', $this); | |
| 193 | + add_action( | |
| 194 | + 'AHEE__EE_Bootstrap__load_espresso_addons', | |
| 195 | + array($this, 'loadCapabilities'), | |
| 196 | + 5 | |
| 197 | + ); | |
| 198 | + add_action( | |
| 199 | + 'AHEE__EE_Bootstrap__load_espresso_addons', | |
| 200 | + array($this, 'loadCommandBus'), | |
| 201 | + 7 | |
| 202 | + ); | |
| 203 | + add_action( | |
| 204 | + 'AHEE__EE_Bootstrap__load_espresso_addons', | |
| 205 | + array($this, 'loadPluginApi'), | |
| 206 | + 9 | |
| 207 | + ); | |
| 208 | + // allow addons to load first so that they can register autoloaders, set hooks for running DMS's, etc | |
| 209 | + add_action( | |
| 210 | + 'AHEE__EE_Bootstrap__load_espresso_addons', | |
| 211 | + array($this, 'load_espresso_addons') | |
| 212 | + ); | |
| 213 | + // when an ee addon is activated, we want to call the core hook(s) again | |
| 214 | + // because the newly-activated addon didn't get a chance to run at all | |
| 215 | +		add_action('activate_plugin', array($this, 'load_espresso_addons'), 1); | |
| 216 | + // detect whether install or upgrade | |
| 217 | + add_action( | |
| 218 | + 'AHEE__EE_Bootstrap__detect_activations_or_upgrades', | |
| 219 | + array($this, 'detect_activations_or_upgrades'), | |
| 220 | + 3 | |
| 221 | + ); | |
| 222 | + // load EE_Config, EE_Textdomain, etc | |
| 223 | + add_action( | |
| 224 | + 'AHEE__EE_Bootstrap__load_core_configuration', | |
| 225 | + array($this, 'load_core_configuration'), | |
| 226 | + 5 | |
| 227 | + ); | |
| 228 | + // load specifications for matching routes to current request | |
| 229 | + add_action( | |
| 230 | + 'AHEE__EE_Bootstrap__load_core_configuration', | |
| 231 | + array($this, 'loadRouteMatchSpecifications') | |
| 232 | + ); | |
| 233 | + // load EE_Config, EE_Textdomain, etc | |
| 234 | + add_action( | |
| 235 | + 'AHEE__EE_Bootstrap__register_shortcodes_modules_and_widgets', | |
| 236 | + array($this, 'register_shortcodes_modules_and_widgets'), | |
| 237 | + 7 | |
| 238 | + ); | |
| 239 | + // you wanna get going? I wanna get going... let's get going! | |
| 240 | + add_action( | |
| 241 | + 'AHEE__EE_Bootstrap__brew_espresso', | |
| 242 | + array($this, 'brew_espresso'), | |
| 243 | + 9 | |
| 244 | + ); | |
| 245 | + // other housekeeping | |
| 246 | + // exclude EE critical pages from wp_list_pages | |
| 247 | + add_filter( | |
| 248 | + 'wp_list_pages_excludes', | |
| 249 | + array($this, 'remove_pages_from_wp_list_pages'), | |
| 250 | + 10 | |
| 251 | + ); | |
| 252 | + // ALL EE Addons should use the following hook point to attach their initial setup too | |
| 253 | + // it's extremely important for EE Addons to register any class autoloaders so that they can be available when the EE_Config loads | |
| 254 | +		do_action('AHEE__EE_System__construct__complete', $this); | |
| 255 | + } | |
| 256 | + | |
| 257 | + | |
| 258 | + /** | |
| 259 | + * load and setup EE_Capabilities | |
| 260 | + * | |
| 261 | + * @return void | |
| 262 | + */ | |
| 263 | + public function loadCapabilities() | |
| 264 | +	{ | |
| 265 | +		$this->capabilities = $this->loader->getShared('EE_Capabilities'); | |
| 266 | + add_action( | |
| 267 | + 'AHEE__EE_Capabilities__init_caps__before_initialization', | |
| 268 | +			function () { | |
| 269 | +				LoaderFactory::getLoader()->getShared('EE_Payment_Method_Manager'); | |
| 270 | + } | |
| 271 | + ); | |
| 272 | + } | |
| 273 | + | |
| 274 | + | |
| 275 | + /** | |
| 276 | + * create and cache the CommandBus, and also add middleware | |
| 277 | + * The CapChecker middleware requires the use of EE_Capabilities | |
| 278 | + * which is why we need to load the CommandBus after Caps are set up | |
| 279 | + * | |
| 280 | + * @return void | |
| 281 | + */ | |
| 282 | + public function loadCommandBus() | |
| 283 | +	{ | |
| 284 | + $this->loader->getShared( | |
| 285 | + 'CommandBusInterface', | |
| 286 | + array( | |
| 287 | + null, | |
| 288 | + apply_filters( | |
| 289 | + 'FHEE__EE_Load_Espresso_Core__handle_request__CommandBus_middleware', | |
| 290 | + array( | |
| 291 | +						$this->loader->getShared('EventEspresso\core\services\commands\middleware\CapChecker'), | |
| 292 | +						$this->loader->getShared('EventEspresso\core\services\commands\middleware\AddActionHook'), | |
| 293 | + ) | |
| 294 | + ), | |
| 295 | + ) | |
| 296 | + ); | |
| 297 | + } | |
| 298 | + | |
| 299 | + | |
| 300 | + /** | |
| 301 | + * @return void | |
| 302 | + * @throws EE_Error | |
| 303 | + */ | |
| 304 | + public function loadPluginApi() | |
| 305 | +	{ | |
| 306 | + // set autoloaders for all of the classes implementing EEI_Plugin_API | |
| 307 | + // which provide helpers for EE plugin authors to more easily register certain components with EE. | |
| 308 | + EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_LIBRARIES . 'plugin_api'); | |
| 309 | +		$this->loader->getShared('EE_Request_Handler'); | |
| 310 | + } | |
| 311 | + | |
| 312 | + | |
| 313 | + /** | |
| 314 | + * @param string $addon_name | |
| 315 | + * @param string $version_constant | |
| 316 | + * @param string $min_version_required | |
| 317 | + * @param string $load_callback | |
| 318 | + * @param string $plugin_file_constant | |
| 319 | + * @return void | |
| 320 | + */ | |
| 321 | + private function deactivateIncompatibleAddon( | |
| 322 | + $addon_name, | |
| 323 | + $version_constant, | |
| 324 | + $min_version_required, | |
| 325 | + $load_callback, | |
| 326 | + $plugin_file_constant | |
| 327 | +	) { | |
| 328 | +		if (! defined($version_constant)) { | |
| 329 | + return; | |
| 330 | + } | |
| 331 | + $addon_version = constant($version_constant); | |
| 332 | +		if ($addon_version && version_compare($addon_version, $min_version_required, '<')) { | |
| 333 | +			remove_action('AHEE__EE_System__load_espresso_addons', $load_callback); | |
| 334 | +			if (! function_exists('deactivate_plugins')) { | |
| 335 | + require_once ABSPATH . 'wp-admin/includes/plugin.php'; | |
| 336 | + } | |
| 337 | + deactivate_plugins(plugin_basename(constant($plugin_file_constant))); | |
| 338 | + unset($_GET['activate'], $_REQUEST['activate'], $_GET['activate-multi'], $_REQUEST['activate-multi']); | |
| 339 | + EE_Error::add_error( | |
| 340 | + sprintf( | |
| 341 | + esc_html__( | |
| 342 | + 'We\'re sorry, but the Event Espresso %1$s addon was deactivated because version %2$s or higher is required with this version of Event Espresso core.', | |
| 343 | + 'event_espresso' | |
| 344 | + ), | |
| 345 | + $addon_name, | |
| 346 | + $min_version_required | |
| 347 | + ), | |
| 348 | + __FILE__, | |
| 349 | +				__FUNCTION__ . "({$addon_name})", | |
| 350 | + __LINE__ | |
| 351 | + ); | |
| 352 | + EE_Error::get_notices(false, true); | |
| 353 | + } | |
| 354 | + } | |
| 355 | + | |
| 356 | + | |
| 357 | + /** | |
| 358 | + * load_espresso_addons | |
| 359 | + * allow addons to load first so that they can set hooks for running DMS's, etc | |
| 360 | + * this is hooked into both: | |
| 361 | + * 'AHEE__EE_Bootstrap__load_core_configuration' | |
| 362 | + * which runs during the WP 'plugins_loaded' action at priority 5 | |
| 363 | + * and the WP 'activate_plugin' hook point | |
| 364 | + * | |
| 365 | + * @access public | |
| 366 | + * @return void | |
| 367 | + */ | |
| 368 | + public function load_espresso_addons() | |
| 369 | +	{ | |
| 370 | + $this->deactivateIncompatibleAddon( | |
| 371 | + 'Wait Lists', | |
| 372 | + 'EE_WAIT_LISTS_VERSION', | |
| 373 | + '1.0.0.beta.074', | |
| 374 | + 'load_espresso_wait_lists', | |
| 375 | + 'EE_WAIT_LISTS_PLUGIN_FILE' | |
| 376 | + ); | |
| 377 | + $this->deactivateIncompatibleAddon( | |
| 378 | + 'Automated Upcoming Event Notifications', | |
| 379 | + 'EE_AUTOMATED_UPCOMING_EVENT_NOTIFICATION_VERSION', | |
| 380 | + '1.0.0.beta.091', | |
| 381 | + 'load_espresso_automated_upcoming_event_notification', | |
| 382 | + 'EE_AUTOMATED_UPCOMING_EVENT_NOTIFICATION_PLUGIN_FILE' | |
| 383 | + ); | |
| 384 | +		do_action('AHEE__EE_System__load_espresso_addons'); | |
| 385 | + // if the WP API basic auth plugin isn't already loaded, load it now. | |
| 386 | + // We want it for mobile apps. Just include the entire plugin | |
| 387 | + // also, don't load the basic auth when a plugin is getting activated, because | |
| 388 | + // it could be the basic auth plugin, and it doesn't check if its methods are already defined | |
| 389 | + // and causes a fatal error | |
| 390 | + if (($this->request->isWordPressApi() || $this->request->isApi()) | |
| 391 | + && ! $this->request->isActivation() | |
| 392 | +			&& ! function_exists('json_basic_auth_handler') | |
| 393 | +			&& ! function_exists('json_basic_auth_error') | |
| 394 | +		) { | |
| 395 | + include_once EE_THIRD_PARTY . 'wp-api-basic-auth/basic-auth.php'; | |
| 396 | + } | |
| 397 | +		do_action('AHEE__EE_System__load_espresso_addons__complete'); | |
| 398 | + } | |
| 399 | + | |
| 400 | + | |
| 401 | + /** | |
| 402 | + * detect_activations_or_upgrades | |
| 403 | + * Checks for activation or upgrade of core first; | |
| 404 | + * then also checks if any registered addons have been activated or upgraded | |
| 405 | + * This is hooked into 'AHEE__EE_Bootstrap__detect_activations_or_upgrades' | |
| 406 | + * which runs during the WP 'plugins_loaded' action at priority 3 | |
| 407 | + * | |
| 408 | + * @access public | |
| 409 | + * @return void | |
| 410 | + */ | |
| 411 | + public function detect_activations_or_upgrades() | |
| 412 | +	{ | |
| 413 | + // first off: let's make sure to handle core | |
| 414 | + $this->detect_if_activation_or_upgrade(); | |
| 415 | +		foreach ($this->registry->addons as $addon) { | |
| 416 | +			if ($addon instanceof EE_Addon) { | |
| 417 | + // detect teh request type for that addon | |
| 418 | + $addon->detect_activation_or_upgrade(); | |
| 419 | + } | |
| 420 | + } | |
| 421 | + } | |
| 422 | + | |
| 423 | + | |
| 424 | + /** | |
| 425 | + * detect_if_activation_or_upgrade | |
| 426 | + * Takes care of detecting whether this is a brand new install or code upgrade, | |
| 427 | + * and either setting up the DB or setting up maintenance mode etc. | |
| 428 | + * | |
| 429 | + * @access public | |
| 430 | + * @return void | |
| 431 | + */ | |
| 432 | + public function detect_if_activation_or_upgrade() | |
| 433 | +	{ | |
| 434 | +		do_action('AHEE__EE_System___detect_if_activation_or_upgrade__begin'); | |
| 435 | + // check if db has been updated, or if its a brand-new installation | |
| 436 | + $espresso_db_update = $this->fix_espresso_db_upgrade_option(); | |
| 437 | + $request_type = $this->detect_req_type($espresso_db_update); | |
| 438 | + // EEH_Debug_Tools::printr( $request_type, '$request_type', __FILE__, __LINE__ ); | |
| 439 | +		switch ($request_type) { | |
| 440 | + case EE_System::req_type_new_activation: | |
| 441 | +				do_action('AHEE__EE_System__detect_if_activation_or_upgrade__new_activation'); | |
| 442 | + $this->_handle_core_version_change($espresso_db_update); | |
| 443 | + break; | |
| 444 | + case EE_System::req_type_reactivation: | |
| 445 | +				do_action('AHEE__EE_System__detect_if_activation_or_upgrade__reactivation'); | |
| 446 | + $this->_handle_core_version_change($espresso_db_update); | |
| 447 | + break; | |
| 448 | + case EE_System::req_type_upgrade: | |
| 449 | +				do_action('AHEE__EE_System__detect_if_activation_or_upgrade__upgrade'); | |
| 450 | + // migrations may be required now that we've upgraded | |
| 451 | + $this->maintenance_mode->set_maintenance_mode_if_db_old(); | |
| 452 | + $this->_handle_core_version_change($espresso_db_update); | |
| 453 | + break; | |
| 454 | + case EE_System::req_type_downgrade: | |
| 455 | +				do_action('AHEE__EE_System__detect_if_activation_or_upgrade__downgrade'); | |
| 456 | + // its possible migrations are no longer required | |
| 457 | + $this->maintenance_mode->set_maintenance_mode_if_db_old(); | |
| 458 | + $this->_handle_core_version_change($espresso_db_update); | |
| 459 | + break; | |
| 460 | + case EE_System::req_type_normal: | |
| 461 | + default: | |
| 462 | + break; | |
| 463 | + } | |
| 464 | +		do_action('AHEE__EE_System__detect_if_activation_or_upgrade__complete'); | |
| 465 | + } | |
| 466 | + | |
| 467 | + | |
| 468 | + /** | |
| 469 | + * Updates the list of installed versions and sets hooks for | |
| 470 | + * initializing the database later during the request | |
| 471 | + * | |
| 472 | + * @param array $espresso_db_update | |
| 473 | + */ | |
| 474 | + private function _handle_core_version_change($espresso_db_update) | |
| 475 | +	{ | |
| 476 | + $this->update_list_of_installed_versions($espresso_db_update); | |
| 477 | + // get ready to verify the DB is ok (provided we aren't in maintenance mode, of course) | |
| 478 | + add_action( | |
| 479 | + 'AHEE__EE_System__perform_activations_upgrades_and_migrations', | |
| 480 | + array($this, 'initialize_db_if_no_migrations_required') | |
| 481 | + ); | |
| 482 | + } | |
| 483 | + | |
| 484 | + | |
| 485 | + /** | |
| 486 | + * standardizes the wp option 'espresso_db_upgrade' which actually stores | |
| 487 | + * information about what versions of EE have been installed and activated, | |
| 488 | + * NOT necessarily the state of the database | |
| 489 | + * | |
| 490 | + * @param mixed $espresso_db_update the value of the WordPress option. | |
| 491 | + * If not supplied, fetches it from the options table | |
| 492 | + * @return array the correct value of 'espresso_db_upgrade', after saving it, if it needed correction | |
| 493 | + */ | |
| 494 | + private function fix_espresso_db_upgrade_option($espresso_db_update = null) | |
| 495 | +	{ | |
| 496 | +		do_action('FHEE__EE_System__manage_fix_espresso_db_upgrade_option__begin', $espresso_db_update); | |
| 497 | +		if (! $espresso_db_update) { | |
| 498 | +			$espresso_db_update = get_option('espresso_db_update'); | |
| 499 | + } | |
| 500 | + // check that option is an array | |
| 501 | +		if (! is_array($espresso_db_update)) { | |
| 502 | + // if option is FALSE, then it never existed | |
| 503 | +			if ($espresso_db_update === false) { | |
| 504 | + // make $espresso_db_update an array and save option with autoload OFF | |
| 505 | + $espresso_db_update = array(); | |
| 506 | +				add_option('espresso_db_update', $espresso_db_update, '', 'no'); | |
| 507 | +			} else { | |
| 508 | + // option is NOT FALSE but also is NOT an array, so make it an array and save it | |
| 509 | + $espresso_db_update = array($espresso_db_update => array()); | |
| 510 | +				update_option('espresso_db_update', $espresso_db_update); | |
| 511 | + } | |
| 512 | +		} else { | |
| 513 | + $corrected_db_update = array(); | |
| 514 | + // if IS an array, but is it an array where KEYS are version numbers, and values are arrays? | |
| 515 | +			foreach ($espresso_db_update as $should_be_version_string => $should_be_array) { | |
| 516 | +				if (is_int($should_be_version_string) && ! is_array($should_be_array)) { | |
| 517 | + // the key is an int, and the value IS NOT an array | |
| 518 | + // so it must be numerically-indexed, where values are versions installed... | |
| 519 | + // fix it! | |
| 520 | + $version_string = $should_be_array; | |
| 521 | +					$corrected_db_update[ $version_string ] = array('unknown-date'); | |
| 522 | +				} else { | |
| 523 | + // ok it checks out | |
| 524 | + $corrected_db_update[ $should_be_version_string ] = $should_be_array; | |
| 525 | + } | |
| 526 | + } | |
| 527 | + $espresso_db_update = $corrected_db_update; | |
| 528 | +			update_option('espresso_db_update', $espresso_db_update); | |
| 529 | + } | |
| 530 | +		do_action('FHEE__EE_System__manage_fix_espresso_db_upgrade_option__complete', $espresso_db_update); | |
| 531 | + return $espresso_db_update; | |
| 532 | + } | |
| 533 | + | |
| 534 | + | |
| 535 | + /** | |
| 536 | + * Does the traditional work of setting up the plugin's database and adding default data. | |
| 537 | + * If migration script/process did not exist, this is what would happen on every activation/reactivation/upgrade. | |
| 538 | + * NOTE: if we're in maintenance mode (which would be the case if we detect there are data | |
| 539 | + * migration scripts that need to be run and a version change happens), enqueues core for database initialization, | |
| 540 | + * so that it will be done when migrations are finished | |
| 541 | + * | |
| 542 | + * @param boolean $initialize_addons_too if true, we double-check addons' database tables etc too; | |
| 543 | + * @param boolean $verify_schema if true will re-check the database tables have the correct schema. | |
| 544 | + * This is a resource-intensive job | |
| 545 | + * so we prefer to only do it when necessary | |
| 546 | + * @return void | |
| 547 | + * @throws EE_Error | |
| 548 | + */ | |
| 549 | + public function initialize_db_if_no_migrations_required($initialize_addons_too = false, $verify_schema = true) | |
| 550 | +	{ | |
| 551 | + $request_type = $this->detect_req_type(); | |
| 552 | + // only initialize system if we're not in maintenance mode. | |
| 553 | +		if ($this->maintenance_mode->level() !== EE_Maintenance_Mode::level_2_complete_maintenance) { | |
| 554 | + /** @var EventEspresso\core\domain\services\custom_post_types\RewriteRules $rewrite_rules */ | |
| 555 | + $rewrite_rules = $this->loader->getShared( | |
| 556 | + 'EventEspresso\core\domain\services\custom_post_types\RewriteRules' | |
| 557 | + ); | |
| 558 | + $rewrite_rules->flush(); | |
| 559 | +			if ($verify_schema) { | |
| 560 | + EEH_Activation::initialize_db_and_folders(); | |
| 561 | + } | |
| 562 | + EEH_Activation::initialize_db_content(); | |
| 563 | + EEH_Activation::system_initialization(); | |
| 564 | +			if ($initialize_addons_too) { | |
| 565 | + $this->initialize_addons(); | |
| 566 | + } | |
| 567 | +		} else { | |
| 568 | +			EE_Data_Migration_Manager::instance()->enqueue_db_initialization_for('Core'); | |
| 569 | + } | |
| 570 | + if ($request_type === EE_System::req_type_new_activation | |
| 571 | + || $request_type === EE_System::req_type_reactivation | |
| 572 | + || ( | |
| 573 | + $request_type === EE_System::req_type_upgrade | |
| 574 | + && $this->is_major_version_change() | |
| 575 | + ) | |
| 576 | +		) { | |
| 577 | +			add_action('AHEE__EE_System__initialize_last', array($this, 'redirect_to_about_ee'), 9); | |
| 578 | + } | |
| 579 | + } | |
| 580 | + | |
| 581 | + | |
| 582 | + /** | |
| 583 | + * Initializes the db for all registered addons | |
| 584 | + * | |
| 585 | + * @throws EE_Error | |
| 586 | + */ | |
| 587 | + public function initialize_addons() | |
| 588 | +	{ | |
| 589 | + // foreach registered addon, make sure its db is up-to-date too | |
| 590 | +		foreach ($this->registry->addons as $addon) { | |
| 591 | +			if ($addon instanceof EE_Addon) { | |
| 592 | + $addon->initialize_db_if_no_migrations_required(); | |
| 593 | + } | |
| 594 | + } | |
| 595 | + } | |
| 596 | + | |
| 597 | + | |
| 598 | + /** | |
| 599 | + * Adds the current code version to the saved wp option which stores a list of all ee versions ever installed. | |
| 600 | + * | |
| 601 | + * @param array $version_history | |
| 602 | + * @param string $current_version_to_add version to be added to the version history | |
| 603 | + * @return boolean success as to whether or not this option was changed | |
| 604 | + */ | |
| 605 | + public function update_list_of_installed_versions($version_history = null, $current_version_to_add = null) | |
| 606 | +	{ | |
| 607 | +		if (! $version_history) { | |
| 608 | + $version_history = $this->fix_espresso_db_upgrade_option($version_history); | |
| 609 | + } | |
| 610 | +		if ($current_version_to_add === null) { | |
| 611 | + $current_version_to_add = espresso_version(); | |
| 612 | + } | |
| 613 | +		$version_history[ $current_version_to_add ][] = date('Y-m-d H:i:s', time()); | |
| 614 | + // re-save | |
| 615 | +		return update_option('espresso_db_update', $version_history); | |
| 616 | + } | |
| 617 | + | |
| 618 | + | |
| 619 | + /** | |
| 620 | + * Detects if the current version indicated in the has existed in the list of | |
| 621 | + * previously-installed versions of EE (espresso_db_update). Does NOT modify it (ie, no side-effect) | |
| 622 | + * | |
| 623 | + * @param array $espresso_db_update array from the wp option stored under the name 'espresso_db_update'. | |
| 624 | + * If not supplied, fetches it from the options table. | |
| 625 | + * Also, caches its result so later parts of the code can also know whether | |
| 626 | + * there's been an update or not. This way we can add the current version to | |
| 627 | + * espresso_db_update, but still know if this is a new install or not | |
| 628 | + * @return int one of the constants on EE_System::req_type_ | |
| 629 | + */ | |
| 630 | + public function detect_req_type($espresso_db_update = null) | |
| 631 | +	{ | |
| 632 | +		if ($this->_req_type === null) { | |
| 633 | + $espresso_db_update = ! empty($espresso_db_update) | |
| 634 | + ? $espresso_db_update | |
| 635 | + : $this->fix_espresso_db_upgrade_option(); | |
| 636 | + $this->_req_type = EE_System::detect_req_type_given_activation_history( | |
| 637 | + $espresso_db_update, | |
| 638 | + 'ee_espresso_activation', | |
| 639 | + espresso_version() | |
| 640 | + ); | |
| 641 | + $this->_major_version_change = $this->_detect_major_version_change($espresso_db_update); | |
| 642 | + $this->request->setIsActivation($this->_req_type !== EE_System::req_type_normal); | |
| 643 | + } | |
| 644 | + return $this->_req_type; | |
| 645 | + } | |
| 646 | + | |
| 647 | + | |
| 648 | + /** | |
| 649 | + * Returns whether or not there was a non-micro version change (ie, change in either | |
| 650 | + * the first or second number in the version. Eg 4.9.0.rc.001 to 4.10.0.rc.000, | |
| 651 | + * but not 4.9.0.rc.0001 to 4.9.1.rc.0001 | |
| 652 | + * | |
| 653 | + * @param $activation_history | |
| 654 | + * @return bool | |
| 655 | + */ | |
| 656 | + private function _detect_major_version_change($activation_history) | |
| 657 | +	{ | |
| 658 | + $previous_version = EE_System::_get_most_recently_active_version_from_activation_history($activation_history); | |
| 659 | +		$previous_version_parts = explode('.', $previous_version); | |
| 660 | +		$current_version_parts = explode('.', espresso_version()); | |
| 661 | + return isset($previous_version_parts[0], $previous_version_parts[1], $current_version_parts[0], $current_version_parts[1]) | |
| 662 | + && ( | |
| 663 | + $previous_version_parts[0] !== $current_version_parts[0] | |
| 664 | + || $previous_version_parts[1] !== $current_version_parts[1] | |
| 665 | + ); | |
| 666 | + } | |
| 667 | + | |
| 668 | + | |
| 669 | + /** | |
| 670 | + * Returns true if either the major or minor version of EE changed during this request. | |
| 671 | + * Eg 4.9.0.rc.001 to 4.10.0.rc.000, but not 4.9.0.rc.0001 to 4.9.1.rc.0001 | |
| 672 | + * | |
| 673 | + * @return bool | |
| 674 | + */ | |
| 675 | + public function is_major_version_change() | |
| 676 | +	{ | |
| 677 | + return $this->_major_version_change; | |
| 678 | + } | |
| 679 | + | |
| 680 | + | |
| 681 | + /** | |
| 682 | + * Determines the request type for any ee addon, given three piece of info: the current array of activation | |
| 683 | + * histories (for core that' 'espresso_db_update' wp option); the name of the WordPress option which is temporarily | |
| 684 | + * set upon activation of the plugin (for core it's 'ee_espresso_activation'); and the version that this plugin was | |
| 685 | + * just activated to (for core that will always be espresso_version()) | |
| 686 | + * | |
| 687 | + * @param array $activation_history_for_addon the option's value which stores the activation history for this | |
| 688 | + * ee plugin. for core that's 'espresso_db_update' | |
| 689 | + * @param string $activation_indicator_option_name the name of the WordPress option that is temporarily set to | |
| 690 | + * indicate that this plugin was just activated | |
| 691 | + * @param string $version_to_upgrade_to the version that was just upgraded to (for core that will be | |
| 692 | + * espresso_version()) | |
| 693 | + * @return int one of the constants on EE_System::req_type_* | |
| 694 | + */ | |
| 695 | + public static function detect_req_type_given_activation_history( | |
| 696 | + $activation_history_for_addon, | |
| 697 | + $activation_indicator_option_name, | |
| 698 | + $version_to_upgrade_to | |
| 699 | +	) { | |
| 700 | + $version_is_higher = self::_new_version_is_higher($activation_history_for_addon, $version_to_upgrade_to); | |
| 701 | +		if ($activation_history_for_addon) { | |
| 702 | + // it exists, so this isn't a completely new install | |
| 703 | + // check if this version already in that list of previously installed versions | |
| 704 | +			if (! isset($activation_history_for_addon[ $version_to_upgrade_to ])) { | |
| 705 | + // it a version we haven't seen before | |
| 706 | +				if ($version_is_higher === 1) { | |
| 707 | + $req_type = EE_System::req_type_upgrade; | |
| 708 | +				} else { | |
| 709 | + $req_type = EE_System::req_type_downgrade; | |
| 710 | + } | |
| 711 | + delete_option($activation_indicator_option_name); | |
| 712 | +			} else { | |
| 713 | + // its not an update. maybe a reactivation? | |
| 714 | +				if (get_option($activation_indicator_option_name, false)) { | |
| 715 | +					if ($version_is_higher === -1) { | |
| 716 | + $req_type = EE_System::req_type_downgrade; | |
| 717 | +					} elseif ($version_is_higher === 0) { | |
| 718 | + // we've seen this version before, but it's an activation. must be a reactivation | |
| 719 | + $req_type = EE_System::req_type_reactivation; | |
| 720 | +					} else {// $version_is_higher === 1 | |
| 721 | + $req_type = EE_System::req_type_upgrade; | |
| 722 | + } | |
| 723 | + delete_option($activation_indicator_option_name); | |
| 724 | +				} else { | |
| 725 | + // we've seen this version before and the activation indicate doesn't show it was just activated | |
| 726 | +					if ($version_is_higher === -1) { | |
| 727 | + $req_type = EE_System::req_type_downgrade; | |
| 728 | +					} elseif ($version_is_higher === 0) { | |
| 729 | + // we've seen this version before and it's not an activation. its normal request | |
| 730 | + $req_type = EE_System::req_type_normal; | |
| 731 | +					} else {// $version_is_higher === 1 | |
| 732 | + $req_type = EE_System::req_type_upgrade; | |
| 733 | + } | |
| 734 | + } | |
| 735 | + } | |
| 736 | +		} else { | |
| 737 | + // brand new install | |
| 738 | + $req_type = EE_System::req_type_new_activation; | |
| 739 | + delete_option($activation_indicator_option_name); | |
| 740 | + } | |
| 741 | + return $req_type; | |
| 742 | + } | |
| 743 | + | |
| 744 | + | |
| 745 | + /** | |
| 746 | + * Detects if the $version_to_upgrade_to is higher than the most recent version in | |
| 747 | + * the $activation_history_for_addon | |
| 748 | + * | |
| 749 | + * @param array $activation_history_for_addon (keys are versions, values are arrays of times activated, | |
| 750 | + * sometimes containing 'unknown-date' | |
| 751 | + * @param string $version_to_upgrade_to (current version) | |
| 752 | + * @return int results of version_compare( $version_to_upgrade_to, $most_recently_active_version ). | |
| 753 | + * ie, -1 if $version_to_upgrade_to is LOWER (downgrade); | |
| 754 | + * 0 if $version_to_upgrade_to MATCHES (reactivation or normal request); | |
| 755 | + * 1 if $version_to_upgrade_to is HIGHER (upgrade) ; | |
| 756 | + */ | |
| 757 | + private static function _new_version_is_higher($activation_history_for_addon, $version_to_upgrade_to) | |
| 758 | +	{ | |
| 759 | + // find the most recently-activated version | |
| 760 | + $most_recently_active_version = | |
| 761 | + EE_System::_get_most_recently_active_version_from_activation_history($activation_history_for_addon); | |
| 762 | + return version_compare($version_to_upgrade_to, $most_recently_active_version); | |
| 763 | + } | |
| 764 | + | |
| 765 | + | |
| 766 | + /** | |
| 767 | + * Gets the most recently active version listed in the activation history, | |
| 768 | + * and if none are found (ie, it's a brand new install) returns '0.0.0.dev.000'. | |
| 769 | + * | |
| 770 | + * @param array $activation_history (keys are versions, values are arrays of times activated, | |
| 771 | + * sometimes containing 'unknown-date' | |
| 772 | + * @return string | |
| 773 | + */ | |
| 774 | + private static function _get_most_recently_active_version_from_activation_history($activation_history) | |
| 775 | +	{ | |
| 776 | + $most_recently_active_version_activation = '1970-01-01 00:00:00'; | |
| 777 | + $most_recently_active_version = '0.0.0.dev.000'; | |
| 778 | +		if (is_array($activation_history)) { | |
| 779 | +			foreach ($activation_history as $version => $times_activated) { | |
| 780 | + // check there is a record of when this version was activated. Otherwise, | |
| 781 | + // mark it as unknown | |
| 782 | +				if (! $times_activated) { | |
| 783 | +					$times_activated = array('unknown-date'); | |
| 784 | + } | |
| 785 | +				if (is_string($times_activated)) { | |
| 786 | + $times_activated = array($times_activated); | |
| 787 | + } | |
| 788 | +				foreach ($times_activated as $an_activation) { | |
| 789 | + if ($an_activation !== 'unknown-date' | |
| 790 | + && $an_activation | |
| 791 | +						   > $most_recently_active_version_activation) { | |
| 792 | + $most_recently_active_version = $version; | |
| 793 | + $most_recently_active_version_activation = $an_activation === 'unknown-date' | |
| 794 | + ? '1970-01-01 00:00:00' | |
| 795 | + : $an_activation; | |
| 796 | + } | |
| 797 | + } | |
| 798 | + } | |
| 799 | + } | |
| 800 | + return $most_recently_active_version; | |
| 801 | + } | |
| 802 | + | |
| 803 | + | |
| 804 | + /** | |
| 805 | + * This redirects to the about EE page after activation | |
| 806 | + * | |
| 807 | + * @return void | |
| 808 | + */ | |
| 809 | + public function redirect_to_about_ee() | |
| 810 | +	{ | |
| 811 | + $notices = EE_Error::get_notices(false); | |
| 812 | + // if current user is an admin and it's not an ajax or rest request | |
| 813 | + if (! isset($notices['errors']) | |
| 814 | + && $this->request->isAdmin() | |
| 815 | + && apply_filters( | |
| 816 | + 'FHEE__EE_System__redirect_to_about_ee__do_redirect', | |
| 817 | +				$this->capabilities->current_user_can('manage_options', 'espresso_about_default') | |
| 818 | + ) | |
| 819 | +		) { | |
| 820 | +			$query_params = array('page' => 'espresso_about'); | |
| 821 | +			if (EE_System::instance()->detect_req_type() === EE_System::req_type_new_activation) { | |
| 822 | + $query_params['new_activation'] = true; | |
| 823 | + } | |
| 824 | +			if (EE_System::instance()->detect_req_type() === EE_System::req_type_reactivation) { | |
| 825 | + $query_params['reactivation'] = true; | |
| 826 | + } | |
| 827 | +			$url = add_query_arg($query_params, admin_url('admin.php')); | |
| 828 | + wp_safe_redirect($url); | |
| 829 | + exit(); | |
| 830 | + } | |
| 831 | + } | |
| 832 | + | |
| 833 | + | |
| 834 | + /** | |
| 835 | + * load_core_configuration | |
| 836 | + * this is hooked into 'AHEE__EE_Bootstrap__load_core_configuration' | |
| 837 | + * which runs during the WP 'plugins_loaded' action at priority 5 | |
| 838 | + * | |
| 839 | + * @return void | |
| 840 | + * @throws ReflectionException | |
| 841 | + * @throws Exception | |
| 842 | + */ | |
| 843 | + public function load_core_configuration() | |
| 844 | +	{ | |
| 845 | +		do_action('AHEE__EE_System__load_core_configuration__begin', $this); | |
| 846 | +		$this->loader->getShared('EE_Load_Textdomain'); | |
| 847 | + // load textdomain | |
| 848 | + EE_Load_Textdomain::load_textdomain(); | |
| 849 | + // load caf stuff a chance to play during the activation process too. | |
| 850 | + $this->_maybe_brew_regular(); | |
| 851 | + // load and setup EE_Config and EE_Network_Config | |
| 852 | +		$config = $this->loader->getShared('EE_Config'); | |
| 853 | +		$this->loader->getShared('EE_Network_Config'); | |
| 854 | + // setup autoloaders | |
| 855 | + // enable logging? | |
| 856 | +		if ($config->admin->use_remote_logging) { | |
| 857 | +			$this->loader->getShared('EE_Log'); | |
| 858 | + } | |
| 859 | + // check for activation errors | |
| 860 | +		$activation_errors = get_option('ee_plugin_activation_errors', false); | |
| 861 | +		if ($activation_errors) { | |
| 862 | + EE_Error::add_error($activation_errors, __FILE__, __FUNCTION__, __LINE__); | |
| 863 | +			update_option('ee_plugin_activation_errors', false); | |
| 864 | + } | |
| 865 | + // get model names | |
| 866 | + $this->_parse_model_names(); | |
| 867 | + // configure custom post type definitions | |
| 868 | +		$this->loader->getShared('EventEspresso\core\domain\entities\custom_post_types\CustomTaxonomyDefinitions'); | |
| 869 | +		$this->loader->getShared('EventEspresso\core\domain\entities\custom_post_types\CustomPostTypeDefinitions'); | |
| 870 | +		do_action('AHEE__EE_System__load_core_configuration__complete', $this); | |
| 871 | + } | |
| 872 | + | |
| 873 | + | |
| 874 | + /** | |
| 875 | + * cycles through all of the models/*.model.php files, and assembles an array of model names | |
| 876 | + * | |
| 877 | + * @return void | |
| 878 | + * @throws ReflectionException | |
| 879 | + */ | |
| 880 | + private function _parse_model_names() | |
| 881 | +	{ | |
| 882 | + // get all the files in the EE_MODELS folder that end in .model.php | |
| 883 | + $models = glob(EE_MODELS . '*.model.php'); | |
| 884 | + $model_names = array(); | |
| 885 | + $non_abstract_db_models = array(); | |
| 886 | +		foreach ($models as $model) { | |
| 887 | + // get model classname | |
| 888 | + $classname = EEH_File::get_classname_from_filepath_with_standard_filename($model); | |
| 889 | +			$short_name = str_replace('EEM_', '', $classname); | |
| 890 | + $reflectionClass = new ReflectionClass($classname); | |
| 891 | +			if ($reflectionClass->isSubclassOf('EEM_Base') && ! $reflectionClass->isAbstract()) { | |
| 892 | + $non_abstract_db_models[ $short_name ] = $classname; | |
| 893 | + } | |
| 894 | + $model_names[ $short_name ] = $classname; | |
| 895 | + } | |
| 896 | +		$this->registry->models = apply_filters('FHEE__EE_System__parse_model_names', $model_names); | |
| 897 | + $this->registry->non_abstract_db_models = apply_filters( | |
| 898 | + 'FHEE__EE_System__parse_implemented_model_names', | |
| 899 | + $non_abstract_db_models | |
| 900 | + ); | |
| 901 | + } | |
| 902 | + | |
| 903 | + | |
| 904 | + /** | |
| 905 | + * The purpose of this method is to simply check for a file named "caffeinated/brewing_regular.php" for any hooks | |
| 906 | + * that need to be setup before our EE_System launches. | |
| 907 | + * | |
| 908 | + * @return void | |
| 909 | + * @throws DomainException | |
| 910 | + * @throws InvalidArgumentException | |
| 911 | + * @throws InvalidDataTypeException | |
| 912 | + * @throws InvalidInterfaceException | |
| 913 | + * @throws InvalidClassException | |
| 914 | + * @throws InvalidFilePathException | |
| 915 | + */ | |
| 916 | + private function _maybe_brew_regular() | |
| 917 | +	{ | |
| 918 | + /** @var Domain $domain */ | |
| 919 | + $domain = DomainFactory::getEventEspressoCoreDomain(); | |
| 920 | +		if ($domain->isCaffeinated()) { | |
| 921 | + require_once EE_CAFF_PATH . 'brewing_regular.php'; | |
| 922 | + } | |
| 923 | + } | |
| 924 | + | |
| 925 | + | |
| 926 | + /** | |
| 927 | + * @since 4.9.71.p | |
| 928 | + * @throws Exception | |
| 929 | + */ | |
| 930 | + public function loadRouteMatchSpecifications() | |
| 931 | +	{ | |
| 932 | +		try { | |
| 933 | +			$this->loader->getShared('EventEspresso\core\services\routing\RouteMatchSpecificationManager'); | |
| 934 | +			$this->loader->getShared('EventEspresso\core\services\routing\RouteCollection'); | |
| 935 | + $this->router->loadPrimaryRoutes(); | |
| 936 | +		} catch (Exception $exception) { | |
| 937 | + new ExceptionStackTraceDisplay($exception); | |
| 938 | + } | |
| 939 | +		do_action('AHEE__EE_System__loadRouteMatchSpecifications'); | |
| 940 | + } | |
| 941 | + | |
| 942 | + | |
| 943 | + /** | |
| 944 | + * register_shortcodes_modules_and_widgets | |
| 945 | + * generate lists of shortcodes and modules, then verify paths and classes | |
| 946 | + * This is hooked into 'AHEE__EE_Bootstrap__register_shortcodes_modules_and_widgets' | |
| 947 | + * which runs during the WP 'plugins_loaded' action at priority 7 | |
| 948 | + * | |
| 949 | + * @access public | |
| 950 | + * @return void | |
| 951 | + * @throws Exception | |
| 952 | + */ | |
| 953 | + public function register_shortcodes_modules_and_widgets() | |
| 954 | +	{ | |
| 955 | + $this->router->registerShortcodesModulesAndWidgets(); | |
| 956 | +		do_action('AHEE__EE_System__register_shortcodes_modules_and_widgets'); | |
| 957 | + // check for addons using old hook point | |
| 958 | +		if (has_action('AHEE__EE_System__register_shortcodes_modules_and_addons')) { | |
| 959 | + $this->_incompatible_addon_error(); | |
| 960 | + } | |
| 961 | + } | |
| 962 | + | |
| 963 | + | |
| 964 | + /** | |
| 965 | + * _incompatible_addon_error | |
| 966 | + * | |
| 967 | + * @access public | |
| 968 | + * @return void | |
| 969 | + */ | |
| 970 | + private function _incompatible_addon_error() | |
| 971 | +	{ | |
| 972 | + // get array of classes hooking into here | |
| 973 | + $class_names = EEH_Class_Tools::get_class_names_for_all_callbacks_on_hook( | |
| 974 | + 'AHEE__EE_System__register_shortcodes_modules_and_addons' | |
| 975 | + ); | |
| 976 | +		if (! empty($class_names)) { | |
| 977 | + $msg = __( | |
| 978 | + 'The following plugins, addons, or modules appear to be incompatible with this version of Event Espresso and were automatically deactivated to avoid fatal errors:', | |
| 979 | + 'event_espresso' | |
| 980 | + ); | |
| 981 | + $msg .= '<ul>'; | |
| 982 | +			foreach ($class_names as $class_name) { | |
| 983 | + $msg .= '<li><b>Event Espresso - ' | |
| 984 | + . str_replace( | |
| 985 | +							array('EE_', 'EEM_', 'EED_', 'EES_', 'EEW_'), | |
| 986 | + '', | |
| 987 | + $class_name | |
| 988 | + ) . '</b></li>'; | |
| 989 | + } | |
| 990 | + $msg .= '</ul>'; | |
| 991 | + $msg .= __( | |
| 992 | + 'Compatibility issues can be avoided and/or resolved by keeping addons and plugins updated to the latest version.', | |
| 993 | + 'event_espresso' | |
| 994 | + ); | |
| 995 | + // save list of incompatible addons to wp-options for later use | |
| 996 | +			add_option('ee_incompatible_addons', $class_names, '', 'no'); | |
| 997 | +			if (is_admin()) { | |
| 998 | + EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); | |
| 999 | + } | |
| 1000 | + } | |
| 1001 | + } | |
| 1002 | + | |
| 1003 | + | |
| 1004 | + /** | |
| 1005 | + * brew_espresso | |
| 1006 | + * begins the process of setting hooks for initializing EE in the correct order | |
| 1007 | + * This is happening on the 'AHEE__EE_Bootstrap__brew_espresso' hook point | |
| 1008 | + * which runs during the WP 'plugins_loaded' action at priority 9 | |
| 1009 | + * | |
| 1010 | + * @return void | |
| 1011 | + * @throws Exception | |
| 1012 | + */ | |
| 1013 | + public function brew_espresso() | |
| 1014 | +	{ | |
| 1015 | +		do_action('AHEE__EE_System__brew_espresso__begin', $this); | |
| 1016 | + // load some final core systems | |
| 1017 | +		add_action('init', array($this, 'set_hooks_for_core'), 1); | |
| 1018 | +		add_action('init', array($this, 'perform_activations_upgrades_and_migrations'), 3); | |
| 1019 | +		add_action('init', array($this, 'load_CPTs_and_session'), 5); | |
| 1020 | +		add_action('init', array($this, 'load_controllers'), 7); | |
| 1021 | +		add_action('init', array($this, 'core_loaded_and_ready'), 9); | |
| 1022 | +		add_action('init', array($this, 'initialize'), 10); | |
| 1023 | +		add_action('init', array($this, 'initialize_last'), 100); | |
| 1024 | + $this->router->brewEspresso(); | |
| 1025 | +		do_action('AHEE__EE_System__brew_espresso__complete', $this); | |
| 1026 | + } | |
| 1027 | + | |
| 1028 | + | |
| 1029 | + /** | |
| 1030 | + * set_hooks_for_core | |
| 1031 | + * | |
| 1032 | + * @access public | |
| 1033 | + * @return void | |
| 1034 | + * @throws EE_Error | |
| 1035 | + */ | |
| 1036 | + public function set_hooks_for_core() | |
| 1037 | +	{ | |
| 1038 | + $this->_deactivate_incompatible_addons(); | |
| 1039 | +		do_action('AHEE__EE_System__set_hooks_for_core'); | |
| 1040 | +		$this->loader->getShared('EventEspresso\core\domain\values\session\SessionLifespan'); | |
| 1041 | + // caps need to be initialized on every request so that capability maps are set. | |
| 1042 | + // @see https://events.codebasehq.com/projects/event-espresso/tickets/8674 | |
| 1043 | + $this->registry->CAP->init_caps(); | |
| 1044 | + } | |
| 1045 | + | |
| 1046 | + | |
| 1047 | + /** | |
| 1048 | + * Using the information gathered in EE_System::_incompatible_addon_error, | |
| 1049 | + * deactivates any addons considered incompatible with the current version of EE | |
| 1050 | + */ | |
| 1051 | + private function _deactivate_incompatible_addons() | |
| 1052 | +	{ | |
| 1053 | +		$incompatible_addons = get_option('ee_incompatible_addons', array()); | |
| 1054 | +		if (! empty($incompatible_addons)) { | |
| 1055 | +			$active_plugins = get_option('active_plugins', array()); | |
| 1056 | +			foreach ($active_plugins as $active_plugin) { | |
| 1057 | +				foreach ($incompatible_addons as $incompatible_addon) { | |
| 1058 | +					if (strpos($active_plugin, $incompatible_addon) !== false) { | |
| 1059 | + unset($_GET['activate']); | |
| 1060 | + espresso_deactivate_plugin($active_plugin); | |
| 1061 | + } | |
| 1062 | + } | |
| 1063 | + } | |
| 1064 | + } | |
| 1065 | + } | |
| 1066 | + | |
| 1067 | + | |
| 1068 | + /** | |
| 1069 | + * perform_activations_upgrades_and_migrations | |
| 1070 | + * | |
| 1071 | + * @access public | |
| 1072 | + * @return void | |
| 1073 | + */ | |
| 1074 | + public function perform_activations_upgrades_and_migrations() | |
| 1075 | +	{ | |
| 1076 | +		do_action('AHEE__EE_System__perform_activations_upgrades_and_migrations'); | |
| 1077 | + } | |
| 1078 | + | |
| 1079 | + | |
| 1080 | + /** | |
| 1081 | + * @return void | |
| 1082 | + * @throws DomainException | |
| 1083 | + */ | |
| 1084 | + public function load_CPTs_and_session() | |
| 1085 | +	{ | |
| 1086 | +		do_action('AHEE__EE_System__load_CPTs_and_session__start'); | |
| 1087 | + /** @var EventEspresso\core\domain\services\custom_post_types\RegisterCustomTaxonomies $register_custom_taxonomies */ | |
| 1088 | + $register_custom_taxonomies = $this->loader->getShared( | |
| 1089 | + 'EventEspresso\core\domain\services\custom_post_types\RegisterCustomTaxonomies' | |
| 1090 | + ); | |
| 1091 | + $register_custom_taxonomies->registerCustomTaxonomies(); | |
| 1092 | + /** @var EventEspresso\core\domain\services\custom_post_types\RegisterCustomPostTypes $register_custom_post_types */ | |
| 1093 | + $register_custom_post_types = $this->loader->getShared( | |
| 1094 | + 'EventEspresso\core\domain\services\custom_post_types\RegisterCustomPostTypes' | |
| 1095 | + ); | |
| 1096 | + $register_custom_post_types->registerCustomPostTypes(); | |
| 1097 | + /** @var EventEspresso\core\domain\services\custom_post_types\RegisterCustomTaxonomyTerms $register_custom_taxonomy_terms */ | |
| 1098 | + $register_custom_taxonomy_terms = $this->loader->getShared( | |
| 1099 | + 'EventEspresso\core\domain\services\custom_post_types\RegisterCustomTaxonomyTerms' | |
| 1100 | + ); | |
| 1101 | + $register_custom_taxonomy_terms->registerCustomTaxonomyTerms(); | |
| 1102 | + // load legacy Custom Post Types and Taxonomies | |
| 1103 | +		$this->loader->getShared('EE_Register_CPTs'); | |
| 1104 | +		do_action('AHEE__EE_System__load_CPTs_and_session__complete'); | |
| 1105 | + } | |
| 1106 | + | |
| 1107 | + | |
| 1108 | + /** | |
| 1109 | + * load_controllers | |
| 1110 | + * this is the best place to load any additional controllers that needs access to EE core. | |
| 1111 | + * it is expected that all basic core EE systems, that are not dependant on the current request are loaded at this | |
| 1112 | + * time | |
| 1113 | + * | |
| 1114 | + * @access public | |
| 1115 | + * @return void | |
| 1116 | + * @throws Exception | |
| 1117 | + */ | |
| 1118 | + public function load_controllers() | |
| 1119 | +	{ | |
| 1120 | +		do_action('AHEE__EE_System__load_controllers__start'); | |
| 1121 | + $this->router->loadControllers(); | |
| 1122 | +		do_action('AHEE__EE_System__load_controllers__complete'); | |
| 1123 | + } | |
| 1124 | + | |
| 1125 | + | |
| 1126 | + /** | |
| 1127 | + * core_loaded_and_ready | |
| 1128 | + * all of the basic EE core should be loaded at this point and available regardless of M-Mode | |
| 1129 | + * | |
| 1130 | + * @access public | |
| 1131 | + * @return void | |
| 1132 | + * @throws Exception | |
| 1133 | + */ | |
| 1134 | + public function core_loaded_and_ready() | |
| 1135 | +	{ | |
| 1136 | + $this->router->coreLoadedAndReady(); | |
| 1137 | + // integrate WP_Query with the EE models | |
| 1138 | +		$this->loader->getShared('EE_CPT_Strategy'); | |
| 1139 | +		do_action('AHEE__EE_System__core_loaded_and_ready'); | |
| 1140 | + // always load template tags, because it's faster than checking if it's a front-end request, and many page | |
| 1141 | + // builders require these even on the front-end | |
| 1142 | + require_once EE_PUBLIC . 'template_tags.php'; | |
| 1143 | +		do_action('AHEE__EE_System__set_hooks_for_shortcodes_modules_and_addons'); | |
| 1144 | + } | |
| 1145 | + | |
| 1146 | + | |
| 1147 | + /** | |
| 1148 | + * initialize | |
| 1149 | + * this is the best place to begin initializing client code | |
| 1150 | + * | |
| 1151 | + * @access public | |
| 1152 | + * @return void | |
| 1153 | + */ | |
| 1154 | + public function initialize() | |
| 1155 | +	{ | |
| 1156 | +		do_action('AHEE__EE_System__initialize'); | |
| 1157 | + } | |
| 1158 | + | |
| 1159 | + | |
| 1160 | + /** | |
| 1161 | + * initialize_last | |
| 1162 | + * this is run really late during the WP init hook point, and ensures that mostly everything else that needs to | |
| 1163 | + * initialize has done so | |
| 1164 | + * | |
| 1165 | + * @access public | |
| 1166 | + * @return void | |
| 1167 | + * @throws Exception | |
| 1168 | + */ | |
| 1169 | + public function initialize_last() | |
| 1170 | +	{ | |
| 1171 | +		do_action('AHEE__EE_System__initialize_last'); | |
| 1172 | + /** @var EventEspresso\core\domain\services\custom_post_types\RewriteRules $rewrite_rules */ | |
| 1173 | + $rewrite_rules = $this->loader->getShared( | |
| 1174 | + 'EventEspresso\core\domain\services\custom_post_types\RewriteRules' | |
| 1175 | + ); | |
| 1176 | + $rewrite_rules->flushRewriteRules(); | |
| 1177 | + $this->router->initializeLast(); | |
| 1178 | +		add_action('admin_bar_init', array($this, 'addEspressoToolbar')); | |
| 1179 | + } | |
| 1180 | + | |
| 1181 | + | |
| 1182 | + /** | |
| 1183 | + * @return void | |
| 1184 | + */ | |
| 1185 | + public function addEspressoToolbar() | |
| 1186 | +	{ | |
| 1187 | + $this->loader->getShared( | |
| 1188 | + 'EventEspresso\core\domain\services\admin\AdminToolBar', | |
| 1189 | + array($this->registry->CAP) | |
| 1190 | + ); | |
| 1191 | + } | |
| 1192 | + | |
| 1193 | + | |
| 1194 | + /** | |
| 1195 | + * do_not_cache | |
| 1196 | + * sets no cache headers and defines no cache constants for WP plugins | |
| 1197 | + * | |
| 1198 | + * @access public | |
| 1199 | + * @return void | |
| 1200 | + */ | |
| 1201 | + public static function do_not_cache() | |
| 1202 | +	{ | |
| 1203 | + // set no cache constants | |
| 1204 | +		if (! defined('DONOTCACHEPAGE')) { | |
| 1205 | +			define('DONOTCACHEPAGE', true); | |
| 1206 | + } | |
| 1207 | +		if (! defined('DONOTCACHCEOBJECT')) { | |
| 1208 | +			define('DONOTCACHCEOBJECT', true); | |
| 1209 | + } | |
| 1210 | +		if (! defined('DONOTCACHEDB')) { | |
| 1211 | +			define('DONOTCACHEDB', true); | |
| 1212 | + } | |
| 1213 | + // add no cache headers | |
| 1214 | +		add_action('send_headers', array('EE_System', 'nocache_headers'), 10); | |
| 1215 | + // plus a little extra for nginx and Google Chrome | |
| 1216 | +		add_filter('nocache_headers', array('EE_System', 'extra_nocache_headers'), 10, 1); | |
| 1217 | + // prevent browsers from prefetching of the rel='next' link, because it may contain content that interferes with the registration process | |
| 1218 | +		remove_action('wp_head', 'adjacent_posts_rel_link_wp_head'); | |
| 1219 | + } | |
| 1220 | + | |
| 1221 | + | |
| 1222 | + /** | |
| 1223 | + * extra_nocache_headers | |
| 1224 | + * | |
| 1225 | + * @access public | |
| 1226 | + * @param $headers | |
| 1227 | + * @return array | |
| 1228 | + */ | |
| 1229 | + public static function extra_nocache_headers($headers) | |
| 1230 | +	{ | |
| 1231 | + // for NGINX | |
| 1232 | + $headers['X-Accel-Expires'] = 0; | |
| 1233 | + // plus extra for Google Chrome since it doesn't seem to respect "no-cache", but WILL respect "no-store" | |
| 1234 | + $headers['Cache-Control'] = 'no-store, no-cache, must-revalidate, max-age=0'; | |
| 1235 | + return $headers; | |
| 1236 | + } | |
| 1237 | + | |
| 1238 | + | |
| 1239 | + /** | |
| 1240 | + * nocache_headers | |
| 1241 | + * | |
| 1242 | + * @access public | |
| 1243 | + * @return void | |
| 1244 | + */ | |
| 1245 | + public static function nocache_headers() | |
| 1246 | +	{ | |
| 1247 | + nocache_headers(); | |
| 1248 | + } | |
| 1249 | + | |
| 1250 | + | |
| 1251 | + /** | |
| 1252 | + * simply hooks into "wp_list_pages_exclude" filter (for wp_list_pages method) and makes sure EE critical pages are | |
| 1253 | + * never returned with the function. | |
| 1254 | + * | |
| 1255 | + * @param array $exclude_array any existing pages being excluded are in this array. | |
| 1256 | + * @return array | |
| 1257 | + */ | |
| 1258 | + public function remove_pages_from_wp_list_pages($exclude_array) | |
| 1259 | +	{ | |
| 1260 | + return array_merge($exclude_array, $this->registry->CFG->core->get_critical_pages_array()); | |
| 1261 | + } | |
| 1262 | 1262 | } | 
| @@ -141,7 +141,7 @@ discard block | ||
| 141 | 141 | Router $router = null | 
| 142 | 142 |      ) { | 
| 143 | 143 | // check if class object is instantiated | 
| 144 | -        if (! self::$_instance instanceof EE_System) { | |
| 144 | +        if ( ! self::$_instance instanceof EE_System) { | |
| 145 | 145 | self::$_instance = new self($loader, $maintenance_mode, $registry, $request, $router); | 
| 146 | 146 | } | 
| 147 | 147 | return self::$_instance; | 
| @@ -265,7 +265,7 @@ discard block | ||
| 265 | 265 |          $this->capabilities = $this->loader->getShared('EE_Capabilities'); | 
| 266 | 266 | add_action( | 
| 267 | 267 | 'AHEE__EE_Capabilities__init_caps__before_initialization', | 
| 268 | -            function () { | |
| 268 | +            function() { | |
| 269 | 269 |                  LoaderFactory::getLoader()->getShared('EE_Payment_Method_Manager'); | 
| 270 | 270 | } | 
| 271 | 271 | ); | 
| @@ -305,7 +305,7 @@ discard block | ||
| 305 | 305 |      { | 
| 306 | 306 | // set autoloaders for all of the classes implementing EEI_Plugin_API | 
| 307 | 307 | // which provide helpers for EE plugin authors to more easily register certain components with EE. | 
| 308 | - EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_LIBRARIES . 'plugin_api'); | |
| 308 | + EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_LIBRARIES.'plugin_api'); | |
| 309 | 309 |          $this->loader->getShared('EE_Request_Handler'); | 
| 310 | 310 | } | 
| 311 | 311 | |
| @@ -325,14 +325,14 @@ discard block | ||
| 325 | 325 | $load_callback, | 
| 326 | 326 | $plugin_file_constant | 
| 327 | 327 |      ) { | 
| 328 | -        if (! defined($version_constant)) { | |
| 328 | +        if ( ! defined($version_constant)) { | |
| 329 | 329 | return; | 
| 330 | 330 | } | 
| 331 | 331 | $addon_version = constant($version_constant); | 
| 332 | 332 |          if ($addon_version && version_compare($addon_version, $min_version_required, '<')) { | 
| 333 | 333 |              remove_action('AHEE__EE_System__load_espresso_addons', $load_callback); | 
| 334 | -            if (! function_exists('deactivate_plugins')) { | |
| 335 | - require_once ABSPATH . 'wp-admin/includes/plugin.php'; | |
| 334 | +            if ( ! function_exists('deactivate_plugins')) { | |
| 335 | + require_once ABSPATH.'wp-admin/includes/plugin.php'; | |
| 336 | 336 | } | 
| 337 | 337 | deactivate_plugins(plugin_basename(constant($plugin_file_constant))); | 
| 338 | 338 | unset($_GET['activate'], $_REQUEST['activate'], $_GET['activate-multi'], $_REQUEST['activate-multi']); | 
| @@ -346,7 +346,7 @@ discard block | ||
| 346 | 346 | $min_version_required | 
| 347 | 347 | ), | 
| 348 | 348 | __FILE__, | 
| 349 | -                __FUNCTION__ . "({$addon_name})", | |
| 349 | +                __FUNCTION__."({$addon_name})", | |
| 350 | 350 | __LINE__ | 
| 351 | 351 | ); | 
| 352 | 352 | EE_Error::get_notices(false, true); | 
| @@ -392,7 +392,7 @@ discard block | ||
| 392 | 392 |              && ! function_exists('json_basic_auth_handler') | 
| 393 | 393 |              && ! function_exists('json_basic_auth_error') | 
| 394 | 394 |          ) { | 
| 395 | - include_once EE_THIRD_PARTY . 'wp-api-basic-auth/basic-auth.php'; | |
| 395 | + include_once EE_THIRD_PARTY.'wp-api-basic-auth/basic-auth.php'; | |
| 396 | 396 | } | 
| 397 | 397 |          do_action('AHEE__EE_System__load_espresso_addons__complete'); | 
| 398 | 398 | } | 
| @@ -494,11 +494,11 @@ discard block | ||
| 494 | 494 | private function fix_espresso_db_upgrade_option($espresso_db_update = null) | 
| 495 | 495 |      { | 
| 496 | 496 |          do_action('FHEE__EE_System__manage_fix_espresso_db_upgrade_option__begin', $espresso_db_update); | 
| 497 | -        if (! $espresso_db_update) { | |
| 497 | +        if ( ! $espresso_db_update) { | |
| 498 | 498 |              $espresso_db_update = get_option('espresso_db_update'); | 
| 499 | 499 | } | 
| 500 | 500 | // check that option is an array | 
| 501 | -        if (! is_array($espresso_db_update)) { | |
| 501 | +        if ( ! is_array($espresso_db_update)) { | |
| 502 | 502 | // if option is FALSE, then it never existed | 
| 503 | 503 |              if ($espresso_db_update === false) { | 
| 504 | 504 | // make $espresso_db_update an array and save option with autoload OFF | 
| @@ -518,10 +518,10 @@ discard block | ||
| 518 | 518 | // so it must be numerically-indexed, where values are versions installed... | 
| 519 | 519 | // fix it! | 
| 520 | 520 | $version_string = $should_be_array; | 
| 521 | -                    $corrected_db_update[ $version_string ] = array('unknown-date'); | |
| 521 | +                    $corrected_db_update[$version_string] = array('unknown-date'); | |
| 522 | 522 |                  } else { | 
| 523 | 523 | // ok it checks out | 
| 524 | - $corrected_db_update[ $should_be_version_string ] = $should_be_array; | |
| 524 | + $corrected_db_update[$should_be_version_string] = $should_be_array; | |
| 525 | 525 | } | 
| 526 | 526 | } | 
| 527 | 527 | $espresso_db_update = $corrected_db_update; | 
| @@ -604,13 +604,13 @@ discard block | ||
| 604 | 604 | */ | 
| 605 | 605 | public function update_list_of_installed_versions($version_history = null, $current_version_to_add = null) | 
| 606 | 606 |      { | 
| 607 | -        if (! $version_history) { | |
| 607 | +        if ( ! $version_history) { | |
| 608 | 608 | $version_history = $this->fix_espresso_db_upgrade_option($version_history); | 
| 609 | 609 | } | 
| 610 | 610 |          if ($current_version_to_add === null) { | 
| 611 | 611 | $current_version_to_add = espresso_version(); | 
| 612 | 612 | } | 
| 613 | -        $version_history[ $current_version_to_add ][] = date('Y-m-d H:i:s', time()); | |
| 613 | +        $version_history[$current_version_to_add][] = date('Y-m-d H:i:s', time()); | |
| 614 | 614 | // re-save | 
| 615 | 615 |          return update_option('espresso_db_update', $version_history); | 
| 616 | 616 | } | 
| @@ -701,7 +701,7 @@ discard block | ||
| 701 | 701 |          if ($activation_history_for_addon) { | 
| 702 | 702 | // it exists, so this isn't a completely new install | 
| 703 | 703 | // check if this version already in that list of previously installed versions | 
| 704 | -            if (! isset($activation_history_for_addon[ $version_to_upgrade_to ])) { | |
| 704 | +            if ( ! isset($activation_history_for_addon[$version_to_upgrade_to])) { | |
| 705 | 705 | // it a version we haven't seen before | 
| 706 | 706 |                  if ($version_is_higher === 1) { | 
| 707 | 707 | $req_type = EE_System::req_type_upgrade; | 
| @@ -779,7 +779,7 @@ discard block | ||
| 779 | 779 |              foreach ($activation_history as $version => $times_activated) { | 
| 780 | 780 | // check there is a record of when this version was activated. Otherwise, | 
| 781 | 781 | // mark it as unknown | 
| 782 | -                if (! $times_activated) { | |
| 782 | +                if ( ! $times_activated) { | |
| 783 | 783 |                      $times_activated = array('unknown-date'); | 
| 784 | 784 | } | 
| 785 | 785 |                  if (is_string($times_activated)) { | 
| @@ -810,7 +810,7 @@ discard block | ||
| 810 | 810 |      { | 
| 811 | 811 | $notices = EE_Error::get_notices(false); | 
| 812 | 812 | // if current user is an admin and it's not an ajax or rest request | 
| 813 | - if (! isset($notices['errors']) | |
| 813 | + if ( ! isset($notices['errors']) | |
| 814 | 814 | && $this->request->isAdmin() | 
| 815 | 815 | && apply_filters( | 
| 816 | 816 | 'FHEE__EE_System__redirect_to_about_ee__do_redirect', | 
| @@ -880,7 +880,7 @@ discard block | ||
| 880 | 880 | private function _parse_model_names() | 
| 881 | 881 |      { | 
| 882 | 882 | // get all the files in the EE_MODELS folder that end in .model.php | 
| 883 | - $models = glob(EE_MODELS . '*.model.php'); | |
| 883 | + $models = glob(EE_MODELS.'*.model.php'); | |
| 884 | 884 | $model_names = array(); | 
| 885 | 885 | $non_abstract_db_models = array(); | 
| 886 | 886 |          foreach ($models as $model) { | 
| @@ -889,9 +889,9 @@ discard block | ||
| 889 | 889 |              $short_name = str_replace('EEM_', '', $classname); | 
| 890 | 890 | $reflectionClass = new ReflectionClass($classname); | 
| 891 | 891 |              if ($reflectionClass->isSubclassOf('EEM_Base') && ! $reflectionClass->isAbstract()) { | 
| 892 | - $non_abstract_db_models[ $short_name ] = $classname; | |
| 892 | + $non_abstract_db_models[$short_name] = $classname; | |
| 893 | 893 | } | 
| 894 | - $model_names[ $short_name ] = $classname; | |
| 894 | + $model_names[$short_name] = $classname; | |
| 895 | 895 | } | 
| 896 | 896 |          $this->registry->models = apply_filters('FHEE__EE_System__parse_model_names', $model_names); | 
| 897 | 897 | $this->registry->non_abstract_db_models = apply_filters( | 
| @@ -918,7 +918,7 @@ discard block | ||
| 918 | 918 | /** @var Domain $domain */ | 
| 919 | 919 | $domain = DomainFactory::getEventEspressoCoreDomain(); | 
| 920 | 920 |          if ($domain->isCaffeinated()) { | 
| 921 | - require_once EE_CAFF_PATH . 'brewing_regular.php'; | |
| 921 | + require_once EE_CAFF_PATH.'brewing_regular.php'; | |
| 922 | 922 | } | 
| 923 | 923 | } | 
| 924 | 924 | |
| @@ -973,7 +973,7 @@ discard block | ||
| 973 | 973 | $class_names = EEH_Class_Tools::get_class_names_for_all_callbacks_on_hook( | 
| 974 | 974 | 'AHEE__EE_System__register_shortcodes_modules_and_addons' | 
| 975 | 975 | ); | 
| 976 | -        if (! empty($class_names)) { | |
| 976 | +        if ( ! empty($class_names)) { | |
| 977 | 977 | $msg = __( | 
| 978 | 978 | 'The following plugins, addons, or modules appear to be incompatible with this version of Event Espresso and were automatically deactivated to avoid fatal errors:', | 
| 979 | 979 | 'event_espresso' | 
| @@ -985,7 +985,7 @@ discard block | ||
| 985 | 985 |                              array('EE_', 'EEM_', 'EED_', 'EES_', 'EEW_'), | 
| 986 | 986 | '', | 
| 987 | 987 | $class_name | 
| 988 | - ) . '</b></li>'; | |
| 988 | + ).'</b></li>'; | |
| 989 | 989 | } | 
| 990 | 990 | $msg .= '</ul>'; | 
| 991 | 991 | $msg .= __( | 
| @@ -1051,7 +1051,7 @@ discard block | ||
| 1051 | 1051 | private function _deactivate_incompatible_addons() | 
| 1052 | 1052 |      { | 
| 1053 | 1053 |          $incompatible_addons = get_option('ee_incompatible_addons', array()); | 
| 1054 | -        if (! empty($incompatible_addons)) { | |
| 1054 | +        if ( ! empty($incompatible_addons)) { | |
| 1055 | 1055 |              $active_plugins = get_option('active_plugins', array()); | 
| 1056 | 1056 |              foreach ($active_plugins as $active_plugin) { | 
| 1057 | 1057 |                  foreach ($incompatible_addons as $incompatible_addon) { | 
| @@ -1139,7 +1139,7 @@ discard block | ||
| 1139 | 1139 |          do_action('AHEE__EE_System__core_loaded_and_ready'); | 
| 1140 | 1140 | // always load template tags, because it's faster than checking if it's a front-end request, and many page | 
| 1141 | 1141 | // builders require these even on the front-end | 
| 1142 | - require_once EE_PUBLIC . 'template_tags.php'; | |
| 1142 | + require_once EE_PUBLIC.'template_tags.php'; | |
| 1143 | 1143 |          do_action('AHEE__EE_System__set_hooks_for_shortcodes_modules_and_addons'); | 
| 1144 | 1144 | } | 
| 1145 | 1145 | |
| @@ -1201,13 +1201,13 @@ discard block | ||
| 1201 | 1201 | public static function do_not_cache() | 
| 1202 | 1202 |      { | 
| 1203 | 1203 | // set no cache constants | 
| 1204 | -        if (! defined('DONOTCACHEPAGE')) { | |
| 1204 | +        if ( ! defined('DONOTCACHEPAGE')) { | |
| 1205 | 1205 |              define('DONOTCACHEPAGE', true); | 
| 1206 | 1206 | } | 
| 1207 | -        if (! defined('DONOTCACHCEOBJECT')) { | |
| 1207 | +        if ( ! defined('DONOTCACHCEOBJECT')) { | |
| 1208 | 1208 |              define('DONOTCACHCEOBJECT', true); | 
| 1209 | 1209 | } | 
| 1210 | -        if (! defined('DONOTCACHEDB')) { | |
| 1210 | +        if ( ! defined('DONOTCACHEDB')) { | |
| 1211 | 1211 |              define('DONOTCACHEDB', true); | 
| 1212 | 1212 | } | 
| 1213 | 1213 | // add no cache headers | 
| @@ -11,10 +11,10 @@ | ||
| 11 | 11 | interface StaticFactoryInterface | 
| 12 | 12 |  { | 
| 13 | 13 | |
| 14 | - /** | |
| 15 | - * @param string $fqcn Fully Qualified Class Name | |
| 16 | - * @param array $arguments [optional] array of data required for construction | |
| 17 | - * @return mixed | |
| 18 | - */ | |
| 19 | - public static function create($fqcn, array $arguments = []); | |
| 14 | + /** | |
| 15 | + * @param string $fqcn Fully Qualified Class Name | |
| 16 | + * @param array $arguments [optional] array of data required for construction | |
| 17 | + * @return mixed | |
| 18 | + */ | |
| 19 | + public static function create($fqcn, array $arguments = []); | |
| 20 | 20 | } | 
| @@ -7,19 +7,19 @@ | ||
| 7 | 7 | abstract class Factory implements FactoryInterface | 
| 8 | 8 |  { | 
| 9 | 9 | |
| 10 | - /** | |
| 11 | - * @var LoaderInterface $loader | |
| 12 | - */ | |
| 13 | - protected $loader; | |
| 10 | + /** | |
| 11 | + * @var LoaderInterface $loader | |
| 12 | + */ | |
| 13 | + protected $loader; | |
| 14 | 14 | |
| 15 | 15 | |
| 16 | - /** | |
| 17 | - * RouteFactory constructor. | |
| 18 | - * | |
| 19 | - * @param LoaderInterface $loader | |
| 20 | - */ | |
| 21 | - public function __construct(LoaderInterface $loader) | |
| 22 | -    { | |
| 23 | - $this->loader = $loader; | |
| 24 | - } | |
| 16 | + /** | |
| 17 | + * RouteFactory constructor. | |
| 18 | + * | |
| 19 | + * @param LoaderInterface $loader | |
| 20 | + */ | |
| 21 | + public function __construct(LoaderInterface $loader) | |
| 22 | +	{ | |
| 23 | + $this->loader = $loader; | |
| 24 | + } | |
| 25 | 25 | } | 
| @@ -11,10 +11,10 @@ | ||
| 11 | 11 | interface FactoryInterface | 
| 12 | 12 |  { | 
| 13 | 13 | |
| 14 | - /** | |
| 15 | - * @param string $fqcn Fully Qualified Class Name | |
| 16 | - * @param array $arguments [optional] array of data required for construction | |
| 17 | - * @return mixed | |
| 18 | - */ | |
| 19 | - public function create($fqcn, array $arguments = []); | |
| 14 | + /** | |
| 15 | + * @param string $fqcn Fully Qualified Class Name | |
| 16 | + * @param array $arguments [optional] array of data required for construction | |
| 17 | + * @return mixed | |
| 18 | + */ | |
| 19 | + public function create($fqcn, array $arguments = []); | |
| 20 | 20 | } | 
| @@ -16,115 +16,115 @@ | ||
| 16 | 16 | class ObjectIdentifier | 
| 17 | 17 |  { | 
| 18 | 18 | |
| 19 | - /** | |
| 20 | - * used to separate the FQCN from the class's arguments identifier | |
| 21 | - */ | |
| 22 | - const DELIMITER = '____'; | |
| 19 | + /** | |
| 20 | + * used to separate the FQCN from the class's arguments identifier | |
| 21 | + */ | |
| 22 | + const DELIMITER = '____'; | |
| 23 | 23 | |
| 24 | - /** | |
| 25 | - * @var ClassInterfaceCache $class_cache | |
| 26 | - */ | |
| 27 | - private $class_cache; | |
| 24 | + /** | |
| 25 | + * @var ClassInterfaceCache $class_cache | |
| 26 | + */ | |
| 27 | + private $class_cache; | |
| 28 | 28 | |
| 29 | 29 | |
| 30 | - /** | |
| 31 | - * ObjectIdentifier constructor. | |
| 32 | - * | |
| 33 | - * @param ClassInterfaceCache $class_cache | |
| 34 | - */ | |
| 35 | - public function __construct(ClassInterfaceCache $class_cache) | |
| 36 | -    { | |
| 37 | - $this->class_cache = $class_cache; | |
| 38 | - } | |
| 30 | + /** | |
| 31 | + * ObjectIdentifier constructor. | |
| 32 | + * | |
| 33 | + * @param ClassInterfaceCache $class_cache | |
| 34 | + */ | |
| 35 | + public function __construct(ClassInterfaceCache $class_cache) | |
| 36 | +	{ | |
| 37 | + $this->class_cache = $class_cache; | |
| 38 | + } | |
| 39 | 39 | |
| 40 | 40 | |
| 41 | - /** | |
| 42 | - * Returns true if the supplied $object_identifier contains | |
| 43 | - * the delimiter used to separate an fqcn from the arguments hash | |
| 44 | - * | |
| 45 | - * @param string $object_identifier | |
| 46 | - * @return bool | |
| 47 | - */ | |
| 48 | - public function hasArguments($object_identifier) | |
| 49 | -    { | |
| 50 | - // type casting to bool instead of using strpos() !== false | |
| 51 | - // because an object identifier should never begin with the delimiter | |
| 52 | - // therefore the delimiter should NOT be found at position 0 | |
| 53 | - return (bool) strpos($object_identifier, ObjectIdentifier::DELIMITER); | |
| 54 | - } | |
| 41 | + /** | |
| 42 | + * Returns true if the supplied $object_identifier contains | |
| 43 | + * the delimiter used to separate an fqcn from the arguments hash | |
| 44 | + * | |
| 45 | + * @param string $object_identifier | |
| 46 | + * @return bool | |
| 47 | + */ | |
| 48 | + public function hasArguments($object_identifier) | |
| 49 | +	{ | |
| 50 | + // type casting to bool instead of using strpos() !== false | |
| 51 | + // because an object identifier should never begin with the delimiter | |
| 52 | + // therefore the delimiter should NOT be found at position 0 | |
| 53 | + return (bool) strpos($object_identifier, ObjectIdentifier::DELIMITER); | |
| 54 | + } | |
| 55 | 55 | |
| 56 | 56 | |
| 57 | - /** | |
| 58 | - * Returns true if the supplied FQCN equals the supplied $object_identifier | |
| 59 | - * OR the supplied FQCN matches the FQCN portion of the supplied $object_identifier | |
| 60 | - * AND that $object_identifier is for an object with arguments. | |
| 61 | - * This allows a request for an object using a FQCN to match | |
| 62 | - * a previously instantiated object with arguments | |
| 63 | - * without having to know those arguments. | |
| 64 | - * | |
| 65 | - * @param string $fqcn | |
| 66 | - * @param string $object_identifier | |
| 67 | - * @return bool | |
| 68 | - */ | |
| 69 | - public function fqcnMatchesObjectIdentifier($fqcn, $object_identifier) | |
| 70 | -    { | |
| 71 | -        $fqcn = str_replace('\\', '_', $fqcn); | |
| 72 | - return $fqcn === $object_identifier | |
| 73 | - || strpos($object_identifier, $fqcn . ObjectIdentifier::DELIMITER) === 0; | |
| 74 | - } | |
| 57 | + /** | |
| 58 | + * Returns true if the supplied FQCN equals the supplied $object_identifier | |
| 59 | + * OR the supplied FQCN matches the FQCN portion of the supplied $object_identifier | |
| 60 | + * AND that $object_identifier is for an object with arguments. | |
| 61 | + * This allows a request for an object using a FQCN to match | |
| 62 | + * a previously instantiated object with arguments | |
| 63 | + * without having to know those arguments. | |
| 64 | + * | |
| 65 | + * @param string $fqcn | |
| 66 | + * @param string $object_identifier | |
| 67 | + * @return bool | |
| 68 | + */ | |
| 69 | + public function fqcnMatchesObjectIdentifier($fqcn, $object_identifier) | |
| 70 | +	{ | |
| 71 | +		$fqcn = str_replace('\\', '_', $fqcn); | |
| 72 | + return $fqcn === $object_identifier | |
| 73 | + || strpos($object_identifier, $fqcn . ObjectIdentifier::DELIMITER) === 0; | |
| 74 | + } | |
| 75 | 75 | |
| 76 | 76 | |
| 77 | - /** | |
| 78 | - * build a string representation of an object's FQCN and arguments | |
| 79 | - * | |
| 80 | - * @param string $fqcn | |
| 81 | - * @param array $arguments | |
| 82 | - * @return string | |
| 83 | - */ | |
| 84 | - public function getIdentifier($fqcn, array $arguments = array()) | |
| 85 | -    { | |
| 86 | - // only build identifier from arguments if class is not ReservedInstanceInterface | |
| 87 | - $identifier = ! $this->class_cache->hasInterface( | |
| 88 | - $fqcn, | |
| 89 | - 'EventEspresso\core\interfaces\ReservedInstanceInterface' | |
| 90 | - ) | |
| 91 | - ? $this->getIdentifierForArguments($arguments) | |
| 92 | - : ''; | |
| 93 | -        if (! empty($identifier)) { | |
| 94 | - $fqcn .= ObjectIdentifier::DELIMITER . md5($identifier); | |
| 95 | - } | |
| 96 | -        $fqcn = str_replace('\\', '_', $fqcn); | |
| 97 | - return $fqcn; | |
| 98 | - } | |
| 77 | + /** | |
| 78 | + * build a string representation of an object's FQCN and arguments | |
| 79 | + * | |
| 80 | + * @param string $fqcn | |
| 81 | + * @param array $arguments | |
| 82 | + * @return string | |
| 83 | + */ | |
| 84 | + public function getIdentifier($fqcn, array $arguments = array()) | |
| 85 | +	{ | |
| 86 | + // only build identifier from arguments if class is not ReservedInstanceInterface | |
| 87 | + $identifier = ! $this->class_cache->hasInterface( | |
| 88 | + $fqcn, | |
| 89 | + 'EventEspresso\core\interfaces\ReservedInstanceInterface' | |
| 90 | + ) | |
| 91 | + ? $this->getIdentifierForArguments($arguments) | |
| 92 | + : ''; | |
| 93 | +		if (! empty($identifier)) { | |
| 94 | + $fqcn .= ObjectIdentifier::DELIMITER . md5($identifier); | |
| 95 | + } | |
| 96 | +		$fqcn = str_replace('\\', '_', $fqcn); | |
| 97 | + return $fqcn; | |
| 98 | + } | |
| 99 | 99 | |
| 100 | 100 | |
| 101 | - /** | |
| 102 | - * build a string representation of a object's arguments | |
| 103 | - * (mostly because Closures can't be serialized) | |
| 104 | - * | |
| 105 | - * @param array $arguments | |
| 106 | - * @return string | |
| 107 | - */ | |
| 108 | - protected function getIdentifierForArguments(array $arguments) | |
| 109 | -    { | |
| 110 | -        if (empty($arguments)) { | |
| 111 | - return ''; | |
| 112 | - } | |
| 113 | - $identifier = ''; | |
| 114 | -        foreach ($arguments as $argument) { | |
| 115 | -            switch (true) { | |
| 116 | - case is_object($argument): | |
| 117 | - case $argument instanceof Closure: | |
| 118 | - $identifier .= spl_object_hash($argument); | |
| 119 | - break; | |
| 120 | - case is_array($argument): | |
| 121 | - $identifier .= $this->getIdentifierForArguments($argument); | |
| 122 | - break; | |
| 123 | - default: | |
| 124 | - $identifier .= $argument; | |
| 125 | - break; | |
| 126 | - } | |
| 127 | - } | |
| 128 | - return $identifier; | |
| 129 | - } | |
| 101 | + /** | |
| 102 | + * build a string representation of a object's arguments | |
| 103 | + * (mostly because Closures can't be serialized) | |
| 104 | + * | |
| 105 | + * @param array $arguments | |
| 106 | + * @return string | |
| 107 | + */ | |
| 108 | + protected function getIdentifierForArguments(array $arguments) | |
| 109 | +	{ | |
| 110 | +		if (empty($arguments)) { | |
| 111 | + return ''; | |
| 112 | + } | |
| 113 | + $identifier = ''; | |
| 114 | +		foreach ($arguments as $argument) { | |
| 115 | +			switch (true) { | |
| 116 | + case is_object($argument): | |
| 117 | + case $argument instanceof Closure: | |
| 118 | + $identifier .= spl_object_hash($argument); | |
| 119 | + break; | |
| 120 | + case is_array($argument): | |
| 121 | + $identifier .= $this->getIdentifierForArguments($argument); | |
| 122 | + break; | |
| 123 | + default: | |
| 124 | + $identifier .= $argument; | |
| 125 | + break; | |
| 126 | + } | |
| 127 | + } | |
| 128 | + return $identifier; | |
| 129 | + } | |
| 130 | 130 | } | 
| @@ -70,7 +70,7 @@ discard block | ||
| 70 | 70 |      { | 
| 71 | 71 |          $fqcn = str_replace('\\', '_', $fqcn); | 
| 72 | 72 | return $fqcn === $object_identifier | 
| 73 | - || strpos($object_identifier, $fqcn . ObjectIdentifier::DELIMITER) === 0; | |
| 73 | + || strpos($object_identifier, $fqcn.ObjectIdentifier::DELIMITER) === 0; | |
| 74 | 74 | } | 
| 75 | 75 | |
| 76 | 76 | |
| @@ -90,8 +90,8 @@ discard block | ||
| 90 | 90 | ) | 
| 91 | 91 | ? $this->getIdentifierForArguments($arguments) | 
| 92 | 92 | : ''; | 
| 93 | -        if (! empty($identifier)) { | |
| 94 | - $fqcn .= ObjectIdentifier::DELIMITER . md5($identifier); | |
| 93 | +        if ( ! empty($identifier)) { | |
| 94 | + $fqcn .= ObjectIdentifier::DELIMITER.md5($identifier); | |
| 95 | 95 | } | 
| 96 | 96 |          $fqcn = str_replace('\\', '_', $fqcn); | 
| 97 | 97 | return $fqcn; | 
| @@ -8,50 +8,50 @@ | ||
| 8 | 8 | interface LoaderInterface | 
| 9 | 9 |  { | 
| 10 | 10 | |
| 11 | - /** | |
| 12 | - * Can be for instantiating a new instance of a class, | |
| 13 | - * or for getting a shared instance of a class (default) | |
| 14 | - * | |
| 15 | - * @param FullyQualifiedName|string $fqcn | |
| 16 | - * @param array $arguments | |
| 17 | - * @param bool $shared | |
| 18 | - * @return mixed | |
| 19 | - */ | |
| 20 | - public function load($fqcn, array $arguments = [], $shared = true); | |
| 21 | - | |
| 22 | - | |
| 23 | - /** | |
| 24 | - * Used for instantiating a new instance of a class | |
| 25 | - * | |
| 26 | - * @param FullyQualifiedName|string $fqcn | |
| 27 | - * @param array $arguments | |
| 28 | - * @return mixed | |
| 29 | - */ | |
| 30 | - public function getNew($fqcn, array $arguments = []); | |
| 31 | - | |
| 32 | - | |
| 33 | - /** | |
| 34 | - * Used for getting a shared instance of a class | |
| 35 | - * | |
| 36 | - * @param FullyQualifiedName|string $fqcn | |
| 37 | - * @param array $arguments | |
| 38 | - * @return mixed | |
| 39 | - */ | |
| 40 | - public function getShared($fqcn, array $arguments = []); | |
| 41 | - | |
| 42 | - | |
| 43 | - /** | |
| 44 | - * @param FullyQualifiedName|string $fqcn | |
| 45 | - * @param mixed $object | |
| 46 | - * @param array $arguments | |
| 47 | - * @return bool | |
| 48 | - * @throws InvalidArgumentException | |
| 49 | - */ | |
| 50 | - public function share($fqcn, $object, array $arguments = []); | |
| 51 | - | |
| 52 | - | |
| 53 | - /** | |
| 54 | - * calls reset() on loader if method exists | |
| 55 | - */ | |
| 56 | - public function reset(); | |
| 11 | + /** | |
| 12 | + * Can be for instantiating a new instance of a class, | |
| 13 | + * or for getting a shared instance of a class (default) | |
| 14 | + * | |
| 15 | + * @param FullyQualifiedName|string $fqcn | |
| 16 | + * @param array $arguments | |
| 17 | + * @param bool $shared | |
| 18 | + * @return mixed | |
| 19 | + */ | |
| 20 | + public function load($fqcn, array $arguments = [], $shared = true); | |
| 21 | + | |
| 22 | + | |
| 23 | + /** | |
| 24 | + * Used for instantiating a new instance of a class | |
| 25 | + * | |
| 26 | + * @param FullyQualifiedName|string $fqcn | |
| 27 | + * @param array $arguments | |
| 28 | + * @return mixed | |
| 29 | + */ | |
| 30 | + public function getNew($fqcn, array $arguments = []); | |
| 31 | + | |
| 32 | + | |
| 33 | + /** | |
| 34 | + * Used for getting a shared instance of a class | |
| 35 | + * | |
| 36 | + * @param FullyQualifiedName|string $fqcn | |
| 37 | + * @param array $arguments | |
| 38 | + * @return mixed | |
| 39 | + */ | |
| 40 | + public function getShared($fqcn, array $arguments = []); | |
| 41 | + | |
| 42 | + | |
| 43 | + /** | |
| 44 | + * @param FullyQualifiedName|string $fqcn | |
| 45 | + * @param mixed $object | |
| 46 | + * @param array $arguments | |
| 47 | + * @return bool | |
| 48 | + * @throws InvalidArgumentException | |
| 49 | + */ | |
| 50 | + public function share($fqcn, $object, array $arguments = []); | |
| 51 | + | |
| 52 | + | |
| 53 | + /** | |
| 54 | + * calls reset() on loader if method exists | |
| 55 | + */ | |
| 56 | + public function reset(); | |
| 57 | 57 | } | 
| @@ -11,12 +11,12 @@ | ||
| 11 | 11 | interface CachingLoaderDecoratorInterface extends LoaderDecoratorInterface | 
| 12 | 12 |  { | 
| 13 | 13 | |
| 14 | - /** | |
| 15 | - * @param string $fqcn | |
| 16 | - * @param mixed $object | |
| 17 | - * @param array $arguments | |
| 18 | - * @return bool | |
| 19 | - * @throws InvalidArgumentException | |
| 20 | - */ | |
| 21 | - public function share($fqcn, $object, array $arguments = []); | |
| 14 | + /** | |
| 15 | + * @param string $fqcn | |
| 16 | + * @param mixed $object | |
| 17 | + * @param array $arguments | |
| 18 | + * @return bool | |
| 19 | + * @throws InvalidArgumentException | |
| 20 | + */ | |
| 21 | + public function share($fqcn, $object, array $arguments = []); | |
| 22 | 22 | } | 
| @@ -15,116 +15,116 @@ | ||
| 15 | 15 | class Loader implements LoaderInterface | 
| 16 | 16 |  { | 
| 17 | 17 | |
| 18 | - /** | |
| 19 | - * @var LoaderDecoratorInterface $new_loader | |
| 20 | - */ | |
| 21 | - private $new_loader; | |
| 22 | - | |
| 23 | - /** | |
| 24 | - * @var LoaderDecoratorInterface $shared_loader | |
| 25 | - */ | |
| 26 | - private $shared_loader; | |
| 27 | - | |
| 28 | - /** | |
| 29 | - * @var ClassInterfaceCache $class_cache | |
| 30 | - */ | |
| 31 | - private $class_cache; | |
| 32 | - | |
| 33 | - /** | |
| 34 | - * Loader constructor. | |
| 35 | - * | |
| 36 | - * @param LoaderDecoratorInterface $new_loader | |
| 37 | - * @param CachingLoaderDecoratorInterface $shared_loader | |
| 38 | - * @param ClassInterfaceCache $class_cache | |
| 39 | - */ | |
| 40 | - public function __construct( | |
| 41 | - LoaderDecoratorInterface $new_loader, | |
| 42 | - CachingLoaderDecoratorInterface $shared_loader, | |
| 43 | - ClassInterfaceCache $class_cache | |
| 44 | -    ) { | |
| 45 | - $this->new_loader = $new_loader; | |
| 46 | - $this->shared_loader = $shared_loader; | |
| 47 | - $this->class_cache = $class_cache; | |
| 48 | - } | |
| 49 | - | |
| 50 | - | |
| 51 | - /** | |
| 52 | - * @return LoaderDecoratorInterface | |
| 53 | - */ | |
| 54 | - public function getNewLoader() | |
| 55 | -    { | |
| 56 | - return $this->new_loader; | |
| 57 | - } | |
| 58 | - | |
| 59 | - | |
| 60 | - /** | |
| 61 | - * @return CachingLoaderDecoratorInterface | |
| 62 | - */ | |
| 63 | - public function getSharedLoader() | |
| 64 | -    { | |
| 65 | - return $this->shared_loader; | |
| 66 | - } | |
| 67 | - | |
| 68 | - | |
| 69 | - /** | |
| 70 | - * @param FullyQualifiedName|string $fqcn | |
| 71 | - * @param array $arguments | |
| 72 | - * @param bool $shared | |
| 73 | - * @return mixed | |
| 74 | - */ | |
| 75 | - public function load($fqcn, array $arguments = array(), $shared = true) | |
| 76 | -    { | |
| 77 | - $fqcn = $this->class_cache->getFqn($fqcn); | |
| 78 | -        if ($this->class_cache->hasInterface($fqcn, 'EventEspresso\core\interfaces\ReservedInstanceInterface')) { | |
| 79 | - $shared = true; | |
| 80 | - } | |
| 81 | - return $shared | |
| 82 | - ? $this->getSharedLoader()->load($fqcn, $arguments, $shared) | |
| 83 | - : $this->getNewLoader()->load($fqcn, $arguments, $shared); | |
| 84 | - } | |
| 85 | - | |
| 86 | - | |
| 87 | - /** | |
| 88 | - * @param FullyQualifiedName|string $fqcn | |
| 89 | - * @param array $arguments | |
| 90 | - * @return mixed | |
| 91 | - */ | |
| 92 | - public function getNew($fqcn, array $arguments = array()) | |
| 93 | -    { | |
| 94 | - return $this->load($fqcn, $arguments, false); | |
| 95 | - } | |
| 96 | - | |
| 97 | - | |
| 98 | - /** | |
| 99 | - * @param FullyQualifiedName|string $fqcn | |
| 100 | - * @param array $arguments | |
| 101 | - * @return mixed | |
| 102 | - */ | |
| 103 | - public function getShared($fqcn, array $arguments = array()) | |
| 104 | -    { | |
| 105 | - return $this->load($fqcn, $arguments); | |
| 106 | - } | |
| 107 | - | |
| 108 | - | |
| 109 | - /** | |
| 110 | - * @param FullyQualifiedName|string $fqcn | |
| 111 | - * @param mixed $object | |
| 112 | - * @param array $arguments | |
| 113 | - * @return bool | |
| 114 | - * @throws InvalidArgumentException | |
| 115 | - */ | |
| 116 | - public function share($fqcn, $object, array $arguments = []) | |
| 117 | -    { | |
| 118 | - $fqcn = $this->class_cache->getFqn($fqcn); | |
| 119 | - return $this->getSharedLoader()->share($fqcn, $object, $arguments); | |
| 120 | - } | |
| 121 | - | |
| 122 | - | |
| 123 | - /** | |
| 124 | - * calls reset() on loaders if that method exists | |
| 125 | - */ | |
| 126 | - public function reset() | |
| 127 | -    { | |
| 128 | - $this->shared_loader->reset(); | |
| 129 | - } | |
| 18 | + /** | |
| 19 | + * @var LoaderDecoratorInterface $new_loader | |
| 20 | + */ | |
| 21 | + private $new_loader; | |
| 22 | + | |
| 23 | + /** | |
| 24 | + * @var LoaderDecoratorInterface $shared_loader | |
| 25 | + */ | |
| 26 | + private $shared_loader; | |
| 27 | + | |
| 28 | + /** | |
| 29 | + * @var ClassInterfaceCache $class_cache | |
| 30 | + */ | |
| 31 | + private $class_cache; | |
| 32 | + | |
| 33 | + /** | |
| 34 | + * Loader constructor. | |
| 35 | + * | |
| 36 | + * @param LoaderDecoratorInterface $new_loader | |
| 37 | + * @param CachingLoaderDecoratorInterface $shared_loader | |
| 38 | + * @param ClassInterfaceCache $class_cache | |
| 39 | + */ | |
| 40 | + public function __construct( | |
| 41 | + LoaderDecoratorInterface $new_loader, | |
| 42 | + CachingLoaderDecoratorInterface $shared_loader, | |
| 43 | + ClassInterfaceCache $class_cache | |
| 44 | +	) { | |
| 45 | + $this->new_loader = $new_loader; | |
| 46 | + $this->shared_loader = $shared_loader; | |
| 47 | + $this->class_cache = $class_cache; | |
| 48 | + } | |
| 49 | + | |
| 50 | + | |
| 51 | + /** | |
| 52 | + * @return LoaderDecoratorInterface | |
| 53 | + */ | |
| 54 | + public function getNewLoader() | |
| 55 | +	{ | |
| 56 | + return $this->new_loader; | |
| 57 | + } | |
| 58 | + | |
| 59 | + | |
| 60 | + /** | |
| 61 | + * @return CachingLoaderDecoratorInterface | |
| 62 | + */ | |
| 63 | + public function getSharedLoader() | |
| 64 | +	{ | |
| 65 | + return $this->shared_loader; | |
| 66 | + } | |
| 67 | + | |
| 68 | + | |
| 69 | + /** | |
| 70 | + * @param FullyQualifiedName|string $fqcn | |
| 71 | + * @param array $arguments | |
| 72 | + * @param bool $shared | |
| 73 | + * @return mixed | |
| 74 | + */ | |
| 75 | + public function load($fqcn, array $arguments = array(), $shared = true) | |
| 76 | +	{ | |
| 77 | + $fqcn = $this->class_cache->getFqn($fqcn); | |
| 78 | +		if ($this->class_cache->hasInterface($fqcn, 'EventEspresso\core\interfaces\ReservedInstanceInterface')) { | |
| 79 | + $shared = true; | |
| 80 | + } | |
| 81 | + return $shared | |
| 82 | + ? $this->getSharedLoader()->load($fqcn, $arguments, $shared) | |
| 83 | + : $this->getNewLoader()->load($fqcn, $arguments, $shared); | |
| 84 | + } | |
| 85 | + | |
| 86 | + | |
| 87 | + /** | |
| 88 | + * @param FullyQualifiedName|string $fqcn | |
| 89 | + * @param array $arguments | |
| 90 | + * @return mixed | |
| 91 | + */ | |
| 92 | + public function getNew($fqcn, array $arguments = array()) | |
| 93 | +	{ | |
| 94 | + return $this->load($fqcn, $arguments, false); | |
| 95 | + } | |
| 96 | + | |
| 97 | + | |
| 98 | + /** | |
| 99 | + * @param FullyQualifiedName|string $fqcn | |
| 100 | + * @param array $arguments | |
| 101 | + * @return mixed | |
| 102 | + */ | |
| 103 | + public function getShared($fqcn, array $arguments = array()) | |
| 104 | +	{ | |
| 105 | + return $this->load($fqcn, $arguments); | |
| 106 | + } | |
| 107 | + | |
| 108 | + | |
| 109 | + /** | |
| 110 | + * @param FullyQualifiedName|string $fqcn | |
| 111 | + * @param mixed $object | |
| 112 | + * @param array $arguments | |
| 113 | + * @return bool | |
| 114 | + * @throws InvalidArgumentException | |
| 115 | + */ | |
| 116 | + public function share($fqcn, $object, array $arguments = []) | |
| 117 | +	{ | |
| 118 | + $fqcn = $this->class_cache->getFqn($fqcn); | |
| 119 | + return $this->getSharedLoader()->share($fqcn, $object, $arguments); | |
| 120 | + } | |
| 121 | + | |
| 122 | + | |
| 123 | + /** | |
| 124 | + * calls reset() on loaders if that method exists | |
| 125 | + */ | |
| 126 | + public function reset() | |
| 127 | +	{ | |
| 128 | + $this->shared_loader->reset(); | |
| 129 | + } | |
| 130 | 130 | } | 
| @@ -53,7 +53,7 @@ discard block | ||
| 53 | 53 | */ | 
| 54 | 54 | public function create($fqcn, array $arguments = []) | 
| 55 | 55 |      { | 
| 56 | -        if (! isset($arguments[0]) || ! $arguments[0] instanceof DomainInterface) { | |
| 56 | +        if ( ! isset($arguments[0]) || ! $arguments[0] instanceof DomainInterface) { | |
| 57 | 57 | throw new InvalidArgumentException( | 
| 58 | 58 | esc_html__( | 
| 59 | 59 | 'In order to generate an AssetManifest class you need to supply an array where the first argument is an instance of DomainInterface.', | 
| @@ -73,9 +73,9 @@ discard block | ||
| 73 | 73 | private function getAssetManifestForDomain($manifest_fqcn, DomainInterface $domain) | 
| 74 | 74 |      { | 
| 75 | 75 | $domain_fqcn = get_class($domain); | 
| 76 | -        if (! isset(AssetManifestFactory::$manifests[ $domain_fqcn ])) { | |
| 76 | +        if ( ! isset(AssetManifestFactory::$manifests[$domain_fqcn])) { | |
| 77 | 77 | $asset_manifest = new $manifest_fqcn($domain); | 
| 78 | -            if (! $asset_manifest instanceof AssetManifestInterface || ! $asset_manifest instanceof $manifest_fqcn) { | |
| 78 | +            if ( ! $asset_manifest instanceof AssetManifestInterface || ! $asset_manifest instanceof $manifest_fqcn) { | |
| 79 | 79 | throw new DomainException( | 
| 80 | 80 | sprintf( | 
| 81 | 81 | esc_html__( | 
| @@ -88,8 +88,8 @@ discard block | ||
| 88 | 88 | } | 
| 89 | 89 | // we still need to share this with the core loader to facilitate automatic dependency injection | 
| 90 | 90 | $this->loader->share(AssetManifest::class, $asset_manifest, [$domain]); | 
| 91 | - AssetManifestFactory::$manifests[ $domain_fqcn ] = $asset_manifest; | |
| 91 | + AssetManifestFactory::$manifests[$domain_fqcn] = $asset_manifest; | |
| 92 | 92 | } | 
| 93 | - return AssetManifestFactory::$manifests[ $domain_fqcn ]; | |
| 93 | + return AssetManifestFactory::$manifests[$domain_fqcn]; | |
| 94 | 94 | } | 
| 95 | 95 | } | 
| @@ -16,86 +16,86 @@ | ||
| 16 | 16 | */ | 
| 17 | 17 | class AssetManifestFactory implements FactoryInterface | 
| 18 | 18 |  { | 
| 19 | - /** | |
| 20 | - * @var AssetManifestInterface[] | |
| 21 | - */ | |
| 22 | - private static $manifests = []; | |
| 19 | + /** | |
| 20 | + * @var AssetManifestInterface[] | |
| 21 | + */ | |
| 22 | + private static $manifests = []; | |
| 23 | 23 | |
| 24 | - /** | |
| 25 | - * @var LoaderInterface $loader | |
| 26 | - */ | |
| 27 | - protected $loader; | |
| 24 | + /** | |
| 25 | + * @var LoaderInterface $loader | |
| 26 | + */ | |
| 27 | + protected $loader; | |
| 28 | 28 | |
| 29 | 29 | |
| 30 | - /** | |
| 31 | - * AssetManifestFactory constructor. | |
| 32 | - * | |
| 33 | - * @param LoaderInterface $loader | |
| 34 | - */ | |
| 35 | - public function __construct(LoaderInterface $loader) | |
| 36 | -    { | |
| 37 | - $this->loader = $loader; | |
| 38 | - } | |
| 30 | + /** | |
| 31 | + * AssetManifestFactory constructor. | |
| 32 | + * | |
| 33 | + * @param LoaderInterface $loader | |
| 34 | + */ | |
| 35 | + public function __construct(LoaderInterface $loader) | |
| 36 | +	{ | |
| 37 | + $this->loader = $loader; | |
| 38 | + } | |
| 39 | 39 | |
| 40 | 40 | |
| 41 | - /** | |
| 42 | - * returns the applicable AssetManifest for the provided Domain | |
| 43 | - * | |
| 44 | - * @param DomainInterface $domain | |
| 45 | - * @return AssetManifestInterface | |
| 46 | - */ | |
| 47 | - public function createFromDomainObject(DomainInterface $domain) | |
| 48 | -    { | |
| 49 | - return $this->getAssetManifestForDomain(AssetManifest::class, $domain); | |
| 50 | - } | |
| 41 | + /** | |
| 42 | + * returns the applicable AssetManifest for the provided Domain | |
| 43 | + * | |
| 44 | + * @param DomainInterface $domain | |
| 45 | + * @return AssetManifestInterface | |
| 46 | + */ | |
| 47 | + public function createFromDomainObject(DomainInterface $domain) | |
| 48 | +	{ | |
| 49 | + return $this->getAssetManifestForDomain(AssetManifest::class, $domain); | |
| 50 | + } | |
| 51 | 51 | |
| 52 | 52 | |
| 53 | - /** | |
| 54 | - * for creating an atypical AssetManifest for the Domain provided in the $arguments array | |
| 55 | - * | |
| 56 | - * @param string $fqcn Fully Qualified Class Name | |
| 57 | - * @param array $arguments [optional] array of data required for construction | |
| 58 | - * @return AssetManifestInterface | |
| 59 | - */ | |
| 60 | - public function create($fqcn, array $arguments = []) | |
| 61 | -    { | |
| 62 | -        if (! isset($arguments[0]) || ! $arguments[0] instanceof DomainInterface) { | |
| 63 | - throw new InvalidArgumentException( | |
| 64 | - esc_html__( | |
| 65 | - 'In order to generate an AssetManifest class you need to supply an array where the first argument is an instance of DomainInterface.', | |
| 66 | - 'event_espresso' | |
| 67 | - ) | |
| 68 | - ); | |
| 69 | - } | |
| 70 | - return $this->getAssetManifestForDomain($fqcn, $arguments[0]); | |
| 71 | - } | |
| 53 | + /** | |
| 54 | + * for creating an atypical AssetManifest for the Domain provided in the $arguments array | |
| 55 | + * | |
| 56 | + * @param string $fqcn Fully Qualified Class Name | |
| 57 | + * @param array $arguments [optional] array of data required for construction | |
| 58 | + * @return AssetManifestInterface | |
| 59 | + */ | |
| 60 | + public function create($fqcn, array $arguments = []) | |
| 61 | +	{ | |
| 62 | +		if (! isset($arguments[0]) || ! $arguments[0] instanceof DomainInterface) { | |
| 63 | + throw new InvalidArgumentException( | |
| 64 | + esc_html__( | |
| 65 | + 'In order to generate an AssetManifest class you need to supply an array where the first argument is an instance of DomainInterface.', | |
| 66 | + 'event_espresso' | |
| 67 | + ) | |
| 68 | + ); | |
| 69 | + } | |
| 70 | + return $this->getAssetManifestForDomain($fqcn, $arguments[0]); | |
| 71 | + } | |
| 72 | 72 | |
| 73 | 73 | |
| 74 | - /** | |
| 75 | - * @param string $manifest_fqcn | |
| 76 | - * @param DomainInterface $domain | |
| 77 | - * @return AssetManifestInterface | |
| 78 | - */ | |
| 79 | - private function getAssetManifestForDomain($manifest_fqcn, DomainInterface $domain) | |
| 80 | -    { | |
| 81 | - $domain_fqcn = get_class($domain); | |
| 82 | -        if (! isset(AssetManifestFactory::$manifests[ $domain_fqcn ])) { | |
| 83 | - $asset_manifest = new $manifest_fqcn($domain); | |
| 84 | -            if (! $asset_manifest instanceof AssetManifestInterface || ! $asset_manifest instanceof $manifest_fqcn) { | |
| 85 | - throw new DomainException( | |
| 86 | - sprintf( | |
| 87 | - esc_html__( | |
| 88 | - 'The requested AssetManifest class "%1$s" could not be loaded.', | |
| 89 | - 'event_espresso' | |
| 90 | - ), | |
| 91 | - $manifest_fqcn | |
| 92 | - ) | |
| 93 | - ); | |
| 94 | - } | |
| 95 | - // we still need to share this with the core loader to facilitate automatic dependency injection | |
| 96 | - $this->loader->share(AssetManifest::class, $asset_manifest, [$domain]); | |
| 97 | - AssetManifestFactory::$manifests[ $domain_fqcn ] = $asset_manifest; | |
| 98 | - } | |
| 99 | - return AssetManifestFactory::$manifests[ $domain_fqcn ]; | |
| 100 | - } | |
| 74 | + /** | |
| 75 | + * @param string $manifest_fqcn | |
| 76 | + * @param DomainInterface $domain | |
| 77 | + * @return AssetManifestInterface | |
| 78 | + */ | |
| 79 | + private function getAssetManifestForDomain($manifest_fqcn, DomainInterface $domain) | |
| 80 | +	{ | |
| 81 | + $domain_fqcn = get_class($domain); | |
| 82 | +		if (! isset(AssetManifestFactory::$manifests[ $domain_fqcn ])) { | |
| 83 | + $asset_manifest = new $manifest_fqcn($domain); | |
| 84 | +			if (! $asset_manifest instanceof AssetManifestInterface || ! $asset_manifest instanceof $manifest_fqcn) { | |
| 85 | + throw new DomainException( | |
| 86 | + sprintf( | |
| 87 | + esc_html__( | |
| 88 | + 'The requested AssetManifest class "%1$s" could not be loaded.', | |
| 89 | + 'event_espresso' | |
| 90 | + ), | |
| 91 | + $manifest_fqcn | |
| 92 | + ) | |
| 93 | + ); | |
| 94 | + } | |
| 95 | + // we still need to share this with the core loader to facilitate automatic dependency injection | |
| 96 | + $this->loader->share(AssetManifest::class, $asset_manifest, [$domain]); | |
| 97 | + AssetManifestFactory::$manifests[ $domain_fqcn ] = $asset_manifest; | |
| 98 | + } | |
| 99 | + return AssetManifestFactory::$manifests[ $domain_fqcn ]; | |
| 100 | + } | |
| 101 | 101 | } |