Skip to content

Conversation

@obenland
Copy link
Member

@obenland obenland commented Nov 20, 2025

Follow-up to 8798394 (#2500)

Proposed changes:

  • Return false after calling Update::handle_update() for existing comments/posts to prevent duplicate notifications via the activitypub_handled_create action
  • Rename $check_dupe to $existing_comment and $existing_post for improved code readability
  • Use instanceof \WP_Post instead of ! \is_wp_error() for more accurate type checking
  • Update docblocks to clarify that false is returned when duplicates are found
  • Fix comment from "If comment exists" to "If post exists" in create_post()

Other information:

  • Have you written new tests for your changes, if applicable?

Testing instructions:

  • Send duplicate Create activities for both comments and posts
  • Verify that Update::handle_update() is called
  • Confirm that no duplicate notifications are triggered (check that activitypub_handled_create action doesn't fire for duplicates)
  • Verify existing comments/posts are properly updated

Changelog entry

  • Automatically create a changelog entry from the details below.
Changelog Entry Details

Significance

  • Patch
  • Minor
  • Major

Type

  • Added - for new features
  • Changed - for changes in existing functionality
  • Deprecated - for soon-to-be removed features
  • Removed - for now removed features
  • Fixed - for any bug fixes
  • Security - in case of vulnerabilities

Message

Maintain consistent return values in Create handler.

Follow-up to commit 8798394 which replaced action hooks with direct method calls.

After calling Update::handle_update(), explicitly fetch and return fresh objects to maintain consistent return types and values across all code paths.

Additional improvements:
- Rename $check_dupe to $existing_comment and $existing_post for clarity
- Use instanceof check instead of !is_wp_error() for better type safety
- Fix comment and docblock accuracy in create_post()
Copilot AI review requested due to automatic review settings November 20, 2025 14:37
@obenland obenland self-assigned this Nov 20, 2025
@obenland obenland requested a review from a team November 20, 2025 14:37
Copilot finished reviewing on behalf of obenland November 20, 2025 14:38
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR improves the Create handler to maintain consistent return values and prevent duplicate notifications when processing duplicate ActivityPub Create activities. The changes ensure that when a duplicate comment or post is detected, Update::handle_update() is called to process it as an update, and the method returns false to prevent the activitypub_handled_create action from firing.

Key Changes:

  • Return false after calling Update::handle_update() for existing comments/posts to prevent duplicate notifications
  • Improve variable naming from $check_dupe to $existing_comment and $existing_post for better code clarity
  • Use instanceof \WP_Post instead of ! \is_wp_error() for more accurate type checking in create_post()

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

pfefferle
pfefferle previously approved these changes Nov 20, 2025
@obenland obenland merged commit e37af8d into trunk Nov 20, 2025
17 of 24 checks passed
@obenland obenland deleted the improve/create-handler-refactoring branch November 20, 2025 15:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants