From 0a31dec3af26eb095c8a2c6bd7a18a9569263721 Mon Sep 17 00:00:00 2001 From: Alex Kirk Date: Thu, 16 Jan 2025 14:50:27 +0100 Subject: [PATCH 1/6] Add metadata to New Follower E-Mail --- includes/class-mailer.php | 14 ++++++++++++- templates/new-follower-email.php | 36 ++++++++++++++++++++++++++++++++ 2 files changed, 49 insertions(+), 1 deletion(-) create mode 100644 templates/new-follower-email.php diff --git a/includes/class-mailer.php b/includes/class-mailer.php index c93662161..5e2f5b03d 100644 --- a/includes/class-mailer.php +++ b/includes/class-mailer.php @@ -143,7 +143,19 @@ public static function new_follower( $notification ) { $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 ); + \ob_start(); + require ACTIVITYPUB_PLUGIN_DIR . '/templates/new-follower-email.php'; + $html_message = \ob_get_clean(); + + $alt_function = function ( $mailer ) use ( $message ) { + $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 ); + } /** diff --git a/templates/new-follower-email.php b/templates/new-follower-email.php new file mode 100644 index 000000000..396599bf7 --- /dev/null +++ b/templates/new-follower-email.php @@ -0,0 +1,36 @@ +

+ +

+ + + + + + +
+ + + <?php echo esc_attr( $actor['name'] ); ?> + + + + + + () + +
+ +
+ + Date: Fri, 24 Jan 2025 15:07:08 +0100 Subject: [PATCH 2/6] changelog --- CHANGELOG.md | 1 + readme.txt | 1 + 2 files changed, 2 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 717120b4b..e19324080 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/readme.txt b/readme.txt index efaf265ad..539373522 100644 --- a/readme.txt +++ b/readme.txt @@ -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 = From b937b8efad5ac4814034d7ce6d65661b0e5466d1 Mon Sep 17 00:00:00 2001 From: Alex Kirk Date: Fri, 24 Jan 2025 15:21:31 +0100 Subject: [PATCH 3/6] Remove HTML escaping from subject and plain text --- includes/class-mailer.php | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/includes/class-mailer.php b/includes/class-mailer.php index 5e2f5b03d..b25e63d2e 100644 --- a/includes/class-mailer.php +++ b/includes/class-mailer.php @@ -135,19 +135,19 @@ 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"; + $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 ( $message ) { + $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 .= \esc_html__( '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 ); From ea9a7d803b3a7cd3f3bf5753d030ef61c25cda65 Mon Sep 17 00:00:00 2001 From: Alex Kirk Date: Fri, 24 Jan 2025 15:24:35 +0100 Subject: [PATCH 4/6] Lint fixes --- includes/class-mailer.php | 9 ++++----- templates/new-follower-email.php | 15 ++++++++++++++- 2 files changed, 18 insertions(+), 6 deletions(-) diff --git a/includes/class-mailer.php b/includes/class-mailer.php index b25e63d2e..0c2f6e6d9 100644 --- a/includes/class-mailer.php +++ b/includes/class-mailer.php @@ -143,11 +143,11 @@ public static function new_follower( $notification ) { $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"; + $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 .= \esc_html__( 'You can see all followers here:', 'activitypub' ) . "\r\n"; - $message .= \esc_url( \admin_url( $admin_url ) ) . "\r\n\r\n"; + $message .= \sprintf( \__( '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"; $mailer->{'AltBody'} = $message; }; \add_action( 'phpmailer_init', $alt_function ); @@ -155,7 +155,6 @@ public static function new_follower( $notification ) { \wp_mail( $email, $subject, $html_message, array( 'Content-type: text/html' ) ); \remove_action( 'phpmailer_init', $alt_function ); - } /** diff --git a/templates/new-follower-email.php b/templates/new-follower-email.php index 396599bf7..a63d7c292 100644 --- a/templates/new-follower-email.php +++ b/templates/new-follower-email.php @@ -1,6 +1,19 @@ +

From 65fd34c725f1e91c6517a3d5b89fb2de429fc6d8 Mon Sep 17 00:00:00 2001 From: Alex Kirk Date: Tue, 28 Jan 2025 10:31:00 +0100 Subject: [PATCH 5/6] update comment --- templates/new-follower-email.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/templates/new-follower-email.php b/templates/new-follower-email.php index a63d7c292..dc4898f0c 100644 --- a/templates/new-follower-email.php +++ b/templates/new-follower-email.php @@ -44,6 +44,6 @@ Date: Tue, 28 Jan 2025 10:32:05 +0100 Subject: [PATCH 6/6] No need to HTML escape inside the plain text --- includes/class-mailer.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/includes/class-mailer.php b/includes/class-mailer.php index 0c2f6e6d9..9131ec33e 100644 --- a/includes/class-mailer.php +++ b/includes/class-mailer.php @@ -146,7 +146,7 @@ public static function new_follower( $notification ) { $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 .= \esc_html__( 'You can see all followers here:', 'activitypub' ) . "\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; };