Skip to content

Simplify return types for Following::follow() method #2092

@obenland

Description

@obenland

Problem

The Following::follow() method and related follow() function have overly complex return type signatures that make the code harder to understand and use reliably.

Current Return Types

Activitypub\Collection\Following::follow() method:

  • \WP_Error - when invalid actor or actor retrieval fails
  • int|false - from add_to_outbox() when successfully adding follow activity
  • \WP_Post - when user is already following the actor

Activitypub\follow() function:

  • @return int|false|\WP_Post|\WP_Error The Outbox ID or false on failure, the Actor post or a WP_Error.

Referenced Discussion

This issue was raised in PR #2086: #2086 (comment)

@obenland suggested: "Would it be possible to limit it to two types?" to simplify the return type complexity.

Proposed Solution

Standardize the return types to a maximum of two types (e.g., int|\WP_Error or bool|\WP_Error) to improve:

  • Code predictability
  • Error handling consistency
  • Developer experience when using these methods

Code References

This refactoring would make the codebase more maintainable and reduce confusion about expected return types.

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions