Skip to content

Commit cbb5570

Browse files
authored
add backward compatibility support (#489)
1 parent c9fa9b8 commit cbb5570

File tree

3 files changed

+38
-13
lines changed

3 files changed

+38
-13
lines changed

activitypub.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717

1818
use function Activitypub\site_supports_blocks;
1919

20+
require_once __DIR__ . '/includes/compat.php';
2021
require_once __DIR__ . '/includes/functions.php';
2122

2223
/**

includes/compat.php

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
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+
}

includes/functions.php

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -439,19 +439,6 @@ function is_single_user() {
439439
return false;
440440
}
441441

442-
if ( ! function_exists( 'get_self_link' ) ) {
443-
/**
444-
* Returns the link for the currently displayed feed.
445-
*
446-
* @return string Correct link for the atom:self element.
447-
*/
448-
function get_self_link() {
449-
$host = wp_parse_url( home_url() );
450-
$path = isset( $_SERVER['REQUEST_URI'] ) ? sanitize_text_field( wp_unslash( $_SERVER['REQUEST_URI'] ) ) : '';
451-
return esc_url( apply_filters( 'self_link', set_url_scheme( 'http://' . $host['host'] . $path ) ) );
452-
}
453-
}
454-
455442
/**
456443
* Check if a site supports the block editor.
457444
*

0 commit comments

Comments
 (0)