Code Modernization: Use str_contains() in a few more places.

`str_contains()` was introduced in PHP 8.0 to perform a case-sensitive check indicating if the string to search in (haystack) contains the given substring (needle).

WordPress core includes a polyfill for `str_contains()` on PHP < 8.0 as of WordPress 5.9.

This commit replaces `false !== strpos( ... )` with `str_contains()` in core files, making the code more readable and consistent, as well as better aligned with modern development practices.

Follow-up to [55988].

Props spacedmonkey.
See #58220.

git-svn-id: https://develop.svn.wordpress.org/trunk@56021 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Sergey Biryukov
2023-06-25 10:48:28 +00:00
parent 89676d88a2
commit 7a6bff44fc
3 changed files with 7 additions and 6 deletions
+3 -3
View File
@@ -222,7 +222,7 @@ function get_permalink( $post = 0, $leavename = false ) {
) {
$category = '';
if ( strpos( $permalink, '%category%' ) !== false ) {
if ( str_contains( $permalink, '%category%' ) ) {
$cats = get_the_category( $post->ID );
if ( $cats ) {
$cats = wp_list_sort(
@@ -260,7 +260,7 @@ function get_permalink( $post = 0, $leavename = false ) {
}
$author = '';
if ( strpos( $permalink, '%author%' ) !== false ) {
if ( str_contains( $permalink, '%author%' ) ) {
$authordata = get_userdata( $post->post_author );
$author = $authordata->user_nicename;
}
@@ -502,7 +502,7 @@ function get_attachment_link( $post = null, $leavename = false ) {
$name = $post->post_name;
}
if ( strpos( $parentlink, '?' ) === false ) {
if ( ! str_contains( $parentlink, '?' ) ) {
$link = user_trailingslashit( trailingslashit( $parentlink ) . '%postname%' );
}