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.
Built from https://develop.svn.wordpress.org/trunk@56021


git-svn-id: http://core.svn.wordpress.org/trunk@55533 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
Sergey Biryukov 2023-06-25 10:50:24 +00:00
parent e28f97b887
commit c2603744aa
4 changed files with 8 additions and 7 deletions

View File

@ -803,7 +803,7 @@ function serialize_blocks( $blocks ) {
function filter_block_content( $text, $allowed_html = 'post', $allowed_protocols = array() ) {
$result = '';
if ( false !== strpos( $text, '<!--' ) && false !== strpos( $text, '--->' ) ) {
if ( str_contains( $text, '<!--' ) && str_contains( $text, '--->' ) ) {
$text = preg_replace_callback( '%<!--(.*?)--->%', '_filter_block_content_callback', $text );
}

View File

@ -4463,8 +4463,9 @@ function esc_url( $url, $protocols = null, $_context = 'display' ) {
* it needs http:// prepended (unless it's a relative link
* starting with /, # or ?, or a PHP file).
*/
if ( strpos( $url, ':' ) === false && ! in_array( $url[0], array( '/', '#', '?' ), true ) &&
! preg_match( '/^[a-z0-9-]+?\.php/i', $url ) ) {
if ( ! str_contains( $url, ':' ) && ! in_array( $url[0], array( '/', '#', '?' ), true ) &&
! preg_match( '/^[a-z0-9-]+?\.php/i', $url )
) {
$url = 'http://' . $url;
}

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%' );
}

View File

@ -16,7 +16,7 @@
*
* @global string $wp_version
*/
$wp_version = '6.3-alpha-56020';
$wp_version = '6.3-alpha-56021';
/**
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.