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 7 commits into
base: trunk
Choose a base branch
from
Open
Show file tree
Hide file tree
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Changed

* Improved content negotiation and AUTHORIZED_FETCH support for third-party plugins
* Added metadata to New Follower E-Mail

## [4.7.3] - 2025-01-21

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'] );

\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";
/* 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 @@ -134,6 +134,7 @@ For reasons of data protection, it is not possible to see the followers of other
= Unreleased =

* Changed: Improved content negotiation and AUTHORIZED_FETCH support for third-party plugins
* Added: Show metadata in the New Follower E-Mail

= 4.7.3 =

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;
}

?>
<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>

<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'] ) );
}
?>
</td>
</tr>
</table>

<?php

/**
* Fires at the bottom of the new follower email.
*/
do_action( 'activitypub_new_follower_email', $actor );
Loading