Skip to content

Commit 3a913e8

Browse files
akirkobenlandpfefferle
authored
Add metadata to New Follower E-Mail (#1172)
* Add metadata to New Follower E-Mail * changelog * Remove HTML escaping from subject and plain text * Lint fixes * update comment * No need to HTML escape inside the plain text * Resolve some PR feedbacks * Use load_template to align with other uses * Add footer link to follower list. Props @pfefferle * Move follower list into separate paragraph for better margins * Clarify who this new follower is following --------- Co-authored-by: Konstantin Obenland <[email protected]> Co-authored-by: Matthias Pfefferle <[email protected]>
1 parent 19f8852 commit 3a913e8

File tree

4 files changed

+93
-9
lines changed

4 files changed

+93
-9
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1010
### Added
1111

1212
* Setting to adjust the number of days Outbox items are kept before being purged.
13+
* Metadata to New Follower E-Mail.
1314

1415
### Changed
1516

includes/class-mailer.php

Lines changed: 28 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -134,16 +134,35 @@ public static function new_follower( $notification ) {
134134
$admin_url = '/users.php?page=activitypub-followers-list';
135135
}
136136

137-
/* translators: 1: Blog name, 2: Follower name */
138-
$subject = \sprintf( \esc_html__( '[%1$s] Follower: %2$s', 'activitypub' ), \esc_html( get_option( 'blogname' ) ), \esc_html( $actor['name'] ) );
139-
/* translators: 1: Blog name, 2: Follower name */
140-
$message = \sprintf( \esc_html__( 'New Follower: %2$s.', 'activitypub' ), \esc_html( get_option( 'blogname' ) ), \esc_html( $actor['name'] ) ) . "\r\n\r\n";
141-
/* translators: Follower URL */
142-
$message .= \sprintf( \esc_html__( 'URL: %s', 'activitypub' ), \esc_url( $actor['url'] ) ) . "\r\n\r\n";
143-
$message .= \esc_html__( 'You can see all followers here:', 'activitypub' ) . "\r\n";
144-
$message .= \esc_url( \admin_url( $admin_url ) ) . "\r\n\r\n";
137+
$template_args = array_merge(
138+
$actor,
139+
array(
140+
'admin_url' => $admin_url,
141+
'target' => $notification->target,
142+
)
143+
);
145144

146-
\wp_mail( $email, $subject, $message );
145+
/* translators: 1: Blog name, 2: Follower name */
146+
$subject = \sprintf( \__( '[%1$s] New Follower: %2$s', 'activitypub' ), get_option( 'blogname' ), $actor['name'] );
147+
148+
\ob_start();
149+
\load_template( ACTIVITYPUB_PLUGIN_DIR . 'templates/new-follower-email.php', false, $template_args );
150+
$html_message = \ob_get_clean();
151+
152+
$alt_function = function ( $mailer ) use ( $actor, $admin_url ) {
153+
/* translators: 1: Follower name */
154+
$message = \sprintf( \__( 'New Follower: %1$s.', 'activitypub' ), $actor['name'] ) . "\r\n\r\n";
155+
/* translators: Follower URL */
156+
$message .= \sprintf( \__( 'URL: %s', 'activitypub' ), \esc_url( $actor['url'] ) ) . "\r\n\r\n";
157+
$message .= \__( 'You can see all followers here:', 'activitypub' ) . "\r\n";
158+
$message .= \esc_url( \admin_url( $admin_url ) ) . "\r\n\r\n";
159+
$mailer->{'AltBody'} = $message;
160+
};
161+
\add_action( 'phpmailer_init', $alt_function );
162+
163+
\wp_mail( $email, $subject, $html_message, array( 'Content-type: text/html' ) );
164+
165+
\remove_action( 'phpmailer_init', $alt_function );
147166
}
148167

149168
/**

readme.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,7 @@ For reasons of data protection, it is not possible to see the followers of other
134134
* Added: Allow Activities on URLs instead of requiring Activity-Objects. This is useful especially for sending Announces and Likes.
135135
* Added: Undo API for Outbox items.
136136
* Added: Setting to adjust the number of days Outbox items are kept before being purged.
137+
* Added: Show metadata in the New Follower E-Mail.
137138
* Changed: Outbox now precesses the first batch of followers right away to avoid delays in processing new Activities.
138139
* Fixed: The Outbox purging routine no longer is limited to deleting 5 items at a time.
139140
* Fixed an issue where the outbox could not send object types other than `Base_Object` (introduced in 5.0.0).

templates/new-follower-email.php

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
<?php
2+
/**
3+
* ActivityPub New Follower E-Mail template.
4+
*
5+
* @package Activitypub
6+
*/
7+
8+
use Activitypub\Collection\Actors;
9+
10+
/* @var array $args Template arguments. */
11+
$args = wp_parse_args( $args );
12+
?>
13+
<p>
14+
<?php
15+
if ( Actors::BLOG_USER_ID === $args['target'] ) :
16+
esc_html_e( 'Your blog has a new follower:', 'activitypub' );
17+
else :
18+
esc_html_e( 'You have a new follower:', 'activitypub' );
19+
endif;
20+
?>
21+
</p>
22+
23+
<table>
24+
<tr>
25+
<td style="vertical-align: top">
26+
<a href="<?php echo esc_url( $args['url'] ); ?>" style="float: left; margin-right: 1em;">
27+
<?php if ( ! empty( $args['icon']['url'] ) ) : ?>
28+
<img src="<?php echo esc_url( $args['icon']['url'] ); ?>" alt="<?php echo esc_attr( $args['name'] ); ?>" width="64" height="64">
29+
<?php endif; ?>
30+
</a>
31+
</td>
32+
<td>
33+
<a href="<?php echo esc_url( $args['url'] ); ?>">
34+
<strong><?php echo esc_html( $args['name'] ); ?></strong> (<?php echo esc_html( $args['url'] ); ?>)
35+
</a>
36+
<br>
37+
<?php
38+
if ( ! empty( $args['summary'] ) ) :
39+
echo wp_kses_post( nl2br( $args['summary'] ) );
40+
endif;
41+
?>
42+
</td>
43+
</tr>
44+
</table>
45+
46+
<p>
47+
<?php
48+
printf(
49+
/* translators: %s: URL to followers list. */
50+
wp_kses( __( 'Visit the <a href="%s">followers list</a> to see all followers.', 'activitypub' ), array( 'a' => array( 'href' => array() ) ) ),
51+
esc_url( admin_url( $args['admin_url'] ) )
52+
);
53+
?>
54+
</p>
55+
56+
<?php
57+
58+
/**
59+
* Fires at the bottom of the new follower email.
60+
*
61+
* @param array $args The actor that followed the blog.
62+
*/
63+
do_action( 'activitypub_new_follower_email', $args );

0 commit comments

Comments
 (0)