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].

See #58220.
Built from https://develop.svn.wordpress.org/trunk@56019


git-svn-id: http://core.svn.wordpress.org/trunk@55531 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
Sergey Biryukov 2023-06-24 16:50:24 +00:00
parent b3eb7b301c
commit 32e94b4de1
6 changed files with 7 additions and 8 deletions

View File

@ -1461,7 +1461,7 @@ class WP_Query {
foreach ( $q['search_terms'] as $term ) {
// If there is an $exclusion_prefix, terms prefixed with it should be excluded.
$exclude = $exclusion_prefix && ( substr( $term, 0, 1 ) === $exclusion_prefix );
$exclude = $exclusion_prefix && str_starts_with( $term, $exclusion_prefix );
if ( $exclude ) {
$like_op = 'NOT LIKE';
$andor_op = 'AND';

View File

@ -947,7 +947,7 @@ function get_links($category = -1, $before = '', $after = '<br />', $between = '
_deprecated_function( __FUNCTION__, '2.1.0', 'get_bookmarks()' );
$order = 'ASC';
if ( substr($orderby, 0, 1) === '_' ) {
if ( str_starts_with($orderby, '_') ) {
$order = 'DESC';
$orderby = substr($orderby, 1);
}

View File

@ -3891,7 +3891,7 @@ function set_url_scheme( $url, $scheme = null ) {
}
$url = trim( $url );
if ( substr( $url, 0, 2 ) === '//' ) {
if ( str_starts_with( $url, '//' ) ) {
$url = 'http:' . $url;
}

View File

@ -401,13 +401,12 @@ function is_email_address_unsafe( $user_email ) {
continue;
}
if ( $email_domain == $banned_domain ) {
if ( $email_domain === $banned_domain ) {
$is_email_address_unsafe = true;
break;
}
$dotted_domain = ".$banned_domain";
if ( substr( $normalized_email, -strlen( $dotted_domain ) ) === $dotted_domain ) {
if ( str_ends_with( $normalized_email, ".$banned_domain" ) ) {
$is_email_address_unsafe = true;
break;
}

View File

@ -1137,7 +1137,7 @@ class WP_REST_Attachments_Controller extends WP_REST_Posts_Controller {
$filename = trim( $attributes['filename'] );
// Unquote quoted filename, but after trimming.
if ( substr( $filename, 0, 1 ) === '"' && substr( $filename, -1, 1 ) === '"' ) {
if ( str_starts_with( $filename, '"' ) && str_ends_with( $filename, '"' ) ) {
$filename = substr( $filename, 1, -1 );
}
}

View File

@ -16,7 +16,7 @@
*
* @global string $wp_version
*/
$wp_version = '6.3-alpha-56018';
$wp_version = '6.3-alpha-56019';
/**
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.