From ced8cd0e29c7e730777afd67c94e46ef07dfded0 Mon Sep 17 00:00:00 2001 From: Matthias Pfefferle Date: Thu, 29 Jun 2023 19:10:49 +0200 Subject: [PATCH] send activities for blog-wide user --- includes/class-scheduler.php | 26 +++++++++++++------------- includes/model/class-post.php | 10 +++++++++- 2 files changed, 22 insertions(+), 14 deletions(-) diff --git a/includes/class-scheduler.php b/includes/class-scheduler.php index 0349e44..94a74a8 100644 --- a/includes/class-scheduler.php +++ b/includes/class-scheduler.php @@ -68,35 +68,35 @@ class Scheduler { return; } - $activitypub_post = new Post( $post ); - - $activity_type = false; + $type = false; if ( 'publish' === $new_status && 'publish' !== $old_status ) { - $activity_type = 'Create'; + $type = 'Create'; } elseif ( 'publish' === $new_status ) { - $activity_type = 'Update'; + $type = 'Update'; } elseif ( 'trash' === $new_status ) { - $activity_type = 'Delete'; + $type = 'Delete'; } - if ( ! $activity_type ) { + if ( ! $type ) { return; } // send User activities - if ( ! is_user_disabled( $activitypub_post->get_user_id() ) ) { + if ( ! is_user_disabled( $post->post_author ) ) { + $activitypub_post = new Post( $post ); + \wp_schedule_single_event( \time(), 'activitypub_send_activity', - array( $activitypub_post, $activity_type ) + array( $activitypub_post, $type ) ); \wp_schedule_single_event( \time(), sprintf( 'activitypub_send_%s_activity', - \strtolower( $activity_type ) + \strtolower( $type ) ), array( $activitypub_post ) ); @@ -104,19 +104,19 @@ class Scheduler { // send Blog-User activities if ( ! is_user_disabled( User_Factory::BLOG_USER_ID ) ) { - $activitypub_post->set_post_author( User_Factory::BLOG_USER_ID ); + $activitypub_post = new Post( $post, User_Factory::BLOG_USER_ID ); \wp_schedule_single_event( \time(), 'activitypub_send_activity', - array( $activitypub_post, $activity_type ) + array( $activitypub_post, $type ) ); \wp_schedule_single_event( \time(), sprintf( 'activitypub_send_%s_activity', - \strtolower( $activity_type ) + \strtolower( $type ) ), array( $activitypub_post ) ); diff --git a/includes/model/class-post.php b/includes/model/class-post.php index 5004162..03199ff 100644 --- a/includes/model/class-post.php +++ b/includes/model/class-post.php @@ -147,9 +147,17 @@ class Post { * Constructor * * @param WP_Post $post + * @param int $post_author */ - public function __construct( $post ) { + public function __construct( $post, $post_author = null ) { $this->post = \get_post( $post ); + + if ( $post_author ) { + $this->post_author = $post_author; + } else { + $this->post_author = $this->post->post_author; + } + $path = sprintf( 'users/%d/followers', intval( $this->get_post_author() ) ); $this->add_to( get_rest_url_by_path( $path ) ); }