| @@ -1,5 +1,6 @@ | ||
| 1 | 1 | <?php |
| 2 | +defined('ABSPATH') || die('Restricted Access'); | |
| 2 | 3 | |
| 3 | 4 | use AcyMailing\Classes\PluginClass; |
| 4 | 5 | |
| 5 | 6 | global $acymPlugins; |
| @@ -6,12 +7,14 @@ | ||
| 6 | 7 | global $acymAddonsForSettings; |
| 7 | 8 | |
| 8 | 9 | function acym_trigger(string $method, array $args = [], ?string $plugin = null, ?callable $callbackOnePlugin = null): ?array |
| 9 | 10 | { |
| 11 | + // On WordPress we load the addons before the tables are created on installation | |
| 10 | 12 | if (!in_array(acym_getPrefix().'acym_configuration', acym_getTableList())) { |
| 11 | 13 | return null; |
| 12 | 14 | } |
| 13 | 15 | |
| 16 | + // Handle multilingual | |
| 14 | 17 | if (in_array($method, ['replaceContent', 'replaceUserInformation']) && !empty($args[0]->language)) { |
| 15 | 18 | $previousLanguage = acym_setLanguage($args[0]->language); |
| 16 | 19 | acym_loadLanguage($args[0]->language); |
| 17 | 20 | } |
| @@ -32,8 +35,9 @@ | ||
| 32 | 35 | if (is_callable($callbackOnePlugin)) $callbackOnePlugin($onePlugin); |
| 33 | 36 | if (!method_exists($onePlugin, $method)) continue; |
| 34 | 37 | if (!empty($plugin) && $class !== $plugin) continue; |
| 35 | 38 | |
| 39 | + // There may be an error here, but I don't know how to handle it. At least don't block the execution | |
| 36 | 40 | try { |
| 37 | 41 | $value = call_user_func_array([$onePlugin, $method], $args); |
| 38 | 42 | if (isset($value)) { |
| 39 | 43 | $result[] = $value; |
| @@ -81,5 +85,47 @@ | ||
| 81 | 85 | } |
| 82 | 86 | } |
| 83 | 87 | |
| 84 | 88 | return true; |
| 89 | +} | |
| 90 | + | |
| 91 | +/** | |
| 92 | + * Displays the option fields of a trigger / filter / condition / action declared by an add-on | |
| 93 | + */ | |
| 94 | +function acym_displayAddonOption(object $declaration, ?string $fieldName = null): void | |
| 95 | +{ | |
| 96 | + if (isset($declaration->displayOptions) && is_callable($declaration->displayOptions)) { | |
| 97 | + ($declaration->displayOptions)($fieldName); | |
| 98 | + | |
| 99 | + return; | |
| 100 | + } | |
| 101 | + | |
| 102 | + if (empty($declaration->option)) { | |
| 103 | + return; | |
| 104 | + } | |
| 105 | + | |
| 106 | + // TODO: remove this on version 12, only there for retro-compat of add-ons/plugins not updated along with AcyMailing | |
| 107 | + // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- Add-on that still declares its option as a string, escaped on its side. Migrate it to declareTrigger(). | |
| 108 | + echo preg_replace_callback(ACYM_REGEX_SWITCHES, 'acym_prefixSwitchIds', $declaration->option); | |
| 109 | +} | |
| 110 | + | |
| 111 | +function acym_getAddonOption(object $declaration, ?string $fieldName = null): string | |
| 112 | +{ | |
| 113 | + ob_start(); | |
| 114 | + try { | |
| 115 | + acym_displayAddonOption($declaration, $fieldName); | |
| 116 | + } finally { | |
| 117 | + $html = ob_get_clean(); | |
| 118 | + } | |
| 119 | + | |
| 120 | + return $html === false ? '' : $html; | |
| 121 | +} | |
| 122 | + | |
| 123 | +/** | |
| 124 | + * Makes the ids of a switch unique per row of a filter/condition form. | |
| 125 | + * | |
| 126 | + * TODO: remove this on version 12, along with the string options | |
| 127 | + */ | |
| 128 | +function acym_prefixSwitchIds(array $matches): string | |
| 129 | +{ | |
| 130 | + return '__numand__'.$matches[1].$matches[2].'__numand__'.$matches[3].'__numand__'.$matches[4].'__numand__'.$matches[5]; | |
| 85 | 131 | } |