* Performs a case-sensitive check indicating if
* the haystack begins with needle.
* @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 ) {
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.
* @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 ) {
$len = strlen( $needle );
return substr( $haystack, -$len, $len ) === $needle;
// IMAGETYPE_AVIF constant is only defined in PHP 8.x or later.
if ( ! defined( 'IMAGETYPE_AVIF' ) ) {
define( 'IMAGETYPE_AVIF', 19 );
// IMG_AVIF constant is only defined in PHP 8.x or later.
if ( ! defined( 'IMG_AVIF' ) ) {
define( 'IMG_AVIF', IMAGETYPE_AVIF );