diff --git a/src/wp-includes/functions.php b/src/wp-includes/functions.php index dca95d69b69fe..77a2484b86fc0 100644 --- a/src/wp-includes/functions.php +++ b/src/wp-includes/functions.php @@ -3955,9 +3955,14 @@ function _default_wp_die_handler( $message, $title = '', $args = array() ) { /* * If `text_direction` was not explicitly passed, * use get_language_attributes() if available. + * + * Skipped while installing: get_language_attributes() queries the + * database, which could re-trigger the DB error that led here and + * loop wp_die() indefinitely. See #50228. */ if ( empty( $args['text_direction'] ) && function_exists( 'language_attributes' ) && function_exists( 'is_rtl' ) + && ! wp_installing() ) { $dir_attr = get_language_attributes(); } diff --git a/tests/phpunit/tests/functions.php b/tests/phpunit/tests/functions.php index 19c721aeaa46a..69ab0204f1804 100644 --- a/tests/phpunit/tests/functions.php +++ b/tests/phpunit/tests/functions.php @@ -2247,4 +2247,54 @@ public function test_wp_recursive_ksort() { ); $this->assertSameSetsWithIndex( $theme_json, $expected_theme_json ); } + + /** + * Tests that _default_wp_die_handler() only queries the database for language + * attributes when WordPress is not installing. + * + * @ticket 50228 + * @covers ::_default_wp_die_handler + * @dataProvider data_default_wp_die_handler_language_attributes + * + * @param bool $installing Whether WordPress is installing. + * @param string $expected_attr Substring the output is expected to contain. + * @param string $unexpected_attr Substring the output is expected not to contain. + */ + public function test_default_wp_die_handler_language_attributes( $installing, $expected_attr, $unexpected_attr ) { + $was_installing = wp_installing(); + wp_installing( $installing ); + + ob_start(); + _default_wp_die_handler( 'Error message', 'Error title', array( 'exit' => false ) ); + $output = ob_get_clean(); + + wp_installing( $was_installing ); + + $this->assertStringContainsString( $expected_attr, $output ); + $this->assertStringNotContainsString( $unexpected_attr, $output ); + } + + /** + * Data provider for test_default_wp_die_handler_language_attributes(). + * + * @return array[] { + * @type bool $installing Whether WordPress is installing. + * @type string $expected_attr Substring the output is expected to contain. + * @type string $unexpected_attr Substring the output is expected not to contain. + * } + */ + public function data_default_wp_die_handler_language_attributes() { + return array( + 'installing: falls back to the dir attribute' => array( + 'installing' => true, + 'expected_attr' => " 'lang=', + ), + 'not installing: uses get_language_attributes()' => array( + 'installing' => false, + 'expected_attr' => 'lang="', + 'unexpected_attr' => "dir='", + ), + ); + } }