Skip to content

Commit cd15158

Browse files
committed
Update follow return types and error handling
Changed the return type documentation for follow methods to only return WP_Post or WP_Error. Improved error handling in Following::follow by returning a WP_Error if adding to outbox fails.
1 parent 8239677 commit cd15158

File tree

2 files changed

+7
-3
lines changed

2 files changed

+7
-3
lines changed

includes/collection/class-following.php

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ class Following {
6060
* @param \WP_Post|int $post The ID of the remote Actor.
6161
* @param int $user_id The ID of the WordPress User.
6262
*
63-
* @return int|false|\WP_Post|\WP_Error The Outbox ID or false on failure, the Actor post or a WP_Error.
63+
* @return \WP_Post|\WP_Error The Actor post or a WP_Error.
6464
*/
6565
public static function follow( $post, $user_id ) {
6666
$post = \get_post( $post );
@@ -88,7 +88,11 @@ public static function follow( $post, $user_id ) {
8888
$follow->set_object( $post->guid );
8989
$follow->set_to( array( $post->guid ) );
9090

91-
return add_to_outbox( $follow, null, $user_id, ACTIVITYPUB_CONTENT_VISIBILITY_PRIVATE );
91+
$id = add_to_outbox( $follow, null, $user_id, ACTIVITYPUB_CONTENT_VISIBILITY_PRIVATE );
92+
93+
if ( ! $id ) {
94+
return new \WP_Error( 'activitypub_follow_failed', 'Failed to add follow to outbox' );
95+
}
9296
}
9397

9498
return $post;

includes/functions.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1545,7 +1545,7 @@ function add_to_outbox( $data, $activity_type = null, $user_id = 0, $content_vis
15451545
* @param string|int $remote_actor The Actor URL, WebFinger Resource or Post-ID of the remote Actor.
15461546
* @param int $user_id The ID of the WordPress User.
15471547
*
1548-
* @return int|false|\WP_Post|\WP_Error The Outbox ID or false on failure, the Actor post or a WP_Error.
1548+
* @return \WP_Post|\WP_Error The Actor post or a WP_Error.
15491549
*/
15501550
function follow( $remote_actor, $user_id ) {
15511551
if ( \is_numeric( $remote_actor ) ) {

0 commit comments

Comments
 (0)