PluginProbe
AcyMailing – An Ultimate Newsletter Plugin and Marketing Automation Solution for WordPress / 11.1.1
AcyMailing – An Ultimate Newsletter Plugin and Marketing Automation Solution for WordPress v11.1.1
11.1.1 11.1.0 11.0.5 11.0.4 11.0.3 11.0.2 11.0.1 11.0.0 10.11.1 10.11.0 10.10.2 10.10.1 10.10.0 10.9.1 trunk 10.0.0 10.0.1 10.1.0 10.1.1 10.1.2 10.1.3 10.1.4 10.2.0 10.2.1 10.2.2 All 62 releases
← All changes | back/Helpers/global/addon.php +0 -141 trunk → 11.1.1 View file →
@@ -1,141 +1,0 @@
1 -<?php
2 -defined('ABSPATH') || die('Restricted Access');
3 -
4 -use AcyMailing\Classes\PluginClass;
5 -
6 -global $acymPlugins;
7 -global $acymAddonsForSettings;
8 -
9 -function acym_trigger(string $method, array $args = [], ?string $plugin = null, ?callable $callbackOnePlugin = null): ?array
10 -{
11 - // On WordPress we load the addons before the tables are created on installation
12 - if (!in_array(acym_getPrefix().'acym_configuration', acym_getTableList())) {
13 - return null;
14 - }
15 -
16 - // Handle multilingual
17 - if (in_array($method, ['replaceContent', 'replaceUserInformation']) && !empty($args[0]->language)) {
18 - $previousLanguage = acym_setLanguage($args[0]->language);
19 - acym_loadLanguage($args[0]->language);
20 - }
21 -
22 - global $acymPlugins;
23 - global $acymAddonsForSettings;
24 - if (empty($acymPlugins)) {
25 - acym_loadPlugins();
26 - }
27 -
28 - $result = [];
29 - $listAddons = $acymPlugins;
30 - if ($method === 'onAcymAddSettings') {
31 - $listAddons = $acymAddonsForSettings;
32 - }
33 -
34 - foreach ($listAddons as $class => $onePlugin) {
35 - if (is_callable($callbackOnePlugin)) $callbackOnePlugin($onePlugin);
36 - if (!method_exists($onePlugin, $method)) continue;
37 - if (!empty($plugin) && $class !== $plugin) continue;
38 -
39 - // An add-on failing while it builds its HTML would otherwise leak a half written tag and its own buffers in the page, breaking the whole layout
40 - $bufferLevel = ob_get_level();
41 - $failed = false;
42 - ob_start();
43 - try {
44 - $value = call_user_func_array([$onePlugin, $method], $args);
45 - if (isset($value)) {
46 - $result[] = $value;
47 - }
48 -
49 - if (!empty($onePlugin->errors)) {
50 - $onePlugin->errorCallback();
51 - }
52 - } catch (\Throwable $e) {
53 - $failed = true;
54 - acym_logError('An error occurred when triggering the method '.$method.': '.$e->getMessage());
55 - }
56 -
57 - while (ob_get_level() > $bufferLevel + 1) {
58 - ob_end_clean();
59 - }
60 -
61 - $failed ? ob_end_clean() : ob_end_flush();
62 - }
63 -
64 - if (!empty($previousLanguage)) {
65 - acym_setLanguage($previousLanguage);
66 - acym_loadLanguage($previousLanguage);
67 - }
68 -
69 - return $result;
70 -}
71 -
72 -function acym_checkPluginsVersion(): bool
73 -{
74 - $pluginClass = new PluginClass();
75 - $pluginsInstalled = $pluginClass->getMatchingElements();
76 - $pluginsInstalled = $pluginsInstalled['elements'];
77 -
78 - if (empty($pluginsInstalled)) {
79 - return true;
80 - }
81 -
82 - $response = acym_fileGetContent(ACYM_UPDATEME_API_URL.'public/addons');
83 - $pluginsAvailable = @json_decode($response, true);
84 - if (empty($pluginsAvailable)) {
85 - return true;
86 - }
87 -
88 - foreach ($pluginsInstalled as $key => $pluginInstalled) {
89 - foreach ($pluginsAvailable as $pluginAvailable) {
90 - if ($pluginAvailable['file_name'] === $pluginInstalled->folder_name && !version_compare($pluginInstalled->version, $pluginAvailable['version'], '>=')) {
91 - $pluginInstalled->uptodate = 0;
92 - $pluginInstalled->latest_version = $pluginAvailable['version'];
93 - $pluginClass->save($pluginInstalled);
94 - }
95 - }
96 - }
97 -
98 - return true;
99 -}
100 -
101 -/**
102 - * Displays the option fields of a trigger / filter / condition / action declared by an add-on
103 - */
104 -function acym_displayAddonOption(object $declaration, ?string $fieldName = null): void
105 -{
106 - if (isset($declaration->displayOptions) && is_callable($declaration->displayOptions)) {
107 - ($declaration->displayOptions)($fieldName);
108 -
109 - return;
110 - }
111 -
112 - if (empty($declaration->option)) {
113 - return;
114 - }
115 -
116 - // TODO: remove this on version 12, only there for retro-compat of add-ons/plugins not updated along with AcyMailing
117 - // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- Add-on that still declares its option as a string, escaped on its side. Migrate it to declareTrigger().
118 - echo preg_replace_callback(ACYM_REGEX_SWITCHES, 'acym_prefixSwitchIds', $declaration->option);
119 -}
120 -
121 -function acym_getAddonOption(object $declaration, ?string $fieldName = null): string
122 -{
123 - ob_start();
124 - try {
125 - acym_displayAddonOption($declaration, $fieldName);
126 - } finally {
127 - $html = ob_get_clean();
128 - }
129 -
130 - return $html === false ? '' : $html;
131 -}
132 -
133 -/**
134 - * Makes the ids of a switch unique per row of a filter/condition form.
135 - *
136 - * TODO: remove this on version 12, along with the string options
137 - */
138 -function acym_prefixSwitchIds(array $matches): string
139 -{
140 - return '__numand__'.$matches[1].$matches[2].'__numand__'.$matches[3].'__numand__'.$matches[4].'__numand__'.$matches[5];
141 -}