PluginProbe
ActivityPub / 7.7.0
ActivityPub v7.7.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
← All changes | includes/compat.php +28 -12 2.1.17.7.0 View file →
@@ -1,7 +1,9 @@
1 1 <?php
2 2 /**
3 3 * ActivityPub implementation for WordPress/PHP functions either missing from older WordPress/PHP versions or not included by default.
4 + *
5 + * @package Activitypub
4 6 */
5 7
6 8 if ( ! function_exists( 'str_starts_with' ) ) {
7 9 /**
@@ -22,18 +24,22 @@
22 24 return 0 === strpos( $haystack, $needle );
23 25 }
24 26 }
25 27
26 -if ( ! function_exists( 'get_self_link' ) ) {
28 +if ( ! function_exists( 'str_ends_with' ) ) {
27 29 /**
28 - * Returns the link for the currently displayed feed.
30 + * Polyfill for `str_ends_with()` function added in PHP 8.0.
29 31 *
30 - * @return string Correct link for the atom:self element.
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.
31 39 */
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 ) ) );
40 + function str_ends_with( $haystack, $needle ) {
41 + return strlen( $needle ) === 0 || substr( $haystack, - strlen( $needle ) ) === $needle;
36 42 }
37 43 }
38 44
39 45 if ( ! function_exists( 'is_countable' ) ) {
@@ -43,9 +49,9 @@
43 49 * @param mixed $value The value to check.
44 50 * @return bool True if `$value` is countable, otherwise false.
45 51 */
46 52 function is_countable( $value ) {
47 - return is_array( $value ) || $value instanceof \Countable;
53 + return is_array( $value ) || $value instanceof Countable;
48 54 }
49 55 }
50 56
51 57 /**
@@ -55,20 +61,30 @@
55 61 *
56 62 * @return bool True if `$array` is a list, otherwise false.
57 63 */
58 64 if ( ! function_exists( 'array_is_list' ) ) {
59 - function array_is_list( $array ) {
60 - if ( ! is_array( $array ) ) {
65 + /**
66 + * Check if an array is a list.
67 + *
68 + * An array is considered a list if its keys are a range of numbers
69 + * starting from 0 and ending at count( $array ) - 1.
70 + *
71 + * @param array $input The array to check.
72 + *
73 + * @return bool True if `$input` is a list, otherwise false.
74 + */
75 + function array_is_list( $input ) {
76 + if ( ! is_array( $input ) ) {
61 77 return false;
62 78 }
63 79
64 - if ( array_values( $array ) === $array ) {
80 + if ( array_values( $input ) === $input ) {
65 81 return true;
66 82 }
67 83
68 84 $next_key = -1;
69 85
70 - foreach ( $array as $k => $v ) {
86 + foreach ( $input as $k => $v ) {
71 87 if ( ++$next_key !== $k ) {
72 88 return false;
73 89 }
74 90 }