From f3d2243afbb884fd408bf73a74389b3551df6fd0 Mon Sep 17 00:00:00 2001 From: Matthias Pfefferle Date: Fri, 7 Jul 2023 15:10:22 +0200 Subject: [PATCH] use `paged` instead of `offset` --- includes/rest/class-outbox.php | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/includes/rest/class-outbox.php b/includes/rest/class-outbox.php index 8485647..047ae22 100644 --- a/includes/rest/class-outbox.php +++ b/includes/rest/class-outbox.php @@ -61,7 +61,7 @@ class Outbox { $post_types = \get_option( 'activitypub_support_post_types', array( 'post', 'page' ) ); - $page = $request->get_param( 'page', 0 ); + $page = $request->get_param( 'page', 1 ); /* * Action triggerd prior to the ActivityPub profile being created and sent to the client @@ -78,9 +78,6 @@ class Outbox { $json->partOf = get_rest_url_by_path( sprintf( 'users/%d/outbox', $user_id ) ); // phpcs:ignore $json->totalItems = 0; // phpcs:ignore - // phpcs:ignore - $json->totalItems = 0; - foreach ( $post_types as $post_type ) { $count_posts = \wp_count_posts( $post_type ); $json->totalItems += \intval( $count_posts->publish ); // phpcs:ignore @@ -93,13 +90,17 @@ class Outbox { $json->next = \add_query_arg( 'page', $page + 1, $json->partOf ); // phpcs:ignore } + if ( $page && ( $page > 1 ) ) { // phpcs:ignore + $json->prev = \add_query_arg( 'page', $page - 1, $json->partOf ); // phpcs:ignore + } + if ( $page ) { $posts = \get_posts( array( 'posts_per_page' => 10, - 'author' => $user_id, - 'offset' => ( $page - 1 ) * 10, - 'post_type' => $post_types, + 'author' => $user_id, + 'paged' => $page, + 'post_type' => $post_types, ) ); @@ -139,6 +140,7 @@ class Outbox { $params['page'] = array( 'type' => 'integer', + 'default' => 1, ); $params['user_id'] = array(