Skip to content

Commit 01e53d9

Browse files
committed
More minimal Release Confirmation UI.
1 parent bdae38f commit 01e53d9

File tree

3 files changed

+64
-70
lines changed

3 files changed

+64
-70
lines changed

wordpress.org/public_html/wp-content/plugins/plugin-directory/jobs/class-api-update-updater.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -106,13 +106,13 @@ public static function update_single_plugin( $plugin_slug, $self_loop = false )
106106
}
107107

108108
// Add phased rollout strategy data if needed.
109-
if ( $release && $release['phased_rollout'] ) {
110-
$meta['phased_rollout'] = array(
111-
'strategy' => $release['phased_rollout'],
109+
if ( $release && ! empty( $release['rollout_strategy'] ) ) {
110+
$meta['rollout'] = array(
111+
'strategy' => $release['rollout_strategy'],
112112
);
113-
} elseif ( $post->phased_rollout ) {
114-
$meta['phased_rollout'] = array(
115-
'strategy' => $post->phased_rollout,
113+
} elseif ( $post->rollout_strategy ) {
114+
$meta['rollout'] = array(
115+
'strategy' => $post->rollout_strategy,
116116
);
117117
}
118118

wordpress.org/public_html/wp-content/plugins/plugin-directory/shortcodes/class-release-confirmation.php

Lines changed: 17 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -352,35 +352,29 @@ static function get_release_strategy( $plugin, $data ) {
352352
}
353353

354354
$rollout = $data['rollout_strategy'] ?? '';
355-
356-
if ( $data['confirmed'] ) {
357-
if ( $rollout ) {
358-
ob_start();
359-
echo '<div class="release-strategy">';
360-
echo '<h3>' . __( 'Release Strategy', 'wporg-plugins' ) . '</h3>';
361-
echo '<p>' . __( 'This release has been confirmed, and the rollout strategy is set.', 'wporg-plugins' ) . '</p>';
362-
echo '<pre>' . esc_html( print_r( $data['rollout_strategy'], true ) ) . '</pre>';
363-
echo '</div>';
364-
365-
return ob_get_clean();
366-
}
355+
if ( $data['confirmed'] && ! $rollout ) {
356+
// If the release is confirmed, but no rollout strategy was set for the release, don't display the UI.
367357
return '';
368358
}
369359

370360
ob_start();
371361
echo '<div class="release-strategy">';
372-
echo '<h3>Release Strategy</h3>';
373-
echo '<p>WordPress sites check for plugin updates multiple times per day, and may attempt to automatically update if the site owner has enabled automatic updates. This immediate rollout strategy can result in many users installing a plugin before the author becomes aware of any issues with the update. By using this feature you can choose how (and when) sites automatically install your plugin update.</p>';
374-
echo '<label for="rollout_strategy">' . __( 'Rollout Strategy', 'wporg-plugins' ) . '</label>';
375-
376-
echo '<select id="rollout_strategy" name="rollout_strategy" onchange="this.nextElementSibling.innerHTML = this.options[this.selectedIndex].dataset.description;">';
362+
echo '<h3>' . __( 'Rollout Strategy', 'wporg-plugins' ) . '</h3>';
363+
364+
echo '<select
365+
id="rollout_strategy"
366+
name="rollout_strategy"
367+
onchange="this.nextElementSibling.innerText = this.options[this.selectedIndex].dataset.description;"
368+
' . disabled( $data['confirmed'], true, false ) . '
369+
>';
377370
foreach ( Template::get_rollout_strategies() as $slug => $set ) {
378-
echo '<option ' .
379-
'value="' . esc_attr( $slug ) . '" ' .
380-
selected( $rollout, $slug, false ) .
381-
disabled( 'custom', $slug, false ) .
382-
' data-description="' . esc_attr( $set['description'] ) .
383-
'">' . $set['name'] . '</option>';
371+
printf(
372+
'<option value="%s" data-description="%s" %s>%s</option>',
373+
esc_attr( $slug ),
374+
esc_attr( $set['description'] ),
375+
selected( $rollout, $slug, false ),
376+
esc_html( $set['name'] )
377+
);
384378
}
385379
echo '</select>';
386380
echo '<div class="help">' . esc_html( Template::get_rollout_strategies()[ $rollout ]['description'] ?? '' ) . '</div>';

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

Lines changed: 41 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -24,46 +24,11 @@
2424
*/
2525
function 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

Comments
 (0)