Send an Update when blog details are updated

This commit is contained in:
Jeremy Dormitzer 2018-11-01 07:36:07 -04:00
parent f1e577fd01
commit 8d335bf3da
4 changed files with 46 additions and 6 deletions

View File

@ -0,0 +1,27 @@
<?php
namespace pterotype\identity;
require_once plugin_dir_path( __FILE__ ) . '../server/actors.php';
require_once plugin_dir_path( __FILE__ ) . '../server/activities/update.php';
function update_identity( $actor_slug ) {
$actor = \pterotype\actors\get_actor_by_slug( $actor_slug );
if ( ! $actor || is_wp_error( $actor ) ) {
return;
}
$update = \pterotype\activities\update\make_update( $actor_slug, $actor );
if ( ! $update || is_wp_error( $update ) ) {
return;
}
$update['to'] = array(
'https://www.w3.org/ns/activitystreams#Public',
$actor['followers']
);
$server = \rest_get_server();
$request = \WP_REST_Request::from_url( $actor['outbox'] );
$request->set_method( 'POST' );
$request->set_body( wp_json_encode( $update ) );
$request->add_header( 'Content-Type', 'application/ld+json' );
$server->dispatch( $request );
}
?>

View File

@ -8,6 +8,7 @@ require_once plugin_dir_path( __FILE__ ) . 'schema.php';
require_once plugin_dir_path( __FILE__ ) . 'server/webfinger.php';
require_once plugin_dir_path( __FILE__ ) . 'client/posts.php';
require_once plugin_dir_path( __FILE__ ) . 'client/comments.php';
require_once plugin_dir_path( __FILE__ ) . 'client/identity.php';
require_once plugin_dir_path( __FILE__ ) . 'server/async.php';
require_once plugin_dir_path( __FILE__ ) . 'pgp.php';
@ -51,4 +52,13 @@ add_action(
add_action( 'comment_post', '\pterotype\comments\handle_comment_post', 10, 2 );
add_action( 'edit_comment', '\pterotype\comments\handle_edit_comment', 10, 1 );
add_action( 'template_redirect', '\pterotype\api\handle_non_api_requests' );
add_action( 'update_option_blogname', function() {
\pterotype\identity\update_identity( PTEROTYPE_BLOG_ACTOR_SLUG );
});
add_action( 'update_option_blogdescription', function() {
\pterotype\identity\update_identity( PTEROTYPE_BLOG_ACTOR_SLUG );
});
add_action( 'update_option_site_icon', function() {
\pterotype\identity\update_identity( PTEROTYPE_BLOG_ACTOR_SLUG );
});
?>

View File

@ -37,10 +37,11 @@ function handle_activity( $actor_slug, $activity ) {
);
}
forward_activity( $actor_slug, $activity );
$activity = persist_activity( $actor_slug, $activity );
if ( is_wp_error( $activity ) ) {
return $activity;
$persisted = persist_activity( $actor_slug, $activity );
if ( is_wp_error( $persisted ) ) {
return $persisted;
}
$activity['id'] = $persisted['id'];
switch ( $activity['type'] ) {
case 'Create':
$activity = \pterotype\activities\create\handle_inbox( $actor_slug, $activity );

View File

@ -36,10 +36,12 @@ function handle_activity( $actor_slug, $activity ) {
array( 'status' => 400 )
);
}
$activity = persist_activity( $actor_slug, $activity );
if ( is_wp_error( $activity ) ) {
return $activity;
// Don't overwrite the activity to prevent compacting from deleting data
$persisted = persist_activity( $actor_slug, $activity );
if ( is_wp_error( $persisted ) ) {
return $persisted;
}
$activity['id'] = $persisted['id'];
switch ( $activity['type'] ) {
case 'Create':
$activity = \pterotype\activities\create\handle_outbox( $actor_slug, $activity );