Upgrade/Install: Pass stored credentials to WP_Filesystem() in WP_Upgrader.

When using a non-direct filesystem, the call in `WP_Upgrader::maintenance_mode()` did not include the required credentials, leading to a fatal error as the connection was not initialized properly.

This commit attempts to use the stored credentials if available, and triggers a notice otherwise.

Follow-up to [56341], [58128].

Props hideishi, dd32, SergeyBiryukov.
Fixes #62718.

git-svn-id: https://develop.svn.wordpress.org/trunk@59981 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Sergey Biryukov 2025-03-14 12:57:10 +00:00
parent 32fe6af9c3
commit 001a86a7ca

View File

@ -1007,9 +1007,17 @@ class WP_Upgrader {
public function maintenance_mode( $enable = false ) {
global $wp_filesystem;
if ( ! $wp_filesystem ) {
require_once ABSPATH . 'wp-admin/includes/file.php';
WP_Filesystem();
if ( ! function_exists( 'WP_Filesystem' ) ) {
require_once ABSPATH . '/wp-admin/includes/file.php';
}
ob_start();
$credentials = request_filesystem_credentials( '' );
ob_end_clean();
if ( false === $credentials || ! WP_Filesystem( $credentials ) ) {
wp_trigger_error( __FUNCTION__, __( 'Could not access filesystem.' ) );
return;
}
$file = $wp_filesystem->abspath() . '.maintenance';