| @@ -427,68 +427,8 @@ | ||
| 427 | 427 | } |
| 428 | 428 | } |
| 429 | 429 | |
| 430 | 430 | /** |
| 431 | - * Send a templated email to a user. | |
| 432 | - * | |
| 433 | - * @param int $user_id The user ID (or BLOG_USER_ID for blog actor). | |
| 434 | - * @param string $subject The email subject. | |
| 435 | - * @param string $template The template name (without path/extension). | |
| 436 | - * @param array $args Template arguments. | |
| 437 | - * @param string $alt_body Optional plain text alternative. Auto-generated from HTML if empty. | |
| 438 | - * | |
| 439 | - * @return bool True if email was sent, false otherwise. | |
| 440 | - */ | |
| 441 | - public static function send( $user_id, $subject, $template, $args = array(), $alt_body = '' ) { | |
| 442 | - // Get the recipient email address. | |
| 443 | - if ( $user_id > Actors::BLOG_USER_ID ) { | |
| 444 | - $user = \get_userdata( $user_id ); | |
| 445 | - if ( ! $user || empty( $user->user_email ) ) { | |
| 446 | - return false; | |
| 447 | - } | |
| 448 | - $email = $user->user_email; | |
| 449 | - } else { | |
| 450 | - $email = \get_option( 'admin_email' ); | |
| 451 | - } | |
| 452 | - | |
| 453 | - // Load the HTML template. | |
| 454 | - $template_file = ACTIVITYPUB_PLUGIN_DIR . 'templates/emails/' . \sanitize_file_name( $template ) . '.php'; | |
| 455 | - | |
| 456 | - /** | |
| 457 | - * Filter the email template file path. | |
| 458 | - * | |
| 459 | - * @param string $template_file The template file path. | |
| 460 | - * @param string $template The template name. | |
| 461 | - * @param int $user_id The user ID. | |
| 462 | - * @param array $args Template arguments. | |
| 463 | - */ | |
| 464 | - $template_file = \apply_filters( 'activitypub_email_template', $template_file, $template, $user_id, $args ); | |
| 465 | - | |
| 466 | - if ( ! \file_exists( $template_file ) ) { | |
| 467 | - return false; | |
| 468 | - } | |
| 469 | - | |
| 470 | - \ob_start(); | |
| 471 | - \load_template( $template_file, false, $args ); | |
| 472 | - $html_message = \ob_get_clean(); | |
| 473 | - | |
| 474 | - // Build plain text alternative from HTML if not provided. | |
| 475 | - if ( empty( $alt_body ) ) { | |
| 476 | - $alt_body = \wp_strip_all_tags( $html_message ); | |
| 477 | - } | |
| 478 | - $alt_function = static function ( $mailer ) use ( $alt_body ) { | |
| 479 | - $mailer->{'AltBody'} = $alt_body; | |
| 480 | - }; | |
| 481 | - \add_action( 'phpmailer_init', $alt_function ); | |
| 482 | - | |
| 483 | - $result = \wp_mail( $email, $subject, $html_message, array( 'Content-type: text/html' ) ); | |
| 484 | - | |
| 485 | - \remove_action( 'phpmailer_init', $alt_function ); | |
| 486 | - | |
| 487 | - return $result; | |
| 488 | - } | |
| 489 | - | |
| 490 | - /** | |
| 491 | 431 | * Apply defaults to the actor object. |
| 492 | 432 | * |
| 493 | 433 | * Ensure that the actor object has a name, url, and webfinger. |
| 494 | 434 | * |