Hook up /user endpoint
This commit is contained in:
parent
a8837a7290
commit
9233f7bc92
@ -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();
|
||||
} );
|
||||
?>
|
||||
|
@ -1,8 +1,8 @@
|
||||
<?php
|
||||
namespace actors;
|
||||
|
||||
function author_to_user( $authorID ) {
|
||||
$handle = get_the_author_meta( 'user_nicename', $authorID );
|
||||
function author_to_user( $user ) {
|
||||
$handle = get_the_author_meta( 'user_nicename', $user->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;
|
||||
}
|
||||
|
14
inc/api.php
14
inc/api.php
@ -1,16 +1,18 @@
|
||||
<?php
|
||||
include 'actors';
|
||||
namespace api;
|
||||
|
||||
require_once plugin_dir_path( __FILE__ ) . '/actors.php';
|
||||
|
||||
function get_user( $data ) {
|
||||
$handle = $data["handle"];
|
||||
$id = get_user_by( 'slug', $handle );
|
||||
return actors\author_to_user( $id );
|
||||
return \actors\author_to_user( $id );
|
||||
}
|
||||
|
||||
add_action( 'rest_api_init', function () {
|
||||
register_rest_route( 'activitypub/v1', '/user/(?P<handle>[A-Za-z0-9]+)', array(
|
||||
function register_routes() {
|
||||
register_rest_route( 'activitypub/v1', '/user/(?P<handle>[a-zA-Z0-9-]+)', array(
|
||||
'methods' => 'GET',
|
||||
'callback' => 'get_user',
|
||||
'callback' => __NAMESPACE__ . '\get_user',
|
||||
) );
|
||||
} );
|
||||
}
|
||||
?>
|
||||
|
Loading…
Reference in New Issue
Block a user