diff --git a/includes/rest/class-collection.php b/includes/rest/class-collection.php index 3936d78..b29a090 100644 --- a/includes/rest/class-collection.php +++ b/includes/rest/class-collection.php @@ -5,8 +5,10 @@ use WP_REST_Server; use WP_REST_Response; use Activitypub\Transformer\Post; use Activitypub\Activity\Activity; +use Activitypub\Collection\Users as User_Collection; use function Activitypub\esc_hashtag; +use function Activitypub\is_single_user; use function Activitypub\get_rest_url_by_path; /** @@ -65,7 +67,13 @@ class Collection { */ public static function tags_get( $request ) { $user_id = $request->get_param( 'user_id' ); - $number = 4; + $user = User_Collection::get_by_various( $user_id ); + + if ( is_wp_error( $user ) ) { + return $user; + } + + $number = 4; $tags = \get_terms( array( @@ -82,7 +90,7 @@ class Collection { $response = array( '@context' => Activity::CONTEXT, - 'id' => get_rest_url_by_path( sprintf( 'users/%d/collections/tags', $user_id ) ), + 'id' => get_rest_url_by_path( sprintf( 'users/%d/collections/tags', $user->get__id() ) ), 'type' => 'Collection', 'totalItems' => count( $tags ), 'items' => array(), @@ -108,17 +116,32 @@ class Collection { */ public static function featured_get( $request ) { $user_id = $request->get_param( 'user_id' ); + $user = User_Collection::get_by_various( $user_id ); - $args = array( - 'post__in' => \get_option( 'sticky_posts' ), - 'ignore_sticky_posts' => 1, - ); - - if ( $user_id > 0 ) { - $args['author'] = $user_id; + if ( is_wp_error( $user ) ) { + return $user; } - $posts = \get_posts( $args ); + $sticky_posts = \get_option( 'sticky_posts' ); + + if ( ! is_single_user() && User_Collection::BLOG_USER_ID === $user->get__id() ) { + $posts = array(); + } elseif ( $sticky_posts ) { + $args = array( + 'post__in' => $sticky_posts, + 'ignore_sticky_posts' => 1, + 'orderby' => 'date', + 'order' => 'DESC', + ); + + if ( $user->get__id() > 0 ) { + $args['author'] = $user->get__id(); + } + + $posts = \get_posts( $args ); + } else { + $posts = array(); + } $response = array( '@context' => Activity::CONTEXT,