PluginProbe
ActivityPub / 8.0.2
ActivityPub v8.0.2
9.3.1 9.3.0 9.2.2 9.2.1 9.2.0 9.1.0 9.0.2 9.0.1 9.0.0 8.3.0 8.2.1 8.2.0 8.1.1 1.0.5 1.0.6 1.0.7 1.0.8 1.0.9 1.1.0 1.2.0 1.3.0 2.0.0 2.0.1 2.1.0 2.1.1 All 160 releases
← All changes | includes/class-mailer.php +14 -81 9.2.08.0.2 View file →
@@ -58,9 +58,9 @@
58 58
59 59 $post = \get_post( $comment->comment_post_ID );
60 60
61 61 /* translators: 1: Blog name, 2: Like or Repost, 3: Post title */
62 - return \sprintf( \esc_html__( '[%1$s] %2$s: %3$s', 'activitypub' ), \esc_html( \get_option( 'blogname' ) ), \esc_html( $singular ), \esc_html( $post->post_title ) );
62 + return \sprintf( \esc_html__( '[%1$s] %2$s: %3$s', 'activitypub' ), \esc_html( get_option( 'blogname' ) ), \esc_html( $singular ), \esc_html( $post->post_title ) );
63 63 }
64 64
65 65 /**
66 66 * Filter the notification text for Like and Announce notifications.
@@ -100,9 +100,9 @@
100 100 // Check if this is a reaction to a post or a comment.
101 101 if ( 0 === (int) $comment->comment_parent ) {
102 102 $notify_message = \sprintf(
103 103 /* translators: 1: Comment type, 2: Post title */
104 - \html_entity_decode( \esc_html__( 'New %1$s on your post “%2$s”.', 'activitypub' ) ),
104 + \html_entity_decode( esc_html__( 'New %1$s on your post “%2$s”.', 'activitypub' ) ),
105 105 \esc_html( $comment_type['singular'] ),
106 106 \esc_html( $post->post_title )
107 107 ) . PHP_EOL . PHP_EOL;
108 108
@@ -109,9 +109,9 @@
109 109 } else {
110 110 $parent_comment = \get_comment( $comment->comment_parent );
111 111 $notify_message = \sprintf(
112 112 /* translators: 1: Comment type, 2: Post title, 3: Parent comment author */
113 - \html_entity_decode( \esc_html__( 'New %1$s on your post “%2$s” in reply to %3$s’s comment.', 'activitypub' ) ),
113 + \html_entity_decode( esc_html__( 'New %1$s on your post “%2$s” in reply to %3$s’s comment.', 'activitypub' ) ),
114 114 \esc_html( $comment_type['singular'] ),
115 115 \esc_html( $post->post_title ),
116 116 \esc_html( $parent_comment->comment_author )
117 117 ) . PHP_EOL . PHP_EOL;
@@ -119,21 +119,9 @@
119 119
120 120 /* translators: 1: Website name, 2: Website IP address, 3: Website hostname. */
121 121 $notify_message .= \sprintf( \esc_html__( 'From: %1$s (IP address: %2$s, %3$s)', 'activitypub' ), \esc_html( $comment->comment_author ), \esc_html( $comment->comment_author_IP ), \esc_html( $comment_author_domain ) ) . "\r\n";
122 122 /* translators: Reaction author URL. */
123 - $notify_message .= \sprintf( \esc_html__( 'URL: %s', 'activitypub' ), \esc_url( $comment->comment_author_url ) ) . "\r\n";
124 -
125 - // For quotes, link to the quoting post itself so the author can review and respond.
126 - if ( 'quote' === $comment->comment_type ) {
127 - $quote_url = Comment::get_source_url( $comment->comment_ID );
128 -
129 - if ( $quote_url ) {
130 - /* translators: Quoting post URL. */
131 - $notify_message .= \sprintf( \esc_html__( 'Quoting post: %s', 'activitypub' ), \esc_url( $quote_url ) ) . "\r\n";
132 - }
133 - }
134 -
135 - $notify_message .= "\r\n";
123 + $notify_message .= \sprintf( \esc_html__( 'URL: %s', 'activitypub' ), \esc_url( $comment->comment_author_url ) ) . "\r\n\r\n";
136 124 /* translators: Comment type label */
137 125 $notify_message .= \sprintf( \esc_html__( 'You can see all %s on this post here:', 'activitypub' ), \esc_html( $comment_type['label'] ) ) . "\r\n";
138 126 $notify_message .= \get_permalink( $comment->comment_post_ID ) . '#' . \esc_attr( $comment_type['type'] ) . "\r\n\r\n";
139 127
@@ -155,8 +143,13 @@
155 143
156 144 // Extract the user ID (follows are always for a single user).
157 145 $user_id = \is_array( $user_ids ) ? \reset( $user_ids ) : $user_ids;
158 146
147 + // Do not send notifications to the Application user.
148 + if ( Actors::APPLICATION_USER_ID === $user_id ) {
149 + return;
150 + }
151 +
159 152 if ( $user_id > Actors::BLOG_USER_ID ) {
160 153 if ( ! \get_user_option( 'activitypub_mailer_new_follower', $user_id ) ) {
161 154 return;
162 155 }
@@ -186,9 +179,9 @@
186 179 if ( ! empty( $actor['summary'] ) ) {
187 180 $actor['summary'] = Emoji::replace_for_actor( $actor['summary'], $actor['url'] );
188 181 }
189 182
190 - $template_args = \array_merge(
183 + $template_args = array_merge(
191 184 $actor,
192 185 array(
193 186 'admin_url' => $admin_url,
194 187 'user_id' => $user_id,
@@ -311,9 +304,9 @@
311 304
312 305 $alt_function = static function ( $mailer ) use ( $actor, $activity ) {
313 306 $content = \html_entity_decode(
314 307 \wp_strip_all_tags(
315 - \str_replace( '</p>', PHP_EOL . PHP_EOL, $activity['object']['content'] )
308 + str_replace( '</p>', PHP_EOL . PHP_EOL, $activity['object']['content'] )
316 309 ),
317 310 ENT_QUOTES | ENT_SUBSTITUTE | ENT_HTML401
318 311 );
319 312
@@ -351,10 +344,10 @@
351 344 return;
352 345 }
353 346
354 347 $recipients = array();
355 - $mentions = \wp_list_filter( (array) $activity['object']['tag'], array( 'type' => 'Mention' ) );
356 - $mentions = \array_map( '\Activitypub\object_to_uri', $mentions );
348 + $mentions = wp_list_filter( (array) $activity['object']['tag'], array( 'type' => 'Mention' ) );
349 + $mentions = array_map( '\Activitypub\object_to_uri', $mentions );
357 350 foreach ( (array) $user_ids as $user_id ) {
358 351 $actor = Actors::get_by_id( $user_id );
359 352 if ( \is_wp_error( $actor ) ) {
360 353 continue;
@@ -411,9 +404,9 @@
411 404
412 405 $alt_function = static function ( $mailer ) use ( $actor, $activity ) {
413 406 $content = \html_entity_decode(
414 407 \wp_strip_all_tags(
415 - \str_replace( '</p>', PHP_EOL . PHP_EOL, $activity['object']['content'] )
408 + str_replace( '</p>', PHP_EOL . PHP_EOL, $activity['object']['content'] )
416 409 ),
417 410 ENT_QUOTES | ENT_SUBSTITUTE | ENT_HTML401
418 411 );
419 412
@@ -431,68 +424,8 @@
431 424 \wp_mail( $email, $subject, $html_message, array( 'Content-type: text/html' ) );
432 425
433 426 \remove_action( 'phpmailer_init', $alt_function );
434 427 }
435 - }
436 -
437 - /**
438 - * Send a templated email to a user.
439 - *
440 - * @param int $user_id The user ID (or BLOG_USER_ID for blog actor).
441 - * @param string $subject The email subject.
442 - * @param string $template The template name (without path/extension).
443 - * @param array $args Template arguments.
444 - * @param string $alt_body Optional plain text alternative. Auto-generated from HTML if empty.
445 - *
446 - * @return bool True if email was sent, false otherwise.
447 - */
448 - public static function send( $user_id, $subject, $template, $args = array(), $alt_body = '' ) {
449 - // Get the recipient email address.
450 - if ( $user_id > Actors::BLOG_USER_ID ) {
451 - $user = \get_userdata( $user_id );
452 - if ( ! $user || empty( $user->user_email ) ) {
453 - return false;
454 - }
455 - $email = $user->user_email;
456 - } else {
457 - $email = \get_option( 'admin_email' );
458 - }
459 -
460 - // Load the HTML template.
461 - $template_file = ACTIVITYPUB_PLUGIN_DIR . 'templates/emails/' . \sanitize_file_name( $template ) . '.php';
462 -
463 - /**
464 - * Filter the email template file path.
465 - *
466 - * @param string $template_file The template file path.
467 - * @param string $template The template name.
468 - * @param int $user_id The user ID.
469 - * @param array $args Template arguments.
470 - */
471 - $template_file = \apply_filters( 'activitypub_email_template', $template_file, $template, $user_id, $args );
472 -
473 - if ( ! \file_exists( $template_file ) ) {
474 - return false;
475 - }
476 -
477 - \ob_start();
478 - \load_template( $template_file, false, $args );
479 - $html_message = \ob_get_clean();
480 -
481 - // Build plain text alternative from HTML if not provided.
482 - if ( empty( $alt_body ) ) {
483 - $alt_body = \wp_strip_all_tags( $html_message );
484 - }
485 - $alt_function = static function ( $mailer ) use ( $alt_body ) {
486 - $mailer->{'AltBody'} = $alt_body;
487 - };
488 - \add_action( 'phpmailer_init', $alt_function );
489 -
490 - $result = \wp_mail( $email, $subject, $html_message, array( 'Content-type: text/html' ) );
491 -
492 - \remove_action( 'phpmailer_init', $alt_function );
493 -
494 - return $result;
495 428 }
496 429
497 430 /**
498 431 * Apply defaults to the actor object.