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
This commit is contained in:
Sergey Biryukov 2023-06-24 09:52:19 +00:00
parent 6628bb32a3
commit cded028e59
6 changed files with 6 additions and 6 deletions

View File

@ -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 ) ) {

View File

@ -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 ) ) {

View File

@ -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 ) ) {

View File

@ -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 ) )

View File

@ -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';
}

View File

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