From 30f001cfab31cf9fc290755eb61aa1c008f94486 Mon Sep 17 00:00:00 2001 From: jeherve Date: Mon, 20 Nov 2023 15:33:16 +0000 Subject: [PATCH] Code Modernization: Replace strpos() with str_starts_with() (#34135) Co-authored-by: Brad Jorsch Committed via a GitHub action: https://github.com/Automattic/jetpack/actions/runs/6932111860 --- CHANGELOG.md | 1 + inc/delete-cache-button.php | 2 +- ossdl-cdn.php | 2 +- wp-cache-base.php | 2 +- wp-cache-phase2.php | 4 ++-- 5 files changed, 6 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 18216eb8..c94cc5c8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,6 +10,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 This is an alpha version! The changes listed here are not final. ### Changed +- Code Modernization: Replace usage of strpos() with str_starts_with(). - General: updated PHP requirement to PHP 7.0+ - General: update WordPress version requirements to WordPress 6.3. - Updated package dependencies. diff --git a/inc/delete-cache-button.php b/inc/delete-cache-button.php index 00577ec6..dc18b26d 100644 --- a/inc/delete-cache-button.php +++ b/inc/delete-cache-button.php @@ -167,7 +167,7 @@ function wpsc_delete_cache_directory() { $path = trailingslashit( $path ); $supercachepath = realpath( get_supercache_dir() ); - if ( false === wp_cache_confirm_delete( $path ) || 0 !== strpos( $path, $supercachepath ) ) { + if ( false === wp_cache_confirm_delete( $path ) || ! str_starts_with( $path, $supercachepath ) ) { wp_cache_debug( 'Could not delete directory: ' . $path ); define( 'WPSCDELETEERROR', 'Could not delete directory' ); return false; diff --git a/ossdl-cdn.php b/ossdl-cdn.php index a0cc1116..7eb462b6 100755 --- a/ossdl-cdn.php +++ b/ossdl-cdn.php @@ -141,7 +141,7 @@ function scossdl_off_rewriter( $match ) { $include_dirs = scossdl_off_additional_directories(); } - if ( $ossdl_https && 0 === strpos( $match[0], 'https' ) ) { + if ( $ossdl_https && str_starts_with( $match[0], 'https' ) ) { return $match[0]; } diff --git a/wp-cache-base.php b/wp-cache-base.php index 313d9c43..59efb188 100644 --- a/wp-cache-base.php +++ b/wp-cache-base.php @@ -37,7 +37,7 @@ } if ( count( $wpsc_path_segs ) > $wpsc_base_count && - ( ! defined( 'PATH_CURRENT_SITE' ) || 0 === strpos( $request_uri, PATH_CURRENT_SITE ) ) + ( ! defined( 'PATH_CURRENT_SITE' ) || str_starts_with( $request_uri, PATH_CURRENT_SITE ) ) ) { $blogcacheid = $wpsc_path_segs[ $wpsc_base_count ]; } diff --git a/wp-cache-phase2.php b/wp-cache-phase2.php index d0caa1a8..814e8559 100644 --- a/wp-cache-phase2.php +++ b/wp-cache-phase2.php @@ -825,7 +825,7 @@ function get_current_url_supercache_dir( $post_id = 0 ) { } } else { $uri = str_replace( $site_url, '', $permalink ); - if ( strpos( $uri, $wp_cache_home_path ) !== 0 ) { + if ( ! str_starts_with( $uri, $wp_cache_home_path ) ) { $uri = rtrim( $wp_cache_home_path, '/' ) . $uri; } } @@ -3529,7 +3529,7 @@ function apache_request_headers() { $headers = array(); foreach ( array_keys( $_SERVER ) as $skey ) { - if ( 0 === strpos( $skey, 'HTTP_' ) ) { + if ( str_starts_with( $skey, 'HTTP_' ) ) { $header = implode( '-', array_map( 'ucfirst', array_slice( explode( '_', strtolower( $skey ) ), 1 ) ) ); $headers[ $header ] = $_SERVER[ $skey ]; }