PluginProbe
ActivityPub / 2.3.0
ActivityPub v2.3.0
9.3.1 9.3.0 9.2.2 9.2.1 9.2.0 9.1.0 9.0.2 9.0.1 9.0.0 8.3.0 8.2.1 8.2.0 8.1.1 1.0.5 1.0.6 1.0.7 1.0.8 1.0.9 1.1.0 1.2.0 1.3.0 2.0.0 2.0.1 2.1.0 2.1.1 All 160 releases
activitypub / includes / compat.php

compat.php in ActivityPub 2.3.0, at includes/compat.php

100 lines 2.5 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
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
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 function array_is_list( $array ) {
60 if ( ! is_array( $array ) ) {
61 return false;
62 }
63
64 if ( array_values( $array ) === $array ) {
65 return true;
66 }
67
68 $next_key = -1;
69
70 foreach ( $array as $k => $v ) {
71 if ( ++$next_key !== $k ) {
72 return false;
73 }
74 }
75
76 return true;
77 }
78 }
79
80 if ( ! function_exists( 'str_contains' ) ) {
81 /**
82 * Polyfill for `str_contains()` function added in PHP 8.0.
83 *
84 * Performs a case-sensitive check indicating if needle is
85 * contained in haystack.
86 *
87 * @param string $haystack The string to search in.
88 * @param string $needle The substring to search for in the `$haystack`.
89 *
90 * @return bool True if `$needle` is in `$haystack`, otherwise false.
91 */
92 function str_contains( $haystack, $needle ) {
93 if ( '' === $needle ) {
94 return true;
95 }
96
97 return false !== strpos( $haystack, $needle );
98 }
99 }
100