Skip to content

Commit 2e5bacd

Browse files
committed
Merge branch 'trunk' into plugins/phased-rollout
2 parents dfe16bb + 2998b65 commit 2e5bacd

File tree

1 file changed

+19
-19
lines changed

1 file changed

+19
-19
lines changed

wordpress.org/public_html/wp-content/plugins/plugin-directory/standalone/plugin-update-helpers.php

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,11 @@
33

44
/**
55
* This file contains some functions that are used in the plugin update-check API.
6-
* The API is currently closed source, but these functions are made public through this file.
6+
* The API is currently not open-source, but these functions are made public through this file.
77
*
88
* NOTE: This file is executed without WordPress being loaded.
99
* Please ensure no WordPress dependencies, or other plugin file dependencies are added.
10-
* Certain methods are polyfilled in that environment with no-op variants such as __() and apply_filters().
10+
* Certain methods MAY BE polyfilled in that environment with no-op variants such as __() and apply_filters().
1111
*
1212
* @link https://api.wordpress.org/plugins/update-check/{1.0,1.1}/
1313
*/
@@ -24,46 +24,46 @@
2424
*/
2525
function alter_update( $plugin_info, $plugin_details, $installed_version, $wp_version, $wp_url ) {
2626

27+
// Apply the Phased Rollout / Staged Rollout / Gradual Rollout strategy to the plugin update.
2728
$plugin_info = phased_rollout( $plugin_info, $plugin_details, $installed_version );
2829

2930
return $plugin_info;
3031
}
3132

3233
/**
33-
* This function acts as a filter on the update that's presented to the site.
34+
* Apply the Phased / Staged rollout strategies to the plugin update.
35+
*
36+
* @see https://meta.trac.wordpress.org/ticket/8009
3437
*
3538
* @param object $plugin_info The plugin update details.
3639
* @param object $plugin_details The plugin details.
3740
* @param string $installed_version The currently installed version of the plugin.
3841
* @return object The updated plugin update details.
3942
*/
4043
function phased_rollout( $plugin_info, $plugin_details, $installed_version ) {
41-
$strategy = $plugin_info['meta']['rollout']['strategy'] ?? false;
42-
if ( ! $strategy ) {
43-
return $plugin_info;
44-
}
44+
$strategy = $plugin_info->meta->rollout['strategy'] ?? false;
4545

46-
// This is effectively a NOOP strategy, no changes.
47-
if ( 'immediate' === $strategy ) {
46+
// If no strategy is set, or it's immediate, return the plugin info unchanged.
47+
if ( ! $strategy || 'immediate' === $strategy ) {
4848
return $plugin_info;
4949
}
5050

5151
// Calculate the number of hours since the plugin was released.
52-
$hours_since_release = ( time() - $plugin_details->meta->release_time ) / 3600;
52+
$hours_since_release = ( time() - $plugin_details->meta->release_time ) / 3600 /* HOUR_IN_SECONDS */;
53+
54+
// If more than 5 days have passed, always assume the update is available.
5355
if ( $hours_since_release > 120 ) {
54-
// If more than 5 days have passed, always assume the update is available.
5556
return $plugin_info;
5657
}
5758

5859
// If the strategy is manual updates only for the first 24hrs, then we can just disable the sites ability to perform autoupdates.
59-
if ( 'manual-updates-24hr' === $strategy ) {
60-
61-
// If less than 24 hours have passed, do not update.
62-
if ( $hours_since_release <= 24 ) {
63-
$plugin_info->disable_autoupdates = true;
64-
}
65-
// Else: The plugin update is unchanged, sites will update.
60+
if (
61+
'manual-updates-24hr' === $strategy &&
62+
$hours_since_release <= 24
63+
) {
64+
$plugin_info->disable_autoupdates = true;
6665

66+
// Early return to avoid further processing.
6767
return $plugin_info;
6868
}
6969

@@ -152,7 +152,7 @@ function phased_rollout_get_plugin_percent( string $strategy, float $hours_since
152152
'cautious',
153153
];
154154

155-
$phase_details = $update_details->meta->rollout->strategy ?? false;
155+
$phase_details = $update_details->meta->rollout ?? false;
156156

157157
if (
158158
! $phase_details ||

0 commit comments

Comments
 (0)