| 1 |
<?php |
| 2 |
/** |
| 3 |
* ActivityPub implementation for WordPress/PHP functions either missing from older WordPress/PHP versions or not included by default. |
| 4 |
*/ |
| 5 |
|
| 6 |
if ( ! function_exists( 'str_starts_with' ) ) { |
| 7 |
/** |
| 8 |
* Polyfill for `str_starts_with()` function added in PHP 8.0. |
| 9 |
* |
| 10 |
* Performs a case-sensitive check indicating if |
| 11 |
* the haystack begins with needle. |
| 12 |
* |
| 13 |
* @param string $haystack The string to search in. |
| 14 |
* @param string $needle The substring to search for in the `$haystack`. |
| 15 |
* @return bool True if `$haystack` starts with `$needle`, otherwise false. |
| 16 |
*/ |
| 17 |
function str_starts_with( $haystack, $needle ) { |
| 18 |
if ( '' === $needle ) { |
| 19 |
return true; |
| 20 |
} |
| 21 |
|
| 22 |
return 0 === strpos( $haystack, $needle ); |
| 23 |
} |
| 24 |
} |
| 25 |
|
| 26 |
if ( ! function_exists( 'get_self_link' ) ) { |
| 27 |
/** |
| 28 |
* Returns the link for the currently displayed feed. |
| 29 |
* |
| 30 |
* @return string Correct link for the atom:self element. |
| 31 |
*/ |
| 32 |
function get_self_link() { |
| 33 |
$host = wp_parse_url( home_url() ); |
| 34 |
$path = isset( $_SERVER['REQUEST_URI'] ) ? sanitize_text_field( wp_unslash( $_SERVER['REQUEST_URI'] ) ) : ''; |
| 35 |
return esc_url( apply_filters( 'self_link', set_url_scheme( 'http://' . $host['host'] . $path ) ) ); |
| 36 |
} |
| 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 |
|