| @@ -24,27 +24,22 @@ | ||
| 24 | 24 | return 0 === strpos( $haystack, $needle ); |
| 25 | 25 | } |
| 26 | 26 | } |
| 27 | 27 | |
| 28 | -if ( ! function_exists( 'str_ends_with' ) ) { | |
| 28 | +if ( ! function_exists( 'is_countable' ) ) { | |
| 29 | 29 | /** |
| 30 | - * Polyfill for `str_ends_with()` function added in PHP 8.0. | |
| 30 | + * Polyfill for `is_countable()` function added in PHP 7.3. | |
| 31 | 31 | * |
| 32 | - * Performs a case-sensitive check indicating if | |
| 33 | - * the haystack ends with needle. | |
| 34 | - * | |
| 35 | - * @param string $haystack The string to search in. | |
| 36 | - * @param string $needle The substring to search for in the `$haystack`. | |
| 37 | - * | |
| 38 | - * @return bool True if `$haystack` ends with `$needle`, otherwise false. | |
| 32 | + * @param mixed $value The value to check. | |
| 33 | + * @return bool True if `$value` is countable, otherwise false. | |
| 39 | 34 | */ |
| 40 | - function str_ends_with( $haystack, $needle ) { | |
| 41 | - return strlen( $needle ) === 0 || substr( $haystack, - strlen( $needle ) ) === $needle; | |
| 35 | + function is_countable( $value ) { | |
| 36 | + return is_array( $value ) || $value instanceof \Countable; | |
| 42 | 37 | } |
| 43 | 38 | } |
| 44 | 39 | |
| 45 | 40 | /** |
| 46 | - * Polyfill for `array_is_list()` function added in PHP 8.1. | |
| 41 | + * Polyfill for `array_is_list()` function added in PHP 7.3. | |
| 47 | 42 | * |
| 48 | 43 | * @param array $array The array to check. |
| 49 | 44 | * |
| 50 | 45 | * @return bool True if `$array` is a list, otherwise false. |
| @@ -98,6 +93,19 @@ | ||
| 98 | 93 | return true; |
| 99 | 94 | } |
| 100 | 95 | |
| 101 | 96 | return false !== strpos( $haystack, $needle ); |
| 97 | + } | |
| 98 | +} | |
| 99 | + | |
| 100 | +if ( ! function_exists( 'wp_is_serving_rest_request' ) ) { | |
| 101 | + /** | |
| 102 | + * Polyfill for `wp_is_serving_rest_request()` function added in WordPress 6.5. | |
| 103 | + * | |
| 104 | + * @see https://developer.wordpress.org/reference/functions/wp_is_serving_rest_request/ | |
| 105 | + * | |
| 106 | + * @return bool True if it's a WordPress REST API request, false otherwise. | |
| 107 | + */ | |
| 108 | + function wp_is_serving_rest_request() { | |
| 109 | + return defined( 'REST_REQUEST' ) && REST_REQUEST; | |
| 102 | 110 | } |
| 103 | 111 | } |