Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.
Common duplication problems, and corresponding solutions are:
Complex classes like EE_System often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes. You can also have a look at the cohesion graph to spot any un-connected, or weakly-connected components.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
While breaking up the class, it is a good idea to analyze how other classes use EE_System, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 28 | final class EE_System implements ResettableInterface |
||
| 29 | { |
||
| 30 | |||
| 31 | /** |
||
| 32 | * indicates this is a 'normal' request. Ie, not activation, nor upgrade, nor activation. |
||
| 33 | * So examples of this would be a normal GET request on the frontend or backend, or a POST, etc |
||
| 34 | */ |
||
| 35 | const req_type_normal = 0; |
||
| 36 | |||
| 37 | /** |
||
| 38 | * Indicates this is a brand new installation of EE so we should install |
||
| 39 | * tables and default data etc |
||
| 40 | */ |
||
| 41 | const req_type_new_activation = 1; |
||
| 42 | |||
| 43 | /** |
||
| 44 | * we've detected that EE has been reactivated (or EE was activated during maintenance mode, |
||
| 45 | * and we just exited maintenance mode). We MUST check the database is setup properly |
||
| 46 | * and that default data is setup too |
||
| 47 | */ |
||
| 48 | const req_type_reactivation = 2; |
||
| 49 | |||
| 50 | /** |
||
| 51 | * indicates that EE has been upgraded since its previous request. |
||
| 52 | * We may have data migration scripts to call and will want to trigger maintenance mode |
||
| 53 | */ |
||
| 54 | const req_type_upgrade = 3; |
||
| 55 | |||
| 56 | /** |
||
| 57 | * TODO will detect that EE has been DOWNGRADED. We probably don't want to run in this case... |
||
| 58 | */ |
||
| 59 | const req_type_downgrade = 4; |
||
| 60 | |||
| 61 | /** |
||
| 62 | * @deprecated since version 4.6.0.dev.006 |
||
| 63 | * Now whenever a new_activation is detected the request type is still just |
||
| 64 | * new_activation (same for reactivation, upgrade, downgrade etc), but if we'r ein maintenance mode |
||
| 65 | * EE_System::initialize_db_if_no_migrations_required and EE_Addon::initialize_db_if_no_migrations_required |
||
| 66 | * will instead enqueue that EE plugin's db initialization for when we're taken out of maintenance mode. |
||
| 67 | * (Specifically, when the migration manager indicates migrations are finished |
||
| 68 | * EE_Data_Migration_Manager::initialize_db_for_enqueued_ee_plugins() will be called) |
||
| 69 | */ |
||
| 70 | const req_type_activation_but_not_installed = 5; |
||
| 71 | |||
| 72 | /** |
||
| 73 | * option prefix for recording the activation history (like core's "espresso_db_update") of addons |
||
| 74 | */ |
||
| 75 | const addon_activation_history_option_prefix = 'ee_addon_activation_history_'; |
||
| 76 | |||
| 77 | /** |
||
| 78 | * @var EE_System $_instance |
||
| 79 | */ |
||
| 80 | private static $_instance; |
||
| 81 | |||
| 82 | /** |
||
| 83 | * @var EE_Registry $registry |
||
| 84 | */ |
||
| 85 | private $registry; |
||
| 86 | |||
| 87 | /** |
||
| 88 | * @var LoaderInterface $loader |
||
| 89 | */ |
||
| 90 | private $loader; |
||
| 91 | |||
| 92 | /** |
||
| 93 | * @var EE_Capabilities $capabilities |
||
| 94 | */ |
||
| 95 | private $capabilities; |
||
| 96 | |||
| 97 | /** |
||
| 98 | * @var RequestInterface $request |
||
| 99 | */ |
||
| 100 | private $request; |
||
| 101 | |||
| 102 | /** |
||
| 103 | * @var RouteMatchSpecificationManager $route_manager |
||
| 104 | */ |
||
| 105 | private $route_manager; |
||
| 106 | |||
| 107 | /** |
||
| 108 | * @var EE_Maintenance_Mode $maintenance_mode |
||
| 109 | */ |
||
| 110 | private $maintenance_mode; |
||
| 111 | |||
| 112 | /** |
||
| 113 | * Stores which type of request this is, options being one of the constants on EE_System starting with req_type_*. |
||
| 114 | * It can be a brand-new activation, a reactivation, an upgrade, a downgrade, or a normal request. |
||
| 115 | * |
||
| 116 | * @var int $_req_type |
||
| 117 | */ |
||
| 118 | private $_req_type; |
||
| 119 | |||
| 120 | /** |
||
| 121 | * Whether or not there was a non-micro version change in EE core version during this request |
||
| 122 | * |
||
| 123 | * @var boolean $_major_version_change |
||
| 124 | */ |
||
| 125 | private $_major_version_change = false; |
||
| 126 | |||
| 127 | /** |
||
| 128 | * A Context DTO dedicated solely to identifying the current request type. |
||
| 129 | * |
||
| 130 | * @var RequestTypeContextCheckerInterface $request_type |
||
| 131 | */ |
||
| 132 | private $request_type; |
||
| 133 | |||
| 134 | |||
| 135 | /** |
||
| 136 | * @singleton method used to instantiate class object |
||
| 137 | * @param EE_Registry|null $registry |
||
| 138 | * @param LoaderInterface|null $loader |
||
| 139 | * @param RequestInterface|null $request |
||
| 140 | * @param EE_Maintenance_Mode|null $maintenance_mode |
||
| 141 | * @return EE_System |
||
| 142 | */ |
||
| 143 | public static function instance( |
||
| 144 | EE_Registry $registry = null, |
||
| 145 | LoaderInterface $loader = null, |
||
| 146 | RequestInterface $request = null, |
||
| 147 | EE_Maintenance_Mode $maintenance_mode = null |
||
| 148 | ) { |
||
| 149 | // check if class object is instantiated |
||
| 150 | if (! self::$_instance instanceof EE_System) { |
||
| 151 | self::$_instance = new self($registry, $loader, $request, $maintenance_mode); |
||
| 152 | } |
||
| 153 | return self::$_instance; |
||
| 154 | } |
||
| 155 | |||
| 156 | |||
| 157 | /** |
||
| 158 | * resets the instance and returns it |
||
| 159 | * |
||
| 160 | * @return EE_System |
||
| 161 | */ |
||
| 162 | public static function reset() |
||
| 163 | { |
||
| 164 | self::$_instance->_req_type = null; |
||
| 165 | // make sure none of the old hooks are left hanging around |
||
| 166 | remove_all_actions('AHEE__EE_System__perform_activations_upgrades_and_migrations'); |
||
| 167 | // we need to reset the migration manager in order for it to detect DMSs properly |
||
| 168 | EE_Data_Migration_Manager::reset(); |
||
| 169 | self::instance()->detect_activations_or_upgrades(); |
||
| 170 | self::instance()->perform_activations_upgrades_and_migrations(); |
||
| 171 | return self::instance(); |
||
| 172 | } |
||
| 173 | |||
| 174 | |||
| 175 | /** |
||
| 176 | * sets hooks for running rest of system |
||
| 177 | * provides "AHEE__EE_System__construct__complete" hook for EE Addons to use as their starting point |
||
| 178 | * starting EE Addons from any other point may lead to problems |
||
| 179 | * |
||
| 180 | * @param EE_Registry $registry |
||
| 181 | * @param LoaderInterface $loader |
||
| 182 | * @param RequestInterface $request |
||
| 183 | * @param EE_Maintenance_Mode $maintenance_mode |
||
| 184 | */ |
||
| 185 | private function __construct( |
||
| 186 | EE_Registry $registry, |
||
| 187 | LoaderInterface $loader, |
||
| 188 | RequestInterface $request, |
||
| 189 | EE_Maintenance_Mode $maintenance_mode |
||
| 190 | ) { |
||
| 191 | $this->registry = $registry; |
||
| 192 | $this->loader = $loader; |
||
| 193 | $this->request = $request; |
||
| 194 | $this->maintenance_mode = $maintenance_mode; |
||
| 195 | do_action('AHEE__EE_System__construct__begin', $this); |
||
| 196 | add_action( |
||
| 197 | 'AHEE__EE_Bootstrap__load_espresso_addons', |
||
| 198 | array($this, 'loadCapabilities'), |
||
| 199 | 5 |
||
| 200 | ); |
||
| 201 | add_action( |
||
| 202 | 'AHEE__EE_Bootstrap__load_espresso_addons', |
||
| 203 | array($this, 'loadCommandBus'), |
||
| 204 | 7 |
||
| 205 | ); |
||
| 206 | add_action( |
||
| 207 | 'AHEE__EE_Bootstrap__load_espresso_addons', |
||
| 208 | array($this, 'loadPluginApi'), |
||
| 209 | 9 |
||
| 210 | ); |
||
| 211 | // allow addons to load first so that they can register autoloaders, set hooks for running DMS's, etc |
||
| 212 | add_action( |
||
| 213 | 'AHEE__EE_Bootstrap__load_espresso_addons', |
||
| 214 | array($this, 'load_espresso_addons') |
||
| 215 | ); |
||
| 216 | // when an ee addon is activated, we want to call the core hook(s) again |
||
| 217 | // because the newly-activated addon didn't get a chance to run at all |
||
| 218 | add_action('activate_plugin', array($this, 'load_espresso_addons'), 1); |
||
| 219 | // detect whether install or upgrade |
||
| 220 | add_action( |
||
| 221 | 'AHEE__EE_Bootstrap__detect_activations_or_upgrades', |
||
| 222 | array($this, 'detect_activations_or_upgrades'), |
||
| 223 | 3 |
||
| 224 | ); |
||
| 225 | // load EE_Config, EE_Textdomain, etc |
||
| 226 | add_action( |
||
| 227 | 'AHEE__EE_Bootstrap__load_core_configuration', |
||
| 228 | array($this, 'load_core_configuration'), |
||
| 229 | 5 |
||
| 230 | ); |
||
| 231 | // load specifications for matching routes to current request |
||
| 232 | add_action( |
||
| 233 | 'AHEE__EE_Bootstrap__load_core_configuration', |
||
| 234 | array($this, 'loadRouteMatchSpecifications') |
||
| 235 | ); |
||
| 236 | // load EE_Config, EE_Textdomain, etc |
||
| 237 | add_action( |
||
| 238 | 'AHEE__EE_Bootstrap__register_shortcodes_modules_and_widgets', |
||
| 239 | array($this, 'register_shortcodes_modules_and_widgets'), |
||
| 240 | 7 |
||
| 241 | ); |
||
| 242 | // you wanna get going? I wanna get going... let's get going! |
||
| 243 | add_action( |
||
| 244 | 'AHEE__EE_Bootstrap__brew_espresso', |
||
| 245 | array($this, 'brew_espresso'), |
||
| 246 | 9 |
||
| 247 | ); |
||
| 248 | // other housekeeping |
||
| 249 | // exclude EE critical pages from wp_list_pages |
||
| 250 | add_filter( |
||
| 251 | 'wp_list_pages_excludes', |
||
| 252 | array($this, 'remove_pages_from_wp_list_pages'), |
||
| 253 | 10 |
||
| 254 | ); |
||
| 255 | // ALL EE Addons should use the following hook point to attach their initial setup too |
||
| 256 | // it's extremely important for EE Addons to register any class autoloaders so that they can be available when the EE_Config loads |
||
| 257 | do_action('AHEE__EE_System__construct__complete', $this); |
||
| 258 | } |
||
| 259 | |||
| 260 | |||
| 261 | /** |
||
| 262 | * load and setup EE_Capabilities |
||
| 263 | * |
||
| 264 | * @return void |
||
| 265 | * @throws EE_Error |
||
| 266 | */ |
||
| 267 | public function loadCapabilities() |
||
| 268 | { |
||
| 269 | $this->capabilities = $this->loader->getShared('EE_Capabilities'); |
||
| 270 | add_action( |
||
| 271 | 'AHEE__EE_Capabilities__init_caps__before_initialization', |
||
| 272 | function () { |
||
| 273 | LoaderFactory::getLoader()->getShared('EE_Payment_Method_Manager'); |
||
| 274 | } |
||
| 275 | ); |
||
| 276 | } |
||
| 277 | |||
| 278 | |||
| 279 | /** |
||
| 280 | * create and cache the CommandBus, and also add middleware |
||
| 281 | * The CapChecker middleware requires the use of EE_Capabilities |
||
| 282 | * which is why we need to load the CommandBus after Caps are set up |
||
| 283 | * |
||
| 284 | * @return void |
||
| 285 | * @throws EE_Error |
||
| 286 | */ |
||
| 287 | public function loadCommandBus() |
||
| 303 | |||
| 304 | |||
| 305 | /** |
||
| 306 | * @return void |
||
| 307 | * @throws EE_Error |
||
| 308 | */ |
||
| 309 | public function loadPluginApi() |
||
| 310 | { |
||
| 311 | // set autoloaders for all of the classes implementing EEI_Plugin_API |
||
| 312 | // which provide helpers for EE plugin authors to more easily register certain components with EE. |
||
| 313 | EEH_Autoloader::instance()->register_autoloaders_for_each_file_in_folder(EE_LIBRARIES . 'plugin_api'); |
||
| 314 | $this->loader->getShared('EE_Request_Handler'); |
||
| 315 | } |
||
| 316 | |||
| 317 | |||
| 318 | /** |
||
| 319 | * @param string $addon_name |
||
| 320 | * @param string $version_constant |
||
| 321 | * @param string $min_version_required |
||
| 322 | * @param string $load_callback |
||
| 323 | * @param string $plugin_file_constant |
||
| 324 | * @return void |
||
| 325 | */ |
||
| 326 | private function deactivateIncompatibleAddon( |
||
| 327 | $addon_name, |
||
| 328 | $version_constant, |
||
| 329 | $min_version_required, |
||
| 330 | $load_callback, |
||
| 331 | $plugin_file_constant |
||
| 332 | ) { |
||
| 333 | if (! defined($version_constant)) { |
||
| 334 | return; |
||
| 335 | } |
||
| 336 | $addon_version = constant($version_constant); |
||
| 337 | if ($addon_version && version_compare($addon_version, $min_version_required, '<')) { |
||
| 338 | remove_action('AHEE__EE_System__load_espresso_addons', $load_callback); |
||
| 339 | if (! function_exists('deactivate_plugins')) { |
||
| 340 | require_once ABSPATH . 'wp-admin/includes/plugin.php'; |
||
| 341 | } |
||
| 342 | deactivate_plugins(plugin_basename(constant($plugin_file_constant))); |
||
| 343 | unset($_GET['activate'], $_REQUEST['activate'], $_GET['activate-multi'], $_REQUEST['activate-multi']); |
||
| 344 | EE_Error::add_error( |
||
| 345 | sprintf( |
||
| 346 | esc_html__( |
||
| 347 | '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.', |
||
| 348 | 'event_espresso' |
||
| 349 | ), |
||
| 350 | $addon_name, |
||
| 351 | $min_version_required |
||
| 352 | ), |
||
| 353 | __FILE__, |
||
| 354 | __FUNCTION__ . "({$addon_name})", |
||
| 355 | __LINE__ |
||
| 356 | ); |
||
| 357 | EE_Error::get_notices(false, true); |
||
| 358 | } |
||
| 359 | } |
||
| 360 | |||
| 361 | |||
| 362 | /** |
||
| 363 | * load_espresso_addons |
||
| 364 | * allow addons to load first so that they can set hooks for running DMS's, etc |
||
| 365 | * this is hooked into both: |
||
| 366 | * 'AHEE__EE_Bootstrap__load_core_configuration' |
||
| 367 | * which runs during the WP 'plugins_loaded' action at priority 5 |
||
| 368 | * and the WP 'activate_plugin' hook point |
||
| 369 | * |
||
| 370 | * @access public |
||
| 371 | * @return void |
||
| 372 | */ |
||
| 373 | public function load_espresso_addons() |
||
| 374 | { |
||
| 375 | $this->deactivateIncompatibleAddon( |
||
| 376 | 'Wait Lists', |
||
| 377 | 'EE_WAIT_LISTS_VERSION', |
||
| 378 | '1.0.0.beta.074', |
||
| 379 | 'load_espresso_wait_lists', |
||
| 380 | 'EE_WAIT_LISTS_PLUGIN_FILE' |
||
| 381 | ); |
||
| 382 | $this->deactivateIncompatibleAddon( |
||
| 383 | 'Automated Upcoming Event Notifications', |
||
| 384 | 'EE_AUTOMATED_UPCOMING_EVENT_NOTIFICATION_VERSION', |
||
| 385 | '1.0.0.beta.091', |
||
| 386 | 'load_espresso_automated_upcoming_event_notification', |
||
| 387 | 'EE_AUTOMATED_UPCOMING_EVENT_NOTIFICATION_PLUGIN_FILE' |
||
| 388 | ); |
||
| 389 | do_action('AHEE__EE_System__load_espresso_addons'); |
||
| 390 | // if the WP API basic auth plugin isn't already loaded, load it now. |
||
| 391 | // We want it for mobile apps. Just include the entire plugin |
||
| 392 | // also, don't load the basic auth when a plugin is getting activated, because |
||
| 393 | // it could be the basic auth plugin, and it doesn't check if its methods are already defined |
||
| 394 | // and causes a fatal error |
||
| 395 | if (($this->request->isWordPressApi() || $this->request->isApi()) |
||
| 396 | && $this->request->getRequestParam('activate') !== 'true' |
||
| 397 | && ! function_exists('json_basic_auth_handler') |
||
| 398 | && ! function_exists('json_basic_auth_error') |
||
| 399 | && ! in_array( |
||
| 400 | $this->request->getRequestParam('action'), |
||
| 401 | array('activate', 'activate-selected'), |
||
| 402 | true |
||
| 403 | ) |
||
| 404 | ) { |
||
| 405 | include_once EE_THIRD_PARTY . 'wp-api-basic-auth/basic-auth.php'; |
||
| 406 | } |
||
| 407 | do_action('AHEE__EE_System__load_espresso_addons__complete'); |
||
| 408 | } |
||
| 409 | |||
| 410 | |||
| 411 | /** |
||
| 412 | * detect_activations_or_upgrades |
||
| 413 | * Checks for activation or upgrade of core first; |
||
| 414 | * then also checks if any registered addons have been activated or upgraded |
||
| 415 | * This is hooked into 'AHEE__EE_Bootstrap__detect_activations_or_upgrades' |
||
| 416 | * which runs during the WP 'plugins_loaded' action at priority 3 |
||
| 417 | * |
||
| 418 | * @access public |
||
| 419 | * @return void |
||
| 420 | */ |
||
| 421 | public function detect_activations_or_upgrades() |
||
| 432 | |||
| 433 | |||
| 434 | /** |
||
| 435 | * detect_if_activation_or_upgrade |
||
| 436 | * Takes care of detecting whether this is a brand new install or code upgrade, |
||
| 437 | * and either setting up the DB or setting up maintenance mode etc. |
||
| 438 | * |
||
| 439 | * @access public |
||
| 440 | * @return void |
||
| 441 | */ |
||
| 442 | public function detect_if_activation_or_upgrade() |
||
| 476 | |||
| 477 | |||
| 478 | /** |
||
| 479 | * Updates the list of installed versions and sets hooks for |
||
| 480 | * initializing the database later during the request |
||
| 481 | * |
||
| 482 | * @param array $espresso_db_update |
||
| 483 | */ |
||
| 484 | private function _handle_core_version_change($espresso_db_update) |
||
| 493 | |||
| 494 | |||
| 495 | /** |
||
| 496 | * standardizes the wp option 'espresso_db_upgrade' which actually stores |
||
| 497 | * information about what versions of EE have been installed and activated, |
||
| 498 | * NOT necessarily the state of the database |
||
| 499 | * |
||
| 500 | * @param mixed $espresso_db_update the value of the WordPress option. |
||
| 501 | * If not supplied, fetches it from the options table |
||
| 502 | * @return array the correct value of 'espresso_db_upgrade', after saving it, if it needed correction |
||
| 503 | */ |
||
| 504 | private function fix_espresso_db_upgrade_option($espresso_db_update = null) |
||
| 543 | |||
| 544 | |||
| 545 | /** |
||
| 546 | * Does the traditional work of setting up the plugin's database and adding default data. |
||
| 547 | * If migration script/process did not exist, this is what would happen on every activation/reactivation/upgrade. |
||
| 548 | * NOTE: if we're in maintenance mode (which would be the case if we detect there are data |
||
| 549 | * migration scripts that need to be run and a version change happens), enqueues core for database initialization, |
||
| 550 | * so that it will be done when migrations are finished |
||
| 551 | * |
||
| 552 | * @param boolean $initialize_addons_too if true, we double-check addons' database tables etc too; |
||
| 553 | * @param boolean $verify_schema if true will re-check the database tables have the correct schema. |
||
| 554 | * This is a resource-intensive job |
||
| 555 | * so we prefer to only do it when necessary |
||
| 556 | * @return void |
||
| 557 | * @throws EE_Error |
||
| 558 | */ |
||
| 559 | public function initialize_db_if_no_migrations_required($initialize_addons_too = false, $verify_schema = true) |
||
| 590 | |||
| 591 | |||
| 592 | /** |
||
| 593 | * Initializes the db for all registered addons |
||
| 594 | * |
||
| 595 | * @throws EE_Error |
||
| 596 | */ |
||
| 597 | public function initialize_addons() |
||
| 606 | |||
| 607 | |||
| 608 | /** |
||
| 609 | * Adds the current code version to the saved wp option which stores a list of all ee versions ever installed. |
||
| 610 | * |
||
| 611 | * @param array $version_history |
||
| 612 | * @param string $current_version_to_add version to be added to the version history |
||
| 613 | * @return boolean success as to whether or not this option was changed |
||
| 614 | */ |
||
| 615 | public function update_list_of_installed_versions($version_history = null, $current_version_to_add = null) |
||
| 627 | |||
| 628 | |||
| 629 | /** |
||
| 630 | * Detects if the current version indicated in the has existed in the list of |
||
| 631 | * previously-installed versions of EE (espresso_db_update). Does NOT modify it (ie, no side-effect) |
||
| 632 | * |
||
| 633 | * @param array $espresso_db_update array from the wp option stored under the name 'espresso_db_update'. |
||
| 634 | * If not supplied, fetches it from the options table. |
||
| 635 | * Also, caches its result so later parts of the code can also know whether |
||
| 636 | * there's been an update or not. This way we can add the current version to |
||
| 637 | * espresso_db_update, but still know if this is a new install or not |
||
| 638 | * @return int one of the constants on EE_System::req_type_ |
||
| 639 | */ |
||
| 640 | public function detect_req_type($espresso_db_update = null) |
||
| 656 | |||
| 657 | |||
| 658 | /** |
||
| 659 | * Returns whether or not there was a non-micro version change (ie, change in either |
||
| 660 | * the first or second number in the version. Eg 4.9.0.rc.001 to 4.10.0.rc.000, |
||
| 661 | * but not 4.9.0.rc.0001 to 4.9.1.rc.0001 |
||
| 662 | * |
||
| 663 | * @param $activation_history |
||
| 664 | * @return bool |
||
| 665 | */ |
||
| 666 | private function _detect_major_version_change($activation_history) |
||
| 677 | |||
| 678 | |||
| 679 | /** |
||
| 680 | * Returns true if either the major or minor version of EE changed during this request. |
||
| 681 | * 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 |
||
| 682 | * |
||
| 683 | * @return bool |
||
| 684 | */ |
||
| 685 | public function is_major_version_change() |
||
| 689 | |||
| 690 | |||
| 691 | /** |
||
| 692 | * Determines the request type for any ee addon, given three piece of info: the current array of activation |
||
| 693 | * histories (for core that' 'espresso_db_update' wp option); the name of the WordPress option which is temporarily |
||
| 694 | * set upon activation of the plugin (for core it's 'ee_espresso_activation'); and the version that this plugin was |
||
| 695 | * just activated to (for core that will always be espresso_version()) |
||
| 696 | * |
||
| 697 | * @param array $activation_history_for_addon the option's value which stores the activation history for this |
||
| 698 | * ee plugin. for core that's 'espresso_db_update' |
||
| 699 | * @param string $activation_indicator_option_name the name of the WordPress option that is temporarily set to |
||
| 700 | * indicate that this plugin was just activated |
||
| 701 | * @param string $version_to_upgrade_to the version that was just upgraded to (for core that will be |
||
| 702 | * espresso_version()) |
||
| 703 | * @return int one of the constants on EE_System::req_type_* |
||
| 704 | */ |
||
| 705 | public static function detect_req_type_given_activation_history( |
||
| 753 | |||
| 754 | |||
| 755 | /** |
||
| 756 | * Detects if the $version_to_upgrade_to is higher than the most recent version in |
||
| 757 | * the $activation_history_for_addon |
||
| 758 | * |
||
| 759 | * @param array $activation_history_for_addon (keys are versions, values are arrays of times activated, |
||
| 760 | * sometimes containing 'unknown-date' |
||
| 761 | * @param string $version_to_upgrade_to (current version) |
||
| 762 | * @return int results of version_compare( $version_to_upgrade_to, $most_recently_active_version ). |
||
| 763 | * ie, -1 if $version_to_upgrade_to is LOWER (downgrade); |
||
| 764 | * 0 if $version_to_upgrade_to MATCHES (reactivation or normal request); |
||
| 765 | * 1 if $version_to_upgrade_to is HIGHER (upgrade) ; |
||
| 766 | */ |
||
| 767 | private static function _new_version_is_higher($activation_history_for_addon, $version_to_upgrade_to) |
||
| 774 | |||
| 775 | |||
| 776 | /** |
||
| 777 | * Gets the most recently active version listed in the activation history, |
||
| 778 | * and if none are found (ie, it's a brand new install) returns '0.0.0.dev.000'. |
||
| 779 | * |
||
| 780 | * @param array $activation_history (keys are versions, values are arrays of times activated, |
||
| 781 | * sometimes containing 'unknown-date' |
||
| 782 | * @return string |
||
| 783 | */ |
||
| 784 | private static function _get_most_recently_active_version_from_activation_history($activation_history) |
||
| 812 | |||
| 813 | |||
| 814 | /** |
||
| 815 | * This redirects to the about EE page after activation |
||
| 816 | * |
||
| 817 | * @return void |
||
| 818 | */ |
||
| 819 | public function redirect_to_about_ee() |
||
| 842 | |||
| 843 | |||
| 844 | /** |
||
| 845 | * load_core_configuration |
||
| 846 | * this is hooked into 'AHEE__EE_Bootstrap__load_core_configuration' |
||
| 847 | * which runs during the WP 'plugins_loaded' action at priority 5 |
||
| 848 | * |
||
| 849 | * @return void |
||
| 850 | * @throws ReflectionException |
||
| 851 | * @throws Exception |
||
| 852 | */ |
||
| 853 | public function load_core_configuration() |
||
| 882 | |||
| 883 | |||
| 884 | /** |
||
| 885 | * cycles through all of the models/*.model.php files, and assembles an array of model names |
||
| 886 | * |
||
| 887 | * @return void |
||
| 888 | * @throws ReflectionException |
||
| 889 | */ |
||
| 890 | private function _parse_model_names() |
||
| 912 | |||
| 913 | |||
| 914 | /** |
||
| 915 | * The purpose of this method is to simply check for a file named "caffeinated/brewing_regular.php" for any hooks |
||
| 916 | * that need to be setup before our EE_System launches. |
||
| 917 | * |
||
| 918 | * @return void |
||
| 919 | * @throws DomainException |
||
| 920 | * @throws InvalidArgumentException |
||
| 921 | * @throws InvalidDataTypeException |
||
| 922 | * @throws InvalidInterfaceException |
||
| 923 | * @throws InvalidClassException |
||
| 924 | * @throws InvalidFilePathException |
||
| 925 | */ |
||
| 926 | private function _maybe_brew_regular() |
||
| 942 | |||
| 943 | |||
| 944 | /** |
||
| 945 | * @since 4.9.71.p |
||
| 946 | * @throws Exception |
||
| 947 | */ |
||
| 948 | public function loadRouteMatchSpecifications() |
||
| 959 | |||
| 960 | |||
| 961 | /** |
||
| 962 | * register_shortcodes_modules_and_widgets |
||
| 963 | * generate lists of shortcodes and modules, then verify paths and classes |
||
| 964 | * This is hooked into 'AHEE__EE_Bootstrap__register_shortcodes_modules_and_widgets' |
||
| 965 | * which runs during the WP 'plugins_loaded' action at priority 7 |
||
| 966 | * |
||
| 967 | * @access public |
||
| 968 | * @return void |
||
| 969 | * @throws Exception |
||
| 970 | */ |
||
| 971 | public function register_shortcodes_modules_and_widgets() |
||
| 993 | |||
| 994 | |||
| 995 | /** |
||
| 996 | * _incompatible_addon_error |
||
| 997 | * |
||
| 998 | * @access public |
||
| 999 | * @return void |
||
| 1000 | */ |
||
| 1001 | private function _incompatible_addon_error() |
||
| 1033 | |||
| 1034 | |||
| 1035 | /** |
||
| 1036 | * brew_espresso |
||
| 1037 | * begins the process of setting hooks for initializing EE in the correct order |
||
| 1038 | * This is happening on the 'AHEE__EE_Bootstrap__brew_espresso' hook point |
||
| 1039 | * which runs during the WP 'plugins_loaded' action at priority 9 |
||
| 1040 | * |
||
| 1041 | * @return void |
||
| 1042 | * @throws Exception |
||
| 1043 | */ |
||
| 1044 | public function brew_espresso() |
||
| 1063 | |||
| 1064 | |||
| 1065 | /** |
||
| 1066 | * @return void |
||
| 1067 | * @throws Exception |
||
| 1068 | */ |
||
| 1069 | public function loadWpGraphql() |
||
| 1099 | |||
| 1100 | |||
| 1101 | /** |
||
| 1102 | * set_hooks_for_core |
||
| 1103 | * |
||
| 1104 | * @access public |
||
| 1105 | * @return void |
||
| 1106 | * @throws EE_Error |
||
| 1107 | */ |
||
| 1108 | public function set_hooks_for_core() |
||
| 1117 | |||
| 1118 | |||
| 1119 | /** |
||
| 1120 | * Using the information gathered in EE_System::_incompatible_addon_error, |
||
| 1121 | * deactivates any addons considered incompatible with the current version of EE |
||
| 1122 | */ |
||
| 1123 | private function _deactivate_incompatible_addons() |
||
| 1138 | |||
| 1139 | |||
| 1140 | /** |
||
| 1141 | * perform_activations_upgrades_and_migrations |
||
| 1142 | * |
||
| 1143 | * @access public |
||
| 1144 | * @return void |
||
| 1145 | */ |
||
| 1146 | public function perform_activations_upgrades_and_migrations() |
||
| 1150 | |||
| 1151 | |||
| 1152 | /** |
||
| 1153 | * @return void |
||
| 1154 | * @throws DomainException |
||
| 1155 | */ |
||
| 1156 | public function load_CPTs_and_session() |
||
| 1178 | |||
| 1179 | |||
| 1180 | /** |
||
| 1181 | * load_controllers |
||
| 1182 | * this is the best place to load any additional controllers that needs access to EE core. |
||
| 1183 | * it is expected that all basic core EE systems, that are not dependant on the current request are loaded at this |
||
| 1184 | * time |
||
| 1185 | * |
||
| 1186 | * @access public |
||
| 1187 | * @return void |
||
| 1188 | */ |
||
| 1189 | public function load_controllers() |
||
| 1206 | |||
| 1207 | |||
| 1208 | /** |
||
| 1209 | * core_loaded_and_ready |
||
| 1210 | * all of the basic EE core should be loaded at this point and available regardless of M-Mode |
||
| 1211 | * |
||
| 1212 | * @access public |
||
| 1213 | * @return void |
||
| 1214 | * @throws Exception |
||
| 1215 | */ |
||
| 1216 | public function core_loaded_and_ready() |
||
| 1249 | |||
| 1250 | |||
| 1251 | /** |
||
| 1252 | * initialize |
||
| 1253 | * this is the best place to begin initializing client code |
||
| 1254 | * |
||
| 1255 | * @access public |
||
| 1256 | * @return void |
||
| 1257 | */ |
||
| 1258 | public function initialize() |
||
| 1262 | |||
| 1263 | |||
| 1264 | /** |
||
| 1265 | * initialize_last |
||
| 1266 | * this is run really late during the WP init hook point, and ensures that mostly everything else that needs to |
||
| 1267 | * initialize has done so |
||
| 1268 | * |
||
| 1269 | * @access public |
||
| 1270 | * @return void |
||
| 1271 | */ |
||
| 1272 | public function initialize_last() |
||
| 1287 | |||
| 1288 | |||
| 1289 | /** |
||
| 1290 | * @return void |
||
| 1291 | * @throws EE_Error |
||
| 1292 | */ |
||
| 1293 | public function addEspressoToolbar() |
||
| 1300 | |||
| 1301 | |||
| 1302 | /** |
||
| 1303 | * do_not_cache |
||
| 1304 | * sets no cache headers and defines no cache constants for WP plugins |
||
| 1305 | * |
||
| 1306 | * @access public |
||
| 1307 | * @return void |
||
| 1308 | */ |
||
| 1309 | public static function do_not_cache() |
||
| 1328 | |||
| 1329 | |||
| 1330 | /** |
||
| 1331 | * extra_nocache_headers |
||
| 1332 | * |
||
| 1333 | * @access public |
||
| 1334 | * @param $headers |
||
| 1335 | * @return array |
||
| 1336 | */ |
||
| 1337 | public static function extra_nocache_headers($headers) |
||
| 1345 | |||
| 1346 | |||
| 1347 | /** |
||
| 1348 | * nocache_headers |
||
| 1349 | * |
||
| 1350 | * @access public |
||
| 1351 | * @return void |
||
| 1352 | */ |
||
| 1353 | public static function nocache_headers() |
||
| 1357 | |||
| 1358 | |||
| 1359 | /** |
||
| 1360 | * simply hooks into "wp_list_pages_exclude" filter (for wp_list_pages method) and makes sure EE critical pages are |
||
| 1361 | * never returned with the function. |
||
| 1362 | * |
||
| 1363 | * @param array $exclude_array any existing pages being excluded are in this array. |
||
| 1364 | * @return array |
||
| 1365 | */ |
||
| 1366 | public function remove_pages_from_wp_list_pages($exclude_array) |
||
| 1370 | |||
| 1371 | |||
| 1372 | /** |
||
| 1373 | * Return whether blocks can be registered/loaded or not. |
||
| 1374 | * @return bool |
||
| 1375 | */ |
||
| 1376 | private function canLoadBlocks() |
||
| 1384 | } |
||
| 1385 |
It seems like you allow that null is being passed for a parameter, however the function which is called does not seem to accept null.
We recommend to add an additional type check (or disallow null for the parameter):