[WIP] Register webfinger route
This commit is contained in:
parent
718c7c84a5
commit
f89dd048a4
@ -4,6 +4,7 @@ namespace init;
|
||||
require_once plugin_dir_path( __FILE__ ) . 'server/api.php';
|
||||
require_once plugin_dir_path( __FILE__ ) . 'server/actors.php';
|
||||
require_once plugin_dir_path( __FILE__ ) . 'migrations.php';
|
||||
require_once plugin_dir_path( __FILE__ ) . 'server/webfinger.php';
|
||||
|
||||
add_action( 'rest_api_init', function() {
|
||||
\api\register_routes();
|
||||
@ -21,4 +22,9 @@ add_action( 'pterotype_init', function() {
|
||||
add_action( 'pterotype_load', function() {
|
||||
\migrations\run_migrations();
|
||||
} );
|
||||
|
||||
add_action( 'generate_rewrite_rules', '\webfinger\generate_rewrite_rules', 111 );
|
||||
add_action( 'parse_request', '\webfinger\parse_request', 111 );
|
||||
add_filter( 'query_vars', '\webfinger\query_vars' );
|
||||
add_action( 'well_known_webfinger', '\webfinger\handle' );
|
||||
?>
|
||||
|
@ -68,6 +68,8 @@ function get_blog_actor() {
|
||||
null, sprintf( '/pterotype/v1/actor/%s/outbox', PTEROTYPE_BLOG_ACTOR_SLUG )
|
||||
),
|
||||
'name' => get_bloginfo( 'name' ),
|
||||
// TODO in the future, make this configurable, both here and in the Webfinger handler
|
||||
'preferredUsername' => 'blog',
|
||||
'summary' => get_bloginfo( 'description' ),
|
||||
'url' => network_site_url( '/' ),
|
||||
);
|
||||
|
29
includes/server/webfinger.php
Normal file
29
includes/server/webfinger.php
Normal file
@ -0,0 +1,29 @@
|
||||
<?php
|
||||
namespace webfinger;
|
||||
|
||||
function generate_rewrite_rules( $wp_rewrite ) {
|
||||
$dot_well_known = array(
|
||||
'.well-known/webfinger' => 'index.php?well-known=webfinger'
|
||||
);
|
||||
$wp_rewrite->rules = $dot_well_known + $wp_rewrite->rules;
|
||||
}
|
||||
|
||||
function parse_request( $req ) {
|
||||
if ( ! array_key_exists( 'well-known', $req->query_vars ) ) {
|
||||
return;
|
||||
}
|
||||
if ( $req->query_vars['well-known'] === 'webfinger' ) {
|
||||
do_action( 'well_known_webfinger', $req->query_vars );
|
||||
}
|
||||
}
|
||||
|
||||
function query_vars( $query_vars ) {
|
||||
$query_vars[] = 'well-known';
|
||||
return $query_vars;
|
||||
}
|
||||
|
||||
function handle( $query ) {
|
||||
echo var_dump( $query );
|
||||
exit;
|
||||
}
|
||||
?>
|
@ -8,9 +8,19 @@ define( 'PTEROTYPE_VERSION', '0.0.4' );
|
||||
|
||||
function pterotype_init() {
|
||||
do_action( 'pterotype_init' );
|
||||
flush_rewrite_rules();
|
||||
}
|
||||
|
||||
do_action( 'pterotype_load' );
|
||||
function pterotype_deactive() {
|
||||
do_action( 'pterotype_deactivate' );
|
||||
flush_rewrite_rules();
|
||||
}
|
||||
|
||||
register_activation_hook( __FILE__, 'pterotype_init');
|
||||
function pterotype_load() {
|
||||
do_action( 'pterotype_load' );
|
||||
}
|
||||
|
||||
add_action( 'plugins_loaded', 'pterotype_load' );
|
||||
register_activation_hook( __FILE__, 'pterotype_init' );
|
||||
register_deactivation_hook( __FILE__, 'pterotype_deactivate' );
|
||||
?>
|
||||
|
Loading…
Reference in New Issue
Block a user