2424 */
2525function alter_update ( $ plugin_info , $ plugin_details , $ installed_version , $ wp_version , $ wp_url ) {
2626
27- $ plugin_info = phased_rollout_alter_update ( $ plugin_info , $ plugin_details , $ installed_version );
27+ $ plugin_info = phased_rollout ( $ plugin_info , $ plugin_details , $ installed_version );
2828
2929 return $ plugin_info ;
3030}
3131
32- /**
33- * Return the current sites update-percentage.
34- *
35- * @global string $wp_url The WordPress site URL. Extracted from the HTTP User Agent header.
36- *
37- * @param string $slug The plugin slug.
38- * @param string $version The plugin version.
39- *
40- * @return float 0...100.00
41- */
42- function get_site_percentage ( string $ slug = '' , string $ version = '' ) {
43- global $ wp_url ;
44-
45- /*
46- * If the site URL hasn't been extracted already, pull it from the global.
47- * NOTE: This may be set by the tests or other codepaths that run before this function.
48- */
49- if ( empty ( $ wp_url ) && preg_match ( '#^WordPress/.+; (http.+)$#i ' , $ _SERVER ['HTTP_USER_AGENT ' ] ?? '' , $ m ) ) {
50- $ wp_url = $ m [1 ];
51- }
52-
53- $ site_domain = strtolower ( parse_url ( $ wp_url , PHP_URL_HOST ) ?: '' );
54-
55- // If we've reached this point and have no URL, delay the update until 100% is reached.
56- if ( ! $ site_domain ) {
57- return 100 ;
58- }
59-
60- // $site_step represents an integer from 0 to 4095.
61- $ site_step = base_convert ( substr ( md5 ( "{$ site_domain }| {$ slug }| {$ version }" ), 0 , 3 ), 16 , 10 );
62- $ site_percent = $ site_step / 4095 * 100 ;
63-
64- return $ site_percent ;
65- }
66-
6732/**
6833 * This function acts as a filter on the update that's presented to the site.
6934 *
@@ -72,9 +37,8 @@ function get_site_percentage( string $slug = '', string $version = '' ) {
7237 * @param string $installed_version The currently installed version of the plugin.
7338 * @return object The updated plugin update details.
7439 */
75- function phased_rollout_alter_update ( $ plugin_info , $ plugin_details , $ installed_version ) {
76-
77- $ strategy = $ phase_details ['strategy ' ] ?? false ;
40+ function phased_rollout ( $ plugin_info , $ plugin_details , $ installed_version ) {
41+ $ strategy = $ plugin_info ['meta ' ]['rollout ' ]['strategy ' ] ?? false ;
7842 if ( ! $ strategy ) {
7943 return $ plugin_info ;
8044 }
@@ -118,7 +82,8 @@ function phased_rollout_alter_update( $plugin_info, $plugin_details, $installed_
11882
11983 // If the site should not update, we'll return the last-version if possible.
12084 if ( $ do_not_offer_update ) {
121- $ plugin_info ->version = $ plugin_details ->meta ->last_version ?? $ installed_version ;
85+ $ last_version = $ plugin_details ->meta ->last_version ?? '' ;
86+ $ plugin_info ->version = $ last_version ?: $ installed_version ;
12287
12388 // Match update-check API.
12489 unset(
@@ -133,6 +98,41 @@ function phased_rollout_alter_update( $plugin_info, $plugin_details, $installed_
13398 return $ plugin_info ;
13499}
135100
101+ /**
102+ * Return the current sites update-percentage.
103+ *
104+ * @global string $wp_url The WordPress site URL. Extracted from the HTTP User Agent header.
105+ *
106+ * @param string $slug The plugin slug.
107+ * @param string $version The plugin version.
108+ *
109+ * @return float 0...100.00
110+ */
111+ function get_site_percentage ( string $ slug = '' , string $ version = '' ) {
112+ global $ wp_url ;
113+
114+ /*
115+ * If the site URL hasn't been extracted already, pull it from the global.
116+ * NOTE: This may be set by the tests or other codepaths that run before this function.
117+ */
118+ if ( empty ( $ wp_url ) && preg_match ( '#^WordPress/.+; (http.+)$#i ' , $ _SERVER ['HTTP_USER_AGENT ' ] ?? '' , $ m ) ) {
119+ $ wp_url = $ m [1 ];
120+ }
121+
122+ $ site_domain = strtolower ( parse_url ( $ wp_url , PHP_URL_HOST ) ?: '' );
123+
124+ // If we've reached this point and have no URL, delay the update until 100% is reached.
125+ if ( ! $ site_domain ) {
126+ return 100 ;
127+ }
128+
129+ // $site_step represents an integer from 0 to 4095.
130+ $ site_step = base_convert ( substr ( md5 ( "{$ site_domain }| {$ slug }| {$ version }" ), 0 , 3 ), 16 , 10 );
131+ $ site_percent = $ site_step / 4095 * 100 ;
132+
133+ return $ site_percent ;
134+ }
135+
136136/**
137137 * Get the percentage of sites that should receive the update for the plugin.
138138 *
@@ -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 ->phased_rollout ?? false ;
155+ $ phase_details = $ update_details ->meta ->rollout -> strategy ?? false ;
156156
157157 if (
158158 ! $ phase_details ||
0 commit comments