@@ -17,256 +17,256 @@ |
||
| 17 | 17 | final class EE_Module_Request_Router implements InterminableInterface |
| 18 | 18 | { |
| 19 | 19 | |
| 20 | - /** |
|
| 21 | - * @var EE_Request $request |
|
| 22 | - */ |
|
| 23 | - private $request; |
|
| 20 | + /** |
|
| 21 | + * @var EE_Request $request |
|
| 22 | + */ |
|
| 23 | + private $request; |
|
| 24 | 24 | |
| 25 | - /** |
|
| 26 | - * @var array $_previous_routes |
|
| 27 | - */ |
|
| 28 | - private static $_previous_routes = array(); |
|
| 25 | + /** |
|
| 26 | + * @var array $_previous_routes |
|
| 27 | + */ |
|
| 28 | + private static $_previous_routes = array(); |
|
| 29 | 29 | |
| 30 | - /** |
|
| 31 | - * @var WP_Query $WP_Query |
|
| 32 | - */ |
|
| 33 | - public $WP_Query; |
|
| 30 | + /** |
|
| 31 | + * @var WP_Query $WP_Query |
|
| 32 | + */ |
|
| 33 | + public $WP_Query; |
|
| 34 | 34 | |
| 35 | 35 | |
| 36 | 36 | |
| 37 | - /** |
|
| 38 | - * EE_Module_Request_Router constructor. |
|
| 39 | - * |
|
| 40 | - * @param EE_Request $request |
|
| 41 | - */ |
|
| 42 | - public function __construct(EE_Request $request) |
|
| 43 | - { |
|
| 44 | - $this->request = $request; |
|
| 45 | - } |
|
| 37 | + /** |
|
| 38 | + * EE_Module_Request_Router constructor. |
|
| 39 | + * |
|
| 40 | + * @param EE_Request $request |
|
| 41 | + */ |
|
| 42 | + public function __construct(EE_Request $request) |
|
| 43 | + { |
|
| 44 | + $this->request = $request; |
|
| 45 | + } |
|
| 46 | 46 | |
| 47 | 47 | |
| 48 | 48 | |
| 49 | - /** |
|
| 50 | - * on the first call to this method, it checks the EE_Request_Handler for a "route" |
|
| 51 | - * on subsequent calls to this method, |
|
| 52 | - * instead of checking the EE_Request_Handler for a route, it checks the previous routes array, |
|
| 53 | - * and checks if the last called route has any forwarding routes registered for it |
|
| 54 | - * |
|
| 55 | - * @param WP_Query $WP_Query |
|
| 56 | - * @return NULL|string |
|
| 57 | - * @throws EE_Error |
|
| 58 | - * @throws ReflectionException |
|
| 59 | - */ |
|
| 60 | - public function get_route(WP_Query $WP_Query) |
|
| 61 | - { |
|
| 62 | - $this->WP_Query = $WP_Query; |
|
| 63 | - // assume this if first route being called |
|
| 64 | - $previous_route = false; |
|
| 65 | - // but is it really ??? |
|
| 66 | - if (! empty(self::$_previous_routes)) { |
|
| 67 | - // get last run route |
|
| 68 | - $previous_routes = array_values(self::$_previous_routes); |
|
| 69 | - $previous_route = array_pop($previous_routes); |
|
| 70 | - } |
|
| 71 | - // has another route already been run ? |
|
| 72 | - if ($previous_route) { |
|
| 73 | - // check if forwarding has been set |
|
| 74 | - $current_route = $this->get_forward($previous_route); |
|
| 75 | - try { |
|
| 76 | - //check for recursive forwarding |
|
| 77 | - if (isset(self::$_previous_routes[$current_route])) { |
|
| 78 | - throw new EE_Error( |
|
| 79 | - sprintf( |
|
| 80 | - __( |
|
| 81 | - 'An error occurred. The %s route has already been called, and therefore can not be forwarded to, because an infinite loop would be created and break the interweb.', |
|
| 82 | - 'event_espresso' |
|
| 83 | - ), |
|
| 84 | - $current_route |
|
| 85 | - ) |
|
| 86 | - ); |
|
| 87 | - } |
|
| 88 | - } catch (EE_Error $e) { |
|
| 89 | - $e->get_error(); |
|
| 90 | - return null; |
|
| 91 | - } |
|
| 92 | - } else { |
|
| 93 | - // first route called |
|
| 94 | - $current_route = null; |
|
| 95 | - // grab all routes |
|
| 96 | - $routes = EE_Config::get_routes(); |
|
| 97 | - foreach ($routes as $key => $route) { |
|
| 98 | - // first determine if route key uses w?ldc*rds |
|
| 99 | - $uses_wildcards = strpos($key, '?') !== false |
|
| 100 | - || strpos($key, '*') !== false; |
|
| 101 | - // check request for module route |
|
| 102 | - $route_found = $uses_wildcards |
|
| 103 | - ? $this->request->matches($key) |
|
| 104 | - : $this->request->is_set($key); |
|
| 105 | - if ($route_found) { |
|
| 106 | - $current_route = $uses_wildcards |
|
| 107 | - ? $this->request->getMatch($key) |
|
| 108 | - : $this->request->get($key); |
|
| 109 | - $current_route = sanitize_text_field($current_route); |
|
| 110 | - if ($current_route) { |
|
| 111 | - $current_route = array($key, $current_route); |
|
| 112 | - break; |
|
| 113 | - } |
|
| 114 | - } |
|
| 115 | - } |
|
| 116 | - } |
|
| 117 | - // sorry, but I can't read what you route ! |
|
| 118 | - if (empty($current_route)) { |
|
| 119 | - return null; |
|
| 120 | - } |
|
| 121 | - //add route to previous routes array |
|
| 122 | - self::$_previous_routes[] = $current_route; |
|
| 123 | - return $current_route; |
|
| 124 | - } |
|
| 49 | + /** |
|
| 50 | + * on the first call to this method, it checks the EE_Request_Handler for a "route" |
|
| 51 | + * on subsequent calls to this method, |
|
| 52 | + * instead of checking the EE_Request_Handler for a route, it checks the previous routes array, |
|
| 53 | + * and checks if the last called route has any forwarding routes registered for it |
|
| 54 | + * |
|
| 55 | + * @param WP_Query $WP_Query |
|
| 56 | + * @return NULL|string |
|
| 57 | + * @throws EE_Error |
|
| 58 | + * @throws ReflectionException |
|
| 59 | + */ |
|
| 60 | + public function get_route(WP_Query $WP_Query) |
|
| 61 | + { |
|
| 62 | + $this->WP_Query = $WP_Query; |
|
| 63 | + // assume this if first route being called |
|
| 64 | + $previous_route = false; |
|
| 65 | + // but is it really ??? |
|
| 66 | + if (! empty(self::$_previous_routes)) { |
|
| 67 | + // get last run route |
|
| 68 | + $previous_routes = array_values(self::$_previous_routes); |
|
| 69 | + $previous_route = array_pop($previous_routes); |
|
| 70 | + } |
|
| 71 | + // has another route already been run ? |
|
| 72 | + if ($previous_route) { |
|
| 73 | + // check if forwarding has been set |
|
| 74 | + $current_route = $this->get_forward($previous_route); |
|
| 75 | + try { |
|
| 76 | + //check for recursive forwarding |
|
| 77 | + if (isset(self::$_previous_routes[$current_route])) { |
|
| 78 | + throw new EE_Error( |
|
| 79 | + sprintf( |
|
| 80 | + __( |
|
| 81 | + 'An error occurred. The %s route has already been called, and therefore can not be forwarded to, because an infinite loop would be created and break the interweb.', |
|
| 82 | + 'event_espresso' |
|
| 83 | + ), |
|
| 84 | + $current_route |
|
| 85 | + ) |
|
| 86 | + ); |
|
| 87 | + } |
|
| 88 | + } catch (EE_Error $e) { |
|
| 89 | + $e->get_error(); |
|
| 90 | + return null; |
|
| 91 | + } |
|
| 92 | + } else { |
|
| 93 | + // first route called |
|
| 94 | + $current_route = null; |
|
| 95 | + // grab all routes |
|
| 96 | + $routes = EE_Config::get_routes(); |
|
| 97 | + foreach ($routes as $key => $route) { |
|
| 98 | + // first determine if route key uses w?ldc*rds |
|
| 99 | + $uses_wildcards = strpos($key, '?') !== false |
|
| 100 | + || strpos($key, '*') !== false; |
|
| 101 | + // check request for module route |
|
| 102 | + $route_found = $uses_wildcards |
|
| 103 | + ? $this->request->matches($key) |
|
| 104 | + : $this->request->is_set($key); |
|
| 105 | + if ($route_found) { |
|
| 106 | + $current_route = $uses_wildcards |
|
| 107 | + ? $this->request->getMatch($key) |
|
| 108 | + : $this->request->get($key); |
|
| 109 | + $current_route = sanitize_text_field($current_route); |
|
| 110 | + if ($current_route) { |
|
| 111 | + $current_route = array($key, $current_route); |
|
| 112 | + break; |
|
| 113 | + } |
|
| 114 | + } |
|
| 115 | + } |
|
| 116 | + } |
|
| 117 | + // sorry, but I can't read what you route ! |
|
| 118 | + if (empty($current_route)) { |
|
| 119 | + return null; |
|
| 120 | + } |
|
| 121 | + //add route to previous routes array |
|
| 122 | + self::$_previous_routes[] = $current_route; |
|
| 123 | + return $current_route; |
|
| 124 | + } |
|
| 125 | 125 | |
| 126 | 126 | |
| 127 | 127 | |
| 128 | - /** |
|
| 129 | - * this method simply takes a valid route, and resolves what module class method the route points to |
|
| 130 | - * |
|
| 131 | - * @param string $key |
|
| 132 | - * @param string $current_route |
|
| 133 | - * @return mixed EED_Module | boolean |
|
| 134 | - * @throws EE_Error |
|
| 135 | - * @throws ReflectionException |
|
| 136 | - */ |
|
| 137 | - public function resolve_route($key, $current_route) |
|
| 138 | - { |
|
| 139 | - // get module method that route has been mapped to |
|
| 140 | - $module_method = EE_Config::get_route($current_route, $key); |
|
| 141 | - // verify result was returned |
|
| 142 | - if (empty($module_method)) { |
|
| 143 | - $msg = sprintf( |
|
| 144 | - __('The requested route %s could not be mapped to any registered modules.', 'event_espresso'), |
|
| 145 | - $current_route |
|
| 146 | - ); |
|
| 147 | - EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 148 | - return false; |
|
| 149 | - } |
|
| 150 | - // verify that result is an array |
|
| 151 | - if (! is_array($module_method)) { |
|
| 152 | - $msg = sprintf(__('The %s route has not been properly registered.', 'event_espresso'), $current_route); |
|
| 153 | - EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 154 | - return false; |
|
| 155 | - } |
|
| 156 | - // grab module name |
|
| 157 | - $module_name = $module_method[0]; |
|
| 158 | - // verify that a class method was registered properly |
|
| 159 | - if (! isset($module_method[1])) { |
|
| 160 | - $msg = sprintf( |
|
| 161 | - __('A class method for the %s route has not been properly registered.', 'event_espresso'), |
|
| 162 | - $current_route |
|
| 163 | - ); |
|
| 164 | - EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 165 | - return false; |
|
| 166 | - } |
|
| 167 | - // grab method |
|
| 168 | - $method = $module_method[1]; |
|
| 169 | - // verify that class exists |
|
| 170 | - if (! class_exists($module_name)) { |
|
| 171 | - $msg = sprintf(__('The requested %s class could not be found.', 'event_espresso'), $module_name); |
|
| 172 | - EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 173 | - return false; |
|
| 174 | - } |
|
| 175 | - // verify that method exists |
|
| 176 | - if (! method_exists($module_name, $method)) { |
|
| 177 | - $msg = sprintf( |
|
| 178 | - __('The class method %s for the %s route is in invalid.', 'event_espresso'), $method, $current_route |
|
| 179 | - ); |
|
| 180 | - EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 181 | - return false; |
|
| 182 | - } |
|
| 183 | - // instantiate module and call route method |
|
| 184 | - return $this->_module_router($module_name, $method); |
|
| 185 | - } |
|
| 128 | + /** |
|
| 129 | + * this method simply takes a valid route, and resolves what module class method the route points to |
|
| 130 | + * |
|
| 131 | + * @param string $key |
|
| 132 | + * @param string $current_route |
|
| 133 | + * @return mixed EED_Module | boolean |
|
| 134 | + * @throws EE_Error |
|
| 135 | + * @throws ReflectionException |
|
| 136 | + */ |
|
| 137 | + public function resolve_route($key, $current_route) |
|
| 138 | + { |
|
| 139 | + // get module method that route has been mapped to |
|
| 140 | + $module_method = EE_Config::get_route($current_route, $key); |
|
| 141 | + // verify result was returned |
|
| 142 | + if (empty($module_method)) { |
|
| 143 | + $msg = sprintf( |
|
| 144 | + __('The requested route %s could not be mapped to any registered modules.', 'event_espresso'), |
|
| 145 | + $current_route |
|
| 146 | + ); |
|
| 147 | + EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 148 | + return false; |
|
| 149 | + } |
|
| 150 | + // verify that result is an array |
|
| 151 | + if (! is_array($module_method)) { |
|
| 152 | + $msg = sprintf(__('The %s route has not been properly registered.', 'event_espresso'), $current_route); |
|
| 153 | + EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 154 | + return false; |
|
| 155 | + } |
|
| 156 | + // grab module name |
|
| 157 | + $module_name = $module_method[0]; |
|
| 158 | + // verify that a class method was registered properly |
|
| 159 | + if (! isset($module_method[1])) { |
|
| 160 | + $msg = sprintf( |
|
| 161 | + __('A class method for the %s route has not been properly registered.', 'event_espresso'), |
|
| 162 | + $current_route |
|
| 163 | + ); |
|
| 164 | + EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 165 | + return false; |
|
| 166 | + } |
|
| 167 | + // grab method |
|
| 168 | + $method = $module_method[1]; |
|
| 169 | + // verify that class exists |
|
| 170 | + if (! class_exists($module_name)) { |
|
| 171 | + $msg = sprintf(__('The requested %s class could not be found.', 'event_espresso'), $module_name); |
|
| 172 | + EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 173 | + return false; |
|
| 174 | + } |
|
| 175 | + // verify that method exists |
|
| 176 | + if (! method_exists($module_name, $method)) { |
|
| 177 | + $msg = sprintf( |
|
| 178 | + __('The class method %s for the %s route is in invalid.', 'event_espresso'), $method, $current_route |
|
| 179 | + ); |
|
| 180 | + EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 181 | + return false; |
|
| 182 | + } |
|
| 183 | + // instantiate module and call route method |
|
| 184 | + return $this->_module_router($module_name, $method); |
|
| 185 | + } |
|
| 186 | 186 | |
| 187 | 187 | |
| 188 | 188 | |
| 189 | - /** |
|
| 190 | - * this method instantiates modules and calls the method that was defined when the route was registered |
|
| 191 | - * |
|
| 192 | - * @param string $module_name |
|
| 193 | - * @return EED_Module|object|null |
|
| 194 | - * @throws ReflectionException |
|
| 195 | - */ |
|
| 196 | - public static function module_factory($module_name) |
|
| 197 | - { |
|
| 198 | - if ($module_name === 'EED_Module') { |
|
| 199 | - EE_Error::add_error( |
|
| 200 | - sprintf( |
|
| 201 | - __( |
|
| 202 | - 'EED_Module is an abstract parent class an can not be instantiated. Please provide a proper module name.', |
|
| 203 | - 'event_espresso' |
|
| 204 | - ), $module_name |
|
| 205 | - ), __FILE__, __FUNCTION__, __LINE__ |
|
| 206 | - ); |
|
| 207 | - return null; |
|
| 208 | - } |
|
| 209 | - // instantiate module class |
|
| 210 | - $module = new $module_name(); |
|
| 211 | - // ensure that class is actually a module |
|
| 212 | - if (! $module instanceof EED_Module) { |
|
| 213 | - EE_Error::add_error( |
|
| 214 | - sprintf(__('The requested %s module is not of the class EED_Module.', 'event_espresso'), $module_name), |
|
| 215 | - __FILE__, __FUNCTION__, __LINE__ |
|
| 216 | - ); |
|
| 217 | - return null; |
|
| 218 | - } |
|
| 219 | - return $module; |
|
| 220 | - } |
|
| 189 | + /** |
|
| 190 | + * this method instantiates modules and calls the method that was defined when the route was registered |
|
| 191 | + * |
|
| 192 | + * @param string $module_name |
|
| 193 | + * @return EED_Module|object|null |
|
| 194 | + * @throws ReflectionException |
|
| 195 | + */ |
|
| 196 | + public static function module_factory($module_name) |
|
| 197 | + { |
|
| 198 | + if ($module_name === 'EED_Module') { |
|
| 199 | + EE_Error::add_error( |
|
| 200 | + sprintf( |
|
| 201 | + __( |
|
| 202 | + 'EED_Module is an abstract parent class an can not be instantiated. Please provide a proper module name.', |
|
| 203 | + 'event_espresso' |
|
| 204 | + ), $module_name |
|
| 205 | + ), __FILE__, __FUNCTION__, __LINE__ |
|
| 206 | + ); |
|
| 207 | + return null; |
|
| 208 | + } |
|
| 209 | + // instantiate module class |
|
| 210 | + $module = new $module_name(); |
|
| 211 | + // ensure that class is actually a module |
|
| 212 | + if (! $module instanceof EED_Module) { |
|
| 213 | + EE_Error::add_error( |
|
| 214 | + sprintf(__('The requested %s module is not of the class EED_Module.', 'event_espresso'), $module_name), |
|
| 215 | + __FILE__, __FUNCTION__, __LINE__ |
|
| 216 | + ); |
|
| 217 | + return null; |
|
| 218 | + } |
|
| 219 | + return $module; |
|
| 220 | + } |
|
| 221 | 221 | |
| 222 | 222 | |
| 223 | 223 | |
| 224 | - /** |
|
| 225 | - * this method instantiates modules and calls the method that was defined when the route was registered |
|
| 226 | - * |
|
| 227 | - * @param string $module_name |
|
| 228 | - * @param string $method |
|
| 229 | - * @return EED_Module|null |
|
| 230 | - * @throws EE_Error |
|
| 231 | - * @throws ReflectionException |
|
| 232 | - */ |
|
| 233 | - private function _module_router($module_name, $method) |
|
| 234 | - { |
|
| 235 | - // instantiate module class |
|
| 236 | - $module = EE_Module_Request_Router::module_factory($module_name); |
|
| 237 | - if ($module instanceof EED_Module) { |
|
| 238 | - // and call whatever action the route was for |
|
| 239 | - try { |
|
| 240 | - call_user_func(array($module, $method), $this->WP_Query); |
|
| 241 | - } catch (EE_Error $e) { |
|
| 242 | - $e->get_error(); |
|
| 243 | - return null; |
|
| 244 | - } |
|
| 245 | - } |
|
| 246 | - return $module; |
|
| 247 | - } |
|
| 224 | + /** |
|
| 225 | + * this method instantiates modules and calls the method that was defined when the route was registered |
|
| 226 | + * |
|
| 227 | + * @param string $module_name |
|
| 228 | + * @param string $method |
|
| 229 | + * @return EED_Module|null |
|
| 230 | + * @throws EE_Error |
|
| 231 | + * @throws ReflectionException |
|
| 232 | + */ |
|
| 233 | + private function _module_router($module_name, $method) |
|
| 234 | + { |
|
| 235 | + // instantiate module class |
|
| 236 | + $module = EE_Module_Request_Router::module_factory($module_name); |
|
| 237 | + if ($module instanceof EED_Module) { |
|
| 238 | + // and call whatever action the route was for |
|
| 239 | + try { |
|
| 240 | + call_user_func(array($module, $method), $this->WP_Query); |
|
| 241 | + } catch (EE_Error $e) { |
|
| 242 | + $e->get_error(); |
|
| 243 | + return null; |
|
| 244 | + } |
|
| 245 | + } |
|
| 246 | + return $module; |
|
| 247 | + } |
|
| 248 | 248 | |
| 249 | 249 | |
| 250 | 250 | |
| 251 | - /** |
|
| 252 | - * @param $current_route |
|
| 253 | - * @return string |
|
| 254 | - */ |
|
| 255 | - public function get_forward($current_route) |
|
| 256 | - { |
|
| 257 | - return EE_Config::get_forward($current_route); |
|
| 258 | - } |
|
| 251 | + /** |
|
| 252 | + * @param $current_route |
|
| 253 | + * @return string |
|
| 254 | + */ |
|
| 255 | + public function get_forward($current_route) |
|
| 256 | + { |
|
| 257 | + return EE_Config::get_forward($current_route); |
|
| 258 | + } |
|
| 259 | 259 | |
| 260 | 260 | |
| 261 | 261 | |
| 262 | - /** |
|
| 263 | - * @param $current_route |
|
| 264 | - * @return string |
|
| 265 | - */ |
|
| 266 | - public function get_view($current_route) |
|
| 267 | - { |
|
| 268 | - return EE_Config::get_view($current_route); |
|
| 269 | - } |
|
| 262 | + /** |
|
| 263 | + * @param $current_route |
|
| 264 | + * @return string |
|
| 265 | + */ |
|
| 266 | + public function get_view($current_route) |
|
| 267 | + { |
|
| 268 | + return EE_Config::get_view($current_route); |
|
| 269 | + } |
|
| 270 | 270 | |
| 271 | 271 | |
| 272 | 272 | } |
@@ -3,7 +3,6 @@ |
||
| 3 | 3 | use EventEspresso\core\exceptions\InvalidDataTypeException; |
| 4 | 4 | use EventEspresso\core\exceptions\InvalidInterfaceException; |
| 5 | 5 | use EventEspresso\core\interfaces\ResettableInterface; |
| 6 | - |
|
| 7 | 6 | use EventEspresso\core\services\database\TableManager; |
| 8 | 7 | use EventEspresso\core\services\database\TableAnalysis; |
| 9 | 8 | |
@@ -136,9 +136,9 @@ discard block |
||
| 136 | 136 | protected $script_migration_versions; |
| 137 | 137 | |
| 138 | 138 | /** |
| 139 | - * @var EE_Data_Migration_Manager $_instance |
|
| 139 | + * @var EE_Data_Migration_Manager $_instance |
|
| 140 | 140 | * @access private |
| 141 | - */ |
|
| 141 | + */ |
|
| 142 | 142 | private static $_instance = NULL; |
| 143 | 143 | |
| 144 | 144 | |
@@ -322,9 +322,9 @@ discard block |
||
| 322 | 322 | */ |
| 323 | 323 | public function get_data_migration_script_folders(){ |
| 324 | 324 | return apply_filters( |
| 325 | - 'FHEE__EE_Data_Migration_Manager__get_data_migration_script_folders', |
|
| 326 | - array('Core' => EE_CORE.'data_migration_scripts') |
|
| 327 | - ); |
|
| 325 | + 'FHEE__EE_Data_Migration_Manager__get_data_migration_script_folders', |
|
| 326 | + array('Core' => EE_CORE.'data_migration_scripts') |
|
| 327 | + ); |
|
| 328 | 328 | } |
| 329 | 329 | |
| 330 | 330 | /** |
@@ -337,15 +337,15 @@ discard block |
||
| 337 | 337 | * @throws EE_Error |
| 338 | 338 | */ |
| 339 | 339 | public function script_migrates_to_version($migration_script_name, $eeAddonClass = ''){ |
| 340 | - if(isset($this->script_migration_versions[ $migration_script_name ])){ |
|
| 341 | - return $this->script_migration_versions[ $migration_script_name ]; |
|
| 342 | - } |
|
| 340 | + if(isset($this->script_migration_versions[ $migration_script_name ])){ |
|
| 341 | + return $this->script_migration_versions[ $migration_script_name ]; |
|
| 342 | + } |
|
| 343 | 343 | $dms_info = $this->parse_dms_classname($migration_script_name); |
| 344 | - $this->script_migration_versions[ $migration_script_name ] = array( |
|
| 344 | + $this->script_migration_versions[ $migration_script_name ] = array( |
|
| 345 | 345 | 'slug'=> $eeAddonClass !== '' ? $eeAddonClass : $dms_info[ 'slug' ], |
| 346 | 346 | 'version'=> $dms_info[ 'major_version' ] . "." . $dms_info[ 'minor_version' ] . "." . $dms_info[ 'micro_version' ] |
| 347 | - ); |
|
| 348 | - return $this->script_migration_versions[ $migration_script_name ]; |
|
| 347 | + ); |
|
| 348 | + return $this->script_migration_versions[ $migration_script_name ]; |
|
| 349 | 349 | } |
| 350 | 350 | |
| 351 | 351 | /** |
@@ -736,60 +736,60 @@ discard block |
||
| 736 | 736 | } |
| 737 | 737 | |
| 738 | 738 | |
| 739 | - /** |
|
| 740 | - * Gets all the data migration scripts available in the core folder and folders |
|
| 741 | - * in addons. Has the side effect of adding them for autoloading |
|
| 742 | - * |
|
| 743 | - * @return array keys are expected classnames, values are their filepaths |
|
| 744 | - * @throws InvalidInterfaceException |
|
| 745 | - * @throws InvalidDataTypeException |
|
| 746 | - * @throws EE_Error |
|
| 747 | - * @throws InvalidArgumentException |
|
| 748 | - */ |
|
| 749 | - public function get_all_data_migration_scripts_available() |
|
| 750 | - { |
|
| 751 | - if (! $this->_data_migration_class_to_filepath_map) { |
|
| 752 | - $this->_data_migration_class_to_filepath_map = array(); |
|
| 753 | - foreach ($this->get_data_migration_script_folders() as $eeAddonClass => $folder_path) { |
|
| 754 | - // strip any placeholders added to classname to make it a unique array key |
|
| 755 | - $eeAddonClass = trim($eeAddonClass, '*'); |
|
| 756 | - $eeAddonClass = $eeAddonClass === 'Core' || class_exists($eeAddonClass) |
|
| 757 | - ? $eeAddonClass |
|
| 758 | - : ''; |
|
| 759 | - $folder_path = EEH_File::end_with_directory_separator($folder_path); |
|
| 760 | - $files = glob($folder_path . '*.dms.php'); |
|
| 761 | - if (empty($files)) { |
|
| 762 | - continue; |
|
| 763 | - } |
|
| 764 | - foreach ($files as $file) { |
|
| 765 | - $pos_of_last_slash = strrpos($file, DS); |
|
| 766 | - $classname = str_replace('.dms.php', '', substr($file, $pos_of_last_slash + 1)); |
|
| 767 | - $migrates_to = $this->script_migrates_to_version($classname, $eeAddonClass); |
|
| 768 | - $slug = $migrates_to['slug']; |
|
| 769 | - //check that the slug as contained in the DMS is associated with |
|
| 770 | - //the slug of an addon or core |
|
| 771 | - if ($slug !== 'Core' && EE_Registry::instance()->get_addon_by_name($slug) === null) { |
|
| 772 | - EE_Error::doing_it_wrong( |
|
| 773 | - __FUNCTION__, |
|
| 774 | - sprintf( |
|
| 775 | - esc_html__( |
|
| 776 | - 'The data migration script "%s" migrates the "%s" data, but there is no EE addon with that name. There is only: %s. ', |
|
| 777 | - 'event_espresso' |
|
| 778 | - ), |
|
| 779 | - $classname, |
|
| 780 | - $slug, |
|
| 781 | - implode(', ', array_keys(EE_Registry::instance()->get_addons_by_name())) |
|
| 782 | - ), |
|
| 783 | - '4.3.0.alpha.019' |
|
| 784 | - ); |
|
| 785 | - } |
|
| 786 | - $this->_data_migration_class_to_filepath_map[ $classname ] = $file; |
|
| 787 | - } |
|
| 788 | - } |
|
| 789 | - EEH_Autoloader::register_autoloader($this->_data_migration_class_to_filepath_map); |
|
| 790 | - } |
|
| 791 | - return $this->_data_migration_class_to_filepath_map; |
|
| 792 | - } |
|
| 739 | + /** |
|
| 740 | + * Gets all the data migration scripts available in the core folder and folders |
|
| 741 | + * in addons. Has the side effect of adding them for autoloading |
|
| 742 | + * |
|
| 743 | + * @return array keys are expected classnames, values are their filepaths |
|
| 744 | + * @throws InvalidInterfaceException |
|
| 745 | + * @throws InvalidDataTypeException |
|
| 746 | + * @throws EE_Error |
|
| 747 | + * @throws InvalidArgumentException |
|
| 748 | + */ |
|
| 749 | + public function get_all_data_migration_scripts_available() |
|
| 750 | + { |
|
| 751 | + if (! $this->_data_migration_class_to_filepath_map) { |
|
| 752 | + $this->_data_migration_class_to_filepath_map = array(); |
|
| 753 | + foreach ($this->get_data_migration_script_folders() as $eeAddonClass => $folder_path) { |
|
| 754 | + // strip any placeholders added to classname to make it a unique array key |
|
| 755 | + $eeAddonClass = trim($eeAddonClass, '*'); |
|
| 756 | + $eeAddonClass = $eeAddonClass === 'Core' || class_exists($eeAddonClass) |
|
| 757 | + ? $eeAddonClass |
|
| 758 | + : ''; |
|
| 759 | + $folder_path = EEH_File::end_with_directory_separator($folder_path); |
|
| 760 | + $files = glob($folder_path . '*.dms.php'); |
|
| 761 | + if (empty($files)) { |
|
| 762 | + continue; |
|
| 763 | + } |
|
| 764 | + foreach ($files as $file) { |
|
| 765 | + $pos_of_last_slash = strrpos($file, DS); |
|
| 766 | + $classname = str_replace('.dms.php', '', substr($file, $pos_of_last_slash + 1)); |
|
| 767 | + $migrates_to = $this->script_migrates_to_version($classname, $eeAddonClass); |
|
| 768 | + $slug = $migrates_to['slug']; |
|
| 769 | + //check that the slug as contained in the DMS is associated with |
|
| 770 | + //the slug of an addon or core |
|
| 771 | + if ($slug !== 'Core' && EE_Registry::instance()->get_addon_by_name($slug) === null) { |
|
| 772 | + EE_Error::doing_it_wrong( |
|
| 773 | + __FUNCTION__, |
|
| 774 | + sprintf( |
|
| 775 | + esc_html__( |
|
| 776 | + 'The data migration script "%s" migrates the "%s" data, but there is no EE addon with that name. There is only: %s. ', |
|
| 777 | + 'event_espresso' |
|
| 778 | + ), |
|
| 779 | + $classname, |
|
| 780 | + $slug, |
|
| 781 | + implode(', ', array_keys(EE_Registry::instance()->get_addons_by_name())) |
|
| 782 | + ), |
|
| 783 | + '4.3.0.alpha.019' |
|
| 784 | + ); |
|
| 785 | + } |
|
| 786 | + $this->_data_migration_class_to_filepath_map[ $classname ] = $file; |
|
| 787 | + } |
|
| 788 | + } |
|
| 789 | + EEH_Autoloader::register_autoloader($this->_data_migration_class_to_filepath_map); |
|
| 790 | + } |
|
| 791 | + return $this->_data_migration_class_to_filepath_map; |
|
| 792 | + } |
|
| 793 | 793 | |
| 794 | 794 | |
| 795 | 795 | |
@@ -961,12 +961,12 @@ discard block |
||
| 961 | 961 | } |
| 962 | 962 | |
| 963 | 963 | /** |
| 964 | - * Resets the borked data migration scripts so they're no longer borked |
|
| 965 | - * so we can again attempt to migrate |
|
| 966 | - * |
|
| 967 | - * @return bool |
|
| 968 | - * @throws EE_Error |
|
| 969 | - */ |
|
| 964 | + * Resets the borked data migration scripts so they're no longer borked |
|
| 965 | + * so we can again attempt to migrate |
|
| 966 | + * |
|
| 967 | + * @return bool |
|
| 968 | + * @throws EE_Error |
|
| 969 | + */ |
|
| 970 | 970 | public function reattempt(){ |
| 971 | 971 | //find if the last-ran script was borked |
| 972 | 972 | //set it as being non-borked (we shouldn't ever get DMSs that we don't recognize) |
@@ -85,7 +85,7 @@ discard block |
||
| 85 | 85 | * of this EE installation. Keys should be the name of the version the script upgraded to |
| 86 | 86 | * @var EE_Data_Migration_Script_Base[] |
| 87 | 87 | */ |
| 88 | - private $_data_migrations_ran =null; |
|
| 88 | + private $_data_migrations_ran = null; |
|
| 89 | 89 | /** |
| 90 | 90 | * The last ran script. It's nice to store this somewhere accessible, as its easiest |
| 91 | 91 | * to know which was the last run by which is the newest wp option; but in most of the code |
@@ -150,7 +150,7 @@ discard block |
||
| 150 | 150 | */ |
| 151 | 151 | public static function instance() { |
| 152 | 152 | // check if class object is instantiated |
| 153 | - if ( ! self::$_instance instanceof EE_Data_Migration_Manager ) { |
|
| 153 | + if ( ! self::$_instance instanceof EE_Data_Migration_Manager) { |
|
| 154 | 154 | self::$_instance = new self(); |
| 155 | 155 | } |
| 156 | 156 | return self::$_instance; |
@@ -160,7 +160,7 @@ discard block |
||
| 160 | 160 | * all new usages of the singleton should be made with Classname::instance()) and returns it |
| 161 | 161 | * @return EE_Data_Migration_Manager |
| 162 | 162 | */ |
| 163 | - public static function reset(){ |
|
| 163 | + public static function reset() { |
|
| 164 | 164 | self::$_instance = NULL; |
| 165 | 165 | return self::instance(); |
| 166 | 166 | } |
@@ -170,7 +170,7 @@ discard block |
||
| 170 | 170 | /** |
| 171 | 171 | * constructor |
| 172 | 172 | */ |
| 173 | - private function __construct(){ |
|
| 173 | + private function __construct() { |
|
| 174 | 174 | $this->stati_that_indicate_to_continue_migrations = array( |
| 175 | 175 | self::status_continue, |
| 176 | 176 | self::status_completed |
@@ -189,13 +189,13 @@ discard block |
||
| 189 | 189 | ); |
| 190 | 190 | //make sure we've included the base migration script, because we may need the EE_DMS_Unknown_1_0_0 class |
| 191 | 191 | //to be defined, because right now it doesn't get autoloaded on its own |
| 192 | - EE_Registry::instance()->load_core( 'Data_Migration_Class_Base', array(), TRUE ); |
|
| 193 | - EE_Registry::instance()->load_core( 'Data_Migration_Script_Base', array(), TRUE ); |
|
| 194 | - EE_Registry::instance()->load_core( 'DMS_Unknown_1_0_0', array(), TRUE ); |
|
| 195 | - EE_Registry::instance()->load_core( 'Data_Migration_Script_Stage', array(), TRUE ); |
|
| 196 | - EE_Registry::instance()->load_core( 'Data_Migration_Script_Stage_Table', array(), TRUE ); |
|
| 197 | - $this->_table_manager = EE_Registry::instance()->create( 'TableManager', array(), true ); |
|
| 198 | - $this->_table_analysis = EE_Registry::instance()->create( 'TableAnalysis', array(), true ); |
|
| 192 | + EE_Registry::instance()->load_core('Data_Migration_Class_Base', array(), TRUE); |
|
| 193 | + EE_Registry::instance()->load_core('Data_Migration_Script_Base', array(), TRUE); |
|
| 194 | + EE_Registry::instance()->load_core('DMS_Unknown_1_0_0', array(), TRUE); |
|
| 195 | + EE_Registry::instance()->load_core('Data_Migration_Script_Stage', array(), TRUE); |
|
| 196 | + EE_Registry::instance()->load_core('Data_Migration_Script_Stage_Table', array(), TRUE); |
|
| 197 | + $this->_table_manager = EE_Registry::instance()->create('TableManager', array(), true); |
|
| 198 | + $this->_table_analysis = EE_Registry::instance()->create('TableAnalysis', array(), true); |
|
| 199 | 199 | } |
| 200 | 200 | |
| 201 | 201 | |
@@ -208,21 +208,21 @@ discard block |
||
| 208 | 208 | * @param string $option_name (see EE_Data_Migration_Manage::_save_migrations_ran() where the option name is set) |
| 209 | 209 | * @return array where the first item is the plugin slug (eg 'Core','Calendar',etc) and the 2nd is the version of that plugin (eg '4.1.0') |
| 210 | 210 | */ |
| 211 | - private function _get_plugin_slug_and_version_string_from_dms_option_name($option_name){ |
|
| 211 | + private function _get_plugin_slug_and_version_string_from_dms_option_name($option_name) { |
|
| 212 | 212 | $plugin_slug_and_version_string = str_replace(EE_Data_Migration_Manager::data_migration_script_option_prefix, "", $option_name); |
| 213 | 213 | //check if $plugin_slug_and_version_string is like '4.1.0' (4.1-style) or 'Core.4.1.0' (4.2-style) |
| 214 | - $parts = explode(".",$plugin_slug_and_version_string); |
|
| 214 | + $parts = explode(".", $plugin_slug_and_version_string); |
|
| 215 | 215 | |
| 216 | - if(count($parts) == 4){ |
|
| 216 | + if (count($parts) == 4) { |
|
| 217 | 217 | //it's 4.2-style.eg Core.4.1.0 |
| 218 | - $plugin_slug = $parts[0];//eg Core |
|
| 218 | + $plugin_slug = $parts[0]; //eg Core |
|
| 219 | 219 | $version_string = $parts[1].".".$parts[2].".".$parts[3]; //eg 4.1.0 |
| 220 | - }else{ |
|
| 220 | + } else { |
|
| 221 | 221 | //it's 4.1-style: eg 4.1.0 |
| 222 | 222 | $plugin_slug = 'Core'; |
| 223 | - $version_string = $plugin_slug_and_version_string;//eg 4.1.0 |
|
| 223 | + $version_string = $plugin_slug_and_version_string; //eg 4.1.0 |
|
| 224 | 224 | } |
| 225 | - return array($plugin_slug,$version_string); |
|
| 225 | + return array($plugin_slug, $version_string); |
|
| 226 | 226 | } |
| 227 | 227 | |
| 228 | 228 | /** |
@@ -233,21 +233,21 @@ discard block |
||
| 233 | 233 | * @return EE_Data_Migration_Script_Base |
| 234 | 234 | * @throws EE_Error |
| 235 | 235 | */ |
| 236 | - private function _get_dms_class_from_wp_option($dms_option_name,$dms_option_value){ |
|
| 236 | + private function _get_dms_class_from_wp_option($dms_option_name, $dms_option_value) { |
|
| 237 | 237 | $data_migration_data = maybe_unserialize($dms_option_value); |
| 238 | - if(isset($data_migration_data['class']) && class_exists($data_migration_data['class'])){ |
|
| 238 | + if (isset($data_migration_data['class']) && class_exists($data_migration_data['class'])) { |
|
| 239 | 239 | $class = new $data_migration_data['class']; |
| 240 | - if($class instanceof EE_Data_Migration_Script_Base){ |
|
| 240 | + if ($class instanceof EE_Data_Migration_Script_Base) { |
|
| 241 | 241 | $class->instantiate_from_array_of_properties($data_migration_data); |
| 242 | 242 | return $class; |
| 243 | - }else{ |
|
| 243 | + } else { |
|
| 244 | 244 | //huh, so its an object but not a data migration script?? that shouldn't happen |
| 245 | 245 | //just leave it as an array (which will probably just get ignored) |
| 246 | - throw new EE_Error(sprintf(__("Trying to retrieve DMS class from wp option. No DMS by the name '%s' exists", 'event_espresso'),$data_migration_data['class'])); |
|
| 246 | + throw new EE_Error(sprintf(__("Trying to retrieve DMS class from wp option. No DMS by the name '%s' exists", 'event_espresso'), $data_migration_data['class'])); |
|
| 247 | 247 | } |
| 248 | - }else{ |
|
| 248 | + } else { |
|
| 249 | 249 | //so the data doesn't specify a class. So it must either be a legacy array of info or some array (which we'll probably just ignore), or a class that no longer exists |
| 250 | - throw new EE_Error(sprintf(__("The wp option with key '%s' does not represent a DMS", 'event_espresso'),$dms_option_name)); |
|
| 250 | + throw new EE_Error(sprintf(__("The wp option with key '%s' does not represent a DMS", 'event_espresso'), $dms_option_name)); |
|
| 251 | 251 | } |
| 252 | 252 | } |
| 253 | 253 | /** |
@@ -255,34 +255,34 @@ discard block |
||
| 255 | 255 | * the last ran which hasn't finished yet |
| 256 | 256 | * @return array where each element should be an array of EE_Data_Migration_Script_Base (but also has a few legacy arrays in there - which should probably be ignored) |
| 257 | 257 | */ |
| 258 | - public function get_data_migrations_ran(){ |
|
| 259 | - if( ! $this->_data_migrations_ran ){ |
|
| 258 | + public function get_data_migrations_ran() { |
|
| 259 | + if ( ! $this->_data_migrations_ran) { |
|
| 260 | 260 | //setup autoloaders for each of the scripts in there |
| 261 | 261 | $this->get_all_data_migration_scripts_available(); |
| 262 | - $data_migrations_options = $this->get_all_migration_script_options();//get_option(EE_Data_Migration_Manager::data_migrations_option_name,get_option('espresso_data_migrations',array())); |
|
| 262 | + $data_migrations_options = $this->get_all_migration_script_options(); //get_option(EE_Data_Migration_Manager::data_migrations_option_name,get_option('espresso_data_migrations',array())); |
|
| 263 | 263 | |
| 264 | 264 | $data_migrations_ran = array(); |
| 265 | 265 | //convert into data migration script classes where possible |
| 266 | - foreach($data_migrations_options as $data_migration_option){ |
|
| 267 | - list($plugin_slug,$version_string) = $this->_get_plugin_slug_and_version_string_from_dms_option_name($data_migration_option['option_name']); |
|
| 266 | + foreach ($data_migrations_options as $data_migration_option) { |
|
| 267 | + list($plugin_slug, $version_string) = $this->_get_plugin_slug_and_version_string_from_dms_option_name($data_migration_option['option_name']); |
|
| 268 | 268 | |
| 269 | - try{ |
|
| 270 | - $class = $this->_get_dms_class_from_wp_option($data_migration_option['option_name'],$data_migration_option['option_value']); |
|
| 269 | + try { |
|
| 270 | + $class = $this->_get_dms_class_from_wp_option($data_migration_option['option_name'], $data_migration_option['option_value']); |
|
| 271 | 271 | $data_migrations_ran[$plugin_slug][$version_string] = $class; |
| 272 | 272 | //ok so far THIS is the 'last-ran-script'... unless we find another on next iteration |
| 273 | 273 | $this->_last_ran_script = $class; |
| 274 | - if( ! $class->is_completed()){ |
|
| 274 | + if ( ! $class->is_completed()) { |
|
| 275 | 275 | //sometimes we also like to know which was the last incomplete script (or if there are any at all) |
| 276 | 276 | $this->_last_ran_incomplete_script = $class; |
| 277 | 277 | } |
| 278 | - }catch(EE_Error $e){ |
|
| 278 | + } catch (EE_Error $e) { |
|
| 279 | 279 | //ok so its not a DMS. We'll just keep it, although other code will need to expect non-DMSs |
| 280 | 280 | $data_migrations_ran[$plugin_slug][$version_string] = maybe_unserialize($data_migration_option['option_value']); |
| 281 | 281 | } |
| 282 | 282 | } |
| 283 | 283 | //so here the array of $data_migrations_ran is actually a mix of classes and a few legacy arrays |
| 284 | 284 | $this->_data_migrations_ran = $data_migrations_ran; |
| 285 | - if ( ! $this->_data_migrations_ran || ! is_array($this->_data_migrations_ran) ){ |
|
| 285 | + if ( ! $this->_data_migrations_ran || ! is_array($this->_data_migrations_ran)) { |
|
| 286 | 286 | $this->_data_migrations_ran = array(); |
| 287 | 287 | } |
| 288 | 288 | } |
@@ -299,7 +299,7 @@ discard block |
||
| 299 | 299 | * @param $new_table |
| 300 | 300 | * @return mixed string or int |
| 301 | 301 | */ |
| 302 | - public function get_mapping_new_pk( $script_name, $old_table, $old_pk, $new_table){ |
|
| 302 | + public function get_mapping_new_pk($script_name, $old_table, $old_pk, $new_table) { |
|
| 303 | 303 | $script = EE_Registry::instance()->load_dms($script_name); |
| 304 | 304 | $mapping = $script->get_mapping_new_pk($old_table, $old_pk, $new_table); |
| 305 | 305 | return $mapping; |
@@ -310,9 +310,9 @@ discard block |
||
| 310 | 310 | * option returned in this array is the most-recently ran DMS option |
| 311 | 311 | * @return array |
| 312 | 312 | */ |
| 313 | - public function get_all_migration_script_options(){ |
|
| 313 | + public function get_all_migration_script_options() { |
|
| 314 | 314 | global $wpdb; |
| 315 | - return $wpdb->get_results("SELECT * FROM {$wpdb->options} WHERE option_name like '".EE_Data_Migration_Manager::data_migration_script_option_prefix."%' ORDER BY option_id ASC",ARRAY_A); |
|
| 315 | + return $wpdb->get_results("SELECT * FROM {$wpdb->options} WHERE option_name like '".EE_Data_Migration_Manager::data_migration_script_option_prefix."%' ORDER BY option_id ASC", ARRAY_A); |
|
| 316 | 316 | } |
| 317 | 317 | |
| 318 | 318 | /** |
@@ -320,7 +320,7 @@ discard block |
||
| 320 | 320 | * @return array where each value is the full folder path of a folder containing data migration scripts, WITH slashes at the end of the |
| 321 | 321 | * folder name. |
| 322 | 322 | */ |
| 323 | - public function get_data_migration_script_folders(){ |
|
| 323 | + public function get_data_migration_script_folders() { |
|
| 324 | 324 | return apply_filters( |
| 325 | 325 | 'FHEE__EE_Data_Migration_Manager__get_data_migration_script_folders', |
| 326 | 326 | array('Core' => EE_CORE.'data_migration_scripts') |
@@ -336,16 +336,16 @@ discard block |
||
| 336 | 336 | * } |
| 337 | 337 | * @throws EE_Error |
| 338 | 338 | */ |
| 339 | - public function script_migrates_to_version($migration_script_name, $eeAddonClass = ''){ |
|
| 340 | - if(isset($this->script_migration_versions[ $migration_script_name ])){ |
|
| 341 | - return $this->script_migration_versions[ $migration_script_name ]; |
|
| 339 | + public function script_migrates_to_version($migration_script_name, $eeAddonClass = '') { |
|
| 340 | + if (isset($this->script_migration_versions[$migration_script_name])) { |
|
| 341 | + return $this->script_migration_versions[$migration_script_name]; |
|
| 342 | 342 | } |
| 343 | 343 | $dms_info = $this->parse_dms_classname($migration_script_name); |
| 344 | - $this->script_migration_versions[ $migration_script_name ] = array( |
|
| 345 | - 'slug'=> $eeAddonClass !== '' ? $eeAddonClass : $dms_info[ 'slug' ], |
|
| 346 | - 'version'=> $dms_info[ 'major_version' ] . "." . $dms_info[ 'minor_version' ] . "." . $dms_info[ 'micro_version' ] |
|
| 344 | + $this->script_migration_versions[$migration_script_name] = array( |
|
| 345 | + 'slug'=> $eeAddonClass !== '' ? $eeAddonClass : $dms_info['slug'], |
|
| 346 | + 'version'=> $dms_info['major_version'].".".$dms_info['minor_version'].".".$dms_info['micro_version'] |
|
| 347 | 347 | ); |
| 348 | - return $this->script_migration_versions[ $migration_script_name ]; |
|
| 348 | + return $this->script_migration_versions[$migration_script_name]; |
|
| 349 | 349 | } |
| 350 | 350 | |
| 351 | 351 | /** |
@@ -354,13 +354,13 @@ discard block |
||
| 354 | 354 | * @return array with keys 'slug','major_version','minor_version', and 'micro_version' (the last 3 are ints) |
| 355 | 355 | * @throws EE_Error |
| 356 | 356 | */ |
| 357 | - public function parse_dms_classname($classname){ |
|
| 357 | + public function parse_dms_classname($classname) { |
|
| 358 | 358 | $matches = array(); |
| 359 | - preg_match('~EE_DMS_(.*)_([0-9]*)_([0-9]*)_([0-9]*)~',$classname,$matches); |
|
| 360 | - if( ! $matches || ! (isset($matches[1]) && isset($matches[2]) && isset($matches[3]))){ |
|
| 361 | - throw new EE_Error(sprintf(__("%s is not a valid Data Migration Script. The classname should be like EE_DMS_w_x_y_z, where w is either 'Core' or the slug of an addon and x, y and z are numbers, ", "event_espresso"),$classname)); |
|
| 359 | + preg_match('~EE_DMS_(.*)_([0-9]*)_([0-9]*)_([0-9]*)~', $classname, $matches); |
|
| 360 | + if ( ! $matches || ! (isset($matches[1]) && isset($matches[2]) && isset($matches[3]))) { |
|
| 361 | + throw new EE_Error(sprintf(__("%s is not a valid Data Migration Script. The classname should be like EE_DMS_w_x_y_z, where w is either 'Core' or the slug of an addon and x, y and z are numbers, ", "event_espresso"), $classname)); |
|
| 362 | 362 | } |
| 363 | - return array('slug'=>$matches[1],'major_version'=>intval($matches[2]),'minor_version'=>intval($matches[3]),'micro_version'=>intval($matches[4])); |
|
| 363 | + return array('slug'=>$matches[1], 'major_version'=>intval($matches[2]), 'minor_version'=>intval($matches[3]), 'micro_version'=>intval($matches[4])); |
|
| 364 | 364 | } |
| 365 | 365 | /** |
| 366 | 366 | * Ensures that the option indicating the current DB version is set. This should only be |
@@ -369,33 +369,33 @@ discard block |
||
| 369 | 369 | * to 4.1.x. |
| 370 | 370 | * @return string of current db state |
| 371 | 371 | */ |
| 372 | - public function ensure_current_database_state_is_set(){ |
|
| 373 | - $espresso_db_core_updates = get_option( 'espresso_db_update', array() ); |
|
| 372 | + public function ensure_current_database_state_is_set() { |
|
| 373 | + $espresso_db_core_updates = get_option('espresso_db_update', array()); |
|
| 374 | 374 | $db_state = get_option(EE_Data_Migration_Manager::current_database_state); |
| 375 | - if( ! $db_state ){ |
|
| 375 | + if ( ! $db_state) { |
|
| 376 | 376 | //mark the DB as being in the state as the last version in there. |
| 377 | 377 | //this is done to trigger maintenance mode and do data migration scripts |
| 378 | 378 | //if the admin installed this version of EE over 3.1.x or 4.0.x |
| 379 | 379 | //otherwise, the normal maintenance mode code is fine |
| 380 | 380 | $previous_versions_installed = array_keys($espresso_db_core_updates); |
| 381 | 381 | $previous_version_installed = end($previous_versions_installed); |
| 382 | - if(version_compare('4.1.0', $previous_version_installed)){ |
|
| 382 | + if (version_compare('4.1.0', $previous_version_installed)) { |
|
| 383 | 383 | //last installed version was less than 4.1 |
| 384 | 384 | //so we want the data migrations to happen. SO, we're going to say the DB is at that state |
| 385 | 385 | // echo "4.1.0 is greater than $previous_version_installed! update the option"; |
| 386 | 386 | $db_state = array('Core'=>$previous_version_installed); |
| 387 | - }else{ |
|
| 387 | + } else { |
|
| 388 | 388 | // echo "4.1.0 is SMALLER than $previous_version_installed"; |
| 389 | 389 | $db_state = array('Core'=>EVENT_ESPRESSO_VERSION); |
| 390 | 390 | } |
| 391 | - update_option(EE_Data_Migration_Manager::current_database_state,$db_state); |
|
| 391 | + update_option(EE_Data_Migration_Manager::current_database_state, $db_state); |
|
| 392 | 392 | } |
| 393 | 393 | //in 4.1, $db_state would have only been a simple string like '4.1.0', |
| 394 | 394 | //but in 4.2+ it should be an array with at least key 'Core' and the value of that plugin's |
| 395 | 395 | //db, and possibly other keys for other addons like 'Calendar','Permissions',etc |
| 396 | - if( ! is_array($db_state)){ |
|
| 396 | + if ( ! is_array($db_state)) { |
|
| 397 | 397 | $db_state = array('Core'=>$db_state); |
| 398 | - update_option(EE_Data_Migration_Manager::current_database_state,$db_state); |
|
| 398 | + update_option(EE_Data_Migration_Manager::current_database_state, $db_state); |
|
| 399 | 399 | } |
| 400 | 400 | return $db_state; |
| 401 | 401 | } |
@@ -406,7 +406,7 @@ discard block |
||
| 406 | 406 | * or they don't apply), returns an empty array |
| 407 | 407 | * @return EE_Data_Migration_Script_Base[] |
| 408 | 408 | */ |
| 409 | - public function check_for_applicable_data_migration_scripts(){ |
|
| 409 | + public function check_for_applicable_data_migration_scripts() { |
|
| 410 | 410 | //get the option describing what options have already run |
| 411 | 411 | $scripts_ran = $this->get_data_migrations_ran(); |
| 412 | 412 | //$scripts_ran = array('4.1.0.core'=>array('monkey'=>null)); |
@@ -419,62 +419,62 @@ discard block |
||
| 419 | 419 | $iteration = 0; |
| 420 | 420 | $next_database_state_to_consider = $current_database_state; |
| 421 | 421 | $theoretical_database_state = NULL; |
| 422 | - do{ |
|
| 422 | + do { |
|
| 423 | 423 | //the next state after the currently-considered one will start off looking the same as the current, but we may make additions... |
| 424 | 424 | $theoretical_database_state = $next_database_state_to_consider; |
| 425 | 425 | //the next db state to consider is "what would the DB be like had we run all the scripts we found that applied last time?) |
| 426 | - foreach($script_class_and_filepaths_available as $classname => $filepath){ |
|
| 426 | + foreach ($script_class_and_filepaths_available as $classname => $filepath) { |
|
| 427 | 427 | |
| 428 | 428 | $migrates_to_version = $this->script_migrates_to_version($classname); |
| 429 | - $script_converts_plugin_slug = $migrates_to_version[ 'slug' ]; |
|
| 430 | - $script_converts_to_version = $migrates_to_version[ 'version' ]; |
|
| 429 | + $script_converts_plugin_slug = $migrates_to_version['slug']; |
|
| 430 | + $script_converts_to_version = $migrates_to_version['version']; |
|
| 431 | 431 | //check if this version script is DONE or not; or if it's never been ran |
| 432 | - if( ! $scripts_ran || |
|
| 432 | + if ( ! $scripts_ran || |
|
| 433 | 433 | ! isset($scripts_ran[$script_converts_plugin_slug]) || |
| 434 | - ! isset($scripts_ran[$script_converts_plugin_slug][$script_converts_to_version])){ |
|
| 434 | + ! isset($scripts_ran[$script_converts_plugin_slug][$script_converts_to_version])) { |
|
| 435 | 435 | //we haven't ran this conversion script before |
| 436 | 436 | //now check if it applies... note that we've added an autoloader for it on get_all_data_migration_scripts_available |
| 437 | - $script = new $classname( $this->_get_table_manager(), $this->_get_table_analysis() ); |
|
| 437 | + $script = new $classname($this->_get_table_manager(), $this->_get_table_analysis()); |
|
| 438 | 438 | /* @var $script EE_Data_Migration_Script_Base */ |
| 439 | 439 | $can_migrate = $script->can_migrate_from_version($theoretical_database_state); |
| 440 | - if($can_migrate){ |
|
| 440 | + if ($can_migrate) { |
|
| 441 | 441 | $script_classes_that_should_run_per_iteration[$iteration][$script->priority()][] = $script; |
| 442 | 442 | $migrates_to_version = $script->migrates_to_version(); |
| 443 | - $next_database_state_to_consider[ $migrates_to_version[ 'slug' ] ] = $migrates_to_version[ 'version' ]; |
|
| 443 | + $next_database_state_to_consider[$migrates_to_version['slug']] = $migrates_to_version['version']; |
|
| 444 | 444 | unset($script_class_and_filepaths_available[$classname]); |
| 445 | 445 | } |
| 446 | - } elseif($scripts_ran[$script_converts_plugin_slug][$script_converts_to_version] instanceof EE_Data_Migration_Script_Base){ |
|
| 446 | + } elseif ($scripts_ran[$script_converts_plugin_slug][$script_converts_to_version] instanceof EE_Data_Migration_Script_Base) { |
|
| 447 | 447 | //this script has been ran, or at least started |
| 448 | 448 | $script = $scripts_ran[$script_converts_plugin_slug][$script_converts_to_version]; |
| 449 | - if( $script->get_status() != self::status_completed){ |
|
| 449 | + if ($script->get_status() != self::status_completed) { |
|
| 450 | 450 | //this script is already underway... keep going with it |
| 451 | 451 | $script_classes_that_should_run_per_iteration[$iteration][$script->priority()][] = $script; |
| 452 | 452 | $migrates_to_version = $script->migrates_to_version(); |
| 453 | - $next_database_state_to_consider[ $migrates_to_version[ 'slug' ] ] = $migrates_to_version[ 'version' ]; |
|
| 453 | + $next_database_state_to_consider[$migrates_to_version['slug']] = $migrates_to_version['version']; |
|
| 454 | 454 | unset($script_class_and_filepaths_available[$classname]); |
| 455 | - }else{ |
|
| 455 | + } else { |
|
| 456 | 456 | //it must have a status that indicates it has finished, so we don't want to try and run it again |
| 457 | 457 | } |
| 458 | - }else{ |
|
| 458 | + } else { |
|
| 459 | 459 | //it exists but it's not a proper data migration script |
| 460 | 460 | //maybe the script got renamed? or was simply removed from EE? |
| 461 | 461 | //either way, its certainly not runnable! |
| 462 | 462 | } |
| 463 | 463 | } |
| 464 | 464 | $iteration++; |
| 465 | - }while( $next_database_state_to_consider != $theoretical_database_state && $iteration<6); |
|
| 465 | + }while ($next_database_state_to_consider != $theoretical_database_state && $iteration < 6); |
|
| 466 | 466 | //ok we have all the scripts that should run, now let's make them into flat array |
| 467 | 467 | $scripts_that_should_run = array(); |
| 468 | - foreach($script_classes_that_should_run_per_iteration as $scripts_at_priority){ |
|
| 468 | + foreach ($script_classes_that_should_run_per_iteration as $scripts_at_priority) { |
|
| 469 | 469 | ksort($scripts_at_priority); |
| 470 | - foreach($scripts_at_priority as $scripts){ |
|
| 471 | - foreach($scripts as $script){ |
|
| 470 | + foreach ($scripts_at_priority as $scripts) { |
|
| 471 | + foreach ($scripts as $script) { |
|
| 472 | 472 | $scripts_that_should_run[get_class($script)] = $script; |
| 473 | 473 | } |
| 474 | 474 | } |
| 475 | 475 | } |
| 476 | 476 | |
| 477 | - do_action( 'AHEE__EE_Data_Migration_Manager__check_for_applicable_data_migration_scripts__scripts_that_should_run', $scripts_that_should_run ); |
|
| 477 | + do_action('AHEE__EE_Data_Migration_Manager__check_for_applicable_data_migration_scripts__scripts_that_should_run', $scripts_that_should_run); |
|
| 478 | 478 | return $scripts_that_should_run; |
| 479 | 479 | } |
| 480 | 480 | |
@@ -488,14 +488,14 @@ discard block |
||
| 488 | 488 | * @param bool $include_completed_scripts |
| 489 | 489 | * @return EE_Data_Migration_Script_Base |
| 490 | 490 | */ |
| 491 | - public function get_last_ran_script($include_completed_scripts = false){ |
|
| 491 | + public function get_last_ran_script($include_completed_scripts = false) { |
|
| 492 | 492 | //make sure we've setup the class properties _last_ran_script and _last_ran_incomplete_script |
| 493 | - if( ! $this->_data_migrations_ran){ |
|
| 493 | + if ( ! $this->_data_migrations_ran) { |
|
| 494 | 494 | $this->get_data_migrations_ran(); |
| 495 | 495 | } |
| 496 | - if($include_completed_scripts){ |
|
| 496 | + if ($include_completed_scripts) { |
|
| 497 | 497 | return $this->_last_ran_script; |
| 498 | - }else{ |
|
| 498 | + } else { |
|
| 499 | 499 | return $this->_last_ran_incomplete_script; |
| 500 | 500 | } |
| 501 | 501 | } |
@@ -518,19 +518,19 @@ discard block |
||
| 518 | 518 | * @type string $message string describing what was done during this step |
| 519 | 519 | * } |
| 520 | 520 | */ |
| 521 | - public function migration_step( $step_size = 0 ){ |
|
| 521 | + public function migration_step($step_size = 0) { |
|
| 522 | 522 | |
| 523 | 523 | //bandaid fix for issue https://events.codebasehq.com/projects/event-espresso/tickets/7535 |
| 524 | - if ( class_exists( 'EE_CPT_Strategy' ) ) { |
|
| 525 | - remove_action( 'pre_get_posts', array( EE_CPT_Strategy::instance(), 'pre_get_posts' ), 5 ); |
|
| 524 | + if (class_exists('EE_CPT_Strategy')) { |
|
| 525 | + remove_action('pre_get_posts', array(EE_CPT_Strategy::instance(), 'pre_get_posts'), 5); |
|
| 526 | 526 | } |
| 527 | 527 | |
| 528 | - try{ |
|
| 528 | + try { |
|
| 529 | 529 | $currently_executing_script = $this->get_last_ran_script(); |
| 530 | - if( ! $currently_executing_script){ |
|
| 530 | + if ( ! $currently_executing_script) { |
|
| 531 | 531 | //Find the next script that needs to execute |
| 532 | 532 | $scripts = $this->check_for_applicable_data_migration_scripts(); |
| 533 | - if( ! $scripts ){ |
|
| 533 | + if ( ! $scripts) { |
|
| 534 | 534 | //huh, no more scripts to run... apparently we're done! |
| 535 | 535 | //but dont forget to make sure initial data is there |
| 536 | 536 | //we should be good to allow them to exit maintenance mode now |
@@ -551,18 +551,18 @@ discard block |
||
| 551 | 551 | //and add to the array/wp option showing the scripts ran |
| 552 | 552 | // $this->_data_migrations_ran[$this->script_migrates_to_version(get_class($currently_executing_script))] = $currently_executing_script; |
| 553 | 553 | $migrates_to = $this->script_migrates_to_version(get_class($currently_executing_script)); |
| 554 | - $plugin_slug = $migrates_to[ 'slug' ]; |
|
| 555 | - $version = $migrates_to[ 'version' ]; |
|
| 554 | + $plugin_slug = $migrates_to['slug']; |
|
| 555 | + $version = $migrates_to['version']; |
|
| 556 | 556 | $this->_data_migrations_ran[$plugin_slug][$version] = $currently_executing_script; |
| 557 | 557 | } |
| 558 | 558 | $current_script_name = get_class($currently_executing_script); |
| 559 | - }catch(Exception $e){ |
|
| 559 | + } catch (Exception $e) { |
|
| 560 | 560 | //an exception occurred while trying to get migration scripts |
| 561 | 561 | |
| 562 | - $message = sprintf( __("Error Message: %sStack Trace:%s", "event_espresso"), $e->getMessage() . '<br>', $e->getTraceAsString() ); |
|
| 562 | + $message = sprintf(__("Error Message: %sStack Trace:%s", "event_espresso"), $e->getMessage().'<br>', $e->getTraceAsString()); |
|
| 563 | 563 | //record it on the array of data migration scripts ran. This will be overwritten next time we try and try to run data migrations |
| 564 | 564 | //but that's ok-- it's just an FYI to support that we couldn't even run any data migrations |
| 565 | - $this->add_error_to_migrations_ran(sprintf(__("Could not run data migrations because: %s", "event_espresso"),$message)); |
|
| 565 | + $this->add_error_to_migrations_ran(sprintf(__("Could not run data migrations because: %s", "event_espresso"), $message)); |
|
| 566 | 566 | return array( |
| 567 | 567 | 'records_to_migrate'=>1, |
| 568 | 568 | 'records_migrated'=>0, |
@@ -572,16 +572,16 @@ discard block |
||
| 572 | 572 | ); |
| 573 | 573 | } |
| 574 | 574 | //ok so we definitely have a data migration script |
| 575 | - try{ |
|
| 575 | + try { |
|
| 576 | 576 | //how big of a bite do we want to take? Allow users to easily override via their wp-config |
| 577 | - if( ! absint( $step_size ) > 0 ){ |
|
| 578 | - $step_size = defined( 'EE_MIGRATION_STEP_SIZE' ) && absint( EE_MIGRATION_STEP_SIZE ) ? EE_MIGRATION_STEP_SIZE : EE_Data_Migration_Manager::step_size; |
|
| 577 | + if ( ! absint($step_size) > 0) { |
|
| 578 | + $step_size = defined('EE_MIGRATION_STEP_SIZE') && absint(EE_MIGRATION_STEP_SIZE) ? EE_MIGRATION_STEP_SIZE : EE_Data_Migration_Manager::step_size; |
|
| 579 | 579 | } |
| 580 | 580 | //do what we came to do! |
| 581 | 581 | $currently_executing_script->migration_step($step_size); |
| 582 | 582 | //can we wrap it up and verify default data? |
| 583 | 583 | $init_dbs = false; |
| 584 | - switch($currently_executing_script->get_status()){ |
|
| 584 | + switch ($currently_executing_script->get_status()) { |
|
| 585 | 585 | case EE_Data_Migration_Manager::status_continue: |
| 586 | 586 | $response_array = array( |
| 587 | 587 | 'records_to_migrate'=>$currently_executing_script->count_records_to_migrate(), |
@@ -593,16 +593,16 @@ discard block |
||
| 593 | 593 | case EE_Data_Migration_Manager::status_completed: |
| 594 | 594 | //ok so THAT script has completed |
| 595 | 595 | $this->update_current_database_state_to($this->script_migrates_to_version($current_script_name)); |
| 596 | - $response_array = array( |
|
| 596 | + $response_array = array( |
|
| 597 | 597 | 'records_to_migrate'=>$currently_executing_script->count_records_to_migrate(), |
| 598 | 598 | 'records_migrated'=>$currently_executing_script->count_records_migrated(), |
| 599 | 599 | 'status'=> EE_Data_Migration_Manager::status_completed, |
| 600 | 600 | 'message'=>$currently_executing_script->get_feedback_message(), |
| 601 | - 'script'=> sprintf(__("%s Completed",'event_espresso'),$currently_executing_script->pretty_name()) |
|
| 601 | + 'script'=> sprintf(__("%s Completed", 'event_espresso'), $currently_executing_script->pretty_name()) |
|
| 602 | 602 | ); |
| 603 | 603 | //check if there are any more after this one. |
| 604 | 604 | $scripts_remaining = $this->check_for_applicable_data_migration_scripts(); |
| 605 | - if( ! $scripts_remaining ){ |
|
| 605 | + if ( ! $scripts_remaining) { |
|
| 606 | 606 | //we should be good to allow them to exit maintenance mode now |
| 607 | 607 | EE_Maintenance_Mode::instance()->set_maintenance_level(intval(EE_Maintenance_Mode::level_0_not_in_maintenance)); |
| 608 | 608 | ////huh, no more scripts to run... apparently we're done! |
@@ -616,39 +616,39 @@ discard block |
||
| 616 | 616 | 'records_to_migrate'=>$currently_executing_script->count_records_to_migrate(), |
| 617 | 617 | 'records_migrated'=>$currently_executing_script->count_records_migrated(), |
| 618 | 618 | 'status'=> $currently_executing_script->get_status(), |
| 619 | - 'message'=> sprintf(__("Minor errors occurred during %s: %s", "event_espresso"), $currently_executing_script->pretty_name(), implode(", ",$currently_executing_script->get_errors())), |
|
| 619 | + 'message'=> sprintf(__("Minor errors occurred during %s: %s", "event_espresso"), $currently_executing_script->pretty_name(), implode(", ", $currently_executing_script->get_errors())), |
|
| 620 | 620 | 'script'=>$currently_executing_script->pretty_name() |
| 621 | 621 | ); |
| 622 | 622 | break; |
| 623 | 623 | } |
| 624 | - }catch(Exception $e){ |
|
| 624 | + } catch (Exception $e) { |
|
| 625 | 625 | //ok so some exception was thrown which killed the data migration script |
| 626 | 626 | //double-check we have a real script |
| 627 | - if($currently_executing_script instanceof EE_Data_Migration_Script_Base){ |
|
| 627 | + if ($currently_executing_script instanceof EE_Data_Migration_Script_Base) { |
|
| 628 | 628 | $script_name = $currently_executing_script->pretty_name(); |
| 629 | 629 | $currently_executing_script->set_broken(); |
| 630 | 630 | $currently_executing_script->add_error($e->getMessage()); |
| 631 | - }else{ |
|
| 631 | + } else { |
|
| 632 | 632 | $script_name = __("Error getting Migration Script", "event_espresso"); |
| 633 | 633 | } |
| 634 | 634 | $response_array = array( |
| 635 | 635 | 'records_to_migrate'=>1, |
| 636 | 636 | 'records_migrated'=>0, |
| 637 | 637 | 'status'=>self::status_fatal_error, |
| 638 | - 'message'=> sprintf(__("A fatal error occurred during the migration: %s", "event_espresso"),$e->getMessage()), |
|
| 638 | + 'message'=> sprintf(__("A fatal error occurred during the migration: %s", "event_espresso"), $e->getMessage()), |
|
| 639 | 639 | 'script'=>$script_name |
| 640 | 640 | ); |
| 641 | 641 | } |
| 642 | 642 | $successful_save = $this->_save_migrations_ran(); |
| 643 | - if($successful_save !== TRUE){ |
|
| 643 | + if ($successful_save !== TRUE) { |
|
| 644 | 644 | //ok so the current wp option didn't save. that's tricky, because we'd like to update it |
| 645 | 645 | //and mark it as having a fatal error, but remember- WE CAN'T SAVE THIS WP OPTION! |
| 646 | 646 | //however, if we throw an exception, and return that, then the next request |
| 647 | 647 | //won't have as much info in it, and it may be able to save |
| 648 | - throw new EE_Error(sprintf(__("The error '%s' occurred updating the status of the migration. This is a FATAL ERROR, but the error is preventing the system from remembering that. Please contact event espresso support.", "event_espresso"),$successful_save)); |
|
| 648 | + throw new EE_Error(sprintf(__("The error '%s' occurred updating the status of the migration. This is a FATAL ERROR, but the error is preventing the system from remembering that. Please contact event espresso support.", "event_espresso"), $successful_save)); |
|
| 649 | 649 | } |
| 650 | 650 | //if we're all done, initialize EE plugins' default data etc. |
| 651 | - if( $init_dbs ) { |
|
| 651 | + if ($init_dbs) { |
|
| 652 | 652 | $this->initialize_db_for_enqueued_ee_plugins(); |
| 653 | 653 | } |
| 654 | 654 | return $response_array; |
@@ -666,23 +666,23 @@ discard block |
||
| 666 | 666 | * 'message'=>a string, containing any message you want to show to the user. We may decide to split this up into errors, notifications, and successes |
| 667 | 667 | * 'script'=>a pretty name of the script currently running |
| 668 | 668 | */ |
| 669 | - public function response_to_migration_ajax_request(){ |
|
| 669 | + public function response_to_migration_ajax_request() { |
|
| 670 | 670 | // //start output buffer just to make sure we don't mess up the json |
| 671 | 671 | ob_start(); |
| 672 | - try{ |
|
| 672 | + try { |
|
| 673 | 673 | $response = $this->migration_step(); |
| 674 | - }catch(Exception $e){ |
|
| 674 | + } catch (Exception $e) { |
|
| 675 | 675 | $response = array( |
| 676 | 676 | 'records_to_migrate'=>0, |
| 677 | 677 | 'records_migrated'=>0, |
| 678 | 678 | 'status'=> EE_Data_Migration_Manager::status_fatal_error, |
| 679 | - 'message'=> sprintf(__("Unknown fatal error occurred: %s", "event_espresso"),$e->getMessage()), |
|
| 679 | + 'message'=> sprintf(__("Unknown fatal error occurred: %s", "event_espresso"), $e->getMessage()), |
|
| 680 | 680 | 'script'=>'Unknown'); |
| 681 | 681 | $this->add_error_to_migrations_ran($e->getMessage()."; Stack trace:".$e->getTraceAsString()); |
| 682 | 682 | } |
| 683 | 683 | $warnings_etc = @ob_get_contents(); |
| 684 | 684 | ob_end_clean(); |
| 685 | - $response['message'] .=$warnings_etc; |
|
| 685 | + $response['message'] .= $warnings_etc; |
|
| 686 | 686 | return $response; |
| 687 | 687 | } |
| 688 | 688 | |
@@ -695,14 +695,14 @@ discard block |
||
| 695 | 695 | * } |
| 696 | 696 | * @return void |
| 697 | 697 | */ |
| 698 | - public function update_current_database_state_to($slug_and_version = null){ |
|
| 699 | - if( ! $slug_and_version ){ |
|
| 698 | + public function update_current_database_state_to($slug_and_version = null) { |
|
| 699 | + if ( ! $slug_and_version) { |
|
| 700 | 700 | //no version was provided, assume it should be at the current code version |
| 701 | 701 | $slug_and_version = array('slug' => 'Core', 'version' => espresso_version()); |
| 702 | 702 | } |
| 703 | 703 | $current_database_state = get_option(self::current_database_state); |
| 704 | - $current_database_state[ $slug_and_version[ 'slug' ] ]=$slug_and_version[ 'version' ]; |
|
| 705 | - update_option(self::current_database_state,$current_database_state); |
|
| 704 | + $current_database_state[$slug_and_version['slug']] = $slug_and_version['version']; |
|
| 705 | + update_option(self::current_database_state, $current_database_state); |
|
| 706 | 706 | } |
| 707 | 707 | |
| 708 | 708 | /** |
@@ -713,20 +713,20 @@ discard block |
||
| 713 | 713 | * } |
| 714 | 714 | * @return boolean |
| 715 | 715 | */ |
| 716 | - public function database_needs_updating_to( $slug_and_version ) { |
|
| 716 | + public function database_needs_updating_to($slug_and_version) { |
|
| 717 | 717 | |
| 718 | - $slug = $slug_and_version[ 'slug' ]; |
|
| 719 | - $version = $slug_and_version[ 'version' ]; |
|
| 718 | + $slug = $slug_and_version['slug']; |
|
| 719 | + $version = $slug_and_version['version']; |
|
| 720 | 720 | $current_database_state = get_option(self::current_database_state); |
| 721 | - if( ! isset( $current_database_state[ $slug ] ) ) { |
|
| 721 | + if ( ! isset($current_database_state[$slug])) { |
|
| 722 | 722 | return true; |
| 723 | - }else{ |
|
| 723 | + } else { |
|
| 724 | 724 | //just compare the first 3 parts of version string, eg "4.7.1", not "4.7.1.dev.032" because DBs shouldn't change on nano version changes |
| 725 | - $version_parts_current_db_state = array_slice( explode('.', $current_database_state[ $slug ] ), 0, 3); |
|
| 726 | - $version_parts_of_provided_db_state = array_slice( explode( '.', $version ), 0, 3 ); |
|
| 725 | + $version_parts_current_db_state = array_slice(explode('.', $current_database_state[$slug]), 0, 3); |
|
| 726 | + $version_parts_of_provided_db_state = array_slice(explode('.', $version), 0, 3); |
|
| 727 | 727 | $needs_updating = false; |
| 728 | - foreach($version_parts_current_db_state as $offset => $version_part_in_current_db_state ) { |
|
| 729 | - if( $version_part_in_current_db_state < $version_parts_of_provided_db_state[ $offset ] ) { |
|
| 728 | + foreach ($version_parts_current_db_state as $offset => $version_part_in_current_db_state) { |
|
| 729 | + if ($version_part_in_current_db_state < $version_parts_of_provided_db_state[$offset]) { |
|
| 730 | 730 | $needs_updating = true; |
| 731 | 731 | break; |
| 732 | 732 | } |
@@ -748,7 +748,7 @@ discard block |
||
| 748 | 748 | */ |
| 749 | 749 | public function get_all_data_migration_scripts_available() |
| 750 | 750 | { |
| 751 | - if (! $this->_data_migration_class_to_filepath_map) { |
|
| 751 | + if ( ! $this->_data_migration_class_to_filepath_map) { |
|
| 752 | 752 | $this->_data_migration_class_to_filepath_map = array(); |
| 753 | 753 | foreach ($this->get_data_migration_script_folders() as $eeAddonClass => $folder_path) { |
| 754 | 754 | // strip any placeholders added to classname to make it a unique array key |
@@ -757,7 +757,7 @@ discard block |
||
| 757 | 757 | ? $eeAddonClass |
| 758 | 758 | : ''; |
| 759 | 759 | $folder_path = EEH_File::end_with_directory_separator($folder_path); |
| 760 | - $files = glob($folder_path . '*.dms.php'); |
|
| 760 | + $files = glob($folder_path.'*.dms.php'); |
|
| 761 | 761 | if (empty($files)) { |
| 762 | 762 | continue; |
| 763 | 763 | } |
@@ -783,7 +783,7 @@ discard block |
||
| 783 | 783 | '4.3.0.alpha.019' |
| 784 | 784 | ); |
| 785 | 785 | } |
| 786 | - $this->_data_migration_class_to_filepath_map[ $classname ] = $file; |
|
| 786 | + $this->_data_migration_class_to_filepath_map[$classname] = $file; |
|
| 787 | 787 | } |
| 788 | 788 | } |
| 789 | 789 | EEH_Autoloader::register_autoloader($this->_data_migration_class_to_filepath_map); |
@@ -798,7 +798,7 @@ discard block |
||
| 798 | 798 | * from each addon, and check if they need updating, |
| 799 | 799 | * @return boolean |
| 800 | 800 | */ |
| 801 | - public function addons_need_updating(){ |
|
| 801 | + public function addons_need_updating() { |
|
| 802 | 802 | return false; |
| 803 | 803 | } |
| 804 | 804 | /** |
@@ -807,25 +807,25 @@ discard block |
||
| 807 | 807 | * @param string $error_message |
| 808 | 808 | * @throws EE_Error |
| 809 | 809 | */ |
| 810 | - public function add_error_to_migrations_ran($error_message){ |
|
| 810 | + public function add_error_to_migrations_ran($error_message) { |
|
| 811 | 811 | //get last-ran migration script |
| 812 | 812 | global $wpdb; |
| 813 | - $last_migration_script_option = $wpdb->get_row("SELECT * FROM $wpdb->options WHERE option_name like '".EE_Data_Migration_Manager::data_migration_script_option_prefix."%' ORDER BY option_id DESC LIMIT 1",ARRAY_A); |
|
| 813 | + $last_migration_script_option = $wpdb->get_row("SELECT * FROM $wpdb->options WHERE option_name like '".EE_Data_Migration_Manager::data_migration_script_option_prefix."%' ORDER BY option_id DESC LIMIT 1", ARRAY_A); |
|
| 814 | 814 | |
| 815 | 815 | $last_ran_migration_script_properties = isset($last_migration_script_option['option_value']) ? maybe_unserialize($last_migration_script_option['option_value']) : null; |
| 816 | 816 | //now, tread lightly because we're here because a FATAL non-catchable error |
| 817 | 817 | //was thrown last time when we were trying to run a data migration script |
| 818 | 818 | //so the fatal error could have happened while getting the migration script |
| 819 | 819 | //or doing running it... |
| 820 | - $versions_migrated_to = isset($last_migration_script_option['option_name']) ? str_replace(EE_Data_Migration_Manager::data_migration_script_option_prefix,"",$last_migration_script_option['option_name']) : null; |
|
| 820 | + $versions_migrated_to = isset($last_migration_script_option['option_name']) ? str_replace(EE_Data_Migration_Manager::data_migration_script_option_prefix, "", $last_migration_script_option['option_name']) : null; |
|
| 821 | 821 | |
| 822 | 822 | //check if it THINKS its a data migration script and especially if it's one that HASN'T finished yet |
| 823 | 823 | //because if it has finished, then it obviously couldn't be the cause of this error, right? (because its all done) |
| 824 | - if(isset($last_ran_migration_script_properties['class']) && isset($last_ran_migration_script_properties['_status']) && $last_ran_migration_script_properties['_status'] != self::status_completed){ |
|
| 824 | + if (isset($last_ran_migration_script_properties['class']) && isset($last_ran_migration_script_properties['_status']) && $last_ran_migration_script_properties['_status'] != self::status_completed) { |
|
| 825 | 825 | //ok then just add this error to its list of errors |
| 826 | 826 | $last_ran_migration_script_properties['_errors'][] = $error_message; |
| 827 | 827 | $last_ran_migration_script_properties['_status'] = self::status_fatal_error; |
| 828 | - }else{ |
|
| 828 | + } else { |
|
| 829 | 829 | //so we don't even know which script was last running |
| 830 | 830 | //use the data migration error stub, which is designed specifically for this type of thing |
| 831 | 831 | $general_migration_error = new EE_DMS_Unknown_1_0_0(); |
@@ -835,39 +835,39 @@ discard block |
||
| 835 | 835 | $versions_migrated_to = 'Unknown.1.0.0'; |
| 836 | 836 | //now just to make sure appears as last (in case the were previously a fatal error like this) |
| 837 | 837 | //delete the old one |
| 838 | - delete_option( self::data_migration_script_option_prefix . $versions_migrated_to ); |
|
| 838 | + delete_option(self::data_migration_script_option_prefix.$versions_migrated_to); |
|
| 839 | 839 | } |
| 840 | - update_option(self::data_migration_script_option_prefix.$versions_migrated_to,$last_ran_migration_script_properties); |
|
| 840 | + update_option(self::data_migration_script_option_prefix.$versions_migrated_to, $last_ran_migration_script_properties); |
|
| 841 | 841 | |
| 842 | 842 | } |
| 843 | 843 | /** |
| 844 | 844 | * saves what data migrations have ran to the database |
| 845 | 845 | * @return mixed TRUE if successfully saved migrations ran, string if an error occurred |
| 846 | 846 | */ |
| 847 | - protected function _save_migrations_ran(){ |
|
| 848 | - if($this->_data_migrations_ran == null){ |
|
| 847 | + protected function _save_migrations_ran() { |
|
| 848 | + if ($this->_data_migrations_ran == null) { |
|
| 849 | 849 | $this->get_data_migrations_ran(); |
| 850 | 850 | } |
| 851 | 851 | //now, we don't want to save actual classes to the DB because that's messy |
| 852 | 852 | $successful_updates = true; |
| 853 | - foreach($this->_data_migrations_ran as $plugin_slug => $migrations_ran_for_plugin){ |
|
| 854 | - foreach($migrations_ran_for_plugin as $version_string => $array_or_migration_obj){ |
|
| 853 | + foreach ($this->_data_migrations_ran as $plugin_slug => $migrations_ran_for_plugin) { |
|
| 854 | + foreach ($migrations_ran_for_plugin as $version_string => $array_or_migration_obj) { |
|
| 855 | 855 | // echo "saving migration script to $version_string<br>"; |
| 856 | 856 | $plugin_slug_for_use_in_option_name = $plugin_slug."."; |
| 857 | 857 | $option_name = self::data_migration_script_option_prefix.$plugin_slug_for_use_in_option_name.$version_string; |
| 858 | 858 | $old_option_value = get_option($option_name); |
| 859 | - if($array_or_migration_obj instanceof EE_Data_Migration_Script_Base){ |
|
| 859 | + if ($array_or_migration_obj instanceof EE_Data_Migration_Script_Base) { |
|
| 860 | 860 | $script_array_for_saving = $array_or_migration_obj->properties_as_array(); |
| 861 | - if( $old_option_value != $script_array_for_saving){ |
|
| 862 | - $successful_updates = update_option($option_name,$script_array_for_saving); |
|
| 861 | + if ($old_option_value != $script_array_for_saving) { |
|
| 862 | + $successful_updates = update_option($option_name, $script_array_for_saving); |
|
| 863 | 863 | } |
| 864 | - }else{//we don't know what this array-thing is. So just save it as-is |
|
| 864 | + } else {//we don't know what this array-thing is. So just save it as-is |
|
| 865 | 865 | // $array_of_migrations[$version_string] = $array_or_migration_obj; |
| 866 | - if($old_option_value != $array_or_migration_obj){ |
|
| 867 | - $successful_updates = update_option($option_name,$array_or_migration_obj); |
|
| 866 | + if ($old_option_value != $array_or_migration_obj) { |
|
| 867 | + $successful_updates = update_option($option_name, $array_or_migration_obj); |
|
| 868 | 868 | } |
| 869 | 869 | } |
| 870 | - if( ! $successful_updates ){ |
|
| 870 | + if ( ! $successful_updates) { |
|
| 871 | 871 | global $wpdb; |
| 872 | 872 | return $wpdb->last_error; |
| 873 | 873 | } |
@@ -891,17 +891,17 @@ discard block |
||
| 891 | 891 | * @return EE_Data_Migration_Script_Base |
| 892 | 892 | * @throws EE_Error |
| 893 | 893 | */ |
| 894 | - function _instantiate_script_from_properties_array($properties_array){ |
|
| 895 | - if( ! isset($properties_array['class'])){ |
|
| 896 | - throw new EE_Error(sprintf(__("Properties array has no 'class' properties. Here's what it has: %s", "event_espresso"),implode(",",$properties_array))); |
|
| 894 | + function _instantiate_script_from_properties_array($properties_array) { |
|
| 895 | + if ( ! isset($properties_array['class'])) { |
|
| 896 | + throw new EE_Error(sprintf(__("Properties array has no 'class' properties. Here's what it has: %s", "event_espresso"), implode(",", $properties_array))); |
|
| 897 | 897 | } |
| 898 | 898 | $class_name = $properties_array['class']; |
| 899 | - if( ! class_exists($class_name)){ |
|
| 900 | - throw new EE_Error(sprintf(__("There is no migration script named %s", "event_espresso"),$class_name)); |
|
| 899 | + if ( ! class_exists($class_name)) { |
|
| 900 | + throw new EE_Error(sprintf(__("There is no migration script named %s", "event_espresso"), $class_name)); |
|
| 901 | 901 | } |
| 902 | 902 | $class = new $class_name; |
| 903 | - if( ! $class instanceof EE_Data_Migration_Script_Base){ |
|
| 904 | - throw new EE_Error(sprintf(__("Class '%s' is supposed to be a migration script. Its not, its a '%s'", "event_espresso"),$class_name,get_class($class))); |
|
| 903 | + if ( ! $class instanceof EE_Data_Migration_Script_Base) { |
|
| 904 | + throw new EE_Error(sprintf(__("Class '%s' is supposed to be a migration script. Its not, its a '%s'", "event_espresso"), $class_name, get_class($class))); |
|
| 905 | 905 | } |
| 906 | 906 | $class->instantiate_from_array_of_properties($properties_array); |
| 907 | 907 | return $class; |
@@ -913,25 +913,25 @@ discard block |
||
| 913 | 913 | * @param string $plugin_slug the slug for the ee plugin we are searching for. Default is 'Core' |
| 914 | 914 | * @return string |
| 915 | 915 | */ |
| 916 | - public function get_most_up_to_date_dms($plugin_slug = 'Core'){ |
|
| 916 | + public function get_most_up_to_date_dms($plugin_slug = 'Core') { |
|
| 917 | 917 | $class_to_filepath_map = $this->get_all_data_migration_scripts_available(); |
| 918 | 918 | $most_up_to_date_dms_classname = NULL; |
| 919 | - foreach($class_to_filepath_map as $classname => $filepath){ |
|
| 920 | - if($most_up_to_date_dms_classname === NULL){ |
|
| 919 | + foreach ($class_to_filepath_map as $classname => $filepath) { |
|
| 920 | + if ($most_up_to_date_dms_classname === NULL) { |
|
| 921 | 921 | $migrates_to = $this->script_migrates_to_version($classname); |
| 922 | - $this_plugin_slug = $migrates_to[ 'slug' ]; |
|
| 922 | + $this_plugin_slug = $migrates_to['slug']; |
|
| 923 | 923 | // $version_string = $migrates_to[ 'version' ]; |
| 924 | 924 | // $details = $this->parse_dms_classname($classname); |
| 925 | - if($this_plugin_slug == $plugin_slug){ |
|
| 925 | + if ($this_plugin_slug == $plugin_slug) { |
|
| 926 | 926 | //if it's for core, it wins |
| 927 | 927 | $most_up_to_date_dms_classname = $classname; |
| 928 | 928 | } |
| 929 | 929 | //if it wasn't for core, we must keep searching for one that is! |
| 930 | 930 | continue; |
| 931 | - }else{ |
|
| 932 | - $champion_migrates_to= $this->script_migrates_to_version($most_up_to_date_dms_classname); |
|
| 931 | + } else { |
|
| 932 | + $champion_migrates_to = $this->script_migrates_to_version($most_up_to_date_dms_classname); |
|
| 933 | 933 | $contender_migrates_to = $this->script_migrates_to_version($classname); |
| 934 | - if($contender_migrates_to[ 'slug' ] == $plugin_slug && version_compare($champion_migrates_to[ 'version' ], $contender_migrates_to[ 'version' ], '<')){ |
|
| 934 | + if ($contender_migrates_to['slug'] == $plugin_slug && version_compare($champion_migrates_to['version'], $contender_migrates_to['version'], '<')) { |
|
| 935 | 935 | //so the contenders version is higher and its for Core |
| 936 | 936 | $most_up_to_date_dms_classname = $classname; |
| 937 | 937 | } |
@@ -951,11 +951,11 @@ discard block |
||
| 951 | 951 | * @param string $plugin_slug like 'Core', 'Mailchimp', 'Calendar', etc |
| 952 | 952 | * @return EE_Data_Migration_Script_Base |
| 953 | 953 | */ |
| 954 | - public function get_migration_ran( $version, $plugin_slug = 'Core' ) { |
|
| 954 | + public function get_migration_ran($version, $plugin_slug = 'Core') { |
|
| 955 | 955 | $migrations_ran = $this->get_data_migrations_ran(); |
| 956 | - if( isset( $migrations_ran[ $plugin_slug ] ) && isset( $migrations_ran[ $plugin_slug ][ $version ] ) ){ |
|
| 957 | - return $migrations_ran[ $plugin_slug ][ $version ]; |
|
| 958 | - }else{ |
|
| 956 | + if (isset($migrations_ran[$plugin_slug]) && isset($migrations_ran[$plugin_slug][$version])) { |
|
| 957 | + return $migrations_ran[$plugin_slug][$version]; |
|
| 958 | + } else { |
|
| 959 | 959 | return NULL; |
| 960 | 960 | } |
| 961 | 961 | } |
@@ -967,20 +967,20 @@ discard block |
||
| 967 | 967 | * @return bool |
| 968 | 968 | * @throws EE_Error |
| 969 | 969 | */ |
| 970 | - public function reattempt(){ |
|
| 970 | + public function reattempt() { |
|
| 971 | 971 | //find if the last-ran script was borked |
| 972 | 972 | //set it as being non-borked (we shouldn't ever get DMSs that we don't recognize) |
| 973 | 973 | //add an 'error' saying that we attempted to reset |
| 974 | 974 | //does it have a stage that was borked too? if so make it no longer borked |
| 975 | 975 | //add an 'error' saying we attempted to reset |
| 976 | 976 | $last_ran_script = $this->get_last_ran_script(); |
| 977 | - if( $last_ran_script instanceof EE_DMS_Unknown_1_0_0 ){ |
|
| 977 | + if ($last_ran_script instanceof EE_DMS_Unknown_1_0_0) { |
|
| 978 | 978 | //if it was an error DMS, just mark it as complete (if another error occurs it will overwrite it) |
| 979 | 979 | $last_ran_script->set_completed(); |
| 980 | - }elseif( $last_ran_script instanceof EE_Data_Migration_Script_Base ) { |
|
| 980 | + }elseif ($last_ran_script instanceof EE_Data_Migration_Script_Base) { |
|
| 981 | 981 | $last_ran_script->reattempt(); |
| 982 | - }else{ |
|
| 983 | - throw new EE_Error( sprintf( __( 'Unable to reattempt the last ran migration script because it was not a valid migration script. || It was %s', 'event_espresso' ), print_r( $last_ran_script, true ) ) ); |
|
| 982 | + } else { |
|
| 983 | + throw new EE_Error(sprintf(__('Unable to reattempt the last ran migration script because it was not a valid migration script. || It was %s', 'event_espresso'), print_r($last_ran_script, true))); |
|
| 984 | 984 | } |
| 985 | 985 | return $this->_save_migrations_ran(); |
| 986 | 986 | } |
@@ -990,19 +990,19 @@ discard block |
||
| 990 | 990 | * @param string $plugin_slug like 'Core', 'Mailchimp', 'Calendar', etc |
| 991 | 991 | * @return boolean |
| 992 | 992 | */ |
| 993 | - public function migration_has_ran( $version, $plugin_slug = 'Core' ) { |
|
| 994 | - return $this->get_migration_ran( $version, $plugin_slug ) !== NULL; |
|
| 993 | + public function migration_has_ran($version, $plugin_slug = 'Core') { |
|
| 994 | + return $this->get_migration_ran($version, $plugin_slug) !== NULL; |
|
| 995 | 995 | } |
| 996 | 996 | /** |
| 997 | 997 | * Enqueues this ee plugin to have its data initialized |
| 998 | 998 | * @param string $plugin_slug either 'Core' or EE_Addon::name()'s return value |
| 999 | 999 | */ |
| 1000 | - public function enqueue_db_initialization_for( $plugin_slug ) { |
|
| 1000 | + public function enqueue_db_initialization_for($plugin_slug) { |
|
| 1001 | 1001 | $queue = $this->get_db_initialization_queue(); |
| 1002 | - if( ! in_array( $plugin_slug, $queue ) ) { |
|
| 1002 | + if ( ! in_array($plugin_slug, $queue)) { |
|
| 1003 | 1003 | $queue[] = $plugin_slug; |
| 1004 | 1004 | } |
| 1005 | - update_option( self::db_init_queue_option_name, $queue ); |
|
| 1005 | + update_option(self::db_init_queue_option_name, $queue); |
|
| 1006 | 1006 | } |
| 1007 | 1007 | /** |
| 1008 | 1008 | * Calls EE_Addon::initialize_db_if_no_migrations_required() on each addon |
@@ -1012,26 +1012,26 @@ discard block |
||
| 1012 | 1012 | public function initialize_db_for_enqueued_ee_plugins() { |
| 1013 | 1013 | // EEH_Debug_Tools::instance()->start_timer( 'initialize_db_for_enqueued_ee_plugins' ); |
| 1014 | 1014 | $queue = $this->get_db_initialization_queue(); |
| 1015 | - foreach( $queue as $plugin_slug ) { |
|
| 1016 | - $most_up_to_date_dms = $this->get_most_up_to_date_dms( $plugin_slug ); |
|
| 1017 | - if( ! $most_up_to_date_dms ) { |
|
| 1015 | + foreach ($queue as $plugin_slug) { |
|
| 1016 | + $most_up_to_date_dms = $this->get_most_up_to_date_dms($plugin_slug); |
|
| 1017 | + if ( ! $most_up_to_date_dms) { |
|
| 1018 | 1018 | //if there is NO DMS for this plugin, obviously there's no schema to verify anyways |
| 1019 | 1019 | $verify_db = false; |
| 1020 | - }else{ |
|
| 1021 | - $most_up_to_date_dms_migrates_to = $this->script_migrates_to_version( $most_up_to_date_dms ); |
|
| 1022 | - $verify_db = $this->database_needs_updating_to( $most_up_to_date_dms_migrates_to ); |
|
| 1020 | + } else { |
|
| 1021 | + $most_up_to_date_dms_migrates_to = $this->script_migrates_to_version($most_up_to_date_dms); |
|
| 1022 | + $verify_db = $this->database_needs_updating_to($most_up_to_date_dms_migrates_to); |
|
| 1023 | 1023 | } |
| 1024 | - if( $plugin_slug == 'Core' ){ |
|
| 1024 | + if ($plugin_slug == 'Core') { |
|
| 1025 | 1025 | EE_System::instance()->initialize_db_if_no_migrations_required( |
| 1026 | 1026 | false, |
| 1027 | 1027 | $verify_db |
| 1028 | 1028 | ); |
| 1029 | - }else{ |
|
| 1029 | + } else { |
|
| 1030 | 1030 | //just loop through the addons to make sure their database is setup |
| 1031 | - foreach( EE_Registry::instance()->addons as $addon ) { |
|
| 1032 | - if( $addon->name() == $plugin_slug ) { |
|
| 1031 | + foreach (EE_Registry::instance()->addons as $addon) { |
|
| 1032 | + if ($addon->name() == $plugin_slug) { |
|
| 1033 | 1033 | |
| 1034 | - $addon->initialize_db_if_no_migrations_required( $verify_db ); |
|
| 1034 | + $addon->initialize_db_if_no_migrations_required($verify_db); |
|
| 1035 | 1035 | break; |
| 1036 | 1036 | } |
| 1037 | 1037 | } |
@@ -1041,7 +1041,7 @@ discard block |
||
| 1041 | 1041 | // EEH_Debug_Tools::instance()->show_times(); |
| 1042 | 1042 | //because we just initialized the DBs for the enqueued ee plugins |
| 1043 | 1043 | //we don't need to keep remembering which ones needed to be initialized |
| 1044 | - delete_option( self::db_init_queue_option_name ); |
|
| 1044 | + delete_option(self::db_init_queue_option_name); |
|
| 1045 | 1045 | } |
| 1046 | 1046 | |
| 1047 | 1047 | /** |
@@ -1050,8 +1050,8 @@ discard block |
||
| 1050 | 1050 | * 'Core', or the return value of EE_Addon::name() for an addon |
| 1051 | 1051 | * @return array |
| 1052 | 1052 | */ |
| 1053 | - public function get_db_initialization_queue(){ |
|
| 1054 | - return get_option ( self::db_init_queue_option_name, array() ); |
|
| 1053 | + public function get_db_initialization_queue() { |
|
| 1054 | + return get_option(self::db_init_queue_option_name, array()); |
|
| 1055 | 1055 | } |
| 1056 | 1056 | |
| 1057 | 1057 | /** |
@@ -1061,13 +1061,13 @@ discard block |
||
| 1061 | 1061 | * @throws EE_Error |
| 1062 | 1062 | */ |
| 1063 | 1063 | protected function _get_table_analysis() { |
| 1064 | - if( $this->_table_analysis instanceof TableAnalysis ) { |
|
| 1064 | + if ($this->_table_analysis instanceof TableAnalysis) { |
|
| 1065 | 1065 | return $this->_table_analysis; |
| 1066 | 1066 | } else { |
| 1067 | 1067 | throw new EE_Error( |
| 1068 | 1068 | sprintf( |
| 1069 | - __( 'Table analysis class on class %1$s is not set properly.', 'event_espresso'), |
|
| 1070 | - get_class( $this ) |
|
| 1069 | + __('Table analysis class on class %1$s is not set properly.', 'event_espresso'), |
|
| 1070 | + get_class($this) |
|
| 1071 | 1071 | ) |
| 1072 | 1072 | ); |
| 1073 | 1073 | } |
@@ -1080,13 +1080,13 @@ discard block |
||
| 1080 | 1080 | * @throws EE_Error |
| 1081 | 1081 | */ |
| 1082 | 1082 | protected function _get_table_manager() { |
| 1083 | - if( $this->_table_manager instanceof TableManager ) { |
|
| 1083 | + if ($this->_table_manager instanceof TableManager) { |
|
| 1084 | 1084 | return $this->_table_manager; |
| 1085 | 1085 | } else { |
| 1086 | 1086 | throw new EE_Error( |
| 1087 | 1087 | sprintf( |
| 1088 | - __( 'Table manager class on class %1$s is not set properly.', 'event_espresso'), |
|
| 1089 | - get_class( $this ) |
|
| 1088 | + __('Table manager class on class %1$s is not set properly.', 'event_espresso'), |
|
| 1089 | + get_class($this) |
|
| 1090 | 1090 | ) |
| 1091 | 1091 | ); |
| 1092 | 1092 | } |
@@ -25,1152 +25,1152 @@ |
||
| 25 | 25 | class EE_Register_Addon implements EEI_Plugin_API |
| 26 | 26 | { |
| 27 | 27 | |
| 28 | - /** |
|
| 29 | - * possibly truncated version of the EE core version string |
|
| 30 | - * |
|
| 31 | - * @var string |
|
| 32 | - */ |
|
| 33 | - protected static $_core_version = ''; |
|
| 28 | + /** |
|
| 29 | + * possibly truncated version of the EE core version string |
|
| 30 | + * |
|
| 31 | + * @var string |
|
| 32 | + */ |
|
| 33 | + protected static $_core_version = ''; |
|
| 34 | 34 | |
| 35 | - /** |
|
| 36 | - * Holds values for registered addons |
|
| 37 | - * |
|
| 38 | - * @var array |
|
| 39 | - */ |
|
| 40 | - protected static $_settings = array(); |
|
| 35 | + /** |
|
| 36 | + * Holds values for registered addons |
|
| 37 | + * |
|
| 38 | + * @var array |
|
| 39 | + */ |
|
| 40 | + protected static $_settings = array(); |
|
| 41 | 41 | |
| 42 | - /** |
|
| 43 | - * @var array $_incompatible_addons keys are addon SLUGS |
|
| 44 | - * (first argument passed to EE_Register_Addon::register()), keys are |
|
| 45 | - * their MINIMUM VERSION (with all 5 parts. Eg 1.2.3.rc.004). |
|
| 46 | - * Generally this should be used sparingly, as we don't want to muddle up |
|
| 47 | - * EE core with knowledge of ALL the addons out there. |
|
| 48 | - * If you want NO versions of an addon to run with a certain version of core, |
|
| 49 | - * it's usually best to define the addon's "min_core_version" as part of its call |
|
| 50 | - * to EE_Register_Addon::register(), rather than using this array with a super high value for its |
|
| 51 | - * minimum plugin version. |
|
| 52 | - * @access protected |
|
| 53 | - */ |
|
| 54 | - protected static $_incompatible_addons = array( |
|
| 55 | - 'Multi_Event_Registration' => '2.0.11.rc.002', |
|
| 56 | - 'Promotions' => '1.0.0.rc.084', |
|
| 57 | - ); |
|
| 42 | + /** |
|
| 43 | + * @var array $_incompatible_addons keys are addon SLUGS |
|
| 44 | + * (first argument passed to EE_Register_Addon::register()), keys are |
|
| 45 | + * their MINIMUM VERSION (with all 5 parts. Eg 1.2.3.rc.004). |
|
| 46 | + * Generally this should be used sparingly, as we don't want to muddle up |
|
| 47 | + * EE core with knowledge of ALL the addons out there. |
|
| 48 | + * If you want NO versions of an addon to run with a certain version of core, |
|
| 49 | + * it's usually best to define the addon's "min_core_version" as part of its call |
|
| 50 | + * to EE_Register_Addon::register(), rather than using this array with a super high value for its |
|
| 51 | + * minimum plugin version. |
|
| 52 | + * @access protected |
|
| 53 | + */ |
|
| 54 | + protected static $_incompatible_addons = array( |
|
| 55 | + 'Multi_Event_Registration' => '2.0.11.rc.002', |
|
| 56 | + 'Promotions' => '1.0.0.rc.084', |
|
| 57 | + ); |
|
| 58 | 58 | |
| 59 | 59 | |
| 60 | - /** |
|
| 61 | - * We should always be comparing core to a version like '4.3.0.rc.000', |
|
| 62 | - * not just '4.3.0'. |
|
| 63 | - * So if the addon developer doesn't provide that full version string, |
|
| 64 | - * fill in the blanks for them |
|
| 65 | - * |
|
| 66 | - * @param string $min_core_version |
|
| 67 | - * @return string always like '4.3.0.rc.000' |
|
| 68 | - */ |
|
| 69 | - protected static function _effective_version($min_core_version) |
|
| 70 | - { |
|
| 71 | - // versions: 4 . 3 . 1 . p . 123 |
|
| 72 | - // offsets: 0 . 1 . 2 . 3 . 4 |
|
| 73 | - $version_parts = explode('.', $min_core_version); |
|
| 74 | - //check they specified the micro version (after 2nd period) |
|
| 75 | - if (! isset($version_parts[2])) { |
|
| 76 | - $version_parts[2] = '0'; |
|
| 77 | - } |
|
| 78 | - //if they didn't specify the 'p', or 'rc' part. Just assume the lowest possible |
|
| 79 | - //soon we can assume that's 'rc', but this current version is 'alpha' |
|
| 80 | - if (! isset($version_parts[3])) { |
|
| 81 | - $version_parts[3] = 'dev'; |
|
| 82 | - } |
|
| 83 | - if (! isset($version_parts[4])) { |
|
| 84 | - $version_parts[4] = '000'; |
|
| 85 | - } |
|
| 86 | - return implode('.', $version_parts); |
|
| 87 | - } |
|
| 60 | + /** |
|
| 61 | + * We should always be comparing core to a version like '4.3.0.rc.000', |
|
| 62 | + * not just '4.3.0'. |
|
| 63 | + * So if the addon developer doesn't provide that full version string, |
|
| 64 | + * fill in the blanks for them |
|
| 65 | + * |
|
| 66 | + * @param string $min_core_version |
|
| 67 | + * @return string always like '4.3.0.rc.000' |
|
| 68 | + */ |
|
| 69 | + protected static function _effective_version($min_core_version) |
|
| 70 | + { |
|
| 71 | + // versions: 4 . 3 . 1 . p . 123 |
|
| 72 | + // offsets: 0 . 1 . 2 . 3 . 4 |
|
| 73 | + $version_parts = explode('.', $min_core_version); |
|
| 74 | + //check they specified the micro version (after 2nd period) |
|
| 75 | + if (! isset($version_parts[2])) { |
|
| 76 | + $version_parts[2] = '0'; |
|
| 77 | + } |
|
| 78 | + //if they didn't specify the 'p', or 'rc' part. Just assume the lowest possible |
|
| 79 | + //soon we can assume that's 'rc', but this current version is 'alpha' |
|
| 80 | + if (! isset($version_parts[3])) { |
|
| 81 | + $version_parts[3] = 'dev'; |
|
| 82 | + } |
|
| 83 | + if (! isset($version_parts[4])) { |
|
| 84 | + $version_parts[4] = '000'; |
|
| 85 | + } |
|
| 86 | + return implode('.', $version_parts); |
|
| 87 | + } |
|
| 88 | 88 | |
| 89 | 89 | |
| 90 | - /** |
|
| 91 | - * Returns whether or not the min core version requirement of the addon is met |
|
| 92 | - * |
|
| 93 | - * @param string $min_core_version the minimum core version required by the addon |
|
| 94 | - * @param string $actual_core_version the actual core version, optional |
|
| 95 | - * @return boolean |
|
| 96 | - */ |
|
| 97 | - public static function _meets_min_core_version_requirement( |
|
| 98 | - $min_core_version, |
|
| 99 | - $actual_core_version = EVENT_ESPRESSO_VERSION |
|
| 100 | - ) { |
|
| 101 | - return version_compare( |
|
| 102 | - self::_effective_version($actual_core_version), |
|
| 103 | - self::_effective_version($min_core_version), |
|
| 104 | - '>=' |
|
| 105 | - ); |
|
| 106 | - } |
|
| 90 | + /** |
|
| 91 | + * Returns whether or not the min core version requirement of the addon is met |
|
| 92 | + * |
|
| 93 | + * @param string $min_core_version the minimum core version required by the addon |
|
| 94 | + * @param string $actual_core_version the actual core version, optional |
|
| 95 | + * @return boolean |
|
| 96 | + */ |
|
| 97 | + public static function _meets_min_core_version_requirement( |
|
| 98 | + $min_core_version, |
|
| 99 | + $actual_core_version = EVENT_ESPRESSO_VERSION |
|
| 100 | + ) { |
|
| 101 | + return version_compare( |
|
| 102 | + self::_effective_version($actual_core_version), |
|
| 103 | + self::_effective_version($min_core_version), |
|
| 104 | + '>=' |
|
| 105 | + ); |
|
| 106 | + } |
|
| 107 | 107 | |
| 108 | 108 | |
| 109 | - /** |
|
| 110 | - * Method for registering new EE_Addons. |
|
| 111 | - * Should be called AFTER AHEE__EE_System__load_espresso_addons but BEFORE |
|
| 112 | - * AHEE__EE_System___detect_if_activation_or_upgrade__begin in order to register all its components. However, it |
|
| 113 | - * may also be called after the 'activate_plugin' action (when an addon is activated), because an activating addon |
|
| 114 | - * won't be loaded by WP until after AHEE__EE_System__load_espresso_addons has fired. If its called after |
|
| 115 | - * 'activate_plugin', it registers the addon still, but its components are not registered |
|
| 116 | - * (they shouldn't be needed anyways, because it's just an activation request and they won't have a chance to do |
|
| 117 | - * anything anyways). Instead, it just sets the newly-activated addon's activation indicator wp option and returns |
|
| 118 | - * (so that we can detect that the addon has activated on the subsequent request) |
|
| 119 | - * |
|
| 120 | - * @since 4.3.0 |
|
| 121 | - * @param string $addon_name [Required] the EE_Addon's name. |
|
| 122 | - * @param array $setup_args { |
|
| 123 | - * An array of arguments provided for registering |
|
| 124 | - * the message type. |
|
| 125 | - * @type string $class_name the addon's main file name. |
|
| 126 | - * If left blank, generated from the addon name, |
|
| 127 | - * changes something like "calendar" to |
|
| 128 | - * "EE_Calendar" |
|
| 129 | - * @type string $min_core_version the minimum version of EE Core that the |
|
| 130 | - * addon will work with. eg "4.8.1.rc.084" |
|
| 131 | - * @type string $version the "software" version for the addon. eg |
|
| 132 | - * "1.0.0.p" for a first stable release, or |
|
| 133 | - * "1.0.0.rc.043" for a version in progress |
|
| 134 | - * @type string $main_file_path the full server path to the main file |
|
| 135 | - * loaded directly by WP |
|
| 136 | - * @type string $domain_fqcn Fully Qualified Class Name |
|
| 137 | - * for the addon's Domain class |
|
| 138 | - * (see EventEspresso\core\domain\Domain) |
|
| 139 | - * @type string $admin_path full server path to the folder where the |
|
| 140 | - * addon\'s admin files reside |
|
| 141 | - * @type string $admin_callback a method to be called when the EE Admin is |
|
| 142 | - * first invoked, can be used for hooking into |
|
| 143 | - * any admin page |
|
| 144 | - * @type string $config_section the section name for this addon's |
|
| 145 | - * configuration settings section |
|
| 146 | - * (defaults to "addons") |
|
| 147 | - * @type string $config_class the class name for this addon's |
|
| 148 | - * configuration settings object |
|
| 149 | - * @type string $config_name the class name for this addon's |
|
| 150 | - * configuration settings object |
|
| 151 | - * @type string $autoloader_paths [Required] an array of class names and the full |
|
| 152 | - * server paths to those files. |
|
| 153 | - * @type string $autoloader_folders an array of "full server paths" for any |
|
| 154 | - * folders containing classes that might be |
|
| 155 | - * invoked by the addon |
|
| 156 | - * @type string $dms_paths [Required] an array of full server paths to |
|
| 157 | - * folders that contain data migration scripts. |
|
| 158 | - * The key should be the EE_Addon class name that |
|
| 159 | - * this set of data migration scripts belongs to. |
|
| 160 | - * If the EE_Addon class is namespaced, then this |
|
| 161 | - * needs to be the Fully Qualified Class Name |
|
| 162 | - * @type string $module_paths an array of full server paths to any |
|
| 163 | - * EED_Modules used by the addon |
|
| 164 | - * @type string $shortcode_paths an array of full server paths to folders |
|
| 165 | - * that contain EES_Shortcodes |
|
| 166 | - * @type string $widget_paths an array of full server paths to folders |
|
| 167 | - * that contain WP_Widgets |
|
| 168 | - * @type string $pue_options |
|
| 169 | - * @type array $capabilities an array indexed by role name |
|
| 170 | - * (i.e administrator,author ) and the values |
|
| 171 | - * are an array of caps to add to the role. |
|
| 172 | - * 'administrator' => array( |
|
| 173 | - * 'read_addon', |
|
| 174 | - * 'edit_addon', |
|
| 175 | - * etc. |
|
| 176 | - * ). |
|
| 177 | - * @type EE_Meta_Capability_Map[] $capability_maps an array of EE_Meta_Capability_Map object |
|
| 178 | - * for any addons that need to register any |
|
| 179 | - * special meta mapped capabilities. Should |
|
| 180 | - * be indexed where the key is the |
|
| 181 | - * EE_Meta_Capability_Map class name and the |
|
| 182 | - * values are the arguments sent to the class. |
|
| 183 | - * @type array $model_paths array of folders containing DB models |
|
| 184 | - * @see EE_Register_Model |
|
| 185 | - * @type array $class_paths array of folders containing DB classes |
|
| 186 | - * @see EE_Register_Model |
|
| 187 | - * @type array $model_extension_paths array of folders containing DB model |
|
| 188 | - * extensions |
|
| 189 | - * @see EE_Register_Model_Extension |
|
| 190 | - * @type array $class_extension_paths array of folders containing DB class |
|
| 191 | - * extensions |
|
| 192 | - * @see EE_Register_Model_Extension |
|
| 193 | - * @type array message_types { |
|
| 194 | - * An array of message types with the key as |
|
| 195 | - * the message type name and the values as |
|
| 196 | - * below: |
|
| 197 | - * @type string $mtfilename [Required] The filename of the message type |
|
| 198 | - * being registered. This will be the main |
|
| 199 | - * EE_{Message Type Name}_message_type class. |
|
| 200 | - * for example: |
|
| 201 | - * EE_Declined_Registration_message_type.class.php |
|
| 202 | - * @type array $autoloadpaths [Required] An array of paths to add to the |
|
| 203 | - * messages autoloader for the new message type. |
|
| 204 | - * @type array $messengers_to_activate_with An array of messengers that this message |
|
| 205 | - * type should activate with. Each value in |
|
| 206 | - * the |
|
| 207 | - * array |
|
| 208 | - * should match the name property of a |
|
| 209 | - * EE_messenger. Optional. |
|
| 210 | - * @type array $messengers_to_validate_with An array of messengers that this message |
|
| 211 | - * type should validate with. Each value in |
|
| 212 | - * the |
|
| 213 | - * array |
|
| 214 | - * should match the name property of an |
|
| 215 | - * EE_messenger. |
|
| 216 | - * Optional. |
|
| 217 | - * } |
|
| 218 | - * @type array $custom_post_types |
|
| 219 | - * @type array $custom_taxonomies |
|
| 220 | - * @type array $payment_method_paths each element is the folder containing the |
|
| 221 | - * EE_PMT_Base child class |
|
| 222 | - * (eg, |
|
| 223 | - * '/wp-content/plugins/my_plugin/Payomatic/' |
|
| 224 | - * which contains the files |
|
| 225 | - * EE_PMT_Payomatic.pm.php) |
|
| 226 | - * @type array $default_terms |
|
| 227 | - * @type array $namespace { |
|
| 228 | - * An array with two items for registering the |
|
| 229 | - * addon's namespace. (If, for some reason, you |
|
| 230 | - * require additional namespaces, |
|
| 231 | - * use |
|
| 232 | - * EventEspresso\core\Psr4Autoloader::addNamespace() |
|
| 233 | - * directly) |
|
| 234 | - * @see EventEspresso\core\Psr4Autoloader::addNamespace() |
|
| 235 | - * @type string $FQNS the namespace prefix |
|
| 236 | - * @type string $DIR a base directory for class files in the |
|
| 237 | - * namespace. |
|
| 238 | - * } |
|
| 239 | - * } |
|
| 240 | - * @return void |
|
| 241 | - * @throws DomainException |
|
| 242 | - * @throws EE_Error |
|
| 243 | - * @throws InvalidArgumentException |
|
| 244 | - * @throws ReflectionException |
|
| 245 | - * @throws InvalidDataTypeException |
|
| 246 | - * @throws InvalidInterfaceException |
|
| 247 | - */ |
|
| 248 | - public static function register($addon_name = '', $setup_args = array()) |
|
| 249 | - { |
|
| 250 | - // required fields MUST be present, so let's make sure they are. |
|
| 251 | - EE_Register_Addon::_verify_parameters($addon_name, $setup_args); |
|
| 252 | - // get class name for addon |
|
| 253 | - $class_name = EE_Register_Addon::_parse_class_name($addon_name, $setup_args); |
|
| 254 | - //setup $_settings array from incoming values. |
|
| 255 | - $addon_settings = EE_Register_Addon::_get_addon_settings($class_name, $setup_args); |
|
| 256 | - // setup PUE |
|
| 257 | - EE_Register_Addon::_parse_pue_options($addon_name, $class_name, $setup_args); |
|
| 258 | - // does this addon work with this version of core or WordPress ? |
|
| 259 | - if (! EE_Register_Addon::_addon_is_compatible($addon_name, $addon_settings)) { |
|
| 260 | - return; |
|
| 261 | - } |
|
| 262 | - // register namespaces |
|
| 263 | - EE_Register_Addon::_setup_namespaces($addon_settings); |
|
| 264 | - // check if this is an activation request |
|
| 265 | - if (EE_Register_Addon::_addon_activation($addon_name, $addon_settings)) { |
|
| 266 | - // dont bother setting up the rest of the addon atm |
|
| 267 | - return; |
|
| 268 | - } |
|
| 269 | - // we need cars |
|
| 270 | - EE_Register_Addon::_setup_autoloaders($addon_name); |
|
| 271 | - // register new models and extensions |
|
| 272 | - EE_Register_Addon::_register_models_and_extensions($addon_name); |
|
| 273 | - // setup DMS |
|
| 274 | - EE_Register_Addon::_register_data_migration_scripts($addon_name); |
|
| 275 | - // if config_class is present let's register config. |
|
| 276 | - EE_Register_Addon::_register_config($addon_name); |
|
| 277 | - // register admin pages |
|
| 278 | - EE_Register_Addon::_register_admin_pages($addon_name); |
|
| 279 | - // add to list of modules to be registered |
|
| 280 | - EE_Register_Addon::_register_modules($addon_name); |
|
| 281 | - // add to list of shortcodes to be registered |
|
| 282 | - EE_Register_Addon::_register_shortcodes($addon_name); |
|
| 283 | - // add to list of widgets to be registered |
|
| 284 | - EE_Register_Addon::_register_widgets($addon_name); |
|
| 285 | - // register capability related stuff. |
|
| 286 | - EE_Register_Addon::_register_capabilities($addon_name); |
|
| 287 | - // any message type to register? |
|
| 288 | - EE_Register_Addon::_register_message_types($addon_name); |
|
| 289 | - // any custom post type/ custom capabilities or default terms to register |
|
| 290 | - EE_Register_Addon::_register_custom_post_types($addon_name); |
|
| 291 | - // and any payment methods |
|
| 292 | - EE_Register_Addon::_register_payment_methods($addon_name); |
|
| 293 | - // load and instantiate main addon class |
|
| 294 | - $addon = EE_Register_Addon::_load_and_init_addon_class($addon_name); |
|
| 295 | - //delay calling after_registration hook on each addon until after all add-ons have been registered. |
|
| 296 | - add_action('AHEE__EE_System__load_espresso_addons__complete', array($addon, 'after_registration'), 999); |
|
| 297 | - } |
|
| 109 | + /** |
|
| 110 | + * Method for registering new EE_Addons. |
|
| 111 | + * Should be called AFTER AHEE__EE_System__load_espresso_addons but BEFORE |
|
| 112 | + * AHEE__EE_System___detect_if_activation_or_upgrade__begin in order to register all its components. However, it |
|
| 113 | + * may also be called after the 'activate_plugin' action (when an addon is activated), because an activating addon |
|
| 114 | + * won't be loaded by WP until after AHEE__EE_System__load_espresso_addons has fired. If its called after |
|
| 115 | + * 'activate_plugin', it registers the addon still, but its components are not registered |
|
| 116 | + * (they shouldn't be needed anyways, because it's just an activation request and they won't have a chance to do |
|
| 117 | + * anything anyways). Instead, it just sets the newly-activated addon's activation indicator wp option and returns |
|
| 118 | + * (so that we can detect that the addon has activated on the subsequent request) |
|
| 119 | + * |
|
| 120 | + * @since 4.3.0 |
|
| 121 | + * @param string $addon_name [Required] the EE_Addon's name. |
|
| 122 | + * @param array $setup_args { |
|
| 123 | + * An array of arguments provided for registering |
|
| 124 | + * the message type. |
|
| 125 | + * @type string $class_name the addon's main file name. |
|
| 126 | + * If left blank, generated from the addon name, |
|
| 127 | + * changes something like "calendar" to |
|
| 128 | + * "EE_Calendar" |
|
| 129 | + * @type string $min_core_version the minimum version of EE Core that the |
|
| 130 | + * addon will work with. eg "4.8.1.rc.084" |
|
| 131 | + * @type string $version the "software" version for the addon. eg |
|
| 132 | + * "1.0.0.p" for a first stable release, or |
|
| 133 | + * "1.0.0.rc.043" for a version in progress |
|
| 134 | + * @type string $main_file_path the full server path to the main file |
|
| 135 | + * loaded directly by WP |
|
| 136 | + * @type string $domain_fqcn Fully Qualified Class Name |
|
| 137 | + * for the addon's Domain class |
|
| 138 | + * (see EventEspresso\core\domain\Domain) |
|
| 139 | + * @type string $admin_path full server path to the folder where the |
|
| 140 | + * addon\'s admin files reside |
|
| 141 | + * @type string $admin_callback a method to be called when the EE Admin is |
|
| 142 | + * first invoked, can be used for hooking into |
|
| 143 | + * any admin page |
|
| 144 | + * @type string $config_section the section name for this addon's |
|
| 145 | + * configuration settings section |
|
| 146 | + * (defaults to "addons") |
|
| 147 | + * @type string $config_class the class name for this addon's |
|
| 148 | + * configuration settings object |
|
| 149 | + * @type string $config_name the class name for this addon's |
|
| 150 | + * configuration settings object |
|
| 151 | + * @type string $autoloader_paths [Required] an array of class names and the full |
|
| 152 | + * server paths to those files. |
|
| 153 | + * @type string $autoloader_folders an array of "full server paths" for any |
|
| 154 | + * folders containing classes that might be |
|
| 155 | + * invoked by the addon |
|
| 156 | + * @type string $dms_paths [Required] an array of full server paths to |
|
| 157 | + * folders that contain data migration scripts. |
|
| 158 | + * The key should be the EE_Addon class name that |
|
| 159 | + * this set of data migration scripts belongs to. |
|
| 160 | + * If the EE_Addon class is namespaced, then this |
|
| 161 | + * needs to be the Fully Qualified Class Name |
|
| 162 | + * @type string $module_paths an array of full server paths to any |
|
| 163 | + * EED_Modules used by the addon |
|
| 164 | + * @type string $shortcode_paths an array of full server paths to folders |
|
| 165 | + * that contain EES_Shortcodes |
|
| 166 | + * @type string $widget_paths an array of full server paths to folders |
|
| 167 | + * that contain WP_Widgets |
|
| 168 | + * @type string $pue_options |
|
| 169 | + * @type array $capabilities an array indexed by role name |
|
| 170 | + * (i.e administrator,author ) and the values |
|
| 171 | + * are an array of caps to add to the role. |
|
| 172 | + * 'administrator' => array( |
|
| 173 | + * 'read_addon', |
|
| 174 | + * 'edit_addon', |
|
| 175 | + * etc. |
|
| 176 | + * ). |
|
| 177 | + * @type EE_Meta_Capability_Map[] $capability_maps an array of EE_Meta_Capability_Map object |
|
| 178 | + * for any addons that need to register any |
|
| 179 | + * special meta mapped capabilities. Should |
|
| 180 | + * be indexed where the key is the |
|
| 181 | + * EE_Meta_Capability_Map class name and the |
|
| 182 | + * values are the arguments sent to the class. |
|
| 183 | + * @type array $model_paths array of folders containing DB models |
|
| 184 | + * @see EE_Register_Model |
|
| 185 | + * @type array $class_paths array of folders containing DB classes |
|
| 186 | + * @see EE_Register_Model |
|
| 187 | + * @type array $model_extension_paths array of folders containing DB model |
|
| 188 | + * extensions |
|
| 189 | + * @see EE_Register_Model_Extension |
|
| 190 | + * @type array $class_extension_paths array of folders containing DB class |
|
| 191 | + * extensions |
|
| 192 | + * @see EE_Register_Model_Extension |
|
| 193 | + * @type array message_types { |
|
| 194 | + * An array of message types with the key as |
|
| 195 | + * the message type name and the values as |
|
| 196 | + * below: |
|
| 197 | + * @type string $mtfilename [Required] The filename of the message type |
|
| 198 | + * being registered. This will be the main |
|
| 199 | + * EE_{Message Type Name}_message_type class. |
|
| 200 | + * for example: |
|
| 201 | + * EE_Declined_Registration_message_type.class.php |
|
| 202 | + * @type array $autoloadpaths [Required] An array of paths to add to the |
|
| 203 | + * messages autoloader for the new message type. |
|
| 204 | + * @type array $messengers_to_activate_with An array of messengers that this message |
|
| 205 | + * type should activate with. Each value in |
|
| 206 | + * the |
|
| 207 | + * array |
|
| 208 | + * should match the name property of a |
|
| 209 | + * EE_messenger. Optional. |
|
| 210 | + * @type array $messengers_to_validate_with An array of messengers that this message |
|
| 211 | + * type should validate with. Each value in |
|
| 212 | + * the |
|
| 213 | + * array |
|
| 214 | + * should match the name property of an |
|
| 215 | + * EE_messenger. |
|
| 216 | + * Optional. |
|
| 217 | + * } |
|
| 218 | + * @type array $custom_post_types |
|
| 219 | + * @type array $custom_taxonomies |
|
| 220 | + * @type array $payment_method_paths each element is the folder containing the |
|
| 221 | + * EE_PMT_Base child class |
|
| 222 | + * (eg, |
|
| 223 | + * '/wp-content/plugins/my_plugin/Payomatic/' |
|
| 224 | + * which contains the files |
|
| 225 | + * EE_PMT_Payomatic.pm.php) |
|
| 226 | + * @type array $default_terms |
|
| 227 | + * @type array $namespace { |
|
| 228 | + * An array with two items for registering the |
|
| 229 | + * addon's namespace. (If, for some reason, you |
|
| 230 | + * require additional namespaces, |
|
| 231 | + * use |
|
| 232 | + * EventEspresso\core\Psr4Autoloader::addNamespace() |
|
| 233 | + * directly) |
|
| 234 | + * @see EventEspresso\core\Psr4Autoloader::addNamespace() |
|
| 235 | + * @type string $FQNS the namespace prefix |
|
| 236 | + * @type string $DIR a base directory for class files in the |
|
| 237 | + * namespace. |
|
| 238 | + * } |
|
| 239 | + * } |
|
| 240 | + * @return void |
|
| 241 | + * @throws DomainException |
|
| 242 | + * @throws EE_Error |
|
| 243 | + * @throws InvalidArgumentException |
|
| 244 | + * @throws ReflectionException |
|
| 245 | + * @throws InvalidDataTypeException |
|
| 246 | + * @throws InvalidInterfaceException |
|
| 247 | + */ |
|
| 248 | + public static function register($addon_name = '', $setup_args = array()) |
|
| 249 | + { |
|
| 250 | + // required fields MUST be present, so let's make sure they are. |
|
| 251 | + EE_Register_Addon::_verify_parameters($addon_name, $setup_args); |
|
| 252 | + // get class name for addon |
|
| 253 | + $class_name = EE_Register_Addon::_parse_class_name($addon_name, $setup_args); |
|
| 254 | + //setup $_settings array from incoming values. |
|
| 255 | + $addon_settings = EE_Register_Addon::_get_addon_settings($class_name, $setup_args); |
|
| 256 | + // setup PUE |
|
| 257 | + EE_Register_Addon::_parse_pue_options($addon_name, $class_name, $setup_args); |
|
| 258 | + // does this addon work with this version of core or WordPress ? |
|
| 259 | + if (! EE_Register_Addon::_addon_is_compatible($addon_name, $addon_settings)) { |
|
| 260 | + return; |
|
| 261 | + } |
|
| 262 | + // register namespaces |
|
| 263 | + EE_Register_Addon::_setup_namespaces($addon_settings); |
|
| 264 | + // check if this is an activation request |
|
| 265 | + if (EE_Register_Addon::_addon_activation($addon_name, $addon_settings)) { |
|
| 266 | + // dont bother setting up the rest of the addon atm |
|
| 267 | + return; |
|
| 268 | + } |
|
| 269 | + // we need cars |
|
| 270 | + EE_Register_Addon::_setup_autoloaders($addon_name); |
|
| 271 | + // register new models and extensions |
|
| 272 | + EE_Register_Addon::_register_models_and_extensions($addon_name); |
|
| 273 | + // setup DMS |
|
| 274 | + EE_Register_Addon::_register_data_migration_scripts($addon_name); |
|
| 275 | + // if config_class is present let's register config. |
|
| 276 | + EE_Register_Addon::_register_config($addon_name); |
|
| 277 | + // register admin pages |
|
| 278 | + EE_Register_Addon::_register_admin_pages($addon_name); |
|
| 279 | + // add to list of modules to be registered |
|
| 280 | + EE_Register_Addon::_register_modules($addon_name); |
|
| 281 | + // add to list of shortcodes to be registered |
|
| 282 | + EE_Register_Addon::_register_shortcodes($addon_name); |
|
| 283 | + // add to list of widgets to be registered |
|
| 284 | + EE_Register_Addon::_register_widgets($addon_name); |
|
| 285 | + // register capability related stuff. |
|
| 286 | + EE_Register_Addon::_register_capabilities($addon_name); |
|
| 287 | + // any message type to register? |
|
| 288 | + EE_Register_Addon::_register_message_types($addon_name); |
|
| 289 | + // any custom post type/ custom capabilities or default terms to register |
|
| 290 | + EE_Register_Addon::_register_custom_post_types($addon_name); |
|
| 291 | + // and any payment methods |
|
| 292 | + EE_Register_Addon::_register_payment_methods($addon_name); |
|
| 293 | + // load and instantiate main addon class |
|
| 294 | + $addon = EE_Register_Addon::_load_and_init_addon_class($addon_name); |
|
| 295 | + //delay calling after_registration hook on each addon until after all add-ons have been registered. |
|
| 296 | + add_action('AHEE__EE_System__load_espresso_addons__complete', array($addon, 'after_registration'), 999); |
|
| 297 | + } |
|
| 298 | 298 | |
| 299 | 299 | |
| 300 | - /** |
|
| 301 | - * @param string $addon_name |
|
| 302 | - * @param array $setup_args |
|
| 303 | - * @return void |
|
| 304 | - * @throws EE_Error |
|
| 305 | - */ |
|
| 306 | - private static function _verify_parameters($addon_name, array $setup_args) |
|
| 307 | - { |
|
| 308 | - // required fields MUST be present, so let's make sure they are. |
|
| 309 | - if (empty($addon_name) || ! is_array($setup_args)) { |
|
| 310 | - throw new EE_Error( |
|
| 311 | - __( |
|
| 312 | - '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.', |
|
| 313 | - 'event_espresso' |
|
| 314 | - ) |
|
| 315 | - ); |
|
| 316 | - } |
|
| 317 | - if (! isset($setup_args['main_file_path']) || empty($setup_args['main_file_path'])) { |
|
| 318 | - throw new EE_Error( |
|
| 319 | - sprintf( |
|
| 320 | - __( |
|
| 321 | - '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', |
|
| 322 | - 'event_espresso' |
|
| 323 | - ), |
|
| 324 | - implode(',', array_keys($setup_args)) |
|
| 325 | - ) |
|
| 326 | - ); |
|
| 327 | - } |
|
| 328 | - // check that addon has not already been registered with that name |
|
| 329 | - if (isset(self::$_settings[ $addon_name ]) && ! did_action('activate_plugin')) { |
|
| 330 | - throw new EE_Error( |
|
| 331 | - sprintf( |
|
| 332 | - __( |
|
| 333 | - 'An EE_Addon with the name "%s" has already been registered and each EE_Addon requires a unique name.', |
|
| 334 | - 'event_espresso' |
|
| 335 | - ), |
|
| 336 | - $addon_name |
|
| 337 | - ) |
|
| 338 | - ); |
|
| 339 | - } |
|
| 340 | - } |
|
| 300 | + /** |
|
| 301 | + * @param string $addon_name |
|
| 302 | + * @param array $setup_args |
|
| 303 | + * @return void |
|
| 304 | + * @throws EE_Error |
|
| 305 | + */ |
|
| 306 | + private static function _verify_parameters($addon_name, array $setup_args) |
|
| 307 | + { |
|
| 308 | + // required fields MUST be present, so let's make sure they are. |
|
| 309 | + if (empty($addon_name) || ! is_array($setup_args)) { |
|
| 310 | + throw new EE_Error( |
|
| 311 | + __( |
|
| 312 | + '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.', |
|
| 313 | + 'event_espresso' |
|
| 314 | + ) |
|
| 315 | + ); |
|
| 316 | + } |
|
| 317 | + if (! isset($setup_args['main_file_path']) || empty($setup_args['main_file_path'])) { |
|
| 318 | + throw new EE_Error( |
|
| 319 | + sprintf( |
|
| 320 | + __( |
|
| 321 | + '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', |
|
| 322 | + 'event_espresso' |
|
| 323 | + ), |
|
| 324 | + implode(',', array_keys($setup_args)) |
|
| 325 | + ) |
|
| 326 | + ); |
|
| 327 | + } |
|
| 328 | + // check that addon has not already been registered with that name |
|
| 329 | + if (isset(self::$_settings[ $addon_name ]) && ! did_action('activate_plugin')) { |
|
| 330 | + throw new EE_Error( |
|
| 331 | + sprintf( |
|
| 332 | + __( |
|
| 333 | + 'An EE_Addon with the name "%s" has already been registered and each EE_Addon requires a unique name.', |
|
| 334 | + 'event_espresso' |
|
| 335 | + ), |
|
| 336 | + $addon_name |
|
| 337 | + ) |
|
| 338 | + ); |
|
| 339 | + } |
|
| 340 | + } |
|
| 341 | 341 | |
| 342 | 342 | |
| 343 | - /** |
|
| 344 | - * @param string $addon_name |
|
| 345 | - * @param array $setup_args |
|
| 346 | - * @return string |
|
| 347 | - */ |
|
| 348 | - private static function _parse_class_name($addon_name, array $setup_args) |
|
| 349 | - { |
|
| 350 | - if (empty($setup_args['class_name'])) { |
|
| 351 | - // generate one by first separating name with spaces |
|
| 352 | - $class_name = str_replace(array('-', '_'), ' ', trim($addon_name)); |
|
| 353 | - //capitalize, then replace spaces with underscores |
|
| 354 | - $class_name = str_replace(' ', '_', ucwords($class_name)); |
|
| 355 | - } else { |
|
| 356 | - $class_name = $setup_args['class_name']; |
|
| 357 | - } |
|
| 358 | - // check if classname is fully qualified or is a legacy classname already prefixed with 'EE_' |
|
| 359 | - return strpos($class_name, '\\') || strpos($class_name, 'EE_') === 0 |
|
| 360 | - ? $class_name |
|
| 361 | - : 'EE_' . $class_name; |
|
| 362 | - } |
|
| 343 | + /** |
|
| 344 | + * @param string $addon_name |
|
| 345 | + * @param array $setup_args |
|
| 346 | + * @return string |
|
| 347 | + */ |
|
| 348 | + private static function _parse_class_name($addon_name, array $setup_args) |
|
| 349 | + { |
|
| 350 | + if (empty($setup_args['class_name'])) { |
|
| 351 | + // generate one by first separating name with spaces |
|
| 352 | + $class_name = str_replace(array('-', '_'), ' ', trim($addon_name)); |
|
| 353 | + //capitalize, then replace spaces with underscores |
|
| 354 | + $class_name = str_replace(' ', '_', ucwords($class_name)); |
|
| 355 | + } else { |
|
| 356 | + $class_name = $setup_args['class_name']; |
|
| 357 | + } |
|
| 358 | + // check if classname is fully qualified or is a legacy classname already prefixed with 'EE_' |
|
| 359 | + return strpos($class_name, '\\') || strpos($class_name, 'EE_') === 0 |
|
| 360 | + ? $class_name |
|
| 361 | + : 'EE_' . $class_name; |
|
| 362 | + } |
|
| 363 | 363 | |
| 364 | 364 | |
| 365 | - /** |
|
| 366 | - * @param string $class_name |
|
| 367 | - * @param array $setup_args |
|
| 368 | - * @return array |
|
| 369 | - */ |
|
| 370 | - private static function _get_addon_settings($class_name, array $setup_args) |
|
| 371 | - { |
|
| 372 | - //setup $_settings array from incoming values. |
|
| 373 | - $addon_settings = array( |
|
| 374 | - // generated from the addon name, changes something like "calendar" to "EE_Calendar" |
|
| 375 | - 'class_name' => $class_name, |
|
| 376 | - // the addon slug for use in URLs, etc |
|
| 377 | - 'plugin_slug' => isset($setup_args['plugin_slug']) |
|
| 378 | - ? (string) $setup_args['plugin_slug'] |
|
| 379 | - : '', |
|
| 380 | - // page slug to be used when generating the "Settings" link on the WP plugin page |
|
| 381 | - 'plugin_action_slug' => isset($setup_args['plugin_action_slug']) |
|
| 382 | - ? (string) $setup_args['plugin_action_slug'] |
|
| 383 | - : '', |
|
| 384 | - // the "software" version for the addon |
|
| 385 | - 'version' => isset($setup_args['version']) |
|
| 386 | - ? (string) $setup_args['version'] |
|
| 387 | - : '', |
|
| 388 | - // the minimum version of EE Core that the addon will work with |
|
| 389 | - 'min_core_version' => isset($setup_args['min_core_version']) |
|
| 390 | - ? (string) $setup_args['min_core_version'] |
|
| 391 | - : '', |
|
| 392 | - // the minimum version of WordPress that the addon will work with |
|
| 393 | - 'min_wp_version' => isset($setup_args['min_wp_version']) |
|
| 394 | - ? (string) $setup_args['min_wp_version'] |
|
| 395 | - : EE_MIN_WP_VER_REQUIRED, |
|
| 396 | - // full server path to main file (file loaded directly by WP) |
|
| 397 | - 'main_file_path' => isset($setup_args['main_file_path']) |
|
| 398 | - ? (string) $setup_args['main_file_path'] |
|
| 399 | - : '', |
|
| 400 | - // Fully Qualified Class Name for the addon's Domain class |
|
| 401 | - 'domain_fqcn' => isset($setup_args['domain_fqcn']) |
|
| 402 | - ? (string) $setup_args['domain_fqcn'] |
|
| 403 | - : '', |
|
| 404 | - // path to folder containing files for integrating with the EE core admin and/or setting up EE admin pages |
|
| 405 | - 'admin_path' => isset($setup_args['admin_path']) |
|
| 406 | - ? (string) $setup_args['admin_path'] : '', |
|
| 407 | - // a method to be called when the EE Admin is first invoked, can be used for hooking into any admin page |
|
| 408 | - 'admin_callback' => isset($setup_args['admin_callback']) |
|
| 409 | - ? (string) $setup_args['admin_callback'] |
|
| 410 | - : '', |
|
| 411 | - // the section name for this addon's configuration settings section (defaults to "addons") |
|
| 412 | - 'config_section' => isset($setup_args['config_section']) |
|
| 413 | - ? (string) $setup_args['config_section'] |
|
| 414 | - : 'addons', |
|
| 415 | - // the class name for this addon's configuration settings object |
|
| 416 | - 'config_class' => isset($setup_args['config_class']) |
|
| 417 | - ? (string) $setup_args['config_class'] : '', |
|
| 418 | - //the name given to the config for this addons' configuration settings object (optional) |
|
| 419 | - 'config_name' => isset($setup_args['config_name']) |
|
| 420 | - ? (string) $setup_args['config_name'] : '', |
|
| 421 | - // an array of "class names" => "full server paths" for any classes that might be invoked by the addon |
|
| 422 | - 'autoloader_paths' => isset($setup_args['autoloader_paths']) |
|
| 423 | - ? (array) $setup_args['autoloader_paths'] |
|
| 424 | - : array(), |
|
| 425 | - // an array of "full server paths" for any folders containing classes that might be invoked by the addon |
|
| 426 | - 'autoloader_folders' => isset($setup_args['autoloader_folders']) |
|
| 427 | - ? (array) $setup_args['autoloader_folders'] |
|
| 428 | - : array(), |
|
| 429 | - // array of full server paths to any EE_DMS data migration scripts used by the addon. |
|
| 430 | - // The key should be the EE_Addon class name that this set of data migration scripts belongs to. |
|
| 431 | - // If the EE_Addon class is namespaced, then this needs to be the Fully Qualified Class Name |
|
| 432 | - 'dms_paths' => isset($setup_args['dms_paths']) |
|
| 433 | - ? (array) $setup_args['dms_paths'] |
|
| 434 | - : array(), |
|
| 435 | - // array of full server paths to any EED_Modules used by the addon |
|
| 436 | - 'module_paths' => isset($setup_args['module_paths']) |
|
| 437 | - ? (array) $setup_args['module_paths'] |
|
| 438 | - : array(), |
|
| 439 | - // array of full server paths to any EES_Shortcodes used by the addon |
|
| 440 | - 'shortcode_paths' => isset($setup_args['shortcode_paths']) |
|
| 441 | - ? (array) $setup_args['shortcode_paths'] |
|
| 442 | - : array(), |
|
| 443 | - 'shortcode_fqcns' => isset($setup_args['shortcode_fqcns']) |
|
| 444 | - ? (array) $setup_args['shortcode_fqcns'] |
|
| 445 | - : array(), |
|
| 446 | - // array of full server paths to any WP_Widgets used by the addon |
|
| 447 | - 'widget_paths' => isset($setup_args['widget_paths']) |
|
| 448 | - ? (array) $setup_args['widget_paths'] |
|
| 449 | - : array(), |
|
| 450 | - // array of PUE options used by the addon |
|
| 451 | - 'pue_options' => isset($setup_args['pue_options']) |
|
| 452 | - ? (array) $setup_args['pue_options'] |
|
| 453 | - : array(), |
|
| 454 | - 'message_types' => isset($setup_args['message_types']) |
|
| 455 | - ? (array) $setup_args['message_types'] |
|
| 456 | - : array(), |
|
| 457 | - 'capabilities' => isset($setup_args['capabilities']) |
|
| 458 | - ? (array) $setup_args['capabilities'] |
|
| 459 | - : array(), |
|
| 460 | - 'capability_maps' => isset($setup_args['capability_maps']) |
|
| 461 | - ? (array) $setup_args['capability_maps'] |
|
| 462 | - : array(), |
|
| 463 | - 'model_paths' => isset($setup_args['model_paths']) |
|
| 464 | - ? (array) $setup_args['model_paths'] |
|
| 465 | - : array(), |
|
| 466 | - 'class_paths' => isset($setup_args['class_paths']) |
|
| 467 | - ? (array) $setup_args['class_paths'] |
|
| 468 | - : array(), |
|
| 469 | - 'model_extension_paths' => isset($setup_args['model_extension_paths']) |
|
| 470 | - ? (array) $setup_args['model_extension_paths'] |
|
| 471 | - : array(), |
|
| 472 | - 'class_extension_paths' => isset($setup_args['class_extension_paths']) |
|
| 473 | - ? (array) $setup_args['class_extension_paths'] |
|
| 474 | - : array(), |
|
| 475 | - 'custom_post_types' => isset($setup_args['custom_post_types']) |
|
| 476 | - ? (array) $setup_args['custom_post_types'] |
|
| 477 | - : array(), |
|
| 478 | - 'custom_taxonomies' => isset($setup_args['custom_taxonomies']) |
|
| 479 | - ? (array) $setup_args['custom_taxonomies'] |
|
| 480 | - : array(), |
|
| 481 | - 'payment_method_paths' => isset($setup_args['payment_method_paths']) |
|
| 482 | - ? (array) $setup_args['payment_method_paths'] |
|
| 483 | - : array(), |
|
| 484 | - 'default_terms' => isset($setup_args['default_terms']) |
|
| 485 | - ? (array) $setup_args['default_terms'] |
|
| 486 | - : array(), |
|
| 487 | - // if not empty, inserts a new table row after this plugin's row on the WP Plugins page |
|
| 488 | - // that can be used for adding upgrading/marketing info |
|
| 489 | - 'plugins_page_row' => isset($setup_args['plugins_page_row']) |
|
| 490 | - ? $setup_args['plugins_page_row'] |
|
| 491 | - : '', |
|
| 492 | - 'namespace' => isset( |
|
| 493 | - $setup_args['namespace']['FQNS'], |
|
| 494 | - $setup_args['namespace']['DIR'] |
|
| 495 | - ) |
|
| 496 | - ? (array) $setup_args['namespace'] |
|
| 497 | - : array(), |
|
| 498 | - ); |
|
| 499 | - // if plugin_action_slug is NOT set, but an admin page path IS set, |
|
| 500 | - // then let's just use the plugin_slug since that will be used for linking to the admin page |
|
| 501 | - $addon_settings['plugin_action_slug'] = empty($addon_settings['plugin_action_slug']) |
|
| 502 | - && ! empty($addon_settings['admin_path']) |
|
| 503 | - ? $addon_settings['plugin_slug'] |
|
| 504 | - : $addon_settings['plugin_action_slug']; |
|
| 505 | - // full server path to main file (file loaded directly by WP) |
|
| 506 | - $addon_settings['plugin_basename'] = plugin_basename($addon_settings['main_file_path']); |
|
| 507 | - return $addon_settings; |
|
| 508 | - } |
|
| 365 | + /** |
|
| 366 | + * @param string $class_name |
|
| 367 | + * @param array $setup_args |
|
| 368 | + * @return array |
|
| 369 | + */ |
|
| 370 | + private static function _get_addon_settings($class_name, array $setup_args) |
|
| 371 | + { |
|
| 372 | + //setup $_settings array from incoming values. |
|
| 373 | + $addon_settings = array( |
|
| 374 | + // generated from the addon name, changes something like "calendar" to "EE_Calendar" |
|
| 375 | + 'class_name' => $class_name, |
|
| 376 | + // the addon slug for use in URLs, etc |
|
| 377 | + 'plugin_slug' => isset($setup_args['plugin_slug']) |
|
| 378 | + ? (string) $setup_args['plugin_slug'] |
|
| 379 | + : '', |
|
| 380 | + // page slug to be used when generating the "Settings" link on the WP plugin page |
|
| 381 | + 'plugin_action_slug' => isset($setup_args['plugin_action_slug']) |
|
| 382 | + ? (string) $setup_args['plugin_action_slug'] |
|
| 383 | + : '', |
|
| 384 | + // the "software" version for the addon |
|
| 385 | + 'version' => isset($setup_args['version']) |
|
| 386 | + ? (string) $setup_args['version'] |
|
| 387 | + : '', |
|
| 388 | + // the minimum version of EE Core that the addon will work with |
|
| 389 | + 'min_core_version' => isset($setup_args['min_core_version']) |
|
| 390 | + ? (string) $setup_args['min_core_version'] |
|
| 391 | + : '', |
|
| 392 | + // the minimum version of WordPress that the addon will work with |
|
| 393 | + 'min_wp_version' => isset($setup_args['min_wp_version']) |
|
| 394 | + ? (string) $setup_args['min_wp_version'] |
|
| 395 | + : EE_MIN_WP_VER_REQUIRED, |
|
| 396 | + // full server path to main file (file loaded directly by WP) |
|
| 397 | + 'main_file_path' => isset($setup_args['main_file_path']) |
|
| 398 | + ? (string) $setup_args['main_file_path'] |
|
| 399 | + : '', |
|
| 400 | + // Fully Qualified Class Name for the addon's Domain class |
|
| 401 | + 'domain_fqcn' => isset($setup_args['domain_fqcn']) |
|
| 402 | + ? (string) $setup_args['domain_fqcn'] |
|
| 403 | + : '', |
|
| 404 | + // path to folder containing files for integrating with the EE core admin and/or setting up EE admin pages |
|
| 405 | + 'admin_path' => isset($setup_args['admin_path']) |
|
| 406 | + ? (string) $setup_args['admin_path'] : '', |
|
| 407 | + // a method to be called when the EE Admin is first invoked, can be used for hooking into any admin page |
|
| 408 | + 'admin_callback' => isset($setup_args['admin_callback']) |
|
| 409 | + ? (string) $setup_args['admin_callback'] |
|
| 410 | + : '', |
|
| 411 | + // the section name for this addon's configuration settings section (defaults to "addons") |
|
| 412 | + 'config_section' => isset($setup_args['config_section']) |
|
| 413 | + ? (string) $setup_args['config_section'] |
|
| 414 | + : 'addons', |
|
| 415 | + // the class name for this addon's configuration settings object |
|
| 416 | + 'config_class' => isset($setup_args['config_class']) |
|
| 417 | + ? (string) $setup_args['config_class'] : '', |
|
| 418 | + //the name given to the config for this addons' configuration settings object (optional) |
|
| 419 | + 'config_name' => isset($setup_args['config_name']) |
|
| 420 | + ? (string) $setup_args['config_name'] : '', |
|
| 421 | + // an array of "class names" => "full server paths" for any classes that might be invoked by the addon |
|
| 422 | + 'autoloader_paths' => isset($setup_args['autoloader_paths']) |
|
| 423 | + ? (array) $setup_args['autoloader_paths'] |
|
| 424 | + : array(), |
|
| 425 | + // an array of "full server paths" for any folders containing classes that might be invoked by the addon |
|
| 426 | + 'autoloader_folders' => isset($setup_args['autoloader_folders']) |
|
| 427 | + ? (array) $setup_args['autoloader_folders'] |
|
| 428 | + : array(), |
|
| 429 | + // array of full server paths to any EE_DMS data migration scripts used by the addon. |
|
| 430 | + // The key should be the EE_Addon class name that this set of data migration scripts belongs to. |
|
| 431 | + // If the EE_Addon class is namespaced, then this needs to be the Fully Qualified Class Name |
|
| 432 | + 'dms_paths' => isset($setup_args['dms_paths']) |
|
| 433 | + ? (array) $setup_args['dms_paths'] |
|
| 434 | + : array(), |
|
| 435 | + // array of full server paths to any EED_Modules used by the addon |
|
| 436 | + 'module_paths' => isset($setup_args['module_paths']) |
|
| 437 | + ? (array) $setup_args['module_paths'] |
|
| 438 | + : array(), |
|
| 439 | + // array of full server paths to any EES_Shortcodes used by the addon |
|
| 440 | + 'shortcode_paths' => isset($setup_args['shortcode_paths']) |
|
| 441 | + ? (array) $setup_args['shortcode_paths'] |
|
| 442 | + : array(), |
|
| 443 | + 'shortcode_fqcns' => isset($setup_args['shortcode_fqcns']) |
|
| 444 | + ? (array) $setup_args['shortcode_fqcns'] |
|
| 445 | + : array(), |
|
| 446 | + // array of full server paths to any WP_Widgets used by the addon |
|
| 447 | + 'widget_paths' => isset($setup_args['widget_paths']) |
|
| 448 | + ? (array) $setup_args['widget_paths'] |
|
| 449 | + : array(), |
|
| 450 | + // array of PUE options used by the addon |
|
| 451 | + 'pue_options' => isset($setup_args['pue_options']) |
|
| 452 | + ? (array) $setup_args['pue_options'] |
|
| 453 | + : array(), |
|
| 454 | + 'message_types' => isset($setup_args['message_types']) |
|
| 455 | + ? (array) $setup_args['message_types'] |
|
| 456 | + : array(), |
|
| 457 | + 'capabilities' => isset($setup_args['capabilities']) |
|
| 458 | + ? (array) $setup_args['capabilities'] |
|
| 459 | + : array(), |
|
| 460 | + 'capability_maps' => isset($setup_args['capability_maps']) |
|
| 461 | + ? (array) $setup_args['capability_maps'] |
|
| 462 | + : array(), |
|
| 463 | + 'model_paths' => isset($setup_args['model_paths']) |
|
| 464 | + ? (array) $setup_args['model_paths'] |
|
| 465 | + : array(), |
|
| 466 | + 'class_paths' => isset($setup_args['class_paths']) |
|
| 467 | + ? (array) $setup_args['class_paths'] |
|
| 468 | + : array(), |
|
| 469 | + 'model_extension_paths' => isset($setup_args['model_extension_paths']) |
|
| 470 | + ? (array) $setup_args['model_extension_paths'] |
|
| 471 | + : array(), |
|
| 472 | + 'class_extension_paths' => isset($setup_args['class_extension_paths']) |
|
| 473 | + ? (array) $setup_args['class_extension_paths'] |
|
| 474 | + : array(), |
|
| 475 | + 'custom_post_types' => isset($setup_args['custom_post_types']) |
|
| 476 | + ? (array) $setup_args['custom_post_types'] |
|
| 477 | + : array(), |
|
| 478 | + 'custom_taxonomies' => isset($setup_args['custom_taxonomies']) |
|
| 479 | + ? (array) $setup_args['custom_taxonomies'] |
|
| 480 | + : array(), |
|
| 481 | + 'payment_method_paths' => isset($setup_args['payment_method_paths']) |
|
| 482 | + ? (array) $setup_args['payment_method_paths'] |
|
| 483 | + : array(), |
|
| 484 | + 'default_terms' => isset($setup_args['default_terms']) |
|
| 485 | + ? (array) $setup_args['default_terms'] |
|
| 486 | + : array(), |
|
| 487 | + // if not empty, inserts a new table row after this plugin's row on the WP Plugins page |
|
| 488 | + // that can be used for adding upgrading/marketing info |
|
| 489 | + 'plugins_page_row' => isset($setup_args['plugins_page_row']) |
|
| 490 | + ? $setup_args['plugins_page_row'] |
|
| 491 | + : '', |
|
| 492 | + 'namespace' => isset( |
|
| 493 | + $setup_args['namespace']['FQNS'], |
|
| 494 | + $setup_args['namespace']['DIR'] |
|
| 495 | + ) |
|
| 496 | + ? (array) $setup_args['namespace'] |
|
| 497 | + : array(), |
|
| 498 | + ); |
|
| 499 | + // if plugin_action_slug is NOT set, but an admin page path IS set, |
|
| 500 | + // then let's just use the plugin_slug since that will be used for linking to the admin page |
|
| 501 | + $addon_settings['plugin_action_slug'] = empty($addon_settings['plugin_action_slug']) |
|
| 502 | + && ! empty($addon_settings['admin_path']) |
|
| 503 | + ? $addon_settings['plugin_slug'] |
|
| 504 | + : $addon_settings['plugin_action_slug']; |
|
| 505 | + // full server path to main file (file loaded directly by WP) |
|
| 506 | + $addon_settings['plugin_basename'] = plugin_basename($addon_settings['main_file_path']); |
|
| 507 | + return $addon_settings; |
|
| 508 | + } |
|
| 509 | 509 | |
| 510 | 510 | |
| 511 | - /** |
|
| 512 | - * @param string $addon_name |
|
| 513 | - * @param array $addon_settings |
|
| 514 | - * @return boolean |
|
| 515 | - */ |
|
| 516 | - private static function _addon_is_compatible($addon_name, array $addon_settings) |
|
| 517 | - { |
|
| 518 | - global $wp_version; |
|
| 519 | - $incompatibility_message = ''; |
|
| 520 | - //check whether this addon version is compatible with EE core |
|
| 521 | - if ( |
|
| 522 | - isset(EE_Register_Addon::$_incompatible_addons[ $addon_name ]) |
|
| 523 | - && ! self::_meets_min_core_version_requirement( |
|
| 524 | - EE_Register_Addon::$_incompatible_addons[ $addon_name ], |
|
| 525 | - $addon_settings['version'] |
|
| 526 | - ) |
|
| 527 | - ) { |
|
| 528 | - $incompatibility_message = sprintf( |
|
| 529 | - __( |
|
| 530 | - '%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.' |
|
| 531 | - ), |
|
| 532 | - $addon_name, |
|
| 533 | - '<br />', |
|
| 534 | - EE_Register_Addon::$_incompatible_addons[ $addon_name ], |
|
| 535 | - '<span style="font-weight: bold; color: #D54E21;">', |
|
| 536 | - '</span><br />' |
|
| 537 | - ); |
|
| 538 | - } elseif ( |
|
| 539 | - ! self::_meets_min_core_version_requirement($addon_settings['min_core_version'], espresso_version()) |
|
| 540 | - ) { |
|
| 541 | - $incompatibility_message = sprintf( |
|
| 542 | - __( |
|
| 543 | - '%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".', |
|
| 544 | - 'event_espresso' |
|
| 545 | - ), |
|
| 546 | - $addon_name, |
|
| 547 | - self::_effective_version($addon_settings['min_core_version']), |
|
| 548 | - self::_effective_version(espresso_version()), |
|
| 549 | - '<br />', |
|
| 550 | - '<span style="font-weight: bold; color: #D54E21;">', |
|
| 551 | - '</span><br />' |
|
| 552 | - ); |
|
| 553 | - } elseif (version_compare($wp_version, $addon_settings['min_wp_version'], '<')) { |
|
| 554 | - $incompatibility_message = sprintf( |
|
| 555 | - __( |
|
| 556 | - '%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.', |
|
| 557 | - 'event_espresso' |
|
| 558 | - ), |
|
| 559 | - $addon_name, |
|
| 560 | - $addon_settings['min_wp_version'], |
|
| 561 | - '<br />', |
|
| 562 | - '<span style="font-weight: bold; color: #D54E21;">', |
|
| 563 | - '</span><br />' |
|
| 564 | - ); |
|
| 565 | - } |
|
| 566 | - if (! empty($incompatibility_message)) { |
|
| 567 | - // remove 'activate' from the REQUEST |
|
| 568 | - // so WP doesn't erroneously tell the user the plugin activated fine when it didn't |
|
| 569 | - unset($_GET['activate'], $_REQUEST['activate']); |
|
| 570 | - if (current_user_can('activate_plugins')) { |
|
| 571 | - // show an error message indicating the plugin didn't activate properly |
|
| 572 | - EE_Error::add_error($incompatibility_message, __FILE__, __FUNCTION__, __LINE__); |
|
| 573 | - } |
|
| 574 | - // BAIL FROM THE ADDON REGISTRATION PROCESS |
|
| 575 | - return false; |
|
| 576 | - } |
|
| 577 | - // addon IS compatible |
|
| 578 | - return true; |
|
| 579 | - } |
|
| 511 | + /** |
|
| 512 | + * @param string $addon_name |
|
| 513 | + * @param array $addon_settings |
|
| 514 | + * @return boolean |
|
| 515 | + */ |
|
| 516 | + private static function _addon_is_compatible($addon_name, array $addon_settings) |
|
| 517 | + { |
|
| 518 | + global $wp_version; |
|
| 519 | + $incompatibility_message = ''; |
|
| 520 | + //check whether this addon version is compatible with EE core |
|
| 521 | + if ( |
|
| 522 | + isset(EE_Register_Addon::$_incompatible_addons[ $addon_name ]) |
|
| 523 | + && ! self::_meets_min_core_version_requirement( |
|
| 524 | + EE_Register_Addon::$_incompatible_addons[ $addon_name ], |
|
| 525 | + $addon_settings['version'] |
|
| 526 | + ) |
|
| 527 | + ) { |
|
| 528 | + $incompatibility_message = sprintf( |
|
| 529 | + __( |
|
| 530 | + '%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.' |
|
| 531 | + ), |
|
| 532 | + $addon_name, |
|
| 533 | + '<br />', |
|
| 534 | + EE_Register_Addon::$_incompatible_addons[ $addon_name ], |
|
| 535 | + '<span style="font-weight: bold; color: #D54E21;">', |
|
| 536 | + '</span><br />' |
|
| 537 | + ); |
|
| 538 | + } elseif ( |
|
| 539 | + ! self::_meets_min_core_version_requirement($addon_settings['min_core_version'], espresso_version()) |
|
| 540 | + ) { |
|
| 541 | + $incompatibility_message = sprintf( |
|
| 542 | + __( |
|
| 543 | + '%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".', |
|
| 544 | + 'event_espresso' |
|
| 545 | + ), |
|
| 546 | + $addon_name, |
|
| 547 | + self::_effective_version($addon_settings['min_core_version']), |
|
| 548 | + self::_effective_version(espresso_version()), |
|
| 549 | + '<br />', |
|
| 550 | + '<span style="font-weight: bold; color: #D54E21;">', |
|
| 551 | + '</span><br />' |
|
| 552 | + ); |
|
| 553 | + } elseif (version_compare($wp_version, $addon_settings['min_wp_version'], '<')) { |
|
| 554 | + $incompatibility_message = sprintf( |
|
| 555 | + __( |
|
| 556 | + '%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.', |
|
| 557 | + 'event_espresso' |
|
| 558 | + ), |
|
| 559 | + $addon_name, |
|
| 560 | + $addon_settings['min_wp_version'], |
|
| 561 | + '<br />', |
|
| 562 | + '<span style="font-weight: bold; color: #D54E21;">', |
|
| 563 | + '</span><br />' |
|
| 564 | + ); |
|
| 565 | + } |
|
| 566 | + if (! empty($incompatibility_message)) { |
|
| 567 | + // remove 'activate' from the REQUEST |
|
| 568 | + // so WP doesn't erroneously tell the user the plugin activated fine when it didn't |
|
| 569 | + unset($_GET['activate'], $_REQUEST['activate']); |
|
| 570 | + if (current_user_can('activate_plugins')) { |
|
| 571 | + // show an error message indicating the plugin didn't activate properly |
|
| 572 | + EE_Error::add_error($incompatibility_message, __FILE__, __FUNCTION__, __LINE__); |
|
| 573 | + } |
|
| 574 | + // BAIL FROM THE ADDON REGISTRATION PROCESS |
|
| 575 | + return false; |
|
| 576 | + } |
|
| 577 | + // addon IS compatible |
|
| 578 | + return true; |
|
| 579 | + } |
|
| 580 | 580 | |
| 581 | 581 | |
| 582 | - /** |
|
| 583 | - * if plugin update engine is being used for auto-updates, |
|
| 584 | - * then let's set that up now before going any further so that ALL addons can be updated |
|
| 585 | - * (not needed if PUE is not being used) |
|
| 586 | - * |
|
| 587 | - * @param string $addon_name |
|
| 588 | - * @param string $class_name |
|
| 589 | - * @param array $setup_args |
|
| 590 | - * @return void |
|
| 591 | - */ |
|
| 592 | - private static function _parse_pue_options($addon_name, $class_name, array $setup_args) |
|
| 593 | - { |
|
| 594 | - if (! empty($setup_args['pue_options'])) { |
|
| 595 | - self::$_settings[ $addon_name ]['pue_options'] = array( |
|
| 596 | - 'pue_plugin_slug' => isset($setup_args['pue_options']['pue_plugin_slug']) |
|
| 597 | - ? (string) $setup_args['pue_options']['pue_plugin_slug'] |
|
| 598 | - : 'espresso_' . strtolower($class_name), |
|
| 599 | - 'plugin_basename' => isset($setup_args['pue_options']['plugin_basename']) |
|
| 600 | - ? (string) $setup_args['pue_options']['plugin_basename'] |
|
| 601 | - : plugin_basename($setup_args['main_file_path']), |
|
| 602 | - 'checkPeriod' => isset($setup_args['pue_options']['checkPeriod']) |
|
| 603 | - ? (string) $setup_args['pue_options']['checkPeriod'] |
|
| 604 | - : '24', |
|
| 605 | - 'use_wp_update' => isset($setup_args['pue_options']['use_wp_update']) |
|
| 606 | - ? (string) $setup_args['pue_options']['use_wp_update'] |
|
| 607 | - : false, |
|
| 608 | - ); |
|
| 609 | - add_action( |
|
| 610 | - 'AHEE__EE_System__brew_espresso__after_pue_init', |
|
| 611 | - array('EE_Register_Addon', 'load_pue_update') |
|
| 612 | - ); |
|
| 613 | - } |
|
| 614 | - } |
|
| 582 | + /** |
|
| 583 | + * if plugin update engine is being used for auto-updates, |
|
| 584 | + * then let's set that up now before going any further so that ALL addons can be updated |
|
| 585 | + * (not needed if PUE is not being used) |
|
| 586 | + * |
|
| 587 | + * @param string $addon_name |
|
| 588 | + * @param string $class_name |
|
| 589 | + * @param array $setup_args |
|
| 590 | + * @return void |
|
| 591 | + */ |
|
| 592 | + private static function _parse_pue_options($addon_name, $class_name, array $setup_args) |
|
| 593 | + { |
|
| 594 | + if (! empty($setup_args['pue_options'])) { |
|
| 595 | + self::$_settings[ $addon_name ]['pue_options'] = array( |
|
| 596 | + 'pue_plugin_slug' => isset($setup_args['pue_options']['pue_plugin_slug']) |
|
| 597 | + ? (string) $setup_args['pue_options']['pue_plugin_slug'] |
|
| 598 | + : 'espresso_' . strtolower($class_name), |
|
| 599 | + 'plugin_basename' => isset($setup_args['pue_options']['plugin_basename']) |
|
| 600 | + ? (string) $setup_args['pue_options']['plugin_basename'] |
|
| 601 | + : plugin_basename($setup_args['main_file_path']), |
|
| 602 | + 'checkPeriod' => isset($setup_args['pue_options']['checkPeriod']) |
|
| 603 | + ? (string) $setup_args['pue_options']['checkPeriod'] |
|
| 604 | + : '24', |
|
| 605 | + 'use_wp_update' => isset($setup_args['pue_options']['use_wp_update']) |
|
| 606 | + ? (string) $setup_args['pue_options']['use_wp_update'] |
|
| 607 | + : false, |
|
| 608 | + ); |
|
| 609 | + add_action( |
|
| 610 | + 'AHEE__EE_System__brew_espresso__after_pue_init', |
|
| 611 | + array('EE_Register_Addon', 'load_pue_update') |
|
| 612 | + ); |
|
| 613 | + } |
|
| 614 | + } |
|
| 615 | 615 | |
| 616 | 616 | |
| 617 | - /** |
|
| 618 | - * register namespaces right away before any other files or classes get loaded, but AFTER the version checks |
|
| 619 | - * |
|
| 620 | - * @param array $addon_settings |
|
| 621 | - * @return void |
|
| 622 | - */ |
|
| 623 | - private static function _setup_namespaces(array $addon_settings) |
|
| 624 | - { |
|
| 625 | - // |
|
| 626 | - if ( |
|
| 627 | - isset( |
|
| 628 | - $addon_settings['namespace']['FQNS'], |
|
| 629 | - $addon_settings['namespace']['DIR'] |
|
| 630 | - ) |
|
| 631 | - ) { |
|
| 632 | - EE_Psr4AutoloaderInit::psr4_loader()->addNamespace( |
|
| 633 | - $addon_settings['namespace']['FQNS'], |
|
| 634 | - $addon_settings['namespace']['DIR'] |
|
| 635 | - ); |
|
| 636 | - } |
|
| 637 | - } |
|
| 617 | + /** |
|
| 618 | + * register namespaces right away before any other files or classes get loaded, but AFTER the version checks |
|
| 619 | + * |
|
| 620 | + * @param array $addon_settings |
|
| 621 | + * @return void |
|
| 622 | + */ |
|
| 623 | + private static function _setup_namespaces(array $addon_settings) |
|
| 624 | + { |
|
| 625 | + // |
|
| 626 | + if ( |
|
| 627 | + isset( |
|
| 628 | + $addon_settings['namespace']['FQNS'], |
|
| 629 | + $addon_settings['namespace']['DIR'] |
|
| 630 | + ) |
|
| 631 | + ) { |
|
| 632 | + EE_Psr4AutoloaderInit::psr4_loader()->addNamespace( |
|
| 633 | + $addon_settings['namespace']['FQNS'], |
|
| 634 | + $addon_settings['namespace']['DIR'] |
|
| 635 | + ); |
|
| 636 | + } |
|
| 637 | + } |
|
| 638 | 638 | |
| 639 | 639 | |
| 640 | - /** |
|
| 641 | - * @param string $addon_name |
|
| 642 | - * @param array $addon_settings |
|
| 643 | - * @return bool |
|
| 644 | - * @throws EE_Error |
|
| 645 | - * @throws InvalidArgumentException |
|
| 646 | - * @throws ReflectionException |
|
| 647 | - * @throws InvalidDataTypeException |
|
| 648 | - * @throws InvalidInterfaceException |
|
| 649 | - */ |
|
| 650 | - private static function _addon_activation($addon_name, array $addon_settings) |
|
| 651 | - { |
|
| 652 | - // this is an activation request |
|
| 653 | - if (did_action('activate_plugin')) { |
|
| 654 | - //to find if THIS is the addon that was activated, just check if we have already registered it or not |
|
| 655 | - //(as the newly-activated addon wasn't around the first time addons were registered). |
|
| 656 | - //Note: the presence of pue_options in the addon registration options will initialize the $_settings |
|
| 657 | - //property for the add-on, but the add-on is only partially initialized. Hence, the additional check. |
|
| 658 | - if (! isset(self::$_settings[ $addon_name ]) |
|
| 659 | - || (isset(self::$_settings[ $addon_name ]) |
|
| 660 | - && ! isset(self::$_settings[ $addon_name ]['class_name']) |
|
| 661 | - ) |
|
| 662 | - ) { |
|
| 663 | - self::$_settings[ $addon_name ] = $addon_settings; |
|
| 664 | - $addon = self::_load_and_init_addon_class($addon_name); |
|
| 665 | - $addon->set_activation_indicator_option(); |
|
| 666 | - // dont bother setting up the rest of the addon. |
|
| 667 | - // we know it was just activated and the request will end soon |
|
| 668 | - } |
|
| 669 | - return true; |
|
| 670 | - } |
|
| 671 | - // make sure this was called in the right place! |
|
| 672 | - if ( |
|
| 673 | - ! did_action('AHEE__EE_System__load_espresso_addons') |
|
| 674 | - || did_action('AHEE__EE_System___detect_if_activation_or_upgrade__begin') |
|
| 675 | - ) { |
|
| 676 | - EE_Error::doing_it_wrong( |
|
| 677 | - __METHOD__, |
|
| 678 | - sprintf( |
|
| 679 | - __( |
|
| 680 | - '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.', |
|
| 681 | - 'event_espresso' |
|
| 682 | - ), |
|
| 683 | - $addon_name |
|
| 684 | - ), |
|
| 685 | - '4.3.0' |
|
| 686 | - ); |
|
| 687 | - } |
|
| 688 | - // make sure addon settings are set correctly without overwriting anything existing |
|
| 689 | - if (isset(self::$_settings[ $addon_name ])) { |
|
| 690 | - self::$_settings[ $addon_name ] += $addon_settings; |
|
| 691 | - } else { |
|
| 692 | - self::$_settings[ $addon_name ] = $addon_settings; |
|
| 693 | - } |
|
| 694 | - return false; |
|
| 695 | - } |
|
| 640 | + /** |
|
| 641 | + * @param string $addon_name |
|
| 642 | + * @param array $addon_settings |
|
| 643 | + * @return bool |
|
| 644 | + * @throws EE_Error |
|
| 645 | + * @throws InvalidArgumentException |
|
| 646 | + * @throws ReflectionException |
|
| 647 | + * @throws InvalidDataTypeException |
|
| 648 | + * @throws InvalidInterfaceException |
|
| 649 | + */ |
|
| 650 | + private static function _addon_activation($addon_name, array $addon_settings) |
|
| 651 | + { |
|
| 652 | + // this is an activation request |
|
| 653 | + if (did_action('activate_plugin')) { |
|
| 654 | + //to find if THIS is the addon that was activated, just check if we have already registered it or not |
|
| 655 | + //(as the newly-activated addon wasn't around the first time addons were registered). |
|
| 656 | + //Note: the presence of pue_options in the addon registration options will initialize the $_settings |
|
| 657 | + //property for the add-on, but the add-on is only partially initialized. Hence, the additional check. |
|
| 658 | + if (! isset(self::$_settings[ $addon_name ]) |
|
| 659 | + || (isset(self::$_settings[ $addon_name ]) |
|
| 660 | + && ! isset(self::$_settings[ $addon_name ]['class_name']) |
|
| 661 | + ) |
|
| 662 | + ) { |
|
| 663 | + self::$_settings[ $addon_name ] = $addon_settings; |
|
| 664 | + $addon = self::_load_and_init_addon_class($addon_name); |
|
| 665 | + $addon->set_activation_indicator_option(); |
|
| 666 | + // dont bother setting up the rest of the addon. |
|
| 667 | + // we know it was just activated and the request will end soon |
|
| 668 | + } |
|
| 669 | + return true; |
|
| 670 | + } |
|
| 671 | + // make sure this was called in the right place! |
|
| 672 | + if ( |
|
| 673 | + ! did_action('AHEE__EE_System__load_espresso_addons') |
|
| 674 | + || did_action('AHEE__EE_System___detect_if_activation_or_upgrade__begin') |
|
| 675 | + ) { |
|
| 676 | + EE_Error::doing_it_wrong( |
|
| 677 | + __METHOD__, |
|
| 678 | + sprintf( |
|
| 679 | + __( |
|
| 680 | + '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.', |
|
| 681 | + 'event_espresso' |
|
| 682 | + ), |
|
| 683 | + $addon_name |
|
| 684 | + ), |
|
| 685 | + '4.3.0' |
|
| 686 | + ); |
|
| 687 | + } |
|
| 688 | + // make sure addon settings are set correctly without overwriting anything existing |
|
| 689 | + if (isset(self::$_settings[ $addon_name ])) { |
|
| 690 | + self::$_settings[ $addon_name ] += $addon_settings; |
|
| 691 | + } else { |
|
| 692 | + self::$_settings[ $addon_name ] = $addon_settings; |
|
| 693 | + } |
|
| 694 | + return false; |
|
| 695 | + } |
|
| 696 | 696 | |
| 697 | 697 | |
| 698 | - /** |
|
| 699 | - * @param string $addon_name |
|
| 700 | - * @return void |
|
| 701 | - * @throws EE_Error |
|
| 702 | - */ |
|
| 703 | - private static function _setup_autoloaders($addon_name) |
|
| 704 | - { |
|
| 705 | - if (! empty(self::$_settings[ $addon_name ]['autoloader_paths'])) { |
|
| 706 | - // setup autoloader for single file |
|
| 707 | - EEH_Autoloader::instance()->register_autoloader(self::$_settings[ $addon_name ]['autoloader_paths']); |
|
| 708 | - } |
|
| 709 | - // setup autoloaders for folders |
|
| 710 | - if (! empty(self::$_settings[ $addon_name ]['autoloader_folders'])) { |
|
| 711 | - foreach ((array) self::$_settings[ $addon_name ]['autoloader_folders'] as $autoloader_folder) { |
|
| 712 | - EEH_Autoloader::register_autoloaders_for_each_file_in_folder($autoloader_folder); |
|
| 713 | - } |
|
| 714 | - } |
|
| 715 | - } |
|
| 698 | + /** |
|
| 699 | + * @param string $addon_name |
|
| 700 | + * @return void |
|
| 701 | + * @throws EE_Error |
|
| 702 | + */ |
|
| 703 | + private static function _setup_autoloaders($addon_name) |
|
| 704 | + { |
|
| 705 | + if (! empty(self::$_settings[ $addon_name ]['autoloader_paths'])) { |
|
| 706 | + // setup autoloader for single file |
|
| 707 | + EEH_Autoloader::instance()->register_autoloader(self::$_settings[ $addon_name ]['autoloader_paths']); |
|
| 708 | + } |
|
| 709 | + // setup autoloaders for folders |
|
| 710 | + if (! empty(self::$_settings[ $addon_name ]['autoloader_folders'])) { |
|
| 711 | + foreach ((array) self::$_settings[ $addon_name ]['autoloader_folders'] as $autoloader_folder) { |
|
| 712 | + EEH_Autoloader::register_autoloaders_for_each_file_in_folder($autoloader_folder); |
|
| 713 | + } |
|
| 714 | + } |
|
| 715 | + } |
|
| 716 | 716 | |
| 717 | 717 | |
| 718 | - /** |
|
| 719 | - * register new models and extensions |
|
| 720 | - * |
|
| 721 | - * @param string $addon_name |
|
| 722 | - * @return void |
|
| 723 | - * @throws EE_Error |
|
| 724 | - */ |
|
| 725 | - private static function _register_models_and_extensions($addon_name) |
|
| 726 | - { |
|
| 727 | - // register new models |
|
| 728 | - if ( |
|
| 729 | - ! empty(self::$_settings[ $addon_name ]['model_paths']) |
|
| 730 | - || ! empty(self::$_settings[ $addon_name ]['class_paths']) |
|
| 731 | - ) { |
|
| 732 | - EE_Register_Model::register( |
|
| 733 | - $addon_name, |
|
| 734 | - array( |
|
| 735 | - 'model_paths' => self::$_settings[ $addon_name ]['model_paths'], |
|
| 736 | - 'class_paths' => self::$_settings[ $addon_name ]['class_paths'], |
|
| 737 | - ) |
|
| 738 | - ); |
|
| 739 | - } |
|
| 740 | - // register model extensions |
|
| 741 | - if ( |
|
| 742 | - ! empty(self::$_settings[ $addon_name ]['model_extension_paths']) |
|
| 743 | - || ! empty(self::$_settings[ $addon_name ]['class_extension_paths']) |
|
| 744 | - ) { |
|
| 745 | - EE_Register_Model_Extensions::register( |
|
| 746 | - $addon_name, |
|
| 747 | - array( |
|
| 748 | - 'model_extension_paths' => self::$_settings[ $addon_name ]['model_extension_paths'], |
|
| 749 | - 'class_extension_paths' => self::$_settings[ $addon_name ]['class_extension_paths'], |
|
| 750 | - ) |
|
| 751 | - ); |
|
| 752 | - } |
|
| 753 | - } |
|
| 718 | + /** |
|
| 719 | + * register new models and extensions |
|
| 720 | + * |
|
| 721 | + * @param string $addon_name |
|
| 722 | + * @return void |
|
| 723 | + * @throws EE_Error |
|
| 724 | + */ |
|
| 725 | + private static function _register_models_and_extensions($addon_name) |
|
| 726 | + { |
|
| 727 | + // register new models |
|
| 728 | + if ( |
|
| 729 | + ! empty(self::$_settings[ $addon_name ]['model_paths']) |
|
| 730 | + || ! empty(self::$_settings[ $addon_name ]['class_paths']) |
|
| 731 | + ) { |
|
| 732 | + EE_Register_Model::register( |
|
| 733 | + $addon_name, |
|
| 734 | + array( |
|
| 735 | + 'model_paths' => self::$_settings[ $addon_name ]['model_paths'], |
|
| 736 | + 'class_paths' => self::$_settings[ $addon_name ]['class_paths'], |
|
| 737 | + ) |
|
| 738 | + ); |
|
| 739 | + } |
|
| 740 | + // register model extensions |
|
| 741 | + if ( |
|
| 742 | + ! empty(self::$_settings[ $addon_name ]['model_extension_paths']) |
|
| 743 | + || ! empty(self::$_settings[ $addon_name ]['class_extension_paths']) |
|
| 744 | + ) { |
|
| 745 | + EE_Register_Model_Extensions::register( |
|
| 746 | + $addon_name, |
|
| 747 | + array( |
|
| 748 | + 'model_extension_paths' => self::$_settings[ $addon_name ]['model_extension_paths'], |
|
| 749 | + 'class_extension_paths' => self::$_settings[ $addon_name ]['class_extension_paths'], |
|
| 750 | + ) |
|
| 751 | + ); |
|
| 752 | + } |
|
| 753 | + } |
|
| 754 | 754 | |
| 755 | 755 | |
| 756 | - /** |
|
| 757 | - * @param string $addon_name |
|
| 758 | - * @return void |
|
| 759 | - * @throws EE_Error |
|
| 760 | - */ |
|
| 761 | - private static function _register_data_migration_scripts($addon_name) |
|
| 762 | - { |
|
| 763 | - // setup DMS |
|
| 764 | - if (! empty(self::$_settings[ $addon_name ]['dms_paths'])) { |
|
| 765 | - EE_Register_Data_Migration_Scripts::register( |
|
| 766 | - $addon_name, |
|
| 767 | - array('dms_paths' => self::$_settings[ $addon_name ]['dms_paths']) |
|
| 768 | - ); |
|
| 769 | - } |
|
| 770 | - } |
|
| 756 | + /** |
|
| 757 | + * @param string $addon_name |
|
| 758 | + * @return void |
|
| 759 | + * @throws EE_Error |
|
| 760 | + */ |
|
| 761 | + private static function _register_data_migration_scripts($addon_name) |
|
| 762 | + { |
|
| 763 | + // setup DMS |
|
| 764 | + if (! empty(self::$_settings[ $addon_name ]['dms_paths'])) { |
|
| 765 | + EE_Register_Data_Migration_Scripts::register( |
|
| 766 | + $addon_name, |
|
| 767 | + array('dms_paths' => self::$_settings[ $addon_name ]['dms_paths']) |
|
| 768 | + ); |
|
| 769 | + } |
|
| 770 | + } |
|
| 771 | 771 | |
| 772 | 772 | |
| 773 | - /** |
|
| 774 | - * @param string $addon_name |
|
| 775 | - * @return void |
|
| 776 | - * @throws EE_Error |
|
| 777 | - */ |
|
| 778 | - private static function _register_config($addon_name) |
|
| 779 | - { |
|
| 780 | - // if config_class is present let's register config. |
|
| 781 | - if (! empty(self::$_settings[ $addon_name ]['config_class'])) { |
|
| 782 | - EE_Register_Config::register( |
|
| 783 | - self::$_settings[ $addon_name ]['config_class'], |
|
| 784 | - array( |
|
| 785 | - 'config_section' => self::$_settings[ $addon_name ]['config_section'], |
|
| 786 | - 'config_name' => self::$_settings[ $addon_name ]['config_name'], |
|
| 787 | - ) |
|
| 788 | - ); |
|
| 789 | - } |
|
| 790 | - } |
|
| 773 | + /** |
|
| 774 | + * @param string $addon_name |
|
| 775 | + * @return void |
|
| 776 | + * @throws EE_Error |
|
| 777 | + */ |
|
| 778 | + private static function _register_config($addon_name) |
|
| 779 | + { |
|
| 780 | + // if config_class is present let's register config. |
|
| 781 | + if (! empty(self::$_settings[ $addon_name ]['config_class'])) { |
|
| 782 | + EE_Register_Config::register( |
|
| 783 | + self::$_settings[ $addon_name ]['config_class'], |
|
| 784 | + array( |
|
| 785 | + 'config_section' => self::$_settings[ $addon_name ]['config_section'], |
|
| 786 | + 'config_name' => self::$_settings[ $addon_name ]['config_name'], |
|
| 787 | + ) |
|
| 788 | + ); |
|
| 789 | + } |
|
| 790 | + } |
|
| 791 | 791 | |
| 792 | 792 | |
| 793 | - /** |
|
| 794 | - * @param string $addon_name |
|
| 795 | - * @return void |
|
| 796 | - * @throws EE_Error |
|
| 797 | - */ |
|
| 798 | - private static function _register_admin_pages($addon_name) |
|
| 799 | - { |
|
| 800 | - if (! empty(self::$_settings[ $addon_name ]['admin_path'])) { |
|
| 801 | - EE_Register_Admin_Page::register( |
|
| 802 | - $addon_name, |
|
| 803 | - array('page_path' => self::$_settings[ $addon_name ]['admin_path']) |
|
| 804 | - ); |
|
| 805 | - } |
|
| 806 | - } |
|
| 793 | + /** |
|
| 794 | + * @param string $addon_name |
|
| 795 | + * @return void |
|
| 796 | + * @throws EE_Error |
|
| 797 | + */ |
|
| 798 | + private static function _register_admin_pages($addon_name) |
|
| 799 | + { |
|
| 800 | + if (! empty(self::$_settings[ $addon_name ]['admin_path'])) { |
|
| 801 | + EE_Register_Admin_Page::register( |
|
| 802 | + $addon_name, |
|
| 803 | + array('page_path' => self::$_settings[ $addon_name ]['admin_path']) |
|
| 804 | + ); |
|
| 805 | + } |
|
| 806 | + } |
|
| 807 | 807 | |
| 808 | 808 | |
| 809 | - /** |
|
| 810 | - * @param string $addon_name |
|
| 811 | - * @return void |
|
| 812 | - * @throws EE_Error |
|
| 813 | - */ |
|
| 814 | - private static function _register_modules($addon_name) |
|
| 815 | - { |
|
| 816 | - if (! empty(self::$_settings[ $addon_name ]['module_paths'])) { |
|
| 817 | - EE_Register_Module::register( |
|
| 818 | - $addon_name, |
|
| 819 | - array('module_paths' => self::$_settings[ $addon_name ]['module_paths']) |
|
| 820 | - ); |
|
| 821 | - } |
|
| 822 | - } |
|
| 809 | + /** |
|
| 810 | + * @param string $addon_name |
|
| 811 | + * @return void |
|
| 812 | + * @throws EE_Error |
|
| 813 | + */ |
|
| 814 | + private static function _register_modules($addon_name) |
|
| 815 | + { |
|
| 816 | + if (! empty(self::$_settings[ $addon_name ]['module_paths'])) { |
|
| 817 | + EE_Register_Module::register( |
|
| 818 | + $addon_name, |
|
| 819 | + array('module_paths' => self::$_settings[ $addon_name ]['module_paths']) |
|
| 820 | + ); |
|
| 821 | + } |
|
| 822 | + } |
|
| 823 | 823 | |
| 824 | 824 | |
| 825 | - /** |
|
| 826 | - * @param string $addon_name |
|
| 827 | - * @return void |
|
| 828 | - * @throws EE_Error |
|
| 829 | - */ |
|
| 830 | - private static function _register_shortcodes($addon_name) |
|
| 831 | - { |
|
| 832 | - if (! empty(self::$_settings[ $addon_name ]['shortcode_paths']) |
|
| 833 | - || ! empty(self::$_settings[ $addon_name ]['shortcode_fqcns']) |
|
| 834 | - ) { |
|
| 835 | - EE_Register_Shortcode::register( |
|
| 836 | - $addon_name, |
|
| 837 | - array( |
|
| 838 | - 'shortcode_paths' => isset(self::$_settings[ $addon_name ]['shortcode_paths']) |
|
| 839 | - ? self::$_settings[ $addon_name ]['shortcode_paths'] |
|
| 840 | - : array(), |
|
| 841 | - 'shortcode_fqcns' => isset(self::$_settings[ $addon_name ]['shortcode_fqcns']) |
|
| 842 | - ? self::$_settings[ $addon_name ]['shortcode_fqcns'] |
|
| 843 | - : array(), |
|
| 844 | - ) |
|
| 845 | - ); |
|
| 846 | - } |
|
| 847 | - } |
|
| 825 | + /** |
|
| 826 | + * @param string $addon_name |
|
| 827 | + * @return void |
|
| 828 | + * @throws EE_Error |
|
| 829 | + */ |
|
| 830 | + private static function _register_shortcodes($addon_name) |
|
| 831 | + { |
|
| 832 | + if (! empty(self::$_settings[ $addon_name ]['shortcode_paths']) |
|
| 833 | + || ! empty(self::$_settings[ $addon_name ]['shortcode_fqcns']) |
|
| 834 | + ) { |
|
| 835 | + EE_Register_Shortcode::register( |
|
| 836 | + $addon_name, |
|
| 837 | + array( |
|
| 838 | + 'shortcode_paths' => isset(self::$_settings[ $addon_name ]['shortcode_paths']) |
|
| 839 | + ? self::$_settings[ $addon_name ]['shortcode_paths'] |
|
| 840 | + : array(), |
|
| 841 | + 'shortcode_fqcns' => isset(self::$_settings[ $addon_name ]['shortcode_fqcns']) |
|
| 842 | + ? self::$_settings[ $addon_name ]['shortcode_fqcns'] |
|
| 843 | + : array(), |
|
| 844 | + ) |
|
| 845 | + ); |
|
| 846 | + } |
|
| 847 | + } |
|
| 848 | 848 | |
| 849 | 849 | |
| 850 | - /** |
|
| 851 | - * @param string $addon_name |
|
| 852 | - * @return void |
|
| 853 | - * @throws EE_Error |
|
| 854 | - */ |
|
| 855 | - private static function _register_widgets($addon_name) |
|
| 856 | - { |
|
| 857 | - if (! empty(self::$_settings[ $addon_name ]['widget_paths'])) { |
|
| 858 | - EE_Register_Widget::register( |
|
| 859 | - $addon_name, |
|
| 860 | - array('widget_paths' => self::$_settings[ $addon_name ]['widget_paths']) |
|
| 861 | - ); |
|
| 862 | - } |
|
| 863 | - } |
|
| 850 | + /** |
|
| 851 | + * @param string $addon_name |
|
| 852 | + * @return void |
|
| 853 | + * @throws EE_Error |
|
| 854 | + */ |
|
| 855 | + private static function _register_widgets($addon_name) |
|
| 856 | + { |
|
| 857 | + if (! empty(self::$_settings[ $addon_name ]['widget_paths'])) { |
|
| 858 | + EE_Register_Widget::register( |
|
| 859 | + $addon_name, |
|
| 860 | + array('widget_paths' => self::$_settings[ $addon_name ]['widget_paths']) |
|
| 861 | + ); |
|
| 862 | + } |
|
| 863 | + } |
|
| 864 | 864 | |
| 865 | 865 | |
| 866 | - /** |
|
| 867 | - * @param string $addon_name |
|
| 868 | - * @return void |
|
| 869 | - * @throws EE_Error |
|
| 870 | - */ |
|
| 871 | - private static function _register_capabilities($addon_name) |
|
| 872 | - { |
|
| 873 | - if (! empty(self::$_settings[ $addon_name ]['capabilities'])) { |
|
| 874 | - EE_Register_Capabilities::register( |
|
| 875 | - $addon_name, |
|
| 876 | - array( |
|
| 877 | - 'capabilities' => self::$_settings[ $addon_name ]['capabilities'], |
|
| 878 | - 'capability_maps' => self::$_settings[ $addon_name ]['capability_maps'], |
|
| 879 | - ) |
|
| 880 | - ); |
|
| 881 | - } |
|
| 882 | - } |
|
| 866 | + /** |
|
| 867 | + * @param string $addon_name |
|
| 868 | + * @return void |
|
| 869 | + * @throws EE_Error |
|
| 870 | + */ |
|
| 871 | + private static function _register_capabilities($addon_name) |
|
| 872 | + { |
|
| 873 | + if (! empty(self::$_settings[ $addon_name ]['capabilities'])) { |
|
| 874 | + EE_Register_Capabilities::register( |
|
| 875 | + $addon_name, |
|
| 876 | + array( |
|
| 877 | + 'capabilities' => self::$_settings[ $addon_name ]['capabilities'], |
|
| 878 | + 'capability_maps' => self::$_settings[ $addon_name ]['capability_maps'], |
|
| 879 | + ) |
|
| 880 | + ); |
|
| 881 | + } |
|
| 882 | + } |
|
| 883 | 883 | |
| 884 | 884 | |
| 885 | - /** |
|
| 886 | - * @param string $addon_name |
|
| 887 | - * @return void |
|
| 888 | - * @throws EE_Error |
|
| 889 | - */ |
|
| 890 | - private static function _register_message_types($addon_name) |
|
| 891 | - { |
|
| 892 | - if (! empty(self::$_settings[ $addon_name ]['message_types'])) { |
|
| 893 | - add_action( |
|
| 894 | - 'EE_Brewing_Regular___messages_caf', |
|
| 895 | - array('EE_Register_Addon', 'register_message_types') |
|
| 896 | - ); |
|
| 897 | - } |
|
| 898 | - } |
|
| 885 | + /** |
|
| 886 | + * @param string $addon_name |
|
| 887 | + * @return void |
|
| 888 | + * @throws EE_Error |
|
| 889 | + */ |
|
| 890 | + private static function _register_message_types($addon_name) |
|
| 891 | + { |
|
| 892 | + if (! empty(self::$_settings[ $addon_name ]['message_types'])) { |
|
| 893 | + add_action( |
|
| 894 | + 'EE_Brewing_Regular___messages_caf', |
|
| 895 | + array('EE_Register_Addon', 'register_message_types') |
|
| 896 | + ); |
|
| 897 | + } |
|
| 898 | + } |
|
| 899 | 899 | |
| 900 | 900 | |
| 901 | - /** |
|
| 902 | - * @param string $addon_name |
|
| 903 | - * @return void |
|
| 904 | - * @throws EE_Error |
|
| 905 | - */ |
|
| 906 | - private static function _register_custom_post_types($addon_name) |
|
| 907 | - { |
|
| 908 | - if ( |
|
| 909 | - ! empty(self::$_settings[ $addon_name ]['custom_post_types']) |
|
| 910 | - || ! empty(self::$_settings[ $addon_name ]['custom_taxonomies']) |
|
| 911 | - ) { |
|
| 912 | - EE_Register_CPT::register( |
|
| 913 | - $addon_name, |
|
| 914 | - array( |
|
| 915 | - 'cpts' => self::$_settings[ $addon_name ]['custom_post_types'], |
|
| 916 | - 'cts' => self::$_settings[ $addon_name ]['custom_taxonomies'], |
|
| 917 | - 'default_terms' => self::$_settings[ $addon_name ]['default_terms'], |
|
| 918 | - ) |
|
| 919 | - ); |
|
| 920 | - } |
|
| 921 | - } |
|
| 901 | + /** |
|
| 902 | + * @param string $addon_name |
|
| 903 | + * @return void |
|
| 904 | + * @throws EE_Error |
|
| 905 | + */ |
|
| 906 | + private static function _register_custom_post_types($addon_name) |
|
| 907 | + { |
|
| 908 | + if ( |
|
| 909 | + ! empty(self::$_settings[ $addon_name ]['custom_post_types']) |
|
| 910 | + || ! empty(self::$_settings[ $addon_name ]['custom_taxonomies']) |
|
| 911 | + ) { |
|
| 912 | + EE_Register_CPT::register( |
|
| 913 | + $addon_name, |
|
| 914 | + array( |
|
| 915 | + 'cpts' => self::$_settings[ $addon_name ]['custom_post_types'], |
|
| 916 | + 'cts' => self::$_settings[ $addon_name ]['custom_taxonomies'], |
|
| 917 | + 'default_terms' => self::$_settings[ $addon_name ]['default_terms'], |
|
| 918 | + ) |
|
| 919 | + ); |
|
| 920 | + } |
|
| 921 | + } |
|
| 922 | 922 | |
| 923 | 923 | |
| 924 | - /** |
|
| 925 | - * @param string $addon_name |
|
| 926 | - * @return void |
|
| 927 | - * @throws InvalidArgumentException |
|
| 928 | - * @throws InvalidInterfaceException |
|
| 929 | - * @throws InvalidDataTypeException |
|
| 930 | - * @throws DomainException |
|
| 931 | - * @throws EE_Error |
|
| 932 | - */ |
|
| 933 | - private static function _register_payment_methods($addon_name) |
|
| 934 | - { |
|
| 935 | - if (! empty(self::$_settings[ $addon_name ]['payment_method_paths'])) { |
|
| 936 | - EE_Register_Payment_Method::register( |
|
| 937 | - $addon_name, |
|
| 938 | - array('payment_method_paths' => self::$_settings[ $addon_name ]['payment_method_paths']) |
|
| 939 | - ); |
|
| 940 | - } |
|
| 941 | - } |
|
| 924 | + /** |
|
| 925 | + * @param string $addon_name |
|
| 926 | + * @return void |
|
| 927 | + * @throws InvalidArgumentException |
|
| 928 | + * @throws InvalidInterfaceException |
|
| 929 | + * @throws InvalidDataTypeException |
|
| 930 | + * @throws DomainException |
|
| 931 | + * @throws EE_Error |
|
| 932 | + */ |
|
| 933 | + private static function _register_payment_methods($addon_name) |
|
| 934 | + { |
|
| 935 | + if (! empty(self::$_settings[ $addon_name ]['payment_method_paths'])) { |
|
| 936 | + EE_Register_Payment_Method::register( |
|
| 937 | + $addon_name, |
|
| 938 | + array('payment_method_paths' => self::$_settings[ $addon_name ]['payment_method_paths']) |
|
| 939 | + ); |
|
| 940 | + } |
|
| 941 | + } |
|
| 942 | 942 | |
| 943 | 943 | |
| 944 | - /** |
|
| 945 | - * Loads and instantiates the EE_Addon class and adds it onto the registry |
|
| 946 | - * |
|
| 947 | - * @param string $addon_name |
|
| 948 | - * @return EE_Addon |
|
| 949 | - * @throws InvalidArgumentException |
|
| 950 | - * @throws InvalidInterfaceException |
|
| 951 | - * @throws InvalidDataTypeException |
|
| 952 | - * @throws ReflectionException |
|
| 953 | - * @throws EE_Error |
|
| 954 | - */ |
|
| 955 | - private static function _load_and_init_addon_class($addon_name) |
|
| 956 | - { |
|
| 957 | - $loader = EventEspresso\core\services\loaders\LoaderFactory::getLoader(); |
|
| 958 | - $addon = $loader->getShared( |
|
| 959 | - self::$_settings[ $addon_name ]['class_name'], |
|
| 960 | - array('EE_Registry::create(addon)' => true) |
|
| 961 | - ); |
|
| 962 | - // setter inject dep map if required |
|
| 963 | - if ($addon instanceof RequiresDependencyMapInterface && $addon->dependencyMap() === null) { |
|
| 964 | - $addon->setDependencyMap($loader->getShared('EE_Dependency_Map')); |
|
| 965 | - } |
|
| 966 | - // setter inject domain if required |
|
| 967 | - if ( |
|
| 968 | - $addon instanceof RequiresDomainInterface |
|
| 969 | - && self::$_settings[ $addon_name ]['domain_fqcn'] !== '' |
|
| 970 | - && $addon->domain() === null |
|
| 971 | - ) { |
|
| 972 | - $addon->setDomain( |
|
| 973 | - $loader->getShared( |
|
| 974 | - self::$_settings[ $addon_name ]['domain_fqcn'], |
|
| 975 | - array( |
|
| 976 | - self::$_settings[ $addon_name ]['main_file_path'], |
|
| 977 | - self::$_settings[ $addon_name ]['version'], |
|
| 978 | - ) |
|
| 979 | - ) |
|
| 980 | - ); |
|
| 981 | - } |
|
| 982 | - $addon->set_name($addon_name); |
|
| 983 | - $addon->set_plugin_slug(self::$_settings[ $addon_name ]['plugin_slug']); |
|
| 984 | - $addon->set_plugin_basename(self::$_settings[ $addon_name ]['plugin_basename']); |
|
| 985 | - $addon->set_main_plugin_file(self::$_settings[ $addon_name ]['main_file_path']); |
|
| 986 | - $addon->set_plugin_action_slug(self::$_settings[ $addon_name ]['plugin_action_slug']); |
|
| 987 | - $addon->set_plugins_page_row(self::$_settings[ $addon_name ]['plugins_page_row']); |
|
| 988 | - $addon->set_version(self::$_settings[ $addon_name ]['version']); |
|
| 989 | - $addon->set_min_core_version(self::_effective_version(self::$_settings[ $addon_name ]['min_core_version'])); |
|
| 990 | - $addon->set_config_section(self::$_settings[ $addon_name ]['config_section']); |
|
| 991 | - $addon->set_config_class(self::$_settings[ $addon_name ]['config_class']); |
|
| 992 | - $addon->set_config_name(self::$_settings[ $addon_name ]['config_name']); |
|
| 993 | - //unfortunately this can't be hooked in upon construction, because we don't have |
|
| 994 | - //the plugin mainfile's path upon construction. |
|
| 995 | - register_deactivation_hook($addon->get_main_plugin_file(), array($addon, 'deactivation')); |
|
| 996 | - // call any additional admin_callback functions during load_admin_controller hook |
|
| 997 | - if (! empty(self::$_settings[ $addon_name ]['admin_callback'])) { |
|
| 998 | - add_action( |
|
| 999 | - 'AHEE__EE_System__load_controllers__load_admin_controllers', |
|
| 1000 | - array($addon, self::$_settings[ $addon_name ]['admin_callback']) |
|
| 1001 | - ); |
|
| 1002 | - } |
|
| 1003 | - return $addon; |
|
| 1004 | - } |
|
| 944 | + /** |
|
| 945 | + * Loads and instantiates the EE_Addon class and adds it onto the registry |
|
| 946 | + * |
|
| 947 | + * @param string $addon_name |
|
| 948 | + * @return EE_Addon |
|
| 949 | + * @throws InvalidArgumentException |
|
| 950 | + * @throws InvalidInterfaceException |
|
| 951 | + * @throws InvalidDataTypeException |
|
| 952 | + * @throws ReflectionException |
|
| 953 | + * @throws EE_Error |
|
| 954 | + */ |
|
| 955 | + private static function _load_and_init_addon_class($addon_name) |
|
| 956 | + { |
|
| 957 | + $loader = EventEspresso\core\services\loaders\LoaderFactory::getLoader(); |
|
| 958 | + $addon = $loader->getShared( |
|
| 959 | + self::$_settings[ $addon_name ]['class_name'], |
|
| 960 | + array('EE_Registry::create(addon)' => true) |
|
| 961 | + ); |
|
| 962 | + // setter inject dep map if required |
|
| 963 | + if ($addon instanceof RequiresDependencyMapInterface && $addon->dependencyMap() === null) { |
|
| 964 | + $addon->setDependencyMap($loader->getShared('EE_Dependency_Map')); |
|
| 965 | + } |
|
| 966 | + // setter inject domain if required |
|
| 967 | + if ( |
|
| 968 | + $addon instanceof RequiresDomainInterface |
|
| 969 | + && self::$_settings[ $addon_name ]['domain_fqcn'] !== '' |
|
| 970 | + && $addon->domain() === null |
|
| 971 | + ) { |
|
| 972 | + $addon->setDomain( |
|
| 973 | + $loader->getShared( |
|
| 974 | + self::$_settings[ $addon_name ]['domain_fqcn'], |
|
| 975 | + array( |
|
| 976 | + self::$_settings[ $addon_name ]['main_file_path'], |
|
| 977 | + self::$_settings[ $addon_name ]['version'], |
|
| 978 | + ) |
|
| 979 | + ) |
|
| 980 | + ); |
|
| 981 | + } |
|
| 982 | + $addon->set_name($addon_name); |
|
| 983 | + $addon->set_plugin_slug(self::$_settings[ $addon_name ]['plugin_slug']); |
|
| 984 | + $addon->set_plugin_basename(self::$_settings[ $addon_name ]['plugin_basename']); |
|
| 985 | + $addon->set_main_plugin_file(self::$_settings[ $addon_name ]['main_file_path']); |
|
| 986 | + $addon->set_plugin_action_slug(self::$_settings[ $addon_name ]['plugin_action_slug']); |
|
| 987 | + $addon->set_plugins_page_row(self::$_settings[ $addon_name ]['plugins_page_row']); |
|
| 988 | + $addon->set_version(self::$_settings[ $addon_name ]['version']); |
|
| 989 | + $addon->set_min_core_version(self::_effective_version(self::$_settings[ $addon_name ]['min_core_version'])); |
|
| 990 | + $addon->set_config_section(self::$_settings[ $addon_name ]['config_section']); |
|
| 991 | + $addon->set_config_class(self::$_settings[ $addon_name ]['config_class']); |
|
| 992 | + $addon->set_config_name(self::$_settings[ $addon_name ]['config_name']); |
|
| 993 | + //unfortunately this can't be hooked in upon construction, because we don't have |
|
| 994 | + //the plugin mainfile's path upon construction. |
|
| 995 | + register_deactivation_hook($addon->get_main_plugin_file(), array($addon, 'deactivation')); |
|
| 996 | + // call any additional admin_callback functions during load_admin_controller hook |
|
| 997 | + if (! empty(self::$_settings[ $addon_name ]['admin_callback'])) { |
|
| 998 | + add_action( |
|
| 999 | + 'AHEE__EE_System__load_controllers__load_admin_controllers', |
|
| 1000 | + array($addon, self::$_settings[ $addon_name ]['admin_callback']) |
|
| 1001 | + ); |
|
| 1002 | + } |
|
| 1003 | + return $addon; |
|
| 1004 | + } |
|
| 1005 | 1005 | |
| 1006 | 1006 | |
| 1007 | - /** |
|
| 1008 | - * load_pue_update - Update notifications |
|
| 1009 | - * |
|
| 1010 | - * @return void |
|
| 1011 | - * @throws InvalidArgumentException |
|
| 1012 | - * @throws InvalidDataTypeException |
|
| 1013 | - * @throws InvalidInterfaceException |
|
| 1014 | - */ |
|
| 1015 | - public static function load_pue_update() |
|
| 1016 | - { |
|
| 1017 | - // load PUE client |
|
| 1018 | - require_once EE_THIRD_PARTY . 'pue' . DS . 'pue-client.php'; |
|
| 1019 | - // cycle thru settings |
|
| 1020 | - foreach (self::$_settings as $settings) { |
|
| 1021 | - if (! empty($settings['pue_options'])) { |
|
| 1022 | - // initiate the class and start the plugin update engine! |
|
| 1023 | - new PluginUpdateEngineChecker( |
|
| 1024 | - // host file URL |
|
| 1025 | - 'https://eventespresso.com', |
|
| 1026 | - // plugin slug(s) |
|
| 1027 | - array( |
|
| 1028 | - 'premium' => array('p' => $settings['pue_options']['pue_plugin_slug']), |
|
| 1029 | - 'prerelease' => array('beta' => $settings['pue_options']['pue_plugin_slug'] . '-pr'), |
|
| 1030 | - ), |
|
| 1031 | - // options |
|
| 1032 | - array( |
|
| 1033 | - 'apikey' => EE_Registry::instance()->NET_CFG->core->site_license_key, |
|
| 1034 | - 'lang_domain' => 'event_espresso', |
|
| 1035 | - 'checkPeriod' => $settings['pue_options']['checkPeriod'], |
|
| 1036 | - 'option_key' => 'site_license_key', |
|
| 1037 | - 'options_page_slug' => 'event_espresso', |
|
| 1038 | - 'plugin_basename' => $settings['pue_options']['plugin_basename'], |
|
| 1039 | - // if use_wp_update is TRUE it means you want FREE versions of the plugin to be updated from WP |
|
| 1040 | - 'use_wp_update' => $settings['pue_options']['use_wp_update'], |
|
| 1041 | - ) |
|
| 1042 | - ); |
|
| 1043 | - } |
|
| 1044 | - } |
|
| 1045 | - } |
|
| 1007 | + /** |
|
| 1008 | + * load_pue_update - Update notifications |
|
| 1009 | + * |
|
| 1010 | + * @return void |
|
| 1011 | + * @throws InvalidArgumentException |
|
| 1012 | + * @throws InvalidDataTypeException |
|
| 1013 | + * @throws InvalidInterfaceException |
|
| 1014 | + */ |
|
| 1015 | + public static function load_pue_update() |
|
| 1016 | + { |
|
| 1017 | + // load PUE client |
|
| 1018 | + require_once EE_THIRD_PARTY . 'pue' . DS . 'pue-client.php'; |
|
| 1019 | + // cycle thru settings |
|
| 1020 | + foreach (self::$_settings as $settings) { |
|
| 1021 | + if (! empty($settings['pue_options'])) { |
|
| 1022 | + // initiate the class and start the plugin update engine! |
|
| 1023 | + new PluginUpdateEngineChecker( |
|
| 1024 | + // host file URL |
|
| 1025 | + 'https://eventespresso.com', |
|
| 1026 | + // plugin slug(s) |
|
| 1027 | + array( |
|
| 1028 | + 'premium' => array('p' => $settings['pue_options']['pue_plugin_slug']), |
|
| 1029 | + 'prerelease' => array('beta' => $settings['pue_options']['pue_plugin_slug'] . '-pr'), |
|
| 1030 | + ), |
|
| 1031 | + // options |
|
| 1032 | + array( |
|
| 1033 | + 'apikey' => EE_Registry::instance()->NET_CFG->core->site_license_key, |
|
| 1034 | + 'lang_domain' => 'event_espresso', |
|
| 1035 | + 'checkPeriod' => $settings['pue_options']['checkPeriod'], |
|
| 1036 | + 'option_key' => 'site_license_key', |
|
| 1037 | + 'options_page_slug' => 'event_espresso', |
|
| 1038 | + 'plugin_basename' => $settings['pue_options']['plugin_basename'], |
|
| 1039 | + // if use_wp_update is TRUE it means you want FREE versions of the plugin to be updated from WP |
|
| 1040 | + 'use_wp_update' => $settings['pue_options']['use_wp_update'], |
|
| 1041 | + ) |
|
| 1042 | + ); |
|
| 1043 | + } |
|
| 1044 | + } |
|
| 1045 | + } |
|
| 1046 | 1046 | |
| 1047 | 1047 | |
| 1048 | - /** |
|
| 1049 | - * Callback for EE_Brewing_Regular__messages_caf hook used to register message types. |
|
| 1050 | - * |
|
| 1051 | - * @since 4.4.0 |
|
| 1052 | - * @return void |
|
| 1053 | - * @throws EE_Error |
|
| 1054 | - */ |
|
| 1055 | - public static function register_message_types() |
|
| 1056 | - { |
|
| 1057 | - foreach (self::$_settings as $addon_name => $settings) { |
|
| 1058 | - if (! empty($settings['message_types'])) { |
|
| 1059 | - foreach ((array) $settings['message_types'] as $message_type => $message_type_settings) { |
|
| 1060 | - EE_Register_Message_Type::register($message_type, $message_type_settings); |
|
| 1061 | - } |
|
| 1062 | - } |
|
| 1063 | - } |
|
| 1064 | - } |
|
| 1048 | + /** |
|
| 1049 | + * Callback for EE_Brewing_Regular__messages_caf hook used to register message types. |
|
| 1050 | + * |
|
| 1051 | + * @since 4.4.0 |
|
| 1052 | + * @return void |
|
| 1053 | + * @throws EE_Error |
|
| 1054 | + */ |
|
| 1055 | + public static function register_message_types() |
|
| 1056 | + { |
|
| 1057 | + foreach (self::$_settings as $addon_name => $settings) { |
|
| 1058 | + if (! empty($settings['message_types'])) { |
|
| 1059 | + foreach ((array) $settings['message_types'] as $message_type => $message_type_settings) { |
|
| 1060 | + EE_Register_Message_Type::register($message_type, $message_type_settings); |
|
| 1061 | + } |
|
| 1062 | + } |
|
| 1063 | + } |
|
| 1064 | + } |
|
| 1065 | 1065 | |
| 1066 | 1066 | |
| 1067 | - /** |
|
| 1068 | - * This deregisters an addon that was previously registered with a specific addon_name. |
|
| 1069 | - * |
|
| 1070 | - * @since 4.3.0 |
|
| 1071 | - * @param string $addon_name the name for the addon that was previously registered |
|
| 1072 | - * @throws DomainException |
|
| 1073 | - * @throws EE_Error |
|
| 1074 | - * @throws InvalidArgumentException |
|
| 1075 | - * @throws InvalidDataTypeException |
|
| 1076 | - * @throws InvalidInterfaceException |
|
| 1077 | - */ |
|
| 1078 | - public static function deregister($addon_name = null) |
|
| 1079 | - { |
|
| 1080 | - if (isset(self::$_settings[ $addon_name ]['class_name'])) { |
|
| 1081 | - try { |
|
| 1082 | - do_action('AHEE__EE_Register_Addon__deregister__before', $addon_name); |
|
| 1083 | - $class_name = self::$_settings[ $addon_name ]['class_name']; |
|
| 1084 | - if (! empty(self::$_settings[ $addon_name ]['dms_paths'])) { |
|
| 1085 | - // setup DMS |
|
| 1086 | - EE_Register_Data_Migration_Scripts::deregister($addon_name); |
|
| 1087 | - } |
|
| 1088 | - if (! empty(self::$_settings[ $addon_name ]['admin_path'])) { |
|
| 1089 | - // register admin page |
|
| 1090 | - EE_Register_Admin_Page::deregister($addon_name); |
|
| 1091 | - } |
|
| 1092 | - if (! empty(self::$_settings[ $addon_name ]['module_paths'])) { |
|
| 1093 | - // add to list of modules to be registered |
|
| 1094 | - EE_Register_Module::deregister($addon_name); |
|
| 1095 | - } |
|
| 1096 | - if (! empty(self::$_settings[ $addon_name ]['shortcode_paths']) |
|
| 1097 | - || ! empty(self::$_settings[ $addon_name ]['shortcode_fqcns']) |
|
| 1098 | - ) { |
|
| 1099 | - // add to list of shortcodes to be registered |
|
| 1100 | - EE_Register_Shortcode::deregister($addon_name); |
|
| 1101 | - } |
|
| 1102 | - if (! empty(self::$_settings[ $addon_name ]['config_class'])) { |
|
| 1103 | - // if config_class present let's register config. |
|
| 1104 | - EE_Register_Config::deregister(self::$_settings[ $addon_name ]['config_class']); |
|
| 1105 | - } |
|
| 1106 | - if (! empty(self::$_settings[ $addon_name ]['widget_paths'])) { |
|
| 1107 | - // add to list of widgets to be registered |
|
| 1108 | - EE_Register_Widget::deregister($addon_name); |
|
| 1109 | - } |
|
| 1110 | - if (! empty(self::$_settings[ $addon_name ]['model_paths']) |
|
| 1111 | - || ! empty(self::$_settings[ $addon_name ]['class_paths']) |
|
| 1112 | - ) { |
|
| 1113 | - // add to list of shortcodes to be registered |
|
| 1114 | - EE_Register_Model::deregister($addon_name); |
|
| 1115 | - } |
|
| 1116 | - if (! empty(self::$_settings[ $addon_name ]['model_extension_paths']) |
|
| 1117 | - || ! empty(self::$_settings[ $addon_name ]['class_extension_paths']) |
|
| 1118 | - ) { |
|
| 1119 | - // add to list of shortcodes to be registered |
|
| 1120 | - EE_Register_Model_Extensions::deregister($addon_name); |
|
| 1121 | - } |
|
| 1122 | - if (! empty(self::$_settings[ $addon_name ]['message_types'])) { |
|
| 1123 | - foreach ( |
|
| 1124 | - (array) self::$_settings[ $addon_name ]['message_types'] as $message_type => |
|
| 1125 | - $message_type_settings |
|
| 1126 | - ) { |
|
| 1127 | - EE_Register_Message_Type::deregister($message_type); |
|
| 1128 | - } |
|
| 1129 | - } |
|
| 1130 | - //deregister capabilities for addon |
|
| 1131 | - if ( |
|
| 1132 | - ! empty(self::$_settings[ $addon_name ]['capabilities']) |
|
| 1133 | - || ! empty(self::$_settings[ $addon_name ]['capability_maps']) |
|
| 1134 | - ) { |
|
| 1135 | - EE_Register_Capabilities::deregister($addon_name); |
|
| 1136 | - } |
|
| 1137 | - //deregister custom_post_types for addon |
|
| 1138 | - if (! empty(self::$_settings[ $addon_name ]['custom_post_types'])) { |
|
| 1139 | - EE_Register_CPT::deregister($addon_name); |
|
| 1140 | - } |
|
| 1141 | - if (! empty(self::$_settings[ $addon_name ]['payment_method_paths'])) { |
|
| 1142 | - EE_Register_Payment_Method::deregister($addon_name); |
|
| 1143 | - } |
|
| 1144 | - $addon = EE_Registry::instance()->getAddon($class_name); |
|
| 1145 | - if ($addon instanceof EE_Addon) { |
|
| 1146 | - remove_action( |
|
| 1147 | - 'deactivate_' . $addon->get_main_plugin_file_basename(), |
|
| 1148 | - array($addon, 'deactivation') |
|
| 1149 | - ); |
|
| 1150 | - remove_action( |
|
| 1151 | - 'AHEE__EE_System__perform_activations_upgrades_and_migrations', |
|
| 1152 | - array($addon, 'initialize_db_if_no_migrations_required') |
|
| 1153 | - ); |
|
| 1154 | - //remove `after_registration` call |
|
| 1155 | - remove_action( |
|
| 1156 | - 'AHEE__EE_System__load_espresso_addons__complete', |
|
| 1157 | - array($addon, 'after_registration'), |
|
| 1158 | - 999 |
|
| 1159 | - ); |
|
| 1160 | - } |
|
| 1161 | - EE_Registry::instance()->removeAddon($class_name); |
|
| 1162 | - } catch (OutOfBoundsException $addon_not_yet_registered_exception) { |
|
| 1163 | - // the add-on was not yet registered in the registry, |
|
| 1164 | - // so RegistryContainer::__get() throws this exception. |
|
| 1165 | - // also no need to worry about this or log it, |
|
| 1166 | - // it's ok to deregister an add-on before its registered in the registry |
|
| 1167 | - } catch (Exception $e) { |
|
| 1168 | - new ExceptionLogger($e); |
|
| 1169 | - } |
|
| 1170 | - unset(self::$_settings[ $addon_name ]); |
|
| 1171 | - do_action('AHEE__EE_Register_Addon__deregister__after', $addon_name); |
|
| 1172 | - } |
|
| 1173 | - } |
|
| 1067 | + /** |
|
| 1068 | + * This deregisters an addon that was previously registered with a specific addon_name. |
|
| 1069 | + * |
|
| 1070 | + * @since 4.3.0 |
|
| 1071 | + * @param string $addon_name the name for the addon that was previously registered |
|
| 1072 | + * @throws DomainException |
|
| 1073 | + * @throws EE_Error |
|
| 1074 | + * @throws InvalidArgumentException |
|
| 1075 | + * @throws InvalidDataTypeException |
|
| 1076 | + * @throws InvalidInterfaceException |
|
| 1077 | + */ |
|
| 1078 | + public static function deregister($addon_name = null) |
|
| 1079 | + { |
|
| 1080 | + if (isset(self::$_settings[ $addon_name ]['class_name'])) { |
|
| 1081 | + try { |
|
| 1082 | + do_action('AHEE__EE_Register_Addon__deregister__before', $addon_name); |
|
| 1083 | + $class_name = self::$_settings[ $addon_name ]['class_name']; |
|
| 1084 | + if (! empty(self::$_settings[ $addon_name ]['dms_paths'])) { |
|
| 1085 | + // setup DMS |
|
| 1086 | + EE_Register_Data_Migration_Scripts::deregister($addon_name); |
|
| 1087 | + } |
|
| 1088 | + if (! empty(self::$_settings[ $addon_name ]['admin_path'])) { |
|
| 1089 | + // register admin page |
|
| 1090 | + EE_Register_Admin_Page::deregister($addon_name); |
|
| 1091 | + } |
|
| 1092 | + if (! empty(self::$_settings[ $addon_name ]['module_paths'])) { |
|
| 1093 | + // add to list of modules to be registered |
|
| 1094 | + EE_Register_Module::deregister($addon_name); |
|
| 1095 | + } |
|
| 1096 | + if (! empty(self::$_settings[ $addon_name ]['shortcode_paths']) |
|
| 1097 | + || ! empty(self::$_settings[ $addon_name ]['shortcode_fqcns']) |
|
| 1098 | + ) { |
|
| 1099 | + // add to list of shortcodes to be registered |
|
| 1100 | + EE_Register_Shortcode::deregister($addon_name); |
|
| 1101 | + } |
|
| 1102 | + if (! empty(self::$_settings[ $addon_name ]['config_class'])) { |
|
| 1103 | + // if config_class present let's register config. |
|
| 1104 | + EE_Register_Config::deregister(self::$_settings[ $addon_name ]['config_class']); |
|
| 1105 | + } |
|
| 1106 | + if (! empty(self::$_settings[ $addon_name ]['widget_paths'])) { |
|
| 1107 | + // add to list of widgets to be registered |
|
| 1108 | + EE_Register_Widget::deregister($addon_name); |
|
| 1109 | + } |
|
| 1110 | + if (! empty(self::$_settings[ $addon_name ]['model_paths']) |
|
| 1111 | + || ! empty(self::$_settings[ $addon_name ]['class_paths']) |
|
| 1112 | + ) { |
|
| 1113 | + // add to list of shortcodes to be registered |
|
| 1114 | + EE_Register_Model::deregister($addon_name); |
|
| 1115 | + } |
|
| 1116 | + if (! empty(self::$_settings[ $addon_name ]['model_extension_paths']) |
|
| 1117 | + || ! empty(self::$_settings[ $addon_name ]['class_extension_paths']) |
|
| 1118 | + ) { |
|
| 1119 | + // add to list of shortcodes to be registered |
|
| 1120 | + EE_Register_Model_Extensions::deregister($addon_name); |
|
| 1121 | + } |
|
| 1122 | + if (! empty(self::$_settings[ $addon_name ]['message_types'])) { |
|
| 1123 | + foreach ( |
|
| 1124 | + (array) self::$_settings[ $addon_name ]['message_types'] as $message_type => |
|
| 1125 | + $message_type_settings |
|
| 1126 | + ) { |
|
| 1127 | + EE_Register_Message_Type::deregister($message_type); |
|
| 1128 | + } |
|
| 1129 | + } |
|
| 1130 | + //deregister capabilities for addon |
|
| 1131 | + if ( |
|
| 1132 | + ! empty(self::$_settings[ $addon_name ]['capabilities']) |
|
| 1133 | + || ! empty(self::$_settings[ $addon_name ]['capability_maps']) |
|
| 1134 | + ) { |
|
| 1135 | + EE_Register_Capabilities::deregister($addon_name); |
|
| 1136 | + } |
|
| 1137 | + //deregister custom_post_types for addon |
|
| 1138 | + if (! empty(self::$_settings[ $addon_name ]['custom_post_types'])) { |
|
| 1139 | + EE_Register_CPT::deregister($addon_name); |
|
| 1140 | + } |
|
| 1141 | + if (! empty(self::$_settings[ $addon_name ]['payment_method_paths'])) { |
|
| 1142 | + EE_Register_Payment_Method::deregister($addon_name); |
|
| 1143 | + } |
|
| 1144 | + $addon = EE_Registry::instance()->getAddon($class_name); |
|
| 1145 | + if ($addon instanceof EE_Addon) { |
|
| 1146 | + remove_action( |
|
| 1147 | + 'deactivate_' . $addon->get_main_plugin_file_basename(), |
|
| 1148 | + array($addon, 'deactivation') |
|
| 1149 | + ); |
|
| 1150 | + remove_action( |
|
| 1151 | + 'AHEE__EE_System__perform_activations_upgrades_and_migrations', |
|
| 1152 | + array($addon, 'initialize_db_if_no_migrations_required') |
|
| 1153 | + ); |
|
| 1154 | + //remove `after_registration` call |
|
| 1155 | + remove_action( |
|
| 1156 | + 'AHEE__EE_System__load_espresso_addons__complete', |
|
| 1157 | + array($addon, 'after_registration'), |
|
| 1158 | + 999 |
|
| 1159 | + ); |
|
| 1160 | + } |
|
| 1161 | + EE_Registry::instance()->removeAddon($class_name); |
|
| 1162 | + } catch (OutOfBoundsException $addon_not_yet_registered_exception) { |
|
| 1163 | + // the add-on was not yet registered in the registry, |
|
| 1164 | + // so RegistryContainer::__get() throws this exception. |
|
| 1165 | + // also no need to worry about this or log it, |
|
| 1166 | + // it's ok to deregister an add-on before its registered in the registry |
|
| 1167 | + } catch (Exception $e) { |
|
| 1168 | + new ExceptionLogger($e); |
|
| 1169 | + } |
|
| 1170 | + unset(self::$_settings[ $addon_name ]); |
|
| 1171 | + do_action('AHEE__EE_Register_Addon__deregister__after', $addon_name); |
|
| 1172 | + } |
|
| 1173 | + } |
|
| 1174 | 1174 | } |
| 1175 | 1175 | // End of file EE_Register_Addon.lib.php |
| 1176 | 1176 | // Location: /core/libraries/plugin_api/EE_Register_Addon.lib.php |
@@ -72,15 +72,15 @@ discard block |
||
| 72 | 72 | // offsets: 0 . 1 . 2 . 3 . 4 |
| 73 | 73 | $version_parts = explode('.', $min_core_version); |
| 74 | 74 | //check they specified the micro version (after 2nd period) |
| 75 | - if (! isset($version_parts[2])) { |
|
| 75 | + if ( ! isset($version_parts[2])) { |
|
| 76 | 76 | $version_parts[2] = '0'; |
| 77 | 77 | } |
| 78 | 78 | //if they didn't specify the 'p', or 'rc' part. Just assume the lowest possible |
| 79 | 79 | //soon we can assume that's 'rc', but this current version is 'alpha' |
| 80 | - if (! isset($version_parts[3])) { |
|
| 80 | + if ( ! isset($version_parts[3])) { |
|
| 81 | 81 | $version_parts[3] = 'dev'; |
| 82 | 82 | } |
| 83 | - if (! isset($version_parts[4])) { |
|
| 83 | + if ( ! isset($version_parts[4])) { |
|
| 84 | 84 | $version_parts[4] = '000'; |
| 85 | 85 | } |
| 86 | 86 | return implode('.', $version_parts); |
@@ -256,7 +256,7 @@ discard block |
||
| 256 | 256 | // setup PUE |
| 257 | 257 | EE_Register_Addon::_parse_pue_options($addon_name, $class_name, $setup_args); |
| 258 | 258 | // does this addon work with this version of core or WordPress ? |
| 259 | - if (! EE_Register_Addon::_addon_is_compatible($addon_name, $addon_settings)) { |
|
| 259 | + if ( ! EE_Register_Addon::_addon_is_compatible($addon_name, $addon_settings)) { |
|
| 260 | 260 | return; |
| 261 | 261 | } |
| 262 | 262 | // register namespaces |
@@ -314,7 +314,7 @@ discard block |
||
| 314 | 314 | ) |
| 315 | 315 | ); |
| 316 | 316 | } |
| 317 | - if (! isset($setup_args['main_file_path']) || empty($setup_args['main_file_path'])) { |
|
| 317 | + if ( ! isset($setup_args['main_file_path']) || empty($setup_args['main_file_path'])) { |
|
| 318 | 318 | throw new EE_Error( |
| 319 | 319 | sprintf( |
| 320 | 320 | __( |
@@ -326,7 +326,7 @@ discard block |
||
| 326 | 326 | ); |
| 327 | 327 | } |
| 328 | 328 | // check that addon has not already been registered with that name |
| 329 | - if (isset(self::$_settings[ $addon_name ]) && ! did_action('activate_plugin')) { |
|
| 329 | + if (isset(self::$_settings[$addon_name]) && ! did_action('activate_plugin')) { |
|
| 330 | 330 | throw new EE_Error( |
| 331 | 331 | sprintf( |
| 332 | 332 | __( |
@@ -358,7 +358,7 @@ discard block |
||
| 358 | 358 | // check if classname is fully qualified or is a legacy classname already prefixed with 'EE_' |
| 359 | 359 | return strpos($class_name, '\\') || strpos($class_name, 'EE_') === 0 |
| 360 | 360 | ? $class_name |
| 361 | - : 'EE_' . $class_name; |
|
| 361 | + : 'EE_'.$class_name; |
|
| 362 | 362 | } |
| 363 | 363 | |
| 364 | 364 | |
@@ -519,9 +519,9 @@ discard block |
||
| 519 | 519 | $incompatibility_message = ''; |
| 520 | 520 | //check whether this addon version is compatible with EE core |
| 521 | 521 | if ( |
| 522 | - isset(EE_Register_Addon::$_incompatible_addons[ $addon_name ]) |
|
| 522 | + isset(EE_Register_Addon::$_incompatible_addons[$addon_name]) |
|
| 523 | 523 | && ! self::_meets_min_core_version_requirement( |
| 524 | - EE_Register_Addon::$_incompatible_addons[ $addon_name ], |
|
| 524 | + EE_Register_Addon::$_incompatible_addons[$addon_name], |
|
| 525 | 525 | $addon_settings['version'] |
| 526 | 526 | ) |
| 527 | 527 | ) { |
@@ -531,7 +531,7 @@ discard block |
||
| 531 | 531 | ), |
| 532 | 532 | $addon_name, |
| 533 | 533 | '<br />', |
| 534 | - EE_Register_Addon::$_incompatible_addons[ $addon_name ], |
|
| 534 | + EE_Register_Addon::$_incompatible_addons[$addon_name], |
|
| 535 | 535 | '<span style="font-weight: bold; color: #D54E21;">', |
| 536 | 536 | '</span><br />' |
| 537 | 537 | ); |
@@ -563,7 +563,7 @@ discard block |
||
| 563 | 563 | '</span><br />' |
| 564 | 564 | ); |
| 565 | 565 | } |
| 566 | - if (! empty($incompatibility_message)) { |
|
| 566 | + if ( ! empty($incompatibility_message)) { |
|
| 567 | 567 | // remove 'activate' from the REQUEST |
| 568 | 568 | // so WP doesn't erroneously tell the user the plugin activated fine when it didn't |
| 569 | 569 | unset($_GET['activate'], $_REQUEST['activate']); |
@@ -591,11 +591,11 @@ discard block |
||
| 591 | 591 | */ |
| 592 | 592 | private static function _parse_pue_options($addon_name, $class_name, array $setup_args) |
| 593 | 593 | { |
| 594 | - if (! empty($setup_args['pue_options'])) { |
|
| 595 | - self::$_settings[ $addon_name ]['pue_options'] = array( |
|
| 594 | + if ( ! empty($setup_args['pue_options'])) { |
|
| 595 | + self::$_settings[$addon_name]['pue_options'] = array( |
|
| 596 | 596 | 'pue_plugin_slug' => isset($setup_args['pue_options']['pue_plugin_slug']) |
| 597 | 597 | ? (string) $setup_args['pue_options']['pue_plugin_slug'] |
| 598 | - : 'espresso_' . strtolower($class_name), |
|
| 598 | + : 'espresso_'.strtolower($class_name), |
|
| 599 | 599 | 'plugin_basename' => isset($setup_args['pue_options']['plugin_basename']) |
| 600 | 600 | ? (string) $setup_args['pue_options']['plugin_basename'] |
| 601 | 601 | : plugin_basename($setup_args['main_file_path']), |
@@ -655,12 +655,12 @@ discard block |
||
| 655 | 655 | //(as the newly-activated addon wasn't around the first time addons were registered). |
| 656 | 656 | //Note: the presence of pue_options in the addon registration options will initialize the $_settings |
| 657 | 657 | //property for the add-on, but the add-on is only partially initialized. Hence, the additional check. |
| 658 | - if (! isset(self::$_settings[ $addon_name ]) |
|
| 659 | - || (isset(self::$_settings[ $addon_name ]) |
|
| 660 | - && ! isset(self::$_settings[ $addon_name ]['class_name']) |
|
| 658 | + if ( ! isset(self::$_settings[$addon_name]) |
|
| 659 | + || (isset(self::$_settings[$addon_name]) |
|
| 660 | + && ! isset(self::$_settings[$addon_name]['class_name']) |
|
| 661 | 661 | ) |
| 662 | 662 | ) { |
| 663 | - self::$_settings[ $addon_name ] = $addon_settings; |
|
| 663 | + self::$_settings[$addon_name] = $addon_settings; |
|
| 664 | 664 | $addon = self::_load_and_init_addon_class($addon_name); |
| 665 | 665 | $addon->set_activation_indicator_option(); |
| 666 | 666 | // dont bother setting up the rest of the addon. |
@@ -686,10 +686,10 @@ discard block |
||
| 686 | 686 | ); |
| 687 | 687 | } |
| 688 | 688 | // make sure addon settings are set correctly without overwriting anything existing |
| 689 | - if (isset(self::$_settings[ $addon_name ])) { |
|
| 690 | - self::$_settings[ $addon_name ] += $addon_settings; |
|
| 689 | + if (isset(self::$_settings[$addon_name])) { |
|
| 690 | + self::$_settings[$addon_name] += $addon_settings; |
|
| 691 | 691 | } else { |
| 692 | - self::$_settings[ $addon_name ] = $addon_settings; |
|
| 692 | + self::$_settings[$addon_name] = $addon_settings; |
|
| 693 | 693 | } |
| 694 | 694 | return false; |
| 695 | 695 | } |
@@ -702,13 +702,13 @@ discard block |
||
| 702 | 702 | */ |
| 703 | 703 | private static function _setup_autoloaders($addon_name) |
| 704 | 704 | { |
| 705 | - if (! empty(self::$_settings[ $addon_name ]['autoloader_paths'])) { |
|
| 705 | + if ( ! empty(self::$_settings[$addon_name]['autoloader_paths'])) { |
|
| 706 | 706 | // setup autoloader for single file |
| 707 | - EEH_Autoloader::instance()->register_autoloader(self::$_settings[ $addon_name ]['autoloader_paths']); |
|
| 707 | + EEH_Autoloader::instance()->register_autoloader(self::$_settings[$addon_name]['autoloader_paths']); |
|
| 708 | 708 | } |
| 709 | 709 | // setup autoloaders for folders |
| 710 | - if (! empty(self::$_settings[ $addon_name ]['autoloader_folders'])) { |
|
| 711 | - foreach ((array) self::$_settings[ $addon_name ]['autoloader_folders'] as $autoloader_folder) { |
|
| 710 | + if ( ! empty(self::$_settings[$addon_name]['autoloader_folders'])) { |
|
| 711 | + foreach ((array) self::$_settings[$addon_name]['autoloader_folders'] as $autoloader_folder) { |
|
| 712 | 712 | EEH_Autoloader::register_autoloaders_for_each_file_in_folder($autoloader_folder); |
| 713 | 713 | } |
| 714 | 714 | } |
@@ -726,27 +726,27 @@ discard block |
||
| 726 | 726 | { |
| 727 | 727 | // register new models |
| 728 | 728 | if ( |
| 729 | - ! empty(self::$_settings[ $addon_name ]['model_paths']) |
|
| 730 | - || ! empty(self::$_settings[ $addon_name ]['class_paths']) |
|
| 729 | + ! empty(self::$_settings[$addon_name]['model_paths']) |
|
| 730 | + || ! empty(self::$_settings[$addon_name]['class_paths']) |
|
| 731 | 731 | ) { |
| 732 | 732 | EE_Register_Model::register( |
| 733 | 733 | $addon_name, |
| 734 | 734 | array( |
| 735 | - 'model_paths' => self::$_settings[ $addon_name ]['model_paths'], |
|
| 736 | - 'class_paths' => self::$_settings[ $addon_name ]['class_paths'], |
|
| 735 | + 'model_paths' => self::$_settings[$addon_name]['model_paths'], |
|
| 736 | + 'class_paths' => self::$_settings[$addon_name]['class_paths'], |
|
| 737 | 737 | ) |
| 738 | 738 | ); |
| 739 | 739 | } |
| 740 | 740 | // register model extensions |
| 741 | 741 | if ( |
| 742 | - ! empty(self::$_settings[ $addon_name ]['model_extension_paths']) |
|
| 743 | - || ! empty(self::$_settings[ $addon_name ]['class_extension_paths']) |
|
| 742 | + ! empty(self::$_settings[$addon_name]['model_extension_paths']) |
|
| 743 | + || ! empty(self::$_settings[$addon_name]['class_extension_paths']) |
|
| 744 | 744 | ) { |
| 745 | 745 | EE_Register_Model_Extensions::register( |
| 746 | 746 | $addon_name, |
| 747 | 747 | array( |
| 748 | - 'model_extension_paths' => self::$_settings[ $addon_name ]['model_extension_paths'], |
|
| 749 | - 'class_extension_paths' => self::$_settings[ $addon_name ]['class_extension_paths'], |
|
| 748 | + 'model_extension_paths' => self::$_settings[$addon_name]['model_extension_paths'], |
|
| 749 | + 'class_extension_paths' => self::$_settings[$addon_name]['class_extension_paths'], |
|
| 750 | 750 | ) |
| 751 | 751 | ); |
| 752 | 752 | } |
@@ -761,10 +761,10 @@ discard block |
||
| 761 | 761 | private static function _register_data_migration_scripts($addon_name) |
| 762 | 762 | { |
| 763 | 763 | // setup DMS |
| 764 | - if (! empty(self::$_settings[ $addon_name ]['dms_paths'])) { |
|
| 764 | + if ( ! empty(self::$_settings[$addon_name]['dms_paths'])) { |
|
| 765 | 765 | EE_Register_Data_Migration_Scripts::register( |
| 766 | 766 | $addon_name, |
| 767 | - array('dms_paths' => self::$_settings[ $addon_name ]['dms_paths']) |
|
| 767 | + array('dms_paths' => self::$_settings[$addon_name]['dms_paths']) |
|
| 768 | 768 | ); |
| 769 | 769 | } |
| 770 | 770 | } |
@@ -778,12 +778,12 @@ discard block |
||
| 778 | 778 | private static function _register_config($addon_name) |
| 779 | 779 | { |
| 780 | 780 | // if config_class is present let's register config. |
| 781 | - if (! empty(self::$_settings[ $addon_name ]['config_class'])) { |
|
| 781 | + if ( ! empty(self::$_settings[$addon_name]['config_class'])) { |
|
| 782 | 782 | EE_Register_Config::register( |
| 783 | - self::$_settings[ $addon_name ]['config_class'], |
|
| 783 | + self::$_settings[$addon_name]['config_class'], |
|
| 784 | 784 | array( |
| 785 | - 'config_section' => self::$_settings[ $addon_name ]['config_section'], |
|
| 786 | - 'config_name' => self::$_settings[ $addon_name ]['config_name'], |
|
| 785 | + 'config_section' => self::$_settings[$addon_name]['config_section'], |
|
| 786 | + 'config_name' => self::$_settings[$addon_name]['config_name'], |
|
| 787 | 787 | ) |
| 788 | 788 | ); |
| 789 | 789 | } |
@@ -797,10 +797,10 @@ discard block |
||
| 797 | 797 | */ |
| 798 | 798 | private static function _register_admin_pages($addon_name) |
| 799 | 799 | { |
| 800 | - if (! empty(self::$_settings[ $addon_name ]['admin_path'])) { |
|
| 800 | + if ( ! empty(self::$_settings[$addon_name]['admin_path'])) { |
|
| 801 | 801 | EE_Register_Admin_Page::register( |
| 802 | 802 | $addon_name, |
| 803 | - array('page_path' => self::$_settings[ $addon_name ]['admin_path']) |
|
| 803 | + array('page_path' => self::$_settings[$addon_name]['admin_path']) |
|
| 804 | 804 | ); |
| 805 | 805 | } |
| 806 | 806 | } |
@@ -813,10 +813,10 @@ discard block |
||
| 813 | 813 | */ |
| 814 | 814 | private static function _register_modules($addon_name) |
| 815 | 815 | { |
| 816 | - if (! empty(self::$_settings[ $addon_name ]['module_paths'])) { |
|
| 816 | + if ( ! empty(self::$_settings[$addon_name]['module_paths'])) { |
|
| 817 | 817 | EE_Register_Module::register( |
| 818 | 818 | $addon_name, |
| 819 | - array('module_paths' => self::$_settings[ $addon_name ]['module_paths']) |
|
| 819 | + array('module_paths' => self::$_settings[$addon_name]['module_paths']) |
|
| 820 | 820 | ); |
| 821 | 821 | } |
| 822 | 822 | } |
@@ -829,17 +829,17 @@ discard block |
||
| 829 | 829 | */ |
| 830 | 830 | private static function _register_shortcodes($addon_name) |
| 831 | 831 | { |
| 832 | - if (! empty(self::$_settings[ $addon_name ]['shortcode_paths']) |
|
| 833 | - || ! empty(self::$_settings[ $addon_name ]['shortcode_fqcns']) |
|
| 832 | + if ( ! empty(self::$_settings[$addon_name]['shortcode_paths']) |
|
| 833 | + || ! empty(self::$_settings[$addon_name]['shortcode_fqcns']) |
|
| 834 | 834 | ) { |
| 835 | 835 | EE_Register_Shortcode::register( |
| 836 | 836 | $addon_name, |
| 837 | 837 | array( |
| 838 | - 'shortcode_paths' => isset(self::$_settings[ $addon_name ]['shortcode_paths']) |
|
| 839 | - ? self::$_settings[ $addon_name ]['shortcode_paths'] |
|
| 838 | + 'shortcode_paths' => isset(self::$_settings[$addon_name]['shortcode_paths']) |
|
| 839 | + ? self::$_settings[$addon_name]['shortcode_paths'] |
|
| 840 | 840 | : array(), |
| 841 | - 'shortcode_fqcns' => isset(self::$_settings[ $addon_name ]['shortcode_fqcns']) |
|
| 842 | - ? self::$_settings[ $addon_name ]['shortcode_fqcns'] |
|
| 841 | + 'shortcode_fqcns' => isset(self::$_settings[$addon_name]['shortcode_fqcns']) |
|
| 842 | + ? self::$_settings[$addon_name]['shortcode_fqcns'] |
|
| 843 | 843 | : array(), |
| 844 | 844 | ) |
| 845 | 845 | ); |
@@ -854,10 +854,10 @@ discard block |
||
| 854 | 854 | */ |
| 855 | 855 | private static function _register_widgets($addon_name) |
| 856 | 856 | { |
| 857 | - if (! empty(self::$_settings[ $addon_name ]['widget_paths'])) { |
|
| 857 | + if ( ! empty(self::$_settings[$addon_name]['widget_paths'])) { |
|
| 858 | 858 | EE_Register_Widget::register( |
| 859 | 859 | $addon_name, |
| 860 | - array('widget_paths' => self::$_settings[ $addon_name ]['widget_paths']) |
|
| 860 | + array('widget_paths' => self::$_settings[$addon_name]['widget_paths']) |
|
| 861 | 861 | ); |
| 862 | 862 | } |
| 863 | 863 | } |
@@ -870,12 +870,12 @@ discard block |
||
| 870 | 870 | */ |
| 871 | 871 | private static function _register_capabilities($addon_name) |
| 872 | 872 | { |
| 873 | - if (! empty(self::$_settings[ $addon_name ]['capabilities'])) { |
|
| 873 | + if ( ! empty(self::$_settings[$addon_name]['capabilities'])) { |
|
| 874 | 874 | EE_Register_Capabilities::register( |
| 875 | 875 | $addon_name, |
| 876 | 876 | array( |
| 877 | - 'capabilities' => self::$_settings[ $addon_name ]['capabilities'], |
|
| 878 | - 'capability_maps' => self::$_settings[ $addon_name ]['capability_maps'], |
|
| 877 | + 'capabilities' => self::$_settings[$addon_name]['capabilities'], |
|
| 878 | + 'capability_maps' => self::$_settings[$addon_name]['capability_maps'], |
|
| 879 | 879 | ) |
| 880 | 880 | ); |
| 881 | 881 | } |
@@ -889,7 +889,7 @@ discard block |
||
| 889 | 889 | */ |
| 890 | 890 | private static function _register_message_types($addon_name) |
| 891 | 891 | { |
| 892 | - if (! empty(self::$_settings[ $addon_name ]['message_types'])) { |
|
| 892 | + if ( ! empty(self::$_settings[$addon_name]['message_types'])) { |
|
| 893 | 893 | add_action( |
| 894 | 894 | 'EE_Brewing_Regular___messages_caf', |
| 895 | 895 | array('EE_Register_Addon', 'register_message_types') |
@@ -906,15 +906,15 @@ discard block |
||
| 906 | 906 | private static function _register_custom_post_types($addon_name) |
| 907 | 907 | { |
| 908 | 908 | if ( |
| 909 | - ! empty(self::$_settings[ $addon_name ]['custom_post_types']) |
|
| 910 | - || ! empty(self::$_settings[ $addon_name ]['custom_taxonomies']) |
|
| 909 | + ! empty(self::$_settings[$addon_name]['custom_post_types']) |
|
| 910 | + || ! empty(self::$_settings[$addon_name]['custom_taxonomies']) |
|
| 911 | 911 | ) { |
| 912 | 912 | EE_Register_CPT::register( |
| 913 | 913 | $addon_name, |
| 914 | 914 | array( |
| 915 | - 'cpts' => self::$_settings[ $addon_name ]['custom_post_types'], |
|
| 916 | - 'cts' => self::$_settings[ $addon_name ]['custom_taxonomies'], |
|
| 917 | - 'default_terms' => self::$_settings[ $addon_name ]['default_terms'], |
|
| 915 | + 'cpts' => self::$_settings[$addon_name]['custom_post_types'], |
|
| 916 | + 'cts' => self::$_settings[$addon_name]['custom_taxonomies'], |
|
| 917 | + 'default_terms' => self::$_settings[$addon_name]['default_terms'], |
|
| 918 | 918 | ) |
| 919 | 919 | ); |
| 920 | 920 | } |
@@ -932,10 +932,10 @@ discard block |
||
| 932 | 932 | */ |
| 933 | 933 | private static function _register_payment_methods($addon_name) |
| 934 | 934 | { |
| 935 | - if (! empty(self::$_settings[ $addon_name ]['payment_method_paths'])) { |
|
| 935 | + if ( ! empty(self::$_settings[$addon_name]['payment_method_paths'])) { |
|
| 936 | 936 | EE_Register_Payment_Method::register( |
| 937 | 937 | $addon_name, |
| 938 | - array('payment_method_paths' => self::$_settings[ $addon_name ]['payment_method_paths']) |
|
| 938 | + array('payment_method_paths' => self::$_settings[$addon_name]['payment_method_paths']) |
|
| 939 | 939 | ); |
| 940 | 940 | } |
| 941 | 941 | } |
@@ -956,7 +956,7 @@ discard block |
||
| 956 | 956 | { |
| 957 | 957 | $loader = EventEspresso\core\services\loaders\LoaderFactory::getLoader(); |
| 958 | 958 | $addon = $loader->getShared( |
| 959 | - self::$_settings[ $addon_name ]['class_name'], |
|
| 959 | + self::$_settings[$addon_name]['class_name'], |
|
| 960 | 960 | array('EE_Registry::create(addon)' => true) |
| 961 | 961 | ); |
| 962 | 962 | // setter inject dep map if required |
@@ -966,38 +966,38 @@ discard block |
||
| 966 | 966 | // setter inject domain if required |
| 967 | 967 | if ( |
| 968 | 968 | $addon instanceof RequiresDomainInterface |
| 969 | - && self::$_settings[ $addon_name ]['domain_fqcn'] !== '' |
|
| 969 | + && self::$_settings[$addon_name]['domain_fqcn'] !== '' |
|
| 970 | 970 | && $addon->domain() === null |
| 971 | 971 | ) { |
| 972 | 972 | $addon->setDomain( |
| 973 | 973 | $loader->getShared( |
| 974 | - self::$_settings[ $addon_name ]['domain_fqcn'], |
|
| 974 | + self::$_settings[$addon_name]['domain_fqcn'], |
|
| 975 | 975 | array( |
| 976 | - self::$_settings[ $addon_name ]['main_file_path'], |
|
| 977 | - self::$_settings[ $addon_name ]['version'], |
|
| 976 | + self::$_settings[$addon_name]['main_file_path'], |
|
| 977 | + self::$_settings[$addon_name]['version'], |
|
| 978 | 978 | ) |
| 979 | 979 | ) |
| 980 | 980 | ); |
| 981 | 981 | } |
| 982 | 982 | $addon->set_name($addon_name); |
| 983 | - $addon->set_plugin_slug(self::$_settings[ $addon_name ]['plugin_slug']); |
|
| 984 | - $addon->set_plugin_basename(self::$_settings[ $addon_name ]['plugin_basename']); |
|
| 985 | - $addon->set_main_plugin_file(self::$_settings[ $addon_name ]['main_file_path']); |
|
| 986 | - $addon->set_plugin_action_slug(self::$_settings[ $addon_name ]['plugin_action_slug']); |
|
| 987 | - $addon->set_plugins_page_row(self::$_settings[ $addon_name ]['plugins_page_row']); |
|
| 988 | - $addon->set_version(self::$_settings[ $addon_name ]['version']); |
|
| 989 | - $addon->set_min_core_version(self::_effective_version(self::$_settings[ $addon_name ]['min_core_version'])); |
|
| 990 | - $addon->set_config_section(self::$_settings[ $addon_name ]['config_section']); |
|
| 991 | - $addon->set_config_class(self::$_settings[ $addon_name ]['config_class']); |
|
| 992 | - $addon->set_config_name(self::$_settings[ $addon_name ]['config_name']); |
|
| 983 | + $addon->set_plugin_slug(self::$_settings[$addon_name]['plugin_slug']); |
|
| 984 | + $addon->set_plugin_basename(self::$_settings[$addon_name]['plugin_basename']); |
|
| 985 | + $addon->set_main_plugin_file(self::$_settings[$addon_name]['main_file_path']); |
|
| 986 | + $addon->set_plugin_action_slug(self::$_settings[$addon_name]['plugin_action_slug']); |
|
| 987 | + $addon->set_plugins_page_row(self::$_settings[$addon_name]['plugins_page_row']); |
|
| 988 | + $addon->set_version(self::$_settings[$addon_name]['version']); |
|
| 989 | + $addon->set_min_core_version(self::_effective_version(self::$_settings[$addon_name]['min_core_version'])); |
|
| 990 | + $addon->set_config_section(self::$_settings[$addon_name]['config_section']); |
|
| 991 | + $addon->set_config_class(self::$_settings[$addon_name]['config_class']); |
|
| 992 | + $addon->set_config_name(self::$_settings[$addon_name]['config_name']); |
|
| 993 | 993 | //unfortunately this can't be hooked in upon construction, because we don't have |
| 994 | 994 | //the plugin mainfile's path upon construction. |
| 995 | 995 | register_deactivation_hook($addon->get_main_plugin_file(), array($addon, 'deactivation')); |
| 996 | 996 | // call any additional admin_callback functions during load_admin_controller hook |
| 997 | - if (! empty(self::$_settings[ $addon_name ]['admin_callback'])) { |
|
| 997 | + if ( ! empty(self::$_settings[$addon_name]['admin_callback'])) { |
|
| 998 | 998 | add_action( |
| 999 | 999 | 'AHEE__EE_System__load_controllers__load_admin_controllers', |
| 1000 | - array($addon, self::$_settings[ $addon_name ]['admin_callback']) |
|
| 1000 | + array($addon, self::$_settings[$addon_name]['admin_callback']) |
|
| 1001 | 1001 | ); |
| 1002 | 1002 | } |
| 1003 | 1003 | return $addon; |
@@ -1015,10 +1015,10 @@ discard block |
||
| 1015 | 1015 | public static function load_pue_update() |
| 1016 | 1016 | { |
| 1017 | 1017 | // load PUE client |
| 1018 | - require_once EE_THIRD_PARTY . 'pue' . DS . 'pue-client.php'; |
|
| 1018 | + require_once EE_THIRD_PARTY.'pue'.DS.'pue-client.php'; |
|
| 1019 | 1019 | // cycle thru settings |
| 1020 | 1020 | foreach (self::$_settings as $settings) { |
| 1021 | - if (! empty($settings['pue_options'])) { |
|
| 1021 | + if ( ! empty($settings['pue_options'])) { |
|
| 1022 | 1022 | // initiate the class and start the plugin update engine! |
| 1023 | 1023 | new PluginUpdateEngineChecker( |
| 1024 | 1024 | // host file URL |
@@ -1026,7 +1026,7 @@ discard block |
||
| 1026 | 1026 | // plugin slug(s) |
| 1027 | 1027 | array( |
| 1028 | 1028 | 'premium' => array('p' => $settings['pue_options']['pue_plugin_slug']), |
| 1029 | - 'prerelease' => array('beta' => $settings['pue_options']['pue_plugin_slug'] . '-pr'), |
|
| 1029 | + 'prerelease' => array('beta' => $settings['pue_options']['pue_plugin_slug'].'-pr'), |
|
| 1030 | 1030 | ), |
| 1031 | 1031 | // options |
| 1032 | 1032 | array( |
@@ -1055,7 +1055,7 @@ discard block |
||
| 1055 | 1055 | public static function register_message_types() |
| 1056 | 1056 | { |
| 1057 | 1057 | foreach (self::$_settings as $addon_name => $settings) { |
| 1058 | - if (! empty($settings['message_types'])) { |
|
| 1058 | + if ( ! empty($settings['message_types'])) { |
|
| 1059 | 1059 | foreach ((array) $settings['message_types'] as $message_type => $message_type_settings) { |
| 1060 | 1060 | EE_Register_Message_Type::register($message_type, $message_type_settings); |
| 1061 | 1061 | } |
@@ -1077,51 +1077,51 @@ discard block |
||
| 1077 | 1077 | */ |
| 1078 | 1078 | public static function deregister($addon_name = null) |
| 1079 | 1079 | { |
| 1080 | - if (isset(self::$_settings[ $addon_name ]['class_name'])) { |
|
| 1080 | + if (isset(self::$_settings[$addon_name]['class_name'])) { |
|
| 1081 | 1081 | try { |
| 1082 | 1082 | do_action('AHEE__EE_Register_Addon__deregister__before', $addon_name); |
| 1083 | - $class_name = self::$_settings[ $addon_name ]['class_name']; |
|
| 1084 | - if (! empty(self::$_settings[ $addon_name ]['dms_paths'])) { |
|
| 1083 | + $class_name = self::$_settings[$addon_name]['class_name']; |
|
| 1084 | + if ( ! empty(self::$_settings[$addon_name]['dms_paths'])) { |
|
| 1085 | 1085 | // setup DMS |
| 1086 | 1086 | EE_Register_Data_Migration_Scripts::deregister($addon_name); |
| 1087 | 1087 | } |
| 1088 | - if (! empty(self::$_settings[ $addon_name ]['admin_path'])) { |
|
| 1088 | + if ( ! empty(self::$_settings[$addon_name]['admin_path'])) { |
|
| 1089 | 1089 | // register admin page |
| 1090 | 1090 | EE_Register_Admin_Page::deregister($addon_name); |
| 1091 | 1091 | } |
| 1092 | - if (! empty(self::$_settings[ $addon_name ]['module_paths'])) { |
|
| 1092 | + if ( ! empty(self::$_settings[$addon_name]['module_paths'])) { |
|
| 1093 | 1093 | // add to list of modules to be registered |
| 1094 | 1094 | EE_Register_Module::deregister($addon_name); |
| 1095 | 1095 | } |
| 1096 | - if (! empty(self::$_settings[ $addon_name ]['shortcode_paths']) |
|
| 1097 | - || ! empty(self::$_settings[ $addon_name ]['shortcode_fqcns']) |
|
| 1096 | + if ( ! empty(self::$_settings[$addon_name]['shortcode_paths']) |
|
| 1097 | + || ! empty(self::$_settings[$addon_name]['shortcode_fqcns']) |
|
| 1098 | 1098 | ) { |
| 1099 | 1099 | // add to list of shortcodes to be registered |
| 1100 | 1100 | EE_Register_Shortcode::deregister($addon_name); |
| 1101 | 1101 | } |
| 1102 | - if (! empty(self::$_settings[ $addon_name ]['config_class'])) { |
|
| 1102 | + if ( ! empty(self::$_settings[$addon_name]['config_class'])) { |
|
| 1103 | 1103 | // if config_class present let's register config. |
| 1104 | - EE_Register_Config::deregister(self::$_settings[ $addon_name ]['config_class']); |
|
| 1104 | + EE_Register_Config::deregister(self::$_settings[$addon_name]['config_class']); |
|
| 1105 | 1105 | } |
| 1106 | - if (! empty(self::$_settings[ $addon_name ]['widget_paths'])) { |
|
| 1106 | + if ( ! empty(self::$_settings[$addon_name]['widget_paths'])) { |
|
| 1107 | 1107 | // add to list of widgets to be registered |
| 1108 | 1108 | EE_Register_Widget::deregister($addon_name); |
| 1109 | 1109 | } |
| 1110 | - if (! empty(self::$_settings[ $addon_name ]['model_paths']) |
|
| 1111 | - || ! empty(self::$_settings[ $addon_name ]['class_paths']) |
|
| 1110 | + if ( ! empty(self::$_settings[$addon_name]['model_paths']) |
|
| 1111 | + || ! empty(self::$_settings[$addon_name]['class_paths']) |
|
| 1112 | 1112 | ) { |
| 1113 | 1113 | // add to list of shortcodes to be registered |
| 1114 | 1114 | EE_Register_Model::deregister($addon_name); |
| 1115 | 1115 | } |
| 1116 | - if (! empty(self::$_settings[ $addon_name ]['model_extension_paths']) |
|
| 1117 | - || ! empty(self::$_settings[ $addon_name ]['class_extension_paths']) |
|
| 1116 | + if ( ! empty(self::$_settings[$addon_name]['model_extension_paths']) |
|
| 1117 | + || ! empty(self::$_settings[$addon_name]['class_extension_paths']) |
|
| 1118 | 1118 | ) { |
| 1119 | 1119 | // add to list of shortcodes to be registered |
| 1120 | 1120 | EE_Register_Model_Extensions::deregister($addon_name); |
| 1121 | 1121 | } |
| 1122 | - if (! empty(self::$_settings[ $addon_name ]['message_types'])) { |
|
| 1122 | + if ( ! empty(self::$_settings[$addon_name]['message_types'])) { |
|
| 1123 | 1123 | foreach ( |
| 1124 | - (array) self::$_settings[ $addon_name ]['message_types'] as $message_type => |
|
| 1124 | + (array) self::$_settings[$addon_name]['message_types'] as $message_type => |
|
| 1125 | 1125 | $message_type_settings |
| 1126 | 1126 | ) { |
| 1127 | 1127 | EE_Register_Message_Type::deregister($message_type); |
@@ -1129,22 +1129,22 @@ discard block |
||
| 1129 | 1129 | } |
| 1130 | 1130 | //deregister capabilities for addon |
| 1131 | 1131 | if ( |
| 1132 | - ! empty(self::$_settings[ $addon_name ]['capabilities']) |
|
| 1133 | - || ! empty(self::$_settings[ $addon_name ]['capability_maps']) |
|
| 1132 | + ! empty(self::$_settings[$addon_name]['capabilities']) |
|
| 1133 | + || ! empty(self::$_settings[$addon_name]['capability_maps']) |
|
| 1134 | 1134 | ) { |
| 1135 | 1135 | EE_Register_Capabilities::deregister($addon_name); |
| 1136 | 1136 | } |
| 1137 | 1137 | //deregister custom_post_types for addon |
| 1138 | - if (! empty(self::$_settings[ $addon_name ]['custom_post_types'])) { |
|
| 1138 | + if ( ! empty(self::$_settings[$addon_name]['custom_post_types'])) { |
|
| 1139 | 1139 | EE_Register_CPT::deregister($addon_name); |
| 1140 | 1140 | } |
| 1141 | - if (! empty(self::$_settings[ $addon_name ]['payment_method_paths'])) { |
|
| 1141 | + if ( ! empty(self::$_settings[$addon_name]['payment_method_paths'])) { |
|
| 1142 | 1142 | EE_Register_Payment_Method::deregister($addon_name); |
| 1143 | 1143 | } |
| 1144 | 1144 | $addon = EE_Registry::instance()->getAddon($class_name); |
| 1145 | 1145 | if ($addon instanceof EE_Addon) { |
| 1146 | 1146 | remove_action( |
| 1147 | - 'deactivate_' . $addon->get_main_plugin_file_basename(), |
|
| 1147 | + 'deactivate_'.$addon->get_main_plugin_file_basename(), |
|
| 1148 | 1148 | array($addon, 'deactivation') |
| 1149 | 1149 | ); |
| 1150 | 1150 | remove_action( |
@@ -1167,7 +1167,7 @@ discard block |
||
| 1167 | 1167 | } catch (Exception $e) { |
| 1168 | 1168 | new ExceptionLogger($e); |
| 1169 | 1169 | } |
| 1170 | - unset(self::$_settings[ $addon_name ]); |
|
| 1170 | + unset(self::$_settings[$addon_name]); |
|
| 1171 | 1171 | do_action('AHEE__EE_Register_Addon__deregister__after', $addon_name); |
| 1172 | 1172 | } |
| 1173 | 1173 | } |
@@ -18,99 +18,99 @@ |
||
| 18 | 18 | class EE_Register_Data_Migration_Scripts implements EEI_Plugin_API |
| 19 | 19 | { |
| 20 | 20 | |
| 21 | - /** |
|
| 22 | - * Holds values for registered DMSs |
|
| 23 | - * |
|
| 24 | - * @var array[][] |
|
| 25 | - */ |
|
| 26 | - protected static $_settings = array(); |
|
| 21 | + /** |
|
| 22 | + * Holds values for registered DMSs |
|
| 23 | + * |
|
| 24 | + * @var array[][] |
|
| 25 | + */ |
|
| 26 | + protected static $_settings = array(); |
|
| 27 | 27 | |
| 28 | 28 | |
| 29 | - /** |
|
| 30 | - * Method for registering new Data Migration Scripts |
|
| 31 | - * |
|
| 32 | - * @since 4.3.0 |
|
| 33 | - * @param string $addon_name EE_Addon class name that this set of data migration scripts belongs to |
|
| 34 | - * If EE_Addon class is namespaced, then this needs to be the Fully Qualified Class Name |
|
| 35 | - * @param array $setup_args { |
|
| 36 | - * @type string $dms_paths an array of full server paths to folders that contain data migration scripts |
|
| 37 | - * } |
|
| 38 | - * @throws EE_Error |
|
| 39 | - * @return void |
|
| 40 | - */ |
|
| 41 | - public static function register($addon_name = '', $setup_args = array()) |
|
| 42 | - { |
|
| 43 | - //required fields MUST be present, so let's make sure they are. |
|
| 44 | - if (empty($addon_name) || ! is_array($setup_args) || empty($setup_args['dms_paths'])) { |
|
| 45 | - throw new EE_Error( |
|
| 46 | - esc_html__( |
|
| 47 | - 'In order to register Data Migration Scripts with EE_Register_Data_Migration_Scripts::register(), you must include the EE_Addon class name (used as a unique identifier for this set of data migration scripts), and an array containing the following keys: "dms_paths" (an array of full server paths to folders that contain data migration scripts)', |
|
| 48 | - 'event_espresso' |
|
| 49 | - ) |
|
| 50 | - ); |
|
| 51 | - } |
|
| 52 | - //make sure we don't register twice |
|
| 53 | - if (isset(self::$_settings[ $addon_name ])) { |
|
| 54 | - return; |
|
| 55 | - } |
|
| 56 | - //make sure this was called in the right place! |
|
| 57 | - if (! did_action('AHEE__EE_System__load_espresso_addons') |
|
| 58 | - || did_action('AHEE__EE_System___detect_if_activation_or_upgrade__begin') |
|
| 59 | - ) { |
|
| 60 | - EE_Error::doing_it_wrong( |
|
| 61 | - __METHOD__, |
|
| 62 | - esc_html__( |
|
| 63 | - 'An attempt to register Data Migration Scripts has failed because it was not registered at the correct time. Please use the "AHEE__EE_System__load_espresso_addons" hook to register Data Migration Scripts.', |
|
| 64 | - 'event_espresso' |
|
| 65 | - ), |
|
| 66 | - '4.3.0' |
|
| 67 | - ); |
|
| 68 | - } |
|
| 69 | - //setup $_settings array from incoming values. |
|
| 70 | - self::$_settings[ $addon_name ] = array( |
|
| 71 | - 'dms_paths' => (array) $setup_args['dms_paths'] |
|
| 72 | - ); |
|
| 73 | - // setup DMS |
|
| 74 | - add_filter( |
|
| 75 | - 'FHEE__EE_Data_Migration_Manager__get_data_migration_script_folders', |
|
| 76 | - array('EE_Register_Data_Migration_Scripts', 'add_data_migration_script_folders') |
|
| 77 | - ); |
|
| 78 | - } |
|
| 29 | + /** |
|
| 30 | + * Method for registering new Data Migration Scripts |
|
| 31 | + * |
|
| 32 | + * @since 4.3.0 |
|
| 33 | + * @param string $addon_name EE_Addon class name that this set of data migration scripts belongs to |
|
| 34 | + * If EE_Addon class is namespaced, then this needs to be the Fully Qualified Class Name |
|
| 35 | + * @param array $setup_args { |
|
| 36 | + * @type string $dms_paths an array of full server paths to folders that contain data migration scripts |
|
| 37 | + * } |
|
| 38 | + * @throws EE_Error |
|
| 39 | + * @return void |
|
| 40 | + */ |
|
| 41 | + public static function register($addon_name = '', $setup_args = array()) |
|
| 42 | + { |
|
| 43 | + //required fields MUST be present, so let's make sure they are. |
|
| 44 | + if (empty($addon_name) || ! is_array($setup_args) || empty($setup_args['dms_paths'])) { |
|
| 45 | + throw new EE_Error( |
|
| 46 | + esc_html__( |
|
| 47 | + 'In order to register Data Migration Scripts with EE_Register_Data_Migration_Scripts::register(), you must include the EE_Addon class name (used as a unique identifier for this set of data migration scripts), and an array containing the following keys: "dms_paths" (an array of full server paths to folders that contain data migration scripts)', |
|
| 48 | + 'event_espresso' |
|
| 49 | + ) |
|
| 50 | + ); |
|
| 51 | + } |
|
| 52 | + //make sure we don't register twice |
|
| 53 | + if (isset(self::$_settings[ $addon_name ])) { |
|
| 54 | + return; |
|
| 55 | + } |
|
| 56 | + //make sure this was called in the right place! |
|
| 57 | + if (! did_action('AHEE__EE_System__load_espresso_addons') |
|
| 58 | + || did_action('AHEE__EE_System___detect_if_activation_or_upgrade__begin') |
|
| 59 | + ) { |
|
| 60 | + EE_Error::doing_it_wrong( |
|
| 61 | + __METHOD__, |
|
| 62 | + esc_html__( |
|
| 63 | + 'An attempt to register Data Migration Scripts has failed because it was not registered at the correct time. Please use the "AHEE__EE_System__load_espresso_addons" hook to register Data Migration Scripts.', |
|
| 64 | + 'event_espresso' |
|
| 65 | + ), |
|
| 66 | + '4.3.0' |
|
| 67 | + ); |
|
| 68 | + } |
|
| 69 | + //setup $_settings array from incoming values. |
|
| 70 | + self::$_settings[ $addon_name ] = array( |
|
| 71 | + 'dms_paths' => (array) $setup_args['dms_paths'] |
|
| 72 | + ); |
|
| 73 | + // setup DMS |
|
| 74 | + add_filter( |
|
| 75 | + 'FHEE__EE_Data_Migration_Manager__get_data_migration_script_folders', |
|
| 76 | + array('EE_Register_Data_Migration_Scripts', 'add_data_migration_script_folders') |
|
| 77 | + ); |
|
| 78 | + } |
|
| 79 | 79 | |
| 80 | 80 | |
| 81 | - /** |
|
| 82 | - * @param array $dms_paths |
|
| 83 | - * @return array |
|
| 84 | - */ |
|
| 85 | - public static function add_data_migration_script_folders($dms_paths = array()) |
|
| 86 | - { |
|
| 87 | - foreach (self::$_settings as $addon_name => $settings) { |
|
| 88 | - $wildcards = 0; |
|
| 89 | - foreach ($settings['dms_paths'] as $dms_path) { |
|
| 90 | - // since we are using the addon name for the array key |
|
| 91 | - // we need to ensure that the key is unique, |
|
| 92 | - // so if for some reason an addon has multiple dms paths, |
|
| 93 | - // we append one or more * to the classname |
|
| 94 | - // which will get stripped out later on |
|
| 95 | - $dms_paths[ $addon_name . str_repeat('*', $wildcards) ] = $dms_path; |
|
| 96 | - $wildcards++; |
|
| 97 | - } |
|
| 98 | - } |
|
| 99 | - return $dms_paths; |
|
| 100 | - } |
|
| 81 | + /** |
|
| 82 | + * @param array $dms_paths |
|
| 83 | + * @return array |
|
| 84 | + */ |
|
| 85 | + public static function add_data_migration_script_folders($dms_paths = array()) |
|
| 86 | + { |
|
| 87 | + foreach (self::$_settings as $addon_name => $settings) { |
|
| 88 | + $wildcards = 0; |
|
| 89 | + foreach ($settings['dms_paths'] as $dms_path) { |
|
| 90 | + // since we are using the addon name for the array key |
|
| 91 | + // we need to ensure that the key is unique, |
|
| 92 | + // so if for some reason an addon has multiple dms paths, |
|
| 93 | + // we append one or more * to the classname |
|
| 94 | + // which will get stripped out later on |
|
| 95 | + $dms_paths[ $addon_name . str_repeat('*', $wildcards) ] = $dms_path; |
|
| 96 | + $wildcards++; |
|
| 97 | + } |
|
| 98 | + } |
|
| 99 | + return $dms_paths; |
|
| 100 | + } |
|
| 101 | 101 | |
| 102 | 102 | |
| 103 | - /** |
|
| 104 | - * This deregisters a set of Data Migration Scripts that were previously registered with a specific dms_id |
|
| 105 | - * |
|
| 106 | - * @since 4.3.0 |
|
| 107 | - * @param string $addon_name EE_Addon class name that this set of data migration scripts belongs to |
|
| 108 | - * @return void |
|
| 109 | - */ |
|
| 110 | - public static function deregister($addon_name = '') |
|
| 111 | - { |
|
| 112 | - unset(self::$_settings[ $addon_name ]); |
|
| 113 | - } |
|
| 103 | + /** |
|
| 104 | + * This deregisters a set of Data Migration Scripts that were previously registered with a specific dms_id |
|
| 105 | + * |
|
| 106 | + * @since 4.3.0 |
|
| 107 | + * @param string $addon_name EE_Addon class name that this set of data migration scripts belongs to |
|
| 108 | + * @return void |
|
| 109 | + */ |
|
| 110 | + public static function deregister($addon_name = '') |
|
| 111 | + { |
|
| 112 | + unset(self::$_settings[ $addon_name ]); |
|
| 113 | + } |
|
| 114 | 114 | } |
| 115 | 115 | // End of file EE_Register_Data_Migration_Scripts.lib.php |
| 116 | 116 | // Location: /core/libraries/plugin_api/EE_Register_Data_Migration_Scripts.lib.php |
@@ -50,11 +50,11 @@ discard block |
||
| 50 | 50 | ); |
| 51 | 51 | } |
| 52 | 52 | //make sure we don't register twice |
| 53 | - if (isset(self::$_settings[ $addon_name ])) { |
|
| 53 | + if (isset(self::$_settings[$addon_name])) { |
|
| 54 | 54 | return; |
| 55 | 55 | } |
| 56 | 56 | //make sure this was called in the right place! |
| 57 | - if (! did_action('AHEE__EE_System__load_espresso_addons') |
|
| 57 | + if ( ! did_action('AHEE__EE_System__load_espresso_addons') |
|
| 58 | 58 | || did_action('AHEE__EE_System___detect_if_activation_or_upgrade__begin') |
| 59 | 59 | ) { |
| 60 | 60 | EE_Error::doing_it_wrong( |
@@ -67,7 +67,7 @@ discard block |
||
| 67 | 67 | ); |
| 68 | 68 | } |
| 69 | 69 | //setup $_settings array from incoming values. |
| 70 | - self::$_settings[ $addon_name ] = array( |
|
| 70 | + self::$_settings[$addon_name] = array( |
|
| 71 | 71 | 'dms_paths' => (array) $setup_args['dms_paths'] |
| 72 | 72 | ); |
| 73 | 73 | // setup DMS |
@@ -92,7 +92,7 @@ discard block |
||
| 92 | 92 | // so if for some reason an addon has multiple dms paths, |
| 93 | 93 | // we append one or more * to the classname |
| 94 | 94 | // which will get stripped out later on |
| 95 | - $dms_paths[ $addon_name . str_repeat('*', $wildcards) ] = $dms_path; |
|
| 95 | + $dms_paths[$addon_name.str_repeat('*', $wildcards)] = $dms_path; |
|
| 96 | 96 | $wildcards++; |
| 97 | 97 | } |
| 98 | 98 | } |
@@ -109,7 +109,7 @@ discard block |
||
| 109 | 109 | */ |
| 110 | 110 | public static function deregister($addon_name = '') |
| 111 | 111 | { |
| 112 | - unset(self::$_settings[ $addon_name ]); |
|
| 112 | + unset(self::$_settings[$addon_name]); |
|
| 113 | 113 | } |
| 114 | 114 | } |
| 115 | 115 | // End of file EE_Register_Data_Migration_Scripts.lib.php |
@@ -23,1593 +23,1593 @@ |
||
| 23 | 23 | class EE_Registry implements ResettableInterface |
| 24 | 24 | { |
| 25 | 25 | |
| 26 | - /** |
|
| 27 | - * @var EE_Registry $_instance |
|
| 28 | - */ |
|
| 29 | - private static $_instance; |
|
| 30 | - |
|
| 31 | - /** |
|
| 32 | - * @var EE_Dependency_Map $_dependency_map |
|
| 33 | - */ |
|
| 34 | - protected $_dependency_map; |
|
| 35 | - |
|
| 36 | - /** |
|
| 37 | - * @var array $_class_abbreviations |
|
| 38 | - */ |
|
| 39 | - protected $_class_abbreviations = array(); |
|
| 40 | - |
|
| 41 | - /** |
|
| 42 | - * @var CommandBusInterface $BUS |
|
| 43 | - */ |
|
| 44 | - public $BUS; |
|
| 45 | - |
|
| 46 | - /** |
|
| 47 | - * @var EE_Cart $CART |
|
| 48 | - */ |
|
| 49 | - public $CART; |
|
| 50 | - |
|
| 51 | - /** |
|
| 52 | - * @var EE_Config $CFG |
|
| 53 | - */ |
|
| 54 | - public $CFG; |
|
| 55 | - |
|
| 56 | - /** |
|
| 57 | - * @var EE_Network_Config $NET_CFG |
|
| 58 | - */ |
|
| 59 | - public $NET_CFG; |
|
| 60 | - |
|
| 61 | - /** |
|
| 62 | - * StdClass object for storing library classes in |
|
| 63 | - * |
|
| 64 | - * @var StdClass $LIB |
|
| 65 | - */ |
|
| 66 | - public $LIB; |
|
| 67 | - |
|
| 68 | - /** |
|
| 69 | - * @var EE_Request_Handler $REQ |
|
| 70 | - */ |
|
| 71 | - public $REQ; |
|
| 72 | - |
|
| 73 | - /** |
|
| 74 | - * @var EE_Session $SSN |
|
| 75 | - */ |
|
| 76 | - public $SSN; |
|
| 77 | - |
|
| 78 | - /** |
|
| 79 | - * @since 4.5.0 |
|
| 80 | - * @var EE_Capabilities $CAP |
|
| 81 | - */ |
|
| 82 | - public $CAP; |
|
| 83 | - |
|
| 84 | - /** |
|
| 85 | - * @since 4.9.0 |
|
| 86 | - * @var EE_Message_Resource_Manager $MRM |
|
| 87 | - */ |
|
| 88 | - public $MRM; |
|
| 89 | - |
|
| 90 | - |
|
| 91 | - /** |
|
| 92 | - * @var Registry $AssetsRegistry |
|
| 93 | - */ |
|
| 94 | - public $AssetsRegistry; |
|
| 95 | - |
|
| 96 | - /** |
|
| 97 | - * StdClass object for holding addons which have registered themselves to work with EE core |
|
| 98 | - * |
|
| 99 | - * @var EE_Addon[] $addons |
|
| 100 | - */ |
|
| 101 | - public $addons; |
|
| 102 | - |
|
| 103 | - /** |
|
| 104 | - * keys are 'short names' (eg Event), values are class names (eg 'EEM_Event') |
|
| 105 | - * |
|
| 106 | - * @var EEM_Base[] $models |
|
| 107 | - */ |
|
| 108 | - public $models = array(); |
|
| 109 | - |
|
| 110 | - /** |
|
| 111 | - * @var EED_Module[] $modules |
|
| 112 | - */ |
|
| 113 | - public $modules; |
|
| 114 | - |
|
| 115 | - /** |
|
| 116 | - * @var EES_Shortcode[] $shortcodes |
|
| 117 | - */ |
|
| 118 | - public $shortcodes; |
|
| 119 | - |
|
| 120 | - /** |
|
| 121 | - * @var WP_Widget[] $widgets |
|
| 122 | - */ |
|
| 123 | - public $widgets; |
|
| 124 | - |
|
| 125 | - /** |
|
| 126 | - * this is an array of all implemented model names (i.e. not the parent abstract models, or models |
|
| 127 | - * which don't actually fetch items from the DB in the normal way (ie, are not children of EEM_Base)). |
|
| 128 | - * Keys are model "short names" (eg "Event") as used in model relations, and values are |
|
| 129 | - * classnames (eg "EEM_Event") |
|
| 130 | - * |
|
| 131 | - * @var array $non_abstract_db_models |
|
| 132 | - */ |
|
| 133 | - public $non_abstract_db_models = array(); |
|
| 134 | - |
|
| 135 | - |
|
| 136 | - /** |
|
| 137 | - * internationalization for JS strings |
|
| 138 | - * usage: EE_Registry::i18n_js_strings['string_key'] = esc_html__( 'string to translate.', 'event_espresso' ); |
|
| 139 | - * in js file: var translatedString = eei18n.string_key; |
|
| 140 | - * |
|
| 141 | - * @var array $i18n_js_strings |
|
| 142 | - */ |
|
| 143 | - public static $i18n_js_strings = array(); |
|
| 144 | - |
|
| 145 | - |
|
| 146 | - /** |
|
| 147 | - * $main_file - path to espresso.php |
|
| 148 | - * |
|
| 149 | - * @var array $main_file |
|
| 150 | - */ |
|
| 151 | - public $main_file; |
|
| 152 | - |
|
| 153 | - /** |
|
| 154 | - * array of ReflectionClass objects where the key is the class name |
|
| 155 | - * |
|
| 156 | - * @var ReflectionClass[] $_reflectors |
|
| 157 | - */ |
|
| 158 | - public $_reflectors; |
|
| 159 | - |
|
| 160 | - /** |
|
| 161 | - * boolean flag to indicate whether or not to load/save dependencies from/to the cache |
|
| 162 | - * |
|
| 163 | - * @var boolean $_cache_on |
|
| 164 | - */ |
|
| 165 | - protected $_cache_on = true; |
|
| 166 | - |
|
| 167 | - |
|
| 168 | - |
|
| 169 | - /** |
|
| 170 | - * @singleton method used to instantiate class object |
|
| 171 | - * @param EE_Dependency_Map $dependency_map |
|
| 172 | - * @return EE_Registry instance |
|
| 173 | - * @throws InvalidArgumentException |
|
| 174 | - * @throws InvalidInterfaceException |
|
| 175 | - * @throws InvalidDataTypeException |
|
| 176 | - */ |
|
| 177 | - public static function instance(EE_Dependency_Map $dependency_map = null) |
|
| 178 | - { |
|
| 179 | - // check if class object is instantiated |
|
| 180 | - if (! self::$_instance instanceof EE_Registry) { |
|
| 181 | - self::$_instance = new self($dependency_map); |
|
| 182 | - } |
|
| 183 | - return self::$_instance; |
|
| 184 | - } |
|
| 185 | - |
|
| 186 | - |
|
| 187 | - |
|
| 188 | - /** |
|
| 189 | - * protected constructor to prevent direct creation |
|
| 190 | - * |
|
| 191 | - * @Constructor |
|
| 192 | - * @param EE_Dependency_Map $dependency_map |
|
| 193 | - * @throws InvalidDataTypeException |
|
| 194 | - * @throws InvalidInterfaceException |
|
| 195 | - * @throws InvalidArgumentException |
|
| 196 | - */ |
|
| 197 | - protected function __construct(EE_Dependency_Map $dependency_map) |
|
| 198 | - { |
|
| 199 | - $this->_dependency_map = $dependency_map; |
|
| 200 | - // $registry_container = new RegistryContainer(); |
|
| 201 | - $this->LIB = new RegistryContainer(); |
|
| 202 | - $this->addons = new RegistryContainer(); |
|
| 203 | - $this->modules = new RegistryContainer(); |
|
| 204 | - $this->shortcodes = new RegistryContainer(); |
|
| 205 | - $this->widgets = new RegistryContainer(); |
|
| 206 | - add_action('EE_Load_Espresso_Core__handle_request__initialize_core_loading', array($this, 'initialize')); |
|
| 207 | - } |
|
| 208 | - |
|
| 209 | - |
|
| 210 | - |
|
| 211 | - /** |
|
| 212 | - * initialize |
|
| 213 | - * |
|
| 214 | - * @throws EE_Error |
|
| 215 | - * @throws ReflectionException |
|
| 216 | - */ |
|
| 217 | - public function initialize() |
|
| 218 | - { |
|
| 219 | - $this->_class_abbreviations = apply_filters( |
|
| 220 | - 'FHEE__EE_Registry____construct___class_abbreviations', |
|
| 221 | - array( |
|
| 222 | - 'EE_Config' => 'CFG', |
|
| 223 | - 'EE_Session' => 'SSN', |
|
| 224 | - 'EE_Capabilities' => 'CAP', |
|
| 225 | - 'EE_Cart' => 'CART', |
|
| 226 | - 'EE_Network_Config' => 'NET_CFG', |
|
| 227 | - 'EE_Request_Handler' => 'REQ', |
|
| 228 | - 'EE_Message_Resource_Manager' => 'MRM', |
|
| 229 | - 'EventEspresso\core\services\commands\CommandBus' => 'BUS', |
|
| 230 | - 'EventEspresso\core\services\assets\Registry' => 'AssetsRegistry', |
|
| 231 | - ) |
|
| 232 | - ); |
|
| 233 | - $this->load_core('Base', array(), true); |
|
| 234 | - // add our request and response objects to the cache |
|
| 235 | - $request_loader = $this->_dependency_map->class_loader( |
|
| 236 | - 'EventEspresso\core\services\request\Request' |
|
| 237 | - ); |
|
| 238 | - $this->_set_cached_class( |
|
| 239 | - $request_loader(), |
|
| 240 | - 'EventEspresso\core\services\request\Request' |
|
| 241 | - ); |
|
| 242 | - $response_loader = $this->_dependency_map->class_loader( |
|
| 243 | - 'EventEspresso\core\services\request\Response' |
|
| 244 | - ); |
|
| 245 | - $this->_set_cached_class( |
|
| 246 | - $response_loader(), |
|
| 247 | - 'EventEspresso\core\services\request\Response' |
|
| 248 | - ); |
|
| 249 | - add_action('AHEE__EE_System__set_hooks_for_core', array($this, 'init')); |
|
| 250 | - } |
|
| 251 | - |
|
| 252 | - |
|
| 253 | - |
|
| 254 | - /** |
|
| 255 | - * @return void |
|
| 256 | - */ |
|
| 257 | - public function init() |
|
| 258 | - { |
|
| 259 | - // Get current page protocol |
|
| 260 | - $protocol = isset($_SERVER['HTTPS']) ? 'https://' : 'http://'; |
|
| 261 | - // Output admin-ajax.php URL with same protocol as current page |
|
| 262 | - self::$i18n_js_strings['ajax_url'] = admin_url('admin-ajax.php', $protocol); |
|
| 263 | - self::$i18n_js_strings['wp_debug'] = defined('WP_DEBUG') ? WP_DEBUG : false; |
|
| 264 | - } |
|
| 265 | - |
|
| 266 | - |
|
| 267 | - |
|
| 268 | - /** |
|
| 269 | - * localize_i18n_js_strings |
|
| 270 | - * |
|
| 271 | - * @return string |
|
| 272 | - */ |
|
| 273 | - public static function localize_i18n_js_strings() |
|
| 274 | - { |
|
| 275 | - $i18n_js_strings = (array)self::$i18n_js_strings; |
|
| 276 | - foreach ($i18n_js_strings as $key => $value) { |
|
| 277 | - if (is_scalar($value)) { |
|
| 278 | - $i18n_js_strings[$key] = html_entity_decode((string)$value, ENT_QUOTES, 'UTF-8'); |
|
| 279 | - } |
|
| 280 | - } |
|
| 281 | - return '/* <![CDATA[ */ var eei18n = ' . wp_json_encode($i18n_js_strings) . '; /* ]]> */'; |
|
| 282 | - } |
|
| 283 | - |
|
| 284 | - |
|
| 285 | - |
|
| 286 | - /** |
|
| 287 | - * @param mixed string | EED_Module $module |
|
| 288 | - * @throws EE_Error |
|
| 289 | - * @throws ReflectionException |
|
| 290 | - */ |
|
| 291 | - public function add_module($module) |
|
| 292 | - { |
|
| 293 | - if ($module instanceof EED_Module) { |
|
| 294 | - $module_class = get_class($module); |
|
| 295 | - $this->modules->{$module_class} = $module; |
|
| 296 | - } else { |
|
| 297 | - if ( ! class_exists('EE_Module_Request_Router', false)) { |
|
| 298 | - $this->load_core('Module_Request_Router'); |
|
| 299 | - } |
|
| 300 | - EE_Module_Request_Router::module_factory($module); |
|
| 301 | - } |
|
| 302 | - } |
|
| 303 | - |
|
| 304 | - |
|
| 305 | - |
|
| 306 | - /** |
|
| 307 | - * @param string $module_name |
|
| 308 | - * @return mixed EED_Module | NULL |
|
| 309 | - */ |
|
| 310 | - public function get_module($module_name = '') |
|
| 311 | - { |
|
| 312 | - return isset($this->modules->{$module_name}) |
|
| 313 | - ? $this->modules->{$module_name} |
|
| 314 | - : null; |
|
| 315 | - } |
|
| 316 | - |
|
| 317 | - |
|
| 318 | - |
|
| 319 | - /** |
|
| 320 | - * loads core classes - must be singletons |
|
| 321 | - * |
|
| 322 | - * @param string $class_name - simple class name ie: session |
|
| 323 | - * @param mixed $arguments |
|
| 324 | - * @param bool $load_only |
|
| 325 | - * @return mixed |
|
| 326 | - * @throws EE_Error |
|
| 327 | - * @throws ReflectionException |
|
| 328 | - */ |
|
| 329 | - public function load_core($class_name, $arguments = array(), $load_only = false) |
|
| 330 | - { |
|
| 331 | - $core_paths = apply_filters( |
|
| 332 | - 'FHEE__EE_Registry__load_core__core_paths', |
|
| 333 | - array( |
|
| 334 | - EE_CORE, |
|
| 335 | - EE_ADMIN, |
|
| 336 | - EE_CPTS, |
|
| 337 | - EE_CORE . 'data_migration_scripts' . DS, |
|
| 338 | - EE_CORE . 'capabilities' . DS, |
|
| 339 | - EE_CORE . 'request_stack' . DS, |
|
| 340 | - EE_CORE . 'middleware' . DS, |
|
| 341 | - ) |
|
| 342 | - ); |
|
| 343 | - // retrieve instantiated class |
|
| 344 | - return $this->_load( |
|
| 345 | - $core_paths, |
|
| 346 | - 'EE_', |
|
| 347 | - $class_name, |
|
| 348 | - 'core', |
|
| 349 | - $arguments, |
|
| 350 | - false, |
|
| 351 | - true, |
|
| 352 | - $load_only |
|
| 353 | - ); |
|
| 354 | - } |
|
| 355 | - |
|
| 356 | - |
|
| 357 | - |
|
| 358 | - /** |
|
| 359 | - * loads service classes |
|
| 360 | - * |
|
| 361 | - * @param string $class_name - simple class name ie: session |
|
| 362 | - * @param mixed $arguments |
|
| 363 | - * @param bool $load_only |
|
| 364 | - * @return mixed |
|
| 365 | - * @throws EE_Error |
|
| 366 | - * @throws ReflectionException |
|
| 367 | - */ |
|
| 368 | - public function load_service($class_name, $arguments = array(), $load_only = false) |
|
| 369 | - { |
|
| 370 | - $service_paths = apply_filters( |
|
| 371 | - 'FHEE__EE_Registry__load_service__service_paths', |
|
| 372 | - array( |
|
| 373 | - EE_CORE . 'services' . DS, |
|
| 374 | - ) |
|
| 375 | - ); |
|
| 376 | - // retrieve instantiated class |
|
| 377 | - return $this->_load( |
|
| 378 | - $service_paths, |
|
| 379 | - 'EE_', |
|
| 380 | - $class_name, |
|
| 381 | - 'class', |
|
| 382 | - $arguments, |
|
| 383 | - false, |
|
| 384 | - true, |
|
| 385 | - $load_only |
|
| 386 | - ); |
|
| 387 | - } |
|
| 388 | - |
|
| 389 | - |
|
| 390 | - |
|
| 391 | - /** |
|
| 392 | - * loads data_migration_scripts |
|
| 393 | - * |
|
| 394 | - * @param string $class_name - class name for the DMS ie: EE_DMS_Core_4_2_0 |
|
| 395 | - * @param mixed $arguments |
|
| 396 | - * @return EE_Data_Migration_Script_Base|mixed |
|
| 397 | - * @throws EE_Error |
|
| 398 | - * @throws ReflectionException |
|
| 399 | - */ |
|
| 400 | - public function load_dms($class_name, $arguments = array()) |
|
| 401 | - { |
|
| 402 | - // retrieve instantiated class |
|
| 403 | - return $this->_load( |
|
| 404 | - EE_Data_Migration_Manager::instance()->get_data_migration_script_folders(), |
|
| 405 | - 'EE_DMS_', |
|
| 406 | - $class_name, |
|
| 407 | - 'dms', |
|
| 408 | - $arguments, |
|
| 409 | - false, |
|
| 410 | - false |
|
| 411 | - ); |
|
| 412 | - } |
|
| 413 | - |
|
| 414 | - |
|
| 415 | - |
|
| 416 | - /** |
|
| 417 | - * loads object creating classes - must be singletons |
|
| 418 | - * |
|
| 419 | - * @param string $class_name - simple class name ie: attendee |
|
| 420 | - * @param mixed $arguments - an array of arguments to pass to the class |
|
| 421 | - * @param bool $from_db - some classes are instantiated from the db and thus call a different method to |
|
| 422 | - * instantiate |
|
| 423 | - * @param bool $cache if you don't want the class to be stored in the internal cache (non-persistent) then |
|
| 424 | - * set this to FALSE (ie. when instantiating model objects from client in a loop) |
|
| 425 | - * @param bool $load_only whether or not to just load the file and NOT instantiate, or load AND instantiate |
|
| 426 | - * (default) |
|
| 427 | - * @return EE_Base_Class | bool |
|
| 428 | - * @throws EE_Error |
|
| 429 | - * @throws ReflectionException |
|
| 430 | - */ |
|
| 431 | - public function load_class($class_name, $arguments = array(), $from_db = false, $cache = true, $load_only = false) |
|
| 432 | - { |
|
| 433 | - $paths = apply_filters( |
|
| 434 | - 'FHEE__EE_Registry__load_class__paths', array( |
|
| 435 | - EE_CORE, |
|
| 436 | - EE_CLASSES, |
|
| 437 | - EE_BUSINESS, |
|
| 438 | - ) |
|
| 439 | - ); |
|
| 440 | - // retrieve instantiated class |
|
| 441 | - return $this->_load( |
|
| 442 | - $paths, |
|
| 443 | - 'EE_', |
|
| 444 | - $class_name, |
|
| 445 | - 'class', |
|
| 446 | - $arguments, |
|
| 447 | - $from_db, |
|
| 448 | - $cache, |
|
| 449 | - $load_only |
|
| 450 | - ); |
|
| 451 | - } |
|
| 452 | - |
|
| 453 | - |
|
| 454 | - |
|
| 455 | - /** |
|
| 456 | - * loads helper classes - must be singletons |
|
| 457 | - * |
|
| 458 | - * @param string $class_name - simple class name ie: price |
|
| 459 | - * @param mixed $arguments |
|
| 460 | - * @param bool $load_only |
|
| 461 | - * @return EEH_Base | bool |
|
| 462 | - * @throws EE_Error |
|
| 463 | - * @throws ReflectionException |
|
| 464 | - */ |
|
| 465 | - public function load_helper($class_name, $arguments = array(), $load_only = true) |
|
| 466 | - { |
|
| 467 | - // todo: add doing_it_wrong() in a few versions after all addons have had calls to this method removed |
|
| 468 | - $helper_paths = apply_filters('FHEE__EE_Registry__load_helper__helper_paths', array(EE_HELPERS)); |
|
| 469 | - // retrieve instantiated class |
|
| 470 | - return $this->_load( |
|
| 471 | - $helper_paths, |
|
| 472 | - 'EEH_', |
|
| 473 | - $class_name, |
|
| 474 | - 'helper', |
|
| 475 | - $arguments, |
|
| 476 | - false, |
|
| 477 | - true, |
|
| 478 | - $load_only |
|
| 479 | - ); |
|
| 480 | - } |
|
| 481 | - |
|
| 482 | - |
|
| 483 | - |
|
| 484 | - /** |
|
| 485 | - * loads core classes - must be singletons |
|
| 486 | - * |
|
| 487 | - * @param string $class_name - simple class name ie: session |
|
| 488 | - * @param mixed $arguments |
|
| 489 | - * @param bool $load_only |
|
| 490 | - * @param bool $cache whether to cache the object or not. |
|
| 491 | - * @return mixed |
|
| 492 | - * @throws EE_Error |
|
| 493 | - * @throws ReflectionException |
|
| 494 | - */ |
|
| 495 | - public function load_lib($class_name, $arguments = array(), $load_only = false, $cache = true) |
|
| 496 | - { |
|
| 497 | - $paths = array( |
|
| 498 | - EE_LIBRARIES, |
|
| 499 | - EE_LIBRARIES . 'messages' . DS, |
|
| 500 | - EE_LIBRARIES . 'shortcodes' . DS, |
|
| 501 | - EE_LIBRARIES . 'qtips' . DS, |
|
| 502 | - EE_LIBRARIES . 'payment_methods' . DS, |
|
| 503 | - ); |
|
| 504 | - // retrieve instantiated class |
|
| 505 | - return $this->_load( |
|
| 506 | - $paths, |
|
| 507 | - 'EE_', |
|
| 508 | - $class_name, |
|
| 509 | - 'lib', |
|
| 510 | - $arguments, |
|
| 511 | - false, |
|
| 512 | - $cache, |
|
| 513 | - $load_only |
|
| 514 | - ); |
|
| 515 | - } |
|
| 516 | - |
|
| 517 | - |
|
| 518 | - |
|
| 519 | - /** |
|
| 520 | - * loads model classes - must be singletons |
|
| 521 | - * |
|
| 522 | - * @param string $class_name - simple class name ie: price |
|
| 523 | - * @param mixed $arguments |
|
| 524 | - * @param bool $load_only |
|
| 525 | - * @return EEM_Base | bool |
|
| 526 | - * @throws EE_Error |
|
| 527 | - * @throws ReflectionException |
|
| 528 | - */ |
|
| 529 | - public function load_model($class_name, $arguments = array(), $load_only = false) |
|
| 530 | - { |
|
| 531 | - $paths = apply_filters( |
|
| 532 | - 'FHEE__EE_Registry__load_model__paths', array( |
|
| 533 | - EE_MODELS, |
|
| 534 | - EE_CORE, |
|
| 535 | - ) |
|
| 536 | - ); |
|
| 537 | - // retrieve instantiated class |
|
| 538 | - return $this->_load( |
|
| 539 | - $paths, |
|
| 540 | - 'EEM_', |
|
| 541 | - $class_name, |
|
| 542 | - 'model', |
|
| 543 | - $arguments, |
|
| 544 | - false, |
|
| 545 | - true, |
|
| 546 | - $load_only |
|
| 547 | - ); |
|
| 548 | - } |
|
| 549 | - |
|
| 550 | - |
|
| 551 | - |
|
| 552 | - /** |
|
| 553 | - * loads model classes - must be singletons |
|
| 554 | - * |
|
| 555 | - * @param string $class_name - simple class name ie: price |
|
| 556 | - * @param mixed $arguments |
|
| 557 | - * @param bool $load_only |
|
| 558 | - * @return mixed | bool |
|
| 559 | - * @throws EE_Error |
|
| 560 | - * @throws ReflectionException |
|
| 561 | - */ |
|
| 562 | - public function load_model_class($class_name, $arguments = array(), $load_only = true) |
|
| 563 | - { |
|
| 564 | - $paths = array( |
|
| 565 | - EE_MODELS . 'fields' . DS, |
|
| 566 | - EE_MODELS . 'helpers' . DS, |
|
| 567 | - EE_MODELS . 'relations' . DS, |
|
| 568 | - EE_MODELS . 'strategies' . DS, |
|
| 569 | - ); |
|
| 570 | - // retrieve instantiated class |
|
| 571 | - return $this->_load( |
|
| 572 | - $paths, |
|
| 573 | - 'EE_', |
|
| 574 | - $class_name, |
|
| 575 | - '', |
|
| 576 | - $arguments, |
|
| 577 | - false, |
|
| 578 | - true, |
|
| 579 | - $load_only |
|
| 580 | - ); |
|
| 581 | - } |
|
| 582 | - |
|
| 583 | - |
|
| 584 | - |
|
| 585 | - /** |
|
| 586 | - * Determines if $model_name is the name of an actual EE model. |
|
| 587 | - * |
|
| 588 | - * @param string $model_name like Event, Attendee, Question_Group_Question, etc. |
|
| 589 | - * @return boolean |
|
| 590 | - */ |
|
| 591 | - public function is_model_name($model_name) |
|
| 592 | - { |
|
| 593 | - return isset($this->models[$model_name]); |
|
| 594 | - } |
|
| 595 | - |
|
| 596 | - |
|
| 597 | - |
|
| 598 | - /** |
|
| 599 | - * generic class loader |
|
| 600 | - * |
|
| 601 | - * @param string $path_to_file - directory path to file location, not including filename |
|
| 602 | - * @param string $file_name - file name ie: my_file.php, including extension |
|
| 603 | - * @param string $type - file type - core? class? helper? model? |
|
| 604 | - * @param mixed $arguments |
|
| 605 | - * @param bool $load_only |
|
| 606 | - * @return mixed |
|
| 607 | - * @throws EE_Error |
|
| 608 | - * @throws ReflectionException |
|
| 609 | - */ |
|
| 610 | - public function load_file($path_to_file, $file_name, $type = '', $arguments = array(), $load_only = true) |
|
| 611 | - { |
|
| 612 | - // retrieve instantiated class |
|
| 613 | - return $this->_load( |
|
| 614 | - $path_to_file, |
|
| 615 | - '', |
|
| 616 | - $file_name, |
|
| 617 | - $type, |
|
| 618 | - $arguments, |
|
| 619 | - false, |
|
| 620 | - true, |
|
| 621 | - $load_only |
|
| 622 | - ); |
|
| 623 | - } |
|
| 624 | - |
|
| 625 | - |
|
| 626 | - |
|
| 627 | - /** |
|
| 628 | - * @param string $path_to_file - directory path to file location, not including filename |
|
| 629 | - * @param string $class_name - full class name ie: My_Class |
|
| 630 | - * @param string $type - file type - core? class? helper? model? |
|
| 631 | - * @param mixed $arguments |
|
| 632 | - * @param bool $load_only |
|
| 633 | - * @return bool|EE_Addon|object |
|
| 634 | - * @throws EE_Error |
|
| 635 | - * @throws ReflectionException |
|
| 636 | - */ |
|
| 637 | - public function load_addon($path_to_file, $class_name, $type = 'class', $arguments = array(), $load_only = false) |
|
| 638 | - { |
|
| 639 | - // retrieve instantiated class |
|
| 640 | - return $this->_load( |
|
| 641 | - $path_to_file, |
|
| 642 | - 'addon', |
|
| 643 | - $class_name, |
|
| 644 | - $type, |
|
| 645 | - $arguments, |
|
| 646 | - false, |
|
| 647 | - true, |
|
| 648 | - $load_only |
|
| 649 | - ); |
|
| 650 | - } |
|
| 651 | - |
|
| 652 | - |
|
| 653 | - |
|
| 654 | - /** |
|
| 655 | - * instantiates, caches, and automatically resolves dependencies |
|
| 656 | - * for classes that use a Fully Qualified Class Name. |
|
| 657 | - * if the class is not capable of being loaded using PSR-4 autoloading, |
|
| 658 | - * then you need to use one of the existing load_*() methods |
|
| 659 | - * which can resolve the classname and filepath from the passed arguments |
|
| 660 | - * |
|
| 661 | - * @param bool|string $class_name Fully Qualified Class Name |
|
| 662 | - * @param array $arguments an argument, or array of arguments to pass to the class upon instantiation |
|
| 663 | - * @param bool $cache whether to cache the instantiated object for reuse |
|
| 664 | - * @param bool $from_db some classes are instantiated from the db |
|
| 665 | - * and thus call a different method to instantiate |
|
| 666 | - * @param bool $load_only if true, will only load the file, but will NOT instantiate an object |
|
| 667 | - * @param bool|string $addon if true, will cache the object in the EE_Registry->$addons array |
|
| 668 | - * @return bool|null|mixed null = failure to load or instantiate class object. |
|
| 669 | - * object = class loaded and instantiated successfully. |
|
| 670 | - * bool = fail or success when $load_only is true |
|
| 671 | - * @throws EE_Error |
|
| 672 | - * @throws ReflectionException |
|
| 673 | - */ |
|
| 674 | - public function create( |
|
| 675 | - $class_name = false, |
|
| 676 | - $arguments = array(), |
|
| 677 | - $cache = false, |
|
| 678 | - $from_db = false, |
|
| 679 | - $load_only = false, |
|
| 680 | - $addon = false |
|
| 681 | - ) { |
|
| 682 | - $class_name = ltrim($class_name, '\\'); |
|
| 683 | - $class_name = $this->_dependency_map->get_alias($class_name); |
|
| 684 | - $class_exists = $this->loadOrVerifyClassExists($class_name, $arguments); |
|
| 685 | - // if a non-FQCN was passed, then verifyClassExists() might return an object |
|
| 686 | - // or it could return null if the class just could not be found anywhere |
|
| 687 | - if ($class_exists instanceof $class_name || $class_exists === null){ |
|
| 688 | - // either way, return the results |
|
| 689 | - return $class_exists; |
|
| 690 | - } |
|
| 691 | - $class_name = $class_exists; |
|
| 692 | - // if we're only loading the class and it already exists, then let's just return true immediately |
|
| 693 | - if ($load_only) { |
|
| 694 | - return true; |
|
| 695 | - } |
|
| 696 | - $addon = $addon |
|
| 697 | - ? 'addon' |
|
| 698 | - : ''; |
|
| 699 | - // $this->_cache_on is toggled during the recursive loading that can occur with dependency injection |
|
| 700 | - // $cache is controlled by individual calls to separate Registry loader methods like load_class() |
|
| 701 | - // $load_only is also controlled by individual calls to separate Registry loader methods like load_file() |
|
| 702 | - if ($this->_cache_on && $cache && ! $load_only) { |
|
| 703 | - // return object if it's already cached |
|
| 704 | - $cached_class = $this->_get_cached_class($class_name, $addon); |
|
| 705 | - if ($cached_class !== null) { |
|
| 706 | - return $cached_class; |
|
| 707 | - } |
|
| 708 | - } |
|
| 709 | - // obtain the loader method from the dependency map |
|
| 710 | - $loader = $this->_dependency_map->class_loader($class_name); |
|
| 711 | - // instantiate the requested object |
|
| 712 | - if ($loader instanceof Closure) { |
|
| 713 | - $class_obj = $loader($arguments); |
|
| 714 | - } else if ($loader && method_exists($this, $loader)) { |
|
| 715 | - $class_obj = $this->{$loader}($class_name, $arguments); |
|
| 716 | - } else { |
|
| 717 | - $class_obj = $this->_create_object($class_name, $arguments, $addon, $from_db); |
|
| 718 | - } |
|
| 719 | - if (($this->_cache_on && $cache) || $this->get_class_abbreviation($class_name, '')) { |
|
| 720 | - // save it for later... kinda like gum { : $ |
|
| 721 | - $this->_set_cached_class($class_obj, $class_name, $addon, $from_db); |
|
| 722 | - } |
|
| 723 | - $this->_cache_on = true; |
|
| 724 | - return $class_obj; |
|
| 725 | - } |
|
| 726 | - |
|
| 727 | - |
|
| 728 | - |
|
| 729 | - /** |
|
| 730 | - * Recursively checks that a class exists and potentially attempts to load classes with non-FQCNs |
|
| 731 | - * |
|
| 732 | - * @param string $class_name |
|
| 733 | - * @param array $arguments |
|
| 734 | - * @param int $attempt |
|
| 735 | - * @return mixed |
|
| 736 | - */ |
|
| 737 | - private function loadOrVerifyClassExists($class_name, array $arguments, $attempt = 1) { |
|
| 738 | - if (is_object($class_name) || class_exists($class_name)) { |
|
| 739 | - return $class_name; |
|
| 740 | - } |
|
| 741 | - switch ($attempt) { |
|
| 742 | - case 1: |
|
| 743 | - // if it's a FQCN then maybe the class is registered with a preceding \ |
|
| 744 | - $class_name = strpos($class_name, '\\') !== false |
|
| 745 | - ? '\\' . ltrim($class_name, '\\') |
|
| 746 | - : $class_name; |
|
| 747 | - break; |
|
| 748 | - case 2: |
|
| 749 | - // |
|
| 750 | - $loader = $this->_dependency_map->class_loader($class_name); |
|
| 751 | - if ($loader && method_exists($this, $loader)) { |
|
| 752 | - return $this->{$loader}($class_name, $arguments); |
|
| 753 | - } |
|
| 754 | - break; |
|
| 755 | - case 3: |
|
| 756 | - default; |
|
| 757 | - return null; |
|
| 758 | - } |
|
| 759 | - $attempt++; |
|
| 760 | - return $this->loadOrVerifyClassExists($class_name, $arguments, $attempt); |
|
| 761 | - } |
|
| 762 | - |
|
| 763 | - |
|
| 764 | - |
|
| 765 | - /** |
|
| 766 | - * instantiates, caches, and injects dependencies for classes |
|
| 767 | - * |
|
| 768 | - * @param array $file_paths an array of paths to folders to look in |
|
| 769 | - * @param string $class_prefix EE or EEM or... ??? |
|
| 770 | - * @param bool|string $class_name $class name |
|
| 771 | - * @param string $type file type - core? class? helper? model? |
|
| 772 | - * @param mixed $arguments an argument or array of arguments to pass to the class upon instantiation |
|
| 773 | - * @param bool $from_db some classes are instantiated from the db |
|
| 774 | - * and thus call a different method to instantiate |
|
| 775 | - * @param bool $cache whether to cache the instantiated object for reuse |
|
| 776 | - * @param bool $load_only if true, will only load the file, but will NOT instantiate an object |
|
| 777 | - * @return bool|null|object null = failure to load or instantiate class object. |
|
| 778 | - * object = class loaded and instantiated successfully. |
|
| 779 | - * bool = fail or success when $load_only is true |
|
| 780 | - * @throws EE_Error |
|
| 781 | - * @throws ReflectionException |
|
| 782 | - */ |
|
| 783 | - protected function _load( |
|
| 784 | - $file_paths = array(), |
|
| 785 | - $class_prefix = 'EE_', |
|
| 786 | - $class_name = false, |
|
| 787 | - $type = 'class', |
|
| 788 | - $arguments = array(), |
|
| 789 | - $from_db = false, |
|
| 790 | - $cache = true, |
|
| 791 | - $load_only = false |
|
| 792 | - ) { |
|
| 793 | - $class_name = ltrim($class_name, '\\'); |
|
| 794 | - // strip php file extension |
|
| 795 | - $class_name = str_replace('.php', '', trim($class_name)); |
|
| 796 | - // does the class have a prefix ? |
|
| 797 | - if (! empty($class_prefix) && $class_prefix !== 'addon') { |
|
| 798 | - // make sure $class_prefix is uppercase |
|
| 799 | - $class_prefix = strtoupper(trim($class_prefix)); |
|
| 800 | - // add class prefix ONCE!!! |
|
| 801 | - $class_name = $class_prefix . str_replace($class_prefix, '', $class_name); |
|
| 802 | - } |
|
| 803 | - $class_name = $this->_dependency_map->get_alias($class_name); |
|
| 804 | - $class_exists = class_exists($class_name, false); |
|
| 805 | - // if we're only loading the class and it already exists, then let's just return true immediately |
|
| 806 | - if ($load_only && $class_exists) { |
|
| 807 | - return true; |
|
| 808 | - } |
|
| 809 | - // $this->_cache_on is toggled during the recursive loading that can occur with dependency injection |
|
| 810 | - // $cache is controlled by individual calls to separate Registry loader methods like load_class() |
|
| 811 | - // $load_only is also controlled by individual calls to separate Registry loader methods like load_file() |
|
| 812 | - if ($this->_cache_on && $cache && ! $load_only) { |
|
| 813 | - // return object if it's already cached |
|
| 814 | - $cached_class = $this->_get_cached_class($class_name, $class_prefix); |
|
| 815 | - if ($cached_class !== null) { |
|
| 816 | - return $cached_class; |
|
| 817 | - } |
|
| 818 | - } |
|
| 819 | - // if the class doesn't already exist.. then we need to try and find the file and load it |
|
| 820 | - if (! $class_exists) { |
|
| 821 | - // get full path to file |
|
| 822 | - $path = $this->_resolve_path($class_name, $type, $file_paths); |
|
| 823 | - // load the file |
|
| 824 | - $loaded = $this->_require_file($path, $class_name, $type, $file_paths); |
|
| 825 | - // if loading failed, or we are only loading a file but NOT instantiating an object |
|
| 826 | - if (! $loaded || $load_only) { |
|
| 827 | - // return boolean if only loading, or null if an object was expected |
|
| 828 | - return $load_only |
|
| 829 | - ? $loaded |
|
| 830 | - : null; |
|
| 831 | - } |
|
| 832 | - } |
|
| 833 | - // instantiate the requested object |
|
| 834 | - $class_obj = $this->_create_object($class_name, $arguments, $type, $from_db); |
|
| 835 | - if ($this->_cache_on && $cache) { |
|
| 836 | - // save it for later... kinda like gum { : $ |
|
| 837 | - $this->_set_cached_class($class_obj, $class_name, $class_prefix, $from_db); |
|
| 838 | - } |
|
| 839 | - $this->_cache_on = true; |
|
| 840 | - return $class_obj; |
|
| 841 | - } |
|
| 842 | - |
|
| 843 | - |
|
| 844 | - |
|
| 845 | - /** |
|
| 846 | - * @param string $class_name |
|
| 847 | - * @param string $default have to specify something, but not anything that will conflict |
|
| 848 | - * @return mixed|string |
|
| 849 | - */ |
|
| 850 | - protected function get_class_abbreviation($class_name, $default = 'FANCY_BATMAN_PANTS') |
|
| 851 | - { |
|
| 852 | - return isset($this->_class_abbreviations[$class_name]) |
|
| 853 | - ? $this->_class_abbreviations[$class_name] |
|
| 854 | - : $default; |
|
| 855 | - } |
|
| 856 | - |
|
| 857 | - /** |
|
| 858 | - * attempts to find a cached version of the requested class |
|
| 859 | - * by looking in the following places: |
|
| 860 | - * $this->{$class_abbreviation} ie: $this->CART |
|
| 861 | - * $this->{$class_name} ie: $this->Some_Class |
|
| 862 | - * $this->LIB->{$class_name} ie: $this->LIB->Some_Class |
|
| 863 | - * $this->addon->{$class_name} ie: $this->addon->Some_Addon_Class |
|
| 864 | - * |
|
| 865 | - * @param string $class_name |
|
| 866 | - * @param string $class_prefix |
|
| 867 | - * @return mixed |
|
| 868 | - * @throws OutOfBoundsException |
|
| 869 | - */ |
|
| 870 | - protected function _get_cached_class($class_name, $class_prefix = '') |
|
| 871 | - { |
|
| 872 | - if ($class_name === 'EE_Registry') { |
|
| 873 | - return $this; |
|
| 874 | - } |
|
| 875 | - $class_abbreviation = $this->get_class_abbreviation($class_name); |
|
| 876 | - $class_name = str_replace('\\', '_', $class_name); |
|
| 877 | - // check if class has already been loaded, and return it if it has been |
|
| 878 | - if (isset($this->{$class_abbreviation})) { |
|
| 879 | - return $this->{$class_abbreviation}; |
|
| 880 | - } |
|
| 881 | - if (isset ($this->{$class_name})) { |
|
| 882 | - return $this->{$class_name}; |
|
| 883 | - } |
|
| 884 | - if (isset ($this->LIB->{$class_name})) { |
|
| 885 | - return $this->LIB->{$class_name}; |
|
| 886 | - } |
|
| 887 | - if ($class_prefix === 'addon' && isset ($this->addons->{$class_name})) { |
|
| 888 | - return $this->addons->{$class_name}; |
|
| 889 | - } |
|
| 890 | - return null; |
|
| 891 | - } |
|
| 892 | - |
|
| 893 | - |
|
| 894 | - |
|
| 895 | - /** |
|
| 896 | - * removes a cached version of the requested class |
|
| 897 | - * |
|
| 898 | - * @param string $class_name |
|
| 899 | - * @param boolean $addon |
|
| 900 | - * @return boolean |
|
| 901 | - * @throws OutOfBoundsException |
|
| 902 | - */ |
|
| 903 | - public function clear_cached_class($class_name, $addon = false) |
|
| 904 | - { |
|
| 905 | - $class_abbreviation = $this->get_class_abbreviation($class_name); |
|
| 906 | - $class_name = str_replace('\\', '_', $class_name); |
|
| 907 | - // check if class has already been loaded, and return it if it has been |
|
| 908 | - if (isset($this->{$class_abbreviation})) { |
|
| 909 | - $this->{$class_abbreviation} = null; |
|
| 910 | - return true; |
|
| 911 | - } |
|
| 912 | - if (isset($this->{$class_name})) { |
|
| 913 | - $this->{$class_name} = null; |
|
| 914 | - return true; |
|
| 915 | - } |
|
| 916 | - if (isset($this->LIB->{$class_name})) { |
|
| 917 | - unset($this->LIB->{$class_name}); |
|
| 918 | - return true; |
|
| 919 | - } |
|
| 920 | - if ($addon && isset($this->addons->{$class_name})) { |
|
| 921 | - unset($this->addons->{$class_name}); |
|
| 922 | - return true; |
|
| 923 | - } |
|
| 924 | - return false; |
|
| 925 | - } |
|
| 926 | - |
|
| 927 | - |
|
| 928 | - |
|
| 929 | - /** |
|
| 930 | - * attempts to find a full valid filepath for the requested class. |
|
| 931 | - * loops thru each of the base paths in the $file_paths array and appends : "{classname} . {file type} . php" |
|
| 932 | - * then returns that path if the target file has been found and is readable |
|
| 933 | - * |
|
| 934 | - * @param string $class_name |
|
| 935 | - * @param string $type |
|
| 936 | - * @param array $file_paths |
|
| 937 | - * @return string | bool |
|
| 938 | - */ |
|
| 939 | - protected function _resolve_path($class_name, $type = '', $file_paths = array()) |
|
| 940 | - { |
|
| 941 | - // make sure $file_paths is an array |
|
| 942 | - $file_paths = is_array($file_paths) |
|
| 943 | - ? $file_paths |
|
| 944 | - : array($file_paths); |
|
| 945 | - // cycle thru paths |
|
| 946 | - foreach ($file_paths as $key => $file_path) { |
|
| 947 | - // convert all separators to proper DS, if no filepath, then use EE_CLASSES |
|
| 948 | - $file_path = $file_path |
|
| 949 | - ? str_replace(array('/', '\\'), DS, $file_path) |
|
| 950 | - : EE_CLASSES; |
|
| 951 | - // prep file type |
|
| 952 | - $type = ! empty($type) |
|
| 953 | - ? trim($type, '.') . '.' |
|
| 954 | - : ''; |
|
| 955 | - // build full file path |
|
| 956 | - $file_paths[$key] = rtrim($file_path, DS) . DS . $class_name . '.' . $type . 'php'; |
|
| 957 | - //does the file exist and can be read ? |
|
| 958 | - if (is_readable($file_paths[$key])) { |
|
| 959 | - return $file_paths[$key]; |
|
| 960 | - } |
|
| 961 | - } |
|
| 962 | - return false; |
|
| 963 | - } |
|
| 964 | - |
|
| 965 | - |
|
| 966 | - |
|
| 967 | - /** |
|
| 968 | - * basically just performs a require_once() |
|
| 969 | - * but with some error handling |
|
| 970 | - * |
|
| 971 | - * @param string $path |
|
| 972 | - * @param string $class_name |
|
| 973 | - * @param string $type |
|
| 974 | - * @param array $file_paths |
|
| 975 | - * @return bool |
|
| 976 | - * @throws EE_Error |
|
| 977 | - * @throws ReflectionException |
|
| 978 | - */ |
|
| 979 | - protected function _require_file($path, $class_name, $type = '', $file_paths = array()) |
|
| 980 | - { |
|
| 981 | - $this->resolve_legacy_class_parent($class_name); |
|
| 982 | - // don't give up! you gotta... |
|
| 983 | - try { |
|
| 984 | - //does the file exist and can it be read ? |
|
| 985 | - if (! $path) { |
|
| 986 | - // just in case the file has already been autoloaded, |
|
| 987 | - // but discrepancies in the naming schema are preventing it from |
|
| 988 | - // being loaded via one of the EE_Registry::load_*() methods, |
|
| 989 | - // then let's try one last hail mary before throwing an exception |
|
| 990 | - // and call class_exists() again, but with autoloading turned ON |
|
| 991 | - if(class_exists($class_name)) { |
|
| 992 | - return true; |
|
| 993 | - } |
|
| 994 | - // so sorry, can't find the file |
|
| 995 | - throw new EE_Error ( |
|
| 996 | - sprintf( |
|
| 997 | - esc_html__( |
|
| 998 | - 'The %1$s file %2$s could not be located or is not readable due to file permissions. Please ensure that the following filepath(s) are correct: %3$s', |
|
| 999 | - 'event_espresso' |
|
| 1000 | - ), |
|
| 1001 | - trim($type, '.'), |
|
| 1002 | - $class_name, |
|
| 1003 | - '<br />' . implode(',<br />', $file_paths) |
|
| 1004 | - ) |
|
| 1005 | - ); |
|
| 1006 | - } |
|
| 1007 | - // get the file |
|
| 1008 | - require_once($path); |
|
| 1009 | - // if the class isn't already declared somewhere |
|
| 1010 | - if (class_exists($class_name, false) === false) { |
|
| 1011 | - // so sorry, not a class |
|
| 1012 | - throw new EE_Error( |
|
| 1013 | - sprintf( |
|
| 1014 | - esc_html__('The %s file %s does not appear to contain the %s Class.', 'event_espresso'), |
|
| 1015 | - $type, |
|
| 1016 | - $path, |
|
| 1017 | - $class_name |
|
| 1018 | - ) |
|
| 1019 | - ); |
|
| 1020 | - } |
|
| 1021 | - } catch (EE_Error $e) { |
|
| 1022 | - $e->get_error(); |
|
| 1023 | - return false; |
|
| 1024 | - } |
|
| 1025 | - return true; |
|
| 1026 | - } |
|
| 1027 | - |
|
| 1028 | - |
|
| 1029 | - |
|
| 1030 | - /** |
|
| 1031 | - * Some of our legacy classes that extended a parent class would simply use a require() statement |
|
| 1032 | - * before their class declaration in order to ensure that the parent class was loaded. |
|
| 1033 | - * This is not ideal, but it's nearly impossible to determine the parent class of a non-namespaced class, |
|
| 1034 | - * without triggering a fatal error because the parent class has yet to be loaded and therefore doesn't exist. |
|
| 1035 | - * |
|
| 1036 | - * @param string $class_name |
|
| 1037 | - */ |
|
| 1038 | - protected function resolve_legacy_class_parent($class_name = '') |
|
| 1039 | - { |
|
| 1040 | - try { |
|
| 1041 | - $legacy_parent_class_map = array( |
|
| 1042 | - 'EE_Payment_Processor' => 'core/business/EE_Processor_Base.class.php' |
|
| 1043 | - ); |
|
| 1044 | - if(isset($legacy_parent_class_map[$class_name])) { |
|
| 1045 | - require_once EE_PLUGIN_DIR_PATH . $legacy_parent_class_map[$class_name]; |
|
| 1046 | - } |
|
| 1047 | - } catch (Exception $exception) { |
|
| 1048 | - } |
|
| 1049 | - } |
|
| 1050 | - |
|
| 1051 | - |
|
| 1052 | - |
|
| 1053 | - /** |
|
| 1054 | - * _create_object |
|
| 1055 | - * Attempts to instantiate the requested class via any of the |
|
| 1056 | - * commonly used instantiation methods employed throughout EE. |
|
| 1057 | - * The priority for instantiation is as follows: |
|
| 1058 | - * - abstract classes or any class flagged as "load only" (no instantiation occurs) |
|
| 1059 | - * - model objects via their 'new_instance_from_db' method |
|
| 1060 | - * - model objects via their 'new_instance' method |
|
| 1061 | - * - "singleton" classes" via their 'instance' method |
|
| 1062 | - * - standard instantiable classes via their __constructor |
|
| 1063 | - * Prior to instantiation, if the classname exists in the dependency_map, |
|
| 1064 | - * then the constructor for the requested class will be examined to determine |
|
| 1065 | - * if any dependencies exist, and if they can be injected. |
|
| 1066 | - * If so, then those classes will be added to the array of arguments passed to the constructor |
|
| 1067 | - * |
|
| 1068 | - * @param string $class_name |
|
| 1069 | - * @param array $arguments |
|
| 1070 | - * @param string $type |
|
| 1071 | - * @param bool $from_db |
|
| 1072 | - * @return null|object |
|
| 1073 | - * @throws EE_Error |
|
| 1074 | - * @throws ReflectionException |
|
| 1075 | - */ |
|
| 1076 | - protected function _create_object($class_name, $arguments = array(), $type = '', $from_db = false) |
|
| 1077 | - { |
|
| 1078 | - // create reflection |
|
| 1079 | - $reflector = $this->get_ReflectionClass($class_name); |
|
| 1080 | - // make sure arguments are an array |
|
| 1081 | - $arguments = is_array($arguments) |
|
| 1082 | - ? $arguments |
|
| 1083 | - : array($arguments); |
|
| 1084 | - // and if arguments array is numerically and sequentially indexed, then we want it to remain as is, |
|
| 1085 | - // else wrap it in an additional array so that it doesn't get split into multiple parameters |
|
| 1086 | - $arguments = $this->_array_is_numerically_and_sequentially_indexed($arguments) |
|
| 1087 | - ? $arguments |
|
| 1088 | - : array($arguments); |
|
| 1089 | - // attempt to inject dependencies ? |
|
| 1090 | - if ($this->_dependency_map->has($class_name)) { |
|
| 1091 | - $arguments = $this->_resolve_dependencies($reflector, $class_name, $arguments); |
|
| 1092 | - } |
|
| 1093 | - // instantiate the class if possible |
|
| 1094 | - if ($reflector->isAbstract()) { |
|
| 1095 | - // nothing to instantiate, loading file was enough |
|
| 1096 | - // does not throw an exception so $instantiation_mode is unused |
|
| 1097 | - // $instantiation_mode = "1) no constructor abstract class"; |
|
| 1098 | - return true; |
|
| 1099 | - } |
|
| 1100 | - if (empty($arguments) && $reflector->getConstructor() === null && $reflector->isInstantiable()) { |
|
| 1101 | - // no constructor = static methods only... nothing to instantiate, loading file was enough |
|
| 1102 | - // $instantiation_mode = "2) no constructor but instantiable"; |
|
| 1103 | - return $reflector->newInstance(); |
|
| 1104 | - } |
|
| 1105 | - if ($from_db && method_exists($class_name, 'new_instance_from_db')) { |
|
| 1106 | - // $instantiation_mode = "3) new_instance_from_db()"; |
|
| 1107 | - return call_user_func_array(array($class_name, 'new_instance_from_db'), $arguments); |
|
| 1108 | - } |
|
| 1109 | - if (method_exists($class_name, 'new_instance')) { |
|
| 1110 | - // $instantiation_mode = "4) new_instance()"; |
|
| 1111 | - return call_user_func_array(array($class_name, 'new_instance'), $arguments); |
|
| 1112 | - } |
|
| 1113 | - if (method_exists($class_name, 'instance')) { |
|
| 1114 | - // $instantiation_mode = "5) instance()"; |
|
| 1115 | - return call_user_func_array(array($class_name, 'instance'), $arguments); |
|
| 1116 | - } |
|
| 1117 | - if ($reflector->isInstantiable()) { |
|
| 1118 | - // $instantiation_mode = "6) constructor"; |
|
| 1119 | - return $reflector->newInstanceArgs($arguments); |
|
| 1120 | - } |
|
| 1121 | - // heh ? something's not right ! |
|
| 1122 | - throw new EE_Error( |
|
| 1123 | - sprintf( |
|
| 1124 | - __('The %s file %s could not be instantiated.', 'event_espresso'), |
|
| 1125 | - $type, |
|
| 1126 | - $class_name |
|
| 1127 | - ) |
|
| 1128 | - ); |
|
| 1129 | - } |
|
| 1130 | - |
|
| 1131 | - |
|
| 1132 | - |
|
| 1133 | - /** |
|
| 1134 | - * @see http://stackoverflow.com/questions/173400/how-to-check-if-php-array-is-associative-or-sequential |
|
| 1135 | - * @param array $array |
|
| 1136 | - * @return bool |
|
| 1137 | - */ |
|
| 1138 | - protected function _array_is_numerically_and_sequentially_indexed(array $array) |
|
| 1139 | - { |
|
| 1140 | - return ! empty($array) |
|
| 1141 | - ? array_keys($array) === range(0, count($array) - 1) |
|
| 1142 | - : true; |
|
| 1143 | - } |
|
| 1144 | - |
|
| 1145 | - |
|
| 1146 | - |
|
| 1147 | - /** |
|
| 1148 | - * getReflectionClass |
|
| 1149 | - * checks if a ReflectionClass object has already been generated for a class |
|
| 1150 | - * and returns that instead of creating a new one |
|
| 1151 | - * |
|
| 1152 | - * @param string $class_name |
|
| 1153 | - * @return ReflectionClass |
|
| 1154 | - * @throws ReflectionException |
|
| 1155 | - */ |
|
| 1156 | - public function get_ReflectionClass($class_name) |
|
| 1157 | - { |
|
| 1158 | - if ( |
|
| 1159 | - ! isset($this->_reflectors[$class_name]) |
|
| 1160 | - || ! $this->_reflectors[$class_name] instanceof ReflectionClass |
|
| 1161 | - ) { |
|
| 1162 | - $this->_reflectors[$class_name] = new ReflectionClass($class_name); |
|
| 1163 | - } |
|
| 1164 | - return $this->_reflectors[$class_name]; |
|
| 1165 | - } |
|
| 1166 | - |
|
| 1167 | - |
|
| 1168 | - |
|
| 1169 | - /** |
|
| 1170 | - * _resolve_dependencies |
|
| 1171 | - * examines the constructor for the requested class to determine |
|
| 1172 | - * if any dependencies exist, and if they can be injected. |
|
| 1173 | - * If so, then those classes will be added to the array of arguments passed to the constructor |
|
| 1174 | - * PLZ NOTE: this is achieved by type hinting the constructor params |
|
| 1175 | - * For example: |
|
| 1176 | - * if attempting to load a class "Foo" with the following constructor: |
|
| 1177 | - * __construct( Bar $bar_class, Fighter $grohl_class ) |
|
| 1178 | - * then $bar_class and $grohl_class will be added to the $arguments array, |
|
| 1179 | - * but only IF they are NOT already present in the incoming arguments array, |
|
| 1180 | - * and the correct classes can be loaded |
|
| 1181 | - * |
|
| 1182 | - * @param ReflectionClass $reflector |
|
| 1183 | - * @param string $class_name |
|
| 1184 | - * @param array $arguments |
|
| 1185 | - * @return array |
|
| 1186 | - * @throws EE_Error |
|
| 1187 | - * @throws ReflectionException |
|
| 1188 | - */ |
|
| 1189 | - protected function _resolve_dependencies(ReflectionClass $reflector, $class_name, $arguments = array()) |
|
| 1190 | - { |
|
| 1191 | - // let's examine the constructor |
|
| 1192 | - $constructor = $reflector->getConstructor(); |
|
| 1193 | - // whu? huh? nothing? |
|
| 1194 | - if (! $constructor) { |
|
| 1195 | - return $arguments; |
|
| 1196 | - } |
|
| 1197 | - // get constructor parameters |
|
| 1198 | - $params = $constructor->getParameters(); |
|
| 1199 | - // and the keys for the incoming arguments array so that we can compare existing arguments with what is expected |
|
| 1200 | - $argument_keys = array_keys($arguments); |
|
| 1201 | - // now loop thru all of the constructors expected parameters |
|
| 1202 | - foreach ($params as $index => $param) { |
|
| 1203 | - // is this a dependency for a specific class ? |
|
| 1204 | - $param_class = $param->getClass() |
|
| 1205 | - ? $param->getClass()->name |
|
| 1206 | - : null; |
|
| 1207 | - // BUT WAIT !!! This class may be an alias for something else (or getting replaced at runtime) |
|
| 1208 | - $param_class = $this->_dependency_map->has_alias($param_class, $class_name) |
|
| 1209 | - ? $this->_dependency_map->get_alias($param_class, $class_name) |
|
| 1210 | - : $param_class; |
|
| 1211 | - if ( |
|
| 1212 | - // param is not even a class |
|
| 1213 | - $param_class === null |
|
| 1214 | - // and something already exists in the incoming arguments for this param |
|
| 1215 | - && array_key_exists($index, $argument_keys) |
|
| 1216 | - && array_key_exists($argument_keys[$index], $arguments) |
|
| 1217 | - ) { |
|
| 1218 | - // so let's skip this argument and move on to the next |
|
| 1219 | - continue; |
|
| 1220 | - } |
|
| 1221 | - if ( |
|
| 1222 | - // parameter is type hinted as a class, exists as an incoming argument, AND it's the correct class |
|
| 1223 | - $param_class !== null |
|
| 1224 | - && isset($argument_keys[$index], $arguments[$argument_keys[$index]]) |
|
| 1225 | - && $arguments[$argument_keys[$index]] instanceof $param_class |
|
| 1226 | - ) { |
|
| 1227 | - // skip this argument and move on to the next |
|
| 1228 | - continue; |
|
| 1229 | - } |
|
| 1230 | - if ( |
|
| 1231 | - // parameter is type hinted as a class, and should be injected |
|
| 1232 | - $param_class !== null |
|
| 1233 | - && $this->_dependency_map->has_dependency_for_class($class_name, $param_class) |
|
| 1234 | - ) { |
|
| 1235 | - $arguments = $this->_resolve_dependency( |
|
| 1236 | - $class_name, |
|
| 1237 | - $param_class, |
|
| 1238 | - $arguments, |
|
| 1239 | - $index, |
|
| 1240 | - $argument_keys |
|
| 1241 | - ); |
|
| 1242 | - } else { |
|
| 1243 | - try { |
|
| 1244 | - $arguments[$index] = $param->isDefaultValueAvailable() |
|
| 1245 | - ? $param->getDefaultValue() |
|
| 1246 | - : null; |
|
| 1247 | - } catch (ReflectionException $e) { |
|
| 1248 | - throw new ReflectionException( |
|
| 1249 | - sprintf( |
|
| 1250 | - esc_html__('%1$s for parameter "$%2$s on classname "%3$s"', 'event_espresso'), |
|
| 1251 | - $e->getMessage(), |
|
| 1252 | - $param->getName(), |
|
| 1253 | - $class_name |
|
| 1254 | - ) |
|
| 1255 | - ); |
|
| 1256 | - } |
|
| 1257 | - } |
|
| 1258 | - } |
|
| 1259 | - return $arguments; |
|
| 1260 | - } |
|
| 1261 | - |
|
| 1262 | - |
|
| 1263 | - |
|
| 1264 | - /** |
|
| 1265 | - * @param string $class_name |
|
| 1266 | - * @param string $param_class |
|
| 1267 | - * @param array $arguments |
|
| 1268 | - * @param mixed $index |
|
| 1269 | - * @param array $argument_keys |
|
| 1270 | - * @return array |
|
| 1271 | - * @throws EE_Error |
|
| 1272 | - * @throws ReflectionException |
|
| 1273 | - * @throws InvalidArgumentException |
|
| 1274 | - * @throws InvalidInterfaceException |
|
| 1275 | - * @throws InvalidDataTypeException |
|
| 1276 | - */ |
|
| 1277 | - protected function _resolve_dependency($class_name, $param_class, $arguments, $index, array $argument_keys) |
|
| 1278 | - { |
|
| 1279 | - $dependency = null; |
|
| 1280 | - // should dependency be loaded from cache ? |
|
| 1281 | - $cache_on = $this->_dependency_map->loading_strategy_for_class_dependency( |
|
| 1282 | - $class_name, |
|
| 1283 | - $param_class |
|
| 1284 | - ); |
|
| 1285 | - $cache_on = $cache_on !== EE_Dependency_Map::load_new_object; |
|
| 1286 | - // we might have a dependency... |
|
| 1287 | - // let's MAYBE try and find it in our cache if that's what's been requested |
|
| 1288 | - $cached_class = $cache_on |
|
| 1289 | - ? $this->_get_cached_class($param_class) |
|
| 1290 | - : null; |
|
| 1291 | - // and grab it if it exists |
|
| 1292 | - if ($cached_class instanceof $param_class) { |
|
| 1293 | - $dependency = $cached_class; |
|
| 1294 | - } else if ($param_class !== $class_name) { |
|
| 1295 | - // obtain the loader method from the dependency map |
|
| 1296 | - $loader = $this->_dependency_map->class_loader($param_class); |
|
| 1297 | - // is loader a custom closure ? |
|
| 1298 | - if ($loader instanceof Closure) { |
|
| 1299 | - $dependency = $loader($arguments); |
|
| 1300 | - } else { |
|
| 1301 | - // set the cache on property for the recursive loading call |
|
| 1302 | - $this->_cache_on = $cache_on; |
|
| 1303 | - // if not, then let's try and load it via the registry |
|
| 1304 | - if ($loader && method_exists($this, $loader)) { |
|
| 1305 | - $dependency = $this->{$loader}($param_class); |
|
| 1306 | - } else { |
|
| 1307 | - $dependency = LoaderFactory::getLoader()->load( |
|
| 1308 | - $param_class, |
|
| 1309 | - array(), |
|
| 1310 | - $cache_on |
|
| 1311 | - ); |
|
| 1312 | - } |
|
| 1313 | - } |
|
| 1314 | - } |
|
| 1315 | - // did we successfully find the correct dependency ? |
|
| 1316 | - if ($dependency instanceof $param_class) { |
|
| 1317 | - // then let's inject it into the incoming array of arguments at the correct location |
|
| 1318 | - $arguments[$index] = $dependency; |
|
| 1319 | - } |
|
| 1320 | - return $arguments; |
|
| 1321 | - } |
|
| 1322 | - |
|
| 1323 | - |
|
| 1324 | - |
|
| 1325 | - /** |
|
| 1326 | - * _set_cached_class |
|
| 1327 | - * attempts to cache the instantiated class locally |
|
| 1328 | - * in one of the following places, in the following order: |
|
| 1329 | - * $this->{class_abbreviation} ie: $this->CART |
|
| 1330 | - * $this->{$class_name} ie: $this->Some_Class |
|
| 1331 | - * $this->addon->{$$class_name} ie: $this->addon->Some_Addon_Class |
|
| 1332 | - * $this->LIB->{$class_name} ie: $this->LIB->Some_Class |
|
| 1333 | - * |
|
| 1334 | - * @param object $class_obj |
|
| 1335 | - * @param string $class_name |
|
| 1336 | - * @param string $class_prefix |
|
| 1337 | - * @param bool $from_db |
|
| 1338 | - * @return void |
|
| 1339 | - * @throws OutOfBoundsException |
|
| 1340 | - */ |
|
| 1341 | - protected function _set_cached_class($class_obj, $class_name, $class_prefix = '', $from_db = false) |
|
| 1342 | - { |
|
| 1343 | - if ($class_name === 'EE_Registry' || empty($class_obj)) { |
|
| 1344 | - return; |
|
| 1345 | - } |
|
| 1346 | - // return newly instantiated class |
|
| 1347 | - $class_abbreviation = $this->get_class_abbreviation($class_name, ''); |
|
| 1348 | - if ($class_abbreviation) { |
|
| 1349 | - $this->{$class_abbreviation} = $class_obj; |
|
| 1350 | - return; |
|
| 1351 | - } |
|
| 1352 | - $class_name = str_replace('\\', '_', $class_name); |
|
| 1353 | - if (property_exists($this, $class_name)) { |
|
| 1354 | - $this->{$class_name} = $class_obj; |
|
| 1355 | - return; |
|
| 1356 | - } |
|
| 1357 | - if ($class_prefix === 'addon') { |
|
| 1358 | - $this->addons->{$class_name} = $class_obj; |
|
| 1359 | - return; |
|
| 1360 | - } |
|
| 1361 | - if (! $from_db) { |
|
| 1362 | - $this->LIB->{$class_name} = $class_obj; |
|
| 1363 | - } |
|
| 1364 | - } |
|
| 1365 | - |
|
| 1366 | - |
|
| 1367 | - |
|
| 1368 | - /** |
|
| 1369 | - * call any loader that's been registered in the EE_Dependency_Map::$_class_loaders array |
|
| 1370 | - * |
|
| 1371 | - * @param string $classname PLEASE NOTE: the class name needs to match what's registered |
|
| 1372 | - * in the EE_Dependency_Map::$_class_loaders array, |
|
| 1373 | - * including the class prefix, ie: "EE_", "EEM_", "EEH_", etc |
|
| 1374 | - * @param array $arguments |
|
| 1375 | - * @return object |
|
| 1376 | - */ |
|
| 1377 | - public static function factory($classname, $arguments = array()) |
|
| 1378 | - { |
|
| 1379 | - $loader = self::instance()->_dependency_map->class_loader($classname); |
|
| 1380 | - if ($loader instanceof Closure) { |
|
| 1381 | - return $loader($arguments); |
|
| 1382 | - } |
|
| 1383 | - if (method_exists(self::instance(), $loader)) { |
|
| 1384 | - return self::instance()->{$loader}($classname, $arguments); |
|
| 1385 | - } |
|
| 1386 | - return null; |
|
| 1387 | - } |
|
| 1388 | - |
|
| 1389 | - |
|
| 1390 | - |
|
| 1391 | - /** |
|
| 1392 | - * Gets the addon by its class name |
|
| 1393 | - * |
|
| 1394 | - * @param string $class_name |
|
| 1395 | - * @return EE_Addon |
|
| 1396 | - * @throws OutOfBoundsException |
|
| 1397 | - */ |
|
| 1398 | - public function getAddon($class_name) |
|
| 1399 | - { |
|
| 1400 | - $class_name = str_replace('\\', '_', $class_name); |
|
| 1401 | - return $this->addons->{$class_name}; |
|
| 1402 | - } |
|
| 1403 | - |
|
| 1404 | - |
|
| 1405 | - /** |
|
| 1406 | - * removes the addon from the internal cache |
|
| 1407 | - * |
|
| 1408 | - * @param string $class_name |
|
| 1409 | - * @return void |
|
| 1410 | - */ |
|
| 1411 | - public function removeAddon($class_name) |
|
| 1412 | - { |
|
| 1413 | - $class_name = str_replace('\\', '_', $class_name); |
|
| 1414 | - unset($this->addons->{$class_name}); |
|
| 1415 | - } |
|
| 1416 | - |
|
| 1417 | - |
|
| 1418 | - |
|
| 1419 | - /** |
|
| 1420 | - * Gets the addon by its name/slug (not classname. For that, just |
|
| 1421 | - * use the get_addon() method above |
|
| 1422 | - * |
|
| 1423 | - * @param string $name |
|
| 1424 | - * @return EE_Addon |
|
| 1425 | - */ |
|
| 1426 | - public function get_addon_by_name($name) |
|
| 1427 | - { |
|
| 1428 | - foreach ($this->addons as $addon) { |
|
| 1429 | - if ($addon->name() === $name) { |
|
| 1430 | - return $addon; |
|
| 1431 | - } |
|
| 1432 | - } |
|
| 1433 | - return null; |
|
| 1434 | - } |
|
| 1435 | - |
|
| 1436 | - |
|
| 1437 | - |
|
| 1438 | - /** |
|
| 1439 | - * Gets an array of all the registered addons, where the keys are their names. |
|
| 1440 | - * (ie, what each returns for their name() function) |
|
| 1441 | - * They're already available on EE_Registry::instance()->addons as properties, |
|
| 1442 | - * where each property's name is the addon's classname, |
|
| 1443 | - * So if you just want to get the addon by classname, |
|
| 1444 | - * OR use the get_addon() method above. |
|
| 1445 | - * PLEASE NOTE: |
|
| 1446 | - * addons with Fully Qualified Class Names |
|
| 1447 | - * have had the namespace separators converted to underscores, |
|
| 1448 | - * so a classname like Fully\Qualified\ClassName |
|
| 1449 | - * would have been converted to Fully_Qualified_ClassName |
|
| 1450 | - * |
|
| 1451 | - * @return EE_Addon[] where the KEYS are the addon's name() |
|
| 1452 | - */ |
|
| 1453 | - public function get_addons_by_name() |
|
| 1454 | - { |
|
| 1455 | - $addons = array(); |
|
| 1456 | - foreach ($this->addons as $addon) { |
|
| 1457 | - $addons[$addon->name()] = $addon; |
|
| 1458 | - } |
|
| 1459 | - return $addons; |
|
| 1460 | - } |
|
| 1461 | - |
|
| 1462 | - |
|
| 1463 | - /** |
|
| 1464 | - * Resets the specified model's instance AND makes sure EE_Registry doesn't keep |
|
| 1465 | - * a stale copy of it around |
|
| 1466 | - * |
|
| 1467 | - * @param string $model_name |
|
| 1468 | - * @return \EEM_Base |
|
| 1469 | - * @throws \EE_Error |
|
| 1470 | - */ |
|
| 1471 | - public function reset_model($model_name) |
|
| 1472 | - { |
|
| 1473 | - $model_class_name = strpos($model_name, 'EEM_') !== 0 |
|
| 1474 | - ? "EEM_{$model_name}" |
|
| 1475 | - : $model_name; |
|
| 1476 | - if (! isset($this->LIB->{$model_class_name}) || ! $this->LIB->{$model_class_name} instanceof EEM_Base) { |
|
| 1477 | - return null; |
|
| 1478 | - } |
|
| 1479 | - //get that model reset it and make sure we nuke the old reference to it |
|
| 1480 | - if ($this->LIB->{$model_class_name} instanceof $model_class_name |
|
| 1481 | - && is_callable( |
|
| 1482 | - array($model_class_name, 'reset') |
|
| 1483 | - )) { |
|
| 1484 | - $this->LIB->{$model_class_name} = $this->LIB->{$model_class_name}->reset(); |
|
| 1485 | - } else { |
|
| 1486 | - throw new EE_Error(sprintf(esc_html__('Model %s does not have a method "reset"', 'event_espresso'), $model_name)); |
|
| 1487 | - } |
|
| 1488 | - return $this->LIB->{$model_class_name}; |
|
| 1489 | - } |
|
| 1490 | - |
|
| 1491 | - |
|
| 1492 | - |
|
| 1493 | - /** |
|
| 1494 | - * Resets the registry. |
|
| 1495 | - * The criteria for what gets reset is based on what can be shared between sites on the same request when |
|
| 1496 | - * switch_to_blog is used in a multisite install. Here is a list of things that are NOT reset. |
|
| 1497 | - * - $_dependency_map |
|
| 1498 | - * - $_class_abbreviations |
|
| 1499 | - * - $NET_CFG (EE_Network_Config): The config is shared network wide so no need to reset. |
|
| 1500 | - * - $REQ: Still on the same request so no need to change. |
|
| 1501 | - * - $CAP: There is no site specific state in the EE_Capability class. |
|
| 1502 | - * - $SSN: Although ideally, the session should not be shared between site switches, we can't reset it because only |
|
| 1503 | - * one Session can be active in a single request. Resetting could resolve in "headers already sent" errors. |
|
| 1504 | - * - $addons: In multisite, the state of the addons is something controlled via hooks etc in a normal request. So |
|
| 1505 | - * for now, we won't reset the addons because it could break calls to an add-ons class/methods in the |
|
| 1506 | - * switch or on the restore. |
|
| 1507 | - * - $modules |
|
| 1508 | - * - $shortcodes |
|
| 1509 | - * - $widgets |
|
| 1510 | - * |
|
| 1511 | - * @param boolean $hard [deprecated] |
|
| 1512 | - * @param boolean $reinstantiate whether to create new instances of EE_Registry's singletons too, |
|
| 1513 | - * or just reset without re-instantiating (handy to set to FALSE if you're not |
|
| 1514 | - * sure if you CAN currently reinstantiate the singletons at the moment) |
|
| 1515 | - * @param bool $reset_models Defaults to true. When false, then the models are not reset. This is so |
|
| 1516 | - * client |
|
| 1517 | - * code instead can just change the model context to a different blog id if |
|
| 1518 | - * necessary |
|
| 1519 | - * @return EE_Registry |
|
| 1520 | - * @throws EE_Error |
|
| 1521 | - * @throws ReflectionException |
|
| 1522 | - */ |
|
| 1523 | - public static function reset($hard = false, $reinstantiate = true, $reset_models = true) |
|
| 1524 | - { |
|
| 1525 | - $instance = self::instance(); |
|
| 1526 | - $instance->_cache_on = true; |
|
| 1527 | - // reset some "special" classes |
|
| 1528 | - EEH_Activation::reset(); |
|
| 1529 | - $hard = apply_filters( 'FHEE__EE_Registry__reset__hard', $hard); |
|
| 1530 | - $instance->CFG = EE_Config::reset($hard, $reinstantiate); |
|
| 1531 | - $instance->CART = null; |
|
| 1532 | - $instance->MRM = null; |
|
| 1533 | - $instance->AssetsRegistry = $instance->create('EventEspresso\core\services\assets\Registry'); |
|
| 1534 | - //messages reset |
|
| 1535 | - EED_Messages::reset(); |
|
| 1536 | - //handle of objects cached on LIB |
|
| 1537 | - foreach (array('LIB', 'modules') as $cache) { |
|
| 1538 | - foreach ($instance->{$cache} as $class_name => $class) { |
|
| 1539 | - if (self::_reset_and_unset_object($class, $reset_models)) { |
|
| 1540 | - unset($instance->{$cache}->{$class_name}); |
|
| 1541 | - } |
|
| 1542 | - } |
|
| 1543 | - } |
|
| 1544 | - return $instance; |
|
| 1545 | - } |
|
| 1546 | - |
|
| 1547 | - |
|
| 1548 | - |
|
| 1549 | - /** |
|
| 1550 | - * if passed object implements ResettableInterface, then call it's reset() method |
|
| 1551 | - * if passed object implements InterminableInterface, then return false, |
|
| 1552 | - * to indicate that it should NOT be cleared from the Registry cache |
|
| 1553 | - * |
|
| 1554 | - * @param $object |
|
| 1555 | - * @param bool $reset_models |
|
| 1556 | - * @return bool returns true if cached object should be unset |
|
| 1557 | - */ |
|
| 1558 | - private static function _reset_and_unset_object($object, $reset_models) |
|
| 1559 | - { |
|
| 1560 | - if (! is_object($object)) { |
|
| 1561 | - // don't unset anything that's not an object |
|
| 1562 | - return false; |
|
| 1563 | - } |
|
| 1564 | - if ($object instanceof EED_Module) { |
|
| 1565 | - $object::reset(); |
|
| 1566 | - // don't unset modules |
|
| 1567 | - return false; |
|
| 1568 | - } |
|
| 1569 | - if ($object instanceof ResettableInterface) { |
|
| 1570 | - if ($object instanceof EEM_Base) { |
|
| 1571 | - if ($reset_models) { |
|
| 1572 | - $object->reset(); |
|
| 1573 | - return true; |
|
| 1574 | - } |
|
| 1575 | - return false; |
|
| 1576 | - } |
|
| 1577 | - $object->reset(); |
|
| 1578 | - return true; |
|
| 1579 | - } |
|
| 1580 | - if (! $object instanceof InterminableInterface) { |
|
| 1581 | - return true; |
|
| 1582 | - } |
|
| 1583 | - return false; |
|
| 1584 | - } |
|
| 1585 | - |
|
| 1586 | - |
|
| 1587 | - |
|
| 1588 | - /** |
|
| 1589 | - * Gets all the custom post type models defined |
|
| 1590 | - * |
|
| 1591 | - * @return array keys are model "short names" (Eg "Event") and keys are classnames (eg "EEM_Event") |
|
| 1592 | - */ |
|
| 1593 | - public function cpt_models() |
|
| 1594 | - { |
|
| 1595 | - $cpt_models = array(); |
|
| 1596 | - foreach ($this->non_abstract_db_models as $short_name => $classname) { |
|
| 1597 | - if (is_subclass_of($classname, 'EEM_CPT_Base')) { |
|
| 1598 | - $cpt_models[$short_name] = $classname; |
|
| 1599 | - } |
|
| 1600 | - } |
|
| 1601 | - return $cpt_models; |
|
| 1602 | - } |
|
| 1603 | - |
|
| 1604 | - |
|
| 1605 | - |
|
| 1606 | - /** |
|
| 1607 | - * @return \EE_Config |
|
| 1608 | - */ |
|
| 1609 | - public static function CFG() |
|
| 1610 | - { |
|
| 1611 | - return self::instance()->CFG; |
|
| 1612 | - } |
|
| 26 | + /** |
|
| 27 | + * @var EE_Registry $_instance |
|
| 28 | + */ |
|
| 29 | + private static $_instance; |
|
| 30 | + |
|
| 31 | + /** |
|
| 32 | + * @var EE_Dependency_Map $_dependency_map |
|
| 33 | + */ |
|
| 34 | + protected $_dependency_map; |
|
| 35 | + |
|
| 36 | + /** |
|
| 37 | + * @var array $_class_abbreviations |
|
| 38 | + */ |
|
| 39 | + protected $_class_abbreviations = array(); |
|
| 40 | + |
|
| 41 | + /** |
|
| 42 | + * @var CommandBusInterface $BUS |
|
| 43 | + */ |
|
| 44 | + public $BUS; |
|
| 45 | + |
|
| 46 | + /** |
|
| 47 | + * @var EE_Cart $CART |
|
| 48 | + */ |
|
| 49 | + public $CART; |
|
| 50 | + |
|
| 51 | + /** |
|
| 52 | + * @var EE_Config $CFG |
|
| 53 | + */ |
|
| 54 | + public $CFG; |
|
| 55 | + |
|
| 56 | + /** |
|
| 57 | + * @var EE_Network_Config $NET_CFG |
|
| 58 | + */ |
|
| 59 | + public $NET_CFG; |
|
| 60 | + |
|
| 61 | + /** |
|
| 62 | + * StdClass object for storing library classes in |
|
| 63 | + * |
|
| 64 | + * @var StdClass $LIB |
|
| 65 | + */ |
|
| 66 | + public $LIB; |
|
| 67 | + |
|
| 68 | + /** |
|
| 69 | + * @var EE_Request_Handler $REQ |
|
| 70 | + */ |
|
| 71 | + public $REQ; |
|
| 72 | + |
|
| 73 | + /** |
|
| 74 | + * @var EE_Session $SSN |
|
| 75 | + */ |
|
| 76 | + public $SSN; |
|
| 77 | + |
|
| 78 | + /** |
|
| 79 | + * @since 4.5.0 |
|
| 80 | + * @var EE_Capabilities $CAP |
|
| 81 | + */ |
|
| 82 | + public $CAP; |
|
| 83 | + |
|
| 84 | + /** |
|
| 85 | + * @since 4.9.0 |
|
| 86 | + * @var EE_Message_Resource_Manager $MRM |
|
| 87 | + */ |
|
| 88 | + public $MRM; |
|
| 89 | + |
|
| 90 | + |
|
| 91 | + /** |
|
| 92 | + * @var Registry $AssetsRegistry |
|
| 93 | + */ |
|
| 94 | + public $AssetsRegistry; |
|
| 95 | + |
|
| 96 | + /** |
|
| 97 | + * StdClass object for holding addons which have registered themselves to work with EE core |
|
| 98 | + * |
|
| 99 | + * @var EE_Addon[] $addons |
|
| 100 | + */ |
|
| 101 | + public $addons; |
|
| 102 | + |
|
| 103 | + /** |
|
| 104 | + * keys are 'short names' (eg Event), values are class names (eg 'EEM_Event') |
|
| 105 | + * |
|
| 106 | + * @var EEM_Base[] $models |
|
| 107 | + */ |
|
| 108 | + public $models = array(); |
|
| 109 | + |
|
| 110 | + /** |
|
| 111 | + * @var EED_Module[] $modules |
|
| 112 | + */ |
|
| 113 | + public $modules; |
|
| 114 | + |
|
| 115 | + /** |
|
| 116 | + * @var EES_Shortcode[] $shortcodes |
|
| 117 | + */ |
|
| 118 | + public $shortcodes; |
|
| 119 | + |
|
| 120 | + /** |
|
| 121 | + * @var WP_Widget[] $widgets |
|
| 122 | + */ |
|
| 123 | + public $widgets; |
|
| 124 | + |
|
| 125 | + /** |
|
| 126 | + * this is an array of all implemented model names (i.e. not the parent abstract models, or models |
|
| 127 | + * which don't actually fetch items from the DB in the normal way (ie, are not children of EEM_Base)). |
|
| 128 | + * Keys are model "short names" (eg "Event") as used in model relations, and values are |
|
| 129 | + * classnames (eg "EEM_Event") |
|
| 130 | + * |
|
| 131 | + * @var array $non_abstract_db_models |
|
| 132 | + */ |
|
| 133 | + public $non_abstract_db_models = array(); |
|
| 134 | + |
|
| 135 | + |
|
| 136 | + /** |
|
| 137 | + * internationalization for JS strings |
|
| 138 | + * usage: EE_Registry::i18n_js_strings['string_key'] = esc_html__( 'string to translate.', 'event_espresso' ); |
|
| 139 | + * in js file: var translatedString = eei18n.string_key; |
|
| 140 | + * |
|
| 141 | + * @var array $i18n_js_strings |
|
| 142 | + */ |
|
| 143 | + public static $i18n_js_strings = array(); |
|
| 144 | + |
|
| 145 | + |
|
| 146 | + /** |
|
| 147 | + * $main_file - path to espresso.php |
|
| 148 | + * |
|
| 149 | + * @var array $main_file |
|
| 150 | + */ |
|
| 151 | + public $main_file; |
|
| 152 | + |
|
| 153 | + /** |
|
| 154 | + * array of ReflectionClass objects where the key is the class name |
|
| 155 | + * |
|
| 156 | + * @var ReflectionClass[] $_reflectors |
|
| 157 | + */ |
|
| 158 | + public $_reflectors; |
|
| 159 | + |
|
| 160 | + /** |
|
| 161 | + * boolean flag to indicate whether or not to load/save dependencies from/to the cache |
|
| 162 | + * |
|
| 163 | + * @var boolean $_cache_on |
|
| 164 | + */ |
|
| 165 | + protected $_cache_on = true; |
|
| 166 | + |
|
| 167 | + |
|
| 168 | + |
|
| 169 | + /** |
|
| 170 | + * @singleton method used to instantiate class object |
|
| 171 | + * @param EE_Dependency_Map $dependency_map |
|
| 172 | + * @return EE_Registry instance |
|
| 173 | + * @throws InvalidArgumentException |
|
| 174 | + * @throws InvalidInterfaceException |
|
| 175 | + * @throws InvalidDataTypeException |
|
| 176 | + */ |
|
| 177 | + public static function instance(EE_Dependency_Map $dependency_map = null) |
|
| 178 | + { |
|
| 179 | + // check if class object is instantiated |
|
| 180 | + if (! self::$_instance instanceof EE_Registry) { |
|
| 181 | + self::$_instance = new self($dependency_map); |
|
| 182 | + } |
|
| 183 | + return self::$_instance; |
|
| 184 | + } |
|
| 185 | + |
|
| 186 | + |
|
| 187 | + |
|
| 188 | + /** |
|
| 189 | + * protected constructor to prevent direct creation |
|
| 190 | + * |
|
| 191 | + * @Constructor |
|
| 192 | + * @param EE_Dependency_Map $dependency_map |
|
| 193 | + * @throws InvalidDataTypeException |
|
| 194 | + * @throws InvalidInterfaceException |
|
| 195 | + * @throws InvalidArgumentException |
|
| 196 | + */ |
|
| 197 | + protected function __construct(EE_Dependency_Map $dependency_map) |
|
| 198 | + { |
|
| 199 | + $this->_dependency_map = $dependency_map; |
|
| 200 | + // $registry_container = new RegistryContainer(); |
|
| 201 | + $this->LIB = new RegistryContainer(); |
|
| 202 | + $this->addons = new RegistryContainer(); |
|
| 203 | + $this->modules = new RegistryContainer(); |
|
| 204 | + $this->shortcodes = new RegistryContainer(); |
|
| 205 | + $this->widgets = new RegistryContainer(); |
|
| 206 | + add_action('EE_Load_Espresso_Core__handle_request__initialize_core_loading', array($this, 'initialize')); |
|
| 207 | + } |
|
| 208 | + |
|
| 209 | + |
|
| 210 | + |
|
| 211 | + /** |
|
| 212 | + * initialize |
|
| 213 | + * |
|
| 214 | + * @throws EE_Error |
|
| 215 | + * @throws ReflectionException |
|
| 216 | + */ |
|
| 217 | + public function initialize() |
|
| 218 | + { |
|
| 219 | + $this->_class_abbreviations = apply_filters( |
|
| 220 | + 'FHEE__EE_Registry____construct___class_abbreviations', |
|
| 221 | + array( |
|
| 222 | + 'EE_Config' => 'CFG', |
|
| 223 | + 'EE_Session' => 'SSN', |
|
| 224 | + 'EE_Capabilities' => 'CAP', |
|
| 225 | + 'EE_Cart' => 'CART', |
|
| 226 | + 'EE_Network_Config' => 'NET_CFG', |
|
| 227 | + 'EE_Request_Handler' => 'REQ', |
|
| 228 | + 'EE_Message_Resource_Manager' => 'MRM', |
|
| 229 | + 'EventEspresso\core\services\commands\CommandBus' => 'BUS', |
|
| 230 | + 'EventEspresso\core\services\assets\Registry' => 'AssetsRegistry', |
|
| 231 | + ) |
|
| 232 | + ); |
|
| 233 | + $this->load_core('Base', array(), true); |
|
| 234 | + // add our request and response objects to the cache |
|
| 235 | + $request_loader = $this->_dependency_map->class_loader( |
|
| 236 | + 'EventEspresso\core\services\request\Request' |
|
| 237 | + ); |
|
| 238 | + $this->_set_cached_class( |
|
| 239 | + $request_loader(), |
|
| 240 | + 'EventEspresso\core\services\request\Request' |
|
| 241 | + ); |
|
| 242 | + $response_loader = $this->_dependency_map->class_loader( |
|
| 243 | + 'EventEspresso\core\services\request\Response' |
|
| 244 | + ); |
|
| 245 | + $this->_set_cached_class( |
|
| 246 | + $response_loader(), |
|
| 247 | + 'EventEspresso\core\services\request\Response' |
|
| 248 | + ); |
|
| 249 | + add_action('AHEE__EE_System__set_hooks_for_core', array($this, 'init')); |
|
| 250 | + } |
|
| 251 | + |
|
| 252 | + |
|
| 253 | + |
|
| 254 | + /** |
|
| 255 | + * @return void |
|
| 256 | + */ |
|
| 257 | + public function init() |
|
| 258 | + { |
|
| 259 | + // Get current page protocol |
|
| 260 | + $protocol = isset($_SERVER['HTTPS']) ? 'https://' : 'http://'; |
|
| 261 | + // Output admin-ajax.php URL with same protocol as current page |
|
| 262 | + self::$i18n_js_strings['ajax_url'] = admin_url('admin-ajax.php', $protocol); |
|
| 263 | + self::$i18n_js_strings['wp_debug'] = defined('WP_DEBUG') ? WP_DEBUG : false; |
|
| 264 | + } |
|
| 265 | + |
|
| 266 | + |
|
| 267 | + |
|
| 268 | + /** |
|
| 269 | + * localize_i18n_js_strings |
|
| 270 | + * |
|
| 271 | + * @return string |
|
| 272 | + */ |
|
| 273 | + public static function localize_i18n_js_strings() |
|
| 274 | + { |
|
| 275 | + $i18n_js_strings = (array)self::$i18n_js_strings; |
|
| 276 | + foreach ($i18n_js_strings as $key => $value) { |
|
| 277 | + if (is_scalar($value)) { |
|
| 278 | + $i18n_js_strings[$key] = html_entity_decode((string)$value, ENT_QUOTES, 'UTF-8'); |
|
| 279 | + } |
|
| 280 | + } |
|
| 281 | + return '/* <![CDATA[ */ var eei18n = ' . wp_json_encode($i18n_js_strings) . '; /* ]]> */'; |
|
| 282 | + } |
|
| 283 | + |
|
| 284 | + |
|
| 285 | + |
|
| 286 | + /** |
|
| 287 | + * @param mixed string | EED_Module $module |
|
| 288 | + * @throws EE_Error |
|
| 289 | + * @throws ReflectionException |
|
| 290 | + */ |
|
| 291 | + public function add_module($module) |
|
| 292 | + { |
|
| 293 | + if ($module instanceof EED_Module) { |
|
| 294 | + $module_class = get_class($module); |
|
| 295 | + $this->modules->{$module_class} = $module; |
|
| 296 | + } else { |
|
| 297 | + if ( ! class_exists('EE_Module_Request_Router', false)) { |
|
| 298 | + $this->load_core('Module_Request_Router'); |
|
| 299 | + } |
|
| 300 | + EE_Module_Request_Router::module_factory($module); |
|
| 301 | + } |
|
| 302 | + } |
|
| 303 | + |
|
| 304 | + |
|
| 305 | + |
|
| 306 | + /** |
|
| 307 | + * @param string $module_name |
|
| 308 | + * @return mixed EED_Module | NULL |
|
| 309 | + */ |
|
| 310 | + public function get_module($module_name = '') |
|
| 311 | + { |
|
| 312 | + return isset($this->modules->{$module_name}) |
|
| 313 | + ? $this->modules->{$module_name} |
|
| 314 | + : null; |
|
| 315 | + } |
|
| 316 | + |
|
| 317 | + |
|
| 318 | + |
|
| 319 | + /** |
|
| 320 | + * loads core classes - must be singletons |
|
| 321 | + * |
|
| 322 | + * @param string $class_name - simple class name ie: session |
|
| 323 | + * @param mixed $arguments |
|
| 324 | + * @param bool $load_only |
|
| 325 | + * @return mixed |
|
| 326 | + * @throws EE_Error |
|
| 327 | + * @throws ReflectionException |
|
| 328 | + */ |
|
| 329 | + public function load_core($class_name, $arguments = array(), $load_only = false) |
|
| 330 | + { |
|
| 331 | + $core_paths = apply_filters( |
|
| 332 | + 'FHEE__EE_Registry__load_core__core_paths', |
|
| 333 | + array( |
|
| 334 | + EE_CORE, |
|
| 335 | + EE_ADMIN, |
|
| 336 | + EE_CPTS, |
|
| 337 | + EE_CORE . 'data_migration_scripts' . DS, |
|
| 338 | + EE_CORE . 'capabilities' . DS, |
|
| 339 | + EE_CORE . 'request_stack' . DS, |
|
| 340 | + EE_CORE . 'middleware' . DS, |
|
| 341 | + ) |
|
| 342 | + ); |
|
| 343 | + // retrieve instantiated class |
|
| 344 | + return $this->_load( |
|
| 345 | + $core_paths, |
|
| 346 | + 'EE_', |
|
| 347 | + $class_name, |
|
| 348 | + 'core', |
|
| 349 | + $arguments, |
|
| 350 | + false, |
|
| 351 | + true, |
|
| 352 | + $load_only |
|
| 353 | + ); |
|
| 354 | + } |
|
| 355 | + |
|
| 356 | + |
|
| 357 | + |
|
| 358 | + /** |
|
| 359 | + * loads service classes |
|
| 360 | + * |
|
| 361 | + * @param string $class_name - simple class name ie: session |
|
| 362 | + * @param mixed $arguments |
|
| 363 | + * @param bool $load_only |
|
| 364 | + * @return mixed |
|
| 365 | + * @throws EE_Error |
|
| 366 | + * @throws ReflectionException |
|
| 367 | + */ |
|
| 368 | + public function load_service($class_name, $arguments = array(), $load_only = false) |
|
| 369 | + { |
|
| 370 | + $service_paths = apply_filters( |
|
| 371 | + 'FHEE__EE_Registry__load_service__service_paths', |
|
| 372 | + array( |
|
| 373 | + EE_CORE . 'services' . DS, |
|
| 374 | + ) |
|
| 375 | + ); |
|
| 376 | + // retrieve instantiated class |
|
| 377 | + return $this->_load( |
|
| 378 | + $service_paths, |
|
| 379 | + 'EE_', |
|
| 380 | + $class_name, |
|
| 381 | + 'class', |
|
| 382 | + $arguments, |
|
| 383 | + false, |
|
| 384 | + true, |
|
| 385 | + $load_only |
|
| 386 | + ); |
|
| 387 | + } |
|
| 388 | + |
|
| 389 | + |
|
| 390 | + |
|
| 391 | + /** |
|
| 392 | + * loads data_migration_scripts |
|
| 393 | + * |
|
| 394 | + * @param string $class_name - class name for the DMS ie: EE_DMS_Core_4_2_0 |
|
| 395 | + * @param mixed $arguments |
|
| 396 | + * @return EE_Data_Migration_Script_Base|mixed |
|
| 397 | + * @throws EE_Error |
|
| 398 | + * @throws ReflectionException |
|
| 399 | + */ |
|
| 400 | + public function load_dms($class_name, $arguments = array()) |
|
| 401 | + { |
|
| 402 | + // retrieve instantiated class |
|
| 403 | + return $this->_load( |
|
| 404 | + EE_Data_Migration_Manager::instance()->get_data_migration_script_folders(), |
|
| 405 | + 'EE_DMS_', |
|
| 406 | + $class_name, |
|
| 407 | + 'dms', |
|
| 408 | + $arguments, |
|
| 409 | + false, |
|
| 410 | + false |
|
| 411 | + ); |
|
| 412 | + } |
|
| 413 | + |
|
| 414 | + |
|
| 415 | + |
|
| 416 | + /** |
|
| 417 | + * loads object creating classes - must be singletons |
|
| 418 | + * |
|
| 419 | + * @param string $class_name - simple class name ie: attendee |
|
| 420 | + * @param mixed $arguments - an array of arguments to pass to the class |
|
| 421 | + * @param bool $from_db - some classes are instantiated from the db and thus call a different method to |
|
| 422 | + * instantiate |
|
| 423 | + * @param bool $cache if you don't want the class to be stored in the internal cache (non-persistent) then |
|
| 424 | + * set this to FALSE (ie. when instantiating model objects from client in a loop) |
|
| 425 | + * @param bool $load_only whether or not to just load the file and NOT instantiate, or load AND instantiate |
|
| 426 | + * (default) |
|
| 427 | + * @return EE_Base_Class | bool |
|
| 428 | + * @throws EE_Error |
|
| 429 | + * @throws ReflectionException |
|
| 430 | + */ |
|
| 431 | + public function load_class($class_name, $arguments = array(), $from_db = false, $cache = true, $load_only = false) |
|
| 432 | + { |
|
| 433 | + $paths = apply_filters( |
|
| 434 | + 'FHEE__EE_Registry__load_class__paths', array( |
|
| 435 | + EE_CORE, |
|
| 436 | + EE_CLASSES, |
|
| 437 | + EE_BUSINESS, |
|
| 438 | + ) |
|
| 439 | + ); |
|
| 440 | + // retrieve instantiated class |
|
| 441 | + return $this->_load( |
|
| 442 | + $paths, |
|
| 443 | + 'EE_', |
|
| 444 | + $class_name, |
|
| 445 | + 'class', |
|
| 446 | + $arguments, |
|
| 447 | + $from_db, |
|
| 448 | + $cache, |
|
| 449 | + $load_only |
|
| 450 | + ); |
|
| 451 | + } |
|
| 452 | + |
|
| 453 | + |
|
| 454 | + |
|
| 455 | + /** |
|
| 456 | + * loads helper classes - must be singletons |
|
| 457 | + * |
|
| 458 | + * @param string $class_name - simple class name ie: price |
|
| 459 | + * @param mixed $arguments |
|
| 460 | + * @param bool $load_only |
|
| 461 | + * @return EEH_Base | bool |
|
| 462 | + * @throws EE_Error |
|
| 463 | + * @throws ReflectionException |
|
| 464 | + */ |
|
| 465 | + public function load_helper($class_name, $arguments = array(), $load_only = true) |
|
| 466 | + { |
|
| 467 | + // todo: add doing_it_wrong() in a few versions after all addons have had calls to this method removed |
|
| 468 | + $helper_paths = apply_filters('FHEE__EE_Registry__load_helper__helper_paths', array(EE_HELPERS)); |
|
| 469 | + // retrieve instantiated class |
|
| 470 | + return $this->_load( |
|
| 471 | + $helper_paths, |
|
| 472 | + 'EEH_', |
|
| 473 | + $class_name, |
|
| 474 | + 'helper', |
|
| 475 | + $arguments, |
|
| 476 | + false, |
|
| 477 | + true, |
|
| 478 | + $load_only |
|
| 479 | + ); |
|
| 480 | + } |
|
| 481 | + |
|
| 482 | + |
|
| 483 | + |
|
| 484 | + /** |
|
| 485 | + * loads core classes - must be singletons |
|
| 486 | + * |
|
| 487 | + * @param string $class_name - simple class name ie: session |
|
| 488 | + * @param mixed $arguments |
|
| 489 | + * @param bool $load_only |
|
| 490 | + * @param bool $cache whether to cache the object or not. |
|
| 491 | + * @return mixed |
|
| 492 | + * @throws EE_Error |
|
| 493 | + * @throws ReflectionException |
|
| 494 | + */ |
|
| 495 | + public function load_lib($class_name, $arguments = array(), $load_only = false, $cache = true) |
|
| 496 | + { |
|
| 497 | + $paths = array( |
|
| 498 | + EE_LIBRARIES, |
|
| 499 | + EE_LIBRARIES . 'messages' . DS, |
|
| 500 | + EE_LIBRARIES . 'shortcodes' . DS, |
|
| 501 | + EE_LIBRARIES . 'qtips' . DS, |
|
| 502 | + EE_LIBRARIES . 'payment_methods' . DS, |
|
| 503 | + ); |
|
| 504 | + // retrieve instantiated class |
|
| 505 | + return $this->_load( |
|
| 506 | + $paths, |
|
| 507 | + 'EE_', |
|
| 508 | + $class_name, |
|
| 509 | + 'lib', |
|
| 510 | + $arguments, |
|
| 511 | + false, |
|
| 512 | + $cache, |
|
| 513 | + $load_only |
|
| 514 | + ); |
|
| 515 | + } |
|
| 516 | + |
|
| 517 | + |
|
| 518 | + |
|
| 519 | + /** |
|
| 520 | + * loads model classes - must be singletons |
|
| 521 | + * |
|
| 522 | + * @param string $class_name - simple class name ie: price |
|
| 523 | + * @param mixed $arguments |
|
| 524 | + * @param bool $load_only |
|
| 525 | + * @return EEM_Base | bool |
|
| 526 | + * @throws EE_Error |
|
| 527 | + * @throws ReflectionException |
|
| 528 | + */ |
|
| 529 | + public function load_model($class_name, $arguments = array(), $load_only = false) |
|
| 530 | + { |
|
| 531 | + $paths = apply_filters( |
|
| 532 | + 'FHEE__EE_Registry__load_model__paths', array( |
|
| 533 | + EE_MODELS, |
|
| 534 | + EE_CORE, |
|
| 535 | + ) |
|
| 536 | + ); |
|
| 537 | + // retrieve instantiated class |
|
| 538 | + return $this->_load( |
|
| 539 | + $paths, |
|
| 540 | + 'EEM_', |
|
| 541 | + $class_name, |
|
| 542 | + 'model', |
|
| 543 | + $arguments, |
|
| 544 | + false, |
|
| 545 | + true, |
|
| 546 | + $load_only |
|
| 547 | + ); |
|
| 548 | + } |
|
| 549 | + |
|
| 550 | + |
|
| 551 | + |
|
| 552 | + /** |
|
| 553 | + * loads model classes - must be singletons |
|
| 554 | + * |
|
| 555 | + * @param string $class_name - simple class name ie: price |
|
| 556 | + * @param mixed $arguments |
|
| 557 | + * @param bool $load_only |
|
| 558 | + * @return mixed | bool |
|
| 559 | + * @throws EE_Error |
|
| 560 | + * @throws ReflectionException |
|
| 561 | + */ |
|
| 562 | + public function load_model_class($class_name, $arguments = array(), $load_only = true) |
|
| 563 | + { |
|
| 564 | + $paths = array( |
|
| 565 | + EE_MODELS . 'fields' . DS, |
|
| 566 | + EE_MODELS . 'helpers' . DS, |
|
| 567 | + EE_MODELS . 'relations' . DS, |
|
| 568 | + EE_MODELS . 'strategies' . DS, |
|
| 569 | + ); |
|
| 570 | + // retrieve instantiated class |
|
| 571 | + return $this->_load( |
|
| 572 | + $paths, |
|
| 573 | + 'EE_', |
|
| 574 | + $class_name, |
|
| 575 | + '', |
|
| 576 | + $arguments, |
|
| 577 | + false, |
|
| 578 | + true, |
|
| 579 | + $load_only |
|
| 580 | + ); |
|
| 581 | + } |
|
| 582 | + |
|
| 583 | + |
|
| 584 | + |
|
| 585 | + /** |
|
| 586 | + * Determines if $model_name is the name of an actual EE model. |
|
| 587 | + * |
|
| 588 | + * @param string $model_name like Event, Attendee, Question_Group_Question, etc. |
|
| 589 | + * @return boolean |
|
| 590 | + */ |
|
| 591 | + public function is_model_name($model_name) |
|
| 592 | + { |
|
| 593 | + return isset($this->models[$model_name]); |
|
| 594 | + } |
|
| 595 | + |
|
| 596 | + |
|
| 597 | + |
|
| 598 | + /** |
|
| 599 | + * generic class loader |
|
| 600 | + * |
|
| 601 | + * @param string $path_to_file - directory path to file location, not including filename |
|
| 602 | + * @param string $file_name - file name ie: my_file.php, including extension |
|
| 603 | + * @param string $type - file type - core? class? helper? model? |
|
| 604 | + * @param mixed $arguments |
|
| 605 | + * @param bool $load_only |
|
| 606 | + * @return mixed |
|
| 607 | + * @throws EE_Error |
|
| 608 | + * @throws ReflectionException |
|
| 609 | + */ |
|
| 610 | + public function load_file($path_to_file, $file_name, $type = '', $arguments = array(), $load_only = true) |
|
| 611 | + { |
|
| 612 | + // retrieve instantiated class |
|
| 613 | + return $this->_load( |
|
| 614 | + $path_to_file, |
|
| 615 | + '', |
|
| 616 | + $file_name, |
|
| 617 | + $type, |
|
| 618 | + $arguments, |
|
| 619 | + false, |
|
| 620 | + true, |
|
| 621 | + $load_only |
|
| 622 | + ); |
|
| 623 | + } |
|
| 624 | + |
|
| 625 | + |
|
| 626 | + |
|
| 627 | + /** |
|
| 628 | + * @param string $path_to_file - directory path to file location, not including filename |
|
| 629 | + * @param string $class_name - full class name ie: My_Class |
|
| 630 | + * @param string $type - file type - core? class? helper? model? |
|
| 631 | + * @param mixed $arguments |
|
| 632 | + * @param bool $load_only |
|
| 633 | + * @return bool|EE_Addon|object |
|
| 634 | + * @throws EE_Error |
|
| 635 | + * @throws ReflectionException |
|
| 636 | + */ |
|
| 637 | + public function load_addon($path_to_file, $class_name, $type = 'class', $arguments = array(), $load_only = false) |
|
| 638 | + { |
|
| 639 | + // retrieve instantiated class |
|
| 640 | + return $this->_load( |
|
| 641 | + $path_to_file, |
|
| 642 | + 'addon', |
|
| 643 | + $class_name, |
|
| 644 | + $type, |
|
| 645 | + $arguments, |
|
| 646 | + false, |
|
| 647 | + true, |
|
| 648 | + $load_only |
|
| 649 | + ); |
|
| 650 | + } |
|
| 651 | + |
|
| 652 | + |
|
| 653 | + |
|
| 654 | + /** |
|
| 655 | + * instantiates, caches, and automatically resolves dependencies |
|
| 656 | + * for classes that use a Fully Qualified Class Name. |
|
| 657 | + * if the class is not capable of being loaded using PSR-4 autoloading, |
|
| 658 | + * then you need to use one of the existing load_*() methods |
|
| 659 | + * which can resolve the classname and filepath from the passed arguments |
|
| 660 | + * |
|
| 661 | + * @param bool|string $class_name Fully Qualified Class Name |
|
| 662 | + * @param array $arguments an argument, or array of arguments to pass to the class upon instantiation |
|
| 663 | + * @param bool $cache whether to cache the instantiated object for reuse |
|
| 664 | + * @param bool $from_db some classes are instantiated from the db |
|
| 665 | + * and thus call a different method to instantiate |
|
| 666 | + * @param bool $load_only if true, will only load the file, but will NOT instantiate an object |
|
| 667 | + * @param bool|string $addon if true, will cache the object in the EE_Registry->$addons array |
|
| 668 | + * @return bool|null|mixed null = failure to load or instantiate class object. |
|
| 669 | + * object = class loaded and instantiated successfully. |
|
| 670 | + * bool = fail or success when $load_only is true |
|
| 671 | + * @throws EE_Error |
|
| 672 | + * @throws ReflectionException |
|
| 673 | + */ |
|
| 674 | + public function create( |
|
| 675 | + $class_name = false, |
|
| 676 | + $arguments = array(), |
|
| 677 | + $cache = false, |
|
| 678 | + $from_db = false, |
|
| 679 | + $load_only = false, |
|
| 680 | + $addon = false |
|
| 681 | + ) { |
|
| 682 | + $class_name = ltrim($class_name, '\\'); |
|
| 683 | + $class_name = $this->_dependency_map->get_alias($class_name); |
|
| 684 | + $class_exists = $this->loadOrVerifyClassExists($class_name, $arguments); |
|
| 685 | + // if a non-FQCN was passed, then verifyClassExists() might return an object |
|
| 686 | + // or it could return null if the class just could not be found anywhere |
|
| 687 | + if ($class_exists instanceof $class_name || $class_exists === null){ |
|
| 688 | + // either way, return the results |
|
| 689 | + return $class_exists; |
|
| 690 | + } |
|
| 691 | + $class_name = $class_exists; |
|
| 692 | + // if we're only loading the class and it already exists, then let's just return true immediately |
|
| 693 | + if ($load_only) { |
|
| 694 | + return true; |
|
| 695 | + } |
|
| 696 | + $addon = $addon |
|
| 697 | + ? 'addon' |
|
| 698 | + : ''; |
|
| 699 | + // $this->_cache_on is toggled during the recursive loading that can occur with dependency injection |
|
| 700 | + // $cache is controlled by individual calls to separate Registry loader methods like load_class() |
|
| 701 | + // $load_only is also controlled by individual calls to separate Registry loader methods like load_file() |
|
| 702 | + if ($this->_cache_on && $cache && ! $load_only) { |
|
| 703 | + // return object if it's already cached |
|
| 704 | + $cached_class = $this->_get_cached_class($class_name, $addon); |
|
| 705 | + if ($cached_class !== null) { |
|
| 706 | + return $cached_class; |
|
| 707 | + } |
|
| 708 | + } |
|
| 709 | + // obtain the loader method from the dependency map |
|
| 710 | + $loader = $this->_dependency_map->class_loader($class_name); |
|
| 711 | + // instantiate the requested object |
|
| 712 | + if ($loader instanceof Closure) { |
|
| 713 | + $class_obj = $loader($arguments); |
|
| 714 | + } else if ($loader && method_exists($this, $loader)) { |
|
| 715 | + $class_obj = $this->{$loader}($class_name, $arguments); |
|
| 716 | + } else { |
|
| 717 | + $class_obj = $this->_create_object($class_name, $arguments, $addon, $from_db); |
|
| 718 | + } |
|
| 719 | + if (($this->_cache_on && $cache) || $this->get_class_abbreviation($class_name, '')) { |
|
| 720 | + // save it for later... kinda like gum { : $ |
|
| 721 | + $this->_set_cached_class($class_obj, $class_name, $addon, $from_db); |
|
| 722 | + } |
|
| 723 | + $this->_cache_on = true; |
|
| 724 | + return $class_obj; |
|
| 725 | + } |
|
| 726 | + |
|
| 727 | + |
|
| 728 | + |
|
| 729 | + /** |
|
| 730 | + * Recursively checks that a class exists and potentially attempts to load classes with non-FQCNs |
|
| 731 | + * |
|
| 732 | + * @param string $class_name |
|
| 733 | + * @param array $arguments |
|
| 734 | + * @param int $attempt |
|
| 735 | + * @return mixed |
|
| 736 | + */ |
|
| 737 | + private function loadOrVerifyClassExists($class_name, array $arguments, $attempt = 1) { |
|
| 738 | + if (is_object($class_name) || class_exists($class_name)) { |
|
| 739 | + return $class_name; |
|
| 740 | + } |
|
| 741 | + switch ($attempt) { |
|
| 742 | + case 1: |
|
| 743 | + // if it's a FQCN then maybe the class is registered with a preceding \ |
|
| 744 | + $class_name = strpos($class_name, '\\') !== false |
|
| 745 | + ? '\\' . ltrim($class_name, '\\') |
|
| 746 | + : $class_name; |
|
| 747 | + break; |
|
| 748 | + case 2: |
|
| 749 | + // |
|
| 750 | + $loader = $this->_dependency_map->class_loader($class_name); |
|
| 751 | + if ($loader && method_exists($this, $loader)) { |
|
| 752 | + return $this->{$loader}($class_name, $arguments); |
|
| 753 | + } |
|
| 754 | + break; |
|
| 755 | + case 3: |
|
| 756 | + default; |
|
| 757 | + return null; |
|
| 758 | + } |
|
| 759 | + $attempt++; |
|
| 760 | + return $this->loadOrVerifyClassExists($class_name, $arguments, $attempt); |
|
| 761 | + } |
|
| 762 | + |
|
| 763 | + |
|
| 764 | + |
|
| 765 | + /** |
|
| 766 | + * instantiates, caches, and injects dependencies for classes |
|
| 767 | + * |
|
| 768 | + * @param array $file_paths an array of paths to folders to look in |
|
| 769 | + * @param string $class_prefix EE or EEM or... ??? |
|
| 770 | + * @param bool|string $class_name $class name |
|
| 771 | + * @param string $type file type - core? class? helper? model? |
|
| 772 | + * @param mixed $arguments an argument or array of arguments to pass to the class upon instantiation |
|
| 773 | + * @param bool $from_db some classes are instantiated from the db |
|
| 774 | + * and thus call a different method to instantiate |
|
| 775 | + * @param bool $cache whether to cache the instantiated object for reuse |
|
| 776 | + * @param bool $load_only if true, will only load the file, but will NOT instantiate an object |
|
| 777 | + * @return bool|null|object null = failure to load or instantiate class object. |
|
| 778 | + * object = class loaded and instantiated successfully. |
|
| 779 | + * bool = fail or success when $load_only is true |
|
| 780 | + * @throws EE_Error |
|
| 781 | + * @throws ReflectionException |
|
| 782 | + */ |
|
| 783 | + protected function _load( |
|
| 784 | + $file_paths = array(), |
|
| 785 | + $class_prefix = 'EE_', |
|
| 786 | + $class_name = false, |
|
| 787 | + $type = 'class', |
|
| 788 | + $arguments = array(), |
|
| 789 | + $from_db = false, |
|
| 790 | + $cache = true, |
|
| 791 | + $load_only = false |
|
| 792 | + ) { |
|
| 793 | + $class_name = ltrim($class_name, '\\'); |
|
| 794 | + // strip php file extension |
|
| 795 | + $class_name = str_replace('.php', '', trim($class_name)); |
|
| 796 | + // does the class have a prefix ? |
|
| 797 | + if (! empty($class_prefix) && $class_prefix !== 'addon') { |
|
| 798 | + // make sure $class_prefix is uppercase |
|
| 799 | + $class_prefix = strtoupper(trim($class_prefix)); |
|
| 800 | + // add class prefix ONCE!!! |
|
| 801 | + $class_name = $class_prefix . str_replace($class_prefix, '', $class_name); |
|
| 802 | + } |
|
| 803 | + $class_name = $this->_dependency_map->get_alias($class_name); |
|
| 804 | + $class_exists = class_exists($class_name, false); |
|
| 805 | + // if we're only loading the class and it already exists, then let's just return true immediately |
|
| 806 | + if ($load_only && $class_exists) { |
|
| 807 | + return true; |
|
| 808 | + } |
|
| 809 | + // $this->_cache_on is toggled during the recursive loading that can occur with dependency injection |
|
| 810 | + // $cache is controlled by individual calls to separate Registry loader methods like load_class() |
|
| 811 | + // $load_only is also controlled by individual calls to separate Registry loader methods like load_file() |
|
| 812 | + if ($this->_cache_on && $cache && ! $load_only) { |
|
| 813 | + // return object if it's already cached |
|
| 814 | + $cached_class = $this->_get_cached_class($class_name, $class_prefix); |
|
| 815 | + if ($cached_class !== null) { |
|
| 816 | + return $cached_class; |
|
| 817 | + } |
|
| 818 | + } |
|
| 819 | + // if the class doesn't already exist.. then we need to try and find the file and load it |
|
| 820 | + if (! $class_exists) { |
|
| 821 | + // get full path to file |
|
| 822 | + $path = $this->_resolve_path($class_name, $type, $file_paths); |
|
| 823 | + // load the file |
|
| 824 | + $loaded = $this->_require_file($path, $class_name, $type, $file_paths); |
|
| 825 | + // if loading failed, or we are only loading a file but NOT instantiating an object |
|
| 826 | + if (! $loaded || $load_only) { |
|
| 827 | + // return boolean if only loading, or null if an object was expected |
|
| 828 | + return $load_only |
|
| 829 | + ? $loaded |
|
| 830 | + : null; |
|
| 831 | + } |
|
| 832 | + } |
|
| 833 | + // instantiate the requested object |
|
| 834 | + $class_obj = $this->_create_object($class_name, $arguments, $type, $from_db); |
|
| 835 | + if ($this->_cache_on && $cache) { |
|
| 836 | + // save it for later... kinda like gum { : $ |
|
| 837 | + $this->_set_cached_class($class_obj, $class_name, $class_prefix, $from_db); |
|
| 838 | + } |
|
| 839 | + $this->_cache_on = true; |
|
| 840 | + return $class_obj; |
|
| 841 | + } |
|
| 842 | + |
|
| 843 | + |
|
| 844 | + |
|
| 845 | + /** |
|
| 846 | + * @param string $class_name |
|
| 847 | + * @param string $default have to specify something, but not anything that will conflict |
|
| 848 | + * @return mixed|string |
|
| 849 | + */ |
|
| 850 | + protected function get_class_abbreviation($class_name, $default = 'FANCY_BATMAN_PANTS') |
|
| 851 | + { |
|
| 852 | + return isset($this->_class_abbreviations[$class_name]) |
|
| 853 | + ? $this->_class_abbreviations[$class_name] |
|
| 854 | + : $default; |
|
| 855 | + } |
|
| 856 | + |
|
| 857 | + /** |
|
| 858 | + * attempts to find a cached version of the requested class |
|
| 859 | + * by looking in the following places: |
|
| 860 | + * $this->{$class_abbreviation} ie: $this->CART |
|
| 861 | + * $this->{$class_name} ie: $this->Some_Class |
|
| 862 | + * $this->LIB->{$class_name} ie: $this->LIB->Some_Class |
|
| 863 | + * $this->addon->{$class_name} ie: $this->addon->Some_Addon_Class |
|
| 864 | + * |
|
| 865 | + * @param string $class_name |
|
| 866 | + * @param string $class_prefix |
|
| 867 | + * @return mixed |
|
| 868 | + * @throws OutOfBoundsException |
|
| 869 | + */ |
|
| 870 | + protected function _get_cached_class($class_name, $class_prefix = '') |
|
| 871 | + { |
|
| 872 | + if ($class_name === 'EE_Registry') { |
|
| 873 | + return $this; |
|
| 874 | + } |
|
| 875 | + $class_abbreviation = $this->get_class_abbreviation($class_name); |
|
| 876 | + $class_name = str_replace('\\', '_', $class_name); |
|
| 877 | + // check if class has already been loaded, and return it if it has been |
|
| 878 | + if (isset($this->{$class_abbreviation})) { |
|
| 879 | + return $this->{$class_abbreviation}; |
|
| 880 | + } |
|
| 881 | + if (isset ($this->{$class_name})) { |
|
| 882 | + return $this->{$class_name}; |
|
| 883 | + } |
|
| 884 | + if (isset ($this->LIB->{$class_name})) { |
|
| 885 | + return $this->LIB->{$class_name}; |
|
| 886 | + } |
|
| 887 | + if ($class_prefix === 'addon' && isset ($this->addons->{$class_name})) { |
|
| 888 | + return $this->addons->{$class_name}; |
|
| 889 | + } |
|
| 890 | + return null; |
|
| 891 | + } |
|
| 892 | + |
|
| 893 | + |
|
| 894 | + |
|
| 895 | + /** |
|
| 896 | + * removes a cached version of the requested class |
|
| 897 | + * |
|
| 898 | + * @param string $class_name |
|
| 899 | + * @param boolean $addon |
|
| 900 | + * @return boolean |
|
| 901 | + * @throws OutOfBoundsException |
|
| 902 | + */ |
|
| 903 | + public function clear_cached_class($class_name, $addon = false) |
|
| 904 | + { |
|
| 905 | + $class_abbreviation = $this->get_class_abbreviation($class_name); |
|
| 906 | + $class_name = str_replace('\\', '_', $class_name); |
|
| 907 | + // check if class has already been loaded, and return it if it has been |
|
| 908 | + if (isset($this->{$class_abbreviation})) { |
|
| 909 | + $this->{$class_abbreviation} = null; |
|
| 910 | + return true; |
|
| 911 | + } |
|
| 912 | + if (isset($this->{$class_name})) { |
|
| 913 | + $this->{$class_name} = null; |
|
| 914 | + return true; |
|
| 915 | + } |
|
| 916 | + if (isset($this->LIB->{$class_name})) { |
|
| 917 | + unset($this->LIB->{$class_name}); |
|
| 918 | + return true; |
|
| 919 | + } |
|
| 920 | + if ($addon && isset($this->addons->{$class_name})) { |
|
| 921 | + unset($this->addons->{$class_name}); |
|
| 922 | + return true; |
|
| 923 | + } |
|
| 924 | + return false; |
|
| 925 | + } |
|
| 926 | + |
|
| 927 | + |
|
| 928 | + |
|
| 929 | + /** |
|
| 930 | + * attempts to find a full valid filepath for the requested class. |
|
| 931 | + * loops thru each of the base paths in the $file_paths array and appends : "{classname} . {file type} . php" |
|
| 932 | + * then returns that path if the target file has been found and is readable |
|
| 933 | + * |
|
| 934 | + * @param string $class_name |
|
| 935 | + * @param string $type |
|
| 936 | + * @param array $file_paths |
|
| 937 | + * @return string | bool |
|
| 938 | + */ |
|
| 939 | + protected function _resolve_path($class_name, $type = '', $file_paths = array()) |
|
| 940 | + { |
|
| 941 | + // make sure $file_paths is an array |
|
| 942 | + $file_paths = is_array($file_paths) |
|
| 943 | + ? $file_paths |
|
| 944 | + : array($file_paths); |
|
| 945 | + // cycle thru paths |
|
| 946 | + foreach ($file_paths as $key => $file_path) { |
|
| 947 | + // convert all separators to proper DS, if no filepath, then use EE_CLASSES |
|
| 948 | + $file_path = $file_path |
|
| 949 | + ? str_replace(array('/', '\\'), DS, $file_path) |
|
| 950 | + : EE_CLASSES; |
|
| 951 | + // prep file type |
|
| 952 | + $type = ! empty($type) |
|
| 953 | + ? trim($type, '.') . '.' |
|
| 954 | + : ''; |
|
| 955 | + // build full file path |
|
| 956 | + $file_paths[$key] = rtrim($file_path, DS) . DS . $class_name . '.' . $type . 'php'; |
|
| 957 | + //does the file exist and can be read ? |
|
| 958 | + if (is_readable($file_paths[$key])) { |
|
| 959 | + return $file_paths[$key]; |
|
| 960 | + } |
|
| 961 | + } |
|
| 962 | + return false; |
|
| 963 | + } |
|
| 964 | + |
|
| 965 | + |
|
| 966 | + |
|
| 967 | + /** |
|
| 968 | + * basically just performs a require_once() |
|
| 969 | + * but with some error handling |
|
| 970 | + * |
|
| 971 | + * @param string $path |
|
| 972 | + * @param string $class_name |
|
| 973 | + * @param string $type |
|
| 974 | + * @param array $file_paths |
|
| 975 | + * @return bool |
|
| 976 | + * @throws EE_Error |
|
| 977 | + * @throws ReflectionException |
|
| 978 | + */ |
|
| 979 | + protected function _require_file($path, $class_name, $type = '', $file_paths = array()) |
|
| 980 | + { |
|
| 981 | + $this->resolve_legacy_class_parent($class_name); |
|
| 982 | + // don't give up! you gotta... |
|
| 983 | + try { |
|
| 984 | + //does the file exist and can it be read ? |
|
| 985 | + if (! $path) { |
|
| 986 | + // just in case the file has already been autoloaded, |
|
| 987 | + // but discrepancies in the naming schema are preventing it from |
|
| 988 | + // being loaded via one of the EE_Registry::load_*() methods, |
|
| 989 | + // then let's try one last hail mary before throwing an exception |
|
| 990 | + // and call class_exists() again, but with autoloading turned ON |
|
| 991 | + if(class_exists($class_name)) { |
|
| 992 | + return true; |
|
| 993 | + } |
|
| 994 | + // so sorry, can't find the file |
|
| 995 | + throw new EE_Error ( |
|
| 996 | + sprintf( |
|
| 997 | + esc_html__( |
|
| 998 | + 'The %1$s file %2$s could not be located or is not readable due to file permissions. Please ensure that the following filepath(s) are correct: %3$s', |
|
| 999 | + 'event_espresso' |
|
| 1000 | + ), |
|
| 1001 | + trim($type, '.'), |
|
| 1002 | + $class_name, |
|
| 1003 | + '<br />' . implode(',<br />', $file_paths) |
|
| 1004 | + ) |
|
| 1005 | + ); |
|
| 1006 | + } |
|
| 1007 | + // get the file |
|
| 1008 | + require_once($path); |
|
| 1009 | + // if the class isn't already declared somewhere |
|
| 1010 | + if (class_exists($class_name, false) === false) { |
|
| 1011 | + // so sorry, not a class |
|
| 1012 | + throw new EE_Error( |
|
| 1013 | + sprintf( |
|
| 1014 | + esc_html__('The %s file %s does not appear to contain the %s Class.', 'event_espresso'), |
|
| 1015 | + $type, |
|
| 1016 | + $path, |
|
| 1017 | + $class_name |
|
| 1018 | + ) |
|
| 1019 | + ); |
|
| 1020 | + } |
|
| 1021 | + } catch (EE_Error $e) { |
|
| 1022 | + $e->get_error(); |
|
| 1023 | + return false; |
|
| 1024 | + } |
|
| 1025 | + return true; |
|
| 1026 | + } |
|
| 1027 | + |
|
| 1028 | + |
|
| 1029 | + |
|
| 1030 | + /** |
|
| 1031 | + * Some of our legacy classes that extended a parent class would simply use a require() statement |
|
| 1032 | + * before their class declaration in order to ensure that the parent class was loaded. |
|
| 1033 | + * This is not ideal, but it's nearly impossible to determine the parent class of a non-namespaced class, |
|
| 1034 | + * without triggering a fatal error because the parent class has yet to be loaded and therefore doesn't exist. |
|
| 1035 | + * |
|
| 1036 | + * @param string $class_name |
|
| 1037 | + */ |
|
| 1038 | + protected function resolve_legacy_class_parent($class_name = '') |
|
| 1039 | + { |
|
| 1040 | + try { |
|
| 1041 | + $legacy_parent_class_map = array( |
|
| 1042 | + 'EE_Payment_Processor' => 'core/business/EE_Processor_Base.class.php' |
|
| 1043 | + ); |
|
| 1044 | + if(isset($legacy_parent_class_map[$class_name])) { |
|
| 1045 | + require_once EE_PLUGIN_DIR_PATH . $legacy_parent_class_map[$class_name]; |
|
| 1046 | + } |
|
| 1047 | + } catch (Exception $exception) { |
|
| 1048 | + } |
|
| 1049 | + } |
|
| 1050 | + |
|
| 1051 | + |
|
| 1052 | + |
|
| 1053 | + /** |
|
| 1054 | + * _create_object |
|
| 1055 | + * Attempts to instantiate the requested class via any of the |
|
| 1056 | + * commonly used instantiation methods employed throughout EE. |
|
| 1057 | + * The priority for instantiation is as follows: |
|
| 1058 | + * - abstract classes or any class flagged as "load only" (no instantiation occurs) |
|
| 1059 | + * - model objects via their 'new_instance_from_db' method |
|
| 1060 | + * - model objects via their 'new_instance' method |
|
| 1061 | + * - "singleton" classes" via their 'instance' method |
|
| 1062 | + * - standard instantiable classes via their __constructor |
|
| 1063 | + * Prior to instantiation, if the classname exists in the dependency_map, |
|
| 1064 | + * then the constructor for the requested class will be examined to determine |
|
| 1065 | + * if any dependencies exist, and if they can be injected. |
|
| 1066 | + * If so, then those classes will be added to the array of arguments passed to the constructor |
|
| 1067 | + * |
|
| 1068 | + * @param string $class_name |
|
| 1069 | + * @param array $arguments |
|
| 1070 | + * @param string $type |
|
| 1071 | + * @param bool $from_db |
|
| 1072 | + * @return null|object |
|
| 1073 | + * @throws EE_Error |
|
| 1074 | + * @throws ReflectionException |
|
| 1075 | + */ |
|
| 1076 | + protected function _create_object($class_name, $arguments = array(), $type = '', $from_db = false) |
|
| 1077 | + { |
|
| 1078 | + // create reflection |
|
| 1079 | + $reflector = $this->get_ReflectionClass($class_name); |
|
| 1080 | + // make sure arguments are an array |
|
| 1081 | + $arguments = is_array($arguments) |
|
| 1082 | + ? $arguments |
|
| 1083 | + : array($arguments); |
|
| 1084 | + // and if arguments array is numerically and sequentially indexed, then we want it to remain as is, |
|
| 1085 | + // else wrap it in an additional array so that it doesn't get split into multiple parameters |
|
| 1086 | + $arguments = $this->_array_is_numerically_and_sequentially_indexed($arguments) |
|
| 1087 | + ? $arguments |
|
| 1088 | + : array($arguments); |
|
| 1089 | + // attempt to inject dependencies ? |
|
| 1090 | + if ($this->_dependency_map->has($class_name)) { |
|
| 1091 | + $arguments = $this->_resolve_dependencies($reflector, $class_name, $arguments); |
|
| 1092 | + } |
|
| 1093 | + // instantiate the class if possible |
|
| 1094 | + if ($reflector->isAbstract()) { |
|
| 1095 | + // nothing to instantiate, loading file was enough |
|
| 1096 | + // does not throw an exception so $instantiation_mode is unused |
|
| 1097 | + // $instantiation_mode = "1) no constructor abstract class"; |
|
| 1098 | + return true; |
|
| 1099 | + } |
|
| 1100 | + if (empty($arguments) && $reflector->getConstructor() === null && $reflector->isInstantiable()) { |
|
| 1101 | + // no constructor = static methods only... nothing to instantiate, loading file was enough |
|
| 1102 | + // $instantiation_mode = "2) no constructor but instantiable"; |
|
| 1103 | + return $reflector->newInstance(); |
|
| 1104 | + } |
|
| 1105 | + if ($from_db && method_exists($class_name, 'new_instance_from_db')) { |
|
| 1106 | + // $instantiation_mode = "3) new_instance_from_db()"; |
|
| 1107 | + return call_user_func_array(array($class_name, 'new_instance_from_db'), $arguments); |
|
| 1108 | + } |
|
| 1109 | + if (method_exists($class_name, 'new_instance')) { |
|
| 1110 | + // $instantiation_mode = "4) new_instance()"; |
|
| 1111 | + return call_user_func_array(array($class_name, 'new_instance'), $arguments); |
|
| 1112 | + } |
|
| 1113 | + if (method_exists($class_name, 'instance')) { |
|
| 1114 | + // $instantiation_mode = "5) instance()"; |
|
| 1115 | + return call_user_func_array(array($class_name, 'instance'), $arguments); |
|
| 1116 | + } |
|
| 1117 | + if ($reflector->isInstantiable()) { |
|
| 1118 | + // $instantiation_mode = "6) constructor"; |
|
| 1119 | + return $reflector->newInstanceArgs($arguments); |
|
| 1120 | + } |
|
| 1121 | + // heh ? something's not right ! |
|
| 1122 | + throw new EE_Error( |
|
| 1123 | + sprintf( |
|
| 1124 | + __('The %s file %s could not be instantiated.', 'event_espresso'), |
|
| 1125 | + $type, |
|
| 1126 | + $class_name |
|
| 1127 | + ) |
|
| 1128 | + ); |
|
| 1129 | + } |
|
| 1130 | + |
|
| 1131 | + |
|
| 1132 | + |
|
| 1133 | + /** |
|
| 1134 | + * @see http://stackoverflow.com/questions/173400/how-to-check-if-php-array-is-associative-or-sequential |
|
| 1135 | + * @param array $array |
|
| 1136 | + * @return bool |
|
| 1137 | + */ |
|
| 1138 | + protected function _array_is_numerically_and_sequentially_indexed(array $array) |
|
| 1139 | + { |
|
| 1140 | + return ! empty($array) |
|
| 1141 | + ? array_keys($array) === range(0, count($array) - 1) |
|
| 1142 | + : true; |
|
| 1143 | + } |
|
| 1144 | + |
|
| 1145 | + |
|
| 1146 | + |
|
| 1147 | + /** |
|
| 1148 | + * getReflectionClass |
|
| 1149 | + * checks if a ReflectionClass object has already been generated for a class |
|
| 1150 | + * and returns that instead of creating a new one |
|
| 1151 | + * |
|
| 1152 | + * @param string $class_name |
|
| 1153 | + * @return ReflectionClass |
|
| 1154 | + * @throws ReflectionException |
|
| 1155 | + */ |
|
| 1156 | + public function get_ReflectionClass($class_name) |
|
| 1157 | + { |
|
| 1158 | + if ( |
|
| 1159 | + ! isset($this->_reflectors[$class_name]) |
|
| 1160 | + || ! $this->_reflectors[$class_name] instanceof ReflectionClass |
|
| 1161 | + ) { |
|
| 1162 | + $this->_reflectors[$class_name] = new ReflectionClass($class_name); |
|
| 1163 | + } |
|
| 1164 | + return $this->_reflectors[$class_name]; |
|
| 1165 | + } |
|
| 1166 | + |
|
| 1167 | + |
|
| 1168 | + |
|
| 1169 | + /** |
|
| 1170 | + * _resolve_dependencies |
|
| 1171 | + * examines the constructor for the requested class to determine |
|
| 1172 | + * if any dependencies exist, and if they can be injected. |
|
| 1173 | + * If so, then those classes will be added to the array of arguments passed to the constructor |
|
| 1174 | + * PLZ NOTE: this is achieved by type hinting the constructor params |
|
| 1175 | + * For example: |
|
| 1176 | + * if attempting to load a class "Foo" with the following constructor: |
|
| 1177 | + * __construct( Bar $bar_class, Fighter $grohl_class ) |
|
| 1178 | + * then $bar_class and $grohl_class will be added to the $arguments array, |
|
| 1179 | + * but only IF they are NOT already present in the incoming arguments array, |
|
| 1180 | + * and the correct classes can be loaded |
|
| 1181 | + * |
|
| 1182 | + * @param ReflectionClass $reflector |
|
| 1183 | + * @param string $class_name |
|
| 1184 | + * @param array $arguments |
|
| 1185 | + * @return array |
|
| 1186 | + * @throws EE_Error |
|
| 1187 | + * @throws ReflectionException |
|
| 1188 | + */ |
|
| 1189 | + protected function _resolve_dependencies(ReflectionClass $reflector, $class_name, $arguments = array()) |
|
| 1190 | + { |
|
| 1191 | + // let's examine the constructor |
|
| 1192 | + $constructor = $reflector->getConstructor(); |
|
| 1193 | + // whu? huh? nothing? |
|
| 1194 | + if (! $constructor) { |
|
| 1195 | + return $arguments; |
|
| 1196 | + } |
|
| 1197 | + // get constructor parameters |
|
| 1198 | + $params = $constructor->getParameters(); |
|
| 1199 | + // and the keys for the incoming arguments array so that we can compare existing arguments with what is expected |
|
| 1200 | + $argument_keys = array_keys($arguments); |
|
| 1201 | + // now loop thru all of the constructors expected parameters |
|
| 1202 | + foreach ($params as $index => $param) { |
|
| 1203 | + // is this a dependency for a specific class ? |
|
| 1204 | + $param_class = $param->getClass() |
|
| 1205 | + ? $param->getClass()->name |
|
| 1206 | + : null; |
|
| 1207 | + // BUT WAIT !!! This class may be an alias for something else (or getting replaced at runtime) |
|
| 1208 | + $param_class = $this->_dependency_map->has_alias($param_class, $class_name) |
|
| 1209 | + ? $this->_dependency_map->get_alias($param_class, $class_name) |
|
| 1210 | + : $param_class; |
|
| 1211 | + if ( |
|
| 1212 | + // param is not even a class |
|
| 1213 | + $param_class === null |
|
| 1214 | + // and something already exists in the incoming arguments for this param |
|
| 1215 | + && array_key_exists($index, $argument_keys) |
|
| 1216 | + && array_key_exists($argument_keys[$index], $arguments) |
|
| 1217 | + ) { |
|
| 1218 | + // so let's skip this argument and move on to the next |
|
| 1219 | + continue; |
|
| 1220 | + } |
|
| 1221 | + if ( |
|
| 1222 | + // parameter is type hinted as a class, exists as an incoming argument, AND it's the correct class |
|
| 1223 | + $param_class !== null |
|
| 1224 | + && isset($argument_keys[$index], $arguments[$argument_keys[$index]]) |
|
| 1225 | + && $arguments[$argument_keys[$index]] instanceof $param_class |
|
| 1226 | + ) { |
|
| 1227 | + // skip this argument and move on to the next |
|
| 1228 | + continue; |
|
| 1229 | + } |
|
| 1230 | + if ( |
|
| 1231 | + // parameter is type hinted as a class, and should be injected |
|
| 1232 | + $param_class !== null |
|
| 1233 | + && $this->_dependency_map->has_dependency_for_class($class_name, $param_class) |
|
| 1234 | + ) { |
|
| 1235 | + $arguments = $this->_resolve_dependency( |
|
| 1236 | + $class_name, |
|
| 1237 | + $param_class, |
|
| 1238 | + $arguments, |
|
| 1239 | + $index, |
|
| 1240 | + $argument_keys |
|
| 1241 | + ); |
|
| 1242 | + } else { |
|
| 1243 | + try { |
|
| 1244 | + $arguments[$index] = $param->isDefaultValueAvailable() |
|
| 1245 | + ? $param->getDefaultValue() |
|
| 1246 | + : null; |
|
| 1247 | + } catch (ReflectionException $e) { |
|
| 1248 | + throw new ReflectionException( |
|
| 1249 | + sprintf( |
|
| 1250 | + esc_html__('%1$s for parameter "$%2$s on classname "%3$s"', 'event_espresso'), |
|
| 1251 | + $e->getMessage(), |
|
| 1252 | + $param->getName(), |
|
| 1253 | + $class_name |
|
| 1254 | + ) |
|
| 1255 | + ); |
|
| 1256 | + } |
|
| 1257 | + } |
|
| 1258 | + } |
|
| 1259 | + return $arguments; |
|
| 1260 | + } |
|
| 1261 | + |
|
| 1262 | + |
|
| 1263 | + |
|
| 1264 | + /** |
|
| 1265 | + * @param string $class_name |
|
| 1266 | + * @param string $param_class |
|
| 1267 | + * @param array $arguments |
|
| 1268 | + * @param mixed $index |
|
| 1269 | + * @param array $argument_keys |
|
| 1270 | + * @return array |
|
| 1271 | + * @throws EE_Error |
|
| 1272 | + * @throws ReflectionException |
|
| 1273 | + * @throws InvalidArgumentException |
|
| 1274 | + * @throws InvalidInterfaceException |
|
| 1275 | + * @throws InvalidDataTypeException |
|
| 1276 | + */ |
|
| 1277 | + protected function _resolve_dependency($class_name, $param_class, $arguments, $index, array $argument_keys) |
|
| 1278 | + { |
|
| 1279 | + $dependency = null; |
|
| 1280 | + // should dependency be loaded from cache ? |
|
| 1281 | + $cache_on = $this->_dependency_map->loading_strategy_for_class_dependency( |
|
| 1282 | + $class_name, |
|
| 1283 | + $param_class |
|
| 1284 | + ); |
|
| 1285 | + $cache_on = $cache_on !== EE_Dependency_Map::load_new_object; |
|
| 1286 | + // we might have a dependency... |
|
| 1287 | + // let's MAYBE try and find it in our cache if that's what's been requested |
|
| 1288 | + $cached_class = $cache_on |
|
| 1289 | + ? $this->_get_cached_class($param_class) |
|
| 1290 | + : null; |
|
| 1291 | + // and grab it if it exists |
|
| 1292 | + if ($cached_class instanceof $param_class) { |
|
| 1293 | + $dependency = $cached_class; |
|
| 1294 | + } else if ($param_class !== $class_name) { |
|
| 1295 | + // obtain the loader method from the dependency map |
|
| 1296 | + $loader = $this->_dependency_map->class_loader($param_class); |
|
| 1297 | + // is loader a custom closure ? |
|
| 1298 | + if ($loader instanceof Closure) { |
|
| 1299 | + $dependency = $loader($arguments); |
|
| 1300 | + } else { |
|
| 1301 | + // set the cache on property for the recursive loading call |
|
| 1302 | + $this->_cache_on = $cache_on; |
|
| 1303 | + // if not, then let's try and load it via the registry |
|
| 1304 | + if ($loader && method_exists($this, $loader)) { |
|
| 1305 | + $dependency = $this->{$loader}($param_class); |
|
| 1306 | + } else { |
|
| 1307 | + $dependency = LoaderFactory::getLoader()->load( |
|
| 1308 | + $param_class, |
|
| 1309 | + array(), |
|
| 1310 | + $cache_on |
|
| 1311 | + ); |
|
| 1312 | + } |
|
| 1313 | + } |
|
| 1314 | + } |
|
| 1315 | + // did we successfully find the correct dependency ? |
|
| 1316 | + if ($dependency instanceof $param_class) { |
|
| 1317 | + // then let's inject it into the incoming array of arguments at the correct location |
|
| 1318 | + $arguments[$index] = $dependency; |
|
| 1319 | + } |
|
| 1320 | + return $arguments; |
|
| 1321 | + } |
|
| 1322 | + |
|
| 1323 | + |
|
| 1324 | + |
|
| 1325 | + /** |
|
| 1326 | + * _set_cached_class |
|
| 1327 | + * attempts to cache the instantiated class locally |
|
| 1328 | + * in one of the following places, in the following order: |
|
| 1329 | + * $this->{class_abbreviation} ie: $this->CART |
|
| 1330 | + * $this->{$class_name} ie: $this->Some_Class |
|
| 1331 | + * $this->addon->{$$class_name} ie: $this->addon->Some_Addon_Class |
|
| 1332 | + * $this->LIB->{$class_name} ie: $this->LIB->Some_Class |
|
| 1333 | + * |
|
| 1334 | + * @param object $class_obj |
|
| 1335 | + * @param string $class_name |
|
| 1336 | + * @param string $class_prefix |
|
| 1337 | + * @param bool $from_db |
|
| 1338 | + * @return void |
|
| 1339 | + * @throws OutOfBoundsException |
|
| 1340 | + */ |
|
| 1341 | + protected function _set_cached_class($class_obj, $class_name, $class_prefix = '', $from_db = false) |
|
| 1342 | + { |
|
| 1343 | + if ($class_name === 'EE_Registry' || empty($class_obj)) { |
|
| 1344 | + return; |
|
| 1345 | + } |
|
| 1346 | + // return newly instantiated class |
|
| 1347 | + $class_abbreviation = $this->get_class_abbreviation($class_name, ''); |
|
| 1348 | + if ($class_abbreviation) { |
|
| 1349 | + $this->{$class_abbreviation} = $class_obj; |
|
| 1350 | + return; |
|
| 1351 | + } |
|
| 1352 | + $class_name = str_replace('\\', '_', $class_name); |
|
| 1353 | + if (property_exists($this, $class_name)) { |
|
| 1354 | + $this->{$class_name} = $class_obj; |
|
| 1355 | + return; |
|
| 1356 | + } |
|
| 1357 | + if ($class_prefix === 'addon') { |
|
| 1358 | + $this->addons->{$class_name} = $class_obj; |
|
| 1359 | + return; |
|
| 1360 | + } |
|
| 1361 | + if (! $from_db) { |
|
| 1362 | + $this->LIB->{$class_name} = $class_obj; |
|
| 1363 | + } |
|
| 1364 | + } |
|
| 1365 | + |
|
| 1366 | + |
|
| 1367 | + |
|
| 1368 | + /** |
|
| 1369 | + * call any loader that's been registered in the EE_Dependency_Map::$_class_loaders array |
|
| 1370 | + * |
|
| 1371 | + * @param string $classname PLEASE NOTE: the class name needs to match what's registered |
|
| 1372 | + * in the EE_Dependency_Map::$_class_loaders array, |
|
| 1373 | + * including the class prefix, ie: "EE_", "EEM_", "EEH_", etc |
|
| 1374 | + * @param array $arguments |
|
| 1375 | + * @return object |
|
| 1376 | + */ |
|
| 1377 | + public static function factory($classname, $arguments = array()) |
|
| 1378 | + { |
|
| 1379 | + $loader = self::instance()->_dependency_map->class_loader($classname); |
|
| 1380 | + if ($loader instanceof Closure) { |
|
| 1381 | + return $loader($arguments); |
|
| 1382 | + } |
|
| 1383 | + if (method_exists(self::instance(), $loader)) { |
|
| 1384 | + return self::instance()->{$loader}($classname, $arguments); |
|
| 1385 | + } |
|
| 1386 | + return null; |
|
| 1387 | + } |
|
| 1388 | + |
|
| 1389 | + |
|
| 1390 | + |
|
| 1391 | + /** |
|
| 1392 | + * Gets the addon by its class name |
|
| 1393 | + * |
|
| 1394 | + * @param string $class_name |
|
| 1395 | + * @return EE_Addon |
|
| 1396 | + * @throws OutOfBoundsException |
|
| 1397 | + */ |
|
| 1398 | + public function getAddon($class_name) |
|
| 1399 | + { |
|
| 1400 | + $class_name = str_replace('\\', '_', $class_name); |
|
| 1401 | + return $this->addons->{$class_name}; |
|
| 1402 | + } |
|
| 1403 | + |
|
| 1404 | + |
|
| 1405 | + /** |
|
| 1406 | + * removes the addon from the internal cache |
|
| 1407 | + * |
|
| 1408 | + * @param string $class_name |
|
| 1409 | + * @return void |
|
| 1410 | + */ |
|
| 1411 | + public function removeAddon($class_name) |
|
| 1412 | + { |
|
| 1413 | + $class_name = str_replace('\\', '_', $class_name); |
|
| 1414 | + unset($this->addons->{$class_name}); |
|
| 1415 | + } |
|
| 1416 | + |
|
| 1417 | + |
|
| 1418 | + |
|
| 1419 | + /** |
|
| 1420 | + * Gets the addon by its name/slug (not classname. For that, just |
|
| 1421 | + * use the get_addon() method above |
|
| 1422 | + * |
|
| 1423 | + * @param string $name |
|
| 1424 | + * @return EE_Addon |
|
| 1425 | + */ |
|
| 1426 | + public function get_addon_by_name($name) |
|
| 1427 | + { |
|
| 1428 | + foreach ($this->addons as $addon) { |
|
| 1429 | + if ($addon->name() === $name) { |
|
| 1430 | + return $addon; |
|
| 1431 | + } |
|
| 1432 | + } |
|
| 1433 | + return null; |
|
| 1434 | + } |
|
| 1435 | + |
|
| 1436 | + |
|
| 1437 | + |
|
| 1438 | + /** |
|
| 1439 | + * Gets an array of all the registered addons, where the keys are their names. |
|
| 1440 | + * (ie, what each returns for their name() function) |
|
| 1441 | + * They're already available on EE_Registry::instance()->addons as properties, |
|
| 1442 | + * where each property's name is the addon's classname, |
|
| 1443 | + * So if you just want to get the addon by classname, |
|
| 1444 | + * OR use the get_addon() method above. |
|
| 1445 | + * PLEASE NOTE: |
|
| 1446 | + * addons with Fully Qualified Class Names |
|
| 1447 | + * have had the namespace separators converted to underscores, |
|
| 1448 | + * so a classname like Fully\Qualified\ClassName |
|
| 1449 | + * would have been converted to Fully_Qualified_ClassName |
|
| 1450 | + * |
|
| 1451 | + * @return EE_Addon[] where the KEYS are the addon's name() |
|
| 1452 | + */ |
|
| 1453 | + public function get_addons_by_name() |
|
| 1454 | + { |
|
| 1455 | + $addons = array(); |
|
| 1456 | + foreach ($this->addons as $addon) { |
|
| 1457 | + $addons[$addon->name()] = $addon; |
|
| 1458 | + } |
|
| 1459 | + return $addons; |
|
| 1460 | + } |
|
| 1461 | + |
|
| 1462 | + |
|
| 1463 | + /** |
|
| 1464 | + * Resets the specified model's instance AND makes sure EE_Registry doesn't keep |
|
| 1465 | + * a stale copy of it around |
|
| 1466 | + * |
|
| 1467 | + * @param string $model_name |
|
| 1468 | + * @return \EEM_Base |
|
| 1469 | + * @throws \EE_Error |
|
| 1470 | + */ |
|
| 1471 | + public function reset_model($model_name) |
|
| 1472 | + { |
|
| 1473 | + $model_class_name = strpos($model_name, 'EEM_') !== 0 |
|
| 1474 | + ? "EEM_{$model_name}" |
|
| 1475 | + : $model_name; |
|
| 1476 | + if (! isset($this->LIB->{$model_class_name}) || ! $this->LIB->{$model_class_name} instanceof EEM_Base) { |
|
| 1477 | + return null; |
|
| 1478 | + } |
|
| 1479 | + //get that model reset it and make sure we nuke the old reference to it |
|
| 1480 | + if ($this->LIB->{$model_class_name} instanceof $model_class_name |
|
| 1481 | + && is_callable( |
|
| 1482 | + array($model_class_name, 'reset') |
|
| 1483 | + )) { |
|
| 1484 | + $this->LIB->{$model_class_name} = $this->LIB->{$model_class_name}->reset(); |
|
| 1485 | + } else { |
|
| 1486 | + throw new EE_Error(sprintf(esc_html__('Model %s does not have a method "reset"', 'event_espresso'), $model_name)); |
|
| 1487 | + } |
|
| 1488 | + return $this->LIB->{$model_class_name}; |
|
| 1489 | + } |
|
| 1490 | + |
|
| 1491 | + |
|
| 1492 | + |
|
| 1493 | + /** |
|
| 1494 | + * Resets the registry. |
|
| 1495 | + * The criteria for what gets reset is based on what can be shared between sites on the same request when |
|
| 1496 | + * switch_to_blog is used in a multisite install. Here is a list of things that are NOT reset. |
|
| 1497 | + * - $_dependency_map |
|
| 1498 | + * - $_class_abbreviations |
|
| 1499 | + * - $NET_CFG (EE_Network_Config): The config is shared network wide so no need to reset. |
|
| 1500 | + * - $REQ: Still on the same request so no need to change. |
|
| 1501 | + * - $CAP: There is no site specific state in the EE_Capability class. |
|
| 1502 | + * - $SSN: Although ideally, the session should not be shared between site switches, we can't reset it because only |
|
| 1503 | + * one Session can be active in a single request. Resetting could resolve in "headers already sent" errors. |
|
| 1504 | + * - $addons: In multisite, the state of the addons is something controlled via hooks etc in a normal request. So |
|
| 1505 | + * for now, we won't reset the addons because it could break calls to an add-ons class/methods in the |
|
| 1506 | + * switch or on the restore. |
|
| 1507 | + * - $modules |
|
| 1508 | + * - $shortcodes |
|
| 1509 | + * - $widgets |
|
| 1510 | + * |
|
| 1511 | + * @param boolean $hard [deprecated] |
|
| 1512 | + * @param boolean $reinstantiate whether to create new instances of EE_Registry's singletons too, |
|
| 1513 | + * or just reset without re-instantiating (handy to set to FALSE if you're not |
|
| 1514 | + * sure if you CAN currently reinstantiate the singletons at the moment) |
|
| 1515 | + * @param bool $reset_models Defaults to true. When false, then the models are not reset. This is so |
|
| 1516 | + * client |
|
| 1517 | + * code instead can just change the model context to a different blog id if |
|
| 1518 | + * necessary |
|
| 1519 | + * @return EE_Registry |
|
| 1520 | + * @throws EE_Error |
|
| 1521 | + * @throws ReflectionException |
|
| 1522 | + */ |
|
| 1523 | + public static function reset($hard = false, $reinstantiate = true, $reset_models = true) |
|
| 1524 | + { |
|
| 1525 | + $instance = self::instance(); |
|
| 1526 | + $instance->_cache_on = true; |
|
| 1527 | + // reset some "special" classes |
|
| 1528 | + EEH_Activation::reset(); |
|
| 1529 | + $hard = apply_filters( 'FHEE__EE_Registry__reset__hard', $hard); |
|
| 1530 | + $instance->CFG = EE_Config::reset($hard, $reinstantiate); |
|
| 1531 | + $instance->CART = null; |
|
| 1532 | + $instance->MRM = null; |
|
| 1533 | + $instance->AssetsRegistry = $instance->create('EventEspresso\core\services\assets\Registry'); |
|
| 1534 | + //messages reset |
|
| 1535 | + EED_Messages::reset(); |
|
| 1536 | + //handle of objects cached on LIB |
|
| 1537 | + foreach (array('LIB', 'modules') as $cache) { |
|
| 1538 | + foreach ($instance->{$cache} as $class_name => $class) { |
|
| 1539 | + if (self::_reset_and_unset_object($class, $reset_models)) { |
|
| 1540 | + unset($instance->{$cache}->{$class_name}); |
|
| 1541 | + } |
|
| 1542 | + } |
|
| 1543 | + } |
|
| 1544 | + return $instance; |
|
| 1545 | + } |
|
| 1546 | + |
|
| 1547 | + |
|
| 1548 | + |
|
| 1549 | + /** |
|
| 1550 | + * if passed object implements ResettableInterface, then call it's reset() method |
|
| 1551 | + * if passed object implements InterminableInterface, then return false, |
|
| 1552 | + * to indicate that it should NOT be cleared from the Registry cache |
|
| 1553 | + * |
|
| 1554 | + * @param $object |
|
| 1555 | + * @param bool $reset_models |
|
| 1556 | + * @return bool returns true if cached object should be unset |
|
| 1557 | + */ |
|
| 1558 | + private static function _reset_and_unset_object($object, $reset_models) |
|
| 1559 | + { |
|
| 1560 | + if (! is_object($object)) { |
|
| 1561 | + // don't unset anything that's not an object |
|
| 1562 | + return false; |
|
| 1563 | + } |
|
| 1564 | + if ($object instanceof EED_Module) { |
|
| 1565 | + $object::reset(); |
|
| 1566 | + // don't unset modules |
|
| 1567 | + return false; |
|
| 1568 | + } |
|
| 1569 | + if ($object instanceof ResettableInterface) { |
|
| 1570 | + if ($object instanceof EEM_Base) { |
|
| 1571 | + if ($reset_models) { |
|
| 1572 | + $object->reset(); |
|
| 1573 | + return true; |
|
| 1574 | + } |
|
| 1575 | + return false; |
|
| 1576 | + } |
|
| 1577 | + $object->reset(); |
|
| 1578 | + return true; |
|
| 1579 | + } |
|
| 1580 | + if (! $object instanceof InterminableInterface) { |
|
| 1581 | + return true; |
|
| 1582 | + } |
|
| 1583 | + return false; |
|
| 1584 | + } |
|
| 1585 | + |
|
| 1586 | + |
|
| 1587 | + |
|
| 1588 | + /** |
|
| 1589 | + * Gets all the custom post type models defined |
|
| 1590 | + * |
|
| 1591 | + * @return array keys are model "short names" (Eg "Event") and keys are classnames (eg "EEM_Event") |
|
| 1592 | + */ |
|
| 1593 | + public function cpt_models() |
|
| 1594 | + { |
|
| 1595 | + $cpt_models = array(); |
|
| 1596 | + foreach ($this->non_abstract_db_models as $short_name => $classname) { |
|
| 1597 | + if (is_subclass_of($classname, 'EEM_CPT_Base')) { |
|
| 1598 | + $cpt_models[$short_name] = $classname; |
|
| 1599 | + } |
|
| 1600 | + } |
|
| 1601 | + return $cpt_models; |
|
| 1602 | + } |
|
| 1603 | + |
|
| 1604 | + |
|
| 1605 | + |
|
| 1606 | + /** |
|
| 1607 | + * @return \EE_Config |
|
| 1608 | + */ |
|
| 1609 | + public static function CFG() |
|
| 1610 | + { |
|
| 1611 | + return self::instance()->CFG; |
|
| 1612 | + } |
|
| 1613 | 1613 | |
| 1614 | 1614 | |
| 1615 | 1615 | } |
@@ -11,7 +11,7 @@ discard block |
||
| 11 | 11 | use ReflectionException; |
| 12 | 12 | |
| 13 | 13 | if ( ! defined( 'EVENT_ESPRESSO_VERSION' ) ) { |
| 14 | - exit( 'No direct script access allowed' ); |
|
| 14 | + exit( 'No direct script access allowed' ); |
|
| 15 | 15 | } |
| 16 | 16 | |
| 17 | 17 | |
@@ -28,83 +28,83 @@ discard block |
||
| 28 | 28 | class TicketSelectorIframe extends Iframe |
| 29 | 29 | { |
| 30 | 30 | |
| 31 | - /** |
|
| 32 | - * TicketSelectorIframe constructor. |
|
| 33 | - * |
|
| 34 | - * @throws InvalidArgumentException |
|
| 35 | - * @throws InvalidInterfaceException |
|
| 36 | - * @throws InvalidDataTypeException |
|
| 37 | - * @throws DomainException |
|
| 38 | - * @throws EE_Error |
|
| 39 | - * @throws ReflectionException |
|
| 40 | - */ |
|
| 41 | - public function __construct() |
|
| 42 | - { |
|
| 43 | - EE_Registry::instance()->REQ->set_espresso_page( true ); |
|
| 44 | - /** @type \EEM_Event $EEM_Event */ |
|
| 45 | - $EEM_Event = EE_Registry::instance()->load_model( 'Event' ); |
|
| 46 | - $event = $EEM_Event->get_one_by_ID( |
|
| 47 | - EE_Registry::instance()->REQ->get( 'event', 0 ) |
|
| 48 | - ); |
|
| 49 | - $ticket_selector = new DisplayTicketSelector(); |
|
| 50 | - $ticket_selector->setIframe( true ); |
|
| 51 | - parent::__construct( |
|
| 52 | - esc_html__( 'Ticket Selector', 'event_espresso' ), |
|
| 53 | - $ticket_selector->display( $event ) |
|
| 54 | - ); |
|
| 55 | - $this->addStylesheets( |
|
| 56 | - apply_filters( |
|
| 57 | - 'FHEE__EED_Ticket_Selector__ticket_selector_iframe__css', |
|
| 58 | - array( |
|
| 59 | - 'ticket_selector_embed' => TICKET_SELECTOR_ASSETS_URL |
|
| 60 | - . 'ticket_selector_embed.css?ver=' |
|
| 61 | - . EVENT_ESPRESSO_VERSION, |
|
| 62 | - 'ticket_selector' => TICKET_SELECTOR_ASSETS_URL |
|
| 63 | - . 'ticket_selector.css?ver=' |
|
| 64 | - . EVENT_ESPRESSO_VERSION, |
|
| 65 | - ), |
|
| 66 | - $this |
|
| 67 | - ) |
|
| 68 | - ); |
|
| 69 | - if ( ! apply_filters('FHEE__EED_Ticket_Selector__ticket_selector_iframe__load_theme_css', false, $this)) { |
|
| 70 | - $this->addStylesheets( array('site_theme' => '' ) ); |
|
| 71 | - } |
|
| 72 | - $this->addScripts( |
|
| 73 | - apply_filters( |
|
| 74 | - 'FHEE__EED_Ticket_Selector__ticket_selector_iframe__js', |
|
| 75 | - array( |
|
| 76 | - 'ticket_selector_iframe_embed' => TICKET_SELECTOR_ASSETS_URL |
|
| 77 | - . 'ticket_selector_iframe_embed.js?ver=' |
|
| 78 | - . EVENT_ESPRESSO_VERSION, |
|
| 79 | - ), |
|
| 80 | - $this |
|
| 81 | - ) |
|
| 82 | - ); |
|
| 83 | - $js_attributes = apply_filters( |
|
| 84 | - 'FHEE__EventEspresso_modules_ticket_selector_TicketSelectorIframe__construct__js_attributes', |
|
| 85 | - array(), |
|
| 86 | - $this |
|
| 87 | - ); |
|
| 88 | - if(! empty($js_attributes)) { |
|
| 89 | - $this->addScriptAttributes($js_attributes); |
|
| 90 | - } |
|
| 91 | - $this->addLocalizedVars( |
|
| 92 | - apply_filters( |
|
| 93 | - 'FHEE__EventEspresso_modules_ticket_selector_TicketSelectorIframe__construct__localized_vars', |
|
| 94 | - array( |
|
| 95 | - 'ticket_selector_iframe' => true, |
|
| 96 | - 'EEDTicketSelectorMsg' => __( |
|
| 97 | - 'Please choose at least one ticket before continuing.', |
|
| 98 | - 'event_espresso' |
|
| 99 | - ), |
|
| 100 | - ) |
|
| 101 | - ) |
|
| 102 | - ); |
|
| 103 | - do_action( |
|
| 104 | - 'AHEE__EventEspresso_modules_ticket_selector_TicketSelectorIframe__construct__complete', |
|
| 105 | - $this |
|
| 106 | - ); |
|
| 107 | - } |
|
| 31 | + /** |
|
| 32 | + * TicketSelectorIframe constructor. |
|
| 33 | + * |
|
| 34 | + * @throws InvalidArgumentException |
|
| 35 | + * @throws InvalidInterfaceException |
|
| 36 | + * @throws InvalidDataTypeException |
|
| 37 | + * @throws DomainException |
|
| 38 | + * @throws EE_Error |
|
| 39 | + * @throws ReflectionException |
|
| 40 | + */ |
|
| 41 | + public function __construct() |
|
| 42 | + { |
|
| 43 | + EE_Registry::instance()->REQ->set_espresso_page( true ); |
|
| 44 | + /** @type \EEM_Event $EEM_Event */ |
|
| 45 | + $EEM_Event = EE_Registry::instance()->load_model( 'Event' ); |
|
| 46 | + $event = $EEM_Event->get_one_by_ID( |
|
| 47 | + EE_Registry::instance()->REQ->get( 'event', 0 ) |
|
| 48 | + ); |
|
| 49 | + $ticket_selector = new DisplayTicketSelector(); |
|
| 50 | + $ticket_selector->setIframe( true ); |
|
| 51 | + parent::__construct( |
|
| 52 | + esc_html__( 'Ticket Selector', 'event_espresso' ), |
|
| 53 | + $ticket_selector->display( $event ) |
|
| 54 | + ); |
|
| 55 | + $this->addStylesheets( |
|
| 56 | + apply_filters( |
|
| 57 | + 'FHEE__EED_Ticket_Selector__ticket_selector_iframe__css', |
|
| 58 | + array( |
|
| 59 | + 'ticket_selector_embed' => TICKET_SELECTOR_ASSETS_URL |
|
| 60 | + . 'ticket_selector_embed.css?ver=' |
|
| 61 | + . EVENT_ESPRESSO_VERSION, |
|
| 62 | + 'ticket_selector' => TICKET_SELECTOR_ASSETS_URL |
|
| 63 | + . 'ticket_selector.css?ver=' |
|
| 64 | + . EVENT_ESPRESSO_VERSION, |
|
| 65 | + ), |
|
| 66 | + $this |
|
| 67 | + ) |
|
| 68 | + ); |
|
| 69 | + if ( ! apply_filters('FHEE__EED_Ticket_Selector__ticket_selector_iframe__load_theme_css', false, $this)) { |
|
| 70 | + $this->addStylesheets( array('site_theme' => '' ) ); |
|
| 71 | + } |
|
| 72 | + $this->addScripts( |
|
| 73 | + apply_filters( |
|
| 74 | + 'FHEE__EED_Ticket_Selector__ticket_selector_iframe__js', |
|
| 75 | + array( |
|
| 76 | + 'ticket_selector_iframe_embed' => TICKET_SELECTOR_ASSETS_URL |
|
| 77 | + . 'ticket_selector_iframe_embed.js?ver=' |
|
| 78 | + . EVENT_ESPRESSO_VERSION, |
|
| 79 | + ), |
|
| 80 | + $this |
|
| 81 | + ) |
|
| 82 | + ); |
|
| 83 | + $js_attributes = apply_filters( |
|
| 84 | + 'FHEE__EventEspresso_modules_ticket_selector_TicketSelectorIframe__construct__js_attributes', |
|
| 85 | + array(), |
|
| 86 | + $this |
|
| 87 | + ); |
|
| 88 | + if(! empty($js_attributes)) { |
|
| 89 | + $this->addScriptAttributes($js_attributes); |
|
| 90 | + } |
|
| 91 | + $this->addLocalizedVars( |
|
| 92 | + apply_filters( |
|
| 93 | + 'FHEE__EventEspresso_modules_ticket_selector_TicketSelectorIframe__construct__localized_vars', |
|
| 94 | + array( |
|
| 95 | + 'ticket_selector_iframe' => true, |
|
| 96 | + 'EEDTicketSelectorMsg' => __( |
|
| 97 | + 'Please choose at least one ticket before continuing.', |
|
| 98 | + 'event_espresso' |
|
| 99 | + ), |
|
| 100 | + ) |
|
| 101 | + ) |
|
| 102 | + ); |
|
| 103 | + do_action( |
|
| 104 | + 'AHEE__EventEspresso_modules_ticket_selector_TicketSelectorIframe__construct__complete', |
|
| 105 | + $this |
|
| 106 | + ); |
|
| 107 | + } |
|
| 108 | 108 | |
| 109 | 109 | } |
| 110 | 110 | // End of file TicketSelectorIframe.php |
@@ -10,8 +10,8 @@ discard block |
||
| 10 | 10 | use InvalidArgumentException; |
| 11 | 11 | use ReflectionException; |
| 12 | 12 | |
| 13 | -if ( ! defined( 'EVENT_ESPRESSO_VERSION' ) ) { |
|
| 14 | - exit( 'No direct script access allowed' ); |
|
| 13 | +if ( ! defined('EVENT_ESPRESSO_VERSION')) { |
|
| 14 | + exit('No direct script access allowed'); |
|
| 15 | 15 | } |
| 16 | 16 | |
| 17 | 17 | |
@@ -40,17 +40,17 @@ discard block |
||
| 40 | 40 | */ |
| 41 | 41 | public function __construct() |
| 42 | 42 | { |
| 43 | - EE_Registry::instance()->REQ->set_espresso_page( true ); |
|
| 43 | + EE_Registry::instance()->REQ->set_espresso_page(true); |
|
| 44 | 44 | /** @type \EEM_Event $EEM_Event */ |
| 45 | - $EEM_Event = EE_Registry::instance()->load_model( 'Event' ); |
|
| 45 | + $EEM_Event = EE_Registry::instance()->load_model('Event'); |
|
| 46 | 46 | $event = $EEM_Event->get_one_by_ID( |
| 47 | - EE_Registry::instance()->REQ->get( 'event', 0 ) |
|
| 47 | + EE_Registry::instance()->REQ->get('event', 0) |
|
| 48 | 48 | ); |
| 49 | 49 | $ticket_selector = new DisplayTicketSelector(); |
| 50 | - $ticket_selector->setIframe( true ); |
|
| 50 | + $ticket_selector->setIframe(true); |
|
| 51 | 51 | parent::__construct( |
| 52 | - esc_html__( 'Ticket Selector', 'event_espresso' ), |
|
| 53 | - $ticket_selector->display( $event ) |
|
| 52 | + esc_html__('Ticket Selector', 'event_espresso'), |
|
| 53 | + $ticket_selector->display($event) |
|
| 54 | 54 | ); |
| 55 | 55 | $this->addStylesheets( |
| 56 | 56 | apply_filters( |
@@ -67,7 +67,7 @@ discard block |
||
| 67 | 67 | ) |
| 68 | 68 | ); |
| 69 | 69 | if ( ! apply_filters('FHEE__EED_Ticket_Selector__ticket_selector_iframe__load_theme_css', false, $this)) { |
| 70 | - $this->addStylesheets( array('site_theme' => '' ) ); |
|
| 70 | + $this->addStylesheets(array('site_theme' => '')); |
|
| 71 | 71 | } |
| 72 | 72 | $this->addScripts( |
| 73 | 73 | apply_filters( |
@@ -85,7 +85,7 @@ discard block |
||
| 85 | 85 | array(), |
| 86 | 86 | $this |
| 87 | 87 | ); |
| 88 | - if(! empty($js_attributes)) { |
|
| 88 | + if ( ! empty($js_attributes)) { |
|
| 89 | 89 | $this->addScriptAttributes($js_attributes); |
| 90 | 90 | } |
| 91 | 91 | $this->addLocalizedVars( |
@@ -19,224 +19,224 @@ |
||
| 19 | 19 | class EE_Invisible_Recaptcha_Input extends EE_Form_Input_Base |
| 20 | 20 | { |
| 21 | 21 | |
| 22 | - const SCRIPT_HANDLE_GOOGLE_INVISIBLE_RECAPTCHA = 'google_invisible_recaptcha'; |
|
| 23 | - |
|
| 24 | - const SCRIPT_HANDLE_ESPRESSO_INVISIBLE_RECAPTCHA = 'espresso_invisible_recaptcha'; |
|
| 25 | - |
|
| 26 | - /** |
|
| 27 | - * @var EE_Registration_Config $config |
|
| 28 | - */ |
|
| 29 | - private $config; |
|
| 30 | - |
|
| 31 | - /** |
|
| 32 | - * @var string $recaptcha_id |
|
| 33 | - */ |
|
| 34 | - private $recaptcha_id; |
|
| 35 | - |
|
| 36 | - /** |
|
| 37 | - * @var string $submit_button_id |
|
| 38 | - */ |
|
| 39 | - private $submit_button_id; |
|
| 40 | - |
|
| 41 | - |
|
| 42 | - /** |
|
| 43 | - * @param array $input_settings |
|
| 44 | - * @param EE_Registration_Config $registration_config |
|
| 45 | - * @throws InvalidArgumentException |
|
| 46 | - * @throws InvalidDataTypeException |
|
| 47 | - * @throws InvalidInterfaceException |
|
| 48 | - * @throws DomainException |
|
| 49 | - */ |
|
| 50 | - public function __construct(array $input_settings = array(), EE_Registration_Config $registration_config = null) |
|
| 51 | - { |
|
| 52 | - $this->_set_display_strategy(new EE_Invisible_Recaptcha_Display_Strategy()); |
|
| 53 | - parent::__construct($input_settings); |
|
| 54 | - $registration_config = $registration_config instanceof EE_Registration_Config |
|
| 55 | - ? $registration_config |
|
| 56 | - : EE_Registry::instance()->CFG->registration; |
|
| 57 | - $this->config = $registration_config; |
|
| 58 | - $this->recaptcha_id = isset($input_settings['recaptcha_id']) |
|
| 59 | - ? $input_settings['recaptcha_id'] |
|
| 60 | - : substr(spl_object_hash($this), 8, 8); |
|
| 61 | - $this->submit_button_id = isset($input_settings['submit_button_id']) |
|
| 62 | - ? $input_settings['submit_button_id'] |
|
| 63 | - : ''; |
|
| 64 | - if( |
|
| 65 | - isset($input_settings['localized_vars']) |
|
| 66 | - && filter_var($input_settings['iframe'], FILTER_VALIDATE_BOOLEAN) |
|
| 67 | - ) { |
|
| 68 | - $this->addIframeAssets($input_settings['localized_vars']); |
|
| 69 | - } else { |
|
| 70 | - $this->registerScripts(); |
|
| 71 | - } |
|
| 72 | - } |
|
| 73 | - |
|
| 74 | - |
|
| 75 | - /** |
|
| 76 | - * @return bool |
|
| 77 | - */ |
|
| 78 | - public function useCaptcha() |
|
| 79 | - { |
|
| 80 | - return $this->config->use_captcha && $this->config->recaptcha_theme === 'invisible'; |
|
| 81 | - } |
|
| 82 | - |
|
| 83 | - |
|
| 84 | - /** |
|
| 85 | - * @return string |
|
| 86 | - */ |
|
| 87 | - public function badge() |
|
| 88 | - { |
|
| 89 | - return $this->config->recaptcha_badge; |
|
| 90 | - } |
|
| 91 | - |
|
| 92 | - |
|
| 93 | - /** |
|
| 94 | - * @return string |
|
| 95 | - */ |
|
| 96 | - public function language() |
|
| 97 | - { |
|
| 98 | - return $this->config->recaptcha_language; |
|
| 99 | - } |
|
| 100 | - |
|
| 101 | - |
|
| 102 | - /** |
|
| 103 | - * @return string |
|
| 104 | - */ |
|
| 105 | - public function siteKey() |
|
| 106 | - { |
|
| 107 | - return $this->config->recaptcha_publickey; |
|
| 108 | - } |
|
| 109 | - |
|
| 110 | - |
|
| 111 | - /** |
|
| 112 | - * @return string |
|
| 113 | - */ |
|
| 114 | - public function secretKey() |
|
| 115 | - { |
|
| 116 | - return $this->config->recaptcha_privatekey; |
|
| 117 | - } |
|
| 118 | - |
|
| 119 | - |
|
| 120 | - /** |
|
| 121 | - * @return string |
|
| 122 | - */ |
|
| 123 | - public function recaptchaId() |
|
| 124 | - { |
|
| 125 | - return $this->recaptcha_id; |
|
| 126 | - } |
|
| 127 | - |
|
| 128 | - |
|
| 129 | - /** |
|
| 130 | - * @return string |
|
| 131 | - */ |
|
| 132 | - public function submitButtonId() |
|
| 133 | - { |
|
| 134 | - return $this->submit_button_id; |
|
| 135 | - } |
|
| 136 | - |
|
| 137 | - |
|
| 138 | - /** |
|
| 139 | - * @param array $localized_vars |
|
| 140 | - * @throws DomainException |
|
| 141 | - */ |
|
| 142 | - private function addIframeAssets(array $localized_vars) |
|
| 143 | - { |
|
| 144 | - if (! $this->useCaptcha()) { |
|
| 145 | - return; |
|
| 146 | - } |
|
| 147 | - add_filter( |
|
| 148 | - 'FHEE__EED_Ticket_Selector__ticket_selector_iframe__js', |
|
| 149 | - function(array $iframe_assets) { |
|
| 150 | - $iframe_assets[ EE_Invisible_Recaptcha_Input::SCRIPT_HANDLE_ESPRESSO_INVISIBLE_RECAPTCHA ] = |
|
| 151 | - EED_Recaptcha_Invisible::assetsUrl() |
|
| 152 | - . 'espresso_invisible_recaptcha.js?ver=' |
|
| 153 | - . EVENT_ESPRESSO_VERSION; |
|
| 154 | - $iframe_assets[ EE_Invisible_Recaptcha_Input::SCRIPT_HANDLE_GOOGLE_INVISIBLE_RECAPTCHA ] = |
|
| 155 | - add_query_arg( |
|
| 156 | - array( |
|
| 157 | - 'onload' => 'espressoLoadRecaptcha', |
|
| 158 | - 'render' => 'explicit', |
|
| 159 | - 'hl' => $this->language(), |
|
| 160 | - ), |
|
| 161 | - 'https://www.google.com/recaptcha/api.js?' |
|
| 162 | - ); |
|
| 163 | - return $iframe_assets; |
|
| 164 | - } |
|
| 165 | - ); |
|
| 166 | - add_filter( |
|
| 167 | - 'FHEE__EventEspresso_modules_ticket_selector_TicketSelectorIframe__construct__js_attributes', |
|
| 168 | - function (array $iframe_asset_attributes) |
|
| 169 | - { |
|
| 170 | - $iframe_asset_attributes[ EE_Invisible_Recaptcha_Input::SCRIPT_HANDLE_GOOGLE_INVISIBLE_RECAPTCHA ] |
|
| 171 | - = ' async="async" defer="defer"'; |
|
| 172 | - return $iframe_asset_attributes; |
|
| 173 | - } |
|
| 174 | - ); |
|
| 175 | - add_action( |
|
| 176 | - 'AHEE__EventEspresso_modules_ticket_selector_TicketSelectorIframe__construct__complete', |
|
| 177 | - function (EventEspresso\modules\ticket_selector\TicketSelectorIframe $ticket_selector_iframe) use ($localized_vars) |
|
| 178 | - { |
|
| 179 | - $ticket_selector_iframe->addLocalizedVars($localized_vars, 'eeRecaptcha'); |
|
| 180 | - } |
|
| 181 | - ); |
|
| 182 | - } |
|
| 183 | - |
|
| 184 | - |
|
| 185 | - /** |
|
| 186 | - * @return void |
|
| 187 | - */ |
|
| 188 | - private function registerScripts() |
|
| 189 | - { |
|
| 190 | - if (! $this->useCaptcha()) { |
|
| 191 | - return; |
|
| 192 | - } |
|
| 193 | - add_filter('script_loader_tag', array($this, 'addScriptAttributes'), 10, 2); |
|
| 194 | - wp_register_script( |
|
| 195 | - EE_Invisible_Recaptcha_Input::SCRIPT_HANDLE_ESPRESSO_INVISIBLE_RECAPTCHA, |
|
| 196 | - EED_Recaptcha_Invisible::assetsUrl() . 'espresso_invisible_recaptcha.js', |
|
| 197 | - array('espresso_core'), |
|
| 198 | - EVENT_ESPRESSO_VERSION, |
|
| 199 | - true |
|
| 200 | - ); |
|
| 201 | - wp_register_script( |
|
| 202 | - EE_Invisible_Recaptcha_Input::SCRIPT_HANDLE_GOOGLE_INVISIBLE_RECAPTCHA, |
|
| 203 | - add_query_arg( |
|
| 204 | - array( |
|
| 205 | - 'onload' => 'espressoLoadRecaptcha', |
|
| 206 | - 'render' => 'explicit', |
|
| 207 | - 'hl' => $this->language(), |
|
| 208 | - ), |
|
| 209 | - 'https://www.google.com/recaptcha/api.js?' |
|
| 210 | - ), |
|
| 211 | - array(EE_Invisible_Recaptcha_Input::SCRIPT_HANDLE_ESPRESSO_INVISIBLE_RECAPTCHA), |
|
| 212 | - false, |
|
| 213 | - true |
|
| 214 | - ); |
|
| 215 | - } |
|
| 216 | - |
|
| 217 | - |
|
| 218 | - /** |
|
| 219 | - * @param string $tag |
|
| 220 | - * @param string $handle |
|
| 221 | - * @return string |
|
| 222 | - */ |
|
| 223 | - public function addScriptAttributes($tag, $handle) |
|
| 224 | - { |
|
| 225 | - if ($handle === EE_Invisible_Recaptcha_Input::SCRIPT_HANDLE_GOOGLE_INVISIBLE_RECAPTCHA) { |
|
| 226 | - $tag = str_replace('></script>', ' async="async" defer="defer"></script>', $tag); |
|
| 227 | - } |
|
| 228 | - return $tag; |
|
| 229 | - } |
|
| 230 | - |
|
| 231 | - |
|
| 232 | - /** |
|
| 233 | - * Gets the HTML for displaying the label for this form input |
|
| 234 | - * according to the form section's layout strategy |
|
| 235 | - * |
|
| 236 | - * @return string |
|
| 237 | - */ |
|
| 238 | - public function get_html_for_label() |
|
| 239 | - { |
|
| 240 | - return ''; |
|
| 241 | - } |
|
| 22 | + const SCRIPT_HANDLE_GOOGLE_INVISIBLE_RECAPTCHA = 'google_invisible_recaptcha'; |
|
| 23 | + |
|
| 24 | + const SCRIPT_HANDLE_ESPRESSO_INVISIBLE_RECAPTCHA = 'espresso_invisible_recaptcha'; |
|
| 25 | + |
|
| 26 | + /** |
|
| 27 | + * @var EE_Registration_Config $config |
|
| 28 | + */ |
|
| 29 | + private $config; |
|
| 30 | + |
|
| 31 | + /** |
|
| 32 | + * @var string $recaptcha_id |
|
| 33 | + */ |
|
| 34 | + private $recaptcha_id; |
|
| 35 | + |
|
| 36 | + /** |
|
| 37 | + * @var string $submit_button_id |
|
| 38 | + */ |
|
| 39 | + private $submit_button_id; |
|
| 40 | + |
|
| 41 | + |
|
| 42 | + /** |
|
| 43 | + * @param array $input_settings |
|
| 44 | + * @param EE_Registration_Config $registration_config |
|
| 45 | + * @throws InvalidArgumentException |
|
| 46 | + * @throws InvalidDataTypeException |
|
| 47 | + * @throws InvalidInterfaceException |
|
| 48 | + * @throws DomainException |
|
| 49 | + */ |
|
| 50 | + public function __construct(array $input_settings = array(), EE_Registration_Config $registration_config = null) |
|
| 51 | + { |
|
| 52 | + $this->_set_display_strategy(new EE_Invisible_Recaptcha_Display_Strategy()); |
|
| 53 | + parent::__construct($input_settings); |
|
| 54 | + $registration_config = $registration_config instanceof EE_Registration_Config |
|
| 55 | + ? $registration_config |
|
| 56 | + : EE_Registry::instance()->CFG->registration; |
|
| 57 | + $this->config = $registration_config; |
|
| 58 | + $this->recaptcha_id = isset($input_settings['recaptcha_id']) |
|
| 59 | + ? $input_settings['recaptcha_id'] |
|
| 60 | + : substr(spl_object_hash($this), 8, 8); |
|
| 61 | + $this->submit_button_id = isset($input_settings['submit_button_id']) |
|
| 62 | + ? $input_settings['submit_button_id'] |
|
| 63 | + : ''; |
|
| 64 | + if( |
|
| 65 | + isset($input_settings['localized_vars']) |
|
| 66 | + && filter_var($input_settings['iframe'], FILTER_VALIDATE_BOOLEAN) |
|
| 67 | + ) { |
|
| 68 | + $this->addIframeAssets($input_settings['localized_vars']); |
|
| 69 | + } else { |
|
| 70 | + $this->registerScripts(); |
|
| 71 | + } |
|
| 72 | + } |
|
| 73 | + |
|
| 74 | + |
|
| 75 | + /** |
|
| 76 | + * @return bool |
|
| 77 | + */ |
|
| 78 | + public function useCaptcha() |
|
| 79 | + { |
|
| 80 | + return $this->config->use_captcha && $this->config->recaptcha_theme === 'invisible'; |
|
| 81 | + } |
|
| 82 | + |
|
| 83 | + |
|
| 84 | + /** |
|
| 85 | + * @return string |
|
| 86 | + */ |
|
| 87 | + public function badge() |
|
| 88 | + { |
|
| 89 | + return $this->config->recaptcha_badge; |
|
| 90 | + } |
|
| 91 | + |
|
| 92 | + |
|
| 93 | + /** |
|
| 94 | + * @return string |
|
| 95 | + */ |
|
| 96 | + public function language() |
|
| 97 | + { |
|
| 98 | + return $this->config->recaptcha_language; |
|
| 99 | + } |
|
| 100 | + |
|
| 101 | + |
|
| 102 | + /** |
|
| 103 | + * @return string |
|
| 104 | + */ |
|
| 105 | + public function siteKey() |
|
| 106 | + { |
|
| 107 | + return $this->config->recaptcha_publickey; |
|
| 108 | + } |
|
| 109 | + |
|
| 110 | + |
|
| 111 | + /** |
|
| 112 | + * @return string |
|
| 113 | + */ |
|
| 114 | + public function secretKey() |
|
| 115 | + { |
|
| 116 | + return $this->config->recaptcha_privatekey; |
|
| 117 | + } |
|
| 118 | + |
|
| 119 | + |
|
| 120 | + /** |
|
| 121 | + * @return string |
|
| 122 | + */ |
|
| 123 | + public function recaptchaId() |
|
| 124 | + { |
|
| 125 | + return $this->recaptcha_id; |
|
| 126 | + } |
|
| 127 | + |
|
| 128 | + |
|
| 129 | + /** |
|
| 130 | + * @return string |
|
| 131 | + */ |
|
| 132 | + public function submitButtonId() |
|
| 133 | + { |
|
| 134 | + return $this->submit_button_id; |
|
| 135 | + } |
|
| 136 | + |
|
| 137 | + |
|
| 138 | + /** |
|
| 139 | + * @param array $localized_vars |
|
| 140 | + * @throws DomainException |
|
| 141 | + */ |
|
| 142 | + private function addIframeAssets(array $localized_vars) |
|
| 143 | + { |
|
| 144 | + if (! $this->useCaptcha()) { |
|
| 145 | + return; |
|
| 146 | + } |
|
| 147 | + add_filter( |
|
| 148 | + 'FHEE__EED_Ticket_Selector__ticket_selector_iframe__js', |
|
| 149 | + function(array $iframe_assets) { |
|
| 150 | + $iframe_assets[ EE_Invisible_Recaptcha_Input::SCRIPT_HANDLE_ESPRESSO_INVISIBLE_RECAPTCHA ] = |
|
| 151 | + EED_Recaptcha_Invisible::assetsUrl() |
|
| 152 | + . 'espresso_invisible_recaptcha.js?ver=' |
|
| 153 | + . EVENT_ESPRESSO_VERSION; |
|
| 154 | + $iframe_assets[ EE_Invisible_Recaptcha_Input::SCRIPT_HANDLE_GOOGLE_INVISIBLE_RECAPTCHA ] = |
|
| 155 | + add_query_arg( |
|
| 156 | + array( |
|
| 157 | + 'onload' => 'espressoLoadRecaptcha', |
|
| 158 | + 'render' => 'explicit', |
|
| 159 | + 'hl' => $this->language(), |
|
| 160 | + ), |
|
| 161 | + 'https://www.google.com/recaptcha/api.js?' |
|
| 162 | + ); |
|
| 163 | + return $iframe_assets; |
|
| 164 | + } |
|
| 165 | + ); |
|
| 166 | + add_filter( |
|
| 167 | + 'FHEE__EventEspresso_modules_ticket_selector_TicketSelectorIframe__construct__js_attributes', |
|
| 168 | + function (array $iframe_asset_attributes) |
|
| 169 | + { |
|
| 170 | + $iframe_asset_attributes[ EE_Invisible_Recaptcha_Input::SCRIPT_HANDLE_GOOGLE_INVISIBLE_RECAPTCHA ] |
|
| 171 | + = ' async="async" defer="defer"'; |
|
| 172 | + return $iframe_asset_attributes; |
|
| 173 | + } |
|
| 174 | + ); |
|
| 175 | + add_action( |
|
| 176 | + 'AHEE__EventEspresso_modules_ticket_selector_TicketSelectorIframe__construct__complete', |
|
| 177 | + function (EventEspresso\modules\ticket_selector\TicketSelectorIframe $ticket_selector_iframe) use ($localized_vars) |
|
| 178 | + { |
|
| 179 | + $ticket_selector_iframe->addLocalizedVars($localized_vars, 'eeRecaptcha'); |
|
| 180 | + } |
|
| 181 | + ); |
|
| 182 | + } |
|
| 183 | + |
|
| 184 | + |
|
| 185 | + /** |
|
| 186 | + * @return void |
|
| 187 | + */ |
|
| 188 | + private function registerScripts() |
|
| 189 | + { |
|
| 190 | + if (! $this->useCaptcha()) { |
|
| 191 | + return; |
|
| 192 | + } |
|
| 193 | + add_filter('script_loader_tag', array($this, 'addScriptAttributes'), 10, 2); |
|
| 194 | + wp_register_script( |
|
| 195 | + EE_Invisible_Recaptcha_Input::SCRIPT_HANDLE_ESPRESSO_INVISIBLE_RECAPTCHA, |
|
| 196 | + EED_Recaptcha_Invisible::assetsUrl() . 'espresso_invisible_recaptcha.js', |
|
| 197 | + array('espresso_core'), |
|
| 198 | + EVENT_ESPRESSO_VERSION, |
|
| 199 | + true |
|
| 200 | + ); |
|
| 201 | + wp_register_script( |
|
| 202 | + EE_Invisible_Recaptcha_Input::SCRIPT_HANDLE_GOOGLE_INVISIBLE_RECAPTCHA, |
|
| 203 | + add_query_arg( |
|
| 204 | + array( |
|
| 205 | + 'onload' => 'espressoLoadRecaptcha', |
|
| 206 | + 'render' => 'explicit', |
|
| 207 | + 'hl' => $this->language(), |
|
| 208 | + ), |
|
| 209 | + 'https://www.google.com/recaptcha/api.js?' |
|
| 210 | + ), |
|
| 211 | + array(EE_Invisible_Recaptcha_Input::SCRIPT_HANDLE_ESPRESSO_INVISIBLE_RECAPTCHA), |
|
| 212 | + false, |
|
| 213 | + true |
|
| 214 | + ); |
|
| 215 | + } |
|
| 216 | + |
|
| 217 | + |
|
| 218 | + /** |
|
| 219 | + * @param string $tag |
|
| 220 | + * @param string $handle |
|
| 221 | + * @return string |
|
| 222 | + */ |
|
| 223 | + public function addScriptAttributes($tag, $handle) |
|
| 224 | + { |
|
| 225 | + if ($handle === EE_Invisible_Recaptcha_Input::SCRIPT_HANDLE_GOOGLE_INVISIBLE_RECAPTCHA) { |
|
| 226 | + $tag = str_replace('></script>', ' async="async" defer="defer"></script>', $tag); |
|
| 227 | + } |
|
| 228 | + return $tag; |
|
| 229 | + } |
|
| 230 | + |
|
| 231 | + |
|
| 232 | + /** |
|
| 233 | + * Gets the HTML for displaying the label for this form input |
|
| 234 | + * according to the form section's layout strategy |
|
| 235 | + * |
|
| 236 | + * @return string |
|
| 237 | + */ |
|
| 238 | + public function get_html_for_label() |
|
| 239 | + { |
|
| 240 | + return ''; |
|
| 241 | + } |
|
| 242 | 242 | } |
@@ -61,7 +61,7 @@ discard block |
||
| 61 | 61 | $this->submit_button_id = isset($input_settings['submit_button_id']) |
| 62 | 62 | ? $input_settings['submit_button_id'] |
| 63 | 63 | : ''; |
| 64 | - if( |
|
| 64 | + if ( |
|
| 65 | 65 | isset($input_settings['localized_vars']) |
| 66 | 66 | && filter_var($input_settings['iframe'], FILTER_VALIDATE_BOOLEAN) |
| 67 | 67 | ) { |
@@ -141,17 +141,17 @@ discard block |
||
| 141 | 141 | */ |
| 142 | 142 | private function addIframeAssets(array $localized_vars) |
| 143 | 143 | { |
| 144 | - if (! $this->useCaptcha()) { |
|
| 144 | + if ( ! $this->useCaptcha()) { |
|
| 145 | 145 | return; |
| 146 | 146 | } |
| 147 | 147 | add_filter( |
| 148 | 148 | 'FHEE__EED_Ticket_Selector__ticket_selector_iframe__js', |
| 149 | 149 | function(array $iframe_assets) { |
| 150 | - $iframe_assets[ EE_Invisible_Recaptcha_Input::SCRIPT_HANDLE_ESPRESSO_INVISIBLE_RECAPTCHA ] = |
|
| 150 | + $iframe_assets[EE_Invisible_Recaptcha_Input::SCRIPT_HANDLE_ESPRESSO_INVISIBLE_RECAPTCHA] = |
|
| 151 | 151 | EED_Recaptcha_Invisible::assetsUrl() |
| 152 | 152 | . 'espresso_invisible_recaptcha.js?ver=' |
| 153 | 153 | . EVENT_ESPRESSO_VERSION; |
| 154 | - $iframe_assets[ EE_Invisible_Recaptcha_Input::SCRIPT_HANDLE_GOOGLE_INVISIBLE_RECAPTCHA ] = |
|
| 154 | + $iframe_assets[EE_Invisible_Recaptcha_Input::SCRIPT_HANDLE_GOOGLE_INVISIBLE_RECAPTCHA] = |
|
| 155 | 155 | add_query_arg( |
| 156 | 156 | array( |
| 157 | 157 | 'onload' => 'espressoLoadRecaptcha', |
@@ -165,16 +165,16 @@ discard block |
||
| 165 | 165 | ); |
| 166 | 166 | add_filter( |
| 167 | 167 | 'FHEE__EventEspresso_modules_ticket_selector_TicketSelectorIframe__construct__js_attributes', |
| 168 | - function (array $iframe_asset_attributes) |
|
| 168 | + function(array $iframe_asset_attributes) |
|
| 169 | 169 | { |
| 170 | - $iframe_asset_attributes[ EE_Invisible_Recaptcha_Input::SCRIPT_HANDLE_GOOGLE_INVISIBLE_RECAPTCHA ] |
|
| 170 | + $iframe_asset_attributes[EE_Invisible_Recaptcha_Input::SCRIPT_HANDLE_GOOGLE_INVISIBLE_RECAPTCHA] |
|
| 171 | 171 | = ' async="async" defer="defer"'; |
| 172 | 172 | return $iframe_asset_attributes; |
| 173 | 173 | } |
| 174 | 174 | ); |
| 175 | 175 | add_action( |
| 176 | 176 | 'AHEE__EventEspresso_modules_ticket_selector_TicketSelectorIframe__construct__complete', |
| 177 | - function (EventEspresso\modules\ticket_selector\TicketSelectorIframe $ticket_selector_iframe) use ($localized_vars) |
|
| 177 | + function(EventEspresso\modules\ticket_selector\TicketSelectorIframe $ticket_selector_iframe) use ($localized_vars) |
|
| 178 | 178 | { |
| 179 | 179 | $ticket_selector_iframe->addLocalizedVars($localized_vars, 'eeRecaptcha'); |
| 180 | 180 | } |
@@ -187,13 +187,13 @@ discard block |
||
| 187 | 187 | */ |
| 188 | 188 | private function registerScripts() |
| 189 | 189 | { |
| 190 | - if (! $this->useCaptcha()) { |
|
| 190 | + if ( ! $this->useCaptcha()) { |
|
| 191 | 191 | return; |
| 192 | 192 | } |
| 193 | 193 | add_filter('script_loader_tag', array($this, 'addScriptAttributes'), 10, 2); |
| 194 | 194 | wp_register_script( |
| 195 | 195 | EE_Invisible_Recaptcha_Input::SCRIPT_HANDLE_ESPRESSO_INVISIBLE_RECAPTCHA, |
| 196 | - EED_Recaptcha_Invisible::assetsUrl() . 'espresso_invisible_recaptcha.js', |
|
| 196 | + EED_Recaptcha_Invisible::assetsUrl().'espresso_invisible_recaptcha.js', |
|
| 197 | 197 | array('espresso_core'), |
| 198 | 198 | EVENT_ESPRESSO_VERSION, |
| 199 | 199 | true |
@@ -22,17 +22,17 @@ discard block |
||
| 22 | 22 | <html> |
| 23 | 23 | <head> |
| 24 | 24 | <title><?php echo $title; ?></title> |
| 25 | -<?php if ( $enqueue_wp_assets ) : ?> |
|
| 25 | +<?php if ($enqueue_wp_assets) : ?> |
|
| 26 | 26 | <?php wp_head(); ?> |
| 27 | 27 | <?php else : ?> |
| 28 | - <?php foreach ( $css as $url ) : ?> |
|
| 29 | - <link rel="stylesheet" type="text/css" href="<?php echo $url;?>"> |
|
| 28 | + <?php foreach ($css as $url) : ?> |
|
| 29 | + <link rel="stylesheet" type="text/css" href="<?php echo $url; ?>"> |
|
| 30 | 30 | <?php endforeach; ?> |
| 31 | 31 | <script type="text/javascript"> |
| 32 | 32 | <?php echo $eei18n; ?> |
| 33 | 33 | </script> |
| 34 | - <?php foreach ( $header_js as $key => $url ) : ?> |
|
| 35 | - <?php $header_attributes = isset($header_js_attributes[ $key ]) ? $header_js_attributes[ $key ] : ''; ?> |
|
| 34 | + <?php foreach ($header_js as $key => $url) : ?> |
|
| 35 | + <?php $header_attributes = isset($header_js_attributes[$key]) ? $header_js_attributes[$key] : ''; ?> |
|
| 36 | 36 | <script type="text/javascript" src="<?php echo $url; ?>"<?php echo $header_attributes; ?>></script> |
| 37 | 37 | <?php endforeach; ?> |
| 38 | 38 | <?php endif; ?> |
@@ -42,11 +42,11 @@ discard block |
||
| 42 | 42 | <div style="padding: 1em;"> |
| 43 | 43 | <?php echo $content; ?> |
| 44 | 44 | </div> |
| 45 | - <?php foreach ( $footer_js as $key => $url ) : ?> |
|
| 46 | - <?php $footer_attributes = isset($footer_js_attributes[$key]) ? $footer_js_attributes[ $key ] : ''; ?> |
|
| 47 | - <script type="text/javascript" src="<?php echo $url; ?>"<?php echo $footer_attributes;?>></script> |
|
| 45 | + <?php foreach ($footer_js as $key => $url) : ?> |
|
| 46 | + <?php $footer_attributes = isset($footer_js_attributes[$key]) ? $footer_js_attributes[$key] : ''; ?> |
|
| 47 | + <script type="text/javascript" src="<?php echo $url; ?>"<?php echo $footer_attributes; ?>></script> |
|
| 48 | 48 | <?php endforeach; ?> |
| 49 | -<?php if ( $enqueue_wp_assets ) : ?> |
|
| 49 | +<?php if ($enqueue_wp_assets) : ?> |
|
| 50 | 50 | <?php wp_footer(); ?> |
| 51 | 51 | <?php endif; ?> |
| 52 | 52 | </body> |
@@ -31,241 +31,241 @@ |
||
| 31 | 31 | class InvisibleRecaptcha |
| 32 | 32 | { |
| 33 | 33 | |
| 34 | - const URL_GOOGLE_RECAPTCHA_API = 'https://www.google.com/recaptcha/api/siteverify'; |
|
| 35 | - |
|
| 36 | - const SESSION_DATA_KEY_RECAPTCHA_PASSED = 'recaptcha_passed'; |
|
| 37 | - |
|
| 38 | - /** |
|
| 39 | - * @var EE_Registration_Config $config |
|
| 40 | - */ |
|
| 41 | - private $config; |
|
| 42 | - |
|
| 43 | - /** |
|
| 44 | - * @var EE_Session $session |
|
| 45 | - */ |
|
| 46 | - private $session; |
|
| 47 | - |
|
| 48 | - /** |
|
| 49 | - * @var boolean $recaptcha_passed |
|
| 50 | - */ |
|
| 51 | - private $recaptcha_passed; |
|
| 52 | - |
|
| 53 | - |
|
| 54 | - /** |
|
| 55 | - * InvisibleRecaptcha constructor. |
|
| 56 | - * |
|
| 57 | - * @param EE_Registration_Config $registration_config |
|
| 58 | - * @param EE_Session $session |
|
| 59 | - */ |
|
| 60 | - public function __construct(EE_Registration_Config $registration_config, EE_Session $session) |
|
| 61 | - { |
|
| 62 | - $this->config = $registration_config; |
|
| 63 | - $this->session = $session; |
|
| 64 | - } |
|
| 65 | - |
|
| 66 | - |
|
| 67 | - /** |
|
| 68 | - * @return boolean |
|
| 69 | - */ |
|
| 70 | - public function useInvisibleRecaptcha() |
|
| 71 | - { |
|
| 72 | - return $this->config->use_captcha && $this->config->recaptcha_theme === 'invisible'; |
|
| 73 | - } |
|
| 74 | - |
|
| 75 | - |
|
| 76 | - /** |
|
| 77 | - * @param array $input_settings |
|
| 78 | - * @return EE_Invisible_Recaptcha_Input |
|
| 79 | - * @throws InvalidDataTypeException |
|
| 80 | - * @throws InvalidInterfaceException |
|
| 81 | - * @throws InvalidArgumentException |
|
| 82 | - * @throws DomainException |
|
| 83 | - */ |
|
| 84 | - public function getInput(array $input_settings = array()) |
|
| 85 | - { |
|
| 86 | - return new EE_Invisible_Recaptcha_Input( |
|
| 87 | - $input_settings, |
|
| 88 | - $this->config |
|
| 89 | - ); |
|
| 90 | - } |
|
| 91 | - |
|
| 92 | - |
|
| 93 | - /** |
|
| 94 | - * @param array $input_settings |
|
| 95 | - * @return string |
|
| 96 | - * @throws EE_Error |
|
| 97 | - * @throws InvalidDataTypeException |
|
| 98 | - * @throws InvalidInterfaceException |
|
| 99 | - * @throws InvalidArgumentException |
|
| 100 | - * @throws DomainException |
|
| 101 | - */ |
|
| 102 | - public function getInputHtml(array $input_settings = array()) |
|
| 103 | - { |
|
| 104 | - return $this->getInput($input_settings)->get_html_for_input(); |
|
| 105 | - } |
|
| 106 | - |
|
| 107 | - |
|
| 108 | - /** |
|
| 109 | - * @param EE_Form_Section_Proper $form |
|
| 110 | - * @param array $input_settings |
|
| 111 | - * @throws EE_Error |
|
| 112 | - * @throws InvalidArgumentException |
|
| 113 | - * @throws InvalidDataTypeException |
|
| 114 | - * @throws InvalidInterfaceException |
|
| 115 | - * @throws DomainException |
|
| 116 | - */ |
|
| 117 | - public function addToFormSection(EE_Form_Section_Proper $form, array $input_settings = array()) |
|
| 118 | - { |
|
| 119 | - $form->add_subsections( |
|
| 120 | - array( |
|
| 121 | - 'espresso_recaptcha' => $this->getInput($input_settings), |
|
| 122 | - ), |
|
| 123 | - null, |
|
| 124 | - false |
|
| 125 | - ); |
|
| 126 | - } |
|
| 127 | - |
|
| 128 | - |
|
| 129 | - /** |
|
| 130 | - * @param EE_Request $request |
|
| 131 | - * @return boolean |
|
| 132 | - * @throws RuntimeException |
|
| 133 | - */ |
|
| 134 | - public function verifyToken(EE_Request $request) |
|
| 135 | - { |
|
| 136 | - static $previous_recaptcha_response = array(); |
|
| 137 | - $grecaptcha_response = $request->get('g-recaptcha-response'); |
|
| 138 | - // if this token has already been verified, then return previous response |
|
| 139 | - if (isset($previous_recaptcha_response[ $grecaptcha_response ])) { |
|
| 140 | - return $previous_recaptcha_response[ $grecaptcha_response ]; |
|
| 141 | - } |
|
| 142 | - // will update to true if everything passes |
|
| 143 | - $previous_recaptcha_response[ $grecaptcha_response ] = false; |
|
| 144 | - $response = wp_safe_remote_post( |
|
| 145 | - InvisibleRecaptcha::URL_GOOGLE_RECAPTCHA_API, |
|
| 146 | - array( |
|
| 147 | - 'body' => array( |
|
| 148 | - 'secret' => $this->config->recaptcha_privatekey, |
|
| 149 | - 'response' => $grecaptcha_response, |
|
| 150 | - 'remoteip' => $request->ip_address(), |
|
| 151 | - ), |
|
| 152 | - ) |
|
| 153 | - ); |
|
| 154 | - if ($response instanceof WP_Error) { |
|
| 155 | - $this->generateError($response->get_error_messages()); |
|
| 156 | - return false; |
|
| 157 | - } |
|
| 158 | - $results = json_decode(wp_remote_retrieve_body($response), true); |
|
| 159 | - if (filter_var($results['success'], FILTER_VALIDATE_BOOLEAN) !== true) { |
|
| 160 | - $errors = array_map( |
|
| 161 | - array($this, 'getErrorCode'), |
|
| 162 | - $results['error-codes'] |
|
| 163 | - ); |
|
| 164 | - if(isset($results['challenge_ts'])) { |
|
| 165 | - $errors[] = 'challenge timestamp: ' . $results['challenge_ts'] . '.'; |
|
| 166 | - } |
|
| 167 | - $this->generateError(implode(' ', $errors)); |
|
| 168 | - } |
|
| 169 | - $previous_recaptcha_response[ $grecaptcha_response ] = true; |
|
| 170 | - add_action('shutdown', array($this, 'setSessionData')); |
|
| 171 | - return true; |
|
| 172 | - } |
|
| 173 | - |
|
| 174 | - |
|
| 175 | - /** |
|
| 176 | - * @param string $error_response |
|
| 177 | - * @return void |
|
| 178 | - * @throws RuntimeException |
|
| 179 | - */ |
|
| 180 | - public function generateError($error_response = '') |
|
| 181 | - { |
|
| 182 | - throw new RuntimeException( |
|
| 183 | - sprintf( |
|
| 184 | - esc_html__( |
|
| 185 | - 'We\'re sorry but an attempt to verify the form\'s reCAPTCHA has failed. %1$s %2$s Please try again.', |
|
| 186 | - 'event_espresso' |
|
| 187 | - ), |
|
| 188 | - '<br />', |
|
| 189 | - current_user_can('manage_options') ? $error_response : '' |
|
| 190 | - ) |
|
| 191 | - ); |
|
| 192 | - } |
|
| 193 | - |
|
| 194 | - |
|
| 195 | - /** |
|
| 196 | - * @param string $error_code |
|
| 197 | - * @return string |
|
| 198 | - */ |
|
| 199 | - public function getErrorCode(&$error_code) |
|
| 200 | - { |
|
| 201 | - $error_codes = array( |
|
| 202 | - 'missing-input-secret' => 'The secret parameter is missing.', |
|
| 203 | - 'invalid-input-secret' => 'The secret parameter is invalid or malformed.', |
|
| 204 | - 'missing-input-response' => 'The response parameter is missing.', |
|
| 205 | - 'invalid-input-response' => 'The response parameter is invalid or malformed.', |
|
| 206 | - 'bad-request' => 'The request is invalid or malformed.', |
|
| 207 | - 'timeout-or-duplicate' => 'The request took too long to be sent or was a duplicate of a previous request.', |
|
| 208 | - ); |
|
| 209 | - return isset($error_codes[ $error_code ]) ? $error_codes[ $error_code ] : ''; |
|
| 210 | - } |
|
| 211 | - |
|
| 212 | - |
|
| 213 | - /** |
|
| 214 | - * @return array |
|
| 215 | - * @throws InvalidInterfaceException |
|
| 216 | - * @throws InvalidDataTypeException |
|
| 217 | - * @throws InvalidArgumentException |
|
| 218 | - */ |
|
| 219 | - public function getLocalizedVars() |
|
| 220 | - { |
|
| 221 | - return (array) apply_filters( |
|
| 222 | - 'FHEE__EventEspresso_caffeinated_modules_recaptcha_invisible_InvisibleRecaptcha__getLocalizedVars__localized_vars', |
|
| 223 | - array( |
|
| 224 | - 'siteKey' => $this->config->recaptcha_publickey, |
|
| 225 | - 'recaptcha_passed' => $this->recaptchaPassed(), |
|
| 226 | - 'wp_debug' => WP_DEBUG, |
|
| 227 | - 'disable_submit' => defined('EE_EVENT_QUEUE_BASE_URL'), |
|
| 228 | - ) |
|
| 229 | - ); |
|
| 230 | - } |
|
| 231 | - |
|
| 232 | - |
|
| 233 | - /** |
|
| 234 | - * @return boolean |
|
| 235 | - * @throws InvalidInterfaceException |
|
| 236 | - * @throws InvalidDataTypeException |
|
| 237 | - * @throws InvalidArgumentException |
|
| 238 | - */ |
|
| 239 | - public function recaptchaPassed() |
|
| 240 | - { |
|
| 241 | - if ($this->recaptcha_passed !== null) { |
|
| 242 | - return $this->recaptcha_passed; |
|
| 243 | - } |
|
| 244 | - // logged in means you have already passed a turing test of sorts |
|
| 245 | - if ($this->useInvisibleRecaptcha() === false || is_user_logged_in()) { |
|
| 246 | - $this->recaptcha_passed = true; |
|
| 247 | - return $this->recaptcha_passed; |
|
| 248 | - } |
|
| 249 | - // was test already passed? |
|
| 250 | - $this->recaptcha_passed = filter_var( |
|
| 251 | - $this->session->get_session_data( |
|
| 252 | - InvisibleRecaptcha::SESSION_DATA_KEY_RECAPTCHA_PASSED |
|
| 253 | - ), |
|
| 254 | - FILTER_VALIDATE_BOOLEAN |
|
| 255 | - ); |
|
| 256 | - return $this->recaptcha_passed; |
|
| 257 | - } |
|
| 258 | - |
|
| 259 | - |
|
| 260 | - /** |
|
| 261 | - * @throws InvalidArgumentException |
|
| 262 | - * @throws InvalidDataTypeException |
|
| 263 | - * @throws InvalidInterfaceException |
|
| 264 | - */ |
|
| 265 | - public function setSessionData() |
|
| 266 | - { |
|
| 267 | - $this->session->set_session_data( |
|
| 268 | - array(InvisibleRecaptcha::SESSION_DATA_KEY_RECAPTCHA_PASSED => true) |
|
| 269 | - ); |
|
| 270 | - } |
|
| 34 | + const URL_GOOGLE_RECAPTCHA_API = 'https://www.google.com/recaptcha/api/siteverify'; |
|
| 35 | + |
|
| 36 | + const SESSION_DATA_KEY_RECAPTCHA_PASSED = 'recaptcha_passed'; |
|
| 37 | + |
|
| 38 | + /** |
|
| 39 | + * @var EE_Registration_Config $config |
|
| 40 | + */ |
|
| 41 | + private $config; |
|
| 42 | + |
|
| 43 | + /** |
|
| 44 | + * @var EE_Session $session |
|
| 45 | + */ |
|
| 46 | + private $session; |
|
| 47 | + |
|
| 48 | + /** |
|
| 49 | + * @var boolean $recaptcha_passed |
|
| 50 | + */ |
|
| 51 | + private $recaptcha_passed; |
|
| 52 | + |
|
| 53 | + |
|
| 54 | + /** |
|
| 55 | + * InvisibleRecaptcha constructor. |
|
| 56 | + * |
|
| 57 | + * @param EE_Registration_Config $registration_config |
|
| 58 | + * @param EE_Session $session |
|
| 59 | + */ |
|
| 60 | + public function __construct(EE_Registration_Config $registration_config, EE_Session $session) |
|
| 61 | + { |
|
| 62 | + $this->config = $registration_config; |
|
| 63 | + $this->session = $session; |
|
| 64 | + } |
|
| 65 | + |
|
| 66 | + |
|
| 67 | + /** |
|
| 68 | + * @return boolean |
|
| 69 | + */ |
|
| 70 | + public function useInvisibleRecaptcha() |
|
| 71 | + { |
|
| 72 | + return $this->config->use_captcha && $this->config->recaptcha_theme === 'invisible'; |
|
| 73 | + } |
|
| 74 | + |
|
| 75 | + |
|
| 76 | + /** |
|
| 77 | + * @param array $input_settings |
|
| 78 | + * @return EE_Invisible_Recaptcha_Input |
|
| 79 | + * @throws InvalidDataTypeException |
|
| 80 | + * @throws InvalidInterfaceException |
|
| 81 | + * @throws InvalidArgumentException |
|
| 82 | + * @throws DomainException |
|
| 83 | + */ |
|
| 84 | + public function getInput(array $input_settings = array()) |
|
| 85 | + { |
|
| 86 | + return new EE_Invisible_Recaptcha_Input( |
|
| 87 | + $input_settings, |
|
| 88 | + $this->config |
|
| 89 | + ); |
|
| 90 | + } |
|
| 91 | + |
|
| 92 | + |
|
| 93 | + /** |
|
| 94 | + * @param array $input_settings |
|
| 95 | + * @return string |
|
| 96 | + * @throws EE_Error |
|
| 97 | + * @throws InvalidDataTypeException |
|
| 98 | + * @throws InvalidInterfaceException |
|
| 99 | + * @throws InvalidArgumentException |
|
| 100 | + * @throws DomainException |
|
| 101 | + */ |
|
| 102 | + public function getInputHtml(array $input_settings = array()) |
|
| 103 | + { |
|
| 104 | + return $this->getInput($input_settings)->get_html_for_input(); |
|
| 105 | + } |
|
| 106 | + |
|
| 107 | + |
|
| 108 | + /** |
|
| 109 | + * @param EE_Form_Section_Proper $form |
|
| 110 | + * @param array $input_settings |
|
| 111 | + * @throws EE_Error |
|
| 112 | + * @throws InvalidArgumentException |
|
| 113 | + * @throws InvalidDataTypeException |
|
| 114 | + * @throws InvalidInterfaceException |
|
| 115 | + * @throws DomainException |
|
| 116 | + */ |
|
| 117 | + public function addToFormSection(EE_Form_Section_Proper $form, array $input_settings = array()) |
|
| 118 | + { |
|
| 119 | + $form->add_subsections( |
|
| 120 | + array( |
|
| 121 | + 'espresso_recaptcha' => $this->getInput($input_settings), |
|
| 122 | + ), |
|
| 123 | + null, |
|
| 124 | + false |
|
| 125 | + ); |
|
| 126 | + } |
|
| 127 | + |
|
| 128 | + |
|
| 129 | + /** |
|
| 130 | + * @param EE_Request $request |
|
| 131 | + * @return boolean |
|
| 132 | + * @throws RuntimeException |
|
| 133 | + */ |
|
| 134 | + public function verifyToken(EE_Request $request) |
|
| 135 | + { |
|
| 136 | + static $previous_recaptcha_response = array(); |
|
| 137 | + $grecaptcha_response = $request->get('g-recaptcha-response'); |
|
| 138 | + // if this token has already been verified, then return previous response |
|
| 139 | + if (isset($previous_recaptcha_response[ $grecaptcha_response ])) { |
|
| 140 | + return $previous_recaptcha_response[ $grecaptcha_response ]; |
|
| 141 | + } |
|
| 142 | + // will update to true if everything passes |
|
| 143 | + $previous_recaptcha_response[ $grecaptcha_response ] = false; |
|
| 144 | + $response = wp_safe_remote_post( |
|
| 145 | + InvisibleRecaptcha::URL_GOOGLE_RECAPTCHA_API, |
|
| 146 | + array( |
|
| 147 | + 'body' => array( |
|
| 148 | + 'secret' => $this->config->recaptcha_privatekey, |
|
| 149 | + 'response' => $grecaptcha_response, |
|
| 150 | + 'remoteip' => $request->ip_address(), |
|
| 151 | + ), |
|
| 152 | + ) |
|
| 153 | + ); |
|
| 154 | + if ($response instanceof WP_Error) { |
|
| 155 | + $this->generateError($response->get_error_messages()); |
|
| 156 | + return false; |
|
| 157 | + } |
|
| 158 | + $results = json_decode(wp_remote_retrieve_body($response), true); |
|
| 159 | + if (filter_var($results['success'], FILTER_VALIDATE_BOOLEAN) !== true) { |
|
| 160 | + $errors = array_map( |
|
| 161 | + array($this, 'getErrorCode'), |
|
| 162 | + $results['error-codes'] |
|
| 163 | + ); |
|
| 164 | + if(isset($results['challenge_ts'])) { |
|
| 165 | + $errors[] = 'challenge timestamp: ' . $results['challenge_ts'] . '.'; |
|
| 166 | + } |
|
| 167 | + $this->generateError(implode(' ', $errors)); |
|
| 168 | + } |
|
| 169 | + $previous_recaptcha_response[ $grecaptcha_response ] = true; |
|
| 170 | + add_action('shutdown', array($this, 'setSessionData')); |
|
| 171 | + return true; |
|
| 172 | + } |
|
| 173 | + |
|
| 174 | + |
|
| 175 | + /** |
|
| 176 | + * @param string $error_response |
|
| 177 | + * @return void |
|
| 178 | + * @throws RuntimeException |
|
| 179 | + */ |
|
| 180 | + public function generateError($error_response = '') |
|
| 181 | + { |
|
| 182 | + throw new RuntimeException( |
|
| 183 | + sprintf( |
|
| 184 | + esc_html__( |
|
| 185 | + 'We\'re sorry but an attempt to verify the form\'s reCAPTCHA has failed. %1$s %2$s Please try again.', |
|
| 186 | + 'event_espresso' |
|
| 187 | + ), |
|
| 188 | + '<br />', |
|
| 189 | + current_user_can('manage_options') ? $error_response : '' |
|
| 190 | + ) |
|
| 191 | + ); |
|
| 192 | + } |
|
| 193 | + |
|
| 194 | + |
|
| 195 | + /** |
|
| 196 | + * @param string $error_code |
|
| 197 | + * @return string |
|
| 198 | + */ |
|
| 199 | + public function getErrorCode(&$error_code) |
|
| 200 | + { |
|
| 201 | + $error_codes = array( |
|
| 202 | + 'missing-input-secret' => 'The secret parameter is missing.', |
|
| 203 | + 'invalid-input-secret' => 'The secret parameter is invalid or malformed.', |
|
| 204 | + 'missing-input-response' => 'The response parameter is missing.', |
|
| 205 | + 'invalid-input-response' => 'The response parameter is invalid or malformed.', |
|
| 206 | + 'bad-request' => 'The request is invalid or malformed.', |
|
| 207 | + 'timeout-or-duplicate' => 'The request took too long to be sent or was a duplicate of a previous request.', |
|
| 208 | + ); |
|
| 209 | + return isset($error_codes[ $error_code ]) ? $error_codes[ $error_code ] : ''; |
|
| 210 | + } |
|
| 211 | + |
|
| 212 | + |
|
| 213 | + /** |
|
| 214 | + * @return array |
|
| 215 | + * @throws InvalidInterfaceException |
|
| 216 | + * @throws InvalidDataTypeException |
|
| 217 | + * @throws InvalidArgumentException |
|
| 218 | + */ |
|
| 219 | + public function getLocalizedVars() |
|
| 220 | + { |
|
| 221 | + return (array) apply_filters( |
|
| 222 | + 'FHEE__EventEspresso_caffeinated_modules_recaptcha_invisible_InvisibleRecaptcha__getLocalizedVars__localized_vars', |
|
| 223 | + array( |
|
| 224 | + 'siteKey' => $this->config->recaptcha_publickey, |
|
| 225 | + 'recaptcha_passed' => $this->recaptchaPassed(), |
|
| 226 | + 'wp_debug' => WP_DEBUG, |
|
| 227 | + 'disable_submit' => defined('EE_EVENT_QUEUE_BASE_URL'), |
|
| 228 | + ) |
|
| 229 | + ); |
|
| 230 | + } |
|
| 231 | + |
|
| 232 | + |
|
| 233 | + /** |
|
| 234 | + * @return boolean |
|
| 235 | + * @throws InvalidInterfaceException |
|
| 236 | + * @throws InvalidDataTypeException |
|
| 237 | + * @throws InvalidArgumentException |
|
| 238 | + */ |
|
| 239 | + public function recaptchaPassed() |
|
| 240 | + { |
|
| 241 | + if ($this->recaptcha_passed !== null) { |
|
| 242 | + return $this->recaptcha_passed; |
|
| 243 | + } |
|
| 244 | + // logged in means you have already passed a turing test of sorts |
|
| 245 | + if ($this->useInvisibleRecaptcha() === false || is_user_logged_in()) { |
|
| 246 | + $this->recaptcha_passed = true; |
|
| 247 | + return $this->recaptcha_passed; |
|
| 248 | + } |
|
| 249 | + // was test already passed? |
|
| 250 | + $this->recaptcha_passed = filter_var( |
|
| 251 | + $this->session->get_session_data( |
|
| 252 | + InvisibleRecaptcha::SESSION_DATA_KEY_RECAPTCHA_PASSED |
|
| 253 | + ), |
|
| 254 | + FILTER_VALIDATE_BOOLEAN |
|
| 255 | + ); |
|
| 256 | + return $this->recaptcha_passed; |
|
| 257 | + } |
|
| 258 | + |
|
| 259 | + |
|
| 260 | + /** |
|
| 261 | + * @throws InvalidArgumentException |
|
| 262 | + * @throws InvalidDataTypeException |
|
| 263 | + * @throws InvalidInterfaceException |
|
| 264 | + */ |
|
| 265 | + public function setSessionData() |
|
| 266 | + { |
|
| 267 | + $this->session->set_session_data( |
|
| 268 | + array(InvisibleRecaptcha::SESSION_DATA_KEY_RECAPTCHA_PASSED => true) |
|
| 269 | + ); |
|
| 270 | + } |
|
| 271 | 271 | } |
@@ -136,11 +136,11 @@ discard block |
||
| 136 | 136 | static $previous_recaptcha_response = array(); |
| 137 | 137 | $grecaptcha_response = $request->get('g-recaptcha-response'); |
| 138 | 138 | // if this token has already been verified, then return previous response |
| 139 | - if (isset($previous_recaptcha_response[ $grecaptcha_response ])) { |
|
| 140 | - return $previous_recaptcha_response[ $grecaptcha_response ]; |
|
| 139 | + if (isset($previous_recaptcha_response[$grecaptcha_response])) { |
|
| 140 | + return $previous_recaptcha_response[$grecaptcha_response]; |
|
| 141 | 141 | } |
| 142 | 142 | // will update to true if everything passes |
| 143 | - $previous_recaptcha_response[ $grecaptcha_response ] = false; |
|
| 143 | + $previous_recaptcha_response[$grecaptcha_response] = false; |
|
| 144 | 144 | $response = wp_safe_remote_post( |
| 145 | 145 | InvisibleRecaptcha::URL_GOOGLE_RECAPTCHA_API, |
| 146 | 146 | array( |
@@ -157,16 +157,16 @@ discard block |
||
| 157 | 157 | } |
| 158 | 158 | $results = json_decode(wp_remote_retrieve_body($response), true); |
| 159 | 159 | if (filter_var($results['success'], FILTER_VALIDATE_BOOLEAN) !== true) { |
| 160 | - $errors = array_map( |
|
| 160 | + $errors = array_map( |
|
| 161 | 161 | array($this, 'getErrorCode'), |
| 162 | 162 | $results['error-codes'] |
| 163 | 163 | ); |
| 164 | - if(isset($results['challenge_ts'])) { |
|
| 165 | - $errors[] = 'challenge timestamp: ' . $results['challenge_ts'] . '.'; |
|
| 164 | + if (isset($results['challenge_ts'])) { |
|
| 165 | + $errors[] = 'challenge timestamp: '.$results['challenge_ts'].'.'; |
|
| 166 | 166 | } |
| 167 | 167 | $this->generateError(implode(' ', $errors)); |
| 168 | 168 | } |
| 169 | - $previous_recaptcha_response[ $grecaptcha_response ] = true; |
|
| 169 | + $previous_recaptcha_response[$grecaptcha_response] = true; |
|
| 170 | 170 | add_action('shutdown', array($this, 'setSessionData')); |
| 171 | 171 | return true; |
| 172 | 172 | } |
@@ -206,7 +206,7 @@ discard block |
||
| 206 | 206 | 'bad-request' => 'The request is invalid or malformed.', |
| 207 | 207 | 'timeout-or-duplicate' => 'The request took too long to be sent or was a duplicate of a previous request.', |
| 208 | 208 | ); |
| 209 | - return isset($error_codes[ $error_code ]) ? $error_codes[ $error_code ] : ''; |
|
| 209 | + return isset($error_codes[$error_code]) ? $error_codes[$error_code] : ''; |
|
| 210 | 210 | } |
| 211 | 211 | |
| 212 | 212 | |