@@ -17,231 +17,231 @@ |
||
| 17 | 17 | abstract class DomainBase implements DomainInterface |
| 18 | 18 | { |
| 19 | 19 | |
| 20 | - const ASSETS_FOLDER = 'assets/'; |
|
| 21 | - |
|
| 22 | - /** |
|
| 23 | - * Equivalent to `__FILE__` for main plugin file. |
|
| 24 | - * |
|
| 25 | - * @var FilePath |
|
| 26 | - */ |
|
| 27 | - private $plugin_file; |
|
| 28 | - |
|
| 29 | - /** |
|
| 30 | - * String indicating version for plugin |
|
| 31 | - * |
|
| 32 | - * @var string |
|
| 33 | - */ |
|
| 34 | - private $version; |
|
| 35 | - |
|
| 36 | - /** |
|
| 37 | - * @var string $plugin_basename |
|
| 38 | - */ |
|
| 39 | - private $plugin_basename; |
|
| 40 | - |
|
| 41 | - /** |
|
| 42 | - * @var string $plugin_path |
|
| 43 | - */ |
|
| 44 | - private $plugin_path; |
|
| 45 | - |
|
| 46 | - /** |
|
| 47 | - * @var string $plugin_url |
|
| 48 | - */ |
|
| 49 | - private $plugin_url; |
|
| 50 | - |
|
| 51 | - /** |
|
| 52 | - * @var string $asset_namespace |
|
| 53 | - */ |
|
| 54 | - private $asset_namespace; |
|
| 55 | - |
|
| 56 | - /** |
|
| 57 | - * @var string $assets_path |
|
| 58 | - */ |
|
| 59 | - private $assets_path; |
|
| 60 | - |
|
| 61 | - /** |
|
| 62 | - * @var bool |
|
| 63 | - */ |
|
| 64 | - protected $initialized = false; |
|
| 65 | - |
|
| 66 | - |
|
| 67 | - /** |
|
| 68 | - * Initializes internal properties. |
|
| 69 | - * |
|
| 70 | - * @param FilePath $plugin_file |
|
| 71 | - * @param Version $version |
|
| 72 | - * @param string $asset_namespace |
|
| 73 | - */ |
|
| 74 | - public function __construct( |
|
| 75 | - FilePath $plugin_file, |
|
| 76 | - Version $version, |
|
| 77 | - string $asset_namespace = Domain::ASSET_NAMESPACE |
|
| 78 | - ) { |
|
| 79 | - $this->plugin_file = $plugin_file; |
|
| 80 | - $this->version = $version; |
|
| 81 | - $this->initialize($asset_namespace); |
|
| 82 | - } |
|
| 83 | - |
|
| 84 | - |
|
| 85 | - /** |
|
| 86 | - * @param string $asset_namespace |
|
| 87 | - * @return void |
|
| 88 | - * @since $VID:$ |
|
| 89 | - */ |
|
| 90 | - public function initialize($asset_namespace = Domain::ASSET_NAMESPACE) |
|
| 91 | - { |
|
| 92 | - if (! $this->initialized) { |
|
| 93 | - $this->plugin_basename = plugin_basename($this->pluginFile()); |
|
| 94 | - $this->plugin_path = plugin_dir_path($this->pluginFile()); |
|
| 95 | - $this->plugin_url = plugin_dir_url($this->pluginFile()); |
|
| 96 | - $this->setAssetNamespace($asset_namespace); |
|
| 97 | - $this->setDistributionAssetsPath(); |
|
| 98 | - $this->initialized = true; |
|
| 99 | - } |
|
| 100 | - } |
|
| 101 | - |
|
| 102 | - |
|
| 103 | - /** |
|
| 104 | - * @param string $asset_namespace |
|
| 105 | - * @return void |
|
| 106 | - */ |
|
| 107 | - public function setAssetNamespace($asset_namespace = Domain::ASSET_NAMESPACE) |
|
| 108 | - { |
|
| 109 | - if (! $this->asset_namespace) { |
|
| 110 | - $this->asset_namespace = sanitize_key( |
|
| 111 | - // convert directory separators to dashes and remove file extension |
|
| 112 | - str_replace(['/', '.php'], ['-', ''], $asset_namespace) |
|
| 113 | - ); |
|
| 114 | - } |
|
| 115 | - } |
|
| 116 | - |
|
| 117 | - |
|
| 118 | - /** |
|
| 119 | - * @throws DomainException |
|
| 120 | - * @since $VID:$ |
|
| 121 | - */ |
|
| 122 | - private function setDistributionAssetsPath() |
|
| 123 | - { |
|
| 124 | - $assets_folder_paths = [ |
|
| 125 | - $this->plugin_path . DomainBase::ASSETS_FOLDER, |
|
| 126 | - $this->plugin_path . 'src/' . DomainBase::ASSETS_FOLDER, |
|
| 127 | - ]; |
|
| 128 | - foreach ($assets_folder_paths as $assets_folder_path) { |
|
| 129 | - if (is_readable($assets_folder_path)) { |
|
| 130 | - $this->assets_path = trailingslashit($assets_folder_path); |
|
| 131 | - // once we find a valid path, just break out of loop |
|
| 132 | - break; |
|
| 133 | - } |
|
| 134 | - } |
|
| 135 | - } |
|
| 136 | - |
|
| 137 | - |
|
| 138 | - /** |
|
| 139 | - * @return string |
|
| 140 | - */ |
|
| 141 | - public function pluginFile(): string |
|
| 142 | - { |
|
| 143 | - return (string) $this->plugin_file; |
|
| 144 | - } |
|
| 145 | - |
|
| 146 | - |
|
| 147 | - /** |
|
| 148 | - * @return FilePath |
|
| 149 | - */ |
|
| 150 | - public function pluginFileObject(): FilePath |
|
| 151 | - { |
|
| 152 | - return $this->plugin_file; |
|
| 153 | - } |
|
| 154 | - |
|
| 155 | - |
|
| 156 | - /** |
|
| 157 | - * @return string |
|
| 158 | - */ |
|
| 159 | - public function pluginBasename(): string |
|
| 160 | - { |
|
| 161 | - return $this->plugin_basename; |
|
| 162 | - } |
|
| 163 | - |
|
| 164 | - |
|
| 165 | - /** |
|
| 166 | - * @param string $additional_path |
|
| 167 | - * @return string |
|
| 168 | - */ |
|
| 169 | - public function pluginPath($additional_path = ''): string |
|
| 170 | - { |
|
| 171 | - return is_string($additional_path) && $additional_path !== '' |
|
| 172 | - ? $this->plugin_path . $additional_path |
|
| 173 | - : $this->plugin_path; |
|
| 174 | - } |
|
| 175 | - |
|
| 176 | - |
|
| 177 | - /** |
|
| 178 | - * @param string $additional_path |
|
| 179 | - * @return string |
|
| 180 | - */ |
|
| 181 | - public function pluginUrl($additional_path = ''): string |
|
| 182 | - { |
|
| 183 | - return is_string($additional_path) && $additional_path !== '' |
|
| 184 | - ? $this->plugin_url . $additional_path |
|
| 185 | - : $this->plugin_url; |
|
| 186 | - } |
|
| 187 | - |
|
| 188 | - |
|
| 189 | - /** |
|
| 190 | - * @return string |
|
| 191 | - */ |
|
| 192 | - public function version(): string |
|
| 193 | - { |
|
| 194 | - return (string) $this->version; |
|
| 195 | - } |
|
| 196 | - |
|
| 197 | - |
|
| 198 | - /** |
|
| 199 | - * @return Version |
|
| 200 | - */ |
|
| 201 | - public function versionValueObject() |
|
| 202 | - { |
|
| 203 | - return $this->version; |
|
| 204 | - } |
|
| 205 | - |
|
| 206 | - |
|
| 207 | - /** |
|
| 208 | - * @return string |
|
| 209 | - */ |
|
| 210 | - public function distributionAssetsFolder(): string |
|
| 211 | - { |
|
| 212 | - return DomainBase::ASSETS_FOLDER; |
|
| 213 | - } |
|
| 214 | - |
|
| 215 | - |
|
| 216 | - /** |
|
| 217 | - * @param string $additional_path |
|
| 218 | - * @return string |
|
| 219 | - */ |
|
| 220 | - public function distributionAssetsPath($additional_path = ''): string |
|
| 221 | - { |
|
| 222 | - return is_string($additional_path) && $additional_path !== '' |
|
| 223 | - ? $this->assets_path . $additional_path |
|
| 224 | - : $this->assets_path; |
|
| 225 | - } |
|
| 226 | - |
|
| 227 | - |
|
| 228 | - /** |
|
| 229 | - * @param string $additional_path |
|
| 230 | - * @return string |
|
| 231 | - */ |
|
| 232 | - public function distributionAssetsUrl($additional_path = ''): string |
|
| 233 | - { |
|
| 234 | - return is_string($additional_path) && $additional_path !== '' |
|
| 235 | - ? $this->plugin_url . DomainBase::ASSETS_FOLDER . $additional_path |
|
| 236 | - : $this->plugin_url . DomainBase::ASSETS_FOLDER; |
|
| 237 | - } |
|
| 238 | - |
|
| 239 | - |
|
| 240 | - /** |
|
| 241 | - * @return string |
|
| 242 | - */ |
|
| 243 | - public function assetNamespace(): string |
|
| 244 | - { |
|
| 245 | - return $this->asset_namespace; |
|
| 246 | - } |
|
| 20 | + const ASSETS_FOLDER = 'assets/'; |
|
| 21 | + |
|
| 22 | + /** |
|
| 23 | + * Equivalent to `__FILE__` for main plugin file. |
|
| 24 | + * |
|
| 25 | + * @var FilePath |
|
| 26 | + */ |
|
| 27 | + private $plugin_file; |
|
| 28 | + |
|
| 29 | + /** |
|
| 30 | + * String indicating version for plugin |
|
| 31 | + * |
|
| 32 | + * @var string |
|
| 33 | + */ |
|
| 34 | + private $version; |
|
| 35 | + |
|
| 36 | + /** |
|
| 37 | + * @var string $plugin_basename |
|
| 38 | + */ |
|
| 39 | + private $plugin_basename; |
|
| 40 | + |
|
| 41 | + /** |
|
| 42 | + * @var string $plugin_path |
|
| 43 | + */ |
|
| 44 | + private $plugin_path; |
|
| 45 | + |
|
| 46 | + /** |
|
| 47 | + * @var string $plugin_url |
|
| 48 | + */ |
|
| 49 | + private $plugin_url; |
|
| 50 | + |
|
| 51 | + /** |
|
| 52 | + * @var string $asset_namespace |
|
| 53 | + */ |
|
| 54 | + private $asset_namespace; |
|
| 55 | + |
|
| 56 | + /** |
|
| 57 | + * @var string $assets_path |
|
| 58 | + */ |
|
| 59 | + private $assets_path; |
|
| 60 | + |
|
| 61 | + /** |
|
| 62 | + * @var bool |
|
| 63 | + */ |
|
| 64 | + protected $initialized = false; |
|
| 65 | + |
|
| 66 | + |
|
| 67 | + /** |
|
| 68 | + * Initializes internal properties. |
|
| 69 | + * |
|
| 70 | + * @param FilePath $plugin_file |
|
| 71 | + * @param Version $version |
|
| 72 | + * @param string $asset_namespace |
|
| 73 | + */ |
|
| 74 | + public function __construct( |
|
| 75 | + FilePath $plugin_file, |
|
| 76 | + Version $version, |
|
| 77 | + string $asset_namespace = Domain::ASSET_NAMESPACE |
|
| 78 | + ) { |
|
| 79 | + $this->plugin_file = $plugin_file; |
|
| 80 | + $this->version = $version; |
|
| 81 | + $this->initialize($asset_namespace); |
|
| 82 | + } |
|
| 83 | + |
|
| 84 | + |
|
| 85 | + /** |
|
| 86 | + * @param string $asset_namespace |
|
| 87 | + * @return void |
|
| 88 | + * @since $VID:$ |
|
| 89 | + */ |
|
| 90 | + public function initialize($asset_namespace = Domain::ASSET_NAMESPACE) |
|
| 91 | + { |
|
| 92 | + if (! $this->initialized) { |
|
| 93 | + $this->plugin_basename = plugin_basename($this->pluginFile()); |
|
| 94 | + $this->plugin_path = plugin_dir_path($this->pluginFile()); |
|
| 95 | + $this->plugin_url = plugin_dir_url($this->pluginFile()); |
|
| 96 | + $this->setAssetNamespace($asset_namespace); |
|
| 97 | + $this->setDistributionAssetsPath(); |
|
| 98 | + $this->initialized = true; |
|
| 99 | + } |
|
| 100 | + } |
|
| 101 | + |
|
| 102 | + |
|
| 103 | + /** |
|
| 104 | + * @param string $asset_namespace |
|
| 105 | + * @return void |
|
| 106 | + */ |
|
| 107 | + public function setAssetNamespace($asset_namespace = Domain::ASSET_NAMESPACE) |
|
| 108 | + { |
|
| 109 | + if (! $this->asset_namespace) { |
|
| 110 | + $this->asset_namespace = sanitize_key( |
|
| 111 | + // convert directory separators to dashes and remove file extension |
|
| 112 | + str_replace(['/', '.php'], ['-', ''], $asset_namespace) |
|
| 113 | + ); |
|
| 114 | + } |
|
| 115 | + } |
|
| 116 | + |
|
| 117 | + |
|
| 118 | + /** |
|
| 119 | + * @throws DomainException |
|
| 120 | + * @since $VID:$ |
|
| 121 | + */ |
|
| 122 | + private function setDistributionAssetsPath() |
|
| 123 | + { |
|
| 124 | + $assets_folder_paths = [ |
|
| 125 | + $this->plugin_path . DomainBase::ASSETS_FOLDER, |
|
| 126 | + $this->plugin_path . 'src/' . DomainBase::ASSETS_FOLDER, |
|
| 127 | + ]; |
|
| 128 | + foreach ($assets_folder_paths as $assets_folder_path) { |
|
| 129 | + if (is_readable($assets_folder_path)) { |
|
| 130 | + $this->assets_path = trailingslashit($assets_folder_path); |
|
| 131 | + // once we find a valid path, just break out of loop |
|
| 132 | + break; |
|
| 133 | + } |
|
| 134 | + } |
|
| 135 | + } |
|
| 136 | + |
|
| 137 | + |
|
| 138 | + /** |
|
| 139 | + * @return string |
|
| 140 | + */ |
|
| 141 | + public function pluginFile(): string |
|
| 142 | + { |
|
| 143 | + return (string) $this->plugin_file; |
|
| 144 | + } |
|
| 145 | + |
|
| 146 | + |
|
| 147 | + /** |
|
| 148 | + * @return FilePath |
|
| 149 | + */ |
|
| 150 | + public function pluginFileObject(): FilePath |
|
| 151 | + { |
|
| 152 | + return $this->plugin_file; |
|
| 153 | + } |
|
| 154 | + |
|
| 155 | + |
|
| 156 | + /** |
|
| 157 | + * @return string |
|
| 158 | + */ |
|
| 159 | + public function pluginBasename(): string |
|
| 160 | + { |
|
| 161 | + return $this->plugin_basename; |
|
| 162 | + } |
|
| 163 | + |
|
| 164 | + |
|
| 165 | + /** |
|
| 166 | + * @param string $additional_path |
|
| 167 | + * @return string |
|
| 168 | + */ |
|
| 169 | + public function pluginPath($additional_path = ''): string |
|
| 170 | + { |
|
| 171 | + return is_string($additional_path) && $additional_path !== '' |
|
| 172 | + ? $this->plugin_path . $additional_path |
|
| 173 | + : $this->plugin_path; |
|
| 174 | + } |
|
| 175 | + |
|
| 176 | + |
|
| 177 | + /** |
|
| 178 | + * @param string $additional_path |
|
| 179 | + * @return string |
|
| 180 | + */ |
|
| 181 | + public function pluginUrl($additional_path = ''): string |
|
| 182 | + { |
|
| 183 | + return is_string($additional_path) && $additional_path !== '' |
|
| 184 | + ? $this->plugin_url . $additional_path |
|
| 185 | + : $this->plugin_url; |
|
| 186 | + } |
|
| 187 | + |
|
| 188 | + |
|
| 189 | + /** |
|
| 190 | + * @return string |
|
| 191 | + */ |
|
| 192 | + public function version(): string |
|
| 193 | + { |
|
| 194 | + return (string) $this->version; |
|
| 195 | + } |
|
| 196 | + |
|
| 197 | + |
|
| 198 | + /** |
|
| 199 | + * @return Version |
|
| 200 | + */ |
|
| 201 | + public function versionValueObject() |
|
| 202 | + { |
|
| 203 | + return $this->version; |
|
| 204 | + } |
|
| 205 | + |
|
| 206 | + |
|
| 207 | + /** |
|
| 208 | + * @return string |
|
| 209 | + */ |
|
| 210 | + public function distributionAssetsFolder(): string |
|
| 211 | + { |
|
| 212 | + return DomainBase::ASSETS_FOLDER; |
|
| 213 | + } |
|
| 214 | + |
|
| 215 | + |
|
| 216 | + /** |
|
| 217 | + * @param string $additional_path |
|
| 218 | + * @return string |
|
| 219 | + */ |
|
| 220 | + public function distributionAssetsPath($additional_path = ''): string |
|
| 221 | + { |
|
| 222 | + return is_string($additional_path) && $additional_path !== '' |
|
| 223 | + ? $this->assets_path . $additional_path |
|
| 224 | + : $this->assets_path; |
|
| 225 | + } |
|
| 226 | + |
|
| 227 | + |
|
| 228 | + /** |
|
| 229 | + * @param string $additional_path |
|
| 230 | + * @return string |
|
| 231 | + */ |
|
| 232 | + public function distributionAssetsUrl($additional_path = ''): string |
|
| 233 | + { |
|
| 234 | + return is_string($additional_path) && $additional_path !== '' |
|
| 235 | + ? $this->plugin_url . DomainBase::ASSETS_FOLDER . $additional_path |
|
| 236 | + : $this->plugin_url . DomainBase::ASSETS_FOLDER; |
|
| 237 | + } |
|
| 238 | + |
|
| 239 | + |
|
| 240 | + /** |
|
| 241 | + * @return string |
|
| 242 | + */ |
|
| 243 | + public function assetNamespace(): string |
|
| 244 | + { |
|
| 245 | + return $this->asset_namespace; |
|
| 246 | + } |
|
| 247 | 247 | } |
@@ -89,7 +89,7 @@ discard block |
||
| 89 | 89 | */ |
| 90 | 90 | public function initialize($asset_namespace = Domain::ASSET_NAMESPACE) |
| 91 | 91 | { |
| 92 | - if (! $this->initialized) { |
|
| 92 | + if ( ! $this->initialized) { |
|
| 93 | 93 | $this->plugin_basename = plugin_basename($this->pluginFile()); |
| 94 | 94 | $this->plugin_path = plugin_dir_path($this->pluginFile()); |
| 95 | 95 | $this->plugin_url = plugin_dir_url($this->pluginFile()); |
@@ -106,7 +106,7 @@ discard block |
||
| 106 | 106 | */ |
| 107 | 107 | public function setAssetNamespace($asset_namespace = Domain::ASSET_NAMESPACE) |
| 108 | 108 | { |
| 109 | - if (! $this->asset_namespace) { |
|
| 109 | + if ( ! $this->asset_namespace) { |
|
| 110 | 110 | $this->asset_namespace = sanitize_key( |
| 111 | 111 | // convert directory separators to dashes and remove file extension |
| 112 | 112 | str_replace(['/', '.php'], ['-', ''], $asset_namespace) |
@@ -122,8 +122,8 @@ discard block |
||
| 122 | 122 | private function setDistributionAssetsPath() |
| 123 | 123 | { |
| 124 | 124 | $assets_folder_paths = [ |
| 125 | - $this->plugin_path . DomainBase::ASSETS_FOLDER, |
|
| 126 | - $this->plugin_path . 'src/' . DomainBase::ASSETS_FOLDER, |
|
| 125 | + $this->plugin_path.DomainBase::ASSETS_FOLDER, |
|
| 126 | + $this->plugin_path.'src/'.DomainBase::ASSETS_FOLDER, |
|
| 127 | 127 | ]; |
| 128 | 128 | foreach ($assets_folder_paths as $assets_folder_path) { |
| 129 | 129 | if (is_readable($assets_folder_path)) { |
@@ -169,7 +169,7 @@ discard block |
||
| 169 | 169 | public function pluginPath($additional_path = ''): string |
| 170 | 170 | { |
| 171 | 171 | return is_string($additional_path) && $additional_path !== '' |
| 172 | - ? $this->plugin_path . $additional_path |
|
| 172 | + ? $this->plugin_path.$additional_path |
|
| 173 | 173 | : $this->plugin_path; |
| 174 | 174 | } |
| 175 | 175 | |
@@ -181,7 +181,7 @@ discard block |
||
| 181 | 181 | public function pluginUrl($additional_path = ''): string |
| 182 | 182 | { |
| 183 | 183 | return is_string($additional_path) && $additional_path !== '' |
| 184 | - ? $this->plugin_url . $additional_path |
|
| 184 | + ? $this->plugin_url.$additional_path |
|
| 185 | 185 | : $this->plugin_url; |
| 186 | 186 | } |
| 187 | 187 | |
@@ -220,7 +220,7 @@ discard block |
||
| 220 | 220 | public function distributionAssetsPath($additional_path = ''): string |
| 221 | 221 | { |
| 222 | 222 | return is_string($additional_path) && $additional_path !== '' |
| 223 | - ? $this->assets_path . $additional_path |
|
| 223 | + ? $this->assets_path.$additional_path |
|
| 224 | 224 | : $this->assets_path; |
| 225 | 225 | } |
| 226 | 226 | |
@@ -232,8 +232,8 @@ discard block |
||
| 232 | 232 | public function distributionAssetsUrl($additional_path = ''): string |
| 233 | 233 | { |
| 234 | 234 | return is_string($additional_path) && $additional_path !== '' |
| 235 | - ? $this->plugin_url . DomainBase::ASSETS_FOLDER . $additional_path |
|
| 236 | - : $this->plugin_url . DomainBase::ASSETS_FOLDER; |
|
| 235 | + ? $this->plugin_url.DomainBase::ASSETS_FOLDER.$additional_path |
|
| 236 | + : $this->plugin_url.DomainBase::ASSETS_FOLDER; |
|
| 237 | 237 | } |
| 238 | 238 | |
| 239 | 239 | |
@@ -16,1333 +16,1333 @@ |
||
| 16 | 16 | class EED_Messages extends EED_Module |
| 17 | 17 | { |
| 18 | 18 | |
| 19 | - /** |
|
| 20 | - * This holds the EE_messages controller |
|
| 21 | - * |
|
| 22 | - * @deprecated 4.9.0 |
|
| 23 | - * @var EE_messages $_EEMSG |
|
| 24 | - */ |
|
| 25 | - protected static $_EEMSG; |
|
| 26 | - |
|
| 27 | - /** |
|
| 28 | - * @type EE_Message_Resource_Manager $_message_resource_manager |
|
| 29 | - */ |
|
| 30 | - protected static $_message_resource_manager; |
|
| 31 | - |
|
| 32 | - /** |
|
| 33 | - * This holds the EE_Messages_Processor business class. |
|
| 34 | - * |
|
| 35 | - * @type EE_Messages_Processor |
|
| 36 | - */ |
|
| 37 | - protected static $_MSG_PROCESSOR; |
|
| 38 | - |
|
| 39 | - /** |
|
| 40 | - * holds all the paths for various messages components. |
|
| 41 | - * Utilized by autoloader registry |
|
| 42 | - * |
|
| 43 | - * @var array |
|
| 44 | - */ |
|
| 45 | - protected static $_MSG_PATHS; |
|
| 46 | - |
|
| 47 | - |
|
| 48 | - /** |
|
| 49 | - * This will hold an array of messages template packs that are registered in the messages system. |
|
| 50 | - * Format is: |
|
| 51 | - * array( |
|
| 52 | - * 'template_pack_dbref' => EE_Messages_Template_Pack (instance) |
|
| 53 | - * ) |
|
| 54 | - * |
|
| 55 | - * @var EE_Messages_Template_Pack[] |
|
| 56 | - */ |
|
| 57 | - protected static $_TMP_PACKS = array(); |
|
| 58 | - |
|
| 59 | - |
|
| 60 | - /** |
|
| 61 | - * @return EED_Messages |
|
| 62 | - */ |
|
| 63 | - public static function instance() |
|
| 64 | - { |
|
| 65 | - return parent::get_instance(__CLASS__); |
|
| 66 | - } |
|
| 67 | - |
|
| 68 | - |
|
| 69 | - /** |
|
| 70 | - * set_hooks - for hooking into EE Core, other modules, etc |
|
| 71 | - * |
|
| 72 | - * @since 4.5.0 |
|
| 73 | - * @return void |
|
| 74 | - */ |
|
| 75 | - public static function set_hooks() |
|
| 76 | - { |
|
| 77 | - // actions |
|
| 78 | - add_action('AHEE__EE_Payment_Processor__update_txn_based_on_payment', array('EED_Messages', 'payment'), 10, 2); |
|
| 79 | - add_action( |
|
| 80 | - 'AHEE__EE_Registration_Processor__trigger_registration_update_notifications', |
|
| 81 | - array('EED_Messages', 'maybe_registration'), |
|
| 82 | - 10, |
|
| 83 | - 2 |
|
| 84 | - ); |
|
| 85 | - // filters |
|
| 86 | - add_filter( |
|
| 87 | - 'FHEE__EE_Registration__receipt_url__receipt_url', |
|
| 88 | - array('EED_Messages', 'registration_message_trigger_url'), |
|
| 89 | - 10, |
|
| 90 | - 4 |
|
| 91 | - ); |
|
| 92 | - add_filter( |
|
| 93 | - 'FHEE__EE_Registration__invoice_url__invoice_url', |
|
| 94 | - array('EED_Messages', 'registration_message_trigger_url'), |
|
| 95 | - 10, |
|
| 96 | - 4 |
|
| 97 | - ); |
|
| 98 | - // register routes |
|
| 99 | - self::_register_routes(); |
|
| 100 | - } |
|
| 101 | - |
|
| 102 | - /** |
|
| 103 | - * set_hooks_admin - for hooking into EE Admin Core, other modules, etc |
|
| 104 | - * |
|
| 105 | - * @access public |
|
| 106 | - * @return void |
|
| 107 | - */ |
|
| 108 | - public static function set_hooks_admin() |
|
| 109 | - { |
|
| 110 | - // actions |
|
| 111 | - add_action('AHEE__EE_Payment_Processor__update_txn_based_on_payment', array('EED_Messages', 'payment'), 10, 2); |
|
| 112 | - add_action( |
|
| 113 | - 'AHEE__Transactions_Admin_Page___send_payment_reminder__process_admin_payment_reminder', |
|
| 114 | - array('EED_Messages', 'payment_reminder'), |
|
| 115 | - 10 |
|
| 116 | - ); |
|
| 117 | - add_action( |
|
| 118 | - 'AHEE__EE_Registration_Processor__trigger_registration_update_notifications', |
|
| 119 | - array('EED_Messages', 'maybe_registration'), |
|
| 120 | - 10, |
|
| 121 | - 3 |
|
| 122 | - ); |
|
| 123 | - add_action( |
|
| 124 | - 'AHEE__Extend_Registrations_Admin_Page___newsletter_selected_send__with_registrations', |
|
| 125 | - array('EED_Messages', 'send_newsletter_message'), |
|
| 126 | - 10, |
|
| 127 | - 2 |
|
| 128 | - ); |
|
| 129 | - add_action( |
|
| 130 | - 'AHEE__EES_Espresso_Cancelled__process_shortcode__transaction', |
|
| 131 | - array('EED_Messages', 'cancelled_registration'), |
|
| 132 | - 10 |
|
| 133 | - ); |
|
| 134 | - add_action( |
|
| 135 | - 'AHEE__EE_Admin_Page___process_admin_payment_notification', |
|
| 136 | - array('EED_Messages', 'process_admin_payment'), |
|
| 137 | - 10, |
|
| 138 | - 1 |
|
| 139 | - ); |
|
| 140 | - // filters |
|
| 141 | - add_filter( |
|
| 142 | - 'FHEE__EE_Admin_Page___process_resend_registration__success', |
|
| 143 | - array('EED_Messages', 'process_resend'), |
|
| 144 | - 10, |
|
| 145 | - 2 |
|
| 146 | - ); |
|
| 147 | - add_filter( |
|
| 148 | - 'FHEE__EE_Registration__receipt_url__receipt_url', |
|
| 149 | - array('EED_Messages', 'registration_message_trigger_url'), |
|
| 150 | - 10, |
|
| 151 | - 4 |
|
| 152 | - ); |
|
| 153 | - add_filter( |
|
| 154 | - 'FHEE__EE_Registration__invoice_url__invoice_url', |
|
| 155 | - array('EED_Messages', 'registration_message_trigger_url'), |
|
| 156 | - 10, |
|
| 157 | - 4 |
|
| 158 | - ); |
|
| 159 | - } |
|
| 160 | - |
|
| 161 | - |
|
| 162 | - /** |
|
| 163 | - * All the message triggers done by route go in here. |
|
| 164 | - * |
|
| 165 | - * @since 4.5.0 |
|
| 166 | - * @return void |
|
| 167 | - */ |
|
| 168 | - protected static function _register_routes() |
|
| 169 | - { |
|
| 170 | - EE_Config::register_route('msg_url_trigger', 'Messages', 'run'); |
|
| 171 | - EE_Config::register_route('msg_cron_trigger', 'Messages', 'execute_batch_request'); |
|
| 172 | - EE_Config::register_route('msg_browser_trigger', 'Messages', 'browser_trigger'); |
|
| 173 | - EE_Config::register_route('msg_browser_error_trigger', 'Messages', 'browser_error_trigger'); |
|
| 174 | - do_action('AHEE__EED_Messages___register_routes'); |
|
| 175 | - } |
|
| 176 | - |
|
| 177 | - |
|
| 178 | - /** |
|
| 179 | - * This is called when a browser display trigger is executed. |
|
| 180 | - * The browser display trigger is typically used when a already generated message is displayed directly in the |
|
| 181 | - * browser. |
|
| 182 | - * |
|
| 183 | - * @since 4.9.0 |
|
| 184 | - * @param WP $WP |
|
| 185 | - * @throws EE_Error |
|
| 186 | - * @throws InvalidArgumentException |
|
| 187 | - * @throws ReflectionException |
|
| 188 | - * @throws InvalidDataTypeException |
|
| 189 | - * @throws InvalidInterfaceException |
|
| 190 | - */ |
|
| 191 | - public function browser_trigger($WP) |
|
| 192 | - { |
|
| 193 | - // ensure controller is loaded |
|
| 194 | - self::_load_controller(); |
|
| 195 | - $token = EE_Registry::instance()->REQ->get('token'); |
|
| 196 | - try { |
|
| 197 | - $mtg = new EE_Message_Generated_From_Token($token, 'html', self::$_message_resource_manager); |
|
| 198 | - self::$_MSG_PROCESSOR->generate_and_send_now($mtg); |
|
| 199 | - } catch (EE_Error $e) { |
|
| 200 | - $error_msg = __( |
|
| 201 | - 'Please note that a system message failed to send due to a technical issue.', |
|
| 202 | - 'event_espresso' |
|
| 203 | - ); |
|
| 204 | - // add specific message for developers if WP_DEBUG in on |
|
| 205 | - $error_msg .= '||' . $e->getMessage(); |
|
| 206 | - EE_Error::add_error($error_msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 207 | - } |
|
| 208 | - } |
|
| 209 | - |
|
| 210 | - |
|
| 211 | - /** |
|
| 212 | - * This is called when a browser error trigger is executed. |
|
| 213 | - * When triggered this will grab the EE_Message matching the token in the request and use that to get the error |
|
| 214 | - * message and display it. |
|
| 215 | - * |
|
| 216 | - * @since 4.9.0 |
|
| 217 | - * @param $WP |
|
| 218 | - * @throws EE_Error |
|
| 219 | - * @throws InvalidArgumentException |
|
| 220 | - * @throws InvalidDataTypeException |
|
| 221 | - * @throws InvalidInterfaceException |
|
| 222 | - */ |
|
| 223 | - public function browser_error_trigger($WP) |
|
| 224 | - { |
|
| 225 | - $token = EE_Registry::instance()->REQ->get('token'); |
|
| 226 | - if ($token) { |
|
| 227 | - $message = EEM_Message::instance()->get_one_by_token($token); |
|
| 228 | - if ($message instanceof EE_Message) { |
|
| 229 | - header('HTTP/1.1 200 OK'); |
|
| 230 | - $error_msg = nl2br($message->error_message()); |
|
| 231 | - ?> |
|
| 19 | + /** |
|
| 20 | + * This holds the EE_messages controller |
|
| 21 | + * |
|
| 22 | + * @deprecated 4.9.0 |
|
| 23 | + * @var EE_messages $_EEMSG |
|
| 24 | + */ |
|
| 25 | + protected static $_EEMSG; |
|
| 26 | + |
|
| 27 | + /** |
|
| 28 | + * @type EE_Message_Resource_Manager $_message_resource_manager |
|
| 29 | + */ |
|
| 30 | + protected static $_message_resource_manager; |
|
| 31 | + |
|
| 32 | + /** |
|
| 33 | + * This holds the EE_Messages_Processor business class. |
|
| 34 | + * |
|
| 35 | + * @type EE_Messages_Processor |
|
| 36 | + */ |
|
| 37 | + protected static $_MSG_PROCESSOR; |
|
| 38 | + |
|
| 39 | + /** |
|
| 40 | + * holds all the paths for various messages components. |
|
| 41 | + * Utilized by autoloader registry |
|
| 42 | + * |
|
| 43 | + * @var array |
|
| 44 | + */ |
|
| 45 | + protected static $_MSG_PATHS; |
|
| 46 | + |
|
| 47 | + |
|
| 48 | + /** |
|
| 49 | + * This will hold an array of messages template packs that are registered in the messages system. |
|
| 50 | + * Format is: |
|
| 51 | + * array( |
|
| 52 | + * 'template_pack_dbref' => EE_Messages_Template_Pack (instance) |
|
| 53 | + * ) |
|
| 54 | + * |
|
| 55 | + * @var EE_Messages_Template_Pack[] |
|
| 56 | + */ |
|
| 57 | + protected static $_TMP_PACKS = array(); |
|
| 58 | + |
|
| 59 | + |
|
| 60 | + /** |
|
| 61 | + * @return EED_Messages |
|
| 62 | + */ |
|
| 63 | + public static function instance() |
|
| 64 | + { |
|
| 65 | + return parent::get_instance(__CLASS__); |
|
| 66 | + } |
|
| 67 | + |
|
| 68 | + |
|
| 69 | + /** |
|
| 70 | + * set_hooks - for hooking into EE Core, other modules, etc |
|
| 71 | + * |
|
| 72 | + * @since 4.5.0 |
|
| 73 | + * @return void |
|
| 74 | + */ |
|
| 75 | + public static function set_hooks() |
|
| 76 | + { |
|
| 77 | + // actions |
|
| 78 | + add_action('AHEE__EE_Payment_Processor__update_txn_based_on_payment', array('EED_Messages', 'payment'), 10, 2); |
|
| 79 | + add_action( |
|
| 80 | + 'AHEE__EE_Registration_Processor__trigger_registration_update_notifications', |
|
| 81 | + array('EED_Messages', 'maybe_registration'), |
|
| 82 | + 10, |
|
| 83 | + 2 |
|
| 84 | + ); |
|
| 85 | + // filters |
|
| 86 | + add_filter( |
|
| 87 | + 'FHEE__EE_Registration__receipt_url__receipt_url', |
|
| 88 | + array('EED_Messages', 'registration_message_trigger_url'), |
|
| 89 | + 10, |
|
| 90 | + 4 |
|
| 91 | + ); |
|
| 92 | + add_filter( |
|
| 93 | + 'FHEE__EE_Registration__invoice_url__invoice_url', |
|
| 94 | + array('EED_Messages', 'registration_message_trigger_url'), |
|
| 95 | + 10, |
|
| 96 | + 4 |
|
| 97 | + ); |
|
| 98 | + // register routes |
|
| 99 | + self::_register_routes(); |
|
| 100 | + } |
|
| 101 | + |
|
| 102 | + /** |
|
| 103 | + * set_hooks_admin - for hooking into EE Admin Core, other modules, etc |
|
| 104 | + * |
|
| 105 | + * @access public |
|
| 106 | + * @return void |
|
| 107 | + */ |
|
| 108 | + public static function set_hooks_admin() |
|
| 109 | + { |
|
| 110 | + // actions |
|
| 111 | + add_action('AHEE__EE_Payment_Processor__update_txn_based_on_payment', array('EED_Messages', 'payment'), 10, 2); |
|
| 112 | + add_action( |
|
| 113 | + 'AHEE__Transactions_Admin_Page___send_payment_reminder__process_admin_payment_reminder', |
|
| 114 | + array('EED_Messages', 'payment_reminder'), |
|
| 115 | + 10 |
|
| 116 | + ); |
|
| 117 | + add_action( |
|
| 118 | + 'AHEE__EE_Registration_Processor__trigger_registration_update_notifications', |
|
| 119 | + array('EED_Messages', 'maybe_registration'), |
|
| 120 | + 10, |
|
| 121 | + 3 |
|
| 122 | + ); |
|
| 123 | + add_action( |
|
| 124 | + 'AHEE__Extend_Registrations_Admin_Page___newsletter_selected_send__with_registrations', |
|
| 125 | + array('EED_Messages', 'send_newsletter_message'), |
|
| 126 | + 10, |
|
| 127 | + 2 |
|
| 128 | + ); |
|
| 129 | + add_action( |
|
| 130 | + 'AHEE__EES_Espresso_Cancelled__process_shortcode__transaction', |
|
| 131 | + array('EED_Messages', 'cancelled_registration'), |
|
| 132 | + 10 |
|
| 133 | + ); |
|
| 134 | + add_action( |
|
| 135 | + 'AHEE__EE_Admin_Page___process_admin_payment_notification', |
|
| 136 | + array('EED_Messages', 'process_admin_payment'), |
|
| 137 | + 10, |
|
| 138 | + 1 |
|
| 139 | + ); |
|
| 140 | + // filters |
|
| 141 | + add_filter( |
|
| 142 | + 'FHEE__EE_Admin_Page___process_resend_registration__success', |
|
| 143 | + array('EED_Messages', 'process_resend'), |
|
| 144 | + 10, |
|
| 145 | + 2 |
|
| 146 | + ); |
|
| 147 | + add_filter( |
|
| 148 | + 'FHEE__EE_Registration__receipt_url__receipt_url', |
|
| 149 | + array('EED_Messages', 'registration_message_trigger_url'), |
|
| 150 | + 10, |
|
| 151 | + 4 |
|
| 152 | + ); |
|
| 153 | + add_filter( |
|
| 154 | + 'FHEE__EE_Registration__invoice_url__invoice_url', |
|
| 155 | + array('EED_Messages', 'registration_message_trigger_url'), |
|
| 156 | + 10, |
|
| 157 | + 4 |
|
| 158 | + ); |
|
| 159 | + } |
|
| 160 | + |
|
| 161 | + |
|
| 162 | + /** |
|
| 163 | + * All the message triggers done by route go in here. |
|
| 164 | + * |
|
| 165 | + * @since 4.5.0 |
|
| 166 | + * @return void |
|
| 167 | + */ |
|
| 168 | + protected static function _register_routes() |
|
| 169 | + { |
|
| 170 | + EE_Config::register_route('msg_url_trigger', 'Messages', 'run'); |
|
| 171 | + EE_Config::register_route('msg_cron_trigger', 'Messages', 'execute_batch_request'); |
|
| 172 | + EE_Config::register_route('msg_browser_trigger', 'Messages', 'browser_trigger'); |
|
| 173 | + EE_Config::register_route('msg_browser_error_trigger', 'Messages', 'browser_error_trigger'); |
|
| 174 | + do_action('AHEE__EED_Messages___register_routes'); |
|
| 175 | + } |
|
| 176 | + |
|
| 177 | + |
|
| 178 | + /** |
|
| 179 | + * This is called when a browser display trigger is executed. |
|
| 180 | + * The browser display trigger is typically used when a already generated message is displayed directly in the |
|
| 181 | + * browser. |
|
| 182 | + * |
|
| 183 | + * @since 4.9.0 |
|
| 184 | + * @param WP $WP |
|
| 185 | + * @throws EE_Error |
|
| 186 | + * @throws InvalidArgumentException |
|
| 187 | + * @throws ReflectionException |
|
| 188 | + * @throws InvalidDataTypeException |
|
| 189 | + * @throws InvalidInterfaceException |
|
| 190 | + */ |
|
| 191 | + public function browser_trigger($WP) |
|
| 192 | + { |
|
| 193 | + // ensure controller is loaded |
|
| 194 | + self::_load_controller(); |
|
| 195 | + $token = EE_Registry::instance()->REQ->get('token'); |
|
| 196 | + try { |
|
| 197 | + $mtg = new EE_Message_Generated_From_Token($token, 'html', self::$_message_resource_manager); |
|
| 198 | + self::$_MSG_PROCESSOR->generate_and_send_now($mtg); |
|
| 199 | + } catch (EE_Error $e) { |
|
| 200 | + $error_msg = __( |
|
| 201 | + 'Please note that a system message failed to send due to a technical issue.', |
|
| 202 | + 'event_espresso' |
|
| 203 | + ); |
|
| 204 | + // add specific message for developers if WP_DEBUG in on |
|
| 205 | + $error_msg .= '||' . $e->getMessage(); |
|
| 206 | + EE_Error::add_error($error_msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 207 | + } |
|
| 208 | + } |
|
| 209 | + |
|
| 210 | + |
|
| 211 | + /** |
|
| 212 | + * This is called when a browser error trigger is executed. |
|
| 213 | + * When triggered this will grab the EE_Message matching the token in the request and use that to get the error |
|
| 214 | + * message and display it. |
|
| 215 | + * |
|
| 216 | + * @since 4.9.0 |
|
| 217 | + * @param $WP |
|
| 218 | + * @throws EE_Error |
|
| 219 | + * @throws InvalidArgumentException |
|
| 220 | + * @throws InvalidDataTypeException |
|
| 221 | + * @throws InvalidInterfaceException |
|
| 222 | + */ |
|
| 223 | + public function browser_error_trigger($WP) |
|
| 224 | + { |
|
| 225 | + $token = EE_Registry::instance()->REQ->get('token'); |
|
| 226 | + if ($token) { |
|
| 227 | + $message = EEM_Message::instance()->get_one_by_token($token); |
|
| 228 | + if ($message instanceof EE_Message) { |
|
| 229 | + header('HTTP/1.1 200 OK'); |
|
| 230 | + $error_msg = nl2br($message->error_message()); |
|
| 231 | + ?> |
|
| 232 | 232 | <!DOCTYPE html> |
| 233 | 233 | <html> |
| 234 | 234 | <head></head> |
| 235 | 235 | <body> |
| 236 | 236 | <?php echo empty($error_msg) |
| 237 | - ? esc_html__( |
|
| 238 | - 'Unfortunately, we were unable to capture the error message for this message.', |
|
| 239 | - 'event_espresso' |
|
| 240 | - ) |
|
| 241 | - : wp_kses( |
|
| 242 | - $error_msg, |
|
| 243 | - array( |
|
| 244 | - 'a' => array( |
|
| 245 | - 'href' => array(), |
|
| 246 | - 'title' => array(), |
|
| 247 | - ), |
|
| 248 | - 'span' => array(), |
|
| 249 | - 'div' => array(), |
|
| 250 | - 'p' => array(), |
|
| 251 | - 'strong' => array(), |
|
| 252 | - 'em' => array(), |
|
| 253 | - 'br' => array(), |
|
| 254 | - ) |
|
| 255 | - ); ?> |
|
| 237 | + ? esc_html__( |
|
| 238 | + 'Unfortunately, we were unable to capture the error message for this message.', |
|
| 239 | + 'event_espresso' |
|
| 240 | + ) |
|
| 241 | + : wp_kses( |
|
| 242 | + $error_msg, |
|
| 243 | + array( |
|
| 244 | + 'a' => array( |
|
| 245 | + 'href' => array(), |
|
| 246 | + 'title' => array(), |
|
| 247 | + ), |
|
| 248 | + 'span' => array(), |
|
| 249 | + 'div' => array(), |
|
| 250 | + 'p' => array(), |
|
| 251 | + 'strong' => array(), |
|
| 252 | + 'em' => array(), |
|
| 253 | + 'br' => array(), |
|
| 254 | + ) |
|
| 255 | + ); ?> |
|
| 256 | 256 | </body> |
| 257 | 257 | </html> |
| 258 | 258 | <?php |
| 259 | - exit; |
|
| 260 | - } |
|
| 261 | - } |
|
| 262 | - return; |
|
| 263 | - } |
|
| 264 | - |
|
| 265 | - |
|
| 266 | - /** |
|
| 267 | - * This runs when the msg_url_trigger route has initiated. |
|
| 268 | - * |
|
| 269 | - * @since 4.5.0 |
|
| 270 | - * @param WP $WP |
|
| 271 | - * @throws EE_Error |
|
| 272 | - * @throws InvalidArgumentException |
|
| 273 | - * @throws ReflectionException |
|
| 274 | - * @throws InvalidDataTypeException |
|
| 275 | - * @throws InvalidInterfaceException |
|
| 276 | - */ |
|
| 277 | - public function run($WP) |
|
| 278 | - { |
|
| 279 | - // ensure controller is loaded |
|
| 280 | - self::_load_controller(); |
|
| 281 | - // attempt to process message |
|
| 282 | - try { |
|
| 283 | - /** @type EE_Message_To_Generate_From_Request $message_to_generate */ |
|
| 284 | - $message_to_generate = EE_Registry::instance()->load_lib('Message_To_Generate_From_Request'); |
|
| 285 | - self::$_MSG_PROCESSOR->generate_and_send_now($message_to_generate); |
|
| 286 | - } catch (EE_Error $e) { |
|
| 287 | - $error_msg = __( |
|
| 288 | - 'Please note that a system message failed to send due to a technical issue.', |
|
| 289 | - 'event_espresso' |
|
| 290 | - ); |
|
| 291 | - // add specific message for developers if WP_DEBUG in on |
|
| 292 | - $error_msg .= '||' . $e->getMessage(); |
|
| 293 | - EE_Error::add_error($error_msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 294 | - } |
|
| 295 | - } |
|
| 296 | - |
|
| 297 | - |
|
| 298 | - /** |
|
| 299 | - * This is triggered by the 'msg_cron_trigger' route. |
|
| 300 | - * |
|
| 301 | - * @param WP $WP |
|
| 302 | - */ |
|
| 303 | - public function execute_batch_request($WP) |
|
| 304 | - { |
|
| 305 | - $this->run_cron(); |
|
| 306 | - header('HTTP/1.1 200 OK'); |
|
| 307 | - exit(); |
|
| 308 | - } |
|
| 309 | - |
|
| 310 | - |
|
| 311 | - /** |
|
| 312 | - * This gets executed on wp_cron jobs or when a batch request is initiated on its own separate non regular wp |
|
| 313 | - * request. |
|
| 314 | - */ |
|
| 315 | - public function run_cron() |
|
| 316 | - { |
|
| 317 | - self::_load_controller(); |
|
| 318 | - // get required vars |
|
| 319 | - $cron_type = EE_Registry::instance()->REQ->get('type'); |
|
| 320 | - $transient_key = EE_Registry::instance()->REQ->get('key'); |
|
| 321 | - |
|
| 322 | - // now let's verify transient, if not valid exit immediately |
|
| 323 | - if (! get_transient($transient_key)) { |
|
| 324 | - /** |
|
| 325 | - * trigger error so this gets in the error logs. This is important because it happens on a non-user |
|
| 326 | - * request. |
|
| 327 | - */ |
|
| 328 | - trigger_error(esc_attr__('Invalid Request (Transient does not exist)', 'event_espresso')); |
|
| 329 | - } |
|
| 330 | - |
|
| 331 | - // if made it here, lets' delete the transient to keep the db clean |
|
| 332 | - delete_transient($transient_key); |
|
| 333 | - |
|
| 334 | - if (apply_filters('FHEE__EED_Messages__run_cron__use_wp_cron', true)) { |
|
| 335 | - $method = 'batch_' . $cron_type . '_from_queue'; |
|
| 336 | - if (method_exists(self::$_MSG_PROCESSOR, $method)) { |
|
| 337 | - self::$_MSG_PROCESSOR->$method(); |
|
| 338 | - } else { |
|
| 339 | - // no matching task |
|
| 340 | - /** |
|
| 341 | - * trigger error so this gets in the error logs. This is important because it happens on a non user |
|
| 342 | - * request. |
|
| 343 | - */ |
|
| 344 | - trigger_error( |
|
| 345 | - esc_attr( |
|
| 346 | - sprintf( |
|
| 347 | - __('There is no task corresponding to this route %s', 'event_espresso'), |
|
| 348 | - $cron_type |
|
| 349 | - ) |
|
| 350 | - ) |
|
| 351 | - ); |
|
| 352 | - } |
|
| 353 | - } |
|
| 354 | - |
|
| 355 | - do_action('FHEE__EED_Messages__run_cron__end'); |
|
| 356 | - } |
|
| 357 | - |
|
| 358 | - |
|
| 359 | - /** |
|
| 360 | - * This is used to retrieve the template pack for the given name. |
|
| 361 | - * Retrieved packs are cached on the static $_TMP_PACKS array. If there is no class matching the given name then |
|
| 362 | - * the default template pack is returned. |
|
| 363 | - * |
|
| 364 | - * @deprecated 4.9.0 @see EEH_MSG_Template::get_template_pack() |
|
| 365 | - * @param string $template_pack_name This should correspond to the dbref of the template pack (which is also used |
|
| 366 | - * in generating the Pack class name). |
|
| 367 | - * @return EE_Messages_Template_Pack |
|
| 368 | - * @throws EE_Error |
|
| 369 | - * @throws InvalidArgumentException |
|
| 370 | - * @throws ReflectionException |
|
| 371 | - * @throws InvalidDataTypeException |
|
| 372 | - * @throws InvalidInterfaceException |
|
| 373 | - */ |
|
| 374 | - public static function get_template_pack($template_pack_name) |
|
| 375 | - { |
|
| 376 | - EE_Registry::instance()->load_helper('MSG_Template'); |
|
| 377 | - return EEH_MSG_Template::get_template_pack($template_pack_name); |
|
| 378 | - } |
|
| 379 | - |
|
| 380 | - |
|
| 381 | - /** |
|
| 382 | - * Retrieves an array of all template packs. |
|
| 383 | - * Array is in the format array( 'dbref' => EE_Messages_Template_Pack ) |
|
| 384 | - * |
|
| 385 | - * @deprecated 4.9.0 @see EEH_MSG_Template_Pack::get_template_pack_collection |
|
| 386 | - * @return EE_Messages_Template_Pack[] |
|
| 387 | - * @throws EE_Error |
|
| 388 | - * @throws InvalidArgumentException |
|
| 389 | - * @throws ReflectionException |
|
| 390 | - * @throws InvalidDataTypeException |
|
| 391 | - * @throws InvalidInterfaceException |
|
| 392 | - */ |
|
| 393 | - public static function get_template_packs() |
|
| 394 | - { |
|
| 395 | - EE_Registry::instance()->load_helper('MSG_Template'); |
|
| 396 | - |
|
| 397 | - // for backward compat, let's make sure this returns in the same format as originally. |
|
| 398 | - $template_pack_collection = EEH_MSG_Template::get_template_pack_collection(); |
|
| 399 | - $template_pack_collection->rewind(); |
|
| 400 | - $template_packs = array(); |
|
| 401 | - while ($template_pack_collection->valid()) { |
|
| 402 | - $template_packs[ $template_pack_collection->current()->dbref ] = $template_pack_collection->current(); |
|
| 403 | - $template_pack_collection->next(); |
|
| 404 | - } |
|
| 405 | - return $template_packs; |
|
| 406 | - } |
|
| 407 | - |
|
| 408 | - |
|
| 409 | - /** |
|
| 410 | - * This simply makes sure the autoloaders are registered for the EE_messages system. |
|
| 411 | - * |
|
| 412 | - * @since 4.5.0 |
|
| 413 | - * @return void |
|
| 414 | - * @throws EE_Error |
|
| 415 | - */ |
|
| 416 | - public static function set_autoloaders() |
|
| 417 | - { |
|
| 418 | - if (empty(self::$_MSG_PATHS)) { |
|
| 419 | - self::_set_messages_paths(); |
|
| 420 | - foreach (self::$_MSG_PATHS as $path) { |
|
| 421 | - EEH_Autoloader::register_autoloaders_for_each_file_in_folder($path); |
|
| 422 | - } |
|
| 423 | - // add aliases |
|
| 424 | - EEH_Autoloader::add_alias('EE_messages', 'EE_messages'); |
|
| 425 | - EEH_Autoloader::add_alias('EE_messenger', 'EE_messenger'); |
|
| 426 | - } |
|
| 427 | - } |
|
| 428 | - |
|
| 429 | - |
|
| 430 | - /** |
|
| 431 | - * Take care of adding all the paths for the messages components to the $_MSG_PATHS property |
|
| 432 | - * for use by the Messages Autoloaders |
|
| 433 | - * |
|
| 434 | - * @since 4.5.0 |
|
| 435 | - * @return void. |
|
| 436 | - */ |
|
| 437 | - protected static function _set_messages_paths() |
|
| 438 | - { |
|
| 439 | - self::$_MSG_PATHS = apply_filters( |
|
| 440 | - 'FHEE__EED_Messages___set_messages_paths___MSG_PATHS', |
|
| 441 | - [ |
|
| 442 | - EE_LIBRARIES . 'messages/message_type', |
|
| 443 | - EE_LIBRARIES . 'messages/messenger', |
|
| 444 | - EE_LIBRARIES . 'messages/defaults', |
|
| 445 | - EE_LIBRARIES . 'messages/defaults/email', |
|
| 446 | - EE_LIBRARIES . 'messages/data_class', |
|
| 447 | - EE_LIBRARIES . 'messages/validators', |
|
| 448 | - EE_LIBRARIES . 'messages/validators/email', |
|
| 449 | - EE_LIBRARIES . 'messages/validators/html', |
|
| 450 | - EE_LIBRARIES . 'shortcodes', |
|
| 451 | - ] |
|
| 452 | - ); |
|
| 453 | - } |
|
| 454 | - |
|
| 455 | - |
|
| 456 | - /** |
|
| 457 | - * Takes care of loading dependencies |
|
| 458 | - * |
|
| 459 | - * @since 4.5.0 |
|
| 460 | - * @return void |
|
| 461 | - * @throws EE_Error |
|
| 462 | - * @throws InvalidArgumentException |
|
| 463 | - * @throws ReflectionException |
|
| 464 | - * @throws InvalidDataTypeException |
|
| 465 | - * @throws InvalidInterfaceException |
|
| 466 | - */ |
|
| 467 | - protected static function _load_controller() |
|
| 468 | - { |
|
| 469 | - if (! self::$_MSG_PROCESSOR instanceof EE_Messages_Processor) { |
|
| 470 | - EE_Registry::instance()->load_core('Request_Handler'); |
|
| 471 | - self::set_autoloaders(); |
|
| 472 | - self::$_EEMSG = EE_Registry::instance()->load_lib('messages'); |
|
| 473 | - self::$_MSG_PROCESSOR = EE_Registry::instance()->load_lib('Messages_Processor'); |
|
| 474 | - self::$_message_resource_manager = EE_Registry::instance()->load_lib('Message_Resource_Manager'); |
|
| 475 | - } |
|
| 476 | - } |
|
| 477 | - |
|
| 478 | - |
|
| 479 | - /** |
|
| 480 | - * @param EE_Transaction $transaction |
|
| 481 | - * @throws EE_Error |
|
| 482 | - * @throws InvalidArgumentException |
|
| 483 | - * @throws InvalidDataTypeException |
|
| 484 | - * @throws InvalidInterfaceException |
|
| 485 | - * @throws ReflectionException |
|
| 486 | - */ |
|
| 487 | - public static function payment_reminder(EE_Transaction $transaction) |
|
| 488 | - { |
|
| 489 | - self::_load_controller(); |
|
| 490 | - $data = array($transaction, null); |
|
| 491 | - self::$_MSG_PROCESSOR->generate_for_all_active_messengers('payment_reminder', $data); |
|
| 492 | - } |
|
| 493 | - |
|
| 494 | - |
|
| 495 | - /** |
|
| 496 | - * Any messages triggers for after successful gateway payments should go in here. |
|
| 497 | - * |
|
| 498 | - * @param EE_Transaction $transaction object |
|
| 499 | - * @param EE_Payment|null $payment object |
|
| 500 | - * @return void |
|
| 501 | - * @throws EE_Error |
|
| 502 | - * @throws InvalidArgumentException |
|
| 503 | - * @throws ReflectionException |
|
| 504 | - * @throws InvalidDataTypeException |
|
| 505 | - * @throws InvalidInterfaceException |
|
| 506 | - */ |
|
| 507 | - public static function payment(EE_Transaction $transaction, EE_Payment $payment = null) |
|
| 508 | - { |
|
| 509 | - // if there's no payment object, then we cannot do a payment type message! |
|
| 510 | - if (! $payment instanceof EE_Payment) { |
|
| 511 | - return; |
|
| 512 | - } |
|
| 513 | - self::_load_controller(); |
|
| 514 | - $data = array($transaction, $payment); |
|
| 515 | - EE_Registry::instance()->load_helper('MSG_Template'); |
|
| 516 | - $message_type = EEH_MSG_Template::convert_payment_status_to_message_type($payment->STS_ID()); |
|
| 517 | - // if payment amount is less than 0 then switch to payment_refund message type. |
|
| 518 | - $message_type = $payment->amount() < 0 ? 'payment_refund' : $message_type; |
|
| 519 | - self::$_MSG_PROCESSOR->generate_for_all_active_messengers($message_type, $data); |
|
| 520 | - } |
|
| 521 | - |
|
| 522 | - |
|
| 523 | - /** |
|
| 524 | - * @param EE_Transaction $transaction |
|
| 525 | - * @throws EE_Error |
|
| 526 | - * @throws InvalidArgumentException |
|
| 527 | - * @throws InvalidDataTypeException |
|
| 528 | - * @throws InvalidInterfaceException |
|
| 529 | - * @throws ReflectionException |
|
| 530 | - */ |
|
| 531 | - public static function cancelled_registration(EE_Transaction $transaction) |
|
| 532 | - { |
|
| 533 | - self::_load_controller(); |
|
| 534 | - $data = array($transaction, null); |
|
| 535 | - self::$_MSG_PROCESSOR->generate_for_all_active_messengers('cancelled_registration', $data); |
|
| 536 | - } |
|
| 537 | - |
|
| 538 | - |
|
| 539 | - /** |
|
| 540 | - * Trigger for Registration messages |
|
| 541 | - * Note that what registration message type is sent depends on what the reg status is for the registrations on the |
|
| 542 | - * incoming transaction. |
|
| 543 | - * |
|
| 544 | - * @param EE_Registration $registration |
|
| 545 | - * @param array $extra_details |
|
| 546 | - * @return void |
|
| 547 | - * @throws EE_Error |
|
| 548 | - * @throws InvalidArgumentException |
|
| 549 | - * @throws InvalidDataTypeException |
|
| 550 | - * @throws InvalidInterfaceException |
|
| 551 | - * @throws ReflectionException |
|
| 552 | - * @throws EntityNotFoundException |
|
| 553 | - */ |
|
| 554 | - public static function maybe_registration(EE_Registration $registration, $extra_details = array()) |
|
| 555 | - { |
|
| 556 | - |
|
| 557 | - if (! self::_verify_registration_notification_send($registration, $extra_details)) { |
|
| 558 | - // no messages please |
|
| 559 | - return; |
|
| 560 | - } |
|
| 561 | - |
|
| 562 | - // get all non-trashed registrations so we make sure we send messages for the right status. |
|
| 563 | - $all_registrations = $registration->transaction()->registrations( |
|
| 564 | - array( |
|
| 565 | - array('REG_deleted' => false), |
|
| 566 | - 'order_by' => array( |
|
| 567 | - 'Event.EVT_name' => 'ASC', |
|
| 568 | - 'Attendee.ATT_lname' => 'ASC', |
|
| 569 | - 'Attendee.ATT_fname' => 'ASC', |
|
| 570 | - ), |
|
| 571 | - ) |
|
| 572 | - ); |
|
| 573 | - // cached array of statuses so we only trigger messages once per status. |
|
| 574 | - $statuses_sent = array(); |
|
| 575 | - self::_load_controller(); |
|
| 576 | - $mtgs = array(); |
|
| 577 | - |
|
| 578 | - // loop through registrations and trigger messages once per status. |
|
| 579 | - foreach ($all_registrations as $reg) { |
|
| 580 | - // already triggered? |
|
| 581 | - if (in_array($reg->status_ID(), $statuses_sent)) { |
|
| 582 | - continue; |
|
| 583 | - } |
|
| 584 | - |
|
| 585 | - $message_type = EEH_MSG_Template::convert_reg_status_to_message_type($reg->status_ID()); |
|
| 586 | - $mtgs = array_merge( |
|
| 587 | - $mtgs, |
|
| 588 | - self::$_MSG_PROCESSOR->setup_mtgs_for_all_active_messengers( |
|
| 589 | - $message_type, |
|
| 590 | - array($registration->transaction(), null, $reg->status_ID()) |
|
| 591 | - ) |
|
| 592 | - ); |
|
| 593 | - $statuses_sent[] = $reg->status_ID(); |
|
| 594 | - } |
|
| 595 | - |
|
| 596 | - if (count($statuses_sent) > 1) { |
|
| 597 | - $mtgs = array_merge( |
|
| 598 | - $mtgs, |
|
| 599 | - self::$_MSG_PROCESSOR->setup_mtgs_for_all_active_messengers( |
|
| 600 | - 'registration_summary', |
|
| 601 | - array($registration->transaction(), null) |
|
| 602 | - ) |
|
| 603 | - ); |
|
| 604 | - } |
|
| 605 | - |
|
| 606 | - // batch queue and initiate request |
|
| 607 | - self::$_MSG_PROCESSOR->batch_queue_for_generation_and_persist($mtgs); |
|
| 608 | - self::$_MSG_PROCESSOR->get_queue()->initiate_request_by_priority(); |
|
| 609 | - } |
|
| 610 | - |
|
| 611 | - |
|
| 612 | - /** |
|
| 613 | - * This is a helper method used to very whether a registration notification should be sent or |
|
| 614 | - * not. Prevents duplicate notifications going out for registration context notifications. |
|
| 615 | - * |
|
| 616 | - * @param EE_Registration $registration [description] |
|
| 617 | - * @param array $extra_details [description] |
|
| 618 | - * @return bool true = send away, false = nope halt the presses. |
|
| 619 | - */ |
|
| 620 | - protected static function _verify_registration_notification_send( |
|
| 621 | - EE_Registration $registration, |
|
| 622 | - $extra_details = array() |
|
| 623 | - ) { |
|
| 624 | - if (! $registration->is_primary_registrant()) { |
|
| 625 | - return false; |
|
| 626 | - } |
|
| 627 | - // first we check if we're in admin and not doing front ajax |
|
| 628 | - if (is_admin() && ! EE_FRONT_AJAX) { |
|
| 629 | - // make sure appropriate admin params are set for sending messages |
|
| 630 | - if (empty($_REQUEST['txn_reg_status_change']['send_notifications']) |
|
| 631 | - || ! absint($_REQUEST['txn_reg_status_change']['send_notifications']) |
|
| 632 | - ) { |
|
| 633 | - // no messages sent please. |
|
| 634 | - return false; |
|
| 635 | - } |
|
| 636 | - } else { |
|
| 637 | - // frontend request (either regular or via AJAX) |
|
| 638 | - // TXN is NOT finalized ? |
|
| 639 | - if (! isset($extra_details['finalized']) || $extra_details['finalized'] === false) { |
|
| 640 | - return false; |
|
| 641 | - } |
|
| 642 | - // return visit but nothing changed ??? |
|
| 643 | - if (isset($extra_details['revisit'], $extra_details['status_updates']) && |
|
| 644 | - $extra_details['revisit'] && ! $extra_details['status_updates'] |
|
| 645 | - ) { |
|
| 646 | - return false; |
|
| 647 | - } |
|
| 648 | - // NOT sending messages && reg status is something other than "Not-Approved" |
|
| 649 | - if (! apply_filters('FHEE__EED_Messages___maybe_registration__deliver_notifications', false) && |
|
| 650 | - $registration->status_ID() !== EEM_Registration::status_id_not_approved |
|
| 651 | - ) { |
|
| 652 | - return false; |
|
| 653 | - } |
|
| 654 | - } |
|
| 655 | - // release the kraken |
|
| 656 | - return true; |
|
| 657 | - } |
|
| 658 | - |
|
| 659 | - |
|
| 660 | - /** |
|
| 661 | - * Simply returns an array indexed by Registration Status ID and the related message_type name associated with that |
|
| 662 | - * status id. |
|
| 663 | - * |
|
| 664 | - * @deprecated 4.9.0 Use EEH_MSG_Template::reg_status_to_message_type_array() |
|
| 665 | - * or EEH_MSG_Template::convert_reg_status_to_message_type |
|
| 666 | - * @param string $reg_status |
|
| 667 | - * @return array |
|
| 668 | - * @throws EE_Error |
|
| 669 | - * @throws InvalidArgumentException |
|
| 670 | - * @throws ReflectionException |
|
| 671 | - * @throws InvalidDataTypeException |
|
| 672 | - * @throws InvalidInterfaceException |
|
| 673 | - */ |
|
| 674 | - protected static function _get_reg_status_array($reg_status = '') |
|
| 675 | - { |
|
| 676 | - EE_Registry::instance()->load_helper('MSG_Template'); |
|
| 677 | - return EEH_MSG_Template::convert_reg_status_to_message_type($reg_status) |
|
| 678 | - ? EEH_MSG_Template::convert_reg_status_to_message_type($reg_status) |
|
| 679 | - : EEH_MSG_Template::reg_status_to_message_type_array(); |
|
| 680 | - } |
|
| 681 | - |
|
| 682 | - |
|
| 683 | - /** |
|
| 684 | - * Simply returns the payment message type for the given payment status. |
|
| 685 | - * |
|
| 686 | - * @deprecated 4.9.0 Use EEH_MSG_Template::payment_status_to_message_type_array |
|
| 687 | - * or EEH_MSG_Template::convert_payment_status_to_message_type |
|
| 688 | - * @param string $payment_status The payment status being matched. |
|
| 689 | - * @return bool|string The payment message type slug matching the status or false if no match. |
|
| 690 | - * @throws EE_Error |
|
| 691 | - * @throws InvalidArgumentException |
|
| 692 | - * @throws ReflectionException |
|
| 693 | - * @throws InvalidDataTypeException |
|
| 694 | - * @throws InvalidInterfaceException |
|
| 695 | - */ |
|
| 696 | - protected static function _get_payment_message_type($payment_status) |
|
| 697 | - { |
|
| 698 | - EE_Registry::instance()->load_helper('MSG_Template'); |
|
| 699 | - return EEH_MSG_Template::convert_payment_status_to_message_type($payment_status) |
|
| 700 | - ? EEH_MSG_Template::convert_payment_status_to_message_type($payment_status) |
|
| 701 | - : false; |
|
| 702 | - } |
|
| 703 | - |
|
| 704 | - |
|
| 705 | - /** |
|
| 706 | - * Message triggers for a resending already sent message(s) (via EE_Message list table) |
|
| 707 | - * |
|
| 708 | - * @access public |
|
| 709 | - * @param array $req_data This is the $_POST & $_GET data sent from EE_Admin Pages |
|
| 710 | - * @return bool success/fail |
|
| 711 | - * @throws EE_Error |
|
| 712 | - * @throws InvalidArgumentException |
|
| 713 | - * @throws InvalidDataTypeException |
|
| 714 | - * @throws InvalidInterfaceException |
|
| 715 | - * @throws ReflectionException |
|
| 716 | - */ |
|
| 717 | - public static function process_resend($req_data) |
|
| 718 | - { |
|
| 719 | - self::_load_controller(); |
|
| 720 | - |
|
| 721 | - // if $msgID in this request then skip to the new resend_message |
|
| 722 | - if (EE_Registry::instance()->REQ->get('MSG_ID')) { |
|
| 723 | - return self::resend_message(); |
|
| 724 | - } |
|
| 725 | - |
|
| 726 | - // make sure any incoming request data is set on the REQ so that it gets picked up later. |
|
| 727 | - $req_data = (array) $req_data; |
|
| 728 | - foreach ($req_data as $request_key => $request_value) { |
|
| 729 | - EE_Registry::instance()->REQ->set($request_key, $request_value); |
|
| 730 | - } |
|
| 731 | - |
|
| 732 | - if (! $messages_to_send = self::$_MSG_PROCESSOR->setup_messages_to_generate_from_registration_ids_in_request( |
|
| 733 | - )) { |
|
| 734 | - return false; |
|
| 735 | - } |
|
| 736 | - |
|
| 737 | - try { |
|
| 738 | - self::$_MSG_PROCESSOR->batch_queue_for_generation_and_persist($messages_to_send); |
|
| 739 | - self::$_MSG_PROCESSOR->get_queue()->initiate_request_by_priority(); |
|
| 740 | - } catch (EE_Error $e) { |
|
| 741 | - EE_Error::add_error($e->getMessage(), __FILE__, __FUNCTION__, __LINE__); |
|
| 742 | - return false; |
|
| 743 | - } |
|
| 744 | - EE_Error::add_success( |
|
| 745 | - __('Messages have been successfully queued for generation and sending.', 'event_espresso') |
|
| 746 | - ); |
|
| 747 | - return true; // everything got queued. |
|
| 748 | - } |
|
| 749 | - |
|
| 750 | - |
|
| 751 | - /** |
|
| 752 | - * Message triggers for a resending already sent message(s) (via EE_Message list table) |
|
| 753 | - * |
|
| 754 | - * @return bool |
|
| 755 | - * @throws EE_Error |
|
| 756 | - * @throws InvalidArgumentException |
|
| 757 | - * @throws InvalidDataTypeException |
|
| 758 | - * @throws InvalidInterfaceException |
|
| 759 | - * @throws ReflectionException |
|
| 760 | - */ |
|
| 761 | - public static function resend_message() |
|
| 762 | - { |
|
| 763 | - self::_load_controller(); |
|
| 764 | - |
|
| 765 | - $msgID = EE_Registry::instance()->REQ->get('MSG_ID'); |
|
| 766 | - if (! $msgID) { |
|
| 767 | - EE_Error::add_error( |
|
| 768 | - __( |
|
| 769 | - 'Something went wrong because there is no "MSG_ID" value in the request', |
|
| 770 | - 'event_espresso' |
|
| 771 | - ), |
|
| 772 | - __FILE__, |
|
| 773 | - __FUNCTION__, |
|
| 774 | - __LINE__ |
|
| 775 | - ); |
|
| 776 | - return false; |
|
| 777 | - } |
|
| 778 | - |
|
| 779 | - self::$_MSG_PROCESSOR->setup_messages_from_ids_and_send((array) $msgID); |
|
| 780 | - |
|
| 781 | - // setup success message. |
|
| 782 | - $count_ready_for_resend = self::$_MSG_PROCESSOR->get_queue()->count_STS_in_queue(EEM_Message::status_resend); |
|
| 783 | - EE_Error::add_success( |
|
| 784 | - sprintf( |
|
| 785 | - _n( |
|
| 786 | - 'There was %d message queued for resending.', |
|
| 787 | - 'There were %d messages queued for resending.', |
|
| 788 | - $count_ready_for_resend, |
|
| 789 | - 'event_espresso' |
|
| 790 | - ), |
|
| 791 | - $count_ready_for_resend |
|
| 792 | - ) |
|
| 793 | - ); |
|
| 794 | - return true; |
|
| 795 | - } |
|
| 796 | - |
|
| 797 | - |
|
| 798 | - /** |
|
| 799 | - * Message triggers for manual payment applied by admin |
|
| 800 | - * |
|
| 801 | - * @param EE_Payment $payment EE_payment object |
|
| 802 | - * @return bool success/fail |
|
| 803 | - * @throws EE_Error |
|
| 804 | - * @throws InvalidArgumentException |
|
| 805 | - * @throws ReflectionException |
|
| 806 | - * @throws InvalidDataTypeException |
|
| 807 | - * @throws InvalidInterfaceException |
|
| 808 | - */ |
|
| 809 | - public static function process_admin_payment(EE_Payment $payment) |
|
| 810 | - { |
|
| 811 | - EE_Registry::instance()->load_helper('MSG_Template'); |
|
| 812 | - // we need to get the transaction object |
|
| 813 | - $transaction = $payment->transaction(); |
|
| 814 | - if ($transaction instanceof EE_Transaction) { |
|
| 815 | - $data = array($transaction, $payment); |
|
| 816 | - $message_type = EEH_MSG_Template::convert_payment_status_to_message_type($payment->STS_ID()); |
|
| 817 | - |
|
| 818 | - // if payment amount is less than 0 then switch to payment_refund message type. |
|
| 819 | - $message_type = $payment->amount() < 0 ? 'payment_refund' : $message_type; |
|
| 820 | - |
|
| 821 | - // if payment_refund is selected, but the status is NOT accepted. Then change message type to false so NO message notification goes out. |
|
| 822 | - $message_type = $message_type == 'payment_refund' && $payment->STS_ID() != EEM_Payment::status_id_approved |
|
| 823 | - ? false : $message_type; |
|
| 824 | - |
|
| 825 | - self::_load_controller(); |
|
| 826 | - |
|
| 827 | - self::$_MSG_PROCESSOR->generate_for_all_active_messengers($message_type, $data); |
|
| 828 | - |
|
| 829 | - // get count of queued for generation |
|
| 830 | - $count_to_generate = self::$_MSG_PROCESSOR->get_queue()->count_STS_in_queue( |
|
| 831 | - array( |
|
| 832 | - EEM_Message::status_incomplete, |
|
| 833 | - EEM_Message::status_idle, |
|
| 834 | - ) |
|
| 835 | - ); |
|
| 836 | - |
|
| 837 | - if ($count_to_generate > 0 && self::$_MSG_PROCESSOR->get_queue()->get_message_repository()->count() !== 0) { |
|
| 838 | - add_filter('FHEE__EE_Admin_Page___process_admin_payment_notification__success', '__return_true'); |
|
| 839 | - return true; |
|
| 840 | - } else { |
|
| 841 | - $count_failed = self::$_MSG_PROCESSOR->get_queue()->count_STS_in_queue( |
|
| 842 | - EEM_Message::instance()->stati_indicating_failed_sending() |
|
| 843 | - ); |
|
| 844 | - /** |
|
| 845 | - * Verify that there are actually errors. If not then we return a success message because the queue might have been emptied due to successful |
|
| 846 | - * IMMEDIATE generation. |
|
| 847 | - */ |
|
| 848 | - if ($count_failed > 0) { |
|
| 849 | - EE_Error::add_error( |
|
| 850 | - sprintf( |
|
| 851 | - _n( |
|
| 852 | - 'The payment notification generation failed.', |
|
| 853 | - '%d payment notifications failed being sent.', |
|
| 854 | - $count_failed, |
|
| 855 | - 'event_espresso' |
|
| 856 | - ), |
|
| 857 | - $count_failed |
|
| 858 | - ), |
|
| 859 | - __FILE__, |
|
| 860 | - __FUNCTION__, |
|
| 861 | - __LINE__ |
|
| 862 | - ); |
|
| 863 | - |
|
| 864 | - return false; |
|
| 865 | - } else { |
|
| 866 | - add_filter('FHEE__EE_Admin_Page___process_admin_payment_notification__success', '__return_true'); |
|
| 867 | - return true; |
|
| 868 | - } |
|
| 869 | - } |
|
| 870 | - } else { |
|
| 871 | - EE_Error::add_error( |
|
| 872 | - 'Unable to generate the payment notification because the given value for the transaction is invalid.', |
|
| 873 | - 'event_espresso' |
|
| 874 | - ); |
|
| 875 | - return false; |
|
| 876 | - } |
|
| 877 | - } |
|
| 878 | - |
|
| 879 | - |
|
| 880 | - /** |
|
| 881 | - * Callback for AHEE__Extend_Registrations_Admin_Page___newsletter_selected_send_with_registrations trigger |
|
| 882 | - * |
|
| 883 | - * @since 4.3.0 |
|
| 884 | - * @param EE_Registration[] $registrations an array of EE_Registration objects |
|
| 885 | - * @param int $grp_id a specific message template group id. |
|
| 886 | - * @return void |
|
| 887 | - * @throws EE_Error |
|
| 888 | - * @throws InvalidArgumentException |
|
| 889 | - * @throws InvalidDataTypeException |
|
| 890 | - * @throws InvalidInterfaceException |
|
| 891 | - * @throws ReflectionException |
|
| 892 | - */ |
|
| 893 | - public static function send_newsletter_message($registrations, $grp_id) |
|
| 894 | - { |
|
| 895 | - // make sure mtp is id and set it in the EE_Request Handler later messages setup. |
|
| 896 | - EE_Registry::instance()->REQ->set('GRP_ID', (int) $grp_id); |
|
| 897 | - self::_load_controller(); |
|
| 898 | - self::$_MSG_PROCESSOR->generate_for_all_active_messengers('newsletter', $registrations); |
|
| 899 | - } |
|
| 900 | - |
|
| 901 | - |
|
| 902 | - /** |
|
| 903 | - * Callback for FHEE__EE_Registration__invoice_url__invoice_url or FHEE__EE_Registration__receipt_url__receipt_url |
|
| 904 | - * |
|
| 905 | - * @since 4.3.0 |
|
| 906 | - * @param string $registration_message_trigger_url |
|
| 907 | - * @param EE_Registration $registration |
|
| 908 | - * @param string $messenger |
|
| 909 | - * @param string $message_type |
|
| 910 | - * @return string |
|
| 911 | - * @throws EE_Error |
|
| 912 | - * @throws InvalidArgumentException |
|
| 913 | - * @throws InvalidDataTypeException |
|
| 914 | - * @throws InvalidInterfaceException |
|
| 915 | - */ |
|
| 916 | - public static function registration_message_trigger_url( |
|
| 917 | - $registration_message_trigger_url, |
|
| 918 | - EE_Registration $registration, |
|
| 919 | - $messenger = 'html', |
|
| 920 | - $message_type = 'invoice' |
|
| 921 | - ) { |
|
| 922 | - // whitelist $messenger |
|
| 923 | - switch ($messenger) { |
|
| 924 | - case 'pdf': |
|
| 925 | - $sending_messenger = 'pdf'; |
|
| 926 | - $generating_messenger = 'html'; |
|
| 927 | - break; |
|
| 928 | - case 'html': |
|
| 929 | - default: |
|
| 930 | - $sending_messenger = 'html'; |
|
| 931 | - $generating_messenger = 'html'; |
|
| 932 | - break; |
|
| 933 | - } |
|
| 934 | - // whitelist $message_type |
|
| 935 | - switch ($message_type) { |
|
| 936 | - case 'receipt': |
|
| 937 | - $message_type = 'receipt'; |
|
| 938 | - break; |
|
| 939 | - case 'invoice': |
|
| 940 | - default: |
|
| 941 | - $message_type = 'invoice'; |
|
| 942 | - break; |
|
| 943 | - } |
|
| 944 | - // verify that both the messenger AND the message type are active |
|
| 945 | - if (EEH_MSG_Template::is_messenger_active($sending_messenger) |
|
| 946 | - && EEH_MSG_Template::is_mt_active($message_type) |
|
| 947 | - ) { |
|
| 948 | - // need to get the correct message template group for this (i.e. is there a custom invoice for the event this registration is registered for?) |
|
| 949 | - $template_query_params = array( |
|
| 950 | - 'MTP_is_active' => true, |
|
| 951 | - 'MTP_messenger' => $generating_messenger, |
|
| 952 | - 'MTP_message_type' => $message_type, |
|
| 953 | - 'Event.EVT_ID' => $registration->event_ID(), |
|
| 954 | - ); |
|
| 955 | - // get the message template group. |
|
| 956 | - $msg_template_group = EEM_Message_Template_Group::instance()->get_one(array($template_query_params)); |
|
| 957 | - // if we don't have an EE_Message_Template_Group then return |
|
| 958 | - if (! $msg_template_group instanceof EE_Message_Template_Group) { |
|
| 959 | - // remove EVT_ID from query params so that global templates get picked up |
|
| 960 | - unset($template_query_params['Event.EVT_ID']); |
|
| 961 | - // get global template as the fallback |
|
| 962 | - $msg_template_group = EEM_Message_Template_Group::instance()->get_one(array($template_query_params)); |
|
| 963 | - } |
|
| 964 | - // if we don't have an EE_Message_Template_Group then return |
|
| 965 | - if (! $msg_template_group instanceof EE_Message_Template_Group) { |
|
| 966 | - return ''; |
|
| 967 | - } |
|
| 968 | - // generate the URL |
|
| 969 | - $registration_message_trigger_url = EEH_MSG_Template::generate_url_trigger( |
|
| 970 | - $sending_messenger, |
|
| 971 | - $generating_messenger, |
|
| 972 | - 'purchaser', |
|
| 973 | - $message_type, |
|
| 974 | - $registration, |
|
| 975 | - $msg_template_group->ID(), |
|
| 976 | - $registration->transaction_ID() |
|
| 977 | - ); |
|
| 978 | - } |
|
| 979 | - return $registration_message_trigger_url; |
|
| 980 | - } |
|
| 981 | - |
|
| 982 | - |
|
| 983 | - /** |
|
| 984 | - * Use to generate and return a message preview! |
|
| 985 | - * |
|
| 986 | - * @param string $type This should correspond with a valid message type |
|
| 987 | - * @param string $context This should correspond with a valid context for the message type |
|
| 988 | - * @param string $messenger This should correspond with a valid messenger. |
|
| 989 | - * @param bool $send true we will do a test send using the messenger delivery, false we just do a regular |
|
| 990 | - * preview |
|
| 991 | - * @return bool|string The body of the message or if send is requested, sends. |
|
| 992 | - * @throws EE_Error |
|
| 993 | - * @throws InvalidArgumentException |
|
| 994 | - * @throws InvalidDataTypeException |
|
| 995 | - * @throws InvalidInterfaceException |
|
| 996 | - * @throws ReflectionException |
|
| 997 | - */ |
|
| 998 | - public static function preview_message($type, $context, $messenger, $send = false) |
|
| 999 | - { |
|
| 1000 | - self::_load_controller(); |
|
| 1001 | - $mtg = new EE_Message_To_Generate( |
|
| 1002 | - $messenger, |
|
| 1003 | - $type, |
|
| 1004 | - array(), |
|
| 1005 | - $context, |
|
| 1006 | - true |
|
| 1007 | - ); |
|
| 1008 | - $generated_preview_queue = self::$_MSG_PROCESSOR->generate_for_preview($mtg, $send); |
|
| 1009 | - if ($generated_preview_queue instanceof EE_Messages_Queue) { |
|
| 1010 | - // loop through all content for the preview and remove any persisted records. |
|
| 1011 | - $content = ''; |
|
| 1012 | - foreach ($generated_preview_queue->get_message_repository() as $message) { |
|
| 1013 | - $content = $message->content(); |
|
| 1014 | - if ($message->ID() > 0 && $message->STS_ID() !== EEM_Message::status_failed) { |
|
| 1015 | - $message->delete(); |
|
| 1016 | - } |
|
| 1017 | - } |
|
| 1018 | - return $content; |
|
| 1019 | - } else { |
|
| 1020 | - return $generated_preview_queue; |
|
| 1021 | - } |
|
| 1022 | - } |
|
| 1023 | - |
|
| 1024 | - |
|
| 1025 | - /** |
|
| 1026 | - * This is a method that allows for sending a message using a messenger matching the string given and the provided |
|
| 1027 | - * EE_Message_Queue object. The EE_Message_Queue object is used to create a single aggregate EE_Message via the |
|
| 1028 | - * content found in the EE_Message objects in the queue. |
|
| 1029 | - * |
|
| 1030 | - * @since 4.9.0 |
|
| 1031 | - * @param string $messenger a string matching a valid active messenger in the system |
|
| 1032 | - * @param string $message_type Although it seems contrary to the name of the method, a message |
|
| 1033 | - * type name is still required to send along the message type to the |
|
| 1034 | - * messenger because this is used for determining what specific |
|
| 1035 | - * variations might be loaded for the generated message. |
|
| 1036 | - * @param EE_Messages_Queue $queue |
|
| 1037 | - * @param string $custom_subject Can be used to set what the custom subject string will be on the |
|
| 1038 | - * aggregate EE_Message object. |
|
| 1039 | - * @return bool success or fail. |
|
| 1040 | - * @throws EE_Error |
|
| 1041 | - * @throws InvalidArgumentException |
|
| 1042 | - * @throws ReflectionException |
|
| 1043 | - * @throws InvalidDataTypeException |
|
| 1044 | - * @throws InvalidInterfaceException |
|
| 1045 | - */ |
|
| 1046 | - public static function send_message_with_messenger_only( |
|
| 1047 | - $messenger, |
|
| 1048 | - $message_type, |
|
| 1049 | - EE_Messages_Queue $queue, |
|
| 1050 | - $custom_subject = '' |
|
| 1051 | - ) { |
|
| 1052 | - self::_load_controller(); |
|
| 1053 | - /** @type EE_Message_To_Generate_From_Queue $message_to_generate */ |
|
| 1054 | - $message_to_generate = EE_Registry::instance()->load_lib( |
|
| 1055 | - 'Message_To_Generate_From_Queue', |
|
| 1056 | - array( |
|
| 1057 | - $messenger, |
|
| 1058 | - $message_type, |
|
| 1059 | - $queue, |
|
| 1060 | - $custom_subject, |
|
| 1061 | - ) |
|
| 1062 | - ); |
|
| 1063 | - return self::$_MSG_PROCESSOR->queue_for_sending($message_to_generate); |
|
| 1064 | - } |
|
| 1065 | - |
|
| 1066 | - |
|
| 1067 | - /** |
|
| 1068 | - * Generates Messages immediately for EE_Message IDs (but only for the correct status for generation) |
|
| 1069 | - * |
|
| 1070 | - * @since 4.9.0 |
|
| 1071 | - * @param array $message_ids An array of message ids |
|
| 1072 | - * @return bool|EE_Messages_Queue false if nothing was generated, EE_Messages_Queue containing generated |
|
| 1073 | - * messages. |
|
| 1074 | - * @throws EE_Error |
|
| 1075 | - * @throws InvalidArgumentException |
|
| 1076 | - * @throws InvalidDataTypeException |
|
| 1077 | - * @throws InvalidInterfaceException |
|
| 1078 | - * @throws ReflectionException |
|
| 1079 | - */ |
|
| 1080 | - public static function generate_now($message_ids) |
|
| 1081 | - { |
|
| 1082 | - self::_load_controller(); |
|
| 1083 | - $messages = EEM_Message::instance()->get_all( |
|
| 1084 | - array( |
|
| 1085 | - 0 => array( |
|
| 1086 | - 'MSG_ID' => array('IN', $message_ids), |
|
| 1087 | - 'STS_ID' => EEM_Message::status_incomplete, |
|
| 1088 | - ), |
|
| 1089 | - ) |
|
| 1090 | - ); |
|
| 1091 | - $generated_queue = false; |
|
| 1092 | - if ($messages) { |
|
| 1093 | - $generated_queue = self::$_MSG_PROCESSOR->batch_generate_from_queue($messages); |
|
| 1094 | - } |
|
| 1095 | - |
|
| 1096 | - if (! $generated_queue instanceof EE_Messages_Queue) { |
|
| 1097 | - EE_Error::add_error( |
|
| 1098 | - __( |
|
| 1099 | - 'The messages were not generated. This could mean there is already a batch being generated on a separate request, or because the selected messages are not ready for generation. Please wait a minute or two and try again.', |
|
| 1100 | - 'event_espresso' |
|
| 1101 | - ), |
|
| 1102 | - __FILE__, |
|
| 1103 | - __FUNCTION__, |
|
| 1104 | - __LINE__ |
|
| 1105 | - ); |
|
| 1106 | - } |
|
| 1107 | - return $generated_queue; |
|
| 1108 | - } |
|
| 1109 | - |
|
| 1110 | - |
|
| 1111 | - /** |
|
| 1112 | - * Sends messages immediately for the incoming message_ids that have the status of EEM_Message::status_resend or, |
|
| 1113 | - * EEM_Message::status_idle |
|
| 1114 | - * |
|
| 1115 | - * @since 4.9.0 |
|
| 1116 | - * @param $message_ids |
|
| 1117 | - * @return bool|EE_Messages_Queue false if no messages sent. |
|
| 1118 | - * @throws EE_Error |
|
| 1119 | - * @throws InvalidArgumentException |
|
| 1120 | - * @throws InvalidDataTypeException |
|
| 1121 | - * @throws InvalidInterfaceException |
|
| 1122 | - * @throws ReflectionException |
|
| 1123 | - */ |
|
| 1124 | - public static function send_now($message_ids) |
|
| 1125 | - { |
|
| 1126 | - self::_load_controller(); |
|
| 1127 | - $messages = EEM_Message::instance()->get_all( |
|
| 1128 | - array( |
|
| 1129 | - 0 => array( |
|
| 1130 | - 'MSG_ID' => array('IN', $message_ids), |
|
| 1131 | - 'STS_ID' => array( |
|
| 1132 | - 'IN', |
|
| 1133 | - array(EEM_Message::status_idle, EEM_Message::status_resend, EEM_Message::status_retry), |
|
| 1134 | - ), |
|
| 1135 | - ), |
|
| 1136 | - ) |
|
| 1137 | - ); |
|
| 1138 | - $sent_queue = false; |
|
| 1139 | - if ($messages) { |
|
| 1140 | - $sent_queue = self::$_MSG_PROCESSOR->batch_send_from_queue($messages); |
|
| 1141 | - } |
|
| 1142 | - |
|
| 1143 | - if (! $sent_queue instanceof EE_Messages_Queue) { |
|
| 1144 | - EE_Error::add_error( |
|
| 1145 | - __( |
|
| 1146 | - 'The messages were not sent. This could mean there is already a batch being sent on a separate request, or because the selected messages are not sendable. Please wait a minute or two and try again.', |
|
| 1147 | - 'event_espresso' |
|
| 1148 | - ), |
|
| 1149 | - __FILE__, |
|
| 1150 | - __FUNCTION__, |
|
| 1151 | - __LINE__ |
|
| 1152 | - ); |
|
| 1153 | - } else { |
|
| 1154 | - // can count how many sent by using the messages in the queue |
|
| 1155 | - $sent_count = $sent_queue->count_STS_in_queue(EEM_Message::instance()->stati_indicating_sent()); |
|
| 1156 | - if ($sent_count > 0) { |
|
| 1157 | - EE_Error::add_success( |
|
| 1158 | - sprintf( |
|
| 1159 | - _n( |
|
| 1160 | - 'There was %d message successfully sent.', |
|
| 1161 | - 'There were %d messages successfully sent.', |
|
| 1162 | - $sent_count, |
|
| 1163 | - 'event_espresso' |
|
| 1164 | - ), |
|
| 1165 | - $sent_count |
|
| 1166 | - ) |
|
| 1167 | - ); |
|
| 1168 | - } else { |
|
| 1169 | - EE_Error::overwrite_errors(); |
|
| 1170 | - EE_Error::add_error( |
|
| 1171 | - __( |
|
| 1172 | - 'No message was sent because of problems with sending. Either all the messages you selected were not a sendable message, they were ALREADY sent on a different scheduled task, or there was an error. |
|
| 259 | + exit; |
|
| 260 | + } |
|
| 261 | + } |
|
| 262 | + return; |
|
| 263 | + } |
|
| 264 | + |
|
| 265 | + |
|
| 266 | + /** |
|
| 267 | + * This runs when the msg_url_trigger route has initiated. |
|
| 268 | + * |
|
| 269 | + * @since 4.5.0 |
|
| 270 | + * @param WP $WP |
|
| 271 | + * @throws EE_Error |
|
| 272 | + * @throws InvalidArgumentException |
|
| 273 | + * @throws ReflectionException |
|
| 274 | + * @throws InvalidDataTypeException |
|
| 275 | + * @throws InvalidInterfaceException |
|
| 276 | + */ |
|
| 277 | + public function run($WP) |
|
| 278 | + { |
|
| 279 | + // ensure controller is loaded |
|
| 280 | + self::_load_controller(); |
|
| 281 | + // attempt to process message |
|
| 282 | + try { |
|
| 283 | + /** @type EE_Message_To_Generate_From_Request $message_to_generate */ |
|
| 284 | + $message_to_generate = EE_Registry::instance()->load_lib('Message_To_Generate_From_Request'); |
|
| 285 | + self::$_MSG_PROCESSOR->generate_and_send_now($message_to_generate); |
|
| 286 | + } catch (EE_Error $e) { |
|
| 287 | + $error_msg = __( |
|
| 288 | + 'Please note that a system message failed to send due to a technical issue.', |
|
| 289 | + 'event_espresso' |
|
| 290 | + ); |
|
| 291 | + // add specific message for developers if WP_DEBUG in on |
|
| 292 | + $error_msg .= '||' . $e->getMessage(); |
|
| 293 | + EE_Error::add_error($error_msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 294 | + } |
|
| 295 | + } |
|
| 296 | + |
|
| 297 | + |
|
| 298 | + /** |
|
| 299 | + * This is triggered by the 'msg_cron_trigger' route. |
|
| 300 | + * |
|
| 301 | + * @param WP $WP |
|
| 302 | + */ |
|
| 303 | + public function execute_batch_request($WP) |
|
| 304 | + { |
|
| 305 | + $this->run_cron(); |
|
| 306 | + header('HTTP/1.1 200 OK'); |
|
| 307 | + exit(); |
|
| 308 | + } |
|
| 309 | + |
|
| 310 | + |
|
| 311 | + /** |
|
| 312 | + * This gets executed on wp_cron jobs or when a batch request is initiated on its own separate non regular wp |
|
| 313 | + * request. |
|
| 314 | + */ |
|
| 315 | + public function run_cron() |
|
| 316 | + { |
|
| 317 | + self::_load_controller(); |
|
| 318 | + // get required vars |
|
| 319 | + $cron_type = EE_Registry::instance()->REQ->get('type'); |
|
| 320 | + $transient_key = EE_Registry::instance()->REQ->get('key'); |
|
| 321 | + |
|
| 322 | + // now let's verify transient, if not valid exit immediately |
|
| 323 | + if (! get_transient($transient_key)) { |
|
| 324 | + /** |
|
| 325 | + * trigger error so this gets in the error logs. This is important because it happens on a non-user |
|
| 326 | + * request. |
|
| 327 | + */ |
|
| 328 | + trigger_error(esc_attr__('Invalid Request (Transient does not exist)', 'event_espresso')); |
|
| 329 | + } |
|
| 330 | + |
|
| 331 | + // if made it here, lets' delete the transient to keep the db clean |
|
| 332 | + delete_transient($transient_key); |
|
| 333 | + |
|
| 334 | + if (apply_filters('FHEE__EED_Messages__run_cron__use_wp_cron', true)) { |
|
| 335 | + $method = 'batch_' . $cron_type . '_from_queue'; |
|
| 336 | + if (method_exists(self::$_MSG_PROCESSOR, $method)) { |
|
| 337 | + self::$_MSG_PROCESSOR->$method(); |
|
| 338 | + } else { |
|
| 339 | + // no matching task |
|
| 340 | + /** |
|
| 341 | + * trigger error so this gets in the error logs. This is important because it happens on a non user |
|
| 342 | + * request. |
|
| 343 | + */ |
|
| 344 | + trigger_error( |
|
| 345 | + esc_attr( |
|
| 346 | + sprintf( |
|
| 347 | + __('There is no task corresponding to this route %s', 'event_espresso'), |
|
| 348 | + $cron_type |
|
| 349 | + ) |
|
| 350 | + ) |
|
| 351 | + ); |
|
| 352 | + } |
|
| 353 | + } |
|
| 354 | + |
|
| 355 | + do_action('FHEE__EED_Messages__run_cron__end'); |
|
| 356 | + } |
|
| 357 | + |
|
| 358 | + |
|
| 359 | + /** |
|
| 360 | + * This is used to retrieve the template pack for the given name. |
|
| 361 | + * Retrieved packs are cached on the static $_TMP_PACKS array. If there is no class matching the given name then |
|
| 362 | + * the default template pack is returned. |
|
| 363 | + * |
|
| 364 | + * @deprecated 4.9.0 @see EEH_MSG_Template::get_template_pack() |
|
| 365 | + * @param string $template_pack_name This should correspond to the dbref of the template pack (which is also used |
|
| 366 | + * in generating the Pack class name). |
|
| 367 | + * @return EE_Messages_Template_Pack |
|
| 368 | + * @throws EE_Error |
|
| 369 | + * @throws InvalidArgumentException |
|
| 370 | + * @throws ReflectionException |
|
| 371 | + * @throws InvalidDataTypeException |
|
| 372 | + * @throws InvalidInterfaceException |
|
| 373 | + */ |
|
| 374 | + public static function get_template_pack($template_pack_name) |
|
| 375 | + { |
|
| 376 | + EE_Registry::instance()->load_helper('MSG_Template'); |
|
| 377 | + return EEH_MSG_Template::get_template_pack($template_pack_name); |
|
| 378 | + } |
|
| 379 | + |
|
| 380 | + |
|
| 381 | + /** |
|
| 382 | + * Retrieves an array of all template packs. |
|
| 383 | + * Array is in the format array( 'dbref' => EE_Messages_Template_Pack ) |
|
| 384 | + * |
|
| 385 | + * @deprecated 4.9.0 @see EEH_MSG_Template_Pack::get_template_pack_collection |
|
| 386 | + * @return EE_Messages_Template_Pack[] |
|
| 387 | + * @throws EE_Error |
|
| 388 | + * @throws InvalidArgumentException |
|
| 389 | + * @throws ReflectionException |
|
| 390 | + * @throws InvalidDataTypeException |
|
| 391 | + * @throws InvalidInterfaceException |
|
| 392 | + */ |
|
| 393 | + public static function get_template_packs() |
|
| 394 | + { |
|
| 395 | + EE_Registry::instance()->load_helper('MSG_Template'); |
|
| 396 | + |
|
| 397 | + // for backward compat, let's make sure this returns in the same format as originally. |
|
| 398 | + $template_pack_collection = EEH_MSG_Template::get_template_pack_collection(); |
|
| 399 | + $template_pack_collection->rewind(); |
|
| 400 | + $template_packs = array(); |
|
| 401 | + while ($template_pack_collection->valid()) { |
|
| 402 | + $template_packs[ $template_pack_collection->current()->dbref ] = $template_pack_collection->current(); |
|
| 403 | + $template_pack_collection->next(); |
|
| 404 | + } |
|
| 405 | + return $template_packs; |
|
| 406 | + } |
|
| 407 | + |
|
| 408 | + |
|
| 409 | + /** |
|
| 410 | + * This simply makes sure the autoloaders are registered for the EE_messages system. |
|
| 411 | + * |
|
| 412 | + * @since 4.5.0 |
|
| 413 | + * @return void |
|
| 414 | + * @throws EE_Error |
|
| 415 | + */ |
|
| 416 | + public static function set_autoloaders() |
|
| 417 | + { |
|
| 418 | + if (empty(self::$_MSG_PATHS)) { |
|
| 419 | + self::_set_messages_paths(); |
|
| 420 | + foreach (self::$_MSG_PATHS as $path) { |
|
| 421 | + EEH_Autoloader::register_autoloaders_for_each_file_in_folder($path); |
|
| 422 | + } |
|
| 423 | + // add aliases |
|
| 424 | + EEH_Autoloader::add_alias('EE_messages', 'EE_messages'); |
|
| 425 | + EEH_Autoloader::add_alias('EE_messenger', 'EE_messenger'); |
|
| 426 | + } |
|
| 427 | + } |
|
| 428 | + |
|
| 429 | + |
|
| 430 | + /** |
|
| 431 | + * Take care of adding all the paths for the messages components to the $_MSG_PATHS property |
|
| 432 | + * for use by the Messages Autoloaders |
|
| 433 | + * |
|
| 434 | + * @since 4.5.0 |
|
| 435 | + * @return void. |
|
| 436 | + */ |
|
| 437 | + protected static function _set_messages_paths() |
|
| 438 | + { |
|
| 439 | + self::$_MSG_PATHS = apply_filters( |
|
| 440 | + 'FHEE__EED_Messages___set_messages_paths___MSG_PATHS', |
|
| 441 | + [ |
|
| 442 | + EE_LIBRARIES . 'messages/message_type', |
|
| 443 | + EE_LIBRARIES . 'messages/messenger', |
|
| 444 | + EE_LIBRARIES . 'messages/defaults', |
|
| 445 | + EE_LIBRARIES . 'messages/defaults/email', |
|
| 446 | + EE_LIBRARIES . 'messages/data_class', |
|
| 447 | + EE_LIBRARIES . 'messages/validators', |
|
| 448 | + EE_LIBRARIES . 'messages/validators/email', |
|
| 449 | + EE_LIBRARIES . 'messages/validators/html', |
|
| 450 | + EE_LIBRARIES . 'shortcodes', |
|
| 451 | + ] |
|
| 452 | + ); |
|
| 453 | + } |
|
| 454 | + |
|
| 455 | + |
|
| 456 | + /** |
|
| 457 | + * Takes care of loading dependencies |
|
| 458 | + * |
|
| 459 | + * @since 4.5.0 |
|
| 460 | + * @return void |
|
| 461 | + * @throws EE_Error |
|
| 462 | + * @throws InvalidArgumentException |
|
| 463 | + * @throws ReflectionException |
|
| 464 | + * @throws InvalidDataTypeException |
|
| 465 | + * @throws InvalidInterfaceException |
|
| 466 | + */ |
|
| 467 | + protected static function _load_controller() |
|
| 468 | + { |
|
| 469 | + if (! self::$_MSG_PROCESSOR instanceof EE_Messages_Processor) { |
|
| 470 | + EE_Registry::instance()->load_core('Request_Handler'); |
|
| 471 | + self::set_autoloaders(); |
|
| 472 | + self::$_EEMSG = EE_Registry::instance()->load_lib('messages'); |
|
| 473 | + self::$_MSG_PROCESSOR = EE_Registry::instance()->load_lib('Messages_Processor'); |
|
| 474 | + self::$_message_resource_manager = EE_Registry::instance()->load_lib('Message_Resource_Manager'); |
|
| 475 | + } |
|
| 476 | + } |
|
| 477 | + |
|
| 478 | + |
|
| 479 | + /** |
|
| 480 | + * @param EE_Transaction $transaction |
|
| 481 | + * @throws EE_Error |
|
| 482 | + * @throws InvalidArgumentException |
|
| 483 | + * @throws InvalidDataTypeException |
|
| 484 | + * @throws InvalidInterfaceException |
|
| 485 | + * @throws ReflectionException |
|
| 486 | + */ |
|
| 487 | + public static function payment_reminder(EE_Transaction $transaction) |
|
| 488 | + { |
|
| 489 | + self::_load_controller(); |
|
| 490 | + $data = array($transaction, null); |
|
| 491 | + self::$_MSG_PROCESSOR->generate_for_all_active_messengers('payment_reminder', $data); |
|
| 492 | + } |
|
| 493 | + |
|
| 494 | + |
|
| 495 | + /** |
|
| 496 | + * Any messages triggers for after successful gateway payments should go in here. |
|
| 497 | + * |
|
| 498 | + * @param EE_Transaction $transaction object |
|
| 499 | + * @param EE_Payment|null $payment object |
|
| 500 | + * @return void |
|
| 501 | + * @throws EE_Error |
|
| 502 | + * @throws InvalidArgumentException |
|
| 503 | + * @throws ReflectionException |
|
| 504 | + * @throws InvalidDataTypeException |
|
| 505 | + * @throws InvalidInterfaceException |
|
| 506 | + */ |
|
| 507 | + public static function payment(EE_Transaction $transaction, EE_Payment $payment = null) |
|
| 508 | + { |
|
| 509 | + // if there's no payment object, then we cannot do a payment type message! |
|
| 510 | + if (! $payment instanceof EE_Payment) { |
|
| 511 | + return; |
|
| 512 | + } |
|
| 513 | + self::_load_controller(); |
|
| 514 | + $data = array($transaction, $payment); |
|
| 515 | + EE_Registry::instance()->load_helper('MSG_Template'); |
|
| 516 | + $message_type = EEH_MSG_Template::convert_payment_status_to_message_type($payment->STS_ID()); |
|
| 517 | + // if payment amount is less than 0 then switch to payment_refund message type. |
|
| 518 | + $message_type = $payment->amount() < 0 ? 'payment_refund' : $message_type; |
|
| 519 | + self::$_MSG_PROCESSOR->generate_for_all_active_messengers($message_type, $data); |
|
| 520 | + } |
|
| 521 | + |
|
| 522 | + |
|
| 523 | + /** |
|
| 524 | + * @param EE_Transaction $transaction |
|
| 525 | + * @throws EE_Error |
|
| 526 | + * @throws InvalidArgumentException |
|
| 527 | + * @throws InvalidDataTypeException |
|
| 528 | + * @throws InvalidInterfaceException |
|
| 529 | + * @throws ReflectionException |
|
| 530 | + */ |
|
| 531 | + public static function cancelled_registration(EE_Transaction $transaction) |
|
| 532 | + { |
|
| 533 | + self::_load_controller(); |
|
| 534 | + $data = array($transaction, null); |
|
| 535 | + self::$_MSG_PROCESSOR->generate_for_all_active_messengers('cancelled_registration', $data); |
|
| 536 | + } |
|
| 537 | + |
|
| 538 | + |
|
| 539 | + /** |
|
| 540 | + * Trigger for Registration messages |
|
| 541 | + * Note that what registration message type is sent depends on what the reg status is for the registrations on the |
|
| 542 | + * incoming transaction. |
|
| 543 | + * |
|
| 544 | + * @param EE_Registration $registration |
|
| 545 | + * @param array $extra_details |
|
| 546 | + * @return void |
|
| 547 | + * @throws EE_Error |
|
| 548 | + * @throws InvalidArgumentException |
|
| 549 | + * @throws InvalidDataTypeException |
|
| 550 | + * @throws InvalidInterfaceException |
|
| 551 | + * @throws ReflectionException |
|
| 552 | + * @throws EntityNotFoundException |
|
| 553 | + */ |
|
| 554 | + public static function maybe_registration(EE_Registration $registration, $extra_details = array()) |
|
| 555 | + { |
|
| 556 | + |
|
| 557 | + if (! self::_verify_registration_notification_send($registration, $extra_details)) { |
|
| 558 | + // no messages please |
|
| 559 | + return; |
|
| 560 | + } |
|
| 561 | + |
|
| 562 | + // get all non-trashed registrations so we make sure we send messages for the right status. |
|
| 563 | + $all_registrations = $registration->transaction()->registrations( |
|
| 564 | + array( |
|
| 565 | + array('REG_deleted' => false), |
|
| 566 | + 'order_by' => array( |
|
| 567 | + 'Event.EVT_name' => 'ASC', |
|
| 568 | + 'Attendee.ATT_lname' => 'ASC', |
|
| 569 | + 'Attendee.ATT_fname' => 'ASC', |
|
| 570 | + ), |
|
| 571 | + ) |
|
| 572 | + ); |
|
| 573 | + // cached array of statuses so we only trigger messages once per status. |
|
| 574 | + $statuses_sent = array(); |
|
| 575 | + self::_load_controller(); |
|
| 576 | + $mtgs = array(); |
|
| 577 | + |
|
| 578 | + // loop through registrations and trigger messages once per status. |
|
| 579 | + foreach ($all_registrations as $reg) { |
|
| 580 | + // already triggered? |
|
| 581 | + if (in_array($reg->status_ID(), $statuses_sent)) { |
|
| 582 | + continue; |
|
| 583 | + } |
|
| 584 | + |
|
| 585 | + $message_type = EEH_MSG_Template::convert_reg_status_to_message_type($reg->status_ID()); |
|
| 586 | + $mtgs = array_merge( |
|
| 587 | + $mtgs, |
|
| 588 | + self::$_MSG_PROCESSOR->setup_mtgs_for_all_active_messengers( |
|
| 589 | + $message_type, |
|
| 590 | + array($registration->transaction(), null, $reg->status_ID()) |
|
| 591 | + ) |
|
| 592 | + ); |
|
| 593 | + $statuses_sent[] = $reg->status_ID(); |
|
| 594 | + } |
|
| 595 | + |
|
| 596 | + if (count($statuses_sent) > 1) { |
|
| 597 | + $mtgs = array_merge( |
|
| 598 | + $mtgs, |
|
| 599 | + self::$_MSG_PROCESSOR->setup_mtgs_for_all_active_messengers( |
|
| 600 | + 'registration_summary', |
|
| 601 | + array($registration->transaction(), null) |
|
| 602 | + ) |
|
| 603 | + ); |
|
| 604 | + } |
|
| 605 | + |
|
| 606 | + // batch queue and initiate request |
|
| 607 | + self::$_MSG_PROCESSOR->batch_queue_for_generation_and_persist($mtgs); |
|
| 608 | + self::$_MSG_PROCESSOR->get_queue()->initiate_request_by_priority(); |
|
| 609 | + } |
|
| 610 | + |
|
| 611 | + |
|
| 612 | + /** |
|
| 613 | + * This is a helper method used to very whether a registration notification should be sent or |
|
| 614 | + * not. Prevents duplicate notifications going out for registration context notifications. |
|
| 615 | + * |
|
| 616 | + * @param EE_Registration $registration [description] |
|
| 617 | + * @param array $extra_details [description] |
|
| 618 | + * @return bool true = send away, false = nope halt the presses. |
|
| 619 | + */ |
|
| 620 | + protected static function _verify_registration_notification_send( |
|
| 621 | + EE_Registration $registration, |
|
| 622 | + $extra_details = array() |
|
| 623 | + ) { |
|
| 624 | + if (! $registration->is_primary_registrant()) { |
|
| 625 | + return false; |
|
| 626 | + } |
|
| 627 | + // first we check if we're in admin and not doing front ajax |
|
| 628 | + if (is_admin() && ! EE_FRONT_AJAX) { |
|
| 629 | + // make sure appropriate admin params are set for sending messages |
|
| 630 | + if (empty($_REQUEST['txn_reg_status_change']['send_notifications']) |
|
| 631 | + || ! absint($_REQUEST['txn_reg_status_change']['send_notifications']) |
|
| 632 | + ) { |
|
| 633 | + // no messages sent please. |
|
| 634 | + return false; |
|
| 635 | + } |
|
| 636 | + } else { |
|
| 637 | + // frontend request (either regular or via AJAX) |
|
| 638 | + // TXN is NOT finalized ? |
|
| 639 | + if (! isset($extra_details['finalized']) || $extra_details['finalized'] === false) { |
|
| 640 | + return false; |
|
| 641 | + } |
|
| 642 | + // return visit but nothing changed ??? |
|
| 643 | + if (isset($extra_details['revisit'], $extra_details['status_updates']) && |
|
| 644 | + $extra_details['revisit'] && ! $extra_details['status_updates'] |
|
| 645 | + ) { |
|
| 646 | + return false; |
|
| 647 | + } |
|
| 648 | + // NOT sending messages && reg status is something other than "Not-Approved" |
|
| 649 | + if (! apply_filters('FHEE__EED_Messages___maybe_registration__deliver_notifications', false) && |
|
| 650 | + $registration->status_ID() !== EEM_Registration::status_id_not_approved |
|
| 651 | + ) { |
|
| 652 | + return false; |
|
| 653 | + } |
|
| 654 | + } |
|
| 655 | + // release the kraken |
|
| 656 | + return true; |
|
| 657 | + } |
|
| 658 | + |
|
| 659 | + |
|
| 660 | + /** |
|
| 661 | + * Simply returns an array indexed by Registration Status ID and the related message_type name associated with that |
|
| 662 | + * status id. |
|
| 663 | + * |
|
| 664 | + * @deprecated 4.9.0 Use EEH_MSG_Template::reg_status_to_message_type_array() |
|
| 665 | + * or EEH_MSG_Template::convert_reg_status_to_message_type |
|
| 666 | + * @param string $reg_status |
|
| 667 | + * @return array |
|
| 668 | + * @throws EE_Error |
|
| 669 | + * @throws InvalidArgumentException |
|
| 670 | + * @throws ReflectionException |
|
| 671 | + * @throws InvalidDataTypeException |
|
| 672 | + * @throws InvalidInterfaceException |
|
| 673 | + */ |
|
| 674 | + protected static function _get_reg_status_array($reg_status = '') |
|
| 675 | + { |
|
| 676 | + EE_Registry::instance()->load_helper('MSG_Template'); |
|
| 677 | + return EEH_MSG_Template::convert_reg_status_to_message_type($reg_status) |
|
| 678 | + ? EEH_MSG_Template::convert_reg_status_to_message_type($reg_status) |
|
| 679 | + : EEH_MSG_Template::reg_status_to_message_type_array(); |
|
| 680 | + } |
|
| 681 | + |
|
| 682 | + |
|
| 683 | + /** |
|
| 684 | + * Simply returns the payment message type for the given payment status. |
|
| 685 | + * |
|
| 686 | + * @deprecated 4.9.0 Use EEH_MSG_Template::payment_status_to_message_type_array |
|
| 687 | + * or EEH_MSG_Template::convert_payment_status_to_message_type |
|
| 688 | + * @param string $payment_status The payment status being matched. |
|
| 689 | + * @return bool|string The payment message type slug matching the status or false if no match. |
|
| 690 | + * @throws EE_Error |
|
| 691 | + * @throws InvalidArgumentException |
|
| 692 | + * @throws ReflectionException |
|
| 693 | + * @throws InvalidDataTypeException |
|
| 694 | + * @throws InvalidInterfaceException |
|
| 695 | + */ |
|
| 696 | + protected static function _get_payment_message_type($payment_status) |
|
| 697 | + { |
|
| 698 | + EE_Registry::instance()->load_helper('MSG_Template'); |
|
| 699 | + return EEH_MSG_Template::convert_payment_status_to_message_type($payment_status) |
|
| 700 | + ? EEH_MSG_Template::convert_payment_status_to_message_type($payment_status) |
|
| 701 | + : false; |
|
| 702 | + } |
|
| 703 | + |
|
| 704 | + |
|
| 705 | + /** |
|
| 706 | + * Message triggers for a resending already sent message(s) (via EE_Message list table) |
|
| 707 | + * |
|
| 708 | + * @access public |
|
| 709 | + * @param array $req_data This is the $_POST & $_GET data sent from EE_Admin Pages |
|
| 710 | + * @return bool success/fail |
|
| 711 | + * @throws EE_Error |
|
| 712 | + * @throws InvalidArgumentException |
|
| 713 | + * @throws InvalidDataTypeException |
|
| 714 | + * @throws InvalidInterfaceException |
|
| 715 | + * @throws ReflectionException |
|
| 716 | + */ |
|
| 717 | + public static function process_resend($req_data) |
|
| 718 | + { |
|
| 719 | + self::_load_controller(); |
|
| 720 | + |
|
| 721 | + // if $msgID in this request then skip to the new resend_message |
|
| 722 | + if (EE_Registry::instance()->REQ->get('MSG_ID')) { |
|
| 723 | + return self::resend_message(); |
|
| 724 | + } |
|
| 725 | + |
|
| 726 | + // make sure any incoming request data is set on the REQ so that it gets picked up later. |
|
| 727 | + $req_data = (array) $req_data; |
|
| 728 | + foreach ($req_data as $request_key => $request_value) { |
|
| 729 | + EE_Registry::instance()->REQ->set($request_key, $request_value); |
|
| 730 | + } |
|
| 731 | + |
|
| 732 | + if (! $messages_to_send = self::$_MSG_PROCESSOR->setup_messages_to_generate_from_registration_ids_in_request( |
|
| 733 | + )) { |
|
| 734 | + return false; |
|
| 735 | + } |
|
| 736 | + |
|
| 737 | + try { |
|
| 738 | + self::$_MSG_PROCESSOR->batch_queue_for_generation_and_persist($messages_to_send); |
|
| 739 | + self::$_MSG_PROCESSOR->get_queue()->initiate_request_by_priority(); |
|
| 740 | + } catch (EE_Error $e) { |
|
| 741 | + EE_Error::add_error($e->getMessage(), __FILE__, __FUNCTION__, __LINE__); |
|
| 742 | + return false; |
|
| 743 | + } |
|
| 744 | + EE_Error::add_success( |
|
| 745 | + __('Messages have been successfully queued for generation and sending.', 'event_espresso') |
|
| 746 | + ); |
|
| 747 | + return true; // everything got queued. |
|
| 748 | + } |
|
| 749 | + |
|
| 750 | + |
|
| 751 | + /** |
|
| 752 | + * Message triggers for a resending already sent message(s) (via EE_Message list table) |
|
| 753 | + * |
|
| 754 | + * @return bool |
|
| 755 | + * @throws EE_Error |
|
| 756 | + * @throws InvalidArgumentException |
|
| 757 | + * @throws InvalidDataTypeException |
|
| 758 | + * @throws InvalidInterfaceException |
|
| 759 | + * @throws ReflectionException |
|
| 760 | + */ |
|
| 761 | + public static function resend_message() |
|
| 762 | + { |
|
| 763 | + self::_load_controller(); |
|
| 764 | + |
|
| 765 | + $msgID = EE_Registry::instance()->REQ->get('MSG_ID'); |
|
| 766 | + if (! $msgID) { |
|
| 767 | + EE_Error::add_error( |
|
| 768 | + __( |
|
| 769 | + 'Something went wrong because there is no "MSG_ID" value in the request', |
|
| 770 | + 'event_espresso' |
|
| 771 | + ), |
|
| 772 | + __FILE__, |
|
| 773 | + __FUNCTION__, |
|
| 774 | + __LINE__ |
|
| 775 | + ); |
|
| 776 | + return false; |
|
| 777 | + } |
|
| 778 | + |
|
| 779 | + self::$_MSG_PROCESSOR->setup_messages_from_ids_and_send((array) $msgID); |
|
| 780 | + |
|
| 781 | + // setup success message. |
|
| 782 | + $count_ready_for_resend = self::$_MSG_PROCESSOR->get_queue()->count_STS_in_queue(EEM_Message::status_resend); |
|
| 783 | + EE_Error::add_success( |
|
| 784 | + sprintf( |
|
| 785 | + _n( |
|
| 786 | + 'There was %d message queued for resending.', |
|
| 787 | + 'There were %d messages queued for resending.', |
|
| 788 | + $count_ready_for_resend, |
|
| 789 | + 'event_espresso' |
|
| 790 | + ), |
|
| 791 | + $count_ready_for_resend |
|
| 792 | + ) |
|
| 793 | + ); |
|
| 794 | + return true; |
|
| 795 | + } |
|
| 796 | + |
|
| 797 | + |
|
| 798 | + /** |
|
| 799 | + * Message triggers for manual payment applied by admin |
|
| 800 | + * |
|
| 801 | + * @param EE_Payment $payment EE_payment object |
|
| 802 | + * @return bool success/fail |
|
| 803 | + * @throws EE_Error |
|
| 804 | + * @throws InvalidArgumentException |
|
| 805 | + * @throws ReflectionException |
|
| 806 | + * @throws InvalidDataTypeException |
|
| 807 | + * @throws InvalidInterfaceException |
|
| 808 | + */ |
|
| 809 | + public static function process_admin_payment(EE_Payment $payment) |
|
| 810 | + { |
|
| 811 | + EE_Registry::instance()->load_helper('MSG_Template'); |
|
| 812 | + // we need to get the transaction object |
|
| 813 | + $transaction = $payment->transaction(); |
|
| 814 | + if ($transaction instanceof EE_Transaction) { |
|
| 815 | + $data = array($transaction, $payment); |
|
| 816 | + $message_type = EEH_MSG_Template::convert_payment_status_to_message_type($payment->STS_ID()); |
|
| 817 | + |
|
| 818 | + // if payment amount is less than 0 then switch to payment_refund message type. |
|
| 819 | + $message_type = $payment->amount() < 0 ? 'payment_refund' : $message_type; |
|
| 820 | + |
|
| 821 | + // if payment_refund is selected, but the status is NOT accepted. Then change message type to false so NO message notification goes out. |
|
| 822 | + $message_type = $message_type == 'payment_refund' && $payment->STS_ID() != EEM_Payment::status_id_approved |
|
| 823 | + ? false : $message_type; |
|
| 824 | + |
|
| 825 | + self::_load_controller(); |
|
| 826 | + |
|
| 827 | + self::$_MSG_PROCESSOR->generate_for_all_active_messengers($message_type, $data); |
|
| 828 | + |
|
| 829 | + // get count of queued for generation |
|
| 830 | + $count_to_generate = self::$_MSG_PROCESSOR->get_queue()->count_STS_in_queue( |
|
| 831 | + array( |
|
| 832 | + EEM_Message::status_incomplete, |
|
| 833 | + EEM_Message::status_idle, |
|
| 834 | + ) |
|
| 835 | + ); |
|
| 836 | + |
|
| 837 | + if ($count_to_generate > 0 && self::$_MSG_PROCESSOR->get_queue()->get_message_repository()->count() !== 0) { |
|
| 838 | + add_filter('FHEE__EE_Admin_Page___process_admin_payment_notification__success', '__return_true'); |
|
| 839 | + return true; |
|
| 840 | + } else { |
|
| 841 | + $count_failed = self::$_MSG_PROCESSOR->get_queue()->count_STS_in_queue( |
|
| 842 | + EEM_Message::instance()->stati_indicating_failed_sending() |
|
| 843 | + ); |
|
| 844 | + /** |
|
| 845 | + * Verify that there are actually errors. If not then we return a success message because the queue might have been emptied due to successful |
|
| 846 | + * IMMEDIATE generation. |
|
| 847 | + */ |
|
| 848 | + if ($count_failed > 0) { |
|
| 849 | + EE_Error::add_error( |
|
| 850 | + sprintf( |
|
| 851 | + _n( |
|
| 852 | + 'The payment notification generation failed.', |
|
| 853 | + '%d payment notifications failed being sent.', |
|
| 854 | + $count_failed, |
|
| 855 | + 'event_espresso' |
|
| 856 | + ), |
|
| 857 | + $count_failed |
|
| 858 | + ), |
|
| 859 | + __FILE__, |
|
| 860 | + __FUNCTION__, |
|
| 861 | + __LINE__ |
|
| 862 | + ); |
|
| 863 | + |
|
| 864 | + return false; |
|
| 865 | + } else { |
|
| 866 | + add_filter('FHEE__EE_Admin_Page___process_admin_payment_notification__success', '__return_true'); |
|
| 867 | + return true; |
|
| 868 | + } |
|
| 869 | + } |
|
| 870 | + } else { |
|
| 871 | + EE_Error::add_error( |
|
| 872 | + 'Unable to generate the payment notification because the given value for the transaction is invalid.', |
|
| 873 | + 'event_espresso' |
|
| 874 | + ); |
|
| 875 | + return false; |
|
| 876 | + } |
|
| 877 | + } |
|
| 878 | + |
|
| 879 | + |
|
| 880 | + /** |
|
| 881 | + * Callback for AHEE__Extend_Registrations_Admin_Page___newsletter_selected_send_with_registrations trigger |
|
| 882 | + * |
|
| 883 | + * @since 4.3.0 |
|
| 884 | + * @param EE_Registration[] $registrations an array of EE_Registration objects |
|
| 885 | + * @param int $grp_id a specific message template group id. |
|
| 886 | + * @return void |
|
| 887 | + * @throws EE_Error |
|
| 888 | + * @throws InvalidArgumentException |
|
| 889 | + * @throws InvalidDataTypeException |
|
| 890 | + * @throws InvalidInterfaceException |
|
| 891 | + * @throws ReflectionException |
|
| 892 | + */ |
|
| 893 | + public static function send_newsletter_message($registrations, $grp_id) |
|
| 894 | + { |
|
| 895 | + // make sure mtp is id and set it in the EE_Request Handler later messages setup. |
|
| 896 | + EE_Registry::instance()->REQ->set('GRP_ID', (int) $grp_id); |
|
| 897 | + self::_load_controller(); |
|
| 898 | + self::$_MSG_PROCESSOR->generate_for_all_active_messengers('newsletter', $registrations); |
|
| 899 | + } |
|
| 900 | + |
|
| 901 | + |
|
| 902 | + /** |
|
| 903 | + * Callback for FHEE__EE_Registration__invoice_url__invoice_url or FHEE__EE_Registration__receipt_url__receipt_url |
|
| 904 | + * |
|
| 905 | + * @since 4.3.0 |
|
| 906 | + * @param string $registration_message_trigger_url |
|
| 907 | + * @param EE_Registration $registration |
|
| 908 | + * @param string $messenger |
|
| 909 | + * @param string $message_type |
|
| 910 | + * @return string |
|
| 911 | + * @throws EE_Error |
|
| 912 | + * @throws InvalidArgumentException |
|
| 913 | + * @throws InvalidDataTypeException |
|
| 914 | + * @throws InvalidInterfaceException |
|
| 915 | + */ |
|
| 916 | + public static function registration_message_trigger_url( |
|
| 917 | + $registration_message_trigger_url, |
|
| 918 | + EE_Registration $registration, |
|
| 919 | + $messenger = 'html', |
|
| 920 | + $message_type = 'invoice' |
|
| 921 | + ) { |
|
| 922 | + // whitelist $messenger |
|
| 923 | + switch ($messenger) { |
|
| 924 | + case 'pdf': |
|
| 925 | + $sending_messenger = 'pdf'; |
|
| 926 | + $generating_messenger = 'html'; |
|
| 927 | + break; |
|
| 928 | + case 'html': |
|
| 929 | + default: |
|
| 930 | + $sending_messenger = 'html'; |
|
| 931 | + $generating_messenger = 'html'; |
|
| 932 | + break; |
|
| 933 | + } |
|
| 934 | + // whitelist $message_type |
|
| 935 | + switch ($message_type) { |
|
| 936 | + case 'receipt': |
|
| 937 | + $message_type = 'receipt'; |
|
| 938 | + break; |
|
| 939 | + case 'invoice': |
|
| 940 | + default: |
|
| 941 | + $message_type = 'invoice'; |
|
| 942 | + break; |
|
| 943 | + } |
|
| 944 | + // verify that both the messenger AND the message type are active |
|
| 945 | + if (EEH_MSG_Template::is_messenger_active($sending_messenger) |
|
| 946 | + && EEH_MSG_Template::is_mt_active($message_type) |
|
| 947 | + ) { |
|
| 948 | + // need to get the correct message template group for this (i.e. is there a custom invoice for the event this registration is registered for?) |
|
| 949 | + $template_query_params = array( |
|
| 950 | + 'MTP_is_active' => true, |
|
| 951 | + 'MTP_messenger' => $generating_messenger, |
|
| 952 | + 'MTP_message_type' => $message_type, |
|
| 953 | + 'Event.EVT_ID' => $registration->event_ID(), |
|
| 954 | + ); |
|
| 955 | + // get the message template group. |
|
| 956 | + $msg_template_group = EEM_Message_Template_Group::instance()->get_one(array($template_query_params)); |
|
| 957 | + // if we don't have an EE_Message_Template_Group then return |
|
| 958 | + if (! $msg_template_group instanceof EE_Message_Template_Group) { |
|
| 959 | + // remove EVT_ID from query params so that global templates get picked up |
|
| 960 | + unset($template_query_params['Event.EVT_ID']); |
|
| 961 | + // get global template as the fallback |
|
| 962 | + $msg_template_group = EEM_Message_Template_Group::instance()->get_one(array($template_query_params)); |
|
| 963 | + } |
|
| 964 | + // if we don't have an EE_Message_Template_Group then return |
|
| 965 | + if (! $msg_template_group instanceof EE_Message_Template_Group) { |
|
| 966 | + return ''; |
|
| 967 | + } |
|
| 968 | + // generate the URL |
|
| 969 | + $registration_message_trigger_url = EEH_MSG_Template::generate_url_trigger( |
|
| 970 | + $sending_messenger, |
|
| 971 | + $generating_messenger, |
|
| 972 | + 'purchaser', |
|
| 973 | + $message_type, |
|
| 974 | + $registration, |
|
| 975 | + $msg_template_group->ID(), |
|
| 976 | + $registration->transaction_ID() |
|
| 977 | + ); |
|
| 978 | + } |
|
| 979 | + return $registration_message_trigger_url; |
|
| 980 | + } |
|
| 981 | + |
|
| 982 | + |
|
| 983 | + /** |
|
| 984 | + * Use to generate and return a message preview! |
|
| 985 | + * |
|
| 986 | + * @param string $type This should correspond with a valid message type |
|
| 987 | + * @param string $context This should correspond with a valid context for the message type |
|
| 988 | + * @param string $messenger This should correspond with a valid messenger. |
|
| 989 | + * @param bool $send true we will do a test send using the messenger delivery, false we just do a regular |
|
| 990 | + * preview |
|
| 991 | + * @return bool|string The body of the message or if send is requested, sends. |
|
| 992 | + * @throws EE_Error |
|
| 993 | + * @throws InvalidArgumentException |
|
| 994 | + * @throws InvalidDataTypeException |
|
| 995 | + * @throws InvalidInterfaceException |
|
| 996 | + * @throws ReflectionException |
|
| 997 | + */ |
|
| 998 | + public static function preview_message($type, $context, $messenger, $send = false) |
|
| 999 | + { |
|
| 1000 | + self::_load_controller(); |
|
| 1001 | + $mtg = new EE_Message_To_Generate( |
|
| 1002 | + $messenger, |
|
| 1003 | + $type, |
|
| 1004 | + array(), |
|
| 1005 | + $context, |
|
| 1006 | + true |
|
| 1007 | + ); |
|
| 1008 | + $generated_preview_queue = self::$_MSG_PROCESSOR->generate_for_preview($mtg, $send); |
|
| 1009 | + if ($generated_preview_queue instanceof EE_Messages_Queue) { |
|
| 1010 | + // loop through all content for the preview and remove any persisted records. |
|
| 1011 | + $content = ''; |
|
| 1012 | + foreach ($generated_preview_queue->get_message_repository() as $message) { |
|
| 1013 | + $content = $message->content(); |
|
| 1014 | + if ($message->ID() > 0 && $message->STS_ID() !== EEM_Message::status_failed) { |
|
| 1015 | + $message->delete(); |
|
| 1016 | + } |
|
| 1017 | + } |
|
| 1018 | + return $content; |
|
| 1019 | + } else { |
|
| 1020 | + return $generated_preview_queue; |
|
| 1021 | + } |
|
| 1022 | + } |
|
| 1023 | + |
|
| 1024 | + |
|
| 1025 | + /** |
|
| 1026 | + * This is a method that allows for sending a message using a messenger matching the string given and the provided |
|
| 1027 | + * EE_Message_Queue object. The EE_Message_Queue object is used to create a single aggregate EE_Message via the |
|
| 1028 | + * content found in the EE_Message objects in the queue. |
|
| 1029 | + * |
|
| 1030 | + * @since 4.9.0 |
|
| 1031 | + * @param string $messenger a string matching a valid active messenger in the system |
|
| 1032 | + * @param string $message_type Although it seems contrary to the name of the method, a message |
|
| 1033 | + * type name is still required to send along the message type to the |
|
| 1034 | + * messenger because this is used for determining what specific |
|
| 1035 | + * variations might be loaded for the generated message. |
|
| 1036 | + * @param EE_Messages_Queue $queue |
|
| 1037 | + * @param string $custom_subject Can be used to set what the custom subject string will be on the |
|
| 1038 | + * aggregate EE_Message object. |
|
| 1039 | + * @return bool success or fail. |
|
| 1040 | + * @throws EE_Error |
|
| 1041 | + * @throws InvalidArgumentException |
|
| 1042 | + * @throws ReflectionException |
|
| 1043 | + * @throws InvalidDataTypeException |
|
| 1044 | + * @throws InvalidInterfaceException |
|
| 1045 | + */ |
|
| 1046 | + public static function send_message_with_messenger_only( |
|
| 1047 | + $messenger, |
|
| 1048 | + $message_type, |
|
| 1049 | + EE_Messages_Queue $queue, |
|
| 1050 | + $custom_subject = '' |
|
| 1051 | + ) { |
|
| 1052 | + self::_load_controller(); |
|
| 1053 | + /** @type EE_Message_To_Generate_From_Queue $message_to_generate */ |
|
| 1054 | + $message_to_generate = EE_Registry::instance()->load_lib( |
|
| 1055 | + 'Message_To_Generate_From_Queue', |
|
| 1056 | + array( |
|
| 1057 | + $messenger, |
|
| 1058 | + $message_type, |
|
| 1059 | + $queue, |
|
| 1060 | + $custom_subject, |
|
| 1061 | + ) |
|
| 1062 | + ); |
|
| 1063 | + return self::$_MSG_PROCESSOR->queue_for_sending($message_to_generate); |
|
| 1064 | + } |
|
| 1065 | + |
|
| 1066 | + |
|
| 1067 | + /** |
|
| 1068 | + * Generates Messages immediately for EE_Message IDs (but only for the correct status for generation) |
|
| 1069 | + * |
|
| 1070 | + * @since 4.9.0 |
|
| 1071 | + * @param array $message_ids An array of message ids |
|
| 1072 | + * @return bool|EE_Messages_Queue false if nothing was generated, EE_Messages_Queue containing generated |
|
| 1073 | + * messages. |
|
| 1074 | + * @throws EE_Error |
|
| 1075 | + * @throws InvalidArgumentException |
|
| 1076 | + * @throws InvalidDataTypeException |
|
| 1077 | + * @throws InvalidInterfaceException |
|
| 1078 | + * @throws ReflectionException |
|
| 1079 | + */ |
|
| 1080 | + public static function generate_now($message_ids) |
|
| 1081 | + { |
|
| 1082 | + self::_load_controller(); |
|
| 1083 | + $messages = EEM_Message::instance()->get_all( |
|
| 1084 | + array( |
|
| 1085 | + 0 => array( |
|
| 1086 | + 'MSG_ID' => array('IN', $message_ids), |
|
| 1087 | + 'STS_ID' => EEM_Message::status_incomplete, |
|
| 1088 | + ), |
|
| 1089 | + ) |
|
| 1090 | + ); |
|
| 1091 | + $generated_queue = false; |
|
| 1092 | + if ($messages) { |
|
| 1093 | + $generated_queue = self::$_MSG_PROCESSOR->batch_generate_from_queue($messages); |
|
| 1094 | + } |
|
| 1095 | + |
|
| 1096 | + if (! $generated_queue instanceof EE_Messages_Queue) { |
|
| 1097 | + EE_Error::add_error( |
|
| 1098 | + __( |
|
| 1099 | + 'The messages were not generated. This could mean there is already a batch being generated on a separate request, or because the selected messages are not ready for generation. Please wait a minute or two and try again.', |
|
| 1100 | + 'event_espresso' |
|
| 1101 | + ), |
|
| 1102 | + __FILE__, |
|
| 1103 | + __FUNCTION__, |
|
| 1104 | + __LINE__ |
|
| 1105 | + ); |
|
| 1106 | + } |
|
| 1107 | + return $generated_queue; |
|
| 1108 | + } |
|
| 1109 | + |
|
| 1110 | + |
|
| 1111 | + /** |
|
| 1112 | + * Sends messages immediately for the incoming message_ids that have the status of EEM_Message::status_resend or, |
|
| 1113 | + * EEM_Message::status_idle |
|
| 1114 | + * |
|
| 1115 | + * @since 4.9.0 |
|
| 1116 | + * @param $message_ids |
|
| 1117 | + * @return bool|EE_Messages_Queue false if no messages sent. |
|
| 1118 | + * @throws EE_Error |
|
| 1119 | + * @throws InvalidArgumentException |
|
| 1120 | + * @throws InvalidDataTypeException |
|
| 1121 | + * @throws InvalidInterfaceException |
|
| 1122 | + * @throws ReflectionException |
|
| 1123 | + */ |
|
| 1124 | + public static function send_now($message_ids) |
|
| 1125 | + { |
|
| 1126 | + self::_load_controller(); |
|
| 1127 | + $messages = EEM_Message::instance()->get_all( |
|
| 1128 | + array( |
|
| 1129 | + 0 => array( |
|
| 1130 | + 'MSG_ID' => array('IN', $message_ids), |
|
| 1131 | + 'STS_ID' => array( |
|
| 1132 | + 'IN', |
|
| 1133 | + array(EEM_Message::status_idle, EEM_Message::status_resend, EEM_Message::status_retry), |
|
| 1134 | + ), |
|
| 1135 | + ), |
|
| 1136 | + ) |
|
| 1137 | + ); |
|
| 1138 | + $sent_queue = false; |
|
| 1139 | + if ($messages) { |
|
| 1140 | + $sent_queue = self::$_MSG_PROCESSOR->batch_send_from_queue($messages); |
|
| 1141 | + } |
|
| 1142 | + |
|
| 1143 | + if (! $sent_queue instanceof EE_Messages_Queue) { |
|
| 1144 | + EE_Error::add_error( |
|
| 1145 | + __( |
|
| 1146 | + 'The messages were not sent. This could mean there is already a batch being sent on a separate request, or because the selected messages are not sendable. Please wait a minute or two and try again.', |
|
| 1147 | + 'event_espresso' |
|
| 1148 | + ), |
|
| 1149 | + __FILE__, |
|
| 1150 | + __FUNCTION__, |
|
| 1151 | + __LINE__ |
|
| 1152 | + ); |
|
| 1153 | + } else { |
|
| 1154 | + // can count how many sent by using the messages in the queue |
|
| 1155 | + $sent_count = $sent_queue->count_STS_in_queue(EEM_Message::instance()->stati_indicating_sent()); |
|
| 1156 | + if ($sent_count > 0) { |
|
| 1157 | + EE_Error::add_success( |
|
| 1158 | + sprintf( |
|
| 1159 | + _n( |
|
| 1160 | + 'There was %d message successfully sent.', |
|
| 1161 | + 'There were %d messages successfully sent.', |
|
| 1162 | + $sent_count, |
|
| 1163 | + 'event_espresso' |
|
| 1164 | + ), |
|
| 1165 | + $sent_count |
|
| 1166 | + ) |
|
| 1167 | + ); |
|
| 1168 | + } else { |
|
| 1169 | + EE_Error::overwrite_errors(); |
|
| 1170 | + EE_Error::add_error( |
|
| 1171 | + __( |
|
| 1172 | + 'No message was sent because of problems with sending. Either all the messages you selected were not a sendable message, they were ALREADY sent on a different scheduled task, or there was an error. |
|
| 1173 | 1173 | If there was an error, you can look at the messages in the message activity list table for any error messages.', |
| 1174 | - 'event_espresso' |
|
| 1175 | - ), |
|
| 1176 | - __FILE__, |
|
| 1177 | - __FUNCTION__, |
|
| 1178 | - __LINE__ |
|
| 1179 | - ); |
|
| 1180 | - } |
|
| 1181 | - } |
|
| 1182 | - return $sent_queue; |
|
| 1183 | - } |
|
| 1184 | - |
|
| 1185 | - |
|
| 1186 | - /** |
|
| 1187 | - * Generate and send immediately from the given $message_ids |
|
| 1188 | - * |
|
| 1189 | - * @param array $message_ids EE_Message entity ids. |
|
| 1190 | - * @throws EE_Error |
|
| 1191 | - * @throws InvalidArgumentException |
|
| 1192 | - * @throws InvalidDataTypeException |
|
| 1193 | - * @throws InvalidInterfaceException |
|
| 1194 | - * @throws ReflectionException |
|
| 1195 | - */ |
|
| 1196 | - public static function generate_and_send_now(array $message_ids) |
|
| 1197 | - { |
|
| 1198 | - $generated_queue = self::generate_now($message_ids); |
|
| 1199 | - // now let's just trigger sending immediately from this queue. |
|
| 1200 | - $messages_sent = $generated_queue instanceof EE_Messages_Queue |
|
| 1201 | - ? $generated_queue->execute() |
|
| 1202 | - : 0; |
|
| 1203 | - if ($messages_sent) { |
|
| 1204 | - EE_Error::add_success( |
|
| 1205 | - esc_html( |
|
| 1206 | - sprintf( |
|
| 1207 | - _n( |
|
| 1208 | - 'There was %d message successfully generated and sent.', |
|
| 1209 | - 'There were %d messages successfully generated and sent.', |
|
| 1210 | - $messages_sent, |
|
| 1211 | - 'event_espresso' |
|
| 1212 | - ), |
|
| 1213 | - $messages_sent |
|
| 1214 | - ) |
|
| 1215 | - ) |
|
| 1216 | - ); |
|
| 1217 | - // errors would be added via the generate_now method. |
|
| 1218 | - } |
|
| 1219 | - } |
|
| 1220 | - |
|
| 1221 | - |
|
| 1222 | - /** |
|
| 1223 | - * This will queue the incoming message ids for resending. |
|
| 1224 | - * Note, only message_ids corresponding to messages with the status of EEM_Message::sent will be queued. |
|
| 1225 | - * |
|
| 1226 | - * @since 4.9.0 |
|
| 1227 | - * @param array $message_ids An array of EE_Message IDs |
|
| 1228 | - * @return bool true means messages were successfully queued for resending, false means none were queued for |
|
| 1229 | - * resending. |
|
| 1230 | - * @throws EE_Error |
|
| 1231 | - * @throws InvalidArgumentException |
|
| 1232 | - * @throws InvalidDataTypeException |
|
| 1233 | - * @throws InvalidInterfaceException |
|
| 1234 | - * @throws ReflectionException |
|
| 1235 | - */ |
|
| 1236 | - public static function queue_for_resending($message_ids) |
|
| 1237 | - { |
|
| 1238 | - self::_load_controller(); |
|
| 1239 | - self::$_MSG_PROCESSOR->setup_messages_from_ids_and_send($message_ids); |
|
| 1240 | - |
|
| 1241 | - // get queue and count |
|
| 1242 | - $queue_count = self::$_MSG_PROCESSOR->get_queue()->count_STS_in_queue(EEM_Message::status_resend); |
|
| 1243 | - |
|
| 1244 | - if ($queue_count > 0 |
|
| 1245 | - ) { |
|
| 1246 | - EE_Error::add_success( |
|
| 1247 | - sprintf( |
|
| 1248 | - _n( |
|
| 1249 | - '%d message successfully queued for resending.', |
|
| 1250 | - '%d messages successfully queued for resending.', |
|
| 1251 | - $queue_count, |
|
| 1252 | - 'event_espresso' |
|
| 1253 | - ), |
|
| 1254 | - $queue_count |
|
| 1255 | - ) |
|
| 1256 | - ); |
|
| 1257 | - /** |
|
| 1258 | - * @see filter usage in EE_Messages_Queue::initiate_request_by_priority |
|
| 1259 | - */ |
|
| 1260 | - } elseif (apply_filters('FHEE__EE_Messages_Processor__initiate_request_by_priority__do_immediate_processing', true) |
|
| 1261 | - || EE_Registry::instance()->NET_CFG->core->do_messages_on_same_request |
|
| 1262 | - ) { |
|
| 1263 | - $queue_count = self::$_MSG_PROCESSOR->get_queue()->count_STS_in_queue(EEM_Message::status_sent); |
|
| 1264 | - if ($queue_count > 0) { |
|
| 1265 | - EE_Error::add_success( |
|
| 1266 | - sprintf( |
|
| 1267 | - _n( |
|
| 1268 | - '%d message successfully sent.', |
|
| 1269 | - '%d messages successfully sent.', |
|
| 1270 | - $queue_count, |
|
| 1271 | - 'event_espresso' |
|
| 1272 | - ), |
|
| 1273 | - $queue_count |
|
| 1274 | - ) |
|
| 1275 | - ); |
|
| 1276 | - } else { |
|
| 1277 | - EE_Error::add_error( |
|
| 1278 | - __( |
|
| 1279 | - 'No messages were queued for resending. This usually only happens when all the messages flagged for resending are not a status that can be resent.', |
|
| 1280 | - 'event_espresso' |
|
| 1281 | - ), |
|
| 1282 | - __FILE__, |
|
| 1283 | - __FUNCTION__, |
|
| 1284 | - __LINE__ |
|
| 1285 | - ); |
|
| 1286 | - } |
|
| 1287 | - } else { |
|
| 1288 | - EE_Error::add_error( |
|
| 1289 | - __( |
|
| 1290 | - 'No messages were queued for resending. This usually only happens when all the messages flagged for resending are not a status that can be resent.', |
|
| 1291 | - 'event_espresso' |
|
| 1292 | - ), |
|
| 1293 | - __FILE__, |
|
| 1294 | - __FUNCTION__, |
|
| 1295 | - __LINE__ |
|
| 1296 | - ); |
|
| 1297 | - } |
|
| 1298 | - return (bool) $queue_count; |
|
| 1299 | - } |
|
| 1300 | - |
|
| 1301 | - |
|
| 1302 | - /** |
|
| 1303 | - * debug |
|
| 1304 | - * |
|
| 1305 | - * @param string $class |
|
| 1306 | - * @param string $func |
|
| 1307 | - * @param string $line |
|
| 1308 | - * @param \EE_Transaction $transaction |
|
| 1309 | - * @param array $info |
|
| 1310 | - * @param bool $display_request |
|
| 1311 | - * @throws EE_Error |
|
| 1312 | - * @throws \EventEspresso\core\exceptions\InvalidSessionDataException |
|
| 1313 | - */ |
|
| 1314 | - protected static function log( |
|
| 1315 | - $class = '', |
|
| 1316 | - $func = '', |
|
| 1317 | - $line = '', |
|
| 1318 | - EE_Transaction $transaction, |
|
| 1319 | - $info = array(), |
|
| 1320 | - $display_request = false |
|
| 1321 | - ) { |
|
| 1322 | - if (defined('EE_DEBUG') && EE_DEBUG) { |
|
| 1323 | - if ($transaction instanceof EE_Transaction) { |
|
| 1324 | - // don't serialize objects |
|
| 1325 | - $info = EEH_Debug_Tools::strip_objects($info); |
|
| 1326 | - $info['TXN_status'] = $transaction->status_ID(); |
|
| 1327 | - $info['TXN_reg_steps'] = $transaction->reg_steps(); |
|
| 1328 | - if ($transaction->ID()) { |
|
| 1329 | - $index = 'EE_Transaction: ' . $transaction->ID(); |
|
| 1330 | - EEH_Debug_Tools::log($class, $func, $line, $info, $display_request, $index); |
|
| 1331 | - } |
|
| 1332 | - } |
|
| 1333 | - } |
|
| 1334 | - } |
|
| 1335 | - |
|
| 1336 | - |
|
| 1337 | - /** |
|
| 1338 | - * Resets all the static properties in this class when called. |
|
| 1339 | - */ |
|
| 1340 | - public static function reset() |
|
| 1341 | - { |
|
| 1342 | - self::$_EEMSG = null; |
|
| 1343 | - self::$_message_resource_manager = null; |
|
| 1344 | - self::$_MSG_PROCESSOR = null; |
|
| 1345 | - self::$_MSG_PATHS = null; |
|
| 1346 | - self::$_TMP_PACKS = array(); |
|
| 1347 | - } |
|
| 1174 | + 'event_espresso' |
|
| 1175 | + ), |
|
| 1176 | + __FILE__, |
|
| 1177 | + __FUNCTION__, |
|
| 1178 | + __LINE__ |
|
| 1179 | + ); |
|
| 1180 | + } |
|
| 1181 | + } |
|
| 1182 | + return $sent_queue; |
|
| 1183 | + } |
|
| 1184 | + |
|
| 1185 | + |
|
| 1186 | + /** |
|
| 1187 | + * Generate and send immediately from the given $message_ids |
|
| 1188 | + * |
|
| 1189 | + * @param array $message_ids EE_Message entity ids. |
|
| 1190 | + * @throws EE_Error |
|
| 1191 | + * @throws InvalidArgumentException |
|
| 1192 | + * @throws InvalidDataTypeException |
|
| 1193 | + * @throws InvalidInterfaceException |
|
| 1194 | + * @throws ReflectionException |
|
| 1195 | + */ |
|
| 1196 | + public static function generate_and_send_now(array $message_ids) |
|
| 1197 | + { |
|
| 1198 | + $generated_queue = self::generate_now($message_ids); |
|
| 1199 | + // now let's just trigger sending immediately from this queue. |
|
| 1200 | + $messages_sent = $generated_queue instanceof EE_Messages_Queue |
|
| 1201 | + ? $generated_queue->execute() |
|
| 1202 | + : 0; |
|
| 1203 | + if ($messages_sent) { |
|
| 1204 | + EE_Error::add_success( |
|
| 1205 | + esc_html( |
|
| 1206 | + sprintf( |
|
| 1207 | + _n( |
|
| 1208 | + 'There was %d message successfully generated and sent.', |
|
| 1209 | + 'There were %d messages successfully generated and sent.', |
|
| 1210 | + $messages_sent, |
|
| 1211 | + 'event_espresso' |
|
| 1212 | + ), |
|
| 1213 | + $messages_sent |
|
| 1214 | + ) |
|
| 1215 | + ) |
|
| 1216 | + ); |
|
| 1217 | + // errors would be added via the generate_now method. |
|
| 1218 | + } |
|
| 1219 | + } |
|
| 1220 | + |
|
| 1221 | + |
|
| 1222 | + /** |
|
| 1223 | + * This will queue the incoming message ids for resending. |
|
| 1224 | + * Note, only message_ids corresponding to messages with the status of EEM_Message::sent will be queued. |
|
| 1225 | + * |
|
| 1226 | + * @since 4.9.0 |
|
| 1227 | + * @param array $message_ids An array of EE_Message IDs |
|
| 1228 | + * @return bool true means messages were successfully queued for resending, false means none were queued for |
|
| 1229 | + * resending. |
|
| 1230 | + * @throws EE_Error |
|
| 1231 | + * @throws InvalidArgumentException |
|
| 1232 | + * @throws InvalidDataTypeException |
|
| 1233 | + * @throws InvalidInterfaceException |
|
| 1234 | + * @throws ReflectionException |
|
| 1235 | + */ |
|
| 1236 | + public static function queue_for_resending($message_ids) |
|
| 1237 | + { |
|
| 1238 | + self::_load_controller(); |
|
| 1239 | + self::$_MSG_PROCESSOR->setup_messages_from_ids_and_send($message_ids); |
|
| 1240 | + |
|
| 1241 | + // get queue and count |
|
| 1242 | + $queue_count = self::$_MSG_PROCESSOR->get_queue()->count_STS_in_queue(EEM_Message::status_resend); |
|
| 1243 | + |
|
| 1244 | + if ($queue_count > 0 |
|
| 1245 | + ) { |
|
| 1246 | + EE_Error::add_success( |
|
| 1247 | + sprintf( |
|
| 1248 | + _n( |
|
| 1249 | + '%d message successfully queued for resending.', |
|
| 1250 | + '%d messages successfully queued for resending.', |
|
| 1251 | + $queue_count, |
|
| 1252 | + 'event_espresso' |
|
| 1253 | + ), |
|
| 1254 | + $queue_count |
|
| 1255 | + ) |
|
| 1256 | + ); |
|
| 1257 | + /** |
|
| 1258 | + * @see filter usage in EE_Messages_Queue::initiate_request_by_priority |
|
| 1259 | + */ |
|
| 1260 | + } elseif (apply_filters('FHEE__EE_Messages_Processor__initiate_request_by_priority__do_immediate_processing', true) |
|
| 1261 | + || EE_Registry::instance()->NET_CFG->core->do_messages_on_same_request |
|
| 1262 | + ) { |
|
| 1263 | + $queue_count = self::$_MSG_PROCESSOR->get_queue()->count_STS_in_queue(EEM_Message::status_sent); |
|
| 1264 | + if ($queue_count > 0) { |
|
| 1265 | + EE_Error::add_success( |
|
| 1266 | + sprintf( |
|
| 1267 | + _n( |
|
| 1268 | + '%d message successfully sent.', |
|
| 1269 | + '%d messages successfully sent.', |
|
| 1270 | + $queue_count, |
|
| 1271 | + 'event_espresso' |
|
| 1272 | + ), |
|
| 1273 | + $queue_count |
|
| 1274 | + ) |
|
| 1275 | + ); |
|
| 1276 | + } else { |
|
| 1277 | + EE_Error::add_error( |
|
| 1278 | + __( |
|
| 1279 | + 'No messages were queued for resending. This usually only happens when all the messages flagged for resending are not a status that can be resent.', |
|
| 1280 | + 'event_espresso' |
|
| 1281 | + ), |
|
| 1282 | + __FILE__, |
|
| 1283 | + __FUNCTION__, |
|
| 1284 | + __LINE__ |
|
| 1285 | + ); |
|
| 1286 | + } |
|
| 1287 | + } else { |
|
| 1288 | + EE_Error::add_error( |
|
| 1289 | + __( |
|
| 1290 | + 'No messages were queued for resending. This usually only happens when all the messages flagged for resending are not a status that can be resent.', |
|
| 1291 | + 'event_espresso' |
|
| 1292 | + ), |
|
| 1293 | + __FILE__, |
|
| 1294 | + __FUNCTION__, |
|
| 1295 | + __LINE__ |
|
| 1296 | + ); |
|
| 1297 | + } |
|
| 1298 | + return (bool) $queue_count; |
|
| 1299 | + } |
|
| 1300 | + |
|
| 1301 | + |
|
| 1302 | + /** |
|
| 1303 | + * debug |
|
| 1304 | + * |
|
| 1305 | + * @param string $class |
|
| 1306 | + * @param string $func |
|
| 1307 | + * @param string $line |
|
| 1308 | + * @param \EE_Transaction $transaction |
|
| 1309 | + * @param array $info |
|
| 1310 | + * @param bool $display_request |
|
| 1311 | + * @throws EE_Error |
|
| 1312 | + * @throws \EventEspresso\core\exceptions\InvalidSessionDataException |
|
| 1313 | + */ |
|
| 1314 | + protected static function log( |
|
| 1315 | + $class = '', |
|
| 1316 | + $func = '', |
|
| 1317 | + $line = '', |
|
| 1318 | + EE_Transaction $transaction, |
|
| 1319 | + $info = array(), |
|
| 1320 | + $display_request = false |
|
| 1321 | + ) { |
|
| 1322 | + if (defined('EE_DEBUG') && EE_DEBUG) { |
|
| 1323 | + if ($transaction instanceof EE_Transaction) { |
|
| 1324 | + // don't serialize objects |
|
| 1325 | + $info = EEH_Debug_Tools::strip_objects($info); |
|
| 1326 | + $info['TXN_status'] = $transaction->status_ID(); |
|
| 1327 | + $info['TXN_reg_steps'] = $transaction->reg_steps(); |
|
| 1328 | + if ($transaction->ID()) { |
|
| 1329 | + $index = 'EE_Transaction: ' . $transaction->ID(); |
|
| 1330 | + EEH_Debug_Tools::log($class, $func, $line, $info, $display_request, $index); |
|
| 1331 | + } |
|
| 1332 | + } |
|
| 1333 | + } |
|
| 1334 | + } |
|
| 1335 | + |
|
| 1336 | + |
|
| 1337 | + /** |
|
| 1338 | + * Resets all the static properties in this class when called. |
|
| 1339 | + */ |
|
| 1340 | + public static function reset() |
|
| 1341 | + { |
|
| 1342 | + self::$_EEMSG = null; |
|
| 1343 | + self::$_message_resource_manager = null; |
|
| 1344 | + self::$_MSG_PROCESSOR = null; |
|
| 1345 | + self::$_MSG_PATHS = null; |
|
| 1346 | + self::$_TMP_PACKS = array(); |
|
| 1347 | + } |
|
| 1348 | 1348 | } |
@@ -202,7 +202,7 @@ discard block |
||
| 202 | 202 | 'event_espresso' |
| 203 | 203 | ); |
| 204 | 204 | // add specific message for developers if WP_DEBUG in on |
| 205 | - $error_msg .= '||' . $e->getMessage(); |
|
| 205 | + $error_msg .= '||'.$e->getMessage(); |
|
| 206 | 206 | EE_Error::add_error($error_msg, __FILE__, __FUNCTION__, __LINE__); |
| 207 | 207 | } |
| 208 | 208 | } |
@@ -289,7 +289,7 @@ discard block |
||
| 289 | 289 | 'event_espresso' |
| 290 | 290 | ); |
| 291 | 291 | // add specific message for developers if WP_DEBUG in on |
| 292 | - $error_msg .= '||' . $e->getMessage(); |
|
| 292 | + $error_msg .= '||'.$e->getMessage(); |
|
| 293 | 293 | EE_Error::add_error($error_msg, __FILE__, __FUNCTION__, __LINE__); |
| 294 | 294 | } |
| 295 | 295 | } |
@@ -320,7 +320,7 @@ discard block |
||
| 320 | 320 | $transient_key = EE_Registry::instance()->REQ->get('key'); |
| 321 | 321 | |
| 322 | 322 | // now let's verify transient, if not valid exit immediately |
| 323 | - if (! get_transient($transient_key)) { |
|
| 323 | + if ( ! get_transient($transient_key)) { |
|
| 324 | 324 | /** |
| 325 | 325 | * trigger error so this gets in the error logs. This is important because it happens on a non-user |
| 326 | 326 | * request. |
@@ -332,7 +332,7 @@ discard block |
||
| 332 | 332 | delete_transient($transient_key); |
| 333 | 333 | |
| 334 | 334 | if (apply_filters('FHEE__EED_Messages__run_cron__use_wp_cron', true)) { |
| 335 | - $method = 'batch_' . $cron_type . '_from_queue'; |
|
| 335 | + $method = 'batch_'.$cron_type.'_from_queue'; |
|
| 336 | 336 | if (method_exists(self::$_MSG_PROCESSOR, $method)) { |
| 337 | 337 | self::$_MSG_PROCESSOR->$method(); |
| 338 | 338 | } else { |
@@ -399,7 +399,7 @@ discard block |
||
| 399 | 399 | $template_pack_collection->rewind(); |
| 400 | 400 | $template_packs = array(); |
| 401 | 401 | while ($template_pack_collection->valid()) { |
| 402 | - $template_packs[ $template_pack_collection->current()->dbref ] = $template_pack_collection->current(); |
|
| 402 | + $template_packs[$template_pack_collection->current()->dbref] = $template_pack_collection->current(); |
|
| 403 | 403 | $template_pack_collection->next(); |
| 404 | 404 | } |
| 405 | 405 | return $template_packs; |
@@ -439,15 +439,15 @@ discard block |
||
| 439 | 439 | self::$_MSG_PATHS = apply_filters( |
| 440 | 440 | 'FHEE__EED_Messages___set_messages_paths___MSG_PATHS', |
| 441 | 441 | [ |
| 442 | - EE_LIBRARIES . 'messages/message_type', |
|
| 443 | - EE_LIBRARIES . 'messages/messenger', |
|
| 444 | - EE_LIBRARIES . 'messages/defaults', |
|
| 445 | - EE_LIBRARIES . 'messages/defaults/email', |
|
| 446 | - EE_LIBRARIES . 'messages/data_class', |
|
| 447 | - EE_LIBRARIES . 'messages/validators', |
|
| 448 | - EE_LIBRARIES . 'messages/validators/email', |
|
| 449 | - EE_LIBRARIES . 'messages/validators/html', |
|
| 450 | - EE_LIBRARIES . 'shortcodes', |
|
| 442 | + EE_LIBRARIES.'messages/message_type', |
|
| 443 | + EE_LIBRARIES.'messages/messenger', |
|
| 444 | + EE_LIBRARIES.'messages/defaults', |
|
| 445 | + EE_LIBRARIES.'messages/defaults/email', |
|
| 446 | + EE_LIBRARIES.'messages/data_class', |
|
| 447 | + EE_LIBRARIES.'messages/validators', |
|
| 448 | + EE_LIBRARIES.'messages/validators/email', |
|
| 449 | + EE_LIBRARIES.'messages/validators/html', |
|
| 450 | + EE_LIBRARIES.'shortcodes', |
|
| 451 | 451 | ] |
| 452 | 452 | ); |
| 453 | 453 | } |
@@ -466,7 +466,7 @@ discard block |
||
| 466 | 466 | */ |
| 467 | 467 | protected static function _load_controller() |
| 468 | 468 | { |
| 469 | - if (! self::$_MSG_PROCESSOR instanceof EE_Messages_Processor) { |
|
| 469 | + if ( ! self::$_MSG_PROCESSOR instanceof EE_Messages_Processor) { |
|
| 470 | 470 | EE_Registry::instance()->load_core('Request_Handler'); |
| 471 | 471 | self::set_autoloaders(); |
| 472 | 472 | self::$_EEMSG = EE_Registry::instance()->load_lib('messages'); |
@@ -507,7 +507,7 @@ discard block |
||
| 507 | 507 | public static function payment(EE_Transaction $transaction, EE_Payment $payment = null) |
| 508 | 508 | { |
| 509 | 509 | // if there's no payment object, then we cannot do a payment type message! |
| 510 | - if (! $payment instanceof EE_Payment) { |
|
| 510 | + if ( ! $payment instanceof EE_Payment) { |
|
| 511 | 511 | return; |
| 512 | 512 | } |
| 513 | 513 | self::_load_controller(); |
@@ -554,7 +554,7 @@ discard block |
||
| 554 | 554 | public static function maybe_registration(EE_Registration $registration, $extra_details = array()) |
| 555 | 555 | { |
| 556 | 556 | |
| 557 | - if (! self::_verify_registration_notification_send($registration, $extra_details)) { |
|
| 557 | + if ( ! self::_verify_registration_notification_send($registration, $extra_details)) { |
|
| 558 | 558 | // no messages please |
| 559 | 559 | return; |
| 560 | 560 | } |
@@ -621,7 +621,7 @@ discard block |
||
| 621 | 621 | EE_Registration $registration, |
| 622 | 622 | $extra_details = array() |
| 623 | 623 | ) { |
| 624 | - if (! $registration->is_primary_registrant()) { |
|
| 624 | + if ( ! $registration->is_primary_registrant()) { |
|
| 625 | 625 | return false; |
| 626 | 626 | } |
| 627 | 627 | // first we check if we're in admin and not doing front ajax |
@@ -636,7 +636,7 @@ discard block |
||
| 636 | 636 | } else { |
| 637 | 637 | // frontend request (either regular or via AJAX) |
| 638 | 638 | // TXN is NOT finalized ? |
| 639 | - if (! isset($extra_details['finalized']) || $extra_details['finalized'] === false) { |
|
| 639 | + if ( ! isset($extra_details['finalized']) || $extra_details['finalized'] === false) { |
|
| 640 | 640 | return false; |
| 641 | 641 | } |
| 642 | 642 | // return visit but nothing changed ??? |
@@ -646,7 +646,7 @@ discard block |
||
| 646 | 646 | return false; |
| 647 | 647 | } |
| 648 | 648 | // NOT sending messages && reg status is something other than "Not-Approved" |
| 649 | - if (! apply_filters('FHEE__EED_Messages___maybe_registration__deliver_notifications', false) && |
|
| 649 | + if ( ! apply_filters('FHEE__EED_Messages___maybe_registration__deliver_notifications', false) && |
|
| 650 | 650 | $registration->status_ID() !== EEM_Registration::status_id_not_approved |
| 651 | 651 | ) { |
| 652 | 652 | return false; |
@@ -729,7 +729,7 @@ discard block |
||
| 729 | 729 | EE_Registry::instance()->REQ->set($request_key, $request_value); |
| 730 | 730 | } |
| 731 | 731 | |
| 732 | - if (! $messages_to_send = self::$_MSG_PROCESSOR->setup_messages_to_generate_from_registration_ids_in_request( |
|
| 732 | + if ( ! $messages_to_send = self::$_MSG_PROCESSOR->setup_messages_to_generate_from_registration_ids_in_request( |
|
| 733 | 733 | )) { |
| 734 | 734 | return false; |
| 735 | 735 | } |
@@ -763,7 +763,7 @@ discard block |
||
| 763 | 763 | self::_load_controller(); |
| 764 | 764 | |
| 765 | 765 | $msgID = EE_Registry::instance()->REQ->get('MSG_ID'); |
| 766 | - if (! $msgID) { |
|
| 766 | + if ( ! $msgID) { |
|
| 767 | 767 | EE_Error::add_error( |
| 768 | 768 | __( |
| 769 | 769 | 'Something went wrong because there is no "MSG_ID" value in the request', |
@@ -955,14 +955,14 @@ discard block |
||
| 955 | 955 | // get the message template group. |
| 956 | 956 | $msg_template_group = EEM_Message_Template_Group::instance()->get_one(array($template_query_params)); |
| 957 | 957 | // if we don't have an EE_Message_Template_Group then return |
| 958 | - if (! $msg_template_group instanceof EE_Message_Template_Group) { |
|
| 958 | + if ( ! $msg_template_group instanceof EE_Message_Template_Group) { |
|
| 959 | 959 | // remove EVT_ID from query params so that global templates get picked up |
| 960 | 960 | unset($template_query_params['Event.EVT_ID']); |
| 961 | 961 | // get global template as the fallback |
| 962 | 962 | $msg_template_group = EEM_Message_Template_Group::instance()->get_one(array($template_query_params)); |
| 963 | 963 | } |
| 964 | 964 | // if we don't have an EE_Message_Template_Group then return |
| 965 | - if (! $msg_template_group instanceof EE_Message_Template_Group) { |
|
| 965 | + if ( ! $msg_template_group instanceof EE_Message_Template_Group) { |
|
| 966 | 966 | return ''; |
| 967 | 967 | } |
| 968 | 968 | // generate the URL |
@@ -1093,7 +1093,7 @@ discard block |
||
| 1093 | 1093 | $generated_queue = self::$_MSG_PROCESSOR->batch_generate_from_queue($messages); |
| 1094 | 1094 | } |
| 1095 | 1095 | |
| 1096 | - if (! $generated_queue instanceof EE_Messages_Queue) { |
|
| 1096 | + if ( ! $generated_queue instanceof EE_Messages_Queue) { |
|
| 1097 | 1097 | EE_Error::add_error( |
| 1098 | 1098 | __( |
| 1099 | 1099 | 'The messages were not generated. This could mean there is already a batch being generated on a separate request, or because the selected messages are not ready for generation. Please wait a minute or two and try again.', |
@@ -1140,7 +1140,7 @@ discard block |
||
| 1140 | 1140 | $sent_queue = self::$_MSG_PROCESSOR->batch_send_from_queue($messages); |
| 1141 | 1141 | } |
| 1142 | 1142 | |
| 1143 | - if (! $sent_queue instanceof EE_Messages_Queue) { |
|
| 1143 | + if ( ! $sent_queue instanceof EE_Messages_Queue) { |
|
| 1144 | 1144 | EE_Error::add_error( |
| 1145 | 1145 | __( |
| 1146 | 1146 | 'The messages were not sent. This could mean there is already a batch being sent on a separate request, or because the selected messages are not sendable. Please wait a minute or two and try again.', |
@@ -1326,7 +1326,7 @@ discard block |
||
| 1326 | 1326 | $info['TXN_status'] = $transaction->status_ID(); |
| 1327 | 1327 | $info['TXN_reg_steps'] = $transaction->reg_steps(); |
| 1328 | 1328 | if ($transaction->ID()) { |
| 1329 | - $index = 'EE_Transaction: ' . $transaction->ID(); |
|
| 1329 | + $index = 'EE_Transaction: '.$transaction->ID(); |
|
| 1330 | 1330 | EEH_Debug_Tools::log($class, $func, $line, $info, $display_request, $index); |
| 1331 | 1331 | } |
| 1332 | 1332 | } |
@@ -15,87 +15,87 @@ |
||
| 15 | 15 | class EventMutation |
| 16 | 16 | { |
| 17 | 17 | |
| 18 | - /** |
|
| 19 | - * Maps the GraphQL input to a format that the model functions can use |
|
| 20 | - * |
|
| 21 | - * @param array $input Data coming from the GraphQL mutation query input |
|
| 22 | - * @param string $mutation_name Name of the mutation being performed |
|
| 23 | - * @return array |
|
| 24 | - * @throws Exception |
|
| 25 | - */ |
|
| 26 | - public static function prepareFields(array $input, string $mutation_name): array |
|
| 27 | - { |
|
| 28 | - $args = []; |
|
| 29 | - |
|
| 30 | - if (array_key_exists('allowDonations', $input)) { |
|
| 31 | - $args['EVT_donations'] = filter_var($input['allowDonations'], FILTER_VALIDATE_BOOLEAN); |
|
| 32 | - } |
|
| 33 | - |
|
| 34 | - if (array_key_exists('allowOverflow', $input)) { |
|
| 35 | - $args['EVT_allow_overflow'] = filter_var($input['allowOverflow'], FILTER_VALIDATE_BOOLEAN); |
|
| 36 | - } |
|
| 37 | - |
|
| 38 | - if (array_key_exists('altRegPage', $input)) { |
|
| 39 | - $args['EVT_external_URL'] = sanitize_text_field($input['altRegPage']); |
|
| 40 | - } |
|
| 41 | - |
|
| 42 | - if (! empty($input['defaultRegStatus'])) { |
|
| 43 | - $args['EVT_default_registration_status'] = sanitize_text_field($input['defaultRegStatus']); |
|
| 44 | - } |
|
| 45 | - |
|
| 46 | - if (! empty($input['description'])) { |
|
| 47 | - $args['EVT_desc'] = wp_kses_post($input['description']); |
|
| 48 | - } |
|
| 49 | - |
|
| 50 | - if (array_key_exists('displayDescription', $input)) { |
|
| 51 | - $args['EVT_display_desc'] = filter_var($input['displayDescription'], FILTER_VALIDATE_BOOLEAN); |
|
| 52 | - } |
|
| 53 | - |
|
| 54 | - if (array_key_exists('displayTicketSelector', $input)) { |
|
| 55 | - $args['EVT_display_ticket_selector'] = filter_var($input['displayTicketSelector'], FILTER_VALIDATE_BOOLEAN); |
|
| 56 | - } |
|
| 57 | - |
|
| 58 | - if (! empty($input['maxRegistrations'])) { |
|
| 59 | - $args['EVT_additional_limit'] = absint($input['maxRegistrations']); |
|
| 60 | - } |
|
| 61 | - |
|
| 62 | - if (array_key_exists('memberOnly', $input)) { |
|
| 63 | - $args['EVT_member_only'] = filter_var($input['memberOnly'], FILTER_VALIDATE_BOOLEAN); |
|
| 64 | - } |
|
| 65 | - |
|
| 66 | - if (! empty($input['name'])) { |
|
| 67 | - $args['EVT_name'] = sanitize_text_field($input['name']); |
|
| 68 | - } |
|
| 69 | - |
|
| 70 | - if (array_key_exists('order', $input)) { |
|
| 71 | - $args['EVT_order'] = absint($input['order']); |
|
| 72 | - } |
|
| 73 | - |
|
| 74 | - if (array_key_exists('phoneNumber', $input)) { |
|
| 75 | - $args['EVT_phone'] = sanitize_text_field($input['phoneNumber']); |
|
| 76 | - } |
|
| 77 | - |
|
| 78 | - if (! empty($input['shortDescription'])) { |
|
| 79 | - $args['EVT_short_desc'] = sanitize_post_field('post_excerpt', $input['shortDescription'], null, $context = 'db'); |
|
| 80 | - } |
|
| 81 | - |
|
| 82 | - if (! empty($input['timezoneString'])) { |
|
| 83 | - $args['EVT_timezone_string'] = sanitize_text_field($input['timezoneString']); |
|
| 84 | - } |
|
| 85 | - |
|
| 86 | - if (! empty($input['visibleOn'])) { |
|
| 87 | - $args['EVT_visible_on'] = new DateTime(sanitize_text_field($input['visibleOn'])); |
|
| 88 | - } |
|
| 89 | - |
|
| 90 | - if (! empty($input['manager'])) { |
|
| 91 | - $parts = Relay::fromGlobalId(sanitize_text_field($input['manager'])); |
|
| 92 | - $args['EVT_wp_user'] = ! empty($parts['id']) ? $parts['id'] : null; |
|
| 93 | - } |
|
| 94 | - |
|
| 95 | - return apply_filters( |
|
| 96 | - 'FHEE__EventEspresso_core_domain_services_graphql_data_mutations__event_args', |
|
| 97 | - $args, |
|
| 98 | - $input |
|
| 99 | - ); |
|
| 100 | - } |
|
| 18 | + /** |
|
| 19 | + * Maps the GraphQL input to a format that the model functions can use |
|
| 20 | + * |
|
| 21 | + * @param array $input Data coming from the GraphQL mutation query input |
|
| 22 | + * @param string $mutation_name Name of the mutation being performed |
|
| 23 | + * @return array |
|
| 24 | + * @throws Exception |
|
| 25 | + */ |
|
| 26 | + public static function prepareFields(array $input, string $mutation_name): array |
|
| 27 | + { |
|
| 28 | + $args = []; |
|
| 29 | + |
|
| 30 | + if (array_key_exists('allowDonations', $input)) { |
|
| 31 | + $args['EVT_donations'] = filter_var($input['allowDonations'], FILTER_VALIDATE_BOOLEAN); |
|
| 32 | + } |
|
| 33 | + |
|
| 34 | + if (array_key_exists('allowOverflow', $input)) { |
|
| 35 | + $args['EVT_allow_overflow'] = filter_var($input['allowOverflow'], FILTER_VALIDATE_BOOLEAN); |
|
| 36 | + } |
|
| 37 | + |
|
| 38 | + if (array_key_exists('altRegPage', $input)) { |
|
| 39 | + $args['EVT_external_URL'] = sanitize_text_field($input['altRegPage']); |
|
| 40 | + } |
|
| 41 | + |
|
| 42 | + if (! empty($input['defaultRegStatus'])) { |
|
| 43 | + $args['EVT_default_registration_status'] = sanitize_text_field($input['defaultRegStatus']); |
|
| 44 | + } |
|
| 45 | + |
|
| 46 | + if (! empty($input['description'])) { |
|
| 47 | + $args['EVT_desc'] = wp_kses_post($input['description']); |
|
| 48 | + } |
|
| 49 | + |
|
| 50 | + if (array_key_exists('displayDescription', $input)) { |
|
| 51 | + $args['EVT_display_desc'] = filter_var($input['displayDescription'], FILTER_VALIDATE_BOOLEAN); |
|
| 52 | + } |
|
| 53 | + |
|
| 54 | + if (array_key_exists('displayTicketSelector', $input)) { |
|
| 55 | + $args['EVT_display_ticket_selector'] = filter_var($input['displayTicketSelector'], FILTER_VALIDATE_BOOLEAN); |
|
| 56 | + } |
|
| 57 | + |
|
| 58 | + if (! empty($input['maxRegistrations'])) { |
|
| 59 | + $args['EVT_additional_limit'] = absint($input['maxRegistrations']); |
|
| 60 | + } |
|
| 61 | + |
|
| 62 | + if (array_key_exists('memberOnly', $input)) { |
|
| 63 | + $args['EVT_member_only'] = filter_var($input['memberOnly'], FILTER_VALIDATE_BOOLEAN); |
|
| 64 | + } |
|
| 65 | + |
|
| 66 | + if (! empty($input['name'])) { |
|
| 67 | + $args['EVT_name'] = sanitize_text_field($input['name']); |
|
| 68 | + } |
|
| 69 | + |
|
| 70 | + if (array_key_exists('order', $input)) { |
|
| 71 | + $args['EVT_order'] = absint($input['order']); |
|
| 72 | + } |
|
| 73 | + |
|
| 74 | + if (array_key_exists('phoneNumber', $input)) { |
|
| 75 | + $args['EVT_phone'] = sanitize_text_field($input['phoneNumber']); |
|
| 76 | + } |
|
| 77 | + |
|
| 78 | + if (! empty($input['shortDescription'])) { |
|
| 79 | + $args['EVT_short_desc'] = sanitize_post_field('post_excerpt', $input['shortDescription'], null, $context = 'db'); |
|
| 80 | + } |
|
| 81 | + |
|
| 82 | + if (! empty($input['timezoneString'])) { |
|
| 83 | + $args['EVT_timezone_string'] = sanitize_text_field($input['timezoneString']); |
|
| 84 | + } |
|
| 85 | + |
|
| 86 | + if (! empty($input['visibleOn'])) { |
|
| 87 | + $args['EVT_visible_on'] = new DateTime(sanitize_text_field($input['visibleOn'])); |
|
| 88 | + } |
|
| 89 | + |
|
| 90 | + if (! empty($input['manager'])) { |
|
| 91 | + $parts = Relay::fromGlobalId(sanitize_text_field($input['manager'])); |
|
| 92 | + $args['EVT_wp_user'] = ! empty($parts['id']) ? $parts['id'] : null; |
|
| 93 | + } |
|
| 94 | + |
|
| 95 | + return apply_filters( |
|
| 96 | + 'FHEE__EventEspresso_core_domain_services_graphql_data_mutations__event_args', |
|
| 97 | + $args, |
|
| 98 | + $input |
|
| 99 | + ); |
|
| 100 | + } |
|
| 101 | 101 | } |
@@ -39,11 +39,11 @@ discard block |
||
| 39 | 39 | $args['EVT_external_URL'] = sanitize_text_field($input['altRegPage']); |
| 40 | 40 | } |
| 41 | 41 | |
| 42 | - if (! empty($input['defaultRegStatus'])) { |
|
| 42 | + if ( ! empty($input['defaultRegStatus'])) { |
|
| 43 | 43 | $args['EVT_default_registration_status'] = sanitize_text_field($input['defaultRegStatus']); |
| 44 | 44 | } |
| 45 | 45 | |
| 46 | - if (! empty($input['description'])) { |
|
| 46 | + if ( ! empty($input['description'])) { |
|
| 47 | 47 | $args['EVT_desc'] = wp_kses_post($input['description']); |
| 48 | 48 | } |
| 49 | 49 | |
@@ -55,7 +55,7 @@ discard block |
||
| 55 | 55 | $args['EVT_display_ticket_selector'] = filter_var($input['displayTicketSelector'], FILTER_VALIDATE_BOOLEAN); |
| 56 | 56 | } |
| 57 | 57 | |
| 58 | - if (! empty($input['maxRegistrations'])) { |
|
| 58 | + if ( ! empty($input['maxRegistrations'])) { |
|
| 59 | 59 | $args['EVT_additional_limit'] = absint($input['maxRegistrations']); |
| 60 | 60 | } |
| 61 | 61 | |
@@ -63,7 +63,7 @@ discard block |
||
| 63 | 63 | $args['EVT_member_only'] = filter_var($input['memberOnly'], FILTER_VALIDATE_BOOLEAN); |
| 64 | 64 | } |
| 65 | 65 | |
| 66 | - if (! empty($input['name'])) { |
|
| 66 | + if ( ! empty($input['name'])) { |
|
| 67 | 67 | $args['EVT_name'] = sanitize_text_field($input['name']); |
| 68 | 68 | } |
| 69 | 69 | |
@@ -75,19 +75,19 @@ discard block |
||
| 75 | 75 | $args['EVT_phone'] = sanitize_text_field($input['phoneNumber']); |
| 76 | 76 | } |
| 77 | 77 | |
| 78 | - if (! empty($input['shortDescription'])) { |
|
| 78 | + if ( ! empty($input['shortDescription'])) { |
|
| 79 | 79 | $args['EVT_short_desc'] = sanitize_post_field('post_excerpt', $input['shortDescription'], null, $context = 'db'); |
| 80 | 80 | } |
| 81 | 81 | |
| 82 | - if (! empty($input['timezoneString'])) { |
|
| 82 | + if ( ! empty($input['timezoneString'])) { |
|
| 83 | 83 | $args['EVT_timezone_string'] = sanitize_text_field($input['timezoneString']); |
| 84 | 84 | } |
| 85 | 85 | |
| 86 | - if (! empty($input['visibleOn'])) { |
|
| 86 | + if ( ! empty($input['visibleOn'])) { |
|
| 87 | 87 | $args['EVT_visible_on'] = new DateTime(sanitize_text_field($input['visibleOn'])); |
| 88 | 88 | } |
| 89 | 89 | |
| 90 | - if (! empty($input['manager'])) { |
|
| 90 | + if ( ! empty($input['manager'])) { |
|
| 91 | 91 | $parts = Relay::fromGlobalId(sanitize_text_field($input['manager'])); |
| 92 | 92 | $args['EVT_wp_user'] = ! empty($parts['id']) ? $parts['id'] : null; |
| 93 | 93 | } |
@@ -23,1241 +23,1241 @@ |
||
| 23 | 23 | class EE_Register_Addon implements EEI_Plugin_API |
| 24 | 24 | { |
| 25 | 25 | |
| 26 | - /** |
|
| 27 | - * possibly truncated version of the EE core version string |
|
| 28 | - * |
|
| 29 | - * @var string |
|
| 30 | - */ |
|
| 31 | - protected static $_core_version = ''; |
|
| 32 | - |
|
| 33 | - /** |
|
| 34 | - * Holds values for registered addons |
|
| 35 | - * |
|
| 36 | - * @var array |
|
| 37 | - */ |
|
| 38 | - protected static $_settings = []; |
|
| 39 | - |
|
| 40 | - /** |
|
| 41 | - * @var array $_incompatible_addons keys are addon SLUGS |
|
| 42 | - * (first argument passed to EE_Register_Addon::register()), keys are |
|
| 43 | - * their MINIMUM VERSION (with all 5 parts. Eg 1.2.3.rc.004). |
|
| 44 | - * Generally this should be used sparingly, as we don't want to muddle up |
|
| 45 | - * EE core with knowledge of ALL the addons out there. |
|
| 46 | - * If you want NO versions of an addon to run with a certain version of core, |
|
| 47 | - * it's usually best to define the addon's "min_core_version" as part of its call |
|
| 48 | - * to EE_Register_Addon::register(), rather than using this array with a super high value for its |
|
| 49 | - * minimum plugin version. |
|
| 50 | - * @access protected |
|
| 51 | - */ |
|
| 52 | - protected static $_incompatible_addons = [ |
|
| 53 | - 'Multi_Event_Registration' => '2.0.11.rc.002', |
|
| 54 | - 'Promotions' => '1.0.0.rc.084', |
|
| 55 | - ]; |
|
| 56 | - |
|
| 57 | - /** |
|
| 58 | - * @var LoaderInterface |
|
| 59 | - */ |
|
| 60 | - protected static $loader; |
|
| 61 | - |
|
| 62 | - |
|
| 63 | - /** |
|
| 64 | - * We should always be comparing core to a version like '4.3.0.rc.000', |
|
| 65 | - * not just '4.3.0'. |
|
| 66 | - * So if the addon developer doesn't provide that full version string, |
|
| 67 | - * fill in the blanks for them |
|
| 68 | - * |
|
| 69 | - * @param string $min_core_version |
|
| 70 | - * @return string always like '4.3.0.rc.000' |
|
| 71 | - */ |
|
| 72 | - protected static function _effective_version(string $min_core_version): string |
|
| 73 | - { |
|
| 74 | - // versions: 4 . 3 . 1 . p . 123 |
|
| 75 | - // offsets: 0 . 1 . 2 . 3 . 4 |
|
| 76 | - $version_parts = explode('.', $min_core_version); |
|
| 77 | - // check they specified the micro version (after 2nd period) |
|
| 78 | - if (! isset($version_parts[2])) { |
|
| 79 | - $version_parts[2] = '0'; |
|
| 80 | - } |
|
| 81 | - // if they didn't specify the 'p', or 'rc' part. Just assume the lowest possible |
|
| 82 | - // soon we can assume that's 'rc', but this current version is 'alpha' |
|
| 83 | - if (! isset($version_parts[3])) { |
|
| 84 | - $version_parts[3] = 'dev'; |
|
| 85 | - } |
|
| 86 | - if (! isset($version_parts[4])) { |
|
| 87 | - $version_parts[4] = '000'; |
|
| 88 | - } |
|
| 89 | - return implode('.', $version_parts); |
|
| 90 | - } |
|
| 91 | - |
|
| 92 | - |
|
| 93 | - /** |
|
| 94 | - * Returns whether or not the min core version requirement of the addon is met |
|
| 95 | - * |
|
| 96 | - * @param string $min_core_version the minimum core version required by the addon |
|
| 97 | - * @param string $actual_core_version the actual core version, optional |
|
| 98 | - * @return boolean |
|
| 99 | - */ |
|
| 100 | - public static function _meets_min_core_version_requirement( |
|
| 101 | - string $min_core_version, |
|
| 102 | - $actual_core_version = EVENT_ESPRESSO_VERSION |
|
| 103 | - ): bool { |
|
| 104 | - return version_compare( |
|
| 105 | - self::_effective_version($actual_core_version), |
|
| 106 | - self::_effective_version($min_core_version), |
|
| 107 | - '>=' |
|
| 108 | - ); |
|
| 109 | - } |
|
| 110 | - |
|
| 111 | - |
|
| 112 | - /** |
|
| 113 | - * Method for registering new EE_Addons. |
|
| 114 | - * Should be called AFTER AHEE__EE_System__load_espresso_addons but BEFORE |
|
| 115 | - * AHEE__EE_System___detect_if_activation_or_upgrade__begin in order to register all its components. However, it |
|
| 116 | - * may also be called after the 'activate_plugin' action (when an addon is activated), because an activating addon |
|
| 117 | - * won't be loaded by WP until after AHEE__EE_System__load_espresso_addons has fired. If its called after |
|
| 118 | - * 'activate_plugin', it registers the addon still, but its components are not registered |
|
| 119 | - * (they shouldn't be needed anyways, because it's just an activation request and they won't have a chance to do |
|
| 120 | - * anything anyways). Instead, it just sets the newly-activated addon's activation indicator wp option and returns |
|
| 121 | - * (so that we can detect that the addon has activated on the subsequent request) |
|
| 122 | - * |
|
| 123 | - * @param string $addon_name [Required] the EE_Addon's name. |
|
| 124 | - * @param array $setup_args { |
|
| 125 | - * An array of arguments provided for registering |
|
| 126 | - * the message type. |
|
| 127 | - * @type string $class_name the addon's main file name. |
|
| 128 | - * If left blank, generated from the addon name, |
|
| 129 | - * changes something like "calendar" to |
|
| 130 | - * "EE_Calendar" |
|
| 131 | - * @type string $min_core_version the minimum version of EE Core that the |
|
| 132 | - * addon will work with. eg "4.8.1.rc.084" |
|
| 133 | - * @type string $version the "software" version for the addon. eg |
|
| 134 | - * "1.0.0.p" for a first stable release, or |
|
| 135 | - * "1.0.0.rc.043" for a version in progress |
|
| 136 | - * @type string $main_file_path the full server path to the main file |
|
| 137 | - * loaded directly by WP |
|
| 138 | - * @type DomainInterface $domain child class of |
|
| 139 | - * EventEspresso\core\domain\DomainBase |
|
| 140 | - * @type string $domain_fqcn Fully Qualified Class Name |
|
| 141 | - * for the addon's Domain class |
|
| 142 | - * (see EventEspresso\core\domain\Domain) |
|
| 143 | - * @type string $admin_path full server path to the folder where the |
|
| 144 | - * addon\'s admin files reside |
|
| 145 | - * @type string $admin_callback a method to be called when the EE Admin is |
|
| 146 | - * first invoked, can be used for hooking into |
|
| 147 | - * any admin page |
|
| 148 | - * @type string $config_section the section name for this addon's |
|
| 149 | - * configuration settings section |
|
| 150 | - * (defaults to "addons") |
|
| 151 | - * @type string $config_class the class name for this addon's |
|
| 152 | - * configuration settings object |
|
| 153 | - * @type string $config_name the class name for this addon's |
|
| 154 | - * configuration settings object |
|
| 155 | - * @type string $autoloader_paths [Required] an array of class names and the full |
|
| 156 | - * server paths to those files. |
|
| 157 | - * @type string $autoloader_folders an array of "full server paths" for any |
|
| 158 | - * folders containing classes that might be |
|
| 159 | - * invoked by the addon |
|
| 160 | - * @type string $dms_paths [Required] an array of full server paths to |
|
| 161 | - * folders that contain data migration scripts. |
|
| 162 | - * The key should be the EE_Addon class name that |
|
| 163 | - * this set of data migration scripts belongs to. |
|
| 164 | - * If the EE_Addon class is namespaced, then this |
|
| 165 | - * needs to be the Fully Qualified Class Name |
|
| 166 | - * @type string $module_paths an array of full server paths to any |
|
| 167 | - * EED_Modules used by the addon |
|
| 168 | - * @type string $shortcode_paths an array of full server paths to folders |
|
| 169 | - * that contain EES_Shortcodes |
|
| 170 | - * @type string $widget_paths an array of full server paths to folders |
|
| 171 | - * that contain WP_Widgets |
|
| 172 | - * @type string $pue_options |
|
| 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 boolean |
|
| 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 | - if (! self::$loader instanceof LoaderInterface) { |
|
| 264 | - self::$loader = EventEspresso\core\services\loaders\LoaderFactory::getLoader(); |
|
| 265 | - } |
|
| 266 | - // make sure this was called in the right place! |
|
| 267 | - if (! did_action('activate_plugin') |
|
| 268 | - && ( |
|
| 269 | - ! did_action('AHEE__EE_System__load_espresso_addons') |
|
| 270 | - || did_action('AHEE__EE_System___detect_if_activation_or_upgrade__begin') |
|
| 271 | - ) |
|
| 272 | - ) { |
|
| 273 | - EE_Error::doing_it_wrong( |
|
| 274 | - __METHOD__, |
|
| 275 | - sprintf( |
|
| 276 | - esc_html__( |
|
| 277 | - '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.', |
|
| 278 | - 'event_espresso' |
|
| 279 | - ), |
|
| 280 | - $addon_name |
|
| 281 | - ), |
|
| 282 | - '4.3.0' |
|
| 283 | - ); |
|
| 284 | - return false; |
|
| 285 | - } |
|
| 286 | - // required fields MUST be present, so let's make sure they are. |
|
| 287 | - EE_Register_Addon::_verify_parameters($addon_name, $setup_args); |
|
| 288 | - // get class name for addon |
|
| 289 | - $class_name = EE_Register_Addon::_parse_class_name($addon_name, $setup_args); |
|
| 290 | - // setup $_settings array from incoming values. |
|
| 291 | - $addon_settings = EE_Register_Addon::_get_addon_settings($class_name, $setup_args); |
|
| 292 | - // setup PUE |
|
| 293 | - EE_Register_Addon::_parse_pue_options($addon_name, $class_name, $setup_args); |
|
| 294 | - // does this addon work with this version of core or WordPress ? |
|
| 295 | - if (! EE_Register_Addon::_addon_is_compatible($addon_name, $addon_settings)) { |
|
| 296 | - return false; |
|
| 297 | - } |
|
| 298 | - // register namespaces |
|
| 299 | - EE_Register_Addon::_setup_namespaces($addon_settings); |
|
| 300 | - // check if this is an activation request |
|
| 301 | - if (EE_Register_Addon::_addon_activation($addon_name, $addon_settings)) { |
|
| 302 | - // dont bother setting up the rest of the addon atm |
|
| 303 | - return false; |
|
| 304 | - } |
|
| 305 | - // we need cars |
|
| 306 | - EE_Register_Addon::_setup_autoloaders($addon_name); |
|
| 307 | - // register new models and extensions |
|
| 308 | - EE_Register_Addon::_register_models_and_extensions($addon_name); |
|
| 309 | - // setup DMS |
|
| 310 | - EE_Register_Addon::_register_data_migration_scripts($addon_name); |
|
| 311 | - // if config_class is present let's register config. |
|
| 312 | - EE_Register_Addon::_register_config($addon_name); |
|
| 313 | - // register admin pages |
|
| 314 | - EE_Register_Addon::_register_admin_pages($addon_name); |
|
| 315 | - // add to list of modules to be registered |
|
| 316 | - EE_Register_Addon::_register_modules($addon_name); |
|
| 317 | - // add to list of shortcodes to be registered |
|
| 318 | - EE_Register_Addon::_register_shortcodes($addon_name); |
|
| 319 | - // add to list of widgets to be registered |
|
| 320 | - EE_Register_Addon::_register_widgets($addon_name); |
|
| 321 | - // register capability related stuff. |
|
| 322 | - EE_Register_Addon::_register_capabilities($addon_name); |
|
| 323 | - // any message type to register? |
|
| 324 | - EE_Register_Addon::_register_message_types($addon_name); |
|
| 325 | - // any custom post type/ custom capabilities or default terms to register |
|
| 326 | - EE_Register_Addon::_register_custom_post_types($addon_name); |
|
| 327 | - // and any payment methods |
|
| 328 | - EE_Register_Addon::_register_payment_methods($addon_name); |
|
| 329 | - // and privacy policy generators |
|
| 330 | - EE_Register_Addon::registerPrivacyPolicies($addon_name); |
|
| 331 | - // and privacy policy generators |
|
| 332 | - EE_Register_Addon::registerPersonalDataExporters($addon_name); |
|
| 333 | - // and privacy policy generators |
|
| 334 | - EE_Register_Addon::registerPersonalDataErasers($addon_name); |
|
| 335 | - // load and instantiate main addon class |
|
| 336 | - $addon = EE_Register_Addon::_load_and_init_addon_class($addon_name); |
|
| 337 | - // delay calling after_registration hook on each addon until after all add-ons have been registered. |
|
| 338 | - add_action('AHEE__EE_System__load_espresso_addons__complete', [$addon, 'after_registration'], 999); |
|
| 339 | - return $addon instanceof EE_Addon; |
|
| 340 | - } |
|
| 341 | - |
|
| 342 | - |
|
| 343 | - /** |
|
| 344 | - * @param string $addon_name |
|
| 345 | - * @param array $setup_args |
|
| 346 | - * @return void |
|
| 347 | - * @throws EE_Error |
|
| 348 | - */ |
|
| 349 | - private static function _verify_parameters(string $addon_name, array $setup_args) |
|
| 350 | - { |
|
| 351 | - // required fields MUST be present, so let's make sure they are. |
|
| 352 | - if (empty($addon_name) || ! is_array($setup_args)) { |
|
| 353 | - throw new EE_Error( |
|
| 354 | - esc_html__( |
|
| 355 | - '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.', |
|
| 356 | - 'event_espresso' |
|
| 357 | - ) |
|
| 358 | - ); |
|
| 359 | - } |
|
| 360 | - if (! isset($setup_args['main_file_path']) || empty($setup_args['main_file_path'])) { |
|
| 361 | - throw new EE_Error( |
|
| 362 | - sprintf( |
|
| 363 | - esc_html__( |
|
| 364 | - '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', |
|
| 365 | - 'event_espresso' |
|
| 366 | - ), |
|
| 367 | - implode(',', array_keys($setup_args)) |
|
| 368 | - ) |
|
| 369 | - ); |
|
| 370 | - } |
|
| 371 | - // check that addon has not already been registered with that name |
|
| 372 | - if (isset(self::$_settings[ $addon_name ]) && ! did_action('activate_plugin')) { |
|
| 373 | - throw new EE_Error( |
|
| 374 | - sprintf( |
|
| 375 | - esc_html__( |
|
| 376 | - 'An EE_Addon with the name "%s" has already been registered and each EE_Addon requires a unique name.', |
|
| 377 | - 'event_espresso' |
|
| 378 | - ), |
|
| 379 | - $addon_name |
|
| 380 | - ) |
|
| 381 | - ); |
|
| 382 | - } |
|
| 383 | - } |
|
| 384 | - |
|
| 385 | - |
|
| 386 | - /** |
|
| 387 | - * @param string $addon_name |
|
| 388 | - * @param array $setup_args |
|
| 389 | - * @return string |
|
| 390 | - */ |
|
| 391 | - private static function _parse_class_name(string $addon_name, array $setup_args): string |
|
| 392 | - { |
|
| 393 | - if (empty($setup_args['class_name'])) { |
|
| 394 | - // generate one by first separating name with spaces |
|
| 395 | - $class_name = str_replace(['-', '_'], ' ', trim($addon_name)); |
|
| 396 | - // capitalize, then replace spaces with underscores |
|
| 397 | - $class_name = str_replace(' ', '_', ucwords($class_name)); |
|
| 398 | - } else { |
|
| 399 | - $class_name = $setup_args['class_name']; |
|
| 400 | - } |
|
| 401 | - // check if classname is fully qualified or is a legacy classname already prefixed with 'EE_' |
|
| 402 | - return strpos($class_name, '\\') || strpos($class_name, 'EE_') === 0 |
|
| 403 | - ? $class_name |
|
| 404 | - : 'EE_' . $class_name; |
|
| 405 | - } |
|
| 406 | - |
|
| 407 | - |
|
| 408 | - /** |
|
| 409 | - * @param string $class_name |
|
| 410 | - * @param array $setup_args |
|
| 411 | - * @return array |
|
| 412 | - */ |
|
| 413 | - private static function _get_addon_settings(string $class_name, array $setup_args): array |
|
| 414 | - { |
|
| 415 | - // setup $_settings array from incoming values. |
|
| 416 | - $addon_settings = [ |
|
| 417 | - // generated from the addon name, changes something like "calendar" to "EE_Calendar" |
|
| 418 | - 'class_name' => $class_name, |
|
| 419 | - // the addon slug for use in URLs, etc |
|
| 420 | - 'plugin_slug' => isset($setup_args['plugin_slug']) |
|
| 421 | - ? (string) $setup_args['plugin_slug'] |
|
| 422 | - : '', |
|
| 423 | - // page slug to be used when generating the "Settings" link on the WP plugin page |
|
| 424 | - 'plugin_action_slug' => isset($setup_args['plugin_action_slug']) |
|
| 425 | - ? (string) $setup_args['plugin_action_slug'] |
|
| 426 | - : '', |
|
| 427 | - // the "software" version for the addon |
|
| 428 | - 'version' => isset($setup_args['version']) |
|
| 429 | - ? (string) $setup_args['version'] |
|
| 430 | - : '', |
|
| 431 | - // the minimum version of EE Core that the addon will work with |
|
| 432 | - 'min_core_version' => isset($setup_args['min_core_version']) |
|
| 433 | - ? (string) $setup_args['min_core_version'] |
|
| 434 | - : '', |
|
| 435 | - // the minimum version of WordPress that the addon will work with |
|
| 436 | - 'min_wp_version' => isset($setup_args['min_wp_version']) |
|
| 437 | - ? (string) $setup_args['min_wp_version'] |
|
| 438 | - : EE_MIN_WP_VER_REQUIRED, |
|
| 439 | - // full server path to main file (file loaded directly by WP) |
|
| 440 | - 'main_file_path' => isset($setup_args['main_file_path']) |
|
| 441 | - ? (string) $setup_args['main_file_path'] |
|
| 442 | - : '', |
|
| 443 | - // instance of \EventEspresso\core\domain\DomainInterface |
|
| 444 | - 'domain' => isset($setup_args['domain']) && $setup_args['domain'] instanceof DomainInterface |
|
| 445 | - ? $setup_args['domain'] |
|
| 446 | - : null, |
|
| 447 | - // Fully Qualified Class Name for the addon's Domain class |
|
| 448 | - 'domain_fqcn' => isset($setup_args['domain_fqcn']) |
|
| 449 | - ? (string) $setup_args['domain_fqcn'] |
|
| 450 | - : '', |
|
| 451 | - // path to folder containing files for integrating with the EE core admin and/or setting up EE admin pages |
|
| 452 | - 'admin_path' => isset($setup_args['admin_path']) |
|
| 453 | - ? (string) $setup_args['admin_path'] : '', |
|
| 454 | - // a method to be called when the EE Admin is first invoked, can be used for hooking into any admin page |
|
| 455 | - 'admin_callback' => isset($setup_args['admin_callback']) |
|
| 456 | - ? (string) $setup_args['admin_callback'] |
|
| 457 | - : '', |
|
| 458 | - // the section name for this addon's configuration settings section (defaults to "addons") |
|
| 459 | - 'config_section' => isset($setup_args['config_section']) |
|
| 460 | - ? (string) $setup_args['config_section'] |
|
| 461 | - : 'addons', |
|
| 462 | - // the class name for this addon's configuration settings object |
|
| 463 | - 'config_class' => isset($setup_args['config_class']) |
|
| 464 | - ? (string) $setup_args['config_class'] : '', |
|
| 465 | - // the name given to the config for this addons' configuration settings object (optional) |
|
| 466 | - 'config_name' => isset($setup_args['config_name']) |
|
| 467 | - ? (string) $setup_args['config_name'] : '', |
|
| 468 | - // an array of "class names" => "full server paths" for any classes that might be invoked by the addon |
|
| 469 | - 'autoloader_paths' => isset($setup_args['autoloader_paths']) |
|
| 470 | - ? (array) $setup_args['autoloader_paths'] |
|
| 471 | - : [], |
|
| 472 | - // an array of "full server paths" for any folders containing classes that might be invoked by the addon |
|
| 473 | - 'autoloader_folders' => isset($setup_args['autoloader_folders']) |
|
| 474 | - ? (array) $setup_args['autoloader_folders'] |
|
| 475 | - : [], |
|
| 476 | - // array of full server paths to any EE_DMS data migration scripts used by the addon. |
|
| 477 | - // The key should be the EE_Addon class name that this set of data migration scripts belongs to. |
|
| 478 | - // If the EE_Addon class is namespaced, then this needs to be the Fully Qualified Class Name |
|
| 479 | - 'dms_paths' => isset($setup_args['dms_paths']) |
|
| 480 | - ? (array) $setup_args['dms_paths'] |
|
| 481 | - : [], |
|
| 482 | - // array of full server paths to any EED_Modules used by the addon |
|
| 483 | - 'module_paths' => isset($setup_args['module_paths']) |
|
| 484 | - ? (array) $setup_args['module_paths'] |
|
| 485 | - : [], |
|
| 486 | - // array of full server paths to any EES_Shortcodes used by the addon |
|
| 487 | - 'shortcode_paths' => isset($setup_args['shortcode_paths']) |
|
| 488 | - ? (array) $setup_args['shortcode_paths'] |
|
| 489 | - : [], |
|
| 490 | - 'shortcode_fqcns' => isset($setup_args['shortcode_fqcns']) |
|
| 491 | - ? (array) $setup_args['shortcode_fqcns'] |
|
| 492 | - : [], |
|
| 493 | - // array of full server paths to any WP_Widgets used by the addon |
|
| 494 | - 'widget_paths' => isset($setup_args['widget_paths']) |
|
| 495 | - ? (array) $setup_args['widget_paths'] |
|
| 496 | - : [], |
|
| 497 | - // array of PUE options used by the addon |
|
| 498 | - 'pue_options' => isset($setup_args['pue_options']) |
|
| 499 | - ? (array) $setup_args['pue_options'] |
|
| 500 | - : [], |
|
| 501 | - 'message_types' => isset($setup_args['message_types']) |
|
| 502 | - ? (array) $setup_args['message_types'] |
|
| 503 | - : [], |
|
| 504 | - 'capabilities' => isset($setup_args['capabilities']) |
|
| 505 | - ? (array) $setup_args['capabilities'] |
|
| 506 | - : [], |
|
| 507 | - 'capability_maps' => isset($setup_args['capability_maps']) |
|
| 508 | - ? (array) $setup_args['capability_maps'] |
|
| 509 | - : [], |
|
| 510 | - 'model_paths' => isset($setup_args['model_paths']) |
|
| 511 | - ? (array) $setup_args['model_paths'] |
|
| 512 | - : [], |
|
| 513 | - 'class_paths' => isset($setup_args['class_paths']) |
|
| 514 | - ? (array) $setup_args['class_paths'] |
|
| 515 | - : [], |
|
| 516 | - 'model_extension_paths' => isset($setup_args['model_extension_paths']) |
|
| 517 | - ? (array) $setup_args['model_extension_paths'] |
|
| 518 | - : [], |
|
| 519 | - 'class_extension_paths' => isset($setup_args['class_extension_paths']) |
|
| 520 | - ? (array) $setup_args['class_extension_paths'] |
|
| 521 | - : [], |
|
| 522 | - 'custom_post_types' => isset($setup_args['custom_post_types']) |
|
| 523 | - ? (array) $setup_args['custom_post_types'] |
|
| 524 | - : [], |
|
| 525 | - 'custom_taxonomies' => isset($setup_args['custom_taxonomies']) |
|
| 526 | - ? (array) $setup_args['custom_taxonomies'] |
|
| 527 | - : [], |
|
| 528 | - 'payment_method_paths' => isset($setup_args['payment_method_paths']) |
|
| 529 | - ? (array) $setup_args['payment_method_paths'] |
|
| 530 | - : [], |
|
| 531 | - 'default_terms' => isset($setup_args['default_terms']) |
|
| 532 | - ? (array) $setup_args['default_terms'] |
|
| 533 | - : [], |
|
| 534 | - // if not empty, inserts a new table row after this plugin's row on the WP Plugins page |
|
| 535 | - // that can be used for adding upgrading/marketing info |
|
| 536 | - 'plugins_page_row' => isset($setup_args['plugins_page_row']) |
|
| 537 | - ? (array) $setup_args['plugins_page_row'] |
|
| 538 | - : [], |
|
| 539 | - 'namespace' => isset( |
|
| 540 | - $setup_args['namespace']['FQNS'], |
|
| 541 | - $setup_args['namespace']['DIR'] |
|
| 542 | - ) |
|
| 543 | - ? (array) $setup_args['namespace'] |
|
| 544 | - : [], |
|
| 545 | - 'privacy_policies' => isset($setup_args['privacy_policies']) |
|
| 546 | - ? (array) $setup_args['privacy_policies'] |
|
| 547 | - : '', |
|
| 548 | - ]; |
|
| 549 | - // if plugin_action_slug is NOT set, but an admin page path IS set, |
|
| 550 | - // then let's just use the plugin_slug since that will be used for linking to the admin page |
|
| 551 | - $addon_settings['plugin_action_slug'] = empty($addon_settings['plugin_action_slug']) |
|
| 552 | - && ! empty($addon_settings['admin_path']) |
|
| 553 | - ? $addon_settings['plugin_slug'] |
|
| 554 | - : $addon_settings['plugin_action_slug']; |
|
| 555 | - // full server path to main file (file loaded directly by WP) |
|
| 556 | - $addon_settings['plugin_basename'] = plugin_basename($addon_settings['main_file_path']); |
|
| 557 | - return $addon_settings; |
|
| 558 | - } |
|
| 559 | - |
|
| 560 | - |
|
| 561 | - /** |
|
| 562 | - * @param string $addon_name |
|
| 563 | - * @param array $addon_settings |
|
| 564 | - * @return boolean |
|
| 565 | - */ |
|
| 566 | - private static function _addon_is_compatible(string $addon_name, array $addon_settings): bool |
|
| 567 | - { |
|
| 568 | - global $wp_version; |
|
| 569 | - $incompatibility_message = ''; |
|
| 570 | - // check whether this addon version is compatible with EE core |
|
| 571 | - if (isset(EE_Register_Addon::$_incompatible_addons[ $addon_name ]) |
|
| 572 | - && ! self::_meets_min_core_version_requirement( |
|
| 573 | - EE_Register_Addon::$_incompatible_addons[ $addon_name ], |
|
| 574 | - $addon_settings['version'] |
|
| 575 | - ) |
|
| 576 | - ) { |
|
| 577 | - $incompatibility_message = sprintf( |
|
| 578 | - __( |
|
| 579 | - '%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.', |
|
| 580 | - 'event_espresso' |
|
| 581 | - ), |
|
| 582 | - $addon_name, |
|
| 583 | - '<br />', |
|
| 584 | - EE_Register_Addon::$_incompatible_addons[ $addon_name ], |
|
| 585 | - '<span style="font-weight: bold; color: #D54E21;">', |
|
| 586 | - '</span><br />' |
|
| 587 | - ); |
|
| 588 | - } elseif (! self::_meets_min_core_version_requirement($addon_settings['min_core_version'], espresso_version()) |
|
| 589 | - ) { |
|
| 590 | - $incompatibility_message = sprintf( |
|
| 591 | - __( |
|
| 592 | - '%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".', |
|
| 593 | - 'event_espresso' |
|
| 594 | - ), |
|
| 595 | - $addon_name, |
|
| 596 | - self::_effective_version($addon_settings['min_core_version']), |
|
| 597 | - self::_effective_version(espresso_version()), |
|
| 598 | - '<br />', |
|
| 599 | - '<span style="font-weight: bold; color: #D54E21;">', |
|
| 600 | - '</span><br />' |
|
| 601 | - ); |
|
| 602 | - } elseif (version_compare($wp_version, $addon_settings['min_wp_version'], '<')) { |
|
| 603 | - $incompatibility_message = sprintf( |
|
| 604 | - __( |
|
| 605 | - '%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.', |
|
| 606 | - 'event_espresso' |
|
| 607 | - ), |
|
| 608 | - $addon_name, |
|
| 609 | - $addon_settings['min_wp_version'], |
|
| 610 | - '<br />', |
|
| 611 | - '<span style="font-weight: bold; color: #D54E21;">', |
|
| 612 | - '</span><br />' |
|
| 613 | - ); |
|
| 614 | - } |
|
| 615 | - if (! empty($incompatibility_message)) { |
|
| 616 | - // remove 'activate' from the REQUEST |
|
| 617 | - // so WP doesn't erroneously tell the user the plugin activated fine when it didn't |
|
| 618 | - unset($_GET['activate'], $_REQUEST['activate']); |
|
| 619 | - if (current_user_can('activate_plugins')) { |
|
| 620 | - // show an error message indicating the plugin didn't activate properly |
|
| 621 | - EE_Error::add_error($incompatibility_message, __FILE__, __FUNCTION__, __LINE__); |
|
| 622 | - } |
|
| 623 | - // BAIL FROM THE ADDON REGISTRATION PROCESS |
|
| 624 | - return false; |
|
| 625 | - } |
|
| 626 | - // addon IS compatible |
|
| 627 | - return true; |
|
| 628 | - } |
|
| 629 | - |
|
| 630 | - |
|
| 631 | - /** |
|
| 632 | - * if plugin update engine is being used for auto-updates, |
|
| 633 | - * then let's set that up now before going any further so that ALL addons can be updated |
|
| 634 | - * (not needed if PUE is not being used) |
|
| 635 | - * |
|
| 636 | - * @param string $addon_name |
|
| 637 | - * @param string $class_name |
|
| 638 | - * @param array $setup_args |
|
| 639 | - * @return void |
|
| 640 | - */ |
|
| 641 | - private static function _parse_pue_options(string $addon_name, string $class_name, array $setup_args) |
|
| 642 | - { |
|
| 643 | - if (! empty($setup_args['pue_options'])) { |
|
| 644 | - self::$_settings[ $addon_name ]['pue_options'] = [ |
|
| 645 | - 'pue_plugin_slug' => isset($setup_args['pue_options']['pue_plugin_slug']) |
|
| 646 | - ? (string) $setup_args['pue_options']['pue_plugin_slug'] |
|
| 647 | - : 'espresso_' . strtolower($class_name), |
|
| 648 | - 'plugin_basename' => isset($setup_args['pue_options']['plugin_basename']) |
|
| 649 | - ? (string) $setup_args['pue_options']['plugin_basename'] |
|
| 650 | - : plugin_basename($setup_args['main_file_path']), |
|
| 651 | - 'checkPeriod' => isset($setup_args['pue_options']['checkPeriod']) |
|
| 652 | - ? (string) $setup_args['pue_options']['checkPeriod'] |
|
| 653 | - : '24', |
|
| 654 | - 'use_wp_update' => isset($setup_args['pue_options']['use_wp_update']) |
|
| 655 | - ? (string) $setup_args['pue_options']['use_wp_update'] |
|
| 656 | - : false, |
|
| 657 | - ]; |
|
| 658 | - add_action( |
|
| 659 | - 'AHEE__EE_System__brew_espresso__after_pue_init', |
|
| 660 | - ['EE_Register_Addon', 'load_pue_update'] |
|
| 661 | - ); |
|
| 662 | - } |
|
| 663 | - } |
|
| 664 | - |
|
| 665 | - |
|
| 666 | - /** |
|
| 667 | - * register namespaces right away before any other files or classes get loaded, but AFTER the version checks |
|
| 668 | - * |
|
| 669 | - * @param array $addon_settings |
|
| 670 | - * @return void |
|
| 671 | - */ |
|
| 672 | - private static function _setup_namespaces(array $addon_settings) |
|
| 673 | - { |
|
| 674 | - // |
|
| 675 | - if (isset( |
|
| 676 | - $addon_settings['namespace']['FQNS'], |
|
| 677 | - $addon_settings['namespace']['DIR'] |
|
| 678 | - ) |
|
| 679 | - ) { |
|
| 680 | - EE_Psr4AutoloaderInit::psr4_loader()->addNamespace( |
|
| 681 | - $addon_settings['namespace']['FQNS'], |
|
| 682 | - $addon_settings['namespace']['DIR'] |
|
| 683 | - ); |
|
| 684 | - } |
|
| 685 | - } |
|
| 686 | - |
|
| 687 | - |
|
| 688 | - /** |
|
| 689 | - * @param string $addon_name |
|
| 690 | - * @param array $addon_settings |
|
| 691 | - * @return bool |
|
| 692 | - * @throws InvalidArgumentException |
|
| 693 | - * @throws InvalidDataTypeException |
|
| 694 | - * @throws InvalidInterfaceException |
|
| 695 | - */ |
|
| 696 | - private static function _addon_activation(string $addon_name, array $addon_settings): bool |
|
| 697 | - { |
|
| 698 | - // this is an activation request |
|
| 699 | - if (did_action('activate_plugin')) { |
|
| 700 | - // to find if THIS is the addon that was activated, just check if we have already registered it or not |
|
| 701 | - // (as the newly-activated addon wasn't around the first time addons were registered). |
|
| 702 | - // Note: the presence of pue_options in the addon registration options will initialize the $_settings |
|
| 703 | - // property for the add-on, but the add-on is only partially initialized. Hence, the additional check. |
|
| 704 | - if (! isset(self::$_settings[ $addon_name ]) |
|
| 705 | - || (isset(self::$_settings[ $addon_name ]) |
|
| 706 | - && ! isset(self::$_settings[ $addon_name ]['class_name']) |
|
| 707 | - ) |
|
| 708 | - ) { |
|
| 709 | - self::$_settings[ $addon_name ] = $addon_settings; |
|
| 710 | - $addon = self::_load_and_init_addon_class($addon_name); |
|
| 711 | - $addon->set_activation_indicator_option(); |
|
| 712 | - // dont bother setting up the rest of the addon. |
|
| 713 | - // we know it was just activated and the request will end soon |
|
| 714 | - } |
|
| 715 | - return true; |
|
| 716 | - } |
|
| 717 | - // make sure addon settings are set correctly without overwriting anything existing |
|
| 718 | - if (isset(self::$_settings[ $addon_name ])) { |
|
| 719 | - self::$_settings[ $addon_name ] += $addon_settings; |
|
| 720 | - } else { |
|
| 721 | - self::$_settings[ $addon_name ] = $addon_settings; |
|
| 722 | - } |
|
| 723 | - return false; |
|
| 724 | - } |
|
| 725 | - |
|
| 726 | - |
|
| 727 | - /** |
|
| 728 | - * @param string $addon_name |
|
| 729 | - * @return void |
|
| 730 | - * @throws EE_Error |
|
| 731 | - */ |
|
| 732 | - private static function _setup_autoloaders(string $addon_name) |
|
| 733 | - { |
|
| 734 | - if (! empty(self::$_settings[ $addon_name ]['autoloader_paths'])) { |
|
| 735 | - // setup autoloader for single file |
|
| 736 | - EEH_Autoloader::instance()->register_autoloader(self::$_settings[ $addon_name ]['autoloader_paths']); |
|
| 737 | - } |
|
| 738 | - // setup autoloaders for folders |
|
| 739 | - if (! empty(self::$_settings[ $addon_name ]['autoloader_folders'])) { |
|
| 740 | - foreach ((array) self::$_settings[ $addon_name ]['autoloader_folders'] as $autoloader_folder) { |
|
| 741 | - EEH_Autoloader::register_autoloaders_for_each_file_in_folder($autoloader_folder); |
|
| 742 | - } |
|
| 743 | - } |
|
| 744 | - } |
|
| 745 | - |
|
| 746 | - |
|
| 747 | - /** |
|
| 748 | - * register new models and extensions |
|
| 749 | - * |
|
| 750 | - * @param string $addon_name |
|
| 751 | - * @return void |
|
| 752 | - * @throws EE_Error |
|
| 753 | - */ |
|
| 754 | - private static function _register_models_and_extensions(string $addon_name) |
|
| 755 | - { |
|
| 756 | - // register new models |
|
| 757 | - if (! empty(self::$_settings[ $addon_name ]['model_paths']) |
|
| 758 | - || ! empty(self::$_settings[ $addon_name ]['class_paths']) |
|
| 759 | - ) { |
|
| 760 | - EE_Register_Model::register( |
|
| 761 | - $addon_name, |
|
| 762 | - [ |
|
| 763 | - 'model_paths' => self::$_settings[ $addon_name ]['model_paths'], |
|
| 764 | - 'class_paths' => self::$_settings[ $addon_name ]['class_paths'], |
|
| 765 | - ] |
|
| 766 | - ); |
|
| 767 | - } |
|
| 768 | - // register model extensions |
|
| 769 | - if (! 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 (! empty(self::$_settings[ $addon_name ]['shortcode_paths']) |
|
| 860 | - || ! empty(self::$_settings[ $addon_name ]['shortcode_fqcns']) |
|
| 861 | - ) { |
|
| 862 | - EE_Register_Shortcode::register( |
|
| 863 | - $addon_name, |
|
| 864 | - [ |
|
| 865 | - 'shortcode_paths' => isset(self::$_settings[ $addon_name ]['shortcode_paths']) |
|
| 866 | - ? self::$_settings[ $addon_name ]['shortcode_paths'] |
|
| 867 | - : [], |
|
| 868 | - 'shortcode_fqcns' => isset(self::$_settings[ $addon_name ]['shortcode_fqcns']) |
|
| 869 | - ? self::$_settings[ $addon_name ]['shortcode_fqcns'] |
|
| 870 | - : [], |
|
| 871 | - ] |
|
| 872 | - ); |
|
| 873 | - } |
|
| 874 | - } |
|
| 875 | - |
|
| 876 | - |
|
| 877 | - /** |
|
| 878 | - * @param string $addon_name |
|
| 879 | - * @return void |
|
| 880 | - * @throws EE_Error |
|
| 881 | - */ |
|
| 882 | - private static function _register_widgets(string $addon_name) |
|
| 883 | - { |
|
| 884 | - if (! empty(self::$_settings[ $addon_name ]['widget_paths'])) { |
|
| 885 | - EE_Register_Widget::register( |
|
| 886 | - $addon_name, |
|
| 887 | - ['widget_paths' => self::$_settings[ $addon_name ]['widget_paths']] |
|
| 888 | - ); |
|
| 889 | - } |
|
| 890 | - } |
|
| 891 | - |
|
| 892 | - |
|
| 893 | - /** |
|
| 894 | - * @param string $addon_name |
|
| 895 | - * @return void |
|
| 896 | - * @throws EE_Error |
|
| 897 | - */ |
|
| 898 | - private static function _register_capabilities(string $addon_name) |
|
| 899 | - { |
|
| 900 | - if (! empty(self::$_settings[ $addon_name ]['capabilities'])) { |
|
| 901 | - EE_Register_Capabilities::register( |
|
| 902 | - $addon_name, |
|
| 903 | - [ |
|
| 904 | - 'capabilities' => self::$_settings[ $addon_name ]['capabilities'], |
|
| 905 | - 'capability_maps' => self::$_settings[ $addon_name ]['capability_maps'], |
|
| 906 | - ] |
|
| 907 | - ); |
|
| 908 | - } |
|
| 909 | - } |
|
| 910 | - |
|
| 911 | - |
|
| 912 | - /** |
|
| 913 | - * @param string $addon_name |
|
| 914 | - * @return void |
|
| 915 | - */ |
|
| 916 | - private static function _register_message_types(string $addon_name) |
|
| 917 | - { |
|
| 918 | - if (! empty(self::$_settings[ $addon_name ]['message_types'])) { |
|
| 919 | - add_action( |
|
| 920 | - 'EE_Brewing_Regular___messages_caf', |
|
| 921 | - ['EE_Register_Addon', 'register_message_types'] |
|
| 922 | - ); |
|
| 923 | - } |
|
| 924 | - } |
|
| 925 | - |
|
| 926 | - |
|
| 927 | - /** |
|
| 928 | - * @param string $addon_name |
|
| 929 | - * @return void |
|
| 930 | - * @throws EE_Error |
|
| 931 | - */ |
|
| 932 | - private static function _register_custom_post_types(string $addon_name) |
|
| 933 | - { |
|
| 934 | - if (! empty(self::$_settings[ $addon_name ]['custom_post_types']) |
|
| 935 | - || ! empty(self::$_settings[ $addon_name ]['custom_taxonomies']) |
|
| 936 | - ) { |
|
| 937 | - EE_Register_CPT::register( |
|
| 938 | - $addon_name, |
|
| 939 | - [ |
|
| 940 | - 'cpts' => self::$_settings[ $addon_name ]['custom_post_types'], |
|
| 941 | - 'cts' => self::$_settings[ $addon_name ]['custom_taxonomies'], |
|
| 942 | - 'default_terms' => self::$_settings[ $addon_name ]['default_terms'], |
|
| 943 | - ] |
|
| 944 | - ); |
|
| 945 | - } |
|
| 946 | - } |
|
| 947 | - |
|
| 948 | - |
|
| 949 | - /** |
|
| 950 | - * @param string $addon_name |
|
| 951 | - * @return void |
|
| 952 | - * @throws InvalidArgumentException |
|
| 953 | - * @throws InvalidInterfaceException |
|
| 954 | - * @throws InvalidDataTypeException |
|
| 955 | - * @throws DomainException |
|
| 956 | - * @throws EE_Error |
|
| 957 | - */ |
|
| 958 | - private static function _register_payment_methods(string $addon_name) |
|
| 959 | - { |
|
| 960 | - if (! empty(self::$_settings[ $addon_name ]['payment_method_paths'])) { |
|
| 961 | - EE_Register_Payment_Method::register( |
|
| 962 | - $addon_name, |
|
| 963 | - ['payment_method_paths' => self::$_settings[ $addon_name ]['payment_method_paths']] |
|
| 964 | - ); |
|
| 965 | - } |
|
| 966 | - } |
|
| 967 | - |
|
| 968 | - |
|
| 969 | - /** |
|
| 970 | - * @param string $addon_name |
|
| 971 | - * @return void |
|
| 972 | - * @throws InvalidArgumentException |
|
| 973 | - * @throws InvalidInterfaceException |
|
| 974 | - * @throws InvalidDataTypeException |
|
| 975 | - * @throws DomainException |
|
| 976 | - */ |
|
| 977 | - private static function registerPrivacyPolicies(string $addon_name) |
|
| 978 | - { |
|
| 979 | - if (! empty(self::$_settings[ $addon_name ]['privacy_policies'])) { |
|
| 980 | - EE_Register_Privacy_Policy::register( |
|
| 981 | - $addon_name, |
|
| 982 | - self::$_settings[ $addon_name ]['privacy_policies'] |
|
| 983 | - ); |
|
| 984 | - } |
|
| 985 | - } |
|
| 986 | - |
|
| 987 | - |
|
| 988 | - /** |
|
| 989 | - * @param string $addon_name |
|
| 990 | - * @return void |
|
| 991 | - */ |
|
| 992 | - private static function registerPersonalDataExporters(string $addon_name) |
|
| 993 | - { |
|
| 994 | - if (! empty(self::$_settings[ $addon_name ]['personal_data_exporters'])) { |
|
| 995 | - EE_Register_Personal_Data_Eraser::register( |
|
| 996 | - $addon_name, |
|
| 997 | - self::$_settings[ $addon_name ]['personal_data_exporters'] |
|
| 998 | - ); |
|
| 999 | - } |
|
| 1000 | - } |
|
| 1001 | - |
|
| 1002 | - |
|
| 1003 | - /** |
|
| 1004 | - * @param string $addon_name |
|
| 1005 | - * @return void |
|
| 1006 | - */ |
|
| 1007 | - private static function registerPersonalDataErasers(string $addon_name) |
|
| 1008 | - { |
|
| 1009 | - if (! empty(self::$_settings[ $addon_name ]['personal_data_erasers'])) { |
|
| 1010 | - EE_Register_Personal_Data_Eraser::register( |
|
| 1011 | - $addon_name, |
|
| 1012 | - self::$_settings[ $addon_name ]['personal_data_erasers'] |
|
| 1013 | - ); |
|
| 1014 | - } |
|
| 1015 | - } |
|
| 1016 | - |
|
| 1017 | - |
|
| 1018 | - /** |
|
| 1019 | - * Loads and instantiates the EE_Addon class and adds it onto the registry |
|
| 1020 | - * |
|
| 1021 | - * @param string $addon_name |
|
| 1022 | - * @return EE_Addon |
|
| 1023 | - * @throws InvalidArgumentException |
|
| 1024 | - * @throws InvalidInterfaceException |
|
| 1025 | - * @throws InvalidDataTypeException |
|
| 1026 | - */ |
|
| 1027 | - private static function _load_and_init_addon_class(string $addon_name) |
|
| 1028 | - { |
|
| 1029 | - $addon = self::$loader->getShared( |
|
| 1030 | - self::$_settings[ $addon_name ]['class_name'], |
|
| 1031 | - ['EE_Registry::create(addon)' => true] |
|
| 1032 | - ); |
|
| 1033 | - if (! $addon instanceof EE_Addon) { |
|
| 1034 | - throw new DomainException( |
|
| 1035 | - sprintf( |
|
| 1036 | - esc_html__('The "%1$s" EE_Addon class failed to instantiate!', 'event_espresso'), |
|
| 1037 | - self::$_settings[ $addon_name ]['class_name'] |
|
| 1038 | - ) |
|
| 1039 | - ); |
|
| 1040 | - } |
|
| 1041 | - // setter inject dep map if required |
|
| 1042 | - if ($addon instanceof RequiresDependencyMapInterface && $addon->dependencyMap() === null) { |
|
| 1043 | - $addon->setDependencyMap(self::$loader->getShared('EE_Dependency_Map')); |
|
| 1044 | - } |
|
| 1045 | - // setter inject domain if required |
|
| 1046 | - if ($addon instanceof RequiresDomainInterface |
|
| 1047 | - && $addon->domain() === null |
|
| 1048 | - ) { |
|
| 1049 | - // using supplied Domain object |
|
| 1050 | - $domain = self::$_settings[ $addon_name ]['domain'] instanceof DomainInterface |
|
| 1051 | - ? self::$_settings[ $addon_name ]['domain'] |
|
| 1052 | - : null; |
|
| 1053 | - // or construct one using Domain FQCN |
|
| 1054 | - if ($domain === null && self::$_settings[ $addon_name ]['domain_fqcn'] !== '') { |
|
| 1055 | - $domain = self::$loader->getShared( |
|
| 1056 | - self::$_settings[ $addon_name ]['domain_fqcn'], |
|
| 1057 | - [ |
|
| 1058 | - new EventEspresso\core\domain\values\FilePath( |
|
| 1059 | - self::$_settings[ $addon_name ]['main_file_path'] |
|
| 1060 | - ), |
|
| 1061 | - EventEspresso\core\domain\values\Version::fromString( |
|
| 1062 | - self::$_settings[ $addon_name ]['version'] |
|
| 1063 | - ), |
|
| 1064 | - ] |
|
| 1065 | - ); |
|
| 1066 | - } |
|
| 1067 | - if ($domain instanceof DomainInterface) { |
|
| 1068 | - $addon->setDomain($domain); |
|
| 1069 | - } |
|
| 1070 | - } |
|
| 1071 | - $addon->set_name($addon_name); |
|
| 1072 | - $addon->set_plugin_slug(self::$_settings[ $addon_name ]['plugin_slug']); |
|
| 1073 | - $addon->set_plugin_basename(self::$_settings[ $addon_name ]['plugin_basename']); |
|
| 1074 | - $addon->set_main_plugin_file(self::$_settings[ $addon_name ]['main_file_path']); |
|
| 1075 | - $addon->set_plugin_action_slug(self::$_settings[ $addon_name ]['plugin_action_slug']); |
|
| 1076 | - $addon->set_plugins_page_row(self::$_settings[ $addon_name ]['plugins_page_row']); |
|
| 1077 | - $addon->set_version(self::$_settings[ $addon_name ]['version']); |
|
| 1078 | - $addon->set_min_core_version(self::_effective_version(self::$_settings[ $addon_name ]['min_core_version'])); |
|
| 1079 | - $addon->set_config_section(self::$_settings[ $addon_name ]['config_section']); |
|
| 1080 | - $addon->set_config_class(self::$_settings[ $addon_name ]['config_class']); |
|
| 1081 | - $addon->set_config_name(self::$_settings[ $addon_name ]['config_name']); |
|
| 1082 | - // setup the add-on's pue_slug if we have one. |
|
| 1083 | - if (! empty(self::$_settings[ $addon_name ]['pue_options']['pue_plugin_slug'])) { |
|
| 1084 | - $addon->setPueSlug(self::$_settings[ $addon_name ]['pue_options']['pue_plugin_slug']); |
|
| 1085 | - } |
|
| 1086 | - // unfortunately this can't be hooked in upon construction, because we don't have |
|
| 1087 | - // the plugin mainfile's path upon construction. |
|
| 1088 | - register_deactivation_hook($addon->get_main_plugin_file(), [$addon, 'deactivation']); |
|
| 1089 | - // call any additional admin_callback functions during load_admin_controller hook |
|
| 1090 | - if (! empty(self::$_settings[ $addon_name ]['admin_callback'])) { |
|
| 1091 | - add_action( |
|
| 1092 | - 'AHEE__EE_System__load_controllers__load_admin_controllers', |
|
| 1093 | - [$addon, self::$_settings[ $addon_name ]['admin_callback']] |
|
| 1094 | - ); |
|
| 1095 | - } |
|
| 1096 | - return $addon; |
|
| 1097 | - } |
|
| 1098 | - |
|
| 1099 | - |
|
| 1100 | - /** |
|
| 1101 | - * load_pue_update - Update notifications |
|
| 1102 | - * |
|
| 1103 | - * @return void |
|
| 1104 | - * @throws InvalidArgumentException |
|
| 1105 | - * @throws InvalidDataTypeException |
|
| 1106 | - * @throws InvalidInterfaceException |
|
| 1107 | - */ |
|
| 1108 | - public static function load_pue_update() |
|
| 1109 | - { |
|
| 1110 | - // load PUE client |
|
| 1111 | - require_once EE_THIRD_PARTY . 'pue/pue-client.php'; |
|
| 1112 | - $license_server = defined('PUE_UPDATES_ENDPOINT') ? PUE_UPDATES_ENDPOINT : 'https://eventespresso.com'; |
|
| 1113 | - // cycle thru settings |
|
| 1114 | - foreach (self::$_settings as $settings) { |
|
| 1115 | - if (! empty($settings['pue_options'])) { |
|
| 1116 | - // initiate the class and start the plugin update engine! |
|
| 1117 | - new PluginUpdateEngineChecker( |
|
| 1118 | - // host file URL |
|
| 1119 | - $license_server, |
|
| 1120 | - // plugin slug(s) |
|
| 1121 | - [ |
|
| 1122 | - 'premium' => ['p' => $settings['pue_options']['pue_plugin_slug']], |
|
| 1123 | - 'prerelease' => ['beta' => $settings['pue_options']['pue_plugin_slug'] . '-pr'], |
|
| 1124 | - ], |
|
| 1125 | - // options |
|
| 1126 | - [ |
|
| 1127 | - 'apikey' => EE_Registry::instance()->NET_CFG->core->site_license_key, |
|
| 1128 | - 'lang_domain' => 'event_espresso', |
|
| 1129 | - 'checkPeriod' => $settings['pue_options']['checkPeriod'], |
|
| 1130 | - 'option_key' => 'ee_site_license_key', |
|
| 1131 | - 'options_page_slug' => 'event_espresso', |
|
| 1132 | - 'plugin_basename' => $settings['pue_options']['plugin_basename'], |
|
| 1133 | - // if use_wp_update is TRUE it means you want FREE versions of the plugin to be updated from WP |
|
| 1134 | - 'use_wp_update' => $settings['pue_options']['use_wp_update'], |
|
| 1135 | - ] |
|
| 1136 | - ); |
|
| 1137 | - } |
|
| 1138 | - } |
|
| 1139 | - } |
|
| 1140 | - |
|
| 1141 | - |
|
| 1142 | - /** |
|
| 1143 | - * Callback for EE_Brewing_Regular__messages_caf hook used to register message types. |
|
| 1144 | - * |
|
| 1145 | - * @return void |
|
| 1146 | - * @throws EE_Error |
|
| 1147 | - * @since 4.4.0 |
|
| 1148 | - */ |
|
| 1149 | - public static function register_message_types() |
|
| 1150 | - { |
|
| 1151 | - foreach (self::$_settings as $addon_name => $settings) { |
|
| 1152 | - if (! empty($settings['message_types'])) { |
|
| 1153 | - foreach ((array) $settings['message_types'] as $message_type => $message_type_settings) { |
|
| 1154 | - EE_Register_Message_Type::register($message_type, $message_type_settings); |
|
| 1155 | - } |
|
| 1156 | - } |
|
| 1157 | - } |
|
| 1158 | - } |
|
| 1159 | - |
|
| 1160 | - |
|
| 1161 | - /** |
|
| 1162 | - * This deregisters an addon that was previously registered with a specific addon_name. |
|
| 1163 | - * |
|
| 1164 | - * @param string $addon_name the name for the addon that was previously registered |
|
| 1165 | - * @throws DomainException |
|
| 1166 | - * @throws InvalidArgumentException |
|
| 1167 | - * @throws InvalidDataTypeException |
|
| 1168 | - * @throws InvalidInterfaceException |
|
| 1169 | - * @since 4.3.0 |
|
| 1170 | - */ |
|
| 1171 | - public static function deregister(string $addon_name = '') |
|
| 1172 | - { |
|
| 1173 | - if (isset(self::$_settings[ $addon_name ]['class_name'])) { |
|
| 1174 | - try { |
|
| 1175 | - do_action('AHEE__EE_Register_Addon__deregister__before', $addon_name); |
|
| 1176 | - $class_name = self::$_settings[ $addon_name ]['class_name']; |
|
| 1177 | - if (! empty(self::$_settings[ $addon_name ]['dms_paths'])) { |
|
| 1178 | - // setup DMS |
|
| 1179 | - EE_Register_Data_Migration_Scripts::deregister($addon_name); |
|
| 1180 | - } |
|
| 1181 | - if (! empty(self::$_settings[ $addon_name ]['admin_path'])) { |
|
| 1182 | - // register admin page |
|
| 1183 | - EE_Register_Admin_Page::deregister($addon_name); |
|
| 1184 | - } |
|
| 1185 | - if (! empty(self::$_settings[ $addon_name ]['module_paths'])) { |
|
| 1186 | - // add to list of modules to be registered |
|
| 1187 | - EE_Register_Module::deregister($addon_name); |
|
| 1188 | - } |
|
| 1189 | - if (! empty(self::$_settings[ $addon_name ]['shortcode_paths']) |
|
| 1190 | - || ! empty(self::$_settings[ $addon_name ]['shortcode_fqcns']) |
|
| 1191 | - ) { |
|
| 1192 | - // add to list of shortcodes to be registered |
|
| 1193 | - EE_Register_Shortcode::deregister($addon_name); |
|
| 1194 | - } |
|
| 1195 | - if (! empty(self::$_settings[ $addon_name ]['config_class'])) { |
|
| 1196 | - // if config_class present let's register config. |
|
| 1197 | - EE_Register_Config::deregister(self::$_settings[ $addon_name ]['config_class']); |
|
| 1198 | - } |
|
| 1199 | - if (! empty(self::$_settings[ $addon_name ]['widget_paths'])) { |
|
| 1200 | - // add to list of widgets to be registered |
|
| 1201 | - EE_Register_Widget::deregister($addon_name); |
|
| 1202 | - } |
|
| 1203 | - if (! empty(self::$_settings[ $addon_name ]['model_paths']) |
|
| 1204 | - || ! empty(self::$_settings[ $addon_name ]['class_paths']) |
|
| 1205 | - ) { |
|
| 1206 | - // add to list of shortcodes to be registered |
|
| 1207 | - EE_Register_Model::deregister($addon_name); |
|
| 1208 | - } |
|
| 1209 | - if (! empty(self::$_settings[ $addon_name ]['model_extension_paths']) |
|
| 1210 | - || ! empty(self::$_settings[ $addon_name ]['class_extension_paths']) |
|
| 1211 | - ) { |
|
| 1212 | - // add to list of shortcodes to be registered |
|
| 1213 | - EE_Register_Model_Extensions::deregister($addon_name); |
|
| 1214 | - } |
|
| 1215 | - if (! empty(self::$_settings[ $addon_name ]['message_types'])) { |
|
| 1216 | - foreach ((array) self::$_settings[ $addon_name ]['message_types'] as $message_type => $message_type_settings) { |
|
| 1217 | - EE_Register_Message_Type::deregister($message_type); |
|
| 1218 | - } |
|
| 1219 | - } |
|
| 1220 | - // deregister capabilities for addon |
|
| 1221 | - if (! empty(self::$_settings[ $addon_name ]['capabilities']) |
|
| 1222 | - || ! empty(self::$_settings[ $addon_name ]['capability_maps']) |
|
| 1223 | - ) { |
|
| 1224 | - EE_Register_Capabilities::deregister($addon_name); |
|
| 1225 | - } |
|
| 1226 | - // deregister custom_post_types for addon |
|
| 1227 | - if (! empty(self::$_settings[ $addon_name ]['custom_post_types'])) { |
|
| 1228 | - EE_Register_CPT::deregister($addon_name); |
|
| 1229 | - } |
|
| 1230 | - if (! empty(self::$_settings[ $addon_name ]['payment_method_paths'])) { |
|
| 1231 | - EE_Register_Payment_Method::deregister($addon_name); |
|
| 1232 | - } |
|
| 1233 | - $addon = EE_Registry::instance()->getAddon($class_name); |
|
| 1234 | - if ($addon instanceof EE_Addon) { |
|
| 1235 | - remove_action( |
|
| 1236 | - 'deactivate_' . $addon->get_main_plugin_file_basename(), |
|
| 1237 | - [$addon, 'deactivation'] |
|
| 1238 | - ); |
|
| 1239 | - remove_action( |
|
| 1240 | - 'AHEE__EE_System__perform_activations_upgrades_and_migrations', |
|
| 1241 | - [$addon, 'initialize_db_if_no_migrations_required'] |
|
| 1242 | - ); |
|
| 1243 | - // remove `after_registration` call |
|
| 1244 | - remove_action( |
|
| 1245 | - 'AHEE__EE_System__load_espresso_addons__complete', |
|
| 1246 | - [$addon, 'after_registration'], |
|
| 1247 | - 999 |
|
| 1248 | - ); |
|
| 1249 | - } |
|
| 1250 | - EE_Registry::instance()->removeAddon($class_name); |
|
| 1251 | - } catch (OutOfBoundsException $addon_not_yet_registered_exception) { |
|
| 1252 | - // the add-on was not yet registered in the registry, |
|
| 1253 | - // so RegistryContainer::__get() throws this exception. |
|
| 1254 | - // also no need to worry about this or log it, |
|
| 1255 | - // it's ok to deregister an add-on before its registered in the registry |
|
| 1256 | - } catch (Exception $e) { |
|
| 1257 | - new ExceptionLogger($e); |
|
| 1258 | - } |
|
| 1259 | - unset(self::$_settings[ $addon_name ]); |
|
| 1260 | - do_action('AHEE__EE_Register_Addon__deregister__after', $addon_name); |
|
| 1261 | - } |
|
| 1262 | - } |
|
| 26 | + /** |
|
| 27 | + * possibly truncated version of the EE core version string |
|
| 28 | + * |
|
| 29 | + * @var string |
|
| 30 | + */ |
|
| 31 | + protected static $_core_version = ''; |
|
| 32 | + |
|
| 33 | + /** |
|
| 34 | + * Holds values for registered addons |
|
| 35 | + * |
|
| 36 | + * @var array |
|
| 37 | + */ |
|
| 38 | + protected static $_settings = []; |
|
| 39 | + |
|
| 40 | + /** |
|
| 41 | + * @var array $_incompatible_addons keys are addon SLUGS |
|
| 42 | + * (first argument passed to EE_Register_Addon::register()), keys are |
|
| 43 | + * their MINIMUM VERSION (with all 5 parts. Eg 1.2.3.rc.004). |
|
| 44 | + * Generally this should be used sparingly, as we don't want to muddle up |
|
| 45 | + * EE core with knowledge of ALL the addons out there. |
|
| 46 | + * If you want NO versions of an addon to run with a certain version of core, |
|
| 47 | + * it's usually best to define the addon's "min_core_version" as part of its call |
|
| 48 | + * to EE_Register_Addon::register(), rather than using this array with a super high value for its |
|
| 49 | + * minimum plugin version. |
|
| 50 | + * @access protected |
|
| 51 | + */ |
|
| 52 | + protected static $_incompatible_addons = [ |
|
| 53 | + 'Multi_Event_Registration' => '2.0.11.rc.002', |
|
| 54 | + 'Promotions' => '1.0.0.rc.084', |
|
| 55 | + ]; |
|
| 56 | + |
|
| 57 | + /** |
|
| 58 | + * @var LoaderInterface |
|
| 59 | + */ |
|
| 60 | + protected static $loader; |
|
| 61 | + |
|
| 62 | + |
|
| 63 | + /** |
|
| 64 | + * We should always be comparing core to a version like '4.3.0.rc.000', |
|
| 65 | + * not just '4.3.0'. |
|
| 66 | + * So if the addon developer doesn't provide that full version string, |
|
| 67 | + * fill in the blanks for them |
|
| 68 | + * |
|
| 69 | + * @param string $min_core_version |
|
| 70 | + * @return string always like '4.3.0.rc.000' |
|
| 71 | + */ |
|
| 72 | + protected static function _effective_version(string $min_core_version): string |
|
| 73 | + { |
|
| 74 | + // versions: 4 . 3 . 1 . p . 123 |
|
| 75 | + // offsets: 0 . 1 . 2 . 3 . 4 |
|
| 76 | + $version_parts = explode('.', $min_core_version); |
|
| 77 | + // check they specified the micro version (after 2nd period) |
|
| 78 | + if (! isset($version_parts[2])) { |
|
| 79 | + $version_parts[2] = '0'; |
|
| 80 | + } |
|
| 81 | + // if they didn't specify the 'p', or 'rc' part. Just assume the lowest possible |
|
| 82 | + // soon we can assume that's 'rc', but this current version is 'alpha' |
|
| 83 | + if (! isset($version_parts[3])) { |
|
| 84 | + $version_parts[3] = 'dev'; |
|
| 85 | + } |
|
| 86 | + if (! isset($version_parts[4])) { |
|
| 87 | + $version_parts[4] = '000'; |
|
| 88 | + } |
|
| 89 | + return implode('.', $version_parts); |
|
| 90 | + } |
|
| 91 | + |
|
| 92 | + |
|
| 93 | + /** |
|
| 94 | + * Returns whether or not the min core version requirement of the addon is met |
|
| 95 | + * |
|
| 96 | + * @param string $min_core_version the minimum core version required by the addon |
|
| 97 | + * @param string $actual_core_version the actual core version, optional |
|
| 98 | + * @return boolean |
|
| 99 | + */ |
|
| 100 | + public static function _meets_min_core_version_requirement( |
|
| 101 | + string $min_core_version, |
|
| 102 | + $actual_core_version = EVENT_ESPRESSO_VERSION |
|
| 103 | + ): bool { |
|
| 104 | + return version_compare( |
|
| 105 | + self::_effective_version($actual_core_version), |
|
| 106 | + self::_effective_version($min_core_version), |
|
| 107 | + '>=' |
|
| 108 | + ); |
|
| 109 | + } |
|
| 110 | + |
|
| 111 | + |
|
| 112 | + /** |
|
| 113 | + * Method for registering new EE_Addons. |
|
| 114 | + * Should be called AFTER AHEE__EE_System__load_espresso_addons but BEFORE |
|
| 115 | + * AHEE__EE_System___detect_if_activation_or_upgrade__begin in order to register all its components. However, it |
|
| 116 | + * may also be called after the 'activate_plugin' action (when an addon is activated), because an activating addon |
|
| 117 | + * won't be loaded by WP until after AHEE__EE_System__load_espresso_addons has fired. If its called after |
|
| 118 | + * 'activate_plugin', it registers the addon still, but its components are not registered |
|
| 119 | + * (they shouldn't be needed anyways, because it's just an activation request and they won't have a chance to do |
|
| 120 | + * anything anyways). Instead, it just sets the newly-activated addon's activation indicator wp option and returns |
|
| 121 | + * (so that we can detect that the addon has activated on the subsequent request) |
|
| 122 | + * |
|
| 123 | + * @param string $addon_name [Required] the EE_Addon's name. |
|
| 124 | + * @param array $setup_args { |
|
| 125 | + * An array of arguments provided for registering |
|
| 126 | + * the message type. |
|
| 127 | + * @type string $class_name the addon's main file name. |
|
| 128 | + * If left blank, generated from the addon name, |
|
| 129 | + * changes something like "calendar" to |
|
| 130 | + * "EE_Calendar" |
|
| 131 | + * @type string $min_core_version the minimum version of EE Core that the |
|
| 132 | + * addon will work with. eg "4.8.1.rc.084" |
|
| 133 | + * @type string $version the "software" version for the addon. eg |
|
| 134 | + * "1.0.0.p" for a first stable release, or |
|
| 135 | + * "1.0.0.rc.043" for a version in progress |
|
| 136 | + * @type string $main_file_path the full server path to the main file |
|
| 137 | + * loaded directly by WP |
|
| 138 | + * @type DomainInterface $domain child class of |
|
| 139 | + * EventEspresso\core\domain\DomainBase |
|
| 140 | + * @type string $domain_fqcn Fully Qualified Class Name |
|
| 141 | + * for the addon's Domain class |
|
| 142 | + * (see EventEspresso\core\domain\Domain) |
|
| 143 | + * @type string $admin_path full server path to the folder where the |
|
| 144 | + * addon\'s admin files reside |
|
| 145 | + * @type string $admin_callback a method to be called when the EE Admin is |
|
| 146 | + * first invoked, can be used for hooking into |
|
| 147 | + * any admin page |
|
| 148 | + * @type string $config_section the section name for this addon's |
|
| 149 | + * configuration settings section |
|
| 150 | + * (defaults to "addons") |
|
| 151 | + * @type string $config_class the class name for this addon's |
|
| 152 | + * configuration settings object |
|
| 153 | + * @type string $config_name the class name for this addon's |
|
| 154 | + * configuration settings object |
|
| 155 | + * @type string $autoloader_paths [Required] an array of class names and the full |
|
| 156 | + * server paths to those files. |
|
| 157 | + * @type string $autoloader_folders an array of "full server paths" for any |
|
| 158 | + * folders containing classes that might be |
|
| 159 | + * invoked by the addon |
|
| 160 | + * @type string $dms_paths [Required] an array of full server paths to |
|
| 161 | + * folders that contain data migration scripts. |
|
| 162 | + * The key should be the EE_Addon class name that |
|
| 163 | + * this set of data migration scripts belongs to. |
|
| 164 | + * If the EE_Addon class is namespaced, then this |
|
| 165 | + * needs to be the Fully Qualified Class Name |
|
| 166 | + * @type string $module_paths an array of full server paths to any |
|
| 167 | + * EED_Modules used by the addon |
|
| 168 | + * @type string $shortcode_paths an array of full server paths to folders |
|
| 169 | + * that contain EES_Shortcodes |
|
| 170 | + * @type string $widget_paths an array of full server paths to folders |
|
| 171 | + * that contain WP_Widgets |
|
| 172 | + * @type string $pue_options |
|
| 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 boolean |
|
| 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 | + if (! self::$loader instanceof LoaderInterface) { |
|
| 264 | + self::$loader = EventEspresso\core\services\loaders\LoaderFactory::getLoader(); |
|
| 265 | + } |
|
| 266 | + // make sure this was called in the right place! |
|
| 267 | + if (! did_action('activate_plugin') |
|
| 268 | + && ( |
|
| 269 | + ! did_action('AHEE__EE_System__load_espresso_addons') |
|
| 270 | + || did_action('AHEE__EE_System___detect_if_activation_or_upgrade__begin') |
|
| 271 | + ) |
|
| 272 | + ) { |
|
| 273 | + EE_Error::doing_it_wrong( |
|
| 274 | + __METHOD__, |
|
| 275 | + sprintf( |
|
| 276 | + esc_html__( |
|
| 277 | + '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.', |
|
| 278 | + 'event_espresso' |
|
| 279 | + ), |
|
| 280 | + $addon_name |
|
| 281 | + ), |
|
| 282 | + '4.3.0' |
|
| 283 | + ); |
|
| 284 | + return false; |
|
| 285 | + } |
|
| 286 | + // required fields MUST be present, so let's make sure they are. |
|
| 287 | + EE_Register_Addon::_verify_parameters($addon_name, $setup_args); |
|
| 288 | + // get class name for addon |
|
| 289 | + $class_name = EE_Register_Addon::_parse_class_name($addon_name, $setup_args); |
|
| 290 | + // setup $_settings array from incoming values. |
|
| 291 | + $addon_settings = EE_Register_Addon::_get_addon_settings($class_name, $setup_args); |
|
| 292 | + // setup PUE |
|
| 293 | + EE_Register_Addon::_parse_pue_options($addon_name, $class_name, $setup_args); |
|
| 294 | + // does this addon work with this version of core or WordPress ? |
|
| 295 | + if (! EE_Register_Addon::_addon_is_compatible($addon_name, $addon_settings)) { |
|
| 296 | + return false; |
|
| 297 | + } |
|
| 298 | + // register namespaces |
|
| 299 | + EE_Register_Addon::_setup_namespaces($addon_settings); |
|
| 300 | + // check if this is an activation request |
|
| 301 | + if (EE_Register_Addon::_addon_activation($addon_name, $addon_settings)) { |
|
| 302 | + // dont bother setting up the rest of the addon atm |
|
| 303 | + return false; |
|
| 304 | + } |
|
| 305 | + // we need cars |
|
| 306 | + EE_Register_Addon::_setup_autoloaders($addon_name); |
|
| 307 | + // register new models and extensions |
|
| 308 | + EE_Register_Addon::_register_models_and_extensions($addon_name); |
|
| 309 | + // setup DMS |
|
| 310 | + EE_Register_Addon::_register_data_migration_scripts($addon_name); |
|
| 311 | + // if config_class is present let's register config. |
|
| 312 | + EE_Register_Addon::_register_config($addon_name); |
|
| 313 | + // register admin pages |
|
| 314 | + EE_Register_Addon::_register_admin_pages($addon_name); |
|
| 315 | + // add to list of modules to be registered |
|
| 316 | + EE_Register_Addon::_register_modules($addon_name); |
|
| 317 | + // add to list of shortcodes to be registered |
|
| 318 | + EE_Register_Addon::_register_shortcodes($addon_name); |
|
| 319 | + // add to list of widgets to be registered |
|
| 320 | + EE_Register_Addon::_register_widgets($addon_name); |
|
| 321 | + // register capability related stuff. |
|
| 322 | + EE_Register_Addon::_register_capabilities($addon_name); |
|
| 323 | + // any message type to register? |
|
| 324 | + EE_Register_Addon::_register_message_types($addon_name); |
|
| 325 | + // any custom post type/ custom capabilities or default terms to register |
|
| 326 | + EE_Register_Addon::_register_custom_post_types($addon_name); |
|
| 327 | + // and any payment methods |
|
| 328 | + EE_Register_Addon::_register_payment_methods($addon_name); |
|
| 329 | + // and privacy policy generators |
|
| 330 | + EE_Register_Addon::registerPrivacyPolicies($addon_name); |
|
| 331 | + // and privacy policy generators |
|
| 332 | + EE_Register_Addon::registerPersonalDataExporters($addon_name); |
|
| 333 | + // and privacy policy generators |
|
| 334 | + EE_Register_Addon::registerPersonalDataErasers($addon_name); |
|
| 335 | + // load and instantiate main addon class |
|
| 336 | + $addon = EE_Register_Addon::_load_and_init_addon_class($addon_name); |
|
| 337 | + // delay calling after_registration hook on each addon until after all add-ons have been registered. |
|
| 338 | + add_action('AHEE__EE_System__load_espresso_addons__complete', [$addon, 'after_registration'], 999); |
|
| 339 | + return $addon instanceof EE_Addon; |
|
| 340 | + } |
|
| 341 | + |
|
| 342 | + |
|
| 343 | + /** |
|
| 344 | + * @param string $addon_name |
|
| 345 | + * @param array $setup_args |
|
| 346 | + * @return void |
|
| 347 | + * @throws EE_Error |
|
| 348 | + */ |
|
| 349 | + private static function _verify_parameters(string $addon_name, array $setup_args) |
|
| 350 | + { |
|
| 351 | + // required fields MUST be present, so let's make sure they are. |
|
| 352 | + if (empty($addon_name) || ! is_array($setup_args)) { |
|
| 353 | + throw new EE_Error( |
|
| 354 | + esc_html__( |
|
| 355 | + '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.', |
|
| 356 | + 'event_espresso' |
|
| 357 | + ) |
|
| 358 | + ); |
|
| 359 | + } |
|
| 360 | + if (! isset($setup_args['main_file_path']) || empty($setup_args['main_file_path'])) { |
|
| 361 | + throw new EE_Error( |
|
| 362 | + sprintf( |
|
| 363 | + esc_html__( |
|
| 364 | + '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', |
|
| 365 | + 'event_espresso' |
|
| 366 | + ), |
|
| 367 | + implode(',', array_keys($setup_args)) |
|
| 368 | + ) |
|
| 369 | + ); |
|
| 370 | + } |
|
| 371 | + // check that addon has not already been registered with that name |
|
| 372 | + if (isset(self::$_settings[ $addon_name ]) && ! did_action('activate_plugin')) { |
|
| 373 | + throw new EE_Error( |
|
| 374 | + sprintf( |
|
| 375 | + esc_html__( |
|
| 376 | + 'An EE_Addon with the name "%s" has already been registered and each EE_Addon requires a unique name.', |
|
| 377 | + 'event_espresso' |
|
| 378 | + ), |
|
| 379 | + $addon_name |
|
| 380 | + ) |
|
| 381 | + ); |
|
| 382 | + } |
|
| 383 | + } |
|
| 384 | + |
|
| 385 | + |
|
| 386 | + /** |
|
| 387 | + * @param string $addon_name |
|
| 388 | + * @param array $setup_args |
|
| 389 | + * @return string |
|
| 390 | + */ |
|
| 391 | + private static function _parse_class_name(string $addon_name, array $setup_args): string |
|
| 392 | + { |
|
| 393 | + if (empty($setup_args['class_name'])) { |
|
| 394 | + // generate one by first separating name with spaces |
|
| 395 | + $class_name = str_replace(['-', '_'], ' ', trim($addon_name)); |
|
| 396 | + // capitalize, then replace spaces with underscores |
|
| 397 | + $class_name = str_replace(' ', '_', ucwords($class_name)); |
|
| 398 | + } else { |
|
| 399 | + $class_name = $setup_args['class_name']; |
|
| 400 | + } |
|
| 401 | + // check if classname is fully qualified or is a legacy classname already prefixed with 'EE_' |
|
| 402 | + return strpos($class_name, '\\') || strpos($class_name, 'EE_') === 0 |
|
| 403 | + ? $class_name |
|
| 404 | + : 'EE_' . $class_name; |
|
| 405 | + } |
|
| 406 | + |
|
| 407 | + |
|
| 408 | + /** |
|
| 409 | + * @param string $class_name |
|
| 410 | + * @param array $setup_args |
|
| 411 | + * @return array |
|
| 412 | + */ |
|
| 413 | + private static function _get_addon_settings(string $class_name, array $setup_args): array |
|
| 414 | + { |
|
| 415 | + // setup $_settings array from incoming values. |
|
| 416 | + $addon_settings = [ |
|
| 417 | + // generated from the addon name, changes something like "calendar" to "EE_Calendar" |
|
| 418 | + 'class_name' => $class_name, |
|
| 419 | + // the addon slug for use in URLs, etc |
|
| 420 | + 'plugin_slug' => isset($setup_args['plugin_slug']) |
|
| 421 | + ? (string) $setup_args['plugin_slug'] |
|
| 422 | + : '', |
|
| 423 | + // page slug to be used when generating the "Settings" link on the WP plugin page |
|
| 424 | + 'plugin_action_slug' => isset($setup_args['plugin_action_slug']) |
|
| 425 | + ? (string) $setup_args['plugin_action_slug'] |
|
| 426 | + : '', |
|
| 427 | + // the "software" version for the addon |
|
| 428 | + 'version' => isset($setup_args['version']) |
|
| 429 | + ? (string) $setup_args['version'] |
|
| 430 | + : '', |
|
| 431 | + // the minimum version of EE Core that the addon will work with |
|
| 432 | + 'min_core_version' => isset($setup_args['min_core_version']) |
|
| 433 | + ? (string) $setup_args['min_core_version'] |
|
| 434 | + : '', |
|
| 435 | + // the minimum version of WordPress that the addon will work with |
|
| 436 | + 'min_wp_version' => isset($setup_args['min_wp_version']) |
|
| 437 | + ? (string) $setup_args['min_wp_version'] |
|
| 438 | + : EE_MIN_WP_VER_REQUIRED, |
|
| 439 | + // full server path to main file (file loaded directly by WP) |
|
| 440 | + 'main_file_path' => isset($setup_args['main_file_path']) |
|
| 441 | + ? (string) $setup_args['main_file_path'] |
|
| 442 | + : '', |
|
| 443 | + // instance of \EventEspresso\core\domain\DomainInterface |
|
| 444 | + 'domain' => isset($setup_args['domain']) && $setup_args['domain'] instanceof DomainInterface |
|
| 445 | + ? $setup_args['domain'] |
|
| 446 | + : null, |
|
| 447 | + // Fully Qualified Class Name for the addon's Domain class |
|
| 448 | + 'domain_fqcn' => isset($setup_args['domain_fqcn']) |
|
| 449 | + ? (string) $setup_args['domain_fqcn'] |
|
| 450 | + : '', |
|
| 451 | + // path to folder containing files for integrating with the EE core admin and/or setting up EE admin pages |
|
| 452 | + 'admin_path' => isset($setup_args['admin_path']) |
|
| 453 | + ? (string) $setup_args['admin_path'] : '', |
|
| 454 | + // a method to be called when the EE Admin is first invoked, can be used for hooking into any admin page |
|
| 455 | + 'admin_callback' => isset($setup_args['admin_callback']) |
|
| 456 | + ? (string) $setup_args['admin_callback'] |
|
| 457 | + : '', |
|
| 458 | + // the section name for this addon's configuration settings section (defaults to "addons") |
|
| 459 | + 'config_section' => isset($setup_args['config_section']) |
|
| 460 | + ? (string) $setup_args['config_section'] |
|
| 461 | + : 'addons', |
|
| 462 | + // the class name for this addon's configuration settings object |
|
| 463 | + 'config_class' => isset($setup_args['config_class']) |
|
| 464 | + ? (string) $setup_args['config_class'] : '', |
|
| 465 | + // the name given to the config for this addons' configuration settings object (optional) |
|
| 466 | + 'config_name' => isset($setup_args['config_name']) |
|
| 467 | + ? (string) $setup_args['config_name'] : '', |
|
| 468 | + // an array of "class names" => "full server paths" for any classes that might be invoked by the addon |
|
| 469 | + 'autoloader_paths' => isset($setup_args['autoloader_paths']) |
|
| 470 | + ? (array) $setup_args['autoloader_paths'] |
|
| 471 | + : [], |
|
| 472 | + // an array of "full server paths" for any folders containing classes that might be invoked by the addon |
|
| 473 | + 'autoloader_folders' => isset($setup_args['autoloader_folders']) |
|
| 474 | + ? (array) $setup_args['autoloader_folders'] |
|
| 475 | + : [], |
|
| 476 | + // array of full server paths to any EE_DMS data migration scripts used by the addon. |
|
| 477 | + // The key should be the EE_Addon class name that this set of data migration scripts belongs to. |
|
| 478 | + // If the EE_Addon class is namespaced, then this needs to be the Fully Qualified Class Name |
|
| 479 | + 'dms_paths' => isset($setup_args['dms_paths']) |
|
| 480 | + ? (array) $setup_args['dms_paths'] |
|
| 481 | + : [], |
|
| 482 | + // array of full server paths to any EED_Modules used by the addon |
|
| 483 | + 'module_paths' => isset($setup_args['module_paths']) |
|
| 484 | + ? (array) $setup_args['module_paths'] |
|
| 485 | + : [], |
|
| 486 | + // array of full server paths to any EES_Shortcodes used by the addon |
|
| 487 | + 'shortcode_paths' => isset($setup_args['shortcode_paths']) |
|
| 488 | + ? (array) $setup_args['shortcode_paths'] |
|
| 489 | + : [], |
|
| 490 | + 'shortcode_fqcns' => isset($setup_args['shortcode_fqcns']) |
|
| 491 | + ? (array) $setup_args['shortcode_fqcns'] |
|
| 492 | + : [], |
|
| 493 | + // array of full server paths to any WP_Widgets used by the addon |
|
| 494 | + 'widget_paths' => isset($setup_args['widget_paths']) |
|
| 495 | + ? (array) $setup_args['widget_paths'] |
|
| 496 | + : [], |
|
| 497 | + // array of PUE options used by the addon |
|
| 498 | + 'pue_options' => isset($setup_args['pue_options']) |
|
| 499 | + ? (array) $setup_args['pue_options'] |
|
| 500 | + : [], |
|
| 501 | + 'message_types' => isset($setup_args['message_types']) |
|
| 502 | + ? (array) $setup_args['message_types'] |
|
| 503 | + : [], |
|
| 504 | + 'capabilities' => isset($setup_args['capabilities']) |
|
| 505 | + ? (array) $setup_args['capabilities'] |
|
| 506 | + : [], |
|
| 507 | + 'capability_maps' => isset($setup_args['capability_maps']) |
|
| 508 | + ? (array) $setup_args['capability_maps'] |
|
| 509 | + : [], |
|
| 510 | + 'model_paths' => isset($setup_args['model_paths']) |
|
| 511 | + ? (array) $setup_args['model_paths'] |
|
| 512 | + : [], |
|
| 513 | + 'class_paths' => isset($setup_args['class_paths']) |
|
| 514 | + ? (array) $setup_args['class_paths'] |
|
| 515 | + : [], |
|
| 516 | + 'model_extension_paths' => isset($setup_args['model_extension_paths']) |
|
| 517 | + ? (array) $setup_args['model_extension_paths'] |
|
| 518 | + : [], |
|
| 519 | + 'class_extension_paths' => isset($setup_args['class_extension_paths']) |
|
| 520 | + ? (array) $setup_args['class_extension_paths'] |
|
| 521 | + : [], |
|
| 522 | + 'custom_post_types' => isset($setup_args['custom_post_types']) |
|
| 523 | + ? (array) $setup_args['custom_post_types'] |
|
| 524 | + : [], |
|
| 525 | + 'custom_taxonomies' => isset($setup_args['custom_taxonomies']) |
|
| 526 | + ? (array) $setup_args['custom_taxonomies'] |
|
| 527 | + : [], |
|
| 528 | + 'payment_method_paths' => isset($setup_args['payment_method_paths']) |
|
| 529 | + ? (array) $setup_args['payment_method_paths'] |
|
| 530 | + : [], |
|
| 531 | + 'default_terms' => isset($setup_args['default_terms']) |
|
| 532 | + ? (array) $setup_args['default_terms'] |
|
| 533 | + : [], |
|
| 534 | + // if not empty, inserts a new table row after this plugin's row on the WP Plugins page |
|
| 535 | + // that can be used for adding upgrading/marketing info |
|
| 536 | + 'plugins_page_row' => isset($setup_args['plugins_page_row']) |
|
| 537 | + ? (array) $setup_args['plugins_page_row'] |
|
| 538 | + : [], |
|
| 539 | + 'namespace' => isset( |
|
| 540 | + $setup_args['namespace']['FQNS'], |
|
| 541 | + $setup_args['namespace']['DIR'] |
|
| 542 | + ) |
|
| 543 | + ? (array) $setup_args['namespace'] |
|
| 544 | + : [], |
|
| 545 | + 'privacy_policies' => isset($setup_args['privacy_policies']) |
|
| 546 | + ? (array) $setup_args['privacy_policies'] |
|
| 547 | + : '', |
|
| 548 | + ]; |
|
| 549 | + // if plugin_action_slug is NOT set, but an admin page path IS set, |
|
| 550 | + // then let's just use the plugin_slug since that will be used for linking to the admin page |
|
| 551 | + $addon_settings['plugin_action_slug'] = empty($addon_settings['plugin_action_slug']) |
|
| 552 | + && ! empty($addon_settings['admin_path']) |
|
| 553 | + ? $addon_settings['plugin_slug'] |
|
| 554 | + : $addon_settings['plugin_action_slug']; |
|
| 555 | + // full server path to main file (file loaded directly by WP) |
|
| 556 | + $addon_settings['plugin_basename'] = plugin_basename($addon_settings['main_file_path']); |
|
| 557 | + return $addon_settings; |
|
| 558 | + } |
|
| 559 | + |
|
| 560 | + |
|
| 561 | + /** |
|
| 562 | + * @param string $addon_name |
|
| 563 | + * @param array $addon_settings |
|
| 564 | + * @return boolean |
|
| 565 | + */ |
|
| 566 | + private static function _addon_is_compatible(string $addon_name, array $addon_settings): bool |
|
| 567 | + { |
|
| 568 | + global $wp_version; |
|
| 569 | + $incompatibility_message = ''; |
|
| 570 | + // check whether this addon version is compatible with EE core |
|
| 571 | + if (isset(EE_Register_Addon::$_incompatible_addons[ $addon_name ]) |
|
| 572 | + && ! self::_meets_min_core_version_requirement( |
|
| 573 | + EE_Register_Addon::$_incompatible_addons[ $addon_name ], |
|
| 574 | + $addon_settings['version'] |
|
| 575 | + ) |
|
| 576 | + ) { |
|
| 577 | + $incompatibility_message = sprintf( |
|
| 578 | + __( |
|
| 579 | + '%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.', |
|
| 580 | + 'event_espresso' |
|
| 581 | + ), |
|
| 582 | + $addon_name, |
|
| 583 | + '<br />', |
|
| 584 | + EE_Register_Addon::$_incompatible_addons[ $addon_name ], |
|
| 585 | + '<span style="font-weight: bold; color: #D54E21;">', |
|
| 586 | + '</span><br />' |
|
| 587 | + ); |
|
| 588 | + } elseif (! self::_meets_min_core_version_requirement($addon_settings['min_core_version'], espresso_version()) |
|
| 589 | + ) { |
|
| 590 | + $incompatibility_message = sprintf( |
|
| 591 | + __( |
|
| 592 | + '%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".', |
|
| 593 | + 'event_espresso' |
|
| 594 | + ), |
|
| 595 | + $addon_name, |
|
| 596 | + self::_effective_version($addon_settings['min_core_version']), |
|
| 597 | + self::_effective_version(espresso_version()), |
|
| 598 | + '<br />', |
|
| 599 | + '<span style="font-weight: bold; color: #D54E21;">', |
|
| 600 | + '</span><br />' |
|
| 601 | + ); |
|
| 602 | + } elseif (version_compare($wp_version, $addon_settings['min_wp_version'], '<')) { |
|
| 603 | + $incompatibility_message = sprintf( |
|
| 604 | + __( |
|
| 605 | + '%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.', |
|
| 606 | + 'event_espresso' |
|
| 607 | + ), |
|
| 608 | + $addon_name, |
|
| 609 | + $addon_settings['min_wp_version'], |
|
| 610 | + '<br />', |
|
| 611 | + '<span style="font-weight: bold; color: #D54E21;">', |
|
| 612 | + '</span><br />' |
|
| 613 | + ); |
|
| 614 | + } |
|
| 615 | + if (! empty($incompatibility_message)) { |
|
| 616 | + // remove 'activate' from the REQUEST |
|
| 617 | + // so WP doesn't erroneously tell the user the plugin activated fine when it didn't |
|
| 618 | + unset($_GET['activate'], $_REQUEST['activate']); |
|
| 619 | + if (current_user_can('activate_plugins')) { |
|
| 620 | + // show an error message indicating the plugin didn't activate properly |
|
| 621 | + EE_Error::add_error($incompatibility_message, __FILE__, __FUNCTION__, __LINE__); |
|
| 622 | + } |
|
| 623 | + // BAIL FROM THE ADDON REGISTRATION PROCESS |
|
| 624 | + return false; |
|
| 625 | + } |
|
| 626 | + // addon IS compatible |
|
| 627 | + return true; |
|
| 628 | + } |
|
| 629 | + |
|
| 630 | + |
|
| 631 | + /** |
|
| 632 | + * if plugin update engine is being used for auto-updates, |
|
| 633 | + * then let's set that up now before going any further so that ALL addons can be updated |
|
| 634 | + * (not needed if PUE is not being used) |
|
| 635 | + * |
|
| 636 | + * @param string $addon_name |
|
| 637 | + * @param string $class_name |
|
| 638 | + * @param array $setup_args |
|
| 639 | + * @return void |
|
| 640 | + */ |
|
| 641 | + private static function _parse_pue_options(string $addon_name, string $class_name, array $setup_args) |
|
| 642 | + { |
|
| 643 | + if (! empty($setup_args['pue_options'])) { |
|
| 644 | + self::$_settings[ $addon_name ]['pue_options'] = [ |
|
| 645 | + 'pue_plugin_slug' => isset($setup_args['pue_options']['pue_plugin_slug']) |
|
| 646 | + ? (string) $setup_args['pue_options']['pue_plugin_slug'] |
|
| 647 | + : 'espresso_' . strtolower($class_name), |
|
| 648 | + 'plugin_basename' => isset($setup_args['pue_options']['plugin_basename']) |
|
| 649 | + ? (string) $setup_args['pue_options']['plugin_basename'] |
|
| 650 | + : plugin_basename($setup_args['main_file_path']), |
|
| 651 | + 'checkPeriod' => isset($setup_args['pue_options']['checkPeriod']) |
|
| 652 | + ? (string) $setup_args['pue_options']['checkPeriod'] |
|
| 653 | + : '24', |
|
| 654 | + 'use_wp_update' => isset($setup_args['pue_options']['use_wp_update']) |
|
| 655 | + ? (string) $setup_args['pue_options']['use_wp_update'] |
|
| 656 | + : false, |
|
| 657 | + ]; |
|
| 658 | + add_action( |
|
| 659 | + 'AHEE__EE_System__brew_espresso__after_pue_init', |
|
| 660 | + ['EE_Register_Addon', 'load_pue_update'] |
|
| 661 | + ); |
|
| 662 | + } |
|
| 663 | + } |
|
| 664 | + |
|
| 665 | + |
|
| 666 | + /** |
|
| 667 | + * register namespaces right away before any other files or classes get loaded, but AFTER the version checks |
|
| 668 | + * |
|
| 669 | + * @param array $addon_settings |
|
| 670 | + * @return void |
|
| 671 | + */ |
|
| 672 | + private static function _setup_namespaces(array $addon_settings) |
|
| 673 | + { |
|
| 674 | + // |
|
| 675 | + if (isset( |
|
| 676 | + $addon_settings['namespace']['FQNS'], |
|
| 677 | + $addon_settings['namespace']['DIR'] |
|
| 678 | + ) |
|
| 679 | + ) { |
|
| 680 | + EE_Psr4AutoloaderInit::psr4_loader()->addNamespace( |
|
| 681 | + $addon_settings['namespace']['FQNS'], |
|
| 682 | + $addon_settings['namespace']['DIR'] |
|
| 683 | + ); |
|
| 684 | + } |
|
| 685 | + } |
|
| 686 | + |
|
| 687 | + |
|
| 688 | + /** |
|
| 689 | + * @param string $addon_name |
|
| 690 | + * @param array $addon_settings |
|
| 691 | + * @return bool |
|
| 692 | + * @throws InvalidArgumentException |
|
| 693 | + * @throws InvalidDataTypeException |
|
| 694 | + * @throws InvalidInterfaceException |
|
| 695 | + */ |
|
| 696 | + private static function _addon_activation(string $addon_name, array $addon_settings): bool |
|
| 697 | + { |
|
| 698 | + // this is an activation request |
|
| 699 | + if (did_action('activate_plugin')) { |
|
| 700 | + // to find if THIS is the addon that was activated, just check if we have already registered it or not |
|
| 701 | + // (as the newly-activated addon wasn't around the first time addons were registered). |
|
| 702 | + // Note: the presence of pue_options in the addon registration options will initialize the $_settings |
|
| 703 | + // property for the add-on, but the add-on is only partially initialized. Hence, the additional check. |
|
| 704 | + if (! isset(self::$_settings[ $addon_name ]) |
|
| 705 | + || (isset(self::$_settings[ $addon_name ]) |
|
| 706 | + && ! isset(self::$_settings[ $addon_name ]['class_name']) |
|
| 707 | + ) |
|
| 708 | + ) { |
|
| 709 | + self::$_settings[ $addon_name ] = $addon_settings; |
|
| 710 | + $addon = self::_load_and_init_addon_class($addon_name); |
|
| 711 | + $addon->set_activation_indicator_option(); |
|
| 712 | + // dont bother setting up the rest of the addon. |
|
| 713 | + // we know it was just activated and the request will end soon |
|
| 714 | + } |
|
| 715 | + return true; |
|
| 716 | + } |
|
| 717 | + // make sure addon settings are set correctly without overwriting anything existing |
|
| 718 | + if (isset(self::$_settings[ $addon_name ])) { |
|
| 719 | + self::$_settings[ $addon_name ] += $addon_settings; |
|
| 720 | + } else { |
|
| 721 | + self::$_settings[ $addon_name ] = $addon_settings; |
|
| 722 | + } |
|
| 723 | + return false; |
|
| 724 | + } |
|
| 725 | + |
|
| 726 | + |
|
| 727 | + /** |
|
| 728 | + * @param string $addon_name |
|
| 729 | + * @return void |
|
| 730 | + * @throws EE_Error |
|
| 731 | + */ |
|
| 732 | + private static function _setup_autoloaders(string $addon_name) |
|
| 733 | + { |
|
| 734 | + if (! empty(self::$_settings[ $addon_name ]['autoloader_paths'])) { |
|
| 735 | + // setup autoloader for single file |
|
| 736 | + EEH_Autoloader::instance()->register_autoloader(self::$_settings[ $addon_name ]['autoloader_paths']); |
|
| 737 | + } |
|
| 738 | + // setup autoloaders for folders |
|
| 739 | + if (! empty(self::$_settings[ $addon_name ]['autoloader_folders'])) { |
|
| 740 | + foreach ((array) self::$_settings[ $addon_name ]['autoloader_folders'] as $autoloader_folder) { |
|
| 741 | + EEH_Autoloader::register_autoloaders_for_each_file_in_folder($autoloader_folder); |
|
| 742 | + } |
|
| 743 | + } |
|
| 744 | + } |
|
| 745 | + |
|
| 746 | + |
|
| 747 | + /** |
|
| 748 | + * register new models and extensions |
|
| 749 | + * |
|
| 750 | + * @param string $addon_name |
|
| 751 | + * @return void |
|
| 752 | + * @throws EE_Error |
|
| 753 | + */ |
|
| 754 | + private static function _register_models_and_extensions(string $addon_name) |
|
| 755 | + { |
|
| 756 | + // register new models |
|
| 757 | + if (! empty(self::$_settings[ $addon_name ]['model_paths']) |
|
| 758 | + || ! empty(self::$_settings[ $addon_name ]['class_paths']) |
|
| 759 | + ) { |
|
| 760 | + EE_Register_Model::register( |
|
| 761 | + $addon_name, |
|
| 762 | + [ |
|
| 763 | + 'model_paths' => self::$_settings[ $addon_name ]['model_paths'], |
|
| 764 | + 'class_paths' => self::$_settings[ $addon_name ]['class_paths'], |
|
| 765 | + ] |
|
| 766 | + ); |
|
| 767 | + } |
|
| 768 | + // register model extensions |
|
| 769 | + if (! 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 (! empty(self::$_settings[ $addon_name ]['shortcode_paths']) |
|
| 860 | + || ! empty(self::$_settings[ $addon_name ]['shortcode_fqcns']) |
|
| 861 | + ) { |
|
| 862 | + EE_Register_Shortcode::register( |
|
| 863 | + $addon_name, |
|
| 864 | + [ |
|
| 865 | + 'shortcode_paths' => isset(self::$_settings[ $addon_name ]['shortcode_paths']) |
|
| 866 | + ? self::$_settings[ $addon_name ]['shortcode_paths'] |
|
| 867 | + : [], |
|
| 868 | + 'shortcode_fqcns' => isset(self::$_settings[ $addon_name ]['shortcode_fqcns']) |
|
| 869 | + ? self::$_settings[ $addon_name ]['shortcode_fqcns'] |
|
| 870 | + : [], |
|
| 871 | + ] |
|
| 872 | + ); |
|
| 873 | + } |
|
| 874 | + } |
|
| 875 | + |
|
| 876 | + |
|
| 877 | + /** |
|
| 878 | + * @param string $addon_name |
|
| 879 | + * @return void |
|
| 880 | + * @throws EE_Error |
|
| 881 | + */ |
|
| 882 | + private static function _register_widgets(string $addon_name) |
|
| 883 | + { |
|
| 884 | + if (! empty(self::$_settings[ $addon_name ]['widget_paths'])) { |
|
| 885 | + EE_Register_Widget::register( |
|
| 886 | + $addon_name, |
|
| 887 | + ['widget_paths' => self::$_settings[ $addon_name ]['widget_paths']] |
|
| 888 | + ); |
|
| 889 | + } |
|
| 890 | + } |
|
| 891 | + |
|
| 892 | + |
|
| 893 | + /** |
|
| 894 | + * @param string $addon_name |
|
| 895 | + * @return void |
|
| 896 | + * @throws EE_Error |
|
| 897 | + */ |
|
| 898 | + private static function _register_capabilities(string $addon_name) |
|
| 899 | + { |
|
| 900 | + if (! empty(self::$_settings[ $addon_name ]['capabilities'])) { |
|
| 901 | + EE_Register_Capabilities::register( |
|
| 902 | + $addon_name, |
|
| 903 | + [ |
|
| 904 | + 'capabilities' => self::$_settings[ $addon_name ]['capabilities'], |
|
| 905 | + 'capability_maps' => self::$_settings[ $addon_name ]['capability_maps'], |
|
| 906 | + ] |
|
| 907 | + ); |
|
| 908 | + } |
|
| 909 | + } |
|
| 910 | + |
|
| 911 | + |
|
| 912 | + /** |
|
| 913 | + * @param string $addon_name |
|
| 914 | + * @return void |
|
| 915 | + */ |
|
| 916 | + private static function _register_message_types(string $addon_name) |
|
| 917 | + { |
|
| 918 | + if (! empty(self::$_settings[ $addon_name ]['message_types'])) { |
|
| 919 | + add_action( |
|
| 920 | + 'EE_Brewing_Regular___messages_caf', |
|
| 921 | + ['EE_Register_Addon', 'register_message_types'] |
|
| 922 | + ); |
|
| 923 | + } |
|
| 924 | + } |
|
| 925 | + |
|
| 926 | + |
|
| 927 | + /** |
|
| 928 | + * @param string $addon_name |
|
| 929 | + * @return void |
|
| 930 | + * @throws EE_Error |
|
| 931 | + */ |
|
| 932 | + private static function _register_custom_post_types(string $addon_name) |
|
| 933 | + { |
|
| 934 | + if (! empty(self::$_settings[ $addon_name ]['custom_post_types']) |
|
| 935 | + || ! empty(self::$_settings[ $addon_name ]['custom_taxonomies']) |
|
| 936 | + ) { |
|
| 937 | + EE_Register_CPT::register( |
|
| 938 | + $addon_name, |
|
| 939 | + [ |
|
| 940 | + 'cpts' => self::$_settings[ $addon_name ]['custom_post_types'], |
|
| 941 | + 'cts' => self::$_settings[ $addon_name ]['custom_taxonomies'], |
|
| 942 | + 'default_terms' => self::$_settings[ $addon_name ]['default_terms'], |
|
| 943 | + ] |
|
| 944 | + ); |
|
| 945 | + } |
|
| 946 | + } |
|
| 947 | + |
|
| 948 | + |
|
| 949 | + /** |
|
| 950 | + * @param string $addon_name |
|
| 951 | + * @return void |
|
| 952 | + * @throws InvalidArgumentException |
|
| 953 | + * @throws InvalidInterfaceException |
|
| 954 | + * @throws InvalidDataTypeException |
|
| 955 | + * @throws DomainException |
|
| 956 | + * @throws EE_Error |
|
| 957 | + */ |
|
| 958 | + private static function _register_payment_methods(string $addon_name) |
|
| 959 | + { |
|
| 960 | + if (! empty(self::$_settings[ $addon_name ]['payment_method_paths'])) { |
|
| 961 | + EE_Register_Payment_Method::register( |
|
| 962 | + $addon_name, |
|
| 963 | + ['payment_method_paths' => self::$_settings[ $addon_name ]['payment_method_paths']] |
|
| 964 | + ); |
|
| 965 | + } |
|
| 966 | + } |
|
| 967 | + |
|
| 968 | + |
|
| 969 | + /** |
|
| 970 | + * @param string $addon_name |
|
| 971 | + * @return void |
|
| 972 | + * @throws InvalidArgumentException |
|
| 973 | + * @throws InvalidInterfaceException |
|
| 974 | + * @throws InvalidDataTypeException |
|
| 975 | + * @throws DomainException |
|
| 976 | + */ |
|
| 977 | + private static function registerPrivacyPolicies(string $addon_name) |
|
| 978 | + { |
|
| 979 | + if (! empty(self::$_settings[ $addon_name ]['privacy_policies'])) { |
|
| 980 | + EE_Register_Privacy_Policy::register( |
|
| 981 | + $addon_name, |
|
| 982 | + self::$_settings[ $addon_name ]['privacy_policies'] |
|
| 983 | + ); |
|
| 984 | + } |
|
| 985 | + } |
|
| 986 | + |
|
| 987 | + |
|
| 988 | + /** |
|
| 989 | + * @param string $addon_name |
|
| 990 | + * @return void |
|
| 991 | + */ |
|
| 992 | + private static function registerPersonalDataExporters(string $addon_name) |
|
| 993 | + { |
|
| 994 | + if (! empty(self::$_settings[ $addon_name ]['personal_data_exporters'])) { |
|
| 995 | + EE_Register_Personal_Data_Eraser::register( |
|
| 996 | + $addon_name, |
|
| 997 | + self::$_settings[ $addon_name ]['personal_data_exporters'] |
|
| 998 | + ); |
|
| 999 | + } |
|
| 1000 | + } |
|
| 1001 | + |
|
| 1002 | + |
|
| 1003 | + /** |
|
| 1004 | + * @param string $addon_name |
|
| 1005 | + * @return void |
|
| 1006 | + */ |
|
| 1007 | + private static function registerPersonalDataErasers(string $addon_name) |
|
| 1008 | + { |
|
| 1009 | + if (! empty(self::$_settings[ $addon_name ]['personal_data_erasers'])) { |
|
| 1010 | + EE_Register_Personal_Data_Eraser::register( |
|
| 1011 | + $addon_name, |
|
| 1012 | + self::$_settings[ $addon_name ]['personal_data_erasers'] |
|
| 1013 | + ); |
|
| 1014 | + } |
|
| 1015 | + } |
|
| 1016 | + |
|
| 1017 | + |
|
| 1018 | + /** |
|
| 1019 | + * Loads and instantiates the EE_Addon class and adds it onto the registry |
|
| 1020 | + * |
|
| 1021 | + * @param string $addon_name |
|
| 1022 | + * @return EE_Addon |
|
| 1023 | + * @throws InvalidArgumentException |
|
| 1024 | + * @throws InvalidInterfaceException |
|
| 1025 | + * @throws InvalidDataTypeException |
|
| 1026 | + */ |
|
| 1027 | + private static function _load_and_init_addon_class(string $addon_name) |
|
| 1028 | + { |
|
| 1029 | + $addon = self::$loader->getShared( |
|
| 1030 | + self::$_settings[ $addon_name ]['class_name'], |
|
| 1031 | + ['EE_Registry::create(addon)' => true] |
|
| 1032 | + ); |
|
| 1033 | + if (! $addon instanceof EE_Addon) { |
|
| 1034 | + throw new DomainException( |
|
| 1035 | + sprintf( |
|
| 1036 | + esc_html__('The "%1$s" EE_Addon class failed to instantiate!', 'event_espresso'), |
|
| 1037 | + self::$_settings[ $addon_name ]['class_name'] |
|
| 1038 | + ) |
|
| 1039 | + ); |
|
| 1040 | + } |
|
| 1041 | + // setter inject dep map if required |
|
| 1042 | + if ($addon instanceof RequiresDependencyMapInterface && $addon->dependencyMap() === null) { |
|
| 1043 | + $addon->setDependencyMap(self::$loader->getShared('EE_Dependency_Map')); |
|
| 1044 | + } |
|
| 1045 | + // setter inject domain if required |
|
| 1046 | + if ($addon instanceof RequiresDomainInterface |
|
| 1047 | + && $addon->domain() === null |
|
| 1048 | + ) { |
|
| 1049 | + // using supplied Domain object |
|
| 1050 | + $domain = self::$_settings[ $addon_name ]['domain'] instanceof DomainInterface |
|
| 1051 | + ? self::$_settings[ $addon_name ]['domain'] |
|
| 1052 | + : null; |
|
| 1053 | + // or construct one using Domain FQCN |
|
| 1054 | + if ($domain === null && self::$_settings[ $addon_name ]['domain_fqcn'] !== '') { |
|
| 1055 | + $domain = self::$loader->getShared( |
|
| 1056 | + self::$_settings[ $addon_name ]['domain_fqcn'], |
|
| 1057 | + [ |
|
| 1058 | + new EventEspresso\core\domain\values\FilePath( |
|
| 1059 | + self::$_settings[ $addon_name ]['main_file_path'] |
|
| 1060 | + ), |
|
| 1061 | + EventEspresso\core\domain\values\Version::fromString( |
|
| 1062 | + self::$_settings[ $addon_name ]['version'] |
|
| 1063 | + ), |
|
| 1064 | + ] |
|
| 1065 | + ); |
|
| 1066 | + } |
|
| 1067 | + if ($domain instanceof DomainInterface) { |
|
| 1068 | + $addon->setDomain($domain); |
|
| 1069 | + } |
|
| 1070 | + } |
|
| 1071 | + $addon->set_name($addon_name); |
|
| 1072 | + $addon->set_plugin_slug(self::$_settings[ $addon_name ]['plugin_slug']); |
|
| 1073 | + $addon->set_plugin_basename(self::$_settings[ $addon_name ]['plugin_basename']); |
|
| 1074 | + $addon->set_main_plugin_file(self::$_settings[ $addon_name ]['main_file_path']); |
|
| 1075 | + $addon->set_plugin_action_slug(self::$_settings[ $addon_name ]['plugin_action_slug']); |
|
| 1076 | + $addon->set_plugins_page_row(self::$_settings[ $addon_name ]['plugins_page_row']); |
|
| 1077 | + $addon->set_version(self::$_settings[ $addon_name ]['version']); |
|
| 1078 | + $addon->set_min_core_version(self::_effective_version(self::$_settings[ $addon_name ]['min_core_version'])); |
|
| 1079 | + $addon->set_config_section(self::$_settings[ $addon_name ]['config_section']); |
|
| 1080 | + $addon->set_config_class(self::$_settings[ $addon_name ]['config_class']); |
|
| 1081 | + $addon->set_config_name(self::$_settings[ $addon_name ]['config_name']); |
|
| 1082 | + // setup the add-on's pue_slug if we have one. |
|
| 1083 | + if (! empty(self::$_settings[ $addon_name ]['pue_options']['pue_plugin_slug'])) { |
|
| 1084 | + $addon->setPueSlug(self::$_settings[ $addon_name ]['pue_options']['pue_plugin_slug']); |
|
| 1085 | + } |
|
| 1086 | + // unfortunately this can't be hooked in upon construction, because we don't have |
|
| 1087 | + // the plugin mainfile's path upon construction. |
|
| 1088 | + register_deactivation_hook($addon->get_main_plugin_file(), [$addon, 'deactivation']); |
|
| 1089 | + // call any additional admin_callback functions during load_admin_controller hook |
|
| 1090 | + if (! empty(self::$_settings[ $addon_name ]['admin_callback'])) { |
|
| 1091 | + add_action( |
|
| 1092 | + 'AHEE__EE_System__load_controllers__load_admin_controllers', |
|
| 1093 | + [$addon, self::$_settings[ $addon_name ]['admin_callback']] |
|
| 1094 | + ); |
|
| 1095 | + } |
|
| 1096 | + return $addon; |
|
| 1097 | + } |
|
| 1098 | + |
|
| 1099 | + |
|
| 1100 | + /** |
|
| 1101 | + * load_pue_update - Update notifications |
|
| 1102 | + * |
|
| 1103 | + * @return void |
|
| 1104 | + * @throws InvalidArgumentException |
|
| 1105 | + * @throws InvalidDataTypeException |
|
| 1106 | + * @throws InvalidInterfaceException |
|
| 1107 | + */ |
|
| 1108 | + public static function load_pue_update() |
|
| 1109 | + { |
|
| 1110 | + // load PUE client |
|
| 1111 | + require_once EE_THIRD_PARTY . 'pue/pue-client.php'; |
|
| 1112 | + $license_server = defined('PUE_UPDATES_ENDPOINT') ? PUE_UPDATES_ENDPOINT : 'https://eventespresso.com'; |
|
| 1113 | + // cycle thru settings |
|
| 1114 | + foreach (self::$_settings as $settings) { |
|
| 1115 | + if (! empty($settings['pue_options'])) { |
|
| 1116 | + // initiate the class and start the plugin update engine! |
|
| 1117 | + new PluginUpdateEngineChecker( |
|
| 1118 | + // host file URL |
|
| 1119 | + $license_server, |
|
| 1120 | + // plugin slug(s) |
|
| 1121 | + [ |
|
| 1122 | + 'premium' => ['p' => $settings['pue_options']['pue_plugin_slug']], |
|
| 1123 | + 'prerelease' => ['beta' => $settings['pue_options']['pue_plugin_slug'] . '-pr'], |
|
| 1124 | + ], |
|
| 1125 | + // options |
|
| 1126 | + [ |
|
| 1127 | + 'apikey' => EE_Registry::instance()->NET_CFG->core->site_license_key, |
|
| 1128 | + 'lang_domain' => 'event_espresso', |
|
| 1129 | + 'checkPeriod' => $settings['pue_options']['checkPeriod'], |
|
| 1130 | + 'option_key' => 'ee_site_license_key', |
|
| 1131 | + 'options_page_slug' => 'event_espresso', |
|
| 1132 | + 'plugin_basename' => $settings['pue_options']['plugin_basename'], |
|
| 1133 | + // if use_wp_update is TRUE it means you want FREE versions of the plugin to be updated from WP |
|
| 1134 | + 'use_wp_update' => $settings['pue_options']['use_wp_update'], |
|
| 1135 | + ] |
|
| 1136 | + ); |
|
| 1137 | + } |
|
| 1138 | + } |
|
| 1139 | + } |
|
| 1140 | + |
|
| 1141 | + |
|
| 1142 | + /** |
|
| 1143 | + * Callback for EE_Brewing_Regular__messages_caf hook used to register message types. |
|
| 1144 | + * |
|
| 1145 | + * @return void |
|
| 1146 | + * @throws EE_Error |
|
| 1147 | + * @since 4.4.0 |
|
| 1148 | + */ |
|
| 1149 | + public static function register_message_types() |
|
| 1150 | + { |
|
| 1151 | + foreach (self::$_settings as $addon_name => $settings) { |
|
| 1152 | + if (! empty($settings['message_types'])) { |
|
| 1153 | + foreach ((array) $settings['message_types'] as $message_type => $message_type_settings) { |
|
| 1154 | + EE_Register_Message_Type::register($message_type, $message_type_settings); |
|
| 1155 | + } |
|
| 1156 | + } |
|
| 1157 | + } |
|
| 1158 | + } |
|
| 1159 | + |
|
| 1160 | + |
|
| 1161 | + /** |
|
| 1162 | + * This deregisters an addon that was previously registered with a specific addon_name. |
|
| 1163 | + * |
|
| 1164 | + * @param string $addon_name the name for the addon that was previously registered |
|
| 1165 | + * @throws DomainException |
|
| 1166 | + * @throws InvalidArgumentException |
|
| 1167 | + * @throws InvalidDataTypeException |
|
| 1168 | + * @throws InvalidInterfaceException |
|
| 1169 | + * @since 4.3.0 |
|
| 1170 | + */ |
|
| 1171 | + public static function deregister(string $addon_name = '') |
|
| 1172 | + { |
|
| 1173 | + if (isset(self::$_settings[ $addon_name ]['class_name'])) { |
|
| 1174 | + try { |
|
| 1175 | + do_action('AHEE__EE_Register_Addon__deregister__before', $addon_name); |
|
| 1176 | + $class_name = self::$_settings[ $addon_name ]['class_name']; |
|
| 1177 | + if (! empty(self::$_settings[ $addon_name ]['dms_paths'])) { |
|
| 1178 | + // setup DMS |
|
| 1179 | + EE_Register_Data_Migration_Scripts::deregister($addon_name); |
|
| 1180 | + } |
|
| 1181 | + if (! empty(self::$_settings[ $addon_name ]['admin_path'])) { |
|
| 1182 | + // register admin page |
|
| 1183 | + EE_Register_Admin_Page::deregister($addon_name); |
|
| 1184 | + } |
|
| 1185 | + if (! empty(self::$_settings[ $addon_name ]['module_paths'])) { |
|
| 1186 | + // add to list of modules to be registered |
|
| 1187 | + EE_Register_Module::deregister($addon_name); |
|
| 1188 | + } |
|
| 1189 | + if (! empty(self::$_settings[ $addon_name ]['shortcode_paths']) |
|
| 1190 | + || ! empty(self::$_settings[ $addon_name ]['shortcode_fqcns']) |
|
| 1191 | + ) { |
|
| 1192 | + // add to list of shortcodes to be registered |
|
| 1193 | + EE_Register_Shortcode::deregister($addon_name); |
|
| 1194 | + } |
|
| 1195 | + if (! empty(self::$_settings[ $addon_name ]['config_class'])) { |
|
| 1196 | + // if config_class present let's register config. |
|
| 1197 | + EE_Register_Config::deregister(self::$_settings[ $addon_name ]['config_class']); |
|
| 1198 | + } |
|
| 1199 | + if (! empty(self::$_settings[ $addon_name ]['widget_paths'])) { |
|
| 1200 | + // add to list of widgets to be registered |
|
| 1201 | + EE_Register_Widget::deregister($addon_name); |
|
| 1202 | + } |
|
| 1203 | + if (! empty(self::$_settings[ $addon_name ]['model_paths']) |
|
| 1204 | + || ! empty(self::$_settings[ $addon_name ]['class_paths']) |
|
| 1205 | + ) { |
|
| 1206 | + // add to list of shortcodes to be registered |
|
| 1207 | + EE_Register_Model::deregister($addon_name); |
|
| 1208 | + } |
|
| 1209 | + if (! empty(self::$_settings[ $addon_name ]['model_extension_paths']) |
|
| 1210 | + || ! empty(self::$_settings[ $addon_name ]['class_extension_paths']) |
|
| 1211 | + ) { |
|
| 1212 | + // add to list of shortcodes to be registered |
|
| 1213 | + EE_Register_Model_Extensions::deregister($addon_name); |
|
| 1214 | + } |
|
| 1215 | + if (! empty(self::$_settings[ $addon_name ]['message_types'])) { |
|
| 1216 | + foreach ((array) self::$_settings[ $addon_name ]['message_types'] as $message_type => $message_type_settings) { |
|
| 1217 | + EE_Register_Message_Type::deregister($message_type); |
|
| 1218 | + } |
|
| 1219 | + } |
|
| 1220 | + // deregister capabilities for addon |
|
| 1221 | + if (! empty(self::$_settings[ $addon_name ]['capabilities']) |
|
| 1222 | + || ! empty(self::$_settings[ $addon_name ]['capability_maps']) |
|
| 1223 | + ) { |
|
| 1224 | + EE_Register_Capabilities::deregister($addon_name); |
|
| 1225 | + } |
|
| 1226 | + // deregister custom_post_types for addon |
|
| 1227 | + if (! empty(self::$_settings[ $addon_name ]['custom_post_types'])) { |
|
| 1228 | + EE_Register_CPT::deregister($addon_name); |
|
| 1229 | + } |
|
| 1230 | + if (! empty(self::$_settings[ $addon_name ]['payment_method_paths'])) { |
|
| 1231 | + EE_Register_Payment_Method::deregister($addon_name); |
|
| 1232 | + } |
|
| 1233 | + $addon = EE_Registry::instance()->getAddon($class_name); |
|
| 1234 | + if ($addon instanceof EE_Addon) { |
|
| 1235 | + remove_action( |
|
| 1236 | + 'deactivate_' . $addon->get_main_plugin_file_basename(), |
|
| 1237 | + [$addon, 'deactivation'] |
|
| 1238 | + ); |
|
| 1239 | + remove_action( |
|
| 1240 | + 'AHEE__EE_System__perform_activations_upgrades_and_migrations', |
|
| 1241 | + [$addon, 'initialize_db_if_no_migrations_required'] |
|
| 1242 | + ); |
|
| 1243 | + // remove `after_registration` call |
|
| 1244 | + remove_action( |
|
| 1245 | + 'AHEE__EE_System__load_espresso_addons__complete', |
|
| 1246 | + [$addon, 'after_registration'], |
|
| 1247 | + 999 |
|
| 1248 | + ); |
|
| 1249 | + } |
|
| 1250 | + EE_Registry::instance()->removeAddon($class_name); |
|
| 1251 | + } catch (OutOfBoundsException $addon_not_yet_registered_exception) { |
|
| 1252 | + // the add-on was not yet registered in the registry, |
|
| 1253 | + // so RegistryContainer::__get() throws this exception. |
|
| 1254 | + // also no need to worry about this or log it, |
|
| 1255 | + // it's ok to deregister an add-on before its registered in the registry |
|
| 1256 | + } catch (Exception $e) { |
|
| 1257 | + new ExceptionLogger($e); |
|
| 1258 | + } |
|
| 1259 | + unset(self::$_settings[ $addon_name ]); |
|
| 1260 | + do_action('AHEE__EE_Register_Addon__deregister__after', $addon_name); |
|
| 1261 | + } |
|
| 1262 | + } |
|
| 1263 | 1263 | } |
@@ -75,15 +75,15 @@ discard block |
||
| 75 | 75 | // offsets: 0 . 1 . 2 . 3 . 4 |
| 76 | 76 | $version_parts = explode('.', $min_core_version); |
| 77 | 77 | // check they specified the micro version (after 2nd period) |
| 78 | - if (! isset($version_parts[2])) { |
|
| 78 | + if ( ! isset($version_parts[2])) { |
|
| 79 | 79 | $version_parts[2] = '0'; |
| 80 | 80 | } |
| 81 | 81 | // if they didn't specify the 'p', or 'rc' part. Just assume the lowest possible |
| 82 | 82 | // soon we can assume that's 'rc', but this current version is 'alpha' |
| 83 | - if (! isset($version_parts[3])) { |
|
| 83 | + if ( ! isset($version_parts[3])) { |
|
| 84 | 84 | $version_parts[3] = 'dev'; |
| 85 | 85 | } |
| 86 | - if (! isset($version_parts[4])) { |
|
| 86 | + if ( ! isset($version_parts[4])) { |
|
| 87 | 87 | $version_parts[4] = '000'; |
| 88 | 88 | } |
| 89 | 89 | return implode('.', $version_parts); |
@@ -260,11 +260,11 @@ discard block |
||
| 260 | 260 | */ |
| 261 | 261 | public static function register(string $addon_name = '', array $setup_args = []): bool |
| 262 | 262 | { |
| 263 | - if (! self::$loader instanceof LoaderInterface) { |
|
| 263 | + if ( ! self::$loader instanceof LoaderInterface) { |
|
| 264 | 264 | self::$loader = EventEspresso\core\services\loaders\LoaderFactory::getLoader(); |
| 265 | 265 | } |
| 266 | 266 | // make sure this was called in the right place! |
| 267 | - if (! did_action('activate_plugin') |
|
| 267 | + if ( ! did_action('activate_plugin') |
|
| 268 | 268 | && ( |
| 269 | 269 | ! did_action('AHEE__EE_System__load_espresso_addons') |
| 270 | 270 | || did_action('AHEE__EE_System___detect_if_activation_or_upgrade__begin') |
@@ -292,7 +292,7 @@ discard block |
||
| 292 | 292 | // setup PUE |
| 293 | 293 | EE_Register_Addon::_parse_pue_options($addon_name, $class_name, $setup_args); |
| 294 | 294 | // does this addon work with this version of core or WordPress ? |
| 295 | - if (! EE_Register_Addon::_addon_is_compatible($addon_name, $addon_settings)) { |
|
| 295 | + if ( ! EE_Register_Addon::_addon_is_compatible($addon_name, $addon_settings)) { |
|
| 296 | 296 | return false; |
| 297 | 297 | } |
| 298 | 298 | // register namespaces |
@@ -357,7 +357,7 @@ discard block |
||
| 357 | 357 | ) |
| 358 | 358 | ); |
| 359 | 359 | } |
| 360 | - if (! isset($setup_args['main_file_path']) || empty($setup_args['main_file_path'])) { |
|
| 360 | + if ( ! isset($setup_args['main_file_path']) || empty($setup_args['main_file_path'])) { |
|
| 361 | 361 | throw new EE_Error( |
| 362 | 362 | sprintf( |
| 363 | 363 | esc_html__( |
@@ -369,7 +369,7 @@ discard block |
||
| 369 | 369 | ); |
| 370 | 370 | } |
| 371 | 371 | // check that addon has not already been registered with that name |
| 372 | - if (isset(self::$_settings[ $addon_name ]) && ! did_action('activate_plugin')) { |
|
| 372 | + if (isset(self::$_settings[$addon_name]) && ! did_action('activate_plugin')) { |
|
| 373 | 373 | throw new EE_Error( |
| 374 | 374 | sprintf( |
| 375 | 375 | esc_html__( |
@@ -401,7 +401,7 @@ discard block |
||
| 401 | 401 | // check if classname is fully qualified or is a legacy classname already prefixed with 'EE_' |
| 402 | 402 | return strpos($class_name, '\\') || strpos($class_name, 'EE_') === 0 |
| 403 | 403 | ? $class_name |
| 404 | - : 'EE_' . $class_name; |
|
| 404 | + : 'EE_'.$class_name; |
|
| 405 | 405 | } |
| 406 | 406 | |
| 407 | 407 | |
@@ -568,9 +568,9 @@ discard block |
||
| 568 | 568 | global $wp_version; |
| 569 | 569 | $incompatibility_message = ''; |
| 570 | 570 | // check whether this addon version is compatible with EE core |
| 571 | - if (isset(EE_Register_Addon::$_incompatible_addons[ $addon_name ]) |
|
| 571 | + if (isset(EE_Register_Addon::$_incompatible_addons[$addon_name]) |
|
| 572 | 572 | && ! self::_meets_min_core_version_requirement( |
| 573 | - EE_Register_Addon::$_incompatible_addons[ $addon_name ], |
|
| 573 | + EE_Register_Addon::$_incompatible_addons[$addon_name], |
|
| 574 | 574 | $addon_settings['version'] |
| 575 | 575 | ) |
| 576 | 576 | ) { |
@@ -581,11 +581,11 @@ discard block |
||
| 581 | 581 | ), |
| 582 | 582 | $addon_name, |
| 583 | 583 | '<br />', |
| 584 | - EE_Register_Addon::$_incompatible_addons[ $addon_name ], |
|
| 584 | + EE_Register_Addon::$_incompatible_addons[$addon_name], |
|
| 585 | 585 | '<span style="font-weight: bold; color: #D54E21;">', |
| 586 | 586 | '</span><br />' |
| 587 | 587 | ); |
| 588 | - } elseif (! self::_meets_min_core_version_requirement($addon_settings['min_core_version'], espresso_version()) |
|
| 588 | + } elseif ( ! self::_meets_min_core_version_requirement($addon_settings['min_core_version'], espresso_version()) |
|
| 589 | 589 | ) { |
| 590 | 590 | $incompatibility_message = sprintf( |
| 591 | 591 | __( |
@@ -612,7 +612,7 @@ discard block |
||
| 612 | 612 | '</span><br />' |
| 613 | 613 | ); |
| 614 | 614 | } |
| 615 | - if (! empty($incompatibility_message)) { |
|
| 615 | + if ( ! empty($incompatibility_message)) { |
|
| 616 | 616 | // remove 'activate' from the REQUEST |
| 617 | 617 | // so WP doesn't erroneously tell the user the plugin activated fine when it didn't |
| 618 | 618 | unset($_GET['activate'], $_REQUEST['activate']); |
@@ -640,11 +640,11 @@ discard block |
||
| 640 | 640 | */ |
| 641 | 641 | private static function _parse_pue_options(string $addon_name, string $class_name, array $setup_args) |
| 642 | 642 | { |
| 643 | - if (! empty($setup_args['pue_options'])) { |
|
| 644 | - self::$_settings[ $addon_name ]['pue_options'] = [ |
|
| 643 | + if ( ! empty($setup_args['pue_options'])) { |
|
| 644 | + self::$_settings[$addon_name]['pue_options'] = [ |
|
| 645 | 645 | 'pue_plugin_slug' => isset($setup_args['pue_options']['pue_plugin_slug']) |
| 646 | 646 | ? (string) $setup_args['pue_options']['pue_plugin_slug'] |
| 647 | - : 'espresso_' . strtolower($class_name), |
|
| 647 | + : 'espresso_'.strtolower($class_name), |
|
| 648 | 648 | 'plugin_basename' => isset($setup_args['pue_options']['plugin_basename']) |
| 649 | 649 | ? (string) $setup_args['pue_options']['plugin_basename'] |
| 650 | 650 | : plugin_basename($setup_args['main_file_path']), |
@@ -701,12 +701,12 @@ discard block |
||
| 701 | 701 | // (as the newly-activated addon wasn't around the first time addons were registered). |
| 702 | 702 | // Note: the presence of pue_options in the addon registration options will initialize the $_settings |
| 703 | 703 | // property for the add-on, but the add-on is only partially initialized. Hence, the additional check. |
| 704 | - if (! isset(self::$_settings[ $addon_name ]) |
|
| 705 | - || (isset(self::$_settings[ $addon_name ]) |
|
| 706 | - && ! isset(self::$_settings[ $addon_name ]['class_name']) |
|
| 704 | + if ( ! isset(self::$_settings[$addon_name]) |
|
| 705 | + || (isset(self::$_settings[$addon_name]) |
|
| 706 | + && ! isset(self::$_settings[$addon_name]['class_name']) |
|
| 707 | 707 | ) |
| 708 | 708 | ) { |
| 709 | - self::$_settings[ $addon_name ] = $addon_settings; |
|
| 709 | + self::$_settings[$addon_name] = $addon_settings; |
|
| 710 | 710 | $addon = self::_load_and_init_addon_class($addon_name); |
| 711 | 711 | $addon->set_activation_indicator_option(); |
| 712 | 712 | // dont bother setting up the rest of the addon. |
@@ -715,10 +715,10 @@ discard block |
||
| 715 | 715 | return true; |
| 716 | 716 | } |
| 717 | 717 | // make sure addon settings are set correctly without overwriting anything existing |
| 718 | - if (isset(self::$_settings[ $addon_name ])) { |
|
| 719 | - self::$_settings[ $addon_name ] += $addon_settings; |
|
| 718 | + if (isset(self::$_settings[$addon_name])) { |
|
| 719 | + self::$_settings[$addon_name] += $addon_settings; |
|
| 720 | 720 | } else { |
| 721 | - self::$_settings[ $addon_name ] = $addon_settings; |
|
| 721 | + self::$_settings[$addon_name] = $addon_settings; |
|
| 722 | 722 | } |
| 723 | 723 | return false; |
| 724 | 724 | } |
@@ -731,13 +731,13 @@ discard block |
||
| 731 | 731 | */ |
| 732 | 732 | private static function _setup_autoloaders(string $addon_name) |
| 733 | 733 | { |
| 734 | - if (! empty(self::$_settings[ $addon_name ]['autoloader_paths'])) { |
|
| 734 | + if ( ! empty(self::$_settings[$addon_name]['autoloader_paths'])) { |
|
| 735 | 735 | // setup autoloader for single file |
| 736 | - EEH_Autoloader::instance()->register_autoloader(self::$_settings[ $addon_name ]['autoloader_paths']); |
|
| 736 | + EEH_Autoloader::instance()->register_autoloader(self::$_settings[$addon_name]['autoloader_paths']); |
|
| 737 | 737 | } |
| 738 | 738 | // setup autoloaders for folders |
| 739 | - if (! empty(self::$_settings[ $addon_name ]['autoloader_folders'])) { |
|
| 740 | - foreach ((array) self::$_settings[ $addon_name ]['autoloader_folders'] as $autoloader_folder) { |
|
| 739 | + if ( ! empty(self::$_settings[$addon_name]['autoloader_folders'])) { |
|
| 740 | + foreach ((array) self::$_settings[$addon_name]['autoloader_folders'] as $autoloader_folder) { |
|
| 741 | 741 | EEH_Autoloader::register_autoloaders_for_each_file_in_folder($autoloader_folder); |
| 742 | 742 | } |
| 743 | 743 | } |
@@ -754,26 +754,26 @@ discard block |
||
| 754 | 754 | private static function _register_models_and_extensions(string $addon_name) |
| 755 | 755 | { |
| 756 | 756 | // register new models |
| 757 | - if (! empty(self::$_settings[ $addon_name ]['model_paths']) |
|
| 758 | - || ! empty(self::$_settings[ $addon_name ]['class_paths']) |
|
| 757 | + if ( ! empty(self::$_settings[$addon_name]['model_paths']) |
|
| 758 | + || ! empty(self::$_settings[$addon_name]['class_paths']) |
|
| 759 | 759 | ) { |
| 760 | 760 | EE_Register_Model::register( |
| 761 | 761 | $addon_name, |
| 762 | 762 | [ |
| 763 | - 'model_paths' => self::$_settings[ $addon_name ]['model_paths'], |
|
| 764 | - 'class_paths' => self::$_settings[ $addon_name ]['class_paths'], |
|
| 763 | + 'model_paths' => self::$_settings[$addon_name]['model_paths'], |
|
| 764 | + 'class_paths' => self::$_settings[$addon_name]['class_paths'], |
|
| 765 | 765 | ] |
| 766 | 766 | ); |
| 767 | 767 | } |
| 768 | 768 | // register model extensions |
| 769 | - if (! empty(self::$_settings[ $addon_name ]['model_extension_paths']) |
|
| 770 | - || ! empty(self::$_settings[ $addon_name ]['class_extension_paths']) |
|
| 769 | + if ( ! 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 | } |
@@ -856,17 +856,17 @@ discard block |
||
| 856 | 856 | */ |
| 857 | 857 | private static function _register_shortcodes(string $addon_name) |
| 858 | 858 | { |
| 859 | - if (! empty(self::$_settings[ $addon_name ]['shortcode_paths']) |
|
| 860 | - || ! empty(self::$_settings[ $addon_name ]['shortcode_fqcns']) |
|
| 859 | + if ( ! empty(self::$_settings[$addon_name]['shortcode_paths']) |
|
| 860 | + || ! empty(self::$_settings[$addon_name]['shortcode_fqcns']) |
|
| 861 | 861 | ) { |
| 862 | 862 | EE_Register_Shortcode::register( |
| 863 | 863 | $addon_name, |
| 864 | 864 | [ |
| 865 | - 'shortcode_paths' => isset(self::$_settings[ $addon_name ]['shortcode_paths']) |
|
| 866 | - ? self::$_settings[ $addon_name ]['shortcode_paths'] |
|
| 865 | + 'shortcode_paths' => isset(self::$_settings[$addon_name]['shortcode_paths']) |
|
| 866 | + ? self::$_settings[$addon_name]['shortcode_paths'] |
|
| 867 | 867 | : [], |
| 868 | - 'shortcode_fqcns' => isset(self::$_settings[ $addon_name ]['shortcode_fqcns']) |
|
| 869 | - ? self::$_settings[ $addon_name ]['shortcode_fqcns'] |
|
| 868 | + 'shortcode_fqcns' => isset(self::$_settings[$addon_name]['shortcode_fqcns']) |
|
| 869 | + ? self::$_settings[$addon_name]['shortcode_fqcns'] |
|
| 870 | 870 | : [], |
| 871 | 871 | ] |
| 872 | 872 | ); |
@@ -881,10 +881,10 @@ discard block |
||
| 881 | 881 | */ |
| 882 | 882 | private static function _register_widgets(string $addon_name) |
| 883 | 883 | { |
| 884 | - if (! empty(self::$_settings[ $addon_name ]['widget_paths'])) { |
|
| 884 | + if ( ! empty(self::$_settings[$addon_name]['widget_paths'])) { |
|
| 885 | 885 | EE_Register_Widget::register( |
| 886 | 886 | $addon_name, |
| 887 | - ['widget_paths' => self::$_settings[ $addon_name ]['widget_paths']] |
|
| 887 | + ['widget_paths' => self::$_settings[$addon_name]['widget_paths']] |
|
| 888 | 888 | ); |
| 889 | 889 | } |
| 890 | 890 | } |
@@ -897,12 +897,12 @@ discard block |
||
| 897 | 897 | */ |
| 898 | 898 | private static function _register_capabilities(string $addon_name) |
| 899 | 899 | { |
| 900 | - if (! empty(self::$_settings[ $addon_name ]['capabilities'])) { |
|
| 900 | + if ( ! empty(self::$_settings[$addon_name]['capabilities'])) { |
|
| 901 | 901 | EE_Register_Capabilities::register( |
| 902 | 902 | $addon_name, |
| 903 | 903 | [ |
| 904 | - 'capabilities' => self::$_settings[ $addon_name ]['capabilities'], |
|
| 905 | - 'capability_maps' => self::$_settings[ $addon_name ]['capability_maps'], |
|
| 904 | + 'capabilities' => self::$_settings[$addon_name]['capabilities'], |
|
| 905 | + 'capability_maps' => self::$_settings[$addon_name]['capability_maps'], |
|
| 906 | 906 | ] |
| 907 | 907 | ); |
| 908 | 908 | } |
@@ -915,7 +915,7 @@ discard block |
||
| 915 | 915 | */ |
| 916 | 916 | private static function _register_message_types(string $addon_name) |
| 917 | 917 | { |
| 918 | - if (! empty(self::$_settings[ $addon_name ]['message_types'])) { |
|
| 918 | + if ( ! empty(self::$_settings[$addon_name]['message_types'])) { |
|
| 919 | 919 | add_action( |
| 920 | 920 | 'EE_Brewing_Regular___messages_caf', |
| 921 | 921 | ['EE_Register_Addon', 'register_message_types'] |
@@ -931,15 +931,15 @@ discard block |
||
| 931 | 931 | */ |
| 932 | 932 | private static function _register_custom_post_types(string $addon_name) |
| 933 | 933 | { |
| 934 | - if (! empty(self::$_settings[ $addon_name ]['custom_post_types']) |
|
| 935 | - || ! empty(self::$_settings[ $addon_name ]['custom_taxonomies']) |
|
| 934 | + if ( ! empty(self::$_settings[$addon_name]['custom_post_types']) |
|
| 935 | + || ! empty(self::$_settings[$addon_name]['custom_taxonomies']) |
|
| 936 | 936 | ) { |
| 937 | 937 | EE_Register_CPT::register( |
| 938 | 938 | $addon_name, |
| 939 | 939 | [ |
| 940 | - 'cpts' => self::$_settings[ $addon_name ]['custom_post_types'], |
|
| 941 | - 'cts' => self::$_settings[ $addon_name ]['custom_taxonomies'], |
|
| 942 | - 'default_terms' => self::$_settings[ $addon_name ]['default_terms'], |
|
| 940 | + 'cpts' => self::$_settings[$addon_name]['custom_post_types'], |
|
| 941 | + 'cts' => self::$_settings[$addon_name]['custom_taxonomies'], |
|
| 942 | + 'default_terms' => self::$_settings[$addon_name]['default_terms'], |
|
| 943 | 943 | ] |
| 944 | 944 | ); |
| 945 | 945 | } |
@@ -957,10 +957,10 @@ discard block |
||
| 957 | 957 | */ |
| 958 | 958 | private static function _register_payment_methods(string $addon_name) |
| 959 | 959 | { |
| 960 | - if (! empty(self::$_settings[ $addon_name ]['payment_method_paths'])) { |
|
| 960 | + if ( ! empty(self::$_settings[$addon_name]['payment_method_paths'])) { |
|
| 961 | 961 | EE_Register_Payment_Method::register( |
| 962 | 962 | $addon_name, |
| 963 | - ['payment_method_paths' => self::$_settings[ $addon_name ]['payment_method_paths']] |
|
| 963 | + ['payment_method_paths' => self::$_settings[$addon_name]['payment_method_paths']] |
|
| 964 | 964 | ); |
| 965 | 965 | } |
| 966 | 966 | } |
@@ -976,10 +976,10 @@ discard block |
||
| 976 | 976 | */ |
| 977 | 977 | private static function registerPrivacyPolicies(string $addon_name) |
| 978 | 978 | { |
| 979 | - if (! empty(self::$_settings[ $addon_name ]['privacy_policies'])) { |
|
| 979 | + if ( ! empty(self::$_settings[$addon_name]['privacy_policies'])) { |
|
| 980 | 980 | EE_Register_Privacy_Policy::register( |
| 981 | 981 | $addon_name, |
| 982 | - self::$_settings[ $addon_name ]['privacy_policies'] |
|
| 982 | + self::$_settings[$addon_name]['privacy_policies'] |
|
| 983 | 983 | ); |
| 984 | 984 | } |
| 985 | 985 | } |
@@ -991,10 +991,10 @@ discard block |
||
| 991 | 991 | */ |
| 992 | 992 | private static function registerPersonalDataExporters(string $addon_name) |
| 993 | 993 | { |
| 994 | - if (! empty(self::$_settings[ $addon_name ]['personal_data_exporters'])) { |
|
| 994 | + if ( ! empty(self::$_settings[$addon_name]['personal_data_exporters'])) { |
|
| 995 | 995 | EE_Register_Personal_Data_Eraser::register( |
| 996 | 996 | $addon_name, |
| 997 | - self::$_settings[ $addon_name ]['personal_data_exporters'] |
|
| 997 | + self::$_settings[$addon_name]['personal_data_exporters'] |
|
| 998 | 998 | ); |
| 999 | 999 | } |
| 1000 | 1000 | } |
@@ -1006,10 +1006,10 @@ discard block |
||
| 1006 | 1006 | */ |
| 1007 | 1007 | private static function registerPersonalDataErasers(string $addon_name) |
| 1008 | 1008 | { |
| 1009 | - if (! empty(self::$_settings[ $addon_name ]['personal_data_erasers'])) { |
|
| 1009 | + if ( ! empty(self::$_settings[$addon_name]['personal_data_erasers'])) { |
|
| 1010 | 1010 | EE_Register_Personal_Data_Eraser::register( |
| 1011 | 1011 | $addon_name, |
| 1012 | - self::$_settings[ $addon_name ]['personal_data_erasers'] |
|
| 1012 | + self::$_settings[$addon_name]['personal_data_erasers'] |
|
| 1013 | 1013 | ); |
| 1014 | 1014 | } |
| 1015 | 1015 | } |
@@ -1027,14 +1027,14 @@ discard block |
||
| 1027 | 1027 | private static function _load_and_init_addon_class(string $addon_name) |
| 1028 | 1028 | { |
| 1029 | 1029 | $addon = self::$loader->getShared( |
| 1030 | - self::$_settings[ $addon_name ]['class_name'], |
|
| 1030 | + self::$_settings[$addon_name]['class_name'], |
|
| 1031 | 1031 | ['EE_Registry::create(addon)' => true] |
| 1032 | 1032 | ); |
| 1033 | - if (! $addon instanceof EE_Addon) { |
|
| 1033 | + if ( ! $addon instanceof EE_Addon) { |
|
| 1034 | 1034 | throw new DomainException( |
| 1035 | 1035 | sprintf( |
| 1036 | 1036 | esc_html__('The "%1$s" EE_Addon class failed to instantiate!', 'event_espresso'), |
| 1037 | - self::$_settings[ $addon_name ]['class_name'] |
|
| 1037 | + self::$_settings[$addon_name]['class_name'] |
|
| 1038 | 1038 | ) |
| 1039 | 1039 | ); |
| 1040 | 1040 | } |
@@ -1047,19 +1047,19 @@ discard block |
||
| 1047 | 1047 | && $addon->domain() === null |
| 1048 | 1048 | ) { |
| 1049 | 1049 | // using supplied Domain object |
| 1050 | - $domain = self::$_settings[ $addon_name ]['domain'] instanceof DomainInterface |
|
| 1051 | - ? self::$_settings[ $addon_name ]['domain'] |
|
| 1050 | + $domain = self::$_settings[$addon_name]['domain'] instanceof DomainInterface |
|
| 1051 | + ? self::$_settings[$addon_name]['domain'] |
|
| 1052 | 1052 | : null; |
| 1053 | 1053 | // or construct one using Domain FQCN |
| 1054 | - if ($domain === null && self::$_settings[ $addon_name ]['domain_fqcn'] !== '') { |
|
| 1054 | + if ($domain === null && self::$_settings[$addon_name]['domain_fqcn'] !== '') { |
|
| 1055 | 1055 | $domain = self::$loader->getShared( |
| 1056 | - self::$_settings[ $addon_name ]['domain_fqcn'], |
|
| 1056 | + self::$_settings[$addon_name]['domain_fqcn'], |
|
| 1057 | 1057 | [ |
| 1058 | 1058 | new EventEspresso\core\domain\values\FilePath( |
| 1059 | - self::$_settings[ $addon_name ]['main_file_path'] |
|
| 1059 | + self::$_settings[$addon_name]['main_file_path'] |
|
| 1060 | 1060 | ), |
| 1061 | 1061 | EventEspresso\core\domain\values\Version::fromString( |
| 1062 | - self::$_settings[ $addon_name ]['version'] |
|
| 1062 | + self::$_settings[$addon_name]['version'] |
|
| 1063 | 1063 | ), |
| 1064 | 1064 | ] |
| 1065 | 1065 | ); |
@@ -1069,28 +1069,28 @@ discard block |
||
| 1069 | 1069 | } |
| 1070 | 1070 | } |
| 1071 | 1071 | $addon->set_name($addon_name); |
| 1072 | - $addon->set_plugin_slug(self::$_settings[ $addon_name ]['plugin_slug']); |
|
| 1073 | - $addon->set_plugin_basename(self::$_settings[ $addon_name ]['plugin_basename']); |
|
| 1074 | - $addon->set_main_plugin_file(self::$_settings[ $addon_name ]['main_file_path']); |
|
| 1075 | - $addon->set_plugin_action_slug(self::$_settings[ $addon_name ]['plugin_action_slug']); |
|
| 1076 | - $addon->set_plugins_page_row(self::$_settings[ $addon_name ]['plugins_page_row']); |
|
| 1077 | - $addon->set_version(self::$_settings[ $addon_name ]['version']); |
|
| 1078 | - $addon->set_min_core_version(self::_effective_version(self::$_settings[ $addon_name ]['min_core_version'])); |
|
| 1079 | - $addon->set_config_section(self::$_settings[ $addon_name ]['config_section']); |
|
| 1080 | - $addon->set_config_class(self::$_settings[ $addon_name ]['config_class']); |
|
| 1081 | - $addon->set_config_name(self::$_settings[ $addon_name ]['config_name']); |
|
| 1072 | + $addon->set_plugin_slug(self::$_settings[$addon_name]['plugin_slug']); |
|
| 1073 | + $addon->set_plugin_basename(self::$_settings[$addon_name]['plugin_basename']); |
|
| 1074 | + $addon->set_main_plugin_file(self::$_settings[$addon_name]['main_file_path']); |
|
| 1075 | + $addon->set_plugin_action_slug(self::$_settings[$addon_name]['plugin_action_slug']); |
|
| 1076 | + $addon->set_plugins_page_row(self::$_settings[$addon_name]['plugins_page_row']); |
|
| 1077 | + $addon->set_version(self::$_settings[$addon_name]['version']); |
|
| 1078 | + $addon->set_min_core_version(self::_effective_version(self::$_settings[$addon_name]['min_core_version'])); |
|
| 1079 | + $addon->set_config_section(self::$_settings[$addon_name]['config_section']); |
|
| 1080 | + $addon->set_config_class(self::$_settings[$addon_name]['config_class']); |
|
| 1081 | + $addon->set_config_name(self::$_settings[$addon_name]['config_name']); |
|
| 1082 | 1082 | // setup the add-on's pue_slug if we have one. |
| 1083 | - if (! empty(self::$_settings[ $addon_name ]['pue_options']['pue_plugin_slug'])) { |
|
| 1084 | - $addon->setPueSlug(self::$_settings[ $addon_name ]['pue_options']['pue_plugin_slug']); |
|
| 1083 | + if ( ! empty(self::$_settings[$addon_name]['pue_options']['pue_plugin_slug'])) { |
|
| 1084 | + $addon->setPueSlug(self::$_settings[$addon_name]['pue_options']['pue_plugin_slug']); |
|
| 1085 | 1085 | } |
| 1086 | 1086 | // unfortunately this can't be hooked in upon construction, because we don't have |
| 1087 | 1087 | // the plugin mainfile's path upon construction. |
| 1088 | 1088 | register_deactivation_hook($addon->get_main_plugin_file(), [$addon, 'deactivation']); |
| 1089 | 1089 | // call any additional admin_callback functions during load_admin_controller hook |
| 1090 | - if (! empty(self::$_settings[ $addon_name ]['admin_callback'])) { |
|
| 1090 | + if ( ! empty(self::$_settings[$addon_name]['admin_callback'])) { |
|
| 1091 | 1091 | add_action( |
| 1092 | 1092 | 'AHEE__EE_System__load_controllers__load_admin_controllers', |
| 1093 | - [$addon, self::$_settings[ $addon_name ]['admin_callback']] |
|
| 1093 | + [$addon, self::$_settings[$addon_name]['admin_callback']] |
|
| 1094 | 1094 | ); |
| 1095 | 1095 | } |
| 1096 | 1096 | return $addon; |
@@ -1108,11 +1108,11 @@ discard block |
||
| 1108 | 1108 | public static function load_pue_update() |
| 1109 | 1109 | { |
| 1110 | 1110 | // load PUE client |
| 1111 | - require_once EE_THIRD_PARTY . 'pue/pue-client.php'; |
|
| 1111 | + require_once EE_THIRD_PARTY.'pue/pue-client.php'; |
|
| 1112 | 1112 | $license_server = defined('PUE_UPDATES_ENDPOINT') ? PUE_UPDATES_ENDPOINT : 'https://eventespresso.com'; |
| 1113 | 1113 | // cycle thru settings |
| 1114 | 1114 | foreach (self::$_settings as $settings) { |
| 1115 | - if (! empty($settings['pue_options'])) { |
|
| 1115 | + if ( ! empty($settings['pue_options'])) { |
|
| 1116 | 1116 | // initiate the class and start the plugin update engine! |
| 1117 | 1117 | new PluginUpdateEngineChecker( |
| 1118 | 1118 | // host file URL |
@@ -1120,7 +1120,7 @@ discard block |
||
| 1120 | 1120 | // plugin slug(s) |
| 1121 | 1121 | [ |
| 1122 | 1122 | 'premium' => ['p' => $settings['pue_options']['pue_plugin_slug']], |
| 1123 | - 'prerelease' => ['beta' => $settings['pue_options']['pue_plugin_slug'] . '-pr'], |
|
| 1123 | + 'prerelease' => ['beta' => $settings['pue_options']['pue_plugin_slug'].'-pr'], |
|
| 1124 | 1124 | ], |
| 1125 | 1125 | // options |
| 1126 | 1126 | [ |
@@ -1149,7 +1149,7 @@ discard block |
||
| 1149 | 1149 | public static function register_message_types() |
| 1150 | 1150 | { |
| 1151 | 1151 | foreach (self::$_settings as $addon_name => $settings) { |
| 1152 | - if (! empty($settings['message_types'])) { |
|
| 1152 | + if ( ! empty($settings['message_types'])) { |
|
| 1153 | 1153 | foreach ((array) $settings['message_types'] as $message_type => $message_type_settings) { |
| 1154 | 1154 | EE_Register_Message_Type::register($message_type, $message_type_settings); |
| 1155 | 1155 | } |
@@ -1170,70 +1170,70 @@ discard block |
||
| 1170 | 1170 | */ |
| 1171 | 1171 | public static function deregister(string $addon_name = '') |
| 1172 | 1172 | { |
| 1173 | - if (isset(self::$_settings[ $addon_name ]['class_name'])) { |
|
| 1173 | + if (isset(self::$_settings[$addon_name]['class_name'])) { |
|
| 1174 | 1174 | try { |
| 1175 | 1175 | do_action('AHEE__EE_Register_Addon__deregister__before', $addon_name); |
| 1176 | - $class_name = self::$_settings[ $addon_name ]['class_name']; |
|
| 1177 | - if (! empty(self::$_settings[ $addon_name ]['dms_paths'])) { |
|
| 1176 | + $class_name = self::$_settings[$addon_name]['class_name']; |
|
| 1177 | + if ( ! empty(self::$_settings[$addon_name]['dms_paths'])) { |
|
| 1178 | 1178 | // setup DMS |
| 1179 | 1179 | EE_Register_Data_Migration_Scripts::deregister($addon_name); |
| 1180 | 1180 | } |
| 1181 | - if (! empty(self::$_settings[ $addon_name ]['admin_path'])) { |
|
| 1181 | + if ( ! empty(self::$_settings[$addon_name]['admin_path'])) { |
|
| 1182 | 1182 | // register admin page |
| 1183 | 1183 | EE_Register_Admin_Page::deregister($addon_name); |
| 1184 | 1184 | } |
| 1185 | - if (! empty(self::$_settings[ $addon_name ]['module_paths'])) { |
|
| 1185 | + if ( ! empty(self::$_settings[$addon_name]['module_paths'])) { |
|
| 1186 | 1186 | // add to list of modules to be registered |
| 1187 | 1187 | EE_Register_Module::deregister($addon_name); |
| 1188 | 1188 | } |
| 1189 | - if (! empty(self::$_settings[ $addon_name ]['shortcode_paths']) |
|
| 1190 | - || ! empty(self::$_settings[ $addon_name ]['shortcode_fqcns']) |
|
| 1189 | + if ( ! empty(self::$_settings[$addon_name]['shortcode_paths']) |
|
| 1190 | + || ! empty(self::$_settings[$addon_name]['shortcode_fqcns']) |
|
| 1191 | 1191 | ) { |
| 1192 | 1192 | // add to list of shortcodes to be registered |
| 1193 | 1193 | EE_Register_Shortcode::deregister($addon_name); |
| 1194 | 1194 | } |
| 1195 | - if (! empty(self::$_settings[ $addon_name ]['config_class'])) { |
|
| 1195 | + if ( ! empty(self::$_settings[$addon_name]['config_class'])) { |
|
| 1196 | 1196 | // if config_class present let's register config. |
| 1197 | - EE_Register_Config::deregister(self::$_settings[ $addon_name ]['config_class']); |
|
| 1197 | + EE_Register_Config::deregister(self::$_settings[$addon_name]['config_class']); |
|
| 1198 | 1198 | } |
| 1199 | - if (! empty(self::$_settings[ $addon_name ]['widget_paths'])) { |
|
| 1199 | + if ( ! empty(self::$_settings[$addon_name]['widget_paths'])) { |
|
| 1200 | 1200 | // add to list of widgets to be registered |
| 1201 | 1201 | EE_Register_Widget::deregister($addon_name); |
| 1202 | 1202 | } |
| 1203 | - if (! empty(self::$_settings[ $addon_name ]['model_paths']) |
|
| 1204 | - || ! empty(self::$_settings[ $addon_name ]['class_paths']) |
|
| 1203 | + if ( ! empty(self::$_settings[$addon_name]['model_paths']) |
|
| 1204 | + || ! empty(self::$_settings[$addon_name]['class_paths']) |
|
| 1205 | 1205 | ) { |
| 1206 | 1206 | // add to list of shortcodes to be registered |
| 1207 | 1207 | EE_Register_Model::deregister($addon_name); |
| 1208 | 1208 | } |
| 1209 | - if (! empty(self::$_settings[ $addon_name ]['model_extension_paths']) |
|
| 1210 | - || ! empty(self::$_settings[ $addon_name ]['class_extension_paths']) |
|
| 1209 | + if ( ! empty(self::$_settings[$addon_name]['model_extension_paths']) |
|
| 1210 | + || ! empty(self::$_settings[$addon_name]['class_extension_paths']) |
|
| 1211 | 1211 | ) { |
| 1212 | 1212 | // add to list of shortcodes to be registered |
| 1213 | 1213 | EE_Register_Model_Extensions::deregister($addon_name); |
| 1214 | 1214 | } |
| 1215 | - if (! empty(self::$_settings[ $addon_name ]['message_types'])) { |
|
| 1216 | - foreach ((array) self::$_settings[ $addon_name ]['message_types'] as $message_type => $message_type_settings) { |
|
| 1215 | + if ( ! empty(self::$_settings[$addon_name]['message_types'])) { |
|
| 1216 | + foreach ((array) self::$_settings[$addon_name]['message_types'] as $message_type => $message_type_settings) { |
|
| 1217 | 1217 | EE_Register_Message_Type::deregister($message_type); |
| 1218 | 1218 | } |
| 1219 | 1219 | } |
| 1220 | 1220 | // deregister capabilities for addon |
| 1221 | - if (! empty(self::$_settings[ $addon_name ]['capabilities']) |
|
| 1222 | - || ! empty(self::$_settings[ $addon_name ]['capability_maps']) |
|
| 1221 | + if ( ! empty(self::$_settings[$addon_name]['capabilities']) |
|
| 1222 | + || ! empty(self::$_settings[$addon_name]['capability_maps']) |
|
| 1223 | 1223 | ) { |
| 1224 | 1224 | EE_Register_Capabilities::deregister($addon_name); |
| 1225 | 1225 | } |
| 1226 | 1226 | // deregister custom_post_types for addon |
| 1227 | - if (! empty(self::$_settings[ $addon_name ]['custom_post_types'])) { |
|
| 1227 | + if ( ! empty(self::$_settings[$addon_name]['custom_post_types'])) { |
|
| 1228 | 1228 | EE_Register_CPT::deregister($addon_name); |
| 1229 | 1229 | } |
| 1230 | - if (! empty(self::$_settings[ $addon_name ]['payment_method_paths'])) { |
|
| 1230 | + if ( ! empty(self::$_settings[$addon_name]['payment_method_paths'])) { |
|
| 1231 | 1231 | EE_Register_Payment_Method::deregister($addon_name); |
| 1232 | 1232 | } |
| 1233 | 1233 | $addon = EE_Registry::instance()->getAddon($class_name); |
| 1234 | 1234 | if ($addon instanceof EE_Addon) { |
| 1235 | 1235 | remove_action( |
| 1236 | - 'deactivate_' . $addon->get_main_plugin_file_basename(), |
|
| 1236 | + 'deactivate_'.$addon->get_main_plugin_file_basename(), |
|
| 1237 | 1237 | [$addon, 'deactivation'] |
| 1238 | 1238 | ); |
| 1239 | 1239 | remove_action( |
@@ -1256,7 +1256,7 @@ discard block |
||
| 1256 | 1256 | } catch (Exception $e) { |
| 1257 | 1257 | new ExceptionLogger($e); |
| 1258 | 1258 | } |
| 1259 | - unset(self::$_settings[ $addon_name ]); |
|
| 1259 | + unset(self::$_settings[$addon_name]); |
|
| 1260 | 1260 | do_action('AHEE__EE_Register_Addon__deregister__after', $addon_name); |
| 1261 | 1261 | } |
| 1262 | 1262 | } |