diff --git a/wp-includes/compat.php b/wp-includes/compat.php index e64af9ab38..02eb4eb6dc 100644 --- a/wp-includes/compat.php +++ b/wp-includes/compat.php @@ -435,6 +435,49 @@ if ( ! function_exists( 'str_contains' ) ) { } } +if ( ! function_exists( 'str_starts_with' ) ) { + /** + * Polyfill for `str_starts_with()` function added in PHP 8.0. + * + * Performs a case-sensitive check indicating if + * the haystack begins with needle. + * + * @since 5.9.0 + * + * @param string $haystack The string to search in. + * @param string $needle The substring to search for in the `$haystack`. + * @return bool True if `$haystack` starts with `$needle`, otherwise false. + */ + function str_starts_with( $haystack, $needle ) { + if ( '' === $needle ) { + return true; + } + return 0 === strpos( $haystack, $needle ); + } +} + +if ( ! function_exists( 'str_ends_with' ) ) { + /** + * Polyfill for `str_ends_with()` function added in PHP 8.0. + * + * Performs a case-sensitive check indicating if + * the haystack ends with needle. + * + * @since 5.9.0 + * + * @param string $haystack The string to search in. + * @param string $needle The substring to search for in the `$haystack`. + * @return bool True if `$haystack` ends with `$needle`, otherwise false. + */ + function str_ends_with( $haystack, $needle ) { + if ( '' === $haystack && '' !== $needle ) { + return false; + } + $len = strlen( $needle ); + return 0 === substr_compare( $haystack, $needle, -$len, $len ); + } +} + // IMAGETYPE_WEBP constant is only defined in PHP 7.1 or later. if ( ! defined( 'IMAGETYPE_WEBP' ) ) { define( 'IMAGETYPE_WEBP', 18 ); diff --git a/wp-includes/version.php b/wp-includes/version.php index dc9ff5ae43..bc27eae6fb 100644 --- a/wp-includes/version.php +++ b/wp-includes/version.php @@ -16,7 +16,7 @@ * * @global string $wp_version */ -$wp_version = '5.9-alpha-52039'; +$wp_version = '5.9-alpha-52040'; /** * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.