From e28f97b88759cce975733b9758801f757e142089 Mon Sep 17 00:00:00 2001 From: Sergey Biryukov Date: Sat, 24 Jun 2023 17:17:23 +0000 Subject: [PATCH] Code Modernization: Use `str_starts_with()` and `str_ends_with()` in a few more places. `str_starts_with()` and `str_ends_with()` were introduced in PHP 8.0 to perform a case-sensitive check indicating if the string to search in (haystack) begins or ends with the given substring (needle). WordPress core includes a polyfill for these functions on PHP < 8.0 as of WordPress 5.9. Follow-up to [55990], [56014], [56019]. See #58220. Built from https://develop.svn.wordpress.org/trunk@56020 git-svn-id: http://core.svn.wordpress.org/trunk@55532 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-includes/class-wp-http-cookie.php | 4 ++-- wp-includes/deprecated.php | 2 +- wp-includes/kses.php | 2 +- wp-includes/version.php | 2 +- 4 files changed, 5 insertions(+), 5 deletions(-) diff --git a/wp-includes/class-wp-http-cookie.php b/wp-includes/class-wp-http-cookie.php index e7ea4bc96d..8f55e4486c 100644 --- a/wp-includes/class-wp-http-cookie.php +++ b/wp-includes/class-wp-http-cookie.php @@ -203,7 +203,7 @@ class WP_Http_Cookie { // Host - very basic check that the request URL ends with the domain restriction (minus leading dot). $domain = ( str_starts_with( $domain, '.' ) ) ? substr( $domain, 1 ) : $domain; - if ( substr( $url['host'], -strlen( $domain ) ) !== $domain ) { + if ( ! str_ends_with( $url['host'], $domain ) ) { return false; } @@ -213,7 +213,7 @@ class WP_Http_Cookie { } // Path - request path must start with path restriction. - if ( substr( $url['path'], 0, strlen( $path ) ) !== $path ) { + if ( ! str_starts_with( $url['path'], $path ) ) { return false; } diff --git a/wp-includes/deprecated.php b/wp-includes/deprecated.php index 750260ab56..36be77efdd 100644 --- a/wp-includes/deprecated.php +++ b/wp-includes/deprecated.php @@ -980,7 +980,7 @@ function get_links($category = -1, $before = '', $after = '
', $between = ' $title = $desc; if ( $show_updated ) - if (substr($row->link_updated_f, 0, 2) !== '00') + if ( !str_starts_with($row->link_updated_f, '00') ) $title .= ' ('.__('Last updated') . ' ' . gmdate(get_option('links_updated_date_format'), $row->link_updated_f + (get_option('gmt_offset') * HOUR_IN_SECONDS)) . ')'; if ( '' != $title ) diff --git a/wp-includes/kses.php b/wp-includes/kses.php index e33909ca7c..df9ae74b08 100644 --- a/wp-includes/kses.php +++ b/wp-includes/kses.php @@ -799,7 +799,7 @@ function wp_kses_one_attr( $attr, $element ) { $quote = $value[0]; } if ( '"' === $quote || "'" === $quote ) { - if ( substr( $value, -1 ) !== $quote ) { + if ( ! str_ends_with( $value, $quote ) ) { return ''; } $value = substr( $value, 1, -1 ); diff --git a/wp-includes/version.php b/wp-includes/version.php index 04ceb76707..0c7435b0f4 100644 --- a/wp-includes/version.php +++ b/wp-includes/version.php @@ -16,7 +16,7 @@ * * @global string $wp_version */ -$wp_version = '6.3-alpha-56019'; +$wp_version = '6.3-alpha-56020'; /** * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.