Skip to content

Conversation

obenland
Copy link
Member

@obenland obenland commented Sep 19, 2025

I could have sworn there was a forum post asking for Web Push support. Well, I can't find it anymore.

Proposed changes:

  • Add new Perfecty Push integration class in /integration/class-perfecty-push.php
  • Hook into ActivityPub activitypub_handled_* events to send web push notifications
  • Support notifications for likes, reposts/boosts, comments, and new followers from the fediverse
  • Add individual notification settings for users and blog actors (all types enabled by default)
  • Include actor profile images in notifications with mp.jpg fallback for users without avatars
  • Integrate settings into existing user profile and blog profile admin pages

Other information:

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

Testing instructions:

  • Install and activate the Perfecty Push plugin from WordPress.org
  • Enable push notifications in browser when prompted by Perfecty Push
  • Go to user profile page and verify "Push Notifications" settings appear
  • Go to ActivityPub settings -> Blog Profile tab and verify "Push Notifications" settings appear
  • Configure notification preferences (likes, reposts/boosts, comments, new followers)
  • Have a fediverse account like, repost, comment on, or follow your ActivityPub account
  • Verify web push notifications are received with correct titles, messages, and actor images
  • Test that notification settings work independently for different users and blog actor

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

Add Perfecty Push integration for web push notifications on ActivityPub events

- Add new integration class for Perfecty Push plugin compatibility
- Hook into ActivityPub events (likes, announces, creates, follows) via activitypub_handled_* actions
- Add per-user and blog actor notification settings with UI in profile pages
- Include actor profile images with mp.jpg fallback for users without avatars
- Support individual notification type toggles (likes, reposts, comments, followers)
- Integrate settings into existing ActivityPub profile sections alongside email notifications
Replaces get_actor with fetch_by_uri for actor retrieval and decodes comment excerpts for notifications. Removes unused helper methods for actor name and image, and ensures the notification includes a direct comment link. Also updates integration file path resolution and streamlines notification sending.
Set the priority to 11 for user and blog settings registration hooks to ensure they run after ActivityPub settings.
@Copilot Copilot AI review requested due to automatic review settings September 19, 2025 21:06
@github-actions github-actions bot added the [Focus] Compatibility Ensuring the plugin plays well with other plugins label Sep 19, 2025
Copy link

@Copilot 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 adds Perfecty Push integration to enable web push notifications for ActivityPub events. It creates a comprehensive notification system that triggers push notifications when fediverse users interact with ActivityPub content.

  • Adds support for four notification types: likes, reposts/boosts, comments, and new followers
  • Integrates individual notification settings for both user profiles and blog actor profiles
  • Includes fallback actor images and error handling for robust notification delivery

Reviewed Changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 3 comments.

File Description
integration/load.php Conditionally loads Perfecty Push integration when plugin is active
integration/class-perfecty-push.php Complete integration class handling notifications, settings, and UI rendering

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

Comment on lines +186 to +187
error_log( 'ActivityPub Perfecty Push notification failed: ' . $e->getMessage() ); // phpcs:ignore WordPress.PHP.DevelopmentFunctions.error_log_error_log
}
Copy link
Preview

Copilot AI Sep 19, 2025

Choose a reason for hiding this comment

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

Using error_log() directly is discouraged in WordPress. Consider using wp_die() for fatal errors or a proper logging mechanism that respects WordPress debugging settings.

Suggested change
error_log( 'ActivityPub Perfecty Push notification failed: ' . $e->getMessage() ); // phpcs:ignore WordPress.PHP.DevelopmentFunctions.error_log_error_log
}
if ( defined( 'WP_DEBUG' ) && WP_DEBUG && defined( 'WP_DEBUG_LOG' ) && WP_DEBUG_LOG ) {
error_log( 'ActivityPub Perfecty Push notification failed: ' . $e->getMessage() );
}

Copilot uses AI. Check for mistakes.

Removes the conditional check for the 'blog-profile' tab when registering the push notifications settings field, ensuring it is always added to the blog settings.
@pfefferle
Copy link
Member

Why this plugin?

@obenland
Copy link
Member Author

Why this plugin?

Honestly, I didn't even look much. https://github.com/web-push-libs/web-push-php was suggested as a popular PHP library and it mentions Perfecty Push Notifications as a plugin that integrates it.

Now, after your prompt and after installing and testing about 10 other Web Push plugins in the repo, I'd add that it's the only one that just works out of the box, without having to create an account, an API key, or buy a plan.

@obenland
Copy link
Member Author

Some learnings from working on this PR:

  • Hook naming between handlers is inconsistent
  • Some handlers do after handle hooks, some don't
  • The Notifications object requires you to get actor objects all over again and doesn't have a concept of the comment/follow/etc that was just created and just duplicates the activitypub_handled_* hooks.

@pfefferle
Copy link
Member

The Notifications object requires you to get actor objects all over again and doesn't have a concept of the comment/follow/etc that was just created and just duplicates the activitypub_handled_* hooks.

At least the notification class unifies the actions and it's params. The other actions are very inconsistend and depending on the implementer and the needs of the feature.

/**
* Render the user notification settings field.
*/
public static function render_user_notification_field() {
Copy link
Member

Choose a reason for hiding this comment

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

I wanted to avoid this, with the initial version of the notification settings an the table (I hope you remember)! I think this is not a good UI and we should avoid adding settings through extensions.

@pfefferle
Copy link
Member

The Notification class was meant to be a nice hook for dependency injection. WordPress does not provide notifications and because this might be a need, the idea was to have a unified way to trigger notifications and an even easier way to subscribe to them.

$default_enabled = array( 'like', 'announce', 'create', 'follow' );

// Check user-specific settings first.
$user_settings = \get_user_meta( $user_id, 'activitypub_perfecty_push_notifications', true );
Copy link
Member

Choose a reason for hiding this comment

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

notification settings should be generic and plugin independent. It doesn't matter what plugin you use, the settings should be the same.

@Jiwoon-Kim
Copy link

Jiwoon-Kim commented Sep 20, 2025

I previously created a Core ticket regarding web push notifications.
However, it failed because there was no dedicated activity table available for implementing notifications.
If possible, please also take Progressive Web App (PWA) compatibility into consideration.

Does Core DB have a table to handle notifications? No, it does not. Isn’t that why notifications are implemented by mass-sending emails?
Why can’t self-hosted WordPress receive in-app notifications via PWA? Why must it always be connected to Jetpack or flood users with email notifications?

https://core.trac.wordpress.org/ticket/63966

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Focus] Compatibility Ensuring the plugin plays well with other plugins
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants