mirror of
https://github.com/gosticks/wordpress-develop.git
synced 2026-08-12 04:40:26 +00:00
Code Modernization: Replace usage of strpos() with str_contains().
`str_contains()` was introduced in PHP 8.0 to perform a case-sensitive check indicating if the string to search in (haystack) contains the given substring (needle). WordPress core includes a polyfill for `str_contains()` on PHP < 8.0 as of WordPress 5.9. This commit replaces `false !== strpos( ... )` with `str_contains()` in core files, making the code more readable and consistent, as well as better aligned with modern development practices. Follow-up to [52039], [52040], [52326], [55703], [55710], [55987]. Props Soean, spacedmonkey, costdev, dingo_d, azaozz, mikeschroder, flixos90, peterwilsoncc, SergeyBiryukov. Fixes #58206. git-svn-id: https://develop.svn.wordpress.org/trunk@55988 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
@@ -311,7 +311,7 @@ class WP_REST_Request implements ArrayAccess {
|
||||
}
|
||||
|
||||
$value = strtolower( $value );
|
||||
if ( false === strpos( $value, '/' ) ) {
|
||||
if ( ! str_contains( $value, '/' ) ) {
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
@@ -304,7 +304,7 @@ class WP_REST_Autosaves_Controller extends WP_REST_Revisions_Controller {
|
||||
$revisions = wp_get_post_revisions( $parent_id, array( 'check_enabled' => false ) );
|
||||
|
||||
foreach ( $revisions as $revision ) {
|
||||
if ( false !== strpos( $revision->post_name, "{$parent_id}-autosave" ) ) {
|
||||
if ( str_contains( $revision->post_name, "{$parent_id}-autosave" ) ) {
|
||||
$data = $this->prepare_item_for_response( $revision, $request );
|
||||
$response[] = $this->prepare_response_for_collection( $data );
|
||||
}
|
||||
|
||||
@@ -298,7 +298,7 @@ class WP_REST_Plugins_Controller extends WP_REST_Controller {
|
||||
);
|
||||
|
||||
if ( is_wp_error( $api ) ) {
|
||||
if ( false !== strpos( $api->get_error_message(), 'Plugin not found.' ) ) {
|
||||
if ( str_contains( $api->get_error_message(), 'Plugin not found.' ) ) {
|
||||
$api->add_data( array( 'status' => 404 ) );
|
||||
} else {
|
||||
$api->add_data( array( 'status' => 500 ) );
|
||||
@@ -809,7 +809,7 @@ class WP_REST_Plugins_Controller extends WP_REST_Controller {
|
||||
$matched_search = false;
|
||||
|
||||
foreach ( $item as $field ) {
|
||||
if ( is_string( $field ) && false !== strpos( strip_tags( $field ), $search ) ) {
|
||||
if ( is_string( $field ) && str_contains( strip_tags( $field ), $search ) ) {
|
||||
$matched_search = true;
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -1305,7 +1305,7 @@ class WP_REST_Users_Controller extends WP_REST_Controller {
|
||||
);
|
||||
}
|
||||
|
||||
if ( false !== strpos( $password, '\\' ) ) {
|
||||
if ( str_contains( $password, '\\' ) ) {
|
||||
return new WP_Error(
|
||||
'rest_user_invalid_password',
|
||||
sprintf(
|
||||
|
||||
Reference in New Issue
Block a user