From cded028e59bd5e5d23fbf8a73b61801109fb4571 Mon Sep 17 00:00:00 2001 From: Sergey Biryukov Date: Sat, 24 Jun 2023 09:52:19 +0000 Subject: [PATCH] Code Modernization: Use `str_ends_with()` in a few more places. `str_ends_with()` was introduced in PHP 8.0 to perform a case-sensitive check indicating if the string to search in (haystack) ends with the given substring (needle). WordPress core includes a polyfill for `str_ends_with()` on PHP < 8.0 as of WordPress 5.9. Follow-up to [55990]. See #58220. Built from https://develop.svn.wordpress.org/trunk@56014 git-svn-id: http://core.svn.wordpress.org/trunk@55526 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-admin/plugin-editor.php | 2 +- wp-admin/theme-editor.php | 2 +- wp-includes/class-wp-rewrite.php | 2 +- wp-includes/load.php | 2 +- wp-includes/rest-api.php | 2 +- wp-includes/version.php | 2 +- 6 files changed, 6 insertions(+), 6 deletions(-) diff --git a/wp-admin/plugin-editor.php b/wp-admin/plugin-editor.php index 78eac87f92..1b0b714c32 100644 --- a/wp-admin/plugin-editor.php +++ b/wp-admin/plugin-editor.php @@ -162,7 +162,7 @@ if ( ! empty( $posted_content ) ) { $content = file_get_contents( $real_file ); } -if ( '.php' === substr( $real_file, strrpos( $real_file, '.' ) ) ) { +if ( str_ends_with( $real_file, '.php' ) ) { $functions = wp_doc_link_parse( $content ); if ( ! empty( $functions ) ) { diff --git a/wp-admin/theme-editor.php b/wp-admin/theme-editor.php index 345d00017f..07de6269a7 100644 --- a/wp-admin/theme-editor.php +++ b/wp-admin/theme-editor.php @@ -161,7 +161,7 @@ if ( ! empty( $posted_content ) ) { $f = fopen( $file, 'r' ); $content = fread( $f, filesize( $file ) ); - if ( '.php' === substr( $file, strrpos( $file, '.' ) ) ) { + if ( str_ends_with( $file, '.php' ) ) { $functions = wp_doc_link_parse( $content ); if ( ! empty( $functions ) ) { diff --git a/wp-includes/class-wp-rewrite.php b/wp-includes/class-wp-rewrite.php index 35598c3d80..1963f21b0c 100644 --- a/wp-includes/class-wp-rewrite.php +++ b/wp-includes/class-wp-rewrite.php @@ -1907,7 +1907,7 @@ class WP_Rewrite { unset( $this->feed_structure ); unset( $this->comment_feed_structure ); - $this->use_trailing_slashes = ( '/' === substr( $this->permalink_structure, -1, 1 ) ); + $this->use_trailing_slashes = str_ends_with( $this->permalink_structure, '/' ); // Enable generic rules for pages if permalink structure doesn't begin with a wildcard. if ( preg_match( '/^[^%]*%(?:postname|category|tag|author)%/', $this->permalink_structure ) ) { diff --git a/wp-includes/load.php b/wp-includes/load.php index 6e7ab4cbcd..9d20aff3d7 100644 --- a/wp-includes/load.php +++ b/wp-includes/load.php @@ -877,7 +877,7 @@ function wp_get_active_and_valid_plugins() { foreach ( $active_plugins as $plugin ) { if ( ! validate_file( $plugin ) // $plugin must validate as file. - && '.php' === substr( $plugin, -4 ) // $plugin must end with '.php'. + && str_ends_with( $plugin, '.php' ) // $plugin must end with '.php'. && file_exists( WP_PLUGIN_DIR . '/' . $plugin ) // $plugin must exist. // Not already included as a network plugin. && ( ! $network_plugins || ! in_array( WP_PLUGIN_DIR . '/' . $plugin, $network_plugins, true ) ) diff --git a/wp-includes/rest-api.php b/wp-includes/rest-api.php index d9dd834c90..70dc9deec6 100644 --- a/wp-includes/rest-api.php +++ b/wp-includes/rest-api.php @@ -467,7 +467,7 @@ function get_rest_url( $blog_id = null, $path = '/', $scheme = 'rest' ) { $url = trailingslashit( get_home_url( $blog_id, '', $scheme ) ); // nginx only allows HTTP/1.0 methods when redirecting from / to /index.php. // To work around this, we manually add index.php to the URL, avoiding the redirect. - if ( 'index.php' !== substr( $url, 9 ) ) { + if ( ! str_ends_with( $url, 'index.php' ) ) { $url .= 'index.php'; } diff --git a/wp-includes/version.php b/wp-includes/version.php index e2541215c8..c41589188d 100644 --- a/wp-includes/version.php +++ b/wp-includes/version.php @@ -16,7 +16,7 @@ * * @global string $wp_version */ -$wp_version = '6.3-alpha-56013'; +$wp_version = '6.3-alpha-56014'; /** * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.