add backward compatibility support (#489)
This commit is contained in:
parent
c9fa9b8d33
commit
cbb5570a1b
3 changed files with 38 additions and 13 deletions
|
@ -17,6 +17,7 @@ namespace Activitypub;
|
||||||
|
|
||||||
use function Activitypub\site_supports_blocks;
|
use function Activitypub\site_supports_blocks;
|
||||||
|
|
||||||
|
require_once __DIR__ . '/includes/compat.php';
|
||||||
require_once __DIR__ . '/includes/functions.php';
|
require_once __DIR__ . '/includes/functions.php';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
37
includes/compat.php
Normal file
37
includes/compat.php
Normal file
|
@ -0,0 +1,37 @@
|
||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* ActivityPub implementation for WordPress/PHP functions either missing from older WordPress/PHP versions or not included by default.
|
||||||
|
*/
|
||||||
|
|
||||||
|
if ( ! function_exists( 'str_starts_with' ) ) {
|
||||||
|
/**
|
||||||
|
* Polyfill for `str_starts_with()` function added in PHP 8.0.
|
||||||
|
*
|
||||||
|
* Performs a case-sensitive check indicating if
|
||||||
|
* the haystack begins with needle.
|
||||||
|
*
|
||||||
|
* @param string $haystack The string to search in.
|
||||||
|
* @param string $needle The substring to search for in the `$haystack`.
|
||||||
|
* @return bool True if `$haystack` starts with `$needle`, otherwise false.
|
||||||
|
*/
|
||||||
|
function str_starts_with( $haystack, $needle ) {
|
||||||
|
if ( '' === $needle ) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0 === strpos( $haystack, $needle );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( ! function_exists( 'get_self_link' ) ) {
|
||||||
|
/**
|
||||||
|
* Returns the link for the currently displayed feed.
|
||||||
|
*
|
||||||
|
* @return string Correct link for the atom:self element.
|
||||||
|
*/
|
||||||
|
function get_self_link() {
|
||||||
|
$host = wp_parse_url( home_url() );
|
||||||
|
$path = isset( $_SERVER['REQUEST_URI'] ) ? sanitize_text_field( wp_unslash( $_SERVER['REQUEST_URI'] ) ) : '';
|
||||||
|
return esc_url( apply_filters( 'self_link', set_url_scheme( 'http://' . $host['host'] . $path ) ) );
|
||||||
|
}
|
||||||
|
}
|
|
@ -439,19 +439,6 @@ function is_single_user() {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( ! function_exists( 'get_self_link' ) ) {
|
|
||||||
/**
|
|
||||||
* Returns the link for the currently displayed feed.
|
|
||||||
*
|
|
||||||
* @return string Correct link for the atom:self element.
|
|
||||||
*/
|
|
||||||
function get_self_link() {
|
|
||||||
$host = wp_parse_url( home_url() );
|
|
||||||
$path = isset( $_SERVER['REQUEST_URI'] ) ? sanitize_text_field( wp_unslash( $_SERVER['REQUEST_URI'] ) ) : '';
|
|
||||||
return esc_url( apply_filters( 'self_link', set_url_scheme( 'http://' . $host['host'] . $path ) ) );
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Check if a site supports the block editor.
|
* Check if a site supports the block editor.
|
||||||
*
|
*
|
||||||
|
|
Loading…
Reference in a new issue