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

Add metadata to New Follower E-Mail #1172

Open
wants to merge 10 commits into
base: trunk
Choose a base branch
from
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Changed

* Added metadata to New Follower E-Mail
* Manually granting `activitypub` cap no longer requires the receiving user to have `publish_post`.

## [5.0.0] - 2025-02-03
Expand Down
29 changes: 20 additions & 9 deletions includes/class-mailer.php
Original file line number Diff line number Diff line change
Expand Up @@ -135,15 +135,26 @@ public static function new_follower( $notification ) {
}

/* translators: 1: Blog name, 2: Follower name */
$subject = \sprintf( \esc_html__( '[%1$s] Follower: %2$s', 'activitypub' ), \esc_html( get_option( 'blogname' ) ), \esc_html( $actor['name'] ) );
/* translators: 1: Blog name, 2: Follower name */
$message = \sprintf( \esc_html__( 'New Follower: %2$s.', 'activitypub' ), \esc_html( get_option( 'blogname' ) ), \esc_html( $actor['name'] ) ) . "\r\n\r\n";
/* translators: Follower URL */
$message .= \sprintf( \esc_html__( 'URL: %s', 'activitypub' ), \esc_url( $actor['url'] ) ) . "\r\n\r\n";
$message .= \esc_html__( 'You can see all followers here:', 'activitypub' ) . "\r\n";
$message .= \esc_url( \admin_url( $admin_url ) ) . "\r\n\r\n";

\wp_mail( $email, $subject, $message );
$subject = \sprintf( \__( '[%1$s] Follower: %2$s', 'activitypub' ), get_option( 'blogname' ), $actor['name'] );
Copy link
Member

Choose a reason for hiding this comment

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

Could we call this "New Follower:"?


\ob_start();
require ACTIVITYPUB_PLUGIN_DIR . '/templates/new-follower-email.php';
$html_message = \ob_get_clean();

$alt_function = function ( $mailer ) use ( $actor, $admin_url ) {
/* translators: 1: Blog name, 2: Follower name */
$message = \sprintf( \__( 'New Follower: %2$s.', 'activitypub' ), \get_option( 'blogname' ), $actor['name'] ) . "\r\n\r\n";
Copy link
Member

Choose a reason for hiding this comment

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

If we don't expect to use the blog name, let's just limit it to one placeholder?

/* translators: Follower URL */
$message .= \sprintf( \__( 'URL: %s', 'activitypub' ), \esc_url( $actor['url'] ) ) . "\r\n\r\n";
$message .= \__( 'You can see all followers here:', 'activitypub' ) . "\r\n";
$message .= \esc_url( \admin_url( $admin_url ) ) . "\r\n\r\n";
$mailer->{'AltBody'} = $message;
};
\add_action( 'phpmailer_init', $alt_function );

\wp_mail( $email, $subject, $html_message, array( 'Content-type: text/html' ) );

\remove_action( 'phpmailer_init', $alt_function );
}

/**
Expand Down
1 change: 1 addition & 0 deletions readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,7 @@ For reasons of data protection, it is not possible to see the followers of other

= Unreleased =

* Changed: Show metadata in the New Follower E-Mail
* Changed: Manually granting `activitypub` cap no longer requires the receiving user to have `publish_post`.

= 5.0.0 =
Expand Down
49 changes: 49 additions & 0 deletions templates/new-follower-email.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
<?php
/**
* ActivityPub New Follower E-Mail template.
*
* @package Activitypub
*/

if ( ! isset( $actor ) ) {
$actor = array();
return;
Comment on lines +9 to +10
Copy link
Member

Choose a reason for hiding this comment

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

Could you help me understand why $actor gets set to an empty array before returning? Does it has to do with how it's being used in new_follower() later on?

}

?>
<p>
<?php
esc_html_e( 'You have a new follower:', 'activitypub' );
?>
</p>

<table>
<tr>
<td style="vertical-align: top">
<a href="<?php echo esc_url( $actor['url'] ); ?>" style="float: left; margin-right: 1em;">
<?php if ( ! empty( $actor['icon']['url'] ) ) : ?>
<img src="<?php echo esc_url( $actor['icon']['url'] ); ?>" alt="<?php echo esc_attr( $actor['name'] ); ?>" width="64" height="64">
<?php endif; ?>
</a>
</td>
<td>

Copy link
Member

Choose a reason for hiding this comment

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

Suggested change

<a href="<?php echo esc_url( $actor['url'] ); ?>">
<strong><?php echo esc_html( $actor['name'] ); ?></strong> (<?php echo esc_html( $actor['url'] ); ?>)
</a>
<br>
<?php
if ( ! empty( $actor['summary'] ) ) {
echo wp_kses_post( nl2br( $actor['summary'] ) );
}
Comment on lines +36 to +38
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
if ( ! empty( $actor['summary'] ) ) {
echo wp_kses_post( nl2br( $actor['summary'] ) );
}
if ( ! empty( $actor['summary'] ) ) :
echo wp_kses_post( nl2br( $actor['summary'] ) );
endif;

?>
</td>
</tr>
</table>

<?php

/**
* Fires at the bottom of the new follower email.
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
* Fires at the bottom of the new follower email.
* Fires at the bottom of the new follower email.
*
* @param array $actor The actor that followed the blog.

*/
do_action( 'activitypub_new_follower_email', $actor );
Loading