Skip to content

Commit 69ba1c8

Browse files
committed
fix sticky posts endpoint
1 parent 6262030 commit 69ba1c8

File tree

1 file changed

+33
-10
lines changed

1 file changed

+33
-10
lines changed

includes/rest/class-collection.php

Lines changed: 33 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,10 @@
55
use WP_REST_Response;
66
use Activitypub\Transformer\Post;
77
use Activitypub\Activity\Activity;
8+
use Activitypub\Collection\Users as User_Collection;
89

910
use function Activitypub\esc_hashtag;
11+
use function Activitypub\is_single_user;
1012
use function Activitypub\get_rest_url_by_path;
1113

1214
/**
@@ -65,7 +67,13 @@ public static function register_routes() {
6567
*/
6668
public static function tags_get( $request ) {
6769
$user_id = $request->get_param( 'user_id' );
68-
$number = 4;
70+
$user = User_Collection::get_by_various( $user_id );
71+
72+
if ( is_wp_error( $user ) ) {
73+
return $user;
74+
}
75+
76+
$number = 4;
6977

7078
$tags = \get_terms(
7179
array(
@@ -82,7 +90,7 @@ public static function tags_get( $request ) {
8290

8391
$response = array(
8492
'@context' => Activity::CONTEXT,
85-
'id' => get_rest_url_by_path( sprintf( 'users/%d/collections/tags', $user_id ) ),
93+
'id' => get_rest_url_by_path( sprintf( 'users/%d/collections/tags', $user->get__id() ) ),
8694
'type' => 'Collection',
8795
'totalItems' => count( $tags ),
8896
'items' => array(),
@@ -108,17 +116,32 @@ public static function tags_get( $request ) {
108116
*/
109117
public static function featured_get( $request ) {
110118
$user_id = $request->get_param( 'user_id' );
119+
$user = User_Collection::get_by_various( $user_id );
111120

112-
$args = array(
113-
'post__in' => \get_option( 'sticky_posts' ),
114-
'ignore_sticky_posts' => 1,
115-
);
116-
117-
if ( $user_id > 0 ) {
118-
$args['author'] = $user_id;
121+
if ( is_wp_error( $user ) ) {
122+
return $user;
119123
}
120124

121-
$posts = \get_posts( $args );
125+
$sticky_posts = \get_option( 'sticky_posts' );
126+
127+
if ( ! is_single_user() && User_Collection::BLOG_USER_ID === $user->get__id() ) {
128+
$posts = array();
129+
} elseif ( $sticky_posts ) {
130+
$args = array(
131+
'post__in' => $sticky_posts,
132+
'ignore_sticky_posts' => 1,
133+
'orderby' => 'date',
134+
'order' => 'DESC',
135+
);
136+
137+
if ( $user->get__id() > 0 ) {
138+
$args['author'] = $user->get__id();
139+
}
140+
141+
$posts = \get_posts( $args );
142+
} else {
143+
$posts = array();
144+
}
122145

123146
$response = array(
124147
'@context' => Activity::CONTEXT,

0 commit comments

Comments
 (0)