Make WordPress Core

Changeset 56014


Ignore:
Timestamp:
06/24/2023 09:50:34 AM (15 months ago)
Author:
SergeyBiryukov
Message:

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.

Location:
trunk/src
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-admin/plugin-editor.php

    r55412 r56014  
    163163}
    164164
    165 if ( '.php' === substr( $real_file, strrpos( $real_file, '.' ) ) ) {
     165if ( str_ends_with( $real_file, '.php' ) ) {
    166166    $functions = wp_doc_link_parse( $content );
    167167
  • trunk/src/wp-admin/theme-editor.php

    r55434 r56014  
    162162    $content = fread( $f, filesize( $file ) );
    163163
    164     if ( '.php' === substr( $file, strrpos( $file, '.' ) ) ) {
     164    if ( str_ends_with( $file, '.php' ) ) {
    165165        $functions = wp_doc_link_parse( $content );
    166166
  • trunk/src/wp-includes/class-wp-rewrite.php

    r55988 r56014  
    19081908        unset( $this->comment_feed_structure );
    19091909
    1910         $this->use_trailing_slashes = ( '/' === substr( $this->permalink_structure, -1, 1 ) );
     1910        $this->use_trailing_slashes = str_ends_with( $this->permalink_structure, '/' );
    19111911
    19121912        // Enable generic rules for pages if permalink structure doesn't begin with a wildcard.
  • trunk/src/wp-includes/load.php

    r55990 r56014  
    878878    foreach ( $active_plugins as $plugin ) {
    879879        if ( ! validate_file( $plugin )                     // $plugin must validate as file.
    880             && '.php' === substr( $plugin, -4 )             // $plugin must end with '.php'.
     880            && str_ends_with( $plugin, '.php' )             // $plugin must end with '.php'.
    881881            && file_exists( WP_PLUGIN_DIR . '/' . $plugin ) // $plugin must exist.
    882882            // Not already included as a network plugin.
  • trunk/src/wp-includes/rest-api.php

    r55703 r56014  
    468468        // nginx only allows HTTP/1.0 methods when redirecting from / to /index.php.
    469469        // To work around this, we manually add index.php to the URL, avoiding the redirect.
    470         if ( 'index.php' !== substr( $url, 9 ) ) {
     470        if ( ! str_ends_with( $url, 'index.php' ) ) {
    471471            $url .= 'index.php';
    472472        }
Note: See TracChangeset for help on using the changeset viewer.