|
3 | 3 |
|
4 | 4 | /** |
5 | 5 | * 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. |
7 | 7 | * |
8 | 8 | * NOTE: This file is executed without WordPress being loaded. |
9 | 9 | * 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(). |
11 | 11 | * |
12 | 12 | * @link https://api.wordpress.org/plugins/update-check/{1.0,1.1}/ |
13 | 13 | */ |
|
24 | 24 | */ |
25 | 25 | function alter_update( $plugin_info, $plugin_details, $installed_version, $wp_version, $wp_url ) { |
26 | 26 |
|
| 27 | + // Apply the Phased Rollout / Staged Rollout / Gradual Rollout strategy to the plugin update. |
27 | 28 | $plugin_info = phased_rollout( $plugin_info, $plugin_details, $installed_version ); |
28 | 29 |
|
29 | 30 | return $plugin_info; |
30 | 31 | } |
31 | 32 |
|
32 | 33 | /** |
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 |
34 | 37 | * |
35 | 38 | * @param object $plugin_info The plugin update details. |
36 | 39 | * @param object $plugin_details The plugin details. |
37 | 40 | * @param string $installed_version The currently installed version of the plugin. |
38 | 41 | * @return object The updated plugin update details. |
39 | 42 | */ |
40 | 43 | 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; |
45 | 45 |
|
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 ) { |
48 | 48 | return $plugin_info; |
49 | 49 | } |
50 | 50 |
|
51 | 51 | // 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. |
53 | 55 | if ( $hours_since_release > 120 ) { |
54 | | - // If more than 5 days have passed, always assume the update is available. |
55 | 56 | return $plugin_info; |
56 | 57 | } |
57 | 58 |
|
58 | 59 | // 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; |
66 | 65 |
|
| 66 | + // Early return to avoid further processing. |
67 | 67 | return $plugin_info; |
68 | 68 | } |
69 | 69 |
|
@@ -152,7 +152,7 @@ function phased_rollout_get_plugin_percent( string $strategy, float $hours_since |
152 | 152 | 'cautious', |
153 | 153 | ]; |
154 | 154 |
|
155 | | - $phase_details = $update_details->meta->rollout->strategy ?? false; |
| 155 | + $phase_details = $update_details->meta->rollout ?? false; |
156 | 156 |
|
157 | 157 | if ( |
158 | 158 | ! $phase_details || |
|
0 commit comments