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'); |
||
24 | final class EE_System { |
||
25 | |||
26 | |||
27 | /** |
||
28 | * instance of the EE_System object |
||
29 | * |
||
30 | * @var $_instance |
||
31 | * @access private |
||
32 | */ |
||
33 | private static $_instance = null; |
||
34 | |||
35 | /** |
||
36 | * @access protected |
||
37 | * @type $config EE_Registry |
||
38 | */ |
||
39 | protected $registry; |
||
40 | |||
41 | /** |
||
42 | * @access protected |
||
43 | * @type $config EE_Config |
||
44 | */ |
||
45 | protected $config; |
||
46 | |||
47 | /** |
||
48 | * indicates this is a 'normal' request. Ie, not activation, nor upgrade, nor activation. |
||
49 | * So examples of this would be a normal GET request on the frontend or backend, or a POST, etc |
||
50 | */ |
||
51 | const req_type_normal = 0; |
||
52 | /** |
||
53 | * Indicates this is a brand new installation of EE so we should install |
||
54 | * tables and default data etc |
||
55 | */ |
||
56 | const req_type_new_activation = 1; |
||
57 | /** |
||
58 | * we've detected that EE has been reactivated (or EE was activated during maintenance mode, |
||
59 | * and we just exited maintenance mode). We MUST check the database is setup properly |
||
60 | * and that default data is setup too |
||
61 | */ |
||
62 | const req_type_reactivation = 2; |
||
63 | /** |
||
64 | * indicates that EE has been upgraded since its previous request. |
||
65 | * We may have data migration scripts to call and will want to trigger maintenance mode |
||
66 | */ |
||
67 | const req_type_upgrade = 3; |
||
68 | /** |
||
69 | * TODO will detect that EE has been DOWNGRADED. We probably don't want to run in this case... |
||
70 | */ |
||
71 | const req_type_downgrade = 4; |
||
72 | |||
73 | /** |
||
74 | * @deprecated since version 4.6.0.dev.006 |
||
75 | * Now whenever a new_activation is detected the request type is still just |
||
76 | * new_activation (same for reactivation, upgrade, downgrade etc), but if we'r ein maintenance mode |
||
77 | * EE_System::initialize_db_if_no_migrations_required and EE_Addon::initialize_db_if_no_migrations_required |
||
78 | * will instead enqueue that EE plugin's db initialization for when we're taken out of maintenance mode. |
||
79 | * (Specifically, when the migration manager indicates migrations are finished |
||
80 | * EE_Data_Migration_Manager::initialize_db_for_enqueued_ee_plugins() will be called) |
||
81 | */ |
||
82 | const req_type_activation_but_not_installed = 5; |
||
83 | |||
84 | /** |
||
85 | * option prefix for recording the activation history (like core's "espresso_db_update") of addons |
||
86 | */ |
||
87 | const addon_activation_history_option_prefix = 'ee_addon_activation_history_'; |
||
88 | |||
89 | /** |
||
90 | * Stores which type of request this is, options being one of the constants on EE_System starting with req_type_*. |
||
91 | * It can be a brand-new activation, a reactivation, an upgrade, a downgrade, or a normal request. |
||
92 | * @var int |
||
93 | */ |
||
94 | private $_req_type; |
||
95 | |||
96 | |||
97 | |||
98 | /** |
||
99 | * @singleton method used to instantiate class object |
||
100 | * @access public |
||
101 | * @return EE_System |
||
102 | */ |
||
103 | public static function instance() { |
||
104 | // check if class object is instantiated |
||
105 | if ( ! self::$_instance instanceof EE_System ) { |
||
106 | self::$_instance = new self(); |
||
107 | } |
||
108 | return self::$_instance; |
||
109 | } |
||
110 | |||
111 | |||
112 | /** |
||
113 | * resets the instance and returns it |
||
114 | * @return EE_System |
||
115 | */ |
||
116 | public static function reset(){ |
||
117 | self::$_instance->_req_type = NULL; |
||
118 | //we need to reset the migration manager in order for it to detect DMSs properly |
||
119 | EE_Data_Migration_Manager::reset(); |
||
120 | //make sure none of the old hooks are left hanging around |
||
121 | remove_all_actions( 'AHEE__EE_System__perform_activations_upgrades_and_migrations'); |
||
122 | self::instance()->detect_activations_or_upgrades(); |
||
123 | self::instance()->perform_activations_upgrades_and_migrations(); |
||
124 | return self::instance(); |
||
125 | } |
||
126 | |||
127 | |||
128 | |||
129 | /** |
||
130 | * sets hooks for running rest of system |
||
131 | * provides "AHEE__EE_System__construct__complete" hook for EE Addons to use as their starting point |
||
132 | * starting EE Addons from any other point may lead to problems |
||
133 | * |
||
134 | * @access private |
||
135 | */ |
||
136 | private function __construct() { |
||
158 | |||
159 | |||
160 | |||
161 | /** |
||
162 | * load_espresso_addons |
||
163 | * |
||
164 | * allow addons to load first so that they can set hooks for running DMS's, etc |
||
165 | * this is hooked into both: |
||
166 | * 'AHEE__EE_Bootstrap__load_core_configuration' |
||
167 | * which runs during the WP 'plugins_loaded' action at priority 5 |
||
168 | * and the WP 'activate_plugin' hookpoint |
||
169 | * |
||
170 | * @access public |
||
171 | * @return void |
||
172 | */ |
||
173 | public function load_espresso_addons() { |
||
174 | // set autoloaders for all of the classes implementing EEI_Plugin_API |
||
175 | // which provide helpers for EE plugin authors to more easily register certain components with EE. |
||
176 | EEH_Autoloader::instance()->register_autoloaders_for_each_file_in_folder( EE_LIBRARIES . 'plugin_api' ); |
||
177 | //load and setup EE_Capabilities |
||
178 | EE_Registry::instance()->load_core( 'Capabilities' ); |
||
179 | //caps need to be initialized on every request so that capability maps are set. |
||
180 | //@see https://events.codebasehq.com/projects/event-espresso/tickets/8674 |
||
181 | EE_Registry::instance()->CAP->init_caps(); |
||
182 | do_action( 'AHEE__EE_System__load_espresso_addons' ); |
||
183 | //if the WP API basic auth plugin isn't already loaded, load it now. |
||
184 | //We want it for mobile apps. Just include the entire plugin |
||
185 | //also, don't load the basic auth when a plugin is getting activated, because |
||
186 | //it could be the basic auth plugin, and it doesn't check if its methods are already defined |
||
187 | //and causes a fatal error |
||
188 | if( !function_exists( 'json_basic_auth_handler' ) |
||
189 | && ! function_exists( 'json_basic_auth_error' ) |
||
190 | && ! ( |
||
191 | isset( $_GET[ 'action'] ) |
||
192 | && in_array( $_GET[ 'action' ], array( 'activate', 'activate-selected' ) ) |
||
193 | ) |
||
194 | && ! ( |
||
195 | isset( $_GET['activate' ] ) |
||
196 | && $_GET['activate' ] === 'true' |
||
197 | ) |
||
198 | ) { |
||
199 | include_once EE_THIRD_PARTY . 'wp-api-basic-auth' . DS . 'basic-auth.php'; |
||
200 | } |
||
201 | } |
||
202 | |||
203 | |||
204 | /** |
||
205 | * detect_activations_or_upgrades |
||
206 | * |
||
207 | * Checks for activation or upgrade of core first; |
||
208 | * then also checks if any registered addons have been activated or upgraded |
||
209 | * This is hooked into 'AHEE__EE_Bootstrap__detect_activations_or_upgrades' |
||
210 | * which runs during the WP 'plugins_loaded' action at priority 3 |
||
211 | * |
||
212 | * @access public |
||
213 | * @return void |
||
214 | */ |
||
215 | public function detect_activations_or_upgrades(){ |
||
223 | |||
224 | |||
225 | |||
226 | /** |
||
227 | * detect_if_activation_or_upgrade |
||
228 | * |
||
229 | * Takes care of detecting whether this is a brand new install or code upgrade, |
||
230 | * and either setting up the DB or setting up maintenance mode etc. |
||
231 | * |
||
232 | * @access public |
||
233 | * @return void |
||
234 | */ |
||
235 | public function detect_if_activation_or_upgrade() { |
||
278 | |||
279 | /** |
||
280 | * Updates the list of installed versions and sets hooks for |
||
281 | * initializing the database later during the request |
||
282 | * @param array $espresso_db_update |
||
283 | */ |
||
284 | protected function _handle_core_version_change( $espresso_db_update ){ |
||
289 | |||
290 | |||
291 | |||
292 | |||
293 | /** |
||
294 | * standardizes the wp option 'espresso_db_upgrade' which actually stores |
||
295 | * information about what versions of EE have been installed and activated, |
||
296 | * NOT necessarily the state of the database |
||
297 | * |
||
298 | * @param null $espresso_db_update |
||
299 | * @internal param array $espresso_db_update_value the value of the WordPress option. If not supplied, fetches it from the options table |
||
300 | * @return array the correct value of 'espresso_db_upgrade', after saving it, if it needed correction |
||
301 | */ |
||
302 | private function fix_espresso_db_upgrade_option($espresso_db_update = null){ |
||
342 | |||
343 | |||
344 | |||
345 | |||
346 | /** |
||
347 | * Does the traditional work of setting up the plugin's database and adding default data. |
||
348 | * If migration script/process did not exist, this is what would happen on every activation/reactivation/upgrade. |
||
349 | * NOTE: if we're in maintenance mode (which would be the case if we detect there are data |
||
350 | * migration scripts that need to be run and a version change happens), enqueues core for database initialization, |
||
351 | * so that it will be done when migrations are finished |
||
352 | * @param boolean $initialize_addons_too if true, we double-check addons' database tables etc too; |
||
353 | * however, |
||
354 | * @param boolean $verify_db_schema if true will re-check the database tables have the correct schema. This is a resource-intensive job |
||
|
|||
355 | * so we prefer to only do it when necessary |
||
356 | * @return void |
||
357 | */ |
||
358 | public function initialize_db_if_no_migrations_required( $initialize_addons_too = FALSE, $verify_schema = true ){ |
||
359 | $request_type = $this->detect_req_type(); |
||
360 | //only initialize system if we're not in maintenance mode. |
||
361 | if( EE_Maintenance_Mode::instance()->level() != EE_Maintenance_Mode::level_2_complete_maintenance ){ |
||
362 | update_option( 'ee_flush_rewrite_rules', TRUE ); |
||
363 | |||
364 | if( $verify_schema ) { |
||
365 | EEH_Activation::initialize_db_and_folders(); |
||
366 | } |
||
367 | EEH_Activation::initialize_db_content(); |
||
368 | EEH_Activation::system_initialization(); |
||
369 | if( $initialize_addons_too ) { |
||
370 | $this->initialize_addons(); |
||
371 | } |
||
372 | }else{ |
||
373 | EE_Data_Migration_Manager::instance()->enqueue_db_initialization_for( 'Core' ); |
||
374 | } |
||
375 | if ( $request_type == EE_System::req_type_new_activation || $request_type == EE_System::req_type_reactivation || $request_type == EE_System::req_type_upgrade ) { |
||
376 | add_action( 'AHEE__EE_System__load_CPTs_and_session__start', array( $this, 'redirect_to_about_ee' ), 9 ); |
||
377 | } |
||
378 | } |
||
379 | |||
380 | /** |
||
381 | * Initializes the db for all registered addons |
||
382 | */ |
||
383 | public function initialize_addons(){ |
||
389 | |||
390 | |||
391 | /** |
||
392 | * Adds the current code version to the saved wp option which stores a list of all ee versions ever installed. |
||
393 | * @param array $version_history |
||
394 | * @param string $current_version_to_add version to be added to the version history |
||
395 | * @return boolean success as to whether or not this option was changed |
||
396 | */ |
||
397 | public function update_list_of_installed_versions($version_history = NULL,$current_version_to_add = NULL) { |
||
408 | |||
409 | |||
410 | |||
411 | |||
412 | /** |
||
413 | * Detects if the current version indicated in the has existed in the list of |
||
414 | * previously-installed versions of EE (espresso_db_update). Does NOT modify it (ie, no side-effect) |
||
415 | * |
||
416 | * @param array $espresso_db_update array from the wp option stored under the name 'espresso_db_update'. |
||
417 | * If not supplied, fetches it from the options table. |
||
418 | * Also, caches its result so later parts of the code can also know whether there's been an |
||
419 | * update or not. This way we can add the current version to espresso_db_update, |
||
420 | * but still know if this is a new install or not |
||
421 | * @return int one of the constants on EE_System::req_type_ |
||
422 | */ |
||
423 | public function detect_req_type( $espresso_db_update = NULL ){ |
||
430 | |||
431 | |||
432 | |||
433 | /** |
||
434 | * 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 |
||
435 | * was just activated to (for core that will always be espresso_version()) |
||
436 | * @param array $activation_history_for_addon the option's value which stores the activation history for this ee plugin. |
||
437 | * for core that's 'espresso_db_update' |
||
438 | * @param string $activation_indicator_option_name the name of the wordpress option that is temporarily set to indicate that this plugin was just activated |
||
439 | * @param string $version_to_upgrade_to the version that was just upgraded to (for core that will be espresso_version()) |
||
440 | * @return int one of the constants on EE_System::req_type_* |
||
441 | */ |
||
442 | public static function detect_req_type_given_activation_history( $activation_history_for_addon, $activation_indicator_option_name, $version_to_upgrade_to ){ |
||
486 | |||
487 | |||
488 | |||
489 | /** |
||
490 | * Detects if the $version_to_upgrade_to is higher than the most recent version in |
||
491 | * the $activation_history_for_addon |
||
492 | * @param array $activation_history_for_addon (keys are versions, values are arrays of times activated, |
||
493 | * sometimes containing 'unknown-date' |
||
494 | * @param string $version_to_upgrade_to (current version) |
||
495 | * @return int results of version_compare( $version_to_upgrade_to, $most_recently_active_version ). |
||
496 | * ie, -1 if $version_to_upgrade_to is LOWER (downgrade); |
||
497 | * 0 if $version_to_upgrade_to MATCHES (reactivation or normal request); |
||
498 | * 1 if $version_to_upgrade_to is HIGHER (upgrade) ; |
||
499 | */ |
||
500 | protected static function _new_version_is_higher( $activation_history_for_addon, $version_to_upgrade_to ){ |
||
525 | |||
526 | |||
527 | |||
528 | /** |
||
529 | * This redirects to the about EE page after activation |
||
530 | * @return void |
||
531 | */ |
||
532 | public function redirect_to_about_ee() { |
||
550 | |||
551 | |||
552 | /** |
||
553 | * load_core_configuration |
||
554 | * |
||
555 | * this is hooked into 'AHEE__EE_Bootstrap__load_core_configuration' |
||
556 | * which runs during the WP 'plugins_loaded' action at priority 5 |
||
557 | * |
||
558 | * @return void |
||
559 | */ |
||
560 | public function load_core_configuration(){ |
||
586 | |||
587 | |||
588 | /** |
||
589 | * cycles through all of the models/*.model.php files, and assembles an array of model names |
||
590 | * |
||
591 | * @return void |
||
592 | */ |
||
593 | private function _parse_model_names(){ |
||
611 | |||
612 | |||
613 | |||
614 | /** |
||
615 | * 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. |
||
616 | * @return void |
||
617 | */ |
||
618 | private function _maybe_brew_regular() { |
||
623 | |||
624 | |||
625 | |||
626 | /** |
||
627 | * register_shortcodes_modules_and_widgets |
||
628 | * |
||
629 | * generate lists of shortcodes and modules, then verify paths and classes |
||
630 | * This is hooked into 'AHEE__EE_Bootstrap__register_shortcodes_modules_and_widgets' |
||
631 | * which runs during the WP 'plugins_loaded' action at priority 7 |
||
632 | * |
||
633 | * @access public |
||
634 | * @return void |
||
635 | */ |
||
636 | public function register_shortcodes_modules_and_widgets() { |
||
643 | |||
644 | |||
645 | /** |
||
646 | * _incompatible_addon_error |
||
647 | * |
||
648 | * @access public |
||
649 | * @return void |
||
650 | */ |
||
651 | private function _incompatible_addon_error() { |
||
669 | |||
670 | |||
671 | |||
672 | |||
673 | /** |
||
674 | * brew_espresso |
||
675 | * |
||
676 | * begins the process of setting hooks for initializing EE in the correct order |
||
677 | * This is happening on the 'AHEE__EE_Bootstrap__brew_espresso' hookpoint |
||
678 | * which runs during the WP 'plugins_loaded' action at priority 9 |
||
679 | * |
||
680 | * @return void |
||
681 | */ |
||
682 | public function brew_espresso(){ |
||
702 | |||
703 | |||
704 | |||
705 | |||
706 | /** |
||
707 | * set_hooks_for_core |
||
708 | * |
||
709 | * @access public |
||
710 | * @return void |
||
711 | */ |
||
712 | public function set_hooks_for_core() { |
||
716 | |||
717 | |||
718 | |||
719 | /** |
||
720 | * Using the information gathered in EE_System::_incompatible_addon_error, |
||
721 | * deactivates any addons considered incompatible with the current version of EE |
||
722 | */ |
||
723 | private function _deactivate_incompatible_addons(){ |
||
737 | |||
738 | |||
739 | |||
740 | /** |
||
741 | * perform_activations_upgrades_and_migrations |
||
742 | * |
||
743 | * @access public |
||
744 | * @return void |
||
745 | */ |
||
746 | public function perform_activations_upgrades_and_migrations() { |
||
753 | |||
754 | |||
755 | |||
756 | /** |
||
757 | * load_CPTs_and_session |
||
758 | * |
||
759 | * @access public |
||
760 | * @return void |
||
761 | */ |
||
762 | public function load_CPTs_and_session() { |
||
768 | |||
769 | |||
770 | |||
771 | /** |
||
772 | * load_controllers |
||
773 | * |
||
774 | * this is the best place to load any additional controllers that needs access to EE core. |
||
775 | * it is expected that all basic core EE systems, that are not dependant on the current request are loaded at this time |
||
776 | * |
||
777 | * @access public |
||
778 | * @return void |
||
779 | */ |
||
780 | public function load_controllers() { |
||
781 | do_action( 'AHEE__EE_System__load_controllers__start' ); |
||
782 | // let's get it started |
||
783 | if ( ! is_admin() && ! EE_Maintenance_Mode::instance()->level() ) { |
||
784 | do_action( 'AHEE__EE_System__load_controllers__load_front_controllers' ); |
||
785 | EE_Registry::instance()->load_core( 'Front_Controller' ); |
||
786 | } else if ( ! EE_FRONT_AJAX ) { |
||
787 | do_action( 'AHEE__EE_System__load_controllers__load_admin_controllers' ); |
||
788 | EE_Registry::instance()->load_core( 'Admin' ); |
||
789 | } else if ( EE_Maintenance_Mode::instance()->level() ) { |
||
790 | // still need to make sure template helper functions are loaded in M-Mode |
||
791 | EE_Registry::instance()->load_helper( 'Template' ); |
||
792 | } |
||
793 | do_action( 'AHEE__EE_System__load_controllers__complete' ); |
||
794 | } |
||
795 | |||
796 | |||
797 | |||
798 | /** |
||
799 | * core_loaded_and_ready |
||
800 | * |
||
801 | * all of the basic EE core should be loaded at this point and available regardless of M-Mode |
||
802 | * |
||
803 | * @access public |
||
804 | * @return void |
||
805 | */ |
||
806 | public function core_loaded_and_ready() { |
||
812 | |||
813 | |||
814 | |||
815 | /** |
||
816 | * initialize |
||
817 | * |
||
818 | * this is the best place to begin initializing client code |
||
819 | * |
||
820 | * @access public |
||
821 | * @return void |
||
822 | */ |
||
823 | public function initialize() { |
||
824 | do_action( 'AHEE__EE_System__initialize' ); |
||
825 | } |
||
826 | |||
827 | |||
828 | |||
829 | /** |
||
830 | * initialize_last |
||
831 | * |
||
832 | * this is run really late during the WP init hookpoint, and ensures that mostly everything else that needs to initialize has done so |
||
833 | * |
||
834 | * @access public |
||
835 | * @return void |
||
836 | */ |
||
837 | public function initialize_last() { |
||
840 | |||
841 | |||
842 | |||
843 | |||
844 | /** |
||
845 | * set_hooks_for_shortcodes_modules_and_addons |
||
846 | * |
||
847 | * this is the best place for other systems to set callbacks for hooking into other parts of EE |
||
848 | * this happens at the very beginning of the wp_loaded hookpoint |
||
849 | * |
||
850 | * @access public |
||
851 | * @return void |
||
852 | */ |
||
853 | public function set_hooks_for_shortcodes_modules_and_addons() { |
||
856 | |||
857 | |||
858 | |||
859 | |||
860 | /** |
||
861 | * do_not_cache |
||
862 | * |
||
863 | * sets no cache headers and defines no cache constants for WP plugins |
||
864 | * |
||
865 | * @access public |
||
866 | * @return void |
||
867 | */ |
||
868 | public static function do_not_cache() { |
||
869 | // set no cache constants |
||
870 | if ( ! defined( 'DONOTCACHEPAGE' ) ) { |
||
871 | define( 'DONOTCACHEPAGE', true ); |
||
872 | } |
||
873 | if ( ! defined( 'DONOTCACHCEOBJECT' ) ) { |
||
874 | define( 'DONOTCACHCEOBJECT', true ); |
||
875 | } |
||
876 | if ( ! defined( 'DONOTCACHEDB' ) ) { |
||
877 | define( 'DONOTCACHEDB', true ); |
||
878 | } |
||
879 | // add no cache headers |
||
880 | add_action( 'send_headers' , array( 'EE_System', 'nocache_headers' ), 10 ); |
||
881 | // plus a little extra for nginx and Google Chrome |
||
882 | add_filter( 'nocache_headers', array( 'EE_System', 'extra_nocache_headers' ), 10, 1 ); |
||
883 | // prevent browsers from prefetching of the rel='next' link, because it may contain content that interferes with the registration process |
||
884 | remove_action( 'wp_head', 'adjacent_posts_rel_link_wp_head' ); |
||
885 | } |
||
886 | |||
887 | |||
888 | |||
889 | /** |
||
890 | * extra_nocache_headers |
||
891 | * |
||
892 | * @access public |
||
893 | * @param $headers |
||
894 | * @return array |
||
895 | */ |
||
896 | public static function extra_nocache_headers ( $headers ) { |
||
897 | // for NGINX |
||
898 | $headers['X-Accel-Expires'] = 0; |
||
899 | // plus extra for Google Chrome since it doesn't seem to respect "no-cache", but WILL respect "no-store" |
||
900 | $headers['Cache-Control'] = 'no-store, no-cache, must-revalidate, max-age=0'; |
||
901 | return $headers; |
||
902 | } |
||
903 | |||
904 | |||
905 | |||
906 | /** |
||
907 | * nocache_headers |
||
908 | * |
||
909 | * @access public |
||
910 | * @return void |
||
911 | */ |
||
912 | public static function nocache_headers() { |
||
915 | |||
916 | |||
917 | |||
918 | /** |
||
919 | * espresso_toolbar_items |
||
920 | * |
||
921 | * @access public |
||
922 | * @param $admin_bar |
||
923 | * @return void |
||
924 | */ |
||
925 | public function espresso_toolbar_items( $admin_bar ) { |
||
926 | |||
927 | // if in full M-Mode, or its an AJAX request, or user is NOT an admin |
||
928 | if ( EE_Maintenance_Mode::instance()->level() == EE_Maintenance_Mode::level_2_complete_maintenance || defined( 'DOING_AJAX' ) || ! EE_Registry::instance()->CAP->current_user_can( 'ee_read_ee', 'ee_admin_bar_menu_top_level' )) { |
||
929 | return; |
||
930 | } |
||
931 | |||
932 | do_action( 'AHEE_log', __FILE__, __FUNCTION__, '' ); |
||
933 | EE_Registry::instance()->load_helper( 'URL' ); |
||
934 | $menu_class = 'espresso_menu_item_class'; |
||
935 | //we don't use the constants EVENTS_ADMIN_URL or REG_ADMIN_URL |
||
936 | //because they're only defined in each of their respective constructors |
||
937 | //and this might be a frontend request, in which case they aren't available |
||
938 | $events_admin_url = admin_url("admin.php?page=espresso_events"); |
||
939 | $reg_admin_url = admin_url("admin.php?page=espresso_registrations"); |
||
940 | $extensions_admin_url = admin_url("admin.php?page=espresso_packages"); |
||
941 | |||
942 | //Top Level |
||
943 | $admin_bar->add_menu(array( |
||
944 | 'id' => 'espresso-toolbar', |
||
945 | '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>', |
||
946 | 'href' => $events_admin_url, |
||
947 | 'meta' => array( |
||
948 | 'title' => __('Event Espresso', 'event_espresso'), |
||
949 | 'class' => $menu_class . 'first' |
||
950 | ), |
||
951 | )); |
||
952 | |||
953 | //Events |
||
954 | View Code Duplication | if ( EE_Registry::instance()->CAP->current_user_can( 'ee_read_events', 'ee_admin_bar_menu_espresso-toolbar-events' ) ) { |
|
955 | $admin_bar->add_menu(array( |
||
956 | 'id' => 'espresso-toolbar-events', |
||
957 | 'parent' => 'espresso-toolbar', |
||
958 | 'title' => __( 'Events', 'event_espresso' ), |
||
959 | 'href' => $events_admin_url, |
||
960 | 'meta' => array( |
||
961 | 'title' => __('Events', 'event_espresso'), |
||
962 | 'target' => '', |
||
963 | 'class' => $menu_class |
||
964 | ), |
||
965 | )); |
||
966 | } |
||
967 | |||
968 | |||
969 | View Code Duplication | if ( EE_Registry::instance()->CAP->current_user_can( 'ee_edit_events', 'ee_admin_bar_menu_espresso-toolbar-events-new' ) ) { |
|
970 | //Events Add New |
||
971 | $admin_bar->add_menu(array( |
||
972 | 'id' => 'espresso-toolbar-events-new', |
||
973 | 'parent' => 'espresso-toolbar-events', |
||
974 | 'title' => __('Add New', 'event_espresso'), |
||
975 | 'href' => EEH_URL::add_query_args_and_nonce( array( 'action'=>'create_new' ), $events_admin_url ), |
||
976 | 'meta' => array( |
||
977 | 'title' => __('Add New', 'event_espresso'), |
||
978 | 'target' => '', |
||
979 | 'class' => $menu_class |
||
980 | ), |
||
981 | )); |
||
982 | } |
||
983 | |||
984 | if ( is_single() && ( get_post_type() == 'espresso_events' ) ) { |
||
985 | |||
986 | //Current post |
||
987 | global $post; |
||
988 | |||
989 | if ( EE_Registry::instance()->CAP->current_user_can( 'ee_edit_event', 'ee_admin_bar_menu_espresso-toolbar-events-edit', $post->ID ) ) { |
||
990 | //Events Edit Current Event |
||
991 | $admin_bar->add_menu(array( |
||
992 | 'id' => 'espresso-toolbar-events-edit', |
||
993 | 'parent' => 'espresso-toolbar-events', |
||
994 | 'title' => __('Edit Event', 'event_espresso'), |
||
995 | 'href' => EEH_URL::add_query_args_and_nonce( array( 'action'=>'edit', 'post'=>$post->ID ), $events_admin_url ), |
||
996 | 'meta' => array( |
||
997 | 'title' => __('Edit Event', 'event_espresso'), |
||
998 | 'target' => '', |
||
999 | 'class' => $menu_class |
||
1000 | ), |
||
1001 | )); |
||
1002 | } |
||
1003 | |||
1004 | } |
||
1005 | |||
1006 | //Events View |
||
1007 | View Code Duplication | if ( EE_Registry::instance()->CAP->current_user_can( 'ee_read_events', 'ee_admin_bar_menu_espresso-toolbar-events-view' ) ) { |
|
1008 | $admin_bar->add_menu(array( |
||
1009 | 'id' => 'espresso-toolbar-events-view', |
||
1010 | 'parent' => 'espresso-toolbar-events', |
||
1011 | 'title' => __( 'View', 'event_espresso' ), |
||
1012 | 'href' => $events_admin_url, |
||
1013 | 'meta' => array( |
||
1014 | 'title' => __('View', 'event_espresso'), |
||
1015 | 'target' => '', |
||
1016 | 'class' => $menu_class |
||
1017 | ), |
||
1018 | )); |
||
1019 | } |
||
1020 | |||
1021 | View Code Duplication | if ( EE_Registry::instance()->CAP->current_user_can( 'ee_read_events', 'ee_admin_bar_menu_espresso-toolbar-events-all' ) ) { |
|
1022 | //Events View All |
||
1023 | $admin_bar->add_menu(array( |
||
1024 | 'id' => 'espresso-toolbar-events-all', |
||
1025 | 'parent' => 'espresso-toolbar-events-view', |
||
1026 | 'title' => __( 'All', 'event_espresso' ), |
||
1027 | 'href' => $events_admin_url, |
||
1028 | 'meta' => array( |
||
1029 | 'title' => __('All', 'event_espresso'), |
||
1030 | 'target' => '', |
||
1031 | 'class' => $menu_class |
||
1032 | ), |
||
1033 | )); |
||
1034 | } |
||
1035 | |||
1036 | |||
1037 | View Code Duplication | if ( EE_Registry::instance()->CAP->current_user_can( 'ee_read_events', 'ee_admin_bar_menu_espresso-toolbar-events-today' ) ) { |
|
1038 | //Events View Today |
||
1039 | $admin_bar->add_menu(array( |
||
1040 | 'id' => 'espresso-toolbar-events-today', |
||
1041 | 'parent' => 'espresso-toolbar-events-view', |
||
1042 | 'title' => __('Today', 'event_espresso'), |
||
1043 | 'href' => EEH_URL::add_query_args_and_nonce( array( 'action'=>'default', 'status'=>'today' ), $events_admin_url ), |
||
1044 | 'meta' => array( |
||
1045 | 'title' => __('Today', 'event_espresso'), |
||
1046 | 'target' => '', |
||
1047 | 'class' => $menu_class |
||
1048 | ), |
||
1049 | )); |
||
1050 | } |
||
1051 | |||
1052 | |||
1053 | View Code Duplication | if ( EE_Registry::instance()->CAP->current_user_can( 'ee_read_events', 'ee_admin_bar_menu_espresso-toolbar-events-month' ) ) { |
|
1054 | //Events View This Month |
||
1055 | $admin_bar->add_menu(array( |
||
1056 | 'id' => 'espresso-toolbar-events-month', |
||
1057 | 'parent' => 'espresso-toolbar-events-view', |
||
1058 | 'title' => __( 'This Month', 'event_espresso'), |
||
1059 | 'href' => EEH_URL::add_query_args_and_nonce( array( 'action'=>'default', 'status'=>'month' ), $events_admin_url ), |
||
1060 | 'meta' => array( |
||
1061 | 'title' => __('This Month', 'event_espresso'), |
||
1062 | 'target' => '', |
||
1063 | 'class' => $menu_class |
||
1064 | ), |
||
1065 | )); |
||
1066 | } |
||
1067 | |||
1068 | //Registration Overview |
||
1069 | View Code Duplication | if ( EE_Registry::instance()->CAP->current_user_can( 'ee_read_registrations', 'ee_admin_bar_menu_espresso-toolbar-registrations' ) ) { |
|
1070 | $admin_bar->add_menu(array( |
||
1071 | 'id' => 'espresso-toolbar-registrations', |
||
1072 | 'parent' => 'espresso-toolbar', |
||
1073 | 'title' => __( 'Registrations', 'event_espresso' ), |
||
1074 | 'href' => $reg_admin_url, |
||
1075 | 'meta' => array( |
||
1076 | 'title' => __('Registrations', 'event_espresso'), |
||
1077 | 'target' => '', |
||
1078 | 'class' => $menu_class |
||
1079 | ), |
||
1080 | )); |
||
1081 | } |
||
1082 | |||
1083 | //Registration Overview Today |
||
1084 | View Code Duplication | if ( EE_Registry::instance()->CAP->current_user_can( 'ee_read_registrations', 'ee_admin_bar_menu_espresso-toolbar-registrations-today' ) ) { |
|
1085 | $admin_bar->add_menu(array( |
||
1086 | 'id' => 'espresso-toolbar-registrations-today', |
||
1087 | 'parent' => 'espresso-toolbar-registrations', |
||
1088 | 'title' => __( 'Today', 'event_espresso'), |
||
1089 | 'href' => EEH_URL::add_query_args_and_nonce( array( 'action'=>'default', 'status'=>'today' ), $reg_admin_url ), |
||
1090 | 'meta' => array( |
||
1091 | 'title' => __('Today', 'event_espresso'), |
||
1092 | 'target' => '', |
||
1093 | 'class' => $menu_class |
||
1094 | ), |
||
1095 | )); |
||
1096 | } |
||
1097 | |||
1098 | //Registration Overview Today Completed |
||
1099 | View Code Duplication | if ( EE_Registry::instance()->CAP->current_user_can( 'ee_read_registrations', 'ee_admin_bar_menu_espresso-toolbar-registrations-today-approved' ) ) { |
|
1100 | $admin_bar->add_menu(array( |
||
1101 | 'id' => 'espresso-toolbar-registrations-today-approved', |
||
1102 | 'parent' => 'espresso-toolbar-registrations-today', |
||
1103 | 'title' => __( 'Approved', 'event_espresso' ), |
||
1104 | 'href' => EEH_URL::add_query_args_and_nonce( array( 'action'=>'default', 'status'=>'today', '_reg_status'=>EEM_Registration::status_id_approved ), $reg_admin_url ), |
||
1105 | 'meta' => array( |
||
1106 | 'title' => __('Approved', 'event_espresso' ), |
||
1107 | 'target' => '', |
||
1108 | 'class' => $menu_class |
||
1109 | ), |
||
1110 | )); |
||
1111 | } |
||
1112 | |||
1113 | //Registration Overview Today Pending\ |
||
1114 | View Code Duplication | if ( EE_Registry::instance()->CAP->current_user_can( 'ee_read_registrations', 'ee_admin_bar_menu_espresso-toolbar-registrations-today-pending' ) ) { |
|
1115 | $admin_bar->add_menu(array( |
||
1116 | 'id' => 'espresso-toolbar-registrations-today-pending', |
||
1117 | 'parent' => 'espresso-toolbar-registrations-today', |
||
1118 | 'title' => __( 'Pending', 'event_espresso' ), |
||
1119 | 'href' => EEH_URL::add_query_args_and_nonce( array( 'action'=>'default', 'status'=>'today', 'reg_status'=>EEM_Registration::status_id_pending_payment ), $reg_admin_url ), |
||
1120 | 'meta' => array( |
||
1121 | 'title' => __('Pending Payment', 'event_espresso' ), |
||
1122 | 'target' => '', |
||
1123 | 'class' => $menu_class |
||
1124 | ), |
||
1125 | )); |
||
1126 | } |
||
1127 | |||
1128 | //Registration Overview Today Incomplete |
||
1129 | View Code Duplication | if ( EE_Registry::instance()->CAP->current_user_can( 'ee_read_registrations', 'ee_admin_bar_menu_espresso-toolbar-registrations-today-not-approved' ) ) { |
|
1130 | $admin_bar->add_menu(array( |
||
1131 | 'id' => 'espresso-toolbar-registrations-today-not-approved', |
||
1132 | 'parent' => 'espresso-toolbar-registrations-today', |
||
1133 | 'title' => __( 'Not Approved', 'event_espresso' ), |
||
1134 | 'href' => EEH_URL::add_query_args_and_nonce( array( 'action'=>'default', 'status'=>'today', '_reg_status'=>EEM_Registration::status_id_not_approved ), $reg_admin_url ), |
||
1135 | 'meta' => array( |
||
1136 | 'title' => __('Not Approved', 'event_espresso' ), |
||
1137 | 'target' => '', |
||
1138 | 'class' => $menu_class |
||
1139 | ), |
||
1140 | )); |
||
1141 | } |
||
1142 | |||
1143 | //Registration Overview Today Incomplete |
||
1144 | View Code Duplication | if ( EE_Registry::instance()->CAP->current_user_can( 'ee_read_registrations', 'ee_admin_bar_menu_espresso-toolbar-registrations-today-cancelled' ) ) { |
|
1145 | $admin_bar->add_menu(array( |
||
1146 | 'id' => 'espresso-toolbar-registrations-today-cancelled', |
||
1147 | 'parent' => 'espresso-toolbar-registrations-today', |
||
1148 | 'title' => __( 'Cancelled', 'event_espresso'), |
||
1149 | 'href' => EEH_URL::add_query_args_and_nonce( array( 'action'=>'default', 'status'=>'today', '_reg_status'=>EEM_Registration::status_id_cancelled ), $reg_admin_url ), |
||
1150 | 'meta' => array( |
||
1151 | 'title' => __('Cancelled', 'event_espresso'), |
||
1152 | 'target' => '', |
||
1153 | 'class' => $menu_class |
||
1154 | ), |
||
1155 | )); |
||
1156 | } |
||
1157 | |||
1158 | //Registration Overview This Month |
||
1159 | View Code Duplication | if ( EE_Registry::instance()->CAP->current_user_can( 'ee_read_registrations', 'ee_admin_bar_menu_espresso-toolbar-registrations-month' ) ) { |
|
1160 | $admin_bar->add_menu(array( |
||
1161 | 'id' => 'espresso-toolbar-registrations-month', |
||
1162 | 'parent' => 'espresso-toolbar-registrations', |
||
1163 | 'title' => __( 'This Month', 'event_espresso' ), |
||
1164 | 'href' => EEH_URL::add_query_args_and_nonce( array( 'action'=>'default', 'status'=>'month' ), $reg_admin_url ), |
||
1165 | 'meta' => array( |
||
1166 | 'title' => __('This Month', 'event_espresso'), |
||
1167 | 'target' => '', |
||
1168 | 'class' => $menu_class |
||
1169 | ), |
||
1170 | )); |
||
1171 | } |
||
1172 | |||
1173 | //Registration Overview This Month Approved |
||
1174 | View Code Duplication | if ( EE_Registry::instance()->CAP->current_user_can( 'ee_read_registrations', 'ee_admin_bar_menu_espresso-toolbar-registrations-month-approved' ) ) { |
|
1175 | $admin_bar->add_menu(array( |
||
1176 | 'id' => 'espresso-toolbar-registrations-month-approved', |
||
1177 | 'parent' => 'espresso-toolbar-registrations-month', |
||
1178 | 'title' => __( 'Approved', 'event_espresso' ), |
||
1179 | 'href' => EEH_URL::add_query_args_and_nonce( array( 'action'=>'default', 'status'=>'month', '_reg_status'=>EEM_Registration::status_id_approved ), $reg_admin_url ), |
||
1180 | 'meta' => array( |
||
1181 | 'title' => __('Approved', 'event_espresso'), |
||
1182 | 'target' => '', |
||
1183 | 'class' => $menu_class |
||
1184 | ), |
||
1185 | )); |
||
1186 | } |
||
1187 | |||
1188 | //Registration Overview This Month Pending |
||
1189 | View Code Duplication | if ( EE_Registry::instance()->CAP->current_user_can( 'ee_read_registrations', 'ee_admin_bar_menu_espresso-toolbar-registrations-month-pending' ) ) { |
|
1190 | $admin_bar->add_menu(array( |
||
1191 | 'id' => 'espresso-toolbar-registrations-month-pending', |
||
1192 | 'parent' => 'espresso-toolbar-registrations-month', |
||
1193 | 'title' => __( 'Pending', 'event_espresso'), |
||
1194 | 'href' => EEH_URL::add_query_args_and_nonce( array( 'action'=>'default', 'status'=>'month', '_reg_status'=>EEM_Registration::status_id_pending_payment ), $reg_admin_url ), |
||
1195 | 'meta' => array( |
||
1196 | 'title' => __('Pending', 'event_espresso'), |
||
1197 | 'target' => '', |
||
1198 | 'class' => $menu_class |
||
1199 | ), |
||
1200 | )); |
||
1201 | } |
||
1202 | |||
1203 | //Registration Overview This Month Not Approved |
||
1204 | View Code Duplication | if ( EE_Registry::instance()->CAP->current_user_can( 'ee_read_registrations', 'ee_admin_bar_menu_espresso-toolbar-registrations-month-not-approved' ) ) { |
|
1205 | $admin_bar->add_menu(array( |
||
1206 | 'id' => 'espresso-toolbar-registrations-month-not-approved', |
||
1207 | 'parent' => 'espresso-toolbar-registrations-month', |
||
1208 | 'title' => __( 'Not Approved', 'event_espresso'), |
||
1209 | 'href' => EEH_URL::add_query_args_and_nonce( array( 'action'=>'default', 'status'=>'month', '_reg_status'=>EEM_Registration::status_id_not_approved ), $reg_admin_url ), |
||
1210 | 'meta' => array( |
||
1211 | 'title' => __('Not Approved', 'event_espresso' ), |
||
1212 | 'target' => '', |
||
1213 | 'class' => $menu_class |
||
1214 | ), |
||
1215 | )); |
||
1216 | } |
||
1217 | |||
1218 | |||
1219 | //Registration Overview This Month Cancelled |
||
1220 | View Code Duplication | if ( EE_Registry::instance()->CAP->current_user_can( 'ee_read_registrations', 'ee_admin_bar_menu_espresso-toolbar-registrations-month-cancelled' ) ) { |
|
1221 | $admin_bar->add_menu(array( |
||
1222 | 'id' => 'espresso-toolbar-registrations-month-cancelled', |
||
1223 | 'parent' => 'espresso-toolbar-registrations-month', |
||
1224 | 'title' => __('Cancelled', 'event_espresso'), |
||
1225 | 'href' => EEH_URL::add_query_args_and_nonce( array( 'action'=>'default', 'status'=>'month', '_reg_status'=>EEM_Registration::status_id_cancelled ), $reg_admin_url ), |
||
1226 | 'meta' => array( |
||
1227 | 'title' => __('Cancelled', 'event_espresso'), |
||
1228 | 'target' => '', |
||
1229 | 'class' => $menu_class |
||
1230 | ), |
||
1231 | )); |
||
1232 | } |
||
1233 | |||
1234 | //Extensions & Services |
||
1235 | View Code Duplication | if ( EE_Registry::instance()->CAP->current_user_can( 'ee_read_ee', 'ee_admin_bar_menu_espresso-toolbar-extensions-and-services' ) ) { |
|
1236 | $admin_bar->add_menu(array( |
||
1237 | 'id' => 'espresso-toolbar-extensions-and-services', |
||
1238 | 'parent' => 'espresso-toolbar', |
||
1239 | 'title' => __( 'Extensions & Services', 'event_espresso' ), |
||
1240 | 'href' => $extensions_admin_url, |
||
1241 | 'meta' => array( |
||
1242 | 'title' => __('Extensions & Services', 'event_espresso'), |
||
1243 | 'target' => '', |
||
1244 | 'class' => $menu_class |
||
1245 | ), |
||
1246 | )); |
||
1247 | } |
||
1248 | } |
||
1249 | |||
1250 | |||
1251 | |||
1252 | |||
1253 | |||
1254 | /** |
||
1255 | * 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. |
||
1256 | * |
||
1257 | * |
||
1258 | * @param array $exclude_array any existing pages being excluded are in this array. |
||
1259 | * @return array |
||
1260 | */ |
||
1261 | public function remove_pages_from_wp_list_pages( $exclude_array ) { |
||
1264 | |||
1265 | |||
1266 | |||
1267 | |||
1268 | |||
1269 | |||
1270 | /*********************************************** WP_ENQUEUE_SCRIPTS HOOK ***********************************************/ |
||
1271 | |||
1272 | |||
1273 | |||
1274 | /** |
||
1275 | * wp_enqueue_scripts |
||
1276 | * |
||
1277 | * @access public |
||
1278 | * @return void |
||
1279 | */ |
||
1280 | public function wp_enqueue_scripts() { |
||
1291 | |||
1292 | |||
1293 | |||
1294 | } |
||
1295 | // End of file EE_System.core.php |
||
1297 |
This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.
Consider the following example. The parameter
$italy
is not defined by the methodfinale(...)
.The most likely cause is that the parameter was removed, but the annotation was not.