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 if ( ! defined('EVENT_ESPRESSO_VERSION')) exit('No direct script access allowed'); |
||
| 12 | final class EE_System { |
||
| 13 | |||
| 14 | |||
| 15 | /** |
||
| 16 | * indicates this is a 'normal' request. Ie, not activation, nor upgrade, nor activation. |
||
| 17 | * So examples of this would be a normal GET request on the frontend or backend, or a POST, etc |
||
| 18 | */ |
||
| 19 | const req_type_normal = 0; |
||
| 20 | |||
| 21 | /** |
||
| 22 | * Indicates this is a brand new installation of EE so we should install |
||
| 23 | * tables and default data etc |
||
| 24 | */ |
||
| 25 | const req_type_new_activation = 1; |
||
| 26 | |||
| 27 | /** |
||
| 28 | * we've detected that EE has been reactivated (or EE was activated during maintenance mode, |
||
| 29 | * and we just exited maintenance mode). We MUST check the database is setup properly |
||
| 30 | * and that default data is setup too |
||
| 31 | */ |
||
| 32 | const req_type_reactivation = 2; |
||
| 33 | |||
| 34 | /** |
||
| 35 | * indicates that EE has been upgraded since its previous request. |
||
| 36 | * We may have data migration scripts to call and will want to trigger maintenance mode |
||
| 37 | */ |
||
| 38 | const req_type_upgrade = 3; |
||
| 39 | |||
| 40 | /** |
||
| 41 | * TODO will detect that EE has been DOWNGRADED. We probably don't want to run in this case... |
||
| 42 | */ |
||
| 43 | const req_type_downgrade = 4; |
||
| 44 | |||
| 45 | /** |
||
| 46 | * @deprecated since version 4.6.0.dev.006 |
||
| 47 | * Now whenever a new_activation is detected the request type is still just |
||
| 48 | * new_activation (same for reactivation, upgrade, downgrade etc), but if we'r ein maintenance mode |
||
| 49 | * EE_System::initialize_db_if_no_migrations_required and EE_Addon::initialize_db_if_no_migrations_required |
||
| 50 | * will instead enqueue that EE plugin's db initialization for when we're taken out of maintenance mode. |
||
| 51 | * (Specifically, when the migration manager indicates migrations are finished |
||
| 52 | * EE_Data_Migration_Manager::initialize_db_for_enqueued_ee_plugins() will be called) |
||
| 53 | */ |
||
| 54 | const req_type_activation_but_not_installed = 5; |
||
| 55 | |||
| 56 | /** |
||
| 57 | * option prefix for recording the activation history (like core's "espresso_db_update") of addons |
||
| 58 | */ |
||
| 59 | const addon_activation_history_option_prefix = 'ee_addon_activation_history_'; |
||
| 60 | |||
| 61 | |||
| 62 | /** |
||
| 63 | * instance of the EE_System object |
||
| 64 | * |
||
| 65 | * @var $_instance |
||
| 66 | * @access private |
||
| 67 | */ |
||
| 68 | private static $_instance = null; |
||
| 69 | |||
| 70 | /** |
||
| 71 | * @type EE_Registry $Registry |
||
| 72 | * @access protected |
||
| 73 | */ |
||
| 74 | protected $registry; |
||
| 75 | |||
| 76 | /** |
||
| 77 | * Stores which type of request this is, options being one of the constants on EE_System starting with req_type_*. |
||
| 78 | * It can be a brand-new activation, a reactivation, an upgrade, a downgrade, or a normal request. |
||
| 79 | * @var int |
||
| 80 | */ |
||
| 81 | private $_req_type; |
||
| 82 | |||
| 83 | |||
| 84 | |||
| 85 | /** |
||
| 86 | * @singleton method used to instantiate class object |
||
| 87 | * @access public |
||
| 88 | * @param \EE_Registry $Registry |
||
| 89 | * @return \EE_System |
||
| 90 | */ |
||
| 91 | public static function instance( EE_Registry $Registry = null ) { |
||
| 98 | |||
| 99 | |||
| 100 | /** |
||
| 101 | * resets the instance and returns it |
||
| 102 | * @return EE_System |
||
| 103 | */ |
||
| 104 | public static function reset(){ |
||
| 114 | |||
| 115 | |||
| 116 | |||
| 117 | /** |
||
| 118 | * sets hooks for running rest of system |
||
| 119 | * provides "AHEE__EE_System__construct__complete" hook for EE Addons to use as their starting point |
||
| 120 | * starting EE Addons from any other point may lead to problems |
||
| 121 | * |
||
| 122 | * @access private |
||
| 123 | * @param \EE_Registry $Registry |
||
| 124 | */ |
||
| 125 | private function __construct( EE_Registry $Registry ) { |
||
| 148 | |||
| 149 | |||
| 150 | |||
| 151 | /** |
||
| 152 | * load_espresso_addons |
||
| 153 | * |
||
| 154 | * allow addons to load first so that they can set hooks for running DMS's, etc |
||
| 155 | * this is hooked into both: |
||
| 156 | * 'AHEE__EE_Bootstrap__load_core_configuration' |
||
| 157 | * which runs during the WP 'plugins_loaded' action at priority 5 |
||
| 158 | * and the WP 'activate_plugin' hookpoint |
||
| 159 | * |
||
| 160 | * @access public |
||
| 161 | * @return void |
||
| 162 | */ |
||
| 163 | public function load_espresso_addons() { |
||
| 164 | // set autoloaders for all of the classes implementing EEI_Plugin_API |
||
| 165 | // which provide helpers for EE plugin authors to more easily register certain components with EE. |
||
| 166 | EEH_Autoloader::instance()->register_autoloaders_for_each_file_in_folder( EE_LIBRARIES . 'plugin_api' ); |
||
| 167 | //load and setup EE_Capabilities |
||
| 168 | $this->registry->load_core( 'Capabilities' ); |
||
| 169 | //caps need to be initialized on every request so that capability maps are set. |
||
| 170 | //@see https://events.codebasehq.com/projects/event-espresso/tickets/8674 |
||
| 171 | $this->registry->CAP->init_caps(); |
||
| 172 | do_action( 'AHEE__EE_System__load_espresso_addons' ); |
||
| 173 | //if the WP API basic auth plugin isn't already loaded, load it now. |
||
| 174 | //We want it for mobile apps. Just include the entire plugin |
||
| 175 | //also, don't load the basic auth when a plugin is getting activated, because |
||
| 176 | //it could be the basic auth plugin, and it doesn't check if its methods are already defined |
||
| 177 | //and causes a fatal error |
||
| 178 | if( !function_exists( 'json_basic_auth_handler' ) |
||
| 179 | && ! function_exists( 'json_basic_auth_error' ) |
||
| 180 | && ! ( |
||
| 181 | isset( $_GET[ 'action'] ) |
||
| 182 | && in_array( $_GET[ 'action' ], array( 'activate', 'activate-selected' ) ) |
||
| 183 | ) |
||
| 184 | && ! ( |
||
| 185 | isset( $_GET['activate' ] ) |
||
| 186 | && $_GET['activate' ] === 'true' |
||
| 187 | ) |
||
| 188 | ) { |
||
| 189 | include_once EE_THIRD_PARTY . 'wp-api-basic-auth' . DS . 'basic-auth.php'; |
||
| 190 | } |
||
| 191 | } |
||
| 192 | |||
| 193 | |||
| 194 | /** |
||
| 195 | * detect_activations_or_upgrades |
||
| 196 | * |
||
| 197 | * Checks for activation or upgrade of core first; |
||
| 198 | * then also checks if any registered addons have been activated or upgraded |
||
| 199 | * This is hooked into 'AHEE__EE_Bootstrap__detect_activations_or_upgrades' |
||
| 200 | * which runs during the WP 'plugins_loaded' action at priority 3 |
||
| 201 | * |
||
| 202 | * @access public |
||
| 203 | * @return void |
||
| 204 | */ |
||
| 205 | public function detect_activations_or_upgrades(){ |
||
| 213 | |||
| 214 | |||
| 215 | |||
| 216 | /** |
||
| 217 | * detect_if_activation_or_upgrade |
||
| 218 | * |
||
| 219 | * Takes care of detecting whether this is a brand new install or code upgrade, |
||
| 220 | * and either setting up the DB or setting up maintenance mode etc. |
||
| 221 | * |
||
| 222 | * @access public |
||
| 223 | * @return void |
||
| 224 | */ |
||
| 225 | public function detect_if_activation_or_upgrade() { |
||
| 226 | do_action('AHEE__EE_System___detect_if_activation_or_upgrade__begin'); |
||
| 227 | |||
| 228 | // load M-Mode class |
||
| 229 | $this->registry->load_core( 'Maintenance_Mode' ); |
||
| 230 | // check if db has been updated, or if its a brand-new installation |
||
| 231 | |||
| 232 | $espresso_db_update = $this->fix_espresso_db_upgrade_option(); |
||
| 233 | $request_type = $this->detect_req_type($espresso_db_update); |
||
| 234 | //EEH_Debug_Tools::printr( $request_type, '$request_type', __FILE__, __LINE__ ); |
||
| 235 | |||
| 236 | switch($request_type){ |
||
| 237 | case EE_System::req_type_new_activation: |
||
| 238 | do_action( 'AHEE__EE_System__detect_if_activation_or_upgrade__new_activation' ); |
||
| 239 | $this->_handle_core_version_change( $espresso_db_update ); |
||
| 240 | break; |
||
| 241 | case EE_System::req_type_reactivation: |
||
| 242 | do_action( 'AHEE__EE_System__detect_if_activation_or_upgrade__reactivation' ); |
||
| 243 | $this->_handle_core_version_change( $espresso_db_update ); |
||
| 244 | break; |
||
| 245 | case EE_System::req_type_upgrade: |
||
| 246 | do_action( 'AHEE__EE_System__detect_if_activation_or_upgrade__upgrade' ); |
||
| 247 | //migrations may be required now that we've upgraded |
||
| 248 | EE_Maintenance_Mode::instance()->set_maintenance_mode_if_db_old(); |
||
| 249 | $this->_handle_core_version_change( $espresso_db_update ); |
||
| 250 | // echo "done upgrade";die; |
||
| 251 | break; |
||
| 252 | case EE_System::req_type_downgrade: |
||
| 253 | do_action( 'AHEE__EE_System__detect_if_activation_or_upgrade__downgrade' ); |
||
| 254 | //its possible migrations are no longer required |
||
| 255 | EE_Maintenance_Mode::instance()->set_maintenance_mode_if_db_old(); |
||
| 256 | $this->_handle_core_version_change( $espresso_db_update ); |
||
| 257 | break; |
||
| 258 | case EE_System::req_type_normal: |
||
| 259 | default: |
||
| 260 | // $this->_maybe_redirect_to_ee_about(); |
||
| 261 | break; |
||
| 262 | } |
||
| 263 | do_action( 'AHEE__EE_System__detect_if_activation_or_upgrade__complete' ); |
||
| 264 | } |
||
| 265 | |||
| 266 | /** |
||
| 267 | * Updates the list of installed versions and sets hooks for |
||
| 268 | * initializing the database later during the request |
||
| 269 | * @param array $espresso_db_update |
||
| 270 | */ |
||
| 271 | protected function _handle_core_version_change( $espresso_db_update ){ |
||
| 276 | |||
| 277 | |||
| 278 | |||
| 279 | |||
| 280 | /** |
||
| 281 | * standardizes the wp option 'espresso_db_upgrade' which actually stores |
||
| 282 | * information about what versions of EE have been installed and activated, |
||
| 283 | * NOT necessarily the state of the database |
||
| 284 | * |
||
| 285 | * @param null $espresso_db_update |
||
| 286 | * @internal param array $espresso_db_update_value the value of the WordPress option. If not supplied, fetches it from the options table |
||
| 287 | * @return array the correct value of 'espresso_db_upgrade', after saving it, if it needed correction |
||
| 288 | */ |
||
| 289 | private function fix_espresso_db_upgrade_option($espresso_db_update = null){ |
||
| 329 | |||
| 330 | |||
| 331 | |||
| 332 | |||
| 333 | /** |
||
| 334 | * Does the traditional work of setting up the plugin's database and adding default data. |
||
| 335 | * If migration script/process did not exist, this is what would happen on every activation/reactivation/upgrade. |
||
| 336 | * NOTE: if we're in maintenance mode (which would be the case if we detect there are data |
||
| 337 | * migration scripts that need to be run and a version change happens), enqueues core for database initialization, |
||
| 338 | * so that it will be done when migrations are finished |
||
| 339 | * |
||
| 340 | * @param boolean $initialize_addons_too if true, we double-check addons' database tables etc too; |
||
| 341 | * @param boolean $verify_schema if true will re-check the database tables have the correct schema. |
||
| 342 | * This is a resource-intensive job |
||
| 343 | * so we prefer to only do it when necessary |
||
| 344 | * @return void |
||
| 345 | */ |
||
| 346 | public function initialize_db_if_no_migrations_required( $initialize_addons_too = FALSE, $verify_schema = true ){ |
||
| 367 | |||
| 368 | /** |
||
| 369 | * Initializes the db for all registered addons |
||
| 370 | */ |
||
| 371 | public function initialize_addons(){ |
||
| 377 | |||
| 378 | |||
| 379 | /** |
||
| 380 | * Adds the current code version to the saved wp option which stores a list of all ee versions ever installed. |
||
| 381 | * @param array $version_history |
||
| 382 | * @param string $current_version_to_add version to be added to the version history |
||
| 383 | * @return boolean success as to whether or not this option was changed |
||
| 384 | */ |
||
| 385 | public function update_list_of_installed_versions($version_history = NULL,$current_version_to_add = NULL) { |
||
| 396 | |||
| 397 | |||
| 398 | |||
| 399 | |||
| 400 | /** |
||
| 401 | * Detects if the current version indicated in the has existed in the list of |
||
| 402 | * previously-installed versions of EE (espresso_db_update). Does NOT modify it (ie, no side-effect) |
||
| 403 | * |
||
| 404 | * @param array $espresso_db_update array from the wp option stored under the name 'espresso_db_update'. |
||
| 405 | * If not supplied, fetches it from the options table. |
||
| 406 | * Also, caches its result so later parts of the code can also know whether there's been an |
||
| 407 | * update or not. This way we can add the current version to espresso_db_update, |
||
| 408 | * but still know if this is a new install or not |
||
| 409 | * @return int one of the constants on EE_System::req_type_ |
||
| 410 | */ |
||
| 411 | public function detect_req_type( $espresso_db_update = NULL ){ |
||
| 418 | |||
| 419 | |||
| 420 | |||
| 421 | /** |
||
| 422 | * Determines the request type for any ee addon, given three piece of info: the current array of activation histories (for core that' 'espresso_db_update' wp option); the name of the wordpress option which is temporarily set upon activation of the plugin (for core it's 'ee_espresso_activation'); and the version that this plugin |
||
| 423 | * was just activated to (for core that will always be espresso_version()) |
||
| 424 | * @param array $activation_history_for_addon the option's value which stores the activation history for this ee plugin. |
||
| 425 | * for core that's 'espresso_db_update' |
||
| 426 | * @param string $activation_indicator_option_name the name of the wordpress option that is temporarily set to indicate that this plugin was just activated |
||
| 427 | * @param string $version_to_upgrade_to the version that was just upgraded to (for core that will be espresso_version()) |
||
| 428 | * @return int one of the constants on EE_System::req_type_* |
||
| 429 | */ |
||
| 430 | public static function detect_req_type_given_activation_history( $activation_history_for_addon, $activation_indicator_option_name, $version_to_upgrade_to ){ |
||
| 474 | |||
| 475 | |||
| 476 | |||
| 477 | /** |
||
| 478 | * Detects if the $version_to_upgrade_to is higher than the most recent version in |
||
| 479 | * the $activation_history_for_addon |
||
| 480 | * @param array $activation_history_for_addon (keys are versions, values are arrays of times activated, |
||
| 481 | * sometimes containing 'unknown-date' |
||
| 482 | * @param string $version_to_upgrade_to (current version) |
||
| 483 | * @return int results of version_compare( $version_to_upgrade_to, $most_recently_active_version ). |
||
| 484 | * ie, -1 if $version_to_upgrade_to is LOWER (downgrade); |
||
| 485 | * 0 if $version_to_upgrade_to MATCHES (reactivation or normal request); |
||
| 486 | * 1 if $version_to_upgrade_to is HIGHER (upgrade) ; |
||
| 487 | */ |
||
| 488 | protected static function _new_version_is_higher( $activation_history_for_addon, $version_to_upgrade_to ){ |
||
| 513 | |||
| 514 | |||
| 515 | |||
| 516 | /** |
||
| 517 | * This redirects to the about EE page after activation |
||
| 518 | * @return void |
||
| 519 | */ |
||
| 520 | public function redirect_to_about_ee() { |
||
| 521 | $notices = EE_Error::get_notices( FALSE ); |
||
| 522 | //if current user is an admin and it's not an ajax request |
||
| 523 | if ( |
||
| 524 | $this->registry->CAP->current_user_can( 'manage_options', 'espresso_about_default' ) |
||
| 525 | && ! ( defined( 'DOING_AJAX' ) && DOING_AJAX ) |
||
| 526 | && ! isset( $notices[ 'errors' ] ) |
||
| 527 | ) { |
||
| 528 | $query_params = array( 'page' => 'espresso_about' ); |
||
| 529 | |||
| 530 | if ( EE_System::instance()->detect_req_type() == EE_System::req_type_new_activation ) { |
||
| 531 | $query_params['new_activation'] = TRUE; |
||
| 532 | } |
||
| 533 | |||
| 534 | if ( EE_System::instance()->detect_req_type() == EE_System::req_type_reactivation ) { |
||
| 535 | $query_params['reactivation'] = TRUE; |
||
| 536 | } |
||
| 537 | $url = add_query_arg( $query_params, admin_url( 'admin.php' ) ); |
||
| 538 | wp_safe_redirect( $url ); |
||
| 539 | exit(); |
||
| 540 | } |
||
| 541 | } |
||
| 542 | |||
| 543 | |||
| 544 | /** |
||
| 545 | * load_core_configuration |
||
| 546 | * |
||
| 547 | * this is hooked into 'AHEE__EE_Bootstrap__load_core_configuration' |
||
| 548 | * which runs during the WP 'plugins_loaded' action at priority 5 |
||
| 549 | * |
||
| 550 | * @return void |
||
| 551 | */ |
||
| 552 | public function load_core_configuration(){ |
||
| 578 | |||
| 579 | |||
| 580 | /** |
||
| 581 | * cycles through all of the models/*.model.php files, and assembles an array of model names |
||
| 582 | * |
||
| 583 | * @return void |
||
| 584 | */ |
||
| 585 | private function _parse_model_names(){ |
||
| 603 | |||
| 604 | |||
| 605 | |||
| 606 | /** |
||
| 607 | * The purpose of this method is to simply check for a file named "caffeinated/brewing_regular.php" for any hooks that need to be setup before our EE_System launches. |
||
| 608 | * @return void |
||
| 609 | */ |
||
| 610 | private function _maybe_brew_regular() { |
||
| 615 | |||
| 616 | |||
| 617 | |||
| 618 | /** |
||
| 619 | * register_shortcodes_modules_and_widgets |
||
| 620 | * |
||
| 621 | * generate lists of shortcodes and modules, then verify paths and classes |
||
| 622 | * This is hooked into 'AHEE__EE_Bootstrap__register_shortcodes_modules_and_widgets' |
||
| 623 | * which runs during the WP 'plugins_loaded' action at priority 7 |
||
| 624 | * |
||
| 625 | * @access public |
||
| 626 | * @return void |
||
| 627 | */ |
||
| 628 | public function register_shortcodes_modules_and_widgets() { |
||
| 635 | |||
| 636 | |||
| 637 | /** |
||
| 638 | * _incompatible_addon_error |
||
| 639 | * |
||
| 640 | * @access public |
||
| 641 | * @return void |
||
| 642 | */ |
||
| 643 | private function _incompatible_addon_error() { |
||
| 661 | |||
| 662 | |||
| 663 | |||
| 664 | |||
| 665 | /** |
||
| 666 | * brew_espresso |
||
| 667 | * |
||
| 668 | * begins the process of setting hooks for initializing EE in the correct order |
||
| 669 | * This is happening on the 'AHEE__EE_Bootstrap__brew_espresso' hookpoint |
||
| 670 | * which runs during the WP 'plugins_loaded' action at priority 9 |
||
| 671 | * |
||
| 672 | * @return void |
||
| 673 | */ |
||
| 674 | public function brew_espresso(){ |
||
| 694 | |||
| 695 | |||
| 696 | |||
| 697 | |||
| 698 | /** |
||
| 699 | * set_hooks_for_core |
||
| 700 | * |
||
| 701 | * @access public |
||
| 702 | * @return void |
||
| 703 | */ |
||
| 704 | public function set_hooks_for_core() { |
||
| 708 | |||
| 709 | |||
| 710 | |||
| 711 | /** |
||
| 712 | * Using the information gathered in EE_System::_incompatible_addon_error, |
||
| 713 | * deactivates any addons considered incompatible with the current version of EE |
||
| 714 | */ |
||
| 715 | private function _deactivate_incompatible_addons(){ |
||
| 729 | |||
| 730 | |||
| 731 | |||
| 732 | /** |
||
| 733 | * perform_activations_upgrades_and_migrations |
||
| 734 | * |
||
| 735 | * @access public |
||
| 736 | * @return void |
||
| 737 | */ |
||
| 738 | public function perform_activations_upgrades_and_migrations() { |
||
| 745 | |||
| 746 | |||
| 747 | |||
| 748 | /** |
||
| 749 | * load_CPTs_and_session |
||
| 750 | * |
||
| 751 | * @access public |
||
| 752 | * @return void |
||
| 753 | */ |
||
| 754 | public function load_CPTs_and_session() { |
||
| 760 | |||
| 761 | |||
| 762 | |||
| 763 | /** |
||
| 764 | * load_controllers |
||
| 765 | * |
||
| 766 | * this is the best place to load any additional controllers that needs access to EE core. |
||
| 767 | * it is expected that all basic core EE systems, that are not dependant on the current request are loaded at this time |
||
| 768 | * |
||
| 769 | * @access public |
||
| 770 | * @return void |
||
| 771 | */ |
||
| 772 | public function load_controllers() { |
||
| 784 | |||
| 785 | |||
| 786 | |||
| 787 | /** |
||
| 788 | * core_loaded_and_ready |
||
| 789 | * |
||
| 790 | * all of the basic EE core should be loaded at this point and available regardless of M-Mode |
||
| 791 | * |
||
| 792 | * @access public |
||
| 793 | * @return void |
||
| 794 | */ |
||
| 795 | public function core_loaded_and_ready() { |
||
| 801 | |||
| 802 | |||
| 803 | |||
| 804 | /** |
||
| 805 | * initialize |
||
| 806 | * |
||
| 807 | * this is the best place to begin initializing client code |
||
| 808 | * |
||
| 809 | * @access public |
||
| 810 | * @return void |
||
| 811 | */ |
||
| 812 | public function initialize() { |
||
| 815 | |||
| 816 | |||
| 817 | |||
| 818 | /** |
||
| 819 | * initialize_last |
||
| 820 | * |
||
| 821 | * this is run really late during the WP init hookpoint, and ensures that mostly everything else that needs to initialize has done so |
||
| 822 | * |
||
| 823 | * @access public |
||
| 824 | * @return void |
||
| 825 | */ |
||
| 826 | public function initialize_last() { |
||
| 829 | |||
| 830 | |||
| 831 | |||
| 832 | |||
| 833 | /** |
||
| 834 | * set_hooks_for_shortcodes_modules_and_addons |
||
| 835 | * |
||
| 836 | * this is the best place for other systems to set callbacks for hooking into other parts of EE |
||
| 837 | * this happens at the very beginning of the wp_loaded hookpoint |
||
| 838 | * |
||
| 839 | * @access public |
||
| 840 | * @return void |
||
| 841 | */ |
||
| 842 | public function set_hooks_for_shortcodes_modules_and_addons() { |
||
| 845 | |||
| 846 | |||
| 847 | |||
| 848 | |||
| 849 | /** |
||
| 850 | * do_not_cache |
||
| 851 | * |
||
| 852 | * sets no cache headers and defines no cache constants for WP plugins |
||
| 853 | * |
||
| 854 | * @access public |
||
| 855 | * @return void |
||
| 856 | */ |
||
| 857 | public static function do_not_cache() { |
||
| 875 | |||
| 876 | |||
| 877 | |||
| 878 | /** |
||
| 879 | * extra_nocache_headers |
||
| 880 | * |
||
| 881 | * @access public |
||
| 882 | * @param $headers |
||
| 883 | * @return array |
||
| 884 | */ |
||
| 885 | public static function extra_nocache_headers ( $headers ) { |
||
| 892 | |||
| 893 | |||
| 894 | |||
| 895 | /** |
||
| 896 | * nocache_headers |
||
| 897 | * |
||
| 898 | * @access public |
||
| 899 | * @return void |
||
| 900 | */ |
||
| 901 | public static function nocache_headers() { |
||
| 904 | |||
| 905 | |||
| 906 | |||
| 907 | /** |
||
| 908 | * espresso_toolbar_items |
||
| 909 | * |
||
| 910 | * @access public |
||
| 911 | * @param WP_Admin_Bar $admin_bar |
||
| 912 | * @return void |
||
| 913 | */ |
||
| 914 | public function espresso_toolbar_items( WP_Admin_Bar $admin_bar ) { |
||
| 915 | |||
| 916 | // if in full M-Mode, or its an AJAX request, or user is NOT an admin |
||
| 917 | if ( EE_Maintenance_Mode::instance()->level() == EE_Maintenance_Mode::level_2_complete_maintenance || defined( 'DOING_AJAX' ) || ! $this->registry->CAP->current_user_can( 'ee_read_ee', 'ee_admin_bar_menu_top_level' )) { |
||
| 918 | return; |
||
| 919 | } |
||
| 920 | |||
| 921 | do_action( 'AHEE_log', __FILE__, __FUNCTION__, '' ); |
||
| 922 | $menu_class = 'espresso_menu_item_class'; |
||
| 923 | //we don't use the constants EVENTS_ADMIN_URL or REG_ADMIN_URL |
||
| 924 | //because they're only defined in each of their respective constructors |
||
| 925 | //and this might be a frontend request, in which case they aren't available |
||
| 926 | $events_admin_url = admin_url("admin.php?page=espresso_events"); |
||
| 927 | $reg_admin_url = admin_url("admin.php?page=espresso_registrations"); |
||
| 928 | $extensions_admin_url = admin_url("admin.php?page=espresso_packages"); |
||
| 929 | |||
| 930 | //Top Level |
||
| 931 | $admin_bar->add_menu(array( |
||
| 932 | 'id' => 'espresso-toolbar', |
||
| 933 | 'title' => '<span class="ee-icon ee-icon-ee-cup-thick ee-icon-size-20"></span><span class="ab-label">' . _x('Event Espresso', 'admin bar menu group label', 'event_espresso') . '</span>', |
||
| 934 | 'href' => $events_admin_url, |
||
| 935 | 'meta' => array( |
||
| 936 | 'title' => __('Event Espresso', 'event_espresso'), |
||
| 937 | 'class' => $menu_class . 'first' |
||
| 938 | ), |
||
| 939 | )); |
||
| 940 | |||
| 941 | //Events |
||
| 942 | View Code Duplication | if ( $this->registry->CAP->current_user_can( 'ee_read_events', 'ee_admin_bar_menu_espresso-toolbar-events' ) ) { |
|
| 943 | $admin_bar->add_menu(array( |
||
| 944 | 'id' => 'espresso-toolbar-events', |
||
| 945 | 'parent' => 'espresso-toolbar', |
||
| 946 | 'title' => __( 'Events', 'event_espresso' ), |
||
| 947 | 'href' => $events_admin_url, |
||
| 948 | 'meta' => array( |
||
| 949 | 'title' => __('Events', 'event_espresso'), |
||
| 950 | 'target' => '', |
||
| 951 | 'class' => $menu_class |
||
| 952 | ), |
||
| 953 | )); |
||
| 954 | } |
||
| 955 | |||
| 956 | |||
| 957 | if ( $this->registry->CAP->current_user_can( 'ee_edit_events', 'ee_admin_bar_menu_espresso-toolbar-events-new' ) ) { |
||
| 958 | //Events Add New |
||
| 959 | $admin_bar->add_menu(array( |
||
| 960 | 'id' => 'espresso-toolbar-events-new', |
||
| 961 | 'parent' => 'espresso-toolbar-events', |
||
| 962 | 'title' => __('Add New', 'event_espresso'), |
||
| 963 | 'href' => EEH_URL::add_query_args_and_nonce( array( 'action'=>'create_new' ), $events_admin_url ), |
||
| 964 | 'meta' => array( |
||
| 965 | 'title' => __('Add New', 'event_espresso'), |
||
| 966 | 'target' => '', |
||
| 967 | 'class' => $menu_class |
||
| 968 | ), |
||
| 969 | )); |
||
| 970 | } |
||
| 971 | |||
| 972 | if ( is_single() && ( get_post_type() == 'espresso_events' ) ) { |
||
| 973 | |||
| 974 | //Current post |
||
| 975 | global $post; |
||
| 976 | |||
| 977 | if ( $this->registry->CAP->current_user_can( 'ee_edit_event', 'ee_admin_bar_menu_espresso-toolbar-events-edit', $post->ID ) ) { |
||
| 978 | //Events Edit Current Event |
||
| 979 | $admin_bar->add_menu(array( |
||
| 980 | 'id' => 'espresso-toolbar-events-edit', |
||
| 981 | 'parent' => 'espresso-toolbar-events', |
||
| 982 | 'title' => __('Edit Event', 'event_espresso'), |
||
| 983 | 'href' => EEH_URL::add_query_args_and_nonce( array( 'action'=>'edit', 'post'=>$post->ID ), $events_admin_url ), |
||
| 984 | 'meta' => array( |
||
| 985 | 'title' => __('Edit Event', 'event_espresso'), |
||
| 986 | 'target' => '', |
||
| 987 | 'class' => $menu_class |
||
| 988 | ), |
||
| 989 | )); |
||
| 990 | } |
||
| 991 | |||
| 992 | } |
||
| 993 | |||
| 994 | //Events View |
||
| 995 | View Code Duplication | if ( $this->registry->CAP->current_user_can( 'ee_read_events', 'ee_admin_bar_menu_espresso-toolbar-events-view' ) ) { |
|
| 996 | $admin_bar->add_menu(array( |
||
| 997 | 'id' => 'espresso-toolbar-events-view', |
||
| 998 | 'parent' => 'espresso-toolbar-events', |
||
| 999 | 'title' => __( 'View', 'event_espresso' ), |
||
| 1000 | 'href' => $events_admin_url, |
||
| 1001 | 'meta' => array( |
||
| 1002 | 'title' => __('View', 'event_espresso'), |
||
| 1003 | 'target' => '', |
||
| 1004 | 'class' => $menu_class |
||
| 1005 | ), |
||
| 1006 | )); |
||
| 1007 | } |
||
| 1008 | |||
| 1009 | View Code Duplication | if ( $this->registry->CAP->current_user_can( 'ee_read_events', 'ee_admin_bar_menu_espresso-toolbar-events-all' ) ) { |
|
| 1010 | //Events View All |
||
| 1011 | $admin_bar->add_menu(array( |
||
| 1012 | 'id' => 'espresso-toolbar-events-all', |
||
| 1013 | 'parent' => 'espresso-toolbar-events-view', |
||
| 1014 | 'title' => __( 'All', 'event_espresso' ), |
||
| 1015 | 'href' => $events_admin_url, |
||
| 1016 | 'meta' => array( |
||
| 1017 | 'title' => __('All', 'event_espresso'), |
||
| 1018 | 'target' => '', |
||
| 1019 | 'class' => $menu_class |
||
| 1020 | ), |
||
| 1021 | )); |
||
| 1022 | } |
||
| 1023 | |||
| 1024 | |||
| 1025 | View Code Duplication | if ( $this->registry->CAP->current_user_can( 'ee_read_events', 'ee_admin_bar_menu_espresso-toolbar-events-today' ) ) { |
|
| 1026 | //Events View Today |
||
| 1027 | $admin_bar->add_menu(array( |
||
| 1028 | 'id' => 'espresso-toolbar-events-today', |
||
| 1029 | 'parent' => 'espresso-toolbar-events-view', |
||
| 1030 | 'title' => __('Today', 'event_espresso'), |
||
| 1031 | 'href' => EEH_URL::add_query_args_and_nonce( array( 'action'=>'default', 'status'=>'today' ), $events_admin_url ), |
||
| 1032 | 'meta' => array( |
||
| 1033 | 'title' => __('Today', 'event_espresso'), |
||
| 1034 | 'target' => '', |
||
| 1035 | 'class' => $menu_class |
||
| 1036 | ), |
||
| 1037 | )); |
||
| 1038 | } |
||
| 1039 | |||
| 1040 | |||
| 1041 | View Code Duplication | if ( $this->registry->CAP->current_user_can( 'ee_read_events', 'ee_admin_bar_menu_espresso-toolbar-events-month' ) ) { |
|
| 1042 | //Events View This Month |
||
| 1043 | $admin_bar->add_menu(array( |
||
| 1044 | 'id' => 'espresso-toolbar-events-month', |
||
| 1045 | 'parent' => 'espresso-toolbar-events-view', |
||
| 1046 | 'title' => __( 'This Month', 'event_espresso'), |
||
| 1047 | 'href' => EEH_URL::add_query_args_and_nonce( array( 'action'=>'default', 'status'=>'month' ), $events_admin_url ), |
||
| 1048 | 'meta' => array( |
||
| 1049 | 'title' => __('This Month', 'event_espresso'), |
||
| 1050 | 'target' => '', |
||
| 1051 | 'class' => $menu_class |
||
| 1052 | ), |
||
| 1053 | )); |
||
| 1054 | } |
||
| 1055 | |||
| 1056 | //Registration Overview |
||
| 1057 | View Code Duplication | if ( $this->registry->CAP->current_user_can( 'ee_read_registrations', 'ee_admin_bar_menu_espresso-toolbar-registrations' ) ) { |
|
| 1058 | $admin_bar->add_menu(array( |
||
| 1059 | 'id' => 'espresso-toolbar-registrations', |
||
| 1060 | 'parent' => 'espresso-toolbar', |
||
| 1061 | 'title' => __( 'Registrations', 'event_espresso' ), |
||
| 1062 | 'href' => $reg_admin_url, |
||
| 1063 | 'meta' => array( |
||
| 1064 | 'title' => __('Registrations', 'event_espresso'), |
||
| 1065 | 'target' => '', |
||
| 1066 | 'class' => $menu_class |
||
| 1067 | ), |
||
| 1068 | )); |
||
| 1069 | } |
||
| 1070 | |||
| 1071 | //Registration Overview Today |
||
| 1072 | View Code Duplication | if ( $this->registry->CAP->current_user_can( 'ee_read_registrations', 'ee_admin_bar_menu_espresso-toolbar-registrations-today' ) ) { |
|
| 1073 | $admin_bar->add_menu(array( |
||
| 1074 | 'id' => 'espresso-toolbar-registrations-today', |
||
| 1075 | 'parent' => 'espresso-toolbar-registrations', |
||
| 1076 | 'title' => __( 'Today', 'event_espresso'), |
||
| 1077 | 'href' => EEH_URL::add_query_args_and_nonce( array( 'action'=>'default', 'status'=>'today' ), $reg_admin_url ), |
||
| 1078 | 'meta' => array( |
||
| 1079 | 'title' => __('Today', 'event_espresso'), |
||
| 1080 | 'target' => '', |
||
| 1081 | 'class' => $menu_class |
||
| 1082 | ), |
||
| 1083 | )); |
||
| 1084 | } |
||
| 1085 | |||
| 1086 | //Registration Overview Today Completed |
||
| 1087 | View Code Duplication | if ( $this->registry->CAP->current_user_can( 'ee_read_registrations', 'ee_admin_bar_menu_espresso-toolbar-registrations-today-approved' ) ) { |
|
| 1088 | $admin_bar->add_menu(array( |
||
| 1089 | 'id' => 'espresso-toolbar-registrations-today-approved', |
||
| 1090 | 'parent' => 'espresso-toolbar-registrations-today', |
||
| 1091 | 'title' => __( 'Approved', 'event_espresso' ), |
||
| 1092 | 'href' => EEH_URL::add_query_args_and_nonce( array( 'action'=>'default', 'status'=>'today', '_reg_status'=>EEM_Registration::status_id_approved ), $reg_admin_url ), |
||
| 1093 | 'meta' => array( |
||
| 1094 | 'title' => __('Approved', 'event_espresso' ), |
||
| 1095 | 'target' => '', |
||
| 1096 | 'class' => $menu_class |
||
| 1097 | ), |
||
| 1098 | )); |
||
| 1099 | } |
||
| 1100 | |||
| 1101 | //Registration Overview Today Pending\ |
||
| 1102 | View Code Duplication | if ( $this->registry->CAP->current_user_can( 'ee_read_registrations', 'ee_admin_bar_menu_espresso-toolbar-registrations-today-pending' ) ) { |
|
| 1103 | $admin_bar->add_menu(array( |
||
| 1104 | 'id' => 'espresso-toolbar-registrations-today-pending', |
||
| 1105 | 'parent' => 'espresso-toolbar-registrations-today', |
||
| 1106 | 'title' => __( 'Pending', 'event_espresso' ), |
||
| 1107 | 'href' => EEH_URL::add_query_args_and_nonce( array( 'action'=>'default', 'status'=>'today', 'reg_status'=>EEM_Registration::status_id_pending_payment ), $reg_admin_url ), |
||
| 1108 | 'meta' => array( |
||
| 1109 | 'title' => __('Pending Payment', 'event_espresso' ), |
||
| 1110 | 'target' => '', |
||
| 1111 | 'class' => $menu_class |
||
| 1112 | ), |
||
| 1113 | )); |
||
| 1114 | } |
||
| 1115 | |||
| 1116 | //Registration Overview Today Incomplete |
||
| 1117 | View Code Duplication | if ( $this->registry->CAP->current_user_can( 'ee_read_registrations', 'ee_admin_bar_menu_espresso-toolbar-registrations-today-not-approved' ) ) { |
|
| 1118 | $admin_bar->add_menu(array( |
||
| 1119 | 'id' => 'espresso-toolbar-registrations-today-not-approved', |
||
| 1120 | 'parent' => 'espresso-toolbar-registrations-today', |
||
| 1121 | 'title' => __( 'Not Approved', 'event_espresso' ), |
||
| 1122 | 'href' => EEH_URL::add_query_args_and_nonce( array( 'action'=>'default', 'status'=>'today', '_reg_status'=>EEM_Registration::status_id_not_approved ), $reg_admin_url ), |
||
| 1123 | 'meta' => array( |
||
| 1124 | 'title' => __('Not Approved', 'event_espresso' ), |
||
| 1125 | 'target' => '', |
||
| 1126 | 'class' => $menu_class |
||
| 1127 | ), |
||
| 1128 | )); |
||
| 1129 | } |
||
| 1130 | |||
| 1131 | //Registration Overview Today Incomplete |
||
| 1132 | View Code Duplication | if ( $this->registry->CAP->current_user_can( 'ee_read_registrations', 'ee_admin_bar_menu_espresso-toolbar-registrations-today-cancelled' ) ) { |
|
| 1133 | $admin_bar->add_menu(array( |
||
| 1134 | 'id' => 'espresso-toolbar-registrations-today-cancelled', |
||
| 1135 | 'parent' => 'espresso-toolbar-registrations-today', |
||
| 1136 | 'title' => __( 'Cancelled', 'event_espresso'), |
||
| 1137 | 'href' => EEH_URL::add_query_args_and_nonce( array( 'action'=>'default', 'status'=>'today', '_reg_status'=>EEM_Registration::status_id_cancelled ), $reg_admin_url ), |
||
| 1138 | 'meta' => array( |
||
| 1139 | 'title' => __('Cancelled', 'event_espresso'), |
||
| 1140 | 'target' => '', |
||
| 1141 | 'class' => $menu_class |
||
| 1142 | ), |
||
| 1143 | )); |
||
| 1144 | } |
||
| 1145 | |||
| 1146 | //Registration Overview This Month |
||
| 1147 | View Code Duplication | if ( $this->registry->CAP->current_user_can( 'ee_read_registrations', 'ee_admin_bar_menu_espresso-toolbar-registrations-month' ) ) { |
|
| 1148 | $admin_bar->add_menu(array( |
||
| 1149 | 'id' => 'espresso-toolbar-registrations-month', |
||
| 1150 | 'parent' => 'espresso-toolbar-registrations', |
||
| 1151 | 'title' => __( 'This Month', 'event_espresso' ), |
||
| 1152 | 'href' => EEH_URL::add_query_args_and_nonce( array( 'action'=>'default', 'status'=>'month' ), $reg_admin_url ), |
||
| 1153 | 'meta' => array( |
||
| 1154 | 'title' => __('This Month', 'event_espresso'), |
||
| 1155 | 'target' => '', |
||
| 1156 | 'class' => $menu_class |
||
| 1157 | ), |
||
| 1158 | )); |
||
| 1159 | } |
||
| 1160 | |||
| 1161 | //Registration Overview This Month Approved |
||
| 1162 | View Code Duplication | if ( $this->registry->CAP->current_user_can( 'ee_read_registrations', 'ee_admin_bar_menu_espresso-toolbar-registrations-month-approved' ) ) { |
|
| 1163 | $admin_bar->add_menu(array( |
||
| 1164 | 'id' => 'espresso-toolbar-registrations-month-approved', |
||
| 1165 | 'parent' => 'espresso-toolbar-registrations-month', |
||
| 1166 | 'title' => __( 'Approved', 'event_espresso' ), |
||
| 1167 | 'href' => EEH_URL::add_query_args_and_nonce( array( 'action'=>'default', 'status'=>'month', '_reg_status'=>EEM_Registration::status_id_approved ), $reg_admin_url ), |
||
| 1168 | 'meta' => array( |
||
| 1169 | 'title' => __('Approved', 'event_espresso'), |
||
| 1170 | 'target' => '', |
||
| 1171 | 'class' => $menu_class |
||
| 1172 | ), |
||
| 1173 | )); |
||
| 1174 | } |
||
| 1175 | |||
| 1176 | //Registration Overview This Month Pending |
||
| 1177 | View Code Duplication | if ( $this->registry->CAP->current_user_can( 'ee_read_registrations', 'ee_admin_bar_menu_espresso-toolbar-registrations-month-pending' ) ) { |
|
| 1178 | $admin_bar->add_menu(array( |
||
| 1179 | 'id' => 'espresso-toolbar-registrations-month-pending', |
||
| 1180 | 'parent' => 'espresso-toolbar-registrations-month', |
||
| 1181 | 'title' => __( 'Pending', 'event_espresso'), |
||
| 1182 | 'href' => EEH_URL::add_query_args_and_nonce( array( 'action'=>'default', 'status'=>'month', '_reg_status'=>EEM_Registration::status_id_pending_payment ), $reg_admin_url ), |
||
| 1183 | 'meta' => array( |
||
| 1184 | 'title' => __('Pending', 'event_espresso'), |
||
| 1185 | 'target' => '', |
||
| 1186 | 'class' => $menu_class |
||
| 1187 | ), |
||
| 1188 | )); |
||
| 1189 | } |
||
| 1190 | |||
| 1191 | //Registration Overview This Month Not Approved |
||
| 1192 | View Code Duplication | if ( $this->registry->CAP->current_user_can( 'ee_read_registrations', 'ee_admin_bar_menu_espresso-toolbar-registrations-month-not-approved' ) ) { |
|
| 1193 | $admin_bar->add_menu(array( |
||
| 1194 | 'id' => 'espresso-toolbar-registrations-month-not-approved', |
||
| 1195 | 'parent' => 'espresso-toolbar-registrations-month', |
||
| 1196 | 'title' => __( 'Not Approved', 'event_espresso'), |
||
| 1197 | 'href' => EEH_URL::add_query_args_and_nonce( array( 'action'=>'default', 'status'=>'month', '_reg_status'=>EEM_Registration::status_id_not_approved ), $reg_admin_url ), |
||
| 1198 | 'meta' => array( |
||
| 1199 | 'title' => __('Not Approved', 'event_espresso' ), |
||
| 1200 | 'target' => '', |
||
| 1201 | 'class' => $menu_class |
||
| 1202 | ), |
||
| 1203 | )); |
||
| 1204 | } |
||
| 1205 | |||
| 1206 | |||
| 1207 | //Registration Overview This Month Cancelled |
||
| 1208 | View Code Duplication | if ( $this->registry->CAP->current_user_can( 'ee_read_registrations', 'ee_admin_bar_menu_espresso-toolbar-registrations-month-cancelled' ) ) { |
|
| 1209 | $admin_bar->add_menu(array( |
||
| 1210 | 'id' => 'espresso-toolbar-registrations-month-cancelled', |
||
| 1211 | 'parent' => 'espresso-toolbar-registrations-month', |
||
| 1212 | 'title' => __('Cancelled', 'event_espresso'), |
||
| 1213 | 'href' => EEH_URL::add_query_args_and_nonce( array( 'action'=>'default', 'status'=>'month', '_reg_status'=>EEM_Registration::status_id_cancelled ), $reg_admin_url ), |
||
| 1214 | 'meta' => array( |
||
| 1215 | 'title' => __('Cancelled', 'event_espresso'), |
||
| 1216 | 'target' => '', |
||
| 1217 | 'class' => $menu_class |
||
| 1218 | ), |
||
| 1219 | )); |
||
| 1220 | } |
||
| 1221 | |||
| 1222 | //Extensions & Services |
||
| 1223 | View Code Duplication | if ( $this->registry->CAP->current_user_can( 'ee_read_ee', 'ee_admin_bar_menu_espresso-toolbar-extensions-and-services' ) ) { |
|
| 1224 | $admin_bar->add_menu(array( |
||
| 1225 | 'id' => 'espresso-toolbar-extensions-and-services', |
||
| 1226 | 'parent' => 'espresso-toolbar', |
||
| 1227 | 'title' => __( 'Extensions & Services', 'event_espresso' ), |
||
| 1228 | 'href' => $extensions_admin_url, |
||
| 1229 | 'meta' => array( |
||
| 1230 | 'title' => __('Extensions & Services', 'event_espresso'), |
||
| 1231 | 'target' => '', |
||
| 1232 | 'class' => $menu_class |
||
| 1233 | ), |
||
| 1234 | )); |
||
| 1235 | } |
||
| 1236 | } |
||
| 1237 | |||
| 1238 | |||
| 1239 | |||
| 1240 | |||
| 1241 | |||
| 1242 | /** |
||
| 1243 | * simply hooks into "wp_list_pages_exclude" filter (for wp_list_pages method) and makes sure EE critical pages are never returned with the function. |
||
| 1244 | * |
||
| 1245 | * |
||
| 1246 | * @param array $exclude_array any existing pages being excluded are in this array. |
||
| 1247 | * @return array |
||
| 1248 | */ |
||
| 1249 | public function remove_pages_from_wp_list_pages( $exclude_array ) { |
||
| 1252 | |||
| 1253 | |||
| 1254 | |||
| 1255 | |||
| 1256 | |||
| 1257 | |||
| 1258 | /*********************************************** WP_ENQUEUE_SCRIPTS HOOK ***********************************************/ |
||
| 1259 | |||
| 1260 | |||
| 1261 | |||
| 1262 | /** |
||
| 1263 | * wp_enqueue_scripts |
||
| 1264 | * |
||
| 1265 | * @access public |
||
| 1266 | * @return void |
||
| 1267 | */ |
||
| 1268 | public function wp_enqueue_scripts() { |
||
| 1279 | |||
| 1280 | |||
| 1281 | |||
| 1282 | } |
||
| 1283 | // End of file EE_System.core.php |
||
| 1285 |
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):