| 1 |
<?php |
| 2 |
/** |
| 3 |
* Polyfills for PHP 8 string helpers when running on PHP 7.4. |
| 4 |
* WordPress core also defines these when missing; this file is a no-op if they already exist. |
| 5 |
*/ |
| 6 |
|
| 7 |
if (!function_exists('str_contains')) { |
| 8 |
/** |
| 9 |
* @param string $haystack |
| 10 |
* @param string $needle |
| 11 |
*/ |
| 12 |
function str_contains($haystack, $needle) |
| 13 |
{ |
| 14 |
if ($needle === '') { |
| 15 |
return true; |
| 16 |
} |
| 17 |
|
| 18 |
return strpos((string) $haystack, (string) $needle) !== false; |
| 19 |
} |
| 20 |
} |
| 21 |
|
| 22 |
if (!function_exists('str_starts_with')) { |
| 23 |
/** |
| 24 |
* @param string $haystack |
| 25 |
* @param string $needle |
| 26 |
*/ |
| 27 |
function str_starts_with($haystack, $needle) |
| 28 |
{ |
| 29 |
if ($needle === '') { |
| 30 |
return true; |
| 31 |
} |
| 32 |
|
| 33 |
return strncmp((string) $haystack, (string) $needle, strlen((string) $needle)) === 0; |
| 34 |
} |
| 35 |
} |
| 36 |
|