@@ -32,110 +32,110 @@ |
||
| 32 | 32 | class CoreLoader implements LoaderDecoratorInterface |
| 33 | 33 | { |
| 34 | 34 | |
| 35 | - /** |
|
| 36 | - * @var EE_Registry|CoffeeShop $generator |
|
| 37 | - */ |
|
| 38 | - private $generator; |
|
| 39 | - |
|
| 40 | - |
|
| 41 | - |
|
| 42 | - /** |
|
| 43 | - * CoreLoader constructor. |
|
| 44 | - * |
|
| 45 | - * @param EE_Registry|CoffeeShop $generator |
|
| 46 | - * @throws InvalidArgumentException |
|
| 47 | - */ |
|
| 48 | - public function __construct($generator) |
|
| 49 | - { |
|
| 50 | - if(!($generator instanceof EE_Registry || $generator instanceof CoffeeShop)) { |
|
| 51 | - throw new InvalidArgumentException( |
|
| 52 | - esc_html__( |
|
| 53 | - 'The CoreLoader class must receive an instance of EE_Registry or the CoffeeShop DI container.', |
|
| 54 | - 'event_espresso' |
|
| 55 | - ) |
|
| 56 | - ); |
|
| 57 | - } |
|
| 58 | - $this->generator = $generator; |
|
| 59 | - } |
|
| 60 | - |
|
| 61 | - |
|
| 62 | - |
|
| 63 | - /** |
|
| 64 | - * Calls the appropriate loading method from the installed generator; |
|
| 65 | - * If EE_Registry is being used, then the additional parameters for the EE_Registry::create() method |
|
| 66 | - * can be added to the $arguments array and they will be extracted and passed to EE_Registry::create(), |
|
| 67 | - * but NOT to the class being instantiated. |
|
| 68 | - * This is done by adding the parameters to the $arguments array as follows: |
|
| 69 | - * array( |
|
| 70 | - * 'EE_Registry::create(from_db)' => true, // boolean value, default = false |
|
| 71 | - * 'EE_Registry::create(load_only)' => true, // boolean value, default = false |
|
| 72 | - * 'EE_Registry::create(addon)' => true, // boolean value, default = false |
|
| 73 | - * ) |
|
| 74 | - * |
|
| 75 | - * @param string $fqcn |
|
| 76 | - * @param array $arguments |
|
| 77 | - * @param bool $shared |
|
| 78 | - * @return mixed |
|
| 79 | - * @throws OutOfBoundsException |
|
| 80 | - * @throws ServiceExistsException |
|
| 81 | - * @throws InstantiationException |
|
| 82 | - * @throws InvalidIdentifierException |
|
| 83 | - * @throws InvalidDataTypeException |
|
| 84 | - * @throws InvalidClassException |
|
| 85 | - * @throws EE_Error |
|
| 86 | - * @throws ServiceNotFoundException |
|
| 87 | - * @throws ReflectionException |
|
| 88 | - */ |
|
| 89 | - public function load($fqcn, $arguments = array(), $shared = true) |
|
| 90 | - { |
|
| 91 | - if($this->generator instanceof EE_Registry) { |
|
| 92 | - // check if additional EE_Registry::create() arguments have been passed |
|
| 93 | - // from_db |
|
| 94 | - $from_db = isset($arguments['EE_Registry::create(from_db)']) |
|
| 95 | - ? $arguments['EE_Registry::create(from_db)'] |
|
| 96 | - : null; |
|
| 97 | - unset($arguments['EE_Registry::create(from_db)']); |
|
| 98 | - // load_only |
|
| 99 | - $load_only = isset($arguments['EE_Registry::create(load_only)']) |
|
| 100 | - ? $arguments['EE_Registry::create(load_only)'] |
|
| 101 | - : null; |
|
| 102 | - unset($arguments['EE_Registry::create(load_only)']); |
|
| 103 | - // addon |
|
| 104 | - $addon = isset($arguments['EE_Registry::create(addon)']) |
|
| 105 | - ? $arguments['EE_Registry::create(addon)'] |
|
| 106 | - : null; |
|
| 107 | - unset($arguments['EE_Registry::create(addon)']); |
|
| 108 | - return $this->generator->create( |
|
| 109 | - $fqcn, |
|
| 110 | - $arguments, |
|
| 111 | - $shared, |
|
| 112 | - $from_db, |
|
| 113 | - $load_only, |
|
| 114 | - $addon |
|
| 115 | - ); |
|
| 116 | - } |
|
| 117 | - return $this->generator->brew( |
|
| 118 | - $fqcn, |
|
| 119 | - $arguments, |
|
| 120 | - $shared ? CoffeeMaker::BREW_SHARED : CoffeeMaker::BREW_NEW |
|
| 121 | - ); |
|
| 122 | - |
|
| 123 | - } |
|
| 124 | - |
|
| 125 | - |
|
| 126 | - |
|
| 127 | - /** |
|
| 128 | - * calls reset() on generator if method exists |
|
| 129 | - * |
|
| 130 | - * @throws EE_Error |
|
| 131 | - * @throws ReflectionException |
|
| 132 | - */ |
|
| 133 | - public function reset() |
|
| 134 | - { |
|
| 135 | - if (method_exists($this->generator, 'reset')) { |
|
| 136 | - $this->generator->reset(); |
|
| 137 | - } |
|
| 138 | - } |
|
| 35 | + /** |
|
| 36 | + * @var EE_Registry|CoffeeShop $generator |
|
| 37 | + */ |
|
| 38 | + private $generator; |
|
| 39 | + |
|
| 40 | + |
|
| 41 | + |
|
| 42 | + /** |
|
| 43 | + * CoreLoader constructor. |
|
| 44 | + * |
|
| 45 | + * @param EE_Registry|CoffeeShop $generator |
|
| 46 | + * @throws InvalidArgumentException |
|
| 47 | + */ |
|
| 48 | + public function __construct($generator) |
|
| 49 | + { |
|
| 50 | + if(!($generator instanceof EE_Registry || $generator instanceof CoffeeShop)) { |
|
| 51 | + throw new InvalidArgumentException( |
|
| 52 | + esc_html__( |
|
| 53 | + 'The CoreLoader class must receive an instance of EE_Registry or the CoffeeShop DI container.', |
|
| 54 | + 'event_espresso' |
|
| 55 | + ) |
|
| 56 | + ); |
|
| 57 | + } |
|
| 58 | + $this->generator = $generator; |
|
| 59 | + } |
|
| 60 | + |
|
| 61 | + |
|
| 62 | + |
|
| 63 | + /** |
|
| 64 | + * Calls the appropriate loading method from the installed generator; |
|
| 65 | + * If EE_Registry is being used, then the additional parameters for the EE_Registry::create() method |
|
| 66 | + * can be added to the $arguments array and they will be extracted and passed to EE_Registry::create(), |
|
| 67 | + * but NOT to the class being instantiated. |
|
| 68 | + * This is done by adding the parameters to the $arguments array as follows: |
|
| 69 | + * array( |
|
| 70 | + * 'EE_Registry::create(from_db)' => true, // boolean value, default = false |
|
| 71 | + * 'EE_Registry::create(load_only)' => true, // boolean value, default = false |
|
| 72 | + * 'EE_Registry::create(addon)' => true, // boolean value, default = false |
|
| 73 | + * ) |
|
| 74 | + * |
|
| 75 | + * @param string $fqcn |
|
| 76 | + * @param array $arguments |
|
| 77 | + * @param bool $shared |
|
| 78 | + * @return mixed |
|
| 79 | + * @throws OutOfBoundsException |
|
| 80 | + * @throws ServiceExistsException |
|
| 81 | + * @throws InstantiationException |
|
| 82 | + * @throws InvalidIdentifierException |
|
| 83 | + * @throws InvalidDataTypeException |
|
| 84 | + * @throws InvalidClassException |
|
| 85 | + * @throws EE_Error |
|
| 86 | + * @throws ServiceNotFoundException |
|
| 87 | + * @throws ReflectionException |
|
| 88 | + */ |
|
| 89 | + public function load($fqcn, $arguments = array(), $shared = true) |
|
| 90 | + { |
|
| 91 | + if($this->generator instanceof EE_Registry) { |
|
| 92 | + // check if additional EE_Registry::create() arguments have been passed |
|
| 93 | + // from_db |
|
| 94 | + $from_db = isset($arguments['EE_Registry::create(from_db)']) |
|
| 95 | + ? $arguments['EE_Registry::create(from_db)'] |
|
| 96 | + : null; |
|
| 97 | + unset($arguments['EE_Registry::create(from_db)']); |
|
| 98 | + // load_only |
|
| 99 | + $load_only = isset($arguments['EE_Registry::create(load_only)']) |
|
| 100 | + ? $arguments['EE_Registry::create(load_only)'] |
|
| 101 | + : null; |
|
| 102 | + unset($arguments['EE_Registry::create(load_only)']); |
|
| 103 | + // addon |
|
| 104 | + $addon = isset($arguments['EE_Registry::create(addon)']) |
|
| 105 | + ? $arguments['EE_Registry::create(addon)'] |
|
| 106 | + : null; |
|
| 107 | + unset($arguments['EE_Registry::create(addon)']); |
|
| 108 | + return $this->generator->create( |
|
| 109 | + $fqcn, |
|
| 110 | + $arguments, |
|
| 111 | + $shared, |
|
| 112 | + $from_db, |
|
| 113 | + $load_only, |
|
| 114 | + $addon |
|
| 115 | + ); |
|
| 116 | + } |
|
| 117 | + return $this->generator->brew( |
|
| 118 | + $fqcn, |
|
| 119 | + $arguments, |
|
| 120 | + $shared ? CoffeeMaker::BREW_SHARED : CoffeeMaker::BREW_NEW |
|
| 121 | + ); |
|
| 122 | + |
|
| 123 | + } |
|
| 124 | + |
|
| 125 | + |
|
| 126 | + |
|
| 127 | + /** |
|
| 128 | + * calls reset() on generator if method exists |
|
| 129 | + * |
|
| 130 | + * @throws EE_Error |
|
| 131 | + * @throws ReflectionException |
|
| 132 | + */ |
|
| 133 | + public function reset() |
|
| 134 | + { |
|
| 135 | + if (method_exists($this->generator, 'reset')) { |
|
| 136 | + $this->generator->reset(); |
|
| 137 | + } |
|
| 138 | + } |
|
| 139 | 139 | |
| 140 | 140 | } |
| 141 | 141 | // End of file CoreLoader.php |
@@ -47,7 +47,7 @@ discard block |
||
| 47 | 47 | */ |
| 48 | 48 | public function __construct($generator) |
| 49 | 49 | { |
| 50 | - if(!($generator instanceof EE_Registry || $generator instanceof CoffeeShop)) { |
|
| 50 | + if ( ! ($generator instanceof EE_Registry || $generator instanceof CoffeeShop)) { |
|
| 51 | 51 | throw new InvalidArgumentException( |
| 52 | 52 | esc_html__( |
| 53 | 53 | 'The CoreLoader class must receive an instance of EE_Registry or the CoffeeShop DI container.', |
@@ -88,7 +88,7 @@ discard block |
||
| 88 | 88 | */ |
| 89 | 89 | public function load($fqcn, $arguments = array(), $shared = true) |
| 90 | 90 | { |
| 91 | - if($this->generator instanceof EE_Registry) { |
|
| 91 | + if ($this->generator instanceof EE_Registry) { |
|
| 92 | 92 | // check if additional EE_Registry::create() arguments have been passed |
| 93 | 93 | // from_db |
| 94 | 94 | $from_db = isset($arguments['EE_Registry::create(from_db)']) |
@@ -21,1012 +21,1012 @@ |
||
| 21 | 21 | { |
| 22 | 22 | |
| 23 | 23 | |
| 24 | - /** |
|
| 25 | - * possibly truncated version of the EE core version string |
|
| 26 | - * |
|
| 27 | - * @var string |
|
| 28 | - */ |
|
| 29 | - protected static $_core_version = ''; |
|
| 24 | + /** |
|
| 25 | + * possibly truncated version of the EE core version string |
|
| 26 | + * |
|
| 27 | + * @var string |
|
| 28 | + */ |
|
| 29 | + protected static $_core_version = ''; |
|
| 30 | 30 | |
| 31 | - /** |
|
| 32 | - * Holds values for registered addons |
|
| 33 | - * |
|
| 34 | - * @var array |
|
| 35 | - */ |
|
| 36 | - protected static $_settings = array(); |
|
| 31 | + /** |
|
| 32 | + * Holds values for registered addons |
|
| 33 | + * |
|
| 34 | + * @var array |
|
| 35 | + */ |
|
| 36 | + protected static $_settings = array(); |
|
| 37 | 37 | |
| 38 | - /** |
|
| 39 | - * @var array $_incompatible_addons keys are addon SLUGS |
|
| 40 | - * (first argument passed to EE_Register_Addon::register()), keys are |
|
| 41 | - * their MINIMUM VERSION (with all 5 parts. Eg 1.2.3.rc.004). |
|
| 42 | - * Generally this should be used sparingly, as we don't want to muddle up |
|
| 43 | - * EE core with knowledge of ALL the addons out there. |
|
| 44 | - * If you want NO versions of an addon to run with a certain version of core, |
|
| 45 | - * it's usually best to define the addon's "min_core_version" as part of its call |
|
| 46 | - * to EE_Register_Addon::register(), rather than using this array with a super high value for its |
|
| 47 | - * minimum plugin version. |
|
| 48 | - * @access protected |
|
| 49 | - */ |
|
| 50 | - protected static $_incompatible_addons = array( |
|
| 51 | - 'Multi_Event_Registration' => '2.0.11.rc.002', |
|
| 52 | - 'Promotions' => '1.0.0.rc.084', |
|
| 53 | - ); |
|
| 38 | + /** |
|
| 39 | + * @var array $_incompatible_addons keys are addon SLUGS |
|
| 40 | + * (first argument passed to EE_Register_Addon::register()), keys are |
|
| 41 | + * their MINIMUM VERSION (with all 5 parts. Eg 1.2.3.rc.004). |
|
| 42 | + * Generally this should be used sparingly, as we don't want to muddle up |
|
| 43 | + * EE core with knowledge of ALL the addons out there. |
|
| 44 | + * If you want NO versions of an addon to run with a certain version of core, |
|
| 45 | + * it's usually best to define the addon's "min_core_version" as part of its call |
|
| 46 | + * to EE_Register_Addon::register(), rather than using this array with a super high value for its |
|
| 47 | + * minimum plugin version. |
|
| 48 | + * @access protected |
|
| 49 | + */ |
|
| 50 | + protected static $_incompatible_addons = array( |
|
| 51 | + 'Multi_Event_Registration' => '2.0.11.rc.002', |
|
| 52 | + 'Promotions' => '1.0.0.rc.084', |
|
| 53 | + ); |
|
| 54 | 54 | |
| 55 | 55 | |
| 56 | - /** |
|
| 57 | - * We should always be comparing core to a version like '4.3.0.rc.000', |
|
| 58 | - * not just '4.3.0'. |
|
| 59 | - * So if the addon developer doesn't provide that full version string, |
|
| 60 | - * fill in the blanks for them |
|
| 61 | - * |
|
| 62 | - * @param string $min_core_version |
|
| 63 | - * @return string always like '4.3.0.rc.000' |
|
| 64 | - */ |
|
| 65 | - protected static function _effective_version($min_core_version) |
|
| 66 | - { |
|
| 67 | - // versions: 4 . 3 . 1 . p . 123 |
|
| 68 | - // offsets: 0 . 1 . 2 . 3 . 4 |
|
| 69 | - $version_parts = explode('.', $min_core_version); |
|
| 70 | - //check they specified the micro version (after 2nd period) |
|
| 71 | - if (! isset($version_parts[2])) { |
|
| 72 | - $version_parts[2] = '0'; |
|
| 73 | - } |
|
| 74 | - //if they didn't specify the 'p', or 'rc' part. Just assume the lowest possible |
|
| 75 | - //soon we can assume that's 'rc', but this current version is 'alpha' |
|
| 76 | - if (! isset($version_parts[3])) { |
|
| 77 | - $version_parts[3] = 'dev'; |
|
| 78 | - } |
|
| 79 | - if (! isset($version_parts[4])) { |
|
| 80 | - $version_parts[4] = '000'; |
|
| 81 | - } |
|
| 82 | - return implode('.', $version_parts); |
|
| 83 | - } |
|
| 56 | + /** |
|
| 57 | + * We should always be comparing core to a version like '4.3.0.rc.000', |
|
| 58 | + * not just '4.3.0'. |
|
| 59 | + * So if the addon developer doesn't provide that full version string, |
|
| 60 | + * fill in the blanks for them |
|
| 61 | + * |
|
| 62 | + * @param string $min_core_version |
|
| 63 | + * @return string always like '4.3.0.rc.000' |
|
| 64 | + */ |
|
| 65 | + protected static function _effective_version($min_core_version) |
|
| 66 | + { |
|
| 67 | + // versions: 4 . 3 . 1 . p . 123 |
|
| 68 | + // offsets: 0 . 1 . 2 . 3 . 4 |
|
| 69 | + $version_parts = explode('.', $min_core_version); |
|
| 70 | + //check they specified the micro version (after 2nd period) |
|
| 71 | + if (! isset($version_parts[2])) { |
|
| 72 | + $version_parts[2] = '0'; |
|
| 73 | + } |
|
| 74 | + //if they didn't specify the 'p', or 'rc' part. Just assume the lowest possible |
|
| 75 | + //soon we can assume that's 'rc', but this current version is 'alpha' |
|
| 76 | + if (! isset($version_parts[3])) { |
|
| 77 | + $version_parts[3] = 'dev'; |
|
| 78 | + } |
|
| 79 | + if (! isset($version_parts[4])) { |
|
| 80 | + $version_parts[4] = '000'; |
|
| 81 | + } |
|
| 82 | + return implode('.', $version_parts); |
|
| 83 | + } |
|
| 84 | 84 | |
| 85 | 85 | |
| 86 | - /** |
|
| 87 | - * Returns whether or not the min core version requirement of the addon is met |
|
| 88 | - * |
|
| 89 | - * @param string $min_core_version the minimum core version required by the addon |
|
| 90 | - * @param string $actual_core_version the actual core version, optional |
|
| 91 | - * @return boolean |
|
| 92 | - */ |
|
| 93 | - public static function _meets_min_core_version_requirement( |
|
| 94 | - $min_core_version, |
|
| 95 | - $actual_core_version = EVENT_ESPRESSO_VERSION |
|
| 96 | - ) { |
|
| 97 | - return version_compare( |
|
| 98 | - self::_effective_version($actual_core_version), |
|
| 99 | - self::_effective_version($min_core_version), |
|
| 100 | - '>=' |
|
| 101 | - ); |
|
| 102 | - } |
|
| 86 | + /** |
|
| 87 | + * Returns whether or not the min core version requirement of the addon is met |
|
| 88 | + * |
|
| 89 | + * @param string $min_core_version the minimum core version required by the addon |
|
| 90 | + * @param string $actual_core_version the actual core version, optional |
|
| 91 | + * @return boolean |
|
| 92 | + */ |
|
| 93 | + public static function _meets_min_core_version_requirement( |
|
| 94 | + $min_core_version, |
|
| 95 | + $actual_core_version = EVENT_ESPRESSO_VERSION |
|
| 96 | + ) { |
|
| 97 | + return version_compare( |
|
| 98 | + self::_effective_version($actual_core_version), |
|
| 99 | + self::_effective_version($min_core_version), |
|
| 100 | + '>=' |
|
| 101 | + ); |
|
| 102 | + } |
|
| 103 | 103 | |
| 104 | 104 | |
| 105 | - /** |
|
| 106 | - * Method for registering new EE_Addons. |
|
| 107 | - * Should be called AFTER AHEE__EE_System__load_espresso_addons but BEFORE |
|
| 108 | - * AHEE__EE_System___detect_if_activation_or_upgrade__begin in order to register all its components. However, it |
|
| 109 | - * may also be called after the 'activate_plugin' action (when an addon is activated), because an activating addon |
|
| 110 | - * won't be loaded by WP until after AHEE__EE_System__load_espresso_addons has fired. If its called after |
|
| 111 | - * 'activate_plugin', it registers the addon still, but its components are not registered |
|
| 112 | - * (they shouldn't be needed anyways, because it's just an activation request and they won't have a chance to do |
|
| 113 | - * anything anyways). Instead, it just sets the newly-activated addon's activation indicator wp option and returns |
|
| 114 | - * (so that we can detect that the addon has activated on the subsequent request) |
|
| 115 | - * |
|
| 116 | - * @since 4.3.0 |
|
| 117 | - * @param string $addon_name the EE_Addon's name. Required. |
|
| 118 | - * @param array $setup_args { An |
|
| 119 | - * array of arguments provided for registering |
|
| 120 | - * the message type. |
|
| 121 | - * @throws DomainException |
|
| 122 | - * @throws EE_Error |
|
| 123 | - * @throws InvalidArgumentException |
|
| 124 | - * @throws InvalidDataTypeException |
|
| 125 | - * @throws InvalidInterfaceException |
|
| 126 | - * @throws ReflectionException |
|
| 127 | - * @see EE_Register_Model |
|
| 128 | - * @see EE_Register_Model |
|
| 129 | - * @see EE_Register_Model_Extension |
|
| 130 | - * @see EE_Register_Model_Extension |
|
| 131 | - * @internal param array $ message_types { |
|
| 132 | - * An array of message types with the key as |
|
| 133 | - * the message type name and the values as |
|
| 134 | - * below: |
|
| 135 | - * @see EventEspresso\core\Psr4Autoloader::addNamespace() |
|
| 136 | - */ |
|
| 137 | - public static function register($addon_name = '', $setup_args = array()) |
|
| 138 | - { |
|
| 139 | - // required fields MUST be present, so let's make sure they are. |
|
| 140 | - \EE_Register_Addon::_verify_parameters($addon_name, $setup_args); |
|
| 141 | - // get class name for addon |
|
| 142 | - $class_name = \EE_Register_Addon::_parse_class_name($addon_name, $setup_args); |
|
| 143 | - //setup $_settings array from incoming values. |
|
| 144 | - $addon_settings = \EE_Register_Addon::_get_addon_settings($class_name, $setup_args); |
|
| 145 | - // setup PUE |
|
| 146 | - \EE_Register_Addon::_parse_pue_options($addon_name, $class_name, $setup_args); |
|
| 147 | - // does this addon work with this version of core or WordPress ? |
|
| 148 | - if (! \EE_Register_Addon::_addon_is_compatible($addon_name, $addon_settings)) { |
|
| 149 | - return; |
|
| 150 | - } |
|
| 151 | - // register namespaces |
|
| 152 | - \EE_Register_Addon::_setup_namespaces($addon_settings); |
|
| 153 | - // check if this is an activation request |
|
| 154 | - if (\EE_Register_Addon::_addon_activation($addon_name, $addon_settings)) { |
|
| 155 | - // dont bother setting up the rest of the addon atm |
|
| 156 | - return; |
|
| 157 | - } |
|
| 158 | - // we need cars |
|
| 159 | - \EE_Register_Addon::_setup_autoloaders($addon_name); |
|
| 160 | - // register new models and extensions |
|
| 161 | - \EE_Register_Addon::_register_models_and_extensions($addon_name); |
|
| 162 | - // setup DMS |
|
| 163 | - \EE_Register_Addon::_register_data_migration_scripts($addon_name); |
|
| 164 | - // if config_class is present let's register config. |
|
| 165 | - \EE_Register_Addon::_register_config($addon_name); |
|
| 166 | - // register admin pages |
|
| 167 | - \EE_Register_Addon::_register_admin_pages($addon_name); |
|
| 168 | - // add to list of modules to be registered |
|
| 169 | - \EE_Register_Addon::_register_modules($addon_name); |
|
| 170 | - // add to list of shortcodes to be registered |
|
| 171 | - \EE_Register_Addon::_register_shortcodes($addon_name); |
|
| 172 | - // add to list of widgets to be registered |
|
| 173 | - \EE_Register_Addon::_register_widgets($addon_name); |
|
| 174 | - // register capability related stuff. |
|
| 175 | - \EE_Register_Addon::_register_capabilities($addon_name); |
|
| 176 | - // any message type to register? |
|
| 177 | - \EE_Register_Addon::_register_message_types($addon_name); |
|
| 178 | - // any custom post type/ custom capabilities or default terms to register |
|
| 179 | - \EE_Register_Addon::_register_custom_post_types($addon_name); |
|
| 180 | - // and any payment methods |
|
| 181 | - \EE_Register_Addon::_register_payment_methods($addon_name); |
|
| 182 | - // load and instantiate main addon class |
|
| 183 | - $addon = \EE_Register_Addon::_load_and_init_addon_class($addon_name); |
|
| 105 | + /** |
|
| 106 | + * Method for registering new EE_Addons. |
|
| 107 | + * Should be called AFTER AHEE__EE_System__load_espresso_addons but BEFORE |
|
| 108 | + * AHEE__EE_System___detect_if_activation_or_upgrade__begin in order to register all its components. However, it |
|
| 109 | + * may also be called after the 'activate_plugin' action (when an addon is activated), because an activating addon |
|
| 110 | + * won't be loaded by WP until after AHEE__EE_System__load_espresso_addons has fired. If its called after |
|
| 111 | + * 'activate_plugin', it registers the addon still, but its components are not registered |
|
| 112 | + * (they shouldn't be needed anyways, because it's just an activation request and they won't have a chance to do |
|
| 113 | + * anything anyways). Instead, it just sets the newly-activated addon's activation indicator wp option and returns |
|
| 114 | + * (so that we can detect that the addon has activated on the subsequent request) |
|
| 115 | + * |
|
| 116 | + * @since 4.3.0 |
|
| 117 | + * @param string $addon_name the EE_Addon's name. Required. |
|
| 118 | + * @param array $setup_args { An |
|
| 119 | + * array of arguments provided for registering |
|
| 120 | + * the message type. |
|
| 121 | + * @throws DomainException |
|
| 122 | + * @throws EE_Error |
|
| 123 | + * @throws InvalidArgumentException |
|
| 124 | + * @throws InvalidDataTypeException |
|
| 125 | + * @throws InvalidInterfaceException |
|
| 126 | + * @throws ReflectionException |
|
| 127 | + * @see EE_Register_Model |
|
| 128 | + * @see EE_Register_Model |
|
| 129 | + * @see EE_Register_Model_Extension |
|
| 130 | + * @see EE_Register_Model_Extension |
|
| 131 | + * @internal param array $ message_types { |
|
| 132 | + * An array of message types with the key as |
|
| 133 | + * the message type name and the values as |
|
| 134 | + * below: |
|
| 135 | + * @see EventEspresso\core\Psr4Autoloader::addNamespace() |
|
| 136 | + */ |
|
| 137 | + public static function register($addon_name = '', $setup_args = array()) |
|
| 138 | + { |
|
| 139 | + // required fields MUST be present, so let's make sure they are. |
|
| 140 | + \EE_Register_Addon::_verify_parameters($addon_name, $setup_args); |
|
| 141 | + // get class name for addon |
|
| 142 | + $class_name = \EE_Register_Addon::_parse_class_name($addon_name, $setup_args); |
|
| 143 | + //setup $_settings array from incoming values. |
|
| 144 | + $addon_settings = \EE_Register_Addon::_get_addon_settings($class_name, $setup_args); |
|
| 145 | + // setup PUE |
|
| 146 | + \EE_Register_Addon::_parse_pue_options($addon_name, $class_name, $setup_args); |
|
| 147 | + // does this addon work with this version of core or WordPress ? |
|
| 148 | + if (! \EE_Register_Addon::_addon_is_compatible($addon_name, $addon_settings)) { |
|
| 149 | + return; |
|
| 150 | + } |
|
| 151 | + // register namespaces |
|
| 152 | + \EE_Register_Addon::_setup_namespaces($addon_settings); |
|
| 153 | + // check if this is an activation request |
|
| 154 | + if (\EE_Register_Addon::_addon_activation($addon_name, $addon_settings)) { |
|
| 155 | + // dont bother setting up the rest of the addon atm |
|
| 156 | + return; |
|
| 157 | + } |
|
| 158 | + // we need cars |
|
| 159 | + \EE_Register_Addon::_setup_autoloaders($addon_name); |
|
| 160 | + // register new models and extensions |
|
| 161 | + \EE_Register_Addon::_register_models_and_extensions($addon_name); |
|
| 162 | + // setup DMS |
|
| 163 | + \EE_Register_Addon::_register_data_migration_scripts($addon_name); |
|
| 164 | + // if config_class is present let's register config. |
|
| 165 | + \EE_Register_Addon::_register_config($addon_name); |
|
| 166 | + // register admin pages |
|
| 167 | + \EE_Register_Addon::_register_admin_pages($addon_name); |
|
| 168 | + // add to list of modules to be registered |
|
| 169 | + \EE_Register_Addon::_register_modules($addon_name); |
|
| 170 | + // add to list of shortcodes to be registered |
|
| 171 | + \EE_Register_Addon::_register_shortcodes($addon_name); |
|
| 172 | + // add to list of widgets to be registered |
|
| 173 | + \EE_Register_Addon::_register_widgets($addon_name); |
|
| 174 | + // register capability related stuff. |
|
| 175 | + \EE_Register_Addon::_register_capabilities($addon_name); |
|
| 176 | + // any message type to register? |
|
| 177 | + \EE_Register_Addon::_register_message_types($addon_name); |
|
| 178 | + // any custom post type/ custom capabilities or default terms to register |
|
| 179 | + \EE_Register_Addon::_register_custom_post_types($addon_name); |
|
| 180 | + // and any payment methods |
|
| 181 | + \EE_Register_Addon::_register_payment_methods($addon_name); |
|
| 182 | + // load and instantiate main addon class |
|
| 183 | + $addon = \EE_Register_Addon::_load_and_init_addon_class($addon_name); |
|
| 184 | 184 | |
| 185 | - //delay calling after_registration hook on each addon until after all add-ons have been registered. |
|
| 186 | - add_action('AHEE__EE_System__load_espresso_addons__complete', array($addon, 'after_registration'), 999); |
|
| 187 | - } |
|
| 185 | + //delay calling after_registration hook on each addon until after all add-ons have been registered. |
|
| 186 | + add_action('AHEE__EE_System__load_espresso_addons__complete', array($addon, 'after_registration'), 999); |
|
| 187 | + } |
|
| 188 | 188 | |
| 189 | 189 | |
| 190 | - /** |
|
| 191 | - * @param string $addon_name |
|
| 192 | - * @param array $setup_args |
|
| 193 | - * @return void |
|
| 194 | - * @throws EE_Error |
|
| 195 | - */ |
|
| 196 | - private static function _verify_parameters($addon_name, array $setup_args) |
|
| 197 | - { |
|
| 198 | - // required fields MUST be present, so let's make sure they are. |
|
| 199 | - if (empty($addon_name) || ! is_array($setup_args)) { |
|
| 200 | - throw new EE_Error( |
|
| 201 | - __( |
|
| 202 | - 'In order to register an EE_Addon with EE_Register_Addon::register(), you must include the "addon_name" (the name of the addon), and an array of arguments.', |
|
| 203 | - 'event_espresso' |
|
| 204 | - ) |
|
| 205 | - ); |
|
| 206 | - } |
|
| 207 | - if (! isset($setup_args['main_file_path']) || empty($setup_args['main_file_path'])) { |
|
| 208 | - throw new EE_Error( |
|
| 209 | - sprintf( |
|
| 210 | - __( |
|
| 211 | - 'When registering an addon, you didn\'t provide the "main_file_path", which is the full path to the main file loaded directly by Wordpress. You only provided %s', |
|
| 212 | - 'event_espresso' |
|
| 213 | - ), |
|
| 214 | - implode(',', array_keys($setup_args)) |
|
| 215 | - ) |
|
| 216 | - ); |
|
| 217 | - } |
|
| 218 | - // check that addon has not already been registered with that name |
|
| 219 | - if (isset(self::$_settings[$addon_name]) && ! did_action('activate_plugin')) { |
|
| 220 | - throw new EE_Error( |
|
| 221 | - sprintf( |
|
| 222 | - __( |
|
| 223 | - 'An EE_Addon with the name "%s" has already been registered and each EE_Addon requires a unique name.', |
|
| 224 | - 'event_espresso' |
|
| 225 | - ), |
|
| 226 | - $addon_name |
|
| 227 | - ) |
|
| 228 | - ); |
|
| 229 | - } |
|
| 230 | - } |
|
| 190 | + /** |
|
| 191 | + * @param string $addon_name |
|
| 192 | + * @param array $setup_args |
|
| 193 | + * @return void |
|
| 194 | + * @throws EE_Error |
|
| 195 | + */ |
|
| 196 | + private static function _verify_parameters($addon_name, array $setup_args) |
|
| 197 | + { |
|
| 198 | + // required fields MUST be present, so let's make sure they are. |
|
| 199 | + if (empty($addon_name) || ! is_array($setup_args)) { |
|
| 200 | + throw new EE_Error( |
|
| 201 | + __( |
|
| 202 | + 'In order to register an EE_Addon with EE_Register_Addon::register(), you must include the "addon_name" (the name of the addon), and an array of arguments.', |
|
| 203 | + 'event_espresso' |
|
| 204 | + ) |
|
| 205 | + ); |
|
| 206 | + } |
|
| 207 | + if (! isset($setup_args['main_file_path']) || empty($setup_args['main_file_path'])) { |
|
| 208 | + throw new EE_Error( |
|
| 209 | + sprintf( |
|
| 210 | + __( |
|
| 211 | + 'When registering an addon, you didn\'t provide the "main_file_path", which is the full path to the main file loaded directly by Wordpress. You only provided %s', |
|
| 212 | + 'event_espresso' |
|
| 213 | + ), |
|
| 214 | + implode(',', array_keys($setup_args)) |
|
| 215 | + ) |
|
| 216 | + ); |
|
| 217 | + } |
|
| 218 | + // check that addon has not already been registered with that name |
|
| 219 | + if (isset(self::$_settings[$addon_name]) && ! did_action('activate_plugin')) { |
|
| 220 | + throw new EE_Error( |
|
| 221 | + sprintf( |
|
| 222 | + __( |
|
| 223 | + 'An EE_Addon with the name "%s" has already been registered and each EE_Addon requires a unique name.', |
|
| 224 | + 'event_espresso' |
|
| 225 | + ), |
|
| 226 | + $addon_name |
|
| 227 | + ) |
|
| 228 | + ); |
|
| 229 | + } |
|
| 230 | + } |
|
| 231 | 231 | |
| 232 | 232 | |
| 233 | - /** |
|
| 234 | - * @param string $addon_name |
|
| 235 | - * @param array $setup_args |
|
| 236 | - * @return string |
|
| 237 | - */ |
|
| 238 | - private static function _parse_class_name($addon_name, array $setup_args) |
|
| 239 | - { |
|
| 240 | - if (empty($setup_args['class_name'])) { |
|
| 241 | - // generate one by first separating name with spaces |
|
| 242 | - $class_name = str_replace(array('-', '_'), ' ', trim($addon_name)); |
|
| 243 | - //capitalize, then replace spaces with underscores |
|
| 244 | - $class_name = str_replace(' ', '_', ucwords($class_name)); |
|
| 245 | - } else { |
|
| 246 | - $class_name = $setup_args['class_name']; |
|
| 247 | - } |
|
| 248 | - // check if classname is fully qualified or is a legacy classname already prefixed with 'EE_' |
|
| 249 | - return strpos($class_name, '\\') || strpos($class_name, 'EE_') === 0 |
|
| 250 | - ? $class_name |
|
| 251 | - : 'EE_' . $class_name; |
|
| 252 | - } |
|
| 233 | + /** |
|
| 234 | + * @param string $addon_name |
|
| 235 | + * @param array $setup_args |
|
| 236 | + * @return string |
|
| 237 | + */ |
|
| 238 | + private static function _parse_class_name($addon_name, array $setup_args) |
|
| 239 | + { |
|
| 240 | + if (empty($setup_args['class_name'])) { |
|
| 241 | + // generate one by first separating name with spaces |
|
| 242 | + $class_name = str_replace(array('-', '_'), ' ', trim($addon_name)); |
|
| 243 | + //capitalize, then replace spaces with underscores |
|
| 244 | + $class_name = str_replace(' ', '_', ucwords($class_name)); |
|
| 245 | + } else { |
|
| 246 | + $class_name = $setup_args['class_name']; |
|
| 247 | + } |
|
| 248 | + // check if classname is fully qualified or is a legacy classname already prefixed with 'EE_' |
|
| 249 | + return strpos($class_name, '\\') || strpos($class_name, 'EE_') === 0 |
|
| 250 | + ? $class_name |
|
| 251 | + : 'EE_' . $class_name; |
|
| 252 | + } |
|
| 253 | 253 | |
| 254 | 254 | |
| 255 | - /** |
|
| 256 | - * @param string $class_name |
|
| 257 | - * @param array $setup_args |
|
| 258 | - * @return array |
|
| 259 | - */ |
|
| 260 | - private static function _get_addon_settings($class_name, array $setup_args) |
|
| 261 | - { |
|
| 262 | - //setup $_settings array from incoming values. |
|
| 263 | - $addon_settings = array( |
|
| 264 | - // generated from the addon name, changes something like "calendar" to "EE_Calendar" |
|
| 265 | - 'class_name' => $class_name, |
|
| 266 | - // the addon slug for use in URLs, etc |
|
| 267 | - 'plugin_slug' => isset($setup_args['plugin_slug']) |
|
| 268 | - ? (string)$setup_args['plugin_slug'] |
|
| 269 | - : '', |
|
| 270 | - // page slug to be used when generating the "Settings" link on the WP plugin page |
|
| 271 | - 'plugin_action_slug' => isset($setup_args['plugin_action_slug']) |
|
| 272 | - ? (string)$setup_args['plugin_action_slug'] |
|
| 273 | - : '', |
|
| 274 | - // the "software" version for the addon |
|
| 275 | - 'version' => isset($setup_args['version']) |
|
| 276 | - ? (string)$setup_args['version'] |
|
| 277 | - : '', |
|
| 278 | - // the minimum version of EE Core that the addon will work with |
|
| 279 | - 'min_core_version' => isset($setup_args['min_core_version']) |
|
| 280 | - ? (string)$setup_args['min_core_version'] |
|
| 281 | - : '', |
|
| 282 | - // the minimum version of WordPress that the addon will work with |
|
| 283 | - 'min_wp_version' => isset($setup_args['min_wp_version']) |
|
| 284 | - ? (string)$setup_args['min_wp_version'] |
|
| 285 | - : EE_MIN_WP_VER_REQUIRED, |
|
| 286 | - // full server path to main file (file loaded directly by WP) |
|
| 287 | - 'main_file_path' => isset($setup_args['main_file_path']) |
|
| 288 | - ? (string)$setup_args['main_file_path'] |
|
| 289 | - : '', |
|
| 290 | - // path to folder containing files for integrating with the EE core admin and/or setting up EE admin pages |
|
| 291 | - 'admin_path' => isset($setup_args['admin_path']) |
|
| 292 | - ? (string)$setup_args['admin_path'] : '', |
|
| 293 | - // a method to be called when the EE Admin is first invoked, can be used for hooking into any admin page |
|
| 294 | - 'admin_callback' => isset($setup_args['admin_callback']) |
|
| 295 | - ? (string)$setup_args['admin_callback'] |
|
| 296 | - : '', |
|
| 297 | - // the section name for this addon's configuration settings section (defaults to "addons") |
|
| 298 | - 'config_section' => isset($setup_args['config_section']) |
|
| 299 | - ? (string)$setup_args['config_section'] |
|
| 300 | - : 'addons', |
|
| 301 | - // the class name for this addon's configuration settings object |
|
| 302 | - 'config_class' => isset($setup_args['config_class']) |
|
| 303 | - ? (string)$setup_args['config_class'] : '', |
|
| 304 | - //the name given to the config for this addons' configuration settings object (optional) |
|
| 305 | - 'config_name' => isset($setup_args['config_name']) |
|
| 306 | - ? (string)$setup_args['config_name'] : '', |
|
| 307 | - // an array of "class names" => "full server paths" for any classes that might be invoked by the addon |
|
| 308 | - 'autoloader_paths' => isset($setup_args['autoloader_paths']) |
|
| 309 | - ? (array)$setup_args['autoloader_paths'] |
|
| 310 | - : array(), |
|
| 311 | - // an array of "full server paths" for any folders containing classes that might be invoked by the addon |
|
| 312 | - 'autoloader_folders' => isset($setup_args['autoloader_folders']) |
|
| 313 | - ? (array)$setup_args['autoloader_folders'] |
|
| 314 | - : array(), |
|
| 315 | - // array of full server paths to any EE_DMS data migration scripts used by the addon |
|
| 316 | - 'dms_paths' => isset($setup_args['dms_paths']) |
|
| 317 | - ? (array)$setup_args['dms_paths'] |
|
| 318 | - : array(), |
|
| 319 | - // array of full server paths to any EED_Modules used by the addon |
|
| 320 | - 'module_paths' => isset($setup_args['module_paths']) |
|
| 321 | - ? (array)$setup_args['module_paths'] |
|
| 322 | - : array(), |
|
| 323 | - // array of full server paths to any EES_Shortcodes used by the addon |
|
| 324 | - 'shortcode_paths' => isset($setup_args['shortcode_paths']) |
|
| 325 | - ? (array)$setup_args['shortcode_paths'] |
|
| 326 | - : array(), |
|
| 327 | - 'shortcode_fqcns' => isset($setup_args['shortcode_fqcns']) |
|
| 328 | - ? (array) $setup_args['shortcode_fqcns'] |
|
| 329 | - : array(), |
|
| 330 | - // array of full server paths to any WP_Widgets used by the addon |
|
| 331 | - 'widget_paths' => isset($setup_args['widget_paths']) |
|
| 332 | - ? (array)$setup_args['widget_paths'] |
|
| 333 | - : array(), |
|
| 334 | - // array of PUE options used by the addon |
|
| 335 | - 'pue_options' => isset($setup_args['pue_options']) |
|
| 336 | - ? (array)$setup_args['pue_options'] |
|
| 337 | - : array(), |
|
| 338 | - 'message_types' => isset($setup_args['message_types']) |
|
| 339 | - ? (array)$setup_args['message_types'] |
|
| 340 | - : array(), |
|
| 341 | - 'capabilities' => isset($setup_args['capabilities']) |
|
| 342 | - ? (array)$setup_args['capabilities'] |
|
| 343 | - : array(), |
|
| 344 | - 'capability_maps' => isset($setup_args['capability_maps']) |
|
| 345 | - ? (array)$setup_args['capability_maps'] |
|
| 346 | - : array(), |
|
| 347 | - 'model_paths' => isset($setup_args['model_paths']) |
|
| 348 | - ? (array)$setup_args['model_paths'] |
|
| 349 | - : array(), |
|
| 350 | - 'class_paths' => isset($setup_args['class_paths']) |
|
| 351 | - ? (array)$setup_args['class_paths'] |
|
| 352 | - : array(), |
|
| 353 | - 'model_extension_paths' => isset($setup_args['model_extension_paths']) |
|
| 354 | - ? (array)$setup_args['model_extension_paths'] |
|
| 355 | - : array(), |
|
| 356 | - 'class_extension_paths' => isset($setup_args['class_extension_paths']) |
|
| 357 | - ? (array)$setup_args['class_extension_paths'] |
|
| 358 | - : array(), |
|
| 359 | - 'custom_post_types' => isset($setup_args['custom_post_types']) |
|
| 360 | - ? (array)$setup_args['custom_post_types'] |
|
| 361 | - : array(), |
|
| 362 | - 'custom_taxonomies' => isset($setup_args['custom_taxonomies']) |
|
| 363 | - ? (array)$setup_args['custom_taxonomies'] |
|
| 364 | - : array(), |
|
| 365 | - 'payment_method_paths' => isset($setup_args['payment_method_paths']) |
|
| 366 | - ? (array)$setup_args['payment_method_paths'] |
|
| 367 | - : array(), |
|
| 368 | - 'default_terms' => isset($setup_args['default_terms']) |
|
| 369 | - ? (array)$setup_args['default_terms'] |
|
| 370 | - : array(), |
|
| 371 | - // if not empty, inserts a new table row after this plugin's row on the WP Plugins page |
|
| 372 | - // that can be used for adding upgrading/marketing info |
|
| 373 | - 'plugins_page_row' => isset($setup_args['plugins_page_row']) |
|
| 374 | - ? $setup_args['plugins_page_row'] |
|
| 375 | - : '', |
|
| 376 | - 'namespace' => isset( |
|
| 377 | - $setup_args['namespace'], |
|
| 378 | - $setup_args['namespace']['FQNS'], |
|
| 379 | - $setup_args['namespace']['DIR'] |
|
| 380 | - ) |
|
| 381 | - ? (array)$setup_args['namespace'] |
|
| 382 | - : array(), |
|
| 383 | - ); |
|
| 384 | - // if plugin_action_slug is NOT set, but an admin page path IS set, |
|
| 385 | - // then let's just use the plugin_slug since that will be used for linking to the admin page |
|
| 386 | - $addon_settings['plugin_action_slug'] = empty($addon_settings['plugin_action_slug']) |
|
| 387 | - && ! empty($addon_settings['admin_path']) |
|
| 388 | - ? $addon_settings['plugin_slug'] |
|
| 389 | - : $addon_settings['plugin_action_slug']; |
|
| 390 | - // full server path to main file (file loaded directly by WP) |
|
| 391 | - $addon_settings['plugin_basename'] = plugin_basename($addon_settings['main_file_path']); |
|
| 392 | - return $addon_settings; |
|
| 393 | - } |
|
| 255 | + /** |
|
| 256 | + * @param string $class_name |
|
| 257 | + * @param array $setup_args |
|
| 258 | + * @return array |
|
| 259 | + */ |
|
| 260 | + private static function _get_addon_settings($class_name, array $setup_args) |
|
| 261 | + { |
|
| 262 | + //setup $_settings array from incoming values. |
|
| 263 | + $addon_settings = array( |
|
| 264 | + // generated from the addon name, changes something like "calendar" to "EE_Calendar" |
|
| 265 | + 'class_name' => $class_name, |
|
| 266 | + // the addon slug for use in URLs, etc |
|
| 267 | + 'plugin_slug' => isset($setup_args['plugin_slug']) |
|
| 268 | + ? (string)$setup_args['plugin_slug'] |
|
| 269 | + : '', |
|
| 270 | + // page slug to be used when generating the "Settings" link on the WP plugin page |
|
| 271 | + 'plugin_action_slug' => isset($setup_args['plugin_action_slug']) |
|
| 272 | + ? (string)$setup_args['plugin_action_slug'] |
|
| 273 | + : '', |
|
| 274 | + // the "software" version for the addon |
|
| 275 | + 'version' => isset($setup_args['version']) |
|
| 276 | + ? (string)$setup_args['version'] |
|
| 277 | + : '', |
|
| 278 | + // the minimum version of EE Core that the addon will work with |
|
| 279 | + 'min_core_version' => isset($setup_args['min_core_version']) |
|
| 280 | + ? (string)$setup_args['min_core_version'] |
|
| 281 | + : '', |
|
| 282 | + // the minimum version of WordPress that the addon will work with |
|
| 283 | + 'min_wp_version' => isset($setup_args['min_wp_version']) |
|
| 284 | + ? (string)$setup_args['min_wp_version'] |
|
| 285 | + : EE_MIN_WP_VER_REQUIRED, |
|
| 286 | + // full server path to main file (file loaded directly by WP) |
|
| 287 | + 'main_file_path' => isset($setup_args['main_file_path']) |
|
| 288 | + ? (string)$setup_args['main_file_path'] |
|
| 289 | + : '', |
|
| 290 | + // path to folder containing files for integrating with the EE core admin and/or setting up EE admin pages |
|
| 291 | + 'admin_path' => isset($setup_args['admin_path']) |
|
| 292 | + ? (string)$setup_args['admin_path'] : '', |
|
| 293 | + // a method to be called when the EE Admin is first invoked, can be used for hooking into any admin page |
|
| 294 | + 'admin_callback' => isset($setup_args['admin_callback']) |
|
| 295 | + ? (string)$setup_args['admin_callback'] |
|
| 296 | + : '', |
|
| 297 | + // the section name for this addon's configuration settings section (defaults to "addons") |
|
| 298 | + 'config_section' => isset($setup_args['config_section']) |
|
| 299 | + ? (string)$setup_args['config_section'] |
|
| 300 | + : 'addons', |
|
| 301 | + // the class name for this addon's configuration settings object |
|
| 302 | + 'config_class' => isset($setup_args['config_class']) |
|
| 303 | + ? (string)$setup_args['config_class'] : '', |
|
| 304 | + //the name given to the config for this addons' configuration settings object (optional) |
|
| 305 | + 'config_name' => isset($setup_args['config_name']) |
|
| 306 | + ? (string)$setup_args['config_name'] : '', |
|
| 307 | + // an array of "class names" => "full server paths" for any classes that might be invoked by the addon |
|
| 308 | + 'autoloader_paths' => isset($setup_args['autoloader_paths']) |
|
| 309 | + ? (array)$setup_args['autoloader_paths'] |
|
| 310 | + : array(), |
|
| 311 | + // an array of "full server paths" for any folders containing classes that might be invoked by the addon |
|
| 312 | + 'autoloader_folders' => isset($setup_args['autoloader_folders']) |
|
| 313 | + ? (array)$setup_args['autoloader_folders'] |
|
| 314 | + : array(), |
|
| 315 | + // array of full server paths to any EE_DMS data migration scripts used by the addon |
|
| 316 | + 'dms_paths' => isset($setup_args['dms_paths']) |
|
| 317 | + ? (array)$setup_args['dms_paths'] |
|
| 318 | + : array(), |
|
| 319 | + // array of full server paths to any EED_Modules used by the addon |
|
| 320 | + 'module_paths' => isset($setup_args['module_paths']) |
|
| 321 | + ? (array)$setup_args['module_paths'] |
|
| 322 | + : array(), |
|
| 323 | + // array of full server paths to any EES_Shortcodes used by the addon |
|
| 324 | + 'shortcode_paths' => isset($setup_args['shortcode_paths']) |
|
| 325 | + ? (array)$setup_args['shortcode_paths'] |
|
| 326 | + : array(), |
|
| 327 | + 'shortcode_fqcns' => isset($setup_args['shortcode_fqcns']) |
|
| 328 | + ? (array) $setup_args['shortcode_fqcns'] |
|
| 329 | + : array(), |
|
| 330 | + // array of full server paths to any WP_Widgets used by the addon |
|
| 331 | + 'widget_paths' => isset($setup_args['widget_paths']) |
|
| 332 | + ? (array)$setup_args['widget_paths'] |
|
| 333 | + : array(), |
|
| 334 | + // array of PUE options used by the addon |
|
| 335 | + 'pue_options' => isset($setup_args['pue_options']) |
|
| 336 | + ? (array)$setup_args['pue_options'] |
|
| 337 | + : array(), |
|
| 338 | + 'message_types' => isset($setup_args['message_types']) |
|
| 339 | + ? (array)$setup_args['message_types'] |
|
| 340 | + : array(), |
|
| 341 | + 'capabilities' => isset($setup_args['capabilities']) |
|
| 342 | + ? (array)$setup_args['capabilities'] |
|
| 343 | + : array(), |
|
| 344 | + 'capability_maps' => isset($setup_args['capability_maps']) |
|
| 345 | + ? (array)$setup_args['capability_maps'] |
|
| 346 | + : array(), |
|
| 347 | + 'model_paths' => isset($setup_args['model_paths']) |
|
| 348 | + ? (array)$setup_args['model_paths'] |
|
| 349 | + : array(), |
|
| 350 | + 'class_paths' => isset($setup_args['class_paths']) |
|
| 351 | + ? (array)$setup_args['class_paths'] |
|
| 352 | + : array(), |
|
| 353 | + 'model_extension_paths' => isset($setup_args['model_extension_paths']) |
|
| 354 | + ? (array)$setup_args['model_extension_paths'] |
|
| 355 | + : array(), |
|
| 356 | + 'class_extension_paths' => isset($setup_args['class_extension_paths']) |
|
| 357 | + ? (array)$setup_args['class_extension_paths'] |
|
| 358 | + : array(), |
|
| 359 | + 'custom_post_types' => isset($setup_args['custom_post_types']) |
|
| 360 | + ? (array)$setup_args['custom_post_types'] |
|
| 361 | + : array(), |
|
| 362 | + 'custom_taxonomies' => isset($setup_args['custom_taxonomies']) |
|
| 363 | + ? (array)$setup_args['custom_taxonomies'] |
|
| 364 | + : array(), |
|
| 365 | + 'payment_method_paths' => isset($setup_args['payment_method_paths']) |
|
| 366 | + ? (array)$setup_args['payment_method_paths'] |
|
| 367 | + : array(), |
|
| 368 | + 'default_terms' => isset($setup_args['default_terms']) |
|
| 369 | + ? (array)$setup_args['default_terms'] |
|
| 370 | + : array(), |
|
| 371 | + // if not empty, inserts a new table row after this plugin's row on the WP Plugins page |
|
| 372 | + // that can be used for adding upgrading/marketing info |
|
| 373 | + 'plugins_page_row' => isset($setup_args['plugins_page_row']) |
|
| 374 | + ? $setup_args['plugins_page_row'] |
|
| 375 | + : '', |
|
| 376 | + 'namespace' => isset( |
|
| 377 | + $setup_args['namespace'], |
|
| 378 | + $setup_args['namespace']['FQNS'], |
|
| 379 | + $setup_args['namespace']['DIR'] |
|
| 380 | + ) |
|
| 381 | + ? (array)$setup_args['namespace'] |
|
| 382 | + : array(), |
|
| 383 | + ); |
|
| 384 | + // if plugin_action_slug is NOT set, but an admin page path IS set, |
|
| 385 | + // then let's just use the plugin_slug since that will be used for linking to the admin page |
|
| 386 | + $addon_settings['plugin_action_slug'] = empty($addon_settings['plugin_action_slug']) |
|
| 387 | + && ! empty($addon_settings['admin_path']) |
|
| 388 | + ? $addon_settings['plugin_slug'] |
|
| 389 | + : $addon_settings['plugin_action_slug']; |
|
| 390 | + // full server path to main file (file loaded directly by WP) |
|
| 391 | + $addon_settings['plugin_basename'] = plugin_basename($addon_settings['main_file_path']); |
|
| 392 | + return $addon_settings; |
|
| 393 | + } |
|
| 394 | 394 | |
| 395 | 395 | |
| 396 | - /** |
|
| 397 | - * @param string $addon_name |
|
| 398 | - * @param array $addon_settings |
|
| 399 | - * @return boolean |
|
| 400 | - */ |
|
| 401 | - private static function _addon_is_compatible($addon_name, array $addon_settings) |
|
| 402 | - { |
|
| 403 | - global $wp_version; |
|
| 404 | - $incompatibility_message = ''; |
|
| 405 | - //check whether this addon version is compatible with EE core |
|
| 406 | - if ( |
|
| 407 | - isset(EE_Register_Addon::$_incompatible_addons[$addon_name]) |
|
| 408 | - && ! self::_meets_min_core_version_requirement( |
|
| 409 | - EE_Register_Addon::$_incompatible_addons[$addon_name], |
|
| 410 | - $addon_settings['version'] |
|
| 411 | - ) |
|
| 412 | - ) { |
|
| 413 | - $incompatibility_message = sprintf( |
|
| 414 | - __( |
|
| 415 | - '%4$sIMPORTANT!%5$sThe Event Espresso "%1$s" addon is not compatible with this version of Event Espresso.%2$sPlease upgrade your "%1$s" addon to version %3$s or newer to resolve this issue.' |
|
| 416 | - ), |
|
| 417 | - $addon_name, |
|
| 418 | - '<br />', |
|
| 419 | - EE_Register_Addon::$_incompatible_addons[$addon_name], |
|
| 420 | - '<span style="font-weight: bold; color: #D54E21;">', |
|
| 421 | - '</span><br />' |
|
| 422 | - ); |
|
| 423 | - } else if ( |
|
| 424 | - ! self::_meets_min_core_version_requirement($addon_settings['min_core_version'], espresso_version()) |
|
| 425 | - ) { |
|
| 426 | - $incompatibility_message = sprintf( |
|
| 427 | - __( |
|
| 428 | - '%5$sIMPORTANT!%6$sThe Event Espresso "%1$s" addon requires Event Espresso Core version "%2$s" or higher in order to run.%4$sYour version of Event Espresso Core is currently at "%3$s". Please upgrade Event Espresso Core first and then re-activate "%1$s".', |
|
| 429 | - 'event_espresso' |
|
| 430 | - ), |
|
| 431 | - $addon_name, |
|
| 432 | - self::_effective_version($addon_settings['min_core_version']), |
|
| 433 | - self::_effective_version(espresso_version()), |
|
| 434 | - '<br />', |
|
| 435 | - '<span style="font-weight: bold; color: #D54E21;">', |
|
| 436 | - '</span><br />' |
|
| 437 | - ); |
|
| 438 | - } else if (version_compare($wp_version, $addon_settings['min_wp_version'], '<')) { |
|
| 439 | - $incompatibility_message = sprintf( |
|
| 440 | - __( |
|
| 441 | - '%4$sIMPORTANT!%5$sThe Event Espresso "%1$s" addon requires WordPress version "%2$s" or greater.%3$sPlease update your version of WordPress to use the "%1$s" addon and to keep your site secure.', |
|
| 442 | - 'event_espresso' |
|
| 443 | - ), |
|
| 444 | - $addon_name, |
|
| 445 | - $addon_settings['min_wp_version'], |
|
| 446 | - '<br />', |
|
| 447 | - '<span style="font-weight: bold; color: #D54E21;">', |
|
| 448 | - '</span><br />' |
|
| 449 | - ); |
|
| 450 | - } |
|
| 451 | - if (! empty($incompatibility_message)) { |
|
| 452 | - // remove 'activate' from the REQUEST |
|
| 453 | - // so WP doesn't erroneously tell the user the plugin activated fine when it didn't |
|
| 454 | - unset($_GET['activate'], $_REQUEST['activate']); |
|
| 455 | - if (current_user_can('activate_plugins')) { |
|
| 456 | - // show an error message indicating the plugin didn't activate properly |
|
| 457 | - EE_Error::add_error($incompatibility_message, __FILE__, __FUNCTION__, __LINE__); |
|
| 458 | - } |
|
| 459 | - // BAIL FROM THE ADDON REGISTRATION PROCESS |
|
| 460 | - return false; |
|
| 461 | - } |
|
| 462 | - // addon IS compatible |
|
| 463 | - return true; |
|
| 464 | - } |
|
| 396 | + /** |
|
| 397 | + * @param string $addon_name |
|
| 398 | + * @param array $addon_settings |
|
| 399 | + * @return boolean |
|
| 400 | + */ |
|
| 401 | + private static function _addon_is_compatible($addon_name, array $addon_settings) |
|
| 402 | + { |
|
| 403 | + global $wp_version; |
|
| 404 | + $incompatibility_message = ''; |
|
| 405 | + //check whether this addon version is compatible with EE core |
|
| 406 | + if ( |
|
| 407 | + isset(EE_Register_Addon::$_incompatible_addons[$addon_name]) |
|
| 408 | + && ! self::_meets_min_core_version_requirement( |
|
| 409 | + EE_Register_Addon::$_incompatible_addons[$addon_name], |
|
| 410 | + $addon_settings['version'] |
|
| 411 | + ) |
|
| 412 | + ) { |
|
| 413 | + $incompatibility_message = sprintf( |
|
| 414 | + __( |
|
| 415 | + '%4$sIMPORTANT!%5$sThe Event Espresso "%1$s" addon is not compatible with this version of Event Espresso.%2$sPlease upgrade your "%1$s" addon to version %3$s or newer to resolve this issue.' |
|
| 416 | + ), |
|
| 417 | + $addon_name, |
|
| 418 | + '<br />', |
|
| 419 | + EE_Register_Addon::$_incompatible_addons[$addon_name], |
|
| 420 | + '<span style="font-weight: bold; color: #D54E21;">', |
|
| 421 | + '</span><br />' |
|
| 422 | + ); |
|
| 423 | + } else if ( |
|
| 424 | + ! self::_meets_min_core_version_requirement($addon_settings['min_core_version'], espresso_version()) |
|
| 425 | + ) { |
|
| 426 | + $incompatibility_message = sprintf( |
|
| 427 | + __( |
|
| 428 | + '%5$sIMPORTANT!%6$sThe Event Espresso "%1$s" addon requires Event Espresso Core version "%2$s" or higher in order to run.%4$sYour version of Event Espresso Core is currently at "%3$s". Please upgrade Event Espresso Core first and then re-activate "%1$s".', |
|
| 429 | + 'event_espresso' |
|
| 430 | + ), |
|
| 431 | + $addon_name, |
|
| 432 | + self::_effective_version($addon_settings['min_core_version']), |
|
| 433 | + self::_effective_version(espresso_version()), |
|
| 434 | + '<br />', |
|
| 435 | + '<span style="font-weight: bold; color: #D54E21;">', |
|
| 436 | + '</span><br />' |
|
| 437 | + ); |
|
| 438 | + } else if (version_compare($wp_version, $addon_settings['min_wp_version'], '<')) { |
|
| 439 | + $incompatibility_message = sprintf( |
|
| 440 | + __( |
|
| 441 | + '%4$sIMPORTANT!%5$sThe Event Espresso "%1$s" addon requires WordPress version "%2$s" or greater.%3$sPlease update your version of WordPress to use the "%1$s" addon and to keep your site secure.', |
|
| 442 | + 'event_espresso' |
|
| 443 | + ), |
|
| 444 | + $addon_name, |
|
| 445 | + $addon_settings['min_wp_version'], |
|
| 446 | + '<br />', |
|
| 447 | + '<span style="font-weight: bold; color: #D54E21;">', |
|
| 448 | + '</span><br />' |
|
| 449 | + ); |
|
| 450 | + } |
|
| 451 | + if (! empty($incompatibility_message)) { |
|
| 452 | + // remove 'activate' from the REQUEST |
|
| 453 | + // so WP doesn't erroneously tell the user the plugin activated fine when it didn't |
|
| 454 | + unset($_GET['activate'], $_REQUEST['activate']); |
|
| 455 | + if (current_user_can('activate_plugins')) { |
|
| 456 | + // show an error message indicating the plugin didn't activate properly |
|
| 457 | + EE_Error::add_error($incompatibility_message, __FILE__, __FUNCTION__, __LINE__); |
|
| 458 | + } |
|
| 459 | + // BAIL FROM THE ADDON REGISTRATION PROCESS |
|
| 460 | + return false; |
|
| 461 | + } |
|
| 462 | + // addon IS compatible |
|
| 463 | + return true; |
|
| 464 | + } |
|
| 465 | 465 | |
| 466 | 466 | |
| 467 | - /** |
|
| 468 | - * if plugin update engine is being used for auto-updates, |
|
| 469 | - * then let's set that up now before going any further so that ALL addons can be updated |
|
| 470 | - * (not needed if PUE is not being used) |
|
| 471 | - * |
|
| 472 | - * @param string $addon_name |
|
| 473 | - * @param string $class_name |
|
| 474 | - * @param array $setup_args |
|
| 475 | - * @return void |
|
| 476 | - */ |
|
| 477 | - private static function _parse_pue_options($addon_name, $class_name, array $setup_args) |
|
| 478 | - { |
|
| 479 | - if (! empty($setup_args['pue_options'])) { |
|
| 480 | - self::$_settings[$addon_name]['pue_options'] = array( |
|
| 481 | - 'pue_plugin_slug' => isset($setup_args['pue_options']['pue_plugin_slug']) |
|
| 482 | - ? (string)$setup_args['pue_options']['pue_plugin_slug'] |
|
| 483 | - : 'espresso_' . strtolower($class_name), |
|
| 484 | - 'plugin_basename' => isset($setup_args['pue_options']['plugin_basename']) |
|
| 485 | - ? (string)$setup_args['pue_options']['plugin_basename'] |
|
| 486 | - : plugin_basename($setup_args['main_file_path']), |
|
| 487 | - 'checkPeriod' => isset($setup_args['pue_options']['checkPeriod']) |
|
| 488 | - ? (string)$setup_args['pue_options']['checkPeriod'] |
|
| 489 | - : '24', |
|
| 490 | - 'use_wp_update' => isset($setup_args['pue_options']['use_wp_update']) |
|
| 491 | - ? (string)$setup_args['pue_options']['use_wp_update'] |
|
| 492 | - : false, |
|
| 493 | - ); |
|
| 494 | - add_action( |
|
| 495 | - 'AHEE__EE_System__brew_espresso__after_pue_init', |
|
| 496 | - array('EE_Register_Addon', 'load_pue_update') |
|
| 497 | - ); |
|
| 498 | - } |
|
| 499 | - } |
|
| 467 | + /** |
|
| 468 | + * if plugin update engine is being used for auto-updates, |
|
| 469 | + * then let's set that up now before going any further so that ALL addons can be updated |
|
| 470 | + * (not needed if PUE is not being used) |
|
| 471 | + * |
|
| 472 | + * @param string $addon_name |
|
| 473 | + * @param string $class_name |
|
| 474 | + * @param array $setup_args |
|
| 475 | + * @return void |
|
| 476 | + */ |
|
| 477 | + private static function _parse_pue_options($addon_name, $class_name, array $setup_args) |
|
| 478 | + { |
|
| 479 | + if (! empty($setup_args['pue_options'])) { |
|
| 480 | + self::$_settings[$addon_name]['pue_options'] = array( |
|
| 481 | + 'pue_plugin_slug' => isset($setup_args['pue_options']['pue_plugin_slug']) |
|
| 482 | + ? (string)$setup_args['pue_options']['pue_plugin_slug'] |
|
| 483 | + : 'espresso_' . strtolower($class_name), |
|
| 484 | + 'plugin_basename' => isset($setup_args['pue_options']['plugin_basename']) |
|
| 485 | + ? (string)$setup_args['pue_options']['plugin_basename'] |
|
| 486 | + : plugin_basename($setup_args['main_file_path']), |
|
| 487 | + 'checkPeriod' => isset($setup_args['pue_options']['checkPeriod']) |
|
| 488 | + ? (string)$setup_args['pue_options']['checkPeriod'] |
|
| 489 | + : '24', |
|
| 490 | + 'use_wp_update' => isset($setup_args['pue_options']['use_wp_update']) |
|
| 491 | + ? (string)$setup_args['pue_options']['use_wp_update'] |
|
| 492 | + : false, |
|
| 493 | + ); |
|
| 494 | + add_action( |
|
| 495 | + 'AHEE__EE_System__brew_espresso__after_pue_init', |
|
| 496 | + array('EE_Register_Addon', 'load_pue_update') |
|
| 497 | + ); |
|
| 498 | + } |
|
| 499 | + } |
|
| 500 | 500 | |
| 501 | 501 | |
| 502 | - /** |
|
| 503 | - * register namespaces right away before any other files or classes get loaded, but AFTER the version checks |
|
| 504 | - * |
|
| 505 | - * @param array $addon_settings |
|
| 506 | - * @return void |
|
| 507 | - */ |
|
| 508 | - private static function _setup_namespaces(array $addon_settings) |
|
| 509 | - { |
|
| 510 | - // |
|
| 511 | - if ( |
|
| 512 | - isset( |
|
| 513 | - $addon_settings['namespace'], |
|
| 514 | - $addon_settings['namespace']['FQNS'], |
|
| 515 | - $addon_settings['namespace']['DIR'] |
|
| 516 | - ) |
|
| 517 | - ) { |
|
| 518 | - EE_Psr4AutoloaderInit::psr4_loader()->addNamespace( |
|
| 519 | - $addon_settings['namespace']['FQNS'], |
|
| 520 | - $addon_settings['namespace']['DIR'] |
|
| 521 | - ); |
|
| 522 | - } |
|
| 523 | - } |
|
| 502 | + /** |
|
| 503 | + * register namespaces right away before any other files or classes get loaded, but AFTER the version checks |
|
| 504 | + * |
|
| 505 | + * @param array $addon_settings |
|
| 506 | + * @return void |
|
| 507 | + */ |
|
| 508 | + private static function _setup_namespaces(array $addon_settings) |
|
| 509 | + { |
|
| 510 | + // |
|
| 511 | + if ( |
|
| 512 | + isset( |
|
| 513 | + $addon_settings['namespace'], |
|
| 514 | + $addon_settings['namespace']['FQNS'], |
|
| 515 | + $addon_settings['namespace']['DIR'] |
|
| 516 | + ) |
|
| 517 | + ) { |
|
| 518 | + EE_Psr4AutoloaderInit::psr4_loader()->addNamespace( |
|
| 519 | + $addon_settings['namespace']['FQNS'], |
|
| 520 | + $addon_settings['namespace']['DIR'] |
|
| 521 | + ); |
|
| 522 | + } |
|
| 523 | + } |
|
| 524 | 524 | |
| 525 | 525 | |
| 526 | - /** |
|
| 527 | - * @param string $addon_name |
|
| 528 | - * @param array $addon_settings |
|
| 529 | - * @return bool |
|
| 530 | - * @throws EE_Error |
|
| 531 | - * @throws InvalidArgumentException |
|
| 532 | - * @throws InvalidDataTypeException |
|
| 533 | - * @throws InvalidInterfaceException |
|
| 534 | - * @throws ReflectionException |
|
| 535 | - */ |
|
| 536 | - private static function _addon_activation($addon_name, array $addon_settings) |
|
| 537 | - { |
|
| 538 | - // this is an activation request |
|
| 539 | - if (did_action('activate_plugin')) { |
|
| 540 | - //to find if THIS is the addon that was activated, just check if we have already registered it or not |
|
| 541 | - //(as the newly-activated addon wasn't around the first time addons were registered). |
|
| 542 | - //Note: the presence of pue_options in the addon registration options will initialize the $_settings |
|
| 543 | - //property for the add-on, but the add-on is only partially initialized. Hence, the additional check. |
|
| 544 | - if (! isset(self::$_settings[$addon_name]) |
|
| 545 | - || (isset(self::$_settings[$addon_name]) |
|
| 546 | - && ! isset(self::$_settings[$addon_name]['class_name']) |
|
| 547 | - ) |
|
| 548 | - ) { |
|
| 549 | - self::$_settings[$addon_name] = $addon_settings; |
|
| 550 | - $addon = self::_load_and_init_addon_class($addon_name); |
|
| 551 | - $addon->set_activation_indicator_option(); |
|
| 552 | - // dont bother setting up the rest of the addon. |
|
| 553 | - // we know it was just activated and the request will end soon |
|
| 554 | - } |
|
| 555 | - return true; |
|
| 556 | - } |
|
| 557 | - // make sure this was called in the right place! |
|
| 558 | - if ( |
|
| 559 | - ! did_action('AHEE__EE_System__load_espresso_addons') |
|
| 560 | - || did_action('AHEE__EE_System___detect_if_activation_or_upgrade__begin') |
|
| 561 | - ) { |
|
| 562 | - EE_Error::doing_it_wrong( |
|
| 563 | - __METHOD__, |
|
| 564 | - sprintf( |
|
| 565 | - __( |
|
| 566 | - 'An attempt to register an EE_Addon named "%s" has failed because it was not registered at the correct time. Please use the "AHEE__EE_System__load_espresso_addons" hook to register addons.', |
|
| 567 | - 'event_espresso' |
|
| 568 | - ), |
|
| 569 | - $addon_name |
|
| 570 | - ), |
|
| 571 | - '4.3.0' |
|
| 572 | - ); |
|
| 573 | - } |
|
| 574 | - // make sure addon settings are set correctly without overwriting anything existing |
|
| 575 | - if (isset(self::$_settings[$addon_name])) { |
|
| 576 | - self::$_settings[$addon_name] += $addon_settings; |
|
| 577 | - } else { |
|
| 578 | - self::$_settings[$addon_name] = $addon_settings; |
|
| 579 | - } |
|
| 580 | - return false; |
|
| 581 | - } |
|
| 526 | + /** |
|
| 527 | + * @param string $addon_name |
|
| 528 | + * @param array $addon_settings |
|
| 529 | + * @return bool |
|
| 530 | + * @throws EE_Error |
|
| 531 | + * @throws InvalidArgumentException |
|
| 532 | + * @throws InvalidDataTypeException |
|
| 533 | + * @throws InvalidInterfaceException |
|
| 534 | + * @throws ReflectionException |
|
| 535 | + */ |
|
| 536 | + private static function _addon_activation($addon_name, array $addon_settings) |
|
| 537 | + { |
|
| 538 | + // this is an activation request |
|
| 539 | + if (did_action('activate_plugin')) { |
|
| 540 | + //to find if THIS is the addon that was activated, just check if we have already registered it or not |
|
| 541 | + //(as the newly-activated addon wasn't around the first time addons were registered). |
|
| 542 | + //Note: the presence of pue_options in the addon registration options will initialize the $_settings |
|
| 543 | + //property for the add-on, but the add-on is only partially initialized. Hence, the additional check. |
|
| 544 | + if (! isset(self::$_settings[$addon_name]) |
|
| 545 | + || (isset(self::$_settings[$addon_name]) |
|
| 546 | + && ! isset(self::$_settings[$addon_name]['class_name']) |
|
| 547 | + ) |
|
| 548 | + ) { |
|
| 549 | + self::$_settings[$addon_name] = $addon_settings; |
|
| 550 | + $addon = self::_load_and_init_addon_class($addon_name); |
|
| 551 | + $addon->set_activation_indicator_option(); |
|
| 552 | + // dont bother setting up the rest of the addon. |
|
| 553 | + // we know it was just activated and the request will end soon |
|
| 554 | + } |
|
| 555 | + return true; |
|
| 556 | + } |
|
| 557 | + // make sure this was called in the right place! |
|
| 558 | + if ( |
|
| 559 | + ! did_action('AHEE__EE_System__load_espresso_addons') |
|
| 560 | + || did_action('AHEE__EE_System___detect_if_activation_or_upgrade__begin') |
|
| 561 | + ) { |
|
| 562 | + EE_Error::doing_it_wrong( |
|
| 563 | + __METHOD__, |
|
| 564 | + sprintf( |
|
| 565 | + __( |
|
| 566 | + 'An attempt to register an EE_Addon named "%s" has failed because it was not registered at the correct time. Please use the "AHEE__EE_System__load_espresso_addons" hook to register addons.', |
|
| 567 | + 'event_espresso' |
|
| 568 | + ), |
|
| 569 | + $addon_name |
|
| 570 | + ), |
|
| 571 | + '4.3.0' |
|
| 572 | + ); |
|
| 573 | + } |
|
| 574 | + // make sure addon settings are set correctly without overwriting anything existing |
|
| 575 | + if (isset(self::$_settings[$addon_name])) { |
|
| 576 | + self::$_settings[$addon_name] += $addon_settings; |
|
| 577 | + } else { |
|
| 578 | + self::$_settings[$addon_name] = $addon_settings; |
|
| 579 | + } |
|
| 580 | + return false; |
|
| 581 | + } |
|
| 582 | 582 | |
| 583 | 583 | |
| 584 | - /** |
|
| 585 | - * @param string $addon_name |
|
| 586 | - * @return void |
|
| 587 | - * @throws EE_Error |
|
| 588 | - */ |
|
| 589 | - private static function _setup_autoloaders($addon_name) |
|
| 590 | - { |
|
| 591 | - if (! empty(self::$_settings[$addon_name]['autoloader_paths'])) { |
|
| 592 | - // setup autoloader for single file |
|
| 593 | - EEH_Autoloader::instance()->register_autoloader(self::$_settings[$addon_name]['autoloader_paths']); |
|
| 594 | - } |
|
| 595 | - // setup autoloaders for folders |
|
| 596 | - if (! empty(self::$_settings[$addon_name]['autoloader_folders'])) { |
|
| 597 | - foreach ((array)self::$_settings[$addon_name]['autoloader_folders'] as $autoloader_folder) { |
|
| 598 | - EEH_Autoloader::register_autoloaders_for_each_file_in_folder($autoloader_folder); |
|
| 599 | - } |
|
| 600 | - } |
|
| 601 | - } |
|
| 584 | + /** |
|
| 585 | + * @param string $addon_name |
|
| 586 | + * @return void |
|
| 587 | + * @throws EE_Error |
|
| 588 | + */ |
|
| 589 | + private static function _setup_autoloaders($addon_name) |
|
| 590 | + { |
|
| 591 | + if (! empty(self::$_settings[$addon_name]['autoloader_paths'])) { |
|
| 592 | + // setup autoloader for single file |
|
| 593 | + EEH_Autoloader::instance()->register_autoloader(self::$_settings[$addon_name]['autoloader_paths']); |
|
| 594 | + } |
|
| 595 | + // setup autoloaders for folders |
|
| 596 | + if (! empty(self::$_settings[$addon_name]['autoloader_folders'])) { |
|
| 597 | + foreach ((array)self::$_settings[$addon_name]['autoloader_folders'] as $autoloader_folder) { |
|
| 598 | + EEH_Autoloader::register_autoloaders_for_each_file_in_folder($autoloader_folder); |
|
| 599 | + } |
|
| 600 | + } |
|
| 601 | + } |
|
| 602 | 602 | |
| 603 | 603 | |
| 604 | - /** |
|
| 605 | - * register new models and extensions |
|
| 606 | - * |
|
| 607 | - * @param string $addon_name |
|
| 608 | - * @return void |
|
| 609 | - * @throws EE_Error |
|
| 610 | - */ |
|
| 611 | - private static function _register_models_and_extensions($addon_name) |
|
| 612 | - { |
|
| 613 | - // register new models |
|
| 614 | - if ( |
|
| 615 | - ! empty(self::$_settings[$addon_name]['model_paths']) |
|
| 616 | - || ! empty(self::$_settings[$addon_name]['class_paths']) |
|
| 617 | - ) { |
|
| 618 | - EE_Register_Model::register( |
|
| 619 | - $addon_name, |
|
| 620 | - array( |
|
| 621 | - 'model_paths' => self::$_settings[$addon_name]['model_paths'], |
|
| 622 | - 'class_paths' => self::$_settings[$addon_name]['class_paths'], |
|
| 623 | - ) |
|
| 624 | - ); |
|
| 625 | - } |
|
| 626 | - // register model extensions |
|
| 627 | - if ( |
|
| 628 | - ! empty(self::$_settings[$addon_name]['model_extension_paths']) |
|
| 629 | - || ! empty(self::$_settings[$addon_name]['class_extension_paths']) |
|
| 630 | - ) { |
|
| 631 | - EE_Register_Model_Extensions::register( |
|
| 632 | - $addon_name, |
|
| 633 | - array( |
|
| 634 | - 'model_extension_paths' => self::$_settings[$addon_name]['model_extension_paths'], |
|
| 635 | - 'class_extension_paths' => self::$_settings[$addon_name]['class_extension_paths'], |
|
| 636 | - ) |
|
| 637 | - ); |
|
| 638 | - } |
|
| 639 | - } |
|
| 604 | + /** |
|
| 605 | + * register new models and extensions |
|
| 606 | + * |
|
| 607 | + * @param string $addon_name |
|
| 608 | + * @return void |
|
| 609 | + * @throws EE_Error |
|
| 610 | + */ |
|
| 611 | + private static function _register_models_and_extensions($addon_name) |
|
| 612 | + { |
|
| 613 | + // register new models |
|
| 614 | + if ( |
|
| 615 | + ! empty(self::$_settings[$addon_name]['model_paths']) |
|
| 616 | + || ! empty(self::$_settings[$addon_name]['class_paths']) |
|
| 617 | + ) { |
|
| 618 | + EE_Register_Model::register( |
|
| 619 | + $addon_name, |
|
| 620 | + array( |
|
| 621 | + 'model_paths' => self::$_settings[$addon_name]['model_paths'], |
|
| 622 | + 'class_paths' => self::$_settings[$addon_name]['class_paths'], |
|
| 623 | + ) |
|
| 624 | + ); |
|
| 625 | + } |
|
| 626 | + // register model extensions |
|
| 627 | + if ( |
|
| 628 | + ! empty(self::$_settings[$addon_name]['model_extension_paths']) |
|
| 629 | + || ! empty(self::$_settings[$addon_name]['class_extension_paths']) |
|
| 630 | + ) { |
|
| 631 | + EE_Register_Model_Extensions::register( |
|
| 632 | + $addon_name, |
|
| 633 | + array( |
|
| 634 | + 'model_extension_paths' => self::$_settings[$addon_name]['model_extension_paths'], |
|
| 635 | + 'class_extension_paths' => self::$_settings[$addon_name]['class_extension_paths'], |
|
| 636 | + ) |
|
| 637 | + ); |
|
| 638 | + } |
|
| 639 | + } |
|
| 640 | 640 | |
| 641 | 641 | |
| 642 | - /** |
|
| 643 | - * @param string $addon_name |
|
| 644 | - * @return void |
|
| 645 | - * @throws EE_Error |
|
| 646 | - */ |
|
| 647 | - private static function _register_data_migration_scripts($addon_name) |
|
| 648 | - { |
|
| 649 | - // setup DMS |
|
| 650 | - if (! empty(self::$_settings[$addon_name]['dms_paths'])) { |
|
| 651 | - EE_Register_Data_Migration_Scripts::register( |
|
| 652 | - $addon_name, |
|
| 653 | - array('dms_paths' => self::$_settings[$addon_name]['dms_paths']) |
|
| 654 | - ); |
|
| 655 | - } |
|
| 656 | - } |
|
| 642 | + /** |
|
| 643 | + * @param string $addon_name |
|
| 644 | + * @return void |
|
| 645 | + * @throws EE_Error |
|
| 646 | + */ |
|
| 647 | + private static function _register_data_migration_scripts($addon_name) |
|
| 648 | + { |
|
| 649 | + // setup DMS |
|
| 650 | + if (! empty(self::$_settings[$addon_name]['dms_paths'])) { |
|
| 651 | + EE_Register_Data_Migration_Scripts::register( |
|
| 652 | + $addon_name, |
|
| 653 | + array('dms_paths' => self::$_settings[$addon_name]['dms_paths']) |
|
| 654 | + ); |
|
| 655 | + } |
|
| 656 | + } |
|
| 657 | 657 | |
| 658 | 658 | |
| 659 | - /** |
|
| 660 | - * @param string $addon_name |
|
| 661 | - * @return void |
|
| 662 | - * @throws EE_Error |
|
| 663 | - */ |
|
| 664 | - private static function _register_config($addon_name) |
|
| 665 | - { |
|
| 666 | - // if config_class is present let's register config. |
|
| 667 | - if (! empty(self::$_settings[$addon_name]['config_class'])) { |
|
| 668 | - EE_Register_Config::register( |
|
| 669 | - self::$_settings[$addon_name]['config_class'], |
|
| 670 | - array( |
|
| 671 | - 'config_section' => self::$_settings[$addon_name]['config_section'], |
|
| 672 | - 'config_name' => self::$_settings[$addon_name]['config_name'], |
|
| 673 | - ) |
|
| 674 | - ); |
|
| 675 | - } |
|
| 676 | - } |
|
| 659 | + /** |
|
| 660 | + * @param string $addon_name |
|
| 661 | + * @return void |
|
| 662 | + * @throws EE_Error |
|
| 663 | + */ |
|
| 664 | + private static function _register_config($addon_name) |
|
| 665 | + { |
|
| 666 | + // if config_class is present let's register config. |
|
| 667 | + if (! empty(self::$_settings[$addon_name]['config_class'])) { |
|
| 668 | + EE_Register_Config::register( |
|
| 669 | + self::$_settings[$addon_name]['config_class'], |
|
| 670 | + array( |
|
| 671 | + 'config_section' => self::$_settings[$addon_name]['config_section'], |
|
| 672 | + 'config_name' => self::$_settings[$addon_name]['config_name'], |
|
| 673 | + ) |
|
| 674 | + ); |
|
| 675 | + } |
|
| 676 | + } |
|
| 677 | 677 | |
| 678 | 678 | |
| 679 | - /** |
|
| 680 | - * @param string $addon_name |
|
| 681 | - * @return void |
|
| 682 | - * @throws EE_Error |
|
| 683 | - */ |
|
| 684 | - private static function _register_admin_pages($addon_name) |
|
| 685 | - { |
|
| 686 | - if (! empty(self::$_settings[$addon_name]['admin_path'])) { |
|
| 687 | - EE_Register_Admin_Page::register( |
|
| 688 | - $addon_name, |
|
| 689 | - array('page_path' => self::$_settings[$addon_name]['admin_path']) |
|
| 690 | - ); |
|
| 691 | - } |
|
| 692 | - } |
|
| 679 | + /** |
|
| 680 | + * @param string $addon_name |
|
| 681 | + * @return void |
|
| 682 | + * @throws EE_Error |
|
| 683 | + */ |
|
| 684 | + private static function _register_admin_pages($addon_name) |
|
| 685 | + { |
|
| 686 | + if (! empty(self::$_settings[$addon_name]['admin_path'])) { |
|
| 687 | + EE_Register_Admin_Page::register( |
|
| 688 | + $addon_name, |
|
| 689 | + array('page_path' => self::$_settings[$addon_name]['admin_path']) |
|
| 690 | + ); |
|
| 691 | + } |
|
| 692 | + } |
|
| 693 | 693 | |
| 694 | 694 | |
| 695 | - /** |
|
| 696 | - * @param string $addon_name |
|
| 697 | - * @return void |
|
| 698 | - * @throws EE_Error |
|
| 699 | - */ |
|
| 700 | - private static function _register_modules($addon_name) |
|
| 701 | - { |
|
| 702 | - if (! empty(self::$_settings[$addon_name]['module_paths'])) { |
|
| 703 | - EE_Register_Module::register( |
|
| 704 | - $addon_name, |
|
| 705 | - array('module_paths' => self::$_settings[$addon_name]['module_paths']) |
|
| 706 | - ); |
|
| 707 | - } |
|
| 708 | - } |
|
| 695 | + /** |
|
| 696 | + * @param string $addon_name |
|
| 697 | + * @return void |
|
| 698 | + * @throws EE_Error |
|
| 699 | + */ |
|
| 700 | + private static function _register_modules($addon_name) |
|
| 701 | + { |
|
| 702 | + if (! empty(self::$_settings[$addon_name]['module_paths'])) { |
|
| 703 | + EE_Register_Module::register( |
|
| 704 | + $addon_name, |
|
| 705 | + array('module_paths' => self::$_settings[$addon_name]['module_paths']) |
|
| 706 | + ); |
|
| 707 | + } |
|
| 708 | + } |
|
| 709 | 709 | |
| 710 | 710 | |
| 711 | - /** |
|
| 712 | - * @param string $addon_name |
|
| 713 | - * @return void |
|
| 714 | - * @throws EE_Error |
|
| 715 | - */ |
|
| 716 | - private static function _register_shortcodes($addon_name) |
|
| 717 | - { |
|
| 718 | - if (! empty(self::$_settings[$addon_name]['shortcode_paths']) |
|
| 719 | - || ! empty(self::$_settings[$addon_name]['shortcode_fqcns']) |
|
| 720 | - ) { |
|
| 721 | - EE_Register_Shortcode::register( |
|
| 722 | - $addon_name, |
|
| 723 | - array( |
|
| 724 | - 'shortcode_paths' => isset(self::$_settings[$addon_name]['shortcode_paths']) |
|
| 725 | - ? self::$_settings[$addon_name]['shortcode_paths'] |
|
| 726 | - : array(), |
|
| 727 | - 'shortcode_fqcns' => isset(self::$_settings[$addon_name]['shortcode_fqcns']) |
|
| 728 | - ? self::$_settings[$addon_name]['shortcode_fqcns'] |
|
| 729 | - : array() |
|
| 730 | - ) |
|
| 731 | - ); |
|
| 732 | - } |
|
| 733 | - } |
|
| 711 | + /** |
|
| 712 | + * @param string $addon_name |
|
| 713 | + * @return void |
|
| 714 | + * @throws EE_Error |
|
| 715 | + */ |
|
| 716 | + private static function _register_shortcodes($addon_name) |
|
| 717 | + { |
|
| 718 | + if (! empty(self::$_settings[$addon_name]['shortcode_paths']) |
|
| 719 | + || ! empty(self::$_settings[$addon_name]['shortcode_fqcns']) |
|
| 720 | + ) { |
|
| 721 | + EE_Register_Shortcode::register( |
|
| 722 | + $addon_name, |
|
| 723 | + array( |
|
| 724 | + 'shortcode_paths' => isset(self::$_settings[$addon_name]['shortcode_paths']) |
|
| 725 | + ? self::$_settings[$addon_name]['shortcode_paths'] |
|
| 726 | + : array(), |
|
| 727 | + 'shortcode_fqcns' => isset(self::$_settings[$addon_name]['shortcode_fqcns']) |
|
| 728 | + ? self::$_settings[$addon_name]['shortcode_fqcns'] |
|
| 729 | + : array() |
|
| 730 | + ) |
|
| 731 | + ); |
|
| 732 | + } |
|
| 733 | + } |
|
| 734 | 734 | |
| 735 | 735 | |
| 736 | - /** |
|
| 737 | - * @param string $addon_name |
|
| 738 | - * @return void |
|
| 739 | - * @throws EE_Error |
|
| 740 | - */ |
|
| 741 | - private static function _register_widgets($addon_name) |
|
| 742 | - { |
|
| 743 | - if (! empty(self::$_settings[$addon_name]['widget_paths'])) { |
|
| 744 | - EE_Register_Widget::register( |
|
| 745 | - $addon_name, |
|
| 746 | - array('widget_paths' => self::$_settings[$addon_name]['widget_paths']) |
|
| 747 | - ); |
|
| 748 | - } |
|
| 749 | - } |
|
| 736 | + /** |
|
| 737 | + * @param string $addon_name |
|
| 738 | + * @return void |
|
| 739 | + * @throws EE_Error |
|
| 740 | + */ |
|
| 741 | + private static function _register_widgets($addon_name) |
|
| 742 | + { |
|
| 743 | + if (! empty(self::$_settings[$addon_name]['widget_paths'])) { |
|
| 744 | + EE_Register_Widget::register( |
|
| 745 | + $addon_name, |
|
| 746 | + array('widget_paths' => self::$_settings[$addon_name]['widget_paths']) |
|
| 747 | + ); |
|
| 748 | + } |
|
| 749 | + } |
|
| 750 | 750 | |
| 751 | 751 | |
| 752 | - /** |
|
| 753 | - * @param string $addon_name |
|
| 754 | - * @return void |
|
| 755 | - * @throws EE_Error |
|
| 756 | - */ |
|
| 757 | - private static function _register_capabilities($addon_name) |
|
| 758 | - { |
|
| 759 | - if (! empty(self::$_settings[$addon_name]['capabilities'])) { |
|
| 760 | - EE_Register_Capabilities::register( |
|
| 761 | - $addon_name, |
|
| 762 | - array( |
|
| 763 | - 'capabilities' => self::$_settings[$addon_name]['capabilities'], |
|
| 764 | - 'capability_maps' => self::$_settings[$addon_name]['capability_maps'], |
|
| 765 | - ) |
|
| 766 | - ); |
|
| 767 | - } |
|
| 768 | - } |
|
| 752 | + /** |
|
| 753 | + * @param string $addon_name |
|
| 754 | + * @return void |
|
| 755 | + * @throws EE_Error |
|
| 756 | + */ |
|
| 757 | + private static function _register_capabilities($addon_name) |
|
| 758 | + { |
|
| 759 | + if (! empty(self::$_settings[$addon_name]['capabilities'])) { |
|
| 760 | + EE_Register_Capabilities::register( |
|
| 761 | + $addon_name, |
|
| 762 | + array( |
|
| 763 | + 'capabilities' => self::$_settings[$addon_name]['capabilities'], |
|
| 764 | + 'capability_maps' => self::$_settings[$addon_name]['capability_maps'], |
|
| 765 | + ) |
|
| 766 | + ); |
|
| 767 | + } |
|
| 768 | + } |
|
| 769 | 769 | |
| 770 | 770 | |
| 771 | - /** |
|
| 772 | - * @param string $addon_name |
|
| 773 | - * @return void |
|
| 774 | - * @throws EE_Error |
|
| 775 | - */ |
|
| 776 | - private static function _register_message_types($addon_name) |
|
| 777 | - { |
|
| 778 | - if (! empty(self::$_settings[$addon_name]['message_types'])) { |
|
| 779 | - add_action( |
|
| 780 | - 'EE_Brewing_Regular___messages_caf', |
|
| 781 | - array('EE_Register_Addon', 'register_message_types') |
|
| 782 | - ); |
|
| 783 | - } |
|
| 784 | - } |
|
| 771 | + /** |
|
| 772 | + * @param string $addon_name |
|
| 773 | + * @return void |
|
| 774 | + * @throws EE_Error |
|
| 775 | + */ |
|
| 776 | + private static function _register_message_types($addon_name) |
|
| 777 | + { |
|
| 778 | + if (! empty(self::$_settings[$addon_name]['message_types'])) { |
|
| 779 | + add_action( |
|
| 780 | + 'EE_Brewing_Regular___messages_caf', |
|
| 781 | + array('EE_Register_Addon', 'register_message_types') |
|
| 782 | + ); |
|
| 783 | + } |
|
| 784 | + } |
|
| 785 | 785 | |
| 786 | 786 | |
| 787 | - /** |
|
| 788 | - * @param string $addon_name |
|
| 789 | - * @return void |
|
| 790 | - * @throws EE_Error |
|
| 791 | - */ |
|
| 792 | - private static function _register_custom_post_types($addon_name) |
|
| 793 | - { |
|
| 794 | - if ( |
|
| 795 | - ! empty(self::$_settings[$addon_name]['custom_post_types']) |
|
| 796 | - || ! empty(self::$_settings[$addon_name]['custom_taxonomies']) |
|
| 797 | - ) { |
|
| 798 | - EE_Register_CPT::register( |
|
| 799 | - $addon_name, |
|
| 800 | - array( |
|
| 801 | - 'cpts' => self::$_settings[$addon_name]['custom_post_types'], |
|
| 802 | - 'cts' => self::$_settings[$addon_name]['custom_taxonomies'], |
|
| 803 | - 'default_terms' => self::$_settings[$addon_name]['default_terms'], |
|
| 804 | - ) |
|
| 805 | - ); |
|
| 806 | - } |
|
| 807 | - } |
|
| 787 | + /** |
|
| 788 | + * @param string $addon_name |
|
| 789 | + * @return void |
|
| 790 | + * @throws EE_Error |
|
| 791 | + */ |
|
| 792 | + private static function _register_custom_post_types($addon_name) |
|
| 793 | + { |
|
| 794 | + if ( |
|
| 795 | + ! empty(self::$_settings[$addon_name]['custom_post_types']) |
|
| 796 | + || ! empty(self::$_settings[$addon_name]['custom_taxonomies']) |
|
| 797 | + ) { |
|
| 798 | + EE_Register_CPT::register( |
|
| 799 | + $addon_name, |
|
| 800 | + array( |
|
| 801 | + 'cpts' => self::$_settings[$addon_name]['custom_post_types'], |
|
| 802 | + 'cts' => self::$_settings[$addon_name]['custom_taxonomies'], |
|
| 803 | + 'default_terms' => self::$_settings[$addon_name]['default_terms'], |
|
| 804 | + ) |
|
| 805 | + ); |
|
| 806 | + } |
|
| 807 | + } |
|
| 808 | 808 | |
| 809 | 809 | |
| 810 | - /** |
|
| 811 | - * @param string $addon_name |
|
| 812 | - * @return void |
|
| 813 | - * @throws DomainException |
|
| 814 | - * @throws EE_Error |
|
| 815 | - * @throws InvalidArgumentException |
|
| 816 | - * @throws InvalidDataTypeException |
|
| 817 | - * @throws InvalidInterfaceException |
|
| 818 | - */ |
|
| 819 | - private static function _register_payment_methods($addon_name) |
|
| 820 | - { |
|
| 821 | - if (! empty(self::$_settings[$addon_name]['payment_method_paths'])) { |
|
| 822 | - EE_Register_Payment_Method::register( |
|
| 823 | - $addon_name, |
|
| 824 | - array('payment_method_paths' => self::$_settings[$addon_name]['payment_method_paths']) |
|
| 825 | - ); |
|
| 826 | - } |
|
| 827 | - } |
|
| 810 | + /** |
|
| 811 | + * @param string $addon_name |
|
| 812 | + * @return void |
|
| 813 | + * @throws DomainException |
|
| 814 | + * @throws EE_Error |
|
| 815 | + * @throws InvalidArgumentException |
|
| 816 | + * @throws InvalidDataTypeException |
|
| 817 | + * @throws InvalidInterfaceException |
|
| 818 | + */ |
|
| 819 | + private static function _register_payment_methods($addon_name) |
|
| 820 | + { |
|
| 821 | + if (! empty(self::$_settings[$addon_name]['payment_method_paths'])) { |
|
| 822 | + EE_Register_Payment_Method::register( |
|
| 823 | + $addon_name, |
|
| 824 | + array('payment_method_paths' => self::$_settings[$addon_name]['payment_method_paths']) |
|
| 825 | + ); |
|
| 826 | + } |
|
| 827 | + } |
|
| 828 | 828 | |
| 829 | 829 | |
| 830 | - /** |
|
| 831 | - * Loads and instantiates the EE_Addon class and adds it onto the registry |
|
| 832 | - * |
|
| 833 | - * @param string $addon_name |
|
| 834 | - * @return EE_Addon |
|
| 835 | - * @throws ReflectionException |
|
| 836 | - * @throws EE_Error |
|
| 837 | - * @throws InvalidArgumentException |
|
| 838 | - * @throws InvalidInterfaceException |
|
| 839 | - * @throws InvalidDataTypeException |
|
| 840 | - */ |
|
| 841 | - private static function _load_and_init_addon_class($addon_name) |
|
| 842 | - { |
|
| 843 | - $addon = EE_Registry::instance()->load_addon( |
|
| 844 | - dirname(self::$_settings[ $addon_name ]['main_file_path']), |
|
| 845 | - self::$_settings[ $addon_name ]['class_name'] |
|
| 846 | - ); |
|
| 847 | - $addon->set_name($addon_name); |
|
| 848 | - $addon->set_plugin_slug(self::$_settings[$addon_name]['plugin_slug']); |
|
| 849 | - $addon->set_plugin_basename(self::$_settings[$addon_name]['plugin_basename']); |
|
| 850 | - $addon->set_main_plugin_file(self::$_settings[$addon_name]['main_file_path']); |
|
| 851 | - $addon->set_plugin_action_slug(self::$_settings[$addon_name]['plugin_action_slug']); |
|
| 852 | - $addon->set_plugins_page_row(self::$_settings[$addon_name]['plugins_page_row']); |
|
| 853 | - $addon->set_version(self::$_settings[$addon_name]['version']); |
|
| 854 | - $addon->set_min_core_version(self::_effective_version(self::$_settings[$addon_name]['min_core_version'])); |
|
| 855 | - $addon->set_config_section(self::$_settings[$addon_name]['config_section']); |
|
| 856 | - $addon->set_config_class(self::$_settings[$addon_name]['config_class']); |
|
| 857 | - $addon->set_config_name(self::$_settings[$addon_name]['config_name']); |
|
| 858 | - //unfortunately this can't be hooked in upon construction, because we don't have |
|
| 859 | - //the plugin mainfile's path upon construction. |
|
| 860 | - register_deactivation_hook($addon->get_main_plugin_file(), array($addon, 'deactivation')); |
|
| 861 | - // call any additional admin_callback functions during load_admin_controller hook |
|
| 862 | - if (! empty(self::$_settings[$addon_name]['admin_callback'])) { |
|
| 863 | - add_action( |
|
| 864 | - 'AHEE__EE_System__load_controllers__load_admin_controllers', |
|
| 865 | - array($addon, self::$_settings[$addon_name]['admin_callback']) |
|
| 866 | - ); |
|
| 867 | - } |
|
| 868 | - return $addon; |
|
| 869 | - } |
|
| 830 | + /** |
|
| 831 | + * Loads and instantiates the EE_Addon class and adds it onto the registry |
|
| 832 | + * |
|
| 833 | + * @param string $addon_name |
|
| 834 | + * @return EE_Addon |
|
| 835 | + * @throws ReflectionException |
|
| 836 | + * @throws EE_Error |
|
| 837 | + * @throws InvalidArgumentException |
|
| 838 | + * @throws InvalidInterfaceException |
|
| 839 | + * @throws InvalidDataTypeException |
|
| 840 | + */ |
|
| 841 | + private static function _load_and_init_addon_class($addon_name) |
|
| 842 | + { |
|
| 843 | + $addon = EE_Registry::instance()->load_addon( |
|
| 844 | + dirname(self::$_settings[ $addon_name ]['main_file_path']), |
|
| 845 | + self::$_settings[ $addon_name ]['class_name'] |
|
| 846 | + ); |
|
| 847 | + $addon->set_name($addon_name); |
|
| 848 | + $addon->set_plugin_slug(self::$_settings[$addon_name]['plugin_slug']); |
|
| 849 | + $addon->set_plugin_basename(self::$_settings[$addon_name]['plugin_basename']); |
|
| 850 | + $addon->set_main_plugin_file(self::$_settings[$addon_name]['main_file_path']); |
|
| 851 | + $addon->set_plugin_action_slug(self::$_settings[$addon_name]['plugin_action_slug']); |
|
| 852 | + $addon->set_plugins_page_row(self::$_settings[$addon_name]['plugins_page_row']); |
|
| 853 | + $addon->set_version(self::$_settings[$addon_name]['version']); |
|
| 854 | + $addon->set_min_core_version(self::_effective_version(self::$_settings[$addon_name]['min_core_version'])); |
|
| 855 | + $addon->set_config_section(self::$_settings[$addon_name]['config_section']); |
|
| 856 | + $addon->set_config_class(self::$_settings[$addon_name]['config_class']); |
|
| 857 | + $addon->set_config_name(self::$_settings[$addon_name]['config_name']); |
|
| 858 | + //unfortunately this can't be hooked in upon construction, because we don't have |
|
| 859 | + //the plugin mainfile's path upon construction. |
|
| 860 | + register_deactivation_hook($addon->get_main_plugin_file(), array($addon, 'deactivation')); |
|
| 861 | + // call any additional admin_callback functions during load_admin_controller hook |
|
| 862 | + if (! empty(self::$_settings[$addon_name]['admin_callback'])) { |
|
| 863 | + add_action( |
|
| 864 | + 'AHEE__EE_System__load_controllers__load_admin_controllers', |
|
| 865 | + array($addon, self::$_settings[$addon_name]['admin_callback']) |
|
| 866 | + ); |
|
| 867 | + } |
|
| 868 | + return $addon; |
|
| 869 | + } |
|
| 870 | 870 | |
| 871 | 871 | |
| 872 | - /** |
|
| 873 | - * load_pue_update - Update notifications |
|
| 874 | - * |
|
| 875 | - * @return void |
|
| 876 | - * @throws InvalidArgumentException |
|
| 877 | - * @throws InvalidDataTypeException |
|
| 878 | - * @throws InvalidInterfaceException |
|
| 879 | - */ |
|
| 880 | - public static function load_pue_update() |
|
| 881 | - { |
|
| 882 | - // load PUE client |
|
| 883 | - require_once EE_THIRD_PARTY . 'pue' . DS . 'pue-client.php'; |
|
| 884 | - // cycle thru settings |
|
| 885 | - foreach (self::$_settings as $settings) { |
|
| 886 | - if (! empty($settings['pue_options'])) { |
|
| 887 | - // initiate the class and start the plugin update engine! |
|
| 888 | - new PluginUpdateEngineChecker( |
|
| 889 | - // host file URL |
|
| 890 | - 'https://eventespresso.com', |
|
| 891 | - // plugin slug(s) |
|
| 892 | - array( |
|
| 893 | - 'premium' => array('p' => $settings['pue_options']['pue_plugin_slug']), |
|
| 894 | - 'prerelease' => array('beta' => $settings['pue_options']['pue_plugin_slug'] . '-pr'), |
|
| 895 | - ), |
|
| 896 | - // options |
|
| 897 | - array( |
|
| 898 | - 'apikey' => EE_Registry::instance()->NET_CFG->core->site_license_key, |
|
| 899 | - 'lang_domain' => 'event_espresso', |
|
| 900 | - 'checkPeriod' => $settings['pue_options']['checkPeriod'], |
|
| 901 | - 'option_key' => 'site_license_key', |
|
| 902 | - 'options_page_slug' => 'event_espresso', |
|
| 903 | - 'plugin_basename' => $settings['pue_options']['plugin_basename'], |
|
| 904 | - // if use_wp_update is TRUE it means you want FREE versions of the plugin to be updated from WP |
|
| 905 | - 'use_wp_update' => $settings['pue_options']['use_wp_update'], |
|
| 906 | - ) |
|
| 907 | - ); |
|
| 908 | - } |
|
| 909 | - } |
|
| 910 | - } |
|
| 872 | + /** |
|
| 873 | + * load_pue_update - Update notifications |
|
| 874 | + * |
|
| 875 | + * @return void |
|
| 876 | + * @throws InvalidArgumentException |
|
| 877 | + * @throws InvalidDataTypeException |
|
| 878 | + * @throws InvalidInterfaceException |
|
| 879 | + */ |
|
| 880 | + public static function load_pue_update() |
|
| 881 | + { |
|
| 882 | + // load PUE client |
|
| 883 | + require_once EE_THIRD_PARTY . 'pue' . DS . 'pue-client.php'; |
|
| 884 | + // cycle thru settings |
|
| 885 | + foreach (self::$_settings as $settings) { |
|
| 886 | + if (! empty($settings['pue_options'])) { |
|
| 887 | + // initiate the class and start the plugin update engine! |
|
| 888 | + new PluginUpdateEngineChecker( |
|
| 889 | + // host file URL |
|
| 890 | + 'https://eventespresso.com', |
|
| 891 | + // plugin slug(s) |
|
| 892 | + array( |
|
| 893 | + 'premium' => array('p' => $settings['pue_options']['pue_plugin_slug']), |
|
| 894 | + 'prerelease' => array('beta' => $settings['pue_options']['pue_plugin_slug'] . '-pr'), |
|
| 895 | + ), |
|
| 896 | + // options |
|
| 897 | + array( |
|
| 898 | + 'apikey' => EE_Registry::instance()->NET_CFG->core->site_license_key, |
|
| 899 | + 'lang_domain' => 'event_espresso', |
|
| 900 | + 'checkPeriod' => $settings['pue_options']['checkPeriod'], |
|
| 901 | + 'option_key' => 'site_license_key', |
|
| 902 | + 'options_page_slug' => 'event_espresso', |
|
| 903 | + 'plugin_basename' => $settings['pue_options']['plugin_basename'], |
|
| 904 | + // if use_wp_update is TRUE it means you want FREE versions of the plugin to be updated from WP |
|
| 905 | + 'use_wp_update' => $settings['pue_options']['use_wp_update'], |
|
| 906 | + ) |
|
| 907 | + ); |
|
| 908 | + } |
|
| 909 | + } |
|
| 910 | + } |
|
| 911 | 911 | |
| 912 | 912 | |
| 913 | - /** |
|
| 914 | - * Callback for EE_Brewing_Regular__messages_caf hook used to register message types. |
|
| 915 | - * |
|
| 916 | - * @since 4.4.0 |
|
| 917 | - * @return void |
|
| 918 | - * @throws EE_Error |
|
| 919 | - */ |
|
| 920 | - public static function register_message_types() |
|
| 921 | - { |
|
| 922 | - foreach (self::$_settings as $addon_name => $settings) { |
|
| 923 | - if (! empty($settings['message_types'])) { |
|
| 924 | - foreach ((array)$settings['message_types'] as $message_type => $message_type_settings) { |
|
| 925 | - EE_Register_Message_Type::register($message_type, $message_type_settings); |
|
| 926 | - } |
|
| 927 | - } |
|
| 928 | - } |
|
| 929 | - } |
|
| 913 | + /** |
|
| 914 | + * Callback for EE_Brewing_Regular__messages_caf hook used to register message types. |
|
| 915 | + * |
|
| 916 | + * @since 4.4.0 |
|
| 917 | + * @return void |
|
| 918 | + * @throws EE_Error |
|
| 919 | + */ |
|
| 920 | + public static function register_message_types() |
|
| 921 | + { |
|
| 922 | + foreach (self::$_settings as $addon_name => $settings) { |
|
| 923 | + if (! empty($settings['message_types'])) { |
|
| 924 | + foreach ((array)$settings['message_types'] as $message_type => $message_type_settings) { |
|
| 925 | + EE_Register_Message_Type::register($message_type, $message_type_settings); |
|
| 926 | + } |
|
| 927 | + } |
|
| 928 | + } |
|
| 929 | + } |
|
| 930 | 930 | |
| 931 | 931 | |
| 932 | - /** |
|
| 933 | - * This deregisters an addon that was previously registered with a specific addon_name. |
|
| 934 | - * |
|
| 935 | - * @since 4.3.0 |
|
| 936 | - * @param string $addon_name the name for the addon that was previously registered |
|
| 937 | - * @throws DomainException |
|
| 938 | - * @throws EE_Error |
|
| 939 | - * @throws InvalidArgumentException |
|
| 940 | - * @throws InvalidDataTypeException |
|
| 941 | - * @throws InvalidInterfaceException |
|
| 942 | - */ |
|
| 943 | - public static function deregister($addon_name = null) |
|
| 944 | - { |
|
| 945 | - if (isset(self::$_settings[$addon_name], self::$_settings[$addon_name]['class_name'])) { |
|
| 946 | - do_action('AHEE__EE_Register_Addon__deregister__before', $addon_name); |
|
| 947 | - $class_name = self::$_settings[$addon_name]['class_name']; |
|
| 948 | - if (! empty(self::$_settings[$addon_name]['dms_paths'])) { |
|
| 949 | - // setup DMS |
|
| 950 | - EE_Register_Data_Migration_Scripts::deregister($addon_name); |
|
| 951 | - } |
|
| 952 | - if (! empty(self::$_settings[$addon_name]['admin_path'])) { |
|
| 953 | - // register admin page |
|
| 954 | - EE_Register_Admin_Page::deregister($addon_name); |
|
| 955 | - } |
|
| 956 | - if (! empty(self::$_settings[$addon_name]['module_paths'])) { |
|
| 957 | - // add to list of modules to be registered |
|
| 958 | - EE_Register_Module::deregister($addon_name); |
|
| 959 | - } |
|
| 960 | - if (! empty(self::$_settings[$addon_name]['shortcode_paths']) |
|
| 961 | - || ! empty(self::$_settings[$addon_name]['shortcode_fqcns']) |
|
| 962 | - ) { |
|
| 963 | - // add to list of shortcodes to be registered |
|
| 964 | - EE_Register_Shortcode::deregister($addon_name); |
|
| 965 | - } |
|
| 966 | - if (! empty(self::$_settings[$addon_name]['config_class'])) { |
|
| 967 | - // if config_class present let's register config. |
|
| 968 | - EE_Register_Config::deregister(self::$_settings[$addon_name]['config_class']); |
|
| 969 | - } |
|
| 970 | - if (! empty(self::$_settings[$addon_name]['widget_paths'])) { |
|
| 971 | - // add to list of widgets to be registered |
|
| 972 | - EE_Register_Widget::deregister($addon_name); |
|
| 973 | - } |
|
| 974 | - if (! empty(self::$_settings[$addon_name]['model_paths']) |
|
| 975 | - || |
|
| 976 | - ! empty(self::$_settings[$addon_name]['class_paths']) |
|
| 977 | - ) { |
|
| 978 | - // add to list of shortcodes to be registered |
|
| 979 | - EE_Register_Model::deregister($addon_name); |
|
| 980 | - } |
|
| 981 | - if (! empty(self::$_settings[$addon_name]['model_extension_paths']) |
|
| 982 | - || |
|
| 983 | - ! empty(self::$_settings[$addon_name]['class_extension_paths']) |
|
| 984 | - ) { |
|
| 985 | - // add to list of shortcodes to be registered |
|
| 986 | - EE_Register_Model_Extensions::deregister($addon_name); |
|
| 987 | - } |
|
| 988 | - if (! empty(self::$_settings[$addon_name]['message_types'])) { |
|
| 989 | - foreach ((array)self::$_settings[$addon_name]['message_types'] as $message_type => $message_type_settings) { |
|
| 990 | - EE_Register_Message_Type::deregister($message_type); |
|
| 991 | - } |
|
| 992 | - } |
|
| 993 | - //deregister capabilities for addon |
|
| 994 | - if ( |
|
| 995 | - ! empty(self::$_settings[$addon_name]['capabilities']) |
|
| 996 | - || ! empty(self::$_settings[$addon_name]['capability_maps']) |
|
| 997 | - ) { |
|
| 998 | - EE_Register_Capabilities::deregister($addon_name); |
|
| 999 | - } |
|
| 1000 | - //deregister custom_post_types for addon |
|
| 1001 | - if (! empty(self::$_settings[$addon_name]['custom_post_types'])) { |
|
| 1002 | - EE_Register_CPT::deregister($addon_name); |
|
| 1003 | - } |
|
| 1004 | - if (! empty(self::$_settings[$addon_name]['payment_method_paths'])) { |
|
| 1005 | - EE_Register_Payment_Method::deregister($addon_name); |
|
| 1006 | - } |
|
| 1007 | - $addon = EE_Registry::instance()->getAddon($class_name); |
|
| 1008 | - if($addon instanceof EE_Addon) { |
|
| 1009 | - remove_action( |
|
| 1010 | - 'deactivate_' . $addon->get_main_plugin_file_basename(), |
|
| 1011 | - array($addon, 'deactivation') |
|
| 1012 | - ); |
|
| 1013 | - remove_action( |
|
| 1014 | - 'AHEE__EE_System__perform_activations_upgrades_and_migrations', |
|
| 1015 | - array($addon, 'initialize_db_if_no_migrations_required') |
|
| 1016 | - ); |
|
| 1017 | - //remove `after_registration` call |
|
| 1018 | - remove_action( |
|
| 1019 | - 'AHEE__EE_System__load_espresso_addons__complete', |
|
| 1020 | - array($addon, 'after_registration'), |
|
| 1021 | - 999 |
|
| 1022 | - ); |
|
| 1023 | - } |
|
| 1024 | - EE_Registry::instance()->removeAddon($class_name); |
|
| 1025 | - unset(self::$_settings[$addon_name]); |
|
| 932 | + /** |
|
| 933 | + * This deregisters an addon that was previously registered with a specific addon_name. |
|
| 934 | + * |
|
| 935 | + * @since 4.3.0 |
|
| 936 | + * @param string $addon_name the name for the addon that was previously registered |
|
| 937 | + * @throws DomainException |
|
| 938 | + * @throws EE_Error |
|
| 939 | + * @throws InvalidArgumentException |
|
| 940 | + * @throws InvalidDataTypeException |
|
| 941 | + * @throws InvalidInterfaceException |
|
| 942 | + */ |
|
| 943 | + public static function deregister($addon_name = null) |
|
| 944 | + { |
|
| 945 | + if (isset(self::$_settings[$addon_name], self::$_settings[$addon_name]['class_name'])) { |
|
| 946 | + do_action('AHEE__EE_Register_Addon__deregister__before', $addon_name); |
|
| 947 | + $class_name = self::$_settings[$addon_name]['class_name']; |
|
| 948 | + if (! empty(self::$_settings[$addon_name]['dms_paths'])) { |
|
| 949 | + // setup DMS |
|
| 950 | + EE_Register_Data_Migration_Scripts::deregister($addon_name); |
|
| 951 | + } |
|
| 952 | + if (! empty(self::$_settings[$addon_name]['admin_path'])) { |
|
| 953 | + // register admin page |
|
| 954 | + EE_Register_Admin_Page::deregister($addon_name); |
|
| 955 | + } |
|
| 956 | + if (! empty(self::$_settings[$addon_name]['module_paths'])) { |
|
| 957 | + // add to list of modules to be registered |
|
| 958 | + EE_Register_Module::deregister($addon_name); |
|
| 959 | + } |
|
| 960 | + if (! empty(self::$_settings[$addon_name]['shortcode_paths']) |
|
| 961 | + || ! empty(self::$_settings[$addon_name]['shortcode_fqcns']) |
|
| 962 | + ) { |
|
| 963 | + // add to list of shortcodes to be registered |
|
| 964 | + EE_Register_Shortcode::deregister($addon_name); |
|
| 965 | + } |
|
| 966 | + if (! empty(self::$_settings[$addon_name]['config_class'])) { |
|
| 967 | + // if config_class present let's register config. |
|
| 968 | + EE_Register_Config::deregister(self::$_settings[$addon_name]['config_class']); |
|
| 969 | + } |
|
| 970 | + if (! empty(self::$_settings[$addon_name]['widget_paths'])) { |
|
| 971 | + // add to list of widgets to be registered |
|
| 972 | + EE_Register_Widget::deregister($addon_name); |
|
| 973 | + } |
|
| 974 | + if (! empty(self::$_settings[$addon_name]['model_paths']) |
|
| 975 | + || |
|
| 976 | + ! empty(self::$_settings[$addon_name]['class_paths']) |
|
| 977 | + ) { |
|
| 978 | + // add to list of shortcodes to be registered |
|
| 979 | + EE_Register_Model::deregister($addon_name); |
|
| 980 | + } |
|
| 981 | + if (! empty(self::$_settings[$addon_name]['model_extension_paths']) |
|
| 982 | + || |
|
| 983 | + ! empty(self::$_settings[$addon_name]['class_extension_paths']) |
|
| 984 | + ) { |
|
| 985 | + // add to list of shortcodes to be registered |
|
| 986 | + EE_Register_Model_Extensions::deregister($addon_name); |
|
| 987 | + } |
|
| 988 | + if (! empty(self::$_settings[$addon_name]['message_types'])) { |
|
| 989 | + foreach ((array)self::$_settings[$addon_name]['message_types'] as $message_type => $message_type_settings) { |
|
| 990 | + EE_Register_Message_Type::deregister($message_type); |
|
| 991 | + } |
|
| 992 | + } |
|
| 993 | + //deregister capabilities for addon |
|
| 994 | + if ( |
|
| 995 | + ! empty(self::$_settings[$addon_name]['capabilities']) |
|
| 996 | + || ! empty(self::$_settings[$addon_name]['capability_maps']) |
|
| 997 | + ) { |
|
| 998 | + EE_Register_Capabilities::deregister($addon_name); |
|
| 999 | + } |
|
| 1000 | + //deregister custom_post_types for addon |
|
| 1001 | + if (! empty(self::$_settings[$addon_name]['custom_post_types'])) { |
|
| 1002 | + EE_Register_CPT::deregister($addon_name); |
|
| 1003 | + } |
|
| 1004 | + if (! empty(self::$_settings[$addon_name]['payment_method_paths'])) { |
|
| 1005 | + EE_Register_Payment_Method::deregister($addon_name); |
|
| 1006 | + } |
|
| 1007 | + $addon = EE_Registry::instance()->getAddon($class_name); |
|
| 1008 | + if($addon instanceof EE_Addon) { |
|
| 1009 | + remove_action( |
|
| 1010 | + 'deactivate_' . $addon->get_main_plugin_file_basename(), |
|
| 1011 | + array($addon, 'deactivation') |
|
| 1012 | + ); |
|
| 1013 | + remove_action( |
|
| 1014 | + 'AHEE__EE_System__perform_activations_upgrades_and_migrations', |
|
| 1015 | + array($addon, 'initialize_db_if_no_migrations_required') |
|
| 1016 | + ); |
|
| 1017 | + //remove `after_registration` call |
|
| 1018 | + remove_action( |
|
| 1019 | + 'AHEE__EE_System__load_espresso_addons__complete', |
|
| 1020 | + array($addon, 'after_registration'), |
|
| 1021 | + 999 |
|
| 1022 | + ); |
|
| 1023 | + } |
|
| 1024 | + EE_Registry::instance()->removeAddon($class_name); |
|
| 1025 | + unset(self::$_settings[$addon_name]); |
|
| 1026 | 1026 | |
| 1027 | - do_action('AHEE__EE_Register_Addon__deregister__after', $addon_name); |
|
| 1028 | - } |
|
| 1029 | - } |
|
| 1027 | + do_action('AHEE__EE_Register_Addon__deregister__after', $addon_name); |
|
| 1028 | + } |
|
| 1029 | + } |
|
| 1030 | 1030 | |
| 1031 | 1031 | |
| 1032 | 1032 | } |
@@ -68,15 +68,15 @@ discard block |
||
| 68 | 68 | // offsets: 0 . 1 . 2 . 3 . 4 |
| 69 | 69 | $version_parts = explode('.', $min_core_version); |
| 70 | 70 | //check they specified the micro version (after 2nd period) |
| 71 | - if (! isset($version_parts[2])) { |
|
| 71 | + if ( ! isset($version_parts[2])) { |
|
| 72 | 72 | $version_parts[2] = '0'; |
| 73 | 73 | } |
| 74 | 74 | //if they didn't specify the 'p', or 'rc' part. Just assume the lowest possible |
| 75 | 75 | //soon we can assume that's 'rc', but this current version is 'alpha' |
| 76 | - if (! isset($version_parts[3])) { |
|
| 76 | + if ( ! isset($version_parts[3])) { |
|
| 77 | 77 | $version_parts[3] = 'dev'; |
| 78 | 78 | } |
| 79 | - if (! isset($version_parts[4])) { |
|
| 79 | + if ( ! isset($version_parts[4])) { |
|
| 80 | 80 | $version_parts[4] = '000'; |
| 81 | 81 | } |
| 82 | 82 | return implode('.', $version_parts); |
@@ -145,7 +145,7 @@ discard block |
||
| 145 | 145 | // setup PUE |
| 146 | 146 | \EE_Register_Addon::_parse_pue_options($addon_name, $class_name, $setup_args); |
| 147 | 147 | // does this addon work with this version of core or WordPress ? |
| 148 | - if (! \EE_Register_Addon::_addon_is_compatible($addon_name, $addon_settings)) { |
|
| 148 | + if ( ! \EE_Register_Addon::_addon_is_compatible($addon_name, $addon_settings)) { |
|
| 149 | 149 | return; |
| 150 | 150 | } |
| 151 | 151 | // register namespaces |
@@ -204,7 +204,7 @@ discard block |
||
| 204 | 204 | ) |
| 205 | 205 | ); |
| 206 | 206 | } |
| 207 | - if (! isset($setup_args['main_file_path']) || empty($setup_args['main_file_path'])) { |
|
| 207 | + if ( ! isset($setup_args['main_file_path']) || empty($setup_args['main_file_path'])) { |
|
| 208 | 208 | throw new EE_Error( |
| 209 | 209 | sprintf( |
| 210 | 210 | __( |
@@ -248,7 +248,7 @@ discard block |
||
| 248 | 248 | // check if classname is fully qualified or is a legacy classname already prefixed with 'EE_' |
| 249 | 249 | return strpos($class_name, '\\') || strpos($class_name, 'EE_') === 0 |
| 250 | 250 | ? $class_name |
| 251 | - : 'EE_' . $class_name; |
|
| 251 | + : 'EE_'.$class_name; |
|
| 252 | 252 | } |
| 253 | 253 | |
| 254 | 254 | |
@@ -265,108 +265,108 @@ discard block |
||
| 265 | 265 | 'class_name' => $class_name, |
| 266 | 266 | // the addon slug for use in URLs, etc |
| 267 | 267 | 'plugin_slug' => isset($setup_args['plugin_slug']) |
| 268 | - ? (string)$setup_args['plugin_slug'] |
|
| 268 | + ? (string) $setup_args['plugin_slug'] |
|
| 269 | 269 | : '', |
| 270 | 270 | // page slug to be used when generating the "Settings" link on the WP plugin page |
| 271 | 271 | 'plugin_action_slug' => isset($setup_args['plugin_action_slug']) |
| 272 | - ? (string)$setup_args['plugin_action_slug'] |
|
| 272 | + ? (string) $setup_args['plugin_action_slug'] |
|
| 273 | 273 | : '', |
| 274 | 274 | // the "software" version for the addon |
| 275 | 275 | 'version' => isset($setup_args['version']) |
| 276 | - ? (string)$setup_args['version'] |
|
| 276 | + ? (string) $setup_args['version'] |
|
| 277 | 277 | : '', |
| 278 | 278 | // the minimum version of EE Core that the addon will work with |
| 279 | 279 | 'min_core_version' => isset($setup_args['min_core_version']) |
| 280 | - ? (string)$setup_args['min_core_version'] |
|
| 280 | + ? (string) $setup_args['min_core_version'] |
|
| 281 | 281 | : '', |
| 282 | 282 | // the minimum version of WordPress that the addon will work with |
| 283 | 283 | 'min_wp_version' => isset($setup_args['min_wp_version']) |
| 284 | - ? (string)$setup_args['min_wp_version'] |
|
| 284 | + ? (string) $setup_args['min_wp_version'] |
|
| 285 | 285 | : EE_MIN_WP_VER_REQUIRED, |
| 286 | 286 | // full server path to main file (file loaded directly by WP) |
| 287 | 287 | 'main_file_path' => isset($setup_args['main_file_path']) |
| 288 | - ? (string)$setup_args['main_file_path'] |
|
| 288 | + ? (string) $setup_args['main_file_path'] |
|
| 289 | 289 | : '', |
| 290 | 290 | // path to folder containing files for integrating with the EE core admin and/or setting up EE admin pages |
| 291 | 291 | 'admin_path' => isset($setup_args['admin_path']) |
| 292 | - ? (string)$setup_args['admin_path'] : '', |
|
| 292 | + ? (string) $setup_args['admin_path'] : '', |
|
| 293 | 293 | // a method to be called when the EE Admin is first invoked, can be used for hooking into any admin page |
| 294 | 294 | 'admin_callback' => isset($setup_args['admin_callback']) |
| 295 | - ? (string)$setup_args['admin_callback'] |
|
| 295 | + ? (string) $setup_args['admin_callback'] |
|
| 296 | 296 | : '', |
| 297 | 297 | // the section name for this addon's configuration settings section (defaults to "addons") |
| 298 | 298 | 'config_section' => isset($setup_args['config_section']) |
| 299 | - ? (string)$setup_args['config_section'] |
|
| 299 | + ? (string) $setup_args['config_section'] |
|
| 300 | 300 | : 'addons', |
| 301 | 301 | // the class name for this addon's configuration settings object |
| 302 | 302 | 'config_class' => isset($setup_args['config_class']) |
| 303 | - ? (string)$setup_args['config_class'] : '', |
|
| 303 | + ? (string) $setup_args['config_class'] : '', |
|
| 304 | 304 | //the name given to the config for this addons' configuration settings object (optional) |
| 305 | 305 | 'config_name' => isset($setup_args['config_name']) |
| 306 | - ? (string)$setup_args['config_name'] : '', |
|
| 306 | + ? (string) $setup_args['config_name'] : '', |
|
| 307 | 307 | // an array of "class names" => "full server paths" for any classes that might be invoked by the addon |
| 308 | 308 | 'autoloader_paths' => isset($setup_args['autoloader_paths']) |
| 309 | - ? (array)$setup_args['autoloader_paths'] |
|
| 309 | + ? (array) $setup_args['autoloader_paths'] |
|
| 310 | 310 | : array(), |
| 311 | 311 | // an array of "full server paths" for any folders containing classes that might be invoked by the addon |
| 312 | 312 | 'autoloader_folders' => isset($setup_args['autoloader_folders']) |
| 313 | - ? (array)$setup_args['autoloader_folders'] |
|
| 313 | + ? (array) $setup_args['autoloader_folders'] |
|
| 314 | 314 | : array(), |
| 315 | 315 | // array of full server paths to any EE_DMS data migration scripts used by the addon |
| 316 | 316 | 'dms_paths' => isset($setup_args['dms_paths']) |
| 317 | - ? (array)$setup_args['dms_paths'] |
|
| 317 | + ? (array) $setup_args['dms_paths'] |
|
| 318 | 318 | : array(), |
| 319 | 319 | // array of full server paths to any EED_Modules used by the addon |
| 320 | 320 | 'module_paths' => isset($setup_args['module_paths']) |
| 321 | - ? (array)$setup_args['module_paths'] |
|
| 321 | + ? (array) $setup_args['module_paths'] |
|
| 322 | 322 | : array(), |
| 323 | 323 | // array of full server paths to any EES_Shortcodes used by the addon |
| 324 | 324 | 'shortcode_paths' => isset($setup_args['shortcode_paths']) |
| 325 | - ? (array)$setup_args['shortcode_paths'] |
|
| 325 | + ? (array) $setup_args['shortcode_paths'] |
|
| 326 | 326 | : array(), |
| 327 | 327 | 'shortcode_fqcns' => isset($setup_args['shortcode_fqcns']) |
| 328 | 328 | ? (array) $setup_args['shortcode_fqcns'] |
| 329 | 329 | : array(), |
| 330 | 330 | // array of full server paths to any WP_Widgets used by the addon |
| 331 | 331 | 'widget_paths' => isset($setup_args['widget_paths']) |
| 332 | - ? (array)$setup_args['widget_paths'] |
|
| 332 | + ? (array) $setup_args['widget_paths'] |
|
| 333 | 333 | : array(), |
| 334 | 334 | // array of PUE options used by the addon |
| 335 | 335 | 'pue_options' => isset($setup_args['pue_options']) |
| 336 | - ? (array)$setup_args['pue_options'] |
|
| 336 | + ? (array) $setup_args['pue_options'] |
|
| 337 | 337 | : array(), |
| 338 | 338 | 'message_types' => isset($setup_args['message_types']) |
| 339 | - ? (array)$setup_args['message_types'] |
|
| 339 | + ? (array) $setup_args['message_types'] |
|
| 340 | 340 | : array(), |
| 341 | 341 | 'capabilities' => isset($setup_args['capabilities']) |
| 342 | - ? (array)$setup_args['capabilities'] |
|
| 342 | + ? (array) $setup_args['capabilities'] |
|
| 343 | 343 | : array(), |
| 344 | 344 | 'capability_maps' => isset($setup_args['capability_maps']) |
| 345 | - ? (array)$setup_args['capability_maps'] |
|
| 345 | + ? (array) $setup_args['capability_maps'] |
|
| 346 | 346 | : array(), |
| 347 | 347 | 'model_paths' => isset($setup_args['model_paths']) |
| 348 | - ? (array)$setup_args['model_paths'] |
|
| 348 | + ? (array) $setup_args['model_paths'] |
|
| 349 | 349 | : array(), |
| 350 | 350 | 'class_paths' => isset($setup_args['class_paths']) |
| 351 | - ? (array)$setup_args['class_paths'] |
|
| 351 | + ? (array) $setup_args['class_paths'] |
|
| 352 | 352 | : array(), |
| 353 | 353 | 'model_extension_paths' => isset($setup_args['model_extension_paths']) |
| 354 | - ? (array)$setup_args['model_extension_paths'] |
|
| 354 | + ? (array) $setup_args['model_extension_paths'] |
|
| 355 | 355 | : array(), |
| 356 | 356 | 'class_extension_paths' => isset($setup_args['class_extension_paths']) |
| 357 | - ? (array)$setup_args['class_extension_paths'] |
|
| 357 | + ? (array) $setup_args['class_extension_paths'] |
|
| 358 | 358 | : array(), |
| 359 | 359 | 'custom_post_types' => isset($setup_args['custom_post_types']) |
| 360 | - ? (array)$setup_args['custom_post_types'] |
|
| 360 | + ? (array) $setup_args['custom_post_types'] |
|
| 361 | 361 | : array(), |
| 362 | 362 | 'custom_taxonomies' => isset($setup_args['custom_taxonomies']) |
| 363 | - ? (array)$setup_args['custom_taxonomies'] |
|
| 363 | + ? (array) $setup_args['custom_taxonomies'] |
|
| 364 | 364 | : array(), |
| 365 | 365 | 'payment_method_paths' => isset($setup_args['payment_method_paths']) |
| 366 | - ? (array)$setup_args['payment_method_paths'] |
|
| 366 | + ? (array) $setup_args['payment_method_paths'] |
|
| 367 | 367 | : array(), |
| 368 | 368 | 'default_terms' => isset($setup_args['default_terms']) |
| 369 | - ? (array)$setup_args['default_terms'] |
|
| 369 | + ? (array) $setup_args['default_terms'] |
|
| 370 | 370 | : array(), |
| 371 | 371 | // if not empty, inserts a new table row after this plugin's row on the WP Plugins page |
| 372 | 372 | // that can be used for adding upgrading/marketing info |
@@ -378,7 +378,7 @@ discard block |
||
| 378 | 378 | $setup_args['namespace']['FQNS'], |
| 379 | 379 | $setup_args['namespace']['DIR'] |
| 380 | 380 | ) |
| 381 | - ? (array)$setup_args['namespace'] |
|
| 381 | + ? (array) $setup_args['namespace'] |
|
| 382 | 382 | : array(), |
| 383 | 383 | ); |
| 384 | 384 | // if plugin_action_slug is NOT set, but an admin page path IS set, |
@@ -448,7 +448,7 @@ discard block |
||
| 448 | 448 | '</span><br />' |
| 449 | 449 | ); |
| 450 | 450 | } |
| 451 | - if (! empty($incompatibility_message)) { |
|
| 451 | + if ( ! empty($incompatibility_message)) { |
|
| 452 | 452 | // remove 'activate' from the REQUEST |
| 453 | 453 | // so WP doesn't erroneously tell the user the plugin activated fine when it didn't |
| 454 | 454 | unset($_GET['activate'], $_REQUEST['activate']); |
@@ -476,19 +476,19 @@ discard block |
||
| 476 | 476 | */ |
| 477 | 477 | private static function _parse_pue_options($addon_name, $class_name, array $setup_args) |
| 478 | 478 | { |
| 479 | - if (! empty($setup_args['pue_options'])) { |
|
| 479 | + if ( ! empty($setup_args['pue_options'])) { |
|
| 480 | 480 | self::$_settings[$addon_name]['pue_options'] = array( |
| 481 | 481 | 'pue_plugin_slug' => isset($setup_args['pue_options']['pue_plugin_slug']) |
| 482 | - ? (string)$setup_args['pue_options']['pue_plugin_slug'] |
|
| 483 | - : 'espresso_' . strtolower($class_name), |
|
| 482 | + ? (string) $setup_args['pue_options']['pue_plugin_slug'] |
|
| 483 | + : 'espresso_'.strtolower($class_name), |
|
| 484 | 484 | 'plugin_basename' => isset($setup_args['pue_options']['plugin_basename']) |
| 485 | - ? (string)$setup_args['pue_options']['plugin_basename'] |
|
| 485 | + ? (string) $setup_args['pue_options']['plugin_basename'] |
|
| 486 | 486 | : plugin_basename($setup_args['main_file_path']), |
| 487 | 487 | 'checkPeriod' => isset($setup_args['pue_options']['checkPeriod']) |
| 488 | - ? (string)$setup_args['pue_options']['checkPeriod'] |
|
| 488 | + ? (string) $setup_args['pue_options']['checkPeriod'] |
|
| 489 | 489 | : '24', |
| 490 | 490 | 'use_wp_update' => isset($setup_args['pue_options']['use_wp_update']) |
| 491 | - ? (string)$setup_args['pue_options']['use_wp_update'] |
|
| 491 | + ? (string) $setup_args['pue_options']['use_wp_update'] |
|
| 492 | 492 | : false, |
| 493 | 493 | ); |
| 494 | 494 | add_action( |
@@ -541,7 +541,7 @@ discard block |
||
| 541 | 541 | //(as the newly-activated addon wasn't around the first time addons were registered). |
| 542 | 542 | //Note: the presence of pue_options in the addon registration options will initialize the $_settings |
| 543 | 543 | //property for the add-on, but the add-on is only partially initialized. Hence, the additional check. |
| 544 | - if (! isset(self::$_settings[$addon_name]) |
|
| 544 | + if ( ! isset(self::$_settings[$addon_name]) |
|
| 545 | 545 | || (isset(self::$_settings[$addon_name]) |
| 546 | 546 | && ! isset(self::$_settings[$addon_name]['class_name']) |
| 547 | 547 | ) |
@@ -588,13 +588,13 @@ discard block |
||
| 588 | 588 | */ |
| 589 | 589 | private static function _setup_autoloaders($addon_name) |
| 590 | 590 | { |
| 591 | - if (! empty(self::$_settings[$addon_name]['autoloader_paths'])) { |
|
| 591 | + if ( ! empty(self::$_settings[$addon_name]['autoloader_paths'])) { |
|
| 592 | 592 | // setup autoloader for single file |
| 593 | 593 | EEH_Autoloader::instance()->register_autoloader(self::$_settings[$addon_name]['autoloader_paths']); |
| 594 | 594 | } |
| 595 | 595 | // setup autoloaders for folders |
| 596 | - if (! empty(self::$_settings[$addon_name]['autoloader_folders'])) { |
|
| 597 | - foreach ((array)self::$_settings[$addon_name]['autoloader_folders'] as $autoloader_folder) { |
|
| 596 | + if ( ! empty(self::$_settings[$addon_name]['autoloader_folders'])) { |
|
| 597 | + foreach ((array) self::$_settings[$addon_name]['autoloader_folders'] as $autoloader_folder) { |
|
| 598 | 598 | EEH_Autoloader::register_autoloaders_for_each_file_in_folder($autoloader_folder); |
| 599 | 599 | } |
| 600 | 600 | } |
@@ -647,7 +647,7 @@ discard block |
||
| 647 | 647 | private static function _register_data_migration_scripts($addon_name) |
| 648 | 648 | { |
| 649 | 649 | // setup DMS |
| 650 | - if (! empty(self::$_settings[$addon_name]['dms_paths'])) { |
|
| 650 | + if ( ! empty(self::$_settings[$addon_name]['dms_paths'])) { |
|
| 651 | 651 | EE_Register_Data_Migration_Scripts::register( |
| 652 | 652 | $addon_name, |
| 653 | 653 | array('dms_paths' => self::$_settings[$addon_name]['dms_paths']) |
@@ -664,7 +664,7 @@ discard block |
||
| 664 | 664 | private static function _register_config($addon_name) |
| 665 | 665 | { |
| 666 | 666 | // if config_class is present let's register config. |
| 667 | - if (! empty(self::$_settings[$addon_name]['config_class'])) { |
|
| 667 | + if ( ! empty(self::$_settings[$addon_name]['config_class'])) { |
|
| 668 | 668 | EE_Register_Config::register( |
| 669 | 669 | self::$_settings[$addon_name]['config_class'], |
| 670 | 670 | array( |
@@ -683,7 +683,7 @@ discard block |
||
| 683 | 683 | */ |
| 684 | 684 | private static function _register_admin_pages($addon_name) |
| 685 | 685 | { |
| 686 | - if (! empty(self::$_settings[$addon_name]['admin_path'])) { |
|
| 686 | + if ( ! empty(self::$_settings[$addon_name]['admin_path'])) { |
|
| 687 | 687 | EE_Register_Admin_Page::register( |
| 688 | 688 | $addon_name, |
| 689 | 689 | array('page_path' => self::$_settings[$addon_name]['admin_path']) |
@@ -699,7 +699,7 @@ discard block |
||
| 699 | 699 | */ |
| 700 | 700 | private static function _register_modules($addon_name) |
| 701 | 701 | { |
| 702 | - if (! empty(self::$_settings[$addon_name]['module_paths'])) { |
|
| 702 | + if ( ! empty(self::$_settings[$addon_name]['module_paths'])) { |
|
| 703 | 703 | EE_Register_Module::register( |
| 704 | 704 | $addon_name, |
| 705 | 705 | array('module_paths' => self::$_settings[$addon_name]['module_paths']) |
@@ -715,7 +715,7 @@ discard block |
||
| 715 | 715 | */ |
| 716 | 716 | private static function _register_shortcodes($addon_name) |
| 717 | 717 | { |
| 718 | - if (! empty(self::$_settings[$addon_name]['shortcode_paths']) |
|
| 718 | + if ( ! empty(self::$_settings[$addon_name]['shortcode_paths']) |
|
| 719 | 719 | || ! empty(self::$_settings[$addon_name]['shortcode_fqcns']) |
| 720 | 720 | ) { |
| 721 | 721 | EE_Register_Shortcode::register( |
@@ -740,7 +740,7 @@ discard block |
||
| 740 | 740 | */ |
| 741 | 741 | private static function _register_widgets($addon_name) |
| 742 | 742 | { |
| 743 | - if (! empty(self::$_settings[$addon_name]['widget_paths'])) { |
|
| 743 | + if ( ! empty(self::$_settings[$addon_name]['widget_paths'])) { |
|
| 744 | 744 | EE_Register_Widget::register( |
| 745 | 745 | $addon_name, |
| 746 | 746 | array('widget_paths' => self::$_settings[$addon_name]['widget_paths']) |
@@ -756,7 +756,7 @@ discard block |
||
| 756 | 756 | */ |
| 757 | 757 | private static function _register_capabilities($addon_name) |
| 758 | 758 | { |
| 759 | - if (! empty(self::$_settings[$addon_name]['capabilities'])) { |
|
| 759 | + if ( ! empty(self::$_settings[$addon_name]['capabilities'])) { |
|
| 760 | 760 | EE_Register_Capabilities::register( |
| 761 | 761 | $addon_name, |
| 762 | 762 | array( |
@@ -775,7 +775,7 @@ discard block |
||
| 775 | 775 | */ |
| 776 | 776 | private static function _register_message_types($addon_name) |
| 777 | 777 | { |
| 778 | - if (! empty(self::$_settings[$addon_name]['message_types'])) { |
|
| 778 | + if ( ! empty(self::$_settings[$addon_name]['message_types'])) { |
|
| 779 | 779 | add_action( |
| 780 | 780 | 'EE_Brewing_Regular___messages_caf', |
| 781 | 781 | array('EE_Register_Addon', 'register_message_types') |
@@ -818,7 +818,7 @@ discard block |
||
| 818 | 818 | */ |
| 819 | 819 | private static function _register_payment_methods($addon_name) |
| 820 | 820 | { |
| 821 | - if (! empty(self::$_settings[$addon_name]['payment_method_paths'])) { |
|
| 821 | + if ( ! empty(self::$_settings[$addon_name]['payment_method_paths'])) { |
|
| 822 | 822 | EE_Register_Payment_Method::register( |
| 823 | 823 | $addon_name, |
| 824 | 824 | array('payment_method_paths' => self::$_settings[$addon_name]['payment_method_paths']) |
@@ -841,8 +841,8 @@ discard block |
||
| 841 | 841 | private static function _load_and_init_addon_class($addon_name) |
| 842 | 842 | { |
| 843 | 843 | $addon = EE_Registry::instance()->load_addon( |
| 844 | - dirname(self::$_settings[ $addon_name ]['main_file_path']), |
|
| 845 | - self::$_settings[ $addon_name ]['class_name'] |
|
| 844 | + dirname(self::$_settings[$addon_name]['main_file_path']), |
|
| 845 | + self::$_settings[$addon_name]['class_name'] |
|
| 846 | 846 | ); |
| 847 | 847 | $addon->set_name($addon_name); |
| 848 | 848 | $addon->set_plugin_slug(self::$_settings[$addon_name]['plugin_slug']); |
@@ -859,7 +859,7 @@ discard block |
||
| 859 | 859 | //the plugin mainfile's path upon construction. |
| 860 | 860 | register_deactivation_hook($addon->get_main_plugin_file(), array($addon, 'deactivation')); |
| 861 | 861 | // call any additional admin_callback functions during load_admin_controller hook |
| 862 | - if (! empty(self::$_settings[$addon_name]['admin_callback'])) { |
|
| 862 | + if ( ! empty(self::$_settings[$addon_name]['admin_callback'])) { |
|
| 863 | 863 | add_action( |
| 864 | 864 | 'AHEE__EE_System__load_controllers__load_admin_controllers', |
| 865 | 865 | array($addon, self::$_settings[$addon_name]['admin_callback']) |
@@ -880,10 +880,10 @@ discard block |
||
| 880 | 880 | public static function load_pue_update() |
| 881 | 881 | { |
| 882 | 882 | // load PUE client |
| 883 | - require_once EE_THIRD_PARTY . 'pue' . DS . 'pue-client.php'; |
|
| 883 | + require_once EE_THIRD_PARTY.'pue'.DS.'pue-client.php'; |
|
| 884 | 884 | // cycle thru settings |
| 885 | 885 | foreach (self::$_settings as $settings) { |
| 886 | - if (! empty($settings['pue_options'])) { |
|
| 886 | + if ( ! empty($settings['pue_options'])) { |
|
| 887 | 887 | // initiate the class and start the plugin update engine! |
| 888 | 888 | new PluginUpdateEngineChecker( |
| 889 | 889 | // host file URL |
@@ -891,7 +891,7 @@ discard block |
||
| 891 | 891 | // plugin slug(s) |
| 892 | 892 | array( |
| 893 | 893 | 'premium' => array('p' => $settings['pue_options']['pue_plugin_slug']), |
| 894 | - 'prerelease' => array('beta' => $settings['pue_options']['pue_plugin_slug'] . '-pr'), |
|
| 894 | + 'prerelease' => array('beta' => $settings['pue_options']['pue_plugin_slug'].'-pr'), |
|
| 895 | 895 | ), |
| 896 | 896 | // options |
| 897 | 897 | array( |
@@ -920,8 +920,8 @@ discard block |
||
| 920 | 920 | public static function register_message_types() |
| 921 | 921 | { |
| 922 | 922 | foreach (self::$_settings as $addon_name => $settings) { |
| 923 | - if (! empty($settings['message_types'])) { |
|
| 924 | - foreach ((array)$settings['message_types'] as $message_type => $message_type_settings) { |
|
| 923 | + if ( ! empty($settings['message_types'])) { |
|
| 924 | + foreach ((array) $settings['message_types'] as $message_type => $message_type_settings) { |
|
| 925 | 925 | EE_Register_Message_Type::register($message_type, $message_type_settings); |
| 926 | 926 | } |
| 927 | 927 | } |
@@ -945,48 +945,48 @@ discard block |
||
| 945 | 945 | if (isset(self::$_settings[$addon_name], self::$_settings[$addon_name]['class_name'])) { |
| 946 | 946 | do_action('AHEE__EE_Register_Addon__deregister__before', $addon_name); |
| 947 | 947 | $class_name = self::$_settings[$addon_name]['class_name']; |
| 948 | - if (! empty(self::$_settings[$addon_name]['dms_paths'])) { |
|
| 948 | + if ( ! empty(self::$_settings[$addon_name]['dms_paths'])) { |
|
| 949 | 949 | // setup DMS |
| 950 | 950 | EE_Register_Data_Migration_Scripts::deregister($addon_name); |
| 951 | 951 | } |
| 952 | - if (! empty(self::$_settings[$addon_name]['admin_path'])) { |
|
| 952 | + if ( ! empty(self::$_settings[$addon_name]['admin_path'])) { |
|
| 953 | 953 | // register admin page |
| 954 | 954 | EE_Register_Admin_Page::deregister($addon_name); |
| 955 | 955 | } |
| 956 | - if (! empty(self::$_settings[$addon_name]['module_paths'])) { |
|
| 956 | + if ( ! empty(self::$_settings[$addon_name]['module_paths'])) { |
|
| 957 | 957 | // add to list of modules to be registered |
| 958 | 958 | EE_Register_Module::deregister($addon_name); |
| 959 | 959 | } |
| 960 | - if (! empty(self::$_settings[$addon_name]['shortcode_paths']) |
|
| 960 | + if ( ! empty(self::$_settings[$addon_name]['shortcode_paths']) |
|
| 961 | 961 | || ! empty(self::$_settings[$addon_name]['shortcode_fqcns']) |
| 962 | 962 | ) { |
| 963 | 963 | // add to list of shortcodes to be registered |
| 964 | 964 | EE_Register_Shortcode::deregister($addon_name); |
| 965 | 965 | } |
| 966 | - if (! empty(self::$_settings[$addon_name]['config_class'])) { |
|
| 966 | + if ( ! empty(self::$_settings[$addon_name]['config_class'])) { |
|
| 967 | 967 | // if config_class present let's register config. |
| 968 | 968 | EE_Register_Config::deregister(self::$_settings[$addon_name]['config_class']); |
| 969 | 969 | } |
| 970 | - if (! empty(self::$_settings[$addon_name]['widget_paths'])) { |
|
| 970 | + if ( ! empty(self::$_settings[$addon_name]['widget_paths'])) { |
|
| 971 | 971 | // add to list of widgets to be registered |
| 972 | 972 | EE_Register_Widget::deregister($addon_name); |
| 973 | 973 | } |
| 974 | - if (! empty(self::$_settings[$addon_name]['model_paths']) |
|
| 974 | + if ( ! empty(self::$_settings[$addon_name]['model_paths']) |
|
| 975 | 975 | || |
| 976 | 976 | ! empty(self::$_settings[$addon_name]['class_paths']) |
| 977 | 977 | ) { |
| 978 | 978 | // add to list of shortcodes to be registered |
| 979 | 979 | EE_Register_Model::deregister($addon_name); |
| 980 | 980 | } |
| 981 | - if (! empty(self::$_settings[$addon_name]['model_extension_paths']) |
|
| 981 | + if ( ! empty(self::$_settings[$addon_name]['model_extension_paths']) |
|
| 982 | 982 | || |
| 983 | 983 | ! empty(self::$_settings[$addon_name]['class_extension_paths']) |
| 984 | 984 | ) { |
| 985 | 985 | // add to list of shortcodes to be registered |
| 986 | 986 | EE_Register_Model_Extensions::deregister($addon_name); |
| 987 | 987 | } |
| 988 | - if (! empty(self::$_settings[$addon_name]['message_types'])) { |
|
| 989 | - foreach ((array)self::$_settings[$addon_name]['message_types'] as $message_type => $message_type_settings) { |
|
| 988 | + if ( ! empty(self::$_settings[$addon_name]['message_types'])) { |
|
| 989 | + foreach ((array) self::$_settings[$addon_name]['message_types'] as $message_type => $message_type_settings) { |
|
| 990 | 990 | EE_Register_Message_Type::deregister($message_type); |
| 991 | 991 | } |
| 992 | 992 | } |
@@ -998,16 +998,16 @@ discard block |
||
| 998 | 998 | EE_Register_Capabilities::deregister($addon_name); |
| 999 | 999 | } |
| 1000 | 1000 | //deregister custom_post_types for addon |
| 1001 | - if (! empty(self::$_settings[$addon_name]['custom_post_types'])) { |
|
| 1001 | + if ( ! empty(self::$_settings[$addon_name]['custom_post_types'])) { |
|
| 1002 | 1002 | EE_Register_CPT::deregister($addon_name); |
| 1003 | 1003 | } |
| 1004 | - if (! empty(self::$_settings[$addon_name]['payment_method_paths'])) { |
|
| 1004 | + if ( ! empty(self::$_settings[$addon_name]['payment_method_paths'])) { |
|
| 1005 | 1005 | EE_Register_Payment_Method::deregister($addon_name); |
| 1006 | 1006 | } |
| 1007 | 1007 | $addon = EE_Registry::instance()->getAddon($class_name); |
| 1008 | - if($addon instanceof EE_Addon) { |
|
| 1008 | + if ($addon instanceof EE_Addon) { |
|
| 1009 | 1009 | remove_action( |
| 1010 | - 'deactivate_' . $addon->get_main_plugin_file_basename(), |
|
| 1010 | + 'deactivate_'.$addon->get_main_plugin_file_basename(), |
|
| 1011 | 1011 | array($addon, 'deactivation') |
| 1012 | 1012 | ); |
| 1013 | 1013 | remove_action( |
@@ -22,1584 +22,1584 @@ |
||
| 22 | 22 | class EE_Registry implements ResettableInterface |
| 23 | 23 | { |
| 24 | 24 | |
| 25 | - /** |
|
| 26 | - * @var EE_Registry $_instance |
|
| 27 | - */ |
|
| 28 | - private static $_instance; |
|
| 29 | - |
|
| 30 | - /** |
|
| 31 | - * @var EE_Dependency_Map $_dependency_map |
|
| 32 | - */ |
|
| 33 | - protected $_dependency_map; |
|
| 34 | - |
|
| 35 | - /** |
|
| 36 | - * @var array $_class_abbreviations |
|
| 37 | - */ |
|
| 38 | - protected $_class_abbreviations = array(); |
|
| 39 | - |
|
| 40 | - /** |
|
| 41 | - * @var CommandBusInterface $BUS |
|
| 42 | - */ |
|
| 43 | - public $BUS; |
|
| 44 | - |
|
| 45 | - /** |
|
| 46 | - * @var EE_Cart $CART |
|
| 47 | - */ |
|
| 48 | - public $CART; |
|
| 49 | - |
|
| 50 | - /** |
|
| 51 | - * @var EE_Config $CFG |
|
| 52 | - */ |
|
| 53 | - public $CFG; |
|
| 54 | - |
|
| 55 | - /** |
|
| 56 | - * @var EE_Network_Config $NET_CFG |
|
| 57 | - */ |
|
| 58 | - public $NET_CFG; |
|
| 59 | - |
|
| 60 | - /** |
|
| 61 | - * StdClass object for storing library classes in |
|
| 62 | - * |
|
| 63 | - * @var StdClass $LIB |
|
| 64 | - */ |
|
| 65 | - public $LIB; |
|
| 66 | - |
|
| 67 | - /** |
|
| 68 | - * @var EE_Request_Handler $REQ |
|
| 69 | - */ |
|
| 70 | - public $REQ; |
|
| 71 | - |
|
| 72 | - /** |
|
| 73 | - * @var EE_Session $SSN |
|
| 74 | - */ |
|
| 75 | - public $SSN; |
|
| 76 | - |
|
| 77 | - /** |
|
| 78 | - * @since 4.5.0 |
|
| 79 | - * @var EE_Capabilities $CAP |
|
| 80 | - */ |
|
| 81 | - public $CAP; |
|
| 82 | - |
|
| 83 | - /** |
|
| 84 | - * @since 4.9.0 |
|
| 85 | - * @var EE_Message_Resource_Manager $MRM |
|
| 86 | - */ |
|
| 87 | - public $MRM; |
|
| 88 | - |
|
| 89 | - |
|
| 90 | - /** |
|
| 91 | - * @var Registry $AssetsRegistry |
|
| 92 | - */ |
|
| 93 | - public $AssetsRegistry; |
|
| 94 | - |
|
| 95 | - /** |
|
| 96 | - * StdClass object for holding addons which have registered themselves to work with EE core |
|
| 97 | - * |
|
| 98 | - * @var EE_Addon[] $addons |
|
| 99 | - */ |
|
| 100 | - public $addons; |
|
| 101 | - |
|
| 102 | - /** |
|
| 103 | - * keys are 'short names' (eg Event), values are class names (eg 'EEM_Event') |
|
| 104 | - * |
|
| 105 | - * @var EEM_Base[] $models |
|
| 106 | - */ |
|
| 107 | - public $models = array(); |
|
| 108 | - |
|
| 109 | - /** |
|
| 110 | - * @var EED_Module[] $modules |
|
| 111 | - */ |
|
| 112 | - public $modules; |
|
| 113 | - |
|
| 114 | - /** |
|
| 115 | - * @var EES_Shortcode[] $shortcodes |
|
| 116 | - */ |
|
| 117 | - public $shortcodes; |
|
| 118 | - |
|
| 119 | - /** |
|
| 120 | - * @var WP_Widget[] $widgets |
|
| 121 | - */ |
|
| 122 | - public $widgets; |
|
| 123 | - |
|
| 124 | - /** |
|
| 125 | - * this is an array of all implemented model names (i.e. not the parent abstract models, or models |
|
| 126 | - * which don't actually fetch items from the DB in the normal way (ie, are not children of EEM_Base)). |
|
| 127 | - * Keys are model "short names" (eg "Event") as used in model relations, and values are |
|
| 128 | - * classnames (eg "EEM_Event") |
|
| 129 | - * |
|
| 130 | - * @var array $non_abstract_db_models |
|
| 131 | - */ |
|
| 132 | - public $non_abstract_db_models = array(); |
|
| 133 | - |
|
| 134 | - |
|
| 135 | - /** |
|
| 136 | - * internationalization for JS strings |
|
| 137 | - * usage: EE_Registry::i18n_js_strings['string_key'] = esc_html__( 'string to translate.', 'event_espresso' ); |
|
| 138 | - * in js file: var translatedString = eei18n.string_key; |
|
| 139 | - * |
|
| 140 | - * @var array $i18n_js_strings |
|
| 141 | - */ |
|
| 142 | - public static $i18n_js_strings = array(); |
|
| 143 | - |
|
| 144 | - |
|
| 145 | - /** |
|
| 146 | - * $main_file - path to espresso.php |
|
| 147 | - * |
|
| 148 | - * @var array $main_file |
|
| 149 | - */ |
|
| 150 | - public $main_file; |
|
| 151 | - |
|
| 152 | - /** |
|
| 153 | - * array of ReflectionClass objects where the key is the class name |
|
| 154 | - * |
|
| 155 | - * @var ReflectionClass[] $_reflectors |
|
| 156 | - */ |
|
| 157 | - public $_reflectors; |
|
| 158 | - |
|
| 159 | - /** |
|
| 160 | - * boolean flag to indicate whether or not to load/save dependencies from/to the cache |
|
| 161 | - * |
|
| 162 | - * @var boolean $_cache_on |
|
| 163 | - */ |
|
| 164 | - protected $_cache_on = true; |
|
| 165 | - |
|
| 166 | - |
|
| 167 | - |
|
| 168 | - /** |
|
| 169 | - * @singleton method used to instantiate class object |
|
| 170 | - * @param EE_Dependency_Map $dependency_map |
|
| 171 | - * @return EE_Registry instance |
|
| 172 | - * @throws InvalidArgumentException |
|
| 173 | - * @throws InvalidInterfaceException |
|
| 174 | - * @throws InvalidDataTypeException |
|
| 175 | - */ |
|
| 176 | - public static function instance(EE_Dependency_Map $dependency_map = null) |
|
| 177 | - { |
|
| 178 | - // check if class object is instantiated |
|
| 179 | - if (! self::$_instance instanceof EE_Registry) { |
|
| 180 | - self::$_instance = new self($dependency_map); |
|
| 181 | - } |
|
| 182 | - return self::$_instance; |
|
| 183 | - } |
|
| 184 | - |
|
| 185 | - |
|
| 186 | - |
|
| 187 | - /** |
|
| 188 | - * protected constructor to prevent direct creation |
|
| 189 | - * |
|
| 190 | - * @Constructor |
|
| 191 | - * @param EE_Dependency_Map $dependency_map |
|
| 192 | - * @throws InvalidDataTypeException |
|
| 193 | - * @throws InvalidInterfaceException |
|
| 194 | - * @throws InvalidArgumentException |
|
| 195 | - */ |
|
| 196 | - protected function __construct(EE_Dependency_Map $dependency_map) |
|
| 197 | - { |
|
| 198 | - $this->_dependency_map = $dependency_map; |
|
| 199 | - $this->LIB = new stdClass(); |
|
| 200 | - $this->addons = new stdClass(); |
|
| 201 | - $this->modules = new stdClass(); |
|
| 202 | - $this->shortcodes = new stdClass(); |
|
| 203 | - $this->widgets = new stdClass(); |
|
| 204 | - add_action('EE_Load_Espresso_Core__handle_request__initialize_core_loading', array($this, 'initialize')); |
|
| 205 | - } |
|
| 206 | - |
|
| 207 | - |
|
| 208 | - |
|
| 209 | - /** |
|
| 210 | - * initialize |
|
| 211 | - * |
|
| 212 | - * @throws EE_Error |
|
| 213 | - * @throws ReflectionException |
|
| 214 | - */ |
|
| 215 | - public function initialize() |
|
| 216 | - { |
|
| 217 | - $this->_class_abbreviations = apply_filters( |
|
| 218 | - 'FHEE__EE_Registry____construct___class_abbreviations', |
|
| 219 | - array( |
|
| 220 | - 'EE_Config' => 'CFG', |
|
| 221 | - 'EE_Session' => 'SSN', |
|
| 222 | - 'EE_Capabilities' => 'CAP', |
|
| 223 | - 'EE_Cart' => 'CART', |
|
| 224 | - 'EE_Network_Config' => 'NET_CFG', |
|
| 225 | - 'EE_Request_Handler' => 'REQ', |
|
| 226 | - 'EE_Message_Resource_Manager' => 'MRM', |
|
| 227 | - 'EventEspresso\core\services\commands\CommandBus' => 'BUS', |
|
| 228 | - 'EventEspresso\core\services\assets\Registry' => 'AssetsRegistry', |
|
| 229 | - ) |
|
| 230 | - ); |
|
| 231 | - $this->load_core('Base', array(), true); |
|
| 232 | - // add our request and response objects to the cache |
|
| 233 | - $request_loader = $this->_dependency_map->class_loader('EE_Request'); |
|
| 234 | - $this->_set_cached_class( |
|
| 235 | - $request_loader(), |
|
| 236 | - 'EE_Request' |
|
| 237 | - ); |
|
| 238 | - $response_loader = $this->_dependency_map->class_loader('EE_Response'); |
|
| 239 | - $this->_set_cached_class( |
|
| 240 | - $response_loader(), |
|
| 241 | - 'EE_Response' |
|
| 242 | - ); |
|
| 243 | - add_action('AHEE__EE_System__set_hooks_for_core', array($this, 'init')); |
|
| 244 | - } |
|
| 245 | - |
|
| 246 | - |
|
| 247 | - |
|
| 248 | - /** |
|
| 249 | - * @return void |
|
| 250 | - */ |
|
| 251 | - public function init() |
|
| 252 | - { |
|
| 253 | - // Get current page protocol |
|
| 254 | - $protocol = isset($_SERVER['HTTPS']) ? 'https://' : 'http://'; |
|
| 255 | - // Output admin-ajax.php URL with same protocol as current page |
|
| 256 | - self::$i18n_js_strings['ajax_url'] = admin_url('admin-ajax.php', $protocol); |
|
| 257 | - self::$i18n_js_strings['wp_debug'] = defined('WP_DEBUG') ? WP_DEBUG : false; |
|
| 258 | - } |
|
| 259 | - |
|
| 260 | - |
|
| 261 | - |
|
| 262 | - /** |
|
| 263 | - * localize_i18n_js_strings |
|
| 264 | - * |
|
| 265 | - * @return string |
|
| 266 | - */ |
|
| 267 | - public static function localize_i18n_js_strings() |
|
| 268 | - { |
|
| 269 | - $i18n_js_strings = (array)self::$i18n_js_strings; |
|
| 270 | - foreach ($i18n_js_strings as $key => $value) { |
|
| 271 | - if (is_scalar($value)) { |
|
| 272 | - $i18n_js_strings[$key] = html_entity_decode((string)$value, ENT_QUOTES, 'UTF-8'); |
|
| 273 | - } |
|
| 274 | - } |
|
| 275 | - return '/* <![CDATA[ */ var eei18n = ' . wp_json_encode($i18n_js_strings) . '; /* ]]> */'; |
|
| 276 | - } |
|
| 277 | - |
|
| 278 | - |
|
| 279 | - |
|
| 280 | - /** |
|
| 281 | - * @param mixed string | EED_Module $module |
|
| 282 | - * @throws EE_Error |
|
| 283 | - * @throws ReflectionException |
|
| 284 | - */ |
|
| 285 | - public function add_module($module) |
|
| 286 | - { |
|
| 287 | - if ($module instanceof EED_Module) { |
|
| 288 | - $module_class = get_class($module); |
|
| 289 | - $this->modules->{$module_class} = $module; |
|
| 290 | - } else { |
|
| 291 | - if ( ! class_exists('EE_Module_Request_Router', false)) { |
|
| 292 | - $this->load_core('Module_Request_Router'); |
|
| 293 | - } |
|
| 294 | - EE_Module_Request_Router::module_factory($module); |
|
| 295 | - } |
|
| 296 | - } |
|
| 297 | - |
|
| 298 | - |
|
| 299 | - |
|
| 300 | - /** |
|
| 301 | - * @param string $module_name |
|
| 302 | - * @return mixed EED_Module | NULL |
|
| 303 | - */ |
|
| 304 | - public function get_module($module_name = '') |
|
| 305 | - { |
|
| 306 | - return isset($this->modules->{$module_name}) |
|
| 307 | - ? $this->modules->{$module_name} |
|
| 308 | - : null; |
|
| 309 | - } |
|
| 310 | - |
|
| 311 | - |
|
| 312 | - |
|
| 313 | - /** |
|
| 314 | - * loads core classes - must be singletons |
|
| 315 | - * |
|
| 316 | - * @param string $class_name - simple class name ie: session |
|
| 317 | - * @param mixed $arguments |
|
| 318 | - * @param bool $load_only |
|
| 319 | - * @return mixed |
|
| 320 | - * @throws EE_Error |
|
| 321 | - * @throws ReflectionException |
|
| 322 | - */ |
|
| 323 | - public function load_core($class_name, $arguments = array(), $load_only = false) |
|
| 324 | - { |
|
| 325 | - $core_paths = apply_filters( |
|
| 326 | - 'FHEE__EE_Registry__load_core__core_paths', |
|
| 327 | - array( |
|
| 328 | - EE_CORE, |
|
| 329 | - EE_ADMIN, |
|
| 330 | - EE_CPTS, |
|
| 331 | - EE_CORE . 'data_migration_scripts' . DS, |
|
| 332 | - EE_CORE . 'capabilities' . DS, |
|
| 333 | - EE_CORE . 'request_stack' . DS, |
|
| 334 | - EE_CORE . 'middleware' . DS, |
|
| 335 | - ) |
|
| 336 | - ); |
|
| 337 | - // retrieve instantiated class |
|
| 338 | - return $this->_load( |
|
| 339 | - $core_paths, |
|
| 340 | - 'EE_', |
|
| 341 | - $class_name, |
|
| 342 | - 'core', |
|
| 343 | - $arguments, |
|
| 344 | - false, |
|
| 345 | - true, |
|
| 346 | - $load_only |
|
| 347 | - ); |
|
| 348 | - } |
|
| 349 | - |
|
| 350 | - |
|
| 351 | - |
|
| 352 | - /** |
|
| 353 | - * loads service classes |
|
| 354 | - * |
|
| 355 | - * @param string $class_name - simple class name ie: session |
|
| 356 | - * @param mixed $arguments |
|
| 357 | - * @param bool $load_only |
|
| 358 | - * @return mixed |
|
| 359 | - * @throws EE_Error |
|
| 360 | - * @throws ReflectionException |
|
| 361 | - */ |
|
| 362 | - public function load_service($class_name, $arguments = array(), $load_only = false) |
|
| 363 | - { |
|
| 364 | - $service_paths = apply_filters( |
|
| 365 | - 'FHEE__EE_Registry__load_service__service_paths', |
|
| 366 | - array( |
|
| 367 | - EE_CORE . 'services' . DS, |
|
| 368 | - ) |
|
| 369 | - ); |
|
| 370 | - // retrieve instantiated class |
|
| 371 | - return $this->_load( |
|
| 372 | - $service_paths, |
|
| 373 | - 'EE_', |
|
| 374 | - $class_name, |
|
| 375 | - 'class', |
|
| 376 | - $arguments, |
|
| 377 | - false, |
|
| 378 | - true, |
|
| 379 | - $load_only |
|
| 380 | - ); |
|
| 381 | - } |
|
| 382 | - |
|
| 383 | - |
|
| 384 | - |
|
| 385 | - /** |
|
| 386 | - * loads data_migration_scripts |
|
| 387 | - * |
|
| 388 | - * @param string $class_name - class name for the DMS ie: EE_DMS_Core_4_2_0 |
|
| 389 | - * @param mixed $arguments |
|
| 390 | - * @return EE_Data_Migration_Script_Base|mixed |
|
| 391 | - * @throws EE_Error |
|
| 392 | - * @throws ReflectionException |
|
| 393 | - */ |
|
| 394 | - public function load_dms($class_name, $arguments = array()) |
|
| 395 | - { |
|
| 396 | - // retrieve instantiated class |
|
| 397 | - return $this->_load( |
|
| 398 | - EE_Data_Migration_Manager::instance()->get_data_migration_script_folders(), |
|
| 399 | - 'EE_DMS_', |
|
| 400 | - $class_name, |
|
| 401 | - 'dms', |
|
| 402 | - $arguments, |
|
| 403 | - false, |
|
| 404 | - false |
|
| 405 | - ); |
|
| 406 | - } |
|
| 407 | - |
|
| 408 | - |
|
| 409 | - |
|
| 410 | - /** |
|
| 411 | - * loads object creating classes - must be singletons |
|
| 412 | - * |
|
| 413 | - * @param string $class_name - simple class name ie: attendee |
|
| 414 | - * @param mixed $arguments - an array of arguments to pass to the class |
|
| 415 | - * @param bool $from_db - some classes are instantiated from the db and thus call a different method to |
|
| 416 | - * instantiate |
|
| 417 | - * @param bool $cache if you don't want the class to be stored in the internal cache (non-persistent) then |
|
| 418 | - * set this to FALSE (ie. when instantiating model objects from client in a loop) |
|
| 419 | - * @param bool $load_only whether or not to just load the file and NOT instantiate, or load AND instantiate |
|
| 420 | - * (default) |
|
| 421 | - * @return EE_Base_Class | bool |
|
| 422 | - * @throws EE_Error |
|
| 423 | - * @throws ReflectionException |
|
| 424 | - */ |
|
| 425 | - public function load_class($class_name, $arguments = array(), $from_db = false, $cache = true, $load_only = false) |
|
| 426 | - { |
|
| 427 | - $paths = apply_filters( |
|
| 428 | - 'FHEE__EE_Registry__load_class__paths', array( |
|
| 429 | - EE_CORE, |
|
| 430 | - EE_CLASSES, |
|
| 431 | - EE_BUSINESS, |
|
| 432 | - ) |
|
| 433 | - ); |
|
| 434 | - // retrieve instantiated class |
|
| 435 | - return $this->_load( |
|
| 436 | - $paths, |
|
| 437 | - 'EE_', |
|
| 438 | - $class_name, |
|
| 439 | - 'class', |
|
| 440 | - $arguments, |
|
| 441 | - $from_db, |
|
| 442 | - $cache, |
|
| 443 | - $load_only |
|
| 444 | - ); |
|
| 445 | - } |
|
| 446 | - |
|
| 447 | - |
|
| 448 | - |
|
| 449 | - /** |
|
| 450 | - * loads helper classes - must be singletons |
|
| 451 | - * |
|
| 452 | - * @param string $class_name - simple class name ie: price |
|
| 453 | - * @param mixed $arguments |
|
| 454 | - * @param bool $load_only |
|
| 455 | - * @return EEH_Base | bool |
|
| 456 | - * @throws EE_Error |
|
| 457 | - * @throws ReflectionException |
|
| 458 | - */ |
|
| 459 | - public function load_helper($class_name, $arguments = array(), $load_only = true) |
|
| 460 | - { |
|
| 461 | - // todo: add doing_it_wrong() in a few versions after all addons have had calls to this method removed |
|
| 462 | - $helper_paths = apply_filters('FHEE__EE_Registry__load_helper__helper_paths', array(EE_HELPERS)); |
|
| 463 | - // retrieve instantiated class |
|
| 464 | - return $this->_load( |
|
| 465 | - $helper_paths, |
|
| 466 | - 'EEH_', |
|
| 467 | - $class_name, |
|
| 468 | - 'helper', |
|
| 469 | - $arguments, |
|
| 470 | - false, |
|
| 471 | - true, |
|
| 472 | - $load_only |
|
| 473 | - ); |
|
| 474 | - } |
|
| 475 | - |
|
| 476 | - |
|
| 477 | - |
|
| 478 | - /** |
|
| 479 | - * loads core classes - must be singletons |
|
| 480 | - * |
|
| 481 | - * @param string $class_name - simple class name ie: session |
|
| 482 | - * @param mixed $arguments |
|
| 483 | - * @param bool $load_only |
|
| 484 | - * @param bool $cache whether to cache the object or not. |
|
| 485 | - * @return mixed |
|
| 486 | - * @throws EE_Error |
|
| 487 | - * @throws ReflectionException |
|
| 488 | - */ |
|
| 489 | - public function load_lib($class_name, $arguments = array(), $load_only = false, $cache = true) |
|
| 490 | - { |
|
| 491 | - $paths = array( |
|
| 492 | - EE_LIBRARIES, |
|
| 493 | - EE_LIBRARIES . 'messages' . DS, |
|
| 494 | - EE_LIBRARIES . 'shortcodes' . DS, |
|
| 495 | - EE_LIBRARIES . 'qtips' . DS, |
|
| 496 | - EE_LIBRARIES . 'payment_methods' . DS, |
|
| 497 | - ); |
|
| 498 | - // retrieve instantiated class |
|
| 499 | - return $this->_load( |
|
| 500 | - $paths, |
|
| 501 | - 'EE_', |
|
| 502 | - $class_name, |
|
| 503 | - 'lib', |
|
| 504 | - $arguments, |
|
| 505 | - false, |
|
| 506 | - $cache, |
|
| 507 | - $load_only |
|
| 508 | - ); |
|
| 509 | - } |
|
| 510 | - |
|
| 511 | - |
|
| 512 | - |
|
| 513 | - /** |
|
| 514 | - * loads model classes - must be singletons |
|
| 515 | - * |
|
| 516 | - * @param string $class_name - simple class name ie: price |
|
| 517 | - * @param mixed $arguments |
|
| 518 | - * @param bool $load_only |
|
| 519 | - * @return EEM_Base | bool |
|
| 520 | - * @throws EE_Error |
|
| 521 | - * @throws ReflectionException |
|
| 522 | - */ |
|
| 523 | - public function load_model($class_name, $arguments = array(), $load_only = false) |
|
| 524 | - { |
|
| 525 | - $paths = apply_filters( |
|
| 526 | - 'FHEE__EE_Registry__load_model__paths', array( |
|
| 527 | - EE_MODELS, |
|
| 528 | - EE_CORE, |
|
| 529 | - ) |
|
| 530 | - ); |
|
| 531 | - // retrieve instantiated class |
|
| 532 | - return $this->_load( |
|
| 533 | - $paths, |
|
| 534 | - 'EEM_', |
|
| 535 | - $class_name, |
|
| 536 | - 'model', |
|
| 537 | - $arguments, |
|
| 538 | - false, |
|
| 539 | - true, |
|
| 540 | - $load_only |
|
| 541 | - ); |
|
| 542 | - } |
|
| 543 | - |
|
| 544 | - |
|
| 545 | - |
|
| 546 | - /** |
|
| 547 | - * loads model classes - must be singletons |
|
| 548 | - * |
|
| 549 | - * @param string $class_name - simple class name ie: price |
|
| 550 | - * @param mixed $arguments |
|
| 551 | - * @param bool $load_only |
|
| 552 | - * @return mixed | bool |
|
| 553 | - * @throws EE_Error |
|
| 554 | - * @throws ReflectionException |
|
| 555 | - */ |
|
| 556 | - public function load_model_class($class_name, $arguments = array(), $load_only = true) |
|
| 557 | - { |
|
| 558 | - $paths = array( |
|
| 559 | - EE_MODELS . 'fields' . DS, |
|
| 560 | - EE_MODELS . 'helpers' . DS, |
|
| 561 | - EE_MODELS . 'relations' . DS, |
|
| 562 | - EE_MODELS . 'strategies' . DS, |
|
| 563 | - ); |
|
| 564 | - // retrieve instantiated class |
|
| 565 | - return $this->_load( |
|
| 566 | - $paths, |
|
| 567 | - 'EE_', |
|
| 568 | - $class_name, |
|
| 569 | - '', |
|
| 570 | - $arguments, |
|
| 571 | - false, |
|
| 572 | - true, |
|
| 573 | - $load_only |
|
| 574 | - ); |
|
| 575 | - } |
|
| 576 | - |
|
| 577 | - |
|
| 578 | - |
|
| 579 | - /** |
|
| 580 | - * Determines if $model_name is the name of an actual EE model. |
|
| 581 | - * |
|
| 582 | - * @param string $model_name like Event, Attendee, Question_Group_Question, etc. |
|
| 583 | - * @return boolean |
|
| 584 | - */ |
|
| 585 | - public function is_model_name($model_name) |
|
| 586 | - { |
|
| 587 | - return isset($this->models[$model_name]); |
|
| 588 | - } |
|
| 589 | - |
|
| 590 | - |
|
| 591 | - |
|
| 592 | - /** |
|
| 593 | - * generic class loader |
|
| 594 | - * |
|
| 595 | - * @param string $path_to_file - directory path to file location, not including filename |
|
| 596 | - * @param string $file_name - file name ie: my_file.php, including extension |
|
| 597 | - * @param string $type - file type - core? class? helper? model? |
|
| 598 | - * @param mixed $arguments |
|
| 599 | - * @param bool $load_only |
|
| 600 | - * @return mixed |
|
| 601 | - * @throws EE_Error |
|
| 602 | - * @throws ReflectionException |
|
| 603 | - */ |
|
| 604 | - public function load_file($path_to_file, $file_name, $type = '', $arguments = array(), $load_only = true) |
|
| 605 | - { |
|
| 606 | - // retrieve instantiated class |
|
| 607 | - return $this->_load( |
|
| 608 | - $path_to_file, |
|
| 609 | - '', |
|
| 610 | - $file_name, |
|
| 611 | - $type, |
|
| 612 | - $arguments, |
|
| 613 | - false, |
|
| 614 | - true, |
|
| 615 | - $load_only |
|
| 616 | - ); |
|
| 617 | - } |
|
| 618 | - |
|
| 619 | - |
|
| 620 | - |
|
| 621 | - /** |
|
| 622 | - * @param string $path_to_file - directory path to file location, not including filename |
|
| 623 | - * @param string $class_name - full class name ie: My_Class |
|
| 624 | - * @param string $type - file type - core? class? helper? model? |
|
| 625 | - * @param mixed $arguments |
|
| 626 | - * @param bool $load_only |
|
| 627 | - * @return bool|EE_Addon|object |
|
| 628 | - * @throws EE_Error |
|
| 629 | - * @throws ReflectionException |
|
| 630 | - */ |
|
| 631 | - public function load_addon($path_to_file, $class_name, $type = 'class', $arguments = array(), $load_only = false) |
|
| 632 | - { |
|
| 633 | - // retrieve instantiated class |
|
| 634 | - return $this->_load( |
|
| 635 | - $path_to_file, |
|
| 636 | - 'addon', |
|
| 637 | - $class_name, |
|
| 638 | - $type, |
|
| 639 | - $arguments, |
|
| 640 | - false, |
|
| 641 | - true, |
|
| 642 | - $load_only |
|
| 643 | - ); |
|
| 644 | - } |
|
| 645 | - |
|
| 646 | - |
|
| 647 | - |
|
| 648 | - /** |
|
| 649 | - * instantiates, caches, and automatically resolves dependencies |
|
| 650 | - * for classes that use a Fully Qualified Class Name. |
|
| 651 | - * if the class is not capable of being loaded using PSR-4 autoloading, |
|
| 652 | - * then you need to use one of the existing load_*() methods |
|
| 653 | - * which can resolve the classname and filepath from the passed arguments |
|
| 654 | - * |
|
| 655 | - * @param bool|string $class_name Fully Qualified Class Name |
|
| 656 | - * @param array $arguments an argument, or array of arguments to pass to the class upon instantiation |
|
| 657 | - * @param bool $cache whether to cache the instantiated object for reuse |
|
| 658 | - * @param bool $from_db some classes are instantiated from the db |
|
| 659 | - * and thus call a different method to instantiate |
|
| 660 | - * @param bool $load_only if true, will only load the file, but will NOT instantiate an object |
|
| 661 | - * @param bool|string $addon if true, will cache the object in the EE_Registry->$addons array |
|
| 662 | - * @return bool|null|mixed null = failure to load or instantiate class object. |
|
| 663 | - * object = class loaded and instantiated successfully. |
|
| 664 | - * bool = fail or success when $load_only is true |
|
| 665 | - * @throws EE_Error |
|
| 666 | - * @throws ReflectionException |
|
| 667 | - */ |
|
| 668 | - public function create( |
|
| 669 | - $class_name = false, |
|
| 670 | - $arguments = array(), |
|
| 671 | - $cache = false, |
|
| 672 | - $from_db = false, |
|
| 673 | - $load_only = false, |
|
| 674 | - $addon = false |
|
| 675 | - ) { |
|
| 676 | - $class_name = ltrim($class_name, '\\'); |
|
| 677 | - $class_name = $this->_dependency_map->get_alias($class_name); |
|
| 678 | - $class_exists = $this->loadOrVerifyClassExists($class_name, $arguments); |
|
| 679 | - // if a non-FQCN was passed, then verifyClassExists() might return an object |
|
| 680 | - // or it could return null if the class just could not be found anywhere |
|
| 681 | - if ($class_exists instanceof $class_name || $class_exists === null){ |
|
| 682 | - // either way, return the results |
|
| 683 | - return $class_exists; |
|
| 684 | - } |
|
| 685 | - $class_name = $class_exists; |
|
| 686 | - // if we're only loading the class and it already exists, then let's just return true immediately |
|
| 687 | - if ($load_only) { |
|
| 688 | - return true; |
|
| 689 | - } |
|
| 690 | - $addon = $addon |
|
| 691 | - ? 'addon' |
|
| 692 | - : ''; |
|
| 693 | - // $this->_cache_on is toggled during the recursive loading that can occur with dependency injection |
|
| 694 | - // $cache is controlled by individual calls to separate Registry loader methods like load_class() |
|
| 695 | - // $load_only is also controlled by individual calls to separate Registry loader methods like load_file() |
|
| 696 | - if ($this->_cache_on && $cache && ! $load_only) { |
|
| 697 | - // return object if it's already cached |
|
| 698 | - $cached_class = $this->_get_cached_class($class_name, $addon); |
|
| 699 | - if ($cached_class !== null) { |
|
| 700 | - return $cached_class; |
|
| 701 | - } |
|
| 702 | - } |
|
| 703 | - // obtain the loader method from the dependency map |
|
| 704 | - $loader = $this->_dependency_map->class_loader($class_name); |
|
| 705 | - // instantiate the requested object |
|
| 706 | - if ($loader instanceof Closure) { |
|
| 707 | - $class_obj = $loader($arguments); |
|
| 708 | - } else if ($loader && method_exists($this, $loader)) { |
|
| 709 | - $class_obj = $this->{$loader}($class_name, $arguments); |
|
| 710 | - } else { |
|
| 711 | - $class_obj = $this->_create_object($class_name, $arguments, $addon, $from_db); |
|
| 712 | - } |
|
| 713 | - if (($this->_cache_on && $cache) || $this->get_class_abbreviation($class_name, '')) { |
|
| 714 | - // save it for later... kinda like gum { : $ |
|
| 715 | - $this->_set_cached_class($class_obj, $class_name, $addon, $from_db); |
|
| 716 | - } |
|
| 717 | - $this->_cache_on = true; |
|
| 718 | - return $class_obj; |
|
| 719 | - } |
|
| 720 | - |
|
| 721 | - |
|
| 722 | - |
|
| 723 | - /** |
|
| 724 | - * Recursively checks that a class exists and potentially attempts to load classes with non-FQCNs |
|
| 725 | - * |
|
| 726 | - * @param string $class_name |
|
| 727 | - * @param array $arguments |
|
| 728 | - * @param int $attempt |
|
| 729 | - * @return mixed |
|
| 730 | - */ |
|
| 731 | - private function loadOrVerifyClassExists($class_name, array $arguments, $attempt = 1) { |
|
| 732 | - if (is_object($class_name) || class_exists($class_name)) { |
|
| 733 | - return $class_name; |
|
| 734 | - } |
|
| 735 | - switch ($attempt) { |
|
| 736 | - case 1: |
|
| 737 | - // if it's a FQCN then maybe the class is registered with a preceding \ |
|
| 738 | - $class_name = strpos($class_name, '\\') !== false |
|
| 739 | - ? '\\' . ltrim($class_name, '\\') |
|
| 740 | - : $class_name; |
|
| 741 | - break; |
|
| 742 | - case 2: |
|
| 743 | - // |
|
| 744 | - $loader = $this->_dependency_map->class_loader($class_name); |
|
| 745 | - if ($loader && method_exists($this, $loader)) { |
|
| 746 | - return $this->{$loader}($class_name, $arguments); |
|
| 747 | - } |
|
| 748 | - break; |
|
| 749 | - case 3: |
|
| 750 | - default; |
|
| 751 | - return null; |
|
| 752 | - } |
|
| 753 | - $attempt++; |
|
| 754 | - return $this->loadOrVerifyClassExists($class_name, $arguments, $attempt); |
|
| 755 | - } |
|
| 756 | - |
|
| 757 | - |
|
| 758 | - |
|
| 759 | - /** |
|
| 760 | - * instantiates, caches, and injects dependencies for classes |
|
| 761 | - * |
|
| 762 | - * @param array $file_paths an array of paths to folders to look in |
|
| 763 | - * @param string $class_prefix EE or EEM or... ??? |
|
| 764 | - * @param bool|string $class_name $class name |
|
| 765 | - * @param string $type file type - core? class? helper? model? |
|
| 766 | - * @param mixed $arguments an argument or array of arguments to pass to the class upon instantiation |
|
| 767 | - * @param bool $from_db some classes are instantiated from the db |
|
| 768 | - * and thus call a different method to instantiate |
|
| 769 | - * @param bool $cache whether to cache the instantiated object for reuse |
|
| 770 | - * @param bool $load_only if true, will only load the file, but will NOT instantiate an object |
|
| 771 | - * @return bool|null|object null = failure to load or instantiate class object. |
|
| 772 | - * object = class loaded and instantiated successfully. |
|
| 773 | - * bool = fail or success when $load_only is true |
|
| 774 | - * @throws EE_Error |
|
| 775 | - * @throws ReflectionException |
|
| 776 | - */ |
|
| 777 | - protected function _load( |
|
| 778 | - $file_paths = array(), |
|
| 779 | - $class_prefix = 'EE_', |
|
| 780 | - $class_name = false, |
|
| 781 | - $type = 'class', |
|
| 782 | - $arguments = array(), |
|
| 783 | - $from_db = false, |
|
| 784 | - $cache = true, |
|
| 785 | - $load_only = false |
|
| 786 | - ) { |
|
| 787 | - $class_name = ltrim($class_name, '\\'); |
|
| 788 | - // strip php file extension |
|
| 789 | - $class_name = str_replace('.php', '', trim($class_name)); |
|
| 790 | - // does the class have a prefix ? |
|
| 791 | - if (! empty($class_prefix) && $class_prefix !== 'addon') { |
|
| 792 | - // make sure $class_prefix is uppercase |
|
| 793 | - $class_prefix = strtoupper(trim($class_prefix)); |
|
| 794 | - // add class prefix ONCE!!! |
|
| 795 | - $class_name = $class_prefix . str_replace($class_prefix, '', $class_name); |
|
| 796 | - } |
|
| 797 | - $class_name = $this->_dependency_map->get_alias($class_name); |
|
| 798 | - $class_exists = class_exists($class_name, false); |
|
| 799 | - // if we're only loading the class and it already exists, then let's just return true immediately |
|
| 800 | - if ($load_only && $class_exists) { |
|
| 801 | - return true; |
|
| 802 | - } |
|
| 803 | - // $this->_cache_on is toggled during the recursive loading that can occur with dependency injection |
|
| 804 | - // $cache is controlled by individual calls to separate Registry loader methods like load_class() |
|
| 805 | - // $load_only is also controlled by individual calls to separate Registry loader methods like load_file() |
|
| 806 | - if ($this->_cache_on && $cache && ! $load_only) { |
|
| 807 | - // return object if it's already cached |
|
| 808 | - $cached_class = $this->_get_cached_class($class_name, $class_prefix); |
|
| 809 | - if ($cached_class !== null) { |
|
| 810 | - return $cached_class; |
|
| 811 | - } |
|
| 812 | - } |
|
| 813 | - // if the class doesn't already exist.. then we need to try and find the file and load it |
|
| 814 | - if (! $class_exists) { |
|
| 815 | - // get full path to file |
|
| 816 | - $path = $this->_resolve_path($class_name, $type, $file_paths); |
|
| 817 | - // load the file |
|
| 818 | - $loaded = $this->_require_file($path, $class_name, $type, $file_paths); |
|
| 819 | - // if loading failed, or we are only loading a file but NOT instantiating an object |
|
| 820 | - if (! $loaded || $load_only) { |
|
| 821 | - // return boolean if only loading, or null if an object was expected |
|
| 822 | - return $load_only |
|
| 823 | - ? $loaded |
|
| 824 | - : null; |
|
| 825 | - } |
|
| 826 | - } |
|
| 827 | - // instantiate the requested object |
|
| 828 | - $class_obj = $this->_create_object($class_name, $arguments, $type, $from_db); |
|
| 829 | - if ($this->_cache_on && $cache) { |
|
| 830 | - // save it for later... kinda like gum { : $ |
|
| 831 | - $this->_set_cached_class($class_obj, $class_name, $class_prefix, $from_db); |
|
| 832 | - } |
|
| 833 | - $this->_cache_on = true; |
|
| 834 | - return $class_obj; |
|
| 835 | - } |
|
| 836 | - |
|
| 837 | - |
|
| 838 | - |
|
| 839 | - /** |
|
| 840 | - * @param string $class_name |
|
| 841 | - * @param string $default have to specify something, but not anything that will conflict |
|
| 842 | - * @return mixed|string |
|
| 843 | - */ |
|
| 844 | - protected function get_class_abbreviation($class_name, $default = 'FANCY_BATMAN_PANTS') |
|
| 845 | - { |
|
| 846 | - return isset($this->_class_abbreviations[$class_name]) |
|
| 847 | - ? $this->_class_abbreviations[$class_name] |
|
| 848 | - : $default; |
|
| 849 | - } |
|
| 850 | - |
|
| 851 | - /** |
|
| 852 | - * attempts to find a cached version of the requested class |
|
| 853 | - * by looking in the following places: |
|
| 854 | - * $this->{$class_abbreviation} ie: $this->CART |
|
| 855 | - * $this->{$class_name} ie: $this->Some_Class |
|
| 856 | - * $this->LIB->{$class_name} ie: $this->LIB->Some_Class |
|
| 857 | - * $this->addon->{$class_name} ie: $this->addon->Some_Addon_Class |
|
| 858 | - * |
|
| 859 | - * @param string $class_name |
|
| 860 | - * @param string $class_prefix |
|
| 861 | - * @return mixed |
|
| 862 | - */ |
|
| 863 | - protected function _get_cached_class($class_name, $class_prefix = '') |
|
| 864 | - { |
|
| 865 | - if ($class_name === 'EE_Registry') { |
|
| 866 | - return $this; |
|
| 867 | - } |
|
| 868 | - $class_abbreviation = $this->get_class_abbreviation($class_name); |
|
| 869 | - $class_name = str_replace('\\', '_', $class_name); |
|
| 870 | - // check if class has already been loaded, and return it if it has been |
|
| 871 | - if (isset($this->{$class_abbreviation})) { |
|
| 872 | - return $this->{$class_abbreviation}; |
|
| 873 | - } |
|
| 874 | - if (isset ($this->{$class_name})) { |
|
| 875 | - return $this->{$class_name}; |
|
| 876 | - } |
|
| 877 | - if (isset ($this->LIB->{$class_name})) { |
|
| 878 | - return $this->LIB->{$class_name}; |
|
| 879 | - } |
|
| 880 | - if ($class_prefix === 'addon' && isset ($this->addons->{$class_name})) { |
|
| 881 | - return $this->addons->{$class_name}; |
|
| 882 | - } |
|
| 883 | - return null; |
|
| 884 | - } |
|
| 885 | - |
|
| 886 | - |
|
| 887 | - |
|
| 888 | - /** |
|
| 889 | - * removes a cached version of the requested class |
|
| 890 | - * |
|
| 891 | - * @param string $class_name |
|
| 892 | - * @param boolean $addon |
|
| 893 | - * @return boolean |
|
| 894 | - */ |
|
| 895 | - public function clear_cached_class($class_name, $addon = false) |
|
| 896 | - { |
|
| 897 | - $class_abbreviation = $this->get_class_abbreviation($class_name); |
|
| 898 | - $class_name = str_replace('\\', '_', $class_name); |
|
| 899 | - // check if class has already been loaded, and return it if it has been |
|
| 900 | - if (isset($this->{$class_abbreviation})) { |
|
| 901 | - $this->{$class_abbreviation} = null; |
|
| 902 | - return true; |
|
| 903 | - } |
|
| 904 | - if (isset($this->{$class_name})) { |
|
| 905 | - $this->{$class_name} = null; |
|
| 906 | - return true; |
|
| 907 | - } |
|
| 908 | - if (isset($this->LIB->{$class_name})) { |
|
| 909 | - unset($this->LIB->{$class_name}); |
|
| 910 | - return true; |
|
| 911 | - } |
|
| 912 | - if ($addon && isset($this->addons->{$class_name})) { |
|
| 913 | - unset($this->addons->{$class_name}); |
|
| 914 | - return true; |
|
| 915 | - } |
|
| 916 | - return false; |
|
| 917 | - } |
|
| 918 | - |
|
| 919 | - |
|
| 920 | - |
|
| 921 | - /** |
|
| 922 | - * attempts to find a full valid filepath for the requested class. |
|
| 923 | - * loops thru each of the base paths in the $file_paths array and appends : "{classname} . {file type} . php" |
|
| 924 | - * then returns that path if the target file has been found and is readable |
|
| 925 | - * |
|
| 926 | - * @param string $class_name |
|
| 927 | - * @param string $type |
|
| 928 | - * @param array $file_paths |
|
| 929 | - * @return string | bool |
|
| 930 | - */ |
|
| 931 | - protected function _resolve_path($class_name, $type = '', $file_paths = array()) |
|
| 932 | - { |
|
| 933 | - // make sure $file_paths is an array |
|
| 934 | - $file_paths = is_array($file_paths) |
|
| 935 | - ? $file_paths |
|
| 936 | - : array($file_paths); |
|
| 937 | - // cycle thru paths |
|
| 938 | - foreach ($file_paths as $key => $file_path) { |
|
| 939 | - // convert all separators to proper DS, if no filepath, then use EE_CLASSES |
|
| 940 | - $file_path = $file_path |
|
| 941 | - ? str_replace(array('/', '\\'), DS, $file_path) |
|
| 942 | - : EE_CLASSES; |
|
| 943 | - // prep file type |
|
| 944 | - $type = ! empty($type) |
|
| 945 | - ? trim($type, '.') . '.' |
|
| 946 | - : ''; |
|
| 947 | - // build full file path |
|
| 948 | - $file_paths[$key] = rtrim($file_path, DS) . DS . $class_name . '.' . $type . 'php'; |
|
| 949 | - //does the file exist and can be read ? |
|
| 950 | - if (is_readable($file_paths[$key])) { |
|
| 951 | - return $file_paths[$key]; |
|
| 952 | - } |
|
| 953 | - } |
|
| 954 | - return false; |
|
| 955 | - } |
|
| 956 | - |
|
| 957 | - |
|
| 958 | - |
|
| 959 | - /** |
|
| 960 | - * basically just performs a require_once() |
|
| 961 | - * but with some error handling |
|
| 962 | - * |
|
| 963 | - * @param string $path |
|
| 964 | - * @param string $class_name |
|
| 965 | - * @param string $type |
|
| 966 | - * @param array $file_paths |
|
| 967 | - * @return bool |
|
| 968 | - * @throws EE_Error |
|
| 969 | - * @throws ReflectionException |
|
| 970 | - */ |
|
| 971 | - protected function _require_file($path, $class_name, $type = '', $file_paths = array()) |
|
| 972 | - { |
|
| 973 | - $this->resolve_legacy_class_parent($class_name); |
|
| 974 | - // don't give up! you gotta... |
|
| 975 | - try { |
|
| 976 | - //does the file exist and can it be read ? |
|
| 977 | - if (! $path) { |
|
| 978 | - // just in case the file has already been autoloaded, |
|
| 979 | - // but discrepancies in the naming schema are preventing it from |
|
| 980 | - // being loaded via one of the EE_Registry::load_*() methods, |
|
| 981 | - // then let's try one last hail mary before throwing an exception |
|
| 982 | - // and call class_exists() again, but with autoloading turned ON |
|
| 983 | - if(class_exists($class_name)) { |
|
| 984 | - return true; |
|
| 985 | - } |
|
| 986 | - // so sorry, can't find the file |
|
| 987 | - throw new EE_Error ( |
|
| 988 | - sprintf( |
|
| 989 | - esc_html__( |
|
| 990 | - 'The %1$s file %2$s could not be located or is not readable due to file permissions. Please ensure that the following filepath(s) are correct: %3$s', |
|
| 991 | - 'event_espresso' |
|
| 992 | - ), |
|
| 993 | - trim($type, '.'), |
|
| 994 | - $class_name, |
|
| 995 | - '<br />' . implode(',<br />', $file_paths) |
|
| 996 | - ) |
|
| 997 | - ); |
|
| 998 | - } |
|
| 999 | - // get the file |
|
| 1000 | - require_once($path); |
|
| 1001 | - // if the class isn't already declared somewhere |
|
| 1002 | - if (class_exists($class_name, false) === false) { |
|
| 1003 | - // so sorry, not a class |
|
| 1004 | - throw new EE_Error( |
|
| 1005 | - sprintf( |
|
| 1006 | - esc_html__('The %s file %s does not appear to contain the %s Class.', 'event_espresso'), |
|
| 1007 | - $type, |
|
| 1008 | - $path, |
|
| 1009 | - $class_name |
|
| 1010 | - ) |
|
| 1011 | - ); |
|
| 1012 | - } |
|
| 1013 | - } catch (EE_Error $e) { |
|
| 1014 | - $e->get_error(); |
|
| 1015 | - return false; |
|
| 1016 | - } |
|
| 1017 | - return true; |
|
| 1018 | - } |
|
| 1019 | - |
|
| 1020 | - |
|
| 1021 | - |
|
| 1022 | - /** |
|
| 1023 | - * Some of our legacy classes that extended a parent class would simply use a require() statement |
|
| 1024 | - * before their class declaration in order to ensure that the parent class was loaded. |
|
| 1025 | - * This is not ideal, but it's nearly impossible to determine the parent class of a non-namespaced class, |
|
| 1026 | - * without triggering a fatal error because the parent class has yet to be loaded and therefore doesn't exist. |
|
| 1027 | - * |
|
| 1028 | - * @param string $class_name |
|
| 1029 | - */ |
|
| 1030 | - protected function resolve_legacy_class_parent($class_name = '') |
|
| 1031 | - { |
|
| 1032 | - try { |
|
| 1033 | - $legacy_parent_class_map = array( |
|
| 1034 | - 'EE_Payment_Processor' => 'core/business/EE_Processor_Base.class.php' |
|
| 1035 | - ); |
|
| 1036 | - if(isset($legacy_parent_class_map[$class_name])) { |
|
| 1037 | - require_once EE_PLUGIN_DIR_PATH . $legacy_parent_class_map[$class_name]; |
|
| 1038 | - } |
|
| 1039 | - } catch (Exception $exception) { |
|
| 1040 | - } |
|
| 1041 | - } |
|
| 1042 | - |
|
| 1043 | - |
|
| 1044 | - |
|
| 1045 | - /** |
|
| 1046 | - * _create_object |
|
| 1047 | - * Attempts to instantiate the requested class via any of the |
|
| 1048 | - * commonly used instantiation methods employed throughout EE. |
|
| 1049 | - * The priority for instantiation is as follows: |
|
| 1050 | - * - abstract classes or any class flagged as "load only" (no instantiation occurs) |
|
| 1051 | - * - model objects via their 'new_instance_from_db' method |
|
| 1052 | - * - model objects via their 'new_instance' method |
|
| 1053 | - * - "singleton" classes" via their 'instance' method |
|
| 1054 | - * - standard instantiable classes via their __constructor |
|
| 1055 | - * Prior to instantiation, if the classname exists in the dependency_map, |
|
| 1056 | - * then the constructor for the requested class will be examined to determine |
|
| 1057 | - * if any dependencies exist, and if they can be injected. |
|
| 1058 | - * If so, then those classes will be added to the array of arguments passed to the constructor |
|
| 1059 | - * |
|
| 1060 | - * @param string $class_name |
|
| 1061 | - * @param array $arguments |
|
| 1062 | - * @param string $type |
|
| 1063 | - * @param bool $from_db |
|
| 1064 | - * @return null|object |
|
| 1065 | - * @throws EE_Error |
|
| 1066 | - * @throws ReflectionException |
|
| 1067 | - */ |
|
| 1068 | - protected function _create_object($class_name, $arguments = array(), $type = '', $from_db = false) |
|
| 1069 | - { |
|
| 1070 | - // create reflection |
|
| 1071 | - $reflector = $this->get_ReflectionClass($class_name); |
|
| 1072 | - // make sure arguments are an array |
|
| 1073 | - $arguments = is_array($arguments) |
|
| 1074 | - ? $arguments |
|
| 1075 | - : array($arguments); |
|
| 1076 | - // and if arguments array is numerically and sequentially indexed, then we want it to remain as is, |
|
| 1077 | - // else wrap it in an additional array so that it doesn't get split into multiple parameters |
|
| 1078 | - $arguments = $this->_array_is_numerically_and_sequentially_indexed($arguments) |
|
| 1079 | - ? $arguments |
|
| 1080 | - : array($arguments); |
|
| 1081 | - // attempt to inject dependencies ? |
|
| 1082 | - if ($this->_dependency_map->has($class_name)) { |
|
| 1083 | - $arguments = $this->_resolve_dependencies($reflector, $class_name, $arguments); |
|
| 1084 | - } |
|
| 1085 | - // instantiate the class if possible |
|
| 1086 | - if ($reflector->isAbstract()) { |
|
| 1087 | - // nothing to instantiate, loading file was enough |
|
| 1088 | - // does not throw an exception so $instantiation_mode is unused |
|
| 1089 | - // $instantiation_mode = "1) no constructor abstract class"; |
|
| 1090 | - return true; |
|
| 1091 | - } |
|
| 1092 | - if (empty($arguments) && $reflector->getConstructor() === null && $reflector->isInstantiable()) { |
|
| 1093 | - // no constructor = static methods only... nothing to instantiate, loading file was enough |
|
| 1094 | - // $instantiation_mode = "2) no constructor but instantiable"; |
|
| 1095 | - return $reflector->newInstance(); |
|
| 1096 | - } |
|
| 1097 | - if ($from_db && method_exists($class_name, 'new_instance_from_db')) { |
|
| 1098 | - // $instantiation_mode = "3) new_instance_from_db()"; |
|
| 1099 | - return call_user_func_array(array($class_name, 'new_instance_from_db'), $arguments); |
|
| 1100 | - } |
|
| 1101 | - if (method_exists($class_name, 'new_instance')) { |
|
| 1102 | - // $instantiation_mode = "4) new_instance()"; |
|
| 1103 | - return call_user_func_array(array($class_name, 'new_instance'), $arguments); |
|
| 1104 | - } |
|
| 1105 | - if (method_exists($class_name, 'instance')) { |
|
| 1106 | - // $instantiation_mode = "5) instance()"; |
|
| 1107 | - return call_user_func_array(array($class_name, 'instance'), $arguments); |
|
| 1108 | - } |
|
| 1109 | - if ($reflector->isInstantiable()) { |
|
| 1110 | - // $instantiation_mode = "6) constructor"; |
|
| 1111 | - return $reflector->newInstanceArgs($arguments); |
|
| 1112 | - } |
|
| 1113 | - // heh ? something's not right ! |
|
| 1114 | - throw new EE_Error( |
|
| 1115 | - sprintf( |
|
| 1116 | - __('The %s file %s could not be instantiated.', 'event_espresso'), |
|
| 1117 | - $type, |
|
| 1118 | - $class_name |
|
| 1119 | - ) |
|
| 1120 | - ); |
|
| 1121 | - } |
|
| 1122 | - |
|
| 1123 | - |
|
| 1124 | - |
|
| 1125 | - /** |
|
| 1126 | - * @see http://stackoverflow.com/questions/173400/how-to-check-if-php-array-is-associative-or-sequential |
|
| 1127 | - * @param array $array |
|
| 1128 | - * @return bool |
|
| 1129 | - */ |
|
| 1130 | - protected function _array_is_numerically_and_sequentially_indexed(array $array) |
|
| 1131 | - { |
|
| 1132 | - return ! empty($array) |
|
| 1133 | - ? array_keys($array) === range(0, count($array) - 1) |
|
| 1134 | - : true; |
|
| 1135 | - } |
|
| 1136 | - |
|
| 1137 | - |
|
| 1138 | - |
|
| 1139 | - /** |
|
| 1140 | - * getReflectionClass |
|
| 1141 | - * checks if a ReflectionClass object has already been generated for a class |
|
| 1142 | - * and returns that instead of creating a new one |
|
| 1143 | - * |
|
| 1144 | - * @param string $class_name |
|
| 1145 | - * @return ReflectionClass |
|
| 1146 | - * @throws ReflectionException |
|
| 1147 | - */ |
|
| 1148 | - public function get_ReflectionClass($class_name) |
|
| 1149 | - { |
|
| 1150 | - if ( |
|
| 1151 | - ! isset($this->_reflectors[$class_name]) |
|
| 1152 | - || ! $this->_reflectors[$class_name] instanceof ReflectionClass |
|
| 1153 | - ) { |
|
| 1154 | - $this->_reflectors[$class_name] = new ReflectionClass($class_name); |
|
| 1155 | - } |
|
| 1156 | - return $this->_reflectors[$class_name]; |
|
| 1157 | - } |
|
| 1158 | - |
|
| 1159 | - |
|
| 1160 | - |
|
| 1161 | - /** |
|
| 1162 | - * _resolve_dependencies |
|
| 1163 | - * examines the constructor for the requested class to determine |
|
| 1164 | - * if any dependencies exist, and if they can be injected. |
|
| 1165 | - * If so, then those classes will be added to the array of arguments passed to the constructor |
|
| 1166 | - * PLZ NOTE: this is achieved by type hinting the constructor params |
|
| 1167 | - * For example: |
|
| 1168 | - * if attempting to load a class "Foo" with the following constructor: |
|
| 1169 | - * __construct( Bar $bar_class, Fighter $grohl_class ) |
|
| 1170 | - * then $bar_class and $grohl_class will be added to the $arguments array, |
|
| 1171 | - * but only IF they are NOT already present in the incoming arguments array, |
|
| 1172 | - * and the correct classes can be loaded |
|
| 1173 | - * |
|
| 1174 | - * @param ReflectionClass $reflector |
|
| 1175 | - * @param string $class_name |
|
| 1176 | - * @param array $arguments |
|
| 1177 | - * @return array |
|
| 1178 | - * @throws EE_Error |
|
| 1179 | - * @throws ReflectionException |
|
| 1180 | - */ |
|
| 1181 | - protected function _resolve_dependencies(ReflectionClass $reflector, $class_name, $arguments = array()) |
|
| 1182 | - { |
|
| 1183 | - // let's examine the constructor |
|
| 1184 | - $constructor = $reflector->getConstructor(); |
|
| 1185 | - // whu? huh? nothing? |
|
| 1186 | - if (! $constructor) { |
|
| 1187 | - return $arguments; |
|
| 1188 | - } |
|
| 1189 | - // get constructor parameters |
|
| 1190 | - $params = $constructor->getParameters(); |
|
| 1191 | - // and the keys for the incoming arguments array so that we can compare existing arguments with what is expected |
|
| 1192 | - $argument_keys = array_keys($arguments); |
|
| 1193 | - // now loop thru all of the constructors expected parameters |
|
| 1194 | - foreach ($params as $index => $param) { |
|
| 1195 | - // is this a dependency for a specific class ? |
|
| 1196 | - $param_class = $param->getClass() |
|
| 1197 | - ? $param->getClass()->name |
|
| 1198 | - : null; |
|
| 1199 | - // BUT WAIT !!! This class may be an alias for something else (or getting replaced at runtime) |
|
| 1200 | - $param_class = $this->_dependency_map->has_alias($param_class, $class_name) |
|
| 1201 | - ? $this->_dependency_map->get_alias($param_class, $class_name) |
|
| 1202 | - : $param_class; |
|
| 1203 | - if ( |
|
| 1204 | - // param is not even a class |
|
| 1205 | - $param_class === null |
|
| 1206 | - // and something already exists in the incoming arguments for this param |
|
| 1207 | - && array_key_exists($index, $argument_keys) |
|
| 1208 | - && array_key_exists($argument_keys[$index], $arguments) |
|
| 1209 | - ) { |
|
| 1210 | - // so let's skip this argument and move on to the next |
|
| 1211 | - continue; |
|
| 1212 | - } |
|
| 1213 | - if ( |
|
| 1214 | - // parameter is type hinted as a class, exists as an incoming argument, AND it's the correct class |
|
| 1215 | - $param_class !== null |
|
| 1216 | - && isset($argument_keys[$index], $arguments[$argument_keys[$index]]) |
|
| 1217 | - && $arguments[$argument_keys[$index]] instanceof $param_class |
|
| 1218 | - ) { |
|
| 1219 | - // skip this argument and move on to the next |
|
| 1220 | - continue; |
|
| 1221 | - } |
|
| 1222 | - if ( |
|
| 1223 | - // parameter is type hinted as a class, and should be injected |
|
| 1224 | - $param_class !== null |
|
| 1225 | - && $this->_dependency_map->has_dependency_for_class($class_name, $param_class) |
|
| 1226 | - ) { |
|
| 1227 | - $arguments = $this->_resolve_dependency( |
|
| 1228 | - $class_name, |
|
| 1229 | - $param_class, |
|
| 1230 | - $arguments, |
|
| 1231 | - $index, |
|
| 1232 | - $argument_keys |
|
| 1233 | - ); |
|
| 1234 | - } else { |
|
| 1235 | - try { |
|
| 1236 | - $arguments[$index] = $param->isDefaultValueAvailable() |
|
| 1237 | - ? $param->getDefaultValue() |
|
| 1238 | - : null; |
|
| 1239 | - } catch (ReflectionException $e) { |
|
| 1240 | - throw new ReflectionException( |
|
| 1241 | - sprintf( |
|
| 1242 | - esc_html__('%1$s for parameter "$%2$s on classname "%3$s"', 'event_espresso'), |
|
| 1243 | - $e->getMessage(), |
|
| 1244 | - $param->getName(), |
|
| 1245 | - $class_name |
|
| 1246 | - ) |
|
| 1247 | - ); |
|
| 1248 | - } |
|
| 1249 | - } |
|
| 1250 | - } |
|
| 1251 | - return $arguments; |
|
| 1252 | - } |
|
| 1253 | - |
|
| 1254 | - |
|
| 1255 | - |
|
| 1256 | - /** |
|
| 1257 | - * @param string $class_name |
|
| 1258 | - * @param string $param_class |
|
| 1259 | - * @param array $arguments |
|
| 1260 | - * @param mixed $index |
|
| 1261 | - * @param array $argument_keys |
|
| 1262 | - * @return array |
|
| 1263 | - * @throws EE_Error |
|
| 1264 | - * @throws ReflectionException |
|
| 1265 | - * @throws InvalidArgumentException |
|
| 1266 | - * @throws InvalidInterfaceException |
|
| 1267 | - * @throws InvalidDataTypeException |
|
| 1268 | - */ |
|
| 1269 | - protected function _resolve_dependency($class_name, $param_class, $arguments, $index, array $argument_keys) |
|
| 1270 | - { |
|
| 1271 | - $dependency = null; |
|
| 1272 | - // should dependency be loaded from cache ? |
|
| 1273 | - $cache_on = $this->_dependency_map->loading_strategy_for_class_dependency( |
|
| 1274 | - $class_name, |
|
| 1275 | - $param_class |
|
| 1276 | - ); |
|
| 1277 | - $cache_on = $cache_on !== EE_Dependency_Map::load_new_object; |
|
| 1278 | - // we might have a dependency... |
|
| 1279 | - // let's MAYBE try and find it in our cache if that's what's been requested |
|
| 1280 | - $cached_class = $cache_on |
|
| 1281 | - ? $this->_get_cached_class($param_class) |
|
| 1282 | - : null; |
|
| 1283 | - // and grab it if it exists |
|
| 1284 | - if ($cached_class instanceof $param_class) { |
|
| 1285 | - $dependency = $cached_class; |
|
| 1286 | - } else if ($param_class !== $class_name) { |
|
| 1287 | - // obtain the loader method from the dependency map |
|
| 1288 | - $loader = $this->_dependency_map->class_loader($param_class); |
|
| 1289 | - // is loader a custom closure ? |
|
| 1290 | - if ($loader instanceof Closure) { |
|
| 1291 | - $dependency = $loader($arguments); |
|
| 1292 | - } else { |
|
| 1293 | - // set the cache on property for the recursive loading call |
|
| 1294 | - $this->_cache_on = $cache_on; |
|
| 1295 | - // if not, then let's try and load it via the registry |
|
| 1296 | - if ($loader && method_exists($this, $loader)) { |
|
| 1297 | - $dependency = $this->{$loader}($param_class); |
|
| 1298 | - } else { |
|
| 1299 | - $dependency = LoaderFactory::getLoader()->load( |
|
| 1300 | - $param_class, |
|
| 1301 | - array(), |
|
| 1302 | - $cache_on |
|
| 1303 | - ); |
|
| 1304 | - } |
|
| 1305 | - } |
|
| 1306 | - } |
|
| 1307 | - // did we successfully find the correct dependency ? |
|
| 1308 | - if ($dependency instanceof $param_class) { |
|
| 1309 | - // then let's inject it into the incoming array of arguments at the correct location |
|
| 1310 | - $arguments[$index] = $dependency; |
|
| 1311 | - } |
|
| 1312 | - return $arguments; |
|
| 1313 | - } |
|
| 1314 | - |
|
| 1315 | - |
|
| 1316 | - |
|
| 1317 | - /** |
|
| 1318 | - * _set_cached_class |
|
| 1319 | - * attempts to cache the instantiated class locally |
|
| 1320 | - * in one of the following places, in the following order: |
|
| 1321 | - * $this->{class_abbreviation} ie: $this->CART |
|
| 1322 | - * $this->{$class_name} ie: $this->Some_Class |
|
| 1323 | - * $this->addon->{$$class_name} ie: $this->addon->Some_Addon_Class |
|
| 1324 | - * $this->LIB->{$class_name} ie: $this->LIB->Some_Class |
|
| 1325 | - * |
|
| 1326 | - * @param object $class_obj |
|
| 1327 | - * @param string $class_name |
|
| 1328 | - * @param string $class_prefix |
|
| 1329 | - * @param bool $from_db |
|
| 1330 | - * @return void |
|
| 1331 | - */ |
|
| 1332 | - protected function _set_cached_class($class_obj, $class_name, $class_prefix = '', $from_db = false) |
|
| 1333 | - { |
|
| 1334 | - if ($class_name === 'EE_Registry' || empty($class_obj)) { |
|
| 1335 | - return; |
|
| 1336 | - } |
|
| 1337 | - // return newly instantiated class |
|
| 1338 | - $class_abbreviation = $this->get_class_abbreviation($class_name, ''); |
|
| 1339 | - if ($class_abbreviation) { |
|
| 1340 | - $this->{$class_abbreviation} = $class_obj; |
|
| 1341 | - return; |
|
| 1342 | - } |
|
| 1343 | - $class_name = str_replace('\\', '_', $class_name); |
|
| 1344 | - if (property_exists($this, $class_name)) { |
|
| 1345 | - $this->{$class_name} = $class_obj; |
|
| 1346 | - return; |
|
| 1347 | - } |
|
| 1348 | - if ($class_prefix === 'addon') { |
|
| 1349 | - $this->addons->{$class_name} = $class_obj; |
|
| 1350 | - return; |
|
| 1351 | - } |
|
| 1352 | - if (! $from_db) { |
|
| 1353 | - $this->LIB->{$class_name} = $class_obj; |
|
| 1354 | - } |
|
| 1355 | - } |
|
| 1356 | - |
|
| 1357 | - |
|
| 1358 | - |
|
| 1359 | - /** |
|
| 1360 | - * call any loader that's been registered in the EE_Dependency_Map::$_class_loaders array |
|
| 1361 | - * |
|
| 1362 | - * @param string $classname PLEASE NOTE: the class name needs to match what's registered |
|
| 1363 | - * in the EE_Dependency_Map::$_class_loaders array, |
|
| 1364 | - * including the class prefix, ie: "EE_", "EEM_", "EEH_", etc |
|
| 1365 | - * @param array $arguments |
|
| 1366 | - * @return object |
|
| 1367 | - */ |
|
| 1368 | - public static function factory($classname, $arguments = array()) |
|
| 1369 | - { |
|
| 1370 | - $loader = self::instance()->_dependency_map->class_loader($classname); |
|
| 1371 | - if ($loader instanceof Closure) { |
|
| 1372 | - return $loader($arguments); |
|
| 1373 | - } |
|
| 1374 | - if (method_exists(self::instance(), $loader)) { |
|
| 1375 | - return self::instance()->{$loader}($classname, $arguments); |
|
| 1376 | - } |
|
| 1377 | - return null; |
|
| 1378 | - } |
|
| 1379 | - |
|
| 1380 | - |
|
| 1381 | - |
|
| 1382 | - /** |
|
| 1383 | - * Gets the addon by its class name |
|
| 1384 | - * |
|
| 1385 | - * @param string $class_name |
|
| 1386 | - * @return EE_Addon |
|
| 1387 | - */ |
|
| 1388 | - public function getAddon($class_name) |
|
| 1389 | - { |
|
| 1390 | - $class_name = str_replace('\\', '_', $class_name); |
|
| 1391 | - return $this->addons->{$class_name}; |
|
| 1392 | - } |
|
| 1393 | - |
|
| 1394 | - |
|
| 1395 | - /** |
|
| 1396 | - * removes the addon from the internal cache |
|
| 1397 | - * |
|
| 1398 | - * @param string $class_name |
|
| 1399 | - * @return EE_Addon |
|
| 1400 | - */ |
|
| 1401 | - public function removeAddon($class_name) |
|
| 1402 | - { |
|
| 1403 | - $class_name = str_replace('\\', '_', $class_name); |
|
| 1404 | - $this->addons->{$class_name} = null; |
|
| 1405 | - } |
|
| 1406 | - |
|
| 1407 | - |
|
| 1408 | - |
|
| 1409 | - /** |
|
| 1410 | - * Gets the addon by its name/slug (not classname. For that, just |
|
| 1411 | - * use the get_addon() method above |
|
| 1412 | - * |
|
| 1413 | - * @param string $name |
|
| 1414 | - * @return EE_Addon |
|
| 1415 | - */ |
|
| 1416 | - public function get_addon_by_name($name) |
|
| 1417 | - { |
|
| 1418 | - foreach ($this->addons as $addon) { |
|
| 1419 | - if ($addon->name() === $name) { |
|
| 1420 | - return $addon; |
|
| 1421 | - } |
|
| 1422 | - } |
|
| 1423 | - return null; |
|
| 1424 | - } |
|
| 1425 | - |
|
| 1426 | - |
|
| 1427 | - |
|
| 1428 | - /** |
|
| 1429 | - * Gets an array of all the registered addons, where the keys are their names. |
|
| 1430 | - * (ie, what each returns for their name() function) |
|
| 1431 | - * They're already available on EE_Registry::instance()->addons as properties, |
|
| 1432 | - * where each property's name is the addon's classname, |
|
| 1433 | - * So if you just want to get the addon by classname, |
|
| 1434 | - * OR use the get_addon() method above. |
|
| 1435 | - * PLEASE NOTE: |
|
| 1436 | - * addons with Fully Qualified Class Names |
|
| 1437 | - * have had the namespace separators converted to underscores, |
|
| 1438 | - * so a classname like Fully\Qualified\ClassName |
|
| 1439 | - * would have been converted to Fully_Qualified_ClassName |
|
| 1440 | - * |
|
| 1441 | - * @return EE_Addon[] where the KEYS are the addon's name() |
|
| 1442 | - */ |
|
| 1443 | - public function get_addons_by_name() |
|
| 1444 | - { |
|
| 1445 | - $addons = array(); |
|
| 1446 | - foreach ($this->addons as $addon) { |
|
| 1447 | - $addons[$addon->name()] = $addon; |
|
| 1448 | - } |
|
| 1449 | - return $addons; |
|
| 1450 | - } |
|
| 1451 | - |
|
| 1452 | - |
|
| 1453 | - /** |
|
| 1454 | - * Resets the specified model's instance AND makes sure EE_Registry doesn't keep |
|
| 1455 | - * a stale copy of it around |
|
| 1456 | - * |
|
| 1457 | - * @param string $model_name |
|
| 1458 | - * @return \EEM_Base |
|
| 1459 | - * @throws \EE_Error |
|
| 1460 | - */ |
|
| 1461 | - public function reset_model($model_name) |
|
| 1462 | - { |
|
| 1463 | - $model_class_name = strpos($model_name, 'EEM_') !== 0 |
|
| 1464 | - ? "EEM_{$model_name}" |
|
| 1465 | - : $model_name; |
|
| 1466 | - if (! isset($this->LIB->{$model_class_name}) || ! $this->LIB->{$model_class_name} instanceof EEM_Base) { |
|
| 1467 | - return null; |
|
| 1468 | - } |
|
| 1469 | - //get that model reset it and make sure we nuke the old reference to it |
|
| 1470 | - if ($this->LIB->{$model_class_name} instanceof $model_class_name |
|
| 1471 | - && is_callable( |
|
| 1472 | - array($model_class_name, 'reset') |
|
| 1473 | - )) { |
|
| 1474 | - $this->LIB->{$model_class_name} = $this->LIB->{$model_class_name}->reset(); |
|
| 1475 | - } else { |
|
| 1476 | - throw new EE_Error(sprintf(esc_html__('Model %s does not have a method "reset"', 'event_espresso'), $model_name)); |
|
| 1477 | - } |
|
| 1478 | - return $this->LIB->{$model_class_name}; |
|
| 1479 | - } |
|
| 1480 | - |
|
| 1481 | - |
|
| 1482 | - |
|
| 1483 | - /** |
|
| 1484 | - * Resets the registry. |
|
| 1485 | - * The criteria for what gets reset is based on what can be shared between sites on the same request when |
|
| 1486 | - * switch_to_blog is used in a multisite install. Here is a list of things that are NOT reset. |
|
| 1487 | - * - $_dependency_map |
|
| 1488 | - * - $_class_abbreviations |
|
| 1489 | - * - $NET_CFG (EE_Network_Config): The config is shared network wide so no need to reset. |
|
| 1490 | - * - $REQ: Still on the same request so no need to change. |
|
| 1491 | - * - $CAP: There is no site specific state in the EE_Capability class. |
|
| 1492 | - * - $SSN: Although ideally, the session should not be shared between site switches, we can't reset it because only |
|
| 1493 | - * one Session can be active in a single request. Resetting could resolve in "headers already sent" errors. |
|
| 1494 | - * - $addons: In multisite, the state of the addons is something controlled via hooks etc in a normal request. So |
|
| 1495 | - * for now, we won't reset the addons because it could break calls to an add-ons class/methods in the |
|
| 1496 | - * switch or on the restore. |
|
| 1497 | - * - $modules |
|
| 1498 | - * - $shortcodes |
|
| 1499 | - * - $widgets |
|
| 1500 | - * |
|
| 1501 | - * @param boolean $hard [deprecated] |
|
| 1502 | - * @param boolean $reinstantiate whether to create new instances of EE_Registry's singletons too, |
|
| 1503 | - * or just reset without re-instantiating (handy to set to FALSE if you're not |
|
| 1504 | - * sure if you CAN currently reinstantiate the singletons at the moment) |
|
| 1505 | - * @param bool $reset_models Defaults to true. When false, then the models are not reset. This is so |
|
| 1506 | - * client |
|
| 1507 | - * code instead can just change the model context to a different blog id if |
|
| 1508 | - * necessary |
|
| 1509 | - * @return EE_Registry |
|
| 1510 | - * @throws EE_Error |
|
| 1511 | - * @throws ReflectionException |
|
| 1512 | - */ |
|
| 1513 | - public static function reset($hard = false, $reinstantiate = true, $reset_models = true) |
|
| 1514 | - { |
|
| 1515 | - $instance = self::instance(); |
|
| 1516 | - $instance->_cache_on = true; |
|
| 1517 | - // reset some "special" classes |
|
| 1518 | - EEH_Activation::reset(); |
|
| 1519 | - $hard = apply_filters( 'FHEE__EE_Registry__reset__hard', $hard); |
|
| 1520 | - $instance->CFG = EE_Config::reset($hard, $reinstantiate); |
|
| 1521 | - $instance->CART = null; |
|
| 1522 | - $instance->MRM = null; |
|
| 1523 | - $instance->AssetsRegistry = $instance->create('EventEspresso\core\services\assets\Registry'); |
|
| 1524 | - //messages reset |
|
| 1525 | - EED_Messages::reset(); |
|
| 1526 | - //handle of objects cached on LIB |
|
| 1527 | - foreach (array('LIB', 'modules') as $cache) { |
|
| 1528 | - foreach ($instance->{$cache} as $class_name => $class) { |
|
| 1529 | - if (self::_reset_and_unset_object($class, $reset_models)) { |
|
| 1530 | - unset($instance->{$cache}->{$class_name}); |
|
| 1531 | - } |
|
| 1532 | - } |
|
| 1533 | - } |
|
| 1534 | - return $instance; |
|
| 1535 | - } |
|
| 1536 | - |
|
| 1537 | - |
|
| 1538 | - |
|
| 1539 | - /** |
|
| 1540 | - * if passed object implements ResettableInterface, then call it's reset() method |
|
| 1541 | - * if passed object implements InterminableInterface, then return false, |
|
| 1542 | - * to indicate that it should NOT be cleared from the Registry cache |
|
| 1543 | - * |
|
| 1544 | - * @param $object |
|
| 1545 | - * @param bool $reset_models |
|
| 1546 | - * @return bool returns true if cached object should be unset |
|
| 1547 | - */ |
|
| 1548 | - private static function _reset_and_unset_object($object, $reset_models) |
|
| 1549 | - { |
|
| 1550 | - if (! is_object($object)) { |
|
| 1551 | - // don't unset anything that's not an object |
|
| 1552 | - return false; |
|
| 1553 | - } |
|
| 1554 | - if ($object instanceof EED_Module) { |
|
| 1555 | - $object::reset(); |
|
| 1556 | - // don't unset modules |
|
| 1557 | - return false; |
|
| 1558 | - } |
|
| 1559 | - if ($object instanceof ResettableInterface) { |
|
| 1560 | - if ($object instanceof EEM_Base) { |
|
| 1561 | - if ($reset_models) { |
|
| 1562 | - $object->reset(); |
|
| 1563 | - return true; |
|
| 1564 | - } |
|
| 1565 | - return false; |
|
| 1566 | - } |
|
| 1567 | - $object->reset(); |
|
| 1568 | - return true; |
|
| 1569 | - } |
|
| 1570 | - if (! $object instanceof InterminableInterface) { |
|
| 1571 | - return true; |
|
| 1572 | - } |
|
| 1573 | - return false; |
|
| 1574 | - } |
|
| 1575 | - |
|
| 1576 | - |
|
| 1577 | - |
|
| 1578 | - /** |
|
| 1579 | - * Gets all the custom post type models defined |
|
| 1580 | - * |
|
| 1581 | - * @return array keys are model "short names" (Eg "Event") and keys are classnames (eg "EEM_Event") |
|
| 1582 | - */ |
|
| 1583 | - public function cpt_models() |
|
| 1584 | - { |
|
| 1585 | - $cpt_models = array(); |
|
| 1586 | - foreach ($this->non_abstract_db_models as $short_name => $classname) { |
|
| 1587 | - if (is_subclass_of($classname, 'EEM_CPT_Base')) { |
|
| 1588 | - $cpt_models[$short_name] = $classname; |
|
| 1589 | - } |
|
| 1590 | - } |
|
| 1591 | - return $cpt_models; |
|
| 1592 | - } |
|
| 1593 | - |
|
| 1594 | - |
|
| 1595 | - |
|
| 1596 | - /** |
|
| 1597 | - * @return \EE_Config |
|
| 1598 | - */ |
|
| 1599 | - public static function CFG() |
|
| 1600 | - { |
|
| 1601 | - return self::instance()->CFG; |
|
| 1602 | - } |
|
| 25 | + /** |
|
| 26 | + * @var EE_Registry $_instance |
|
| 27 | + */ |
|
| 28 | + private static $_instance; |
|
| 29 | + |
|
| 30 | + /** |
|
| 31 | + * @var EE_Dependency_Map $_dependency_map |
|
| 32 | + */ |
|
| 33 | + protected $_dependency_map; |
|
| 34 | + |
|
| 35 | + /** |
|
| 36 | + * @var array $_class_abbreviations |
|
| 37 | + */ |
|
| 38 | + protected $_class_abbreviations = array(); |
|
| 39 | + |
|
| 40 | + /** |
|
| 41 | + * @var CommandBusInterface $BUS |
|
| 42 | + */ |
|
| 43 | + public $BUS; |
|
| 44 | + |
|
| 45 | + /** |
|
| 46 | + * @var EE_Cart $CART |
|
| 47 | + */ |
|
| 48 | + public $CART; |
|
| 49 | + |
|
| 50 | + /** |
|
| 51 | + * @var EE_Config $CFG |
|
| 52 | + */ |
|
| 53 | + public $CFG; |
|
| 54 | + |
|
| 55 | + /** |
|
| 56 | + * @var EE_Network_Config $NET_CFG |
|
| 57 | + */ |
|
| 58 | + public $NET_CFG; |
|
| 59 | + |
|
| 60 | + /** |
|
| 61 | + * StdClass object for storing library classes in |
|
| 62 | + * |
|
| 63 | + * @var StdClass $LIB |
|
| 64 | + */ |
|
| 65 | + public $LIB; |
|
| 66 | + |
|
| 67 | + /** |
|
| 68 | + * @var EE_Request_Handler $REQ |
|
| 69 | + */ |
|
| 70 | + public $REQ; |
|
| 71 | + |
|
| 72 | + /** |
|
| 73 | + * @var EE_Session $SSN |
|
| 74 | + */ |
|
| 75 | + public $SSN; |
|
| 76 | + |
|
| 77 | + /** |
|
| 78 | + * @since 4.5.0 |
|
| 79 | + * @var EE_Capabilities $CAP |
|
| 80 | + */ |
|
| 81 | + public $CAP; |
|
| 82 | + |
|
| 83 | + /** |
|
| 84 | + * @since 4.9.0 |
|
| 85 | + * @var EE_Message_Resource_Manager $MRM |
|
| 86 | + */ |
|
| 87 | + public $MRM; |
|
| 88 | + |
|
| 89 | + |
|
| 90 | + /** |
|
| 91 | + * @var Registry $AssetsRegistry |
|
| 92 | + */ |
|
| 93 | + public $AssetsRegistry; |
|
| 94 | + |
|
| 95 | + /** |
|
| 96 | + * StdClass object for holding addons which have registered themselves to work with EE core |
|
| 97 | + * |
|
| 98 | + * @var EE_Addon[] $addons |
|
| 99 | + */ |
|
| 100 | + public $addons; |
|
| 101 | + |
|
| 102 | + /** |
|
| 103 | + * keys are 'short names' (eg Event), values are class names (eg 'EEM_Event') |
|
| 104 | + * |
|
| 105 | + * @var EEM_Base[] $models |
|
| 106 | + */ |
|
| 107 | + public $models = array(); |
|
| 108 | + |
|
| 109 | + /** |
|
| 110 | + * @var EED_Module[] $modules |
|
| 111 | + */ |
|
| 112 | + public $modules; |
|
| 113 | + |
|
| 114 | + /** |
|
| 115 | + * @var EES_Shortcode[] $shortcodes |
|
| 116 | + */ |
|
| 117 | + public $shortcodes; |
|
| 118 | + |
|
| 119 | + /** |
|
| 120 | + * @var WP_Widget[] $widgets |
|
| 121 | + */ |
|
| 122 | + public $widgets; |
|
| 123 | + |
|
| 124 | + /** |
|
| 125 | + * this is an array of all implemented model names (i.e. not the parent abstract models, or models |
|
| 126 | + * which don't actually fetch items from the DB in the normal way (ie, are not children of EEM_Base)). |
|
| 127 | + * Keys are model "short names" (eg "Event") as used in model relations, and values are |
|
| 128 | + * classnames (eg "EEM_Event") |
|
| 129 | + * |
|
| 130 | + * @var array $non_abstract_db_models |
|
| 131 | + */ |
|
| 132 | + public $non_abstract_db_models = array(); |
|
| 133 | + |
|
| 134 | + |
|
| 135 | + /** |
|
| 136 | + * internationalization for JS strings |
|
| 137 | + * usage: EE_Registry::i18n_js_strings['string_key'] = esc_html__( 'string to translate.', 'event_espresso' ); |
|
| 138 | + * in js file: var translatedString = eei18n.string_key; |
|
| 139 | + * |
|
| 140 | + * @var array $i18n_js_strings |
|
| 141 | + */ |
|
| 142 | + public static $i18n_js_strings = array(); |
|
| 143 | + |
|
| 144 | + |
|
| 145 | + /** |
|
| 146 | + * $main_file - path to espresso.php |
|
| 147 | + * |
|
| 148 | + * @var array $main_file |
|
| 149 | + */ |
|
| 150 | + public $main_file; |
|
| 151 | + |
|
| 152 | + /** |
|
| 153 | + * array of ReflectionClass objects where the key is the class name |
|
| 154 | + * |
|
| 155 | + * @var ReflectionClass[] $_reflectors |
|
| 156 | + */ |
|
| 157 | + public $_reflectors; |
|
| 158 | + |
|
| 159 | + /** |
|
| 160 | + * boolean flag to indicate whether or not to load/save dependencies from/to the cache |
|
| 161 | + * |
|
| 162 | + * @var boolean $_cache_on |
|
| 163 | + */ |
|
| 164 | + protected $_cache_on = true; |
|
| 165 | + |
|
| 166 | + |
|
| 167 | + |
|
| 168 | + /** |
|
| 169 | + * @singleton method used to instantiate class object |
|
| 170 | + * @param EE_Dependency_Map $dependency_map |
|
| 171 | + * @return EE_Registry instance |
|
| 172 | + * @throws InvalidArgumentException |
|
| 173 | + * @throws InvalidInterfaceException |
|
| 174 | + * @throws InvalidDataTypeException |
|
| 175 | + */ |
|
| 176 | + public static function instance(EE_Dependency_Map $dependency_map = null) |
|
| 177 | + { |
|
| 178 | + // check if class object is instantiated |
|
| 179 | + if (! self::$_instance instanceof EE_Registry) { |
|
| 180 | + self::$_instance = new self($dependency_map); |
|
| 181 | + } |
|
| 182 | + return self::$_instance; |
|
| 183 | + } |
|
| 184 | + |
|
| 185 | + |
|
| 186 | + |
|
| 187 | + /** |
|
| 188 | + * protected constructor to prevent direct creation |
|
| 189 | + * |
|
| 190 | + * @Constructor |
|
| 191 | + * @param EE_Dependency_Map $dependency_map |
|
| 192 | + * @throws InvalidDataTypeException |
|
| 193 | + * @throws InvalidInterfaceException |
|
| 194 | + * @throws InvalidArgumentException |
|
| 195 | + */ |
|
| 196 | + protected function __construct(EE_Dependency_Map $dependency_map) |
|
| 197 | + { |
|
| 198 | + $this->_dependency_map = $dependency_map; |
|
| 199 | + $this->LIB = new stdClass(); |
|
| 200 | + $this->addons = new stdClass(); |
|
| 201 | + $this->modules = new stdClass(); |
|
| 202 | + $this->shortcodes = new stdClass(); |
|
| 203 | + $this->widgets = new stdClass(); |
|
| 204 | + add_action('EE_Load_Espresso_Core__handle_request__initialize_core_loading', array($this, 'initialize')); |
|
| 205 | + } |
|
| 206 | + |
|
| 207 | + |
|
| 208 | + |
|
| 209 | + /** |
|
| 210 | + * initialize |
|
| 211 | + * |
|
| 212 | + * @throws EE_Error |
|
| 213 | + * @throws ReflectionException |
|
| 214 | + */ |
|
| 215 | + public function initialize() |
|
| 216 | + { |
|
| 217 | + $this->_class_abbreviations = apply_filters( |
|
| 218 | + 'FHEE__EE_Registry____construct___class_abbreviations', |
|
| 219 | + array( |
|
| 220 | + 'EE_Config' => 'CFG', |
|
| 221 | + 'EE_Session' => 'SSN', |
|
| 222 | + 'EE_Capabilities' => 'CAP', |
|
| 223 | + 'EE_Cart' => 'CART', |
|
| 224 | + 'EE_Network_Config' => 'NET_CFG', |
|
| 225 | + 'EE_Request_Handler' => 'REQ', |
|
| 226 | + 'EE_Message_Resource_Manager' => 'MRM', |
|
| 227 | + 'EventEspresso\core\services\commands\CommandBus' => 'BUS', |
|
| 228 | + 'EventEspresso\core\services\assets\Registry' => 'AssetsRegistry', |
|
| 229 | + ) |
|
| 230 | + ); |
|
| 231 | + $this->load_core('Base', array(), true); |
|
| 232 | + // add our request and response objects to the cache |
|
| 233 | + $request_loader = $this->_dependency_map->class_loader('EE_Request'); |
|
| 234 | + $this->_set_cached_class( |
|
| 235 | + $request_loader(), |
|
| 236 | + 'EE_Request' |
|
| 237 | + ); |
|
| 238 | + $response_loader = $this->_dependency_map->class_loader('EE_Response'); |
|
| 239 | + $this->_set_cached_class( |
|
| 240 | + $response_loader(), |
|
| 241 | + 'EE_Response' |
|
| 242 | + ); |
|
| 243 | + add_action('AHEE__EE_System__set_hooks_for_core', array($this, 'init')); |
|
| 244 | + } |
|
| 245 | + |
|
| 246 | + |
|
| 247 | + |
|
| 248 | + /** |
|
| 249 | + * @return void |
|
| 250 | + */ |
|
| 251 | + public function init() |
|
| 252 | + { |
|
| 253 | + // Get current page protocol |
|
| 254 | + $protocol = isset($_SERVER['HTTPS']) ? 'https://' : 'http://'; |
|
| 255 | + // Output admin-ajax.php URL with same protocol as current page |
|
| 256 | + self::$i18n_js_strings['ajax_url'] = admin_url('admin-ajax.php', $protocol); |
|
| 257 | + self::$i18n_js_strings['wp_debug'] = defined('WP_DEBUG') ? WP_DEBUG : false; |
|
| 258 | + } |
|
| 259 | + |
|
| 260 | + |
|
| 261 | + |
|
| 262 | + /** |
|
| 263 | + * localize_i18n_js_strings |
|
| 264 | + * |
|
| 265 | + * @return string |
|
| 266 | + */ |
|
| 267 | + public static function localize_i18n_js_strings() |
|
| 268 | + { |
|
| 269 | + $i18n_js_strings = (array)self::$i18n_js_strings; |
|
| 270 | + foreach ($i18n_js_strings as $key => $value) { |
|
| 271 | + if (is_scalar($value)) { |
|
| 272 | + $i18n_js_strings[$key] = html_entity_decode((string)$value, ENT_QUOTES, 'UTF-8'); |
|
| 273 | + } |
|
| 274 | + } |
|
| 275 | + return '/* <![CDATA[ */ var eei18n = ' . wp_json_encode($i18n_js_strings) . '; /* ]]> */'; |
|
| 276 | + } |
|
| 277 | + |
|
| 278 | + |
|
| 279 | + |
|
| 280 | + /** |
|
| 281 | + * @param mixed string | EED_Module $module |
|
| 282 | + * @throws EE_Error |
|
| 283 | + * @throws ReflectionException |
|
| 284 | + */ |
|
| 285 | + public function add_module($module) |
|
| 286 | + { |
|
| 287 | + if ($module instanceof EED_Module) { |
|
| 288 | + $module_class = get_class($module); |
|
| 289 | + $this->modules->{$module_class} = $module; |
|
| 290 | + } else { |
|
| 291 | + if ( ! class_exists('EE_Module_Request_Router', false)) { |
|
| 292 | + $this->load_core('Module_Request_Router'); |
|
| 293 | + } |
|
| 294 | + EE_Module_Request_Router::module_factory($module); |
|
| 295 | + } |
|
| 296 | + } |
|
| 297 | + |
|
| 298 | + |
|
| 299 | + |
|
| 300 | + /** |
|
| 301 | + * @param string $module_name |
|
| 302 | + * @return mixed EED_Module | NULL |
|
| 303 | + */ |
|
| 304 | + public function get_module($module_name = '') |
|
| 305 | + { |
|
| 306 | + return isset($this->modules->{$module_name}) |
|
| 307 | + ? $this->modules->{$module_name} |
|
| 308 | + : null; |
|
| 309 | + } |
|
| 310 | + |
|
| 311 | + |
|
| 312 | + |
|
| 313 | + /** |
|
| 314 | + * loads core classes - must be singletons |
|
| 315 | + * |
|
| 316 | + * @param string $class_name - simple class name ie: session |
|
| 317 | + * @param mixed $arguments |
|
| 318 | + * @param bool $load_only |
|
| 319 | + * @return mixed |
|
| 320 | + * @throws EE_Error |
|
| 321 | + * @throws ReflectionException |
|
| 322 | + */ |
|
| 323 | + public function load_core($class_name, $arguments = array(), $load_only = false) |
|
| 324 | + { |
|
| 325 | + $core_paths = apply_filters( |
|
| 326 | + 'FHEE__EE_Registry__load_core__core_paths', |
|
| 327 | + array( |
|
| 328 | + EE_CORE, |
|
| 329 | + EE_ADMIN, |
|
| 330 | + EE_CPTS, |
|
| 331 | + EE_CORE . 'data_migration_scripts' . DS, |
|
| 332 | + EE_CORE . 'capabilities' . DS, |
|
| 333 | + EE_CORE . 'request_stack' . DS, |
|
| 334 | + EE_CORE . 'middleware' . DS, |
|
| 335 | + ) |
|
| 336 | + ); |
|
| 337 | + // retrieve instantiated class |
|
| 338 | + return $this->_load( |
|
| 339 | + $core_paths, |
|
| 340 | + 'EE_', |
|
| 341 | + $class_name, |
|
| 342 | + 'core', |
|
| 343 | + $arguments, |
|
| 344 | + false, |
|
| 345 | + true, |
|
| 346 | + $load_only |
|
| 347 | + ); |
|
| 348 | + } |
|
| 349 | + |
|
| 350 | + |
|
| 351 | + |
|
| 352 | + /** |
|
| 353 | + * loads service classes |
|
| 354 | + * |
|
| 355 | + * @param string $class_name - simple class name ie: session |
|
| 356 | + * @param mixed $arguments |
|
| 357 | + * @param bool $load_only |
|
| 358 | + * @return mixed |
|
| 359 | + * @throws EE_Error |
|
| 360 | + * @throws ReflectionException |
|
| 361 | + */ |
|
| 362 | + public function load_service($class_name, $arguments = array(), $load_only = false) |
|
| 363 | + { |
|
| 364 | + $service_paths = apply_filters( |
|
| 365 | + 'FHEE__EE_Registry__load_service__service_paths', |
|
| 366 | + array( |
|
| 367 | + EE_CORE . 'services' . DS, |
|
| 368 | + ) |
|
| 369 | + ); |
|
| 370 | + // retrieve instantiated class |
|
| 371 | + return $this->_load( |
|
| 372 | + $service_paths, |
|
| 373 | + 'EE_', |
|
| 374 | + $class_name, |
|
| 375 | + 'class', |
|
| 376 | + $arguments, |
|
| 377 | + false, |
|
| 378 | + true, |
|
| 379 | + $load_only |
|
| 380 | + ); |
|
| 381 | + } |
|
| 382 | + |
|
| 383 | + |
|
| 384 | + |
|
| 385 | + /** |
|
| 386 | + * loads data_migration_scripts |
|
| 387 | + * |
|
| 388 | + * @param string $class_name - class name for the DMS ie: EE_DMS_Core_4_2_0 |
|
| 389 | + * @param mixed $arguments |
|
| 390 | + * @return EE_Data_Migration_Script_Base|mixed |
|
| 391 | + * @throws EE_Error |
|
| 392 | + * @throws ReflectionException |
|
| 393 | + */ |
|
| 394 | + public function load_dms($class_name, $arguments = array()) |
|
| 395 | + { |
|
| 396 | + // retrieve instantiated class |
|
| 397 | + return $this->_load( |
|
| 398 | + EE_Data_Migration_Manager::instance()->get_data_migration_script_folders(), |
|
| 399 | + 'EE_DMS_', |
|
| 400 | + $class_name, |
|
| 401 | + 'dms', |
|
| 402 | + $arguments, |
|
| 403 | + false, |
|
| 404 | + false |
|
| 405 | + ); |
|
| 406 | + } |
|
| 407 | + |
|
| 408 | + |
|
| 409 | + |
|
| 410 | + /** |
|
| 411 | + * loads object creating classes - must be singletons |
|
| 412 | + * |
|
| 413 | + * @param string $class_name - simple class name ie: attendee |
|
| 414 | + * @param mixed $arguments - an array of arguments to pass to the class |
|
| 415 | + * @param bool $from_db - some classes are instantiated from the db and thus call a different method to |
|
| 416 | + * instantiate |
|
| 417 | + * @param bool $cache if you don't want the class to be stored in the internal cache (non-persistent) then |
|
| 418 | + * set this to FALSE (ie. when instantiating model objects from client in a loop) |
|
| 419 | + * @param bool $load_only whether or not to just load the file and NOT instantiate, or load AND instantiate |
|
| 420 | + * (default) |
|
| 421 | + * @return EE_Base_Class | bool |
|
| 422 | + * @throws EE_Error |
|
| 423 | + * @throws ReflectionException |
|
| 424 | + */ |
|
| 425 | + public function load_class($class_name, $arguments = array(), $from_db = false, $cache = true, $load_only = false) |
|
| 426 | + { |
|
| 427 | + $paths = apply_filters( |
|
| 428 | + 'FHEE__EE_Registry__load_class__paths', array( |
|
| 429 | + EE_CORE, |
|
| 430 | + EE_CLASSES, |
|
| 431 | + EE_BUSINESS, |
|
| 432 | + ) |
|
| 433 | + ); |
|
| 434 | + // retrieve instantiated class |
|
| 435 | + return $this->_load( |
|
| 436 | + $paths, |
|
| 437 | + 'EE_', |
|
| 438 | + $class_name, |
|
| 439 | + 'class', |
|
| 440 | + $arguments, |
|
| 441 | + $from_db, |
|
| 442 | + $cache, |
|
| 443 | + $load_only |
|
| 444 | + ); |
|
| 445 | + } |
|
| 446 | + |
|
| 447 | + |
|
| 448 | + |
|
| 449 | + /** |
|
| 450 | + * loads helper classes - must be singletons |
|
| 451 | + * |
|
| 452 | + * @param string $class_name - simple class name ie: price |
|
| 453 | + * @param mixed $arguments |
|
| 454 | + * @param bool $load_only |
|
| 455 | + * @return EEH_Base | bool |
|
| 456 | + * @throws EE_Error |
|
| 457 | + * @throws ReflectionException |
|
| 458 | + */ |
|
| 459 | + public function load_helper($class_name, $arguments = array(), $load_only = true) |
|
| 460 | + { |
|
| 461 | + // todo: add doing_it_wrong() in a few versions after all addons have had calls to this method removed |
|
| 462 | + $helper_paths = apply_filters('FHEE__EE_Registry__load_helper__helper_paths', array(EE_HELPERS)); |
|
| 463 | + // retrieve instantiated class |
|
| 464 | + return $this->_load( |
|
| 465 | + $helper_paths, |
|
| 466 | + 'EEH_', |
|
| 467 | + $class_name, |
|
| 468 | + 'helper', |
|
| 469 | + $arguments, |
|
| 470 | + false, |
|
| 471 | + true, |
|
| 472 | + $load_only |
|
| 473 | + ); |
|
| 474 | + } |
|
| 475 | + |
|
| 476 | + |
|
| 477 | + |
|
| 478 | + /** |
|
| 479 | + * loads core classes - must be singletons |
|
| 480 | + * |
|
| 481 | + * @param string $class_name - simple class name ie: session |
|
| 482 | + * @param mixed $arguments |
|
| 483 | + * @param bool $load_only |
|
| 484 | + * @param bool $cache whether to cache the object or not. |
|
| 485 | + * @return mixed |
|
| 486 | + * @throws EE_Error |
|
| 487 | + * @throws ReflectionException |
|
| 488 | + */ |
|
| 489 | + public function load_lib($class_name, $arguments = array(), $load_only = false, $cache = true) |
|
| 490 | + { |
|
| 491 | + $paths = array( |
|
| 492 | + EE_LIBRARIES, |
|
| 493 | + EE_LIBRARIES . 'messages' . DS, |
|
| 494 | + EE_LIBRARIES . 'shortcodes' . DS, |
|
| 495 | + EE_LIBRARIES . 'qtips' . DS, |
|
| 496 | + EE_LIBRARIES . 'payment_methods' . DS, |
|
| 497 | + ); |
|
| 498 | + // retrieve instantiated class |
|
| 499 | + return $this->_load( |
|
| 500 | + $paths, |
|
| 501 | + 'EE_', |
|
| 502 | + $class_name, |
|
| 503 | + 'lib', |
|
| 504 | + $arguments, |
|
| 505 | + false, |
|
| 506 | + $cache, |
|
| 507 | + $load_only |
|
| 508 | + ); |
|
| 509 | + } |
|
| 510 | + |
|
| 511 | + |
|
| 512 | + |
|
| 513 | + /** |
|
| 514 | + * loads model classes - must be singletons |
|
| 515 | + * |
|
| 516 | + * @param string $class_name - simple class name ie: price |
|
| 517 | + * @param mixed $arguments |
|
| 518 | + * @param bool $load_only |
|
| 519 | + * @return EEM_Base | bool |
|
| 520 | + * @throws EE_Error |
|
| 521 | + * @throws ReflectionException |
|
| 522 | + */ |
|
| 523 | + public function load_model($class_name, $arguments = array(), $load_only = false) |
|
| 524 | + { |
|
| 525 | + $paths = apply_filters( |
|
| 526 | + 'FHEE__EE_Registry__load_model__paths', array( |
|
| 527 | + EE_MODELS, |
|
| 528 | + EE_CORE, |
|
| 529 | + ) |
|
| 530 | + ); |
|
| 531 | + // retrieve instantiated class |
|
| 532 | + return $this->_load( |
|
| 533 | + $paths, |
|
| 534 | + 'EEM_', |
|
| 535 | + $class_name, |
|
| 536 | + 'model', |
|
| 537 | + $arguments, |
|
| 538 | + false, |
|
| 539 | + true, |
|
| 540 | + $load_only |
|
| 541 | + ); |
|
| 542 | + } |
|
| 543 | + |
|
| 544 | + |
|
| 545 | + |
|
| 546 | + /** |
|
| 547 | + * loads model classes - must be singletons |
|
| 548 | + * |
|
| 549 | + * @param string $class_name - simple class name ie: price |
|
| 550 | + * @param mixed $arguments |
|
| 551 | + * @param bool $load_only |
|
| 552 | + * @return mixed | bool |
|
| 553 | + * @throws EE_Error |
|
| 554 | + * @throws ReflectionException |
|
| 555 | + */ |
|
| 556 | + public function load_model_class($class_name, $arguments = array(), $load_only = true) |
|
| 557 | + { |
|
| 558 | + $paths = array( |
|
| 559 | + EE_MODELS . 'fields' . DS, |
|
| 560 | + EE_MODELS . 'helpers' . DS, |
|
| 561 | + EE_MODELS . 'relations' . DS, |
|
| 562 | + EE_MODELS . 'strategies' . DS, |
|
| 563 | + ); |
|
| 564 | + // retrieve instantiated class |
|
| 565 | + return $this->_load( |
|
| 566 | + $paths, |
|
| 567 | + 'EE_', |
|
| 568 | + $class_name, |
|
| 569 | + '', |
|
| 570 | + $arguments, |
|
| 571 | + false, |
|
| 572 | + true, |
|
| 573 | + $load_only |
|
| 574 | + ); |
|
| 575 | + } |
|
| 576 | + |
|
| 577 | + |
|
| 578 | + |
|
| 579 | + /** |
|
| 580 | + * Determines if $model_name is the name of an actual EE model. |
|
| 581 | + * |
|
| 582 | + * @param string $model_name like Event, Attendee, Question_Group_Question, etc. |
|
| 583 | + * @return boolean |
|
| 584 | + */ |
|
| 585 | + public function is_model_name($model_name) |
|
| 586 | + { |
|
| 587 | + return isset($this->models[$model_name]); |
|
| 588 | + } |
|
| 589 | + |
|
| 590 | + |
|
| 591 | + |
|
| 592 | + /** |
|
| 593 | + * generic class loader |
|
| 594 | + * |
|
| 595 | + * @param string $path_to_file - directory path to file location, not including filename |
|
| 596 | + * @param string $file_name - file name ie: my_file.php, including extension |
|
| 597 | + * @param string $type - file type - core? class? helper? model? |
|
| 598 | + * @param mixed $arguments |
|
| 599 | + * @param bool $load_only |
|
| 600 | + * @return mixed |
|
| 601 | + * @throws EE_Error |
|
| 602 | + * @throws ReflectionException |
|
| 603 | + */ |
|
| 604 | + public function load_file($path_to_file, $file_name, $type = '', $arguments = array(), $load_only = true) |
|
| 605 | + { |
|
| 606 | + // retrieve instantiated class |
|
| 607 | + return $this->_load( |
|
| 608 | + $path_to_file, |
|
| 609 | + '', |
|
| 610 | + $file_name, |
|
| 611 | + $type, |
|
| 612 | + $arguments, |
|
| 613 | + false, |
|
| 614 | + true, |
|
| 615 | + $load_only |
|
| 616 | + ); |
|
| 617 | + } |
|
| 618 | + |
|
| 619 | + |
|
| 620 | + |
|
| 621 | + /** |
|
| 622 | + * @param string $path_to_file - directory path to file location, not including filename |
|
| 623 | + * @param string $class_name - full class name ie: My_Class |
|
| 624 | + * @param string $type - file type - core? class? helper? model? |
|
| 625 | + * @param mixed $arguments |
|
| 626 | + * @param bool $load_only |
|
| 627 | + * @return bool|EE_Addon|object |
|
| 628 | + * @throws EE_Error |
|
| 629 | + * @throws ReflectionException |
|
| 630 | + */ |
|
| 631 | + public function load_addon($path_to_file, $class_name, $type = 'class', $arguments = array(), $load_only = false) |
|
| 632 | + { |
|
| 633 | + // retrieve instantiated class |
|
| 634 | + return $this->_load( |
|
| 635 | + $path_to_file, |
|
| 636 | + 'addon', |
|
| 637 | + $class_name, |
|
| 638 | + $type, |
|
| 639 | + $arguments, |
|
| 640 | + false, |
|
| 641 | + true, |
|
| 642 | + $load_only |
|
| 643 | + ); |
|
| 644 | + } |
|
| 645 | + |
|
| 646 | + |
|
| 647 | + |
|
| 648 | + /** |
|
| 649 | + * instantiates, caches, and automatically resolves dependencies |
|
| 650 | + * for classes that use a Fully Qualified Class Name. |
|
| 651 | + * if the class is not capable of being loaded using PSR-4 autoloading, |
|
| 652 | + * then you need to use one of the existing load_*() methods |
|
| 653 | + * which can resolve the classname and filepath from the passed arguments |
|
| 654 | + * |
|
| 655 | + * @param bool|string $class_name Fully Qualified Class Name |
|
| 656 | + * @param array $arguments an argument, or array of arguments to pass to the class upon instantiation |
|
| 657 | + * @param bool $cache whether to cache the instantiated object for reuse |
|
| 658 | + * @param bool $from_db some classes are instantiated from the db |
|
| 659 | + * and thus call a different method to instantiate |
|
| 660 | + * @param bool $load_only if true, will only load the file, but will NOT instantiate an object |
|
| 661 | + * @param bool|string $addon if true, will cache the object in the EE_Registry->$addons array |
|
| 662 | + * @return bool|null|mixed null = failure to load or instantiate class object. |
|
| 663 | + * object = class loaded and instantiated successfully. |
|
| 664 | + * bool = fail or success when $load_only is true |
|
| 665 | + * @throws EE_Error |
|
| 666 | + * @throws ReflectionException |
|
| 667 | + */ |
|
| 668 | + public function create( |
|
| 669 | + $class_name = false, |
|
| 670 | + $arguments = array(), |
|
| 671 | + $cache = false, |
|
| 672 | + $from_db = false, |
|
| 673 | + $load_only = false, |
|
| 674 | + $addon = false |
|
| 675 | + ) { |
|
| 676 | + $class_name = ltrim($class_name, '\\'); |
|
| 677 | + $class_name = $this->_dependency_map->get_alias($class_name); |
|
| 678 | + $class_exists = $this->loadOrVerifyClassExists($class_name, $arguments); |
|
| 679 | + // if a non-FQCN was passed, then verifyClassExists() might return an object |
|
| 680 | + // or it could return null if the class just could not be found anywhere |
|
| 681 | + if ($class_exists instanceof $class_name || $class_exists === null){ |
|
| 682 | + // either way, return the results |
|
| 683 | + return $class_exists; |
|
| 684 | + } |
|
| 685 | + $class_name = $class_exists; |
|
| 686 | + // if we're only loading the class and it already exists, then let's just return true immediately |
|
| 687 | + if ($load_only) { |
|
| 688 | + return true; |
|
| 689 | + } |
|
| 690 | + $addon = $addon |
|
| 691 | + ? 'addon' |
|
| 692 | + : ''; |
|
| 693 | + // $this->_cache_on is toggled during the recursive loading that can occur with dependency injection |
|
| 694 | + // $cache is controlled by individual calls to separate Registry loader methods like load_class() |
|
| 695 | + // $load_only is also controlled by individual calls to separate Registry loader methods like load_file() |
|
| 696 | + if ($this->_cache_on && $cache && ! $load_only) { |
|
| 697 | + // return object if it's already cached |
|
| 698 | + $cached_class = $this->_get_cached_class($class_name, $addon); |
|
| 699 | + if ($cached_class !== null) { |
|
| 700 | + return $cached_class; |
|
| 701 | + } |
|
| 702 | + } |
|
| 703 | + // obtain the loader method from the dependency map |
|
| 704 | + $loader = $this->_dependency_map->class_loader($class_name); |
|
| 705 | + // instantiate the requested object |
|
| 706 | + if ($loader instanceof Closure) { |
|
| 707 | + $class_obj = $loader($arguments); |
|
| 708 | + } else if ($loader && method_exists($this, $loader)) { |
|
| 709 | + $class_obj = $this->{$loader}($class_name, $arguments); |
|
| 710 | + } else { |
|
| 711 | + $class_obj = $this->_create_object($class_name, $arguments, $addon, $from_db); |
|
| 712 | + } |
|
| 713 | + if (($this->_cache_on && $cache) || $this->get_class_abbreviation($class_name, '')) { |
|
| 714 | + // save it for later... kinda like gum { : $ |
|
| 715 | + $this->_set_cached_class($class_obj, $class_name, $addon, $from_db); |
|
| 716 | + } |
|
| 717 | + $this->_cache_on = true; |
|
| 718 | + return $class_obj; |
|
| 719 | + } |
|
| 720 | + |
|
| 721 | + |
|
| 722 | + |
|
| 723 | + /** |
|
| 724 | + * Recursively checks that a class exists and potentially attempts to load classes with non-FQCNs |
|
| 725 | + * |
|
| 726 | + * @param string $class_name |
|
| 727 | + * @param array $arguments |
|
| 728 | + * @param int $attempt |
|
| 729 | + * @return mixed |
|
| 730 | + */ |
|
| 731 | + private function loadOrVerifyClassExists($class_name, array $arguments, $attempt = 1) { |
|
| 732 | + if (is_object($class_name) || class_exists($class_name)) { |
|
| 733 | + return $class_name; |
|
| 734 | + } |
|
| 735 | + switch ($attempt) { |
|
| 736 | + case 1: |
|
| 737 | + // if it's a FQCN then maybe the class is registered with a preceding \ |
|
| 738 | + $class_name = strpos($class_name, '\\') !== false |
|
| 739 | + ? '\\' . ltrim($class_name, '\\') |
|
| 740 | + : $class_name; |
|
| 741 | + break; |
|
| 742 | + case 2: |
|
| 743 | + // |
|
| 744 | + $loader = $this->_dependency_map->class_loader($class_name); |
|
| 745 | + if ($loader && method_exists($this, $loader)) { |
|
| 746 | + return $this->{$loader}($class_name, $arguments); |
|
| 747 | + } |
|
| 748 | + break; |
|
| 749 | + case 3: |
|
| 750 | + default; |
|
| 751 | + return null; |
|
| 752 | + } |
|
| 753 | + $attempt++; |
|
| 754 | + return $this->loadOrVerifyClassExists($class_name, $arguments, $attempt); |
|
| 755 | + } |
|
| 756 | + |
|
| 757 | + |
|
| 758 | + |
|
| 759 | + /** |
|
| 760 | + * instantiates, caches, and injects dependencies for classes |
|
| 761 | + * |
|
| 762 | + * @param array $file_paths an array of paths to folders to look in |
|
| 763 | + * @param string $class_prefix EE or EEM or... ??? |
|
| 764 | + * @param bool|string $class_name $class name |
|
| 765 | + * @param string $type file type - core? class? helper? model? |
|
| 766 | + * @param mixed $arguments an argument or array of arguments to pass to the class upon instantiation |
|
| 767 | + * @param bool $from_db some classes are instantiated from the db |
|
| 768 | + * and thus call a different method to instantiate |
|
| 769 | + * @param bool $cache whether to cache the instantiated object for reuse |
|
| 770 | + * @param bool $load_only if true, will only load the file, but will NOT instantiate an object |
|
| 771 | + * @return bool|null|object null = failure to load or instantiate class object. |
|
| 772 | + * object = class loaded and instantiated successfully. |
|
| 773 | + * bool = fail or success when $load_only is true |
|
| 774 | + * @throws EE_Error |
|
| 775 | + * @throws ReflectionException |
|
| 776 | + */ |
|
| 777 | + protected function _load( |
|
| 778 | + $file_paths = array(), |
|
| 779 | + $class_prefix = 'EE_', |
|
| 780 | + $class_name = false, |
|
| 781 | + $type = 'class', |
|
| 782 | + $arguments = array(), |
|
| 783 | + $from_db = false, |
|
| 784 | + $cache = true, |
|
| 785 | + $load_only = false |
|
| 786 | + ) { |
|
| 787 | + $class_name = ltrim($class_name, '\\'); |
|
| 788 | + // strip php file extension |
|
| 789 | + $class_name = str_replace('.php', '', trim($class_name)); |
|
| 790 | + // does the class have a prefix ? |
|
| 791 | + if (! empty($class_prefix) && $class_prefix !== 'addon') { |
|
| 792 | + // make sure $class_prefix is uppercase |
|
| 793 | + $class_prefix = strtoupper(trim($class_prefix)); |
|
| 794 | + // add class prefix ONCE!!! |
|
| 795 | + $class_name = $class_prefix . str_replace($class_prefix, '', $class_name); |
|
| 796 | + } |
|
| 797 | + $class_name = $this->_dependency_map->get_alias($class_name); |
|
| 798 | + $class_exists = class_exists($class_name, false); |
|
| 799 | + // if we're only loading the class and it already exists, then let's just return true immediately |
|
| 800 | + if ($load_only && $class_exists) { |
|
| 801 | + return true; |
|
| 802 | + } |
|
| 803 | + // $this->_cache_on is toggled during the recursive loading that can occur with dependency injection |
|
| 804 | + // $cache is controlled by individual calls to separate Registry loader methods like load_class() |
|
| 805 | + // $load_only is also controlled by individual calls to separate Registry loader methods like load_file() |
|
| 806 | + if ($this->_cache_on && $cache && ! $load_only) { |
|
| 807 | + // return object if it's already cached |
|
| 808 | + $cached_class = $this->_get_cached_class($class_name, $class_prefix); |
|
| 809 | + if ($cached_class !== null) { |
|
| 810 | + return $cached_class; |
|
| 811 | + } |
|
| 812 | + } |
|
| 813 | + // if the class doesn't already exist.. then we need to try and find the file and load it |
|
| 814 | + if (! $class_exists) { |
|
| 815 | + // get full path to file |
|
| 816 | + $path = $this->_resolve_path($class_name, $type, $file_paths); |
|
| 817 | + // load the file |
|
| 818 | + $loaded = $this->_require_file($path, $class_name, $type, $file_paths); |
|
| 819 | + // if loading failed, or we are only loading a file but NOT instantiating an object |
|
| 820 | + if (! $loaded || $load_only) { |
|
| 821 | + // return boolean if only loading, or null if an object was expected |
|
| 822 | + return $load_only |
|
| 823 | + ? $loaded |
|
| 824 | + : null; |
|
| 825 | + } |
|
| 826 | + } |
|
| 827 | + // instantiate the requested object |
|
| 828 | + $class_obj = $this->_create_object($class_name, $arguments, $type, $from_db); |
|
| 829 | + if ($this->_cache_on && $cache) { |
|
| 830 | + // save it for later... kinda like gum { : $ |
|
| 831 | + $this->_set_cached_class($class_obj, $class_name, $class_prefix, $from_db); |
|
| 832 | + } |
|
| 833 | + $this->_cache_on = true; |
|
| 834 | + return $class_obj; |
|
| 835 | + } |
|
| 836 | + |
|
| 837 | + |
|
| 838 | + |
|
| 839 | + /** |
|
| 840 | + * @param string $class_name |
|
| 841 | + * @param string $default have to specify something, but not anything that will conflict |
|
| 842 | + * @return mixed|string |
|
| 843 | + */ |
|
| 844 | + protected function get_class_abbreviation($class_name, $default = 'FANCY_BATMAN_PANTS') |
|
| 845 | + { |
|
| 846 | + return isset($this->_class_abbreviations[$class_name]) |
|
| 847 | + ? $this->_class_abbreviations[$class_name] |
|
| 848 | + : $default; |
|
| 849 | + } |
|
| 850 | + |
|
| 851 | + /** |
|
| 852 | + * attempts to find a cached version of the requested class |
|
| 853 | + * by looking in the following places: |
|
| 854 | + * $this->{$class_abbreviation} ie: $this->CART |
|
| 855 | + * $this->{$class_name} ie: $this->Some_Class |
|
| 856 | + * $this->LIB->{$class_name} ie: $this->LIB->Some_Class |
|
| 857 | + * $this->addon->{$class_name} ie: $this->addon->Some_Addon_Class |
|
| 858 | + * |
|
| 859 | + * @param string $class_name |
|
| 860 | + * @param string $class_prefix |
|
| 861 | + * @return mixed |
|
| 862 | + */ |
|
| 863 | + protected function _get_cached_class($class_name, $class_prefix = '') |
|
| 864 | + { |
|
| 865 | + if ($class_name === 'EE_Registry') { |
|
| 866 | + return $this; |
|
| 867 | + } |
|
| 868 | + $class_abbreviation = $this->get_class_abbreviation($class_name); |
|
| 869 | + $class_name = str_replace('\\', '_', $class_name); |
|
| 870 | + // check if class has already been loaded, and return it if it has been |
|
| 871 | + if (isset($this->{$class_abbreviation})) { |
|
| 872 | + return $this->{$class_abbreviation}; |
|
| 873 | + } |
|
| 874 | + if (isset ($this->{$class_name})) { |
|
| 875 | + return $this->{$class_name}; |
|
| 876 | + } |
|
| 877 | + if (isset ($this->LIB->{$class_name})) { |
|
| 878 | + return $this->LIB->{$class_name}; |
|
| 879 | + } |
|
| 880 | + if ($class_prefix === 'addon' && isset ($this->addons->{$class_name})) { |
|
| 881 | + return $this->addons->{$class_name}; |
|
| 882 | + } |
|
| 883 | + return null; |
|
| 884 | + } |
|
| 885 | + |
|
| 886 | + |
|
| 887 | + |
|
| 888 | + /** |
|
| 889 | + * removes a cached version of the requested class |
|
| 890 | + * |
|
| 891 | + * @param string $class_name |
|
| 892 | + * @param boolean $addon |
|
| 893 | + * @return boolean |
|
| 894 | + */ |
|
| 895 | + public function clear_cached_class($class_name, $addon = false) |
|
| 896 | + { |
|
| 897 | + $class_abbreviation = $this->get_class_abbreviation($class_name); |
|
| 898 | + $class_name = str_replace('\\', '_', $class_name); |
|
| 899 | + // check if class has already been loaded, and return it if it has been |
|
| 900 | + if (isset($this->{$class_abbreviation})) { |
|
| 901 | + $this->{$class_abbreviation} = null; |
|
| 902 | + return true; |
|
| 903 | + } |
|
| 904 | + if (isset($this->{$class_name})) { |
|
| 905 | + $this->{$class_name} = null; |
|
| 906 | + return true; |
|
| 907 | + } |
|
| 908 | + if (isset($this->LIB->{$class_name})) { |
|
| 909 | + unset($this->LIB->{$class_name}); |
|
| 910 | + return true; |
|
| 911 | + } |
|
| 912 | + if ($addon && isset($this->addons->{$class_name})) { |
|
| 913 | + unset($this->addons->{$class_name}); |
|
| 914 | + return true; |
|
| 915 | + } |
|
| 916 | + return false; |
|
| 917 | + } |
|
| 918 | + |
|
| 919 | + |
|
| 920 | + |
|
| 921 | + /** |
|
| 922 | + * attempts to find a full valid filepath for the requested class. |
|
| 923 | + * loops thru each of the base paths in the $file_paths array and appends : "{classname} . {file type} . php" |
|
| 924 | + * then returns that path if the target file has been found and is readable |
|
| 925 | + * |
|
| 926 | + * @param string $class_name |
|
| 927 | + * @param string $type |
|
| 928 | + * @param array $file_paths |
|
| 929 | + * @return string | bool |
|
| 930 | + */ |
|
| 931 | + protected function _resolve_path($class_name, $type = '', $file_paths = array()) |
|
| 932 | + { |
|
| 933 | + // make sure $file_paths is an array |
|
| 934 | + $file_paths = is_array($file_paths) |
|
| 935 | + ? $file_paths |
|
| 936 | + : array($file_paths); |
|
| 937 | + // cycle thru paths |
|
| 938 | + foreach ($file_paths as $key => $file_path) { |
|
| 939 | + // convert all separators to proper DS, if no filepath, then use EE_CLASSES |
|
| 940 | + $file_path = $file_path |
|
| 941 | + ? str_replace(array('/', '\\'), DS, $file_path) |
|
| 942 | + : EE_CLASSES; |
|
| 943 | + // prep file type |
|
| 944 | + $type = ! empty($type) |
|
| 945 | + ? trim($type, '.') . '.' |
|
| 946 | + : ''; |
|
| 947 | + // build full file path |
|
| 948 | + $file_paths[$key] = rtrim($file_path, DS) . DS . $class_name . '.' . $type . 'php'; |
|
| 949 | + //does the file exist and can be read ? |
|
| 950 | + if (is_readable($file_paths[$key])) { |
|
| 951 | + return $file_paths[$key]; |
|
| 952 | + } |
|
| 953 | + } |
|
| 954 | + return false; |
|
| 955 | + } |
|
| 956 | + |
|
| 957 | + |
|
| 958 | + |
|
| 959 | + /** |
|
| 960 | + * basically just performs a require_once() |
|
| 961 | + * but with some error handling |
|
| 962 | + * |
|
| 963 | + * @param string $path |
|
| 964 | + * @param string $class_name |
|
| 965 | + * @param string $type |
|
| 966 | + * @param array $file_paths |
|
| 967 | + * @return bool |
|
| 968 | + * @throws EE_Error |
|
| 969 | + * @throws ReflectionException |
|
| 970 | + */ |
|
| 971 | + protected function _require_file($path, $class_name, $type = '', $file_paths = array()) |
|
| 972 | + { |
|
| 973 | + $this->resolve_legacy_class_parent($class_name); |
|
| 974 | + // don't give up! you gotta... |
|
| 975 | + try { |
|
| 976 | + //does the file exist and can it be read ? |
|
| 977 | + if (! $path) { |
|
| 978 | + // just in case the file has already been autoloaded, |
|
| 979 | + // but discrepancies in the naming schema are preventing it from |
|
| 980 | + // being loaded via one of the EE_Registry::load_*() methods, |
|
| 981 | + // then let's try one last hail mary before throwing an exception |
|
| 982 | + // and call class_exists() again, but with autoloading turned ON |
|
| 983 | + if(class_exists($class_name)) { |
|
| 984 | + return true; |
|
| 985 | + } |
|
| 986 | + // so sorry, can't find the file |
|
| 987 | + throw new EE_Error ( |
|
| 988 | + sprintf( |
|
| 989 | + esc_html__( |
|
| 990 | + 'The %1$s file %2$s could not be located or is not readable due to file permissions. Please ensure that the following filepath(s) are correct: %3$s', |
|
| 991 | + 'event_espresso' |
|
| 992 | + ), |
|
| 993 | + trim($type, '.'), |
|
| 994 | + $class_name, |
|
| 995 | + '<br />' . implode(',<br />', $file_paths) |
|
| 996 | + ) |
|
| 997 | + ); |
|
| 998 | + } |
|
| 999 | + // get the file |
|
| 1000 | + require_once($path); |
|
| 1001 | + // if the class isn't already declared somewhere |
|
| 1002 | + if (class_exists($class_name, false) === false) { |
|
| 1003 | + // so sorry, not a class |
|
| 1004 | + throw new EE_Error( |
|
| 1005 | + sprintf( |
|
| 1006 | + esc_html__('The %s file %s does not appear to contain the %s Class.', 'event_espresso'), |
|
| 1007 | + $type, |
|
| 1008 | + $path, |
|
| 1009 | + $class_name |
|
| 1010 | + ) |
|
| 1011 | + ); |
|
| 1012 | + } |
|
| 1013 | + } catch (EE_Error $e) { |
|
| 1014 | + $e->get_error(); |
|
| 1015 | + return false; |
|
| 1016 | + } |
|
| 1017 | + return true; |
|
| 1018 | + } |
|
| 1019 | + |
|
| 1020 | + |
|
| 1021 | + |
|
| 1022 | + /** |
|
| 1023 | + * Some of our legacy classes that extended a parent class would simply use a require() statement |
|
| 1024 | + * before their class declaration in order to ensure that the parent class was loaded. |
|
| 1025 | + * This is not ideal, but it's nearly impossible to determine the parent class of a non-namespaced class, |
|
| 1026 | + * without triggering a fatal error because the parent class has yet to be loaded and therefore doesn't exist. |
|
| 1027 | + * |
|
| 1028 | + * @param string $class_name |
|
| 1029 | + */ |
|
| 1030 | + protected function resolve_legacy_class_parent($class_name = '') |
|
| 1031 | + { |
|
| 1032 | + try { |
|
| 1033 | + $legacy_parent_class_map = array( |
|
| 1034 | + 'EE_Payment_Processor' => 'core/business/EE_Processor_Base.class.php' |
|
| 1035 | + ); |
|
| 1036 | + if(isset($legacy_parent_class_map[$class_name])) { |
|
| 1037 | + require_once EE_PLUGIN_DIR_PATH . $legacy_parent_class_map[$class_name]; |
|
| 1038 | + } |
|
| 1039 | + } catch (Exception $exception) { |
|
| 1040 | + } |
|
| 1041 | + } |
|
| 1042 | + |
|
| 1043 | + |
|
| 1044 | + |
|
| 1045 | + /** |
|
| 1046 | + * _create_object |
|
| 1047 | + * Attempts to instantiate the requested class via any of the |
|
| 1048 | + * commonly used instantiation methods employed throughout EE. |
|
| 1049 | + * The priority for instantiation is as follows: |
|
| 1050 | + * - abstract classes or any class flagged as "load only" (no instantiation occurs) |
|
| 1051 | + * - model objects via their 'new_instance_from_db' method |
|
| 1052 | + * - model objects via their 'new_instance' method |
|
| 1053 | + * - "singleton" classes" via their 'instance' method |
|
| 1054 | + * - standard instantiable classes via their __constructor |
|
| 1055 | + * Prior to instantiation, if the classname exists in the dependency_map, |
|
| 1056 | + * then the constructor for the requested class will be examined to determine |
|
| 1057 | + * if any dependencies exist, and if they can be injected. |
|
| 1058 | + * If so, then those classes will be added to the array of arguments passed to the constructor |
|
| 1059 | + * |
|
| 1060 | + * @param string $class_name |
|
| 1061 | + * @param array $arguments |
|
| 1062 | + * @param string $type |
|
| 1063 | + * @param bool $from_db |
|
| 1064 | + * @return null|object |
|
| 1065 | + * @throws EE_Error |
|
| 1066 | + * @throws ReflectionException |
|
| 1067 | + */ |
|
| 1068 | + protected function _create_object($class_name, $arguments = array(), $type = '', $from_db = false) |
|
| 1069 | + { |
|
| 1070 | + // create reflection |
|
| 1071 | + $reflector = $this->get_ReflectionClass($class_name); |
|
| 1072 | + // make sure arguments are an array |
|
| 1073 | + $arguments = is_array($arguments) |
|
| 1074 | + ? $arguments |
|
| 1075 | + : array($arguments); |
|
| 1076 | + // and if arguments array is numerically and sequentially indexed, then we want it to remain as is, |
|
| 1077 | + // else wrap it in an additional array so that it doesn't get split into multiple parameters |
|
| 1078 | + $arguments = $this->_array_is_numerically_and_sequentially_indexed($arguments) |
|
| 1079 | + ? $arguments |
|
| 1080 | + : array($arguments); |
|
| 1081 | + // attempt to inject dependencies ? |
|
| 1082 | + if ($this->_dependency_map->has($class_name)) { |
|
| 1083 | + $arguments = $this->_resolve_dependencies($reflector, $class_name, $arguments); |
|
| 1084 | + } |
|
| 1085 | + // instantiate the class if possible |
|
| 1086 | + if ($reflector->isAbstract()) { |
|
| 1087 | + // nothing to instantiate, loading file was enough |
|
| 1088 | + // does not throw an exception so $instantiation_mode is unused |
|
| 1089 | + // $instantiation_mode = "1) no constructor abstract class"; |
|
| 1090 | + return true; |
|
| 1091 | + } |
|
| 1092 | + if (empty($arguments) && $reflector->getConstructor() === null && $reflector->isInstantiable()) { |
|
| 1093 | + // no constructor = static methods only... nothing to instantiate, loading file was enough |
|
| 1094 | + // $instantiation_mode = "2) no constructor but instantiable"; |
|
| 1095 | + return $reflector->newInstance(); |
|
| 1096 | + } |
|
| 1097 | + if ($from_db && method_exists($class_name, 'new_instance_from_db')) { |
|
| 1098 | + // $instantiation_mode = "3) new_instance_from_db()"; |
|
| 1099 | + return call_user_func_array(array($class_name, 'new_instance_from_db'), $arguments); |
|
| 1100 | + } |
|
| 1101 | + if (method_exists($class_name, 'new_instance')) { |
|
| 1102 | + // $instantiation_mode = "4) new_instance()"; |
|
| 1103 | + return call_user_func_array(array($class_name, 'new_instance'), $arguments); |
|
| 1104 | + } |
|
| 1105 | + if (method_exists($class_name, 'instance')) { |
|
| 1106 | + // $instantiation_mode = "5) instance()"; |
|
| 1107 | + return call_user_func_array(array($class_name, 'instance'), $arguments); |
|
| 1108 | + } |
|
| 1109 | + if ($reflector->isInstantiable()) { |
|
| 1110 | + // $instantiation_mode = "6) constructor"; |
|
| 1111 | + return $reflector->newInstanceArgs($arguments); |
|
| 1112 | + } |
|
| 1113 | + // heh ? something's not right ! |
|
| 1114 | + throw new EE_Error( |
|
| 1115 | + sprintf( |
|
| 1116 | + __('The %s file %s could not be instantiated.', 'event_espresso'), |
|
| 1117 | + $type, |
|
| 1118 | + $class_name |
|
| 1119 | + ) |
|
| 1120 | + ); |
|
| 1121 | + } |
|
| 1122 | + |
|
| 1123 | + |
|
| 1124 | + |
|
| 1125 | + /** |
|
| 1126 | + * @see http://stackoverflow.com/questions/173400/how-to-check-if-php-array-is-associative-or-sequential |
|
| 1127 | + * @param array $array |
|
| 1128 | + * @return bool |
|
| 1129 | + */ |
|
| 1130 | + protected function _array_is_numerically_and_sequentially_indexed(array $array) |
|
| 1131 | + { |
|
| 1132 | + return ! empty($array) |
|
| 1133 | + ? array_keys($array) === range(0, count($array) - 1) |
|
| 1134 | + : true; |
|
| 1135 | + } |
|
| 1136 | + |
|
| 1137 | + |
|
| 1138 | + |
|
| 1139 | + /** |
|
| 1140 | + * getReflectionClass |
|
| 1141 | + * checks if a ReflectionClass object has already been generated for a class |
|
| 1142 | + * and returns that instead of creating a new one |
|
| 1143 | + * |
|
| 1144 | + * @param string $class_name |
|
| 1145 | + * @return ReflectionClass |
|
| 1146 | + * @throws ReflectionException |
|
| 1147 | + */ |
|
| 1148 | + public function get_ReflectionClass($class_name) |
|
| 1149 | + { |
|
| 1150 | + if ( |
|
| 1151 | + ! isset($this->_reflectors[$class_name]) |
|
| 1152 | + || ! $this->_reflectors[$class_name] instanceof ReflectionClass |
|
| 1153 | + ) { |
|
| 1154 | + $this->_reflectors[$class_name] = new ReflectionClass($class_name); |
|
| 1155 | + } |
|
| 1156 | + return $this->_reflectors[$class_name]; |
|
| 1157 | + } |
|
| 1158 | + |
|
| 1159 | + |
|
| 1160 | + |
|
| 1161 | + /** |
|
| 1162 | + * _resolve_dependencies |
|
| 1163 | + * examines the constructor for the requested class to determine |
|
| 1164 | + * if any dependencies exist, and if they can be injected. |
|
| 1165 | + * If so, then those classes will be added to the array of arguments passed to the constructor |
|
| 1166 | + * PLZ NOTE: this is achieved by type hinting the constructor params |
|
| 1167 | + * For example: |
|
| 1168 | + * if attempting to load a class "Foo" with the following constructor: |
|
| 1169 | + * __construct( Bar $bar_class, Fighter $grohl_class ) |
|
| 1170 | + * then $bar_class and $grohl_class will be added to the $arguments array, |
|
| 1171 | + * but only IF they are NOT already present in the incoming arguments array, |
|
| 1172 | + * and the correct classes can be loaded |
|
| 1173 | + * |
|
| 1174 | + * @param ReflectionClass $reflector |
|
| 1175 | + * @param string $class_name |
|
| 1176 | + * @param array $arguments |
|
| 1177 | + * @return array |
|
| 1178 | + * @throws EE_Error |
|
| 1179 | + * @throws ReflectionException |
|
| 1180 | + */ |
|
| 1181 | + protected function _resolve_dependencies(ReflectionClass $reflector, $class_name, $arguments = array()) |
|
| 1182 | + { |
|
| 1183 | + // let's examine the constructor |
|
| 1184 | + $constructor = $reflector->getConstructor(); |
|
| 1185 | + // whu? huh? nothing? |
|
| 1186 | + if (! $constructor) { |
|
| 1187 | + return $arguments; |
|
| 1188 | + } |
|
| 1189 | + // get constructor parameters |
|
| 1190 | + $params = $constructor->getParameters(); |
|
| 1191 | + // and the keys for the incoming arguments array so that we can compare existing arguments with what is expected |
|
| 1192 | + $argument_keys = array_keys($arguments); |
|
| 1193 | + // now loop thru all of the constructors expected parameters |
|
| 1194 | + foreach ($params as $index => $param) { |
|
| 1195 | + // is this a dependency for a specific class ? |
|
| 1196 | + $param_class = $param->getClass() |
|
| 1197 | + ? $param->getClass()->name |
|
| 1198 | + : null; |
|
| 1199 | + // BUT WAIT !!! This class may be an alias for something else (or getting replaced at runtime) |
|
| 1200 | + $param_class = $this->_dependency_map->has_alias($param_class, $class_name) |
|
| 1201 | + ? $this->_dependency_map->get_alias($param_class, $class_name) |
|
| 1202 | + : $param_class; |
|
| 1203 | + if ( |
|
| 1204 | + // param is not even a class |
|
| 1205 | + $param_class === null |
|
| 1206 | + // and something already exists in the incoming arguments for this param |
|
| 1207 | + && array_key_exists($index, $argument_keys) |
|
| 1208 | + && array_key_exists($argument_keys[$index], $arguments) |
|
| 1209 | + ) { |
|
| 1210 | + // so let's skip this argument and move on to the next |
|
| 1211 | + continue; |
|
| 1212 | + } |
|
| 1213 | + if ( |
|
| 1214 | + // parameter is type hinted as a class, exists as an incoming argument, AND it's the correct class |
|
| 1215 | + $param_class !== null |
|
| 1216 | + && isset($argument_keys[$index], $arguments[$argument_keys[$index]]) |
|
| 1217 | + && $arguments[$argument_keys[$index]] instanceof $param_class |
|
| 1218 | + ) { |
|
| 1219 | + // skip this argument and move on to the next |
|
| 1220 | + continue; |
|
| 1221 | + } |
|
| 1222 | + if ( |
|
| 1223 | + // parameter is type hinted as a class, and should be injected |
|
| 1224 | + $param_class !== null |
|
| 1225 | + && $this->_dependency_map->has_dependency_for_class($class_name, $param_class) |
|
| 1226 | + ) { |
|
| 1227 | + $arguments = $this->_resolve_dependency( |
|
| 1228 | + $class_name, |
|
| 1229 | + $param_class, |
|
| 1230 | + $arguments, |
|
| 1231 | + $index, |
|
| 1232 | + $argument_keys |
|
| 1233 | + ); |
|
| 1234 | + } else { |
|
| 1235 | + try { |
|
| 1236 | + $arguments[$index] = $param->isDefaultValueAvailable() |
|
| 1237 | + ? $param->getDefaultValue() |
|
| 1238 | + : null; |
|
| 1239 | + } catch (ReflectionException $e) { |
|
| 1240 | + throw new ReflectionException( |
|
| 1241 | + sprintf( |
|
| 1242 | + esc_html__('%1$s for parameter "$%2$s on classname "%3$s"', 'event_espresso'), |
|
| 1243 | + $e->getMessage(), |
|
| 1244 | + $param->getName(), |
|
| 1245 | + $class_name |
|
| 1246 | + ) |
|
| 1247 | + ); |
|
| 1248 | + } |
|
| 1249 | + } |
|
| 1250 | + } |
|
| 1251 | + return $arguments; |
|
| 1252 | + } |
|
| 1253 | + |
|
| 1254 | + |
|
| 1255 | + |
|
| 1256 | + /** |
|
| 1257 | + * @param string $class_name |
|
| 1258 | + * @param string $param_class |
|
| 1259 | + * @param array $arguments |
|
| 1260 | + * @param mixed $index |
|
| 1261 | + * @param array $argument_keys |
|
| 1262 | + * @return array |
|
| 1263 | + * @throws EE_Error |
|
| 1264 | + * @throws ReflectionException |
|
| 1265 | + * @throws InvalidArgumentException |
|
| 1266 | + * @throws InvalidInterfaceException |
|
| 1267 | + * @throws InvalidDataTypeException |
|
| 1268 | + */ |
|
| 1269 | + protected function _resolve_dependency($class_name, $param_class, $arguments, $index, array $argument_keys) |
|
| 1270 | + { |
|
| 1271 | + $dependency = null; |
|
| 1272 | + // should dependency be loaded from cache ? |
|
| 1273 | + $cache_on = $this->_dependency_map->loading_strategy_for_class_dependency( |
|
| 1274 | + $class_name, |
|
| 1275 | + $param_class |
|
| 1276 | + ); |
|
| 1277 | + $cache_on = $cache_on !== EE_Dependency_Map::load_new_object; |
|
| 1278 | + // we might have a dependency... |
|
| 1279 | + // let's MAYBE try and find it in our cache if that's what's been requested |
|
| 1280 | + $cached_class = $cache_on |
|
| 1281 | + ? $this->_get_cached_class($param_class) |
|
| 1282 | + : null; |
|
| 1283 | + // and grab it if it exists |
|
| 1284 | + if ($cached_class instanceof $param_class) { |
|
| 1285 | + $dependency = $cached_class; |
|
| 1286 | + } else if ($param_class !== $class_name) { |
|
| 1287 | + // obtain the loader method from the dependency map |
|
| 1288 | + $loader = $this->_dependency_map->class_loader($param_class); |
|
| 1289 | + // is loader a custom closure ? |
|
| 1290 | + if ($loader instanceof Closure) { |
|
| 1291 | + $dependency = $loader($arguments); |
|
| 1292 | + } else { |
|
| 1293 | + // set the cache on property for the recursive loading call |
|
| 1294 | + $this->_cache_on = $cache_on; |
|
| 1295 | + // if not, then let's try and load it via the registry |
|
| 1296 | + if ($loader && method_exists($this, $loader)) { |
|
| 1297 | + $dependency = $this->{$loader}($param_class); |
|
| 1298 | + } else { |
|
| 1299 | + $dependency = LoaderFactory::getLoader()->load( |
|
| 1300 | + $param_class, |
|
| 1301 | + array(), |
|
| 1302 | + $cache_on |
|
| 1303 | + ); |
|
| 1304 | + } |
|
| 1305 | + } |
|
| 1306 | + } |
|
| 1307 | + // did we successfully find the correct dependency ? |
|
| 1308 | + if ($dependency instanceof $param_class) { |
|
| 1309 | + // then let's inject it into the incoming array of arguments at the correct location |
|
| 1310 | + $arguments[$index] = $dependency; |
|
| 1311 | + } |
|
| 1312 | + return $arguments; |
|
| 1313 | + } |
|
| 1314 | + |
|
| 1315 | + |
|
| 1316 | + |
|
| 1317 | + /** |
|
| 1318 | + * _set_cached_class |
|
| 1319 | + * attempts to cache the instantiated class locally |
|
| 1320 | + * in one of the following places, in the following order: |
|
| 1321 | + * $this->{class_abbreviation} ie: $this->CART |
|
| 1322 | + * $this->{$class_name} ie: $this->Some_Class |
|
| 1323 | + * $this->addon->{$$class_name} ie: $this->addon->Some_Addon_Class |
|
| 1324 | + * $this->LIB->{$class_name} ie: $this->LIB->Some_Class |
|
| 1325 | + * |
|
| 1326 | + * @param object $class_obj |
|
| 1327 | + * @param string $class_name |
|
| 1328 | + * @param string $class_prefix |
|
| 1329 | + * @param bool $from_db |
|
| 1330 | + * @return void |
|
| 1331 | + */ |
|
| 1332 | + protected function _set_cached_class($class_obj, $class_name, $class_prefix = '', $from_db = false) |
|
| 1333 | + { |
|
| 1334 | + if ($class_name === 'EE_Registry' || empty($class_obj)) { |
|
| 1335 | + return; |
|
| 1336 | + } |
|
| 1337 | + // return newly instantiated class |
|
| 1338 | + $class_abbreviation = $this->get_class_abbreviation($class_name, ''); |
|
| 1339 | + if ($class_abbreviation) { |
|
| 1340 | + $this->{$class_abbreviation} = $class_obj; |
|
| 1341 | + return; |
|
| 1342 | + } |
|
| 1343 | + $class_name = str_replace('\\', '_', $class_name); |
|
| 1344 | + if (property_exists($this, $class_name)) { |
|
| 1345 | + $this->{$class_name} = $class_obj; |
|
| 1346 | + return; |
|
| 1347 | + } |
|
| 1348 | + if ($class_prefix === 'addon') { |
|
| 1349 | + $this->addons->{$class_name} = $class_obj; |
|
| 1350 | + return; |
|
| 1351 | + } |
|
| 1352 | + if (! $from_db) { |
|
| 1353 | + $this->LIB->{$class_name} = $class_obj; |
|
| 1354 | + } |
|
| 1355 | + } |
|
| 1356 | + |
|
| 1357 | + |
|
| 1358 | + |
|
| 1359 | + /** |
|
| 1360 | + * call any loader that's been registered in the EE_Dependency_Map::$_class_loaders array |
|
| 1361 | + * |
|
| 1362 | + * @param string $classname PLEASE NOTE: the class name needs to match what's registered |
|
| 1363 | + * in the EE_Dependency_Map::$_class_loaders array, |
|
| 1364 | + * including the class prefix, ie: "EE_", "EEM_", "EEH_", etc |
|
| 1365 | + * @param array $arguments |
|
| 1366 | + * @return object |
|
| 1367 | + */ |
|
| 1368 | + public static function factory($classname, $arguments = array()) |
|
| 1369 | + { |
|
| 1370 | + $loader = self::instance()->_dependency_map->class_loader($classname); |
|
| 1371 | + if ($loader instanceof Closure) { |
|
| 1372 | + return $loader($arguments); |
|
| 1373 | + } |
|
| 1374 | + if (method_exists(self::instance(), $loader)) { |
|
| 1375 | + return self::instance()->{$loader}($classname, $arguments); |
|
| 1376 | + } |
|
| 1377 | + return null; |
|
| 1378 | + } |
|
| 1379 | + |
|
| 1380 | + |
|
| 1381 | + |
|
| 1382 | + /** |
|
| 1383 | + * Gets the addon by its class name |
|
| 1384 | + * |
|
| 1385 | + * @param string $class_name |
|
| 1386 | + * @return EE_Addon |
|
| 1387 | + */ |
|
| 1388 | + public function getAddon($class_name) |
|
| 1389 | + { |
|
| 1390 | + $class_name = str_replace('\\', '_', $class_name); |
|
| 1391 | + return $this->addons->{$class_name}; |
|
| 1392 | + } |
|
| 1393 | + |
|
| 1394 | + |
|
| 1395 | + /** |
|
| 1396 | + * removes the addon from the internal cache |
|
| 1397 | + * |
|
| 1398 | + * @param string $class_name |
|
| 1399 | + * @return EE_Addon |
|
| 1400 | + */ |
|
| 1401 | + public function removeAddon($class_name) |
|
| 1402 | + { |
|
| 1403 | + $class_name = str_replace('\\', '_', $class_name); |
|
| 1404 | + $this->addons->{$class_name} = null; |
|
| 1405 | + } |
|
| 1406 | + |
|
| 1407 | + |
|
| 1408 | + |
|
| 1409 | + /** |
|
| 1410 | + * Gets the addon by its name/slug (not classname. For that, just |
|
| 1411 | + * use the get_addon() method above |
|
| 1412 | + * |
|
| 1413 | + * @param string $name |
|
| 1414 | + * @return EE_Addon |
|
| 1415 | + */ |
|
| 1416 | + public function get_addon_by_name($name) |
|
| 1417 | + { |
|
| 1418 | + foreach ($this->addons as $addon) { |
|
| 1419 | + if ($addon->name() === $name) { |
|
| 1420 | + return $addon; |
|
| 1421 | + } |
|
| 1422 | + } |
|
| 1423 | + return null; |
|
| 1424 | + } |
|
| 1425 | + |
|
| 1426 | + |
|
| 1427 | + |
|
| 1428 | + /** |
|
| 1429 | + * Gets an array of all the registered addons, where the keys are their names. |
|
| 1430 | + * (ie, what each returns for their name() function) |
|
| 1431 | + * They're already available on EE_Registry::instance()->addons as properties, |
|
| 1432 | + * where each property's name is the addon's classname, |
|
| 1433 | + * So if you just want to get the addon by classname, |
|
| 1434 | + * OR use the get_addon() method above. |
|
| 1435 | + * PLEASE NOTE: |
|
| 1436 | + * addons with Fully Qualified Class Names |
|
| 1437 | + * have had the namespace separators converted to underscores, |
|
| 1438 | + * so a classname like Fully\Qualified\ClassName |
|
| 1439 | + * would have been converted to Fully_Qualified_ClassName |
|
| 1440 | + * |
|
| 1441 | + * @return EE_Addon[] where the KEYS are the addon's name() |
|
| 1442 | + */ |
|
| 1443 | + public function get_addons_by_name() |
|
| 1444 | + { |
|
| 1445 | + $addons = array(); |
|
| 1446 | + foreach ($this->addons as $addon) { |
|
| 1447 | + $addons[$addon->name()] = $addon; |
|
| 1448 | + } |
|
| 1449 | + return $addons; |
|
| 1450 | + } |
|
| 1451 | + |
|
| 1452 | + |
|
| 1453 | + /** |
|
| 1454 | + * Resets the specified model's instance AND makes sure EE_Registry doesn't keep |
|
| 1455 | + * a stale copy of it around |
|
| 1456 | + * |
|
| 1457 | + * @param string $model_name |
|
| 1458 | + * @return \EEM_Base |
|
| 1459 | + * @throws \EE_Error |
|
| 1460 | + */ |
|
| 1461 | + public function reset_model($model_name) |
|
| 1462 | + { |
|
| 1463 | + $model_class_name = strpos($model_name, 'EEM_') !== 0 |
|
| 1464 | + ? "EEM_{$model_name}" |
|
| 1465 | + : $model_name; |
|
| 1466 | + if (! isset($this->LIB->{$model_class_name}) || ! $this->LIB->{$model_class_name} instanceof EEM_Base) { |
|
| 1467 | + return null; |
|
| 1468 | + } |
|
| 1469 | + //get that model reset it and make sure we nuke the old reference to it |
|
| 1470 | + if ($this->LIB->{$model_class_name} instanceof $model_class_name |
|
| 1471 | + && is_callable( |
|
| 1472 | + array($model_class_name, 'reset') |
|
| 1473 | + )) { |
|
| 1474 | + $this->LIB->{$model_class_name} = $this->LIB->{$model_class_name}->reset(); |
|
| 1475 | + } else { |
|
| 1476 | + throw new EE_Error(sprintf(esc_html__('Model %s does not have a method "reset"', 'event_espresso'), $model_name)); |
|
| 1477 | + } |
|
| 1478 | + return $this->LIB->{$model_class_name}; |
|
| 1479 | + } |
|
| 1480 | + |
|
| 1481 | + |
|
| 1482 | + |
|
| 1483 | + /** |
|
| 1484 | + * Resets the registry. |
|
| 1485 | + * The criteria for what gets reset is based on what can be shared between sites on the same request when |
|
| 1486 | + * switch_to_blog is used in a multisite install. Here is a list of things that are NOT reset. |
|
| 1487 | + * - $_dependency_map |
|
| 1488 | + * - $_class_abbreviations |
|
| 1489 | + * - $NET_CFG (EE_Network_Config): The config is shared network wide so no need to reset. |
|
| 1490 | + * - $REQ: Still on the same request so no need to change. |
|
| 1491 | + * - $CAP: There is no site specific state in the EE_Capability class. |
|
| 1492 | + * - $SSN: Although ideally, the session should not be shared between site switches, we can't reset it because only |
|
| 1493 | + * one Session can be active in a single request. Resetting could resolve in "headers already sent" errors. |
|
| 1494 | + * - $addons: In multisite, the state of the addons is something controlled via hooks etc in a normal request. So |
|
| 1495 | + * for now, we won't reset the addons because it could break calls to an add-ons class/methods in the |
|
| 1496 | + * switch or on the restore. |
|
| 1497 | + * - $modules |
|
| 1498 | + * - $shortcodes |
|
| 1499 | + * - $widgets |
|
| 1500 | + * |
|
| 1501 | + * @param boolean $hard [deprecated] |
|
| 1502 | + * @param boolean $reinstantiate whether to create new instances of EE_Registry's singletons too, |
|
| 1503 | + * or just reset without re-instantiating (handy to set to FALSE if you're not |
|
| 1504 | + * sure if you CAN currently reinstantiate the singletons at the moment) |
|
| 1505 | + * @param bool $reset_models Defaults to true. When false, then the models are not reset. This is so |
|
| 1506 | + * client |
|
| 1507 | + * code instead can just change the model context to a different blog id if |
|
| 1508 | + * necessary |
|
| 1509 | + * @return EE_Registry |
|
| 1510 | + * @throws EE_Error |
|
| 1511 | + * @throws ReflectionException |
|
| 1512 | + */ |
|
| 1513 | + public static function reset($hard = false, $reinstantiate = true, $reset_models = true) |
|
| 1514 | + { |
|
| 1515 | + $instance = self::instance(); |
|
| 1516 | + $instance->_cache_on = true; |
|
| 1517 | + // reset some "special" classes |
|
| 1518 | + EEH_Activation::reset(); |
|
| 1519 | + $hard = apply_filters( 'FHEE__EE_Registry__reset__hard', $hard); |
|
| 1520 | + $instance->CFG = EE_Config::reset($hard, $reinstantiate); |
|
| 1521 | + $instance->CART = null; |
|
| 1522 | + $instance->MRM = null; |
|
| 1523 | + $instance->AssetsRegistry = $instance->create('EventEspresso\core\services\assets\Registry'); |
|
| 1524 | + //messages reset |
|
| 1525 | + EED_Messages::reset(); |
|
| 1526 | + //handle of objects cached on LIB |
|
| 1527 | + foreach (array('LIB', 'modules') as $cache) { |
|
| 1528 | + foreach ($instance->{$cache} as $class_name => $class) { |
|
| 1529 | + if (self::_reset_and_unset_object($class, $reset_models)) { |
|
| 1530 | + unset($instance->{$cache}->{$class_name}); |
|
| 1531 | + } |
|
| 1532 | + } |
|
| 1533 | + } |
|
| 1534 | + return $instance; |
|
| 1535 | + } |
|
| 1536 | + |
|
| 1537 | + |
|
| 1538 | + |
|
| 1539 | + /** |
|
| 1540 | + * if passed object implements ResettableInterface, then call it's reset() method |
|
| 1541 | + * if passed object implements InterminableInterface, then return false, |
|
| 1542 | + * to indicate that it should NOT be cleared from the Registry cache |
|
| 1543 | + * |
|
| 1544 | + * @param $object |
|
| 1545 | + * @param bool $reset_models |
|
| 1546 | + * @return bool returns true if cached object should be unset |
|
| 1547 | + */ |
|
| 1548 | + private static function _reset_and_unset_object($object, $reset_models) |
|
| 1549 | + { |
|
| 1550 | + if (! is_object($object)) { |
|
| 1551 | + // don't unset anything that's not an object |
|
| 1552 | + return false; |
|
| 1553 | + } |
|
| 1554 | + if ($object instanceof EED_Module) { |
|
| 1555 | + $object::reset(); |
|
| 1556 | + // don't unset modules |
|
| 1557 | + return false; |
|
| 1558 | + } |
|
| 1559 | + if ($object instanceof ResettableInterface) { |
|
| 1560 | + if ($object instanceof EEM_Base) { |
|
| 1561 | + if ($reset_models) { |
|
| 1562 | + $object->reset(); |
|
| 1563 | + return true; |
|
| 1564 | + } |
|
| 1565 | + return false; |
|
| 1566 | + } |
|
| 1567 | + $object->reset(); |
|
| 1568 | + return true; |
|
| 1569 | + } |
|
| 1570 | + if (! $object instanceof InterminableInterface) { |
|
| 1571 | + return true; |
|
| 1572 | + } |
|
| 1573 | + return false; |
|
| 1574 | + } |
|
| 1575 | + |
|
| 1576 | + |
|
| 1577 | + |
|
| 1578 | + /** |
|
| 1579 | + * Gets all the custom post type models defined |
|
| 1580 | + * |
|
| 1581 | + * @return array keys are model "short names" (Eg "Event") and keys are classnames (eg "EEM_Event") |
|
| 1582 | + */ |
|
| 1583 | + public function cpt_models() |
|
| 1584 | + { |
|
| 1585 | + $cpt_models = array(); |
|
| 1586 | + foreach ($this->non_abstract_db_models as $short_name => $classname) { |
|
| 1587 | + if (is_subclass_of($classname, 'EEM_CPT_Base')) { |
|
| 1588 | + $cpt_models[$short_name] = $classname; |
|
| 1589 | + } |
|
| 1590 | + } |
|
| 1591 | + return $cpt_models; |
|
| 1592 | + } |
|
| 1593 | + |
|
| 1594 | + |
|
| 1595 | + |
|
| 1596 | + /** |
|
| 1597 | + * @return \EE_Config |
|
| 1598 | + */ |
|
| 1599 | + public static function CFG() |
|
| 1600 | + { |
|
| 1601 | + return self::instance()->CFG; |
|
| 1602 | + } |
|
| 1603 | 1603 | |
| 1604 | 1604 | |
| 1605 | 1605 | } |
@@ -18,105 +18,105 @@ |
||
| 18 | 18 | abstract class DomainBase |
| 19 | 19 | { |
| 20 | 20 | |
| 21 | - /** |
|
| 22 | - * Equivalent to `__FILE__` for main plugin file. |
|
| 23 | - * |
|
| 24 | - * @var string |
|
| 25 | - */ |
|
| 26 | - private $plugin_file; |
|
| 27 | - |
|
| 28 | - /** |
|
| 29 | - * String indicating version for plugin |
|
| 30 | - * |
|
| 31 | - * @var string |
|
| 32 | - */ |
|
| 33 | - private $version; |
|
| 34 | - |
|
| 35 | - /** |
|
| 36 | - * @var string $plugin_basename |
|
| 37 | - */ |
|
| 38 | - private $plugin_basename; |
|
| 39 | - |
|
| 40 | - /** |
|
| 41 | - * @var string $plugin_path |
|
| 42 | - */ |
|
| 43 | - private $plugin_path; |
|
| 44 | - |
|
| 45 | - /** |
|
| 46 | - * @var string $plugin_url |
|
| 47 | - */ |
|
| 48 | - private $plugin_url; |
|
| 49 | - |
|
| 50 | - |
|
| 51 | - |
|
| 52 | - /** |
|
| 53 | - * Initializes internal properties. |
|
| 54 | - * |
|
| 55 | - * @param string $plugin_file |
|
| 56 | - * @param string $version |
|
| 57 | - */ |
|
| 58 | - public function __construct($plugin_file, $version) |
|
| 59 | - { |
|
| 60 | - $this->plugin_file = $plugin_file; |
|
| 61 | - $this->version = $version; |
|
| 62 | - $this->plugin_basename = plugin_basename($plugin_file); |
|
| 63 | - $this->plugin_path = plugin_dir_path($plugin_file); |
|
| 64 | - $this->plugin_url = plugin_dir_url($plugin_file); |
|
| 65 | - } |
|
| 66 | - |
|
| 67 | - |
|
| 68 | - |
|
| 69 | - /** |
|
| 70 | - * @return string |
|
| 71 | - * @throws DomainException |
|
| 72 | - */ |
|
| 73 | - public function pluginFile() |
|
| 74 | - { |
|
| 75 | - return $this->plugin_file; |
|
| 76 | - } |
|
| 77 | - |
|
| 78 | - |
|
| 79 | - |
|
| 80 | - /** |
|
| 81 | - * @return string |
|
| 82 | - * @throws DomainException |
|
| 83 | - */ |
|
| 84 | - public function pluginBasename() |
|
| 85 | - { |
|
| 86 | - return $this->plugin_basename; |
|
| 87 | - } |
|
| 88 | - |
|
| 89 | - |
|
| 90 | - |
|
| 91 | - /** |
|
| 92 | - * @return string |
|
| 93 | - */ |
|
| 94 | - public function pluginPath() |
|
| 95 | - { |
|
| 96 | - return $this->plugin_path; |
|
| 97 | - } |
|
| 98 | - |
|
| 99 | - |
|
| 100 | - |
|
| 101 | - /** |
|
| 102 | - * @return string |
|
| 103 | - * @throws DomainException |
|
| 104 | - */ |
|
| 105 | - public function pluginUrl() |
|
| 106 | - { |
|
| 107 | - return $this->plugin_url; |
|
| 108 | - } |
|
| 109 | - |
|
| 110 | - |
|
| 111 | - |
|
| 112 | - /** |
|
| 113 | - * @return string |
|
| 114 | - * @throws DomainException |
|
| 115 | - */ |
|
| 116 | - public function version() |
|
| 117 | - { |
|
| 118 | - return $this->version; |
|
| 119 | - } |
|
| 21 | + /** |
|
| 22 | + * Equivalent to `__FILE__` for main plugin file. |
|
| 23 | + * |
|
| 24 | + * @var string |
|
| 25 | + */ |
|
| 26 | + private $plugin_file; |
|
| 27 | + |
|
| 28 | + /** |
|
| 29 | + * String indicating version for plugin |
|
| 30 | + * |
|
| 31 | + * @var string |
|
| 32 | + */ |
|
| 33 | + private $version; |
|
| 34 | + |
|
| 35 | + /** |
|
| 36 | + * @var string $plugin_basename |
|
| 37 | + */ |
|
| 38 | + private $plugin_basename; |
|
| 39 | + |
|
| 40 | + /** |
|
| 41 | + * @var string $plugin_path |
|
| 42 | + */ |
|
| 43 | + private $plugin_path; |
|
| 44 | + |
|
| 45 | + /** |
|
| 46 | + * @var string $plugin_url |
|
| 47 | + */ |
|
| 48 | + private $plugin_url; |
|
| 49 | + |
|
| 50 | + |
|
| 51 | + |
|
| 52 | + /** |
|
| 53 | + * Initializes internal properties. |
|
| 54 | + * |
|
| 55 | + * @param string $plugin_file |
|
| 56 | + * @param string $version |
|
| 57 | + */ |
|
| 58 | + public function __construct($plugin_file, $version) |
|
| 59 | + { |
|
| 60 | + $this->plugin_file = $plugin_file; |
|
| 61 | + $this->version = $version; |
|
| 62 | + $this->plugin_basename = plugin_basename($plugin_file); |
|
| 63 | + $this->plugin_path = plugin_dir_path($plugin_file); |
|
| 64 | + $this->plugin_url = plugin_dir_url($plugin_file); |
|
| 65 | + } |
|
| 66 | + |
|
| 67 | + |
|
| 68 | + |
|
| 69 | + /** |
|
| 70 | + * @return string |
|
| 71 | + * @throws DomainException |
|
| 72 | + */ |
|
| 73 | + public function pluginFile() |
|
| 74 | + { |
|
| 75 | + return $this->plugin_file; |
|
| 76 | + } |
|
| 77 | + |
|
| 78 | + |
|
| 79 | + |
|
| 80 | + /** |
|
| 81 | + * @return string |
|
| 82 | + * @throws DomainException |
|
| 83 | + */ |
|
| 84 | + public function pluginBasename() |
|
| 85 | + { |
|
| 86 | + return $this->plugin_basename; |
|
| 87 | + } |
|
| 88 | + |
|
| 89 | + |
|
| 90 | + |
|
| 91 | + /** |
|
| 92 | + * @return string |
|
| 93 | + */ |
|
| 94 | + public function pluginPath() |
|
| 95 | + { |
|
| 96 | + return $this->plugin_path; |
|
| 97 | + } |
|
| 98 | + |
|
| 99 | + |
|
| 100 | + |
|
| 101 | + /** |
|
| 102 | + * @return string |
|
| 103 | + * @throws DomainException |
|
| 104 | + */ |
|
| 105 | + public function pluginUrl() |
|
| 106 | + { |
|
| 107 | + return $this->plugin_url; |
|
| 108 | + } |
|
| 109 | + |
|
| 110 | + |
|
| 111 | + |
|
| 112 | + /** |
|
| 113 | + * @return string |
|
| 114 | + * @throws DomainException |
|
| 115 | + */ |
|
| 116 | + public function version() |
|
| 117 | + { |
|
| 118 | + return $this->version; |
|
| 119 | + } |
|
| 120 | 120 | |
| 121 | 121 | |
| 122 | 122 | } |