Security, Site Health: Make migrating a site to HTTPS a one-click interaction.
Switching a WordPress site from HTTP to HTTPS has historically been a tedious task. While on the surface the Site Address and WordPress Address have to be updated, existing content still remains using HTTP URLs where hard-coded in the database. Furthermore, updating _two_ URLs to migrate to HTTPS is still a fairly unintuitive step which is not clearly explained.
This changeset simplifies migration from HTTP to HTTPS and, where possible, makes it a one-click interaction.
* Automatically replace insecure versions of the Site Address (`home_url()`) with its HTTPS counterpart on the fly if the site has been migrated from HTTP to HTTPS. This is accomplished by introducing a `https_migration_required` option and enabling it when the `home_url()` is accordingly changed.
* A new `wp_replace_insecure_home_url()` function is hooked into various pieces of content to replace URLs accordingly.
* The migration only kicks in when the Site Address (`home_url()`) and WordPress Address (`site_url()`) match, which is the widely common case. Configurations where these differ are often maintained by more advanced users, where this migration routine would be less essential - something to potentially iterate on in the future though.
* The migration does not actually update content in the database. More savvy users that prefer to do that can prevent the migration logic from running by either deleting the `https_migration_required` option or using the new `wp_should_replace_insecure_home_url` filter.
* For fresh sites that do not have any content yet at the point of changing the URLs to HTTPS, the migration will also be skipped since it would not be relevant.
* Expose a primary action in the Site Health recommendation, if HTTPS is already supported by the environment, built on top of the HTTPS detection mechanism from [49904]. When clicked, the default behavior is to update `home_url()` and `site_url()` in one go to their HTTPS counterpart.
* A new `wp_update_urls_to_https()` function takes care of the update routine.
* A new `update_https` meta capability is introduced to control access.
* If the site's URLs are controlled by constants, this update is not automatically possible, so in these scenarios the user is informed about that in the HTTPS status check in Site Health.
* Allow hosting providers to modify the URLs linked to in the HTTPS status check in Site Health, similar to how that is possible for the URLs around updating the PHP version.
* A `WP_UPDATE_HTTPS_URL` environment variable or `wp_update_https_url` filter can be used to provide a custom URL with guidance about updating the site to use HTTPS.
* A `WP_DIRECT_UPDATE_HTTPS_URL` environment variable or `wp_direct_update_https_url` filter can be used to provide a custom URL for the primary CTA to update the site to use HTTPS.
Props flixos90, timothyblynjacobs.
Fixes #51437.
Built from https://develop.svn.wordpress.org/trunk@50131
git-svn-id: http://core.svn.wordpress.org/trunk@49810 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
@@ -1502,6 +1502,8 @@ class WP_Site_Health {
|
||||
// always rely on the latest results.
|
||||
wp_update_https_detection_errors();
|
||||
|
||||
$default_update_url = wp_get_default_update_https_url();
|
||||
|
||||
$result = array(
|
||||
'label' => __( 'Your website is using an active HTTPS connection' ),
|
||||
'status' => 'good',
|
||||
@@ -1514,9 +1516,8 @@ class WP_Site_Health {
|
||||
__( 'An HTTPS connection is a more secure way of browsing the web. Many services now have HTTPS as a requirement. HTTPS allows you to take advantage of new features that can increase site speed, improve search rankings, and gain the trust of your visitors by helping to protect their online privacy.' )
|
||||
),
|
||||
'actions' => sprintf(
|
||||
'<p><a href="%s" target="_blank" rel="noopener">%s <span class="screen-reader-text">%s</span><span aria-hidden="true" class="dashicons dashicons-external"></span></a></p>',
|
||||
/* translators: Documentation explaining HTTPS and why it should be used. */
|
||||
esc_url( __( 'https://wordpress.org/support/article/why-should-i-use-https/' ) ),
|
||||
'<p><a href="%s" target="_blank" rel="noopener">%s<span class="screen-reader-text"> %s</span><span aria-hidden="true" class="dashicons dashicons-external"></span></a></p>',
|
||||
esc_url( $default_update_url ),
|
||||
__( 'Learn more about why you should use HTTPS' ),
|
||||
/* translators: Accessibility text. */
|
||||
__( '(opens in a new tab)' )
|
||||
@@ -1580,16 +1581,54 @@ class WP_Site_Health {
|
||||
__( 'HTTPS is already supported for your website.' )
|
||||
);
|
||||
|
||||
$result['actions'] = sprintf(
|
||||
'<p><a href="%s">%s</a></p>',
|
||||
esc_url( admin_url( 'options-general.php' ) ),
|
||||
__( 'Update your site addresses' )
|
||||
);
|
||||
if ( defined( 'WP_HOME' ) || defined( 'WP_SITEURL' ) ) {
|
||||
$result['description'] .= sprintf(
|
||||
'<p>%s</p>',
|
||||
sprintf(
|
||||
/* translators: 1: wp-config.php, 2: WP_HOME, 3: WP_SITEURL */
|
||||
__( 'However, your WordPress Address is currently controlled by a PHP constant and therefore cannot be updated. You need to edit your %1$s and remove or update the definitions of %2$s and %3$s.' ),
|
||||
'<code>wp-config.php</code>',
|
||||
'<code>WP_HOME</code>',
|
||||
'<code>WP_SITEURL</code>'
|
||||
)
|
||||
);
|
||||
} elseif ( current_user_can( 'update_https' ) ) {
|
||||
$default_direct_update_url = add_query_arg( 'action', 'update_https', wp_nonce_url( admin_url( 'site-health.php' ), 'wp_update_https' ) );
|
||||
$direct_update_url = wp_get_direct_update_https_url();
|
||||
|
||||
if ( ! empty( $direct_update_url ) ) {
|
||||
$result['actions'] = sprintf(
|
||||
'<p class="button-container"><a class="button button-primary" href="%1$s" target="_blank" rel="noopener">%2$s<span class="screen-reader-text"> %3$s</span><span aria-hidden="true" class="dashicons dashicons-external"></span></a></p>',
|
||||
esc_url( $direct_update_url ),
|
||||
__( 'Update your site to use HTTPS' ),
|
||||
/* translators: Accessibility text. */
|
||||
__( '(opens in a new tab)' )
|
||||
);
|
||||
} else {
|
||||
$result['actions'] = sprintf(
|
||||
'<p class="button-container"><a class="button button-primary" href="%1$s">%2$s</a></p>',
|
||||
esc_url( $default_direct_update_url ),
|
||||
__( 'Update your site to use HTTPS' )
|
||||
);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
$result['description'] .= sprintf(
|
||||
'<p>%s</p>',
|
||||
__( 'Talk to your web host about supporting HTTPS for your website.' )
|
||||
);
|
||||
// If host-specific "Update HTTPS" URL is provided, include a link.
|
||||
$update_url = wp_get_update_https_url();
|
||||
if ( $update_url !== $default_update_url ) {
|
||||
$result['description'] .= sprintf(
|
||||
'<p><a href="%s" target="_blank" rel="noopener">%s<span class="screen-reader-text"> %s</span><span aria-hidden="true" class="dashicons dashicons-external"></span></a></p>',
|
||||
esc_url( $update_url ),
|
||||
__( 'Talk to your web host about supporting HTTPS for your website.' ),
|
||||
/* translators: Accessibility text. */
|
||||
__( '(opens in a new tab)' )
|
||||
);
|
||||
} else {
|
||||
$result['description'] .= sprintf(
|
||||
'<p>%s</p>',
|
||||
__( 'Talk to your web host about supporting HTTPS for your website.' )
|
||||
);
|
||||
}
|
||||
}
|
||||
} elseif ( ! wp_is_https_supported() ) {
|
||||
// If the website is using HTTPS, but HTTPS is actually not supported, inform the user about the potential
|
||||
|
||||
Reference in New Issue
Block a user