@@ -17,117 +17,117 @@ |
||
17 | 17 | */ |
18 | 18 | class VersionParser |
19 | 19 | { |
20 | - public static function getAddonVersion(string $main_file): string |
|
21 | - { |
|
22 | - $version = VersionParser::read(dirname($main_file) . '/VERSION'); |
|
23 | - $version = trim($version); |
|
24 | - if (! empty($version)) { |
|
25 | - return $version; |
|
26 | - } |
|
27 | - return VersionParser::getVersionFromMainfile($main_file); |
|
28 | - } |
|
20 | + public static function getAddonVersion(string $main_file): string |
|
21 | + { |
|
22 | + $version = VersionParser::read(dirname($main_file) . '/VERSION'); |
|
23 | + $version = trim($version); |
|
24 | + if (! empty($version)) { |
|
25 | + return $version; |
|
26 | + } |
|
27 | + return VersionParser::getVersionFromMainfile($main_file); |
|
28 | + } |
|
29 | 29 | |
30 | 30 | |
31 | - private static function getVersionFromMainfile(string $main_file): string |
|
32 | - { |
|
33 | - $matches = []; |
|
34 | - $file_contents = VersionParser::read($main_file, true); |
|
35 | - preg_match('~[/*#@]*Version:\s*(?<version>\S*)~', $file_contents, $matches); |
|
36 | - if (isset($matches['version'])) { |
|
37 | - $currentVersion = trim($matches['version']); |
|
38 | - if (! empty($currentVersion)) { |
|
39 | - return $currentVersion; |
|
40 | - } |
|
41 | - } |
|
42 | - throw new RuntimeException( |
|
43 | - sprintf( |
|
44 | - esc_html__('Could not parse version from main file: %s', 'event_espresso'), |
|
45 | - $main_file |
|
46 | - ) |
|
47 | - ); |
|
48 | - } |
|
31 | + private static function getVersionFromMainfile(string $main_file): string |
|
32 | + { |
|
33 | + $matches = []; |
|
34 | + $file_contents = VersionParser::read($main_file, true); |
|
35 | + preg_match('~[/*#@]*Version:\s*(?<version>\S*)~', $file_contents, $matches); |
|
36 | + if (isset($matches['version'])) { |
|
37 | + $currentVersion = trim($matches['version']); |
|
38 | + if (! empty($currentVersion)) { |
|
39 | + return $currentVersion; |
|
40 | + } |
|
41 | + } |
|
42 | + throw new RuntimeException( |
|
43 | + sprintf( |
|
44 | + esc_html__('Could not parse version from main file: %s', 'event_espresso'), |
|
45 | + $main_file |
|
46 | + ) |
|
47 | + ); |
|
48 | + } |
|
49 | 49 | |
50 | 50 | |
51 | - /** |
|
52 | - * Checks if a file exists. |
|
53 | - * If $throw_exception is true, then throws exception if file does not exist. |
|
54 | - * |
|
55 | - * @param string $file_path |
|
56 | - * @param bool $throw_exception |
|
57 | - * @return bool |
|
58 | - * @throws RuntimeException |
|
59 | - */ |
|
60 | - private static function exists(string $file_path, bool $throw_exception = false): bool |
|
61 | - { |
|
62 | - if (! file_exists($file_path)) { |
|
63 | - if ($throw_exception) { |
|
64 | - throw new RuntimeException( |
|
65 | - sprintf( |
|
66 | - esc_html__('File does not exist: %s', 'event_espresso'), |
|
67 | - $file_path |
|
68 | - ) |
|
69 | - ); |
|
70 | - } |
|
71 | - return false; |
|
72 | - } |
|
73 | - return true; |
|
74 | - } |
|
51 | + /** |
|
52 | + * Checks if a file exists. |
|
53 | + * If $throw_exception is true, then throws exception if file does not exist. |
|
54 | + * |
|
55 | + * @param string $file_path |
|
56 | + * @param bool $throw_exception |
|
57 | + * @return bool |
|
58 | + * @throws RuntimeException |
|
59 | + */ |
|
60 | + private static function exists(string $file_path, bool $throw_exception = false): bool |
|
61 | + { |
|
62 | + if (! file_exists($file_path)) { |
|
63 | + if ($throw_exception) { |
|
64 | + throw new RuntimeException( |
|
65 | + sprintf( |
|
66 | + esc_html__('File does not exist: %s', 'event_espresso'), |
|
67 | + $file_path |
|
68 | + ) |
|
69 | + ); |
|
70 | + } |
|
71 | + return false; |
|
72 | + } |
|
73 | + return true; |
|
74 | + } |
|
75 | 75 | |
76 | 76 | |
77 | - /** |
|
78 | - * Checks if a file is readable. |
|
79 | - * If $throw_exception is true, then throws exception if file is not readable. |
|
80 | - * |
|
81 | - * @param string $file_path |
|
82 | - * @param bool $throw_exception |
|
83 | - * @return bool |
|
84 | - * @throws RuntimeException |
|
85 | - */ |
|
86 | - private static function isReadable(string $file_path, bool $throw_exception = false): bool |
|
87 | - { |
|
88 | - if (! is_readable($file_path)) { |
|
89 | - if ($throw_exception) { |
|
90 | - throw new RuntimeException( |
|
91 | - sprintf( |
|
92 | - esc_html__('File is not readable: %s', 'event_espresso'), |
|
93 | - $file_path |
|
94 | - ) |
|
95 | - ); |
|
96 | - } |
|
97 | - return false; |
|
98 | - } |
|
99 | - return true; |
|
100 | - } |
|
77 | + /** |
|
78 | + * Checks if a file is readable. |
|
79 | + * If $throw_exception is true, then throws exception if file is not readable. |
|
80 | + * |
|
81 | + * @param string $file_path |
|
82 | + * @param bool $throw_exception |
|
83 | + * @return bool |
|
84 | + * @throws RuntimeException |
|
85 | + */ |
|
86 | + private static function isReadable(string $file_path, bool $throw_exception = false): bool |
|
87 | + { |
|
88 | + if (! is_readable($file_path)) { |
|
89 | + if ($throw_exception) { |
|
90 | + throw new RuntimeException( |
|
91 | + sprintf( |
|
92 | + esc_html__('File is not readable: %s', 'event_espresso'), |
|
93 | + $file_path |
|
94 | + ) |
|
95 | + ); |
|
96 | + } |
|
97 | + return false; |
|
98 | + } |
|
99 | + return true; |
|
100 | + } |
|
101 | 101 | |
102 | 102 | |
103 | - /** |
|
104 | - * Reads and returns file contents. |
|
105 | - * If $throw_exception is true, then throws exception if there is an error reading the file. |
|
106 | - * |
|
107 | - * @param string $file_path |
|
108 | - * @param bool $throw_exception |
|
109 | - * @return string |
|
110 | - * @throws RuntimeException |
|
111 | - */ |
|
112 | - private static function read(string $file_path, bool $throw_exception = false): string |
|
113 | - { |
|
114 | - if ( |
|
115 | - VersionParser::exists($file_path, $throw_exception) |
|
116 | - && VersionParser::isReadable($file_path, $throw_exception) |
|
117 | - ) { |
|
118 | - $file_contents = file_get_contents($file_path); |
|
119 | - if ($file_contents !== false) { |
|
120 | - return $file_contents; |
|
121 | - } |
|
122 | - } |
|
123 | - if ($throw_exception) { |
|
124 | - throw new RuntimeException( |
|
125 | - sprintf( |
|
126 | - esc_html__('Error reading file: %s', 'event_espresso'), |
|
127 | - $file_path |
|
128 | - ) |
|
129 | - ); |
|
130 | - } |
|
131 | - return ''; |
|
132 | - } |
|
103 | + /** |
|
104 | + * Reads and returns file contents. |
|
105 | + * If $throw_exception is true, then throws exception if there is an error reading the file. |
|
106 | + * |
|
107 | + * @param string $file_path |
|
108 | + * @param bool $throw_exception |
|
109 | + * @return string |
|
110 | + * @throws RuntimeException |
|
111 | + */ |
|
112 | + private static function read(string $file_path, bool $throw_exception = false): string |
|
113 | + { |
|
114 | + if ( |
|
115 | + VersionParser::exists($file_path, $throw_exception) |
|
116 | + && VersionParser::isReadable($file_path, $throw_exception) |
|
117 | + ) { |
|
118 | + $file_contents = file_get_contents($file_path); |
|
119 | + if ($file_contents !== false) { |
|
120 | + return $file_contents; |
|
121 | + } |
|
122 | + } |
|
123 | + if ($throw_exception) { |
|
124 | + throw new RuntimeException( |
|
125 | + sprintf( |
|
126 | + esc_html__('Error reading file: %s', 'event_espresso'), |
|
127 | + $file_path |
|
128 | + ) |
|
129 | + ); |
|
130 | + } |
|
131 | + return ''; |
|
132 | + } |
|
133 | 133 | } |
@@ -19,9 +19,9 @@ discard block |
||
19 | 19 | { |
20 | 20 | public static function getAddonVersion(string $main_file): string |
21 | 21 | { |
22 | - $version = VersionParser::read(dirname($main_file) . '/VERSION'); |
|
22 | + $version = VersionParser::read(dirname($main_file).'/VERSION'); |
|
23 | 23 | $version = trim($version); |
24 | - if (! empty($version)) { |
|
24 | + if ( ! empty($version)) { |
|
25 | 25 | return $version; |
26 | 26 | } |
27 | 27 | return VersionParser::getVersionFromMainfile($main_file); |
@@ -35,7 +35,7 @@ discard block |
||
35 | 35 | preg_match('~[/*#@]*Version:\s*(?<version>\S*)~', $file_contents, $matches); |
36 | 36 | if (isset($matches['version'])) { |
37 | 37 | $currentVersion = trim($matches['version']); |
38 | - if (! empty($currentVersion)) { |
|
38 | + if ( ! empty($currentVersion)) { |
|
39 | 39 | return $currentVersion; |
40 | 40 | } |
41 | 41 | } |
@@ -59,7 +59,7 @@ discard block |
||
59 | 59 | */ |
60 | 60 | private static function exists(string $file_path, bool $throw_exception = false): bool |
61 | 61 | { |
62 | - if (! file_exists($file_path)) { |
|
62 | + if ( ! file_exists($file_path)) { |
|
63 | 63 | if ($throw_exception) { |
64 | 64 | throw new RuntimeException( |
65 | 65 | sprintf( |
@@ -85,7 +85,7 @@ discard block |
||
85 | 85 | */ |
86 | 86 | private static function isReadable(string $file_path, bool $throw_exception = false): bool |
87 | 87 | { |
88 | - if (! is_readable($file_path)) { |
|
88 | + if ( ! is_readable($file_path)) { |
|
89 | 89 | if ($throw_exception) { |
90 | 90 | throw new RuntimeException( |
91 | 91 | sprintf( |
@@ -15,46 +15,46 @@ |
||
15 | 15 | */ |
16 | 16 | class AddonApiFactory |
17 | 17 | { |
18 | - public static function addonApiV1( |
|
19 | - int $ID, |
|
20 | - string $main_file, |
|
21 | - string $name, |
|
22 | - string $display_name, |
|
23 | - string $namespace, |
|
24 | - string $min_core_version |
|
25 | - ): AddonApi { |
|
26 | - $addon_collection = AddonApiFactory::getAddonCollection(); |
|
27 | - $slug = AddonApiFactory::getSlugFromMainfile($main_file); |
|
28 | - if ($addon_collection->hasAddon($slug)) { |
|
29 | - return $addon_collection->getAddon($slug); |
|
30 | - } |
|
31 | - $addon = AddonApiFactory::createAddon(); |
|
32 | - $addon->setID($ID); |
|
33 | - $addon->setSlug($slug); |
|
34 | - $addon->setName($name); |
|
35 | - $addon->setDisplayName($display_name); |
|
36 | - $addon->setMainFile($main_file); |
|
37 | - $addon->setVersion(VersionParser::getAddonVersion($main_file)); |
|
38 | - $addon->setMinCoreVersion($min_core_version); |
|
39 | - $addon->setNamespace($namespace); |
|
40 | - $addon_collection->addAddon($addon); |
|
41 | - return $addon; |
|
42 | - } |
|
18 | + public static function addonApiV1( |
|
19 | + int $ID, |
|
20 | + string $main_file, |
|
21 | + string $name, |
|
22 | + string $display_name, |
|
23 | + string $namespace, |
|
24 | + string $min_core_version |
|
25 | + ): AddonApi { |
|
26 | + $addon_collection = AddonApiFactory::getAddonCollection(); |
|
27 | + $slug = AddonApiFactory::getSlugFromMainfile($main_file); |
|
28 | + if ($addon_collection->hasAddon($slug)) { |
|
29 | + return $addon_collection->getAddon($slug); |
|
30 | + } |
|
31 | + $addon = AddonApiFactory::createAddon(); |
|
32 | + $addon->setID($ID); |
|
33 | + $addon->setSlug($slug); |
|
34 | + $addon->setName($name); |
|
35 | + $addon->setDisplayName($display_name); |
|
36 | + $addon->setMainFile($main_file); |
|
37 | + $addon->setVersion(VersionParser::getAddonVersion($main_file)); |
|
38 | + $addon->setMinCoreVersion($min_core_version); |
|
39 | + $addon->setNamespace($namespace); |
|
40 | + $addon_collection->addAddon($addon); |
|
41 | + return $addon; |
|
42 | + } |
|
43 | 43 | |
44 | - private static function createAddon(): AddonApi |
|
45 | - { |
|
46 | - return LoaderFactory::getNew(AddonApi::class); |
|
47 | - } |
|
44 | + private static function createAddon(): AddonApi |
|
45 | + { |
|
46 | + return LoaderFactory::getNew(AddonApi::class); |
|
47 | + } |
|
48 | 48 | |
49 | - private static function getSlugFromMainfile(string $main_file): string |
|
50 | - { |
|
51 | - $plugin_basename = plugin_basename($main_file); |
|
52 | - return substr($plugin_basename, 0, strpos($plugin_basename, '/')); |
|
53 | - } |
|
49 | + private static function getSlugFromMainfile(string $main_file): string |
|
50 | + { |
|
51 | + $plugin_basename = plugin_basename($main_file); |
|
52 | + return substr($plugin_basename, 0, strpos($plugin_basename, '/')); |
|
53 | + } |
|
54 | 54 | |
55 | 55 | |
56 | - public static function getAddonCollection(): AddonCollection |
|
57 | - { |
|
58 | - return LoaderFactory::getShared(AddonCollection::class); |
|
59 | - } |
|
56 | + public static function getAddonCollection(): AddonCollection |
|
57 | + { |
|
58 | + return LoaderFactory::getShared(AddonCollection::class); |
|
59 | + } |
|
60 | 60 | } |
@@ -54,213 +54,213 @@ |
||
54 | 54 | */ |
55 | 55 | class BootstrapCore |
56 | 56 | { |
57 | - private LoaderInterface $loader; |
|
57 | + private LoaderInterface $loader; |
|
58 | 58 | |
59 | - protected RequestInterface $request; |
|
59 | + protected RequestInterface $request; |
|
60 | 60 | |
61 | - protected ResponseInterface $response; |
|
61 | + protected ResponseInterface $response; |
|
62 | 62 | |
63 | - protected RequestStackBuilder $request_stack_builder; |
|
63 | + protected RequestStackBuilder $request_stack_builder; |
|
64 | 64 | |
65 | - protected RequestStack $request_stack; |
|
65 | + protected RequestStack $request_stack; |
|
66 | 66 | |
67 | 67 | |
68 | - /** |
|
69 | - * BootstrapCore constructor. |
|
70 | - */ |
|
71 | - public function __construct() |
|
72 | - { |
|
73 | - do_action('AHEE__EventEspresso_core_services_bootstrap_BootstrapCore___construct'); |
|
74 | - // construct request stack and run middleware apps as soon as all WP plugins are loaded |
|
75 | - add_action('plugins_loaded', [$this, 'initialize'], 0); |
|
76 | - } |
|
68 | + /** |
|
69 | + * BootstrapCore constructor. |
|
70 | + */ |
|
71 | + public function __construct() |
|
72 | + { |
|
73 | + do_action('AHEE__EventEspresso_core_services_bootstrap_BootstrapCore___construct'); |
|
74 | + // construct request stack and run middleware apps as soon as all WP plugins are loaded |
|
75 | + add_action('plugins_loaded', [$this, 'initialize'], 0); |
|
76 | + } |
|
77 | 77 | |
78 | 78 | |
79 | - /** |
|
80 | - * @throws DomainException |
|
81 | - * @throws EE_Error |
|
82 | - * @throws Exception |
|
83 | - * @throws InvalidArgumentException |
|
84 | - * @throws InvalidClassException |
|
85 | - * @throws InvalidDataTypeException |
|
86 | - * @throws InvalidFilePathException |
|
87 | - * @throws InvalidInterfaceException |
|
88 | - * @throws InvalidRequestStackMiddlewareException |
|
89 | - * @throws OutOfBoundsException |
|
90 | - * @throws ReflectionException |
|
91 | - * @throws Throwable |
|
92 | - */ |
|
93 | - public function initialize() |
|
94 | - { |
|
95 | - $this->bootstrapDependencyInjectionContainer(); |
|
96 | - $this->bootstrapDomain(); |
|
97 | - $bootstrap_request = $this->bootstrapRequestResponseObjects(); |
|
98 | - add_action( |
|
99 | - 'EE_Load_Espresso_Core__handle_request__initialize_core_loading', |
|
100 | - [$bootstrap_request, 'setupLegacyRequest'] |
|
101 | - ); |
|
102 | - $this->runRequestStack(); |
|
103 | - } |
|
79 | + /** |
|
80 | + * @throws DomainException |
|
81 | + * @throws EE_Error |
|
82 | + * @throws Exception |
|
83 | + * @throws InvalidArgumentException |
|
84 | + * @throws InvalidClassException |
|
85 | + * @throws InvalidDataTypeException |
|
86 | + * @throws InvalidFilePathException |
|
87 | + * @throws InvalidInterfaceException |
|
88 | + * @throws InvalidRequestStackMiddlewareException |
|
89 | + * @throws OutOfBoundsException |
|
90 | + * @throws ReflectionException |
|
91 | + * @throws Throwable |
|
92 | + */ |
|
93 | + public function initialize() |
|
94 | + { |
|
95 | + $this->bootstrapDependencyInjectionContainer(); |
|
96 | + $this->bootstrapDomain(); |
|
97 | + $bootstrap_request = $this->bootstrapRequestResponseObjects(); |
|
98 | + add_action( |
|
99 | + 'EE_Load_Espresso_Core__handle_request__initialize_core_loading', |
|
100 | + [$bootstrap_request, 'setupLegacyRequest'] |
|
101 | + ); |
|
102 | + $this->runRequestStack(); |
|
103 | + } |
|
104 | 104 | |
105 | 105 | |
106 | - /** |
|
107 | - * @throws ReflectionException |
|
108 | - * @throws EE_Error |
|
109 | - * @throws InvalidArgumentException |
|
110 | - * @throws InvalidDataTypeException |
|
111 | - * @throws InvalidInterfaceException |
|
112 | - * @throws OutOfBoundsException |
|
113 | - */ |
|
114 | - private function bootstrapDependencyInjectionContainer() |
|
115 | - { |
|
116 | - $bootstrap_di = new BootstrapDependencyInjectionContainer(); |
|
117 | - $bootstrap_di->buildLegacyDependencyInjectionContainer(); |
|
118 | - $bootstrap_di->buildLoader(); |
|
119 | - $registry = $bootstrap_di->getRegistry(); |
|
120 | - $dependency_map = $bootstrap_di->getDependencyMap(); |
|
121 | - $dependency_map->initialize(); |
|
122 | - $registry->initialize(); |
|
123 | - $this->loader = $bootstrap_di->getLoader(); |
|
124 | - } |
|
106 | + /** |
|
107 | + * @throws ReflectionException |
|
108 | + * @throws EE_Error |
|
109 | + * @throws InvalidArgumentException |
|
110 | + * @throws InvalidDataTypeException |
|
111 | + * @throws InvalidInterfaceException |
|
112 | + * @throws OutOfBoundsException |
|
113 | + */ |
|
114 | + private function bootstrapDependencyInjectionContainer() |
|
115 | + { |
|
116 | + $bootstrap_di = new BootstrapDependencyInjectionContainer(); |
|
117 | + $bootstrap_di->buildLegacyDependencyInjectionContainer(); |
|
118 | + $bootstrap_di->buildLoader(); |
|
119 | + $registry = $bootstrap_di->getRegistry(); |
|
120 | + $dependency_map = $bootstrap_di->getDependencyMap(); |
|
121 | + $dependency_map->initialize(); |
|
122 | + $registry->initialize(); |
|
123 | + $this->loader = $bootstrap_di->getLoader(); |
|
124 | + } |
|
125 | 125 | |
126 | 126 | |
127 | - /** |
|
128 | - * configures the Domain object for core |
|
129 | - * |
|
130 | - * @return void |
|
131 | - * @throws DomainException |
|
132 | - * @throws InvalidArgumentException |
|
133 | - * @throws InvalidDataTypeException |
|
134 | - * @throws InvalidClassException |
|
135 | - * @throws InvalidFilePathException |
|
136 | - * @throws InvalidInterfaceException |
|
137 | - */ |
|
138 | - private function bootstrapDomain() |
|
139 | - { |
|
140 | - DomainFactory::getEventEspressoCoreDomain(); |
|
141 | - } |
|
127 | + /** |
|
128 | + * configures the Domain object for core |
|
129 | + * |
|
130 | + * @return void |
|
131 | + * @throws DomainException |
|
132 | + * @throws InvalidArgumentException |
|
133 | + * @throws InvalidDataTypeException |
|
134 | + * @throws InvalidClassException |
|
135 | + * @throws InvalidFilePathException |
|
136 | + * @throws InvalidInterfaceException |
|
137 | + */ |
|
138 | + private function bootstrapDomain() |
|
139 | + { |
|
140 | + DomainFactory::getEventEspressoCoreDomain(); |
|
141 | + } |
|
142 | 142 | |
143 | 143 | |
144 | - /** |
|
145 | - * sets up the request and response objects |
|
146 | - * |
|
147 | - * @return BootstrapRequestResponseObjects |
|
148 | - * @throws InvalidArgumentException |
|
149 | - */ |
|
150 | - private function bootstrapRequestResponseObjects(): BootstrapRequestResponseObjects |
|
151 | - { |
|
152 | - /** @var BootstrapRequestResponseObjects $bootstrap_request */ |
|
153 | - $bootstrap_request = $this->loader->getShared( |
|
154 | - 'EventEspresso\core\services\bootstrap\BootstrapRequestResponseObjects', |
|
155 | - [$this->loader] |
|
156 | - ); |
|
157 | - $bootstrap_request->buildRequestResponse(); |
|
158 | - $bootstrap_request->shareRequestResponse(); |
|
159 | - $this->request = $this->loader->getShared('EventEspresso\core\services\request\Request'); |
|
160 | - $this->response = $this->loader->getShared('EventEspresso\core\services\request\Response'); |
|
161 | - return $bootstrap_request; |
|
162 | - } |
|
144 | + /** |
|
145 | + * sets up the request and response objects |
|
146 | + * |
|
147 | + * @return BootstrapRequestResponseObjects |
|
148 | + * @throws InvalidArgumentException |
|
149 | + */ |
|
150 | + private function bootstrapRequestResponseObjects(): BootstrapRequestResponseObjects |
|
151 | + { |
|
152 | + /** @var BootstrapRequestResponseObjects $bootstrap_request */ |
|
153 | + $bootstrap_request = $this->loader->getShared( |
|
154 | + 'EventEspresso\core\services\bootstrap\BootstrapRequestResponseObjects', |
|
155 | + [$this->loader] |
|
156 | + ); |
|
157 | + $bootstrap_request->buildRequestResponse(); |
|
158 | + $bootstrap_request->shareRequestResponse(); |
|
159 | + $this->request = $this->loader->getShared('EventEspresso\core\services\request\Request'); |
|
160 | + $this->response = $this->loader->getShared('EventEspresso\core\services\request\Response'); |
|
161 | + return $bootstrap_request; |
|
162 | + } |
|
163 | 163 | |
164 | 164 | |
165 | - /** |
|
166 | - * run_request_stack |
|
167 | - * construct request stack and run middleware apps |
|
168 | - * |
|
169 | - * @throws EE_Error |
|
170 | - * @throws Exception |
|
171 | - * @throws Throwable |
|
172 | - */ |
|
173 | - public function runRequestStack() |
|
174 | - { |
|
175 | - $this->loadAutoloader(); |
|
176 | - $this->setAutoloadersForRequiredFiles(); |
|
177 | - $this->request_stack_builder = $this->buildRequestStack(); |
|
178 | - $this->request_stack = $this->request_stack_builder->resolve( |
|
179 | - new RequestStackCoreApp() |
|
180 | - ); |
|
181 | - $this->request_stack->handleRequest($this->request, $this->response); |
|
182 | - $this->request_stack->handleResponse(); |
|
183 | - } |
|
165 | + /** |
|
166 | + * run_request_stack |
|
167 | + * construct request stack and run middleware apps |
|
168 | + * |
|
169 | + * @throws EE_Error |
|
170 | + * @throws Exception |
|
171 | + * @throws Throwable |
|
172 | + */ |
|
173 | + public function runRequestStack() |
|
174 | + { |
|
175 | + $this->loadAutoloader(); |
|
176 | + $this->setAutoloadersForRequiredFiles(); |
|
177 | + $this->request_stack_builder = $this->buildRequestStack(); |
|
178 | + $this->request_stack = $this->request_stack_builder->resolve( |
|
179 | + new RequestStackCoreApp() |
|
180 | + ); |
|
181 | + $this->request_stack->handleRequest($this->request, $this->response); |
|
182 | + $this->request_stack->handleResponse(); |
|
183 | + } |
|
184 | 184 | |
185 | 185 | |
186 | - /** |
|
187 | - * load_autoloader |
|
188 | - * |
|
189 | - * @throws EE_Error |
|
190 | - */ |
|
191 | - protected function loadAutoloader() |
|
192 | - { |
|
193 | - // load interfaces |
|
194 | - espresso_load_required( |
|
195 | - 'EEH_Autoloader', |
|
196 | - EE_CORE . 'helpers/EEH_Autoloader.helper.php' |
|
197 | - ); |
|
198 | - EEH_Autoloader::instance(); |
|
199 | - } |
|
186 | + /** |
|
187 | + * load_autoloader |
|
188 | + * |
|
189 | + * @throws EE_Error |
|
190 | + */ |
|
191 | + protected function loadAutoloader() |
|
192 | + { |
|
193 | + // load interfaces |
|
194 | + espresso_load_required( |
|
195 | + 'EEH_Autoloader', |
|
196 | + EE_CORE . 'helpers/EEH_Autoloader.helper.php' |
|
197 | + ); |
|
198 | + EEH_Autoloader::instance(); |
|
199 | + } |
|
200 | 200 | |
201 | 201 | |
202 | - /** |
|
203 | - * load_required_files |
|
204 | - * |
|
205 | - * @throws EE_Error |
|
206 | - */ |
|
207 | - protected function setAutoloadersForRequiredFiles() |
|
208 | - { |
|
209 | - // load interfaces |
|
210 | - EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_CORE . 'interfaces', true); |
|
211 | - // load helpers |
|
212 | - EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_HELPERS); |
|
213 | - // register legacy request stack classes just in case |
|
214 | - EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_CORE . 'request_stack/'); |
|
215 | - // register legacy middleware classes just in case |
|
216 | - EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_CORE . 'middleware/'); |
|
217 | - } |
|
202 | + /** |
|
203 | + * load_required_files |
|
204 | + * |
|
205 | + * @throws EE_Error |
|
206 | + */ |
|
207 | + protected function setAutoloadersForRequiredFiles() |
|
208 | + { |
|
209 | + // load interfaces |
|
210 | + EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_CORE . 'interfaces', true); |
|
211 | + // load helpers |
|
212 | + EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_HELPERS); |
|
213 | + // register legacy request stack classes just in case |
|
214 | + EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_CORE . 'request_stack/'); |
|
215 | + // register legacy middleware classes just in case |
|
216 | + EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_CORE . 'middleware/'); |
|
217 | + } |
|
218 | 218 | |
219 | 219 | |
220 | - /** |
|
221 | - * build_request_stack |
|
222 | - * |
|
223 | - * @return RequestStackBuilder |
|
224 | - */ |
|
225 | - public function buildRequestStack(): RequestStackBuilder |
|
226 | - { |
|
227 | - $request_stack_builder = new RequestStackBuilder($this->loader); |
|
228 | - /** |
|
229 | - * ! IMPORTANT ! The middleware stack operates FILO : FIRST IN LAST OUT |
|
230 | - * so items at the beginning of the final middleware stack will run last. |
|
231 | - * First parameter is the middleware classname, second is an array of arguments |
|
232 | - */ |
|
233 | - $stack_apps = apply_filters( |
|
234 | - 'FHEE__EventEspresso_core_services_bootstrap_BootstrapCore__buildRequestStack__stack_apps', |
|
235 | - [ |
|
236 | - // first in last out |
|
237 | - BotDetector::class => [], |
|
238 | - DetectFileEditorRequest::class => [], |
|
239 | - PreProductionVersionWarning::class => [], |
|
240 | - RecommendedVersions::class => [], |
|
241 | - DetectLogin::class => [], |
|
242 | - // last in first out |
|
243 | - SkipRequests::class => [], |
|
244 | - ] |
|
245 | - ); |
|
246 | - // legacy filter for backwards compatibility |
|
247 | - $stack_apps = apply_filters( |
|
248 | - 'FHEE__EE_Bootstrap__build_request_stack__stack_apps', |
|
249 | - $stack_apps |
|
250 | - ); |
|
251 | - // load middleware onto stack : FILO (First In Last Out) |
|
252 | - // items at the beginning of the $stack_apps array will run last |
|
253 | - foreach ((array) $stack_apps as $stack_app => $stack_app_args) { |
|
254 | - $request_stack_builder->push([$stack_app, $stack_app_args]); |
|
255 | - } |
|
256 | - // finally, we'll add this on its own because we need it to always be part of the stack |
|
257 | - // and we also need it to always run first because the rest of the system relies on it |
|
258 | - $request_stack_builder->push( |
|
259 | - [SetRequestTypeContextChecker::class, []] |
|
260 | - ); |
|
261 | - return apply_filters( |
|
262 | - 'FHEE__EE_Bootstrap__build_request_stack__request_stack_builder', |
|
263 | - $request_stack_builder |
|
264 | - ); |
|
265 | - } |
|
220 | + /** |
|
221 | + * build_request_stack |
|
222 | + * |
|
223 | + * @return RequestStackBuilder |
|
224 | + */ |
|
225 | + public function buildRequestStack(): RequestStackBuilder |
|
226 | + { |
|
227 | + $request_stack_builder = new RequestStackBuilder($this->loader); |
|
228 | + /** |
|
229 | + * ! IMPORTANT ! The middleware stack operates FILO : FIRST IN LAST OUT |
|
230 | + * so items at the beginning of the final middleware stack will run last. |
|
231 | + * First parameter is the middleware classname, second is an array of arguments |
|
232 | + */ |
|
233 | + $stack_apps = apply_filters( |
|
234 | + 'FHEE__EventEspresso_core_services_bootstrap_BootstrapCore__buildRequestStack__stack_apps', |
|
235 | + [ |
|
236 | + // first in last out |
|
237 | + BotDetector::class => [], |
|
238 | + DetectFileEditorRequest::class => [], |
|
239 | + PreProductionVersionWarning::class => [], |
|
240 | + RecommendedVersions::class => [], |
|
241 | + DetectLogin::class => [], |
|
242 | + // last in first out |
|
243 | + SkipRequests::class => [], |
|
244 | + ] |
|
245 | + ); |
|
246 | + // legacy filter for backwards compatibility |
|
247 | + $stack_apps = apply_filters( |
|
248 | + 'FHEE__EE_Bootstrap__build_request_stack__stack_apps', |
|
249 | + $stack_apps |
|
250 | + ); |
|
251 | + // load middleware onto stack : FILO (First In Last Out) |
|
252 | + // items at the beginning of the $stack_apps array will run last |
|
253 | + foreach ((array) $stack_apps as $stack_app => $stack_app_args) { |
|
254 | + $request_stack_builder->push([$stack_app, $stack_app_args]); |
|
255 | + } |
|
256 | + // finally, we'll add this on its own because we need it to always be part of the stack |
|
257 | + // and we also need it to always run first because the rest of the system relies on it |
|
258 | + $request_stack_builder->push( |
|
259 | + [SetRequestTypeContextChecker::class, []] |
|
260 | + ); |
|
261 | + return apply_filters( |
|
262 | + 'FHEE__EE_Bootstrap__build_request_stack__request_stack_builder', |
|
263 | + $request_stack_builder |
|
264 | + ); |
|
265 | + } |
|
266 | 266 | } |
@@ -30,139 +30,139 @@ |
||
30 | 30 | */ |
31 | 31 | abstract class EEE_Base_Class |
32 | 32 | { |
33 | - const extending_method_prefix = 'ext_'; |
|
33 | + const extending_method_prefix = 'ext_'; |
|
34 | 34 | |
35 | - const dynamic_callback_method_prefix = 'dynamic_callback_method_'; |
|
35 | + const dynamic_callback_method_prefix = 'dynamic_callback_method_'; |
|
36 | 36 | |
37 | - /** |
|
38 | - * The model name that is extended (not classname) |
|
39 | - * |
|
40 | - * @var string |
|
41 | - */ |
|
42 | - protected string $_model_name_extended = ''; |
|
37 | + /** |
|
38 | + * The model name that is extended (not classname) |
|
39 | + * |
|
40 | + * @var string |
|
41 | + */ |
|
42 | + protected string $_model_name_extended = ''; |
|
43 | 43 | |
44 | - /** |
|
45 | - * The model this extends |
|
46 | - * |
|
47 | - * @var EE_Base_Class|null |
|
48 | - */ |
|
49 | - protected $_ = null; |
|
44 | + /** |
|
45 | + * The model this extends |
|
46 | + * |
|
47 | + * @var EE_Base_Class|null |
|
48 | + */ |
|
49 | + protected $_ = null; |
|
50 | 50 | |
51 | 51 | |
52 | - /** |
|
53 | - * @throws EE_Error |
|
54 | - */ |
|
55 | - public function __construct(?string $model_name_extended = '') |
|
56 | - { |
|
57 | - if ($model_name_extended) { |
|
58 | - // setting this inside a conditional for backwards compatibility |
|
59 | - // because non-updated child classes may set the property directly and not pass to this constructor |
|
60 | - $this->_model_name_extended = $model_name_extended; |
|
61 | - } |
|
62 | - if (! $this->_model_name_extended) { |
|
63 | - throw new EE_Error( |
|
64 | - // not translated because this is happening prior to the WP init hook when translations are set up |
|
65 | - "When declaring a class extension, you must define its _model_name_extended property. It should be a model name like 'Attendee' or 'Event'", |
|
66 | - ); |
|
67 | - } |
|
68 | - if (did_action('AHEE__EE_' . $this->_model_name_extended . '__construct__end')) { |
|
69 | - throw new EE_Error( |
|
70 | - sprintf( |
|
71 | - "Hooked in model object extension '%s' too late! The model object %s has already been used!", |
|
72 | - get_class($this), |
|
73 | - $this->_model_name_extended |
|
74 | - ) |
|
75 | - ); |
|
76 | - } |
|
52 | + /** |
|
53 | + * @throws EE_Error |
|
54 | + */ |
|
55 | + public function __construct(?string $model_name_extended = '') |
|
56 | + { |
|
57 | + if ($model_name_extended) { |
|
58 | + // setting this inside a conditional for backwards compatibility |
|
59 | + // because non-updated child classes may set the property directly and not pass to this constructor |
|
60 | + $this->_model_name_extended = $model_name_extended; |
|
61 | + } |
|
62 | + if (! $this->_model_name_extended) { |
|
63 | + throw new EE_Error( |
|
64 | + // not translated because this is happening prior to the WP init hook when translations are set up |
|
65 | + "When declaring a class extension, you must define its _model_name_extended property. It should be a model name like 'Attendee' or 'Event'", |
|
66 | + ); |
|
67 | + } |
|
68 | + if (did_action('AHEE__EE_' . $this->_model_name_extended . '__construct__end')) { |
|
69 | + throw new EE_Error( |
|
70 | + sprintf( |
|
71 | + "Hooked in model object extension '%s' too late! The model object %s has already been used!", |
|
72 | + get_class($this), |
|
73 | + $this->_model_name_extended |
|
74 | + ) |
|
75 | + ); |
|
76 | + } |
|
77 | 77 | |
78 | - add_action("AHEE__EE_{$this->_model_name_extended}__construct", [$this, 'extendBaseClass']); |
|
79 | - } |
|
78 | + add_action("AHEE__EE_{$this->_model_name_extended}__construct", [$this, 'extendBaseClass']); |
|
79 | + } |
|
80 | 80 | |
81 | 81 | |
82 | - public function extendBaseClass() |
|
83 | - { |
|
84 | - $this->_register_extending_methods(); |
|
85 | - } |
|
82 | + public function extendBaseClass() |
|
83 | + { |
|
84 | + $this->_register_extending_methods(); |
|
85 | + } |
|
86 | 86 | |
87 | 87 | |
88 | - /** |
|
89 | - * scans the child of EEME_Base for functions starting with ext_, and magically makes them functions on the |
|
90 | - * model extended. (Internally uses filters, and the __call magic method) |
|
91 | - */ |
|
92 | - protected function _register_extending_methods() |
|
93 | - { |
|
94 | - $all_methods = get_class_methods(get_class($this)); |
|
95 | - foreach ($all_methods as $method_name) { |
|
96 | - if (strpos($method_name, self::extending_method_prefix) === 0) { |
|
97 | - $method_name_on_model = str_replace(self::extending_method_prefix, '', $method_name); |
|
98 | - $callback_name = "FHEE__EE_{$this->_model_name_extended}__$method_name_on_model"; |
|
99 | - add_filter( |
|
100 | - $callback_name, |
|
101 | - [$this, self::dynamic_callback_method_prefix . $method_name_on_model], |
|
102 | - 10, |
|
103 | - 10 |
|
104 | - ); |
|
105 | - } |
|
106 | - } |
|
107 | - } |
|
88 | + /** |
|
89 | + * scans the child of EEME_Base for functions starting with ext_, and magically makes them functions on the |
|
90 | + * model extended. (Internally uses filters, and the __call magic method) |
|
91 | + */ |
|
92 | + protected function _register_extending_methods() |
|
93 | + { |
|
94 | + $all_methods = get_class_methods(get_class($this)); |
|
95 | + foreach ($all_methods as $method_name) { |
|
96 | + if (strpos($method_name, self::extending_method_prefix) === 0) { |
|
97 | + $method_name_on_model = str_replace(self::extending_method_prefix, '', $method_name); |
|
98 | + $callback_name = "FHEE__EE_{$this->_model_name_extended}__$method_name_on_model"; |
|
99 | + add_filter( |
|
100 | + $callback_name, |
|
101 | + [$this, self::dynamic_callback_method_prefix . $method_name_on_model], |
|
102 | + 10, |
|
103 | + 10 |
|
104 | + ); |
|
105 | + } |
|
106 | + } |
|
107 | + } |
|
108 | 108 | |
109 | 109 | |
110 | - /** |
|
111 | - * scans the child of EEME_Base for functions starting with ext_, and magically REMOVES them as functions on the |
|
112 | - * model extended. (Internally uses filters, and the __call magic method) |
|
113 | - */ |
|
114 | - public function deregister() |
|
115 | - { |
|
116 | - $all_methods = get_class_methods(get_class($this)); |
|
117 | - foreach ($all_methods as $method_name) { |
|
118 | - if (strpos($method_name, self::extending_method_prefix) === 0) { |
|
119 | - $method_name_on_model = str_replace(self::extending_method_prefix, '', $method_name); |
|
120 | - $callback_name = "FHEE__EE_{$this->_model_name_extended}__$method_name_on_model"; |
|
121 | - remove_filter( |
|
122 | - $callback_name, |
|
123 | - [$this, self::dynamic_callback_method_prefix . $method_name_on_model] |
|
124 | - ); |
|
125 | - } |
|
126 | - } |
|
127 | - } |
|
110 | + /** |
|
111 | + * scans the child of EEME_Base for functions starting with ext_, and magically REMOVES them as functions on the |
|
112 | + * model extended. (Internally uses filters, and the __call magic method) |
|
113 | + */ |
|
114 | + public function deregister() |
|
115 | + { |
|
116 | + $all_methods = get_class_methods(get_class($this)); |
|
117 | + foreach ($all_methods as $method_name) { |
|
118 | + if (strpos($method_name, self::extending_method_prefix) === 0) { |
|
119 | + $method_name_on_model = str_replace(self::extending_method_prefix, '', $method_name); |
|
120 | + $callback_name = "FHEE__EE_{$this->_model_name_extended}__$method_name_on_model"; |
|
121 | + remove_filter( |
|
122 | + $callback_name, |
|
123 | + [$this, self::dynamic_callback_method_prefix . $method_name_on_model] |
|
124 | + ); |
|
125 | + } |
|
126 | + } |
|
127 | + } |
|
128 | 128 | |
129 | 129 | |
130 | - /** |
|
131 | - * @throws EE_Error |
|
132 | - */ |
|
133 | - public function __call($callback_method_name, $args) |
|
134 | - { |
|
135 | - if (strpos($callback_method_name, self::dynamic_callback_method_prefix) === 0) { |
|
136 | - // it's a dynamic callback for a method name |
|
137 | - $method_called_on_model = str_replace(self::dynamic_callback_method_prefix, '', $callback_method_name); |
|
138 | - $model_called = $args[1]; |
|
139 | - // phpcs:disable WordPress.WP.I18n.SingleUnderscoreGetTextFunction |
|
140 | - $this->_ = $model_called; |
|
141 | - // phpcs:enable |
|
142 | - $args_provided_to_method_on_model = $args[2]; |
|
143 | - $extending_method = self::extending_method_prefix . $method_called_on_model; |
|
144 | - if (method_exists($this, $extending_method)) { |
|
145 | - return call_user_func_array([$this, $extending_method], $args_provided_to_method_on_model); |
|
146 | - } |
|
147 | - throw new EE_Error( |
|
148 | - sprintf( |
|
149 | - esc_html__( |
|
150 | - "An odd error occurred. Model '%s' had a method called on it that it didn't recognize. So it passed it onto the model extension '%s' (because it had a function named '%s' which should be able to handle it), but the function '%s' doesnt exist!)", |
|
151 | - "event_espresso" |
|
152 | - ), |
|
153 | - $this->_model_name_extended, |
|
154 | - get_class($this), |
|
155 | - $extending_method, |
|
156 | - $extending_method |
|
157 | - ) |
|
158 | - ); |
|
159 | - } |
|
160 | - throw new EE_Error( |
|
161 | - sprintf( |
|
162 | - esc_html__("There is no method named '%s' on '%s'", "event_espresso"), |
|
163 | - $callback_method_name, |
|
164 | - get_class($this) |
|
165 | - ) |
|
166 | - ); |
|
167 | - } |
|
130 | + /** |
|
131 | + * @throws EE_Error |
|
132 | + */ |
|
133 | + public function __call($callback_method_name, $args) |
|
134 | + { |
|
135 | + if (strpos($callback_method_name, self::dynamic_callback_method_prefix) === 0) { |
|
136 | + // it's a dynamic callback for a method name |
|
137 | + $method_called_on_model = str_replace(self::dynamic_callback_method_prefix, '', $callback_method_name); |
|
138 | + $model_called = $args[1]; |
|
139 | + // phpcs:disable WordPress.WP.I18n.SingleUnderscoreGetTextFunction |
|
140 | + $this->_ = $model_called; |
|
141 | + // phpcs:enable |
|
142 | + $args_provided_to_method_on_model = $args[2]; |
|
143 | + $extending_method = self::extending_method_prefix . $method_called_on_model; |
|
144 | + if (method_exists($this, $extending_method)) { |
|
145 | + return call_user_func_array([$this, $extending_method], $args_provided_to_method_on_model); |
|
146 | + } |
|
147 | + throw new EE_Error( |
|
148 | + sprintf( |
|
149 | + esc_html__( |
|
150 | + "An odd error occurred. Model '%s' had a method called on it that it didn't recognize. So it passed it onto the model extension '%s' (because it had a function named '%s' which should be able to handle it), but the function '%s' doesnt exist!)", |
|
151 | + "event_espresso" |
|
152 | + ), |
|
153 | + $this->_model_name_extended, |
|
154 | + get_class($this), |
|
155 | + $extending_method, |
|
156 | + $extending_method |
|
157 | + ) |
|
158 | + ); |
|
159 | + } |
|
160 | + throw new EE_Error( |
|
161 | + sprintf( |
|
162 | + esc_html__("There is no method named '%s' on '%s'", "event_espresso"), |
|
163 | + $callback_method_name, |
|
164 | + get_class($this) |
|
165 | + ) |
|
166 | + ); |
|
167 | + } |
|
168 | 168 | } |
@@ -59,13 +59,13 @@ discard block |
||
59 | 59 | // because non-updated child classes may set the property directly and not pass to this constructor |
60 | 60 | $this->_model_name_extended = $model_name_extended; |
61 | 61 | } |
62 | - if (! $this->_model_name_extended) { |
|
62 | + if ( ! $this->_model_name_extended) { |
|
63 | 63 | throw new EE_Error( |
64 | 64 | // not translated because this is happening prior to the WP init hook when translations are set up |
65 | 65 | "When declaring a class extension, you must define its _model_name_extended property. It should be a model name like 'Attendee' or 'Event'", |
66 | 66 | ); |
67 | 67 | } |
68 | - if (did_action('AHEE__EE_' . $this->_model_name_extended . '__construct__end')) { |
|
68 | + if (did_action('AHEE__EE_'.$this->_model_name_extended.'__construct__end')) { |
|
69 | 69 | throw new EE_Error( |
70 | 70 | sprintf( |
71 | 71 | "Hooked in model object extension '%s' too late! The model object %s has already been used!", |
@@ -98,7 +98,7 @@ discard block |
||
98 | 98 | $callback_name = "FHEE__EE_{$this->_model_name_extended}__$method_name_on_model"; |
99 | 99 | add_filter( |
100 | 100 | $callback_name, |
101 | - [$this, self::dynamic_callback_method_prefix . $method_name_on_model], |
|
101 | + [$this, self::dynamic_callback_method_prefix.$method_name_on_model], |
|
102 | 102 | 10, |
103 | 103 | 10 |
104 | 104 | ); |
@@ -120,7 +120,7 @@ discard block |
||
120 | 120 | $callback_name = "FHEE__EE_{$this->_model_name_extended}__$method_name_on_model"; |
121 | 121 | remove_filter( |
122 | 122 | $callback_name, |
123 | - [$this, self::dynamic_callback_method_prefix . $method_name_on_model] |
|
123 | + [$this, self::dynamic_callback_method_prefix.$method_name_on_model] |
|
124 | 124 | ); |
125 | 125 | } |
126 | 126 | } |
@@ -140,7 +140,7 @@ discard block |
||
140 | 140 | $this->_ = $model_called; |
141 | 141 | // phpcs:enable |
142 | 142 | $args_provided_to_method_on_model = $args[2]; |
143 | - $extending_method = self::extending_method_prefix . $method_called_on_model; |
|
143 | + $extending_method = self::extending_method_prefix.$method_called_on_model; |
|
144 | 144 | if (method_exists($this, $extending_method)) { |
145 | 145 | return call_user_func_array([$this, $extending_method], $args_provided_to_method_on_model); |
146 | 146 | } |
@@ -65,237 +65,237 @@ |
||
65 | 65 | */ |
66 | 66 | abstract class EEME_Base |
67 | 67 | { |
68 | - const extending_method_prefix = 'ext_'; |
|
68 | + const extending_method_prefix = 'ext_'; |
|
69 | 69 | |
70 | - const dynamic_callback_method_prefix = 'dynamic_callback_method_'; |
|
70 | + const dynamic_callback_method_prefix = 'dynamic_callback_method_'; |
|
71 | 71 | |
72 | - protected array $_extra_tables = []; |
|
72 | + protected array $_extra_tables = []; |
|
73 | 73 | |
74 | - protected array $_extra_fields = []; |
|
74 | + protected array $_extra_fields = []; |
|
75 | 75 | |
76 | - protected array $_extra_relations = []; |
|
76 | + protected array $_extra_relations = []; |
|
77 | 77 | |
78 | - /** |
|
79 | - * The model name that is extended (not classname) |
|
80 | - * |
|
81 | - * @var string |
|
82 | - */ |
|
83 | - protected string $_model_name_extended = ''; |
|
78 | + /** |
|
79 | + * The model name that is extended (not classname) |
|
80 | + * |
|
81 | + * @var string |
|
82 | + */ |
|
83 | + protected string $_model_name_extended = ''; |
|
84 | 84 | |
85 | - /** |
|
86 | - * The model this extends |
|
87 | - * |
|
88 | - * @var EEM_Base|null |
|
89 | - */ |
|
90 | - protected $_ = null; |
|
85 | + /** |
|
86 | + * The model this extends |
|
87 | + * |
|
88 | + * @var EEM_Base|null |
|
89 | + */ |
|
90 | + protected $_ = null; |
|
91 | 91 | |
92 | 92 | |
93 | - /** |
|
94 | - * @throws EE_Error |
|
95 | - */ |
|
96 | - public function __construct(?string $model_name_extended = '') |
|
97 | - { |
|
98 | - if ($model_name_extended) { |
|
99 | - // setting this inside a conditional for backwards compatibility |
|
100 | - // because non-updated child classes may set the property directly and not pass to this constructor |
|
101 | - $this->_model_name_extended = $model_name_extended; |
|
102 | - } |
|
103 | - if (! $this->_model_name_extended) { |
|
104 | - throw new EE_Error( |
|
105 | - // not translated because this is happening prior to the WP init hook when translations are set up |
|
106 | - "When declaring a model extension, you must define its _model_name_extended property. It should be a model name like 'Attendee' or 'Event'" |
|
107 | - ); |
|
108 | - } |
|
109 | - $construct_end_action = "AHEE__EEM_{$this->_model_name_extended}__construct__end"; |
|
110 | - if (did_action($construct_end_action)) { |
|
111 | - throw new EE_Error( |
|
112 | - sprintf( |
|
113 | - "Hooked in model extension '%s' too late! The model %s has already been used! We know because the action %s has been fired", |
|
114 | - get_class($this), |
|
115 | - $this->_model_name_extended, |
|
116 | - $construct_end_action |
|
117 | - ) |
|
118 | - ); |
|
119 | - } |
|
120 | - add_action("AHEE__EEM_{$this->_model_name_extended}__instance__before_construct", [$this, 'extendModel']); |
|
121 | - } |
|
93 | + /** |
|
94 | + * @throws EE_Error |
|
95 | + */ |
|
96 | + public function __construct(?string $model_name_extended = '') |
|
97 | + { |
|
98 | + if ($model_name_extended) { |
|
99 | + // setting this inside a conditional for backwards compatibility |
|
100 | + // because non-updated child classes may set the property directly and not pass to this constructor |
|
101 | + $this->_model_name_extended = $model_name_extended; |
|
102 | + } |
|
103 | + if (! $this->_model_name_extended) { |
|
104 | + throw new EE_Error( |
|
105 | + // not translated because this is happening prior to the WP init hook when translations are set up |
|
106 | + "When declaring a model extension, you must define its _model_name_extended property. It should be a model name like 'Attendee' or 'Event'" |
|
107 | + ); |
|
108 | + } |
|
109 | + $construct_end_action = "AHEE__EEM_{$this->_model_name_extended}__construct__end"; |
|
110 | + if (did_action($construct_end_action)) { |
|
111 | + throw new EE_Error( |
|
112 | + sprintf( |
|
113 | + "Hooked in model extension '%s' too late! The model %s has already been used! We know because the action %s has been fired", |
|
114 | + get_class($this), |
|
115 | + $this->_model_name_extended, |
|
116 | + $construct_end_action |
|
117 | + ) |
|
118 | + ); |
|
119 | + } |
|
120 | + add_action("AHEE__EEM_{$this->_model_name_extended}__instance__before_construct", [$this, 'extendModel']); |
|
121 | + } |
|
122 | 122 | |
123 | 123 | |
124 | - /** |
|
125 | - * Used to populate the $_extra_tables, $_extra_fields, and $_extra_relations arrays; |
|
126 | - * |
|
127 | - * @return void |
|
128 | - * @since 5.0.42 |
|
129 | - */ |
|
130 | - public function registerExtensions() { |
|
131 | - // Intentionally left blank, child classes should override this method to populate the arrays |
|
132 | - // with their own values. |
|
133 | - // For example: |
|
134 | - // $this->_extra_tables = [...]; |
|
135 | - // $this->_extra_fields = [...]; |
|
136 | - // $this->_extra_relations = [...]; |
|
137 | - } |
|
124 | + /** |
|
125 | + * Used to populate the $_extra_tables, $_extra_fields, and $_extra_relations arrays; |
|
126 | + * |
|
127 | + * @return void |
|
128 | + * @since 5.0.42 |
|
129 | + */ |
|
130 | + public function registerExtensions() { |
|
131 | + // Intentionally left blank, child classes should override this method to populate the arrays |
|
132 | + // with their own values. |
|
133 | + // For example: |
|
134 | + // $this->_extra_tables = [...]; |
|
135 | + // $this->_extra_fields = [...]; |
|
136 | + // $this->_extra_relations = [...]; |
|
137 | + } |
|
138 | 138 | |
139 | 139 | |
140 | - public function extendModel() |
|
141 | - { |
|
142 | - $this->registerExtensions(); |
|
143 | - add_filter( |
|
144 | - "FHEE__EEM_{$this->_model_name_extended}__construct__tables", |
|
145 | - [$this, 'add_extra_tables_on_filter'] |
|
146 | - ); |
|
147 | - add_filter( |
|
148 | - "FHEE__EEM_{$this->_model_name_extended}__construct__fields", |
|
149 | - [$this, 'add_extra_fields_on_filter'] |
|
150 | - ); |
|
151 | - add_filter( |
|
152 | - "FHEE__EEM_{$this->_model_name_extended}__construct__model_relations", |
|
153 | - [$this, 'add_extra_relations_on_filter'] |
|
154 | - ); |
|
155 | - $this->_register_extending_methods(); |
|
156 | - } |
|
140 | + public function extendModel() |
|
141 | + { |
|
142 | + $this->registerExtensions(); |
|
143 | + add_filter( |
|
144 | + "FHEE__EEM_{$this->_model_name_extended}__construct__tables", |
|
145 | + [$this, 'add_extra_tables_on_filter'] |
|
146 | + ); |
|
147 | + add_filter( |
|
148 | + "FHEE__EEM_{$this->_model_name_extended}__construct__fields", |
|
149 | + [$this, 'add_extra_fields_on_filter'] |
|
150 | + ); |
|
151 | + add_filter( |
|
152 | + "FHEE__EEM_{$this->_model_name_extended}__construct__model_relations", |
|
153 | + [$this, 'add_extra_relations_on_filter'] |
|
154 | + ); |
|
155 | + $this->_register_extending_methods(); |
|
156 | + } |
|
157 | 157 | |
158 | 158 | |
159 | - /** |
|
160 | - * @param array $existing_tables |
|
161 | - * @return array |
|
162 | - */ |
|
163 | - public function add_extra_tables_on_filter($existing_tables) |
|
164 | - { |
|
165 | - return array_merge($existing_tables, $this->_extra_tables); |
|
166 | - } |
|
159 | + /** |
|
160 | + * @param array $existing_tables |
|
161 | + * @return array |
|
162 | + */ |
|
163 | + public function add_extra_tables_on_filter($existing_tables) |
|
164 | + { |
|
165 | + return array_merge($existing_tables, $this->_extra_tables); |
|
166 | + } |
|
167 | 167 | |
168 | 168 | |
169 | - /** |
|
170 | - * @param array $existing_fields |
|
171 | - * @return array |
|
172 | - */ |
|
173 | - public function add_extra_fields_on_filter($existing_fields) |
|
174 | - { |
|
175 | - if ($this->_extra_fields) { |
|
176 | - foreach ($this->_extra_fields as $table_alias => $fields) { |
|
177 | - if (! isset($existing_fields[ $table_alias ])) { |
|
178 | - $existing_fields[ $table_alias ] = []; |
|
179 | - } |
|
180 | - $existing_fields[ $table_alias ] = array_merge( |
|
181 | - (array) $existing_fields[ $table_alias ], |
|
182 | - $this->_extra_fields[ $table_alias ] |
|
183 | - ); |
|
184 | - } |
|
185 | - } |
|
186 | - return $existing_fields; |
|
187 | - } |
|
169 | + /** |
|
170 | + * @param array $existing_fields |
|
171 | + * @return array |
|
172 | + */ |
|
173 | + public function add_extra_fields_on_filter($existing_fields) |
|
174 | + { |
|
175 | + if ($this->_extra_fields) { |
|
176 | + foreach ($this->_extra_fields as $table_alias => $fields) { |
|
177 | + if (! isset($existing_fields[ $table_alias ])) { |
|
178 | + $existing_fields[ $table_alias ] = []; |
|
179 | + } |
|
180 | + $existing_fields[ $table_alias ] = array_merge( |
|
181 | + (array) $existing_fields[ $table_alias ], |
|
182 | + $this->_extra_fields[ $table_alias ] |
|
183 | + ); |
|
184 | + } |
|
185 | + } |
|
186 | + return $existing_fields; |
|
187 | + } |
|
188 | 188 | |
189 | 189 | |
190 | - /** |
|
191 | - * @param array $existing_relations |
|
192 | - * @return array |
|
193 | - */ |
|
194 | - public function add_extra_relations_on_filter($existing_relations) |
|
195 | - { |
|
196 | - return array_merge($existing_relations, $this->_extra_relations); |
|
197 | - } |
|
190 | + /** |
|
191 | + * @param array $existing_relations |
|
192 | + * @return array |
|
193 | + */ |
|
194 | + public function add_extra_relations_on_filter($existing_relations) |
|
195 | + { |
|
196 | + return array_merge($existing_relations, $this->_extra_relations); |
|
197 | + } |
|
198 | 198 | |
199 | 199 | |
200 | - /** |
|
201 | - * scans the child of EEME_Base for functions starting with ext_, and magically makes them functions on the |
|
202 | - * model extended. (Internally uses filters, and the __call magic method) |
|
203 | - */ |
|
204 | - protected function _register_extending_methods() |
|
205 | - { |
|
206 | - $all_methods = get_class_methods(get_class($this)); |
|
207 | - foreach ($all_methods as $method_name) { |
|
208 | - if (strpos($method_name, self::extending_method_prefix) === 0) { |
|
209 | - $method_name_on_model = str_replace(self::extending_method_prefix, '', $method_name); |
|
210 | - $callback_name = "FHEE__EEM_{$this->_model_name_extended}__$method_name_on_model"; |
|
211 | - add_filter( |
|
212 | - $callback_name, |
|
213 | - [$this, self::dynamic_callback_method_prefix . $method_name_on_model], |
|
214 | - 10, |
|
215 | - 10 |
|
216 | - ); |
|
217 | - } |
|
218 | - } |
|
219 | - } |
|
200 | + /** |
|
201 | + * scans the child of EEME_Base for functions starting with ext_, and magically makes them functions on the |
|
202 | + * model extended. (Internally uses filters, and the __call magic method) |
|
203 | + */ |
|
204 | + protected function _register_extending_methods() |
|
205 | + { |
|
206 | + $all_methods = get_class_methods(get_class($this)); |
|
207 | + foreach ($all_methods as $method_name) { |
|
208 | + if (strpos($method_name, self::extending_method_prefix) === 0) { |
|
209 | + $method_name_on_model = str_replace(self::extending_method_prefix, '', $method_name); |
|
210 | + $callback_name = "FHEE__EEM_{$this->_model_name_extended}__$method_name_on_model"; |
|
211 | + add_filter( |
|
212 | + $callback_name, |
|
213 | + [$this, self::dynamic_callback_method_prefix . $method_name_on_model], |
|
214 | + 10, |
|
215 | + 10 |
|
216 | + ); |
|
217 | + } |
|
218 | + } |
|
219 | + } |
|
220 | 220 | |
221 | 221 | |
222 | - /** |
|
223 | - * scans the child of EEME_Base for functions starting with ext_, and magically REMOVES them as functions on the |
|
224 | - * model extended. (Internally uses filters, and the __call magic method) |
|
225 | - */ |
|
226 | - public function deregister() |
|
227 | - { |
|
228 | - remove_filter( |
|
229 | - "FHEE__EEM_{$this->_model_name_extended}__construct__tables", |
|
230 | - [$this, 'add_extra_tables_on_filter'] |
|
231 | - ); |
|
232 | - remove_filter( |
|
233 | - "FHEE__EEM_{$this->_model_name_extended}__construct__fields", |
|
234 | - [$this, 'add_extra_fields_on_filter'] |
|
235 | - ); |
|
236 | - remove_filter( |
|
237 | - "FHEE__EEM_{$this->_model_name_extended}__construct__model_relations", |
|
238 | - [$this, 'add_extra_relations_on_filter'] |
|
239 | - ); |
|
240 | - $all_methods = get_class_methods(get_class($this)); |
|
241 | - foreach ($all_methods as $method_name) { |
|
242 | - if (strpos($method_name, self::extending_method_prefix) === 0) { |
|
243 | - $method_name_on_model = str_replace(self::extending_method_prefix, '', $method_name); |
|
244 | - $callback_name = "FHEE__EEM_{$this->_model_name_extended}__$method_name_on_model"; |
|
245 | - remove_filter( |
|
246 | - $callback_name, |
|
247 | - [$this, self::dynamic_callback_method_prefix . $method_name_on_model] |
|
248 | - ); |
|
249 | - } |
|
250 | - } |
|
251 | - $model_to_reset = "EEM_$this->_model_name_extended"; |
|
252 | - if (class_exists($model_to_reset)) { |
|
253 | - $model_to_reset::reset(); |
|
254 | - } |
|
255 | - } |
|
222 | + /** |
|
223 | + * scans the child of EEME_Base for functions starting with ext_, and magically REMOVES them as functions on the |
|
224 | + * model extended. (Internally uses filters, and the __call magic method) |
|
225 | + */ |
|
226 | + public function deregister() |
|
227 | + { |
|
228 | + remove_filter( |
|
229 | + "FHEE__EEM_{$this->_model_name_extended}__construct__tables", |
|
230 | + [$this, 'add_extra_tables_on_filter'] |
|
231 | + ); |
|
232 | + remove_filter( |
|
233 | + "FHEE__EEM_{$this->_model_name_extended}__construct__fields", |
|
234 | + [$this, 'add_extra_fields_on_filter'] |
|
235 | + ); |
|
236 | + remove_filter( |
|
237 | + "FHEE__EEM_{$this->_model_name_extended}__construct__model_relations", |
|
238 | + [$this, 'add_extra_relations_on_filter'] |
|
239 | + ); |
|
240 | + $all_methods = get_class_methods(get_class($this)); |
|
241 | + foreach ($all_methods as $method_name) { |
|
242 | + if (strpos($method_name, self::extending_method_prefix) === 0) { |
|
243 | + $method_name_on_model = str_replace(self::extending_method_prefix, '', $method_name); |
|
244 | + $callback_name = "FHEE__EEM_{$this->_model_name_extended}__$method_name_on_model"; |
|
245 | + remove_filter( |
|
246 | + $callback_name, |
|
247 | + [$this, self::dynamic_callback_method_prefix . $method_name_on_model] |
|
248 | + ); |
|
249 | + } |
|
250 | + } |
|
251 | + $model_to_reset = "EEM_$this->_model_name_extended"; |
|
252 | + if (class_exists($model_to_reset)) { |
|
253 | + $model_to_reset::reset(); |
|
254 | + } |
|
255 | + } |
|
256 | 256 | |
257 | 257 | |
258 | - /** |
|
259 | - * @param string $callback_method_name |
|
260 | - * @param array $args |
|
261 | - * @return mixed |
|
262 | - * @throws EE_Error |
|
263 | - */ |
|
264 | - public function __call(string $callback_method_name, array $args) |
|
265 | - { |
|
266 | - if (strpos($callback_method_name, self::dynamic_callback_method_prefix) === 0) { |
|
267 | - // it's a dynamic callback for a method name |
|
268 | - $method_called_on_model = str_replace(self::dynamic_callback_method_prefix, '', $callback_method_name); |
|
269 | - // intentionally skipping first array element, ie: [, is correct |
|
270 | - [, $model_called, $args_provided_to_method_on_model] = $args; |
|
271 | - // phpcs:disable WordPress.WP.I18n.SingleUnderscoreGetTextFunction |
|
272 | - $this->_ = $model_called; |
|
273 | - // phpcs:enable |
|
274 | - $extending_method = self::extending_method_prefix . $method_called_on_model; |
|
275 | - if (method_exists($this, $extending_method)) { |
|
276 | - return call_user_func_array([$this, $extending_method], $args_provided_to_method_on_model); |
|
277 | - } else { |
|
278 | - throw new EE_Error( |
|
279 | - sprintf( |
|
280 | - esc_html__( |
|
281 | - "An odd error occurred. Model '%s' had a method called on it that it didn't recognize. So it passed it onto the model extension '%s' (because it had a function named '%s' which should be able to handle it), but the function '%s' doesnt exist!)", |
|
282 | - "event_espresso" |
|
283 | - ), |
|
284 | - $this->_model_name_extended, |
|
285 | - get_class($this), |
|
286 | - $extending_method, |
|
287 | - $extending_method |
|
288 | - ) |
|
289 | - ); |
|
290 | - } |
|
291 | - } else { |
|
292 | - throw new EE_Error( |
|
293 | - sprintf( |
|
294 | - esc_html__("There is no method named '%s' on '%s'", "event_espresso"), |
|
295 | - $callback_method_name, |
|
296 | - get_class($this) |
|
297 | - ) |
|
298 | - ); |
|
299 | - } |
|
300 | - } |
|
258 | + /** |
|
259 | + * @param string $callback_method_name |
|
260 | + * @param array $args |
|
261 | + * @return mixed |
|
262 | + * @throws EE_Error |
|
263 | + */ |
|
264 | + public function __call(string $callback_method_name, array $args) |
|
265 | + { |
|
266 | + if (strpos($callback_method_name, self::dynamic_callback_method_prefix) === 0) { |
|
267 | + // it's a dynamic callback for a method name |
|
268 | + $method_called_on_model = str_replace(self::dynamic_callback_method_prefix, '', $callback_method_name); |
|
269 | + // intentionally skipping first array element, ie: [, is correct |
|
270 | + [, $model_called, $args_provided_to_method_on_model] = $args; |
|
271 | + // phpcs:disable WordPress.WP.I18n.SingleUnderscoreGetTextFunction |
|
272 | + $this->_ = $model_called; |
|
273 | + // phpcs:enable |
|
274 | + $extending_method = self::extending_method_prefix . $method_called_on_model; |
|
275 | + if (method_exists($this, $extending_method)) { |
|
276 | + return call_user_func_array([$this, $extending_method], $args_provided_to_method_on_model); |
|
277 | + } else { |
|
278 | + throw new EE_Error( |
|
279 | + sprintf( |
|
280 | + esc_html__( |
|
281 | + "An odd error occurred. Model '%s' had a method called on it that it didn't recognize. So it passed it onto the model extension '%s' (because it had a function named '%s' which should be able to handle it), but the function '%s' doesnt exist!)", |
|
282 | + "event_espresso" |
|
283 | + ), |
|
284 | + $this->_model_name_extended, |
|
285 | + get_class($this), |
|
286 | + $extending_method, |
|
287 | + $extending_method |
|
288 | + ) |
|
289 | + ); |
|
290 | + } |
|
291 | + } else { |
|
292 | + throw new EE_Error( |
|
293 | + sprintf( |
|
294 | + esc_html__("There is no method named '%s' on '%s'", "event_espresso"), |
|
295 | + $callback_method_name, |
|
296 | + get_class($this) |
|
297 | + ) |
|
298 | + ); |
|
299 | + } |
|
300 | + } |
|
301 | 301 | } |
@@ -100,7 +100,7 @@ discard block |
||
100 | 100 | // because non-updated child classes may set the property directly and not pass to this constructor |
101 | 101 | $this->_model_name_extended = $model_name_extended; |
102 | 102 | } |
103 | - if (! $this->_model_name_extended) { |
|
103 | + if ( ! $this->_model_name_extended) { |
|
104 | 104 | throw new EE_Error( |
105 | 105 | // not translated because this is happening prior to the WP init hook when translations are set up |
106 | 106 | "When declaring a model extension, you must define its _model_name_extended property. It should be a model name like 'Attendee' or 'Event'" |
@@ -174,12 +174,12 @@ discard block |
||
174 | 174 | { |
175 | 175 | if ($this->_extra_fields) { |
176 | 176 | foreach ($this->_extra_fields as $table_alias => $fields) { |
177 | - if (! isset($existing_fields[ $table_alias ])) { |
|
178 | - $existing_fields[ $table_alias ] = []; |
|
177 | + if ( ! isset($existing_fields[$table_alias])) { |
|
178 | + $existing_fields[$table_alias] = []; |
|
179 | 179 | } |
180 | - $existing_fields[ $table_alias ] = array_merge( |
|
181 | - (array) $existing_fields[ $table_alias ], |
|
182 | - $this->_extra_fields[ $table_alias ] |
|
180 | + $existing_fields[$table_alias] = array_merge( |
|
181 | + (array) $existing_fields[$table_alias], |
|
182 | + $this->_extra_fields[$table_alias] |
|
183 | 183 | ); |
184 | 184 | } |
185 | 185 | } |
@@ -210,7 +210,7 @@ discard block |
||
210 | 210 | $callback_name = "FHEE__EEM_{$this->_model_name_extended}__$method_name_on_model"; |
211 | 211 | add_filter( |
212 | 212 | $callback_name, |
213 | - [$this, self::dynamic_callback_method_prefix . $method_name_on_model], |
|
213 | + [$this, self::dynamic_callback_method_prefix.$method_name_on_model], |
|
214 | 214 | 10, |
215 | 215 | 10 |
216 | 216 | ); |
@@ -244,7 +244,7 @@ discard block |
||
244 | 244 | $callback_name = "FHEE__EEM_{$this->_model_name_extended}__$method_name_on_model"; |
245 | 245 | remove_filter( |
246 | 246 | $callback_name, |
247 | - [$this, self::dynamic_callback_method_prefix . $method_name_on_model] |
|
247 | + [$this, self::dynamic_callback_method_prefix.$method_name_on_model] |
|
248 | 248 | ); |
249 | 249 | } |
250 | 250 | } |
@@ -271,7 +271,7 @@ discard block |
||
271 | 271 | // phpcs:disable WordPress.WP.I18n.SingleUnderscoreGetTextFunction |
272 | 272 | $this->_ = $model_called; |
273 | 273 | // phpcs:enable |
274 | - $extending_method = self::extending_method_prefix . $method_called_on_model; |
|
274 | + $extending_method = self::extending_method_prefix.$method_called_on_model; |
|
275 | 275 | if (method_exists($this, $extending_method)) { |
276 | 276 | return call_user_func_array([$this, $extending_method], $args_provided_to_method_on_model); |
277 | 277 | } else { |
@@ -18,170 +18,170 @@ |
||
18 | 18 | */ |
19 | 19 | class EE_Register_Payment_Method implements EEI_Plugin_API |
20 | 20 | { |
21 | - /** |
|
22 | - * Holds values for registered payment methods |
|
23 | - * |
|
24 | - * @var array |
|
25 | - */ |
|
26 | - protected static $_settings = []; |
|
21 | + /** |
|
22 | + * Holds values for registered payment methods |
|
23 | + * |
|
24 | + * @var array |
|
25 | + */ |
|
26 | + protected static $_settings = []; |
|
27 | 27 | |
28 | 28 | |
29 | - /** |
|
30 | - * Method for registering new EE_PMT_Base children |
|
31 | - * |
|
32 | - * @param string $addon_name a unique identifier for this set of modules Required. |
|
33 | - * @param array $setup_args an array of arguments provided for registering modules Required.{ |
|
34 | - * @type string[] $payment_method_paths each element is the folder containing the EE_PMT_Base child class |
|
35 | - * (eg, 'public_html/wp-content/plugins/my_plugin/Payomatic/' which contains |
|
36 | - * the files EE_PMT_Payomatic.pm.php) |
|
37 | - * } |
|
38 | - * @return bool |
|
39 | - * @throws EE_Error |
|
40 | - * @type array payment_method_paths an array of full server paths to folders containing any EE_PMT_Base |
|
41 | - * children, or to the EED_Module files themselves |
|
42 | - * @throws InvalidDataTypeException |
|
43 | - * @throws DomainException |
|
44 | - * @throws InvalidArgumentException |
|
45 | - * @throws InvalidInterfaceException |
|
46 | - * @throws InvalidDataTypeException |
|
47 | - * @since 4.5.0 |
|
48 | - */ |
|
49 | - public static function register(string $addon_name = '', array $setup_args = []): bool |
|
50 | - { |
|
51 | - // required fields MUST be present, so let's make sure they are. |
|
52 | - if (empty($addon_name) || ! is_array($setup_args) || empty($setup_args['payment_method_paths'])) { |
|
53 | - throw new EE_Error( |
|
54 | - esc_html__( |
|
55 | - 'In order to register Payment Methods with EE_Register_Payment_Method::register(), you must include a "payment_method_id" (a unique identifier for this set of modules), and an array containing the following keys: "payment_method_paths" (an array of full server paths to folders that contain modules, or to the module files themselves)', |
|
56 | - 'event_espresso' |
|
57 | - ) |
|
58 | - ); |
|
59 | - } |
|
60 | - // make sure we don't register twice |
|
61 | - if (isset(self::$_settings[ $addon_name ])) { |
|
62 | - return true; |
|
63 | - } |
|
64 | - // make sure this was called in the right place! |
|
65 | - if ( |
|
66 | - ! did_action('AHEE__EE_System__load_espresso_addons') |
|
67 | - || did_action('AHEE__EE_System__register_shortcodes_modules_and_widgets') |
|
68 | - ) { |
|
69 | - EE_Error::doing_it_wrong( |
|
70 | - __METHOD__, |
|
71 | - esc_html__( |
|
72 | - 'An attempt to register modules has failed because it was not registered at the correct time. Please use the "AHEE__EE_System__register_shortcodes_modules_and_widgets" hook to register modules.', |
|
73 | - 'event_espresso' |
|
74 | - ), |
|
75 | - '4.3.0' |
|
76 | - ); |
|
77 | - } |
|
78 | - // setup $_settings array from incoming values. |
|
79 | - self::$_settings[ $addon_name ] = [ |
|
80 | - // array of full server paths to any EE_PMT_Base children used |
|
81 | - 'payment_method_paths' => isset($setup_args['payment_method_paths']) |
|
82 | - ? (array) $setup_args['payment_method_paths'] |
|
83 | - : [], |
|
84 | - ]; |
|
85 | - // add to list of modules to be registered |
|
86 | - add_filter( |
|
87 | - 'FHEE__EE_Payment_Method_Manager__register_payment_methods__payment_methods_to_register', |
|
88 | - ['EE_Register_Payment_Method', 'add_payment_methods'] |
|
89 | - ); |
|
90 | - // If EE_Payment_Method_Manager::register_payment_methods has already been called, |
|
91 | - // then we need to add our caps for this payment method manually |
|
92 | - if (did_action('FHEE__EE_Payment_Method_Manager__register_payment_methods__registered_payment_methods')) { |
|
93 | - /** @var EE_Payment_Method_Manager $payment_method_manager */ |
|
94 | - $payment_method_manager = LoaderFactory::getLoader()->getShared('EE_Payment_Method_Manager'); |
|
95 | - // register payment methods directly |
|
96 | - foreach (self::$_settings[ $addon_name ]['payment_method_paths'] as $payment_method_path) { |
|
97 | - $payment_method_manager->register_payment_method($payment_method_path); |
|
98 | - } |
|
99 | - $capabilities = LoaderFactory::getLoader()->getShared('EE_Capabilities'); |
|
100 | - $capabilities->addCaps( |
|
101 | - self::getPaymentMethodCapabilities(self::$_settings[ $addon_name ]) |
|
102 | - ); |
|
103 | - } |
|
104 | - return true; |
|
105 | - } |
|
29 | + /** |
|
30 | + * Method for registering new EE_PMT_Base children |
|
31 | + * |
|
32 | + * @param string $addon_name a unique identifier for this set of modules Required. |
|
33 | + * @param array $setup_args an array of arguments provided for registering modules Required.{ |
|
34 | + * @type string[] $payment_method_paths each element is the folder containing the EE_PMT_Base child class |
|
35 | + * (eg, 'public_html/wp-content/plugins/my_plugin/Payomatic/' which contains |
|
36 | + * the files EE_PMT_Payomatic.pm.php) |
|
37 | + * } |
|
38 | + * @return bool |
|
39 | + * @throws EE_Error |
|
40 | + * @type array payment_method_paths an array of full server paths to folders containing any EE_PMT_Base |
|
41 | + * children, or to the EED_Module files themselves |
|
42 | + * @throws InvalidDataTypeException |
|
43 | + * @throws DomainException |
|
44 | + * @throws InvalidArgumentException |
|
45 | + * @throws InvalidInterfaceException |
|
46 | + * @throws InvalidDataTypeException |
|
47 | + * @since 4.5.0 |
|
48 | + */ |
|
49 | + public static function register(string $addon_name = '', array $setup_args = []): bool |
|
50 | + { |
|
51 | + // required fields MUST be present, so let's make sure they are. |
|
52 | + if (empty($addon_name) || ! is_array($setup_args) || empty($setup_args['payment_method_paths'])) { |
|
53 | + throw new EE_Error( |
|
54 | + esc_html__( |
|
55 | + 'In order to register Payment Methods with EE_Register_Payment_Method::register(), you must include a "payment_method_id" (a unique identifier for this set of modules), and an array containing the following keys: "payment_method_paths" (an array of full server paths to folders that contain modules, or to the module files themselves)', |
|
56 | + 'event_espresso' |
|
57 | + ) |
|
58 | + ); |
|
59 | + } |
|
60 | + // make sure we don't register twice |
|
61 | + if (isset(self::$_settings[ $addon_name ])) { |
|
62 | + return true; |
|
63 | + } |
|
64 | + // make sure this was called in the right place! |
|
65 | + if ( |
|
66 | + ! did_action('AHEE__EE_System__load_espresso_addons') |
|
67 | + || did_action('AHEE__EE_System__register_shortcodes_modules_and_widgets') |
|
68 | + ) { |
|
69 | + EE_Error::doing_it_wrong( |
|
70 | + __METHOD__, |
|
71 | + esc_html__( |
|
72 | + 'An attempt to register modules has failed because it was not registered at the correct time. Please use the "AHEE__EE_System__register_shortcodes_modules_and_widgets" hook to register modules.', |
|
73 | + 'event_espresso' |
|
74 | + ), |
|
75 | + '4.3.0' |
|
76 | + ); |
|
77 | + } |
|
78 | + // setup $_settings array from incoming values. |
|
79 | + self::$_settings[ $addon_name ] = [ |
|
80 | + // array of full server paths to any EE_PMT_Base children used |
|
81 | + 'payment_method_paths' => isset($setup_args['payment_method_paths']) |
|
82 | + ? (array) $setup_args['payment_method_paths'] |
|
83 | + : [], |
|
84 | + ]; |
|
85 | + // add to list of modules to be registered |
|
86 | + add_filter( |
|
87 | + 'FHEE__EE_Payment_Method_Manager__register_payment_methods__payment_methods_to_register', |
|
88 | + ['EE_Register_Payment_Method', 'add_payment_methods'] |
|
89 | + ); |
|
90 | + // If EE_Payment_Method_Manager::register_payment_methods has already been called, |
|
91 | + // then we need to add our caps for this payment method manually |
|
92 | + if (did_action('FHEE__EE_Payment_Method_Manager__register_payment_methods__registered_payment_methods')) { |
|
93 | + /** @var EE_Payment_Method_Manager $payment_method_manager */ |
|
94 | + $payment_method_manager = LoaderFactory::getLoader()->getShared('EE_Payment_Method_Manager'); |
|
95 | + // register payment methods directly |
|
96 | + foreach (self::$_settings[ $addon_name ]['payment_method_paths'] as $payment_method_path) { |
|
97 | + $payment_method_manager->register_payment_method($payment_method_path); |
|
98 | + } |
|
99 | + $capabilities = LoaderFactory::getLoader()->getShared('EE_Capabilities'); |
|
100 | + $capabilities->addCaps( |
|
101 | + self::getPaymentMethodCapabilities(self::$_settings[ $addon_name ]) |
|
102 | + ); |
|
103 | + } |
|
104 | + return true; |
|
105 | + } |
|
106 | 106 | |
107 | 107 | |
108 | - /** |
|
109 | - * Filters the list of payment methods to add ours. |
|
110 | - * and they're just full filepaths to FOLDERS containing a payment method class file. Eg. |
|
111 | - * |
|
112 | - * @param array $payment_method_folders array of paths to all payment methods that require registering |
|
113 | - * @return array |
|
114 | - */ |
|
115 | - public static function add_payment_methods(array $payment_method_folders): array |
|
116 | - { |
|
117 | - $payment_method_paths = []; |
|
118 | - foreach (self::$_settings as $settings) { |
|
119 | - $payment_method_paths[] = $settings['payment_method_paths']; |
|
120 | - } |
|
121 | - return array_merge($payment_method_folders, ...$payment_method_paths); |
|
122 | - } |
|
108 | + /** |
|
109 | + * Filters the list of payment methods to add ours. |
|
110 | + * and they're just full filepaths to FOLDERS containing a payment method class file. Eg. |
|
111 | + * |
|
112 | + * @param array $payment_method_folders array of paths to all payment methods that require registering |
|
113 | + * @return array |
|
114 | + */ |
|
115 | + public static function add_payment_methods(array $payment_method_folders): array |
|
116 | + { |
|
117 | + $payment_method_paths = []; |
|
118 | + foreach (self::$_settings as $settings) { |
|
119 | + $payment_method_paths[] = $settings['payment_method_paths']; |
|
120 | + } |
|
121 | + return array_merge($payment_method_folders, ...$payment_method_paths); |
|
122 | + } |
|
123 | 123 | |
124 | 124 | |
125 | - /** |
|
126 | - * This deregisters a module that was previously registered with a specific $addon_name. |
|
127 | - * |
|
128 | - * @param string $addon_name the name for the module that was previously registered |
|
129 | - * @return void |
|
130 | - * @throws DomainException |
|
131 | - * @throws InvalidArgumentException |
|
132 | - * @throws InvalidInterfaceException |
|
133 | - * @throws InvalidDataTypeException |
|
134 | - * @since 4.3.0 |
|
135 | - */ |
|
136 | - public static function deregister(string $addon_name = '') |
|
137 | - { |
|
138 | - if (isset(self::$_settings[ $addon_name ])) { |
|
139 | - // set action for just this module id to delay deregistration until core is loaded and ready. |
|
140 | - $module_settings = self::$_settings[ $addon_name ]; |
|
141 | - unset(self::$_settings[ $addon_name ]); |
|
142 | - add_action( |
|
143 | - 'AHEE__EE_System__core_loaded_and_ready', |
|
144 | - function () use ($module_settings) { |
|
145 | - $capabilities = LoaderFactory::getLoader()->getShared('EE_Capabilities'); |
|
146 | - $capabilities->removeCaps( |
|
147 | - EE_Register_Payment_Method::getPaymentMethodCapabilities($module_settings) |
|
148 | - ); |
|
149 | - } |
|
150 | - ); |
|
151 | - } |
|
152 | - } |
|
125 | + /** |
|
126 | + * This deregisters a module that was previously registered with a specific $addon_name. |
|
127 | + * |
|
128 | + * @param string $addon_name the name for the module that was previously registered |
|
129 | + * @return void |
|
130 | + * @throws DomainException |
|
131 | + * @throws InvalidArgumentException |
|
132 | + * @throws InvalidInterfaceException |
|
133 | + * @throws InvalidDataTypeException |
|
134 | + * @since 4.3.0 |
|
135 | + */ |
|
136 | + public static function deregister(string $addon_name = '') |
|
137 | + { |
|
138 | + if (isset(self::$_settings[ $addon_name ])) { |
|
139 | + // set action for just this module id to delay deregistration until core is loaded and ready. |
|
140 | + $module_settings = self::$_settings[ $addon_name ]; |
|
141 | + unset(self::$_settings[ $addon_name ]); |
|
142 | + add_action( |
|
143 | + 'AHEE__EE_System__core_loaded_and_ready', |
|
144 | + function () use ($module_settings) { |
|
145 | + $capabilities = LoaderFactory::getLoader()->getShared('EE_Capabilities'); |
|
146 | + $capabilities->removeCaps( |
|
147 | + EE_Register_Payment_Method::getPaymentMethodCapabilities($module_settings) |
|
148 | + ); |
|
149 | + } |
|
150 | + ); |
|
151 | + } |
|
152 | + } |
|
153 | 153 | |
154 | 154 | |
155 | - /** |
|
156 | - * returns an array of the caps that get added when a Payment Method is registered |
|
157 | - * |
|
158 | - * @param array $settings |
|
159 | - * @return array |
|
160 | - * @throws DomainException |
|
161 | - * @throws InvalidArgumentException |
|
162 | - * @throws InvalidInterfaceException |
|
163 | - * @throws InvalidDataTypeException |
|
164 | - * @access private Developers do NOT use this method. It's only public for PHP5.3 closure support (see deregister) |
|
165 | - * When we drop support for PHP5.3 this will be made private again. You have been warned. |
|
166 | - */ |
|
167 | - public static function getPaymentMethodCapabilities(array $settings): array |
|
168 | - { |
|
169 | - $payment_method_manager = LoaderFactory::getLoader()->getShared('EE_Payment_Method_Manager'); |
|
170 | - $payment_method_caps = ['administrator' => []]; |
|
171 | - if (isset($settings['payment_method_paths'])) { |
|
172 | - foreach ($settings['payment_method_paths'] as $payment_method_path) { |
|
173 | - $payment_method_caps = $payment_method_manager->addPaymentMethodCap( |
|
174 | - strtolower(basename($payment_method_path)), |
|
175 | - $payment_method_caps |
|
176 | - ); |
|
177 | - } |
|
178 | - } |
|
179 | - return $payment_method_caps; |
|
180 | - } |
|
155 | + /** |
|
156 | + * returns an array of the caps that get added when a Payment Method is registered |
|
157 | + * |
|
158 | + * @param array $settings |
|
159 | + * @return array |
|
160 | + * @throws DomainException |
|
161 | + * @throws InvalidArgumentException |
|
162 | + * @throws InvalidInterfaceException |
|
163 | + * @throws InvalidDataTypeException |
|
164 | + * @access private Developers do NOT use this method. It's only public for PHP5.3 closure support (see deregister) |
|
165 | + * When we drop support for PHP5.3 this will be made private again. You have been warned. |
|
166 | + */ |
|
167 | + public static function getPaymentMethodCapabilities(array $settings): array |
|
168 | + { |
|
169 | + $payment_method_manager = LoaderFactory::getLoader()->getShared('EE_Payment_Method_Manager'); |
|
170 | + $payment_method_caps = ['administrator' => []]; |
|
171 | + if (isset($settings['payment_method_paths'])) { |
|
172 | + foreach ($settings['payment_method_paths'] as $payment_method_path) { |
|
173 | + $payment_method_caps = $payment_method_manager->addPaymentMethodCap( |
|
174 | + strtolower(basename($payment_method_path)), |
|
175 | + $payment_method_caps |
|
176 | + ); |
|
177 | + } |
|
178 | + } |
|
179 | + return $payment_method_caps; |
|
180 | + } |
|
181 | 181 | |
182 | 182 | |
183 | - public static function reset(): void |
|
184 | - { |
|
185 | - self::$_settings = []; |
|
186 | - } |
|
183 | + public static function reset(): void |
|
184 | + { |
|
185 | + self::$_settings = []; |
|
186 | + } |
|
187 | 187 | } |
@@ -58,7 +58,7 @@ discard block |
||
58 | 58 | ); |
59 | 59 | } |
60 | 60 | // make sure we don't register twice |
61 | - if (isset(self::$_settings[ $addon_name ])) { |
|
61 | + if (isset(self::$_settings[$addon_name])) { |
|
62 | 62 | return true; |
63 | 63 | } |
64 | 64 | // make sure this was called in the right place! |
@@ -76,7 +76,7 @@ discard block |
||
76 | 76 | ); |
77 | 77 | } |
78 | 78 | // setup $_settings array from incoming values. |
79 | - self::$_settings[ $addon_name ] = [ |
|
79 | + self::$_settings[$addon_name] = [ |
|
80 | 80 | // array of full server paths to any EE_PMT_Base children used |
81 | 81 | 'payment_method_paths' => isset($setup_args['payment_method_paths']) |
82 | 82 | ? (array) $setup_args['payment_method_paths'] |
@@ -93,12 +93,12 @@ discard block |
||
93 | 93 | /** @var EE_Payment_Method_Manager $payment_method_manager */ |
94 | 94 | $payment_method_manager = LoaderFactory::getLoader()->getShared('EE_Payment_Method_Manager'); |
95 | 95 | // register payment methods directly |
96 | - foreach (self::$_settings[ $addon_name ]['payment_method_paths'] as $payment_method_path) { |
|
96 | + foreach (self::$_settings[$addon_name]['payment_method_paths'] as $payment_method_path) { |
|
97 | 97 | $payment_method_manager->register_payment_method($payment_method_path); |
98 | 98 | } |
99 | 99 | $capabilities = LoaderFactory::getLoader()->getShared('EE_Capabilities'); |
100 | 100 | $capabilities->addCaps( |
101 | - self::getPaymentMethodCapabilities(self::$_settings[ $addon_name ]) |
|
101 | + self::getPaymentMethodCapabilities(self::$_settings[$addon_name]) |
|
102 | 102 | ); |
103 | 103 | } |
104 | 104 | return true; |
@@ -135,13 +135,13 @@ discard block |
||
135 | 135 | */ |
136 | 136 | public static function deregister(string $addon_name = '') |
137 | 137 | { |
138 | - if (isset(self::$_settings[ $addon_name ])) { |
|
138 | + if (isset(self::$_settings[$addon_name])) { |
|
139 | 139 | // set action for just this module id to delay deregistration until core is loaded and ready. |
140 | - $module_settings = self::$_settings[ $addon_name ]; |
|
141 | - unset(self::$_settings[ $addon_name ]); |
|
140 | + $module_settings = self::$_settings[$addon_name]; |
|
141 | + unset(self::$_settings[$addon_name]); |
|
142 | 142 | add_action( |
143 | 143 | 'AHEE__EE_System__core_loaded_and_ready', |
144 | - function () use ($module_settings) { |
|
144 | + function() use ($module_settings) { |
|
145 | 145 | $capabilities = LoaderFactory::getLoader()->getShared('EE_Capabilities'); |
146 | 146 | $capabilities->removeCaps( |
147 | 147 | EE_Register_Payment_Method::getPaymentMethodCapabilities($module_settings) |
@@ -24,1282 +24,1282 @@ |
||
24 | 24 | */ |
25 | 25 | class EE_Register_Addon implements EEI_Plugin_API |
26 | 26 | { |
27 | - /** |
|
28 | - * possibly truncated version of the EE core version string |
|
29 | - * |
|
30 | - * @var string |
|
31 | - */ |
|
32 | - protected static $_core_version = ''; |
|
33 | - |
|
34 | - /** |
|
35 | - * Holds values for registered addons |
|
36 | - * |
|
37 | - * @var array |
|
38 | - */ |
|
39 | - protected static $_settings = []; |
|
40 | - |
|
41 | - /** |
|
42 | - * @var array $_incompatible_addons keys are addon SLUGS |
|
43 | - * (first argument passed to EE_Register_Addon::register()), keys are |
|
44 | - * their MINIMUM VERSION (with all 5 parts. Eg 1.2.3.rc.004). |
|
45 | - * Generally this should be used sparingly, as we don't want to muddle up |
|
46 | - * EE core with knowledge of ALL the addons out there. |
|
47 | - * If you want NO versions of an addon to run with a certain version of core, |
|
48 | - * it's usually best to define the addon's "min_core_version" as part of its call |
|
49 | - * to EE_Register_Addon::register(), rather than using this array with a super |
|
50 | - * high value for its minimum plugin version. |
|
51 | - */ |
|
52 | - protected static $_incompatible_addons = [ |
|
53 | - 'Multi_Event_Registration' => '2.0.11.rc.002', |
|
54 | - 'Promotions' => '1.0.0.rc.084', |
|
55 | - 'EE_WPUsers' => '2.1.3.p', |
|
56 | - ]; |
|
57 | - |
|
58 | - /** |
|
59 | - * @var LoaderInterface |
|
60 | - */ |
|
61 | - protected static $loader; |
|
62 | - |
|
63 | - |
|
64 | - /** |
|
65 | - * We should always be comparing core to a version like '4.3.0.rc.000', |
|
66 | - * not just '4.3.0'. |
|
67 | - * So if the addon developer doesn't provide that full version string, |
|
68 | - * fill in the blanks for them |
|
69 | - * |
|
70 | - * @param string $min_core_version |
|
71 | - * @return string always like '4.3.0.rc.000' |
|
72 | - */ |
|
73 | - protected static function _effective_version(string $min_core_version): string |
|
74 | - { |
|
75 | - // versions: 4 . 3 . 1 . p . 123 |
|
76 | - // offsets: 0 . 1 . 2 . 3 . 4 |
|
77 | - $version_parts = explode('.', $min_core_version); |
|
78 | - // check they specified the micro version (after 2nd period) |
|
79 | - if (! isset($version_parts[2])) { |
|
80 | - $version_parts[2] = '0'; |
|
81 | - } |
|
82 | - // if they didn't specify the 'p', or 'rc' part. Just assume the lowest possible |
|
83 | - // soon we can assume that's 'rc', but this current version is 'alpha' |
|
84 | - if (! isset($version_parts[3])) { |
|
85 | - $version_parts[3] = 'dev'; |
|
86 | - } |
|
87 | - if (! isset($version_parts[4])) { |
|
88 | - $version_parts[4] = '000'; |
|
89 | - } |
|
90 | - return implode('.', $version_parts); |
|
91 | - } |
|
92 | - |
|
93 | - |
|
94 | - /** |
|
95 | - * Returns whether or not the min core version requirement of the addon is met |
|
96 | - * |
|
97 | - * @param string $min_core_version the minimum core version required by the addon |
|
98 | - * @param string $actual_core_version the actual core version, optional |
|
99 | - * @return bool |
|
100 | - */ |
|
101 | - public static function _meets_min_core_version_requirement( |
|
102 | - string $min_core_version, |
|
103 | - string $actual_core_version = EVENT_ESPRESSO_VERSION |
|
104 | - ): bool { |
|
105 | - return version_compare( |
|
106 | - self::_effective_version($actual_core_version), |
|
107 | - self::_effective_version($min_core_version), |
|
108 | - '>=' |
|
109 | - ); |
|
110 | - } |
|
111 | - |
|
112 | - |
|
113 | - /** |
|
114 | - * Method for registering new EE_Addons. |
|
115 | - * Should be called AFTER AHEE__EE_System__load_espresso_addons but BEFORE |
|
116 | - * AHEE__EE_System___detect_if_activation_or_upgrade__begin in order to register all its components. However, it |
|
117 | - * may also be called after the 'activate_plugin' action (when an addon is activated), because an activating addon |
|
118 | - * won't be loaded by WP until after AHEE__EE_System__load_espresso_addons has fired. If its called after |
|
119 | - * 'activate_plugin', it registers the addon still, but its components are not registered |
|
120 | - * (they shouldn't be needed anyways, because it's just an activation request and they won't have a chance to do |
|
121 | - * anything anyways). Instead, it just sets the newly-activated addon's activation indicator wp option and returns |
|
122 | - * (so that we can detect that the addon has activated on the subsequent request) |
|
123 | - * |
|
124 | - * @param string $addon_name [Required] the EE_Addon's name. |
|
125 | - * @param array $setup_args { |
|
126 | - * An array of arguments provided for registering |
|
127 | - * the message type. |
|
128 | - * @type string $class_name the addon's main file name. |
|
129 | - * If left blank, generated from the addon name, |
|
130 | - * changes something like "calendar" to |
|
131 | - * "EE_Calendar" |
|
132 | - * @type string $min_core_version the minimum version of EE Core that the |
|
133 | - * addon will work with. eg "4.8.1.rc.084" |
|
134 | - * @type string $version the "software" version for the addon. eg |
|
135 | - * "1.0.0.p" for a first stable release, or |
|
136 | - * "1.0.0.rc.043" for a version in progress |
|
137 | - * @type string $main_file_path the full server path to the main file |
|
138 | - * loaded directly by WP |
|
139 | - * @type DomainInterface $domain child class of |
|
140 | - * EventEspresso\core\domain\DomainBase |
|
141 | - * @type string $domain_fqcn Fully Qualified Class Name |
|
142 | - * for the addon's Domain class |
|
143 | - * (see EventEspresso\core\domain\Domain) |
|
144 | - * @type string $admin_path full server path to the folder where the |
|
145 | - * addon\'s admin files reside |
|
146 | - * @type string $admin_callback a method to be called when the EE Admin is |
|
147 | - * first invoked, can be used for hooking into |
|
148 | - * any admin page |
|
149 | - * @type string $config_section the section name for this addon's |
|
150 | - * configuration settings section |
|
151 | - * (defaults to "addons") |
|
152 | - * @type string $config_class the class name for this addon's |
|
153 | - * configuration settings object |
|
154 | - * @type string $config_name the class name for this addon's |
|
155 | - * configuration settings object |
|
156 | - * @type string $autoloader_paths [Required] an array of class names and the full |
|
157 | - * server paths to those files. |
|
158 | - * @type string $autoloader_folders an array of "full server paths" for any |
|
159 | - * folders containing classes that might be |
|
160 | - * invoked by the addon |
|
161 | - * @type string $dms_paths [Required] an array of full server paths to |
|
162 | - * folders that contain data migration scripts. |
|
163 | - * The key should be the EE_Addon class name that |
|
164 | - * this set of data migration scripts belongs to. |
|
165 | - * If the EE_Addon class is namespaced, then this |
|
166 | - * needs to be the Fully Qualified Class Name |
|
167 | - * @type string $module_paths an array of full server paths to any |
|
168 | - * EED_Modules used by the addon |
|
169 | - * @type string $shortcode_paths an array of full server paths to folders |
|
170 | - * that contain EES_Shortcodes |
|
171 | - * @type string $widget_paths an array of full server paths to folders |
|
172 | - * that contain WP_Widgets |
|
173 | - * @type array $capabilities an array indexed by role name |
|
174 | - * (i.e administrator,author ) and the values |
|
175 | - * are an array of caps to add to the role. |
|
176 | - * 'administrator' => array( |
|
177 | - * 'read_addon', |
|
178 | - * 'edit_addon', |
|
179 | - * etc. |
|
180 | - * ). |
|
181 | - * @type EE_Meta_Capability_Map[] $capability_maps an array of EE_Meta_Capability_Map object |
|
182 | - * for any addons that need to register any |
|
183 | - * special meta mapped capabilities. Should |
|
184 | - * be indexed where the key is the |
|
185 | - * EE_Meta_Capability_Map class name and the |
|
186 | - * values are the arguments sent to the class. |
|
187 | - * @type array $model_paths array of folders containing DB models |
|
188 | - * @return bool |
|
189 | - * @throws DomainException |
|
190 | - * @throws EE_Error |
|
191 | - * @throws InvalidArgumentException |
|
192 | - * @throws InvalidDataTypeException |
|
193 | - * @throws InvalidInterfaceException |
|
194 | - * @since 4.3.0 |
|
195 | - * @see EE_Register_Model |
|
196 | - * @type array $class_paths array of folders containing DB classes |
|
197 | - * @see EE_Register_Model |
|
198 | - * @type array $model_extension_paths array of folders containing DB model |
|
199 | - * extensions |
|
200 | - * @see EE_Register_Model_Extension |
|
201 | - * @type array $class_extension_paths array of folders containing DB class |
|
202 | - * extensions |
|
203 | - * @see EE_Register_Model_Extension |
|
204 | - * @type array message_types { |
|
205 | - * An array of message types with the key as |
|
206 | - * the message type name and the values as |
|
207 | - * below: |
|
208 | - * @type string $mtfilename [Required] The filename of the message type |
|
209 | - * being registered. This will be the main |
|
210 | - * EE_{Message Type Name}_message_type class. |
|
211 | - * for example: |
|
212 | - * EE_Declined_Registration_message_type.class.php |
|
213 | - * @type array $autoloadpaths [Required] An array of paths to add to the |
|
214 | - * messages autoloader for the new message type. |
|
215 | - * @type array $messengers_to_activate_with An array of messengers that this message |
|
216 | - * type should activate with. Each value in |
|
217 | - * the |
|
218 | - * array |
|
219 | - * should match the name property of a |
|
220 | - * EE_messenger. Optional. |
|
221 | - * @type array $messengers_to_validate_with An array of messengers that this message |
|
222 | - * type should validate with. Each value in |
|
223 | - * the |
|
224 | - * array |
|
225 | - * should match the name property of an |
|
226 | - * EE_messenger. |
|
227 | - * Optional. |
|
228 | - * } |
|
229 | - * @type array $custom_post_types |
|
230 | - * @type array $custom_taxonomies |
|
231 | - * @type array $payment_method_paths each element is the folder containing the |
|
232 | - * EE_PMT_Base child class |
|
233 | - * (eg, |
|
234 | - * '/wp-content/plugins/my_plugin/Payomatic/' |
|
235 | - * which contains the files |
|
236 | - * EE_PMT_Payomatic.pm.php) |
|
237 | - * @type array $default_terms |
|
238 | - * @type array $namespace { |
|
239 | - * An array with two items for registering the |
|
240 | - * addon's namespace. (If, for some reason, you |
|
241 | - * require additional namespaces, |
|
242 | - * use |
|
243 | - * EventEspresso\core\Psr4Autoloader::addNamespace() |
|
244 | - * directly) |
|
245 | - * @see EventEspresso\core\Psr4Autoloader::addNamespace() |
|
246 | - * @type string $FQNS the namespace prefix |
|
247 | - * @type string $DIR a base directory for class files in the |
|
248 | - * namespace. |
|
249 | - * } |
|
250 | - * } |
|
251 | - * @type string $privacy_policies FQNSs (namespaces, each of which contains only |
|
252 | - * privacy policy classes) or FQCNs (specific |
|
253 | - * classnames of privacy policy classes) |
|
254 | - * @type string $personal_data_exporters FQNSs (namespaces, each of which contains only |
|
255 | - * privacy policy classes) or FQCNs (specific |
|
256 | - * classnames of privacy policy classes) |
|
257 | - * @type string $personal_data_erasers FQNSs (namespaces, each of which contains only |
|
258 | - * privacy policy classes) or FQCNs (specific |
|
259 | - * classnames of privacy policy classes) |
|
260 | - */ |
|
261 | - public static function register(string $addon_name = '', array $setup_args = []): bool |
|
262 | - { |
|
263 | - // $addon_name = basename($addon_name); |
|
264 | - if (! self::$loader instanceof LoaderInterface) { |
|
265 | - self::$loader = LoaderFactory::getLoader(); |
|
266 | - } |
|
267 | - // make sure this was called in the right place! |
|
268 | - if ( |
|
269 | - ! did_action('activate_plugin') |
|
270 | - && ( |
|
271 | - ! did_action('AHEE__EE_System__load_espresso_addons') |
|
272 | - || did_action('AHEE__EE_System___detect_if_activation_or_upgrade__begin') |
|
273 | - ) |
|
274 | - ) { |
|
275 | - EE_Error::doing_it_wrong( |
|
276 | - __METHOD__, |
|
277 | - sprintf( |
|
278 | - esc_html__( |
|
279 | - '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.', |
|
280 | - 'event_espresso' |
|
281 | - ), |
|
282 | - $addon_name |
|
283 | - ), |
|
284 | - '4.3.0' |
|
285 | - ); |
|
286 | - return false; |
|
287 | - } |
|
288 | - // required fields MUST be present, so let's make sure they are. |
|
289 | - EE_Register_Addon::_verify_parameters($addon_name, $setup_args); |
|
290 | - // get class name for addon |
|
291 | - $class_name = EE_Register_Addon::_parse_class_name($addon_name, $setup_args); |
|
292 | - // setup $_settings array from incoming values. |
|
293 | - $addon_settings = EE_Register_Addon::_get_addon_settings($class_name, $setup_args); |
|
294 | - // allow early addon setup or modification of addon api settings |
|
295 | - self::$_settings = (array) apply_filters( |
|
296 | - 'FHEE__EE_Register_Addon__register', |
|
297 | - self::$_settings, |
|
298 | - $addon_name, |
|
299 | - $class_name, |
|
300 | - $setup_args |
|
301 | - ); |
|
302 | - // does this addon work with this version of core or WordPress ? |
|
303 | - // does this addon work with this version of core or WordPress ? |
|
304 | - if (! EE_Register_Addon::_addon_is_compatible($addon_name, $addon_settings)) { |
|
305 | - return false; |
|
306 | - } |
|
307 | - // register namespaces |
|
308 | - EE_Register_Addon::_setup_namespaces($addon_settings); |
|
309 | - // check if this is an activation request |
|
310 | - if (EE_Register_Addon::_addon_activation($addon_name, $addon_settings)) { |
|
311 | - // dont bother setting up the rest of the addon atm |
|
312 | - return false; |
|
313 | - } |
|
314 | - // we need cars |
|
315 | - EE_Register_Addon::_setup_autoloaders($addon_name); |
|
316 | - // register new models and extensions |
|
317 | - EE_Register_Addon::_register_models_and_extensions($addon_name); |
|
318 | - // setup DMS |
|
319 | - EE_Register_Addon::_register_data_migration_scripts($addon_name); |
|
320 | - // if config_class is present let's register config. |
|
321 | - EE_Register_Addon::_register_config($addon_name); |
|
322 | - // register admin pages |
|
323 | - EE_Register_Addon::_register_admin_pages($addon_name); |
|
324 | - // add to list of modules to be registered |
|
325 | - EE_Register_Addon::_register_modules($addon_name); |
|
326 | - // add to list of shortcodes to be registered |
|
327 | - EE_Register_Addon::_register_shortcodes($addon_name); |
|
328 | - // add to list of widgets to be registered |
|
329 | - EE_Register_Addon::_register_widgets($addon_name); |
|
330 | - // register capability related stuff. |
|
331 | - EE_Register_Addon::_register_capabilities($addon_name); |
|
332 | - // any message type to register? |
|
333 | - EE_Register_Addon::_register_message_types($addon_name); |
|
334 | - // any custom post type/ custom capabilities or default terms to register |
|
335 | - EE_Register_Addon::_register_custom_post_types($addon_name); |
|
336 | - // and any payment methods |
|
337 | - EE_Register_Addon::_register_payment_methods($addon_name); |
|
338 | - // and privacy policy generators |
|
339 | - EE_Register_Addon::registerPrivacyPolicies($addon_name); |
|
340 | - // and privacy policy generators |
|
341 | - EE_Register_Addon::registerPersonalDataExporters($addon_name); |
|
342 | - // and privacy policy generators |
|
343 | - EE_Register_Addon::registerPersonalDataErasers($addon_name); |
|
344 | - EE_Register_Addon::registerLicense($addon_name); |
|
345 | - // load and instantiate main addon class |
|
346 | - $addon = EE_Register_Addon::_load_and_init_addon_class($addon_name); |
|
347 | - // delay calling after_registration hook on each addon until after all add-ons have been registered. |
|
348 | - add_action('AHEE__EE_System__load_espresso_addons__complete', [$addon, 'after_registration'], 999); |
|
349 | - return $addon instanceof EE_Addon; |
|
350 | - } |
|
351 | - |
|
352 | - |
|
353 | - /** |
|
354 | - * @param string $addon_name |
|
355 | - * @param array $setup_args |
|
356 | - * @return void |
|
357 | - * @throws EE_Error |
|
358 | - */ |
|
359 | - private static function _verify_parameters(string $addon_name, array $setup_args) |
|
360 | - { |
|
361 | - // required fields MUST be present, so let's make sure they are. |
|
362 | - if (empty($addon_name) || empty($setup_args)) { |
|
363 | - throw new EE_Error( |
|
364 | - esc_html__( |
|
365 | - '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.', |
|
366 | - 'event_espresso' |
|
367 | - ) |
|
368 | - ); |
|
369 | - } |
|
370 | - if (empty($setup_args['main_file_path'])) { |
|
371 | - throw new EE_Error( |
|
372 | - sprintf( |
|
373 | - esc_html__( |
|
374 | - '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', |
|
375 | - 'event_espresso' |
|
376 | - ), |
|
377 | - implode(',', array_keys($setup_args)) |
|
378 | - ) |
|
379 | - ); |
|
380 | - } |
|
381 | - // check that addon has not already been registered with that name |
|
382 | - if (isset(self::$_settings[ $addon_name ]) && ! did_action('activate_plugin')) { |
|
383 | - throw new EE_Error( |
|
384 | - sprintf( |
|
385 | - esc_html__( |
|
386 | - 'An EE_Addon with the name "%s" has already been registered and each EE_Addon requires a unique name.', |
|
387 | - 'event_espresso' |
|
388 | - ), |
|
389 | - $addon_name |
|
390 | - ) |
|
391 | - ); |
|
392 | - } |
|
393 | - } |
|
394 | - |
|
395 | - |
|
396 | - /** |
|
397 | - * @param string $addon_name |
|
398 | - * @param array $setup_args |
|
399 | - * @return string |
|
400 | - */ |
|
401 | - private static function _parse_class_name(string $addon_name, array $setup_args): string |
|
402 | - { |
|
403 | - if (empty($setup_args['class_name'])) { |
|
404 | - // generate one by first separating name with spaces |
|
405 | - $class_name = str_replace(['-', '_'], ' ', trim($addon_name)); |
|
406 | - // capitalize, then replace spaces with underscores |
|
407 | - $class_name = str_replace(' ', '_', ucwords($class_name)); |
|
408 | - } else { |
|
409 | - $class_name = $setup_args['class_name']; |
|
410 | - } |
|
411 | - // check if classname is fully qualified or is a legacy classname already prefixed with 'EE_' |
|
412 | - return strpos($class_name, '\\') || strpos($class_name, 'EE_') === 0 |
|
413 | - ? $class_name |
|
414 | - : 'EE_' . $class_name; |
|
415 | - } |
|
416 | - |
|
417 | - |
|
418 | - /** |
|
419 | - * @param string $class_name |
|
420 | - * @param array $setup_args |
|
421 | - * @return array |
|
422 | - */ |
|
423 | - private static function _get_addon_settings(string $class_name, array $setup_args): array |
|
424 | - { |
|
425 | - // setup $_settings array from incoming values. |
|
426 | - $addon_settings = [ |
|
427 | - // generated from the addon name, changes something like "calendar" to "EE_Calendar" |
|
428 | - 'class_name' => $class_name, |
|
429 | - // the addon slug for use in URLs, etc |
|
430 | - 'plugin_slug' => isset($setup_args['plugin_slug']) |
|
431 | - ? (string) $setup_args['plugin_slug'] |
|
432 | - : sanitize_key($class_name), |
|
433 | - // page slug to be used when generating the "Settings" link on the WP plugin page |
|
434 | - 'plugin_action_slug' => isset($setup_args['plugin_action_slug']) |
|
435 | - ? (string) $setup_args['plugin_action_slug'] |
|
436 | - : '', |
|
437 | - // the "software" version for the addon |
|
438 | - 'version' => isset($setup_args['version']) |
|
439 | - ? (string) $setup_args['version'] |
|
440 | - : '', |
|
441 | - // the minimum version of EE Core that the addon will work with |
|
442 | - 'min_core_version' => isset($setup_args['min_core_version']) |
|
443 | - ? (string) $setup_args['min_core_version'] |
|
444 | - : '', |
|
445 | - // the minimum version of WordPress that the addon will work with |
|
446 | - 'min_wp_version' => isset($setup_args['min_wp_version']) |
|
447 | - ? (string) $setup_args['min_wp_version'] |
|
448 | - : EE_MIN_WP_VER_REQUIRED, |
|
449 | - // full server path to main file (file loaded directly by WP) |
|
450 | - 'main_file_path' => isset($setup_args['main_file_path']) |
|
451 | - ? (string) $setup_args['main_file_path'] |
|
452 | - : '', |
|
453 | - // instance of \EventEspresso\core\domain\DomainInterface |
|
454 | - 'domain' => isset($setup_args['domain']) && $setup_args['domain'] instanceof DomainInterface |
|
455 | - ? $setup_args['domain'] |
|
456 | - : null, |
|
457 | - // Fully Qualified Class Name for the addon's Domain class |
|
458 | - 'domain_fqcn' => isset($setup_args['domain_fqcn']) |
|
459 | - ? (string) $setup_args['domain_fqcn'] |
|
460 | - : '', |
|
461 | - // path to folder containing files for integrating with the EE core admin and/or setting up EE admin pages |
|
462 | - 'admin_path' => isset($setup_args['admin_path']) |
|
463 | - ? (string) $setup_args['admin_path'] |
|
464 | - : '', |
|
465 | - // a method to be called when the EE Admin is first invoked, can be used for hooking into any admin page |
|
466 | - 'admin_callback' => isset($setup_args['admin_callback']) |
|
467 | - ? (string) $setup_args['admin_callback'] |
|
468 | - : '', |
|
469 | - // the section name for this addon's configuration settings section (defaults to "addons") |
|
470 | - 'config_section' => isset($setup_args['config_section']) |
|
471 | - ? (string) $setup_args['config_section'] |
|
472 | - : 'addons', |
|
473 | - // the class name for this addon's configuration settings object |
|
474 | - 'config_class' => isset($setup_args['config_class']) |
|
475 | - ? (string) $setup_args['config_class'] |
|
476 | - : '', |
|
477 | - // the name given to the config for this addons' configuration settings object (optional) |
|
478 | - 'config_name' => isset($setup_args['config_name']) |
|
479 | - ? (string) $setup_args['config_name'] |
|
480 | - : '', |
|
481 | - // an array of "class names" => "full server paths" for any classes that might be invoked by the addon |
|
482 | - 'autoloader_paths' => isset($setup_args['autoloader_paths']) |
|
483 | - ? (array) $setup_args['autoloader_paths'] |
|
484 | - : [], |
|
485 | - // an array of "full server paths" for any folders containing classes that might be invoked by the addon |
|
486 | - 'autoloader_folders' => isset($setup_args['autoloader_folders']) |
|
487 | - ? (array) $setup_args['autoloader_folders'] |
|
488 | - : [], |
|
489 | - // array of full server paths to any EE_DMS data migration scripts used by the addon. |
|
490 | - // The key should be the EE_Addon class name that this set of data migration scripts belongs to. |
|
491 | - // If the EE_Addon class is namespaced, then this needs to be the Fully Qualified Class Name |
|
492 | - 'dms_paths' => isset($setup_args['dms_paths']) |
|
493 | - ? (array) $setup_args['dms_paths'] |
|
494 | - : [], |
|
495 | - // array of full server paths to any EED_Modules used by the addon |
|
496 | - 'module_paths' => isset($setup_args['module_paths']) |
|
497 | - ? (array) $setup_args['module_paths'] |
|
498 | - : [], |
|
499 | - // array of full server paths to any EES_Shortcodes used by the addon |
|
500 | - 'shortcode_paths' => isset($setup_args['shortcode_paths']) |
|
501 | - ? (array) $setup_args['shortcode_paths'] |
|
502 | - : [], |
|
503 | - 'shortcode_fqcns' => isset($setup_args['shortcode_fqcns']) |
|
504 | - ? (array) $setup_args['shortcode_fqcns'] |
|
505 | - : [], |
|
506 | - // array of full server paths to any WP_Widgets used by the addon |
|
507 | - 'widget_paths' => isset($setup_args['widget_paths']) |
|
508 | - ? (array) $setup_args['widget_paths'] |
|
509 | - : [], |
|
510 | - 'message_types' => isset($setup_args['message_types']) |
|
511 | - ? (array) $setup_args['message_types'] |
|
512 | - : [], |
|
513 | - 'capabilities' => isset($setup_args['capabilities']) |
|
514 | - ? (array) $setup_args['capabilities'] |
|
515 | - : [], |
|
516 | - 'capability_maps' => isset($setup_args['capability_maps']) |
|
517 | - ? (array) $setup_args['capability_maps'] |
|
518 | - : [], |
|
519 | - 'model_paths' => isset($setup_args['model_paths']) |
|
520 | - ? (array) $setup_args['model_paths'] |
|
521 | - : [], |
|
522 | - 'class_paths' => isset($setup_args['class_paths']) |
|
523 | - ? (array) $setup_args['class_paths'] |
|
524 | - : [], |
|
525 | - 'model_extension_paths' => isset($setup_args['model_extension_paths']) |
|
526 | - ? (array) $setup_args['model_extension_paths'] |
|
527 | - : [], |
|
528 | - 'class_extension_paths' => isset($setup_args['class_extension_paths']) |
|
529 | - ? (array) $setup_args['class_extension_paths'] |
|
530 | - : [], |
|
531 | - 'custom_post_types' => isset($setup_args['custom_post_types']) |
|
532 | - ? (array) $setup_args['custom_post_types'] |
|
533 | - : [], |
|
534 | - 'custom_taxonomies' => isset($setup_args['custom_taxonomies']) |
|
535 | - ? (array) $setup_args['custom_taxonomies'] |
|
536 | - : [], |
|
537 | - 'payment_method_paths' => isset($setup_args['payment_method_paths']) |
|
538 | - ? (array) $setup_args['payment_method_paths'] |
|
539 | - : [], |
|
540 | - 'pm_slug' => '', |
|
541 | - 'default_terms' => isset($setup_args['default_terms']) |
|
542 | - ? (array) $setup_args['default_terms'] |
|
543 | - : [], |
|
544 | - // if not empty, inserts a new table row after this plugin's row on the WP Plugins page |
|
545 | - // that can be used for adding upgrading/marketing info |
|
546 | - 'plugins_page_row' => isset($setup_args['plugins_page_row']) |
|
547 | - ? (array) $setup_args['plugins_page_row'] |
|
548 | - : [], |
|
549 | - 'namespace' => isset( |
|
550 | - $setup_args['namespace']['FQNS'], |
|
551 | - $setup_args['namespace']['DIR'] |
|
552 | - ) |
|
553 | - ? (array) $setup_args['namespace'] |
|
554 | - : [], |
|
555 | - 'privacy_policies' => isset($setup_args['privacy_policies']) |
|
556 | - ? (array) $setup_args['privacy_policies'] |
|
557 | - : [], |
|
558 | - 'license' => isset($setup_args['license']) |
|
559 | - ? (array) $setup_args['license'] |
|
560 | - : [], |
|
561 | - ]; |
|
562 | - |
|
563 | - // if plugin_action_slug is NOT set... |
|
564 | - if (empty($addon_settings['plugin_action_slug'])) { |
|
565 | - if (! empty($addon_settings['payment_method_paths'])) { |
|
566 | - // but the addon is a payment method |
|
567 | - $payment_method_path = reset($addon_settings['payment_method_paths']); |
|
568 | - $plugin_action_slug = basename(strtolower($payment_method_path)); |
|
569 | - $addon_settings['plugin_action_slug'] = $plugin_action_slug; |
|
570 | - // let's also set the pm_slug to the same value |
|
571 | - $addon_settings['pm_slug'] = $plugin_action_slug; |
|
572 | - } elseif (! empty($addon_settings['admin_path'])) { |
|
573 | - // or an admin page path IS set |
|
574 | - $addon_settings['plugin_action_slug'] = basename($addon_settings['admin_path']); |
|
575 | - } |
|
576 | - } |
|
577 | - |
|
578 | - // full server path to main file (file loaded directly by WP) |
|
579 | - $addon_settings['plugin_basename'] = plugin_basename($addon_settings['main_file_path']); |
|
580 | - return $addon_settings; |
|
581 | - } |
|
582 | - |
|
583 | - |
|
584 | - /** |
|
585 | - * @param string $addon_name |
|
586 | - * @param array $addon_settings |
|
587 | - * @return bool |
|
588 | - */ |
|
589 | - private static function _addon_is_compatible(string $addon_name, array $addon_settings): bool |
|
590 | - { |
|
591 | - global $wp_version; |
|
592 | - $incompatibility_message = ''; |
|
593 | - // check whether this addon version is compatible with EE core |
|
594 | - if ( |
|
595 | - isset(EE_Register_Addon::$_incompatible_addons[ $addon_name ]) |
|
596 | - && ! self::_meets_min_core_version_requirement( |
|
597 | - EE_Register_Addon::$_incompatible_addons[ $addon_name ], |
|
598 | - $addon_settings['version'] |
|
599 | - ) |
|
600 | - ) { |
|
601 | - $incompatibility_message = sprintf( |
|
602 | - esc_html__( |
|
603 | - '%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.', |
|
604 | - 'event_espresso' |
|
605 | - ), |
|
606 | - $addon_name, |
|
607 | - '<br />', |
|
608 | - EE_Register_Addon::$_incompatible_addons[ $addon_name ], |
|
609 | - '<span style="font-weight: bold; color: #D54E21;">', |
|
610 | - '</span><br />' |
|
611 | - ); |
|
612 | - } elseif ( |
|
613 | - ! self::_meets_min_core_version_requirement($addon_settings['min_core_version'], espresso_version()) |
|
614 | - ) { |
|
615 | - $incompatibility_message = sprintf( |
|
616 | - esc_html__( |
|
617 | - '%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".', |
|
618 | - 'event_espresso' |
|
619 | - ), |
|
620 | - $addon_name, |
|
621 | - self::_effective_version($addon_settings['min_core_version']), |
|
622 | - self::_effective_version(espresso_version()), |
|
623 | - '<br />', |
|
624 | - '<span style="font-weight: bold; color: #D54E21;">', |
|
625 | - '</span><br />' |
|
626 | - ); |
|
627 | - } elseif (version_compare($wp_version, $addon_settings['min_wp_version'], '<')) { |
|
628 | - $incompatibility_message = sprintf( |
|
629 | - esc_html__( |
|
630 | - '%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.', |
|
631 | - 'event_espresso' |
|
632 | - ), |
|
633 | - $addon_name, |
|
634 | - $addon_settings['min_wp_version'], |
|
635 | - '<br />', |
|
636 | - '<span style="font-weight: bold; color: #D54E21;">', |
|
637 | - '</span><br />' |
|
638 | - ); |
|
639 | - } |
|
640 | - if (! empty($incompatibility_message)) { |
|
641 | - // remove 'activate' from the REQUEST |
|
642 | - // so WP doesn't erroneously tell the user the plugin activated fine when it didn't |
|
643 | - /** @var RequestInterface $request */ |
|
644 | - $request = LoaderFactory::getLoader()->getShared(RequestInterface::class); |
|
645 | - $request->unSetRequestParam('activate', true); |
|
646 | - if (current_user_can('activate_plugins')) { |
|
647 | - // show an error message indicating the plugin didn't activate properly |
|
648 | - EE_Error::add_error($incompatibility_message, __FILE__, __FUNCTION__, __LINE__); |
|
649 | - } |
|
650 | - unset($_GET['activate'], $_REQUEST['activate']); |
|
651 | - if (! function_exists('deactivate_plugins')) { |
|
652 | - require_once ABSPATH . 'wp-admin/includes/plugin.php'; |
|
653 | - } |
|
654 | - deactivate_plugins(plugin_basename($addon_settings['main_file_path'])); |
|
655 | - // BAIL FROM THE ADDON REGISTRATION PROCESS |
|
656 | - return false; |
|
657 | - } |
|
658 | - // addon IS compatible |
|
659 | - return true; |
|
660 | - } |
|
661 | - |
|
662 | - |
|
663 | - /** |
|
664 | - * register namespaces right away before any other files or classes get loaded, but AFTER the version checks |
|
665 | - * |
|
666 | - * @param array $addon_settings |
|
667 | - * @return void |
|
668 | - * @throws EE_Error |
|
669 | - */ |
|
670 | - private static function _setup_namespaces(array $addon_settings) |
|
671 | - { |
|
672 | - // |
|
673 | - if ( |
|
674 | - isset( |
|
675 | - $addon_settings['namespace']['FQNS'], |
|
676 | - $addon_settings['namespace']['DIR'] |
|
677 | - ) |
|
678 | - ) { |
|
679 | - EE_Psr4AutoloaderInit::psr4_loader()->addNamespace( |
|
680 | - $addon_settings['namespace']['FQNS'], |
|
681 | - $addon_settings['namespace']['DIR'] |
|
682 | - ); |
|
683 | - } |
|
684 | - } |
|
685 | - |
|
686 | - |
|
687 | - /** |
|
688 | - * @param string $addon_name |
|
689 | - * @param array $addon_settings |
|
690 | - * @return bool |
|
691 | - * @throws InvalidArgumentException |
|
692 | - * @throws InvalidDataTypeException |
|
693 | - * @throws InvalidInterfaceException |
|
694 | - */ |
|
695 | - private static function _addon_activation(string $addon_name, array $addon_settings): bool |
|
696 | - { |
|
697 | - // this is an activation request |
|
698 | - if (did_action('activate_plugin')) { |
|
699 | - // to find if THIS is the addon that was activated, just check if we have already registered it or not |
|
700 | - // (as the newly-activated addon wasn't around the first time addons were registered). |
|
701 | - if ( |
|
702 | - ! isset(self::$_settings[ $addon_name ]) |
|
703 | - || (isset(self::$_settings[ $addon_name ]) |
|
704 | - && ! isset(self::$_settings[ $addon_name ]['class_name']) |
|
705 | - ) |
|
706 | - ) { |
|
707 | - self::$_settings[ $addon_name ] = $addon_settings; |
|
708 | - $addon = self::_load_and_init_addon_class($addon_name); |
|
709 | - $addon->set_activation_indicator_option(); |
|
710 | - // dont bother setting up the rest of the addon. |
|
711 | - // we know it was just activated and the request will end soon |
|
712 | - } |
|
713 | - return true; |
|
714 | - } |
|
715 | - // make sure addon settings are set correctly without overwriting anything existing |
|
716 | - if (isset(self::$_settings[ $addon_name ])) { |
|
717 | - self::$_settings[ $addon_name ] += $addon_settings; |
|
718 | - } else { |
|
719 | - self::$_settings[ $addon_name ] = $addon_settings; |
|
720 | - } |
|
721 | - return false; |
|
722 | - } |
|
723 | - |
|
724 | - |
|
725 | - /** |
|
726 | - * @param string $addon_name |
|
727 | - * @return void |
|
728 | - * @throws EE_Error |
|
729 | - */ |
|
730 | - private static function _setup_autoloaders(string $addon_name) |
|
731 | - { |
|
732 | - if (! empty(self::$_settings[ $addon_name ]['autoloader_paths'])) { |
|
733 | - // setup autoloader for single file |
|
734 | - EEH_Autoloader::instance()->register_autoloader(self::$_settings[ $addon_name ]['autoloader_paths']); |
|
735 | - } |
|
736 | - // setup autoloaders for folders |
|
737 | - if (! empty(self::$_settings[ $addon_name ]['autoloader_folders'])) { |
|
738 | - foreach ((array) self::$_settings[ $addon_name ]['autoloader_folders'] as $autoloader_folder) { |
|
739 | - EEH_Autoloader::register_autoloaders_for_each_file_in_folder($autoloader_folder); |
|
740 | - } |
|
741 | - } |
|
742 | - } |
|
743 | - |
|
744 | - |
|
745 | - /** |
|
746 | - * register new models and extensions |
|
747 | - * |
|
748 | - * @param string $addon_name |
|
749 | - * @return void |
|
750 | - * @throws EE_Error |
|
751 | - */ |
|
752 | - private static function _register_models_and_extensions(string $addon_name) |
|
753 | - { |
|
754 | - // register new models |
|
755 | - if ( |
|
756 | - ! empty(self::$_settings[ $addon_name ]['model_paths']) |
|
757 | - || ! empty(self::$_settings[ $addon_name ]['class_paths']) |
|
758 | - ) { |
|
759 | - EE_Register_Model::register( |
|
760 | - $addon_name, |
|
761 | - [ |
|
762 | - 'model_paths' => self::$_settings[ $addon_name ]['model_paths'], |
|
763 | - 'class_paths' => self::$_settings[ $addon_name ]['class_paths'], |
|
764 | - ] |
|
765 | - ); |
|
766 | - } |
|
767 | - // register model extensions |
|
768 | - if ( |
|
769 | - ! empty(self::$_settings[ $addon_name ]['model_extension_paths']) |
|
770 | - || ! empty(self::$_settings[ $addon_name ]['class_extension_paths']) |
|
771 | - ) { |
|
772 | - EE_Register_Model_Extensions::register( |
|
773 | - $addon_name, |
|
774 | - [ |
|
775 | - 'model_extension_paths' => self::$_settings[ $addon_name ]['model_extension_paths'], |
|
776 | - 'class_extension_paths' => self::$_settings[ $addon_name ]['class_extension_paths'], |
|
777 | - ] |
|
778 | - ); |
|
779 | - } |
|
780 | - } |
|
781 | - |
|
782 | - |
|
783 | - /** |
|
784 | - * @param string $addon_name |
|
785 | - * @return void |
|
786 | - * @throws EE_Error |
|
787 | - */ |
|
788 | - private static function _register_data_migration_scripts(string $addon_name) |
|
789 | - { |
|
790 | - // setup DMS |
|
791 | - if (! empty(self::$_settings[ $addon_name ]['dms_paths'])) { |
|
792 | - EE_Register_Data_Migration_Scripts::register( |
|
793 | - $addon_name, |
|
794 | - ['dms_paths' => self::$_settings[ $addon_name ]['dms_paths']] |
|
795 | - ); |
|
796 | - } |
|
797 | - } |
|
798 | - |
|
799 | - |
|
800 | - /** |
|
801 | - * @param string $addon_name |
|
802 | - * @return void |
|
803 | - * @throws EE_Error |
|
804 | - */ |
|
805 | - private static function _register_config(string $addon_name) |
|
806 | - { |
|
807 | - // if config_class is present let's register config. |
|
808 | - if (! empty(self::$_settings[ $addon_name ]['config_class'])) { |
|
809 | - EE_Register_Config::register( |
|
810 | - self::$_settings[ $addon_name ]['config_class'], |
|
811 | - [ |
|
812 | - 'config_section' => self::$_settings[ $addon_name ]['config_section'], |
|
813 | - 'config_name' => self::$_settings[ $addon_name ]['config_name'], |
|
814 | - ] |
|
815 | - ); |
|
816 | - } |
|
817 | - } |
|
818 | - |
|
819 | - |
|
820 | - /** |
|
821 | - * @param string $addon_name |
|
822 | - * @return void |
|
823 | - * @throws EE_Error |
|
824 | - */ |
|
825 | - private static function _register_admin_pages(string $addon_name) |
|
826 | - { |
|
827 | - if (! empty(self::$_settings[ $addon_name ]['admin_path'])) { |
|
828 | - EE_Register_Admin_Page::register( |
|
829 | - $addon_name, |
|
830 | - ['page_path' => self::$_settings[ $addon_name ]['admin_path']] |
|
831 | - ); |
|
832 | - } |
|
833 | - } |
|
834 | - |
|
835 | - |
|
836 | - /** |
|
837 | - * @param string $addon_name |
|
838 | - * @return void |
|
839 | - * @throws EE_Error |
|
840 | - */ |
|
841 | - private static function _register_modules(string $addon_name) |
|
842 | - { |
|
843 | - if (! empty(self::$_settings[ $addon_name ]['module_paths'])) { |
|
844 | - EE_Register_Module::register( |
|
845 | - $addon_name, |
|
846 | - ['module_paths' => self::$_settings[ $addon_name ]['module_paths']] |
|
847 | - ); |
|
848 | - } |
|
849 | - } |
|
850 | - |
|
851 | - |
|
852 | - /** |
|
853 | - * @param string $addon_name |
|
854 | - * @return void |
|
855 | - * @throws EE_Error |
|
856 | - */ |
|
857 | - private static function _register_shortcodes(string $addon_name) |
|
858 | - { |
|
859 | - if ( |
|
860 | - ! empty(self::$_settings[ $addon_name ]['shortcode_paths']) |
|
861 | - || ! empty(self::$_settings[ $addon_name ]['shortcode_fqcns']) |
|
862 | - ) { |
|
863 | - EE_Register_Shortcode::register( |
|
864 | - $addon_name, |
|
865 | - [ |
|
866 | - 'shortcode_paths' => self::$_settings[ $addon_name ]['shortcode_paths'] ?? [], |
|
867 | - 'shortcode_fqcns' => self::$_settings[ $addon_name ]['shortcode_fqcns'] ?? [], |
|
868 | - ] |
|
869 | - ); |
|
870 | - } |
|
871 | - } |
|
872 | - |
|
873 | - |
|
874 | - /** |
|
875 | - * @param string $addon_name |
|
876 | - * @return void |
|
877 | - * @throws EE_Error |
|
878 | - */ |
|
879 | - private static function _register_widgets(string $addon_name) |
|
880 | - { |
|
881 | - if (! empty(self::$_settings[ $addon_name ]['widget_paths'])) { |
|
882 | - EE_Register_Widget::register( |
|
883 | - $addon_name, |
|
884 | - ['widget_paths' => self::$_settings[ $addon_name ]['widget_paths']] |
|
885 | - ); |
|
886 | - } |
|
887 | - } |
|
888 | - |
|
889 | - |
|
890 | - /** |
|
891 | - * @param string $addon_name |
|
892 | - * @return void |
|
893 | - * @throws EE_Error |
|
894 | - */ |
|
895 | - private static function _register_capabilities(string $addon_name) |
|
896 | - { |
|
897 | - if (! empty(self::$_settings[ $addon_name ]['capabilities'])) { |
|
898 | - EE_Register_Capabilities::register( |
|
899 | - $addon_name, |
|
900 | - [ |
|
901 | - 'capabilities' => self::$_settings[ $addon_name ]['capabilities'], |
|
902 | - 'capability_maps' => self::$_settings[ $addon_name ]['capability_maps'], |
|
903 | - ] |
|
904 | - ); |
|
905 | - } |
|
906 | - } |
|
907 | - |
|
908 | - |
|
909 | - /** |
|
910 | - * @param string $addon_name |
|
911 | - * @return void |
|
912 | - */ |
|
913 | - private static function _register_message_types(string $addon_name) |
|
914 | - { |
|
915 | - if (! empty(self::$_settings[ $addon_name ]['message_types'])) { |
|
916 | - add_action( |
|
917 | - 'EE_Brewing_Regular___messages_caf', |
|
918 | - ['EE_Register_Addon', 'register_message_types'] |
|
919 | - ); |
|
920 | - } |
|
921 | - } |
|
922 | - |
|
923 | - |
|
924 | - /** |
|
925 | - * @param string $addon_name |
|
926 | - * @return void |
|
927 | - * @throws EE_Error |
|
928 | - */ |
|
929 | - private static function _register_custom_post_types(string $addon_name) |
|
930 | - { |
|
931 | - if ( |
|
932 | - ! empty(self::$_settings[ $addon_name ]['custom_post_types']) |
|
933 | - || ! empty(self::$_settings[ $addon_name ]['custom_taxonomies']) |
|
934 | - ) { |
|
935 | - EE_Register_CPT::register( |
|
936 | - $addon_name, |
|
937 | - [ |
|
938 | - 'cpts' => self::$_settings[ $addon_name ]['custom_post_types'], |
|
939 | - 'cts' => self::$_settings[ $addon_name ]['custom_taxonomies'], |
|
940 | - 'default_terms' => self::$_settings[ $addon_name ]['default_terms'], |
|
941 | - ] |
|
942 | - ); |
|
943 | - } |
|
944 | - } |
|
945 | - |
|
946 | - |
|
947 | - /** |
|
948 | - * @param string $addon_name |
|
949 | - * @return void |
|
950 | - * @throws InvalidArgumentException |
|
951 | - * @throws InvalidInterfaceException |
|
952 | - * @throws InvalidDataTypeException |
|
953 | - * @throws DomainException |
|
954 | - * @throws EE_Error |
|
955 | - */ |
|
956 | - private static function _register_payment_methods(string $addon_name) |
|
957 | - { |
|
958 | - if (! empty(self::$_settings[ $addon_name ]['payment_method_paths'])) { |
|
959 | - EE_Register_Payment_Method::register( |
|
960 | - $addon_name, |
|
961 | - ['payment_method_paths' => self::$_settings[ $addon_name ]['payment_method_paths']] |
|
962 | - ); |
|
963 | - } |
|
964 | - } |
|
965 | - |
|
966 | - |
|
967 | - /** |
|
968 | - * @param string $addon_name |
|
969 | - * @return void |
|
970 | - * @throws InvalidArgumentException |
|
971 | - * @throws InvalidInterfaceException |
|
972 | - * @throws InvalidDataTypeException |
|
973 | - * @throws DomainException |
|
974 | - */ |
|
975 | - private static function registerPrivacyPolicies(string $addon_name) |
|
976 | - { |
|
977 | - if (! empty(self::$_settings[ $addon_name ]['privacy_policies'])) { |
|
978 | - EE_Register_Privacy_Policy::register( |
|
979 | - $addon_name, |
|
980 | - self::$_settings[ $addon_name ]['privacy_policies'] |
|
981 | - ); |
|
982 | - } |
|
983 | - } |
|
984 | - |
|
985 | - |
|
986 | - /** |
|
987 | - * @param string $addon_name |
|
988 | - * @return void |
|
989 | - */ |
|
990 | - private static function registerPersonalDataExporters(string $addon_name) |
|
991 | - { |
|
992 | - if (! empty(self::$_settings[ $addon_name ]['personal_data_exporters'])) { |
|
993 | - EE_Register_Personal_Data_Eraser::register( |
|
994 | - $addon_name, |
|
995 | - self::$_settings[ $addon_name ]['personal_data_exporters'] |
|
996 | - ); |
|
997 | - } |
|
998 | - } |
|
999 | - |
|
1000 | - |
|
1001 | - /** |
|
1002 | - * @param string $addon_name |
|
1003 | - * @return void |
|
1004 | - */ |
|
1005 | - private static function registerPersonalDataErasers(string $addon_name) |
|
1006 | - { |
|
1007 | - if (! empty(self::$_settings[ $addon_name ]['personal_data_erasers'])) { |
|
1008 | - EE_Register_Personal_Data_Eraser::register( |
|
1009 | - $addon_name, |
|
1010 | - self::$_settings[ $addon_name ]['personal_data_erasers'] |
|
1011 | - ); |
|
1012 | - } |
|
1013 | - } |
|
1014 | - |
|
1015 | - |
|
1016 | - /** |
|
1017 | - * Loads and instantiates the EE_Addon class and adds it onto the registry |
|
1018 | - * |
|
1019 | - * @param string $addon_name |
|
1020 | - * @return EE_Addon |
|
1021 | - * @throws InvalidArgumentException |
|
1022 | - * @throws InvalidInterfaceException |
|
1023 | - * @throws InvalidDataTypeException |
|
1024 | - */ |
|
1025 | - private static function _load_and_init_addon_class(string $addon_name): EE_Addon |
|
1026 | - { |
|
1027 | - $addon = self::$loader->getShared( |
|
1028 | - self::$_settings[ $addon_name ]['class_name'], |
|
1029 | - ['EE_Registry::create(addon)' => true] |
|
1030 | - ); |
|
1031 | - if (! $addon instanceof EE_Addon) { |
|
1032 | - throw new DomainException( |
|
1033 | - sprintf( |
|
1034 | - esc_html__('The "%1$s" EE_Addon class failed to instantiate!', 'event_espresso'), |
|
1035 | - self::$_settings[ $addon_name ]['class_name'] |
|
1036 | - ) |
|
1037 | - ); |
|
1038 | - } |
|
1039 | - // setter inject dep map if required |
|
1040 | - if ($addon->dependencyMap() === null) { |
|
1041 | - $addon->setDependencyMap(self::$loader->getShared('EE_Dependency_Map')); |
|
1042 | - } |
|
1043 | - // setter inject domain if required |
|
1044 | - EE_Register_Addon::injectAddonDomain($addon_name, $addon); |
|
1045 | - |
|
1046 | - $addon->set_name($addon_name); |
|
1047 | - $addon->set_plugin_slug(self::$_settings[ $addon_name ]['plugin_slug']); |
|
1048 | - $addon->set_plugin_basename(self::$_settings[ $addon_name ]['plugin_basename']); |
|
1049 | - $addon->set_main_plugin_file(self::$_settings[ $addon_name ]['main_file_path']); |
|
1050 | - $addon->set_plugin_action_slug(self::$_settings[ $addon_name ]['plugin_action_slug']); |
|
1051 | - $addon->set_plugins_page_row(self::$_settings[ $addon_name ]['plugins_page_row']); |
|
1052 | - $addon->set_version(self::$_settings[ $addon_name ]['version']); |
|
1053 | - $addon->set_min_core_version(self::_effective_version(self::$_settings[ $addon_name ]['min_core_version'])); |
|
1054 | - $addon->set_config_section(self::$_settings[ $addon_name ]['config_section']); |
|
1055 | - $addon->set_config_class(self::$_settings[ $addon_name ]['config_class']); |
|
1056 | - $addon->set_config_name(self::$_settings[ $addon_name ]['config_name']); |
|
1057 | - if (! empty(self::$_settings[ $addon_name ]['pm_slug'])) { |
|
1058 | - $addon->setPaymentmethodSlug(self::$_settings[ $addon_name ]['pm_slug']); |
|
1059 | - } |
|
1060 | - do_action( |
|
1061 | - 'AHEE__EE_Register_Addon___load_and_init_addon_class', |
|
1062 | - $addon, |
|
1063 | - $addon_name, |
|
1064 | - self::$_settings |
|
1065 | - ); |
|
1066 | - // unfortunately this can't be hooked in upon construction, |
|
1067 | - // because we don't have the plugin's mainfile path upon construction. |
|
1068 | - register_deactivation_hook($addon->get_main_plugin_file(), [$addon, 'deactivation']); |
|
1069 | - // call any additional admin_callback functions during load_admin_controller hook |
|
1070 | - if (! empty(self::$_settings[ $addon_name ]['admin_callback'])) { |
|
1071 | - add_action( |
|
1072 | - 'AHEE__EE_System__load_controllers__load_admin_controllers', |
|
1073 | - [$addon, self::$_settings[ $addon_name ]['admin_callback']] |
|
1074 | - ); |
|
1075 | - } |
|
1076 | - return $addon; |
|
1077 | - } |
|
1078 | - |
|
1079 | - |
|
1080 | - /** |
|
1081 | - * @param string $addon_name |
|
1082 | - * @param EE_Addon $addon |
|
1083 | - * @since 4.10.13.p |
|
1084 | - */ |
|
1085 | - private static function injectAddonDomain(string $addon_name, EE_Addon $addon) |
|
1086 | - { |
|
1087 | - if ($addon instanceof RequiresDomainInterface && $addon->domain() === null) { |
|
1088 | - // using supplied Domain object |
|
1089 | - $domain = self::$_settings[ $addon_name ]['domain'] instanceof DomainInterface |
|
1090 | - ? self::$_settings[ $addon_name ]['domain'] |
|
1091 | - : null; |
|
1092 | - // or construct one using Domain FQCN |
|
1093 | - if ($domain === null && self::$_settings[ $addon_name ]['domain_fqcn'] !== '') { |
|
1094 | - $domain = self::$loader->getShared( |
|
1095 | - self::$_settings[ $addon_name ]['domain_fqcn'], |
|
1096 | - [ |
|
1097 | - new EventEspresso\core\domain\values\FilePath( |
|
1098 | - self::$_settings[ $addon_name ]['main_file_path'] |
|
1099 | - ), |
|
1100 | - EventEspresso\core\domain\values\Version::fromString( |
|
1101 | - self::$_settings[ $addon_name ]['version'] |
|
1102 | - ), |
|
1103 | - ] |
|
1104 | - ); |
|
1105 | - } |
|
1106 | - if ($domain instanceof DomainInterface) { |
|
1107 | - $addon->setDomain($domain); |
|
1108 | - } |
|
1109 | - } |
|
1110 | - } |
|
1111 | - |
|
1112 | - |
|
1113 | - /** |
|
1114 | - * @return void |
|
1115 | - * @deprecated 5.0.0.p |
|
1116 | - */ |
|
1117 | - public static function load_pue_update() |
|
1118 | - { |
|
1119 | - } |
|
1120 | - |
|
1121 | - |
|
1122 | - /** |
|
1123 | - * Callback for EE_Brewing_Regular__messages_caf hook used to register message types. |
|
1124 | - * |
|
1125 | - * @return void |
|
1126 | - * @throws EE_Error |
|
1127 | - * @since 4.4.0 |
|
1128 | - */ |
|
1129 | - public static function register_message_types() |
|
1130 | - { |
|
1131 | - foreach (self::$_settings as $settings) { |
|
1132 | - if (! empty($settings['message_types'])) { |
|
1133 | - foreach ((array) $settings['message_types'] as $message_type => $message_type_settings) { |
|
1134 | - EE_Register_Message_Type::register($message_type, $message_type_settings); |
|
1135 | - } |
|
1136 | - } |
|
1137 | - } |
|
1138 | - } |
|
1139 | - |
|
1140 | - |
|
1141 | - private static function registerLicense($addon_name) |
|
1142 | - { |
|
1143 | - static $request = null; |
|
1144 | - if ($request === null) { |
|
1145 | - /** @var RequestInterface $request */ |
|
1146 | - $request = LoaderFactory::getLoader()->getShared(RequestInterface::class); |
|
1147 | - } |
|
1148 | - if ($request->isWordPressHeartbeat()) { |
|
1149 | - return; |
|
1150 | - } |
|
1151 | - $addon_settings = self::$_settings[ $addon_name ] ?? []; |
|
1152 | - if (empty($addon_settings)) { |
|
1153 | - return; |
|
1154 | - } |
|
1155 | - $license_data = isset($addon_settings['license']) ? (array) $addon_settings['license'] : []; |
|
1156 | - // copy known values from addon settings to license data if anything's missing |
|
1157 | - $license_data += [ |
|
1158 | - 'main_file_path' => $addon_settings['main_file_path'] ?? '', |
|
1159 | - 'min_core_version' => $addon_settings['min_core_version'] ?? '', |
|
1160 | - 'plugin_id' => 0, // no corresponding value in addon settings |
|
1161 | - 'plugin_slug' => $addon_settings['plugin_slug'] ?? '', |
|
1162 | - 'version' => $addon_settings['version'] ?? '', |
|
1163 | - ]; |
|
1164 | - EventEspresso\core\services\licensing\AddonLicense::register($addon_name, $license_data); |
|
1165 | - } |
|
1166 | - |
|
1167 | - |
|
1168 | - /** |
|
1169 | - * This deregisters an addon that was previously registered with a specific addon_name. |
|
1170 | - * |
|
1171 | - * @param string $addon_name the name for the addon that was previously registered |
|
1172 | - * @throws DomainException |
|
1173 | - * @throws InvalidArgumentException |
|
1174 | - * @throws InvalidDataTypeException |
|
1175 | - * @throws InvalidInterfaceException |
|
1176 | - * @since 4.3.0 |
|
1177 | - */ |
|
1178 | - public static function deregister(string $addon_name = '') |
|
1179 | - { |
|
1180 | - if (isset(self::$_settings[ $addon_name ]['class_name'])) { |
|
1181 | - try { |
|
1182 | - do_action('AHEE__EE_Register_Addon__deregister__before', $addon_name); |
|
1183 | - $class_name = self::$_settings[ $addon_name ]['class_name']; |
|
1184 | - if (! empty(self::$_settings[ $addon_name ]['dms_paths'])) { |
|
1185 | - // setup DMS |
|
1186 | - EE_Register_Data_Migration_Scripts::deregister($addon_name); |
|
1187 | - } |
|
1188 | - if (! empty(self::$_settings[ $addon_name ]['admin_path'])) { |
|
1189 | - // register admin page |
|
1190 | - EE_Register_Admin_Page::deregister($addon_name); |
|
1191 | - } |
|
1192 | - if (! empty(self::$_settings[ $addon_name ]['module_paths'])) { |
|
1193 | - // add to list of modules to be registered |
|
1194 | - EE_Register_Module::deregister($addon_name); |
|
1195 | - } |
|
1196 | - if ( |
|
1197 | - ! empty(self::$_settings[ $addon_name ]['shortcode_paths']) |
|
1198 | - || ! empty(self::$_settings[ $addon_name ]['shortcode_fqcns']) |
|
1199 | - ) { |
|
1200 | - // add to list of shortcodes to be registered |
|
1201 | - EE_Register_Shortcode::deregister($addon_name); |
|
1202 | - } |
|
1203 | - if (! empty(self::$_settings[ $addon_name ]['config_class'])) { |
|
1204 | - // if config_class present let's register config. |
|
1205 | - EE_Register_Config::deregister(self::$_settings[ $addon_name ]['config_class']); |
|
1206 | - } |
|
1207 | - if (! empty(self::$_settings[ $addon_name ]['widget_paths'])) { |
|
1208 | - // add to list of widgets to be registered |
|
1209 | - EE_Register_Widget::deregister($addon_name); |
|
1210 | - } |
|
1211 | - if ( |
|
1212 | - ! empty(self::$_settings[ $addon_name ]['model_paths']) |
|
1213 | - || ! empty(self::$_settings[ $addon_name ]['class_paths']) |
|
1214 | - ) { |
|
1215 | - // add to list of shortcodes to be registered |
|
1216 | - EE_Register_Model::deregister($addon_name); |
|
1217 | - } |
|
1218 | - if ( |
|
1219 | - ! empty(self::$_settings[ $addon_name ]['model_extension_paths']) |
|
1220 | - || ! empty(self::$_settings[ $addon_name ]['class_extension_paths']) |
|
1221 | - ) { |
|
1222 | - // add to list of shortcodes to be registered |
|
1223 | - EE_Register_Model_Extensions::deregister($addon_name); |
|
1224 | - } |
|
1225 | - if (! empty(self::$_settings[ $addon_name ]['message_types'])) { |
|
1226 | - foreach ((array) self::$_settings[ $addon_name ]['message_types'] as $message_type => $message_type_settings) { |
|
1227 | - EE_Register_Message_Type::deregister($message_type); |
|
1228 | - } |
|
1229 | - } |
|
1230 | - // deregister capabilities for addon |
|
1231 | - if ( |
|
1232 | - ! empty(self::$_settings[ $addon_name ]['capabilities']) |
|
1233 | - || ! empty(self::$_settings[ $addon_name ]['capability_maps']) |
|
1234 | - ) { |
|
1235 | - EE_Register_Capabilities::deregister($addon_name); |
|
1236 | - } |
|
1237 | - // deregister custom_post_types for addon |
|
1238 | - if (! empty(self::$_settings[ $addon_name ]['custom_post_types'])) { |
|
1239 | - EE_Register_CPT::deregister($addon_name); |
|
1240 | - } |
|
1241 | - if (! empty(self::$_settings[ $addon_name ]['payment_method_paths'])) { |
|
1242 | - EE_Register_Payment_Method::deregister($addon_name); |
|
1243 | - } |
|
1244 | - $addon = EE_Registry::instance()->getAddon($class_name); |
|
1245 | - if ($addon instanceof EE_Addon) { |
|
1246 | - remove_action( |
|
1247 | - 'deactivate_' . $addon->get_main_plugin_file_basename(), |
|
1248 | - [$addon, 'deactivation'] |
|
1249 | - ); |
|
1250 | - remove_action( |
|
1251 | - 'AHEE__EE_System__perform_activations_upgrades_and_migrations', |
|
1252 | - [$addon, 'initialize_db_if_no_migrations_required'] |
|
1253 | - ); |
|
1254 | - // remove `after_registration` call |
|
1255 | - remove_action( |
|
1256 | - 'AHEE__EE_System__load_espresso_addons__complete', |
|
1257 | - [$addon, 'after_registration'], |
|
1258 | - 999 |
|
1259 | - ); |
|
1260 | - } |
|
1261 | - EE_Registry::instance()->removeAddon($class_name); |
|
1262 | - LoaderFactory::getLoader()->remove($class_name); |
|
1263 | - } catch (OutOfBoundsException $addon_not_yet_registered_exception) { |
|
1264 | - // the add-on was not yet registered in the registry, |
|
1265 | - // so RegistryContainer::__get() throws this exception. |
|
1266 | - // also no need to worry about this or log it, |
|
1267 | - // it's ok to deregister an add-on before its registered in the registry |
|
1268 | - } catch (Exception $e) { |
|
1269 | - new ExceptionLogger($e); |
|
1270 | - } |
|
1271 | - unset(self::$_settings[ $addon_name ]); |
|
1272 | - do_action('AHEE__EE_Register_Addon__deregister__after', $addon_name); |
|
1273 | - } |
|
1274 | - } |
|
1275 | - |
|
1276 | - |
|
1277 | - public static function reset(): void |
|
1278 | - { |
|
1279 | - EE_Register_Addon::$_settings = []; |
|
1280 | - } |
|
1281 | - |
|
1282 | - |
|
1283 | - public static function resetAll(): void |
|
1284 | - { |
|
1285 | - // EE_Register_Addon::reset(); |
|
1286 | - EE_Register_Admin_Page::reset(); |
|
1287 | - EE_Register_Capabilities::reset(); |
|
1288 | - EE_Register_Config::reset(); |
|
1289 | - EE_Register_CPT::reset(); |
|
1290 | - EE_Register_Data_Migration_Scripts::reset(); |
|
1291 | - EE_Register_Message_Type::reset(); |
|
1292 | - EE_Register_Messages_Shortcode_Library::reset(); |
|
1293 | - EE_Register_Messages_Template_Pack::reset(); |
|
1294 | - EE_Register_Messages_Template_Variations::reset(); |
|
1295 | - EE_Register_Model::reset(); |
|
1296 | - EE_Register_Model_Extensions::reset(); |
|
1297 | - EE_Register_Module::reset(); |
|
1298 | - EE_Register_Payment_Method::reset(); |
|
1299 | - EE_Register_Personal_Data_Eraser::reset(); |
|
1300 | - EE_Register_Personal_Data_Exporter::reset(); |
|
1301 | - EE_Register_Privacy_Policy::reset(); |
|
1302 | - EE_Register_Shortcode::reset(); |
|
1303 | - EE_Register_Widget::reset(); |
|
1304 | - } |
|
27 | + /** |
|
28 | + * possibly truncated version of the EE core version string |
|
29 | + * |
|
30 | + * @var string |
|
31 | + */ |
|
32 | + protected static $_core_version = ''; |
|
33 | + |
|
34 | + /** |
|
35 | + * Holds values for registered addons |
|
36 | + * |
|
37 | + * @var array |
|
38 | + */ |
|
39 | + protected static $_settings = []; |
|
40 | + |
|
41 | + /** |
|
42 | + * @var array $_incompatible_addons keys are addon SLUGS |
|
43 | + * (first argument passed to EE_Register_Addon::register()), keys are |
|
44 | + * their MINIMUM VERSION (with all 5 parts. Eg 1.2.3.rc.004). |
|
45 | + * Generally this should be used sparingly, as we don't want to muddle up |
|
46 | + * EE core with knowledge of ALL the addons out there. |
|
47 | + * If you want NO versions of an addon to run with a certain version of core, |
|
48 | + * it's usually best to define the addon's "min_core_version" as part of its call |
|
49 | + * to EE_Register_Addon::register(), rather than using this array with a super |
|
50 | + * high value for its minimum plugin version. |
|
51 | + */ |
|
52 | + protected static $_incompatible_addons = [ |
|
53 | + 'Multi_Event_Registration' => '2.0.11.rc.002', |
|
54 | + 'Promotions' => '1.0.0.rc.084', |
|
55 | + 'EE_WPUsers' => '2.1.3.p', |
|
56 | + ]; |
|
57 | + |
|
58 | + /** |
|
59 | + * @var LoaderInterface |
|
60 | + */ |
|
61 | + protected static $loader; |
|
62 | + |
|
63 | + |
|
64 | + /** |
|
65 | + * We should always be comparing core to a version like '4.3.0.rc.000', |
|
66 | + * not just '4.3.0'. |
|
67 | + * So if the addon developer doesn't provide that full version string, |
|
68 | + * fill in the blanks for them |
|
69 | + * |
|
70 | + * @param string $min_core_version |
|
71 | + * @return string always like '4.3.0.rc.000' |
|
72 | + */ |
|
73 | + protected static function _effective_version(string $min_core_version): string |
|
74 | + { |
|
75 | + // versions: 4 . 3 . 1 . p . 123 |
|
76 | + // offsets: 0 . 1 . 2 . 3 . 4 |
|
77 | + $version_parts = explode('.', $min_core_version); |
|
78 | + // check they specified the micro version (after 2nd period) |
|
79 | + if (! isset($version_parts[2])) { |
|
80 | + $version_parts[2] = '0'; |
|
81 | + } |
|
82 | + // if they didn't specify the 'p', or 'rc' part. Just assume the lowest possible |
|
83 | + // soon we can assume that's 'rc', but this current version is 'alpha' |
|
84 | + if (! isset($version_parts[3])) { |
|
85 | + $version_parts[3] = 'dev'; |
|
86 | + } |
|
87 | + if (! isset($version_parts[4])) { |
|
88 | + $version_parts[4] = '000'; |
|
89 | + } |
|
90 | + return implode('.', $version_parts); |
|
91 | + } |
|
92 | + |
|
93 | + |
|
94 | + /** |
|
95 | + * Returns whether or not the min core version requirement of the addon is met |
|
96 | + * |
|
97 | + * @param string $min_core_version the minimum core version required by the addon |
|
98 | + * @param string $actual_core_version the actual core version, optional |
|
99 | + * @return bool |
|
100 | + */ |
|
101 | + public static function _meets_min_core_version_requirement( |
|
102 | + string $min_core_version, |
|
103 | + string $actual_core_version = EVENT_ESPRESSO_VERSION |
|
104 | + ): bool { |
|
105 | + return version_compare( |
|
106 | + self::_effective_version($actual_core_version), |
|
107 | + self::_effective_version($min_core_version), |
|
108 | + '>=' |
|
109 | + ); |
|
110 | + } |
|
111 | + |
|
112 | + |
|
113 | + /** |
|
114 | + * Method for registering new EE_Addons. |
|
115 | + * Should be called AFTER AHEE__EE_System__load_espresso_addons but BEFORE |
|
116 | + * AHEE__EE_System___detect_if_activation_or_upgrade__begin in order to register all its components. However, it |
|
117 | + * may also be called after the 'activate_plugin' action (when an addon is activated), because an activating addon |
|
118 | + * won't be loaded by WP until after AHEE__EE_System__load_espresso_addons has fired. If its called after |
|
119 | + * 'activate_plugin', it registers the addon still, but its components are not registered |
|
120 | + * (they shouldn't be needed anyways, because it's just an activation request and they won't have a chance to do |
|
121 | + * anything anyways). Instead, it just sets the newly-activated addon's activation indicator wp option and returns |
|
122 | + * (so that we can detect that the addon has activated on the subsequent request) |
|
123 | + * |
|
124 | + * @param string $addon_name [Required] the EE_Addon's name. |
|
125 | + * @param array $setup_args { |
|
126 | + * An array of arguments provided for registering |
|
127 | + * the message type. |
|
128 | + * @type string $class_name the addon's main file name. |
|
129 | + * If left blank, generated from the addon name, |
|
130 | + * changes something like "calendar" to |
|
131 | + * "EE_Calendar" |
|
132 | + * @type string $min_core_version the minimum version of EE Core that the |
|
133 | + * addon will work with. eg "4.8.1.rc.084" |
|
134 | + * @type string $version the "software" version for the addon. eg |
|
135 | + * "1.0.0.p" for a first stable release, or |
|
136 | + * "1.0.0.rc.043" for a version in progress |
|
137 | + * @type string $main_file_path the full server path to the main file |
|
138 | + * loaded directly by WP |
|
139 | + * @type DomainInterface $domain child class of |
|
140 | + * EventEspresso\core\domain\DomainBase |
|
141 | + * @type string $domain_fqcn Fully Qualified Class Name |
|
142 | + * for the addon's Domain class |
|
143 | + * (see EventEspresso\core\domain\Domain) |
|
144 | + * @type string $admin_path full server path to the folder where the |
|
145 | + * addon\'s admin files reside |
|
146 | + * @type string $admin_callback a method to be called when the EE Admin is |
|
147 | + * first invoked, can be used for hooking into |
|
148 | + * any admin page |
|
149 | + * @type string $config_section the section name for this addon's |
|
150 | + * configuration settings section |
|
151 | + * (defaults to "addons") |
|
152 | + * @type string $config_class the class name for this addon's |
|
153 | + * configuration settings object |
|
154 | + * @type string $config_name the class name for this addon's |
|
155 | + * configuration settings object |
|
156 | + * @type string $autoloader_paths [Required] an array of class names and the full |
|
157 | + * server paths to those files. |
|
158 | + * @type string $autoloader_folders an array of "full server paths" for any |
|
159 | + * folders containing classes that might be |
|
160 | + * invoked by the addon |
|
161 | + * @type string $dms_paths [Required] an array of full server paths to |
|
162 | + * folders that contain data migration scripts. |
|
163 | + * The key should be the EE_Addon class name that |
|
164 | + * this set of data migration scripts belongs to. |
|
165 | + * If the EE_Addon class is namespaced, then this |
|
166 | + * needs to be the Fully Qualified Class Name |
|
167 | + * @type string $module_paths an array of full server paths to any |
|
168 | + * EED_Modules used by the addon |
|
169 | + * @type string $shortcode_paths an array of full server paths to folders |
|
170 | + * that contain EES_Shortcodes |
|
171 | + * @type string $widget_paths an array of full server paths to folders |
|
172 | + * that contain WP_Widgets |
|
173 | + * @type array $capabilities an array indexed by role name |
|
174 | + * (i.e administrator,author ) and the values |
|
175 | + * are an array of caps to add to the role. |
|
176 | + * 'administrator' => array( |
|
177 | + * 'read_addon', |
|
178 | + * 'edit_addon', |
|
179 | + * etc. |
|
180 | + * ). |
|
181 | + * @type EE_Meta_Capability_Map[] $capability_maps an array of EE_Meta_Capability_Map object |
|
182 | + * for any addons that need to register any |
|
183 | + * special meta mapped capabilities. Should |
|
184 | + * be indexed where the key is the |
|
185 | + * EE_Meta_Capability_Map class name and the |
|
186 | + * values are the arguments sent to the class. |
|
187 | + * @type array $model_paths array of folders containing DB models |
|
188 | + * @return bool |
|
189 | + * @throws DomainException |
|
190 | + * @throws EE_Error |
|
191 | + * @throws InvalidArgumentException |
|
192 | + * @throws InvalidDataTypeException |
|
193 | + * @throws InvalidInterfaceException |
|
194 | + * @since 4.3.0 |
|
195 | + * @see EE_Register_Model |
|
196 | + * @type array $class_paths array of folders containing DB classes |
|
197 | + * @see EE_Register_Model |
|
198 | + * @type array $model_extension_paths array of folders containing DB model |
|
199 | + * extensions |
|
200 | + * @see EE_Register_Model_Extension |
|
201 | + * @type array $class_extension_paths array of folders containing DB class |
|
202 | + * extensions |
|
203 | + * @see EE_Register_Model_Extension |
|
204 | + * @type array message_types { |
|
205 | + * An array of message types with the key as |
|
206 | + * the message type name and the values as |
|
207 | + * below: |
|
208 | + * @type string $mtfilename [Required] The filename of the message type |
|
209 | + * being registered. This will be the main |
|
210 | + * EE_{Message Type Name}_message_type class. |
|
211 | + * for example: |
|
212 | + * EE_Declined_Registration_message_type.class.php |
|
213 | + * @type array $autoloadpaths [Required] An array of paths to add to the |
|
214 | + * messages autoloader for the new message type. |
|
215 | + * @type array $messengers_to_activate_with An array of messengers that this message |
|
216 | + * type should activate with. Each value in |
|
217 | + * the |
|
218 | + * array |
|
219 | + * should match the name property of a |
|
220 | + * EE_messenger. Optional. |
|
221 | + * @type array $messengers_to_validate_with An array of messengers that this message |
|
222 | + * type should validate with. Each value in |
|
223 | + * the |
|
224 | + * array |
|
225 | + * should match the name property of an |
|
226 | + * EE_messenger. |
|
227 | + * Optional. |
|
228 | + * } |
|
229 | + * @type array $custom_post_types |
|
230 | + * @type array $custom_taxonomies |
|
231 | + * @type array $payment_method_paths each element is the folder containing the |
|
232 | + * EE_PMT_Base child class |
|
233 | + * (eg, |
|
234 | + * '/wp-content/plugins/my_plugin/Payomatic/' |
|
235 | + * which contains the files |
|
236 | + * EE_PMT_Payomatic.pm.php) |
|
237 | + * @type array $default_terms |
|
238 | + * @type array $namespace { |
|
239 | + * An array with two items for registering the |
|
240 | + * addon's namespace. (If, for some reason, you |
|
241 | + * require additional namespaces, |
|
242 | + * use |
|
243 | + * EventEspresso\core\Psr4Autoloader::addNamespace() |
|
244 | + * directly) |
|
245 | + * @see EventEspresso\core\Psr4Autoloader::addNamespace() |
|
246 | + * @type string $FQNS the namespace prefix |
|
247 | + * @type string $DIR a base directory for class files in the |
|
248 | + * namespace. |
|
249 | + * } |
|
250 | + * } |
|
251 | + * @type string $privacy_policies FQNSs (namespaces, each of which contains only |
|
252 | + * privacy policy classes) or FQCNs (specific |
|
253 | + * classnames of privacy policy classes) |
|
254 | + * @type string $personal_data_exporters FQNSs (namespaces, each of which contains only |
|
255 | + * privacy policy classes) or FQCNs (specific |
|
256 | + * classnames of privacy policy classes) |
|
257 | + * @type string $personal_data_erasers FQNSs (namespaces, each of which contains only |
|
258 | + * privacy policy classes) or FQCNs (specific |
|
259 | + * classnames of privacy policy classes) |
|
260 | + */ |
|
261 | + public static function register(string $addon_name = '', array $setup_args = []): bool |
|
262 | + { |
|
263 | + // $addon_name = basename($addon_name); |
|
264 | + if (! self::$loader instanceof LoaderInterface) { |
|
265 | + self::$loader = LoaderFactory::getLoader(); |
|
266 | + } |
|
267 | + // make sure this was called in the right place! |
|
268 | + if ( |
|
269 | + ! did_action('activate_plugin') |
|
270 | + && ( |
|
271 | + ! did_action('AHEE__EE_System__load_espresso_addons') |
|
272 | + || did_action('AHEE__EE_System___detect_if_activation_or_upgrade__begin') |
|
273 | + ) |
|
274 | + ) { |
|
275 | + EE_Error::doing_it_wrong( |
|
276 | + __METHOD__, |
|
277 | + sprintf( |
|
278 | + esc_html__( |
|
279 | + '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.', |
|
280 | + 'event_espresso' |
|
281 | + ), |
|
282 | + $addon_name |
|
283 | + ), |
|
284 | + '4.3.0' |
|
285 | + ); |
|
286 | + return false; |
|
287 | + } |
|
288 | + // required fields MUST be present, so let's make sure they are. |
|
289 | + EE_Register_Addon::_verify_parameters($addon_name, $setup_args); |
|
290 | + // get class name for addon |
|
291 | + $class_name = EE_Register_Addon::_parse_class_name($addon_name, $setup_args); |
|
292 | + // setup $_settings array from incoming values. |
|
293 | + $addon_settings = EE_Register_Addon::_get_addon_settings($class_name, $setup_args); |
|
294 | + // allow early addon setup or modification of addon api settings |
|
295 | + self::$_settings = (array) apply_filters( |
|
296 | + 'FHEE__EE_Register_Addon__register', |
|
297 | + self::$_settings, |
|
298 | + $addon_name, |
|
299 | + $class_name, |
|
300 | + $setup_args |
|
301 | + ); |
|
302 | + // does this addon work with this version of core or WordPress ? |
|
303 | + // does this addon work with this version of core or WordPress ? |
|
304 | + if (! EE_Register_Addon::_addon_is_compatible($addon_name, $addon_settings)) { |
|
305 | + return false; |
|
306 | + } |
|
307 | + // register namespaces |
|
308 | + EE_Register_Addon::_setup_namespaces($addon_settings); |
|
309 | + // check if this is an activation request |
|
310 | + if (EE_Register_Addon::_addon_activation($addon_name, $addon_settings)) { |
|
311 | + // dont bother setting up the rest of the addon atm |
|
312 | + return false; |
|
313 | + } |
|
314 | + // we need cars |
|
315 | + EE_Register_Addon::_setup_autoloaders($addon_name); |
|
316 | + // register new models and extensions |
|
317 | + EE_Register_Addon::_register_models_and_extensions($addon_name); |
|
318 | + // setup DMS |
|
319 | + EE_Register_Addon::_register_data_migration_scripts($addon_name); |
|
320 | + // if config_class is present let's register config. |
|
321 | + EE_Register_Addon::_register_config($addon_name); |
|
322 | + // register admin pages |
|
323 | + EE_Register_Addon::_register_admin_pages($addon_name); |
|
324 | + // add to list of modules to be registered |
|
325 | + EE_Register_Addon::_register_modules($addon_name); |
|
326 | + // add to list of shortcodes to be registered |
|
327 | + EE_Register_Addon::_register_shortcodes($addon_name); |
|
328 | + // add to list of widgets to be registered |
|
329 | + EE_Register_Addon::_register_widgets($addon_name); |
|
330 | + // register capability related stuff. |
|
331 | + EE_Register_Addon::_register_capabilities($addon_name); |
|
332 | + // any message type to register? |
|
333 | + EE_Register_Addon::_register_message_types($addon_name); |
|
334 | + // any custom post type/ custom capabilities or default terms to register |
|
335 | + EE_Register_Addon::_register_custom_post_types($addon_name); |
|
336 | + // and any payment methods |
|
337 | + EE_Register_Addon::_register_payment_methods($addon_name); |
|
338 | + // and privacy policy generators |
|
339 | + EE_Register_Addon::registerPrivacyPolicies($addon_name); |
|
340 | + // and privacy policy generators |
|
341 | + EE_Register_Addon::registerPersonalDataExporters($addon_name); |
|
342 | + // and privacy policy generators |
|
343 | + EE_Register_Addon::registerPersonalDataErasers($addon_name); |
|
344 | + EE_Register_Addon::registerLicense($addon_name); |
|
345 | + // load and instantiate main addon class |
|
346 | + $addon = EE_Register_Addon::_load_and_init_addon_class($addon_name); |
|
347 | + // delay calling after_registration hook on each addon until after all add-ons have been registered. |
|
348 | + add_action('AHEE__EE_System__load_espresso_addons__complete', [$addon, 'after_registration'], 999); |
|
349 | + return $addon instanceof EE_Addon; |
|
350 | + } |
|
351 | + |
|
352 | + |
|
353 | + /** |
|
354 | + * @param string $addon_name |
|
355 | + * @param array $setup_args |
|
356 | + * @return void |
|
357 | + * @throws EE_Error |
|
358 | + */ |
|
359 | + private static function _verify_parameters(string $addon_name, array $setup_args) |
|
360 | + { |
|
361 | + // required fields MUST be present, so let's make sure they are. |
|
362 | + if (empty($addon_name) || empty($setup_args)) { |
|
363 | + throw new EE_Error( |
|
364 | + esc_html__( |
|
365 | + '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.', |
|
366 | + 'event_espresso' |
|
367 | + ) |
|
368 | + ); |
|
369 | + } |
|
370 | + if (empty($setup_args['main_file_path'])) { |
|
371 | + throw new EE_Error( |
|
372 | + sprintf( |
|
373 | + esc_html__( |
|
374 | + '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', |
|
375 | + 'event_espresso' |
|
376 | + ), |
|
377 | + implode(',', array_keys($setup_args)) |
|
378 | + ) |
|
379 | + ); |
|
380 | + } |
|
381 | + // check that addon has not already been registered with that name |
|
382 | + if (isset(self::$_settings[ $addon_name ]) && ! did_action('activate_plugin')) { |
|
383 | + throw new EE_Error( |
|
384 | + sprintf( |
|
385 | + esc_html__( |
|
386 | + 'An EE_Addon with the name "%s" has already been registered and each EE_Addon requires a unique name.', |
|
387 | + 'event_espresso' |
|
388 | + ), |
|
389 | + $addon_name |
|
390 | + ) |
|
391 | + ); |
|
392 | + } |
|
393 | + } |
|
394 | + |
|
395 | + |
|
396 | + /** |
|
397 | + * @param string $addon_name |
|
398 | + * @param array $setup_args |
|
399 | + * @return string |
|
400 | + */ |
|
401 | + private static function _parse_class_name(string $addon_name, array $setup_args): string |
|
402 | + { |
|
403 | + if (empty($setup_args['class_name'])) { |
|
404 | + // generate one by first separating name with spaces |
|
405 | + $class_name = str_replace(['-', '_'], ' ', trim($addon_name)); |
|
406 | + // capitalize, then replace spaces with underscores |
|
407 | + $class_name = str_replace(' ', '_', ucwords($class_name)); |
|
408 | + } else { |
|
409 | + $class_name = $setup_args['class_name']; |
|
410 | + } |
|
411 | + // check if classname is fully qualified or is a legacy classname already prefixed with 'EE_' |
|
412 | + return strpos($class_name, '\\') || strpos($class_name, 'EE_') === 0 |
|
413 | + ? $class_name |
|
414 | + : 'EE_' . $class_name; |
|
415 | + } |
|
416 | + |
|
417 | + |
|
418 | + /** |
|
419 | + * @param string $class_name |
|
420 | + * @param array $setup_args |
|
421 | + * @return array |
|
422 | + */ |
|
423 | + private static function _get_addon_settings(string $class_name, array $setup_args): array |
|
424 | + { |
|
425 | + // setup $_settings array from incoming values. |
|
426 | + $addon_settings = [ |
|
427 | + // generated from the addon name, changes something like "calendar" to "EE_Calendar" |
|
428 | + 'class_name' => $class_name, |
|
429 | + // the addon slug for use in URLs, etc |
|
430 | + 'plugin_slug' => isset($setup_args['plugin_slug']) |
|
431 | + ? (string) $setup_args['plugin_slug'] |
|
432 | + : sanitize_key($class_name), |
|
433 | + // page slug to be used when generating the "Settings" link on the WP plugin page |
|
434 | + 'plugin_action_slug' => isset($setup_args['plugin_action_slug']) |
|
435 | + ? (string) $setup_args['plugin_action_slug'] |
|
436 | + : '', |
|
437 | + // the "software" version for the addon |
|
438 | + 'version' => isset($setup_args['version']) |
|
439 | + ? (string) $setup_args['version'] |
|
440 | + : '', |
|
441 | + // the minimum version of EE Core that the addon will work with |
|
442 | + 'min_core_version' => isset($setup_args['min_core_version']) |
|
443 | + ? (string) $setup_args['min_core_version'] |
|
444 | + : '', |
|
445 | + // the minimum version of WordPress that the addon will work with |
|
446 | + 'min_wp_version' => isset($setup_args['min_wp_version']) |
|
447 | + ? (string) $setup_args['min_wp_version'] |
|
448 | + : EE_MIN_WP_VER_REQUIRED, |
|
449 | + // full server path to main file (file loaded directly by WP) |
|
450 | + 'main_file_path' => isset($setup_args['main_file_path']) |
|
451 | + ? (string) $setup_args['main_file_path'] |
|
452 | + : '', |
|
453 | + // instance of \EventEspresso\core\domain\DomainInterface |
|
454 | + 'domain' => isset($setup_args['domain']) && $setup_args['domain'] instanceof DomainInterface |
|
455 | + ? $setup_args['domain'] |
|
456 | + : null, |
|
457 | + // Fully Qualified Class Name for the addon's Domain class |
|
458 | + 'domain_fqcn' => isset($setup_args['domain_fqcn']) |
|
459 | + ? (string) $setup_args['domain_fqcn'] |
|
460 | + : '', |
|
461 | + // path to folder containing files for integrating with the EE core admin and/or setting up EE admin pages |
|
462 | + 'admin_path' => isset($setup_args['admin_path']) |
|
463 | + ? (string) $setup_args['admin_path'] |
|
464 | + : '', |
|
465 | + // a method to be called when the EE Admin is first invoked, can be used for hooking into any admin page |
|
466 | + 'admin_callback' => isset($setup_args['admin_callback']) |
|
467 | + ? (string) $setup_args['admin_callback'] |
|
468 | + : '', |
|
469 | + // the section name for this addon's configuration settings section (defaults to "addons") |
|
470 | + 'config_section' => isset($setup_args['config_section']) |
|
471 | + ? (string) $setup_args['config_section'] |
|
472 | + : 'addons', |
|
473 | + // the class name for this addon's configuration settings object |
|
474 | + 'config_class' => isset($setup_args['config_class']) |
|
475 | + ? (string) $setup_args['config_class'] |
|
476 | + : '', |
|
477 | + // the name given to the config for this addons' configuration settings object (optional) |
|
478 | + 'config_name' => isset($setup_args['config_name']) |
|
479 | + ? (string) $setup_args['config_name'] |
|
480 | + : '', |
|
481 | + // an array of "class names" => "full server paths" for any classes that might be invoked by the addon |
|
482 | + 'autoloader_paths' => isset($setup_args['autoloader_paths']) |
|
483 | + ? (array) $setup_args['autoloader_paths'] |
|
484 | + : [], |
|
485 | + // an array of "full server paths" for any folders containing classes that might be invoked by the addon |
|
486 | + 'autoloader_folders' => isset($setup_args['autoloader_folders']) |
|
487 | + ? (array) $setup_args['autoloader_folders'] |
|
488 | + : [], |
|
489 | + // array of full server paths to any EE_DMS data migration scripts used by the addon. |
|
490 | + // The key should be the EE_Addon class name that this set of data migration scripts belongs to. |
|
491 | + // If the EE_Addon class is namespaced, then this needs to be the Fully Qualified Class Name |
|
492 | + 'dms_paths' => isset($setup_args['dms_paths']) |
|
493 | + ? (array) $setup_args['dms_paths'] |
|
494 | + : [], |
|
495 | + // array of full server paths to any EED_Modules used by the addon |
|
496 | + 'module_paths' => isset($setup_args['module_paths']) |
|
497 | + ? (array) $setup_args['module_paths'] |
|
498 | + : [], |
|
499 | + // array of full server paths to any EES_Shortcodes used by the addon |
|
500 | + 'shortcode_paths' => isset($setup_args['shortcode_paths']) |
|
501 | + ? (array) $setup_args['shortcode_paths'] |
|
502 | + : [], |
|
503 | + 'shortcode_fqcns' => isset($setup_args['shortcode_fqcns']) |
|
504 | + ? (array) $setup_args['shortcode_fqcns'] |
|
505 | + : [], |
|
506 | + // array of full server paths to any WP_Widgets used by the addon |
|
507 | + 'widget_paths' => isset($setup_args['widget_paths']) |
|
508 | + ? (array) $setup_args['widget_paths'] |
|
509 | + : [], |
|
510 | + 'message_types' => isset($setup_args['message_types']) |
|
511 | + ? (array) $setup_args['message_types'] |
|
512 | + : [], |
|
513 | + 'capabilities' => isset($setup_args['capabilities']) |
|
514 | + ? (array) $setup_args['capabilities'] |
|
515 | + : [], |
|
516 | + 'capability_maps' => isset($setup_args['capability_maps']) |
|
517 | + ? (array) $setup_args['capability_maps'] |
|
518 | + : [], |
|
519 | + 'model_paths' => isset($setup_args['model_paths']) |
|
520 | + ? (array) $setup_args['model_paths'] |
|
521 | + : [], |
|
522 | + 'class_paths' => isset($setup_args['class_paths']) |
|
523 | + ? (array) $setup_args['class_paths'] |
|
524 | + : [], |
|
525 | + 'model_extension_paths' => isset($setup_args['model_extension_paths']) |
|
526 | + ? (array) $setup_args['model_extension_paths'] |
|
527 | + : [], |
|
528 | + 'class_extension_paths' => isset($setup_args['class_extension_paths']) |
|
529 | + ? (array) $setup_args['class_extension_paths'] |
|
530 | + : [], |
|
531 | + 'custom_post_types' => isset($setup_args['custom_post_types']) |
|
532 | + ? (array) $setup_args['custom_post_types'] |
|
533 | + : [], |
|
534 | + 'custom_taxonomies' => isset($setup_args['custom_taxonomies']) |
|
535 | + ? (array) $setup_args['custom_taxonomies'] |
|
536 | + : [], |
|
537 | + 'payment_method_paths' => isset($setup_args['payment_method_paths']) |
|
538 | + ? (array) $setup_args['payment_method_paths'] |
|
539 | + : [], |
|
540 | + 'pm_slug' => '', |
|
541 | + 'default_terms' => isset($setup_args['default_terms']) |
|
542 | + ? (array) $setup_args['default_terms'] |
|
543 | + : [], |
|
544 | + // if not empty, inserts a new table row after this plugin's row on the WP Plugins page |
|
545 | + // that can be used for adding upgrading/marketing info |
|
546 | + 'plugins_page_row' => isset($setup_args['plugins_page_row']) |
|
547 | + ? (array) $setup_args['plugins_page_row'] |
|
548 | + : [], |
|
549 | + 'namespace' => isset( |
|
550 | + $setup_args['namespace']['FQNS'], |
|
551 | + $setup_args['namespace']['DIR'] |
|
552 | + ) |
|
553 | + ? (array) $setup_args['namespace'] |
|
554 | + : [], |
|
555 | + 'privacy_policies' => isset($setup_args['privacy_policies']) |
|
556 | + ? (array) $setup_args['privacy_policies'] |
|
557 | + : [], |
|
558 | + 'license' => isset($setup_args['license']) |
|
559 | + ? (array) $setup_args['license'] |
|
560 | + : [], |
|
561 | + ]; |
|
562 | + |
|
563 | + // if plugin_action_slug is NOT set... |
|
564 | + if (empty($addon_settings['plugin_action_slug'])) { |
|
565 | + if (! empty($addon_settings['payment_method_paths'])) { |
|
566 | + // but the addon is a payment method |
|
567 | + $payment_method_path = reset($addon_settings['payment_method_paths']); |
|
568 | + $plugin_action_slug = basename(strtolower($payment_method_path)); |
|
569 | + $addon_settings['plugin_action_slug'] = $plugin_action_slug; |
|
570 | + // let's also set the pm_slug to the same value |
|
571 | + $addon_settings['pm_slug'] = $plugin_action_slug; |
|
572 | + } elseif (! empty($addon_settings['admin_path'])) { |
|
573 | + // or an admin page path IS set |
|
574 | + $addon_settings['plugin_action_slug'] = basename($addon_settings['admin_path']); |
|
575 | + } |
|
576 | + } |
|
577 | + |
|
578 | + // full server path to main file (file loaded directly by WP) |
|
579 | + $addon_settings['plugin_basename'] = plugin_basename($addon_settings['main_file_path']); |
|
580 | + return $addon_settings; |
|
581 | + } |
|
582 | + |
|
583 | + |
|
584 | + /** |
|
585 | + * @param string $addon_name |
|
586 | + * @param array $addon_settings |
|
587 | + * @return bool |
|
588 | + */ |
|
589 | + private static function _addon_is_compatible(string $addon_name, array $addon_settings): bool |
|
590 | + { |
|
591 | + global $wp_version; |
|
592 | + $incompatibility_message = ''; |
|
593 | + // check whether this addon version is compatible with EE core |
|
594 | + if ( |
|
595 | + isset(EE_Register_Addon::$_incompatible_addons[ $addon_name ]) |
|
596 | + && ! self::_meets_min_core_version_requirement( |
|
597 | + EE_Register_Addon::$_incompatible_addons[ $addon_name ], |
|
598 | + $addon_settings['version'] |
|
599 | + ) |
|
600 | + ) { |
|
601 | + $incompatibility_message = sprintf( |
|
602 | + esc_html__( |
|
603 | + '%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.', |
|
604 | + 'event_espresso' |
|
605 | + ), |
|
606 | + $addon_name, |
|
607 | + '<br />', |
|
608 | + EE_Register_Addon::$_incompatible_addons[ $addon_name ], |
|
609 | + '<span style="font-weight: bold; color: #D54E21;">', |
|
610 | + '</span><br />' |
|
611 | + ); |
|
612 | + } elseif ( |
|
613 | + ! self::_meets_min_core_version_requirement($addon_settings['min_core_version'], espresso_version()) |
|
614 | + ) { |
|
615 | + $incompatibility_message = sprintf( |
|
616 | + esc_html__( |
|
617 | + '%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".', |
|
618 | + 'event_espresso' |
|
619 | + ), |
|
620 | + $addon_name, |
|
621 | + self::_effective_version($addon_settings['min_core_version']), |
|
622 | + self::_effective_version(espresso_version()), |
|
623 | + '<br />', |
|
624 | + '<span style="font-weight: bold; color: #D54E21;">', |
|
625 | + '</span><br />' |
|
626 | + ); |
|
627 | + } elseif (version_compare($wp_version, $addon_settings['min_wp_version'], '<')) { |
|
628 | + $incompatibility_message = sprintf( |
|
629 | + esc_html__( |
|
630 | + '%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.', |
|
631 | + 'event_espresso' |
|
632 | + ), |
|
633 | + $addon_name, |
|
634 | + $addon_settings['min_wp_version'], |
|
635 | + '<br />', |
|
636 | + '<span style="font-weight: bold; color: #D54E21;">', |
|
637 | + '</span><br />' |
|
638 | + ); |
|
639 | + } |
|
640 | + if (! empty($incompatibility_message)) { |
|
641 | + // remove 'activate' from the REQUEST |
|
642 | + // so WP doesn't erroneously tell the user the plugin activated fine when it didn't |
|
643 | + /** @var RequestInterface $request */ |
|
644 | + $request = LoaderFactory::getLoader()->getShared(RequestInterface::class); |
|
645 | + $request->unSetRequestParam('activate', true); |
|
646 | + if (current_user_can('activate_plugins')) { |
|
647 | + // show an error message indicating the plugin didn't activate properly |
|
648 | + EE_Error::add_error($incompatibility_message, __FILE__, __FUNCTION__, __LINE__); |
|
649 | + } |
|
650 | + unset($_GET['activate'], $_REQUEST['activate']); |
|
651 | + if (! function_exists('deactivate_plugins')) { |
|
652 | + require_once ABSPATH . 'wp-admin/includes/plugin.php'; |
|
653 | + } |
|
654 | + deactivate_plugins(plugin_basename($addon_settings['main_file_path'])); |
|
655 | + // BAIL FROM THE ADDON REGISTRATION PROCESS |
|
656 | + return false; |
|
657 | + } |
|
658 | + // addon IS compatible |
|
659 | + return true; |
|
660 | + } |
|
661 | + |
|
662 | + |
|
663 | + /** |
|
664 | + * register namespaces right away before any other files or classes get loaded, but AFTER the version checks |
|
665 | + * |
|
666 | + * @param array $addon_settings |
|
667 | + * @return void |
|
668 | + * @throws EE_Error |
|
669 | + */ |
|
670 | + private static function _setup_namespaces(array $addon_settings) |
|
671 | + { |
|
672 | + // |
|
673 | + if ( |
|
674 | + isset( |
|
675 | + $addon_settings['namespace']['FQNS'], |
|
676 | + $addon_settings['namespace']['DIR'] |
|
677 | + ) |
|
678 | + ) { |
|
679 | + EE_Psr4AutoloaderInit::psr4_loader()->addNamespace( |
|
680 | + $addon_settings['namespace']['FQNS'], |
|
681 | + $addon_settings['namespace']['DIR'] |
|
682 | + ); |
|
683 | + } |
|
684 | + } |
|
685 | + |
|
686 | + |
|
687 | + /** |
|
688 | + * @param string $addon_name |
|
689 | + * @param array $addon_settings |
|
690 | + * @return bool |
|
691 | + * @throws InvalidArgumentException |
|
692 | + * @throws InvalidDataTypeException |
|
693 | + * @throws InvalidInterfaceException |
|
694 | + */ |
|
695 | + private static function _addon_activation(string $addon_name, array $addon_settings): bool |
|
696 | + { |
|
697 | + // this is an activation request |
|
698 | + if (did_action('activate_plugin')) { |
|
699 | + // to find if THIS is the addon that was activated, just check if we have already registered it or not |
|
700 | + // (as the newly-activated addon wasn't around the first time addons were registered). |
|
701 | + if ( |
|
702 | + ! isset(self::$_settings[ $addon_name ]) |
|
703 | + || (isset(self::$_settings[ $addon_name ]) |
|
704 | + && ! isset(self::$_settings[ $addon_name ]['class_name']) |
|
705 | + ) |
|
706 | + ) { |
|
707 | + self::$_settings[ $addon_name ] = $addon_settings; |
|
708 | + $addon = self::_load_and_init_addon_class($addon_name); |
|
709 | + $addon->set_activation_indicator_option(); |
|
710 | + // dont bother setting up the rest of the addon. |
|
711 | + // we know it was just activated and the request will end soon |
|
712 | + } |
|
713 | + return true; |
|
714 | + } |
|
715 | + // make sure addon settings are set correctly without overwriting anything existing |
|
716 | + if (isset(self::$_settings[ $addon_name ])) { |
|
717 | + self::$_settings[ $addon_name ] += $addon_settings; |
|
718 | + } else { |
|
719 | + self::$_settings[ $addon_name ] = $addon_settings; |
|
720 | + } |
|
721 | + return false; |
|
722 | + } |
|
723 | + |
|
724 | + |
|
725 | + /** |
|
726 | + * @param string $addon_name |
|
727 | + * @return void |
|
728 | + * @throws EE_Error |
|
729 | + */ |
|
730 | + private static function _setup_autoloaders(string $addon_name) |
|
731 | + { |
|
732 | + if (! empty(self::$_settings[ $addon_name ]['autoloader_paths'])) { |
|
733 | + // setup autoloader for single file |
|
734 | + EEH_Autoloader::instance()->register_autoloader(self::$_settings[ $addon_name ]['autoloader_paths']); |
|
735 | + } |
|
736 | + // setup autoloaders for folders |
|
737 | + if (! empty(self::$_settings[ $addon_name ]['autoloader_folders'])) { |
|
738 | + foreach ((array) self::$_settings[ $addon_name ]['autoloader_folders'] as $autoloader_folder) { |
|
739 | + EEH_Autoloader::register_autoloaders_for_each_file_in_folder($autoloader_folder); |
|
740 | + } |
|
741 | + } |
|
742 | + } |
|
743 | + |
|
744 | + |
|
745 | + /** |
|
746 | + * register new models and extensions |
|
747 | + * |
|
748 | + * @param string $addon_name |
|
749 | + * @return void |
|
750 | + * @throws EE_Error |
|
751 | + */ |
|
752 | + private static function _register_models_and_extensions(string $addon_name) |
|
753 | + { |
|
754 | + // register new models |
|
755 | + if ( |
|
756 | + ! empty(self::$_settings[ $addon_name ]['model_paths']) |
|
757 | + || ! empty(self::$_settings[ $addon_name ]['class_paths']) |
|
758 | + ) { |
|
759 | + EE_Register_Model::register( |
|
760 | + $addon_name, |
|
761 | + [ |
|
762 | + 'model_paths' => self::$_settings[ $addon_name ]['model_paths'], |
|
763 | + 'class_paths' => self::$_settings[ $addon_name ]['class_paths'], |
|
764 | + ] |
|
765 | + ); |
|
766 | + } |
|
767 | + // register model extensions |
|
768 | + if ( |
|
769 | + ! empty(self::$_settings[ $addon_name ]['model_extension_paths']) |
|
770 | + || ! empty(self::$_settings[ $addon_name ]['class_extension_paths']) |
|
771 | + ) { |
|
772 | + EE_Register_Model_Extensions::register( |
|
773 | + $addon_name, |
|
774 | + [ |
|
775 | + 'model_extension_paths' => self::$_settings[ $addon_name ]['model_extension_paths'], |
|
776 | + 'class_extension_paths' => self::$_settings[ $addon_name ]['class_extension_paths'], |
|
777 | + ] |
|
778 | + ); |
|
779 | + } |
|
780 | + } |
|
781 | + |
|
782 | + |
|
783 | + /** |
|
784 | + * @param string $addon_name |
|
785 | + * @return void |
|
786 | + * @throws EE_Error |
|
787 | + */ |
|
788 | + private static function _register_data_migration_scripts(string $addon_name) |
|
789 | + { |
|
790 | + // setup DMS |
|
791 | + if (! empty(self::$_settings[ $addon_name ]['dms_paths'])) { |
|
792 | + EE_Register_Data_Migration_Scripts::register( |
|
793 | + $addon_name, |
|
794 | + ['dms_paths' => self::$_settings[ $addon_name ]['dms_paths']] |
|
795 | + ); |
|
796 | + } |
|
797 | + } |
|
798 | + |
|
799 | + |
|
800 | + /** |
|
801 | + * @param string $addon_name |
|
802 | + * @return void |
|
803 | + * @throws EE_Error |
|
804 | + */ |
|
805 | + private static function _register_config(string $addon_name) |
|
806 | + { |
|
807 | + // if config_class is present let's register config. |
|
808 | + if (! empty(self::$_settings[ $addon_name ]['config_class'])) { |
|
809 | + EE_Register_Config::register( |
|
810 | + self::$_settings[ $addon_name ]['config_class'], |
|
811 | + [ |
|
812 | + 'config_section' => self::$_settings[ $addon_name ]['config_section'], |
|
813 | + 'config_name' => self::$_settings[ $addon_name ]['config_name'], |
|
814 | + ] |
|
815 | + ); |
|
816 | + } |
|
817 | + } |
|
818 | + |
|
819 | + |
|
820 | + /** |
|
821 | + * @param string $addon_name |
|
822 | + * @return void |
|
823 | + * @throws EE_Error |
|
824 | + */ |
|
825 | + private static function _register_admin_pages(string $addon_name) |
|
826 | + { |
|
827 | + if (! empty(self::$_settings[ $addon_name ]['admin_path'])) { |
|
828 | + EE_Register_Admin_Page::register( |
|
829 | + $addon_name, |
|
830 | + ['page_path' => self::$_settings[ $addon_name ]['admin_path']] |
|
831 | + ); |
|
832 | + } |
|
833 | + } |
|
834 | + |
|
835 | + |
|
836 | + /** |
|
837 | + * @param string $addon_name |
|
838 | + * @return void |
|
839 | + * @throws EE_Error |
|
840 | + */ |
|
841 | + private static function _register_modules(string $addon_name) |
|
842 | + { |
|
843 | + if (! empty(self::$_settings[ $addon_name ]['module_paths'])) { |
|
844 | + EE_Register_Module::register( |
|
845 | + $addon_name, |
|
846 | + ['module_paths' => self::$_settings[ $addon_name ]['module_paths']] |
|
847 | + ); |
|
848 | + } |
|
849 | + } |
|
850 | + |
|
851 | + |
|
852 | + /** |
|
853 | + * @param string $addon_name |
|
854 | + * @return void |
|
855 | + * @throws EE_Error |
|
856 | + */ |
|
857 | + private static function _register_shortcodes(string $addon_name) |
|
858 | + { |
|
859 | + if ( |
|
860 | + ! empty(self::$_settings[ $addon_name ]['shortcode_paths']) |
|
861 | + || ! empty(self::$_settings[ $addon_name ]['shortcode_fqcns']) |
|
862 | + ) { |
|
863 | + EE_Register_Shortcode::register( |
|
864 | + $addon_name, |
|
865 | + [ |
|
866 | + 'shortcode_paths' => self::$_settings[ $addon_name ]['shortcode_paths'] ?? [], |
|
867 | + 'shortcode_fqcns' => self::$_settings[ $addon_name ]['shortcode_fqcns'] ?? [], |
|
868 | + ] |
|
869 | + ); |
|
870 | + } |
|
871 | + } |
|
872 | + |
|
873 | + |
|
874 | + /** |
|
875 | + * @param string $addon_name |
|
876 | + * @return void |
|
877 | + * @throws EE_Error |
|
878 | + */ |
|
879 | + private static function _register_widgets(string $addon_name) |
|
880 | + { |
|
881 | + if (! empty(self::$_settings[ $addon_name ]['widget_paths'])) { |
|
882 | + EE_Register_Widget::register( |
|
883 | + $addon_name, |
|
884 | + ['widget_paths' => self::$_settings[ $addon_name ]['widget_paths']] |
|
885 | + ); |
|
886 | + } |
|
887 | + } |
|
888 | + |
|
889 | + |
|
890 | + /** |
|
891 | + * @param string $addon_name |
|
892 | + * @return void |
|
893 | + * @throws EE_Error |
|
894 | + */ |
|
895 | + private static function _register_capabilities(string $addon_name) |
|
896 | + { |
|
897 | + if (! empty(self::$_settings[ $addon_name ]['capabilities'])) { |
|
898 | + EE_Register_Capabilities::register( |
|
899 | + $addon_name, |
|
900 | + [ |
|
901 | + 'capabilities' => self::$_settings[ $addon_name ]['capabilities'], |
|
902 | + 'capability_maps' => self::$_settings[ $addon_name ]['capability_maps'], |
|
903 | + ] |
|
904 | + ); |
|
905 | + } |
|
906 | + } |
|
907 | + |
|
908 | + |
|
909 | + /** |
|
910 | + * @param string $addon_name |
|
911 | + * @return void |
|
912 | + */ |
|
913 | + private static function _register_message_types(string $addon_name) |
|
914 | + { |
|
915 | + if (! empty(self::$_settings[ $addon_name ]['message_types'])) { |
|
916 | + add_action( |
|
917 | + 'EE_Brewing_Regular___messages_caf', |
|
918 | + ['EE_Register_Addon', 'register_message_types'] |
|
919 | + ); |
|
920 | + } |
|
921 | + } |
|
922 | + |
|
923 | + |
|
924 | + /** |
|
925 | + * @param string $addon_name |
|
926 | + * @return void |
|
927 | + * @throws EE_Error |
|
928 | + */ |
|
929 | + private static function _register_custom_post_types(string $addon_name) |
|
930 | + { |
|
931 | + if ( |
|
932 | + ! empty(self::$_settings[ $addon_name ]['custom_post_types']) |
|
933 | + || ! empty(self::$_settings[ $addon_name ]['custom_taxonomies']) |
|
934 | + ) { |
|
935 | + EE_Register_CPT::register( |
|
936 | + $addon_name, |
|
937 | + [ |
|
938 | + 'cpts' => self::$_settings[ $addon_name ]['custom_post_types'], |
|
939 | + 'cts' => self::$_settings[ $addon_name ]['custom_taxonomies'], |
|
940 | + 'default_terms' => self::$_settings[ $addon_name ]['default_terms'], |
|
941 | + ] |
|
942 | + ); |
|
943 | + } |
|
944 | + } |
|
945 | + |
|
946 | + |
|
947 | + /** |
|
948 | + * @param string $addon_name |
|
949 | + * @return void |
|
950 | + * @throws InvalidArgumentException |
|
951 | + * @throws InvalidInterfaceException |
|
952 | + * @throws InvalidDataTypeException |
|
953 | + * @throws DomainException |
|
954 | + * @throws EE_Error |
|
955 | + */ |
|
956 | + private static function _register_payment_methods(string $addon_name) |
|
957 | + { |
|
958 | + if (! empty(self::$_settings[ $addon_name ]['payment_method_paths'])) { |
|
959 | + EE_Register_Payment_Method::register( |
|
960 | + $addon_name, |
|
961 | + ['payment_method_paths' => self::$_settings[ $addon_name ]['payment_method_paths']] |
|
962 | + ); |
|
963 | + } |
|
964 | + } |
|
965 | + |
|
966 | + |
|
967 | + /** |
|
968 | + * @param string $addon_name |
|
969 | + * @return void |
|
970 | + * @throws InvalidArgumentException |
|
971 | + * @throws InvalidInterfaceException |
|
972 | + * @throws InvalidDataTypeException |
|
973 | + * @throws DomainException |
|
974 | + */ |
|
975 | + private static function registerPrivacyPolicies(string $addon_name) |
|
976 | + { |
|
977 | + if (! empty(self::$_settings[ $addon_name ]['privacy_policies'])) { |
|
978 | + EE_Register_Privacy_Policy::register( |
|
979 | + $addon_name, |
|
980 | + self::$_settings[ $addon_name ]['privacy_policies'] |
|
981 | + ); |
|
982 | + } |
|
983 | + } |
|
984 | + |
|
985 | + |
|
986 | + /** |
|
987 | + * @param string $addon_name |
|
988 | + * @return void |
|
989 | + */ |
|
990 | + private static function registerPersonalDataExporters(string $addon_name) |
|
991 | + { |
|
992 | + if (! empty(self::$_settings[ $addon_name ]['personal_data_exporters'])) { |
|
993 | + EE_Register_Personal_Data_Eraser::register( |
|
994 | + $addon_name, |
|
995 | + self::$_settings[ $addon_name ]['personal_data_exporters'] |
|
996 | + ); |
|
997 | + } |
|
998 | + } |
|
999 | + |
|
1000 | + |
|
1001 | + /** |
|
1002 | + * @param string $addon_name |
|
1003 | + * @return void |
|
1004 | + */ |
|
1005 | + private static function registerPersonalDataErasers(string $addon_name) |
|
1006 | + { |
|
1007 | + if (! empty(self::$_settings[ $addon_name ]['personal_data_erasers'])) { |
|
1008 | + EE_Register_Personal_Data_Eraser::register( |
|
1009 | + $addon_name, |
|
1010 | + self::$_settings[ $addon_name ]['personal_data_erasers'] |
|
1011 | + ); |
|
1012 | + } |
|
1013 | + } |
|
1014 | + |
|
1015 | + |
|
1016 | + /** |
|
1017 | + * Loads and instantiates the EE_Addon class and adds it onto the registry |
|
1018 | + * |
|
1019 | + * @param string $addon_name |
|
1020 | + * @return EE_Addon |
|
1021 | + * @throws InvalidArgumentException |
|
1022 | + * @throws InvalidInterfaceException |
|
1023 | + * @throws InvalidDataTypeException |
|
1024 | + */ |
|
1025 | + private static function _load_and_init_addon_class(string $addon_name): EE_Addon |
|
1026 | + { |
|
1027 | + $addon = self::$loader->getShared( |
|
1028 | + self::$_settings[ $addon_name ]['class_name'], |
|
1029 | + ['EE_Registry::create(addon)' => true] |
|
1030 | + ); |
|
1031 | + if (! $addon instanceof EE_Addon) { |
|
1032 | + throw new DomainException( |
|
1033 | + sprintf( |
|
1034 | + esc_html__('The "%1$s" EE_Addon class failed to instantiate!', 'event_espresso'), |
|
1035 | + self::$_settings[ $addon_name ]['class_name'] |
|
1036 | + ) |
|
1037 | + ); |
|
1038 | + } |
|
1039 | + // setter inject dep map if required |
|
1040 | + if ($addon->dependencyMap() === null) { |
|
1041 | + $addon->setDependencyMap(self::$loader->getShared('EE_Dependency_Map')); |
|
1042 | + } |
|
1043 | + // setter inject domain if required |
|
1044 | + EE_Register_Addon::injectAddonDomain($addon_name, $addon); |
|
1045 | + |
|
1046 | + $addon->set_name($addon_name); |
|
1047 | + $addon->set_plugin_slug(self::$_settings[ $addon_name ]['plugin_slug']); |
|
1048 | + $addon->set_plugin_basename(self::$_settings[ $addon_name ]['plugin_basename']); |
|
1049 | + $addon->set_main_plugin_file(self::$_settings[ $addon_name ]['main_file_path']); |
|
1050 | + $addon->set_plugin_action_slug(self::$_settings[ $addon_name ]['plugin_action_slug']); |
|
1051 | + $addon->set_plugins_page_row(self::$_settings[ $addon_name ]['plugins_page_row']); |
|
1052 | + $addon->set_version(self::$_settings[ $addon_name ]['version']); |
|
1053 | + $addon->set_min_core_version(self::_effective_version(self::$_settings[ $addon_name ]['min_core_version'])); |
|
1054 | + $addon->set_config_section(self::$_settings[ $addon_name ]['config_section']); |
|
1055 | + $addon->set_config_class(self::$_settings[ $addon_name ]['config_class']); |
|
1056 | + $addon->set_config_name(self::$_settings[ $addon_name ]['config_name']); |
|
1057 | + if (! empty(self::$_settings[ $addon_name ]['pm_slug'])) { |
|
1058 | + $addon->setPaymentmethodSlug(self::$_settings[ $addon_name ]['pm_slug']); |
|
1059 | + } |
|
1060 | + do_action( |
|
1061 | + 'AHEE__EE_Register_Addon___load_and_init_addon_class', |
|
1062 | + $addon, |
|
1063 | + $addon_name, |
|
1064 | + self::$_settings |
|
1065 | + ); |
|
1066 | + // unfortunately this can't be hooked in upon construction, |
|
1067 | + // because we don't have the plugin's mainfile path upon construction. |
|
1068 | + register_deactivation_hook($addon->get_main_plugin_file(), [$addon, 'deactivation']); |
|
1069 | + // call any additional admin_callback functions during load_admin_controller hook |
|
1070 | + if (! empty(self::$_settings[ $addon_name ]['admin_callback'])) { |
|
1071 | + add_action( |
|
1072 | + 'AHEE__EE_System__load_controllers__load_admin_controllers', |
|
1073 | + [$addon, self::$_settings[ $addon_name ]['admin_callback']] |
|
1074 | + ); |
|
1075 | + } |
|
1076 | + return $addon; |
|
1077 | + } |
|
1078 | + |
|
1079 | + |
|
1080 | + /** |
|
1081 | + * @param string $addon_name |
|
1082 | + * @param EE_Addon $addon |
|
1083 | + * @since 4.10.13.p |
|
1084 | + */ |
|
1085 | + private static function injectAddonDomain(string $addon_name, EE_Addon $addon) |
|
1086 | + { |
|
1087 | + if ($addon instanceof RequiresDomainInterface && $addon->domain() === null) { |
|
1088 | + // using supplied Domain object |
|
1089 | + $domain = self::$_settings[ $addon_name ]['domain'] instanceof DomainInterface |
|
1090 | + ? self::$_settings[ $addon_name ]['domain'] |
|
1091 | + : null; |
|
1092 | + // or construct one using Domain FQCN |
|
1093 | + if ($domain === null && self::$_settings[ $addon_name ]['domain_fqcn'] !== '') { |
|
1094 | + $domain = self::$loader->getShared( |
|
1095 | + self::$_settings[ $addon_name ]['domain_fqcn'], |
|
1096 | + [ |
|
1097 | + new EventEspresso\core\domain\values\FilePath( |
|
1098 | + self::$_settings[ $addon_name ]['main_file_path'] |
|
1099 | + ), |
|
1100 | + EventEspresso\core\domain\values\Version::fromString( |
|
1101 | + self::$_settings[ $addon_name ]['version'] |
|
1102 | + ), |
|
1103 | + ] |
|
1104 | + ); |
|
1105 | + } |
|
1106 | + if ($domain instanceof DomainInterface) { |
|
1107 | + $addon->setDomain($domain); |
|
1108 | + } |
|
1109 | + } |
|
1110 | + } |
|
1111 | + |
|
1112 | + |
|
1113 | + /** |
|
1114 | + * @return void |
|
1115 | + * @deprecated 5.0.0.p |
|
1116 | + */ |
|
1117 | + public static function load_pue_update() |
|
1118 | + { |
|
1119 | + } |
|
1120 | + |
|
1121 | + |
|
1122 | + /** |
|
1123 | + * Callback for EE_Brewing_Regular__messages_caf hook used to register message types. |
|
1124 | + * |
|
1125 | + * @return void |
|
1126 | + * @throws EE_Error |
|
1127 | + * @since 4.4.0 |
|
1128 | + */ |
|
1129 | + public static function register_message_types() |
|
1130 | + { |
|
1131 | + foreach (self::$_settings as $settings) { |
|
1132 | + if (! empty($settings['message_types'])) { |
|
1133 | + foreach ((array) $settings['message_types'] as $message_type => $message_type_settings) { |
|
1134 | + EE_Register_Message_Type::register($message_type, $message_type_settings); |
|
1135 | + } |
|
1136 | + } |
|
1137 | + } |
|
1138 | + } |
|
1139 | + |
|
1140 | + |
|
1141 | + private static function registerLicense($addon_name) |
|
1142 | + { |
|
1143 | + static $request = null; |
|
1144 | + if ($request === null) { |
|
1145 | + /** @var RequestInterface $request */ |
|
1146 | + $request = LoaderFactory::getLoader()->getShared(RequestInterface::class); |
|
1147 | + } |
|
1148 | + if ($request->isWordPressHeartbeat()) { |
|
1149 | + return; |
|
1150 | + } |
|
1151 | + $addon_settings = self::$_settings[ $addon_name ] ?? []; |
|
1152 | + if (empty($addon_settings)) { |
|
1153 | + return; |
|
1154 | + } |
|
1155 | + $license_data = isset($addon_settings['license']) ? (array) $addon_settings['license'] : []; |
|
1156 | + // copy known values from addon settings to license data if anything's missing |
|
1157 | + $license_data += [ |
|
1158 | + 'main_file_path' => $addon_settings['main_file_path'] ?? '', |
|
1159 | + 'min_core_version' => $addon_settings['min_core_version'] ?? '', |
|
1160 | + 'plugin_id' => 0, // no corresponding value in addon settings |
|
1161 | + 'plugin_slug' => $addon_settings['plugin_slug'] ?? '', |
|
1162 | + 'version' => $addon_settings['version'] ?? '', |
|
1163 | + ]; |
|
1164 | + EventEspresso\core\services\licensing\AddonLicense::register($addon_name, $license_data); |
|
1165 | + } |
|
1166 | + |
|
1167 | + |
|
1168 | + /** |
|
1169 | + * This deregisters an addon that was previously registered with a specific addon_name. |
|
1170 | + * |
|
1171 | + * @param string $addon_name the name for the addon that was previously registered |
|
1172 | + * @throws DomainException |
|
1173 | + * @throws InvalidArgumentException |
|
1174 | + * @throws InvalidDataTypeException |
|
1175 | + * @throws InvalidInterfaceException |
|
1176 | + * @since 4.3.0 |
|
1177 | + */ |
|
1178 | + public static function deregister(string $addon_name = '') |
|
1179 | + { |
|
1180 | + if (isset(self::$_settings[ $addon_name ]['class_name'])) { |
|
1181 | + try { |
|
1182 | + do_action('AHEE__EE_Register_Addon__deregister__before', $addon_name); |
|
1183 | + $class_name = self::$_settings[ $addon_name ]['class_name']; |
|
1184 | + if (! empty(self::$_settings[ $addon_name ]['dms_paths'])) { |
|
1185 | + // setup DMS |
|
1186 | + EE_Register_Data_Migration_Scripts::deregister($addon_name); |
|
1187 | + } |
|
1188 | + if (! empty(self::$_settings[ $addon_name ]['admin_path'])) { |
|
1189 | + // register admin page |
|
1190 | + EE_Register_Admin_Page::deregister($addon_name); |
|
1191 | + } |
|
1192 | + if (! empty(self::$_settings[ $addon_name ]['module_paths'])) { |
|
1193 | + // add to list of modules to be registered |
|
1194 | + EE_Register_Module::deregister($addon_name); |
|
1195 | + } |
|
1196 | + if ( |
|
1197 | + ! empty(self::$_settings[ $addon_name ]['shortcode_paths']) |
|
1198 | + || ! empty(self::$_settings[ $addon_name ]['shortcode_fqcns']) |
|
1199 | + ) { |
|
1200 | + // add to list of shortcodes to be registered |
|
1201 | + EE_Register_Shortcode::deregister($addon_name); |
|
1202 | + } |
|
1203 | + if (! empty(self::$_settings[ $addon_name ]['config_class'])) { |
|
1204 | + // if config_class present let's register config. |
|
1205 | + EE_Register_Config::deregister(self::$_settings[ $addon_name ]['config_class']); |
|
1206 | + } |
|
1207 | + if (! empty(self::$_settings[ $addon_name ]['widget_paths'])) { |
|
1208 | + // add to list of widgets to be registered |
|
1209 | + EE_Register_Widget::deregister($addon_name); |
|
1210 | + } |
|
1211 | + if ( |
|
1212 | + ! empty(self::$_settings[ $addon_name ]['model_paths']) |
|
1213 | + || ! empty(self::$_settings[ $addon_name ]['class_paths']) |
|
1214 | + ) { |
|
1215 | + // add to list of shortcodes to be registered |
|
1216 | + EE_Register_Model::deregister($addon_name); |
|
1217 | + } |
|
1218 | + if ( |
|
1219 | + ! empty(self::$_settings[ $addon_name ]['model_extension_paths']) |
|
1220 | + || ! empty(self::$_settings[ $addon_name ]['class_extension_paths']) |
|
1221 | + ) { |
|
1222 | + // add to list of shortcodes to be registered |
|
1223 | + EE_Register_Model_Extensions::deregister($addon_name); |
|
1224 | + } |
|
1225 | + if (! empty(self::$_settings[ $addon_name ]['message_types'])) { |
|
1226 | + foreach ((array) self::$_settings[ $addon_name ]['message_types'] as $message_type => $message_type_settings) { |
|
1227 | + EE_Register_Message_Type::deregister($message_type); |
|
1228 | + } |
|
1229 | + } |
|
1230 | + // deregister capabilities for addon |
|
1231 | + if ( |
|
1232 | + ! empty(self::$_settings[ $addon_name ]['capabilities']) |
|
1233 | + || ! empty(self::$_settings[ $addon_name ]['capability_maps']) |
|
1234 | + ) { |
|
1235 | + EE_Register_Capabilities::deregister($addon_name); |
|
1236 | + } |
|
1237 | + // deregister custom_post_types for addon |
|
1238 | + if (! empty(self::$_settings[ $addon_name ]['custom_post_types'])) { |
|
1239 | + EE_Register_CPT::deregister($addon_name); |
|
1240 | + } |
|
1241 | + if (! empty(self::$_settings[ $addon_name ]['payment_method_paths'])) { |
|
1242 | + EE_Register_Payment_Method::deregister($addon_name); |
|
1243 | + } |
|
1244 | + $addon = EE_Registry::instance()->getAddon($class_name); |
|
1245 | + if ($addon instanceof EE_Addon) { |
|
1246 | + remove_action( |
|
1247 | + 'deactivate_' . $addon->get_main_plugin_file_basename(), |
|
1248 | + [$addon, 'deactivation'] |
|
1249 | + ); |
|
1250 | + remove_action( |
|
1251 | + 'AHEE__EE_System__perform_activations_upgrades_and_migrations', |
|
1252 | + [$addon, 'initialize_db_if_no_migrations_required'] |
|
1253 | + ); |
|
1254 | + // remove `after_registration` call |
|
1255 | + remove_action( |
|
1256 | + 'AHEE__EE_System__load_espresso_addons__complete', |
|
1257 | + [$addon, 'after_registration'], |
|
1258 | + 999 |
|
1259 | + ); |
|
1260 | + } |
|
1261 | + EE_Registry::instance()->removeAddon($class_name); |
|
1262 | + LoaderFactory::getLoader()->remove($class_name); |
|
1263 | + } catch (OutOfBoundsException $addon_not_yet_registered_exception) { |
|
1264 | + // the add-on was not yet registered in the registry, |
|
1265 | + // so RegistryContainer::__get() throws this exception. |
|
1266 | + // also no need to worry about this or log it, |
|
1267 | + // it's ok to deregister an add-on before its registered in the registry |
|
1268 | + } catch (Exception $e) { |
|
1269 | + new ExceptionLogger($e); |
|
1270 | + } |
|
1271 | + unset(self::$_settings[ $addon_name ]); |
|
1272 | + do_action('AHEE__EE_Register_Addon__deregister__after', $addon_name); |
|
1273 | + } |
|
1274 | + } |
|
1275 | + |
|
1276 | + |
|
1277 | + public static function reset(): void |
|
1278 | + { |
|
1279 | + EE_Register_Addon::$_settings = []; |
|
1280 | + } |
|
1281 | + |
|
1282 | + |
|
1283 | + public static function resetAll(): void |
|
1284 | + { |
|
1285 | + // EE_Register_Addon::reset(); |
|
1286 | + EE_Register_Admin_Page::reset(); |
|
1287 | + EE_Register_Capabilities::reset(); |
|
1288 | + EE_Register_Config::reset(); |
|
1289 | + EE_Register_CPT::reset(); |
|
1290 | + EE_Register_Data_Migration_Scripts::reset(); |
|
1291 | + EE_Register_Message_Type::reset(); |
|
1292 | + EE_Register_Messages_Shortcode_Library::reset(); |
|
1293 | + EE_Register_Messages_Template_Pack::reset(); |
|
1294 | + EE_Register_Messages_Template_Variations::reset(); |
|
1295 | + EE_Register_Model::reset(); |
|
1296 | + EE_Register_Model_Extensions::reset(); |
|
1297 | + EE_Register_Module::reset(); |
|
1298 | + EE_Register_Payment_Method::reset(); |
|
1299 | + EE_Register_Personal_Data_Eraser::reset(); |
|
1300 | + EE_Register_Personal_Data_Exporter::reset(); |
|
1301 | + EE_Register_Privacy_Policy::reset(); |
|
1302 | + EE_Register_Shortcode::reset(); |
|
1303 | + EE_Register_Widget::reset(); |
|
1304 | + } |
|
1305 | 1305 | } |
@@ -76,15 +76,15 @@ discard block |
||
76 | 76 | // offsets: 0 . 1 . 2 . 3 . 4 |
77 | 77 | $version_parts = explode('.', $min_core_version); |
78 | 78 | // check they specified the micro version (after 2nd period) |
79 | - if (! isset($version_parts[2])) { |
|
79 | + if ( ! isset($version_parts[2])) { |
|
80 | 80 | $version_parts[2] = '0'; |
81 | 81 | } |
82 | 82 | // if they didn't specify the 'p', or 'rc' part. Just assume the lowest possible |
83 | 83 | // soon we can assume that's 'rc', but this current version is 'alpha' |
84 | - if (! isset($version_parts[3])) { |
|
84 | + if ( ! isset($version_parts[3])) { |
|
85 | 85 | $version_parts[3] = 'dev'; |
86 | 86 | } |
87 | - if (! isset($version_parts[4])) { |
|
87 | + if ( ! isset($version_parts[4])) { |
|
88 | 88 | $version_parts[4] = '000'; |
89 | 89 | } |
90 | 90 | return implode('.', $version_parts); |
@@ -261,7 +261,7 @@ discard block |
||
261 | 261 | public static function register(string $addon_name = '', array $setup_args = []): bool |
262 | 262 | { |
263 | 263 | // $addon_name = basename($addon_name); |
264 | - if (! self::$loader instanceof LoaderInterface) { |
|
264 | + if ( ! self::$loader instanceof LoaderInterface) { |
|
265 | 265 | self::$loader = LoaderFactory::getLoader(); |
266 | 266 | } |
267 | 267 | // make sure this was called in the right place! |
@@ -301,7 +301,7 @@ discard block |
||
301 | 301 | ); |
302 | 302 | // does this addon work with this version of core or WordPress ? |
303 | 303 | // does this addon work with this version of core or WordPress ? |
304 | - if (! EE_Register_Addon::_addon_is_compatible($addon_name, $addon_settings)) { |
|
304 | + if ( ! EE_Register_Addon::_addon_is_compatible($addon_name, $addon_settings)) { |
|
305 | 305 | return false; |
306 | 306 | } |
307 | 307 | // register namespaces |
@@ -379,7 +379,7 @@ discard block |
||
379 | 379 | ); |
380 | 380 | } |
381 | 381 | // check that addon has not already been registered with that name |
382 | - if (isset(self::$_settings[ $addon_name ]) && ! did_action('activate_plugin')) { |
|
382 | + if (isset(self::$_settings[$addon_name]) && ! did_action('activate_plugin')) { |
|
383 | 383 | throw new EE_Error( |
384 | 384 | sprintf( |
385 | 385 | esc_html__( |
@@ -411,7 +411,7 @@ discard block |
||
411 | 411 | // check if classname is fully qualified or is a legacy classname already prefixed with 'EE_' |
412 | 412 | return strpos($class_name, '\\') || strpos($class_name, 'EE_') === 0 |
413 | 413 | ? $class_name |
414 | - : 'EE_' . $class_name; |
|
414 | + : 'EE_'.$class_name; |
|
415 | 415 | } |
416 | 416 | |
417 | 417 | |
@@ -562,14 +562,14 @@ discard block |
||
562 | 562 | |
563 | 563 | // if plugin_action_slug is NOT set... |
564 | 564 | if (empty($addon_settings['plugin_action_slug'])) { |
565 | - if (! empty($addon_settings['payment_method_paths'])) { |
|
565 | + if ( ! empty($addon_settings['payment_method_paths'])) { |
|
566 | 566 | // but the addon is a payment method |
567 | 567 | $payment_method_path = reset($addon_settings['payment_method_paths']); |
568 | 568 | $plugin_action_slug = basename(strtolower($payment_method_path)); |
569 | 569 | $addon_settings['plugin_action_slug'] = $plugin_action_slug; |
570 | 570 | // let's also set the pm_slug to the same value |
571 | 571 | $addon_settings['pm_slug'] = $plugin_action_slug; |
572 | - } elseif (! empty($addon_settings['admin_path'])) { |
|
572 | + } elseif ( ! empty($addon_settings['admin_path'])) { |
|
573 | 573 | // or an admin page path IS set |
574 | 574 | $addon_settings['plugin_action_slug'] = basename($addon_settings['admin_path']); |
575 | 575 | } |
@@ -592,9 +592,9 @@ discard block |
||
592 | 592 | $incompatibility_message = ''; |
593 | 593 | // check whether this addon version is compatible with EE core |
594 | 594 | if ( |
595 | - isset(EE_Register_Addon::$_incompatible_addons[ $addon_name ]) |
|
595 | + isset(EE_Register_Addon::$_incompatible_addons[$addon_name]) |
|
596 | 596 | && ! self::_meets_min_core_version_requirement( |
597 | - EE_Register_Addon::$_incompatible_addons[ $addon_name ], |
|
597 | + EE_Register_Addon::$_incompatible_addons[$addon_name], |
|
598 | 598 | $addon_settings['version'] |
599 | 599 | ) |
600 | 600 | ) { |
@@ -605,7 +605,7 @@ discard block |
||
605 | 605 | ), |
606 | 606 | $addon_name, |
607 | 607 | '<br />', |
608 | - EE_Register_Addon::$_incompatible_addons[ $addon_name ], |
|
608 | + EE_Register_Addon::$_incompatible_addons[$addon_name], |
|
609 | 609 | '<span style="font-weight: bold; color: #D54E21;">', |
610 | 610 | '</span><br />' |
611 | 611 | ); |
@@ -637,7 +637,7 @@ discard block |
||
637 | 637 | '</span><br />' |
638 | 638 | ); |
639 | 639 | } |
640 | - if (! empty($incompatibility_message)) { |
|
640 | + if ( ! empty($incompatibility_message)) { |
|
641 | 641 | // remove 'activate' from the REQUEST |
642 | 642 | // so WP doesn't erroneously tell the user the plugin activated fine when it didn't |
643 | 643 | /** @var RequestInterface $request */ |
@@ -648,8 +648,8 @@ discard block |
||
648 | 648 | EE_Error::add_error($incompatibility_message, __FILE__, __FUNCTION__, __LINE__); |
649 | 649 | } |
650 | 650 | unset($_GET['activate'], $_REQUEST['activate']); |
651 | - if (! function_exists('deactivate_plugins')) { |
|
652 | - require_once ABSPATH . 'wp-admin/includes/plugin.php'; |
|
651 | + if ( ! function_exists('deactivate_plugins')) { |
|
652 | + require_once ABSPATH.'wp-admin/includes/plugin.php'; |
|
653 | 653 | } |
654 | 654 | deactivate_plugins(plugin_basename($addon_settings['main_file_path'])); |
655 | 655 | // BAIL FROM THE ADDON REGISTRATION PROCESS |
@@ -699,12 +699,12 @@ discard block |
||
699 | 699 | // to find if THIS is the addon that was activated, just check if we have already registered it or not |
700 | 700 | // (as the newly-activated addon wasn't around the first time addons were registered). |
701 | 701 | if ( |
702 | - ! isset(self::$_settings[ $addon_name ]) |
|
703 | - || (isset(self::$_settings[ $addon_name ]) |
|
704 | - && ! isset(self::$_settings[ $addon_name ]['class_name']) |
|
702 | + ! isset(self::$_settings[$addon_name]) |
|
703 | + || (isset(self::$_settings[$addon_name]) |
|
704 | + && ! isset(self::$_settings[$addon_name]['class_name']) |
|
705 | 705 | ) |
706 | 706 | ) { |
707 | - self::$_settings[ $addon_name ] = $addon_settings; |
|
707 | + self::$_settings[$addon_name] = $addon_settings; |
|
708 | 708 | $addon = self::_load_and_init_addon_class($addon_name); |
709 | 709 | $addon->set_activation_indicator_option(); |
710 | 710 | // dont bother setting up the rest of the addon. |
@@ -713,10 +713,10 @@ discard block |
||
713 | 713 | return true; |
714 | 714 | } |
715 | 715 | // make sure addon settings are set correctly without overwriting anything existing |
716 | - if (isset(self::$_settings[ $addon_name ])) { |
|
717 | - self::$_settings[ $addon_name ] += $addon_settings; |
|
716 | + if (isset(self::$_settings[$addon_name])) { |
|
717 | + self::$_settings[$addon_name] += $addon_settings; |
|
718 | 718 | } else { |
719 | - self::$_settings[ $addon_name ] = $addon_settings; |
|
719 | + self::$_settings[$addon_name] = $addon_settings; |
|
720 | 720 | } |
721 | 721 | return false; |
722 | 722 | } |
@@ -729,13 +729,13 @@ discard block |
||
729 | 729 | */ |
730 | 730 | private static function _setup_autoloaders(string $addon_name) |
731 | 731 | { |
732 | - if (! empty(self::$_settings[ $addon_name ]['autoloader_paths'])) { |
|
732 | + if ( ! empty(self::$_settings[$addon_name]['autoloader_paths'])) { |
|
733 | 733 | // setup autoloader for single file |
734 | - EEH_Autoloader::instance()->register_autoloader(self::$_settings[ $addon_name ]['autoloader_paths']); |
|
734 | + EEH_Autoloader::instance()->register_autoloader(self::$_settings[$addon_name]['autoloader_paths']); |
|
735 | 735 | } |
736 | 736 | // setup autoloaders for folders |
737 | - if (! empty(self::$_settings[ $addon_name ]['autoloader_folders'])) { |
|
738 | - foreach ((array) self::$_settings[ $addon_name ]['autoloader_folders'] as $autoloader_folder) { |
|
737 | + if ( ! empty(self::$_settings[$addon_name]['autoloader_folders'])) { |
|
738 | + foreach ((array) self::$_settings[$addon_name]['autoloader_folders'] as $autoloader_folder) { |
|
739 | 739 | EEH_Autoloader::register_autoloaders_for_each_file_in_folder($autoloader_folder); |
740 | 740 | } |
741 | 741 | } |
@@ -753,27 +753,27 @@ discard block |
||
753 | 753 | { |
754 | 754 | // register new models |
755 | 755 | if ( |
756 | - ! empty(self::$_settings[ $addon_name ]['model_paths']) |
|
757 | - || ! empty(self::$_settings[ $addon_name ]['class_paths']) |
|
756 | + ! empty(self::$_settings[$addon_name]['model_paths']) |
|
757 | + || ! empty(self::$_settings[$addon_name]['class_paths']) |
|
758 | 758 | ) { |
759 | 759 | EE_Register_Model::register( |
760 | 760 | $addon_name, |
761 | 761 | [ |
762 | - 'model_paths' => self::$_settings[ $addon_name ]['model_paths'], |
|
763 | - 'class_paths' => self::$_settings[ $addon_name ]['class_paths'], |
|
762 | + 'model_paths' => self::$_settings[$addon_name]['model_paths'], |
|
763 | + 'class_paths' => self::$_settings[$addon_name]['class_paths'], |
|
764 | 764 | ] |
765 | 765 | ); |
766 | 766 | } |
767 | 767 | // register model extensions |
768 | 768 | if ( |
769 | - ! empty(self::$_settings[ $addon_name ]['model_extension_paths']) |
|
770 | - || ! empty(self::$_settings[ $addon_name ]['class_extension_paths']) |
|
769 | + ! empty(self::$_settings[$addon_name]['model_extension_paths']) |
|
770 | + || ! empty(self::$_settings[$addon_name]['class_extension_paths']) |
|
771 | 771 | ) { |
772 | 772 | EE_Register_Model_Extensions::register( |
773 | 773 | $addon_name, |
774 | 774 | [ |
775 | - 'model_extension_paths' => self::$_settings[ $addon_name ]['model_extension_paths'], |
|
776 | - 'class_extension_paths' => self::$_settings[ $addon_name ]['class_extension_paths'], |
|
775 | + 'model_extension_paths' => self::$_settings[$addon_name]['model_extension_paths'], |
|
776 | + 'class_extension_paths' => self::$_settings[$addon_name]['class_extension_paths'], |
|
777 | 777 | ] |
778 | 778 | ); |
779 | 779 | } |
@@ -788,10 +788,10 @@ discard block |
||
788 | 788 | private static function _register_data_migration_scripts(string $addon_name) |
789 | 789 | { |
790 | 790 | // setup DMS |
791 | - if (! empty(self::$_settings[ $addon_name ]['dms_paths'])) { |
|
791 | + if ( ! empty(self::$_settings[$addon_name]['dms_paths'])) { |
|
792 | 792 | EE_Register_Data_Migration_Scripts::register( |
793 | 793 | $addon_name, |
794 | - ['dms_paths' => self::$_settings[ $addon_name ]['dms_paths']] |
|
794 | + ['dms_paths' => self::$_settings[$addon_name]['dms_paths']] |
|
795 | 795 | ); |
796 | 796 | } |
797 | 797 | } |
@@ -805,12 +805,12 @@ discard block |
||
805 | 805 | private static function _register_config(string $addon_name) |
806 | 806 | { |
807 | 807 | // if config_class is present let's register config. |
808 | - if (! empty(self::$_settings[ $addon_name ]['config_class'])) { |
|
808 | + if ( ! empty(self::$_settings[$addon_name]['config_class'])) { |
|
809 | 809 | EE_Register_Config::register( |
810 | - self::$_settings[ $addon_name ]['config_class'], |
|
810 | + self::$_settings[$addon_name]['config_class'], |
|
811 | 811 | [ |
812 | - 'config_section' => self::$_settings[ $addon_name ]['config_section'], |
|
813 | - 'config_name' => self::$_settings[ $addon_name ]['config_name'], |
|
812 | + 'config_section' => self::$_settings[$addon_name]['config_section'], |
|
813 | + 'config_name' => self::$_settings[$addon_name]['config_name'], |
|
814 | 814 | ] |
815 | 815 | ); |
816 | 816 | } |
@@ -824,10 +824,10 @@ discard block |
||
824 | 824 | */ |
825 | 825 | private static function _register_admin_pages(string $addon_name) |
826 | 826 | { |
827 | - if (! empty(self::$_settings[ $addon_name ]['admin_path'])) { |
|
827 | + if ( ! empty(self::$_settings[$addon_name]['admin_path'])) { |
|
828 | 828 | EE_Register_Admin_Page::register( |
829 | 829 | $addon_name, |
830 | - ['page_path' => self::$_settings[ $addon_name ]['admin_path']] |
|
830 | + ['page_path' => self::$_settings[$addon_name]['admin_path']] |
|
831 | 831 | ); |
832 | 832 | } |
833 | 833 | } |
@@ -840,10 +840,10 @@ discard block |
||
840 | 840 | */ |
841 | 841 | private static function _register_modules(string $addon_name) |
842 | 842 | { |
843 | - if (! empty(self::$_settings[ $addon_name ]['module_paths'])) { |
|
843 | + if ( ! empty(self::$_settings[$addon_name]['module_paths'])) { |
|
844 | 844 | EE_Register_Module::register( |
845 | 845 | $addon_name, |
846 | - ['module_paths' => self::$_settings[ $addon_name ]['module_paths']] |
|
846 | + ['module_paths' => self::$_settings[$addon_name]['module_paths']] |
|
847 | 847 | ); |
848 | 848 | } |
849 | 849 | } |
@@ -857,14 +857,14 @@ discard block |
||
857 | 857 | private static function _register_shortcodes(string $addon_name) |
858 | 858 | { |
859 | 859 | if ( |
860 | - ! empty(self::$_settings[ $addon_name ]['shortcode_paths']) |
|
861 | - || ! empty(self::$_settings[ $addon_name ]['shortcode_fqcns']) |
|
860 | + ! empty(self::$_settings[$addon_name]['shortcode_paths']) |
|
861 | + || ! empty(self::$_settings[$addon_name]['shortcode_fqcns']) |
|
862 | 862 | ) { |
863 | 863 | EE_Register_Shortcode::register( |
864 | 864 | $addon_name, |
865 | 865 | [ |
866 | - 'shortcode_paths' => self::$_settings[ $addon_name ]['shortcode_paths'] ?? [], |
|
867 | - 'shortcode_fqcns' => self::$_settings[ $addon_name ]['shortcode_fqcns'] ?? [], |
|
866 | + 'shortcode_paths' => self::$_settings[$addon_name]['shortcode_paths'] ?? [], |
|
867 | + 'shortcode_fqcns' => self::$_settings[$addon_name]['shortcode_fqcns'] ?? [], |
|
868 | 868 | ] |
869 | 869 | ); |
870 | 870 | } |
@@ -878,10 +878,10 @@ discard block |
||
878 | 878 | */ |
879 | 879 | private static function _register_widgets(string $addon_name) |
880 | 880 | { |
881 | - if (! empty(self::$_settings[ $addon_name ]['widget_paths'])) { |
|
881 | + if ( ! empty(self::$_settings[$addon_name]['widget_paths'])) { |
|
882 | 882 | EE_Register_Widget::register( |
883 | 883 | $addon_name, |
884 | - ['widget_paths' => self::$_settings[ $addon_name ]['widget_paths']] |
|
884 | + ['widget_paths' => self::$_settings[$addon_name]['widget_paths']] |
|
885 | 885 | ); |
886 | 886 | } |
887 | 887 | } |
@@ -894,12 +894,12 @@ discard block |
||
894 | 894 | */ |
895 | 895 | private static function _register_capabilities(string $addon_name) |
896 | 896 | { |
897 | - if (! empty(self::$_settings[ $addon_name ]['capabilities'])) { |
|
897 | + if ( ! empty(self::$_settings[$addon_name]['capabilities'])) { |
|
898 | 898 | EE_Register_Capabilities::register( |
899 | 899 | $addon_name, |
900 | 900 | [ |
901 | - 'capabilities' => self::$_settings[ $addon_name ]['capabilities'], |
|
902 | - 'capability_maps' => self::$_settings[ $addon_name ]['capability_maps'], |
|
901 | + 'capabilities' => self::$_settings[$addon_name]['capabilities'], |
|
902 | + 'capability_maps' => self::$_settings[$addon_name]['capability_maps'], |
|
903 | 903 | ] |
904 | 904 | ); |
905 | 905 | } |
@@ -912,7 +912,7 @@ discard block |
||
912 | 912 | */ |
913 | 913 | private static function _register_message_types(string $addon_name) |
914 | 914 | { |
915 | - if (! empty(self::$_settings[ $addon_name ]['message_types'])) { |
|
915 | + if ( ! empty(self::$_settings[$addon_name]['message_types'])) { |
|
916 | 916 | add_action( |
917 | 917 | 'EE_Brewing_Regular___messages_caf', |
918 | 918 | ['EE_Register_Addon', 'register_message_types'] |
@@ -929,15 +929,15 @@ discard block |
||
929 | 929 | private static function _register_custom_post_types(string $addon_name) |
930 | 930 | { |
931 | 931 | if ( |
932 | - ! empty(self::$_settings[ $addon_name ]['custom_post_types']) |
|
933 | - || ! empty(self::$_settings[ $addon_name ]['custom_taxonomies']) |
|
932 | + ! empty(self::$_settings[$addon_name]['custom_post_types']) |
|
933 | + || ! empty(self::$_settings[$addon_name]['custom_taxonomies']) |
|
934 | 934 | ) { |
935 | 935 | EE_Register_CPT::register( |
936 | 936 | $addon_name, |
937 | 937 | [ |
938 | - 'cpts' => self::$_settings[ $addon_name ]['custom_post_types'], |
|
939 | - 'cts' => self::$_settings[ $addon_name ]['custom_taxonomies'], |
|
940 | - 'default_terms' => self::$_settings[ $addon_name ]['default_terms'], |
|
938 | + 'cpts' => self::$_settings[$addon_name]['custom_post_types'], |
|
939 | + 'cts' => self::$_settings[$addon_name]['custom_taxonomies'], |
|
940 | + 'default_terms' => self::$_settings[$addon_name]['default_terms'], |
|
941 | 941 | ] |
942 | 942 | ); |
943 | 943 | } |
@@ -955,10 +955,10 @@ discard block |
||
955 | 955 | */ |
956 | 956 | private static function _register_payment_methods(string $addon_name) |
957 | 957 | { |
958 | - if (! empty(self::$_settings[ $addon_name ]['payment_method_paths'])) { |
|
958 | + if ( ! empty(self::$_settings[$addon_name]['payment_method_paths'])) { |
|
959 | 959 | EE_Register_Payment_Method::register( |
960 | 960 | $addon_name, |
961 | - ['payment_method_paths' => self::$_settings[ $addon_name ]['payment_method_paths']] |
|
961 | + ['payment_method_paths' => self::$_settings[$addon_name]['payment_method_paths']] |
|
962 | 962 | ); |
963 | 963 | } |
964 | 964 | } |
@@ -974,10 +974,10 @@ discard block |
||
974 | 974 | */ |
975 | 975 | private static function registerPrivacyPolicies(string $addon_name) |
976 | 976 | { |
977 | - if (! empty(self::$_settings[ $addon_name ]['privacy_policies'])) { |
|
977 | + if ( ! empty(self::$_settings[$addon_name]['privacy_policies'])) { |
|
978 | 978 | EE_Register_Privacy_Policy::register( |
979 | 979 | $addon_name, |
980 | - self::$_settings[ $addon_name ]['privacy_policies'] |
|
980 | + self::$_settings[$addon_name]['privacy_policies'] |
|
981 | 981 | ); |
982 | 982 | } |
983 | 983 | } |
@@ -989,10 +989,10 @@ discard block |
||
989 | 989 | */ |
990 | 990 | private static function registerPersonalDataExporters(string $addon_name) |
991 | 991 | { |
992 | - if (! empty(self::$_settings[ $addon_name ]['personal_data_exporters'])) { |
|
992 | + if ( ! empty(self::$_settings[$addon_name]['personal_data_exporters'])) { |
|
993 | 993 | EE_Register_Personal_Data_Eraser::register( |
994 | 994 | $addon_name, |
995 | - self::$_settings[ $addon_name ]['personal_data_exporters'] |
|
995 | + self::$_settings[$addon_name]['personal_data_exporters'] |
|
996 | 996 | ); |
997 | 997 | } |
998 | 998 | } |
@@ -1004,10 +1004,10 @@ discard block |
||
1004 | 1004 | */ |
1005 | 1005 | private static function registerPersonalDataErasers(string $addon_name) |
1006 | 1006 | { |
1007 | - if (! empty(self::$_settings[ $addon_name ]['personal_data_erasers'])) { |
|
1007 | + if ( ! empty(self::$_settings[$addon_name]['personal_data_erasers'])) { |
|
1008 | 1008 | EE_Register_Personal_Data_Eraser::register( |
1009 | 1009 | $addon_name, |
1010 | - self::$_settings[ $addon_name ]['personal_data_erasers'] |
|
1010 | + self::$_settings[$addon_name]['personal_data_erasers'] |
|
1011 | 1011 | ); |
1012 | 1012 | } |
1013 | 1013 | } |
@@ -1025,14 +1025,14 @@ discard block |
||
1025 | 1025 | private static function _load_and_init_addon_class(string $addon_name): EE_Addon |
1026 | 1026 | { |
1027 | 1027 | $addon = self::$loader->getShared( |
1028 | - self::$_settings[ $addon_name ]['class_name'], |
|
1028 | + self::$_settings[$addon_name]['class_name'], |
|
1029 | 1029 | ['EE_Registry::create(addon)' => true] |
1030 | 1030 | ); |
1031 | - if (! $addon instanceof EE_Addon) { |
|
1031 | + if ( ! $addon instanceof EE_Addon) { |
|
1032 | 1032 | throw new DomainException( |
1033 | 1033 | sprintf( |
1034 | 1034 | esc_html__('The "%1$s" EE_Addon class failed to instantiate!', 'event_espresso'), |
1035 | - self::$_settings[ $addon_name ]['class_name'] |
|
1035 | + self::$_settings[$addon_name]['class_name'] |
|
1036 | 1036 | ) |
1037 | 1037 | ); |
1038 | 1038 | } |
@@ -1044,18 +1044,18 @@ discard block |
||
1044 | 1044 | EE_Register_Addon::injectAddonDomain($addon_name, $addon); |
1045 | 1045 | |
1046 | 1046 | $addon->set_name($addon_name); |
1047 | - $addon->set_plugin_slug(self::$_settings[ $addon_name ]['plugin_slug']); |
|
1048 | - $addon->set_plugin_basename(self::$_settings[ $addon_name ]['plugin_basename']); |
|
1049 | - $addon->set_main_plugin_file(self::$_settings[ $addon_name ]['main_file_path']); |
|
1050 | - $addon->set_plugin_action_slug(self::$_settings[ $addon_name ]['plugin_action_slug']); |
|
1051 | - $addon->set_plugins_page_row(self::$_settings[ $addon_name ]['plugins_page_row']); |
|
1052 | - $addon->set_version(self::$_settings[ $addon_name ]['version']); |
|
1053 | - $addon->set_min_core_version(self::_effective_version(self::$_settings[ $addon_name ]['min_core_version'])); |
|
1054 | - $addon->set_config_section(self::$_settings[ $addon_name ]['config_section']); |
|
1055 | - $addon->set_config_class(self::$_settings[ $addon_name ]['config_class']); |
|
1056 | - $addon->set_config_name(self::$_settings[ $addon_name ]['config_name']); |
|
1057 | - if (! empty(self::$_settings[ $addon_name ]['pm_slug'])) { |
|
1058 | - $addon->setPaymentmethodSlug(self::$_settings[ $addon_name ]['pm_slug']); |
|
1047 | + $addon->set_plugin_slug(self::$_settings[$addon_name]['plugin_slug']); |
|
1048 | + $addon->set_plugin_basename(self::$_settings[$addon_name]['plugin_basename']); |
|
1049 | + $addon->set_main_plugin_file(self::$_settings[$addon_name]['main_file_path']); |
|
1050 | + $addon->set_plugin_action_slug(self::$_settings[$addon_name]['plugin_action_slug']); |
|
1051 | + $addon->set_plugins_page_row(self::$_settings[$addon_name]['plugins_page_row']); |
|
1052 | + $addon->set_version(self::$_settings[$addon_name]['version']); |
|
1053 | + $addon->set_min_core_version(self::_effective_version(self::$_settings[$addon_name]['min_core_version'])); |
|
1054 | + $addon->set_config_section(self::$_settings[$addon_name]['config_section']); |
|
1055 | + $addon->set_config_class(self::$_settings[$addon_name]['config_class']); |
|
1056 | + $addon->set_config_name(self::$_settings[$addon_name]['config_name']); |
|
1057 | + if ( ! empty(self::$_settings[$addon_name]['pm_slug'])) { |
|
1058 | + $addon->setPaymentmethodSlug(self::$_settings[$addon_name]['pm_slug']); |
|
1059 | 1059 | } |
1060 | 1060 | do_action( |
1061 | 1061 | 'AHEE__EE_Register_Addon___load_and_init_addon_class', |
@@ -1067,10 +1067,10 @@ discard block |
||
1067 | 1067 | // because we don't have the plugin's mainfile path upon construction. |
1068 | 1068 | register_deactivation_hook($addon->get_main_plugin_file(), [$addon, 'deactivation']); |
1069 | 1069 | // call any additional admin_callback functions during load_admin_controller hook |
1070 | - if (! empty(self::$_settings[ $addon_name ]['admin_callback'])) { |
|
1070 | + if ( ! empty(self::$_settings[$addon_name]['admin_callback'])) { |
|
1071 | 1071 | add_action( |
1072 | 1072 | 'AHEE__EE_System__load_controllers__load_admin_controllers', |
1073 | - [$addon, self::$_settings[ $addon_name ]['admin_callback']] |
|
1073 | + [$addon, self::$_settings[$addon_name]['admin_callback']] |
|
1074 | 1074 | ); |
1075 | 1075 | } |
1076 | 1076 | return $addon; |
@@ -1086,19 +1086,19 @@ discard block |
||
1086 | 1086 | { |
1087 | 1087 | if ($addon instanceof RequiresDomainInterface && $addon->domain() === null) { |
1088 | 1088 | // using supplied Domain object |
1089 | - $domain = self::$_settings[ $addon_name ]['domain'] instanceof DomainInterface |
|
1090 | - ? self::$_settings[ $addon_name ]['domain'] |
|
1089 | + $domain = self::$_settings[$addon_name]['domain'] instanceof DomainInterface |
|
1090 | + ? self::$_settings[$addon_name]['domain'] |
|
1091 | 1091 | : null; |
1092 | 1092 | // or construct one using Domain FQCN |
1093 | - if ($domain === null && self::$_settings[ $addon_name ]['domain_fqcn'] !== '') { |
|
1093 | + if ($domain === null && self::$_settings[$addon_name]['domain_fqcn'] !== '') { |
|
1094 | 1094 | $domain = self::$loader->getShared( |
1095 | - self::$_settings[ $addon_name ]['domain_fqcn'], |
|
1095 | + self::$_settings[$addon_name]['domain_fqcn'], |
|
1096 | 1096 | [ |
1097 | 1097 | new EventEspresso\core\domain\values\FilePath( |
1098 | - self::$_settings[ $addon_name ]['main_file_path'] |
|
1098 | + self::$_settings[$addon_name]['main_file_path'] |
|
1099 | 1099 | ), |
1100 | 1100 | EventEspresso\core\domain\values\Version::fromString( |
1101 | - self::$_settings[ $addon_name ]['version'] |
|
1101 | + self::$_settings[$addon_name]['version'] |
|
1102 | 1102 | ), |
1103 | 1103 | ] |
1104 | 1104 | ); |
@@ -1129,7 +1129,7 @@ discard block |
||
1129 | 1129 | public static function register_message_types() |
1130 | 1130 | { |
1131 | 1131 | foreach (self::$_settings as $settings) { |
1132 | - if (! empty($settings['message_types'])) { |
|
1132 | + if ( ! empty($settings['message_types'])) { |
|
1133 | 1133 | foreach ((array) $settings['message_types'] as $message_type => $message_type_settings) { |
1134 | 1134 | EE_Register_Message_Type::register($message_type, $message_type_settings); |
1135 | 1135 | } |
@@ -1148,7 +1148,7 @@ discard block |
||
1148 | 1148 | if ($request->isWordPressHeartbeat()) { |
1149 | 1149 | return; |
1150 | 1150 | } |
1151 | - $addon_settings = self::$_settings[ $addon_name ] ?? []; |
|
1151 | + $addon_settings = self::$_settings[$addon_name] ?? []; |
|
1152 | 1152 | if (empty($addon_settings)) { |
1153 | 1153 | return; |
1154 | 1154 | } |
@@ -1177,74 +1177,74 @@ discard block |
||
1177 | 1177 | */ |
1178 | 1178 | public static function deregister(string $addon_name = '') |
1179 | 1179 | { |
1180 | - if (isset(self::$_settings[ $addon_name ]['class_name'])) { |
|
1180 | + if (isset(self::$_settings[$addon_name]['class_name'])) { |
|
1181 | 1181 | try { |
1182 | 1182 | do_action('AHEE__EE_Register_Addon__deregister__before', $addon_name); |
1183 | - $class_name = self::$_settings[ $addon_name ]['class_name']; |
|
1184 | - if (! empty(self::$_settings[ $addon_name ]['dms_paths'])) { |
|
1183 | + $class_name = self::$_settings[$addon_name]['class_name']; |
|
1184 | + if ( ! empty(self::$_settings[$addon_name]['dms_paths'])) { |
|
1185 | 1185 | // setup DMS |
1186 | 1186 | EE_Register_Data_Migration_Scripts::deregister($addon_name); |
1187 | 1187 | } |
1188 | - if (! empty(self::$_settings[ $addon_name ]['admin_path'])) { |
|
1188 | + if ( ! empty(self::$_settings[$addon_name]['admin_path'])) { |
|
1189 | 1189 | // register admin page |
1190 | 1190 | EE_Register_Admin_Page::deregister($addon_name); |
1191 | 1191 | } |
1192 | - if (! empty(self::$_settings[ $addon_name ]['module_paths'])) { |
|
1192 | + if ( ! empty(self::$_settings[$addon_name]['module_paths'])) { |
|
1193 | 1193 | // add to list of modules to be registered |
1194 | 1194 | EE_Register_Module::deregister($addon_name); |
1195 | 1195 | } |
1196 | 1196 | if ( |
1197 | - ! empty(self::$_settings[ $addon_name ]['shortcode_paths']) |
|
1198 | - || ! empty(self::$_settings[ $addon_name ]['shortcode_fqcns']) |
|
1197 | + ! empty(self::$_settings[$addon_name]['shortcode_paths']) |
|
1198 | + || ! empty(self::$_settings[$addon_name]['shortcode_fqcns']) |
|
1199 | 1199 | ) { |
1200 | 1200 | // add to list of shortcodes to be registered |
1201 | 1201 | EE_Register_Shortcode::deregister($addon_name); |
1202 | 1202 | } |
1203 | - if (! empty(self::$_settings[ $addon_name ]['config_class'])) { |
|
1203 | + if ( ! empty(self::$_settings[$addon_name]['config_class'])) { |
|
1204 | 1204 | // if config_class present let's register config. |
1205 | - EE_Register_Config::deregister(self::$_settings[ $addon_name ]['config_class']); |
|
1205 | + EE_Register_Config::deregister(self::$_settings[$addon_name]['config_class']); |
|
1206 | 1206 | } |
1207 | - if (! empty(self::$_settings[ $addon_name ]['widget_paths'])) { |
|
1207 | + if ( ! empty(self::$_settings[$addon_name]['widget_paths'])) { |
|
1208 | 1208 | // add to list of widgets to be registered |
1209 | 1209 | EE_Register_Widget::deregister($addon_name); |
1210 | 1210 | } |
1211 | 1211 | if ( |
1212 | - ! empty(self::$_settings[ $addon_name ]['model_paths']) |
|
1213 | - || ! empty(self::$_settings[ $addon_name ]['class_paths']) |
|
1212 | + ! empty(self::$_settings[$addon_name]['model_paths']) |
|
1213 | + || ! empty(self::$_settings[$addon_name]['class_paths']) |
|
1214 | 1214 | ) { |
1215 | 1215 | // add to list of shortcodes to be registered |
1216 | 1216 | EE_Register_Model::deregister($addon_name); |
1217 | 1217 | } |
1218 | 1218 | if ( |
1219 | - ! empty(self::$_settings[ $addon_name ]['model_extension_paths']) |
|
1220 | - || ! empty(self::$_settings[ $addon_name ]['class_extension_paths']) |
|
1219 | + ! empty(self::$_settings[$addon_name]['model_extension_paths']) |
|
1220 | + || ! empty(self::$_settings[$addon_name]['class_extension_paths']) |
|
1221 | 1221 | ) { |
1222 | 1222 | // add to list of shortcodes to be registered |
1223 | 1223 | EE_Register_Model_Extensions::deregister($addon_name); |
1224 | 1224 | } |
1225 | - if (! empty(self::$_settings[ $addon_name ]['message_types'])) { |
|
1226 | - foreach ((array) self::$_settings[ $addon_name ]['message_types'] as $message_type => $message_type_settings) { |
|
1225 | + if ( ! empty(self::$_settings[$addon_name]['message_types'])) { |
|
1226 | + foreach ((array) self::$_settings[$addon_name]['message_types'] as $message_type => $message_type_settings) { |
|
1227 | 1227 | EE_Register_Message_Type::deregister($message_type); |
1228 | 1228 | } |
1229 | 1229 | } |
1230 | 1230 | // deregister capabilities for addon |
1231 | 1231 | if ( |
1232 | - ! empty(self::$_settings[ $addon_name ]['capabilities']) |
|
1233 | - || ! empty(self::$_settings[ $addon_name ]['capability_maps']) |
|
1232 | + ! empty(self::$_settings[$addon_name]['capabilities']) |
|
1233 | + || ! empty(self::$_settings[$addon_name]['capability_maps']) |
|
1234 | 1234 | ) { |
1235 | 1235 | EE_Register_Capabilities::deregister($addon_name); |
1236 | 1236 | } |
1237 | 1237 | // deregister custom_post_types for addon |
1238 | - if (! empty(self::$_settings[ $addon_name ]['custom_post_types'])) { |
|
1238 | + if ( ! empty(self::$_settings[$addon_name]['custom_post_types'])) { |
|
1239 | 1239 | EE_Register_CPT::deregister($addon_name); |
1240 | 1240 | } |
1241 | - if (! empty(self::$_settings[ $addon_name ]['payment_method_paths'])) { |
|
1241 | + if ( ! empty(self::$_settings[$addon_name]['payment_method_paths'])) { |
|
1242 | 1242 | EE_Register_Payment_Method::deregister($addon_name); |
1243 | 1243 | } |
1244 | 1244 | $addon = EE_Registry::instance()->getAddon($class_name); |
1245 | 1245 | if ($addon instanceof EE_Addon) { |
1246 | 1246 | remove_action( |
1247 | - 'deactivate_' . $addon->get_main_plugin_file_basename(), |
|
1247 | + 'deactivate_'.$addon->get_main_plugin_file_basename(), |
|
1248 | 1248 | [$addon, 'deactivation'] |
1249 | 1249 | ); |
1250 | 1250 | remove_action( |
@@ -1268,7 +1268,7 @@ discard block |
||
1268 | 1268 | } catch (Exception $e) { |
1269 | 1269 | new ExceptionLogger($e); |
1270 | 1270 | } |
1271 | - unset(self::$_settings[ $addon_name ]); |
|
1271 | + unset(self::$_settings[$addon_name]); |
|
1272 | 1272 | do_action('AHEE__EE_Register_Addon__deregister__after', $addon_name); |
1273 | 1273 | } |
1274 | 1274 | } |
@@ -12,279 +12,279 @@ |
||
12 | 12 | */ |
13 | 13 | class EEH_Schema |
14 | 14 | { |
15 | - /** |
|
16 | - * generates JSON-based linked data for an event |
|
17 | - * |
|
18 | - * @param EE_Event $event |
|
19 | - * @throws EE_Error |
|
20 | - * @throws ReflectionException |
|
21 | - */ |
|
22 | - public static function add_json_linked_data_for_event(EE_Event $event) |
|
23 | - { |
|
24 | - // Check we have a valid datetime for the event |
|
25 | - if (! $event->primary_datetime() instanceof EE_Datetime) { |
|
26 | - return; |
|
27 | - } |
|
15 | + /** |
|
16 | + * generates JSON-based linked data for an event |
|
17 | + * |
|
18 | + * @param EE_Event $event |
|
19 | + * @throws EE_Error |
|
20 | + * @throws ReflectionException |
|
21 | + */ |
|
22 | + public static function add_json_linked_data_for_event(EE_Event $event) |
|
23 | + { |
|
24 | + // Check we have a valid datetime for the event |
|
25 | + if (! $event->primary_datetime() instanceof EE_Datetime) { |
|
26 | + return; |
|
27 | + } |
|
28 | 28 | |
29 | - $template_args = [ |
|
30 | - 'event_tickets' => [], |
|
31 | - 'venue_name' => '', |
|
32 | - 'venue_url' => '', |
|
33 | - 'venue_locality' => '', |
|
34 | - 'venue_region' => '', |
|
35 | - 'venue_address' => '', |
|
36 | - ]; |
|
37 | - $template_args['event_permalink'] = $event->get_permalink(); |
|
38 | - $template_args['event_name'] = $event->name(); |
|
39 | - $template_args['event_description'] = wp_strip_all_tags($event->short_description(200)); |
|
40 | - // clone datetime so that date formats don't override those for the original datetime |
|
41 | - $primary_datetime = clone $event->primary_datetime(); |
|
42 | - $template_args['event_start'] = $primary_datetime->start_date(DateTimeInterface::ATOM); |
|
43 | - $template_args['event_end'] = $primary_datetime->end_date(DateTimeInterface::ATOM); |
|
44 | - unset($primary_datetime); |
|
45 | - switch ($event->status()) { |
|
46 | - case EEM_Event::cancelled: |
|
47 | - $event_status = 'EventCancelled'; |
|
48 | - break; |
|
49 | - case EEM_Event::postponed: |
|
50 | - $event_status = 'EventPostponed'; |
|
51 | - break; |
|
52 | - default: |
|
53 | - $event_status = 'EventScheduled'; |
|
54 | - } |
|
55 | - $template_args['event_attendance_mode'] = 'OfflineEventAttendanceMode'; |
|
56 | - $template_args['event_status'] = 'https://schema.org/' . $event_status; |
|
57 | - $template_args['currency'] = EE_Registry::instance()->CFG->currency->code; |
|
58 | - foreach ($event->tickets() as $original_ticket) { |
|
59 | - // clone tickets so that date formats don't override those for the original ticket |
|
60 | - $ticket = clone $original_ticket; |
|
61 | - $ID = $ticket->ID(); |
|
62 | - $template_args['event_tickets'][ $ID ]['start_date'] = $ticket->start_date(DateTimeInterface::ATOM, null); |
|
63 | - $template_args['event_tickets'][ $ID ]['end_date'] = $ticket->end_date(DateTimeInterface::ATOM, null); |
|
64 | - $template_args['event_tickets'][ $ID ]['price'] = number_format( |
|
65 | - $ticket->price(), |
|
66 | - EE_Registry::instance()->CFG->currency->dec_plc, |
|
67 | - EE_Registry::instance()->CFG->currency->dec_mrk, |
|
68 | - '' |
|
69 | - ); |
|
70 | - switch ($ticket->ticket_status()) { |
|
71 | - case 'TKO': |
|
72 | - $availability = 'InStock'; |
|
73 | - break; |
|
74 | - case 'TKS': |
|
75 | - $availability = 'SoldOut'; |
|
76 | - break; |
|
77 | - default: |
|
78 | - $availability = null; |
|
79 | - break; |
|
80 | - } |
|
81 | - $template_args['event_tickets'][ $ID ]['availability'] = $availability; |
|
82 | - unset($ticket); |
|
83 | - } |
|
84 | - $VNU_ID = espresso_venue_id(); |
|
85 | - if (! empty($VNU_ID) && ! espresso_is_venue_private($VNU_ID)) { |
|
86 | - $venue = EEH_Venue_View::get_venue($VNU_ID); |
|
87 | - $template_args['venue_name'] = get_the_title($VNU_ID); |
|
88 | - $template_args['venue_url'] = get_permalink($VNU_ID); |
|
89 | - $template_args['venue_locality'] = $venue->city(); |
|
90 | - $template_args['venue_region'] = $venue->state_name(); |
|
91 | - $template_args['venue_address'] = $venue->address(); |
|
92 | - if ($venue->virtual_url() !== '') { |
|
93 | - $template_args['event_attendance_mode'] = 'OnlineEventAttendanceMode'; |
|
94 | - } |
|
95 | - if ($venue->virtual_url() !== '' && $venue->address() !== '') { |
|
96 | - $template_args['event_attendance_mode'] = 'MixedEventAttendanceMode'; |
|
97 | - } |
|
98 | - } |
|
99 | - $template_args['event_image'] = $event->feature_image_url(); |
|
100 | - $template_args = apply_filters( |
|
101 | - 'FHEE__EEH_Schema__add_json_linked_data_for_event__template_args', |
|
102 | - $template_args, |
|
103 | - $event, |
|
104 | - $VNU_ID |
|
105 | - ); |
|
106 | - extract($template_args); |
|
107 | - include EE_TEMPLATES . 'json_linked_data_for_event.template.php'; |
|
108 | - } |
|
29 | + $template_args = [ |
|
30 | + 'event_tickets' => [], |
|
31 | + 'venue_name' => '', |
|
32 | + 'venue_url' => '', |
|
33 | + 'venue_locality' => '', |
|
34 | + 'venue_region' => '', |
|
35 | + 'venue_address' => '', |
|
36 | + ]; |
|
37 | + $template_args['event_permalink'] = $event->get_permalink(); |
|
38 | + $template_args['event_name'] = $event->name(); |
|
39 | + $template_args['event_description'] = wp_strip_all_tags($event->short_description(200)); |
|
40 | + // clone datetime so that date formats don't override those for the original datetime |
|
41 | + $primary_datetime = clone $event->primary_datetime(); |
|
42 | + $template_args['event_start'] = $primary_datetime->start_date(DateTimeInterface::ATOM); |
|
43 | + $template_args['event_end'] = $primary_datetime->end_date(DateTimeInterface::ATOM); |
|
44 | + unset($primary_datetime); |
|
45 | + switch ($event->status()) { |
|
46 | + case EEM_Event::cancelled: |
|
47 | + $event_status = 'EventCancelled'; |
|
48 | + break; |
|
49 | + case EEM_Event::postponed: |
|
50 | + $event_status = 'EventPostponed'; |
|
51 | + break; |
|
52 | + default: |
|
53 | + $event_status = 'EventScheduled'; |
|
54 | + } |
|
55 | + $template_args['event_attendance_mode'] = 'OfflineEventAttendanceMode'; |
|
56 | + $template_args['event_status'] = 'https://schema.org/' . $event_status; |
|
57 | + $template_args['currency'] = EE_Registry::instance()->CFG->currency->code; |
|
58 | + foreach ($event->tickets() as $original_ticket) { |
|
59 | + // clone tickets so that date formats don't override those for the original ticket |
|
60 | + $ticket = clone $original_ticket; |
|
61 | + $ID = $ticket->ID(); |
|
62 | + $template_args['event_tickets'][ $ID ]['start_date'] = $ticket->start_date(DateTimeInterface::ATOM, null); |
|
63 | + $template_args['event_tickets'][ $ID ]['end_date'] = $ticket->end_date(DateTimeInterface::ATOM, null); |
|
64 | + $template_args['event_tickets'][ $ID ]['price'] = number_format( |
|
65 | + $ticket->price(), |
|
66 | + EE_Registry::instance()->CFG->currency->dec_plc, |
|
67 | + EE_Registry::instance()->CFG->currency->dec_mrk, |
|
68 | + '' |
|
69 | + ); |
|
70 | + switch ($ticket->ticket_status()) { |
|
71 | + case 'TKO': |
|
72 | + $availability = 'InStock'; |
|
73 | + break; |
|
74 | + case 'TKS': |
|
75 | + $availability = 'SoldOut'; |
|
76 | + break; |
|
77 | + default: |
|
78 | + $availability = null; |
|
79 | + break; |
|
80 | + } |
|
81 | + $template_args['event_tickets'][ $ID ]['availability'] = $availability; |
|
82 | + unset($ticket); |
|
83 | + } |
|
84 | + $VNU_ID = espresso_venue_id(); |
|
85 | + if (! empty($VNU_ID) && ! espresso_is_venue_private($VNU_ID)) { |
|
86 | + $venue = EEH_Venue_View::get_venue($VNU_ID); |
|
87 | + $template_args['venue_name'] = get_the_title($VNU_ID); |
|
88 | + $template_args['venue_url'] = get_permalink($VNU_ID); |
|
89 | + $template_args['venue_locality'] = $venue->city(); |
|
90 | + $template_args['venue_region'] = $venue->state_name(); |
|
91 | + $template_args['venue_address'] = $venue->address(); |
|
92 | + if ($venue->virtual_url() !== '') { |
|
93 | + $template_args['event_attendance_mode'] = 'OnlineEventAttendanceMode'; |
|
94 | + } |
|
95 | + if ($venue->virtual_url() !== '' && $venue->address() !== '') { |
|
96 | + $template_args['event_attendance_mode'] = 'MixedEventAttendanceMode'; |
|
97 | + } |
|
98 | + } |
|
99 | + $template_args['event_image'] = $event->feature_image_url(); |
|
100 | + $template_args = apply_filters( |
|
101 | + 'FHEE__EEH_Schema__add_json_linked_data_for_event__template_args', |
|
102 | + $template_args, |
|
103 | + $event, |
|
104 | + $VNU_ID |
|
105 | + ); |
|
106 | + extract($template_args); |
|
107 | + include EE_TEMPLATES . 'json_linked_data_for_event.template.php'; |
|
108 | + } |
|
109 | 109 | |
110 | 110 | |
111 | - /** |
|
112 | - * location |
|
113 | - * The location of the event, organization or action. |
|
114 | - * Should include the Venue name AND schema formatted address info |
|
115 | - * |
|
116 | - * @param string|null $location |
|
117 | - * @return string |
|
118 | - */ |
|
119 | - public static function location(?string $location = ''): string |
|
120 | - { |
|
121 | - return ! empty($location) |
|
122 | - ? "<div itemprop='location' itemscope itemtype='https://schema.org/Place'>$location</div>" |
|
123 | - : ''; |
|
124 | - } |
|
111 | + /** |
|
112 | + * location |
|
113 | + * The location of the event, organization or action. |
|
114 | + * Should include the Venue name AND schema formatted address info |
|
115 | + * |
|
116 | + * @param string|null $location |
|
117 | + * @return string |
|
118 | + */ |
|
119 | + public static function location(?string $location = ''): string |
|
120 | + { |
|
121 | + return ! empty($location) |
|
122 | + ? "<div itemprop='location' itemscope itemtype='https://schema.org/Place'>$location</div>" |
|
123 | + : ''; |
|
124 | + } |
|
125 | 125 | |
126 | 126 | |
127 | - /** |
|
128 | - * name |
|
129 | - * The name of the Event or Venue. |
|
130 | - * |
|
131 | - * @param string|null $name |
|
132 | - * @return string |
|
133 | - */ |
|
134 | - public static function name(?string $name = ''): string |
|
135 | - { |
|
136 | - return ! empty($name) |
|
137 | - ? "<span itemprop='name'>$name</span>" |
|
138 | - : ''; |
|
139 | - } |
|
127 | + /** |
|
128 | + * name |
|
129 | + * The name of the Event or Venue. |
|
130 | + * |
|
131 | + * @param string|null $name |
|
132 | + * @return string |
|
133 | + */ |
|
134 | + public static function name(?string $name = ''): string |
|
135 | + { |
|
136 | + return ! empty($name) |
|
137 | + ? "<span itemprop='name'>$name</span>" |
|
138 | + : ''; |
|
139 | + } |
|
140 | 140 | |
141 | 141 | |
142 | - /** |
|
143 | - * streetAddress |
|
144 | - * The street address. For example, 1600 Amphitheatre Pkwy. |
|
145 | - * |
|
146 | - * @param AddressInterface|null $obj_with_address |
|
147 | - * @return string |
|
148 | - */ |
|
149 | - public static function streetAddress(?AddressInterface $obj_with_address = null): string |
|
150 | - { |
|
151 | - $address = $obj_with_address->address(); |
|
152 | - return ! empty($address) |
|
153 | - ? "<span itemprop='streetAddress'>$address</span>" |
|
154 | - : ''; |
|
155 | - } |
|
142 | + /** |
|
143 | + * streetAddress |
|
144 | + * The street address. For example, 1600 Amphitheatre Pkwy. |
|
145 | + * |
|
146 | + * @param AddressInterface|null $obj_with_address |
|
147 | + * @return string |
|
148 | + */ |
|
149 | + public static function streetAddress(?AddressInterface $obj_with_address = null): string |
|
150 | + { |
|
151 | + $address = $obj_with_address->address(); |
|
152 | + return ! empty($address) |
|
153 | + ? "<span itemprop='streetAddress'>$address</span>" |
|
154 | + : ''; |
|
155 | + } |
|
156 | 156 | |
157 | 157 | |
158 | - /** |
|
159 | - * postOfficeBoxNumber |
|
160 | - * The post office box number for PO box addresses. |
|
161 | - * |
|
162 | - * @param AddressInterface|null $obj_with_address |
|
163 | - * @return string |
|
164 | - */ |
|
165 | - public static function postOfficeBoxNumber(?AddressInterface $obj_with_address = null): string |
|
166 | - { |
|
167 | - $address2 = $obj_with_address->address2(); |
|
168 | - // regex check for some form of PO Box or P.O. Box, etc, etc, etc |
|
169 | - if ( |
|
170 | - preg_match( |
|
171 | - "/^\s*((P(OST)?.?\s*(O(FF(ICE)?)?)?.?\s+(B(IN|OX))?)|B(IN|OX))/i", |
|
172 | - $address2 |
|
173 | - ) |
|
174 | - ) { |
|
175 | - return ! empty($address2) |
|
176 | - ? "<span itemprop='postOfficeBoxNumber'>$address2</span>" |
|
177 | - : ''; |
|
178 | - } |
|
179 | - return $address2; |
|
180 | - } |
|
158 | + /** |
|
159 | + * postOfficeBoxNumber |
|
160 | + * The post office box number for PO box addresses. |
|
161 | + * |
|
162 | + * @param AddressInterface|null $obj_with_address |
|
163 | + * @return string |
|
164 | + */ |
|
165 | + public static function postOfficeBoxNumber(?AddressInterface $obj_with_address = null): string |
|
166 | + { |
|
167 | + $address2 = $obj_with_address->address2(); |
|
168 | + // regex check for some form of PO Box or P.O. Box, etc, etc, etc |
|
169 | + if ( |
|
170 | + preg_match( |
|
171 | + "/^\s*((P(OST)?.?\s*(O(FF(ICE)?)?)?.?\s+(B(IN|OX))?)|B(IN|OX))/i", |
|
172 | + $address2 |
|
173 | + ) |
|
174 | + ) { |
|
175 | + return ! empty($address2) |
|
176 | + ? "<span itemprop='postOfficeBoxNumber'>$address2</span>" |
|
177 | + : ''; |
|
178 | + } |
|
179 | + return $address2; |
|
180 | + } |
|
181 | 181 | |
182 | 182 | |
183 | - /** |
|
184 | - * addressLocality |
|
185 | - * The locality (city, town, etc). For example, Mountain View. |
|
186 | - * |
|
187 | - * @param AddressInterface|null $obj_with_address |
|
188 | - * @return string |
|
189 | - */ |
|
190 | - public static function addressLocality(?AddressInterface $obj_with_address = null): string |
|
191 | - { |
|
192 | - $city = $obj_with_address->city(); |
|
193 | - return ! empty($city) |
|
194 | - ? "<span itemprop='addressLocality'>$city</span>" |
|
195 | - : ''; |
|
196 | - } |
|
183 | + /** |
|
184 | + * addressLocality |
|
185 | + * The locality (city, town, etc). For example, Mountain View. |
|
186 | + * |
|
187 | + * @param AddressInterface|null $obj_with_address |
|
188 | + * @return string |
|
189 | + */ |
|
190 | + public static function addressLocality(?AddressInterface $obj_with_address = null): string |
|
191 | + { |
|
192 | + $city = $obj_with_address->city(); |
|
193 | + return ! empty($city) |
|
194 | + ? "<span itemprop='addressLocality'>$city</span>" |
|
195 | + : ''; |
|
196 | + } |
|
197 | 197 | |
198 | 198 | |
199 | - /** |
|
200 | - * addressRegion |
|
201 | - * The region (state, province, etc). For example, CA. |
|
202 | - * |
|
203 | - * @param AddressInterface|null $obj_with_address |
|
204 | - * @return string |
|
205 | - */ |
|
206 | - public static function addressRegion(?AddressInterface $obj_with_address = null): string |
|
207 | - { |
|
208 | - $state = $obj_with_address->state_name(); |
|
209 | - return ! empty($state) |
|
210 | - ? "<span itemprop='addressRegion'>$state</span>" |
|
211 | - : ''; |
|
212 | - } |
|
199 | + /** |
|
200 | + * addressRegion |
|
201 | + * The region (state, province, etc). For example, CA. |
|
202 | + * |
|
203 | + * @param AddressInterface|null $obj_with_address |
|
204 | + * @return string |
|
205 | + */ |
|
206 | + public static function addressRegion(?AddressInterface $obj_with_address = null): string |
|
207 | + { |
|
208 | + $state = $obj_with_address->state_name(); |
|
209 | + return ! empty($state) |
|
210 | + ? "<span itemprop='addressRegion'>$state</span>" |
|
211 | + : ''; |
|
212 | + } |
|
213 | 213 | |
214 | 214 | |
215 | - /** |
|
216 | - * addressCountry |
|
217 | - * The country. For example, USA. You can also provide the two-letter ISO 3166-1 alpha-2 country code. |
|
218 | - * |
|
219 | - * @param AddressInterface|null $obj_with_address |
|
220 | - * @return string |
|
221 | - */ |
|
222 | - public static function addressCountry(?AddressInterface $obj_with_address = null): string |
|
223 | - { |
|
224 | - $country = $obj_with_address->country_name(); |
|
225 | - return ! empty($country) |
|
226 | - ? "<span itemprop='addressCountry'>$country</span>" |
|
227 | - : ''; |
|
228 | - } |
|
215 | + /** |
|
216 | + * addressCountry |
|
217 | + * The country. For example, USA. You can also provide the two-letter ISO 3166-1 alpha-2 country code. |
|
218 | + * |
|
219 | + * @param AddressInterface|null $obj_with_address |
|
220 | + * @return string |
|
221 | + */ |
|
222 | + public static function addressCountry(?AddressInterface $obj_with_address = null): string |
|
223 | + { |
|
224 | + $country = $obj_with_address->country_name(); |
|
225 | + return ! empty($country) |
|
226 | + ? "<span itemprop='addressCountry'>$country</span>" |
|
227 | + : ''; |
|
228 | + } |
|
229 | 229 | |
230 | 230 | |
231 | - /** |
|
232 | - * postalCode |
|
233 | - * The postal code. For example, 94043. |
|
234 | - * |
|
235 | - * @param AddressInterface|null $obj_with_address |
|
236 | - * @return string |
|
237 | - */ |
|
238 | - public static function postalCode(?AddressInterface $obj_with_address = null): string |
|
239 | - { |
|
240 | - $postal_code = $obj_with_address->zip(); |
|
241 | - return ! empty($postal_code) |
|
242 | - ? "<span itemprop='postalCode'>$postal_code</span>" |
|
243 | - : ''; |
|
244 | - } |
|
231 | + /** |
|
232 | + * postalCode |
|
233 | + * The postal code. For example, 94043. |
|
234 | + * |
|
235 | + * @param AddressInterface|null $obj_with_address |
|
236 | + * @return string |
|
237 | + */ |
|
238 | + public static function postalCode(?AddressInterface $obj_with_address = null): string |
|
239 | + { |
|
240 | + $postal_code = $obj_with_address->zip(); |
|
241 | + return ! empty($postal_code) |
|
242 | + ? "<span itemprop='postalCode'>$postal_code</span>" |
|
243 | + : ''; |
|
244 | + } |
|
245 | 245 | |
246 | 246 | |
247 | - /** |
|
248 | - * telephone |
|
249 | - * The telephone number. |
|
250 | - * |
|
251 | - * @param string|null $phone_nmbr |
|
252 | - * @return string |
|
253 | - */ |
|
254 | - public static function telephone(?string $phone_nmbr = ''): string |
|
255 | - { |
|
256 | - return ! empty($phone_nmbr) |
|
257 | - ? "<span itemprop='telephone'>$phone_nmbr</span>" |
|
258 | - : ''; |
|
259 | - } |
|
247 | + /** |
|
248 | + * telephone |
|
249 | + * The telephone number. |
|
250 | + * |
|
251 | + * @param string|null $phone_nmbr |
|
252 | + * @return string |
|
253 | + */ |
|
254 | + public static function telephone(?string $phone_nmbr = ''): string |
|
255 | + { |
|
256 | + return ! empty($phone_nmbr) |
|
257 | + ? "<span itemprop='telephone'>$phone_nmbr</span>" |
|
258 | + : ''; |
|
259 | + } |
|
260 | 260 | |
261 | 261 | |
262 | - /** |
|
263 | - * URL of the item as a clickable link |
|
264 | - * |
|
265 | - * @param string|null $url - the URL that the link will resolve to |
|
266 | - * @param string|null $text - the text that will be used for the visible link |
|
267 | - * @param array $attributes - array of additional link attributes in attribute_name => value pairs. ie: |
|
268 | - * array( |
|
269 | - * 'title' => 'click here', 'class' => 'link-class' ) |
|
270 | - * @return string (link) |
|
271 | - */ |
|
272 | - public static function url(?string $url = '', ?string $text = '', array $attributes = []): string |
|
273 | - { |
|
274 | - // Check the URL includes a scheme |
|
275 | - $parsed_url = parse_url($url); |
|
276 | - if (empty($parsed_url['scheme'])) { |
|
277 | - $url = 'https://' . ltrim($url, '/'); |
|
278 | - } |
|
279 | - $atts = ''; |
|
280 | - foreach ($attributes as $attribute => $value) { |
|
281 | - $atts .= ' ' . $attribute . '="' . $value . '"'; |
|
282 | - } |
|
283 | - $text = $text !== null && $text !== '' |
|
284 | - ? $text |
|
285 | - : esc_url($url); |
|
286 | - return ! empty($url) |
|
287 | - ? '<a itemprop="url" href="' . esc_url_raw($url) . '"' . $atts . '>' . $text . '</a>' |
|
288 | - : ''; |
|
289 | - } |
|
262 | + /** |
|
263 | + * URL of the item as a clickable link |
|
264 | + * |
|
265 | + * @param string|null $url - the URL that the link will resolve to |
|
266 | + * @param string|null $text - the text that will be used for the visible link |
|
267 | + * @param array $attributes - array of additional link attributes in attribute_name => value pairs. ie: |
|
268 | + * array( |
|
269 | + * 'title' => 'click here', 'class' => 'link-class' ) |
|
270 | + * @return string (link) |
|
271 | + */ |
|
272 | + public static function url(?string $url = '', ?string $text = '', array $attributes = []): string |
|
273 | + { |
|
274 | + // Check the URL includes a scheme |
|
275 | + $parsed_url = parse_url($url); |
|
276 | + if (empty($parsed_url['scheme'])) { |
|
277 | + $url = 'https://' . ltrim($url, '/'); |
|
278 | + } |
|
279 | + $atts = ''; |
|
280 | + foreach ($attributes as $attribute => $value) { |
|
281 | + $atts .= ' ' . $attribute . '="' . $value . '"'; |
|
282 | + } |
|
283 | + $text = $text !== null && $text !== '' |
|
284 | + ? $text |
|
285 | + : esc_url($url); |
|
286 | + return ! empty($url) |
|
287 | + ? '<a itemprop="url" href="' . esc_url_raw($url) . '"' . $atts . '>' . $text . '</a>' |
|
288 | + : ''; |
|
289 | + } |
|
290 | 290 | } |
@@ -14,450 +14,450 @@ |
||
14 | 14 | class EEH_Sideloader extends EEH_Base |
15 | 15 | { |
16 | 16 | |
17 | - /** |
|
18 | - * @since 4.10.5.p |
|
19 | - * @var string |
|
20 | - */ |
|
21 | - private string $download_url = ''; |
|
22 | - |
|
23 | - /** |
|
24 | - * @since 4.1.0 |
|
25 | - * @var string |
|
26 | - */ |
|
27 | - private string $upload_path = ''; |
|
28 | - |
|
29 | - /** |
|
30 | - * @since 4.1.0 |
|
31 | - * @var int |
|
32 | - */ |
|
33 | - private int $permissions = 0644; |
|
34 | - |
|
35 | - /** |
|
36 | - * @since 4.1.0 |
|
37 | - * @var string |
|
38 | - */ |
|
39 | - private string $new_file_name = ''; |
|
40 | - |
|
41 | - |
|
42 | - /** |
|
43 | - * constructor allows the user to set the properties on the side loader on construction. |
|
44 | - * However, there are also setters for doing so. |
|
45 | - * |
|
46 | - * @param array $props array fo initializing the side loader if keys match the properties. |
|
47 | - * @since 4.1.0 |
|
48 | - */ |
|
49 | - public function __construct(array $props = []) |
|
50 | - { |
|
51 | - // make sure we include the required wp file for necessary functions |
|
52 | - require_once(ABSPATH . 'wp-admin/includes/file.php'); |
|
53 | - if (! empty($props)) { |
|
54 | - $this->initialize($props); |
|
55 | - } |
|
56 | - } |
|
57 | - |
|
58 | - |
|
59 | - /** |
|
60 | - * sets the properties for class either to defaults or using incoming initialization array |
|
61 | - * |
|
62 | - * @param array $props values passed to setters |
|
63 | - * @return void |
|
64 | - * @since 4.1.0 |
|
65 | - */ |
|
66 | - public function initialize(array $props) |
|
67 | - { |
|
68 | - $props = $this->convertOldProps($props); |
|
69 | - // set defaults |
|
70 | - $props += [ |
|
71 | - 'download_url' => '', |
|
72 | - 'upload_path' => EVENT_ESPRESSO_UPLOAD_DIR, |
|
73 | - 'new_file_name' => 'EE_Sideloader_' . uniqid() . '.default', |
|
74 | - 'permissions' => 0644, |
|
75 | - ]; |
|
76 | - |
|
77 | - $this->setUploadPath($props['upload_path']); |
|
78 | - $this->setDownloadUrl($props['download_url']); |
|
79 | - $this->setPermissions($props['permissions']); |
|
80 | - $this->setNewFileName($props['new_file_name']); |
|
81 | - } |
|
82 | - |
|
83 | - |
|
84 | - private function convertOldProps(array $props): array |
|
85 | - { |
|
86 | - // keys are old property names, values are new property names |
|
87 | - $prop_mapping = [ |
|
88 | - '_upload_to' => 'upload_path', |
|
89 | - '_download_from' => 'download_url', |
|
90 | - '_permissions' => 'permissions', |
|
91 | - '_new_file_name' => 'new_file_name', |
|
92 | - ]; |
|
93 | - foreach ($prop_mapping as $old_key => $new_key) { |
|
94 | - if (isset($props[ $old_key ])) { |
|
95 | - $props[ $new_key ] = $props[ $old_key ]; |
|
96 | - unset($props[ $old_key ]); |
|
97 | - } |
|
98 | - } |
|
99 | - return $props; |
|
100 | - } |
|
101 | - |
|
102 | - |
|
103 | - // utilities |
|
104 | - |
|
105 | - |
|
106 | - /** |
|
107 | - * @return string |
|
108 | - * @since 4.1.0 |
|
109 | - * @depecated 5.0.42 |
|
110 | - */ |
|
111 | - private function getWpUploadsDir(): string |
|
112 | - { |
|
113 | - $uploads = wp_upload_dir(); |
|
114 | - return $uploads['basedir']; |
|
115 | - } |
|
116 | - |
|
117 | - // setters |
|
118 | - |
|
119 | - |
|
120 | - /** |
|
121 | - * sets the _upload_to property to the directory to upload to. |
|
122 | - * |
|
123 | - * @param string $upload_folder |
|
124 | - * @return void |
|
125 | - * @since 4.1.0 |
|
126 | - */ |
|
127 | - public function setUploadPath(string $upload_folder): void |
|
128 | - { |
|
129 | - $this->upload_path = trailingslashit($upload_folder); |
|
130 | - } |
|
131 | - |
|
132 | - |
|
133 | - /** |
|
134 | - * sets the download_url property to the location we should download the file from. |
|
135 | - * |
|
136 | - * @param string $download_url The full path to the file we should side-load. |
|
137 | - * @return void |
|
138 | - * @since 4.10.5.p |
|
139 | - */ |
|
140 | - public function setDownloadUrl(string $download_url): void |
|
141 | - { |
|
142 | - $this->download_url = $download_url; |
|
143 | - } |
|
144 | - |
|
145 | - |
|
146 | - /** |
|
147 | - * sets the _permissions property used on the side-loaded file. |
|
148 | - * |
|
149 | - * @param int|string $permissions |
|
150 | - * @return void |
|
151 | - * @since 4.1.0 |
|
152 | - */ |
|
153 | - public function setPermissions($permissions = 0644): void |
|
154 | - { |
|
155 | - $this->permissions = intval($permissions, 8); |
|
156 | - } |
|
157 | - |
|
158 | - |
|
159 | - /** |
|
160 | - * sets the _new_file_name property used on the side-loaded file. |
|
161 | - * |
|
162 | - * @param string $new_file_name |
|
163 | - * @return void |
|
164 | - * @since 4.1.0 |
|
165 | - */ |
|
166 | - public function setNewFileName(string $new_file_name): void |
|
167 | - { |
|
168 | - $this->new_file_name = $new_file_name; |
|
169 | - } |
|
170 | - |
|
171 | - // getters |
|
172 | - |
|
173 | - |
|
174 | - /** |
|
175 | - * @return string |
|
176 | - * @since 4.1.0 |
|
177 | - */ |
|
178 | - public function uploadPath(): string |
|
179 | - { |
|
180 | - return $this->upload_path; |
|
181 | - } |
|
182 | - |
|
183 | - |
|
184 | - /** |
|
185 | - * @return string |
|
186 | - * @since 4.10.5.p |
|
187 | - */ |
|
188 | - public function downloadUrl(): string |
|
189 | - { |
|
190 | - return $this->download_url; |
|
191 | - } |
|
192 | - |
|
193 | - |
|
194 | - /** |
|
195 | - * @return int |
|
196 | - * @since 4.1.0 |
|
197 | - */ |
|
198 | - public function permissions(): int |
|
199 | - { |
|
200 | - return $this->permissions; |
|
201 | - } |
|
202 | - |
|
203 | - |
|
204 | - /** |
|
205 | - * @return string |
|
206 | - * @since 4.1.0 |
|
207 | - */ |
|
208 | - public function newFileName(): string |
|
209 | - { |
|
210 | - return $this->new_file_name; |
|
211 | - } |
|
212 | - |
|
213 | - |
|
214 | - // upload methods |
|
215 | - |
|
216 | - |
|
217 | - /** |
|
218 | - * Downloads the file using the WordPress HTTP API. |
|
219 | - * |
|
220 | - * @return bool |
|
221 | - * @since 4.1.0 |
|
222 | - */ |
|
223 | - public function sideload(): bool |
|
224 | - { |
|
225 | - try { |
|
226 | - // setup temp dir |
|
227 | - $temp_file = wp_tempnam($this->download_url); |
|
228 | - |
|
229 | - if (! $temp_file) { |
|
230 | - throw new RuntimeException( |
|
231 | - esc_html__( |
|
232 | - 'Something went wrong with the upload. Unable to create a tmp file for the uploaded file on the server', |
|
233 | - 'event_espresso' |
|
234 | - ) |
|
235 | - ); |
|
236 | - } |
|
237 | - |
|
238 | - do_action('AHEE__EEH_Sideloader__sideload__before', $this, $temp_file); |
|
239 | - |
|
240 | - $wp_remote_args = apply_filters( |
|
241 | - 'FHEE__EEH_Sideloader__sideload__wp_remote_args', |
|
242 | - ['timeout' => 500, 'stream' => true, 'filename' => $temp_file], |
|
243 | - $this, |
|
244 | - $temp_file |
|
245 | - ); |
|
246 | - |
|
247 | - $response = wp_safe_remote_get($this->download_url, $wp_remote_args); |
|
248 | - |
|
249 | - if ($this->isResponseError($response) || $this->isDownloadError($response)) { |
|
250 | - EEH_File::delete($temp_file); |
|
251 | - return false; |
|
252 | - } |
|
253 | - |
|
254 | - // possible md5 check |
|
255 | - $content_md5 = wp_remote_retrieve_header($response, 'content-md5'); |
|
256 | - if ($content_md5) { |
|
257 | - $md5_check = verify_file_md5($temp_file, $content_md5); |
|
258 | - if ($this->isResponseError($md5_check)) { |
|
259 | - EEH_File::delete($temp_file); |
|
260 | - return false; |
|
261 | - } |
|
262 | - } |
|
263 | - |
|
264 | - // now we have the file, let's get it in the right directory with the right name. |
|
265 | - $path = apply_filters( |
|
266 | - 'FHEE__EEH_Sideloader__sideload__new_path', |
|
267 | - $this->upload_path . $this->new_file_name, |
|
268 | - $this |
|
269 | - ); |
|
270 | - if (! EEH_File::move($temp_file, $path, true)) { |
|
271 | - return false; |
|
272 | - } |
|
273 | - |
|
274 | - // set permissions |
|
275 | - $permissions = apply_filters( |
|
276 | - 'FHEE__EEH_Sideloader__sideload__permissions_applied', |
|
277 | - $this->permissions, |
|
278 | - $this |
|
279 | - ); |
|
280 | - $permissions = intval($permissions, 8); |
|
281 | - // verify permissions are an integer but don't actually modify the value |
|
282 | - if (! absint($permissions)) { |
|
283 | - EE_Error::add_error( |
|
284 | - esc_html__('Supplied permissions are invalid', 'event_espresso'), |
|
285 | - __FILE__, |
|
286 | - __FUNCTION__, |
|
287 | - __LINE__ |
|
288 | - ); |
|
289 | - return false; |
|
290 | - } |
|
291 | - EEH_File::chmod($path, $permissions); |
|
292 | - |
|
293 | - // that's it. let's allow for actions after file uploaded. |
|
294 | - do_action('AHEE__EE_Sideloader__sideload_after', $this, $path); |
|
295 | - return true; |
|
296 | - } catch (Exception $exception) { |
|
297 | - EE_Error::add_error($exception->getMessage(), __FILE__, __FUNCTION__, __LINE__); |
|
298 | - return false; |
|
299 | - } |
|
300 | - } |
|
301 | - |
|
302 | - |
|
303 | - /** |
|
304 | - * returns TRUE if there IS an error, FALSE if there is NO ERROR |
|
305 | - * |
|
306 | - * @param array|WP_Error $response |
|
307 | - * @return bool |
|
308 | - * @throws RuntimeException |
|
309 | - */ |
|
310 | - private function isResponseError($response): bool |
|
311 | - { |
|
312 | - if (! is_wp_error($response)) { |
|
313 | - return false; |
|
314 | - } |
|
315 | - if (defined('WP_DEBUG') && WP_DEBUG) { |
|
316 | - EE_Error::add_error( |
|
317 | - sprintf( |
|
318 | - esc_html__( |
|
319 | - 'The following error occurred while attempting to download the file from "%1$s":', |
|
320 | - 'event_espresso' |
|
321 | - ), |
|
322 | - $this->download_url, |
|
323 | - $response->get_error_message() |
|
324 | - ), |
|
325 | - __FILE__, |
|
326 | - __FUNCTION__, |
|
327 | - __LINE__ |
|
328 | - ); |
|
329 | - } |
|
330 | - return true; |
|
331 | - } |
|
332 | - |
|
333 | - |
|
334 | - /** |
|
335 | - * returns TRUE if there IS an error, FALSE if there is NO ERROR |
|
336 | - * |
|
337 | - * @param array $response |
|
338 | - * @return bool |
|
339 | - * @throws RuntimeException |
|
340 | - */ |
|
341 | - private function isDownloadError(array $response): bool |
|
342 | - { |
|
343 | - $response_code = wp_remote_retrieve_response_code($response); |
|
344 | - if ($response_code === 200) { |
|
345 | - return false; |
|
346 | - } |
|
347 | - if (defined('WP_DEBUG') && WP_DEBUG && ! defined('EE_TESTS_DIR')) { |
|
348 | - if ($response_code === 404) { |
|
349 | - EE_Error::add_attention( |
|
350 | - sprintf( |
|
351 | - esc_html__( |
|
352 | - 'Attempted to download a file from "%1$s" but encountered a "404 File Not Found" error.', |
|
353 | - 'event_espresso' |
|
354 | - ), |
|
355 | - $this->download_url |
|
356 | - ), |
|
357 | - __FILE__, |
|
358 | - __FUNCTION__, |
|
359 | - __LINE__ |
|
360 | - ); |
|
361 | - } else { |
|
362 | - EE_Error::add_error( |
|
363 | - sprintf( |
|
364 | - esc_html__( |
|
365 | - 'Unable to download the file. Either the path given is incorrect, or something else happened. Here is the path given: %s', |
|
366 | - 'event_espresso' |
|
367 | - ), |
|
368 | - $this->download_url |
|
369 | - ), |
|
370 | - __FILE__, |
|
371 | - __FUNCTION__, |
|
372 | - __LINE__ |
|
373 | - ); |
|
374 | - } |
|
375 | - } |
|
376 | - return true; |
|
377 | - } |
|
378 | - |
|
379 | - |
|
380 | - /** |
|
381 | - * @depecated 5.0.42 |
|
382 | - * @return string |
|
383 | - */ |
|
384 | - public function get_download_from(): string |
|
385 | - { |
|
386 | - return $this->downloadUrl(); |
|
387 | - } |
|
388 | - |
|
389 | - |
|
390 | - /** |
|
391 | - * |
|
392 | - * @param string $download_url The full path to the file we should side-load. |
|
393 | - * @return void |
|
394 | - * @depecated 5.0.42 |
|
395 | - */ |
|
396 | - public function set_download_from(string $download_url): void |
|
397 | - { |
|
398 | - $this->setDownloadUrl($download_url); |
|
399 | - } |
|
400 | - |
|
401 | - |
|
402 | - /** |
|
403 | - * @return string |
|
404 | - * @depecated 5.0.42 |
|
405 | - */ |
|
406 | - public function get_upload_to(): string |
|
407 | - { |
|
408 | - return $this->uploadPath(); |
|
409 | - } |
|
410 | - |
|
411 | - |
|
412 | - /** |
|
413 | - * @param string $upload_folder |
|
414 | - * @return void |
|
415 | - * @depecated 5.0.42 |
|
416 | - */ |
|
417 | - public function set_upload_to(string $upload_folder): void |
|
418 | - { |
|
419 | - $this->setUploadPath($upload_folder); |
|
420 | - } |
|
421 | - |
|
422 | - |
|
423 | - /** |
|
424 | - * @return int |
|
425 | - * @depecated 5.0.42 |
|
426 | - */ |
|
427 | - public function get_permissions(): int |
|
428 | - { |
|
429 | - return $this->permissions(); |
|
430 | - } |
|
431 | - |
|
432 | - |
|
433 | - /** |
|
434 | - * @param int|string $permissions |
|
435 | - * @return void |
|
436 | - * @depecated 5.0.42 |
|
437 | - */ |
|
438 | - public function set_permissions($permissions): void |
|
439 | - { |
|
440 | - $this->setPermissions($permissions); |
|
441 | - } |
|
442 | - |
|
443 | - |
|
444 | - /** |
|
445 | - * @return string |
|
446 | - * @depecated 5.0.42 |
|
447 | - */ |
|
448 | - public function get_new_file_name(): string |
|
449 | - { |
|
450 | - return $this->newFileName(); |
|
451 | - } |
|
452 | - |
|
453 | - |
|
454 | - /** |
|
455 | - * @param string $new_file_name |
|
456 | - * @return void |
|
457 | - * @depecated 5.0.42 |
|
458 | - */ |
|
459 | - public function set_new_file_name(string $new_file_name): void |
|
460 | - { |
|
461 | - $this->setNewFileName($new_file_name); |
|
462 | - } |
|
17 | + /** |
|
18 | + * @since 4.10.5.p |
|
19 | + * @var string |
|
20 | + */ |
|
21 | + private string $download_url = ''; |
|
22 | + |
|
23 | + /** |
|
24 | + * @since 4.1.0 |
|
25 | + * @var string |
|
26 | + */ |
|
27 | + private string $upload_path = ''; |
|
28 | + |
|
29 | + /** |
|
30 | + * @since 4.1.0 |
|
31 | + * @var int |
|
32 | + */ |
|
33 | + private int $permissions = 0644; |
|
34 | + |
|
35 | + /** |
|
36 | + * @since 4.1.0 |
|
37 | + * @var string |
|
38 | + */ |
|
39 | + private string $new_file_name = ''; |
|
40 | + |
|
41 | + |
|
42 | + /** |
|
43 | + * constructor allows the user to set the properties on the side loader on construction. |
|
44 | + * However, there are also setters for doing so. |
|
45 | + * |
|
46 | + * @param array $props array fo initializing the side loader if keys match the properties. |
|
47 | + * @since 4.1.0 |
|
48 | + */ |
|
49 | + public function __construct(array $props = []) |
|
50 | + { |
|
51 | + // make sure we include the required wp file for necessary functions |
|
52 | + require_once(ABSPATH . 'wp-admin/includes/file.php'); |
|
53 | + if (! empty($props)) { |
|
54 | + $this->initialize($props); |
|
55 | + } |
|
56 | + } |
|
57 | + |
|
58 | + |
|
59 | + /** |
|
60 | + * sets the properties for class either to defaults or using incoming initialization array |
|
61 | + * |
|
62 | + * @param array $props values passed to setters |
|
63 | + * @return void |
|
64 | + * @since 4.1.0 |
|
65 | + */ |
|
66 | + public function initialize(array $props) |
|
67 | + { |
|
68 | + $props = $this->convertOldProps($props); |
|
69 | + // set defaults |
|
70 | + $props += [ |
|
71 | + 'download_url' => '', |
|
72 | + 'upload_path' => EVENT_ESPRESSO_UPLOAD_DIR, |
|
73 | + 'new_file_name' => 'EE_Sideloader_' . uniqid() . '.default', |
|
74 | + 'permissions' => 0644, |
|
75 | + ]; |
|
76 | + |
|
77 | + $this->setUploadPath($props['upload_path']); |
|
78 | + $this->setDownloadUrl($props['download_url']); |
|
79 | + $this->setPermissions($props['permissions']); |
|
80 | + $this->setNewFileName($props['new_file_name']); |
|
81 | + } |
|
82 | + |
|
83 | + |
|
84 | + private function convertOldProps(array $props): array |
|
85 | + { |
|
86 | + // keys are old property names, values are new property names |
|
87 | + $prop_mapping = [ |
|
88 | + '_upload_to' => 'upload_path', |
|
89 | + '_download_from' => 'download_url', |
|
90 | + '_permissions' => 'permissions', |
|
91 | + '_new_file_name' => 'new_file_name', |
|
92 | + ]; |
|
93 | + foreach ($prop_mapping as $old_key => $new_key) { |
|
94 | + if (isset($props[ $old_key ])) { |
|
95 | + $props[ $new_key ] = $props[ $old_key ]; |
|
96 | + unset($props[ $old_key ]); |
|
97 | + } |
|
98 | + } |
|
99 | + return $props; |
|
100 | + } |
|
101 | + |
|
102 | + |
|
103 | + // utilities |
|
104 | + |
|
105 | + |
|
106 | + /** |
|
107 | + * @return string |
|
108 | + * @since 4.1.0 |
|
109 | + * @depecated 5.0.42 |
|
110 | + */ |
|
111 | + private function getWpUploadsDir(): string |
|
112 | + { |
|
113 | + $uploads = wp_upload_dir(); |
|
114 | + return $uploads['basedir']; |
|
115 | + } |
|
116 | + |
|
117 | + // setters |
|
118 | + |
|
119 | + |
|
120 | + /** |
|
121 | + * sets the _upload_to property to the directory to upload to. |
|
122 | + * |
|
123 | + * @param string $upload_folder |
|
124 | + * @return void |
|
125 | + * @since 4.1.0 |
|
126 | + */ |
|
127 | + public function setUploadPath(string $upload_folder): void |
|
128 | + { |
|
129 | + $this->upload_path = trailingslashit($upload_folder); |
|
130 | + } |
|
131 | + |
|
132 | + |
|
133 | + /** |
|
134 | + * sets the download_url property to the location we should download the file from. |
|
135 | + * |
|
136 | + * @param string $download_url The full path to the file we should side-load. |
|
137 | + * @return void |
|
138 | + * @since 4.10.5.p |
|
139 | + */ |
|
140 | + public function setDownloadUrl(string $download_url): void |
|
141 | + { |
|
142 | + $this->download_url = $download_url; |
|
143 | + } |
|
144 | + |
|
145 | + |
|
146 | + /** |
|
147 | + * sets the _permissions property used on the side-loaded file. |
|
148 | + * |
|
149 | + * @param int|string $permissions |
|
150 | + * @return void |
|
151 | + * @since 4.1.0 |
|
152 | + */ |
|
153 | + public function setPermissions($permissions = 0644): void |
|
154 | + { |
|
155 | + $this->permissions = intval($permissions, 8); |
|
156 | + } |
|
157 | + |
|
158 | + |
|
159 | + /** |
|
160 | + * sets the _new_file_name property used on the side-loaded file. |
|
161 | + * |
|
162 | + * @param string $new_file_name |
|
163 | + * @return void |
|
164 | + * @since 4.1.0 |
|
165 | + */ |
|
166 | + public function setNewFileName(string $new_file_name): void |
|
167 | + { |
|
168 | + $this->new_file_name = $new_file_name; |
|
169 | + } |
|
170 | + |
|
171 | + // getters |
|
172 | + |
|
173 | + |
|
174 | + /** |
|
175 | + * @return string |
|
176 | + * @since 4.1.0 |
|
177 | + */ |
|
178 | + public function uploadPath(): string |
|
179 | + { |
|
180 | + return $this->upload_path; |
|
181 | + } |
|
182 | + |
|
183 | + |
|
184 | + /** |
|
185 | + * @return string |
|
186 | + * @since 4.10.5.p |
|
187 | + */ |
|
188 | + public function downloadUrl(): string |
|
189 | + { |
|
190 | + return $this->download_url; |
|
191 | + } |
|
192 | + |
|
193 | + |
|
194 | + /** |
|
195 | + * @return int |
|
196 | + * @since 4.1.0 |
|
197 | + */ |
|
198 | + public function permissions(): int |
|
199 | + { |
|
200 | + return $this->permissions; |
|
201 | + } |
|
202 | + |
|
203 | + |
|
204 | + /** |
|
205 | + * @return string |
|
206 | + * @since 4.1.0 |
|
207 | + */ |
|
208 | + public function newFileName(): string |
|
209 | + { |
|
210 | + return $this->new_file_name; |
|
211 | + } |
|
212 | + |
|
213 | + |
|
214 | + // upload methods |
|
215 | + |
|
216 | + |
|
217 | + /** |
|
218 | + * Downloads the file using the WordPress HTTP API. |
|
219 | + * |
|
220 | + * @return bool |
|
221 | + * @since 4.1.0 |
|
222 | + */ |
|
223 | + public function sideload(): bool |
|
224 | + { |
|
225 | + try { |
|
226 | + // setup temp dir |
|
227 | + $temp_file = wp_tempnam($this->download_url); |
|
228 | + |
|
229 | + if (! $temp_file) { |
|
230 | + throw new RuntimeException( |
|
231 | + esc_html__( |
|
232 | + 'Something went wrong with the upload. Unable to create a tmp file for the uploaded file on the server', |
|
233 | + 'event_espresso' |
|
234 | + ) |
|
235 | + ); |
|
236 | + } |
|
237 | + |
|
238 | + do_action('AHEE__EEH_Sideloader__sideload__before', $this, $temp_file); |
|
239 | + |
|
240 | + $wp_remote_args = apply_filters( |
|
241 | + 'FHEE__EEH_Sideloader__sideload__wp_remote_args', |
|
242 | + ['timeout' => 500, 'stream' => true, 'filename' => $temp_file], |
|
243 | + $this, |
|
244 | + $temp_file |
|
245 | + ); |
|
246 | + |
|
247 | + $response = wp_safe_remote_get($this->download_url, $wp_remote_args); |
|
248 | + |
|
249 | + if ($this->isResponseError($response) || $this->isDownloadError($response)) { |
|
250 | + EEH_File::delete($temp_file); |
|
251 | + return false; |
|
252 | + } |
|
253 | + |
|
254 | + // possible md5 check |
|
255 | + $content_md5 = wp_remote_retrieve_header($response, 'content-md5'); |
|
256 | + if ($content_md5) { |
|
257 | + $md5_check = verify_file_md5($temp_file, $content_md5); |
|
258 | + if ($this->isResponseError($md5_check)) { |
|
259 | + EEH_File::delete($temp_file); |
|
260 | + return false; |
|
261 | + } |
|
262 | + } |
|
263 | + |
|
264 | + // now we have the file, let's get it in the right directory with the right name. |
|
265 | + $path = apply_filters( |
|
266 | + 'FHEE__EEH_Sideloader__sideload__new_path', |
|
267 | + $this->upload_path . $this->new_file_name, |
|
268 | + $this |
|
269 | + ); |
|
270 | + if (! EEH_File::move($temp_file, $path, true)) { |
|
271 | + return false; |
|
272 | + } |
|
273 | + |
|
274 | + // set permissions |
|
275 | + $permissions = apply_filters( |
|
276 | + 'FHEE__EEH_Sideloader__sideload__permissions_applied', |
|
277 | + $this->permissions, |
|
278 | + $this |
|
279 | + ); |
|
280 | + $permissions = intval($permissions, 8); |
|
281 | + // verify permissions are an integer but don't actually modify the value |
|
282 | + if (! absint($permissions)) { |
|
283 | + EE_Error::add_error( |
|
284 | + esc_html__('Supplied permissions are invalid', 'event_espresso'), |
|
285 | + __FILE__, |
|
286 | + __FUNCTION__, |
|
287 | + __LINE__ |
|
288 | + ); |
|
289 | + return false; |
|
290 | + } |
|
291 | + EEH_File::chmod($path, $permissions); |
|
292 | + |
|
293 | + // that's it. let's allow for actions after file uploaded. |
|
294 | + do_action('AHEE__EE_Sideloader__sideload_after', $this, $path); |
|
295 | + return true; |
|
296 | + } catch (Exception $exception) { |
|
297 | + EE_Error::add_error($exception->getMessage(), __FILE__, __FUNCTION__, __LINE__); |
|
298 | + return false; |
|
299 | + } |
|
300 | + } |
|
301 | + |
|
302 | + |
|
303 | + /** |
|
304 | + * returns TRUE if there IS an error, FALSE if there is NO ERROR |
|
305 | + * |
|
306 | + * @param array|WP_Error $response |
|
307 | + * @return bool |
|
308 | + * @throws RuntimeException |
|
309 | + */ |
|
310 | + private function isResponseError($response): bool |
|
311 | + { |
|
312 | + if (! is_wp_error($response)) { |
|
313 | + return false; |
|
314 | + } |
|
315 | + if (defined('WP_DEBUG') && WP_DEBUG) { |
|
316 | + EE_Error::add_error( |
|
317 | + sprintf( |
|
318 | + esc_html__( |
|
319 | + 'The following error occurred while attempting to download the file from "%1$s":', |
|
320 | + 'event_espresso' |
|
321 | + ), |
|
322 | + $this->download_url, |
|
323 | + $response->get_error_message() |
|
324 | + ), |
|
325 | + __FILE__, |
|
326 | + __FUNCTION__, |
|
327 | + __LINE__ |
|
328 | + ); |
|
329 | + } |
|
330 | + return true; |
|
331 | + } |
|
332 | + |
|
333 | + |
|
334 | + /** |
|
335 | + * returns TRUE if there IS an error, FALSE if there is NO ERROR |
|
336 | + * |
|
337 | + * @param array $response |
|
338 | + * @return bool |
|
339 | + * @throws RuntimeException |
|
340 | + */ |
|
341 | + private function isDownloadError(array $response): bool |
|
342 | + { |
|
343 | + $response_code = wp_remote_retrieve_response_code($response); |
|
344 | + if ($response_code === 200) { |
|
345 | + return false; |
|
346 | + } |
|
347 | + if (defined('WP_DEBUG') && WP_DEBUG && ! defined('EE_TESTS_DIR')) { |
|
348 | + if ($response_code === 404) { |
|
349 | + EE_Error::add_attention( |
|
350 | + sprintf( |
|
351 | + esc_html__( |
|
352 | + 'Attempted to download a file from "%1$s" but encountered a "404 File Not Found" error.', |
|
353 | + 'event_espresso' |
|
354 | + ), |
|
355 | + $this->download_url |
|
356 | + ), |
|
357 | + __FILE__, |
|
358 | + __FUNCTION__, |
|
359 | + __LINE__ |
|
360 | + ); |
|
361 | + } else { |
|
362 | + EE_Error::add_error( |
|
363 | + sprintf( |
|
364 | + esc_html__( |
|
365 | + 'Unable to download the file. Either the path given is incorrect, or something else happened. Here is the path given: %s', |
|
366 | + 'event_espresso' |
|
367 | + ), |
|
368 | + $this->download_url |
|
369 | + ), |
|
370 | + __FILE__, |
|
371 | + __FUNCTION__, |
|
372 | + __LINE__ |
|
373 | + ); |
|
374 | + } |
|
375 | + } |
|
376 | + return true; |
|
377 | + } |
|
378 | + |
|
379 | + |
|
380 | + /** |
|
381 | + * @depecated 5.0.42 |
|
382 | + * @return string |
|
383 | + */ |
|
384 | + public function get_download_from(): string |
|
385 | + { |
|
386 | + return $this->downloadUrl(); |
|
387 | + } |
|
388 | + |
|
389 | + |
|
390 | + /** |
|
391 | + * |
|
392 | + * @param string $download_url The full path to the file we should side-load. |
|
393 | + * @return void |
|
394 | + * @depecated 5.0.42 |
|
395 | + */ |
|
396 | + public function set_download_from(string $download_url): void |
|
397 | + { |
|
398 | + $this->setDownloadUrl($download_url); |
|
399 | + } |
|
400 | + |
|
401 | + |
|
402 | + /** |
|
403 | + * @return string |
|
404 | + * @depecated 5.0.42 |
|
405 | + */ |
|
406 | + public function get_upload_to(): string |
|
407 | + { |
|
408 | + return $this->uploadPath(); |
|
409 | + } |
|
410 | + |
|
411 | + |
|
412 | + /** |
|
413 | + * @param string $upload_folder |
|
414 | + * @return void |
|
415 | + * @depecated 5.0.42 |
|
416 | + */ |
|
417 | + public function set_upload_to(string $upload_folder): void |
|
418 | + { |
|
419 | + $this->setUploadPath($upload_folder); |
|
420 | + } |
|
421 | + |
|
422 | + |
|
423 | + /** |
|
424 | + * @return int |
|
425 | + * @depecated 5.0.42 |
|
426 | + */ |
|
427 | + public function get_permissions(): int |
|
428 | + { |
|
429 | + return $this->permissions(); |
|
430 | + } |
|
431 | + |
|
432 | + |
|
433 | + /** |
|
434 | + * @param int|string $permissions |
|
435 | + * @return void |
|
436 | + * @depecated 5.0.42 |
|
437 | + */ |
|
438 | + public function set_permissions($permissions): void |
|
439 | + { |
|
440 | + $this->setPermissions($permissions); |
|
441 | + } |
|
442 | + |
|
443 | + |
|
444 | + /** |
|
445 | + * @return string |
|
446 | + * @depecated 5.0.42 |
|
447 | + */ |
|
448 | + public function get_new_file_name(): string |
|
449 | + { |
|
450 | + return $this->newFileName(); |
|
451 | + } |
|
452 | + |
|
453 | + |
|
454 | + /** |
|
455 | + * @param string $new_file_name |
|
456 | + * @return void |
|
457 | + * @depecated 5.0.42 |
|
458 | + */ |
|
459 | + public function set_new_file_name(string $new_file_name): void |
|
460 | + { |
|
461 | + $this->setNewFileName($new_file_name); |
|
462 | + } |
|
463 | 463 | } |
@@ -49,8 +49,8 @@ discard block |
||
49 | 49 | public function __construct(array $props = []) |
50 | 50 | { |
51 | 51 | // make sure we include the required wp file for necessary functions |
52 | - require_once(ABSPATH . 'wp-admin/includes/file.php'); |
|
53 | - if (! empty($props)) { |
|
52 | + require_once(ABSPATH.'wp-admin/includes/file.php'); |
|
53 | + if ( ! empty($props)) { |
|
54 | 54 | $this->initialize($props); |
55 | 55 | } |
56 | 56 | } |
@@ -70,7 +70,7 @@ discard block |
||
70 | 70 | $props += [ |
71 | 71 | 'download_url' => '', |
72 | 72 | 'upload_path' => EVENT_ESPRESSO_UPLOAD_DIR, |
73 | - 'new_file_name' => 'EE_Sideloader_' . uniqid() . '.default', |
|
73 | + 'new_file_name' => 'EE_Sideloader_'.uniqid().'.default', |
|
74 | 74 | 'permissions' => 0644, |
75 | 75 | ]; |
76 | 76 | |
@@ -91,9 +91,9 @@ discard block |
||
91 | 91 | '_new_file_name' => 'new_file_name', |
92 | 92 | ]; |
93 | 93 | foreach ($prop_mapping as $old_key => $new_key) { |
94 | - if (isset($props[ $old_key ])) { |
|
95 | - $props[ $new_key ] = $props[ $old_key ]; |
|
96 | - unset($props[ $old_key ]); |
|
94 | + if (isset($props[$old_key])) { |
|
95 | + $props[$new_key] = $props[$old_key]; |
|
96 | + unset($props[$old_key]); |
|
97 | 97 | } |
98 | 98 | } |
99 | 99 | return $props; |
@@ -226,7 +226,7 @@ discard block |
||
226 | 226 | // setup temp dir |
227 | 227 | $temp_file = wp_tempnam($this->download_url); |
228 | 228 | |
229 | - if (! $temp_file) { |
|
229 | + if ( ! $temp_file) { |
|
230 | 230 | throw new RuntimeException( |
231 | 231 | esc_html__( |
232 | 232 | 'Something went wrong with the upload. Unable to create a tmp file for the uploaded file on the server', |
@@ -264,10 +264,10 @@ discard block |
||
264 | 264 | // now we have the file, let's get it in the right directory with the right name. |
265 | 265 | $path = apply_filters( |
266 | 266 | 'FHEE__EEH_Sideloader__sideload__new_path', |
267 | - $this->upload_path . $this->new_file_name, |
|
267 | + $this->upload_path.$this->new_file_name, |
|
268 | 268 | $this |
269 | 269 | ); |
270 | - if (! EEH_File::move($temp_file, $path, true)) { |
|
270 | + if ( ! EEH_File::move($temp_file, $path, true)) { |
|
271 | 271 | return false; |
272 | 272 | } |
273 | 273 | |
@@ -279,7 +279,7 @@ discard block |
||
279 | 279 | ); |
280 | 280 | $permissions = intval($permissions, 8); |
281 | 281 | // verify permissions are an integer but don't actually modify the value |
282 | - if (! absint($permissions)) { |
|
282 | + if ( ! absint($permissions)) { |
|
283 | 283 | EE_Error::add_error( |
284 | 284 | esc_html__('Supplied permissions are invalid', 'event_espresso'), |
285 | 285 | __FILE__, |
@@ -309,7 +309,7 @@ discard block |
||
309 | 309 | */ |
310 | 310 | private function isResponseError($response): bool |
311 | 311 | { |
312 | - if (! is_wp_error($response)) { |
|
312 | + if ( ! is_wp_error($response)) { |
|
313 | 313 | return false; |
314 | 314 | } |
315 | 315 | if (defined('WP_DEBUG') && WP_DEBUG) { |