PHP 8.1 compatibility (#533)
* PHP 8.1 compatibility * Update compat.php --------- Co-authored-by: Matthias Pfefferle <pfefferle@users.noreply.github.com>
This commit is contained in:
parent
8078512b8c
commit
53adfe6b80
5 changed files with 19 additions and 5 deletions
|
@ -35,3 +35,15 @@ if ( ! function_exists( 'get_self_link' ) ) {
|
||||||
return esc_url( apply_filters( 'self_link', set_url_scheme( 'http://' . $host['host'] . $path ) ) );
|
return esc_url( apply_filters( 'self_link', set_url_scheme( 'http://' . $host['host'] . $path ) ) );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ( ! function_exists( 'is_countable' ) ) {
|
||||||
|
/**
|
||||||
|
* Polyfill for `is_countable()` function added in PHP 7.3.
|
||||||
|
*
|
||||||
|
* @param mixed $value The value to check.
|
||||||
|
* @return bool True if `$value` is countable, otherwise false.
|
||||||
|
*/
|
||||||
|
function is_countable( $value ) {
|
||||||
|
return is_array( $value ) || $value instanceof \Countable;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -105,7 +105,7 @@ class Collection {
|
||||||
'@context' => Activity::CONTEXT,
|
'@context' => Activity::CONTEXT,
|
||||||
'id' => get_rest_url_by_path( sprintf( 'users/%d/collections/tags', $user->get__id() ) ),
|
'id' => get_rest_url_by_path( sprintf( 'users/%d/collections/tags', $user->get__id() ) ),
|
||||||
'type' => 'Collection',
|
'type' => 'Collection',
|
||||||
'totalItems' => count( $tags ),
|
'totalItems' => is_countable( $tags ) ? count( $tags ) : 0,
|
||||||
'items' => array(),
|
'items' => array(),
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@ -163,7 +163,7 @@ class Collection {
|
||||||
'@context' => Activity::CONTEXT,
|
'@context' => Activity::CONTEXT,
|
||||||
'id' => get_rest_url_by_path( sprintf( 'users/%d/collections/featured', $user_id ) ),
|
'id' => get_rest_url_by_path( sprintf( 'users/%d/collections/featured', $user_id ) ),
|
||||||
'type' => 'OrderedCollection',
|
'type' => 'OrderedCollection',
|
||||||
'totalItems' => count( $posts ),
|
'totalItems' => is_countable( $posts ) ? count( $posts ) : 0,
|
||||||
'orderedItems' => array(),
|
'orderedItems' => array(),
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
|
@ -75,7 +75,7 @@ class Following {
|
||||||
|
|
||||||
$items = apply_filters( 'activitypub_rest_following', array(), $user ); // phpcs:ignore
|
$items = apply_filters( 'activitypub_rest_following', array(), $user ); // phpcs:ignore
|
||||||
|
|
||||||
$json->totalItems = count( $items ); // phpcs:ignore
|
$json->totalItems = is_countable( $items ) ? count( $items ) : 0; // phpcs:ignore
|
||||||
$json->orderedItems = $items; // phpcs:ignore
|
$json->orderedItems = $items; // phpcs:ignore
|
||||||
|
|
||||||
$json->first = $json->partOf; // phpcs:ignore
|
$json->first = $json->partOf; // phpcs:ignore
|
||||||
|
|
|
@ -88,7 +88,7 @@ class Nodeinfo {
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
|
||||||
if ( is_array( $users ) ) {
|
if ( is_countable( $users ) ) {
|
||||||
$users = count( $users );
|
$users = count( $users );
|
||||||
} else {
|
} else {
|
||||||
$users = 1;
|
$users = 1;
|
||||||
|
@ -145,7 +145,7 @@ class Nodeinfo {
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
|
||||||
if ( is_array( $users ) ) {
|
if ( is_countable( $users ) ) {
|
||||||
$users = count( $users );
|
$users = count( $users );
|
||||||
} else {
|
} else {
|
||||||
$users = 1;
|
$users = 1;
|
||||||
|
|
|
@ -335,6 +335,8 @@ class Post {
|
||||||
return \ucfirst( \get_option( 'activitypub_object_type', 'note' ) );
|
return \ucfirst( \get_option( 'activitypub_object_type', 'note' ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Default to Article.
|
||||||
|
$object_type = 'Article';
|
||||||
$post_type = \get_post_type( $this->wp_post );
|
$post_type = \get_post_type( $this->wp_post );
|
||||||
switch ( $post_type ) {
|
switch ( $post_type ) {
|
||||||
case 'post':
|
case 'post':
|
||||||
|
|
Loading…
Reference in a new issue