PluginProbe
Jetpack – WP Security, Backup, Speed, & Growth / 16.3-a.7
Jetpack – WP Security, Backup, Speed, & Growth v16.3-a.7
16.3-a.5 16.3-a.7 16.3-a.3 16.3-a.1 16.2 16.2-beta 12.0.3 12.1.3 12.2.3 12.3.2 12.4.2 12.5.2 12.6.4 12.7.3 12.8.3 12.9.5 13.0.2 13.1.5 13.2.4 13.3.3 13.4.5 13.5.2 13.6.2 13.7.2 13.8.3 All 506 releases
← All changes | json-endpoints/jetpack/class.jetpack-json-api-plugins-modify-endpoint.php +28 -13 13.0.2 → 16.3-a.7 View file →
@@ -1,8 +1,12 @@
1 1 <?php // phpcs:ignore WordPress.Files.FileName.InvalidClassFileName
2 2
3 3 use Automattic\Jetpack\Constants;
4 4
5 +if ( ! defined( 'ABSPATH' ) ) {
6 + exit( 0 );
7 +}
8 +
5 9 new Jetpack_JSON_API_Plugins_Modify_Endpoint(
6 10 array(
7 11 'description' => 'Activate/Deactivate a Plugin on your Jetpack Site, or set automatic updates',
8 12 'min_version' => '1',
@@ -15,12 +19,13 @@
15 19 '$plugin' => '(string) The plugin ID',
16 20 ),
17 21 'allow_jetpack_site_auth' => true,
18 22 '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 + 'action' => '(string) Possible values are \'update\'',
24 + 'autoupdate' => '(bool) Whether or not to automatically update the plugin',
25 + 'active' => '(bool) Activate or deactivate the plugin',
26 + 'network_wide' => '(bool) Do action network wide (default value: false)',
27 + 'scheduled_update' => '(bool) If the update is happening as a result of a scheduled update event',
23 28 ),
24 29 'query_parameters' => array(
25 30 'autoupdate' => '(bool=false) If the update is happening as a result of autoupdate event',
26 31 ),
@@ -111,8 +116,10 @@
111 116 * Plugins modify endpoint class.
112 117 *
113 118 * POST /sites/%s/plugins/%s
114 119 * POST /sites/%s/plugins
120 + *
121 + * @phan-constructor-used-for-side-effects
115 122 */
116 123 class Jetpack_JSON_API_Plugins_Modify_Endpoint extends Jetpack_JSON_API_Plugins_Endpoint {
117 124
118 125 /**
@@ -380,13 +387,18 @@
380 387 *
381 388 * @return bool|WP_Error
382 389 */
383 390 protected function update() {
391 + $query_args = $this->query_args();
384 392
385 - $query_args = $this->query_args();
386 - if ( isset( $query_args['autoupdate'] ) && $query_args['autoupdate'] ) {
387 - Constants::set_constant( 'JETPACK_PLUGIN_AUTOUPDATE', true );
393 + $is_automatic_update = false;
394 + if ( isset( $query_args['autoupdate'] ) && $query_args['autoupdate'] || $this->scheduled_update ) {
395 + $is_automatic_update = true;
388 396 }
397 +
398 + if ( $this->scheduled_update ) {
399 + Constants::set_constant( 'SCHEDULED_AUTOUPDATE', true );
400 + }
389 401 wp_clean_plugins_cache( false );
390 402 ob_start();
391 403 wp_update_plugins(); // Check for Plugin updates
392 404 ob_end_clean();
@@ -407,11 +419,14 @@
407 419 remove_action( 'upgrader_process_complete', array( 'Language_Pack_Upgrader', 'async_upgrade' ), 20 );
408 420 remove_action( 'upgrader_process_complete', 'wp_version_check' );
409 421 remove_action( 'upgrader_process_complete', 'wp_update_themes' );
410 422
423 + // Set the lock timeout to 15 minutes if it's scheduled update, otherwise default to one hour.
424 + $lock_release_timeout = $this->scheduled_update ? 15 * MINUTE_IN_SECONDS : null;
425 +
411 426 // Early return if unable to obtain auto_updater lock.
412 427 // @see https://github.com/WordPress/wordpress-develop/blob/66469efa99e7978c8824e287834135aa9842e84f/src/wp-admin/includes/class-wp-automatic-updater.php#L453.
413 - if ( Constants::get_constant( 'JETPACK_PLUGIN_AUTOUPDATE' ) && ! WP_Upgrader::create_lock( 'auto_updater' ) ) {
428 + if ( $is_automatic_update && ! WP_Upgrader::create_lock( 'auto_updater', $lock_release_timeout ) ) {
414 429 return new WP_Error( 'update_fail', __( 'Updates are already in progress.', 'jetpack' ), 400 );
415 430 }
416 431
417 432 $result = false;
@@ -423,15 +438,15 @@
423 438 continue;
424 439 }
425 440
426 441 // Rely on WP_Automatic_Updater class to check if a plugin item should be updated if it is a Jetpack autoupdate request.
427 - if ( Constants::get_constant( 'JETPACK_PLUGIN_AUTOUPDATE' ) && ! ( new WP_Automatic_Updater() )->should_update( 'plugin', $update_plugins->response[ $plugin ], WP_PLUGIN_DIR ) ) {
442 + if ( $is_automatic_update && ! ( new WP_Automatic_Updater() )->should_update( 'plugin', $update_plugins->response[ $plugin ], WP_PLUGIN_DIR ) ) {
428 443 continue;
429 444 }
430 445
431 446 // Establish per plugin lock.
432 447 $plugin_slug = Jetpack_Autoupdate::get_plugin_slug( $plugin );
433 - if ( ! WP_Upgrader::create_lock( 'jetpack_' . $plugin_slug ) ) {
448 + if ( ! WP_Upgrader::create_lock( 'jetpack_' . $plugin_slug, $lock_release_timeout ) ) {
434 449 continue;
435 450 }
436 451
437 452 /**
@@ -454,10 +469,10 @@
454 469 $upgrader->init();
455 470 // This avoids the plugin to be deactivated.
456 471 // Using bulk upgrade puts the site into maintenance mode during the upgrades
457 472 $result = $upgrader->bulk_upgrade( array( $plugin ) );
458 - $errors = $upgrader->skin->get_errors();
459 - $this->log[ $plugin ] = $upgrader->skin->get_upgrade_messages();
473 + $errors = $skin->get_errors();
474 + $this->log[ $plugin ] = $skin->get_upgrade_messages();
460 475
461 476 // release individual plugin lock.
462 477 WP_Upgrader::release_lock( 'jetpack_' . $plugin_slug );
463 478
@@ -466,9 +481,9 @@
466 481 }
467 482 }
468 483
469 484 // release auto_udpate lock.
470 - if ( Constants::get_constant( 'JETPACK_PLUGIN_AUTOUPDATE' ) ) {
485 + if ( $is_automatic_update ) {
471 486 WP_Upgrader::release_lock( 'auto_updater' );
472 487 }
473 488
474 489 if ( ! $this->bulk && ! $result && $update_attempted ) {