Add Custom Post Type support to outbox API
This commit is contained in:
parent
a6657edd4a
commit
e48986dd99
1 changed files with 7 additions and 3 deletions
|
@ -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,
|
||||
)
|
||||
);
|
||||
|
||||
|
|
Loading…
Reference in a new issue