Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions src/wp-includes/functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand Down
50 changes: 50 additions & 0 deletions tests/phpunit/tests/functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -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' => "<html dir='",
'unexpected_attr' => 'lang=',
),
'not installing: uses get_language_attributes()' => array(
'installing' => false,
'expected_attr' => 'lang="',
'unexpected_attr' => "dir='",
),
);
}
}
Loading