diff --git a/wp-includes/compat.php b/wp-includes/compat.php index f0bdf07974..84e611faee 100644 --- a/wp-includes/compat.php +++ b/wp-includes/compat.php @@ -539,6 +539,48 @@ if ( ! function_exists( 'array_all' ) ) { } } +if ( ! function_exists( 'array_first' ) ) { + /** + * Polyfill for `array_first()` function added in PHP 8.5. + * + * Returns the first element of an array. + * + * @since 6.9.0 + * + * @param array $array The array to get the first element from. + * @return mixed|null The first element of the array, or null if the array is empty. + */ + function array_first( array $array ) { // phpcs:ignore Universal.NamingConventions.NoReservedKeywordParameterNames.arrayFound + if ( empty( $array ) ) { + return null; + } + + foreach ( $array as $value ) { + return $value; + } + } +} + +if ( ! function_exists( 'array_last' ) ) { + /** + * Polyfill for `array_last()` function added in PHP 8.5. + * + * Returns the last element of an array. + * + * @since 6.9.0 + * + * @param array $array The array to get the last element from. + * @return mixed|null The last element of the array, or null if the array is empty. + */ + function array_last( array $array ) { // phpcs:ignore Universal.NamingConventions.NoReservedKeywordParameterNames.arrayFound + if ( empty( $array ) ) { + return null; + } + + return $array[ array_key_last( $array ) ]; + } +} + // IMAGETYPE_AVIF constant is only defined in PHP 8.x or later. if ( ! defined( 'IMAGETYPE_AVIF' ) ) { define( 'IMAGETYPE_AVIF', 19 ); diff --git a/wp-includes/version.php b/wp-includes/version.php index 2f55d7808b..86820be505 100644 --- a/wp-includes/version.php +++ b/wp-includes/version.php @@ -16,7 +16,7 @@ * * @global string $wp_version */ -$wp_version = '6.9-alpha-60671'; +$wp_version = '6.9-alpha-60672'; /** * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.