From dacbed6614cb1166421261af80fbd108a30b46f1 Mon Sep 17 00:00:00 2001 From: Eana Hufwe Date: Sat, 19 Nov 2022 16:01:16 -0800 Subject: [PATCH] Add Custom Post Type support to outbox API --- includes/rest/class-outbox.php | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/includes/rest/class-outbox.php b/includes/rest/class-outbox.php index 55bb523..ad38f8d 100644 --- a/includes/rest/class-outbox.php +++ b/includes/rest/class-outbox.php @@ -43,6 +43,7 @@ class Outbox { public static function user_outbox_get( $request ) { $user_id = $request->get_param( 'user_id' ); $author = \get_user_by( 'ID', $user_id ); + $post_types = \get_option( 'activitypub_support_post_types', array( 'post', 'page' ) ); if ( ! $author ) { return new \WP_Error( @@ -73,8 +74,11 @@ class Outbox { $json->type = 'OrderedCollectionPage'; $json->partOf = \get_rest_url( null, "/activitypub/1.0/users/$user_id/outbox" ); // phpcs:ignore - $count_posts = \wp_count_posts(); - $json->totalItems = \intval( $count_posts->publish ); // 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 + } $json->first = \add_query_arg( 'page', 1, $json->partOf ); // phpcs:ignore $json->last = \add_query_arg( 'page', \ceil ( $json->totalItems / 10 ), $json->partOf ); // phpcs:ignore @@ -89,7 +93,7 @@ class Outbox { 'posts_per_page' => 10, 'author' => $user_id, 'offset' => ( $page - 1 ) * 10, - 'post_type' => 'post', + 'post_type' => $post_types, ) );