parent
122461ab6e
commit
c24966d683
3 changed files with 33 additions and 11 deletions
|
@ -15,7 +15,7 @@ class Activity_Dispatcher {
|
|||
public static function init() {
|
||||
\add_action( 'activitypub_send_post_activity', array( '\Activitypub\Activity_Dispatcher', 'send_post_activity' ) );
|
||||
\add_action( 'activitypub_send_update_activity', array( '\Activitypub\Activity_Dispatcher', 'send_update_activity' ) );
|
||||
// \add_action( 'activitypub_send_delete_activity', array( '\Activitypub\Activity_Dispatcher', 'send_delete_activity' ) );
|
||||
\add_action( 'activitypub_send_delete_activity', array( '\Activitypub\Activity_Dispatcher', 'send_delete_activity' ) );
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -23,8 +23,15 @@ class Activity_Dispatcher {
|
|||
*
|
||||
* @param int $post_id
|
||||
*/
|
||||
public static function send_post_activity( $post_id ) {
|
||||
$post = \get_post( $post_id );
|
||||
public static function send_post_activity( $post ) {
|
||||
if ( \is_object( $post ) ) {
|
||||
$post_id = $post->ID;
|
||||
} else {
|
||||
$post_id = $post;
|
||||
}
|
||||
|
||||
// get latest version of post
|
||||
$post = \get_post( $post );
|
||||
$user_id = $post->post_author;
|
||||
|
||||
$activitypub_post = new \Activitypub\Model\Post( $post );
|
||||
|
@ -44,8 +51,15 @@ class Activity_Dispatcher {
|
|||
*
|
||||
* @param int $post_id
|
||||
*/
|
||||
public static function send_update_activity( $post_id ) {
|
||||
$post = \get_post( $post_id );
|
||||
public static function send_update_activity( $post ) {
|
||||
if ( \is_object( $post ) ) {
|
||||
$post_id = $post->ID;
|
||||
} else {
|
||||
$post_id = $post;
|
||||
}
|
||||
|
||||
// get latest version of post
|
||||
$post = \get_post( $post );
|
||||
$user_id = $post->post_author;
|
||||
|
||||
$activitypub_post = new \Activitypub\Model\Post( $post );
|
||||
|
@ -65,8 +79,7 @@ class Activity_Dispatcher {
|
|||
*
|
||||
* @param int $post_id
|
||||
*/
|
||||
public static function send_delete_activity( $post_id ) {
|
||||
$post = \get_post( $post_id );
|
||||
public static function send_delete_activity( $post ) {
|
||||
$user_id = $post->post_author;
|
||||
|
||||
$activitypub_post = new \Activitypub\Model\Post( $post );
|
||||
|
|
|
@ -113,11 +113,11 @@ class Activitypub {
|
|||
}
|
||||
|
||||
if ( 'publish' === $new_status && 'publish' !== $old_status ) {
|
||||
\wp_schedule_single_event( \time(), 'activitypub_send_post_activity', array( $post->ID ) );
|
||||
\wp_schedule_single_event( \time(), 'activitypub_send_post_activity', array( $post ) );
|
||||
} elseif ( 'publish' === $new_status ) {
|
||||
\wp_schedule_single_event( \time(), 'activitypub_send_update_activity', array( $post->ID ) );
|
||||
\wp_schedule_single_event( \time(), 'activitypub_send_update_activity', array( $post ) );
|
||||
} elseif ( 'trash' === $new_status ) {
|
||||
\wp_schedule_single_event( \time(), 'activitypub_send_delete_activity', array( \get_permalink( $post ) ) );
|
||||
\wp_schedule_single_event( \time(), 'activitypub_send_delete_activity', array( $post ) );
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -33,7 +33,7 @@ class Post {
|
|||
$post = $this->post;
|
||||
|
||||
$array = array(
|
||||
'id' => \get_permalink( $post ),
|
||||
'id' => $this->get_permalink(),
|
||||
'type' => $this->get_object_type(),
|
||||
'published' => \date( 'Y-m-d\TH:i:s\Z', \strtotime( $post->post_date ) ),
|
||||
'attributedTo' => \get_author_posts_url( $post->post_author ),
|
||||
|
@ -56,6 +56,15 @@ class Post {
|
|||
return \wp_json_encode( $this->to_array(), \JSON_HEX_TAG | \JSON_HEX_AMP | \JSON_HEX_QUOT );
|
||||
}
|
||||
|
||||
public function get_permalink() {
|
||||
$post = $this->post;
|
||||
|
||||
$permalink = \get_permalink( $post );
|
||||
|
||||
// replace 'trashed' for delete activity
|
||||
return \str_replace( '__trashed', '', $permalink );
|
||||
}
|
||||
|
||||
public function get_attachments() {
|
||||
$max_images = \apply_filters( 'activitypub_max_images', 3 );
|
||||
|
||||
|
|
Loading…
Reference in a new issue