Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Augment the ActivityPub New Follower E-Mail #434

Merged
merged 1 commit into from
Jan 16, 2025
Merged
Changes from all commits
Commits
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
43 changes: 43 additions & 0 deletions includes/class-notifications.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ private function register_hooks() {
add_action( 'notify_new_friend_request', array( $this, 'notify_new_friend_request' ) );
add_action( 'notify_accepted_friend_request', array( $this, 'notify_accepted_friend_request' ) );
add_action( 'notify_friend_message_received', array( $this, 'notify_friend_message_received' ), 10, 3 );
add_action( 'activitypub_new_follower_email', array( $this, 'activitypub_new_follower_email' ), 10, 3 );
if ( ! get_user_option( 'friends_no_friend_follower_notification' ) ) {
add_action( 'activitypub_followers_post_follow', array( $this, 'activitypub_followers_post_follow' ), 10, 4 );
add_action( 'activitypub_followers_pre_remove_follower', array( $this, 'activitypub_followers_pre_remove_follower' ), 10, 3 );
Expand Down Expand Up @@ -357,6 +358,48 @@ public function notify_friend_message_received( User $friend_user, $message, $su
$this->send_mail( $user->user_email, $email_title, $email_message );
}

/**
* Augment the ActivityPub new follower e-mail
*
* @param array $actor The actor.
*/
public function activitypub_new_follower_email( $actor ) {
if ( isset( $actor['id'] ) ) {
$url = $actor['id'];
} elseif ( isset( $actor['url'] ) ) {
$url = $actor['url'];
} else {
return;
}

$url = \ActivityPub\object_to_uri( $url );
$server = wp_parse_url( $url, PHP_URL_HOST );
$following = User_Feed::get_by_url( $url );
if ( ! $following || is_wp_error( $following ) ) {
$following = User_Feed::get_by_url( str_replace( '/users/', '/@', $url ) );
}
if ( $following && ! is_wp_error( $following ) ) {
$following = $following->get_friend_user();
} else {
$following = false;
}
echo '<p>';
if ( $following ) {
echo esc_html__( 'You are already following them!', 'friends' );
echo ' ';
// translators: %s is a URL.
echo wp_kses( sprintf( __( 'Go to their <a href="%s">friends page</a> to see what they recently posted about.', 'friends' ), esc_url( $following->get_local_friends_page_url() ) ), array( 'a' => array( 'href' => array() ) ) );
} else {
// translators: %s is a URL.
echo wp_kses( sprintf( __( 'You can view their profile at %s', 'friends' ), '<a href="' . esc_url( $url ) . '">' . esc_url( $url ) . '</a>' ), array( 'a' => array( 'href' => array() ) ) );
echo '</p>';
echo '<p>';
// translators: %s is a URL.
echo wp_kses( sprintf( __( 'Maybe you want to <a href="%s">follow them back</a>?', 'friends' ), esc_url( add_query_arg( 'url', $url, admin_url( 'admin.php?page=add-friend' ) ) ) ), array( 'a' => array( 'href' => array() ) ) );
}
echo '</p>';
}

/**
* Notify of a follower
*
Expand Down
Loading