From 6b5d9b772c8278f4f44cb6555962e8acdc8a0b75 Mon Sep 17 00:00:00 2001 From: Colin Stewart <79332690+costdev@users.noreply.github.com> Date: Fri, 18 Jul 2025 00:16:08 +0100 Subject: [PATCH] Replace `strpos()` with newer `str_*()` functions. (#166) Signed-off-by: costdev <79332690+costdev@users.noreply.github.com> --- inc/credits/namespace.php | 4 ++-- inc/default-repo/namespace.php | 6 +++--- inc/importers/namespace.php | 2 +- inc/namespace.php | 2 +- inc/salts/namespace.php | 2 +- inc/version-check/namespace.php | 4 ++-- 6 files changed, 10 insertions(+), 10 deletions(-) diff --git a/inc/credits/namespace.php b/inc/credits/namespace.php index 3aad0fa..a5163ec 100644 --- a/inc/credits/namespace.php +++ b/inc/credits/namespace.php @@ -30,7 +30,7 @@ function bootstrap() { * @return bool|array|WP_Error Replaced value, false to proceed, or WP_Error on failure. */ function replace_credits_api( $response, array $parsed_args, string $url ) { - if ( strpos( $url, 'api.wordpress.org/core/credits/' ) === false ) { + if ( ! str_contains( $url, 'api.wordpress.org/core/credits/' ) ) { return $response; } @@ -45,7 +45,7 @@ function replace_credits_api( $response, array $parsed_args, string $url ) { } // Credits API 1.0 returns a serialized value rather than JSON. - if ( strpos( $url, 'credits/1.0' ) !== false ) { + if ( str_contains( $url, 'credits/1.0' ) ) { $credits = serialize( json_decode( $credits, true ) ); } diff --git a/inc/default-repo/namespace.php b/inc/default-repo/namespace.php index 4eccaef..b98e3aa 100644 --- a/inc/default-repo/namespace.php +++ b/inc/default-repo/namespace.php @@ -49,9 +49,9 @@ function replace_repo_api_urls( $status, $args, $url ) { } if ( - strpos( $url, 'api.wordpress.org/plugins/' ) === false - && strpos( $url, 'api.wordpress.org/themes/' ) === false - && strpos( $url, 'api.wordpress.org/core/version-check/' ) === false + ! str_contains( $url, 'api.wordpress.org/plugins/' ) + && ! str_contains( $url, 'api.wordpress.org/themes/' ) + && ! str_contains( $url, 'api.wordpress.org/core/version-check/' ) ) { return $status; } diff --git a/inc/importers/namespace.php b/inc/importers/namespace.php index 4e00c4f..acd1e1a 100644 --- a/inc/importers/namespace.php +++ b/inc/importers/namespace.php @@ -23,7 +23,7 @@ function bootstrap() { * @return bool Replaced value, or false to proceed. */ function replace_popular_importers_api( $response, $parsed_args, $url ) { - if ( strpos( $url, 'api.wordpress.org/core/importers' ) !== false ) { + if ( str_contains( $url, 'api.wordpress.org/core/importers' ) ) { $query = parse_url( $url, PHP_URL_QUERY ); parse_str( $query, $params ); return get_popular_importers_response( $params['version'] ); diff --git a/inc/namespace.php b/inc/namespace.php index b690abb..ed7df71 100644 --- a/inc/namespace.php +++ b/inc/namespace.php @@ -55,7 +55,7 @@ function bootstrap() { function register_class_path( string $prefix, string $path ) : void { $prefix_length = strlen( $prefix ); spl_autoload_register( function ( $class ) use ( $prefix, $prefix_length, $path ) { - if ( strpos( $class, $prefix . NS_SEPARATOR ) !== 0 ) { + if ( ! str_starts_with( $class, $prefix . NS_SEPARATOR ) ) { return; } diff --git a/inc/salts/namespace.php b/inc/salts/namespace.php index a0674be..a90e49b 100644 --- a/inc/salts/namespace.php +++ b/inc/salts/namespace.php @@ -28,7 +28,7 @@ function bootstrap() { * @return bool|array Replaced value, or false to proceed. */ function replace_salt_generation_via_api( $value, $args, $url ) { - if ( strpos( $url, 'api.wordpress.org/secret-key/1.1/salt' ) !== false ) { + if ( str_contains( $url, 'api.wordpress.org/secret-key/1.1/salt' ) ) { return get_salt_generation_response(); } diff --git a/inc/version-check/namespace.php b/inc/version-check/namespace.php index 17b5fdb..bd897c3 100644 --- a/inc/version-check/namespace.php +++ b/inc/version-check/namespace.php @@ -66,11 +66,11 @@ function bootstrap() { * @return bool|array Replaced value, or false to proceed. */ function replace_browser_version_check( $value, $args, $url ) { - if ( strpos( $url, 'api.wordpress.org/core/browse-happy' ) !== false ) { + if ( str_contains( $url, 'api.wordpress.org/core/browse-happy' ) ) { $agent = $args['body']['useragent']; return get_browser_check_response( $agent ); } - if ( strpos( $url, 'api.wordpress.org/core/serve-happy' ) !== false ) { + if ( str_contains( $url, 'api.wordpress.org/core/serve-happy' ) ) { $query = parse_url( $url, PHP_URL_QUERY ); $url_args = wp_parse_args( $query ); return get_server_check_response( $url_args['php_version'] ?? PHP_VERSION );