Skip to content
Merged
Show file tree
Hide file tree
Changes from 45 commits
Commits
Show all changes
47 commits
Select commit Hold shift + click to select a range
1e29453
Refactor notification system to use action hooks
pfefferle Sep 22, 2025
8488156
Update includes/handler/class-update.php
pfefferle Sep 22, 2025
ce5869e
Update includes/handler/class-accept.php
pfefferle Sep 22, 2025
f902344
Update integration/class-stream-connector.php
pfefferle Sep 22, 2025
6b10aa2
Refactor Accept handler to set $success before action
pfefferle Sep 22, 2025
c727a40
Align docblock param indentation in Stream_Connector
pfefferle Sep 22, 2025
60592c6
Add changelog
matticbot Sep 22, 2025
d4b35f9
Merge branch 'trunk' into change/deprecate-notifications
pfefferle Sep 22, 2025
8cdb9c9
Merge branch 'trunk' into change/deprecate-notifications
pfefferle Sep 22, 2025
52d2e12
Update Accept handler action parameters
pfefferle Sep 23, 2025
78714cf
Rename $reaction variable to $result in Announce handler
pfefferle Sep 23, 2025
5ad1d1b
Rename variable from reaction to result in Create handler
pfefferle Sep 23, 2025
7dbefe0
Update maybe_delete_follower return value and doc
pfefferle Sep 23, 2025
3602a89
Standardize action hook parameter types and names
pfefferle Sep 23, 2025
d7baeac
Fix duplicate parameter in do_action call
pfefferle Sep 23, 2025
d8671c5
Change move status default from null to false
pfefferle Sep 23, 2025
ca158dc
Add deprecation notices to ActivityPub actions
pfefferle Sep 23, 2025
c5ea0f3
Update includes/handler/class-accept.php
pfefferle Sep 23, 2025
ba09426
Update includes/handler/class-announce.php
pfefferle Sep 23, 2025
f9b7ec0
Update includes/handler/class-create.php
pfefferle Sep 23, 2025
0e59f0c
Update includes/handler/class-reject.php
pfefferle Sep 23, 2025
a881a53
Update includes/handler/class-undo.php
pfefferle Sep 23, 2025
4ce56c4
Update includes/handler/class-delete.php
pfefferle Sep 23, 2025
d17a84f
Update includes/handler/class-update.php
pfefferle Sep 23, 2025
653e703
Update includes/handler/class-delete.php
pfefferle Sep 23, 2025
41d7d33
Update includes/handler/class-follow.php
pfefferle Sep 23, 2025
6fb1953
Update includes/handler/class-update.php
pfefferle Sep 23, 2025
b6b0548
Update includes/handler/class-inbox.php
pfefferle Sep 23, 2025
7863f65
Update includes/handler/class-like.php
pfefferle Sep 23, 2025
4581f07
Refactor handler actions to use success flag and result
pfefferle Sep 24, 2025
2ed1715
Fix docblock formatting in Accept handler
pfefferle Sep 24, 2025
18db869
Clarify $success param in handler docblocks
pfefferle Sep 24, 2025
6622b09
Improve parameter docs and variable naming consistency
pfefferle Sep 24, 2025
b75a119
Refactor Undo handler and add object validation
pfefferle Sep 24, 2025
df7b974
Allow remove() to accept WP_Post or ID in Followers
pfefferle Sep 24, 2025
18be575
Add unit tests for Undo handler functionality
pfefferle Sep 24, 2025
0fd91bf
Refactor undo handler tests to use data providers
pfefferle Sep 24, 2025
8624bdc
Expand and refactor follow handler tests
pfefferle Sep 24, 2025
71185f2
Expand Like handler tests with new scenarios and hooks
pfefferle Sep 24, 2025
0e2069d
Refactor and expand handler tests with data providers
pfefferle Sep 24, 2025
4718038
Refactor get_type tests to use data provider
pfefferle Sep 24, 2025
141d895
Refactor inbox handler test with data provider
pfefferle Sep 24, 2025
c2556bb
Remove redundant @covers annotation in inbox test
pfefferle Sep 24, 2025
35e4395
Add integration tests for Stream Connector
pfefferle Sep 24, 2025
dfd7151
Add test for prepare_outbox_data_for_response with blog user URL
pfefferle Sep 24, 2025
7742452
Merge branch 'trunk' into change/deprecate-notifications
pfefferle Sep 24, 2025
0aa68c1
Merge branch 'trunk' into change/deprecate-notifications
pfefferle Sep 24, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .github/changelog/2223-from-description
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Significance: minor
Type: changed

Standardized notification handling with new hooks for better extensibility and consistency.
12 changes: 10 additions & 2 deletions includes/class-notification.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@

/**
* Notification class.
*
* @deprecated unreleased Use action hooks like 'activitypub_handled_{type}' instead.
*/
class Notification {
/**
Expand Down Expand Up @@ -48,6 +50,8 @@ class Notification {
* @param int $target The WordPress User-Id.
*/
public function __construct( $type, $actor, $activity, $target ) {
\_deprecated_class( __CLASS__, 'unreleased', 'Use action hooks like "activitypub_handled_{type}" instead.' );

$this->type = $type;
$this->actor = $actor;
$this->object = $activity;
Expand All @@ -63,15 +67,19 @@ public function send() {
/**
* Action to send ActivityPub notifications.
*
* @deprecated unreleased Use "activitypub_handled_{$type}" instead.
*
* @param Notification $instance The notification object.
*/
do_action( 'activitypub_notification', $this );
\do_action_deprecated( 'activitypub_notification', array( $this ), 'unreleased', "activitypub_handled_{$type}" );

/**
* Type-specific action to send ActivityPub notifications.
*
* @deprecated unreleased Use "activitypub_handled_{$type}" instead.
*
* @param Notification $instance The notification object.
*/
do_action( "activitypub_notification_{$type}", $this );
\do_action_deprecated( "activitypub_notification_{$type}", array( $this ), 'unreleased', "activitypub_handled_{$type}" );
}
}
10 changes: 5 additions & 5 deletions includes/collection/class-followers.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,13 +69,13 @@ public static function add_follower( $user_id, $actor ) {
/**
* Remove a Follower.
*
* @param int $post_id The ID of the remote Actor.
* @param int $user_id The ID of the WordPress User.
* @param \WP_Post|int $post_or_id The ID of the remote Actor.
* @param int $user_id The ID of the WordPress User.
*
* @return bool True on success, false on failure.
*/
public static function remove( $post_id, $user_id ) {
$post = \get_post( $post_id );
public static function remove( $post_or_id, $user_id ) {
$post = \get_post( $post_or_id );

if ( ! $post ) {
return false;
Expand All @@ -93,7 +93,7 @@ public static function remove( $post_id, $user_id ) {
*/
\do_action( 'activitypub_followers_pre_remove_follower', $post, $user_id, Remote_Actors::get_actor( $post ) );

return \delete_post_meta( $post_id, self::FOLLOWER_META_KEY, $user_id );
return \delete_post_meta( $post->ID, self::FOLLOWER_META_KEY, $user_id );
}

/**
Expand Down
2 changes: 1 addition & 1 deletion includes/collection/class-interactions.php
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ public static function update_comment( $activity ) {
*
* @param array $activity Activity array.
*
* @return array|false Comment data or `false` on failure.
* @return array|string|int|\WP_Error|false Comment data or `false` on failure.
*/
public static function add_reaction( $activity ) {
$url = object_to_uri( $activity['object'] );
Expand Down
38 changes: 14 additions & 24 deletions includes/handler/class-accept.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
use Activitypub\Collection\Following;
use Activitypub\Collection\Outbox;
use Activitypub\Collection\Remote_Actors;
use Activitypub\Notification;

use function Activitypub\object_to_uri;

Expand All @@ -22,19 +21,8 @@ class Accept {
* Initialize the class, registering WordPress hooks.
*/
public static function init() {
\add_action(
'activitypub_inbox_accept',
array( self::class, 'handle_accept' ),
10,
2
);

\add_filter(
'activitypub_validate_object',
array( self::class, 'validate_object' ),
10,
3
);
\add_action( 'activitypub_inbox_accept', array( self::class, 'handle_accept' ), 10, 2 );
\add_filter( 'activitypub_validate_object', array( self::class, 'validate_object' ), 10, 3 );
}

/**
Expand All @@ -60,16 +48,18 @@ public static function handle_accept( $accept, $user_id ) {
return;
}

Following::accept( $actor_post, $user_id );

// Send notification.
$notification = new Notification(
'accept',
$actor_post->guid,
$accept,
$user_id
);
$notification->send();
$result = Following::accept( $actor_post, $user_id );
$success = ! \is_wp_error( $result );

/**
* Fires after an ActivityPub Accept activity has been handled.
*
* @param array $accept The ActivityPub activity data.
* @param int $user_id The local user ID.
* @param bool $success True on success, false otherwise.
* @param \WP_Post|\WP_Error $result The remote actor post or error.
*/
\do_action( 'activitypub_handled_accept', $accept, $user_id, $success, $result );
}

/**
Expand Down
28 changes: 12 additions & 16 deletions includes/handler/class-announce.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,7 @@ class Announce {
* Initialize the class, registering WordPress hooks.
*/
public static function init() {
\add_action(
'activitypub_inbox_announce',
array( self::class, 'handle_announce' ),
10,
3
);
\add_action( 'activitypub_inbox_announce', array( self::class, 'handle_announce' ), 10, 3 );
}

/**
Expand Down Expand Up @@ -106,21 +101,22 @@ public static function maybe_save_announce( $activity, $user_id ) {
return;
}

$state = Interactions::add_reaction( $activity );
$reaction = null;
$success = false;
$result = Interactions::add_reaction( $activity );

if ( $state && ! is_wp_error( $state ) ) {
$reaction = get_comment( $state );
if ( $result && ! is_wp_error( $result ) ) {
$success = true;
$result = get_comment( $result );
}

/**
* Fires after an Announce has been saved.
* Fires after an ActivityPub Announce activity has been handled.
*
* @param array $activity The activity-object.
* @param int $user_id The id of the local blog-user.
* @param mixed $state The state of the reaction.
* @param mixed $reaction The reaction.
* @param array $activity The ActivityPub activity data.
* @param int $user_id The local user ID.
* @param bool $success True on success, false otherwise.
* @param array|string|int|\WP_Error|false $result The WP_Comment object of the created announce/repost comment, or null if creation failed.
*/
do_action( 'activitypub_handled_announce', $activity, $user_id, $state, $reaction );
\do_action( 'activitypub_handled_announce', $activity, $user_id, $success, $result );
}
}
36 changes: 13 additions & 23 deletions includes/handler/class-create.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,19 +22,8 @@ class Create {
* Initialize the class, registering WordPress hooks.
*/
public static function init() {
\add_action(
'activitypub_inbox_create',
array( self::class, 'handle_create' ),
10,
3
);

\add_filter(
'activitypub_validate_object',
array( self::class, 'validate_object' ),
10,
3
);
\add_action( 'activitypub_inbox_create', array( self::class, 'handle_create' ), 10, 3 );
\add_filter( 'activitypub_validate_object', array( self::class, 'validate_object' ), 10, 3 );
}

/**
Expand Down Expand Up @@ -72,22 +61,23 @@ public static function handle_create( $activity, $user_id, $activity_object = nu
return;
}

$state = Interactions::add_comment( $activity );
$reaction = null;
$success = false;
$result = Interactions::add_comment( $activity );

if ( $state && ! \is_wp_error( $state ) ) {
$reaction = \get_comment( $state );
if ( $result && ! \is_wp_error( $result ) ) {
$success = true;
$result = \get_comment( $result );
}

/**
* Fires after a Create activity has been handled.
* Fires after an ActivityPub Create activity has been handled.
*
* @param array $activity The activity-object.
* @param int $user_id The id of the local blog-user.
* @param \WP_Comment|\WP_Error $state The comment object or WP_Error.
* @param \WP_Comment|\WP_Error|null $reaction The reaction object or WP_Error.
* @param array $activity The ActivityPub activity data.
* @param int $user_id The local user ID.
* @param bool $success True on success, false otherwise.
* @param array|string|int|\WP_Error|false $result The WP_Comment object of the created comment, or null if creation failed.
*/
\do_action( 'activitypub_handled_create', $activity, $user_id, $state, $reaction );
\do_action( 'activitypub_handled_create', $activity, $user_id, $success, $result );
}

/**
Expand Down
Loading