fix sticky posts endpoint
Some checks failed
PHP_CodeSniffer / phpcs (push) Failing after 2s
Unit Testing / phpunit (5.6, 6.2) (push) Failing after 2s
Unit Testing / phpunit (7.0) (push) Failing after 2s
Unit Testing / phpunit (7.2) (push) Failing after 2s
Unit Testing / phpunit (7.3) (push) Failing after 3s
Unit Testing / phpunit (7.4) (push) Failing after 2s
Unit Testing / phpunit (8.0) (push) Failing after 3s
Unit Testing / phpunit (8.1) (push) Failing after 2s
Unit Testing / phpunit (8.2) (push) Failing after 3s
Unit Testing / phpunit (latest) (push) Failing after 2s
Plugin asset/readme update / Push to master (push) Failing after 18s

This commit is contained in:
Matthias Pfefferle 2023-08-11 11:16:06 +02:00
parent 626203002a
commit 69ba1c87e1

View file

@ -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,