PluginProbe
AcyMailing – An Ultimate Newsletter Plugin and Marketing Automation Solution for WordPress / 11.0.4
AcyMailing – An Ultimate Newsletter Plugin and Marketing Automation Solution for WordPress v11.0.4
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
acymailing / back / Helpers / global / addon.php

addon.php in AcyMailing – An Ultimate Newsletter Plugin and Marketing Automation Solution for WordPress 11.0.4, at back/Helpers/global/addon.php

90 lines 2.8 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
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 // There may be an error here, but I don't know how to handle it. At least don't block the execution
40 try {
41 $value = call_user_func_array([$onePlugin, $method], $args);
42 if (isset($value)) {
43 $result[] = $value;
44 }
45
46 if (!empty($onePlugin->errors)) {
47 $onePlugin->errorCallback();
48 }
49 } catch (\Throwable $e) {
50 acym_logError('An error occurred when triggering the method '.$method.': '.$e->getMessage());
51 }
52 }
53
54 if (!empty($previousLanguage)) {
55 acym_setLanguage($previousLanguage);
56 acym_loadLanguage($previousLanguage);
57 }
58
59 return $result;
60 }
61
62 function acym_checkPluginsVersion(): bool
63 {
64 $pluginClass = new PluginClass();
65 $pluginsInstalled = $pluginClass->getMatchingElements();
66 $pluginsInstalled = $pluginsInstalled['elements'];
67
68 if (empty($pluginsInstalled)) {
69 return true;
70 }
71
72 $response = acym_fileGetContent(ACYM_UPDATEME_API_URL.'public/addons');
73 $pluginsAvailable = @json_decode($response, true);
74 if (empty($pluginsAvailable)) {
75 return true;
76 }
77
78 foreach ($pluginsInstalled as $key => $pluginInstalled) {
79 foreach ($pluginsAvailable as $pluginAvailable) {
80 if ($pluginAvailable['file_name'] === $pluginInstalled->folder_name && !version_compare($pluginInstalled->version, $pluginAvailable['version'], '>=')) {
81 $pluginInstalled->uptodate = 0;
82 $pluginInstalled->latest_version = $pluginAvailable['version'];
83 $pluginClass->save($pluginInstalled);
84 }
85 }
86 }
87
88 return true;
89 }
90