Replace strpos() with newer str_*() functions. (#166)

Signed-off-by: costdev <79332690+costdev@users.noreply.github.com>
This commit is contained in:
Colin Stewart 2025-07-18 00:16:08 +01:00 committed by GitHub
parent b64e97776d
commit 6b5d9b772c
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
6 changed files with 10 additions and 10 deletions

View file

@ -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 ) );
}

View file

@ -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;
}

View file

@ -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'] );

View file

@ -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;
}

View file

@ -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();
}

View file

@ -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 );