PluginProbe
WPBot – AI ChatBot for Live Support, Lead Generation, WordPress Automation, AI Services / 5.0.2
WPBot – AI ChatBot for Live Support, Lead Generation, WordPress Automation, AI Services v5.0.2
8.7.7 8.7.6 8.7.5 8.7.4 8.7.3 8.7.2 8.7.1 8.7.0 8.6.9 8.6.8 8.6.7 8.6.6 8.6.5 8.6.4 8.6.2 8.6.1 8.6.0 8.5.9 8.5.8 8.5.7 8.5.6 8.5.5 8.5.4 8.5.3 8.5.2 All 533 releases
chatbot / includes / openai / plugin-upgrader / classes / plugin-upgrader.php

plugin-upgrader.php in WPBot – AI ChatBot for Live Support, Lead Generation, WordPress Automation, AI Services 5.0.2, at includes/openai/plugin-upgrader/classes/plugin-upgrader.php

195 lines 5.2 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 class QCLD_openaiaddon_AutoUpdate
3 {
4 /**
5 * The plugin current version
6 * @var string
7 */
8 private $current_version;
9
10 /**
11 * The plugin remote update path
12 * @var string
13 */
14 private $update_path;
15
16 /**
17 * Plugin Slug (plugin_directory/plugin_file.php)
18 * @var string
19 */
20 private $plugin_slug;
21
22 /**
23 * Plugin name (plugin_file)
24 * @var string
25 */
26 private $slug;
27
28 /**
29 * License User
30 * @var string
31 */
32 private $license_user;
33
34 /**
35 * License Key
36 * @var string
37 */
38 private $license_key;
39
40 /**
41 * Initialize a new instance of the WordPress Auto-Update class
42 * @param string $current_version
43 * @param string $update_path
44 * @param string $plugin_slug
45 */
46 public function __construct( $current_version, $update_path, $plugin_slug, $license_user = '', $license_key = '' )
47 {
48 $qcld_renew_subscription = get_openaiaddon_renew_transient();
49
50 // Set the class public variables
51 $this->current_version = $current_version;
52 $this->update_path = $update_path;
53
54 // Set the License
55 $this->license_user = $license_user;
56 $this->license_key = $license_key;
57
58 // Set the Plugin Slug
59 $this->plugin_slug = $plugin_slug;
60 list ($t1, $t2) = explode( '/', $plugin_slug );
61 $this->slug = $t1;
62
63 // define the alternative API for updating checking
64 add_filter( 'pre_set_site_transient_update_plugins', array( $this, 'check_update' ) );
65
66 // Define the alternative response for information checking
67 add_filter( 'plugins_api', array( $this, 'check_info' ), 10, 3 );
68
69 if( $qcld_renew_subscription ){
70 add_action("after_plugin_row_{$this->plugin_slug}", array($this, 'show_upgrade_subscription_on_plugin_row'), 10, 3 );
71 }
72
73 }
74
75 /**
76 * Add our self-hosted autoupdate plugin to the filter transient
77 *
78 * @param $transient
79 * @return object $ transient
80 */
81 public function check_update( $transient )
82 {
83 if ( empty( $transient->checked ) ) {
84 return $transient;
85 }
86
87
88 // Get the remote version
89 $remote_version = $this->getRemote('info');
90
91
92 // If a newer version is available, add the update
93 if ( version_compare( $this->current_version, $remote_version->new_version, '<' ) ) {
94 if(isset($remote_version->subscription_enable->plugin_name) ){
95 $subscription_enable = $remote_version->subscription_enable->plugin_name;
96 }else{
97 $subscription_enable = '';
98 }
99
100
101
102 if( $this->slug == $subscription_enable ){
103 $obj = new stdClass();
104 $obj->slug = $this->slug;
105 $obj->new_version = $remote_version->new_version;
106 $obj->url = $remote_version->url;
107 $obj->plugin = $this->plugin_slug;
108 $obj->package = $remote_version->package;
109 $obj->tested = $remote_version->tested;
110 $obj->requires = $remote_version->requires;
111 $obj->last_updated = $remote_version->last_updated;
112 $obj->sections = $remote_version->sections;
113
114 setqc_openaiaddon_update_transient($obj);
115 deleteqc_openaiaddon_renew_transient();
116
117 $transient->response[$this->plugin_slug] = $obj;
118 }else{
119 $obj = new stdClass();
120 setqc_openaiaddon_renew_transient($obj);
121 $qcld_renew_subscription = get_openaiaddon_renew_transient();
122 if( $qcld_renew_subscription ){
123 add_action("after_plugin_row_{$this->plugin_slug}", array($this, 'show_upgrade_subscription_on_plugin_row'), 10, 3 );
124 }
125 }
126
127 }
128 return $transient;
129 }
130
131 public function show_upgrade_subscription_on_plugin_row( $plugin_file, $plugin_data, $status ) {
132 $qcld_renew_subscription = get_openaiaddon_renew_transient();
133
134 if( $qcld_renew_subscription ){
135 echo '<tr class="plugin-update-tr">
136 <td colspan="3" class="plugin-update colspanchange">
137 <div class="update-message notice inline notice-warning notice-alt">
138 <p>There is a new version available. <a href="'.esc_url('https://www.ultrawebmedia.com/li/plugins/live-chat-addon/changelog.txt').'" target="_blank">View version details</a>. Automatic update is unavailable for this plugin. To receive automatic updates, valid license is required.</p>
139 </div>
140 </td>
141 </tr>';
142 }
143 }
144
145 /**
146 * Add our self-hosted description to the filter
147 *
148 * @param boolean $false
149 * @param array $action
150 * @param object $arg
151 * @return bool|object
152 */
153 public function check_info($obj, $action, $arg)
154 {
155 if (($action=='query_plugins' || $action=='plugin_information') &&
156 isset($arg->slug) && $arg->slug === $this->slug) {
157 return $this->getRemote('info');
158 }
159
160 return $obj;
161 }
162
163 /**
164 * Return the remote version
165 *
166 * @return string $remote_version
167 */
168 public function getRemote($action = '')
169 {
170 $qcld_update_plugin = get_openaiaddon_update_transient();
171
172
173
174 $params = array(
175 'body' => array(
176 'action' => $action,
177 'plugin-slug' => $this->slug,
178 'license_user' => $this->license_user,
179 'license_key' => $this->license_key,
180 ),
181 );
182
183 // Make the POST request
184 $request = wp_remote_post($this->update_path, $params );
185 // Check if response is valid
186
187 if ( !is_wp_error( $request ) || wp_remote_retrieve_response_code( $request ) === 200 ) {
188
189 return @unserialize( $request['body'] );
190 }
191
192
193 return false;
194 }
195 }