PluginProbe
Listdom: AI-powered Business Directory with Classifieds Ads Listings / trunk
Listdom: AI-powered Business Directory with Classifieds Ads Listings vtrunk
6.0.0 5.9.0 5.8.1 5.8.0 5.7.0 5.6.0 trunk 1.0.0 1.0.1 1.0.2 1.1.0 1.1.1 1.2.0 1.2.1 1.3.0 1.3.1 1.4.0 1.5.0 1.6.0 1.6.1 1.6.2 1.6.3 1.7.0 1.8.0 1.9.0 All 75 releases
listdom / app / includes / plugin / update.php

update.php in Listdom: AI-powered Business Directory with Classifieds Ads Listings trunk, at app/includes/plugin/update.php

117 lines 3.9 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 use Webilia\WP\Plugin\Update;
4
5 class LSD_Plugin_Update
6 {
7 /**
8 * @var string
9 */
10 private $basename;
11
12 /**
13 * @var string
14 */
15 private $prefix;
16
17 /**
18 * @var bool
19 */
20 private $license_gate;
21
22 /**
23 * Initialize a new instance of the WordPress Auto-Update class
24 *
25 * @param array $args
26 */
27 function __construct(array $args = [])
28 {
29 $this->basename = $args['basename'];
30 $this->prefix = $args['prefix'] ?? '';
31 $this->license_gate = $args['license_gate'] ?? true;
32
33 // Webilia Update Server
34 new Update(
35 $args['version'],
36 $this->basename,
37 null,
38 LSD_VERSION,
39 $args['server'] ?? 'https://api.webilia.com/update'
40 );
41
42 // Connect registers after legacy metadata and only overrides its
43 // package when the configured update capability is authorized.
44 LSD_Webilia_Connect::updateClient($this->basename, $args['version']);
45
46 if ($this->license_gate)
47 {
48 add_filter('upgrader_pre_download', [$this, 'block'], 10, 4);
49 add_action('in_plugin_update_message-' . $this->basename, [$this, 'message'], 10, 2);
50 }
51 }
52
53 public function block($reply, $package, $upgrader, $hook_extra = [])
54 {
55 if (!$this->license_gate) return $reply;
56 if (!$this->basename || !$this->prefix) return $reply;
57 if (!isset($upgrader->skin) || !is_object($upgrader->skin)) return $reply;
58
59 if (is_array($hook_extra) && isset($hook_extra['plugin']) && $hook_extra['plugin'] === $this->basename)
60 {
61 if (!LSD_Licensing::isUpdateAllowed($this->basename, $this->prefix))
62 {
63 $renew_link = sprintf(
64 '<a href="%s" target="_blank">%s</a>',
65 esc_url(LSD_Base::getWebiliaShopURL()),
66 esc_html__('renew', 'listdom')
67 );
68
69 return new WP_Error(
70 'lsd_license_required',
71 sprintf(
72 esc_html__(
73 'An error occurred while updating this add-on: please %1$s or %2$s your license to receive updates.',
74 'listdom'
75 ),
76 '<a href="' . admin_url('admin.php?page=listdom-connect&tab=licenses') . '" target="_parent">' . esc_html__('activate', 'listdom') . '</a>',
77 wp_kses($renew_link, ['a' => ['href' => [], 'target' => []]])
78 )
79 );
80 }
81 }
82
83 return $reply;
84 }
85
86 public function message($plugin_data, $response): void
87 {
88 if (!$this->license_gate) return;
89 if (!$this->basename || !$this->prefix || !is_array($plugin_data)) return;
90
91 if (LSD_Licensing::isUpdateAllowed($this->basename, $this->prefix)) return;
92
93 $version = $response->new_version ?? '';
94 $renew_link = sprintf(
95 '<a href="%s" target="_blank">%s</a>',
96 esc_url(LSD_Base::getWebiliaShopURL()),
97 esc_html__('renew', 'listdom')
98 );
99
100 $message = $version
101 ? sprintf(
102 /* translators: 1: plugin name, 2: version number, 3: renew link. */
103 esc_html__('%1$s %2$s is available. Please %3$s or %4$s your license to receive this update.', 'listdom'),
104 esc_html($plugin_data['Name'] ?? esc_html__('This add-on', 'listdom')),
105 esc_html($version),
106 '<a href="' . admin_url('admin.php?page=listdom-connect&tab=licenses') . '" target="_parent">' . esc_html__('activate', 'listdom') . '</a>',
107 wp_kses($renew_link, ['a' => ['href' => [], 'target' => []]])
108 )
109 : esc_html__('A new version is available. You need an active license to update this add-on.', 'listdom');
110
111 printf(
112 '<br>%s',
113 $message
114 );
115 }
116 }
117