| @@ -86,4 +86,46 @@ | ||
| 86 | 86 | } |
| 87 | 87 | |
| 88 | 88 | return true; |
| 89 | 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]; | |
| 131 | +} | |