From 4d6c6eefae74aa3d41a6ce80734a5f67b48f5f91 Mon Sep 17 00:00:00 2001 From: Sergey Biryukov Date: Mon, 26 Jun 2023 10:42:54 +0000 Subject: [PATCH] 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], [56021], [56031]. See #58206. git-svn-id: https://develop.svn.wordpress.org/trunk@56032 602fd350-edb4-49c9-b593-d223f7449a82 --- src/wp-includes/default-constants.php | 2 +- src/wp-includes/load.php | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/wp-includes/default-constants.php b/src/wp-includes/default-constants.php index 1192ebb7d3..61f02a3f60 100644 --- a/src/wp-includes/default-constants.php +++ b/src/wp-includes/default-constants.php @@ -105,7 +105,7 @@ function wp_initial_constants() { // non-concatenated scripts and stylesheets. if ( ! defined( 'SCRIPT_DEBUG' ) ) { if ( ! empty( $wp_version ) ) { - $develop_src = false !== strpos( $wp_version, '-src' ); + $develop_src = str_contains( $wp_version, '-src' ); } else { $develop_src = false; } diff --git a/src/wp-includes/load.php b/src/wp-includes/load.php index 00639bd447..268af02976 100644 --- a/src/wp-includes/load.php +++ b/src/wp-includes/load.php @@ -1505,11 +1505,11 @@ function wp_convert_hr_to_bytes( $value ) { $value = strtolower( trim( $value ) ); $bytes = (int) $value; - if ( false !== strpos( $value, 'g' ) ) { + if ( str_contains( $value, 'g' ) ) { $bytes *= GB_IN_BYTES; - } elseif ( false !== strpos( $value, 'm' ) ) { + } elseif ( str_contains( $value, 'm' ) ) { $bytes *= MB_IN_BYTES; - } elseif ( false !== strpos( $value, 'k' ) ) { + } elseif ( str_contains( $value, 'k' ) ) { $bytes *= KB_IN_BYTES; } @@ -1788,7 +1788,7 @@ function wp_is_xml_request() { if ( isset( $_SERVER['HTTP_ACCEPT'] ) ) { foreach ( $accepted as $type ) { - if ( false !== strpos( $_SERVER['HTTP_ACCEPT'], $type ) ) { + if ( str_contains( $_SERVER['HTTP_ACCEPT'], $type ) ) { return true; } }