| @@ -34,4 +34,67 @@ | ||
| 34 | 34 | $path = isset( $_SERVER['REQUEST_URI'] ) ? sanitize_text_field( wp_unslash( $_SERVER['REQUEST_URI'] ) ) : ''; |
| 35 | 35 | return esc_url( apply_filters( 'self_link', set_url_scheme( 'http://' . $host['host'] . $path ) ) ); |
| 36 | 36 | } |
| 37 | 37 | } |
| 38 | + | |
| 39 | +if ( ! function_exists( 'is_countable' ) ) { | |
| 40 | + /** | |
| 41 | + * Polyfill for `is_countable()` function added in PHP 7.3. | |
| 42 | + * | |
| 43 | + * @param mixed $value The value to check. | |
| 44 | + * @return bool True if `$value` is countable, otherwise false. | |
| 45 | + */ | |
| 46 | + function is_countable( $value ) { | |
| 47 | + return is_array( $value ) || $value instanceof \Countable; | |
| 48 | + } | |
| 49 | +} | |
| 50 | + | |
| 51 | +/** | |
| 52 | + * Polyfill for `array_is_list()` function added in PHP 7.3. | |
| 53 | + * | |
| 54 | + * @param array $array The array to check. | |
| 55 | + * | |
| 56 | + * @return bool True if `$array` is a list, otherwise false. | |
| 57 | + */ | |
| 58 | +if ( ! function_exists( 'array_is_list' ) ) { | |
| 59 | + // phpcs:disable Universal.NamingConventions.NoReservedKeywordParameterNames.arrayFound | |
| 60 | + function array_is_list( $array ) { | |
| 61 | + if ( ! is_array( $array ) ) { | |
| 62 | + return false; | |
| 63 | + } | |
| 64 | + | |
| 65 | + if ( array_values( $array ) === $array ) { | |
| 66 | + return true; | |
| 67 | + } | |
| 68 | + | |
| 69 | + $next_key = -1; | |
| 70 | + | |
| 71 | + foreach ( $array as $k => $v ) { | |
| 72 | + if ( ++$next_key !== $k ) { | |
| 73 | + return false; | |
| 74 | + } | |
| 75 | + } | |
| 76 | + | |
| 77 | + return true; | |
| 78 | + } | |
| 79 | +} | |
| 80 | + | |
| 81 | +if ( ! function_exists( 'str_contains' ) ) { | |
| 82 | + /** | |
| 83 | + * Polyfill for `str_contains()` function added in PHP 8.0. | |
| 84 | + * | |
| 85 | + * Performs a case-sensitive check indicating if needle is | |
| 86 | + * contained in haystack. | |
| 87 | + * | |
| 88 | + * @param string $haystack The string to search in. | |
| 89 | + * @param string $needle The substring to search for in the `$haystack`. | |
| 90 | + * | |
| 91 | + * @return bool True if `$needle` is in `$haystack`, otherwise false. | |
| 92 | + */ | |
| 93 | + function str_contains( $haystack, $needle ) { | |
| 94 | + if ( '' === $needle ) { | |
| 95 | + return true; | |
| 96 | + } | |
| 97 | + | |
| 98 | + return false !== strpos( $haystack, $needle ); | |
| 99 | + } | |
| 100 | +} | |