-
Notifications
You must be signed in to change notification settings - Fork 3.1k
Use is_string in wp_title to prevent deprecation notice
#10494
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: trunk
Are you sure you want to change the base?
Conversation
|
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 Core Committers: Use this line as a base for the props when committing in SVN: To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. |
src/wp-includes/general-template.php
Outdated
| * @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 ) ); |
There was a problem hiding this comment.
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.
| $title_array = apply_filters( 'wp_title_parts', explode( $t_sep, $title ) ); | |
| $title_array = apply_filters( 'wp_title_parts', ( '' !== $title ) ? explode( $t_sep, $title ) : array() ); |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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/(with0as 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>
There was a problem hiding this comment.
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.
Test using WordPress PlaygroundThe 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
For more details about these limitations and more, check out the Limitations page in the WordPress Playground documentation. |
Checks whether
$titleis 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.