mirror of
https://github.com/gosticks/wordpress-develop.git
synced 2026-12-03 11:31:39 +00:00
Code Modernization: Replace usage of strpos() with str_contains().
`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 [52039], [52040], [52326], [55703], [55710], [55987]. Props Soean, spacedmonkey, costdev, dingo_d, azaozz, mikeschroder, flixos90, peterwilsoncc, SergeyBiryukov. Fixes #58206. git-svn-id: https://develop.svn.wordpress.org/trunk@55988 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
@@ -721,7 +721,7 @@ class WP_Http {
|
||||
* In this case, determine the final HTTP header and parse from there.
|
||||
*/
|
||||
for ( $i = count( $headers ) - 1; $i >= 0; $i-- ) {
|
||||
if ( ! empty( $headers[ $i ] ) && false === strpos( $headers[ $i ], ':' ) ) {
|
||||
if ( ! empty( $headers[ $i ] ) && ! str_contains( $headers[ $i ], ':' ) ) {
|
||||
$headers = array_splice( $headers, $i );
|
||||
break;
|
||||
}
|
||||
@@ -734,7 +734,7 @@ class WP_Http {
|
||||
continue;
|
||||
}
|
||||
|
||||
if ( false === strpos( $tempheader, ':' ) ) {
|
||||
if ( ! str_contains( $tempheader, ':' ) ) {
|
||||
$stack = explode( ' ', $tempheader, 3 );
|
||||
$stack[] = '';
|
||||
list( , $response['code'], $response['message']) = $stack;
|
||||
@@ -905,7 +905,7 @@ class WP_Http {
|
||||
if ( null === $accessible_hosts ) {
|
||||
$accessible_hosts = preg_split( '|,\s*|', WP_ACCESSIBLE_HOSTS );
|
||||
|
||||
if ( false !== strpos( WP_ACCESSIBLE_HOSTS, '*' ) ) {
|
||||
if ( str_contains( WP_ACCESSIBLE_HOSTS, '*' ) ) {
|
||||
$wildcard_regex = array();
|
||||
foreach ( $accessible_hosts as $host ) {
|
||||
$wildcard_regex[] = str_replace( '\*', '.+', preg_quote( $host, '/' ) );
|
||||
@@ -1096,7 +1096,7 @@ class WP_Http {
|
||||
return 4;
|
||||
}
|
||||
|
||||
if ( false !== strpos( $maybe_ip, ':' ) && preg_match( '/^(((?=.*(::))(?!.*\3.+\3))\3?|([\dA-F]{1,4}(\3|:\b|$)|\2))(?4){5}((?4){2}|(((2[0-4]|1\d|[1-9])?\d|25[0-5])\.?\b){4})$/i', trim( $maybe_ip, ' []' ) ) ) {
|
||||
if ( str_contains( $maybe_ip, ':' ) && preg_match( '/^(((?=.*(::))(?!.*\3.+\3))\3?|([\dA-F]{1,4}(\3|:\b|$)|\2))(?4){5}((?4){2}|(((2[0-4]|1\d|[1-9])?\d|25[0-5])\.?\b){4})$/i', trim( $maybe_ip, ' []' ) ) ) {
|
||||
return 6;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user