store permalink in post meta for trashed posts
this should quick fix #16 without changing the permalink structure
This commit is contained in:
parent
bf0b51ceb3
commit
c221daef86
2 changed files with 32 additions and 3 deletions
|
@ -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' );
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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() {
|
||||
|
|
Loading…
Reference in a new issue