From 557d5ae7632686dd4cb49ac64334553fb2e4285b Mon Sep 17 00:00:00 2001 From: Matthias Pfefferle Date: Tue, 2 Oct 2018 22:16:47 +0200 Subject: [PATCH] updated inbox hooks --- includes/class-activitypub-inbox.php | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/includes/class-activitypub-inbox.php b/includes/class-activitypub-inbox.php index 2eccdf3..08e802f 100644 --- a/includes/class-activitypub-inbox.php +++ b/includes/class-activitypub-inbox.php @@ -13,7 +13,7 @@ class Activitypub_Inbox { 'activitypub/1.0', '/inbox', array( array( 'methods' => WP_REST_Server::EDITABLE, - 'callback' => array( 'Activitypub_Inbox', 'shared_inbox' ), + 'callback' => array( 'Activitypub_Inbox', 'global_inbox' ), ), ) ); @@ -35,13 +35,19 @@ class Activitypub_Inbox { $data = json_decode( $request->get_body(), true ); - do_action( 'activitypub_inbox', $data ); + $type = 'create'; + if ( ! empty( $data['type'] ) ) { + $type = strtolower( $data['type'] ); + } + + do_action( 'activitypub_inbox', $data, $author_id, $type ); + do_action( "activitypub_inbox_{$type}", $data, $author_id ); if ( ! is_array( $data ) || ! array_key_exists( 'type', $data ) ) { return new WP_Error( 'rest_invalid_data', __( 'Invalid payload', 'activitypub' ), array( 'status' => 422 ) ); } - return new WP_REST_Response(); + return new WP_REST_Response( null, 202 ); } /** @@ -51,7 +57,7 @@ class Activitypub_Inbox { * * @return WP_Error not yet implemented */ - public static function shared_inbox( $request ) { + public static function global_inbox( $request ) { // Create the response object return new WP_Error( 'rest_not_implemented', __( 'This method is not yet implemented', 'activitypub' ), array( 'status' => 501 ) ); }