post_author ); } /** * Schedules Activities for attachment transitions. * * @param int $post_id Attachment ID. */ public static function transition_attachment_status( $post_id ) { if ( \defined( 'WP_IMPORTING' ) && WP_IMPORTING ) { return; } if ( ! \post_type_supports( 'attachment', 'activitypub' ) ) { return; } if ( is_post_disabled( $post_id ) ) { return; } $post = \get_post( $post_id ); if ( ! $post instanceof \WP_Post ) { return; } switch ( \current_action() ) { case 'add_attachment': $type = 'Create'; break; case 'edit_attachment': $type = 'Update'; break; case 'delete_attachment': $type = 'Delete'; break; default: return; } add_to_outbox( $post, $type, $post->post_author ); } /** * Schedule an Add activity when a post is added to the featured collection. * * @param int $post_id The post ID. */ public static function schedule_featured_add( $post_id ) { self::schedule_featured_update( $post_id, 'Add' ); } /** * Schedule a Remove activity when a post is removed from the featured collection. * * @param int $post_id The post ID. */ public static function schedule_featured_remove( $post_id ) { self::schedule_featured_update( $post_id, 'Remove' ); } /** * Schedule an Add or Remove activity for the featured collection. * * When a post's sticky status changes, this sends an Add or Remove activity * to notify followers about the change to the actor's featured collection. * * @see https://github.com/Automattic/wordpress-activitypub/issues/2795 * * @param int $post_id The post ID. * @param string $activity_type The activity type ('Add' or 'Remove'). */ private static function schedule_featured_update( $post_id, $activity_type ) { if ( \defined( 'WP_IMPORTING' ) && WP_IMPORTING ) { return; } $post = \get_post( $post_id ); if ( ! $post ) { return; } if ( is_post_disabled( $post ) ) { return; } $actor = Actors::get_by_id( $post->post_author ); if ( ! $actor || \is_wp_error( $actor ) ) { return; } $activity = new Activity(); $activity->set_type( $activity_type ); $activity->set_actor( $actor->get_id() ); $activity->set_object( get_post_id( $post->ID ) ); $activity->set_target( $actor->get_featured() ); add_to_outbox( $activity, null, $post->post_author ); } }