diff --git a/includes/class-activitypub.php b/includes/class-activitypub.php index 01246a4..3ff7d13 100644 --- a/includes/class-activitypub.php +++ b/includes/class-activitypub.php @@ -24,6 +24,8 @@ class Activitypub { } \add_action( 'transition_post_status', array( '\Activitypub\Activitypub', 'schedule_post_activity' ), 10, 3 ); + \add_action( 'wp_trash_post', array( '\Activitypub\Activitypub', 'trash_post' ), 10 ); + \add_action( 'untrash_post', array( '\Activitypub\Activitypub', 'untrash_post' ), 10 ); } /** @@ -185,4 +187,26 @@ class Activitypub { } return \get_comment_meta( $comment->comment_ID, 'avatar_url', true ); } + + /** + * Store permalink in meta, to send delete Activity + * + * @param string $post_id The Post ID + * + * @return void + */ + public static function trash_post( $post_id ) { + \add_post_meta( $post_id, 'activitypub_canonical_url', \get_permalink( $post_id ) ); + } + + /** + * Delete permalink from meta + * + * @param string $post_id The Post ID + * + * @return void + */ + public static function untrash_post( $post_id ) { + \delete_post_meta( $post_id, 'activitypub_canonical_url' ); + } } diff --git a/includes/model/class-post.php b/includes/model/class-post.php index e885199..02b77fe 100644 --- a/includes/model/class-post.php +++ b/includes/model/class-post.php @@ -68,11 +68,16 @@ class Post { } public function generate_id() { - $post = $this->post; - $permalink = \get_permalink( $post ); + $post = $this->post; + + if ( 'trash' === get_post_status( $post ) ) { + $permalink = \get_post_meta( $post, 'activitypub_canonical_url', true ); + } else { + $permalink = \get_permalink( $post ); + } // replace 'trashed' for delete activity - return \str_replace( '__trashed', '', $permalink ); + return $permalink; } public function generate_attachments() {