Skip to content

Conversation

@sabernhardt
Copy link

Checks whether $title is a string and then checks whether it equals an empty string before adding the separator.

Trac 61352


This Pull Request is for code review only. Please keep all other discussion in the Trac ticket. Do not merge this Pull Request. See GitHub Pull Requests for Code Review in the Core Handbook for more details.

@github-actions
Copy link

github-actions bot commented Nov 9, 2025

The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the props-bot label.

Core Committers: Use this line as a base for the props when committing in SVN:

Props sabernhardt, mukesh27, joedolson.

To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook.

* @param string[] $title_array Array of parts of the page title.
*/
$title_array = apply_filters( 'wp_title_parts', ! empty( $title ) ? explode( $t_sep, $title ) : array() );
$title_array = apply_filters( 'wp_title_parts', explode( $t_sep, $title ) );
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

While I often create untitled posts on local sites and I expect that sometimes they are appropriate on live sites too, an empty $title string is hopefully uncommon. Also, even an empty array would run through implode() later anyway.

If skipping explode() is important, however, I think that parentheses make the condition a little easier to read.

Suggested change
$title_array = apply_filters( 'wp_title_parts', explode( $t_sep, $title ) );
$title_array = apply_filters( 'wp_title_parts', ( '' !== $title ) ? explode( $t_sep, $title ) : array() );

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggest moving the conditional logic before apply_filters and passing the variable for better readability.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This could be more readable:

	if ( ! is_string( $title ) ) {
		$title = '';
	}

	$prefix      = '';
	$title_array = array();
	if ( '' !== $title ) {
		$prefix      = " $sep ";
		$title_array = explode( $t_sep, $title );
	}

	/**
	 * Filters the parts of the page title.
	 *
	 * @since 4.0.0
	 *
	 * @param string[] $title_array Array of parts of the page title.
	 */
	$title_array = apply_filters( 'wp_title_parts', $title_array );

We probably should change the $sep and/or $t_sep names too, but not for this release.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If the apply_filters( 'wp_title_parts', $title_array ) direction above is worth pursuing, it might be better in a separate PR.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think there's any need to go to a new PR for that change. It looks good to me.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I switched this PR to the more readable concept and checked the following URLs with the updated .diff and Twenty Fourteen.

  • http://localhost/svn/src/0-2/ (with 0 as the post title): <title>0 | Trunk (SVN)</title>
  • http://localhost/svn/src/ (front page, without a static front page): <title>Trunk (SVN)</title>
  • http://localhost/svn/src/sample-page/ (page of posts): <title>Sample Page | Trunk (SVN)</title>

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Duplicated the same tests with Twenty Twenty, and confirmed same behavior.

@github-actions
Copy link

github-actions bot commented Nov 9, 2025

Test using WordPress Playground

The changes in this pull request can previewed and tested using a WordPress Playground instance.

WordPress Playground is an experimental project that creates a full WordPress instance entirely within the browser.

Some things to be aware of

  • The Plugin and Theme Directories cannot be accessed within Playground.
  • All changes will be lost when closing a tab with a Playground instance.
  • All changes will be lost when refreshing the page.
  • A fresh instance is created each time the link below is clicked.
  • Every time this pull request is updated, a new ZIP file containing all changes is created. If changes are not reflected in the Playground instance,
    it's possible that the most recent build failed, or has not completed. Check the list of workflow runs to be sure.

For more details about these limitations and more, check out the Limitations page in the WordPress Playground documentation.

Test this pull request with WordPress Playground.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants