From 1364db92bb6d75276caba38ab94f3fc7dfdcaf55 Mon Sep 17 00:00:00 2001 From: Sergey Biryukov Date: Tue, 1 Aug 2023 16:07:25 +0000 Subject: [PATCH] Upgrade/Install: Pass stored credentials to `WP_Filesystem()` where appropriate. With the introduction of temporary backups of plugins and themes before updating, a new Site Health test was added to verify that plugin and theme temporary backup directories are writable or can be created. When using a non-direct filesystem, the Site Health test did not include the required credentials, leading to a fatal error as the connection was not initialized properly. This commit attemps to use the stored credentials if available, and displays a message otherwise. Includes a similar fix in a function that performs a cleanup of the temporary backup directory. Follow-up to [55720]. Props utsav72640, rajinsharwar, costdev, mukesh27, peterwilsoncc, audrasjb, SergeyBiryukov. See #58940. Built from https://develop.svn.wordpress.org/trunk@56341 git-svn-id: http://core.svn.wordpress.org/trunk@55853 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-admin/includes/class-wp-site-health.php | 14 ++++++++++++-- wp-includes/update.php | 11 +++++++++-- wp-includes/version.php | 2 +- 3 files changed, 22 insertions(+), 5 deletions(-) diff --git a/wp-admin/includes/class-wp-site-health.php b/wp-admin/includes/class-wp-site-health.php index a198b496d7..eda8bfaa4b 100644 --- a/wp-admin/includes/class-wp-site-health.php +++ b/wp-admin/includes/class-wp-site-health.php @@ -2009,9 +2009,19 @@ class WP_Site_Health { 'test' => 'update_temp_backup_writable', ); - if ( ! $wp_filesystem ) { + if ( ! function_exists( 'WP_Filesystem' ) ) { require_once ABSPATH . '/wp-admin/includes/file.php'; - WP_Filesystem(); + } + + ob_start(); + $credentials = request_filesystem_credentials( '' ); + ob_end_clean(); + + if ( false === $credentials || ! WP_Filesystem( $credentials ) ) { + $result['status'] = 'recommended'; + $result['label'] = __( 'Could not access filesystem' ); + $result['description'] = __( 'Unable to connect to the filesystem. Please confirm your credentials.' ); + return $result; } $wp_content = $wp_filesystem->wp_content_dir(); diff --git a/wp-includes/update.php b/wp-includes/update.php index 350182b2ce..7c4e31feef 100644 --- a/wp-includes/update.php +++ b/wp-includes/update.php @@ -1113,9 +1113,16 @@ function wp_delete_all_temp_backups() { function _wp_delete_all_temp_backups() { global $wp_filesystem; - if ( ! $wp_filesystem ) { + if ( ! function_exists( 'WP_Filesystem' ) ) { require_once ABSPATH . '/wp-admin/includes/file.php'; - WP_Filesystem(); + } + + ob_start(); + $credentials = request_filesystem_credentials( '' ); + ob_end_clean(); + + if ( false === $credentials || ! WP_Filesystem( $credentials ) ) { + return new WP_Error( 'fs_unavailable', __( 'Could not access filesystem.' ) ); } if ( ! $wp_filesystem->wp_content_dir() ) { diff --git a/wp-includes/version.php b/wp-includes/version.php index 077bcb66ef..90f48edd15 100644 --- a/wp-includes/version.php +++ b/wp-includes/version.php @@ -16,7 +16,7 @@ * * @global string $wp_version */ -$wp_version = '6.4-alpha-56339'; +$wp_version = '6.4-alpha-56341'; /** * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.