Make WordPress Core

Changeset 55994


Ignore:
Timestamp:
06/23/2023 12:15:06 PM (13 months ago)
Author:
SergeyBiryukov
Message:

Database: Replace str_contains() and str_ends_with() usage in wpdb methods.

This avoids fatal errors on PHP < 8.0 if the file is included directly outside of WordPress core, e.g. by HyperDB.

While WordPress core does include polyfills for these functions, they are not directly loaded in the wpdb class.

Follow-up to [54384], [55157], [55158], [55988], [55990].

Props dd32, ryelle, joedolson.
See #58206.

Location:
trunk/src
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-admin/load-styles.php

    r55710 r55994  
    7474    $content = get_file( $path ) . "\n";
    7575
    76     // str_starts_with() is not used here, as wp-includes/compat.php is not loaded in this file.
     76    // Note: str_starts_with() is not used here, as wp-includes/compat.php is not loaded in this file.
    7777    if ( 0 === strpos( $style->src, '/' . WPINC . '/css/' ) ) {
    7878        $content = str_replace( '../images/', '../' . WPINC . '/images/', $content );
  • trunk/src/wp-includes/class-wpdb.php

    r55990 r55994  
    14971497        }
    14981498
    1499         // This is not meant to be foolproof -- but it will catch obviously incorrect usage.
    1500         if ( ! str_contains( $query, '%' ) ) {
     1499        /*
     1500         * This is not meant to be foolproof -- but it will catch obviously incorrect usage.
     1501         *
     1502         * Note: str_contains() is not used here, as this file can be included
     1503         * directly outside of WordPress core, e.g. by HyperDB, in which case
     1504         * the polyfills from wp-includes/compat.php are not loaded.
     1505         */
     1506        if ( false === strpos( $query, '%' ) ) {
    15011507            wp_load_translations_early();
    15021508            _doing_it_wrong(
     
    15651571
    15661572            if ( 'f' === $type && true === $this->allow_unsafe_unquoted_parameters
    1567                 && str_ends_with( $split_query[ $key - 1 ], '%' )
     1573                /*
     1574                 * Note: str_ends_with() is not used here, as this file can be included
     1575                 * directly outside of WordPress core, e.g. by HyperDB, in which case
     1576                 * the polyfills from wp-includes/compat.php are not loaded.
     1577                 */
     1578                && '%' === substr( $split_query[ $key - 1 ], -1, 1 )
    15681579            ) {
    15691580
     
    16261637                     */
    16271638                    if ( true !== $this->allow_unsafe_unquoted_parameters
    1628                         || ( '' === $format && ! str_ends_with( $split_query[ $key - 1 ], '%' ) )
     1639                        /*
     1640                         * Note: str_ends_with() is not used here, as this file can be included
     1641                         * directly outside of WordPress core, e.g. by HyperDB, in which case
     1642                         * the polyfills from wp-includes/compat.php are not loaded.
     1643                         */
     1644                        || ( '' === $format && '%' !== substr( $split_query[ $key - 1 ], -1, 1 ) )
    16291645                    ) {
    16301646                        $placeholder = "'%" . $format . "s'";
     
    40394055        $db_server_info = $this->db_server_info();
    40404056
    4041         // Account for MariaDB version being prefixed with '5.5.5-' on older PHP versions.
    4042         if ( '5.5.5' === $db_version && str_contains( $db_server_info, 'MariaDB' )
     4057        /*
     4058         * Account for MariaDB version being prefixed with '5.5.5-' on older PHP versions.
     4059         *
     4060         * Note: str_contains() is not used here, as this file can be included
     4061         * directly outside of WordPress core, e.g. by HyperDB, in which case
     4062         * the polyfills from wp-includes/compat.php are not loaded.
     4063         */
     4064        if ( '5.5.5' === $db_version && false !== strpos( $db_server_info, 'MariaDB' )
    40434065            && PHP_VERSION_ID < 80016 // PHP 8.0.15 or older.
    40444066        ) {
     
    40684090                 * libmysql has supported utf8mb4 since 5.5.3, same as the MySQL server.
    40694091                 * mysqlnd has supported utf8mb4 since 5.0.9.
     4092                 *
     4093                 * Note: str_contains() is not used here, as this file can be included
     4094                 * directly outside of WordPress core, e.g. by HyperDB, in which case
     4095                 * the polyfills from wp-includes/compat.php are not loaded.
    40704096                 */
    4071                 if ( str_contains( $client_version, 'mysqlnd' ) ) {
     4097                if ( false !== strpos( $client_version, 'mysqlnd' ) ) {
    40724098                    $client_version = preg_replace( '/^\D+([\d.]+).*/', '$1', $client_version );
    40734099                    return version_compare( $client_version, '5.0.9', '>=' );
Note: See TracChangeset for help on using the changeset viewer.