@@ -21,146 +21,146 @@ |
||
| 21 | 21 | class CachingLoader extends LoaderDecorator |
| 22 | 22 | { |
| 23 | 23 | |
| 24 | - /** |
|
| 25 | - * @var CollectionInterface $cache |
|
| 26 | - */ |
|
| 27 | - protected $cache; |
|
| 28 | - |
|
| 29 | - /** |
|
| 30 | - * @var string $identifier |
|
| 31 | - */ |
|
| 32 | - protected $identifier; |
|
| 33 | - |
|
| 34 | - |
|
| 35 | - |
|
| 36 | - /** |
|
| 37 | - * CachingLoader constructor. |
|
| 38 | - * |
|
| 39 | - * @param LoaderDecoratorInterface $loader |
|
| 40 | - * @param CollectionInterface $cache |
|
| 41 | - * @param string $identifier |
|
| 42 | - * @throws InvalidDataTypeException |
|
| 43 | - */ |
|
| 44 | - public function __construct(LoaderDecoratorInterface $loader, CollectionInterface $cache, $identifier = '') |
|
| 45 | - { |
|
| 46 | - parent::__construct($loader); |
|
| 47 | - $this->cache = $cache; |
|
| 48 | - $this->setIdentifier($identifier); |
|
| 49 | - if ($this->identifier !== '') { |
|
| 50 | - // to only clear this cache, and assuming an identifier has been set, simply do the following: |
|
| 51 | - // do_action('AHEE__EventEspresso_core_services_loaders_CachingLoader__resetCache__IDENTIFIER'); |
|
| 52 | - // where "IDENTIFIER" = the string that was set during construction |
|
| 53 | - add_action( |
|
| 54 | - "AHEE__EventEspresso_core_services_loaders_CachingLoader__resetCache__{$identifier}", |
|
| 55 | - array($this, 'reset') |
|
| 56 | - ); |
|
| 57 | - } |
|
| 58 | - // to clear ALL caches, simply do the following: |
|
| 59 | - // do_action('AHEE__EventEspresso_core_services_loaders_CachingLoader__resetCache'); |
|
| 60 | - add_action( |
|
| 61 | - 'AHEE__EventEspresso_core_services_loaders_CachingLoader__resetCache', |
|
| 62 | - array($this, 'reset') |
|
| 63 | - ); |
|
| 64 | - } |
|
| 65 | - |
|
| 66 | - |
|
| 67 | - |
|
| 68 | - /** |
|
| 69 | - * @return string |
|
| 70 | - */ |
|
| 71 | - public function identifier() |
|
| 72 | - { |
|
| 73 | - return $this->identifier; |
|
| 74 | - } |
|
| 75 | - |
|
| 76 | - |
|
| 77 | - |
|
| 78 | - /** |
|
| 79 | - * @param string $identifier |
|
| 80 | - * @throws InvalidDataTypeException |
|
| 81 | - */ |
|
| 82 | - private function setIdentifier($identifier) |
|
| 83 | - { |
|
| 84 | - if ( ! is_string($identifier)) { |
|
| 85 | - throw new InvalidDataTypeException('$identifier', $identifier, 'string'); |
|
| 86 | - } |
|
| 87 | - $this->identifier = $identifier; |
|
| 88 | - } |
|
| 89 | - |
|
| 90 | - |
|
| 91 | - |
|
| 92 | - /** |
|
| 93 | - * @param string $fqcn |
|
| 94 | - * @param array $arguments |
|
| 95 | - * @param bool $shared |
|
| 96 | - * @return mixed |
|
| 97 | - */ |
|
| 98 | - public function load($fqcn, $arguments = array(), $shared = true) |
|
| 99 | - { |
|
| 100 | - $fqcn = ltrim($fqcn, '\\'); |
|
| 101 | - // caching can be turned off via the following code: |
|
| 102 | - // add_filter('FHEE__EventEspresso_core_services_loaders_CachingLoader__load__bypass_cache', '__return_true'); |
|
| 103 | - if( |
|
| 104 | - apply_filters( |
|
| 105 | - 'FHEE__EventEspresso_core_services_loaders_CachingLoader__load__bypass_cache', |
|
| 106 | - false, |
|
| 107 | - $this |
|
| 108 | - ) |
|
| 109 | - ){ |
|
| 110 | - // even though $shared might be true, caching could be bypassed for whatever reason, |
|
| 111 | - // so we don't want the core loader to cache anything, therefore caching is turned off |
|
| 112 | - return $this->loader->load($fqcn, $arguments, false); |
|
| 113 | - } |
|
| 114 | - $identifier = md5($fqcn . $this->getIdentifierForArgument($arguments)); |
|
| 115 | - if($this->cache->has($identifier)){ |
|
| 116 | - return $this->cache->get($identifier); |
|
| 117 | - } |
|
| 118 | - $object = $this->loader->load($fqcn, $arguments, $shared); |
|
| 119 | - if($object instanceof $fqcn){ |
|
| 120 | - $this->cache->add($object, $identifier); |
|
| 121 | - } |
|
| 122 | - return $object; |
|
| 123 | - } |
|
| 124 | - |
|
| 125 | - |
|
| 126 | - |
|
| 127 | - /** |
|
| 128 | - * empties cache and calls reset() on loader if method exists |
|
| 129 | - */ |
|
| 130 | - public function reset() |
|
| 131 | - { |
|
| 132 | - $this->cache->trashAndDetachAll(); |
|
| 133 | - $this->loader->reset(); |
|
| 134 | - } |
|
| 135 | - |
|
| 136 | - |
|
| 137 | - |
|
| 138 | - /** |
|
| 139 | - * build a string representation of a class' arguments |
|
| 140 | - * (mostly because Closures can't be serialized) |
|
| 141 | - * |
|
| 142 | - * @param array $arguments |
|
| 143 | - * @return string |
|
| 144 | - */ |
|
| 145 | - private function getIdentifierForArgument(array $arguments) |
|
| 146 | - { |
|
| 147 | - $identifier = ''; |
|
| 148 | - foreach ($arguments as $argument) { |
|
| 149 | - switch (true) { |
|
| 150 | - case is_object($argument) : |
|
| 151 | - case $argument instanceof Closure : |
|
| 152 | - $identifier .= spl_object_hash($argument); |
|
| 153 | - break; |
|
| 154 | - case is_array($argument) : |
|
| 155 | - $identifier .= $this->getIdentifierForArgument($argument); |
|
| 156 | - break; |
|
| 157 | - default : |
|
| 158 | - $identifier .= $argument; |
|
| 159 | - break; |
|
| 160 | - } |
|
| 161 | - } |
|
| 162 | - return $identifier; |
|
| 163 | - } |
|
| 24 | + /** |
|
| 25 | + * @var CollectionInterface $cache |
|
| 26 | + */ |
|
| 27 | + protected $cache; |
|
| 28 | + |
|
| 29 | + /** |
|
| 30 | + * @var string $identifier |
|
| 31 | + */ |
|
| 32 | + protected $identifier; |
|
| 33 | + |
|
| 34 | + |
|
| 35 | + |
|
| 36 | + /** |
|
| 37 | + * CachingLoader constructor. |
|
| 38 | + * |
|
| 39 | + * @param LoaderDecoratorInterface $loader |
|
| 40 | + * @param CollectionInterface $cache |
|
| 41 | + * @param string $identifier |
|
| 42 | + * @throws InvalidDataTypeException |
|
| 43 | + */ |
|
| 44 | + public function __construct(LoaderDecoratorInterface $loader, CollectionInterface $cache, $identifier = '') |
|
| 45 | + { |
|
| 46 | + parent::__construct($loader); |
|
| 47 | + $this->cache = $cache; |
|
| 48 | + $this->setIdentifier($identifier); |
|
| 49 | + if ($this->identifier !== '') { |
|
| 50 | + // to only clear this cache, and assuming an identifier has been set, simply do the following: |
|
| 51 | + // do_action('AHEE__EventEspresso_core_services_loaders_CachingLoader__resetCache__IDENTIFIER'); |
|
| 52 | + // where "IDENTIFIER" = the string that was set during construction |
|
| 53 | + add_action( |
|
| 54 | + "AHEE__EventEspresso_core_services_loaders_CachingLoader__resetCache__{$identifier}", |
|
| 55 | + array($this, 'reset') |
|
| 56 | + ); |
|
| 57 | + } |
|
| 58 | + // to clear ALL caches, simply do the following: |
|
| 59 | + // do_action('AHEE__EventEspresso_core_services_loaders_CachingLoader__resetCache'); |
|
| 60 | + add_action( |
|
| 61 | + 'AHEE__EventEspresso_core_services_loaders_CachingLoader__resetCache', |
|
| 62 | + array($this, 'reset') |
|
| 63 | + ); |
|
| 64 | + } |
|
| 65 | + |
|
| 66 | + |
|
| 67 | + |
|
| 68 | + /** |
|
| 69 | + * @return string |
|
| 70 | + */ |
|
| 71 | + public function identifier() |
|
| 72 | + { |
|
| 73 | + return $this->identifier; |
|
| 74 | + } |
|
| 75 | + |
|
| 76 | + |
|
| 77 | + |
|
| 78 | + /** |
|
| 79 | + * @param string $identifier |
|
| 80 | + * @throws InvalidDataTypeException |
|
| 81 | + */ |
|
| 82 | + private function setIdentifier($identifier) |
|
| 83 | + { |
|
| 84 | + if ( ! is_string($identifier)) { |
|
| 85 | + throw new InvalidDataTypeException('$identifier', $identifier, 'string'); |
|
| 86 | + } |
|
| 87 | + $this->identifier = $identifier; |
|
| 88 | + } |
|
| 89 | + |
|
| 90 | + |
|
| 91 | + |
|
| 92 | + /** |
|
| 93 | + * @param string $fqcn |
|
| 94 | + * @param array $arguments |
|
| 95 | + * @param bool $shared |
|
| 96 | + * @return mixed |
|
| 97 | + */ |
|
| 98 | + public function load($fqcn, $arguments = array(), $shared = true) |
|
| 99 | + { |
|
| 100 | + $fqcn = ltrim($fqcn, '\\'); |
|
| 101 | + // caching can be turned off via the following code: |
|
| 102 | + // add_filter('FHEE__EventEspresso_core_services_loaders_CachingLoader__load__bypass_cache', '__return_true'); |
|
| 103 | + if( |
|
| 104 | + apply_filters( |
|
| 105 | + 'FHEE__EventEspresso_core_services_loaders_CachingLoader__load__bypass_cache', |
|
| 106 | + false, |
|
| 107 | + $this |
|
| 108 | + ) |
|
| 109 | + ){ |
|
| 110 | + // even though $shared might be true, caching could be bypassed for whatever reason, |
|
| 111 | + // so we don't want the core loader to cache anything, therefore caching is turned off |
|
| 112 | + return $this->loader->load($fqcn, $arguments, false); |
|
| 113 | + } |
|
| 114 | + $identifier = md5($fqcn . $this->getIdentifierForArgument($arguments)); |
|
| 115 | + if($this->cache->has($identifier)){ |
|
| 116 | + return $this->cache->get($identifier); |
|
| 117 | + } |
|
| 118 | + $object = $this->loader->load($fqcn, $arguments, $shared); |
|
| 119 | + if($object instanceof $fqcn){ |
|
| 120 | + $this->cache->add($object, $identifier); |
|
| 121 | + } |
|
| 122 | + return $object; |
|
| 123 | + } |
|
| 124 | + |
|
| 125 | + |
|
| 126 | + |
|
| 127 | + /** |
|
| 128 | + * empties cache and calls reset() on loader if method exists |
|
| 129 | + */ |
|
| 130 | + public function reset() |
|
| 131 | + { |
|
| 132 | + $this->cache->trashAndDetachAll(); |
|
| 133 | + $this->loader->reset(); |
|
| 134 | + } |
|
| 135 | + |
|
| 136 | + |
|
| 137 | + |
|
| 138 | + /** |
|
| 139 | + * build a string representation of a class' arguments |
|
| 140 | + * (mostly because Closures can't be serialized) |
|
| 141 | + * |
|
| 142 | + * @param array $arguments |
|
| 143 | + * @return string |
|
| 144 | + */ |
|
| 145 | + private function getIdentifierForArgument(array $arguments) |
|
| 146 | + { |
|
| 147 | + $identifier = ''; |
|
| 148 | + foreach ($arguments as $argument) { |
|
| 149 | + switch (true) { |
|
| 150 | + case is_object($argument) : |
|
| 151 | + case $argument instanceof Closure : |
|
| 152 | + $identifier .= spl_object_hash($argument); |
|
| 153 | + break; |
|
| 154 | + case is_array($argument) : |
|
| 155 | + $identifier .= $this->getIdentifierForArgument($argument); |
|
| 156 | + break; |
|
| 157 | + default : |
|
| 158 | + $identifier .= $argument; |
|
| 159 | + break; |
|
| 160 | + } |
|
| 161 | + } |
|
| 162 | + return $identifier; |
|
| 163 | + } |
|
| 164 | 164 | |
| 165 | 165 | |
| 166 | 166 | } |
@@ -100,23 +100,23 @@ |
||
| 100 | 100 | $fqcn = ltrim($fqcn, '\\'); |
| 101 | 101 | // caching can be turned off via the following code: |
| 102 | 102 | // add_filter('FHEE__EventEspresso_core_services_loaders_CachingLoader__load__bypass_cache', '__return_true'); |
| 103 | - if( |
|
| 103 | + if ( |
|
| 104 | 104 | apply_filters( |
| 105 | 105 | 'FHEE__EventEspresso_core_services_loaders_CachingLoader__load__bypass_cache', |
| 106 | 106 | false, |
| 107 | 107 | $this |
| 108 | 108 | ) |
| 109 | - ){ |
|
| 109 | + ) { |
|
| 110 | 110 | // even though $shared might be true, caching could be bypassed for whatever reason, |
| 111 | 111 | // so we don't want the core loader to cache anything, therefore caching is turned off |
| 112 | 112 | return $this->loader->load($fqcn, $arguments, false); |
| 113 | 113 | } |
| 114 | - $identifier = md5($fqcn . $this->getIdentifierForArgument($arguments)); |
|
| 115 | - if($this->cache->has($identifier)){ |
|
| 114 | + $identifier = md5($fqcn.$this->getIdentifierForArgument($arguments)); |
|
| 115 | + if ($this->cache->has($identifier)) { |
|
| 116 | 116 | return $this->cache->get($identifier); |
| 117 | 117 | } |
| 118 | 118 | $object = $this->loader->load($fqcn, $arguments, $shared); |
| 119 | - if($object instanceof $fqcn){ |
|
| 119 | + if ($object instanceof $fqcn) { |
|
| 120 | 120 | $this->cache->add($object, $identifier); |
| 121 | 121 | } |
| 122 | 122 | return $object; |
@@ -32,114 +32,114 @@ |
||
| 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 | - ? (bool)$arguments['EE_Registry::create(from_db)'] |
|
| 96 | - : false; |
|
| 97 | - // load_only |
|
| 98 | - $load_only = isset($arguments['EE_Registry::create(load_only)']) |
|
| 99 | - ? (bool)$arguments['EE_Registry::create(load_only)'] |
|
| 100 | - : false; |
|
| 101 | - // addon |
|
| 102 | - $addon = isset($arguments['EE_Registry::create(addon)']) |
|
| 103 | - ? (bool)$arguments['EE_Registry::create(addon)'] |
|
| 104 | - : false; |
|
| 105 | - unset( |
|
| 106 | - $arguments['EE_Registry::create(from_db)'], |
|
| 107 | - $arguments['EE_Registry::create(load_only)'], |
|
| 108 | - $arguments['EE_Registry::create(addon)'] |
|
| 109 | - ); |
|
| 110 | - // addons need to be cached on EE_Registry |
|
| 111 | - $shared = $addon ? true : $shared; |
|
| 112 | - return $this->generator->create( |
|
| 113 | - $fqcn, |
|
| 114 | - $arguments, |
|
| 115 | - $shared, |
|
| 116 | - $from_db, |
|
| 117 | - $load_only, |
|
| 118 | - $addon |
|
| 119 | - ); |
|
| 120 | - } |
|
| 121 | - return $this->generator->brew( |
|
| 122 | - $fqcn, |
|
| 123 | - $arguments, |
|
| 124 | - $shared ? CoffeeMaker::BREW_SHARED : CoffeeMaker::BREW_NEW |
|
| 125 | - ); |
|
| 126 | - |
|
| 127 | - } |
|
| 128 | - |
|
| 129 | - |
|
| 130 | - |
|
| 131 | - /** |
|
| 132 | - * calls reset() on generator if method exists |
|
| 133 | - * |
|
| 134 | - * @throws EE_Error |
|
| 135 | - * @throws ReflectionException |
|
| 136 | - */ |
|
| 137 | - public function reset() |
|
| 138 | - { |
|
| 139 | - if (method_exists($this->generator, 'reset')) { |
|
| 140 | - $this->generator->reset(); |
|
| 141 | - } |
|
| 142 | - } |
|
| 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 | + ? (bool)$arguments['EE_Registry::create(from_db)'] |
|
| 96 | + : false; |
|
| 97 | + // load_only |
|
| 98 | + $load_only = isset($arguments['EE_Registry::create(load_only)']) |
|
| 99 | + ? (bool)$arguments['EE_Registry::create(load_only)'] |
|
| 100 | + : false; |
|
| 101 | + // addon |
|
| 102 | + $addon = isset($arguments['EE_Registry::create(addon)']) |
|
| 103 | + ? (bool)$arguments['EE_Registry::create(addon)'] |
|
| 104 | + : false; |
|
| 105 | + unset( |
|
| 106 | + $arguments['EE_Registry::create(from_db)'], |
|
| 107 | + $arguments['EE_Registry::create(load_only)'], |
|
| 108 | + $arguments['EE_Registry::create(addon)'] |
|
| 109 | + ); |
|
| 110 | + // addons need to be cached on EE_Registry |
|
| 111 | + $shared = $addon ? true : $shared; |
|
| 112 | + return $this->generator->create( |
|
| 113 | + $fqcn, |
|
| 114 | + $arguments, |
|
| 115 | + $shared, |
|
| 116 | + $from_db, |
|
| 117 | + $load_only, |
|
| 118 | + $addon |
|
| 119 | + ); |
|
| 120 | + } |
|
| 121 | + return $this->generator->brew( |
|
| 122 | + $fqcn, |
|
| 123 | + $arguments, |
|
| 124 | + $shared ? CoffeeMaker::BREW_SHARED : CoffeeMaker::BREW_NEW |
|
| 125 | + ); |
|
| 126 | + |
|
| 127 | + } |
|
| 128 | + |
|
| 129 | + |
|
| 130 | + |
|
| 131 | + /** |
|
| 132 | + * calls reset() on generator if method exists |
|
| 133 | + * |
|
| 134 | + * @throws EE_Error |
|
| 135 | + * @throws ReflectionException |
|
| 136 | + */ |
|
| 137 | + public function reset() |
|
| 138 | + { |
|
| 139 | + if (method_exists($this->generator, 'reset')) { |
|
| 140 | + $this->generator->reset(); |
|
| 141 | + } |
|
| 142 | + } |
|
| 143 | 143 | |
| 144 | 144 | } |
| 145 | 145 | // 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,19 +88,19 @@ 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)']) |
| 95 | - ? (bool)$arguments['EE_Registry::create(from_db)'] |
|
| 95 | + ? (bool) $arguments['EE_Registry::create(from_db)'] |
|
| 96 | 96 | : false; |
| 97 | 97 | // load_only |
| 98 | 98 | $load_only = isset($arguments['EE_Registry::create(load_only)']) |
| 99 | - ? (bool)$arguments['EE_Registry::create(load_only)'] |
|
| 99 | + ? (bool) $arguments['EE_Registry::create(load_only)'] |
|
| 100 | 100 | : false; |
| 101 | 101 | // addon |
| 102 | 102 | $addon = isset($arguments['EE_Registry::create(addon)']) |
| 103 | - ? (bool)$arguments['EE_Registry::create(addon)'] |
|
| 103 | + ? (bool) $arguments['EE_Registry::create(addon)'] |
|
| 104 | 104 | : false; |
| 105 | 105 | unset( |
| 106 | 106 | $arguments['EE_Registry::create(from_db)'], |
@@ -22,1129 +22,1129 @@ |
||
| 22 | 22 | { |
| 23 | 23 | |
| 24 | 24 | |
| 25 | - /** |
|
| 26 | - * possibly truncated version of the EE core version string |
|
| 27 | - * |
|
| 28 | - * @var string |
|
| 29 | - */ |
|
| 30 | - protected static $_core_version = ''; |
|
| 25 | + /** |
|
| 26 | + * possibly truncated version of the EE core version string |
|
| 27 | + * |
|
| 28 | + * @var string |
|
| 29 | + */ |
|
| 30 | + protected static $_core_version = ''; |
|
| 31 | 31 | |
| 32 | - /** |
|
| 33 | - * Holds values for registered addons |
|
| 34 | - * |
|
| 35 | - * @var array |
|
| 36 | - */ |
|
| 37 | - protected static $_settings = array(); |
|
| 32 | + /** |
|
| 33 | + * Holds values for registered addons |
|
| 34 | + * |
|
| 35 | + * @var array |
|
| 36 | + */ |
|
| 37 | + protected static $_settings = array(); |
|
| 38 | 38 | |
| 39 | - /** |
|
| 40 | - * @var array $_incompatible_addons keys are addon SLUGS |
|
| 41 | - * (first argument passed to EE_Register_Addon::register()), keys are |
|
| 42 | - * their MINIMUM VERSION (with all 5 parts. Eg 1.2.3.rc.004). |
|
| 43 | - * Generally this should be used sparingly, as we don't want to muddle up |
|
| 44 | - * EE core with knowledge of ALL the addons out there. |
|
| 45 | - * If you want NO versions of an addon to run with a certain version of core, |
|
| 46 | - * it's usually best to define the addon's "min_core_version" as part of its call |
|
| 47 | - * to EE_Register_Addon::register(), rather than using this array with a super high value for its |
|
| 48 | - * minimum plugin version. |
|
| 49 | - * @access protected |
|
| 50 | - */ |
|
| 51 | - protected static $_incompatible_addons = array( |
|
| 52 | - 'Multi_Event_Registration' => '2.0.11.rc.002', |
|
| 53 | - 'Promotions' => '1.0.0.rc.084', |
|
| 54 | - ); |
|
| 39 | + /** |
|
| 40 | + * @var array $_incompatible_addons keys are addon SLUGS |
|
| 41 | + * (first argument passed to EE_Register_Addon::register()), keys are |
|
| 42 | + * their MINIMUM VERSION (with all 5 parts. Eg 1.2.3.rc.004). |
|
| 43 | + * Generally this should be used sparingly, as we don't want to muddle up |
|
| 44 | + * EE core with knowledge of ALL the addons out there. |
|
| 45 | + * If you want NO versions of an addon to run with a certain version of core, |
|
| 46 | + * it's usually best to define the addon's "min_core_version" as part of its call |
|
| 47 | + * to EE_Register_Addon::register(), rather than using this array with a super high value for its |
|
| 48 | + * minimum plugin version. |
|
| 49 | + * @access protected |
|
| 50 | + */ |
|
| 51 | + protected static $_incompatible_addons = array( |
|
| 52 | + 'Multi_Event_Registration' => '2.0.11.rc.002', |
|
| 53 | + 'Promotions' => '1.0.0.rc.084', |
|
| 54 | + ); |
|
| 55 | 55 | |
| 56 | 56 | |
| 57 | - /** |
|
| 58 | - * We should always be comparing core to a version like '4.3.0.rc.000', |
|
| 59 | - * not just '4.3.0'. |
|
| 60 | - * So if the addon developer doesn't provide that full version string, |
|
| 61 | - * fill in the blanks for them |
|
| 62 | - * |
|
| 63 | - * @param string $min_core_version |
|
| 64 | - * @return string always like '4.3.0.rc.000' |
|
| 65 | - */ |
|
| 66 | - protected static function _effective_version($min_core_version) |
|
| 67 | - { |
|
| 68 | - // versions: 4 . 3 . 1 . p . 123 |
|
| 69 | - // offsets: 0 . 1 . 2 . 3 . 4 |
|
| 70 | - $version_parts = explode('.', $min_core_version); |
|
| 71 | - //check they specified the micro version (after 2nd period) |
|
| 72 | - if (! isset($version_parts[2])) { |
|
| 73 | - $version_parts[2] = '0'; |
|
| 74 | - } |
|
| 75 | - //if they didn't specify the 'p', or 'rc' part. Just assume the lowest possible |
|
| 76 | - //soon we can assume that's 'rc', but this current version is 'alpha' |
|
| 77 | - if (! isset($version_parts[3])) { |
|
| 78 | - $version_parts[3] = 'dev'; |
|
| 79 | - } |
|
| 80 | - if (! isset($version_parts[4])) { |
|
| 81 | - $version_parts[4] = '000'; |
|
| 82 | - } |
|
| 83 | - return implode('.', $version_parts); |
|
| 84 | - } |
|
| 57 | + /** |
|
| 58 | + * We should always be comparing core to a version like '4.3.0.rc.000', |
|
| 59 | + * not just '4.3.0'. |
|
| 60 | + * So if the addon developer doesn't provide that full version string, |
|
| 61 | + * fill in the blanks for them |
|
| 62 | + * |
|
| 63 | + * @param string $min_core_version |
|
| 64 | + * @return string always like '4.3.0.rc.000' |
|
| 65 | + */ |
|
| 66 | + protected static function _effective_version($min_core_version) |
|
| 67 | + { |
|
| 68 | + // versions: 4 . 3 . 1 . p . 123 |
|
| 69 | + // offsets: 0 . 1 . 2 . 3 . 4 |
|
| 70 | + $version_parts = explode('.', $min_core_version); |
|
| 71 | + //check they specified the micro version (after 2nd period) |
|
| 72 | + if (! isset($version_parts[2])) { |
|
| 73 | + $version_parts[2] = '0'; |
|
| 74 | + } |
|
| 75 | + //if they didn't specify the 'p', or 'rc' part. Just assume the lowest possible |
|
| 76 | + //soon we can assume that's 'rc', but this current version is 'alpha' |
|
| 77 | + if (! isset($version_parts[3])) { |
|
| 78 | + $version_parts[3] = 'dev'; |
|
| 79 | + } |
|
| 80 | + if (! isset($version_parts[4])) { |
|
| 81 | + $version_parts[4] = '000'; |
|
| 82 | + } |
|
| 83 | + return implode('.', $version_parts); |
|
| 84 | + } |
|
| 85 | 85 | |
| 86 | 86 | |
| 87 | - /** |
|
| 88 | - * Returns whether or not the min core version requirement of the addon is met |
|
| 89 | - * |
|
| 90 | - * @param string $min_core_version the minimum core version required by the addon |
|
| 91 | - * @param string $actual_core_version the actual core version, optional |
|
| 92 | - * @return boolean |
|
| 93 | - */ |
|
| 94 | - public static function _meets_min_core_version_requirement( |
|
| 95 | - $min_core_version, |
|
| 96 | - $actual_core_version = EVENT_ESPRESSO_VERSION |
|
| 97 | - ) { |
|
| 98 | - return version_compare( |
|
| 99 | - self::_effective_version($actual_core_version), |
|
| 100 | - self::_effective_version($min_core_version), |
|
| 101 | - '>=' |
|
| 102 | - ); |
|
| 103 | - } |
|
| 87 | + /** |
|
| 88 | + * Returns whether or not the min core version requirement of the addon is met |
|
| 89 | + * |
|
| 90 | + * @param string $min_core_version the minimum core version required by the addon |
|
| 91 | + * @param string $actual_core_version the actual core version, optional |
|
| 92 | + * @return boolean |
|
| 93 | + */ |
|
| 94 | + public static function _meets_min_core_version_requirement( |
|
| 95 | + $min_core_version, |
|
| 96 | + $actual_core_version = EVENT_ESPRESSO_VERSION |
|
| 97 | + ) { |
|
| 98 | + return version_compare( |
|
| 99 | + self::_effective_version($actual_core_version), |
|
| 100 | + self::_effective_version($min_core_version), |
|
| 101 | + '>=' |
|
| 102 | + ); |
|
| 103 | + } |
|
| 104 | 104 | |
| 105 | 105 | |
| 106 | - /** |
|
| 107 | - * Method for registering new EE_Addons. |
|
| 108 | - * Should be called AFTER AHEE__EE_System__load_espresso_addons but BEFORE |
|
| 109 | - * AHEE__EE_System___detect_if_activation_or_upgrade__begin in order to register all its components. However, it |
|
| 110 | - * may also be called after the 'activate_plugin' action (when an addon is activated), because an activating addon |
|
| 111 | - * won't be loaded by WP until after AHEE__EE_System__load_espresso_addons has fired. If its called after |
|
| 112 | - * 'activate_plugin', it registers the addon still, but its components are not registered |
|
| 113 | - * (they shouldn't be needed anyways, because it's just an activation request and they won't have a chance to do |
|
| 114 | - * anything anyways). Instead, it just sets the newly-activated addon's activation indicator wp option and returns |
|
| 115 | - * (so that we can detect that the addon has activated on the subsequent request) |
|
| 116 | - * |
|
| 117 | - * @since 4.3.0 |
|
| 118 | - * @param string $addon_name the EE_Addon's name. Required. |
|
| 119 | - * @param array $setup_args { |
|
| 120 | - * An array of arguments provided for registering the |
|
| 121 | - * message type. |
|
| 122 | - * @type string $class_name the addon's main file name. |
|
| 123 | - * If left blank, generated from the addon name, |
|
| 124 | - * changes something like "calendar" to "EE_Calendar" |
|
| 125 | - * @type string $min_core_version the minimum version of EE Core that the |
|
| 126 | - * addon will work with. eg "4.8.1.rc.084" |
|
| 127 | - * @type string $version the "software" version for the addon. eg |
|
| 128 | - * "1.0.0.p" for a first stable release, or |
|
| 129 | - * "1.0.0.rc.043" for a version in progress |
|
| 130 | - * @type string $main_file_path the full server path to the main file |
|
| 131 | - * loaded directly by WP |
|
| 132 | - * @type string $domain_fqcn Fully Qualified Class Name |
|
| 133 | - * for the addon's Domain class |
|
| 134 | - * (see EventEspresso\core\domain\Domain) |
|
| 135 | - * @type string $admin_path full server path to the folder where the |
|
| 136 | - * addon\'s admin files reside |
|
| 137 | - * @type string $admin_callback a method to be called when the EE Admin is |
|
| 138 | - * first invoked, can be used for hooking into |
|
| 139 | - * any admin page |
|
| 140 | - * @type string $config_section the section name for this addon's |
|
| 141 | - * configuration settings section |
|
| 142 | - * (defaults to "addons") |
|
| 143 | - * @type string $config_class the class name for this addon's |
|
| 144 | - * configuration settings object |
|
| 145 | - * @type string $config_name the class name for this addon's |
|
| 146 | - * configuration settings object |
|
| 147 | - * @type string $autoloader_paths an array of class names and the full server |
|
| 148 | - * paths to those files. Required. |
|
| 149 | - * @type string $autoloader_folders an array of "full server paths" for any |
|
| 150 | - * folders containing classes that might be |
|
| 151 | - * invoked by the addon |
|
| 152 | - * @type string $dms_paths an array of full server paths to folders that |
|
| 153 | - * contain data migration scripts. Required. |
|
| 154 | - * @type string $module_paths an array of full server paths to any |
|
| 155 | - * EED_Modules used by the addon |
|
| 156 | - * @type string $shortcode_paths an array of full server paths to folders |
|
| 157 | - * that contain EES_Shortcodes |
|
| 158 | - * @type string $widget_paths an array of full server paths to folders |
|
| 159 | - * that contain WP_Widgets |
|
| 160 | - * @type string $pue_options |
|
| 161 | - * @type array $capabilities an array indexed by role name |
|
| 162 | - * (i.e administrator,author ) and the values |
|
| 163 | - * are an array of caps to add to the role. |
|
| 164 | - * 'administrator' => array( |
|
| 165 | - * 'read_addon', |
|
| 166 | - * 'edit_addon', |
|
| 167 | - * etc. |
|
| 168 | - * ). |
|
| 169 | - * @type EE_Meta_Capability_Map[] $capability_maps an array of EE_Meta_Capability_Map object |
|
| 170 | - * for any addons that need to register any |
|
| 171 | - * special meta mapped capabilities. Should |
|
| 172 | - * be indexed where the key is the |
|
| 173 | - * EE_Meta_Capability_Map class name and the |
|
| 174 | - * values are the arguments sent to the class. |
|
| 175 | - * @type array $model_paths array of folders containing DB models |
|
| 176 | - * @see EE_Register_Model |
|
| 177 | - * @type array $class_paths array of folders containing DB classes |
|
| 178 | - * @see EE_Register_Model |
|
| 179 | - * @type array $model_extension_paths array of folders containing DB model |
|
| 180 | - * extensions |
|
| 181 | - * @see EE_Register_Model_Extension |
|
| 182 | - * @type array $class_extension_paths array of folders containing DB class |
|
| 183 | - * extensions |
|
| 184 | - * @see EE_Register_Model_Extension |
|
| 185 | - * @type array message_types { |
|
| 186 | - * An array of message types with the key as |
|
| 187 | - * the message type name and the values as |
|
| 188 | - * below: |
|
| 189 | - * @type string $mtfilename The filename of the message type being |
|
| 190 | - * registered. This will be the main |
|
| 191 | - * EE_{Message Type Name}_message_type class. |
|
| 192 | - * (eg. EE_Declined_Registration_message_type.class.php) |
|
| 193 | - * Required. |
|
| 194 | - * @type array $autoloadpaths An array of paths to add to the messages |
|
| 195 | - * autoloader for the new message type. |
|
| 196 | - * Required. |
|
| 197 | - * @type array $messengers_to_activate_with An array of messengers that this message |
|
| 198 | - * type should activate with. Each value in |
|
| 199 | - * the |
|
| 200 | - * array |
|
| 201 | - * should match the name property of a |
|
| 202 | - * EE_messenger. Optional. |
|
| 203 | - * @type array $messengers_to_validate_with An array of messengers that this message |
|
| 204 | - * type should validate with. Each value in |
|
| 205 | - * the |
|
| 206 | - * array |
|
| 207 | - * should match the name property of an |
|
| 208 | - * EE_messenger. |
|
| 209 | - * Optional. |
|
| 210 | - * } |
|
| 211 | - * @type array $custom_post_types |
|
| 212 | - * @type array $custom_taxonomies |
|
| 213 | - * @type array $payment_method_paths each element is the folder containing the |
|
| 214 | - * EE_PMT_Base child class |
|
| 215 | - * (eg, |
|
| 216 | - * '/wp-content/plugins/my_plugin/Payomatic/' |
|
| 217 | - * which contains the files |
|
| 218 | - * EE_PMT_Payomatic.pm.php) |
|
| 219 | - * @type array $default_terms |
|
| 220 | - * @type array $namespace { |
|
| 221 | - * An array with two items for registering the |
|
| 222 | - * addon's namespace. (If, for some reason, you |
|
| 223 | - * require additional namespaces, |
|
| 224 | - * use EventEspresso\core\Psr4Autoloader::addNamespace() |
|
| 225 | - * directly) |
|
| 226 | - * @see EventEspresso\core\Psr4Autoloader::addNamespace() |
|
| 227 | - * @type string $FQNS the namespace prefix |
|
| 228 | - * @type string $DIR a base directory for class files in the |
|
| 229 | - * namespace. |
|
| 230 | - * } |
|
| 231 | - * } |
|
| 232 | - * @return void |
|
| 233 | - * @throws DomainException |
|
| 234 | - * @throws EE_Error |
|
| 235 | - * @throws InvalidArgumentException |
|
| 236 | - * @throws ReflectionException |
|
| 237 | - * @throws InvalidDataTypeException |
|
| 238 | - * @throws InvalidInterfaceException |
|
| 239 | - */ |
|
| 240 | - public static function register($addon_name = '', $setup_args = array()) |
|
| 241 | - { |
|
| 242 | - // required fields MUST be present, so let's make sure they are. |
|
| 243 | - EE_Register_Addon::_verify_parameters($addon_name, $setup_args); |
|
| 244 | - // get class name for addon |
|
| 245 | - $class_name = EE_Register_Addon::_parse_class_name($addon_name, $setup_args); |
|
| 246 | - //setup $_settings array from incoming values. |
|
| 247 | - $addon_settings = EE_Register_Addon::_get_addon_settings($class_name, $setup_args); |
|
| 248 | - // setup PUE |
|
| 249 | - EE_Register_Addon::_parse_pue_options($addon_name, $class_name, $setup_args); |
|
| 250 | - // does this addon work with this version of core or WordPress ? |
|
| 251 | - if (! EE_Register_Addon::_addon_is_compatible($addon_name, $addon_settings)) { |
|
| 252 | - return; |
|
| 253 | - } |
|
| 254 | - // register namespaces |
|
| 255 | - EE_Register_Addon::_setup_namespaces($addon_settings); |
|
| 256 | - // check if this is an activation request |
|
| 257 | - if (EE_Register_Addon::_addon_activation($addon_name, $addon_settings)) { |
|
| 258 | - // dont bother setting up the rest of the addon atm |
|
| 259 | - return; |
|
| 260 | - } |
|
| 261 | - // we need cars |
|
| 262 | - EE_Register_Addon::_setup_autoloaders($addon_name); |
|
| 263 | - // register new models and extensions |
|
| 264 | - EE_Register_Addon::_register_models_and_extensions($addon_name); |
|
| 265 | - // setup DMS |
|
| 266 | - EE_Register_Addon::_register_data_migration_scripts($addon_name); |
|
| 267 | - // if config_class is present let's register config. |
|
| 268 | - EE_Register_Addon::_register_config($addon_name); |
|
| 269 | - // register admin pages |
|
| 270 | - EE_Register_Addon::_register_admin_pages($addon_name); |
|
| 271 | - // add to list of modules to be registered |
|
| 272 | - EE_Register_Addon::_register_modules($addon_name); |
|
| 273 | - // add to list of shortcodes to be registered |
|
| 274 | - EE_Register_Addon::_register_shortcodes($addon_name); |
|
| 275 | - // add to list of widgets to be registered |
|
| 276 | - EE_Register_Addon::_register_widgets($addon_name); |
|
| 277 | - // register capability related stuff. |
|
| 278 | - EE_Register_Addon::_register_capabilities($addon_name); |
|
| 279 | - // any message type to register? |
|
| 280 | - EE_Register_Addon::_register_message_types($addon_name); |
|
| 281 | - // any custom post type/ custom capabilities or default terms to register |
|
| 282 | - EE_Register_Addon::_register_custom_post_types($addon_name); |
|
| 283 | - // and any payment methods |
|
| 284 | - EE_Register_Addon::_register_payment_methods($addon_name); |
|
| 285 | - // load and instantiate main addon class |
|
| 286 | - $addon = EE_Register_Addon::_load_and_init_addon_class($addon_name); |
|
| 287 | - //delay calling after_registration hook on each addon until after all add-ons have been registered. |
|
| 288 | - add_action('AHEE__EE_System__load_espresso_addons__complete', array($addon, 'after_registration'), 999); |
|
| 289 | - } |
|
| 106 | + /** |
|
| 107 | + * Method for registering new EE_Addons. |
|
| 108 | + * Should be called AFTER AHEE__EE_System__load_espresso_addons but BEFORE |
|
| 109 | + * AHEE__EE_System___detect_if_activation_or_upgrade__begin in order to register all its components. However, it |
|
| 110 | + * may also be called after the 'activate_plugin' action (when an addon is activated), because an activating addon |
|
| 111 | + * won't be loaded by WP until after AHEE__EE_System__load_espresso_addons has fired. If its called after |
|
| 112 | + * 'activate_plugin', it registers the addon still, but its components are not registered |
|
| 113 | + * (they shouldn't be needed anyways, because it's just an activation request and they won't have a chance to do |
|
| 114 | + * anything anyways). Instead, it just sets the newly-activated addon's activation indicator wp option and returns |
|
| 115 | + * (so that we can detect that the addon has activated on the subsequent request) |
|
| 116 | + * |
|
| 117 | + * @since 4.3.0 |
|
| 118 | + * @param string $addon_name the EE_Addon's name. Required. |
|
| 119 | + * @param array $setup_args { |
|
| 120 | + * An array of arguments provided for registering the |
|
| 121 | + * message type. |
|
| 122 | + * @type string $class_name the addon's main file name. |
|
| 123 | + * If left blank, generated from the addon name, |
|
| 124 | + * changes something like "calendar" to "EE_Calendar" |
|
| 125 | + * @type string $min_core_version the minimum version of EE Core that the |
|
| 126 | + * addon will work with. eg "4.8.1.rc.084" |
|
| 127 | + * @type string $version the "software" version for the addon. eg |
|
| 128 | + * "1.0.0.p" for a first stable release, or |
|
| 129 | + * "1.0.0.rc.043" for a version in progress |
|
| 130 | + * @type string $main_file_path the full server path to the main file |
|
| 131 | + * loaded directly by WP |
|
| 132 | + * @type string $domain_fqcn Fully Qualified Class Name |
|
| 133 | + * for the addon's Domain class |
|
| 134 | + * (see EventEspresso\core\domain\Domain) |
|
| 135 | + * @type string $admin_path full server path to the folder where the |
|
| 136 | + * addon\'s admin files reside |
|
| 137 | + * @type string $admin_callback a method to be called when the EE Admin is |
|
| 138 | + * first invoked, can be used for hooking into |
|
| 139 | + * any admin page |
|
| 140 | + * @type string $config_section the section name for this addon's |
|
| 141 | + * configuration settings section |
|
| 142 | + * (defaults to "addons") |
|
| 143 | + * @type string $config_class the class name for this addon's |
|
| 144 | + * configuration settings object |
|
| 145 | + * @type string $config_name the class name for this addon's |
|
| 146 | + * configuration settings object |
|
| 147 | + * @type string $autoloader_paths an array of class names and the full server |
|
| 148 | + * paths to those files. Required. |
|
| 149 | + * @type string $autoloader_folders an array of "full server paths" for any |
|
| 150 | + * folders containing classes that might be |
|
| 151 | + * invoked by the addon |
|
| 152 | + * @type string $dms_paths an array of full server paths to folders that |
|
| 153 | + * contain data migration scripts. Required. |
|
| 154 | + * @type string $module_paths an array of full server paths to any |
|
| 155 | + * EED_Modules used by the addon |
|
| 156 | + * @type string $shortcode_paths an array of full server paths to folders |
|
| 157 | + * that contain EES_Shortcodes |
|
| 158 | + * @type string $widget_paths an array of full server paths to folders |
|
| 159 | + * that contain WP_Widgets |
|
| 160 | + * @type string $pue_options |
|
| 161 | + * @type array $capabilities an array indexed by role name |
|
| 162 | + * (i.e administrator,author ) and the values |
|
| 163 | + * are an array of caps to add to the role. |
|
| 164 | + * 'administrator' => array( |
|
| 165 | + * 'read_addon', |
|
| 166 | + * 'edit_addon', |
|
| 167 | + * etc. |
|
| 168 | + * ). |
|
| 169 | + * @type EE_Meta_Capability_Map[] $capability_maps an array of EE_Meta_Capability_Map object |
|
| 170 | + * for any addons that need to register any |
|
| 171 | + * special meta mapped capabilities. Should |
|
| 172 | + * be indexed where the key is the |
|
| 173 | + * EE_Meta_Capability_Map class name and the |
|
| 174 | + * values are the arguments sent to the class. |
|
| 175 | + * @type array $model_paths array of folders containing DB models |
|
| 176 | + * @see EE_Register_Model |
|
| 177 | + * @type array $class_paths array of folders containing DB classes |
|
| 178 | + * @see EE_Register_Model |
|
| 179 | + * @type array $model_extension_paths array of folders containing DB model |
|
| 180 | + * extensions |
|
| 181 | + * @see EE_Register_Model_Extension |
|
| 182 | + * @type array $class_extension_paths array of folders containing DB class |
|
| 183 | + * extensions |
|
| 184 | + * @see EE_Register_Model_Extension |
|
| 185 | + * @type array message_types { |
|
| 186 | + * An array of message types with the key as |
|
| 187 | + * the message type name and the values as |
|
| 188 | + * below: |
|
| 189 | + * @type string $mtfilename The filename of the message type being |
|
| 190 | + * registered. This will be the main |
|
| 191 | + * EE_{Message Type Name}_message_type class. |
|
| 192 | + * (eg. EE_Declined_Registration_message_type.class.php) |
|
| 193 | + * Required. |
|
| 194 | + * @type array $autoloadpaths An array of paths to add to the messages |
|
| 195 | + * autoloader for the new message type. |
|
| 196 | + * Required. |
|
| 197 | + * @type array $messengers_to_activate_with An array of messengers that this message |
|
| 198 | + * type should activate with. Each value in |
|
| 199 | + * the |
|
| 200 | + * array |
|
| 201 | + * should match the name property of a |
|
| 202 | + * EE_messenger. Optional. |
|
| 203 | + * @type array $messengers_to_validate_with An array of messengers that this message |
|
| 204 | + * type should validate with. Each value in |
|
| 205 | + * the |
|
| 206 | + * array |
|
| 207 | + * should match the name property of an |
|
| 208 | + * EE_messenger. |
|
| 209 | + * Optional. |
|
| 210 | + * } |
|
| 211 | + * @type array $custom_post_types |
|
| 212 | + * @type array $custom_taxonomies |
|
| 213 | + * @type array $payment_method_paths each element is the folder containing the |
|
| 214 | + * EE_PMT_Base child class |
|
| 215 | + * (eg, |
|
| 216 | + * '/wp-content/plugins/my_plugin/Payomatic/' |
|
| 217 | + * which contains the files |
|
| 218 | + * EE_PMT_Payomatic.pm.php) |
|
| 219 | + * @type array $default_terms |
|
| 220 | + * @type array $namespace { |
|
| 221 | + * An array with two items for registering the |
|
| 222 | + * addon's namespace. (If, for some reason, you |
|
| 223 | + * require additional namespaces, |
|
| 224 | + * use EventEspresso\core\Psr4Autoloader::addNamespace() |
|
| 225 | + * directly) |
|
| 226 | + * @see EventEspresso\core\Psr4Autoloader::addNamespace() |
|
| 227 | + * @type string $FQNS the namespace prefix |
|
| 228 | + * @type string $DIR a base directory for class files in the |
|
| 229 | + * namespace. |
|
| 230 | + * } |
|
| 231 | + * } |
|
| 232 | + * @return void |
|
| 233 | + * @throws DomainException |
|
| 234 | + * @throws EE_Error |
|
| 235 | + * @throws InvalidArgumentException |
|
| 236 | + * @throws ReflectionException |
|
| 237 | + * @throws InvalidDataTypeException |
|
| 238 | + * @throws InvalidInterfaceException |
|
| 239 | + */ |
|
| 240 | + public static function register($addon_name = '', $setup_args = array()) |
|
| 241 | + { |
|
| 242 | + // required fields MUST be present, so let's make sure they are. |
|
| 243 | + EE_Register_Addon::_verify_parameters($addon_name, $setup_args); |
|
| 244 | + // get class name for addon |
|
| 245 | + $class_name = EE_Register_Addon::_parse_class_name($addon_name, $setup_args); |
|
| 246 | + //setup $_settings array from incoming values. |
|
| 247 | + $addon_settings = EE_Register_Addon::_get_addon_settings($class_name, $setup_args); |
|
| 248 | + // setup PUE |
|
| 249 | + EE_Register_Addon::_parse_pue_options($addon_name, $class_name, $setup_args); |
|
| 250 | + // does this addon work with this version of core or WordPress ? |
|
| 251 | + if (! EE_Register_Addon::_addon_is_compatible($addon_name, $addon_settings)) { |
|
| 252 | + return; |
|
| 253 | + } |
|
| 254 | + // register namespaces |
|
| 255 | + EE_Register_Addon::_setup_namespaces($addon_settings); |
|
| 256 | + // check if this is an activation request |
|
| 257 | + if (EE_Register_Addon::_addon_activation($addon_name, $addon_settings)) { |
|
| 258 | + // dont bother setting up the rest of the addon atm |
|
| 259 | + return; |
|
| 260 | + } |
|
| 261 | + // we need cars |
|
| 262 | + EE_Register_Addon::_setup_autoloaders($addon_name); |
|
| 263 | + // register new models and extensions |
|
| 264 | + EE_Register_Addon::_register_models_and_extensions($addon_name); |
|
| 265 | + // setup DMS |
|
| 266 | + EE_Register_Addon::_register_data_migration_scripts($addon_name); |
|
| 267 | + // if config_class is present let's register config. |
|
| 268 | + EE_Register_Addon::_register_config($addon_name); |
|
| 269 | + // register admin pages |
|
| 270 | + EE_Register_Addon::_register_admin_pages($addon_name); |
|
| 271 | + // add to list of modules to be registered |
|
| 272 | + EE_Register_Addon::_register_modules($addon_name); |
|
| 273 | + // add to list of shortcodes to be registered |
|
| 274 | + EE_Register_Addon::_register_shortcodes($addon_name); |
|
| 275 | + // add to list of widgets to be registered |
|
| 276 | + EE_Register_Addon::_register_widgets($addon_name); |
|
| 277 | + // register capability related stuff. |
|
| 278 | + EE_Register_Addon::_register_capabilities($addon_name); |
|
| 279 | + // any message type to register? |
|
| 280 | + EE_Register_Addon::_register_message_types($addon_name); |
|
| 281 | + // any custom post type/ custom capabilities or default terms to register |
|
| 282 | + EE_Register_Addon::_register_custom_post_types($addon_name); |
|
| 283 | + // and any payment methods |
|
| 284 | + EE_Register_Addon::_register_payment_methods($addon_name); |
|
| 285 | + // load and instantiate main addon class |
|
| 286 | + $addon = EE_Register_Addon::_load_and_init_addon_class($addon_name); |
|
| 287 | + //delay calling after_registration hook on each addon until after all add-ons have been registered. |
|
| 288 | + add_action('AHEE__EE_System__load_espresso_addons__complete', array($addon, 'after_registration'), 999); |
|
| 289 | + } |
|
| 290 | 290 | |
| 291 | 291 | |
| 292 | - /** |
|
| 293 | - * @param string $addon_name |
|
| 294 | - * @param array $setup_args |
|
| 295 | - * @return void |
|
| 296 | - * @throws EE_Error |
|
| 297 | - */ |
|
| 298 | - private static function _verify_parameters($addon_name, array $setup_args) |
|
| 299 | - { |
|
| 300 | - // required fields MUST be present, so let's make sure they are. |
|
| 301 | - if (empty($addon_name) || ! is_array($setup_args)) { |
|
| 302 | - throw new EE_Error( |
|
| 303 | - __( |
|
| 304 | - '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.', |
|
| 305 | - 'event_espresso' |
|
| 306 | - ) |
|
| 307 | - ); |
|
| 308 | - } |
|
| 309 | - if (! isset($setup_args['main_file_path']) || empty($setup_args['main_file_path'])) { |
|
| 310 | - throw new EE_Error( |
|
| 311 | - sprintf( |
|
| 312 | - __( |
|
| 313 | - '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', |
|
| 314 | - 'event_espresso' |
|
| 315 | - ), |
|
| 316 | - implode(',', array_keys($setup_args)) |
|
| 317 | - ) |
|
| 318 | - ); |
|
| 319 | - } |
|
| 320 | - // check that addon has not already been registered with that name |
|
| 321 | - if (isset(self::$_settings[ $addon_name ]) && ! did_action('activate_plugin')) { |
|
| 322 | - throw new EE_Error( |
|
| 323 | - sprintf( |
|
| 324 | - __( |
|
| 325 | - 'An EE_Addon with the name "%s" has already been registered and each EE_Addon requires a unique name.', |
|
| 326 | - 'event_espresso' |
|
| 327 | - ), |
|
| 328 | - $addon_name |
|
| 329 | - ) |
|
| 330 | - ); |
|
| 331 | - } |
|
| 332 | - } |
|
| 292 | + /** |
|
| 293 | + * @param string $addon_name |
|
| 294 | + * @param array $setup_args |
|
| 295 | + * @return void |
|
| 296 | + * @throws EE_Error |
|
| 297 | + */ |
|
| 298 | + private static function _verify_parameters($addon_name, array $setup_args) |
|
| 299 | + { |
|
| 300 | + // required fields MUST be present, so let's make sure they are. |
|
| 301 | + if (empty($addon_name) || ! is_array($setup_args)) { |
|
| 302 | + throw new EE_Error( |
|
| 303 | + __( |
|
| 304 | + '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.', |
|
| 305 | + 'event_espresso' |
|
| 306 | + ) |
|
| 307 | + ); |
|
| 308 | + } |
|
| 309 | + if (! isset($setup_args['main_file_path']) || empty($setup_args['main_file_path'])) { |
|
| 310 | + throw new EE_Error( |
|
| 311 | + sprintf( |
|
| 312 | + __( |
|
| 313 | + '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', |
|
| 314 | + 'event_espresso' |
|
| 315 | + ), |
|
| 316 | + implode(',', array_keys($setup_args)) |
|
| 317 | + ) |
|
| 318 | + ); |
|
| 319 | + } |
|
| 320 | + // check that addon has not already been registered with that name |
|
| 321 | + if (isset(self::$_settings[ $addon_name ]) && ! did_action('activate_plugin')) { |
|
| 322 | + throw new EE_Error( |
|
| 323 | + sprintf( |
|
| 324 | + __( |
|
| 325 | + 'An EE_Addon with the name "%s" has already been registered and each EE_Addon requires a unique name.', |
|
| 326 | + 'event_espresso' |
|
| 327 | + ), |
|
| 328 | + $addon_name |
|
| 329 | + ) |
|
| 330 | + ); |
|
| 331 | + } |
|
| 332 | + } |
|
| 333 | 333 | |
| 334 | 334 | |
| 335 | - /** |
|
| 336 | - * @param string $addon_name |
|
| 337 | - * @param array $setup_args |
|
| 338 | - * @return string |
|
| 339 | - */ |
|
| 340 | - private static function _parse_class_name($addon_name, array $setup_args) |
|
| 341 | - { |
|
| 342 | - if (empty($setup_args['class_name'])) { |
|
| 343 | - // generate one by first separating name with spaces |
|
| 344 | - $class_name = str_replace(array('-', '_'), ' ', trim($addon_name)); |
|
| 345 | - //capitalize, then replace spaces with underscores |
|
| 346 | - $class_name = str_replace(' ', '_', ucwords($class_name)); |
|
| 347 | - } else { |
|
| 348 | - $class_name = $setup_args['class_name']; |
|
| 349 | - } |
|
| 350 | - // check if classname is fully qualified or is a legacy classname already prefixed with 'EE_' |
|
| 351 | - return strpos($class_name, '\\') || strpos($class_name, 'EE_') === 0 |
|
| 352 | - ? $class_name |
|
| 353 | - : 'EE_' . $class_name; |
|
| 354 | - } |
|
| 335 | + /** |
|
| 336 | + * @param string $addon_name |
|
| 337 | + * @param array $setup_args |
|
| 338 | + * @return string |
|
| 339 | + */ |
|
| 340 | + private static function _parse_class_name($addon_name, array $setup_args) |
|
| 341 | + { |
|
| 342 | + if (empty($setup_args['class_name'])) { |
|
| 343 | + // generate one by first separating name with spaces |
|
| 344 | + $class_name = str_replace(array('-', '_'), ' ', trim($addon_name)); |
|
| 345 | + //capitalize, then replace spaces with underscores |
|
| 346 | + $class_name = str_replace(' ', '_', ucwords($class_name)); |
|
| 347 | + } else { |
|
| 348 | + $class_name = $setup_args['class_name']; |
|
| 349 | + } |
|
| 350 | + // check if classname is fully qualified or is a legacy classname already prefixed with 'EE_' |
|
| 351 | + return strpos($class_name, '\\') || strpos($class_name, 'EE_') === 0 |
|
| 352 | + ? $class_name |
|
| 353 | + : 'EE_' . $class_name; |
|
| 354 | + } |
|
| 355 | 355 | |
| 356 | 356 | |
| 357 | - /** |
|
| 358 | - * @param string $class_name |
|
| 359 | - * @param array $setup_args |
|
| 360 | - * @return array |
|
| 361 | - */ |
|
| 362 | - private static function _get_addon_settings($class_name, array $setup_args) |
|
| 363 | - { |
|
| 364 | - //setup $_settings array from incoming values. |
|
| 365 | - $addon_settings = array( |
|
| 366 | - // generated from the addon name, changes something like "calendar" to "EE_Calendar" |
|
| 367 | - 'class_name' => $class_name, |
|
| 368 | - // the addon slug for use in URLs, etc |
|
| 369 | - 'plugin_slug' => isset($setup_args['plugin_slug']) |
|
| 370 | - ? (string) $setup_args['plugin_slug'] |
|
| 371 | - : '', |
|
| 372 | - // page slug to be used when generating the "Settings" link on the WP plugin page |
|
| 373 | - 'plugin_action_slug' => isset($setup_args['plugin_action_slug']) |
|
| 374 | - ? (string) $setup_args['plugin_action_slug'] |
|
| 375 | - : '', |
|
| 376 | - // the "software" version for the addon |
|
| 377 | - 'version' => isset($setup_args['version']) |
|
| 378 | - ? (string) $setup_args['version'] |
|
| 379 | - : '', |
|
| 380 | - // the minimum version of EE Core that the addon will work with |
|
| 381 | - 'min_core_version' => isset($setup_args['min_core_version']) |
|
| 382 | - ? (string) $setup_args['min_core_version'] |
|
| 383 | - : '', |
|
| 384 | - // the minimum version of WordPress that the addon will work with |
|
| 385 | - 'min_wp_version' => isset($setup_args['min_wp_version']) |
|
| 386 | - ? (string) $setup_args['min_wp_version'] |
|
| 387 | - : EE_MIN_WP_VER_REQUIRED, |
|
| 388 | - // full server path to main file (file loaded directly by WP) |
|
| 389 | - 'main_file_path' => isset($setup_args['main_file_path']) |
|
| 390 | - ? (string) $setup_args['main_file_path'] |
|
| 391 | - : '', |
|
| 392 | - // Fully Qualified Class Name for the addon's Domain class |
|
| 393 | - 'domain_fqcn' => isset($setup_args['domain_fqcn']) |
|
| 394 | - ? (string) $setup_args['domain_fqcn'] |
|
| 395 | - : '', |
|
| 396 | - // path to folder containing files for integrating with the EE core admin and/or setting up EE admin pages |
|
| 397 | - 'admin_path' => isset($setup_args['admin_path']) |
|
| 398 | - ? (string) $setup_args['admin_path'] : '', |
|
| 399 | - // a method to be called when the EE Admin is first invoked, can be used for hooking into any admin page |
|
| 400 | - 'admin_callback' => isset($setup_args['admin_callback']) |
|
| 401 | - ? (string) $setup_args['admin_callback'] |
|
| 402 | - : '', |
|
| 403 | - // the section name for this addon's configuration settings section (defaults to "addons") |
|
| 404 | - 'config_section' => isset($setup_args['config_section']) |
|
| 405 | - ? (string) $setup_args['config_section'] |
|
| 406 | - : 'addons', |
|
| 407 | - // the class name for this addon's configuration settings object |
|
| 408 | - 'config_class' => isset($setup_args['config_class']) |
|
| 409 | - ? (string) $setup_args['config_class'] : '', |
|
| 410 | - //the name given to the config for this addons' configuration settings object (optional) |
|
| 411 | - 'config_name' => isset($setup_args['config_name']) |
|
| 412 | - ? (string) $setup_args['config_name'] : '', |
|
| 413 | - // an array of "class names" => "full server paths" for any classes that might be invoked by the addon |
|
| 414 | - 'autoloader_paths' => isset($setup_args['autoloader_paths']) |
|
| 415 | - ? (array) $setup_args['autoloader_paths'] |
|
| 416 | - : array(), |
|
| 417 | - // an array of "full server paths" for any folders containing classes that might be invoked by the addon |
|
| 418 | - 'autoloader_folders' => isset($setup_args['autoloader_folders']) |
|
| 419 | - ? (array) $setup_args['autoloader_folders'] |
|
| 420 | - : array(), |
|
| 421 | - // array of full server paths to any EE_DMS data migration scripts used by the addon |
|
| 422 | - 'dms_paths' => isset($setup_args['dms_paths']) |
|
| 423 | - ? (array) $setup_args['dms_paths'] |
|
| 424 | - : array(), |
|
| 425 | - // array of full server paths to any EED_Modules used by the addon |
|
| 426 | - 'module_paths' => isset($setup_args['module_paths']) |
|
| 427 | - ? (array) $setup_args['module_paths'] |
|
| 428 | - : array(), |
|
| 429 | - // array of full server paths to any EES_Shortcodes used by the addon |
|
| 430 | - 'shortcode_paths' => isset($setup_args['shortcode_paths']) |
|
| 431 | - ? (array) $setup_args['shortcode_paths'] |
|
| 432 | - : array(), |
|
| 433 | - 'shortcode_fqcns' => isset($setup_args['shortcode_fqcns']) |
|
| 434 | - ? (array) $setup_args['shortcode_fqcns'] |
|
| 435 | - : array(), |
|
| 436 | - // array of full server paths to any WP_Widgets used by the addon |
|
| 437 | - 'widget_paths' => isset($setup_args['widget_paths']) |
|
| 438 | - ? (array) $setup_args['widget_paths'] |
|
| 439 | - : array(), |
|
| 440 | - // array of PUE options used by the addon |
|
| 441 | - 'pue_options' => isset($setup_args['pue_options']) |
|
| 442 | - ? (array) $setup_args['pue_options'] |
|
| 443 | - : array(), |
|
| 444 | - 'message_types' => isset($setup_args['message_types']) |
|
| 445 | - ? (array) $setup_args['message_types'] |
|
| 446 | - : array(), |
|
| 447 | - 'capabilities' => isset($setup_args['capabilities']) |
|
| 448 | - ? (array) $setup_args['capabilities'] |
|
| 449 | - : array(), |
|
| 450 | - 'capability_maps' => isset($setup_args['capability_maps']) |
|
| 451 | - ? (array) $setup_args['capability_maps'] |
|
| 452 | - : array(), |
|
| 453 | - 'model_paths' => isset($setup_args['model_paths']) |
|
| 454 | - ? (array) $setup_args['model_paths'] |
|
| 455 | - : array(), |
|
| 456 | - 'class_paths' => isset($setup_args['class_paths']) |
|
| 457 | - ? (array) $setup_args['class_paths'] |
|
| 458 | - : array(), |
|
| 459 | - 'model_extension_paths' => isset($setup_args['model_extension_paths']) |
|
| 460 | - ? (array) $setup_args['model_extension_paths'] |
|
| 461 | - : array(), |
|
| 462 | - 'class_extension_paths' => isset($setup_args['class_extension_paths']) |
|
| 463 | - ? (array) $setup_args['class_extension_paths'] |
|
| 464 | - : array(), |
|
| 465 | - 'custom_post_types' => isset($setup_args['custom_post_types']) |
|
| 466 | - ? (array) $setup_args['custom_post_types'] |
|
| 467 | - : array(), |
|
| 468 | - 'custom_taxonomies' => isset($setup_args['custom_taxonomies']) |
|
| 469 | - ? (array) $setup_args['custom_taxonomies'] |
|
| 470 | - : array(), |
|
| 471 | - 'payment_method_paths' => isset($setup_args['payment_method_paths']) |
|
| 472 | - ? (array) $setup_args['payment_method_paths'] |
|
| 473 | - : array(), |
|
| 474 | - 'default_terms' => isset($setup_args['default_terms']) |
|
| 475 | - ? (array) $setup_args['default_terms'] |
|
| 476 | - : array(), |
|
| 477 | - // if not empty, inserts a new table row after this plugin's row on the WP Plugins page |
|
| 478 | - // that can be used for adding upgrading/marketing info |
|
| 479 | - 'plugins_page_row' => isset($setup_args['plugins_page_row']) |
|
| 480 | - ? $setup_args['plugins_page_row'] |
|
| 481 | - : '', |
|
| 482 | - 'namespace' => isset( |
|
| 483 | - $setup_args['namespace']['FQNS'], |
|
| 484 | - $setup_args['namespace']['DIR'] |
|
| 485 | - ) |
|
| 486 | - ? (array) $setup_args['namespace'] |
|
| 487 | - : array(), |
|
| 488 | - ); |
|
| 489 | - // if plugin_action_slug is NOT set, but an admin page path IS set, |
|
| 490 | - // then let's just use the plugin_slug since that will be used for linking to the admin page |
|
| 491 | - $addon_settings['plugin_action_slug'] = empty($addon_settings['plugin_action_slug']) |
|
| 492 | - && ! empty($addon_settings['admin_path']) |
|
| 493 | - ? $addon_settings['plugin_slug'] |
|
| 494 | - : $addon_settings['plugin_action_slug']; |
|
| 495 | - // full server path to main file (file loaded directly by WP) |
|
| 496 | - $addon_settings['plugin_basename'] = plugin_basename($addon_settings['main_file_path']); |
|
| 497 | - return $addon_settings; |
|
| 498 | - } |
|
| 357 | + /** |
|
| 358 | + * @param string $class_name |
|
| 359 | + * @param array $setup_args |
|
| 360 | + * @return array |
|
| 361 | + */ |
|
| 362 | + private static function _get_addon_settings($class_name, array $setup_args) |
|
| 363 | + { |
|
| 364 | + //setup $_settings array from incoming values. |
|
| 365 | + $addon_settings = array( |
|
| 366 | + // generated from the addon name, changes something like "calendar" to "EE_Calendar" |
|
| 367 | + 'class_name' => $class_name, |
|
| 368 | + // the addon slug for use in URLs, etc |
|
| 369 | + 'plugin_slug' => isset($setup_args['plugin_slug']) |
|
| 370 | + ? (string) $setup_args['plugin_slug'] |
|
| 371 | + : '', |
|
| 372 | + // page slug to be used when generating the "Settings" link on the WP plugin page |
|
| 373 | + 'plugin_action_slug' => isset($setup_args['plugin_action_slug']) |
|
| 374 | + ? (string) $setup_args['plugin_action_slug'] |
|
| 375 | + : '', |
|
| 376 | + // the "software" version for the addon |
|
| 377 | + 'version' => isset($setup_args['version']) |
|
| 378 | + ? (string) $setup_args['version'] |
|
| 379 | + : '', |
|
| 380 | + // the minimum version of EE Core that the addon will work with |
|
| 381 | + 'min_core_version' => isset($setup_args['min_core_version']) |
|
| 382 | + ? (string) $setup_args['min_core_version'] |
|
| 383 | + : '', |
|
| 384 | + // the minimum version of WordPress that the addon will work with |
|
| 385 | + 'min_wp_version' => isset($setup_args['min_wp_version']) |
|
| 386 | + ? (string) $setup_args['min_wp_version'] |
|
| 387 | + : EE_MIN_WP_VER_REQUIRED, |
|
| 388 | + // full server path to main file (file loaded directly by WP) |
|
| 389 | + 'main_file_path' => isset($setup_args['main_file_path']) |
|
| 390 | + ? (string) $setup_args['main_file_path'] |
|
| 391 | + : '', |
|
| 392 | + // Fully Qualified Class Name for the addon's Domain class |
|
| 393 | + 'domain_fqcn' => isset($setup_args['domain_fqcn']) |
|
| 394 | + ? (string) $setup_args['domain_fqcn'] |
|
| 395 | + : '', |
|
| 396 | + // path to folder containing files for integrating with the EE core admin and/or setting up EE admin pages |
|
| 397 | + 'admin_path' => isset($setup_args['admin_path']) |
|
| 398 | + ? (string) $setup_args['admin_path'] : '', |
|
| 399 | + // a method to be called when the EE Admin is first invoked, can be used for hooking into any admin page |
|
| 400 | + 'admin_callback' => isset($setup_args['admin_callback']) |
|
| 401 | + ? (string) $setup_args['admin_callback'] |
|
| 402 | + : '', |
|
| 403 | + // the section name for this addon's configuration settings section (defaults to "addons") |
|
| 404 | + 'config_section' => isset($setup_args['config_section']) |
|
| 405 | + ? (string) $setup_args['config_section'] |
|
| 406 | + : 'addons', |
|
| 407 | + // the class name for this addon's configuration settings object |
|
| 408 | + 'config_class' => isset($setup_args['config_class']) |
|
| 409 | + ? (string) $setup_args['config_class'] : '', |
|
| 410 | + //the name given to the config for this addons' configuration settings object (optional) |
|
| 411 | + 'config_name' => isset($setup_args['config_name']) |
|
| 412 | + ? (string) $setup_args['config_name'] : '', |
|
| 413 | + // an array of "class names" => "full server paths" for any classes that might be invoked by the addon |
|
| 414 | + 'autoloader_paths' => isset($setup_args['autoloader_paths']) |
|
| 415 | + ? (array) $setup_args['autoloader_paths'] |
|
| 416 | + : array(), |
|
| 417 | + // an array of "full server paths" for any folders containing classes that might be invoked by the addon |
|
| 418 | + 'autoloader_folders' => isset($setup_args['autoloader_folders']) |
|
| 419 | + ? (array) $setup_args['autoloader_folders'] |
|
| 420 | + : array(), |
|
| 421 | + // array of full server paths to any EE_DMS data migration scripts used by the addon |
|
| 422 | + 'dms_paths' => isset($setup_args['dms_paths']) |
|
| 423 | + ? (array) $setup_args['dms_paths'] |
|
| 424 | + : array(), |
|
| 425 | + // array of full server paths to any EED_Modules used by the addon |
|
| 426 | + 'module_paths' => isset($setup_args['module_paths']) |
|
| 427 | + ? (array) $setup_args['module_paths'] |
|
| 428 | + : array(), |
|
| 429 | + // array of full server paths to any EES_Shortcodes used by the addon |
|
| 430 | + 'shortcode_paths' => isset($setup_args['shortcode_paths']) |
|
| 431 | + ? (array) $setup_args['shortcode_paths'] |
|
| 432 | + : array(), |
|
| 433 | + 'shortcode_fqcns' => isset($setup_args['shortcode_fqcns']) |
|
| 434 | + ? (array) $setup_args['shortcode_fqcns'] |
|
| 435 | + : array(), |
|
| 436 | + // array of full server paths to any WP_Widgets used by the addon |
|
| 437 | + 'widget_paths' => isset($setup_args['widget_paths']) |
|
| 438 | + ? (array) $setup_args['widget_paths'] |
|
| 439 | + : array(), |
|
| 440 | + // array of PUE options used by the addon |
|
| 441 | + 'pue_options' => isset($setup_args['pue_options']) |
|
| 442 | + ? (array) $setup_args['pue_options'] |
|
| 443 | + : array(), |
|
| 444 | + 'message_types' => isset($setup_args['message_types']) |
|
| 445 | + ? (array) $setup_args['message_types'] |
|
| 446 | + : array(), |
|
| 447 | + 'capabilities' => isset($setup_args['capabilities']) |
|
| 448 | + ? (array) $setup_args['capabilities'] |
|
| 449 | + : array(), |
|
| 450 | + 'capability_maps' => isset($setup_args['capability_maps']) |
|
| 451 | + ? (array) $setup_args['capability_maps'] |
|
| 452 | + : array(), |
|
| 453 | + 'model_paths' => isset($setup_args['model_paths']) |
|
| 454 | + ? (array) $setup_args['model_paths'] |
|
| 455 | + : array(), |
|
| 456 | + 'class_paths' => isset($setup_args['class_paths']) |
|
| 457 | + ? (array) $setup_args['class_paths'] |
|
| 458 | + : array(), |
|
| 459 | + 'model_extension_paths' => isset($setup_args['model_extension_paths']) |
|
| 460 | + ? (array) $setup_args['model_extension_paths'] |
|
| 461 | + : array(), |
|
| 462 | + 'class_extension_paths' => isset($setup_args['class_extension_paths']) |
|
| 463 | + ? (array) $setup_args['class_extension_paths'] |
|
| 464 | + : array(), |
|
| 465 | + 'custom_post_types' => isset($setup_args['custom_post_types']) |
|
| 466 | + ? (array) $setup_args['custom_post_types'] |
|
| 467 | + : array(), |
|
| 468 | + 'custom_taxonomies' => isset($setup_args['custom_taxonomies']) |
|
| 469 | + ? (array) $setup_args['custom_taxonomies'] |
|
| 470 | + : array(), |
|
| 471 | + 'payment_method_paths' => isset($setup_args['payment_method_paths']) |
|
| 472 | + ? (array) $setup_args['payment_method_paths'] |
|
| 473 | + : array(), |
|
| 474 | + 'default_terms' => isset($setup_args['default_terms']) |
|
| 475 | + ? (array) $setup_args['default_terms'] |
|
| 476 | + : array(), |
|
| 477 | + // if not empty, inserts a new table row after this plugin's row on the WP Plugins page |
|
| 478 | + // that can be used for adding upgrading/marketing info |
|
| 479 | + 'plugins_page_row' => isset($setup_args['plugins_page_row']) |
|
| 480 | + ? $setup_args['plugins_page_row'] |
|
| 481 | + : '', |
|
| 482 | + 'namespace' => isset( |
|
| 483 | + $setup_args['namespace']['FQNS'], |
|
| 484 | + $setup_args['namespace']['DIR'] |
|
| 485 | + ) |
|
| 486 | + ? (array) $setup_args['namespace'] |
|
| 487 | + : array(), |
|
| 488 | + ); |
|
| 489 | + // if plugin_action_slug is NOT set, but an admin page path IS set, |
|
| 490 | + // then let's just use the plugin_slug since that will be used for linking to the admin page |
|
| 491 | + $addon_settings['plugin_action_slug'] = empty($addon_settings['plugin_action_slug']) |
|
| 492 | + && ! empty($addon_settings['admin_path']) |
|
| 493 | + ? $addon_settings['plugin_slug'] |
|
| 494 | + : $addon_settings['plugin_action_slug']; |
|
| 495 | + // full server path to main file (file loaded directly by WP) |
|
| 496 | + $addon_settings['plugin_basename'] = plugin_basename($addon_settings['main_file_path']); |
|
| 497 | + return $addon_settings; |
|
| 498 | + } |
|
| 499 | 499 | |
| 500 | 500 | |
| 501 | - /** |
|
| 502 | - * @param string $addon_name |
|
| 503 | - * @param array $addon_settings |
|
| 504 | - * @return boolean |
|
| 505 | - */ |
|
| 506 | - private static function _addon_is_compatible($addon_name, array $addon_settings) |
|
| 507 | - { |
|
| 508 | - global $wp_version; |
|
| 509 | - $incompatibility_message = ''; |
|
| 510 | - //check whether this addon version is compatible with EE core |
|
| 511 | - if ( |
|
| 512 | - isset(EE_Register_Addon::$_incompatible_addons[ $addon_name ]) |
|
| 513 | - && ! self::_meets_min_core_version_requirement( |
|
| 514 | - EE_Register_Addon::$_incompatible_addons[ $addon_name ], |
|
| 515 | - $addon_settings['version'] |
|
| 516 | - ) |
|
| 517 | - ) { |
|
| 518 | - $incompatibility_message = sprintf( |
|
| 519 | - __( |
|
| 520 | - '%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.' |
|
| 521 | - ), |
|
| 522 | - $addon_name, |
|
| 523 | - '<br />', |
|
| 524 | - EE_Register_Addon::$_incompatible_addons[ $addon_name ], |
|
| 525 | - '<span style="font-weight: bold; color: #D54E21;">', |
|
| 526 | - '</span><br />' |
|
| 527 | - ); |
|
| 528 | - } elseif ( |
|
| 529 | - ! self::_meets_min_core_version_requirement($addon_settings['min_core_version'], espresso_version()) |
|
| 530 | - ) { |
|
| 531 | - $incompatibility_message = sprintf( |
|
| 532 | - __( |
|
| 533 | - '%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".', |
|
| 534 | - 'event_espresso' |
|
| 535 | - ), |
|
| 536 | - $addon_name, |
|
| 537 | - self::_effective_version($addon_settings['min_core_version']), |
|
| 538 | - self::_effective_version(espresso_version()), |
|
| 539 | - '<br />', |
|
| 540 | - '<span style="font-weight: bold; color: #D54E21;">', |
|
| 541 | - '</span><br />' |
|
| 542 | - ); |
|
| 543 | - } elseif (version_compare($wp_version, $addon_settings['min_wp_version'], '<')) { |
|
| 544 | - $incompatibility_message = sprintf( |
|
| 545 | - __( |
|
| 546 | - '%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.', |
|
| 547 | - 'event_espresso' |
|
| 548 | - ), |
|
| 549 | - $addon_name, |
|
| 550 | - $addon_settings['min_wp_version'], |
|
| 551 | - '<br />', |
|
| 552 | - '<span style="font-weight: bold; color: #D54E21;">', |
|
| 553 | - '</span><br />' |
|
| 554 | - ); |
|
| 555 | - } |
|
| 556 | - if (! empty($incompatibility_message)) { |
|
| 557 | - // remove 'activate' from the REQUEST |
|
| 558 | - // so WP doesn't erroneously tell the user the plugin activated fine when it didn't |
|
| 559 | - unset($_GET['activate'], $_REQUEST['activate']); |
|
| 560 | - if (current_user_can('activate_plugins')) { |
|
| 561 | - // show an error message indicating the plugin didn't activate properly |
|
| 562 | - EE_Error::add_error($incompatibility_message, __FILE__, __FUNCTION__, __LINE__); |
|
| 563 | - } |
|
| 564 | - // BAIL FROM THE ADDON REGISTRATION PROCESS |
|
| 565 | - return false; |
|
| 566 | - } |
|
| 567 | - // addon IS compatible |
|
| 568 | - return true; |
|
| 569 | - } |
|
| 501 | + /** |
|
| 502 | + * @param string $addon_name |
|
| 503 | + * @param array $addon_settings |
|
| 504 | + * @return boolean |
|
| 505 | + */ |
|
| 506 | + private static function _addon_is_compatible($addon_name, array $addon_settings) |
|
| 507 | + { |
|
| 508 | + global $wp_version; |
|
| 509 | + $incompatibility_message = ''; |
|
| 510 | + //check whether this addon version is compatible with EE core |
|
| 511 | + if ( |
|
| 512 | + isset(EE_Register_Addon::$_incompatible_addons[ $addon_name ]) |
|
| 513 | + && ! self::_meets_min_core_version_requirement( |
|
| 514 | + EE_Register_Addon::$_incompatible_addons[ $addon_name ], |
|
| 515 | + $addon_settings['version'] |
|
| 516 | + ) |
|
| 517 | + ) { |
|
| 518 | + $incompatibility_message = sprintf( |
|
| 519 | + __( |
|
| 520 | + '%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.' |
|
| 521 | + ), |
|
| 522 | + $addon_name, |
|
| 523 | + '<br />', |
|
| 524 | + EE_Register_Addon::$_incompatible_addons[ $addon_name ], |
|
| 525 | + '<span style="font-weight: bold; color: #D54E21;">', |
|
| 526 | + '</span><br />' |
|
| 527 | + ); |
|
| 528 | + } elseif ( |
|
| 529 | + ! self::_meets_min_core_version_requirement($addon_settings['min_core_version'], espresso_version()) |
|
| 530 | + ) { |
|
| 531 | + $incompatibility_message = sprintf( |
|
| 532 | + __( |
|
| 533 | + '%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".', |
|
| 534 | + 'event_espresso' |
|
| 535 | + ), |
|
| 536 | + $addon_name, |
|
| 537 | + self::_effective_version($addon_settings['min_core_version']), |
|
| 538 | + self::_effective_version(espresso_version()), |
|
| 539 | + '<br />', |
|
| 540 | + '<span style="font-weight: bold; color: #D54E21;">', |
|
| 541 | + '</span><br />' |
|
| 542 | + ); |
|
| 543 | + } elseif (version_compare($wp_version, $addon_settings['min_wp_version'], '<')) { |
|
| 544 | + $incompatibility_message = sprintf( |
|
| 545 | + __( |
|
| 546 | + '%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.', |
|
| 547 | + 'event_espresso' |
|
| 548 | + ), |
|
| 549 | + $addon_name, |
|
| 550 | + $addon_settings['min_wp_version'], |
|
| 551 | + '<br />', |
|
| 552 | + '<span style="font-weight: bold; color: #D54E21;">', |
|
| 553 | + '</span><br />' |
|
| 554 | + ); |
|
| 555 | + } |
|
| 556 | + if (! empty($incompatibility_message)) { |
|
| 557 | + // remove 'activate' from the REQUEST |
|
| 558 | + // so WP doesn't erroneously tell the user the plugin activated fine when it didn't |
|
| 559 | + unset($_GET['activate'], $_REQUEST['activate']); |
|
| 560 | + if (current_user_can('activate_plugins')) { |
|
| 561 | + // show an error message indicating the plugin didn't activate properly |
|
| 562 | + EE_Error::add_error($incompatibility_message, __FILE__, __FUNCTION__, __LINE__); |
|
| 563 | + } |
|
| 564 | + // BAIL FROM THE ADDON REGISTRATION PROCESS |
|
| 565 | + return false; |
|
| 566 | + } |
|
| 567 | + // addon IS compatible |
|
| 568 | + return true; |
|
| 569 | + } |
|
| 570 | 570 | |
| 571 | 571 | |
| 572 | - /** |
|
| 573 | - * if plugin update engine is being used for auto-updates, |
|
| 574 | - * then let's set that up now before going any further so that ALL addons can be updated |
|
| 575 | - * (not needed if PUE is not being used) |
|
| 576 | - * |
|
| 577 | - * @param string $addon_name |
|
| 578 | - * @param string $class_name |
|
| 579 | - * @param array $setup_args |
|
| 580 | - * @return void |
|
| 581 | - */ |
|
| 582 | - private static function _parse_pue_options($addon_name, $class_name, array $setup_args) |
|
| 583 | - { |
|
| 584 | - if (! empty($setup_args['pue_options'])) { |
|
| 585 | - self::$_settings[ $addon_name ]['pue_options'] = array( |
|
| 586 | - 'pue_plugin_slug' => isset($setup_args['pue_options']['pue_plugin_slug']) |
|
| 587 | - ? (string) $setup_args['pue_options']['pue_plugin_slug'] |
|
| 588 | - : 'espresso_' . strtolower($class_name), |
|
| 589 | - 'plugin_basename' => isset($setup_args['pue_options']['plugin_basename']) |
|
| 590 | - ? (string) $setup_args['pue_options']['plugin_basename'] |
|
| 591 | - : plugin_basename($setup_args['main_file_path']), |
|
| 592 | - 'checkPeriod' => isset($setup_args['pue_options']['checkPeriod']) |
|
| 593 | - ? (string) $setup_args['pue_options']['checkPeriod'] |
|
| 594 | - : '24', |
|
| 595 | - 'use_wp_update' => isset($setup_args['pue_options']['use_wp_update']) |
|
| 596 | - ? (string) $setup_args['pue_options']['use_wp_update'] |
|
| 597 | - : false, |
|
| 598 | - ); |
|
| 599 | - add_action( |
|
| 600 | - 'AHEE__EE_System__brew_espresso__after_pue_init', |
|
| 601 | - array('EE_Register_Addon', 'load_pue_update') |
|
| 602 | - ); |
|
| 603 | - } |
|
| 604 | - } |
|
| 572 | + /** |
|
| 573 | + * if plugin update engine is being used for auto-updates, |
|
| 574 | + * then let's set that up now before going any further so that ALL addons can be updated |
|
| 575 | + * (not needed if PUE is not being used) |
|
| 576 | + * |
|
| 577 | + * @param string $addon_name |
|
| 578 | + * @param string $class_name |
|
| 579 | + * @param array $setup_args |
|
| 580 | + * @return void |
|
| 581 | + */ |
|
| 582 | + private static function _parse_pue_options($addon_name, $class_name, array $setup_args) |
|
| 583 | + { |
|
| 584 | + if (! empty($setup_args['pue_options'])) { |
|
| 585 | + self::$_settings[ $addon_name ]['pue_options'] = array( |
|
| 586 | + 'pue_plugin_slug' => isset($setup_args['pue_options']['pue_plugin_slug']) |
|
| 587 | + ? (string) $setup_args['pue_options']['pue_plugin_slug'] |
|
| 588 | + : 'espresso_' . strtolower($class_name), |
|
| 589 | + 'plugin_basename' => isset($setup_args['pue_options']['plugin_basename']) |
|
| 590 | + ? (string) $setup_args['pue_options']['plugin_basename'] |
|
| 591 | + : plugin_basename($setup_args['main_file_path']), |
|
| 592 | + 'checkPeriod' => isset($setup_args['pue_options']['checkPeriod']) |
|
| 593 | + ? (string) $setup_args['pue_options']['checkPeriod'] |
|
| 594 | + : '24', |
|
| 595 | + 'use_wp_update' => isset($setup_args['pue_options']['use_wp_update']) |
|
| 596 | + ? (string) $setup_args['pue_options']['use_wp_update'] |
|
| 597 | + : false, |
|
| 598 | + ); |
|
| 599 | + add_action( |
|
| 600 | + 'AHEE__EE_System__brew_espresso__after_pue_init', |
|
| 601 | + array('EE_Register_Addon', 'load_pue_update') |
|
| 602 | + ); |
|
| 603 | + } |
|
| 604 | + } |
|
| 605 | 605 | |
| 606 | 606 | |
| 607 | - /** |
|
| 608 | - * register namespaces right away before any other files or classes get loaded, but AFTER the version checks |
|
| 609 | - * |
|
| 610 | - * @param array $addon_settings |
|
| 611 | - * @return void |
|
| 612 | - */ |
|
| 613 | - private static function _setup_namespaces(array $addon_settings) |
|
| 614 | - { |
|
| 615 | - // |
|
| 616 | - if ( |
|
| 617 | - isset( |
|
| 618 | - $addon_settings['namespace']['FQNS'], |
|
| 619 | - $addon_settings['namespace']['DIR'] |
|
| 620 | - ) |
|
| 621 | - ) { |
|
| 622 | - EE_Psr4AutoloaderInit::psr4_loader()->addNamespace( |
|
| 623 | - $addon_settings['namespace']['FQNS'], |
|
| 624 | - $addon_settings['namespace']['DIR'] |
|
| 625 | - ); |
|
| 626 | - } |
|
| 627 | - } |
|
| 607 | + /** |
|
| 608 | + * register namespaces right away before any other files or classes get loaded, but AFTER the version checks |
|
| 609 | + * |
|
| 610 | + * @param array $addon_settings |
|
| 611 | + * @return void |
|
| 612 | + */ |
|
| 613 | + private static function _setup_namespaces(array $addon_settings) |
|
| 614 | + { |
|
| 615 | + // |
|
| 616 | + if ( |
|
| 617 | + isset( |
|
| 618 | + $addon_settings['namespace']['FQNS'], |
|
| 619 | + $addon_settings['namespace']['DIR'] |
|
| 620 | + ) |
|
| 621 | + ) { |
|
| 622 | + EE_Psr4AutoloaderInit::psr4_loader()->addNamespace( |
|
| 623 | + $addon_settings['namespace']['FQNS'], |
|
| 624 | + $addon_settings['namespace']['DIR'] |
|
| 625 | + ); |
|
| 626 | + } |
|
| 627 | + } |
|
| 628 | 628 | |
| 629 | 629 | |
| 630 | - /** |
|
| 631 | - * @param string $addon_name |
|
| 632 | - * @param array $addon_settings |
|
| 633 | - * @return bool |
|
| 634 | - * @throws EE_Error |
|
| 635 | - * @throws InvalidArgumentException |
|
| 636 | - * @throws ReflectionException |
|
| 637 | - * @throws InvalidDataTypeException |
|
| 638 | - * @throws InvalidInterfaceException |
|
| 639 | - */ |
|
| 640 | - private static function _addon_activation($addon_name, array $addon_settings) |
|
| 641 | - { |
|
| 642 | - // this is an activation request |
|
| 643 | - if (did_action('activate_plugin')) { |
|
| 644 | - //to find if THIS is the addon that was activated, just check if we have already registered it or not |
|
| 645 | - //(as the newly-activated addon wasn't around the first time addons were registered). |
|
| 646 | - //Note: the presence of pue_options in the addon registration options will initialize the $_settings |
|
| 647 | - //property for the add-on, but the add-on is only partially initialized. Hence, the additional check. |
|
| 648 | - if (! isset(self::$_settings[ $addon_name ]) |
|
| 649 | - || (isset(self::$_settings[ $addon_name ]) |
|
| 650 | - && ! isset(self::$_settings[ $addon_name ]['class_name']) |
|
| 651 | - ) |
|
| 652 | - ) { |
|
| 653 | - self::$_settings[ $addon_name ] = $addon_settings; |
|
| 654 | - $addon = self::_load_and_init_addon_class($addon_name); |
|
| 655 | - $addon->set_activation_indicator_option(); |
|
| 656 | - // dont bother setting up the rest of the addon. |
|
| 657 | - // we know it was just activated and the request will end soon |
|
| 658 | - } |
|
| 659 | - return true; |
|
| 660 | - } |
|
| 661 | - // make sure this was called in the right place! |
|
| 662 | - if ( |
|
| 663 | - ! did_action('AHEE__EE_System__load_espresso_addons') |
|
| 664 | - || did_action('AHEE__EE_System___detect_if_activation_or_upgrade__begin') |
|
| 665 | - ) { |
|
| 666 | - EE_Error::doing_it_wrong( |
|
| 667 | - __METHOD__, |
|
| 668 | - sprintf( |
|
| 669 | - __( |
|
| 670 | - '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.', |
|
| 671 | - 'event_espresso' |
|
| 672 | - ), |
|
| 673 | - $addon_name |
|
| 674 | - ), |
|
| 675 | - '4.3.0' |
|
| 676 | - ); |
|
| 677 | - } |
|
| 678 | - // make sure addon settings are set correctly without overwriting anything existing |
|
| 679 | - if (isset(self::$_settings[ $addon_name ])) { |
|
| 680 | - self::$_settings[ $addon_name ] += $addon_settings; |
|
| 681 | - } else { |
|
| 682 | - self::$_settings[ $addon_name ] = $addon_settings; |
|
| 683 | - } |
|
| 684 | - return false; |
|
| 685 | - } |
|
| 630 | + /** |
|
| 631 | + * @param string $addon_name |
|
| 632 | + * @param array $addon_settings |
|
| 633 | + * @return bool |
|
| 634 | + * @throws EE_Error |
|
| 635 | + * @throws InvalidArgumentException |
|
| 636 | + * @throws ReflectionException |
|
| 637 | + * @throws InvalidDataTypeException |
|
| 638 | + * @throws InvalidInterfaceException |
|
| 639 | + */ |
|
| 640 | + private static function _addon_activation($addon_name, array $addon_settings) |
|
| 641 | + { |
|
| 642 | + // this is an activation request |
|
| 643 | + if (did_action('activate_plugin')) { |
|
| 644 | + //to find if THIS is the addon that was activated, just check if we have already registered it or not |
|
| 645 | + //(as the newly-activated addon wasn't around the first time addons were registered). |
|
| 646 | + //Note: the presence of pue_options in the addon registration options will initialize the $_settings |
|
| 647 | + //property for the add-on, but the add-on is only partially initialized. Hence, the additional check. |
|
| 648 | + if (! isset(self::$_settings[ $addon_name ]) |
|
| 649 | + || (isset(self::$_settings[ $addon_name ]) |
|
| 650 | + && ! isset(self::$_settings[ $addon_name ]['class_name']) |
|
| 651 | + ) |
|
| 652 | + ) { |
|
| 653 | + self::$_settings[ $addon_name ] = $addon_settings; |
|
| 654 | + $addon = self::_load_and_init_addon_class($addon_name); |
|
| 655 | + $addon->set_activation_indicator_option(); |
|
| 656 | + // dont bother setting up the rest of the addon. |
|
| 657 | + // we know it was just activated and the request will end soon |
|
| 658 | + } |
|
| 659 | + return true; |
|
| 660 | + } |
|
| 661 | + // make sure this was called in the right place! |
|
| 662 | + if ( |
|
| 663 | + ! did_action('AHEE__EE_System__load_espresso_addons') |
|
| 664 | + || did_action('AHEE__EE_System___detect_if_activation_or_upgrade__begin') |
|
| 665 | + ) { |
|
| 666 | + EE_Error::doing_it_wrong( |
|
| 667 | + __METHOD__, |
|
| 668 | + sprintf( |
|
| 669 | + __( |
|
| 670 | + '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.', |
|
| 671 | + 'event_espresso' |
|
| 672 | + ), |
|
| 673 | + $addon_name |
|
| 674 | + ), |
|
| 675 | + '4.3.0' |
|
| 676 | + ); |
|
| 677 | + } |
|
| 678 | + // make sure addon settings are set correctly without overwriting anything existing |
|
| 679 | + if (isset(self::$_settings[ $addon_name ])) { |
|
| 680 | + self::$_settings[ $addon_name ] += $addon_settings; |
|
| 681 | + } else { |
|
| 682 | + self::$_settings[ $addon_name ] = $addon_settings; |
|
| 683 | + } |
|
| 684 | + return false; |
|
| 685 | + } |
|
| 686 | 686 | |
| 687 | 687 | |
| 688 | - /** |
|
| 689 | - * @param string $addon_name |
|
| 690 | - * @return void |
|
| 691 | - * @throws EE_Error |
|
| 692 | - */ |
|
| 693 | - private static function _setup_autoloaders($addon_name) |
|
| 694 | - { |
|
| 695 | - if (! empty(self::$_settings[ $addon_name ]['autoloader_paths'])) { |
|
| 696 | - // setup autoloader for single file |
|
| 697 | - EEH_Autoloader::instance()->register_autoloader(self::$_settings[ $addon_name ]['autoloader_paths']); |
|
| 698 | - } |
|
| 699 | - // setup autoloaders for folders |
|
| 700 | - if (! empty(self::$_settings[ $addon_name ]['autoloader_folders'])) { |
|
| 701 | - foreach ((array) self::$_settings[ $addon_name ]['autoloader_folders'] as $autoloader_folder) { |
|
| 702 | - EEH_Autoloader::register_autoloaders_for_each_file_in_folder($autoloader_folder); |
|
| 703 | - } |
|
| 704 | - } |
|
| 705 | - } |
|
| 688 | + /** |
|
| 689 | + * @param string $addon_name |
|
| 690 | + * @return void |
|
| 691 | + * @throws EE_Error |
|
| 692 | + */ |
|
| 693 | + private static function _setup_autoloaders($addon_name) |
|
| 694 | + { |
|
| 695 | + if (! empty(self::$_settings[ $addon_name ]['autoloader_paths'])) { |
|
| 696 | + // setup autoloader for single file |
|
| 697 | + EEH_Autoloader::instance()->register_autoloader(self::$_settings[ $addon_name ]['autoloader_paths']); |
|
| 698 | + } |
|
| 699 | + // setup autoloaders for folders |
|
| 700 | + if (! empty(self::$_settings[ $addon_name ]['autoloader_folders'])) { |
|
| 701 | + foreach ((array) self::$_settings[ $addon_name ]['autoloader_folders'] as $autoloader_folder) { |
|
| 702 | + EEH_Autoloader::register_autoloaders_for_each_file_in_folder($autoloader_folder); |
|
| 703 | + } |
|
| 704 | + } |
|
| 705 | + } |
|
| 706 | 706 | |
| 707 | 707 | |
| 708 | - /** |
|
| 709 | - * register new models and extensions |
|
| 710 | - * |
|
| 711 | - * @param string $addon_name |
|
| 712 | - * @return void |
|
| 713 | - * @throws EE_Error |
|
| 714 | - */ |
|
| 715 | - private static function _register_models_and_extensions($addon_name) |
|
| 716 | - { |
|
| 717 | - // register new models |
|
| 718 | - if ( |
|
| 719 | - ! empty(self::$_settings[ $addon_name ]['model_paths']) |
|
| 720 | - || ! empty(self::$_settings[ $addon_name ]['class_paths']) |
|
| 721 | - ) { |
|
| 722 | - EE_Register_Model::register( |
|
| 723 | - $addon_name, |
|
| 724 | - array( |
|
| 725 | - 'model_paths' => self::$_settings[ $addon_name ]['model_paths'], |
|
| 726 | - 'class_paths' => self::$_settings[ $addon_name ]['class_paths'], |
|
| 727 | - ) |
|
| 728 | - ); |
|
| 729 | - } |
|
| 730 | - // register model extensions |
|
| 731 | - if ( |
|
| 732 | - ! empty(self::$_settings[ $addon_name ]['model_extension_paths']) |
|
| 733 | - || ! empty(self::$_settings[ $addon_name ]['class_extension_paths']) |
|
| 734 | - ) { |
|
| 735 | - EE_Register_Model_Extensions::register( |
|
| 736 | - $addon_name, |
|
| 737 | - array( |
|
| 738 | - 'model_extension_paths' => self::$_settings[ $addon_name ]['model_extension_paths'], |
|
| 739 | - 'class_extension_paths' => self::$_settings[ $addon_name ]['class_extension_paths'], |
|
| 740 | - ) |
|
| 741 | - ); |
|
| 742 | - } |
|
| 743 | - } |
|
| 708 | + /** |
|
| 709 | + * register new models and extensions |
|
| 710 | + * |
|
| 711 | + * @param string $addon_name |
|
| 712 | + * @return void |
|
| 713 | + * @throws EE_Error |
|
| 714 | + */ |
|
| 715 | + private static function _register_models_and_extensions($addon_name) |
|
| 716 | + { |
|
| 717 | + // register new models |
|
| 718 | + if ( |
|
| 719 | + ! empty(self::$_settings[ $addon_name ]['model_paths']) |
|
| 720 | + || ! empty(self::$_settings[ $addon_name ]['class_paths']) |
|
| 721 | + ) { |
|
| 722 | + EE_Register_Model::register( |
|
| 723 | + $addon_name, |
|
| 724 | + array( |
|
| 725 | + 'model_paths' => self::$_settings[ $addon_name ]['model_paths'], |
|
| 726 | + 'class_paths' => self::$_settings[ $addon_name ]['class_paths'], |
|
| 727 | + ) |
|
| 728 | + ); |
|
| 729 | + } |
|
| 730 | + // register model extensions |
|
| 731 | + if ( |
|
| 732 | + ! empty(self::$_settings[ $addon_name ]['model_extension_paths']) |
|
| 733 | + || ! empty(self::$_settings[ $addon_name ]['class_extension_paths']) |
|
| 734 | + ) { |
|
| 735 | + EE_Register_Model_Extensions::register( |
|
| 736 | + $addon_name, |
|
| 737 | + array( |
|
| 738 | + 'model_extension_paths' => self::$_settings[ $addon_name ]['model_extension_paths'], |
|
| 739 | + 'class_extension_paths' => self::$_settings[ $addon_name ]['class_extension_paths'], |
|
| 740 | + ) |
|
| 741 | + ); |
|
| 742 | + } |
|
| 743 | + } |
|
| 744 | 744 | |
| 745 | 745 | |
| 746 | - /** |
|
| 747 | - * @param string $addon_name |
|
| 748 | - * @return void |
|
| 749 | - * @throws EE_Error |
|
| 750 | - */ |
|
| 751 | - private static function _register_data_migration_scripts($addon_name) |
|
| 752 | - { |
|
| 753 | - // setup DMS |
|
| 754 | - if (! empty(self::$_settings[ $addon_name ]['dms_paths'])) { |
|
| 755 | - EE_Register_Data_Migration_Scripts::register( |
|
| 756 | - $addon_name, |
|
| 757 | - array('dms_paths' => self::$_settings[ $addon_name ]['dms_paths']) |
|
| 758 | - ); |
|
| 759 | - } |
|
| 760 | - } |
|
| 746 | + /** |
|
| 747 | + * @param string $addon_name |
|
| 748 | + * @return void |
|
| 749 | + * @throws EE_Error |
|
| 750 | + */ |
|
| 751 | + private static function _register_data_migration_scripts($addon_name) |
|
| 752 | + { |
|
| 753 | + // setup DMS |
|
| 754 | + if (! empty(self::$_settings[ $addon_name ]['dms_paths'])) { |
|
| 755 | + EE_Register_Data_Migration_Scripts::register( |
|
| 756 | + $addon_name, |
|
| 757 | + array('dms_paths' => self::$_settings[ $addon_name ]['dms_paths']) |
|
| 758 | + ); |
|
| 759 | + } |
|
| 760 | + } |
|
| 761 | 761 | |
| 762 | 762 | |
| 763 | - /** |
|
| 764 | - * @param string $addon_name |
|
| 765 | - * @return void |
|
| 766 | - * @throws EE_Error |
|
| 767 | - */ |
|
| 768 | - private static function _register_config($addon_name) |
|
| 769 | - { |
|
| 770 | - // if config_class is present let's register config. |
|
| 771 | - if (! empty(self::$_settings[ $addon_name ]['config_class'])) { |
|
| 772 | - EE_Register_Config::register( |
|
| 773 | - self::$_settings[ $addon_name ]['config_class'], |
|
| 774 | - array( |
|
| 775 | - 'config_section' => self::$_settings[ $addon_name ]['config_section'], |
|
| 776 | - 'config_name' => self::$_settings[ $addon_name ]['config_name'], |
|
| 777 | - ) |
|
| 778 | - ); |
|
| 779 | - } |
|
| 780 | - } |
|
| 763 | + /** |
|
| 764 | + * @param string $addon_name |
|
| 765 | + * @return void |
|
| 766 | + * @throws EE_Error |
|
| 767 | + */ |
|
| 768 | + private static function _register_config($addon_name) |
|
| 769 | + { |
|
| 770 | + // if config_class is present let's register config. |
|
| 771 | + if (! empty(self::$_settings[ $addon_name ]['config_class'])) { |
|
| 772 | + EE_Register_Config::register( |
|
| 773 | + self::$_settings[ $addon_name ]['config_class'], |
|
| 774 | + array( |
|
| 775 | + 'config_section' => self::$_settings[ $addon_name ]['config_section'], |
|
| 776 | + 'config_name' => self::$_settings[ $addon_name ]['config_name'], |
|
| 777 | + ) |
|
| 778 | + ); |
|
| 779 | + } |
|
| 780 | + } |
|
| 781 | 781 | |
| 782 | 782 | |
| 783 | - /** |
|
| 784 | - * @param string $addon_name |
|
| 785 | - * @return void |
|
| 786 | - * @throws EE_Error |
|
| 787 | - */ |
|
| 788 | - private static function _register_admin_pages($addon_name) |
|
| 789 | - { |
|
| 790 | - if (! empty(self::$_settings[ $addon_name ]['admin_path'])) { |
|
| 791 | - EE_Register_Admin_Page::register( |
|
| 792 | - $addon_name, |
|
| 793 | - array('page_path' => self::$_settings[ $addon_name ]['admin_path']) |
|
| 794 | - ); |
|
| 795 | - } |
|
| 796 | - } |
|
| 783 | + /** |
|
| 784 | + * @param string $addon_name |
|
| 785 | + * @return void |
|
| 786 | + * @throws EE_Error |
|
| 787 | + */ |
|
| 788 | + private static function _register_admin_pages($addon_name) |
|
| 789 | + { |
|
| 790 | + if (! empty(self::$_settings[ $addon_name ]['admin_path'])) { |
|
| 791 | + EE_Register_Admin_Page::register( |
|
| 792 | + $addon_name, |
|
| 793 | + array('page_path' => self::$_settings[ $addon_name ]['admin_path']) |
|
| 794 | + ); |
|
| 795 | + } |
|
| 796 | + } |
|
| 797 | 797 | |
| 798 | 798 | |
| 799 | - /** |
|
| 800 | - * @param string $addon_name |
|
| 801 | - * @return void |
|
| 802 | - * @throws EE_Error |
|
| 803 | - */ |
|
| 804 | - private static function _register_modules($addon_name) |
|
| 805 | - { |
|
| 806 | - if (! empty(self::$_settings[ $addon_name ]['module_paths'])) { |
|
| 807 | - EE_Register_Module::register( |
|
| 808 | - $addon_name, |
|
| 809 | - array('module_paths' => self::$_settings[ $addon_name ]['module_paths']) |
|
| 810 | - ); |
|
| 811 | - } |
|
| 812 | - } |
|
| 799 | + /** |
|
| 800 | + * @param string $addon_name |
|
| 801 | + * @return void |
|
| 802 | + * @throws EE_Error |
|
| 803 | + */ |
|
| 804 | + private static function _register_modules($addon_name) |
|
| 805 | + { |
|
| 806 | + if (! empty(self::$_settings[ $addon_name ]['module_paths'])) { |
|
| 807 | + EE_Register_Module::register( |
|
| 808 | + $addon_name, |
|
| 809 | + array('module_paths' => self::$_settings[ $addon_name ]['module_paths']) |
|
| 810 | + ); |
|
| 811 | + } |
|
| 812 | + } |
|
| 813 | 813 | |
| 814 | 814 | |
| 815 | - /** |
|
| 816 | - * @param string $addon_name |
|
| 817 | - * @return void |
|
| 818 | - * @throws EE_Error |
|
| 819 | - */ |
|
| 820 | - private static function _register_shortcodes($addon_name) |
|
| 821 | - { |
|
| 822 | - if (! empty(self::$_settings[ $addon_name ]['shortcode_paths']) |
|
| 823 | - || ! empty(self::$_settings[ $addon_name ]['shortcode_fqcns']) |
|
| 824 | - ) { |
|
| 825 | - EE_Register_Shortcode::register( |
|
| 826 | - $addon_name, |
|
| 827 | - array( |
|
| 828 | - 'shortcode_paths' => isset(self::$_settings[ $addon_name ]['shortcode_paths']) |
|
| 829 | - ? self::$_settings[ $addon_name ]['shortcode_paths'] |
|
| 830 | - : array(), |
|
| 831 | - 'shortcode_fqcns' => isset(self::$_settings[ $addon_name ]['shortcode_fqcns']) |
|
| 832 | - ? self::$_settings[ $addon_name ]['shortcode_fqcns'] |
|
| 833 | - : array(), |
|
| 834 | - ) |
|
| 835 | - ); |
|
| 836 | - } |
|
| 837 | - } |
|
| 815 | + /** |
|
| 816 | + * @param string $addon_name |
|
| 817 | + * @return void |
|
| 818 | + * @throws EE_Error |
|
| 819 | + */ |
|
| 820 | + private static function _register_shortcodes($addon_name) |
|
| 821 | + { |
|
| 822 | + if (! empty(self::$_settings[ $addon_name ]['shortcode_paths']) |
|
| 823 | + || ! empty(self::$_settings[ $addon_name ]['shortcode_fqcns']) |
|
| 824 | + ) { |
|
| 825 | + EE_Register_Shortcode::register( |
|
| 826 | + $addon_name, |
|
| 827 | + array( |
|
| 828 | + 'shortcode_paths' => isset(self::$_settings[ $addon_name ]['shortcode_paths']) |
|
| 829 | + ? self::$_settings[ $addon_name ]['shortcode_paths'] |
|
| 830 | + : array(), |
|
| 831 | + 'shortcode_fqcns' => isset(self::$_settings[ $addon_name ]['shortcode_fqcns']) |
|
| 832 | + ? self::$_settings[ $addon_name ]['shortcode_fqcns'] |
|
| 833 | + : array(), |
|
| 834 | + ) |
|
| 835 | + ); |
|
| 836 | + } |
|
| 837 | + } |
|
| 838 | 838 | |
| 839 | 839 | |
| 840 | - /** |
|
| 841 | - * @param string $addon_name |
|
| 842 | - * @return void |
|
| 843 | - * @throws EE_Error |
|
| 844 | - */ |
|
| 845 | - private static function _register_widgets($addon_name) |
|
| 846 | - { |
|
| 847 | - if (! empty(self::$_settings[ $addon_name ]['widget_paths'])) { |
|
| 848 | - EE_Register_Widget::register( |
|
| 849 | - $addon_name, |
|
| 850 | - array('widget_paths' => self::$_settings[ $addon_name ]['widget_paths']) |
|
| 851 | - ); |
|
| 852 | - } |
|
| 853 | - } |
|
| 840 | + /** |
|
| 841 | + * @param string $addon_name |
|
| 842 | + * @return void |
|
| 843 | + * @throws EE_Error |
|
| 844 | + */ |
|
| 845 | + private static function _register_widgets($addon_name) |
|
| 846 | + { |
|
| 847 | + if (! empty(self::$_settings[ $addon_name ]['widget_paths'])) { |
|
| 848 | + EE_Register_Widget::register( |
|
| 849 | + $addon_name, |
|
| 850 | + array('widget_paths' => self::$_settings[ $addon_name ]['widget_paths']) |
|
| 851 | + ); |
|
| 852 | + } |
|
| 853 | + } |
|
| 854 | 854 | |
| 855 | 855 | |
| 856 | - /** |
|
| 857 | - * @param string $addon_name |
|
| 858 | - * @return void |
|
| 859 | - * @throws EE_Error |
|
| 860 | - */ |
|
| 861 | - private static function _register_capabilities($addon_name) |
|
| 862 | - { |
|
| 863 | - if (! empty(self::$_settings[ $addon_name ]['capabilities'])) { |
|
| 864 | - EE_Register_Capabilities::register( |
|
| 865 | - $addon_name, |
|
| 866 | - array( |
|
| 867 | - 'capabilities' => self::$_settings[ $addon_name ]['capabilities'], |
|
| 868 | - 'capability_maps' => self::$_settings[ $addon_name ]['capability_maps'], |
|
| 869 | - ) |
|
| 870 | - ); |
|
| 871 | - } |
|
| 872 | - } |
|
| 856 | + /** |
|
| 857 | + * @param string $addon_name |
|
| 858 | + * @return void |
|
| 859 | + * @throws EE_Error |
|
| 860 | + */ |
|
| 861 | + private static function _register_capabilities($addon_name) |
|
| 862 | + { |
|
| 863 | + if (! empty(self::$_settings[ $addon_name ]['capabilities'])) { |
|
| 864 | + EE_Register_Capabilities::register( |
|
| 865 | + $addon_name, |
|
| 866 | + array( |
|
| 867 | + 'capabilities' => self::$_settings[ $addon_name ]['capabilities'], |
|
| 868 | + 'capability_maps' => self::$_settings[ $addon_name ]['capability_maps'], |
|
| 869 | + ) |
|
| 870 | + ); |
|
| 871 | + } |
|
| 872 | + } |
|
| 873 | 873 | |
| 874 | 874 | |
| 875 | - /** |
|
| 876 | - * @param string $addon_name |
|
| 877 | - * @return void |
|
| 878 | - * @throws EE_Error |
|
| 879 | - */ |
|
| 880 | - private static function _register_message_types($addon_name) |
|
| 881 | - { |
|
| 882 | - if (! empty(self::$_settings[ $addon_name ]['message_types'])) { |
|
| 883 | - add_action( |
|
| 884 | - 'EE_Brewing_Regular___messages_caf', |
|
| 885 | - array('EE_Register_Addon', 'register_message_types') |
|
| 886 | - ); |
|
| 887 | - } |
|
| 888 | - } |
|
| 875 | + /** |
|
| 876 | + * @param string $addon_name |
|
| 877 | + * @return void |
|
| 878 | + * @throws EE_Error |
|
| 879 | + */ |
|
| 880 | + private static function _register_message_types($addon_name) |
|
| 881 | + { |
|
| 882 | + if (! empty(self::$_settings[ $addon_name ]['message_types'])) { |
|
| 883 | + add_action( |
|
| 884 | + 'EE_Brewing_Regular___messages_caf', |
|
| 885 | + array('EE_Register_Addon', 'register_message_types') |
|
| 886 | + ); |
|
| 887 | + } |
|
| 888 | + } |
|
| 889 | 889 | |
| 890 | 890 | |
| 891 | - /** |
|
| 892 | - * @param string $addon_name |
|
| 893 | - * @return void |
|
| 894 | - * @throws EE_Error |
|
| 895 | - */ |
|
| 896 | - private static function _register_custom_post_types($addon_name) |
|
| 897 | - { |
|
| 898 | - if ( |
|
| 899 | - ! empty(self::$_settings[ $addon_name ]['custom_post_types']) |
|
| 900 | - || ! empty(self::$_settings[ $addon_name ]['custom_taxonomies']) |
|
| 901 | - ) { |
|
| 902 | - EE_Register_CPT::register( |
|
| 903 | - $addon_name, |
|
| 904 | - array( |
|
| 905 | - 'cpts' => self::$_settings[ $addon_name ]['custom_post_types'], |
|
| 906 | - 'cts' => self::$_settings[ $addon_name ]['custom_taxonomies'], |
|
| 907 | - 'default_terms' => self::$_settings[ $addon_name ]['default_terms'], |
|
| 908 | - ) |
|
| 909 | - ); |
|
| 910 | - } |
|
| 911 | - } |
|
| 891 | + /** |
|
| 892 | + * @param string $addon_name |
|
| 893 | + * @return void |
|
| 894 | + * @throws EE_Error |
|
| 895 | + */ |
|
| 896 | + private static function _register_custom_post_types($addon_name) |
|
| 897 | + { |
|
| 898 | + if ( |
|
| 899 | + ! empty(self::$_settings[ $addon_name ]['custom_post_types']) |
|
| 900 | + || ! empty(self::$_settings[ $addon_name ]['custom_taxonomies']) |
|
| 901 | + ) { |
|
| 902 | + EE_Register_CPT::register( |
|
| 903 | + $addon_name, |
|
| 904 | + array( |
|
| 905 | + 'cpts' => self::$_settings[ $addon_name ]['custom_post_types'], |
|
| 906 | + 'cts' => self::$_settings[ $addon_name ]['custom_taxonomies'], |
|
| 907 | + 'default_terms' => self::$_settings[ $addon_name ]['default_terms'], |
|
| 908 | + ) |
|
| 909 | + ); |
|
| 910 | + } |
|
| 911 | + } |
|
| 912 | 912 | |
| 913 | 913 | |
| 914 | - /** |
|
| 915 | - * @param string $addon_name |
|
| 916 | - * @return void |
|
| 917 | - * @throws InvalidArgumentException |
|
| 918 | - * @throws InvalidInterfaceException |
|
| 919 | - * @throws InvalidDataTypeException |
|
| 920 | - * @throws DomainException |
|
| 921 | - * @throws EE_Error |
|
| 922 | - */ |
|
| 923 | - private static function _register_payment_methods($addon_name) |
|
| 924 | - { |
|
| 925 | - if (! empty(self::$_settings[ $addon_name ]['payment_method_paths'])) { |
|
| 926 | - EE_Register_Payment_Method::register( |
|
| 927 | - $addon_name, |
|
| 928 | - array('payment_method_paths' => self::$_settings[ $addon_name ]['payment_method_paths']) |
|
| 929 | - ); |
|
| 930 | - } |
|
| 931 | - } |
|
| 914 | + /** |
|
| 915 | + * @param string $addon_name |
|
| 916 | + * @return void |
|
| 917 | + * @throws InvalidArgumentException |
|
| 918 | + * @throws InvalidInterfaceException |
|
| 919 | + * @throws InvalidDataTypeException |
|
| 920 | + * @throws DomainException |
|
| 921 | + * @throws EE_Error |
|
| 922 | + */ |
|
| 923 | + private static function _register_payment_methods($addon_name) |
|
| 924 | + { |
|
| 925 | + if (! empty(self::$_settings[ $addon_name ]['payment_method_paths'])) { |
|
| 926 | + EE_Register_Payment_Method::register( |
|
| 927 | + $addon_name, |
|
| 928 | + array('payment_method_paths' => self::$_settings[ $addon_name ]['payment_method_paths']) |
|
| 929 | + ); |
|
| 930 | + } |
|
| 931 | + } |
|
| 932 | 932 | |
| 933 | 933 | |
| 934 | - /** |
|
| 935 | - * Loads and instantiates the EE_Addon class and adds it onto the registry |
|
| 936 | - * |
|
| 937 | - * @param string $addon_name |
|
| 938 | - * @return EE_Addon |
|
| 939 | - * @throws InvalidArgumentException |
|
| 940 | - * @throws InvalidInterfaceException |
|
| 941 | - * @throws InvalidDataTypeException |
|
| 942 | - * @throws ReflectionException |
|
| 943 | - * @throws EE_Error |
|
| 944 | - */ |
|
| 945 | - private static function _load_and_init_addon_class($addon_name) |
|
| 946 | - { |
|
| 947 | - $loader = EventEspresso\core\services\loaders\LoaderFactory::getLoader(); |
|
| 948 | - $addon = $loader->getShared( |
|
| 949 | - self::$_settings[ $addon_name ]['class_name'], |
|
| 950 | - array( |
|
| 951 | - $loader->getShared('EE_Dependency_Map'), |
|
| 952 | - // if a domain_fqcn is specified, then load that class |
|
| 953 | - self::$_settings[ $addon_name ]['domain_fqcn'] !== '' |
|
| 954 | - ? $loader->getShared( |
|
| 955 | - self::$_settings[ $addon_name ]['domain_fqcn'], |
|
| 956 | - array( |
|
| 957 | - self::$_settings[ $addon_name ]['main_file_path'], |
|
| 958 | - self::$_settings[ $addon_name ]['version'] |
|
| 959 | - ) |
|
| 960 | - ) |
|
| 961 | - : null, |
|
| 962 | - 'EE_Registry::create(addon)' => true |
|
| 963 | - ) |
|
| 964 | - ); |
|
| 965 | - $addon->set_name($addon_name); |
|
| 966 | - $addon->set_plugin_slug(self::$_settings[ $addon_name ]['plugin_slug']); |
|
| 967 | - $addon->set_plugin_basename(self::$_settings[ $addon_name ]['plugin_basename']); |
|
| 968 | - $addon->set_main_plugin_file(self::$_settings[ $addon_name ]['main_file_path']); |
|
| 969 | - $addon->set_plugin_action_slug(self::$_settings[ $addon_name ]['plugin_action_slug']); |
|
| 970 | - $addon->set_plugins_page_row(self::$_settings[ $addon_name ]['plugins_page_row']); |
|
| 971 | - $addon->set_version(self::$_settings[ $addon_name ]['version']); |
|
| 972 | - $addon->set_min_core_version(self::_effective_version(self::$_settings[ $addon_name ]['min_core_version'])); |
|
| 973 | - $addon->set_config_section(self::$_settings[ $addon_name ]['config_section']); |
|
| 974 | - $addon->set_config_class(self::$_settings[ $addon_name ]['config_class']); |
|
| 975 | - $addon->set_config_name(self::$_settings[ $addon_name ]['config_name']); |
|
| 976 | - //unfortunately this can't be hooked in upon construction, because we don't have |
|
| 977 | - //the plugin mainfile's path upon construction. |
|
| 978 | - register_deactivation_hook($addon->get_main_plugin_file(), array($addon, 'deactivation')); |
|
| 979 | - // call any additional admin_callback functions during load_admin_controller hook |
|
| 980 | - if (! empty(self::$_settings[ $addon_name ]['admin_callback'])) { |
|
| 981 | - add_action( |
|
| 982 | - 'AHEE__EE_System__load_controllers__load_admin_controllers', |
|
| 983 | - array($addon, self::$_settings[ $addon_name ]['admin_callback']) |
|
| 984 | - ); |
|
| 985 | - } |
|
| 986 | - return $addon; |
|
| 987 | - } |
|
| 934 | + /** |
|
| 935 | + * Loads and instantiates the EE_Addon class and adds it onto the registry |
|
| 936 | + * |
|
| 937 | + * @param string $addon_name |
|
| 938 | + * @return EE_Addon |
|
| 939 | + * @throws InvalidArgumentException |
|
| 940 | + * @throws InvalidInterfaceException |
|
| 941 | + * @throws InvalidDataTypeException |
|
| 942 | + * @throws ReflectionException |
|
| 943 | + * @throws EE_Error |
|
| 944 | + */ |
|
| 945 | + private static function _load_and_init_addon_class($addon_name) |
|
| 946 | + { |
|
| 947 | + $loader = EventEspresso\core\services\loaders\LoaderFactory::getLoader(); |
|
| 948 | + $addon = $loader->getShared( |
|
| 949 | + self::$_settings[ $addon_name ]['class_name'], |
|
| 950 | + array( |
|
| 951 | + $loader->getShared('EE_Dependency_Map'), |
|
| 952 | + // if a domain_fqcn is specified, then load that class |
|
| 953 | + self::$_settings[ $addon_name ]['domain_fqcn'] !== '' |
|
| 954 | + ? $loader->getShared( |
|
| 955 | + self::$_settings[ $addon_name ]['domain_fqcn'], |
|
| 956 | + array( |
|
| 957 | + self::$_settings[ $addon_name ]['main_file_path'], |
|
| 958 | + self::$_settings[ $addon_name ]['version'] |
|
| 959 | + ) |
|
| 960 | + ) |
|
| 961 | + : null, |
|
| 962 | + 'EE_Registry::create(addon)' => true |
|
| 963 | + ) |
|
| 964 | + ); |
|
| 965 | + $addon->set_name($addon_name); |
|
| 966 | + $addon->set_plugin_slug(self::$_settings[ $addon_name ]['plugin_slug']); |
|
| 967 | + $addon->set_plugin_basename(self::$_settings[ $addon_name ]['plugin_basename']); |
|
| 968 | + $addon->set_main_plugin_file(self::$_settings[ $addon_name ]['main_file_path']); |
|
| 969 | + $addon->set_plugin_action_slug(self::$_settings[ $addon_name ]['plugin_action_slug']); |
|
| 970 | + $addon->set_plugins_page_row(self::$_settings[ $addon_name ]['plugins_page_row']); |
|
| 971 | + $addon->set_version(self::$_settings[ $addon_name ]['version']); |
|
| 972 | + $addon->set_min_core_version(self::_effective_version(self::$_settings[ $addon_name ]['min_core_version'])); |
|
| 973 | + $addon->set_config_section(self::$_settings[ $addon_name ]['config_section']); |
|
| 974 | + $addon->set_config_class(self::$_settings[ $addon_name ]['config_class']); |
|
| 975 | + $addon->set_config_name(self::$_settings[ $addon_name ]['config_name']); |
|
| 976 | + //unfortunately this can't be hooked in upon construction, because we don't have |
|
| 977 | + //the plugin mainfile's path upon construction. |
|
| 978 | + register_deactivation_hook($addon->get_main_plugin_file(), array($addon, 'deactivation')); |
|
| 979 | + // call any additional admin_callback functions during load_admin_controller hook |
|
| 980 | + if (! empty(self::$_settings[ $addon_name ]['admin_callback'])) { |
|
| 981 | + add_action( |
|
| 982 | + 'AHEE__EE_System__load_controllers__load_admin_controllers', |
|
| 983 | + array($addon, self::$_settings[ $addon_name ]['admin_callback']) |
|
| 984 | + ); |
|
| 985 | + } |
|
| 986 | + return $addon; |
|
| 987 | + } |
|
| 988 | 988 | |
| 989 | 989 | |
| 990 | - /** |
|
| 991 | - * load_pue_update - Update notifications |
|
| 992 | - * |
|
| 993 | - * @return void |
|
| 994 | - * @throws InvalidArgumentException |
|
| 995 | - * @throws InvalidDataTypeException |
|
| 996 | - * @throws InvalidInterfaceException |
|
| 997 | - */ |
|
| 998 | - public static function load_pue_update() |
|
| 999 | - { |
|
| 1000 | - // load PUE client |
|
| 1001 | - require_once EE_THIRD_PARTY . 'pue' . DS . 'pue-client.php'; |
|
| 1002 | - // cycle thru settings |
|
| 1003 | - foreach (self::$_settings as $settings) { |
|
| 1004 | - if (! empty($settings['pue_options'])) { |
|
| 1005 | - // initiate the class and start the plugin update engine! |
|
| 1006 | - new PluginUpdateEngineChecker( |
|
| 1007 | - // host file URL |
|
| 1008 | - 'https://eventespresso.com', |
|
| 1009 | - // plugin slug(s) |
|
| 1010 | - array( |
|
| 1011 | - 'premium' => array('p' => $settings['pue_options']['pue_plugin_slug']), |
|
| 1012 | - 'prerelease' => array('beta' => $settings['pue_options']['pue_plugin_slug'] . '-pr'), |
|
| 1013 | - ), |
|
| 1014 | - // options |
|
| 1015 | - array( |
|
| 1016 | - 'apikey' => EE_Registry::instance()->NET_CFG->core->site_license_key, |
|
| 1017 | - 'lang_domain' => 'event_espresso', |
|
| 1018 | - 'checkPeriod' => $settings['pue_options']['checkPeriod'], |
|
| 1019 | - 'option_key' => 'site_license_key', |
|
| 1020 | - 'options_page_slug' => 'event_espresso', |
|
| 1021 | - 'plugin_basename' => $settings['pue_options']['plugin_basename'], |
|
| 1022 | - // if use_wp_update is TRUE it means you want FREE versions of the plugin to be updated from WP |
|
| 1023 | - 'use_wp_update' => $settings['pue_options']['use_wp_update'], |
|
| 1024 | - ) |
|
| 1025 | - ); |
|
| 1026 | - } |
|
| 1027 | - } |
|
| 1028 | - } |
|
| 990 | + /** |
|
| 991 | + * load_pue_update - Update notifications |
|
| 992 | + * |
|
| 993 | + * @return void |
|
| 994 | + * @throws InvalidArgumentException |
|
| 995 | + * @throws InvalidDataTypeException |
|
| 996 | + * @throws InvalidInterfaceException |
|
| 997 | + */ |
|
| 998 | + public static function load_pue_update() |
|
| 999 | + { |
|
| 1000 | + // load PUE client |
|
| 1001 | + require_once EE_THIRD_PARTY . 'pue' . DS . 'pue-client.php'; |
|
| 1002 | + // cycle thru settings |
|
| 1003 | + foreach (self::$_settings as $settings) { |
|
| 1004 | + if (! empty($settings['pue_options'])) { |
|
| 1005 | + // initiate the class and start the plugin update engine! |
|
| 1006 | + new PluginUpdateEngineChecker( |
|
| 1007 | + // host file URL |
|
| 1008 | + 'https://eventespresso.com', |
|
| 1009 | + // plugin slug(s) |
|
| 1010 | + array( |
|
| 1011 | + 'premium' => array('p' => $settings['pue_options']['pue_plugin_slug']), |
|
| 1012 | + 'prerelease' => array('beta' => $settings['pue_options']['pue_plugin_slug'] . '-pr'), |
|
| 1013 | + ), |
|
| 1014 | + // options |
|
| 1015 | + array( |
|
| 1016 | + 'apikey' => EE_Registry::instance()->NET_CFG->core->site_license_key, |
|
| 1017 | + 'lang_domain' => 'event_espresso', |
|
| 1018 | + 'checkPeriod' => $settings['pue_options']['checkPeriod'], |
|
| 1019 | + 'option_key' => 'site_license_key', |
|
| 1020 | + 'options_page_slug' => 'event_espresso', |
|
| 1021 | + 'plugin_basename' => $settings['pue_options']['plugin_basename'], |
|
| 1022 | + // if use_wp_update is TRUE it means you want FREE versions of the plugin to be updated from WP |
|
| 1023 | + 'use_wp_update' => $settings['pue_options']['use_wp_update'], |
|
| 1024 | + ) |
|
| 1025 | + ); |
|
| 1026 | + } |
|
| 1027 | + } |
|
| 1028 | + } |
|
| 1029 | 1029 | |
| 1030 | 1030 | |
| 1031 | - /** |
|
| 1032 | - * Callback for EE_Brewing_Regular__messages_caf hook used to register message types. |
|
| 1033 | - * |
|
| 1034 | - * @since 4.4.0 |
|
| 1035 | - * @return void |
|
| 1036 | - * @throws EE_Error |
|
| 1037 | - */ |
|
| 1038 | - public static function register_message_types() |
|
| 1039 | - { |
|
| 1040 | - foreach (self::$_settings as $addon_name => $settings) { |
|
| 1041 | - if (! empty($settings['message_types'])) { |
|
| 1042 | - foreach ((array) $settings['message_types'] as $message_type => $message_type_settings) { |
|
| 1043 | - EE_Register_Message_Type::register($message_type, $message_type_settings); |
|
| 1044 | - } |
|
| 1045 | - } |
|
| 1046 | - } |
|
| 1047 | - } |
|
| 1031 | + /** |
|
| 1032 | + * Callback for EE_Brewing_Regular__messages_caf hook used to register message types. |
|
| 1033 | + * |
|
| 1034 | + * @since 4.4.0 |
|
| 1035 | + * @return void |
|
| 1036 | + * @throws EE_Error |
|
| 1037 | + */ |
|
| 1038 | + public static function register_message_types() |
|
| 1039 | + { |
|
| 1040 | + foreach (self::$_settings as $addon_name => $settings) { |
|
| 1041 | + if (! empty($settings['message_types'])) { |
|
| 1042 | + foreach ((array) $settings['message_types'] as $message_type => $message_type_settings) { |
|
| 1043 | + EE_Register_Message_Type::register($message_type, $message_type_settings); |
|
| 1044 | + } |
|
| 1045 | + } |
|
| 1046 | + } |
|
| 1047 | + } |
|
| 1048 | 1048 | |
| 1049 | 1049 | |
| 1050 | - /** |
|
| 1051 | - * This deregisters an addon that was previously registered with a specific addon_name. |
|
| 1052 | - * |
|
| 1053 | - * @since 4.3.0 |
|
| 1054 | - * @param string $addon_name the name for the addon that was previously registered |
|
| 1055 | - * @throws DomainException |
|
| 1056 | - * @throws EE_Error |
|
| 1057 | - * @throws InvalidArgumentException |
|
| 1058 | - * @throws InvalidDataTypeException |
|
| 1059 | - * @throws InvalidInterfaceException |
|
| 1060 | - */ |
|
| 1061 | - public static function deregister($addon_name = null) |
|
| 1062 | - { |
|
| 1063 | - if (isset(self::$_settings[ $addon_name ]['class_name'])) { |
|
| 1064 | - do_action('AHEE__EE_Register_Addon__deregister__before', $addon_name); |
|
| 1065 | - $class_name = self::$_settings[ $addon_name ]['class_name']; |
|
| 1066 | - if (! empty(self::$_settings[ $addon_name ]['dms_paths'])) { |
|
| 1067 | - // setup DMS |
|
| 1068 | - EE_Register_Data_Migration_Scripts::deregister($addon_name); |
|
| 1069 | - } |
|
| 1070 | - if (! empty(self::$_settings[ $addon_name ]['admin_path'])) { |
|
| 1071 | - // register admin page |
|
| 1072 | - EE_Register_Admin_Page::deregister($addon_name); |
|
| 1073 | - } |
|
| 1074 | - if (! empty(self::$_settings[ $addon_name ]['module_paths'])) { |
|
| 1075 | - // add to list of modules to be registered |
|
| 1076 | - EE_Register_Module::deregister($addon_name); |
|
| 1077 | - } |
|
| 1078 | - if (! empty(self::$_settings[ $addon_name ]['shortcode_paths']) |
|
| 1079 | - || ! empty(self::$_settings[ $addon_name ]['shortcode_fqcns']) |
|
| 1080 | - ) { |
|
| 1081 | - // add to list of shortcodes to be registered |
|
| 1082 | - EE_Register_Shortcode::deregister($addon_name); |
|
| 1083 | - } |
|
| 1084 | - if (! empty(self::$_settings[ $addon_name ]['config_class'])) { |
|
| 1085 | - // if config_class present let's register config. |
|
| 1086 | - EE_Register_Config::deregister(self::$_settings[ $addon_name ]['config_class']); |
|
| 1087 | - } |
|
| 1088 | - if (! empty(self::$_settings[ $addon_name ]['widget_paths'])) { |
|
| 1089 | - // add to list of widgets to be registered |
|
| 1090 | - EE_Register_Widget::deregister($addon_name); |
|
| 1091 | - } |
|
| 1092 | - if (! empty(self::$_settings[ $addon_name ]['model_paths']) |
|
| 1093 | - || ! empty(self::$_settings[ $addon_name ]['class_paths']) |
|
| 1094 | - ) { |
|
| 1095 | - // add to list of shortcodes to be registered |
|
| 1096 | - EE_Register_Model::deregister($addon_name); |
|
| 1097 | - } |
|
| 1098 | - if (! empty(self::$_settings[ $addon_name ]['model_extension_paths']) |
|
| 1099 | - || ! empty(self::$_settings[ $addon_name ]['class_extension_paths']) |
|
| 1100 | - ) { |
|
| 1101 | - // add to list of shortcodes to be registered |
|
| 1102 | - EE_Register_Model_Extensions::deregister($addon_name); |
|
| 1103 | - } |
|
| 1104 | - if (! empty(self::$_settings[ $addon_name ]['message_types'])) { |
|
| 1105 | - foreach ( |
|
| 1106 | - (array) self::$_settings[ $addon_name ]['message_types'] as $message_type => |
|
| 1107 | - $message_type_settings |
|
| 1108 | - ) { |
|
| 1109 | - EE_Register_Message_Type::deregister($message_type); |
|
| 1110 | - } |
|
| 1111 | - } |
|
| 1112 | - //deregister capabilities for addon |
|
| 1113 | - if ( |
|
| 1114 | - ! empty(self::$_settings[ $addon_name ]['capabilities']) |
|
| 1115 | - || ! empty(self::$_settings[ $addon_name ]['capability_maps']) |
|
| 1116 | - ) { |
|
| 1117 | - EE_Register_Capabilities::deregister($addon_name); |
|
| 1118 | - } |
|
| 1119 | - //deregister custom_post_types for addon |
|
| 1120 | - if (! empty(self::$_settings[ $addon_name ]['custom_post_types'])) { |
|
| 1121 | - EE_Register_CPT::deregister($addon_name); |
|
| 1122 | - } |
|
| 1123 | - if (! empty(self::$_settings[ $addon_name ]['payment_method_paths'])) { |
|
| 1124 | - EE_Register_Payment_Method::deregister($addon_name); |
|
| 1125 | - } |
|
| 1126 | - $addon = EE_Registry::instance()->getAddon($class_name); |
|
| 1127 | - if ($addon instanceof EE_Addon) { |
|
| 1128 | - remove_action( |
|
| 1129 | - 'deactivate_' . $addon->get_main_plugin_file_basename(), |
|
| 1130 | - array($addon, 'deactivation') |
|
| 1131 | - ); |
|
| 1132 | - remove_action( |
|
| 1133 | - 'AHEE__EE_System__perform_activations_upgrades_and_migrations', |
|
| 1134 | - array($addon, 'initialize_db_if_no_migrations_required') |
|
| 1135 | - ); |
|
| 1136 | - //remove `after_registration` call |
|
| 1137 | - remove_action( |
|
| 1138 | - 'AHEE__EE_System__load_espresso_addons__complete', |
|
| 1139 | - array($addon, 'after_registration'), |
|
| 1140 | - 999 |
|
| 1141 | - ); |
|
| 1142 | - } |
|
| 1143 | - EE_Registry::instance()->removeAddon($class_name); |
|
| 1144 | - unset(self::$_settings[ $addon_name ]); |
|
| 1145 | - do_action('AHEE__EE_Register_Addon__deregister__after', $addon_name); |
|
| 1146 | - } |
|
| 1147 | - } |
|
| 1050 | + /** |
|
| 1051 | + * This deregisters an addon that was previously registered with a specific addon_name. |
|
| 1052 | + * |
|
| 1053 | + * @since 4.3.0 |
|
| 1054 | + * @param string $addon_name the name for the addon that was previously registered |
|
| 1055 | + * @throws DomainException |
|
| 1056 | + * @throws EE_Error |
|
| 1057 | + * @throws InvalidArgumentException |
|
| 1058 | + * @throws InvalidDataTypeException |
|
| 1059 | + * @throws InvalidInterfaceException |
|
| 1060 | + */ |
|
| 1061 | + public static function deregister($addon_name = null) |
|
| 1062 | + { |
|
| 1063 | + if (isset(self::$_settings[ $addon_name ]['class_name'])) { |
|
| 1064 | + do_action('AHEE__EE_Register_Addon__deregister__before', $addon_name); |
|
| 1065 | + $class_name = self::$_settings[ $addon_name ]['class_name']; |
|
| 1066 | + if (! empty(self::$_settings[ $addon_name ]['dms_paths'])) { |
|
| 1067 | + // setup DMS |
|
| 1068 | + EE_Register_Data_Migration_Scripts::deregister($addon_name); |
|
| 1069 | + } |
|
| 1070 | + if (! empty(self::$_settings[ $addon_name ]['admin_path'])) { |
|
| 1071 | + // register admin page |
|
| 1072 | + EE_Register_Admin_Page::deregister($addon_name); |
|
| 1073 | + } |
|
| 1074 | + if (! empty(self::$_settings[ $addon_name ]['module_paths'])) { |
|
| 1075 | + // add to list of modules to be registered |
|
| 1076 | + EE_Register_Module::deregister($addon_name); |
|
| 1077 | + } |
|
| 1078 | + if (! empty(self::$_settings[ $addon_name ]['shortcode_paths']) |
|
| 1079 | + || ! empty(self::$_settings[ $addon_name ]['shortcode_fqcns']) |
|
| 1080 | + ) { |
|
| 1081 | + // add to list of shortcodes to be registered |
|
| 1082 | + EE_Register_Shortcode::deregister($addon_name); |
|
| 1083 | + } |
|
| 1084 | + if (! empty(self::$_settings[ $addon_name ]['config_class'])) { |
|
| 1085 | + // if config_class present let's register config. |
|
| 1086 | + EE_Register_Config::deregister(self::$_settings[ $addon_name ]['config_class']); |
|
| 1087 | + } |
|
| 1088 | + if (! empty(self::$_settings[ $addon_name ]['widget_paths'])) { |
|
| 1089 | + // add to list of widgets to be registered |
|
| 1090 | + EE_Register_Widget::deregister($addon_name); |
|
| 1091 | + } |
|
| 1092 | + if (! empty(self::$_settings[ $addon_name ]['model_paths']) |
|
| 1093 | + || ! empty(self::$_settings[ $addon_name ]['class_paths']) |
|
| 1094 | + ) { |
|
| 1095 | + // add to list of shortcodes to be registered |
|
| 1096 | + EE_Register_Model::deregister($addon_name); |
|
| 1097 | + } |
|
| 1098 | + if (! empty(self::$_settings[ $addon_name ]['model_extension_paths']) |
|
| 1099 | + || ! empty(self::$_settings[ $addon_name ]['class_extension_paths']) |
|
| 1100 | + ) { |
|
| 1101 | + // add to list of shortcodes to be registered |
|
| 1102 | + EE_Register_Model_Extensions::deregister($addon_name); |
|
| 1103 | + } |
|
| 1104 | + if (! empty(self::$_settings[ $addon_name ]['message_types'])) { |
|
| 1105 | + foreach ( |
|
| 1106 | + (array) self::$_settings[ $addon_name ]['message_types'] as $message_type => |
|
| 1107 | + $message_type_settings |
|
| 1108 | + ) { |
|
| 1109 | + EE_Register_Message_Type::deregister($message_type); |
|
| 1110 | + } |
|
| 1111 | + } |
|
| 1112 | + //deregister capabilities for addon |
|
| 1113 | + if ( |
|
| 1114 | + ! empty(self::$_settings[ $addon_name ]['capabilities']) |
|
| 1115 | + || ! empty(self::$_settings[ $addon_name ]['capability_maps']) |
|
| 1116 | + ) { |
|
| 1117 | + EE_Register_Capabilities::deregister($addon_name); |
|
| 1118 | + } |
|
| 1119 | + //deregister custom_post_types for addon |
|
| 1120 | + if (! empty(self::$_settings[ $addon_name ]['custom_post_types'])) { |
|
| 1121 | + EE_Register_CPT::deregister($addon_name); |
|
| 1122 | + } |
|
| 1123 | + if (! empty(self::$_settings[ $addon_name ]['payment_method_paths'])) { |
|
| 1124 | + EE_Register_Payment_Method::deregister($addon_name); |
|
| 1125 | + } |
|
| 1126 | + $addon = EE_Registry::instance()->getAddon($class_name); |
|
| 1127 | + if ($addon instanceof EE_Addon) { |
|
| 1128 | + remove_action( |
|
| 1129 | + 'deactivate_' . $addon->get_main_plugin_file_basename(), |
|
| 1130 | + array($addon, 'deactivation') |
|
| 1131 | + ); |
|
| 1132 | + remove_action( |
|
| 1133 | + 'AHEE__EE_System__perform_activations_upgrades_and_migrations', |
|
| 1134 | + array($addon, 'initialize_db_if_no_migrations_required') |
|
| 1135 | + ); |
|
| 1136 | + //remove `after_registration` call |
|
| 1137 | + remove_action( |
|
| 1138 | + 'AHEE__EE_System__load_espresso_addons__complete', |
|
| 1139 | + array($addon, 'after_registration'), |
|
| 1140 | + 999 |
|
| 1141 | + ); |
|
| 1142 | + } |
|
| 1143 | + EE_Registry::instance()->removeAddon($class_name); |
|
| 1144 | + unset(self::$_settings[ $addon_name ]); |
|
| 1145 | + do_action('AHEE__EE_Register_Addon__deregister__after', $addon_name); |
|
| 1146 | + } |
|
| 1147 | + } |
|
| 1148 | 1148 | |
| 1149 | 1149 | |
| 1150 | 1150 | } |
@@ -69,15 +69,15 @@ discard block |
||
| 69 | 69 | // offsets: 0 . 1 . 2 . 3 . 4 |
| 70 | 70 | $version_parts = explode('.', $min_core_version); |
| 71 | 71 | //check they specified the micro version (after 2nd period) |
| 72 | - if (! isset($version_parts[2])) { |
|
| 72 | + if ( ! isset($version_parts[2])) { |
|
| 73 | 73 | $version_parts[2] = '0'; |
| 74 | 74 | } |
| 75 | 75 | //if they didn't specify the 'p', or 'rc' part. Just assume the lowest possible |
| 76 | 76 | //soon we can assume that's 'rc', but this current version is 'alpha' |
| 77 | - if (! isset($version_parts[3])) { |
|
| 77 | + if ( ! isset($version_parts[3])) { |
|
| 78 | 78 | $version_parts[3] = 'dev'; |
| 79 | 79 | } |
| 80 | - if (! isset($version_parts[4])) { |
|
| 80 | + if ( ! isset($version_parts[4])) { |
|
| 81 | 81 | $version_parts[4] = '000'; |
| 82 | 82 | } |
| 83 | 83 | return implode('.', $version_parts); |
@@ -248,7 +248,7 @@ discard block |
||
| 248 | 248 | // setup PUE |
| 249 | 249 | EE_Register_Addon::_parse_pue_options($addon_name, $class_name, $setup_args); |
| 250 | 250 | // does this addon work with this version of core or WordPress ? |
| 251 | - if (! EE_Register_Addon::_addon_is_compatible($addon_name, $addon_settings)) { |
|
| 251 | + if ( ! EE_Register_Addon::_addon_is_compatible($addon_name, $addon_settings)) { |
|
| 252 | 252 | return; |
| 253 | 253 | } |
| 254 | 254 | // register namespaces |
@@ -306,7 +306,7 @@ discard block |
||
| 306 | 306 | ) |
| 307 | 307 | ); |
| 308 | 308 | } |
| 309 | - if (! isset($setup_args['main_file_path']) || empty($setup_args['main_file_path'])) { |
|
| 309 | + if ( ! isset($setup_args['main_file_path']) || empty($setup_args['main_file_path'])) { |
|
| 310 | 310 | throw new EE_Error( |
| 311 | 311 | sprintf( |
| 312 | 312 | __( |
@@ -318,7 +318,7 @@ discard block |
||
| 318 | 318 | ); |
| 319 | 319 | } |
| 320 | 320 | // check that addon has not already been registered with that name |
| 321 | - if (isset(self::$_settings[ $addon_name ]) && ! did_action('activate_plugin')) { |
|
| 321 | + if (isset(self::$_settings[$addon_name]) && ! did_action('activate_plugin')) { |
|
| 322 | 322 | throw new EE_Error( |
| 323 | 323 | sprintf( |
| 324 | 324 | __( |
@@ -350,7 +350,7 @@ discard block |
||
| 350 | 350 | // check if classname is fully qualified or is a legacy classname already prefixed with 'EE_' |
| 351 | 351 | return strpos($class_name, '\\') || strpos($class_name, 'EE_') === 0 |
| 352 | 352 | ? $class_name |
| 353 | - : 'EE_' . $class_name; |
|
| 353 | + : 'EE_'.$class_name; |
|
| 354 | 354 | } |
| 355 | 355 | |
| 356 | 356 | |
@@ -509,9 +509,9 @@ discard block |
||
| 509 | 509 | $incompatibility_message = ''; |
| 510 | 510 | //check whether this addon version is compatible with EE core |
| 511 | 511 | if ( |
| 512 | - isset(EE_Register_Addon::$_incompatible_addons[ $addon_name ]) |
|
| 512 | + isset(EE_Register_Addon::$_incompatible_addons[$addon_name]) |
|
| 513 | 513 | && ! self::_meets_min_core_version_requirement( |
| 514 | - EE_Register_Addon::$_incompatible_addons[ $addon_name ], |
|
| 514 | + EE_Register_Addon::$_incompatible_addons[$addon_name], |
|
| 515 | 515 | $addon_settings['version'] |
| 516 | 516 | ) |
| 517 | 517 | ) { |
@@ -521,7 +521,7 @@ discard block |
||
| 521 | 521 | ), |
| 522 | 522 | $addon_name, |
| 523 | 523 | '<br />', |
| 524 | - EE_Register_Addon::$_incompatible_addons[ $addon_name ], |
|
| 524 | + EE_Register_Addon::$_incompatible_addons[$addon_name], |
|
| 525 | 525 | '<span style="font-weight: bold; color: #D54E21;">', |
| 526 | 526 | '</span><br />' |
| 527 | 527 | ); |
@@ -553,7 +553,7 @@ discard block |
||
| 553 | 553 | '</span><br />' |
| 554 | 554 | ); |
| 555 | 555 | } |
| 556 | - if (! empty($incompatibility_message)) { |
|
| 556 | + if ( ! empty($incompatibility_message)) { |
|
| 557 | 557 | // remove 'activate' from the REQUEST |
| 558 | 558 | // so WP doesn't erroneously tell the user the plugin activated fine when it didn't |
| 559 | 559 | unset($_GET['activate'], $_REQUEST['activate']); |
@@ -581,11 +581,11 @@ discard block |
||
| 581 | 581 | */ |
| 582 | 582 | private static function _parse_pue_options($addon_name, $class_name, array $setup_args) |
| 583 | 583 | { |
| 584 | - if (! empty($setup_args['pue_options'])) { |
|
| 585 | - self::$_settings[ $addon_name ]['pue_options'] = array( |
|
| 584 | + if ( ! empty($setup_args['pue_options'])) { |
|
| 585 | + self::$_settings[$addon_name]['pue_options'] = array( |
|
| 586 | 586 | 'pue_plugin_slug' => isset($setup_args['pue_options']['pue_plugin_slug']) |
| 587 | 587 | ? (string) $setup_args['pue_options']['pue_plugin_slug'] |
| 588 | - : 'espresso_' . strtolower($class_name), |
|
| 588 | + : 'espresso_'.strtolower($class_name), |
|
| 589 | 589 | 'plugin_basename' => isset($setup_args['pue_options']['plugin_basename']) |
| 590 | 590 | ? (string) $setup_args['pue_options']['plugin_basename'] |
| 591 | 591 | : plugin_basename($setup_args['main_file_path']), |
@@ -645,12 +645,12 @@ discard block |
||
| 645 | 645 | //(as the newly-activated addon wasn't around the first time addons were registered). |
| 646 | 646 | //Note: the presence of pue_options in the addon registration options will initialize the $_settings |
| 647 | 647 | //property for the add-on, but the add-on is only partially initialized. Hence, the additional check. |
| 648 | - if (! isset(self::$_settings[ $addon_name ]) |
|
| 649 | - || (isset(self::$_settings[ $addon_name ]) |
|
| 650 | - && ! isset(self::$_settings[ $addon_name ]['class_name']) |
|
| 648 | + if ( ! isset(self::$_settings[$addon_name]) |
|
| 649 | + || (isset(self::$_settings[$addon_name]) |
|
| 650 | + && ! isset(self::$_settings[$addon_name]['class_name']) |
|
| 651 | 651 | ) |
| 652 | 652 | ) { |
| 653 | - self::$_settings[ $addon_name ] = $addon_settings; |
|
| 653 | + self::$_settings[$addon_name] = $addon_settings; |
|
| 654 | 654 | $addon = self::_load_and_init_addon_class($addon_name); |
| 655 | 655 | $addon->set_activation_indicator_option(); |
| 656 | 656 | // dont bother setting up the rest of the addon. |
@@ -676,10 +676,10 @@ discard block |
||
| 676 | 676 | ); |
| 677 | 677 | } |
| 678 | 678 | // make sure addon settings are set correctly without overwriting anything existing |
| 679 | - if (isset(self::$_settings[ $addon_name ])) { |
|
| 680 | - self::$_settings[ $addon_name ] += $addon_settings; |
|
| 679 | + if (isset(self::$_settings[$addon_name])) { |
|
| 680 | + self::$_settings[$addon_name] += $addon_settings; |
|
| 681 | 681 | } else { |
| 682 | - self::$_settings[ $addon_name ] = $addon_settings; |
|
| 682 | + self::$_settings[$addon_name] = $addon_settings; |
|
| 683 | 683 | } |
| 684 | 684 | return false; |
| 685 | 685 | } |
@@ -692,13 +692,13 @@ discard block |
||
| 692 | 692 | */ |
| 693 | 693 | private static function _setup_autoloaders($addon_name) |
| 694 | 694 | { |
| 695 | - if (! empty(self::$_settings[ $addon_name ]['autoloader_paths'])) { |
|
| 695 | + if ( ! empty(self::$_settings[$addon_name]['autoloader_paths'])) { |
|
| 696 | 696 | // setup autoloader for single file |
| 697 | - EEH_Autoloader::instance()->register_autoloader(self::$_settings[ $addon_name ]['autoloader_paths']); |
|
| 697 | + EEH_Autoloader::instance()->register_autoloader(self::$_settings[$addon_name]['autoloader_paths']); |
|
| 698 | 698 | } |
| 699 | 699 | // setup autoloaders for folders |
| 700 | - if (! empty(self::$_settings[ $addon_name ]['autoloader_folders'])) { |
|
| 701 | - foreach ((array) self::$_settings[ $addon_name ]['autoloader_folders'] as $autoloader_folder) { |
|
| 700 | + if ( ! empty(self::$_settings[$addon_name]['autoloader_folders'])) { |
|
| 701 | + foreach ((array) self::$_settings[$addon_name]['autoloader_folders'] as $autoloader_folder) { |
|
| 702 | 702 | EEH_Autoloader::register_autoloaders_for_each_file_in_folder($autoloader_folder); |
| 703 | 703 | } |
| 704 | 704 | } |
@@ -716,27 +716,27 @@ discard block |
||
| 716 | 716 | { |
| 717 | 717 | // register new models |
| 718 | 718 | if ( |
| 719 | - ! empty(self::$_settings[ $addon_name ]['model_paths']) |
|
| 720 | - || ! empty(self::$_settings[ $addon_name ]['class_paths']) |
|
| 719 | + ! empty(self::$_settings[$addon_name]['model_paths']) |
|
| 720 | + || ! empty(self::$_settings[$addon_name]['class_paths']) |
|
| 721 | 721 | ) { |
| 722 | 722 | EE_Register_Model::register( |
| 723 | 723 | $addon_name, |
| 724 | 724 | array( |
| 725 | - 'model_paths' => self::$_settings[ $addon_name ]['model_paths'], |
|
| 726 | - 'class_paths' => self::$_settings[ $addon_name ]['class_paths'], |
|
| 725 | + 'model_paths' => self::$_settings[$addon_name]['model_paths'], |
|
| 726 | + 'class_paths' => self::$_settings[$addon_name]['class_paths'], |
|
| 727 | 727 | ) |
| 728 | 728 | ); |
| 729 | 729 | } |
| 730 | 730 | // register model extensions |
| 731 | 731 | if ( |
| 732 | - ! empty(self::$_settings[ $addon_name ]['model_extension_paths']) |
|
| 733 | - || ! empty(self::$_settings[ $addon_name ]['class_extension_paths']) |
|
| 732 | + ! empty(self::$_settings[$addon_name]['model_extension_paths']) |
|
| 733 | + || ! empty(self::$_settings[$addon_name]['class_extension_paths']) |
|
| 734 | 734 | ) { |
| 735 | 735 | EE_Register_Model_Extensions::register( |
| 736 | 736 | $addon_name, |
| 737 | 737 | array( |
| 738 | - 'model_extension_paths' => self::$_settings[ $addon_name ]['model_extension_paths'], |
|
| 739 | - 'class_extension_paths' => self::$_settings[ $addon_name ]['class_extension_paths'], |
|
| 738 | + 'model_extension_paths' => self::$_settings[$addon_name]['model_extension_paths'], |
|
| 739 | + 'class_extension_paths' => self::$_settings[$addon_name]['class_extension_paths'], |
|
| 740 | 740 | ) |
| 741 | 741 | ); |
| 742 | 742 | } |
@@ -751,10 +751,10 @@ discard block |
||
| 751 | 751 | private static function _register_data_migration_scripts($addon_name) |
| 752 | 752 | { |
| 753 | 753 | // setup DMS |
| 754 | - if (! empty(self::$_settings[ $addon_name ]['dms_paths'])) { |
|
| 754 | + if ( ! empty(self::$_settings[$addon_name]['dms_paths'])) { |
|
| 755 | 755 | EE_Register_Data_Migration_Scripts::register( |
| 756 | 756 | $addon_name, |
| 757 | - array('dms_paths' => self::$_settings[ $addon_name ]['dms_paths']) |
|
| 757 | + array('dms_paths' => self::$_settings[$addon_name]['dms_paths']) |
|
| 758 | 758 | ); |
| 759 | 759 | } |
| 760 | 760 | } |
@@ -768,12 +768,12 @@ discard block |
||
| 768 | 768 | private static function _register_config($addon_name) |
| 769 | 769 | { |
| 770 | 770 | // if config_class is present let's register config. |
| 771 | - if (! empty(self::$_settings[ $addon_name ]['config_class'])) { |
|
| 771 | + if ( ! empty(self::$_settings[$addon_name]['config_class'])) { |
|
| 772 | 772 | EE_Register_Config::register( |
| 773 | - self::$_settings[ $addon_name ]['config_class'], |
|
| 773 | + self::$_settings[$addon_name]['config_class'], |
|
| 774 | 774 | array( |
| 775 | - 'config_section' => self::$_settings[ $addon_name ]['config_section'], |
|
| 776 | - 'config_name' => self::$_settings[ $addon_name ]['config_name'], |
|
| 775 | + 'config_section' => self::$_settings[$addon_name]['config_section'], |
|
| 776 | + 'config_name' => self::$_settings[$addon_name]['config_name'], |
|
| 777 | 777 | ) |
| 778 | 778 | ); |
| 779 | 779 | } |
@@ -787,10 +787,10 @@ discard block |
||
| 787 | 787 | */ |
| 788 | 788 | private static function _register_admin_pages($addon_name) |
| 789 | 789 | { |
| 790 | - if (! empty(self::$_settings[ $addon_name ]['admin_path'])) { |
|
| 790 | + if ( ! empty(self::$_settings[$addon_name]['admin_path'])) { |
|
| 791 | 791 | EE_Register_Admin_Page::register( |
| 792 | 792 | $addon_name, |
| 793 | - array('page_path' => self::$_settings[ $addon_name ]['admin_path']) |
|
| 793 | + array('page_path' => self::$_settings[$addon_name]['admin_path']) |
|
| 794 | 794 | ); |
| 795 | 795 | } |
| 796 | 796 | } |
@@ -803,10 +803,10 @@ discard block |
||
| 803 | 803 | */ |
| 804 | 804 | private static function _register_modules($addon_name) |
| 805 | 805 | { |
| 806 | - if (! empty(self::$_settings[ $addon_name ]['module_paths'])) { |
|
| 806 | + if ( ! empty(self::$_settings[$addon_name]['module_paths'])) { |
|
| 807 | 807 | EE_Register_Module::register( |
| 808 | 808 | $addon_name, |
| 809 | - array('module_paths' => self::$_settings[ $addon_name ]['module_paths']) |
|
| 809 | + array('module_paths' => self::$_settings[$addon_name]['module_paths']) |
|
| 810 | 810 | ); |
| 811 | 811 | } |
| 812 | 812 | } |
@@ -819,17 +819,17 @@ discard block |
||
| 819 | 819 | */ |
| 820 | 820 | private static function _register_shortcodes($addon_name) |
| 821 | 821 | { |
| 822 | - if (! empty(self::$_settings[ $addon_name ]['shortcode_paths']) |
|
| 823 | - || ! empty(self::$_settings[ $addon_name ]['shortcode_fqcns']) |
|
| 822 | + if ( ! empty(self::$_settings[$addon_name]['shortcode_paths']) |
|
| 823 | + || ! empty(self::$_settings[$addon_name]['shortcode_fqcns']) |
|
| 824 | 824 | ) { |
| 825 | 825 | EE_Register_Shortcode::register( |
| 826 | 826 | $addon_name, |
| 827 | 827 | array( |
| 828 | - 'shortcode_paths' => isset(self::$_settings[ $addon_name ]['shortcode_paths']) |
|
| 829 | - ? self::$_settings[ $addon_name ]['shortcode_paths'] |
|
| 828 | + 'shortcode_paths' => isset(self::$_settings[$addon_name]['shortcode_paths']) |
|
| 829 | + ? self::$_settings[$addon_name]['shortcode_paths'] |
|
| 830 | 830 | : array(), |
| 831 | - 'shortcode_fqcns' => isset(self::$_settings[ $addon_name ]['shortcode_fqcns']) |
|
| 832 | - ? self::$_settings[ $addon_name ]['shortcode_fqcns'] |
|
| 831 | + 'shortcode_fqcns' => isset(self::$_settings[$addon_name]['shortcode_fqcns']) |
|
| 832 | + ? self::$_settings[$addon_name]['shortcode_fqcns'] |
|
| 833 | 833 | : array(), |
| 834 | 834 | ) |
| 835 | 835 | ); |
@@ -844,10 +844,10 @@ discard block |
||
| 844 | 844 | */ |
| 845 | 845 | private static function _register_widgets($addon_name) |
| 846 | 846 | { |
| 847 | - if (! empty(self::$_settings[ $addon_name ]['widget_paths'])) { |
|
| 847 | + if ( ! empty(self::$_settings[$addon_name]['widget_paths'])) { |
|
| 848 | 848 | EE_Register_Widget::register( |
| 849 | 849 | $addon_name, |
| 850 | - array('widget_paths' => self::$_settings[ $addon_name ]['widget_paths']) |
|
| 850 | + array('widget_paths' => self::$_settings[$addon_name]['widget_paths']) |
|
| 851 | 851 | ); |
| 852 | 852 | } |
| 853 | 853 | } |
@@ -860,12 +860,12 @@ discard block |
||
| 860 | 860 | */ |
| 861 | 861 | private static function _register_capabilities($addon_name) |
| 862 | 862 | { |
| 863 | - if (! empty(self::$_settings[ $addon_name ]['capabilities'])) { |
|
| 863 | + if ( ! empty(self::$_settings[$addon_name]['capabilities'])) { |
|
| 864 | 864 | EE_Register_Capabilities::register( |
| 865 | 865 | $addon_name, |
| 866 | 866 | array( |
| 867 | - 'capabilities' => self::$_settings[ $addon_name ]['capabilities'], |
|
| 868 | - 'capability_maps' => self::$_settings[ $addon_name ]['capability_maps'], |
|
| 867 | + 'capabilities' => self::$_settings[$addon_name]['capabilities'], |
|
| 868 | + 'capability_maps' => self::$_settings[$addon_name]['capability_maps'], |
|
| 869 | 869 | ) |
| 870 | 870 | ); |
| 871 | 871 | } |
@@ -879,7 +879,7 @@ discard block |
||
| 879 | 879 | */ |
| 880 | 880 | private static function _register_message_types($addon_name) |
| 881 | 881 | { |
| 882 | - if (! empty(self::$_settings[ $addon_name ]['message_types'])) { |
|
| 882 | + if ( ! empty(self::$_settings[$addon_name]['message_types'])) { |
|
| 883 | 883 | add_action( |
| 884 | 884 | 'EE_Brewing_Regular___messages_caf', |
| 885 | 885 | array('EE_Register_Addon', 'register_message_types') |
@@ -896,15 +896,15 @@ discard block |
||
| 896 | 896 | private static function _register_custom_post_types($addon_name) |
| 897 | 897 | { |
| 898 | 898 | if ( |
| 899 | - ! empty(self::$_settings[ $addon_name ]['custom_post_types']) |
|
| 900 | - || ! empty(self::$_settings[ $addon_name ]['custom_taxonomies']) |
|
| 899 | + ! empty(self::$_settings[$addon_name]['custom_post_types']) |
|
| 900 | + || ! empty(self::$_settings[$addon_name]['custom_taxonomies']) |
|
| 901 | 901 | ) { |
| 902 | 902 | EE_Register_CPT::register( |
| 903 | 903 | $addon_name, |
| 904 | 904 | array( |
| 905 | - 'cpts' => self::$_settings[ $addon_name ]['custom_post_types'], |
|
| 906 | - 'cts' => self::$_settings[ $addon_name ]['custom_taxonomies'], |
|
| 907 | - 'default_terms' => self::$_settings[ $addon_name ]['default_terms'], |
|
| 905 | + 'cpts' => self::$_settings[$addon_name]['custom_post_types'], |
|
| 906 | + 'cts' => self::$_settings[$addon_name]['custom_taxonomies'], |
|
| 907 | + 'default_terms' => self::$_settings[$addon_name]['default_terms'], |
|
| 908 | 908 | ) |
| 909 | 909 | ); |
| 910 | 910 | } |
@@ -922,10 +922,10 @@ discard block |
||
| 922 | 922 | */ |
| 923 | 923 | private static function _register_payment_methods($addon_name) |
| 924 | 924 | { |
| 925 | - if (! empty(self::$_settings[ $addon_name ]['payment_method_paths'])) { |
|
| 925 | + if ( ! empty(self::$_settings[$addon_name]['payment_method_paths'])) { |
|
| 926 | 926 | EE_Register_Payment_Method::register( |
| 927 | 927 | $addon_name, |
| 928 | - array('payment_method_paths' => self::$_settings[ $addon_name ]['payment_method_paths']) |
|
| 928 | + array('payment_method_paths' => self::$_settings[$addon_name]['payment_method_paths']) |
|
| 929 | 929 | ); |
| 930 | 930 | } |
| 931 | 931 | } |
@@ -946,16 +946,16 @@ discard block |
||
| 946 | 946 | { |
| 947 | 947 | $loader = EventEspresso\core\services\loaders\LoaderFactory::getLoader(); |
| 948 | 948 | $addon = $loader->getShared( |
| 949 | - self::$_settings[ $addon_name ]['class_name'], |
|
| 949 | + self::$_settings[$addon_name]['class_name'], |
|
| 950 | 950 | array( |
| 951 | 951 | $loader->getShared('EE_Dependency_Map'), |
| 952 | 952 | // if a domain_fqcn is specified, then load that class |
| 953 | - self::$_settings[ $addon_name ]['domain_fqcn'] !== '' |
|
| 953 | + self::$_settings[$addon_name]['domain_fqcn'] !== '' |
|
| 954 | 954 | ? $loader->getShared( |
| 955 | - self::$_settings[ $addon_name ]['domain_fqcn'], |
|
| 955 | + self::$_settings[$addon_name]['domain_fqcn'], |
|
| 956 | 956 | array( |
| 957 | - self::$_settings[ $addon_name ]['main_file_path'], |
|
| 958 | - self::$_settings[ $addon_name ]['version'] |
|
| 957 | + self::$_settings[$addon_name]['main_file_path'], |
|
| 958 | + self::$_settings[$addon_name]['version'] |
|
| 959 | 959 | ) |
| 960 | 960 | ) |
| 961 | 961 | : null, |
@@ -963,24 +963,24 @@ discard block |
||
| 963 | 963 | ) |
| 964 | 964 | ); |
| 965 | 965 | $addon->set_name($addon_name); |
| 966 | - $addon->set_plugin_slug(self::$_settings[ $addon_name ]['plugin_slug']); |
|
| 967 | - $addon->set_plugin_basename(self::$_settings[ $addon_name ]['plugin_basename']); |
|
| 968 | - $addon->set_main_plugin_file(self::$_settings[ $addon_name ]['main_file_path']); |
|
| 969 | - $addon->set_plugin_action_slug(self::$_settings[ $addon_name ]['plugin_action_slug']); |
|
| 970 | - $addon->set_plugins_page_row(self::$_settings[ $addon_name ]['plugins_page_row']); |
|
| 971 | - $addon->set_version(self::$_settings[ $addon_name ]['version']); |
|
| 972 | - $addon->set_min_core_version(self::_effective_version(self::$_settings[ $addon_name ]['min_core_version'])); |
|
| 973 | - $addon->set_config_section(self::$_settings[ $addon_name ]['config_section']); |
|
| 974 | - $addon->set_config_class(self::$_settings[ $addon_name ]['config_class']); |
|
| 975 | - $addon->set_config_name(self::$_settings[ $addon_name ]['config_name']); |
|
| 966 | + $addon->set_plugin_slug(self::$_settings[$addon_name]['plugin_slug']); |
|
| 967 | + $addon->set_plugin_basename(self::$_settings[$addon_name]['plugin_basename']); |
|
| 968 | + $addon->set_main_plugin_file(self::$_settings[$addon_name]['main_file_path']); |
|
| 969 | + $addon->set_plugin_action_slug(self::$_settings[$addon_name]['plugin_action_slug']); |
|
| 970 | + $addon->set_plugins_page_row(self::$_settings[$addon_name]['plugins_page_row']); |
|
| 971 | + $addon->set_version(self::$_settings[$addon_name]['version']); |
|
| 972 | + $addon->set_min_core_version(self::_effective_version(self::$_settings[$addon_name]['min_core_version'])); |
|
| 973 | + $addon->set_config_section(self::$_settings[$addon_name]['config_section']); |
|
| 974 | + $addon->set_config_class(self::$_settings[$addon_name]['config_class']); |
|
| 975 | + $addon->set_config_name(self::$_settings[$addon_name]['config_name']); |
|
| 976 | 976 | //unfortunately this can't be hooked in upon construction, because we don't have |
| 977 | 977 | //the plugin mainfile's path upon construction. |
| 978 | 978 | register_deactivation_hook($addon->get_main_plugin_file(), array($addon, 'deactivation')); |
| 979 | 979 | // call any additional admin_callback functions during load_admin_controller hook |
| 980 | - if (! empty(self::$_settings[ $addon_name ]['admin_callback'])) { |
|
| 980 | + if ( ! empty(self::$_settings[$addon_name]['admin_callback'])) { |
|
| 981 | 981 | add_action( |
| 982 | 982 | 'AHEE__EE_System__load_controllers__load_admin_controllers', |
| 983 | - array($addon, self::$_settings[ $addon_name ]['admin_callback']) |
|
| 983 | + array($addon, self::$_settings[$addon_name]['admin_callback']) |
|
| 984 | 984 | ); |
| 985 | 985 | } |
| 986 | 986 | return $addon; |
@@ -998,10 +998,10 @@ discard block |
||
| 998 | 998 | public static function load_pue_update() |
| 999 | 999 | { |
| 1000 | 1000 | // load PUE client |
| 1001 | - require_once EE_THIRD_PARTY . 'pue' . DS . 'pue-client.php'; |
|
| 1001 | + require_once EE_THIRD_PARTY.'pue'.DS.'pue-client.php'; |
|
| 1002 | 1002 | // cycle thru settings |
| 1003 | 1003 | foreach (self::$_settings as $settings) { |
| 1004 | - if (! empty($settings['pue_options'])) { |
|
| 1004 | + if ( ! empty($settings['pue_options'])) { |
|
| 1005 | 1005 | // initiate the class and start the plugin update engine! |
| 1006 | 1006 | new PluginUpdateEngineChecker( |
| 1007 | 1007 | // host file URL |
@@ -1009,7 +1009,7 @@ discard block |
||
| 1009 | 1009 | // plugin slug(s) |
| 1010 | 1010 | array( |
| 1011 | 1011 | 'premium' => array('p' => $settings['pue_options']['pue_plugin_slug']), |
| 1012 | - 'prerelease' => array('beta' => $settings['pue_options']['pue_plugin_slug'] . '-pr'), |
|
| 1012 | + 'prerelease' => array('beta' => $settings['pue_options']['pue_plugin_slug'].'-pr'), |
|
| 1013 | 1013 | ), |
| 1014 | 1014 | // options |
| 1015 | 1015 | array( |
@@ -1038,7 +1038,7 @@ discard block |
||
| 1038 | 1038 | public static function register_message_types() |
| 1039 | 1039 | { |
| 1040 | 1040 | foreach (self::$_settings as $addon_name => $settings) { |
| 1041 | - if (! empty($settings['message_types'])) { |
|
| 1041 | + if ( ! empty($settings['message_types'])) { |
|
| 1042 | 1042 | foreach ((array) $settings['message_types'] as $message_type => $message_type_settings) { |
| 1043 | 1043 | EE_Register_Message_Type::register($message_type, $message_type_settings); |
| 1044 | 1044 | } |
@@ -1060,50 +1060,50 @@ discard block |
||
| 1060 | 1060 | */ |
| 1061 | 1061 | public static function deregister($addon_name = null) |
| 1062 | 1062 | { |
| 1063 | - if (isset(self::$_settings[ $addon_name ]['class_name'])) { |
|
| 1063 | + if (isset(self::$_settings[$addon_name]['class_name'])) { |
|
| 1064 | 1064 | do_action('AHEE__EE_Register_Addon__deregister__before', $addon_name); |
| 1065 | - $class_name = self::$_settings[ $addon_name ]['class_name']; |
|
| 1066 | - if (! empty(self::$_settings[ $addon_name ]['dms_paths'])) { |
|
| 1065 | + $class_name = self::$_settings[$addon_name]['class_name']; |
|
| 1066 | + if ( ! empty(self::$_settings[$addon_name]['dms_paths'])) { |
|
| 1067 | 1067 | // setup DMS |
| 1068 | 1068 | EE_Register_Data_Migration_Scripts::deregister($addon_name); |
| 1069 | 1069 | } |
| 1070 | - if (! empty(self::$_settings[ $addon_name ]['admin_path'])) { |
|
| 1070 | + if ( ! empty(self::$_settings[$addon_name]['admin_path'])) { |
|
| 1071 | 1071 | // register admin page |
| 1072 | 1072 | EE_Register_Admin_Page::deregister($addon_name); |
| 1073 | 1073 | } |
| 1074 | - if (! empty(self::$_settings[ $addon_name ]['module_paths'])) { |
|
| 1074 | + if ( ! empty(self::$_settings[$addon_name]['module_paths'])) { |
|
| 1075 | 1075 | // add to list of modules to be registered |
| 1076 | 1076 | EE_Register_Module::deregister($addon_name); |
| 1077 | 1077 | } |
| 1078 | - if (! empty(self::$_settings[ $addon_name ]['shortcode_paths']) |
|
| 1079 | - || ! empty(self::$_settings[ $addon_name ]['shortcode_fqcns']) |
|
| 1078 | + if ( ! empty(self::$_settings[$addon_name]['shortcode_paths']) |
|
| 1079 | + || ! empty(self::$_settings[$addon_name]['shortcode_fqcns']) |
|
| 1080 | 1080 | ) { |
| 1081 | 1081 | // add to list of shortcodes to be registered |
| 1082 | 1082 | EE_Register_Shortcode::deregister($addon_name); |
| 1083 | 1083 | } |
| 1084 | - if (! empty(self::$_settings[ $addon_name ]['config_class'])) { |
|
| 1084 | + if ( ! empty(self::$_settings[$addon_name]['config_class'])) { |
|
| 1085 | 1085 | // if config_class present let's register config. |
| 1086 | - EE_Register_Config::deregister(self::$_settings[ $addon_name ]['config_class']); |
|
| 1086 | + EE_Register_Config::deregister(self::$_settings[$addon_name]['config_class']); |
|
| 1087 | 1087 | } |
| 1088 | - if (! empty(self::$_settings[ $addon_name ]['widget_paths'])) { |
|
| 1088 | + if ( ! empty(self::$_settings[$addon_name]['widget_paths'])) { |
|
| 1089 | 1089 | // add to list of widgets to be registered |
| 1090 | 1090 | EE_Register_Widget::deregister($addon_name); |
| 1091 | 1091 | } |
| 1092 | - if (! empty(self::$_settings[ $addon_name ]['model_paths']) |
|
| 1093 | - || ! empty(self::$_settings[ $addon_name ]['class_paths']) |
|
| 1092 | + if ( ! empty(self::$_settings[$addon_name]['model_paths']) |
|
| 1093 | + || ! empty(self::$_settings[$addon_name]['class_paths']) |
|
| 1094 | 1094 | ) { |
| 1095 | 1095 | // add to list of shortcodes to be registered |
| 1096 | 1096 | EE_Register_Model::deregister($addon_name); |
| 1097 | 1097 | } |
| 1098 | - if (! empty(self::$_settings[ $addon_name ]['model_extension_paths']) |
|
| 1099 | - || ! empty(self::$_settings[ $addon_name ]['class_extension_paths']) |
|
| 1098 | + if ( ! empty(self::$_settings[$addon_name]['model_extension_paths']) |
|
| 1099 | + || ! empty(self::$_settings[$addon_name]['class_extension_paths']) |
|
| 1100 | 1100 | ) { |
| 1101 | 1101 | // add to list of shortcodes to be registered |
| 1102 | 1102 | EE_Register_Model_Extensions::deregister($addon_name); |
| 1103 | 1103 | } |
| 1104 | - if (! empty(self::$_settings[ $addon_name ]['message_types'])) { |
|
| 1104 | + if ( ! empty(self::$_settings[$addon_name]['message_types'])) { |
|
| 1105 | 1105 | foreach ( |
| 1106 | - (array) self::$_settings[ $addon_name ]['message_types'] as $message_type => |
|
| 1106 | + (array) self::$_settings[$addon_name]['message_types'] as $message_type => |
|
| 1107 | 1107 | $message_type_settings |
| 1108 | 1108 | ) { |
| 1109 | 1109 | EE_Register_Message_Type::deregister($message_type); |
@@ -1111,22 +1111,22 @@ discard block |
||
| 1111 | 1111 | } |
| 1112 | 1112 | //deregister capabilities for addon |
| 1113 | 1113 | if ( |
| 1114 | - ! empty(self::$_settings[ $addon_name ]['capabilities']) |
|
| 1115 | - || ! empty(self::$_settings[ $addon_name ]['capability_maps']) |
|
| 1114 | + ! empty(self::$_settings[$addon_name]['capabilities']) |
|
| 1115 | + || ! empty(self::$_settings[$addon_name]['capability_maps']) |
|
| 1116 | 1116 | ) { |
| 1117 | 1117 | EE_Register_Capabilities::deregister($addon_name); |
| 1118 | 1118 | } |
| 1119 | 1119 | //deregister custom_post_types for addon |
| 1120 | - if (! empty(self::$_settings[ $addon_name ]['custom_post_types'])) { |
|
| 1120 | + if ( ! empty(self::$_settings[$addon_name]['custom_post_types'])) { |
|
| 1121 | 1121 | EE_Register_CPT::deregister($addon_name); |
| 1122 | 1122 | } |
| 1123 | - if (! empty(self::$_settings[ $addon_name ]['payment_method_paths'])) { |
|
| 1123 | + if ( ! empty(self::$_settings[$addon_name]['payment_method_paths'])) { |
|
| 1124 | 1124 | EE_Register_Payment_Method::deregister($addon_name); |
| 1125 | 1125 | } |
| 1126 | 1126 | $addon = EE_Registry::instance()->getAddon($class_name); |
| 1127 | 1127 | if ($addon instanceof EE_Addon) { |
| 1128 | 1128 | remove_action( |
| 1129 | - 'deactivate_' . $addon->get_main_plugin_file_basename(), |
|
| 1129 | + 'deactivate_'.$addon->get_main_plugin_file_basename(), |
|
| 1130 | 1130 | array($addon, 'deactivation') |
| 1131 | 1131 | ); |
| 1132 | 1132 | remove_action( |
@@ -1141,7 +1141,7 @@ discard block |
||
| 1141 | 1141 | ); |
| 1142 | 1142 | } |
| 1143 | 1143 | EE_Registry::instance()->removeAddon($class_name); |
| 1144 | - unset(self::$_settings[ $addon_name ]); |
|
| 1144 | + unset(self::$_settings[$addon_name]); |
|
| 1145 | 1145 | do_action('AHEE__EE_Register_Addon__deregister__after', $addon_name); |
| 1146 | 1146 | } |
| 1147 | 1147 | } |
@@ -18,16 +18,16 @@ |
||
| 18 | 18 | interface RequiresDomainInterface |
| 19 | 19 | { |
| 20 | 20 | |
| 21 | - /** |
|
| 22 | - * @param DomainInterface $domain |
|
| 23 | - */ |
|
| 24 | - public function setDomain(DomainInterface $domain = null); |
|
| 21 | + /** |
|
| 22 | + * @param DomainInterface $domain |
|
| 23 | + */ |
|
| 24 | + public function setDomain(DomainInterface $domain = null); |
|
| 25 | 25 | |
| 26 | 26 | |
| 27 | - /** |
|
| 28 | - * @return DomainInterface |
|
| 29 | - */ |
|
| 30 | - public function domain(); |
|
| 27 | + /** |
|
| 28 | + * @return DomainInterface |
|
| 29 | + */ |
|
| 30 | + public function domain(); |
|
| 31 | 31 | |
| 32 | 32 | } |
| 33 | 33 | // Location: RequiresDomainInterface.php |
@@ -20,15 +20,15 @@ |
||
| 20 | 20 | interface RequiresDependencyMapInterface |
| 21 | 21 | { |
| 22 | 22 | |
| 23 | - /** |
|
| 24 | - * @param EE_Dependency_Map $dependency_map |
|
| 25 | - */ |
|
| 26 | - public function setDependencyMap($dependency_map); |
|
| 27 | - |
|
| 28 | - /** |
|
| 29 | - * @return EE_Dependency_Map |
|
| 30 | - */ |
|
| 31 | - public function dependencyMap(); |
|
| 23 | + /** |
|
| 24 | + * @param EE_Dependency_Map $dependency_map |
|
| 25 | + */ |
|
| 26 | + public function setDependencyMap($dependency_map); |
|
| 27 | + |
|
| 28 | + /** |
|
| 29 | + * @return EE_Dependency_Map |
|
| 30 | + */ |
|
| 31 | + public function dependencyMap(); |
|
| 32 | 32 | |
| 33 | 33 | } |
| 34 | 34 | // Location: RequiresDependencyMap.php |
@@ -18,782 +18,782 @@ discard block |
||
| 18 | 18 | { |
| 19 | 19 | |
| 20 | 20 | |
| 21 | - /** |
|
| 22 | - * prefix to be added onto an addon's plugin slug to make a wp option name |
|
| 23 | - * which will be used to store the plugin's activation history |
|
| 24 | - */ |
|
| 25 | - const ee_addon_version_history_option_prefix = 'ee_version_history_'; |
|
| 26 | - |
|
| 27 | - /** |
|
| 28 | - * @var $_version |
|
| 29 | - * @type string |
|
| 30 | - */ |
|
| 31 | - protected $_version = ''; |
|
| 32 | - |
|
| 33 | - /** |
|
| 34 | - * @var $_min_core_version |
|
| 35 | - * @type string |
|
| 36 | - */ |
|
| 37 | - protected $_min_core_version = ''; |
|
| 38 | - |
|
| 39 | - /** |
|
| 40 | - * derived from plugin 'main_file_path using plugin_basename() |
|
| 41 | - * |
|
| 42 | - * @type string $_plugin_basename |
|
| 43 | - */ |
|
| 44 | - protected $_plugin_basename = ''; |
|
| 45 | - |
|
| 46 | - /** |
|
| 47 | - * A non-internationalized name to identify this addon for use in URLs, etc |
|
| 48 | - * |
|
| 49 | - * @type string $_plugin_slug |
|
| 50 | - */ |
|
| 51 | - protected $_plugin_slug = ''; |
|
| 52 | - |
|
| 53 | - /** |
|
| 54 | - * A non-internationalized name to identify this addon. Eg 'Calendar','MailChimp',etc/ |
|
| 55 | - * |
|
| 56 | - * @type string _addon_name |
|
| 57 | - */ |
|
| 58 | - protected $_addon_name = ''; |
|
| 59 | - |
|
| 60 | - /** |
|
| 61 | - * one of the EE_System::req_type_* constants |
|
| 62 | - * |
|
| 63 | - * @type int $_req_type |
|
| 64 | - */ |
|
| 65 | - protected $_req_type; |
|
| 66 | - |
|
| 67 | - /** |
|
| 68 | - * page slug to be used when generating the "Settings" link on the WP plugin page |
|
| 69 | - * |
|
| 70 | - * @type string $_plugin_action_slug |
|
| 71 | - */ |
|
| 72 | - protected $_plugin_action_slug = ''; |
|
| 73 | - |
|
| 74 | - /** |
|
| 75 | - * if not empty, inserts a new table row after this plugin's row on the WP Plugins page |
|
| 76 | - * that can be used for adding upgrading/marketing info |
|
| 77 | - * |
|
| 78 | - * @type array $_plugins_page_row |
|
| 79 | - */ |
|
| 80 | - protected $_plugins_page_row = array(); |
|
| 81 | - |
|
| 82 | - |
|
| 83 | - |
|
| 84 | - /** |
|
| 85 | - * filepath to the main file, which can be used for register_activation_hook, register_deactivation_hook, etc. |
|
| 86 | - * |
|
| 87 | - * @type string |
|
| 88 | - */ |
|
| 89 | - protected $_main_plugin_file; |
|
| 90 | - |
|
| 91 | - |
|
| 92 | - /** |
|
| 93 | - * @var EE_Dependency_Map $dependency_map |
|
| 94 | - */ |
|
| 95 | - private $dependency_map; |
|
| 96 | - |
|
| 97 | - |
|
| 98 | - /** |
|
| 99 | - * @var DomainInterface $domain |
|
| 100 | - */ |
|
| 101 | - private $domain; |
|
| 102 | - |
|
| 103 | - |
|
| 104 | - /** |
|
| 105 | - * @param DomainInterface $domain |
|
| 106 | - * @param EE_Dependency_Map $dependency_map |
|
| 107 | - */ |
|
| 108 | - public function __construct(EE_Dependency_Map $dependency_map, DomainInterface $domain = null) |
|
| 109 | - { |
|
| 110 | - $this->setDependencyMap($dependency_map); |
|
| 111 | - $this->setDomain($domain); |
|
| 112 | - add_action('AHEE__EE_System__load_controllers__load_admin_controllers', array($this, 'admin_init')); |
|
| 113 | - } |
|
| 114 | - |
|
| 115 | - |
|
| 116 | - /** |
|
| 117 | - * @param EE_Dependency_Map $dependency_map |
|
| 118 | - */ |
|
| 119 | - public function setDependencyMap($dependency_map) |
|
| 120 | - { |
|
| 121 | - $this->dependency_map = $dependency_map; |
|
| 122 | - } |
|
| 123 | - |
|
| 124 | - |
|
| 125 | - /** |
|
| 126 | - * @return EE_Dependency_Map |
|
| 127 | - */ |
|
| 128 | - public function dependencyMap() |
|
| 129 | - { |
|
| 130 | - return $this->dependency_map; |
|
| 131 | - } |
|
| 132 | - |
|
| 133 | - |
|
| 134 | - /** |
|
| 135 | - * @param DomainInterface $domain |
|
| 136 | - */ |
|
| 137 | - public function setDomain(DomainInterface $domain = null) |
|
| 138 | - { |
|
| 139 | - $this->domain = $domain; |
|
| 140 | - } |
|
| 141 | - |
|
| 142 | - /** |
|
| 143 | - * @return DomainInterface |
|
| 144 | - */ |
|
| 145 | - public function domain() |
|
| 146 | - { |
|
| 147 | - return $this->domain; |
|
| 148 | - } |
|
| 149 | - |
|
| 150 | - |
|
| 151 | - /** |
|
| 152 | - * @param mixed $version |
|
| 153 | - */ |
|
| 154 | - public function set_version($version = null) |
|
| 155 | - { |
|
| 156 | - $this->_version = $version; |
|
| 157 | - } |
|
| 158 | - |
|
| 159 | - |
|
| 160 | - /** |
|
| 161 | - * get__version |
|
| 162 | - * |
|
| 163 | - * @return string |
|
| 164 | - */ |
|
| 165 | - public function version() |
|
| 166 | - { |
|
| 167 | - return $this->_version; |
|
| 168 | - } |
|
| 169 | - |
|
| 170 | - |
|
| 171 | - /** |
|
| 172 | - * @param mixed $min_core_version |
|
| 173 | - */ |
|
| 174 | - public function set_min_core_version($min_core_version = null) |
|
| 175 | - { |
|
| 176 | - $this->_min_core_version = $min_core_version; |
|
| 177 | - } |
|
| 178 | - |
|
| 179 | - |
|
| 180 | - /** |
|
| 181 | - * get__min_core_version |
|
| 182 | - * |
|
| 183 | - * @return string |
|
| 184 | - */ |
|
| 185 | - public function min_core_version() |
|
| 186 | - { |
|
| 187 | - return $this->_min_core_version; |
|
| 188 | - } |
|
| 189 | - |
|
| 190 | - |
|
| 191 | - /** |
|
| 192 | - * Sets addon_name |
|
| 193 | - * |
|
| 194 | - * @param string $addon_name |
|
| 195 | - * @return boolean |
|
| 196 | - */ |
|
| 197 | - public function set_name($addon_name) |
|
| 198 | - { |
|
| 199 | - return $this->_addon_name = $addon_name; |
|
| 200 | - } |
|
| 201 | - |
|
| 202 | - |
|
| 203 | - /** |
|
| 204 | - * Gets addon_name |
|
| 205 | - * |
|
| 206 | - * @return string |
|
| 207 | - */ |
|
| 208 | - public function name() |
|
| 209 | - { |
|
| 210 | - return $this->_addon_name; |
|
| 211 | - } |
|
| 212 | - |
|
| 213 | - |
|
| 214 | - /** |
|
| 215 | - * @return string |
|
| 216 | - */ |
|
| 217 | - public function plugin_basename() |
|
| 218 | - { |
|
| 219 | - |
|
| 220 | - return $this->_plugin_basename; |
|
| 221 | - } |
|
| 222 | - |
|
| 223 | - |
|
| 224 | - /** |
|
| 225 | - * @param string $plugin_basename |
|
| 226 | - */ |
|
| 227 | - public function set_plugin_basename($plugin_basename) |
|
| 228 | - { |
|
| 229 | - |
|
| 230 | - $this->_plugin_basename = $plugin_basename; |
|
| 231 | - } |
|
| 232 | - |
|
| 233 | - |
|
| 234 | - /** |
|
| 235 | - * @return string |
|
| 236 | - */ |
|
| 237 | - public function plugin_slug() |
|
| 238 | - { |
|
| 239 | - |
|
| 240 | - return $this->_plugin_slug; |
|
| 241 | - } |
|
| 242 | - |
|
| 243 | - |
|
| 244 | - /** |
|
| 245 | - * @param string $plugin_slug |
|
| 246 | - */ |
|
| 247 | - public function set_plugin_slug($plugin_slug) |
|
| 248 | - { |
|
| 249 | - |
|
| 250 | - $this->_plugin_slug = $plugin_slug; |
|
| 251 | - } |
|
| 252 | - |
|
| 253 | - |
|
| 254 | - /** |
|
| 255 | - * @return string |
|
| 256 | - */ |
|
| 257 | - public function plugin_action_slug() |
|
| 258 | - { |
|
| 259 | - |
|
| 260 | - return $this->_plugin_action_slug; |
|
| 261 | - } |
|
| 262 | - |
|
| 263 | - |
|
| 264 | - /** |
|
| 265 | - * @param string $plugin_action_slug |
|
| 266 | - */ |
|
| 267 | - public function set_plugin_action_slug($plugin_action_slug) |
|
| 268 | - { |
|
| 269 | - |
|
| 270 | - $this->_plugin_action_slug = $plugin_action_slug; |
|
| 271 | - } |
|
| 272 | - |
|
| 273 | - |
|
| 274 | - /** |
|
| 275 | - * @return array |
|
| 276 | - */ |
|
| 277 | - public function get_plugins_page_row() |
|
| 278 | - { |
|
| 279 | - |
|
| 280 | - return $this->_plugins_page_row; |
|
| 281 | - } |
|
| 282 | - |
|
| 283 | - |
|
| 284 | - /** |
|
| 285 | - * @param array $plugins_page_row |
|
| 286 | - */ |
|
| 287 | - public function set_plugins_page_row($plugins_page_row = array()) |
|
| 288 | - { |
|
| 289 | - // sigh.... check for example content that I stupidly merged to master and remove it if found |
|
| 290 | - if (! is_array($plugins_page_row) |
|
| 291 | - && strpos($plugins_page_row, '<h3>Promotions Addon Upsell Info</h3>') !== false |
|
| 292 | - ) { |
|
| 293 | - $plugins_page_row = array(); |
|
| 294 | - } |
|
| 295 | - $this->_plugins_page_row = (array) $plugins_page_row; |
|
| 296 | - } |
|
| 297 | - |
|
| 298 | - |
|
| 299 | - /** |
|
| 300 | - * Called when EE core detects this addon has been activated for the first time. |
|
| 301 | - * If the site isn't in maintenance mode, should setup the addon's database |
|
| 302 | - * |
|
| 303 | - * @return void |
|
| 304 | - */ |
|
| 305 | - public function new_install() |
|
| 306 | - { |
|
| 307 | - $classname = get_class($this); |
|
| 308 | - do_action("AHEE__{$classname}__new_install"); |
|
| 309 | - do_action('AHEE__EE_Addon__new_install', $this); |
|
| 310 | - EE_Maintenance_Mode::instance()->set_maintenance_mode_if_db_old(); |
|
| 311 | - add_action( |
|
| 312 | - 'AHEE__EE_System__perform_activations_upgrades_and_migrations', |
|
| 313 | - array($this, 'initialize_db_if_no_migrations_required') |
|
| 314 | - ); |
|
| 315 | - } |
|
| 316 | - |
|
| 317 | - |
|
| 318 | - /** |
|
| 319 | - * Called when EE core detects this addon has been reactivated. When this happens, |
|
| 320 | - * it's good to just check that your data is still intact |
|
| 321 | - * |
|
| 322 | - * @return void |
|
| 323 | - */ |
|
| 324 | - public function reactivation() |
|
| 325 | - { |
|
| 326 | - $classname = get_class($this); |
|
| 327 | - do_action("AHEE__{$classname}__reactivation"); |
|
| 328 | - do_action('AHEE__EE_Addon__reactivation', $this); |
|
| 329 | - EE_Maintenance_Mode::instance()->set_maintenance_mode_if_db_old(); |
|
| 330 | - add_action( |
|
| 331 | - 'AHEE__EE_System__perform_activations_upgrades_and_migrations', |
|
| 332 | - array($this, 'initialize_db_if_no_migrations_required') |
|
| 333 | - ); |
|
| 334 | - } |
|
| 335 | - |
|
| 336 | - |
|
| 337 | - /** |
|
| 338 | - * Called when the registered deactivation hook for this addon fires. |
|
| 339 | - * @throws EE_Error |
|
| 340 | - */ |
|
| 341 | - public function deactivation() |
|
| 342 | - { |
|
| 343 | - $classname = get_class($this); |
|
| 344 | - do_action("AHEE__{$classname}__deactivation"); |
|
| 345 | - do_action('AHEE__EE_Addon__deactivation', $this); |
|
| 346 | - //check if the site no longer needs to be in maintenance mode |
|
| 347 | - EE_Register_Addon::deregister($this->name()); |
|
| 348 | - EE_Maintenance_Mode::instance()->set_maintenance_mode_if_db_old(); |
|
| 349 | - } |
|
| 350 | - |
|
| 351 | - |
|
| 352 | - /** |
|
| 353 | - * Takes care of double-checking that we're not in maintenance mode, and then |
|
| 354 | - * initializing this addon's necessary initial data. This is called by default on new activations |
|
| 355 | - * and reactivations. |
|
| 356 | - * |
|
| 357 | - * @param boolean $verify_schema whether to verify the database's schema for this addon, or just its data. |
|
| 358 | - * This is a resource-intensive job so we prefer to only do it when necessary |
|
| 359 | - * @return void |
|
| 360 | - * @throws \EE_Error |
|
| 361 | - */ |
|
| 362 | - public function initialize_db_if_no_migrations_required($verify_schema = true) |
|
| 363 | - { |
|
| 364 | - if ($verify_schema === '') { |
|
| 365 | - //wp core bug imo: if no args are passed to `do_action('some_hook_name')` besides the hook's name |
|
| 366 | - //(ie, no 2nd or 3rd arguments), instead of calling the registered callbacks with no arguments, it |
|
| 367 | - //calls them with an argument of an empty string (ie ""), which evaluates to false |
|
| 368 | - //so we need to treat the empty string as if nothing had been passed, and should instead use the default |
|
| 369 | - $verify_schema = true; |
|
| 370 | - } |
|
| 371 | - if (EE_Maintenance_Mode::instance()->level() !== EE_Maintenance_Mode::level_2_complete_maintenance) { |
|
| 372 | - if ($verify_schema) { |
|
| 373 | - $this->initialize_db(); |
|
| 374 | - } |
|
| 375 | - $this->initialize_default_data(); |
|
| 376 | - //@todo: this will probably need to be adjusted in 4.4 as the array changed formats I believe |
|
| 377 | - EE_Data_Migration_Manager::instance()->update_current_database_state_to( |
|
| 378 | - array( |
|
| 379 | - 'slug' => $this->name(), |
|
| 380 | - 'version' => $this->version(), |
|
| 381 | - ) |
|
| 382 | - ); |
|
| 383 | - /* make sure core's data is a-ok |
|
| 21 | + /** |
|
| 22 | + * prefix to be added onto an addon's plugin slug to make a wp option name |
|
| 23 | + * which will be used to store the plugin's activation history |
|
| 24 | + */ |
|
| 25 | + const ee_addon_version_history_option_prefix = 'ee_version_history_'; |
|
| 26 | + |
|
| 27 | + /** |
|
| 28 | + * @var $_version |
|
| 29 | + * @type string |
|
| 30 | + */ |
|
| 31 | + protected $_version = ''; |
|
| 32 | + |
|
| 33 | + /** |
|
| 34 | + * @var $_min_core_version |
|
| 35 | + * @type string |
|
| 36 | + */ |
|
| 37 | + protected $_min_core_version = ''; |
|
| 38 | + |
|
| 39 | + /** |
|
| 40 | + * derived from plugin 'main_file_path using plugin_basename() |
|
| 41 | + * |
|
| 42 | + * @type string $_plugin_basename |
|
| 43 | + */ |
|
| 44 | + protected $_plugin_basename = ''; |
|
| 45 | + |
|
| 46 | + /** |
|
| 47 | + * A non-internationalized name to identify this addon for use in URLs, etc |
|
| 48 | + * |
|
| 49 | + * @type string $_plugin_slug |
|
| 50 | + */ |
|
| 51 | + protected $_plugin_slug = ''; |
|
| 52 | + |
|
| 53 | + /** |
|
| 54 | + * A non-internationalized name to identify this addon. Eg 'Calendar','MailChimp',etc/ |
|
| 55 | + * |
|
| 56 | + * @type string _addon_name |
|
| 57 | + */ |
|
| 58 | + protected $_addon_name = ''; |
|
| 59 | + |
|
| 60 | + /** |
|
| 61 | + * one of the EE_System::req_type_* constants |
|
| 62 | + * |
|
| 63 | + * @type int $_req_type |
|
| 64 | + */ |
|
| 65 | + protected $_req_type; |
|
| 66 | + |
|
| 67 | + /** |
|
| 68 | + * page slug to be used when generating the "Settings" link on the WP plugin page |
|
| 69 | + * |
|
| 70 | + * @type string $_plugin_action_slug |
|
| 71 | + */ |
|
| 72 | + protected $_plugin_action_slug = ''; |
|
| 73 | + |
|
| 74 | + /** |
|
| 75 | + * if not empty, inserts a new table row after this plugin's row on the WP Plugins page |
|
| 76 | + * that can be used for adding upgrading/marketing info |
|
| 77 | + * |
|
| 78 | + * @type array $_plugins_page_row |
|
| 79 | + */ |
|
| 80 | + protected $_plugins_page_row = array(); |
|
| 81 | + |
|
| 82 | + |
|
| 83 | + |
|
| 84 | + /** |
|
| 85 | + * filepath to the main file, which can be used for register_activation_hook, register_deactivation_hook, etc. |
|
| 86 | + * |
|
| 87 | + * @type string |
|
| 88 | + */ |
|
| 89 | + protected $_main_plugin_file; |
|
| 90 | + |
|
| 91 | + |
|
| 92 | + /** |
|
| 93 | + * @var EE_Dependency_Map $dependency_map |
|
| 94 | + */ |
|
| 95 | + private $dependency_map; |
|
| 96 | + |
|
| 97 | + |
|
| 98 | + /** |
|
| 99 | + * @var DomainInterface $domain |
|
| 100 | + */ |
|
| 101 | + private $domain; |
|
| 102 | + |
|
| 103 | + |
|
| 104 | + /** |
|
| 105 | + * @param DomainInterface $domain |
|
| 106 | + * @param EE_Dependency_Map $dependency_map |
|
| 107 | + */ |
|
| 108 | + public function __construct(EE_Dependency_Map $dependency_map, DomainInterface $domain = null) |
|
| 109 | + { |
|
| 110 | + $this->setDependencyMap($dependency_map); |
|
| 111 | + $this->setDomain($domain); |
|
| 112 | + add_action('AHEE__EE_System__load_controllers__load_admin_controllers', array($this, 'admin_init')); |
|
| 113 | + } |
|
| 114 | + |
|
| 115 | + |
|
| 116 | + /** |
|
| 117 | + * @param EE_Dependency_Map $dependency_map |
|
| 118 | + */ |
|
| 119 | + public function setDependencyMap($dependency_map) |
|
| 120 | + { |
|
| 121 | + $this->dependency_map = $dependency_map; |
|
| 122 | + } |
|
| 123 | + |
|
| 124 | + |
|
| 125 | + /** |
|
| 126 | + * @return EE_Dependency_Map |
|
| 127 | + */ |
|
| 128 | + public function dependencyMap() |
|
| 129 | + { |
|
| 130 | + return $this->dependency_map; |
|
| 131 | + } |
|
| 132 | + |
|
| 133 | + |
|
| 134 | + /** |
|
| 135 | + * @param DomainInterface $domain |
|
| 136 | + */ |
|
| 137 | + public function setDomain(DomainInterface $domain = null) |
|
| 138 | + { |
|
| 139 | + $this->domain = $domain; |
|
| 140 | + } |
|
| 141 | + |
|
| 142 | + /** |
|
| 143 | + * @return DomainInterface |
|
| 144 | + */ |
|
| 145 | + public function domain() |
|
| 146 | + { |
|
| 147 | + return $this->domain; |
|
| 148 | + } |
|
| 149 | + |
|
| 150 | + |
|
| 151 | + /** |
|
| 152 | + * @param mixed $version |
|
| 153 | + */ |
|
| 154 | + public function set_version($version = null) |
|
| 155 | + { |
|
| 156 | + $this->_version = $version; |
|
| 157 | + } |
|
| 158 | + |
|
| 159 | + |
|
| 160 | + /** |
|
| 161 | + * get__version |
|
| 162 | + * |
|
| 163 | + * @return string |
|
| 164 | + */ |
|
| 165 | + public function version() |
|
| 166 | + { |
|
| 167 | + return $this->_version; |
|
| 168 | + } |
|
| 169 | + |
|
| 170 | + |
|
| 171 | + /** |
|
| 172 | + * @param mixed $min_core_version |
|
| 173 | + */ |
|
| 174 | + public function set_min_core_version($min_core_version = null) |
|
| 175 | + { |
|
| 176 | + $this->_min_core_version = $min_core_version; |
|
| 177 | + } |
|
| 178 | + |
|
| 179 | + |
|
| 180 | + /** |
|
| 181 | + * get__min_core_version |
|
| 182 | + * |
|
| 183 | + * @return string |
|
| 184 | + */ |
|
| 185 | + public function min_core_version() |
|
| 186 | + { |
|
| 187 | + return $this->_min_core_version; |
|
| 188 | + } |
|
| 189 | + |
|
| 190 | + |
|
| 191 | + /** |
|
| 192 | + * Sets addon_name |
|
| 193 | + * |
|
| 194 | + * @param string $addon_name |
|
| 195 | + * @return boolean |
|
| 196 | + */ |
|
| 197 | + public function set_name($addon_name) |
|
| 198 | + { |
|
| 199 | + return $this->_addon_name = $addon_name; |
|
| 200 | + } |
|
| 201 | + |
|
| 202 | + |
|
| 203 | + /** |
|
| 204 | + * Gets addon_name |
|
| 205 | + * |
|
| 206 | + * @return string |
|
| 207 | + */ |
|
| 208 | + public function name() |
|
| 209 | + { |
|
| 210 | + return $this->_addon_name; |
|
| 211 | + } |
|
| 212 | + |
|
| 213 | + |
|
| 214 | + /** |
|
| 215 | + * @return string |
|
| 216 | + */ |
|
| 217 | + public function plugin_basename() |
|
| 218 | + { |
|
| 219 | + |
|
| 220 | + return $this->_plugin_basename; |
|
| 221 | + } |
|
| 222 | + |
|
| 223 | + |
|
| 224 | + /** |
|
| 225 | + * @param string $plugin_basename |
|
| 226 | + */ |
|
| 227 | + public function set_plugin_basename($plugin_basename) |
|
| 228 | + { |
|
| 229 | + |
|
| 230 | + $this->_plugin_basename = $plugin_basename; |
|
| 231 | + } |
|
| 232 | + |
|
| 233 | + |
|
| 234 | + /** |
|
| 235 | + * @return string |
|
| 236 | + */ |
|
| 237 | + public function plugin_slug() |
|
| 238 | + { |
|
| 239 | + |
|
| 240 | + return $this->_plugin_slug; |
|
| 241 | + } |
|
| 242 | + |
|
| 243 | + |
|
| 244 | + /** |
|
| 245 | + * @param string $plugin_slug |
|
| 246 | + */ |
|
| 247 | + public function set_plugin_slug($plugin_slug) |
|
| 248 | + { |
|
| 249 | + |
|
| 250 | + $this->_plugin_slug = $plugin_slug; |
|
| 251 | + } |
|
| 252 | + |
|
| 253 | + |
|
| 254 | + /** |
|
| 255 | + * @return string |
|
| 256 | + */ |
|
| 257 | + public function plugin_action_slug() |
|
| 258 | + { |
|
| 259 | + |
|
| 260 | + return $this->_plugin_action_slug; |
|
| 261 | + } |
|
| 262 | + |
|
| 263 | + |
|
| 264 | + /** |
|
| 265 | + * @param string $plugin_action_slug |
|
| 266 | + */ |
|
| 267 | + public function set_plugin_action_slug($plugin_action_slug) |
|
| 268 | + { |
|
| 269 | + |
|
| 270 | + $this->_plugin_action_slug = $plugin_action_slug; |
|
| 271 | + } |
|
| 272 | + |
|
| 273 | + |
|
| 274 | + /** |
|
| 275 | + * @return array |
|
| 276 | + */ |
|
| 277 | + public function get_plugins_page_row() |
|
| 278 | + { |
|
| 279 | + |
|
| 280 | + return $this->_plugins_page_row; |
|
| 281 | + } |
|
| 282 | + |
|
| 283 | + |
|
| 284 | + /** |
|
| 285 | + * @param array $plugins_page_row |
|
| 286 | + */ |
|
| 287 | + public function set_plugins_page_row($plugins_page_row = array()) |
|
| 288 | + { |
|
| 289 | + // sigh.... check for example content that I stupidly merged to master and remove it if found |
|
| 290 | + if (! is_array($plugins_page_row) |
|
| 291 | + && strpos($plugins_page_row, '<h3>Promotions Addon Upsell Info</h3>') !== false |
|
| 292 | + ) { |
|
| 293 | + $plugins_page_row = array(); |
|
| 294 | + } |
|
| 295 | + $this->_plugins_page_row = (array) $plugins_page_row; |
|
| 296 | + } |
|
| 297 | + |
|
| 298 | + |
|
| 299 | + /** |
|
| 300 | + * Called when EE core detects this addon has been activated for the first time. |
|
| 301 | + * If the site isn't in maintenance mode, should setup the addon's database |
|
| 302 | + * |
|
| 303 | + * @return void |
|
| 304 | + */ |
|
| 305 | + public function new_install() |
|
| 306 | + { |
|
| 307 | + $classname = get_class($this); |
|
| 308 | + do_action("AHEE__{$classname}__new_install"); |
|
| 309 | + do_action('AHEE__EE_Addon__new_install', $this); |
|
| 310 | + EE_Maintenance_Mode::instance()->set_maintenance_mode_if_db_old(); |
|
| 311 | + add_action( |
|
| 312 | + 'AHEE__EE_System__perform_activations_upgrades_and_migrations', |
|
| 313 | + array($this, 'initialize_db_if_no_migrations_required') |
|
| 314 | + ); |
|
| 315 | + } |
|
| 316 | + |
|
| 317 | + |
|
| 318 | + /** |
|
| 319 | + * Called when EE core detects this addon has been reactivated. When this happens, |
|
| 320 | + * it's good to just check that your data is still intact |
|
| 321 | + * |
|
| 322 | + * @return void |
|
| 323 | + */ |
|
| 324 | + public function reactivation() |
|
| 325 | + { |
|
| 326 | + $classname = get_class($this); |
|
| 327 | + do_action("AHEE__{$classname}__reactivation"); |
|
| 328 | + do_action('AHEE__EE_Addon__reactivation', $this); |
|
| 329 | + EE_Maintenance_Mode::instance()->set_maintenance_mode_if_db_old(); |
|
| 330 | + add_action( |
|
| 331 | + 'AHEE__EE_System__perform_activations_upgrades_and_migrations', |
|
| 332 | + array($this, 'initialize_db_if_no_migrations_required') |
|
| 333 | + ); |
|
| 334 | + } |
|
| 335 | + |
|
| 336 | + |
|
| 337 | + /** |
|
| 338 | + * Called when the registered deactivation hook for this addon fires. |
|
| 339 | + * @throws EE_Error |
|
| 340 | + */ |
|
| 341 | + public function deactivation() |
|
| 342 | + { |
|
| 343 | + $classname = get_class($this); |
|
| 344 | + do_action("AHEE__{$classname}__deactivation"); |
|
| 345 | + do_action('AHEE__EE_Addon__deactivation', $this); |
|
| 346 | + //check if the site no longer needs to be in maintenance mode |
|
| 347 | + EE_Register_Addon::deregister($this->name()); |
|
| 348 | + EE_Maintenance_Mode::instance()->set_maintenance_mode_if_db_old(); |
|
| 349 | + } |
|
| 350 | + |
|
| 351 | + |
|
| 352 | + /** |
|
| 353 | + * Takes care of double-checking that we're not in maintenance mode, and then |
|
| 354 | + * initializing this addon's necessary initial data. This is called by default on new activations |
|
| 355 | + * and reactivations. |
|
| 356 | + * |
|
| 357 | + * @param boolean $verify_schema whether to verify the database's schema for this addon, or just its data. |
|
| 358 | + * This is a resource-intensive job so we prefer to only do it when necessary |
|
| 359 | + * @return void |
|
| 360 | + * @throws \EE_Error |
|
| 361 | + */ |
|
| 362 | + public function initialize_db_if_no_migrations_required($verify_schema = true) |
|
| 363 | + { |
|
| 364 | + if ($verify_schema === '') { |
|
| 365 | + //wp core bug imo: if no args are passed to `do_action('some_hook_name')` besides the hook's name |
|
| 366 | + //(ie, no 2nd or 3rd arguments), instead of calling the registered callbacks with no arguments, it |
|
| 367 | + //calls them with an argument of an empty string (ie ""), which evaluates to false |
|
| 368 | + //so we need to treat the empty string as if nothing had been passed, and should instead use the default |
|
| 369 | + $verify_schema = true; |
|
| 370 | + } |
|
| 371 | + if (EE_Maintenance_Mode::instance()->level() !== EE_Maintenance_Mode::level_2_complete_maintenance) { |
|
| 372 | + if ($verify_schema) { |
|
| 373 | + $this->initialize_db(); |
|
| 374 | + } |
|
| 375 | + $this->initialize_default_data(); |
|
| 376 | + //@todo: this will probably need to be adjusted in 4.4 as the array changed formats I believe |
|
| 377 | + EE_Data_Migration_Manager::instance()->update_current_database_state_to( |
|
| 378 | + array( |
|
| 379 | + 'slug' => $this->name(), |
|
| 380 | + 'version' => $this->version(), |
|
| 381 | + ) |
|
| 382 | + ); |
|
| 383 | + /* make sure core's data is a-ok |
|
| 384 | 384 | * (at the time of writing, we especially want to verify all the caps are present |
| 385 | 385 | * because payment method type capabilities are added dynamically, and it's |
| 386 | 386 | * possible this addon added a payment method. But it's also possible |
| 387 | 387 | * other data needs to be verified) |
| 388 | 388 | */ |
| 389 | - EEH_Activation::initialize_db_content(); |
|
| 390 | - update_option('ee_flush_rewrite_rules', true); |
|
| 391 | - //in case there are lots of addons being activated at once, let's force garbage collection |
|
| 392 | - //to help avoid memory limit errors |
|
| 393 | - //EEH_Debug_Tools::instance()->measure_memory( 'db content initialized for ' . get_class( $this), true ); |
|
| 394 | - gc_collect_cycles(); |
|
| 395 | - } else { |
|
| 396 | - //ask the data migration manager to init this addon's data |
|
| 397 | - //when migrations are finished because we can't do it now |
|
| 398 | - EE_Data_Migration_Manager::instance()->enqueue_db_initialization_for($this->name()); |
|
| 399 | - } |
|
| 400 | - } |
|
| 401 | - |
|
| 402 | - |
|
| 403 | - /** |
|
| 404 | - * Used to setup this addon's database tables, but not necessarily any default |
|
| 405 | - * data in them. The default is to actually use the most up-to-date data migration script |
|
| 406 | - * for this addon, and just use its schema_changes_before_migration() and schema_changes_after_migration() |
|
| 407 | - * methods to setup the db. |
|
| 408 | - */ |
|
| 409 | - public function initialize_db() |
|
| 410 | - { |
|
| 411 | - //find the migration script that sets the database to be compatible with the code |
|
| 412 | - $current_dms_name = EE_Data_Migration_Manager::instance()->get_most_up_to_date_dms($this->name()); |
|
| 413 | - if ($current_dms_name) { |
|
| 414 | - $current_data_migration_script = EE_Registry::instance()->load_dms($current_dms_name); |
|
| 415 | - $current_data_migration_script->set_migrating(false); |
|
| 416 | - $current_data_migration_script->schema_changes_before_migration(); |
|
| 417 | - $current_data_migration_script->schema_changes_after_migration(); |
|
| 418 | - if ($current_data_migration_script->get_errors()) { |
|
| 419 | - foreach ($current_data_migration_script->get_errors() as $error) { |
|
| 420 | - EE_Error::add_error($error, __FILE__, __FUNCTION__, __LINE__); |
|
| 421 | - } |
|
| 422 | - } |
|
| 423 | - } |
|
| 424 | - //if not DMS was found that should be ok. This addon just doesn't require any database changes |
|
| 425 | - EE_Data_Migration_Manager::instance()->update_current_database_state_to( |
|
| 426 | - array( |
|
| 427 | - 'slug' => $this->name(), |
|
| 428 | - 'version' => $this->version(), |
|
| 429 | - ) |
|
| 430 | - ); |
|
| 431 | - } |
|
| 432 | - |
|
| 433 | - |
|
| 434 | - /** |
|
| 435 | - * If you want to setup default data for the addon, override this method, and call |
|
| 436 | - * parent::initialize_default_data() from within it. This is normally called |
|
| 437 | - * from EE_Addon::initialize_db_if_no_migrations_required(), just after EE_Addon::initialize_db() |
|
| 438 | - * and should verify default data is present (but this is also called |
|
| 439 | - * on reactivations and just after migrations, so please verify you actually want |
|
| 440 | - * to ADD default data, because it may already be present). |
|
| 441 | - * However, please call this parent (currently it just fires a hook which other |
|
| 442 | - * addons may be depending on) |
|
| 443 | - */ |
|
| 444 | - public function initialize_default_data() |
|
| 445 | - { |
|
| 446 | - /** |
|
| 447 | - * Called when an addon is ensuring its default data is set (possibly called |
|
| 448 | - * on a reactivation, so first check for the absence of other data before setting |
|
| 449 | - * default data) |
|
| 450 | - * |
|
| 451 | - * @param EE_Addon $addon the addon that called this |
|
| 452 | - */ |
|
| 453 | - do_action('AHEE__EE_Addon__initialize_default_data__begin', $this); |
|
| 454 | - //override to insert default data. It is safe to use the models here |
|
| 455 | - //because the site should not be in maintenance mode |
|
| 456 | - } |
|
| 457 | - |
|
| 458 | - |
|
| 459 | - /** |
|
| 460 | - * EE Core detected that this addon has been upgraded. We should check if there |
|
| 461 | - * are any new migration scripts, and if so put the site into maintenance mode until |
|
| 462 | - * they're ran |
|
| 463 | - * |
|
| 464 | - * @return void |
|
| 465 | - */ |
|
| 466 | - public function upgrade() |
|
| 467 | - { |
|
| 468 | - $classname = get_class($this); |
|
| 469 | - do_action("AHEE__{$classname}__upgrade"); |
|
| 470 | - do_action('AHEE__EE_Addon__upgrade', $this); |
|
| 471 | - EE_Maintenance_Mode::instance()->set_maintenance_mode_if_db_old(); |
|
| 472 | - //also it's possible there is new default data that needs to be added |
|
| 473 | - add_action( |
|
| 474 | - 'AHEE__EE_System__perform_activations_upgrades_and_migrations', |
|
| 475 | - array($this, 'initialize_db_if_no_migrations_required') |
|
| 476 | - ); |
|
| 477 | - } |
|
| 478 | - |
|
| 479 | - |
|
| 480 | - /** |
|
| 481 | - * If Core detects this addon has been downgraded, you may want to invoke some special logic here. |
|
| 482 | - */ |
|
| 483 | - public function downgrade() |
|
| 484 | - { |
|
| 485 | - $classname = get_class($this); |
|
| 486 | - do_action("AHEE__{$classname}__downgrade"); |
|
| 487 | - do_action('AHEE__EE_Addon__downgrade', $this); |
|
| 488 | - //it's possible there's old default data that needs to be double-checked |
|
| 489 | - add_action( |
|
| 490 | - 'AHEE__EE_System__perform_activations_upgrades_and_migrations', |
|
| 491 | - array($this, 'initialize_db_if_no_migrations_required') |
|
| 492 | - ); |
|
| 493 | - } |
|
| 494 | - |
|
| 495 | - |
|
| 496 | - /** |
|
| 497 | - * set_db_update_option_name |
|
| 498 | - * Until we do something better, we'll just check for migration scripts upon |
|
| 499 | - * plugin activation only. In the future, we'll want to do it on plugin updates too |
|
| 500 | - * |
|
| 501 | - * @return bool |
|
| 502 | - */ |
|
| 503 | - public function set_db_update_option_name() |
|
| 504 | - { |
|
| 505 | - EE_Error::doing_it_wrong( |
|
| 506 | - __FUNCTION__, |
|
| 507 | - esc_html__( |
|
| 508 | - 'EE_Addon::set_db_update_option_name was renamed to EE_Addon::set_activation_indicator_option', |
|
| 509 | - 'event_espresso' |
|
| 510 | - ), |
|
| 511 | - '4.3.0.alpha.016' |
|
| 512 | - ); |
|
| 513 | - //let's just handle this on the next request, ok? right now we're just not really ready |
|
| 514 | - return $this->set_activation_indicator_option(); |
|
| 515 | - } |
|
| 516 | - |
|
| 517 | - |
|
| 518 | - /** |
|
| 519 | - * Returns the name of the activation indicator option |
|
| 520 | - * (an option which is set temporarily to indicate that this addon was just activated) |
|
| 521 | - * |
|
| 522 | - * @deprecated since version 4.3.0.alpha.016 |
|
| 523 | - * @return string |
|
| 524 | - */ |
|
| 525 | - public function get_db_update_option_name() |
|
| 526 | - { |
|
| 527 | - EE_Error::doing_it_wrong( |
|
| 528 | - __FUNCTION__, |
|
| 529 | - esc_html__( |
|
| 530 | - 'EE_Addon::get_db_update_option was renamed to EE_Addon::get_activation_indicator_option_name', |
|
| 531 | - 'event_espresso' |
|
| 532 | - ), |
|
| 533 | - '4.3.0.alpha.016' |
|
| 534 | - ); |
|
| 535 | - return $this->get_activation_indicator_option_name(); |
|
| 536 | - } |
|
| 537 | - |
|
| 538 | - |
|
| 539 | - /** |
|
| 540 | - * When the addon is activated, this should be called to set a wordpress option that |
|
| 541 | - * indicates it was activated. This is especially useful for detecting reactivations. |
|
| 542 | - * |
|
| 543 | - * @return bool |
|
| 544 | - */ |
|
| 545 | - public function set_activation_indicator_option() |
|
| 546 | - { |
|
| 547 | - // let's just handle this on the next request, ok? right now we're just not really ready |
|
| 548 | - return update_option($this->get_activation_indicator_option_name(), true); |
|
| 549 | - } |
|
| 550 | - |
|
| 551 | - |
|
| 552 | - /** |
|
| 553 | - * Gets the name of the wp option which is used to temporarily indicate that this addon was activated |
|
| 554 | - * |
|
| 555 | - * @return string |
|
| 556 | - */ |
|
| 557 | - public function get_activation_indicator_option_name() |
|
| 558 | - { |
|
| 559 | - return 'ee_activation_' . $this->name(); |
|
| 560 | - } |
|
| 561 | - |
|
| 562 | - |
|
| 563 | - /** |
|
| 564 | - * Used by EE_System to set the request type of this addon. Should not be used by addon developers |
|
| 565 | - * |
|
| 566 | - * @param int $req_type |
|
| 567 | - */ |
|
| 568 | - public function set_req_type($req_type) |
|
| 569 | - { |
|
| 570 | - $this->_req_type = $req_type; |
|
| 571 | - } |
|
| 572 | - |
|
| 573 | - |
|
| 574 | - /** |
|
| 575 | - * Returns the request type of this addon (ie, EE_System::req_type_normal, EE_System::req_type_new_activation, |
|
| 576 | - * EE_System::req_type_reactivation, EE_System::req_type_upgrade, or EE_System::req_type_downgrade). This is set by |
|
| 577 | - * EE_System when it is checking for new install or upgrades of addons |
|
| 578 | - */ |
|
| 579 | - public function detect_req_type() |
|
| 580 | - { |
|
| 581 | - if (! $this->_req_type) { |
|
| 582 | - $this->detect_activation_or_upgrade(); |
|
| 583 | - } |
|
| 584 | - return $this->_req_type; |
|
| 585 | - } |
|
| 586 | - |
|
| 587 | - |
|
| 588 | - /** |
|
| 589 | - * Detects the request type for this addon (whether it was just activated, upgrades, a normal request, etc.) |
|
| 590 | - * Should only be called once per request |
|
| 591 | - * |
|
| 592 | - * @return void |
|
| 593 | - */ |
|
| 594 | - public function detect_activation_or_upgrade() |
|
| 595 | - { |
|
| 596 | - $activation_history_for_addon = $this->get_activation_history(); |
|
| 389 | + EEH_Activation::initialize_db_content(); |
|
| 390 | + update_option('ee_flush_rewrite_rules', true); |
|
| 391 | + //in case there are lots of addons being activated at once, let's force garbage collection |
|
| 392 | + //to help avoid memory limit errors |
|
| 393 | + //EEH_Debug_Tools::instance()->measure_memory( 'db content initialized for ' . get_class( $this), true ); |
|
| 394 | + gc_collect_cycles(); |
|
| 395 | + } else { |
|
| 396 | + //ask the data migration manager to init this addon's data |
|
| 397 | + //when migrations are finished because we can't do it now |
|
| 398 | + EE_Data_Migration_Manager::instance()->enqueue_db_initialization_for($this->name()); |
|
| 399 | + } |
|
| 400 | + } |
|
| 401 | + |
|
| 402 | + |
|
| 403 | + /** |
|
| 404 | + * Used to setup this addon's database tables, but not necessarily any default |
|
| 405 | + * data in them. The default is to actually use the most up-to-date data migration script |
|
| 406 | + * for this addon, and just use its schema_changes_before_migration() and schema_changes_after_migration() |
|
| 407 | + * methods to setup the db. |
|
| 408 | + */ |
|
| 409 | + public function initialize_db() |
|
| 410 | + { |
|
| 411 | + //find the migration script that sets the database to be compatible with the code |
|
| 412 | + $current_dms_name = EE_Data_Migration_Manager::instance()->get_most_up_to_date_dms($this->name()); |
|
| 413 | + if ($current_dms_name) { |
|
| 414 | + $current_data_migration_script = EE_Registry::instance()->load_dms($current_dms_name); |
|
| 415 | + $current_data_migration_script->set_migrating(false); |
|
| 416 | + $current_data_migration_script->schema_changes_before_migration(); |
|
| 417 | + $current_data_migration_script->schema_changes_after_migration(); |
|
| 418 | + if ($current_data_migration_script->get_errors()) { |
|
| 419 | + foreach ($current_data_migration_script->get_errors() as $error) { |
|
| 420 | + EE_Error::add_error($error, __FILE__, __FUNCTION__, __LINE__); |
|
| 421 | + } |
|
| 422 | + } |
|
| 423 | + } |
|
| 424 | + //if not DMS was found that should be ok. This addon just doesn't require any database changes |
|
| 425 | + EE_Data_Migration_Manager::instance()->update_current_database_state_to( |
|
| 426 | + array( |
|
| 427 | + 'slug' => $this->name(), |
|
| 428 | + 'version' => $this->version(), |
|
| 429 | + ) |
|
| 430 | + ); |
|
| 431 | + } |
|
| 432 | + |
|
| 433 | + |
|
| 434 | + /** |
|
| 435 | + * If you want to setup default data for the addon, override this method, and call |
|
| 436 | + * parent::initialize_default_data() from within it. This is normally called |
|
| 437 | + * from EE_Addon::initialize_db_if_no_migrations_required(), just after EE_Addon::initialize_db() |
|
| 438 | + * and should verify default data is present (but this is also called |
|
| 439 | + * on reactivations and just after migrations, so please verify you actually want |
|
| 440 | + * to ADD default data, because it may already be present). |
|
| 441 | + * However, please call this parent (currently it just fires a hook which other |
|
| 442 | + * addons may be depending on) |
|
| 443 | + */ |
|
| 444 | + public function initialize_default_data() |
|
| 445 | + { |
|
| 446 | + /** |
|
| 447 | + * Called when an addon is ensuring its default data is set (possibly called |
|
| 448 | + * on a reactivation, so first check for the absence of other data before setting |
|
| 449 | + * default data) |
|
| 450 | + * |
|
| 451 | + * @param EE_Addon $addon the addon that called this |
|
| 452 | + */ |
|
| 453 | + do_action('AHEE__EE_Addon__initialize_default_data__begin', $this); |
|
| 454 | + //override to insert default data. It is safe to use the models here |
|
| 455 | + //because the site should not be in maintenance mode |
|
| 456 | + } |
|
| 457 | + |
|
| 458 | + |
|
| 459 | + /** |
|
| 460 | + * EE Core detected that this addon has been upgraded. We should check if there |
|
| 461 | + * are any new migration scripts, and if so put the site into maintenance mode until |
|
| 462 | + * they're ran |
|
| 463 | + * |
|
| 464 | + * @return void |
|
| 465 | + */ |
|
| 466 | + public function upgrade() |
|
| 467 | + { |
|
| 468 | + $classname = get_class($this); |
|
| 469 | + do_action("AHEE__{$classname}__upgrade"); |
|
| 470 | + do_action('AHEE__EE_Addon__upgrade', $this); |
|
| 471 | + EE_Maintenance_Mode::instance()->set_maintenance_mode_if_db_old(); |
|
| 472 | + //also it's possible there is new default data that needs to be added |
|
| 473 | + add_action( |
|
| 474 | + 'AHEE__EE_System__perform_activations_upgrades_and_migrations', |
|
| 475 | + array($this, 'initialize_db_if_no_migrations_required') |
|
| 476 | + ); |
|
| 477 | + } |
|
| 478 | + |
|
| 479 | + |
|
| 480 | + /** |
|
| 481 | + * If Core detects this addon has been downgraded, you may want to invoke some special logic here. |
|
| 482 | + */ |
|
| 483 | + public function downgrade() |
|
| 484 | + { |
|
| 485 | + $classname = get_class($this); |
|
| 486 | + do_action("AHEE__{$classname}__downgrade"); |
|
| 487 | + do_action('AHEE__EE_Addon__downgrade', $this); |
|
| 488 | + //it's possible there's old default data that needs to be double-checked |
|
| 489 | + add_action( |
|
| 490 | + 'AHEE__EE_System__perform_activations_upgrades_and_migrations', |
|
| 491 | + array($this, 'initialize_db_if_no_migrations_required') |
|
| 492 | + ); |
|
| 493 | + } |
|
| 494 | + |
|
| 495 | + |
|
| 496 | + /** |
|
| 497 | + * set_db_update_option_name |
|
| 498 | + * Until we do something better, we'll just check for migration scripts upon |
|
| 499 | + * plugin activation only. In the future, we'll want to do it on plugin updates too |
|
| 500 | + * |
|
| 501 | + * @return bool |
|
| 502 | + */ |
|
| 503 | + public function set_db_update_option_name() |
|
| 504 | + { |
|
| 505 | + EE_Error::doing_it_wrong( |
|
| 506 | + __FUNCTION__, |
|
| 507 | + esc_html__( |
|
| 508 | + 'EE_Addon::set_db_update_option_name was renamed to EE_Addon::set_activation_indicator_option', |
|
| 509 | + 'event_espresso' |
|
| 510 | + ), |
|
| 511 | + '4.3.0.alpha.016' |
|
| 512 | + ); |
|
| 513 | + //let's just handle this on the next request, ok? right now we're just not really ready |
|
| 514 | + return $this->set_activation_indicator_option(); |
|
| 515 | + } |
|
| 516 | + |
|
| 517 | + |
|
| 518 | + /** |
|
| 519 | + * Returns the name of the activation indicator option |
|
| 520 | + * (an option which is set temporarily to indicate that this addon was just activated) |
|
| 521 | + * |
|
| 522 | + * @deprecated since version 4.3.0.alpha.016 |
|
| 523 | + * @return string |
|
| 524 | + */ |
|
| 525 | + public function get_db_update_option_name() |
|
| 526 | + { |
|
| 527 | + EE_Error::doing_it_wrong( |
|
| 528 | + __FUNCTION__, |
|
| 529 | + esc_html__( |
|
| 530 | + 'EE_Addon::get_db_update_option was renamed to EE_Addon::get_activation_indicator_option_name', |
|
| 531 | + 'event_espresso' |
|
| 532 | + ), |
|
| 533 | + '4.3.0.alpha.016' |
|
| 534 | + ); |
|
| 535 | + return $this->get_activation_indicator_option_name(); |
|
| 536 | + } |
|
| 537 | + |
|
| 538 | + |
|
| 539 | + /** |
|
| 540 | + * When the addon is activated, this should be called to set a wordpress option that |
|
| 541 | + * indicates it was activated. This is especially useful for detecting reactivations. |
|
| 542 | + * |
|
| 543 | + * @return bool |
|
| 544 | + */ |
|
| 545 | + public function set_activation_indicator_option() |
|
| 546 | + { |
|
| 547 | + // let's just handle this on the next request, ok? right now we're just not really ready |
|
| 548 | + return update_option($this->get_activation_indicator_option_name(), true); |
|
| 549 | + } |
|
| 550 | + |
|
| 551 | + |
|
| 552 | + /** |
|
| 553 | + * Gets the name of the wp option which is used to temporarily indicate that this addon was activated |
|
| 554 | + * |
|
| 555 | + * @return string |
|
| 556 | + */ |
|
| 557 | + public function get_activation_indicator_option_name() |
|
| 558 | + { |
|
| 559 | + return 'ee_activation_' . $this->name(); |
|
| 560 | + } |
|
| 561 | + |
|
| 562 | + |
|
| 563 | + /** |
|
| 564 | + * Used by EE_System to set the request type of this addon. Should not be used by addon developers |
|
| 565 | + * |
|
| 566 | + * @param int $req_type |
|
| 567 | + */ |
|
| 568 | + public function set_req_type($req_type) |
|
| 569 | + { |
|
| 570 | + $this->_req_type = $req_type; |
|
| 571 | + } |
|
| 572 | + |
|
| 573 | + |
|
| 574 | + /** |
|
| 575 | + * Returns the request type of this addon (ie, EE_System::req_type_normal, EE_System::req_type_new_activation, |
|
| 576 | + * EE_System::req_type_reactivation, EE_System::req_type_upgrade, or EE_System::req_type_downgrade). This is set by |
|
| 577 | + * EE_System when it is checking for new install or upgrades of addons |
|
| 578 | + */ |
|
| 579 | + public function detect_req_type() |
|
| 580 | + { |
|
| 581 | + if (! $this->_req_type) { |
|
| 582 | + $this->detect_activation_or_upgrade(); |
|
| 583 | + } |
|
| 584 | + return $this->_req_type; |
|
| 585 | + } |
|
| 586 | + |
|
| 587 | + |
|
| 588 | + /** |
|
| 589 | + * Detects the request type for this addon (whether it was just activated, upgrades, a normal request, etc.) |
|
| 590 | + * Should only be called once per request |
|
| 591 | + * |
|
| 592 | + * @return void |
|
| 593 | + */ |
|
| 594 | + public function detect_activation_or_upgrade() |
|
| 595 | + { |
|
| 596 | + $activation_history_for_addon = $this->get_activation_history(); |
|
| 597 | 597 | // d($activation_history_for_addon); |
| 598 | - $request_type = EE_System::detect_req_type_given_activation_history( |
|
| 599 | - $activation_history_for_addon, |
|
| 600 | - $this->get_activation_indicator_option_name(), |
|
| 601 | - $this->version() |
|
| 602 | - ); |
|
| 603 | - $this->set_req_type($request_type); |
|
| 604 | - $classname = get_class($this); |
|
| 605 | - switch ($request_type) { |
|
| 606 | - case EE_System::req_type_new_activation: |
|
| 607 | - do_action("AHEE__{$classname}__detect_activations_or_upgrades__new_activation"); |
|
| 608 | - do_action('AHEE__EE_Addon__detect_activations_or_upgrades__new_activation', $this); |
|
| 609 | - $this->new_install(); |
|
| 610 | - $this->update_list_of_installed_versions($activation_history_for_addon); |
|
| 611 | - break; |
|
| 612 | - case EE_System::req_type_reactivation: |
|
| 613 | - do_action("AHEE__{$classname}__detect_activations_or_upgrades__reactivation"); |
|
| 614 | - do_action('AHEE__EE_Addon__detect_activations_or_upgrades__reactivation', $this); |
|
| 615 | - $this->reactivation(); |
|
| 616 | - $this->update_list_of_installed_versions($activation_history_for_addon); |
|
| 617 | - break; |
|
| 618 | - case EE_System::req_type_upgrade: |
|
| 619 | - do_action("AHEE__{$classname}__detect_activations_or_upgrades__upgrade"); |
|
| 620 | - do_action('AHEE__EE_Addon__detect_activations_or_upgrades__upgrade', $this); |
|
| 621 | - $this->upgrade(); |
|
| 622 | - $this->update_list_of_installed_versions($activation_history_for_addon); |
|
| 623 | - break; |
|
| 624 | - case EE_System::req_type_downgrade: |
|
| 625 | - do_action("AHEE__{$classname}__detect_activations_or_upgrades__downgrade"); |
|
| 626 | - do_action('AHEE__EE_Addon__detect_activations_or_upgrades__downgrade', $this); |
|
| 627 | - $this->downgrade(); |
|
| 628 | - $this->update_list_of_installed_versions($activation_history_for_addon); |
|
| 629 | - break; |
|
| 630 | - case EE_System::req_type_normal: |
|
| 631 | - default: |
|
| 598 | + $request_type = EE_System::detect_req_type_given_activation_history( |
|
| 599 | + $activation_history_for_addon, |
|
| 600 | + $this->get_activation_indicator_option_name(), |
|
| 601 | + $this->version() |
|
| 602 | + ); |
|
| 603 | + $this->set_req_type($request_type); |
|
| 604 | + $classname = get_class($this); |
|
| 605 | + switch ($request_type) { |
|
| 606 | + case EE_System::req_type_new_activation: |
|
| 607 | + do_action("AHEE__{$classname}__detect_activations_or_upgrades__new_activation"); |
|
| 608 | + do_action('AHEE__EE_Addon__detect_activations_or_upgrades__new_activation', $this); |
|
| 609 | + $this->new_install(); |
|
| 610 | + $this->update_list_of_installed_versions($activation_history_for_addon); |
|
| 611 | + break; |
|
| 612 | + case EE_System::req_type_reactivation: |
|
| 613 | + do_action("AHEE__{$classname}__detect_activations_or_upgrades__reactivation"); |
|
| 614 | + do_action('AHEE__EE_Addon__detect_activations_or_upgrades__reactivation', $this); |
|
| 615 | + $this->reactivation(); |
|
| 616 | + $this->update_list_of_installed_versions($activation_history_for_addon); |
|
| 617 | + break; |
|
| 618 | + case EE_System::req_type_upgrade: |
|
| 619 | + do_action("AHEE__{$classname}__detect_activations_or_upgrades__upgrade"); |
|
| 620 | + do_action('AHEE__EE_Addon__detect_activations_or_upgrades__upgrade', $this); |
|
| 621 | + $this->upgrade(); |
|
| 622 | + $this->update_list_of_installed_versions($activation_history_for_addon); |
|
| 623 | + break; |
|
| 624 | + case EE_System::req_type_downgrade: |
|
| 625 | + do_action("AHEE__{$classname}__detect_activations_or_upgrades__downgrade"); |
|
| 626 | + do_action('AHEE__EE_Addon__detect_activations_or_upgrades__downgrade', $this); |
|
| 627 | + $this->downgrade(); |
|
| 628 | + $this->update_list_of_installed_versions($activation_history_for_addon); |
|
| 629 | + break; |
|
| 630 | + case EE_System::req_type_normal: |
|
| 631 | + default: |
|
| 632 | 632 | // $this->_maybe_redirect_to_ee_about(); |
| 633 | - break; |
|
| 634 | - } |
|
| 635 | - |
|
| 636 | - do_action("AHEE__{$classname}__detect_if_activation_or_upgrade__complete"); |
|
| 637 | - } |
|
| 638 | - |
|
| 639 | - /** |
|
| 640 | - * Updates the version history for this addon |
|
| 641 | - * |
|
| 642 | - * @param array $version_history |
|
| 643 | - * @param string $current_version_to_add |
|
| 644 | - * @return boolean success |
|
| 645 | - */ |
|
| 646 | - public function update_list_of_installed_versions($version_history = null, $current_version_to_add = null) |
|
| 647 | - { |
|
| 648 | - if (! $version_history) { |
|
| 649 | - $version_history = $this->get_activation_history(); |
|
| 650 | - } |
|
| 651 | - if ($current_version_to_add === null) { |
|
| 652 | - $current_version_to_add = $this->version(); |
|
| 653 | - } |
|
| 654 | - $version_history[$current_version_to_add][] = date('Y-m-d H:i:s', time()); |
|
| 655 | - // resave |
|
| 633 | + break; |
|
| 634 | + } |
|
| 635 | + |
|
| 636 | + do_action("AHEE__{$classname}__detect_if_activation_or_upgrade__complete"); |
|
| 637 | + } |
|
| 638 | + |
|
| 639 | + /** |
|
| 640 | + * Updates the version history for this addon |
|
| 641 | + * |
|
| 642 | + * @param array $version_history |
|
| 643 | + * @param string $current_version_to_add |
|
| 644 | + * @return boolean success |
|
| 645 | + */ |
|
| 646 | + public function update_list_of_installed_versions($version_history = null, $current_version_to_add = null) |
|
| 647 | + { |
|
| 648 | + if (! $version_history) { |
|
| 649 | + $version_history = $this->get_activation_history(); |
|
| 650 | + } |
|
| 651 | + if ($current_version_to_add === null) { |
|
| 652 | + $current_version_to_add = $this->version(); |
|
| 653 | + } |
|
| 654 | + $version_history[$current_version_to_add][] = date('Y-m-d H:i:s', time()); |
|
| 655 | + // resave |
|
| 656 | 656 | // echo "updating list of installed versions:".$this->get_activation_history_option_name();d($version_history); |
| 657 | - return update_option($this->get_activation_history_option_name(), $version_history); |
|
| 658 | - } |
|
| 659 | - |
|
| 660 | - /** |
|
| 661 | - * Gets the name of the wp option that stores the activation history |
|
| 662 | - * of this addon |
|
| 663 | - * |
|
| 664 | - * @return string |
|
| 665 | - */ |
|
| 666 | - public function get_activation_history_option_name() |
|
| 667 | - { |
|
| 668 | - return self::ee_addon_version_history_option_prefix . $this->name(); |
|
| 669 | - } |
|
| 670 | - |
|
| 671 | - |
|
| 672 | - /** |
|
| 673 | - * Gets the wp option which stores the activation history for this addon |
|
| 674 | - * |
|
| 675 | - * @return array |
|
| 676 | - */ |
|
| 677 | - public function get_activation_history() |
|
| 678 | - { |
|
| 679 | - return get_option($this->get_activation_history_option_name(), null); |
|
| 680 | - } |
|
| 681 | - |
|
| 682 | - |
|
| 683 | - /** |
|
| 684 | - * @param string $config_section |
|
| 685 | - */ |
|
| 686 | - public function set_config_section($config_section = '') |
|
| 687 | - { |
|
| 688 | - $this->_config_section = ! empty($config_section) ? $config_section : 'addons'; |
|
| 689 | - } |
|
| 690 | - |
|
| 691 | - /** |
|
| 692 | - * Sets the filepath to the main plugin file |
|
| 693 | - * |
|
| 694 | - * @param string $filepath |
|
| 695 | - */ |
|
| 696 | - public function set_main_plugin_file($filepath) |
|
| 697 | - { |
|
| 698 | - $this->_main_plugin_file = $filepath; |
|
| 699 | - } |
|
| 700 | - |
|
| 701 | - /** |
|
| 702 | - * gets the filepath to teh main file |
|
| 703 | - * |
|
| 704 | - * @return string |
|
| 705 | - */ |
|
| 706 | - public function get_main_plugin_file() |
|
| 707 | - { |
|
| 708 | - return $this->_main_plugin_file; |
|
| 709 | - } |
|
| 710 | - |
|
| 711 | - /** |
|
| 712 | - * Gets the filename (no path) of the main file (the main file loaded |
|
| 713 | - * by WP) |
|
| 714 | - * |
|
| 715 | - * @return string |
|
| 716 | - */ |
|
| 717 | - public function get_main_plugin_file_basename() |
|
| 718 | - { |
|
| 719 | - return plugin_basename($this->get_main_plugin_file()); |
|
| 720 | - } |
|
| 721 | - |
|
| 722 | - /** |
|
| 723 | - * Gets the folder name which contains the main plugin file |
|
| 724 | - * |
|
| 725 | - * @return string |
|
| 726 | - */ |
|
| 727 | - public function get_main_plugin_file_dirname() |
|
| 728 | - { |
|
| 729 | - return dirname($this->get_main_plugin_file()); |
|
| 730 | - } |
|
| 731 | - |
|
| 732 | - |
|
| 733 | - /** |
|
| 734 | - * sets hooks used in the admin |
|
| 735 | - * |
|
| 736 | - * @return void |
|
| 737 | - */ |
|
| 738 | - public function admin_init() |
|
| 739 | - { |
|
| 740 | - // is admin and not in M-Mode ? |
|
| 741 | - if (is_admin() && ! EE_Maintenance_Mode::instance()->level()) { |
|
| 742 | - add_filter('plugin_action_links', array($this, 'plugin_action_links'), 10, 2); |
|
| 743 | - add_filter('after_plugin_row_' . $this->_plugin_basename, array($this, 'after_plugin_row'), 10, 3); |
|
| 744 | - } |
|
| 745 | - } |
|
| 746 | - |
|
| 747 | - |
|
| 748 | - /** |
|
| 749 | - * plugin_actions |
|
| 750 | - * Add a settings link to the Plugins page, so people can go straight from the plugin page to the settings page. |
|
| 751 | - * |
|
| 752 | - * @param $links |
|
| 753 | - * @param $file |
|
| 754 | - * @return array |
|
| 755 | - */ |
|
| 756 | - public function plugin_action_links($links, $file) |
|
| 757 | - { |
|
| 758 | - if ($file === $this->plugin_basename() && $this->plugin_action_slug() !== '') { |
|
| 759 | - // before other links |
|
| 760 | - array_unshift( |
|
| 761 | - $links, |
|
| 762 | - '<a href="admin.php?page=' . $this->plugin_action_slug() . '">' |
|
| 763 | - . esc_html__('Settings', 'event_espresso') |
|
| 764 | - . '</a>' |
|
| 765 | - ); |
|
| 766 | - } |
|
| 767 | - return $links; |
|
| 768 | - } |
|
| 769 | - |
|
| 770 | - |
|
| 771 | - /** |
|
| 772 | - * after_plugin_row |
|
| 773 | - * Add additional content to the plugins page plugin row |
|
| 774 | - * Inserts another row |
|
| 775 | - * |
|
| 776 | - * @param $plugin_file |
|
| 777 | - * @param $plugin_data |
|
| 778 | - * @param $status |
|
| 779 | - * @return void |
|
| 780 | - */ |
|
| 781 | - public function after_plugin_row($plugin_file, $plugin_data, $status) |
|
| 782 | - { |
|
| 783 | - $after_plugin_row = ''; |
|
| 784 | - $plugins_page_row = $this->get_plugins_page_row(); |
|
| 785 | - if (! empty($plugins_page_row) && $plugin_file === $this->plugin_basename()) { |
|
| 786 | - $class = $status ? 'active' : 'inactive'; |
|
| 787 | - $link_text = isset($plugins_page_row['link_text']) ? $plugins_page_row['link_text'] : ''; |
|
| 788 | - $link_url = isset($plugins_page_row['link_url']) ? $plugins_page_row['link_url'] : ''; |
|
| 789 | - $description = isset($plugins_page_row['description']) |
|
| 790 | - ? $plugins_page_row['description'] |
|
| 791 | - : ''; |
|
| 792 | - if (! empty($link_text) && ! empty($link_url) && ! empty($description)) { |
|
| 793 | - $after_plugin_row .= '<tr id="' . sanitize_title($plugin_file) . '-ee-addon" class="' . $class . '">'; |
|
| 794 | - $after_plugin_row .= '<th class="check-column" scope="row"></th>'; |
|
| 795 | - $after_plugin_row .= '<td class="ee-addon-upsell-info-title-td plugin-title column-primary">'; |
|
| 796 | - $after_plugin_row .= '<style> |
|
| 657 | + return update_option($this->get_activation_history_option_name(), $version_history); |
|
| 658 | + } |
|
| 659 | + |
|
| 660 | + /** |
|
| 661 | + * Gets the name of the wp option that stores the activation history |
|
| 662 | + * of this addon |
|
| 663 | + * |
|
| 664 | + * @return string |
|
| 665 | + */ |
|
| 666 | + public function get_activation_history_option_name() |
|
| 667 | + { |
|
| 668 | + return self::ee_addon_version_history_option_prefix . $this->name(); |
|
| 669 | + } |
|
| 670 | + |
|
| 671 | + |
|
| 672 | + /** |
|
| 673 | + * Gets the wp option which stores the activation history for this addon |
|
| 674 | + * |
|
| 675 | + * @return array |
|
| 676 | + */ |
|
| 677 | + public function get_activation_history() |
|
| 678 | + { |
|
| 679 | + return get_option($this->get_activation_history_option_name(), null); |
|
| 680 | + } |
|
| 681 | + |
|
| 682 | + |
|
| 683 | + /** |
|
| 684 | + * @param string $config_section |
|
| 685 | + */ |
|
| 686 | + public function set_config_section($config_section = '') |
|
| 687 | + { |
|
| 688 | + $this->_config_section = ! empty($config_section) ? $config_section : 'addons'; |
|
| 689 | + } |
|
| 690 | + |
|
| 691 | + /** |
|
| 692 | + * Sets the filepath to the main plugin file |
|
| 693 | + * |
|
| 694 | + * @param string $filepath |
|
| 695 | + */ |
|
| 696 | + public function set_main_plugin_file($filepath) |
|
| 697 | + { |
|
| 698 | + $this->_main_plugin_file = $filepath; |
|
| 699 | + } |
|
| 700 | + |
|
| 701 | + /** |
|
| 702 | + * gets the filepath to teh main file |
|
| 703 | + * |
|
| 704 | + * @return string |
|
| 705 | + */ |
|
| 706 | + public function get_main_plugin_file() |
|
| 707 | + { |
|
| 708 | + return $this->_main_plugin_file; |
|
| 709 | + } |
|
| 710 | + |
|
| 711 | + /** |
|
| 712 | + * Gets the filename (no path) of the main file (the main file loaded |
|
| 713 | + * by WP) |
|
| 714 | + * |
|
| 715 | + * @return string |
|
| 716 | + */ |
|
| 717 | + public function get_main_plugin_file_basename() |
|
| 718 | + { |
|
| 719 | + return plugin_basename($this->get_main_plugin_file()); |
|
| 720 | + } |
|
| 721 | + |
|
| 722 | + /** |
|
| 723 | + * Gets the folder name which contains the main plugin file |
|
| 724 | + * |
|
| 725 | + * @return string |
|
| 726 | + */ |
|
| 727 | + public function get_main_plugin_file_dirname() |
|
| 728 | + { |
|
| 729 | + return dirname($this->get_main_plugin_file()); |
|
| 730 | + } |
|
| 731 | + |
|
| 732 | + |
|
| 733 | + /** |
|
| 734 | + * sets hooks used in the admin |
|
| 735 | + * |
|
| 736 | + * @return void |
|
| 737 | + */ |
|
| 738 | + public function admin_init() |
|
| 739 | + { |
|
| 740 | + // is admin and not in M-Mode ? |
|
| 741 | + if (is_admin() && ! EE_Maintenance_Mode::instance()->level()) { |
|
| 742 | + add_filter('plugin_action_links', array($this, 'plugin_action_links'), 10, 2); |
|
| 743 | + add_filter('after_plugin_row_' . $this->_plugin_basename, array($this, 'after_plugin_row'), 10, 3); |
|
| 744 | + } |
|
| 745 | + } |
|
| 746 | + |
|
| 747 | + |
|
| 748 | + /** |
|
| 749 | + * plugin_actions |
|
| 750 | + * Add a settings link to the Plugins page, so people can go straight from the plugin page to the settings page. |
|
| 751 | + * |
|
| 752 | + * @param $links |
|
| 753 | + * @param $file |
|
| 754 | + * @return array |
|
| 755 | + */ |
|
| 756 | + public function plugin_action_links($links, $file) |
|
| 757 | + { |
|
| 758 | + if ($file === $this->plugin_basename() && $this->plugin_action_slug() !== '') { |
|
| 759 | + // before other links |
|
| 760 | + array_unshift( |
|
| 761 | + $links, |
|
| 762 | + '<a href="admin.php?page=' . $this->plugin_action_slug() . '">' |
|
| 763 | + . esc_html__('Settings', 'event_espresso') |
|
| 764 | + . '</a>' |
|
| 765 | + ); |
|
| 766 | + } |
|
| 767 | + return $links; |
|
| 768 | + } |
|
| 769 | + |
|
| 770 | + |
|
| 771 | + /** |
|
| 772 | + * after_plugin_row |
|
| 773 | + * Add additional content to the plugins page plugin row |
|
| 774 | + * Inserts another row |
|
| 775 | + * |
|
| 776 | + * @param $plugin_file |
|
| 777 | + * @param $plugin_data |
|
| 778 | + * @param $status |
|
| 779 | + * @return void |
|
| 780 | + */ |
|
| 781 | + public function after_plugin_row($plugin_file, $plugin_data, $status) |
|
| 782 | + { |
|
| 783 | + $after_plugin_row = ''; |
|
| 784 | + $plugins_page_row = $this->get_plugins_page_row(); |
|
| 785 | + if (! empty($plugins_page_row) && $plugin_file === $this->plugin_basename()) { |
|
| 786 | + $class = $status ? 'active' : 'inactive'; |
|
| 787 | + $link_text = isset($plugins_page_row['link_text']) ? $plugins_page_row['link_text'] : ''; |
|
| 788 | + $link_url = isset($plugins_page_row['link_url']) ? $plugins_page_row['link_url'] : ''; |
|
| 789 | + $description = isset($plugins_page_row['description']) |
|
| 790 | + ? $plugins_page_row['description'] |
|
| 791 | + : ''; |
|
| 792 | + if (! empty($link_text) && ! empty($link_url) && ! empty($description)) { |
|
| 793 | + $after_plugin_row .= '<tr id="' . sanitize_title($plugin_file) . '-ee-addon" class="' . $class . '">'; |
|
| 794 | + $after_plugin_row .= '<th class="check-column" scope="row"></th>'; |
|
| 795 | + $after_plugin_row .= '<td class="ee-addon-upsell-info-title-td plugin-title column-primary">'; |
|
| 796 | + $after_plugin_row .= '<style> |
|
| 797 | 797 | .ee-button, |
| 798 | 798 | .ee-button:active, |
| 799 | 799 | .ee-button:visited { |
@@ -830,49 +830,49 @@ discard block |
||
| 830 | 830 | } |
| 831 | 831 | .ee-button:active { top:0; } |
| 832 | 832 | </style>'; |
| 833 | - $after_plugin_row .= ' |
|
| 833 | + $after_plugin_row .= ' |
|
| 834 | 834 | <p class="ee-addon-upsell-info-dv"> |
| 835 | 835 | <a class="ee-button" href="' . $link_url . '">' |
| 836 | - . $link_text |
|
| 837 | - . ' <span class="dashicons dashicons-arrow-right-alt2" style="margin:0;"></span>' |
|
| 838 | - . '</a> |
|
| 836 | + . $link_text |
|
| 837 | + . ' <span class="dashicons dashicons-arrow-right-alt2" style="margin:0;"></span>' |
|
| 838 | + . '</a> |
|
| 839 | 839 | </p>'; |
| 840 | - $after_plugin_row .= '</td>'; |
|
| 841 | - $after_plugin_row .= '<td class="ee-addon-upsell-info-desc-td column-description desc">'; |
|
| 842 | - $after_plugin_row .= $description; |
|
| 843 | - $after_plugin_row .= '</td>'; |
|
| 844 | - $after_plugin_row .= '</tr>'; |
|
| 845 | - } else { |
|
| 846 | - $after_plugin_row .= $description; |
|
| 847 | - } |
|
| 848 | - } |
|
| 849 | - |
|
| 850 | - echo $after_plugin_row; |
|
| 851 | - } |
|
| 852 | - |
|
| 853 | - |
|
| 854 | - /** |
|
| 855 | - * A safe space for addons to add additional logic like setting hooks that need to be set early in the request. |
|
| 856 | - * Child classes that have logic like that to run can override this method declaration. This was not made abstract |
|
| 857 | - * for back compat reasons. |
|
| 858 | - * |
|
| 859 | - * This will fire on the `AHEE__EE_System__load_espresso_addons__complete` hook at priority 999. |
|
| 860 | - * |
|
| 861 | - * It is recommended, if client code is `de-registering` an add-on, then do it on the |
|
| 862 | - * `AHEE__EE_System__load_espresso_addons__complete` hook before priority 999 so as to ensure any code logic in this |
|
| 863 | - * callback does not get run/set in that request. |
|
| 864 | - * |
|
| 865 | - * Also, keep in mind that if a registered add-on happens to be deactivated via |
|
| 866 | - * EE_System::_deactivate_incompatible_addons() because its incompatible, any code executed in this method |
|
| 867 | - * (including setting hooks etc) will have executed before the plugin was deactivated. If you use |
|
| 868 | - * `after_registration` to set any filter and/or action hooks and want to ensure they are removed on this add-on's |
|
| 869 | - * deactivation, you can override `EE_Addon::deactivation` and unset your hooks and filters there. Just remember |
|
| 870 | - * to call `parent::deactivation`. |
|
| 871 | - * |
|
| 872 | - * @since 4.9.26 |
|
| 873 | - */ |
|
| 874 | - public function after_registration() |
|
| 875 | - { |
|
| 876 | - // cricket chirp... cricket chirp... |
|
| 877 | - } |
|
| 840 | + $after_plugin_row .= '</td>'; |
|
| 841 | + $after_plugin_row .= '<td class="ee-addon-upsell-info-desc-td column-description desc">'; |
|
| 842 | + $after_plugin_row .= $description; |
|
| 843 | + $after_plugin_row .= '</td>'; |
|
| 844 | + $after_plugin_row .= '</tr>'; |
|
| 845 | + } else { |
|
| 846 | + $after_plugin_row .= $description; |
|
| 847 | + } |
|
| 848 | + } |
|
| 849 | + |
|
| 850 | + echo $after_plugin_row; |
|
| 851 | + } |
|
| 852 | + |
|
| 853 | + |
|
| 854 | + /** |
|
| 855 | + * A safe space for addons to add additional logic like setting hooks that need to be set early in the request. |
|
| 856 | + * Child classes that have logic like that to run can override this method declaration. This was not made abstract |
|
| 857 | + * for back compat reasons. |
|
| 858 | + * |
|
| 859 | + * This will fire on the `AHEE__EE_System__load_espresso_addons__complete` hook at priority 999. |
|
| 860 | + * |
|
| 861 | + * It is recommended, if client code is `de-registering` an add-on, then do it on the |
|
| 862 | + * `AHEE__EE_System__load_espresso_addons__complete` hook before priority 999 so as to ensure any code logic in this |
|
| 863 | + * callback does not get run/set in that request. |
|
| 864 | + * |
|
| 865 | + * Also, keep in mind that if a registered add-on happens to be deactivated via |
|
| 866 | + * EE_System::_deactivate_incompatible_addons() because its incompatible, any code executed in this method |
|
| 867 | + * (including setting hooks etc) will have executed before the plugin was deactivated. If you use |
|
| 868 | + * `after_registration` to set any filter and/or action hooks and want to ensure they are removed on this add-on's |
|
| 869 | + * deactivation, you can override `EE_Addon::deactivation` and unset your hooks and filters there. Just remember |
|
| 870 | + * to call `parent::deactivation`. |
|
| 871 | + * |
|
| 872 | + * @since 4.9.26 |
|
| 873 | + */ |
|
| 874 | + public function after_registration() |
|
| 875 | + { |
|
| 876 | + // cricket chirp... cricket chirp... |
|
| 877 | + } |
|
| 878 | 878 | } |