From 9233f7bc920faf68c077088dc5b06b43f5a127c0 Mon Sep 17 00:00:00 2001 From: Jeremy Dormitzer Date: Tue, 21 Aug 2018 17:52:56 -0400 Subject: [PATCH] Hook up /user endpoint --- activitypub.php | 9 ++++----- inc/actors.php | 14 +++++++------- inc/api.php | 14 ++++++++------ 3 files changed, 19 insertions(+), 18 deletions(-) diff --git a/activitypub.php b/activitypub.php index 6c0f888..338181e 100644 --- a/activitypub.php +++ b/activitypub.php @@ -2,10 +2,9 @@ /* Plugin Name: ActivityPub */ +require_once plugin_dir_path( __FILE__ ) . 'inc/api.php'; -function post_published_activity( $ID, $post ) { - // TODO - $author = $post->post_author; -} -add_action( 'publish_post', 'post_published_activity', 10, 2 ); +add_action( 'rest_api_init', function() { + \api\register_routes(); +} ); ?> diff --git a/inc/actors.php b/inc/actors.php index fd74a11..4be04a3 100644 --- a/inc/actors.php +++ b/inc/actors.php @@ -1,8 +1,8 @@ get('ID')); $actor = array( "@context" => array( "https://www.w3.org/ns/activitystreams" ), "type" => "Person", @@ -12,11 +12,11 @@ function author_to_user( $authorID ) { "liked" => "TODO", // link to liked JSON "inbox" => "TODO", // link to inbox JSON "outbox" => "TODO", // link to outbox JSON - "preferredUsername": $handle, - "name": get_the_author_meta( 'display_name', $authorID ), - "summary": get_the_author_meta( 'description', $authorID ), - "icon": get_avatar_url ( $authorID ), - "url": get_the_author_meta( 'user_url', $authorID ), + "preferredUsername" => $handle, + "name" => get_the_author_meta( 'display_name', $user->get('ID') ), + "summary" => get_the_author_meta( 'description', $user->get('ID') ), + "icon" => get_avatar_url ( $user->get('ID') ), + "url" => get_the_author_meta( 'user_url', $user->get('ID') ), ); return $actor; } diff --git a/inc/api.php b/inc/api.php index 229df9e..eef6c83 100644 --- a/inc/api.php +++ b/inc/api.php @@ -1,16 +1,18 @@ [A-Za-z0-9]+)', array( +function register_routes() { + register_rest_route( 'activitypub/v1', '/user/(?P[a-zA-Z0-9-]+)', array( 'methods' => 'GET', - 'callback' => 'get_user', + 'callback' => __NAMESPACE__ . '\get_user', ) ); -} ); +} ?>