Skip to content

Commit c221dae

Browse files
committed
store permalink in post meta for trashed posts
this should quick fix #16 without changing the permalink structure
1 parent bf0b51c commit c221dae

File tree

2 files changed

+32
-3
lines changed

2 files changed

+32
-3
lines changed

includes/class-activitypub.php

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ public static function init() {
2424
}
2525

2626
\add_action( 'transition_post_status', array( '\Activitypub\Activitypub', 'schedule_post_activity' ), 10, 3 );
27+
\add_action( 'wp_trash_post', array( '\Activitypub\Activitypub', 'trash_post' ), 10 );
28+
\add_action( 'untrash_post', array( '\Activitypub\Activitypub', 'untrash_post' ), 10 );
2729
}
2830

2931
/**
@@ -185,4 +187,26 @@ public static function get_avatar_url( $comment ) {
185187
}
186188
return \get_comment_meta( $comment->comment_ID, 'avatar_url', true );
187189
}
190+
191+
/**
192+
* Store permalink in meta, to send delete Activity
193+
*
194+
* @param string $post_id The Post ID
195+
*
196+
* @return void
197+
*/
198+
public static function trash_post( $post_id ) {
199+
\add_post_meta( $post_id, 'activitypub_canonical_url', \get_permalink( $post_id ) );
200+
}
201+
202+
/**
203+
* Delete permalink from meta
204+
*
205+
* @param string $post_id The Post ID
206+
*
207+
* @return void
208+
*/
209+
public static function untrash_post( $post_id ) {
210+
\delete_post_meta( $post_id, 'activitypub_canonical_url' );
211+
}
188212
}

includes/model/class-post.php

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -68,11 +68,16 @@ public function to_json() {
6868
}
6969

7070
public function generate_id() {
71-
$post = $this->post;
72-
$permalink = \get_permalink( $post );
71+
$post = $this->post;
72+
73+
if ( 'trash' === get_post_status( $post ) ) {
74+
$permalink = \get_post_meta( $post, 'activitypub_canonical_url', true );
75+
} else {
76+
$permalink = \get_permalink( $post );
77+
}
7378

7479
// replace 'trashed' for delete activity
75-
return \str_replace( '__trashed', '', $permalink );
80+
return $permalink;
7681
}
7782

7883
public function generate_attachments() {

0 commit comments

Comments
 (0)