1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
use Automattic\Jetpack\Constants; |
4
|
|
|
|
5
|
|
|
new Jetpack_JSON_API_Plugins_Modify_Endpoint( |
6
|
|
|
array( |
7
|
|
|
'description' => 'Activate/Deactivate a Plugin on your Jetpack Site, or set automatic updates', |
8
|
|
|
'min_version' => '1', |
9
|
|
|
'max_version' => '1.1', |
10
|
|
|
'method' => 'POST', |
11
|
|
|
'path' => '/sites/%s/plugins/%s', |
12
|
|
|
'stat' => 'plugins:1:modify', |
13
|
|
|
'path_labels' => array( |
14
|
|
|
'$site' => '(int|string) The site ID, The site domain', |
15
|
|
|
'$plugin' => '(string) The plugin ID', |
16
|
|
|
), |
17
|
|
|
'allow_jetpack_site_auth' => true, |
18
|
|
|
'request_format' => array( |
19
|
|
|
'action' => '(string) Possible values are \'update\'', |
20
|
|
|
'autoupdate' => '(bool) Whether or not to automatically update the plugin', |
21
|
|
|
'active' => '(bool) Activate or deactivate the plugin', |
22
|
|
|
'network_wide' => '(bool) Do action network wide (default value: false)', |
23
|
|
|
), |
24
|
|
|
'query_parameters' => array( |
25
|
|
|
'autoupdate' => '(bool=false) If the update is happening as a result of autoupdate event', |
26
|
|
|
), |
27
|
|
|
'response_format' => Jetpack_JSON_API_Plugins_Endpoint::$_response_format, |
|
|
|
|
28
|
|
|
'example_request_data' => array( |
29
|
|
|
'headers' => array( |
30
|
|
|
'authorization' => 'Bearer YOUR_API_TOKEN', |
31
|
|
|
), |
32
|
|
|
'body' => array( |
33
|
|
|
'action' => 'update', |
34
|
|
|
), |
35
|
|
|
), |
36
|
|
|
'example_request' => 'https://public-api.wordpress.com/rest/v1/sites/example.wordpress.org/plugins/hello-dolly%20hello', |
37
|
|
|
) |
38
|
|
|
); |
39
|
|
|
|
40
|
|
|
new Jetpack_JSON_API_Plugins_Modify_Endpoint( |
41
|
|
|
array( |
42
|
|
|
'description' => 'Activate/Deactivate a list of plugins on your Jetpack Site, or set automatic updates', |
43
|
|
|
'min_version' => '1', |
44
|
|
|
'max_version' => '1.1', |
45
|
|
|
'method' => 'POST', |
46
|
|
|
'path' => '/sites/%s/plugins', |
47
|
|
|
'stat' => 'plugins:modify', |
48
|
|
|
'path_labels' => array( |
49
|
|
|
'$site' => '(int|string) The site ID, The site domain', |
50
|
|
|
), |
51
|
|
|
'request_format' => array( |
52
|
|
|
'action' => '(string) Possible values are \'update\'', |
53
|
|
|
'autoupdate' => '(bool) Whether or not to automatically update the plugin', |
54
|
|
|
'active' => '(bool) Activate or deactivate the plugin', |
55
|
|
|
'network_wide' => '(bool) Do action network wide (default value: false)', |
56
|
|
|
'plugins' => '(array) A list of plugin ids to modify', |
57
|
|
|
), |
58
|
|
|
'allow_jetpack_site_auth' => true, |
59
|
|
|
'query_parameters' => array( |
60
|
|
|
'autoupdate' => '(bool=false) If the update is happening as a result of autoupdate event', |
61
|
|
|
), |
62
|
|
|
'response_format' => array( |
63
|
|
|
'plugins' => '(array:plugin) An array of plugin objects.', |
64
|
|
|
'updated' => '(array) A list of plugin ids that were updated. Only present if action is update.', |
65
|
|
|
'not_updated' => '(array) A list of plugin ids that were not updated. Only present if action is update.', |
66
|
|
|
'log' => '(array) Update log. Only present if action is update.', |
67
|
|
|
), |
68
|
|
|
'example_request_data' => array( |
69
|
|
|
'headers' => array( |
70
|
|
|
'authorization' => 'Bearer YOUR_API_TOKEN', |
71
|
|
|
), |
72
|
|
|
'body' => array( |
73
|
|
|
'active' => true, |
74
|
|
|
'plugins' => array( |
75
|
|
|
'jetpack/jetpack', |
76
|
|
|
'akismet/akismet', |
77
|
|
|
), |
78
|
|
|
), |
79
|
|
|
), |
80
|
|
|
'example_request' => 'https://public-api.wordpress.com/rest/v1/sites/example.wordpress.org/plugins', |
81
|
|
|
) |
82
|
|
|
); |
83
|
|
|
|
84
|
|
|
new Jetpack_JSON_API_Plugins_Modify_Endpoint( |
85
|
|
|
array( |
86
|
|
|
'description' => 'Update a Plugin on your Jetpack Site', |
87
|
|
|
'min_version' => '1', |
88
|
|
|
'max_version' => '1.1', |
89
|
|
|
'method' => 'POST', |
90
|
|
|
'path' => '/sites/%s/plugins/%s/update/', |
91
|
|
|
'stat' => 'plugins:1:update', |
92
|
|
|
'path_labels' => array( |
93
|
|
|
'$site' => '(int|string) The site ID, The site domain', |
94
|
|
|
'$plugin' => '(string) The plugin ID', |
95
|
|
|
), |
96
|
|
|
'allow_jetpack_site_auth' => true, |
97
|
|
|
'query_parameters' => array( |
98
|
|
|
'autoupdate' => '(bool=false) If the update is happening as a result of autoupdate event', |
99
|
|
|
), |
100
|
|
|
'response_format' => Jetpack_JSON_API_Plugins_Endpoint::$_response_format, |
|
|
|
|
101
|
|
|
'example_request_data' => array( |
102
|
|
|
'headers' => array( |
103
|
|
|
'authorization' => 'Bearer YOUR_API_TOKEN', |
104
|
|
|
), |
105
|
|
|
), |
106
|
|
|
'example_request' => 'https://public-api.wordpress.com/rest/v1/sites/example.wordpress.org/plugins/hello-dolly%20hello/update', |
107
|
|
|
) |
108
|
|
|
); |
109
|
|
|
|
110
|
|
|
class Jetpack_JSON_API_Plugins_Modify_Endpoint extends Jetpack_JSON_API_Plugins_Endpoint { |
111
|
|
|
// POST /sites/%s/plugins/%s |
112
|
|
|
// POST /sites/%s/plugins |
113
|
|
|
protected $slug = null; |
114
|
|
|
protected $needed_capabilities = 'activate_plugins'; |
115
|
|
|
protected $action = 'default_action'; |
116
|
|
|
protected $expected_actions = array( 'update', 'install', 'delete', 'update_translations' ); |
117
|
|
|
|
118
|
|
|
public function callback( $path = '', $blog_id = 0, $object = null ) { |
119
|
|
|
Jetpack_JSON_API_Endpoint::validate_input( $object ); |
120
|
|
|
switch ( $this->action ) { |
121
|
|
|
case 'delete': |
122
|
|
|
$this->needed_capabilities = 'delete_plugins'; |
123
|
|
|
case 'update_translations': |
124
|
|
|
case 'update' : |
125
|
|
|
$this->needed_capabilities = 'update_plugins'; |
126
|
|
|
break; |
127
|
|
|
case 'install' : |
128
|
|
|
$this->needed_capabilities = 'install_plugins'; |
129
|
|
|
break; |
130
|
|
|
} |
131
|
|
|
|
132
|
|
|
if ( isset( $args['autoupdate'] ) || isset( $args['autoupdate_translations'] ) ) { |
|
|
|
|
133
|
|
|
$this->needed_capabilities = 'update_plugins'; |
134
|
|
|
} |
135
|
|
|
|
136
|
|
|
return parent::callback( $path, $blog_id, $object ); |
137
|
|
|
} |
138
|
|
|
|
139
|
|
|
public function default_action() { |
140
|
|
|
$args = $this->input(); |
141
|
|
|
|
142
|
|
View Code Duplication |
if ( isset( $args['autoupdate'] ) && is_bool( $args['autoupdate'] ) ) { |
143
|
|
|
if ( $args['autoupdate'] ) { |
144
|
|
|
$this->autoupdate_on(); |
145
|
|
|
} else { |
146
|
|
|
$this->autoupdate_off(); |
147
|
|
|
} |
148
|
|
|
} |
149
|
|
|
|
150
|
|
|
if ( isset( $args['active'] ) && is_bool( $args['active'] ) ) { |
151
|
|
|
if ( $args['active'] ) { |
152
|
|
|
// We don't have to check for activate_plugins permissions since we assume that the user has those |
153
|
|
|
// Since we set them via $needed_capabilities. |
154
|
|
|
return $this->activate(); |
155
|
|
|
} else { |
156
|
|
|
if ( $this->current_user_can( 'deactivate_plugins' ) ) { |
157
|
|
|
return $this->deactivate(); |
158
|
|
|
} else { |
159
|
|
|
return new WP_Error( 'unauthorized_error', __( 'Plugin deactivation is not allowed', 'jetpack' ), '403' ); |
|
|
|
|
160
|
|
|
} |
161
|
|
|
} |
162
|
|
|
} |
163
|
|
|
|
164
|
|
View Code Duplication |
if ( isset( $args['autoupdate_translations'] ) && is_bool( $args['autoupdate_translations'] ) ) { |
165
|
|
|
if ( $args['autoupdate_translations'] ) { |
166
|
|
|
$this->autoupdate_translations_on(); |
167
|
|
|
} else { |
168
|
|
|
$this->autoupdate_translations_off(); |
169
|
|
|
} |
170
|
|
|
} |
171
|
|
|
|
172
|
|
|
return true; |
173
|
|
|
} |
174
|
|
|
|
175
|
|
|
protected function autoupdate_on() { |
176
|
|
|
$autoupdate_plugins = (array) get_site_option( 'auto_update_plugins', array() ); |
177
|
|
|
$autoupdate_plugins = array_unique( array_merge( $autoupdate_plugins, $this->plugins ) ); |
178
|
|
|
update_site_option( 'auto_update_plugins', $autoupdate_plugins ); |
179
|
|
|
} |
180
|
|
|
|
181
|
|
|
protected function autoupdate_off() { |
182
|
|
|
$autoupdate_plugins = (array) get_site_option( 'auto_update_plugins', array() ); |
183
|
|
|
$autoupdate_plugins = array_diff( $autoupdate_plugins, $this->plugins ); |
184
|
|
|
update_site_option( 'auto_update_plugins', $autoupdate_plugins ); |
185
|
|
|
} |
186
|
|
|
|
187
|
|
|
protected function autoupdate_translations_on() { |
188
|
|
|
$autoupdate_plugins = Jetpack_Options::get_option( 'autoupdate_plugins_translations', array() ); |
189
|
|
|
$autoupdate_plugins = array_unique( array_merge( $autoupdate_plugins, $this->plugins ) ); |
190
|
|
|
Jetpack_Options::update_option( 'autoupdate_plugins_translations', $autoupdate_plugins ); |
191
|
|
|
} |
192
|
|
|
|
193
|
|
|
protected function autoupdate_translations_off() { |
194
|
|
|
$autoupdate_plugins = Jetpack_Options::get_option( 'autoupdate_plugins_translations', array() ); |
195
|
|
|
$autoupdate_plugins = array_diff( $autoupdate_plugins, $this->plugins ); |
196
|
|
|
Jetpack_Options::update_option( 'autoupdate_plugins_translations', $autoupdate_plugins ); |
197
|
|
|
} |
198
|
|
|
|
199
|
|
|
protected function activate() { |
200
|
|
|
$permission_error = false; |
201
|
|
|
foreach ( $this->plugins as $plugin ) { |
202
|
|
|
|
203
|
|
|
if ( ! $this->current_user_can( 'activate_plugin', $plugin ) ) { |
204
|
|
|
$this->log[$plugin]['error'] = __( 'Sorry, you are not allowed to activate this plugin.' ); |
205
|
|
|
$has_errors = true; |
206
|
|
|
$permission_error = true; |
207
|
|
|
continue; |
208
|
|
|
} |
209
|
|
|
|
210
|
|
View Code Duplication |
if ( ( ! $this->network_wide && Jetpack::is_plugin_active( $plugin ) ) || is_plugin_active_for_network( $plugin ) ) { |
211
|
|
|
$this->log[$plugin]['error'] = __( 'The Plugin is already active.', 'jetpack' ); |
212
|
|
|
$has_errors = true; |
213
|
|
|
continue; |
214
|
|
|
} |
215
|
|
|
|
216
|
|
View Code Duplication |
if ( ! $this->network_wide && is_network_only_plugin( $plugin ) && is_multisite() ) { |
217
|
|
|
$this->log[$plugin]['error'] = __( 'Plugin can only be Network Activated', 'jetpack' ); |
218
|
|
|
$has_errors = true; |
219
|
|
|
continue; |
220
|
|
|
} |
221
|
|
|
|
222
|
|
|
$result = activate_plugin( $plugin, '', $this->network_wide ); |
223
|
|
|
|
224
|
|
View Code Duplication |
if ( is_wp_error( $result ) ) { |
225
|
|
|
$this->log[$plugin]['error'] = $result->get_error_messages(); |
226
|
|
|
$has_errors = true; |
227
|
|
|
continue; |
228
|
|
|
} |
229
|
|
|
|
230
|
|
|
$success = Jetpack::is_plugin_active( $plugin ); |
231
|
|
|
if ( $success && $this->network_wide ) { |
232
|
|
|
$success &= is_plugin_active_for_network( $plugin ); |
233
|
|
|
} |
234
|
|
|
|
235
|
|
View Code Duplication |
if ( ! $success ) { |
236
|
|
|
$this->log[$plugin]['error'] = $result->get_error_messages; |
237
|
|
|
$has_errors = true; |
238
|
|
|
continue; |
239
|
|
|
} |
240
|
|
|
$this->log[$plugin][] = __( 'Plugin activated.', 'jetpack' ); |
241
|
|
|
} |
242
|
|
|
|
243
|
|
View Code Duplication |
if ( ! $this->bulk && isset( $has_errors ) ) { |
244
|
|
|
$plugin = $this->plugins[0]; |
245
|
|
|
if ( $permission_error ) { |
246
|
|
|
return new WP_Error( 'unauthorized_error', $this->log[$plugin]['error'], 403 ); |
|
|
|
|
247
|
|
|
} |
248
|
|
|
|
249
|
|
|
return new WP_Error( 'activation_error', $this->log[$plugin]['error'] ); |
|
|
|
|
250
|
|
|
} |
251
|
|
|
} |
252
|
|
|
|
253
|
|
|
protected function current_user_can( $capability, $plugin = null ) { |
254
|
|
|
// If this endpoint accepts site based authentication and a blog token is used, skip capabilities check. |
255
|
|
|
if ( $this->accepts_site_based_authentication() ) { |
256
|
|
|
return true; |
257
|
|
|
} |
258
|
|
|
if ( $plugin ) { |
259
|
|
|
return current_user_can( $capability, $plugin ); |
260
|
|
|
} |
261
|
|
|
|
262
|
|
|
return current_user_can( $capability ); |
263
|
|
|
} |
264
|
|
|
|
265
|
|
|
protected function deactivate() { |
266
|
|
|
$permission_error = false; |
267
|
|
|
foreach ( $this->plugins as $plugin ) { |
268
|
|
|
if ( ! $this->current_user_can( 'deactivate_plugin', $plugin ) ) { |
269
|
|
|
$error = $this->log[$plugin]['error'] = __( 'Sorry, you are not allowed to deactivate this plugin.', 'jetpack' ); |
270
|
|
|
$permission_error = true; |
271
|
|
|
continue; |
272
|
|
|
} |
273
|
|
|
|
274
|
|
View Code Duplication |
if ( ! Jetpack::is_plugin_active( $plugin ) ) { |
275
|
|
|
$error = $this->log[$plugin]['error'] = __( 'The Plugin is already deactivated.', 'jetpack' ); |
276
|
|
|
continue; |
277
|
|
|
} |
278
|
|
|
|
279
|
|
|
deactivate_plugins( $plugin, false, $this->network_wide ); |
280
|
|
|
|
281
|
|
|
$success = ! Jetpack::is_plugin_active( $plugin ); |
282
|
|
|
if ( $success && $this->network_wide ) { |
283
|
|
|
$success &= ! is_plugin_active_for_network( $plugin ); |
284
|
|
|
} |
285
|
|
|
|
286
|
|
View Code Duplication |
if ( ! $success ) { |
287
|
|
|
$error = $this->log[$plugin]['error'] = __( 'There was an error deactivating your plugin', 'jetpack' ); |
288
|
|
|
continue; |
289
|
|
|
} |
290
|
|
|
$this->log[$plugin][] = __( 'Plugin deactivated.', 'jetpack' ); |
291
|
|
|
} |
292
|
|
View Code Duplication |
if ( ! $this->bulk && isset( $error ) ) { |
293
|
|
|
if ( $permission_error ) { |
294
|
|
|
return new WP_Error( 'unauthorized_error', $error, 403 ); |
|
|
|
|
295
|
|
|
} |
296
|
|
|
|
297
|
|
|
return new WP_Error( 'deactivation_error', $error ); |
|
|
|
|
298
|
|
|
} |
299
|
|
|
} |
300
|
|
|
|
301
|
|
|
protected function update() { |
302
|
|
|
|
303
|
|
|
$query_args = $this->query_args(); |
304
|
|
|
if ( isset( $query_args['autoupdate'] ) && $query_args['autoupdate'] ) { |
305
|
|
|
Constants::set_constant( 'JETPACK_PLUGIN_AUTOUPDATE', true ); |
|
|
|
|
306
|
|
|
} |
307
|
|
|
wp_clean_plugins_cache(); |
308
|
|
|
ob_start(); |
309
|
|
|
wp_update_plugins(); // Check for Plugin updates |
310
|
|
|
ob_end_clean(); |
311
|
|
|
|
312
|
|
|
$update_plugins = get_site_transient( 'update_plugins' ); |
313
|
|
|
|
314
|
|
|
if ( isset( $update_plugins->response ) ) { |
315
|
|
|
$plugin_updates_needed = array_keys( $update_plugins->response ); |
316
|
|
|
} else { |
317
|
|
|
$plugin_updates_needed = array(); |
318
|
|
|
} |
319
|
|
|
|
320
|
|
|
$update_attempted = false; |
321
|
|
|
|
322
|
|
|
include_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php'; |
323
|
|
|
|
324
|
|
|
// unhook this functions that output things before we send our response header. |
325
|
|
|
remove_action( 'upgrader_process_complete', array( 'Language_Pack_Upgrader', 'async_upgrade' ), 20 ); |
326
|
|
|
remove_action( 'upgrader_process_complete', 'wp_version_check' ); |
327
|
|
|
remove_action( 'upgrader_process_complete', 'wp_update_themes' ); |
328
|
|
|
|
329
|
|
|
// Early return if unable to obtain auto_updater lock. |
330
|
|
|
// @see https://github.com/WordPress/wordpress-develop/blob/66469efa99e7978c8824e287834135aa9842e84f/src/wp-admin/includes/class-wp-automatic-updater.php#L453. |
331
|
|
|
if ( ! WP_Upgrader::create_lock( 'auto_updater' ) ) { |
332
|
|
|
return new WP_Error( 'update_fail', __( 'Updates are already in progress.', 'jetpack' ), 400 ); |
|
|
|
|
333
|
|
|
} |
334
|
|
|
|
335
|
|
|
$result = false; |
336
|
|
|
|
337
|
|
|
foreach ( $this->plugins as $plugin ) { |
338
|
|
|
|
339
|
|
|
if ( ! in_array( $plugin, $plugin_updates_needed ) ) { |
340
|
|
|
$this->log[$plugin][] = __( 'No update needed', 'jetpack' ); |
341
|
|
|
continue; |
342
|
|
|
} |
343
|
|
|
|
344
|
|
|
// Rely on WP_Automatic_Updater class to check if a plugin item should be updated if it is a Jetpack autoupdate request. |
345
|
|
|
if ( Constants::get_constant( 'JETPACK_PLUGIN_AUTOUPDATE' ) && ! ( new WP_Automatic_Updater() )->should_update( 'plugin', $update_plugins->response[ $plugin ], WP_PLUGIN_DIR ) ) { |
346
|
|
|
continue; |
347
|
|
|
} |
348
|
|
|
|
349
|
|
|
// Establish per plugin lock. |
350
|
|
|
$plugin_slug = Jetpack_Autoupdate::get_plugin_slug( $plugin ); |
351
|
|
|
if ( ! WP_Upgrader::create_lock( 'jetpack_' . $plugin_slug ) ) { |
352
|
|
|
continue; |
353
|
|
|
} |
354
|
|
|
|
355
|
|
|
/** |
356
|
|
|
* Pre-upgrade action |
357
|
|
|
* |
358
|
|
|
* @since 3.9.3 |
359
|
|
|
* |
360
|
|
|
* @param array $plugin Plugin data |
361
|
|
|
* @param array $plugin Array of plugin objects |
362
|
|
|
* @param bool $updated_attempted false for the first update, true subsequently |
363
|
|
|
*/ |
364
|
|
|
do_action( 'jetpack_pre_plugin_upgrade', $plugin, $this->plugins, $update_attempted ); |
365
|
|
|
|
366
|
|
|
$update_attempted = true; |
367
|
|
|
|
368
|
|
|
// Object created inside the for loop to clean the messages for each plugin |
369
|
|
|
$skin = new WP_Ajax_Upgrader_Skin(); |
370
|
|
|
// The Automatic_Upgrader_Skin skin shouldn't output anything. |
371
|
|
|
$upgrader = new Plugin_Upgrader( $skin ); |
372
|
|
|
$upgrader->init(); |
373
|
|
|
// This avoids the plugin to be deactivated. |
374
|
|
|
// Using bulk upgrade puts the site into maintenance mode during the upgrades |
375
|
|
|
$result = $upgrader->bulk_upgrade( array( $plugin ) ); |
376
|
|
|
$errors = $upgrader->skin->get_errors(); |
377
|
|
|
$this->log[$plugin] = $upgrader->skin->get_upgrade_messages(); |
378
|
|
|
|
379
|
|
|
// release individual plugin lock. |
380
|
|
|
WP_Upgrader::release_lock( 'jetpack_' . $plugin_slug ); |
381
|
|
|
|
382
|
|
|
if ( is_wp_error( $errors ) && $errors->get_error_code() ) { |
383
|
|
|
return $errors; |
384
|
|
|
} |
385
|
|
|
} |
386
|
|
|
|
387
|
|
|
// release auto_udpate lock. |
388
|
|
|
WP_Upgrader::release_lock( 'auto_updater' ); |
389
|
|
|
|
390
|
|
View Code Duplication |
if ( ! $this->bulk && ! $result && $update_attempted ) { |
391
|
|
|
return new WP_Error( 'update_fail', __( 'There was an error updating your plugin', 'jetpack' ), 400 ); |
|
|
|
|
392
|
|
|
} |
393
|
|
|
|
394
|
|
|
return $this->default_action(); |
395
|
|
|
} |
396
|
|
|
|
397
|
|
|
function update_translations() { |
398
|
|
|
include_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php'; |
399
|
|
|
|
400
|
|
|
// Clear the cache. |
401
|
|
|
wp_clean_plugins_cache(); |
402
|
|
|
ob_start(); |
403
|
|
|
wp_update_plugins(); // Check for Plugin updates |
404
|
|
|
ob_end_clean(); |
405
|
|
|
|
406
|
|
|
$available_updates = get_site_transient( 'update_plugins' ); |
407
|
|
|
if ( ! isset( $available_updates->translations ) || empty( $available_updates->translations ) ) { |
408
|
|
|
return new WP_Error( 'nothing_to_translate' ); |
|
|
|
|
409
|
|
|
} |
410
|
|
|
|
411
|
|
|
$update_attempted = false; |
412
|
|
|
$result = false; |
413
|
|
|
foreach ( $this->plugins as $plugin ) { |
414
|
|
|
$this->slug = Jetpack_Autoupdate::get_plugin_slug( $plugin ); |
415
|
|
|
$translation = array_filter( $available_updates->translations, array( $this, 'get_translation' ) ); |
416
|
|
|
|
417
|
|
|
if ( empty( $translation ) ) { |
418
|
|
|
$this->log[$plugin][] = __( 'No update needed', 'jetpack' ); |
419
|
|
|
continue; |
420
|
|
|
} |
421
|
|
|
|
422
|
|
|
/** |
423
|
|
|
* Pre-upgrade action |
424
|
|
|
* |
425
|
|
|
* @since 4.4.0 |
426
|
|
|
* |
427
|
|
|
* @param array $plugin Plugin data |
428
|
|
|
* @param array $plugin Array of plugin objects |
429
|
|
|
* @param bool $update_attempted false for the first update, true subsequently |
430
|
|
|
*/ |
431
|
|
|
do_action( 'jetpack_pre_plugin_upgrade_translations', $plugin, $this->plugins, $update_attempted ); |
432
|
|
|
|
433
|
|
|
$update_attempted = true; |
434
|
|
|
|
435
|
|
|
$skin = new Automatic_Upgrader_Skin(); |
436
|
|
|
$upgrader = new Language_Pack_Upgrader( $skin ); |
437
|
|
|
$upgrader->init(); |
438
|
|
|
|
439
|
|
|
$result = $upgrader->upgrade( (object) $translation[0] ); |
440
|
|
|
|
441
|
|
|
$this->log[$plugin] = $upgrader->skin->get_upgrade_messages(); |
442
|
|
|
} |
443
|
|
|
|
444
|
|
View Code Duplication |
if ( ! $this->bulk && ! $result ) { |
445
|
|
|
return new WP_Error( 'update_fail', __( 'There was an error updating your plugin', 'jetpack' ), 400 ); |
|
|
|
|
446
|
|
|
} |
447
|
|
|
|
448
|
|
|
return true; |
449
|
|
|
} |
450
|
|
|
|
451
|
|
|
protected function get_translation( $translation ) { |
452
|
|
|
return ( $translation['slug'] === $this->slug ); |
453
|
|
|
} |
454
|
|
|
} |
455
|
|
|
|
This check looks for access to properties that are not accessible from the current context.
If you need to make a property accessible to another context you can either raise its visibility level or provide an accessible getter in the defining class.