diff --git a/includes/class-activity-dispatcher.php b/includes/class-activity-dispatcher.php index ab4bddd..bec4d48 100644 --- a/includes/class-activity-dispatcher.php +++ b/includes/class-activity-dispatcher.php @@ -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 ); diff --git a/includes/class-activitypub.php b/includes/class-activitypub.php index e3b63ee..6576d45 100644 --- a/includes/class-activitypub.php +++ b/includes/class-activitypub.php @@ -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 ) ); } } diff --git a/includes/model/class-post.php b/includes/model/class-post.php index 8b9fa65..d26a26f 100644 --- a/includes/model/class-post.php +++ b/includes/model/class-post.php @@ -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 );