From 2faad88a1e0be7ded37ca9eee7e6152ad9930ff3 Mon Sep 17 00:00:00 2001 From: Ari Stathopoulos Date: Fri, 10 Mar 2023 12:39:07 +0200 Subject: [PATCH] Simplify installation when the server supports SQLite and not MySQL --- src/wp-admin/setup-config.php | 28 +++++++++++++++++++++++++--- 1 file changed, 25 insertions(+), 3 deletions(-) diff --git a/src/wp-admin/setup-config.php b/src/wp-admin/setup-config.php index f3cff57b2b58b..9d910186869fa 100644 --- a/src/wp-admin/setup-config.php +++ b/src/wp-admin/setup-config.php @@ -123,14 +123,17 @@ function setup_config_display_header( $body_classes = array() ) { $language = $GLOBALS['wp_local_package']; } +$server_has_mysql = function_exists( 'mysqli_connect' ) || function_exists( 'mysql_connect' ); +$server_has_sqlite = class_exists( 'SQLite3' ); switch ( $step ) { case -1: if ( wp_can_install_language_pack() && empty( $language ) ) { $languages = wp_get_available_translations(); if ( $languages ) { + $action_step = ! $server_has_mysql && $server_has_sqlite ? '2' : '0'; setup_config_display_header( 'language-chooser' ); echo '

Select a default language

'; - echo '
'; + echo ''; wp_install_language_form( $languages ); echo '
'; break; @@ -164,7 +167,7 @@ function setup_config_display_header( $body_classes = array() ) { ?>

- + @@ -291,17 +294,24 @@ function setup_config_display_header( $body_classes = array() ) { break; case 2: + // If the server doesn't support MySQL, we skipped steps 0 & 1. + if ( ! $server_has_mysql && ! empty( $language ) ) { + wp_download_language_pack( $language ); + } load_default_textdomain( $language ); $GLOBALS['wp_locale'] = new WP_Locale(); $dbtype = trim( wp_unslash( $_POST['dbtype'] ) ); - $dbtype = class_exists( 'SQLite3' ) && 'sqlite' === $dbtype ? 'sqlite' : 'mysql'; + $dbtype = $server_has_sqlite && 'sqlite' === $dbtype ? 'sqlite' : 'mysql'; + $dbtype = $server_has_mysql && ! $server_has_sqlite ? 'mysql' : $dbtype; + $dbtype = $server_has_sqlite && ! $server_has_mysql ? 'sqlite' : $dbtype; $dbname = trim( wp_unslash( $_POST['dbname'] ) ); $uname = trim( wp_unslash( $_POST['uname'] ) ); $pwd = trim( wp_unslash( $_POST['pwd'] ) ); $dbhost = trim( wp_unslash( $_POST['dbhost'] ) ); $prefix = trim( wp_unslash( $_POST['prefix'] ) ); + $prefix = empty( $prefix ) ? 'wp_' : $prefix; $step_1 = 'setup-config.php?step=1'; $install = 'install.php'; @@ -545,6 +555,18 @@ function setup_config_display_header( $body_classes = array() ) {

window.location.href = "' . $install . '";'; + endif; + ?> + %s

', $error_message ); endif;