Skip to content

Commit e1de7e9

Browse files
committed
Themes: Improve type checking in wp_title.
Follow up to [61108]. Change type handling to ensure that falsey string values like `0` are correctly handled. Improves readability of underlying code by consolidating type checks and passing resulting array to the `wp_title_parts` filter. Props tobiasbg, sabernhardt, sirlouen, wildworks, joedolson, mukesh27. Fixes #61352. git-svn-id: https://develop.svn.wordpress.org/trunk@61198 602fd350-edb4-49c9-b593-d223f7449a82
1 parent 03171e1 commit e1de7e9

File tree

1 file changed

+10
-4
lines changed

1 file changed

+10
-4
lines changed

src/wp-includes/general-template.php

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1424,9 +1424,15 @@ function wp_title( $sep = '»', $display = true, $seplocation = '' ) {
14241424
$title = __( 'Page not found' );
14251425
}
14261426

1427-
$prefix = '';
1428-
if ( ! empty( $title ) ) {
1429-
$prefix = " $sep ";
1427+
if ( ! is_string( $title ) ) {
1428+
$title = '';
1429+
}
1430+
1431+
$prefix = '';
1432+
$title_array = array();
1433+
if ( '' !== $title ) {
1434+
$prefix = " $sep ";
1435+
$title_array = explode( $t_sep, $title );
14301436
}
14311437

14321438
/**
@@ -1436,7 +1442,7 @@ function wp_title( $sep = '»', $display = true, $seplocation = '' ) {
14361442
*
14371443
* @param string[] $title_array Array of parts of the page title.
14381444
*/
1439-
$title_array = apply_filters( 'wp_title_parts', ! empty( $title ) ? explode( $t_sep, $title ) : array() );
1445+
$title_array = apply_filters( 'wp_title_parts', $title_array );
14401446

14411447
// Determines position of the separator and direction of the breadcrumb.
14421448
if ( 'right' === $seplocation ) { // Separator on right, so reverse the order.

0 commit comments

Comments
 (0)