adapter( $source ); return $adapter && method_exists( $adapter, 'form_emails_visitor_reference' ) && $adapter->form_emails_visitor_reference( $form_id ); } /** * "We received your submission": reference number, the starting status message and the private link. */ public static function send_confirmation( array $receipt ): bool { $to = sanitize_email( (string) $receipt['email'] ); if ( ! is_email( $to ) ) { return false; } $status = StatusPipeline::get( (string) $receipt['status_key'] ); $site_name = wp_specialchars_decode( get_bloginfo( 'name' ), ENT_QUOTES ); $link = ReceiptService::status_url( $receipt ); /* translators: 1: site name, 2: reference number */ $subject = sprintf( __( '[%1$s] We received your submission %2$s', 'action-receipts' ), $site_name, $receipt['reference'] ); $lines = array(); $lines[] = __( 'Hello,', 'action-receipts' ); $lines[] = ''; // Not the form's name: many sites keep names like "Contact form 1", which read badly to visitors. /* translators: %s: date and time the submission was received */ $lines[] = sprintf( __( 'Thank you. We received your submission on %s.', 'action-receipts' ), Helpers::date( (string) $receipt['created_at'] ) ); $lines[] = ''; /* translators: %s: reference number */ $lines[] = sprintf( __( 'Your reference number is: %s', 'action-receipts' ), $receipt['reference'] ); $lines[] = __( 'Please keep it. You will need it if you contact us about this submission.', 'action-receipts' ); // The built-in "We have received your submission." would only repeat the first line; a custom message is worth adding. $default_message = StatusPipeline::defaults()[ StatusPipeline::DEFAULT_KEY ]['message']; if ( '' !== (string) $status['message'] && $default_message !== $status['message'] ) { $lines[] = ''; $lines[] = $status['message']; } if ( $link ) { $lines[] = ''; $lines[] = __( 'Check the status of your submission at any time:', 'action-receipts' ); $lines[] = $link; $lines[] = __( 'This link is private. Please do not share it.', 'action-receipts' ); } $lines[] = ''; $lines[] = $site_name; /** * Change the confirmation email sent when a submission is received. * * @param array $email ['to','subject','body','headers'] * @param array $receipt */ $email = (array) apply_filters( 'actr_confirmation_email', array( 'to' => $to, 'subject' => $subject, 'body' => implode( "\n", $lines ), 'headers' => array( 'Content-Type: text/plain; charset=UTF-8' ), ), $receipt ); if ( empty( $email['to'] ) ) { return false; // A filter can cancel the email by clearing "to". } $sent = self::mail( $email ); if ( $sent ) { EventRepository::add( (int) $receipt['id'], EventRepository::EMAIL_SENT, array( 'to_status' => (string) $receipt['status_key'] ) ); } return (bool) $sent; } /** * Sends through wp_mail(), so the site's own mail/SMTP setup applies. When the sender name is still * WordPress's default "WordPress", the site name is used instead, so visitors recognise who wrote. * A name set by the site owner or an SMTP plugin is left alone. * * @param array $email ['to','subject','body','headers'] */ private static function mail( array $email ): bool { $use_site_name = static function ( $name ) { $site = wp_specialchars_decode( get_bloginfo( 'name' ), ENT_QUOTES ); return ( 'WordPress' === $name && '' !== $site ) ? $site : $name; }; add_filter( 'wp_mail_from_name', $use_site_name, 99 ); $sent = wp_mail( $email['to'], $email['subject'], $email['body'], $email['headers'] ); remove_filter( 'wp_mail_from_name', $use_site_name, 99 ); return (bool) $sent; } public static function send_update( array $receipt, string $public_note = '' ): bool { $to = sanitize_email( (string) $receipt['email'] ); if ( ! is_email( $to ) ) { return false; } $status = StatusPipeline::get( (string) $receipt['status_key'] ); $site_name = wp_specialchars_decode( get_bloginfo( 'name' ), ENT_QUOTES ); $link = ReceiptService::status_url( $receipt ); /* translators: 1: site name, 2: reference number */ $subject = sprintf( __( '[%1$s] Update on your submission %2$s', 'action-receipts' ), $site_name, $receipt['reference'] ); $lines = array(); $lines[] = __( 'Hello,', 'action-receipts' ); $lines[] = ''; /* translators: 1: reference number, 2: status label */ $lines[] = sprintf( __( 'The status of your submission %1$s is now: %2$s', 'action-receipts' ), $receipt['reference'], $status['label'] ); if ( '' !== (string) $status['message'] ) { $lines[] = $status['message']; } if ( '' !== $public_note ) { $lines[] = ''; $lines[] = __( 'Note:', 'action-receipts' ); $lines[] = $public_note; } if ( $link ) { $lines[] = ''; $lines[] = __( 'View your submission status:', 'action-receipts' ); $lines[] = $link; } $lines[] = ''; $lines[] = $site_name; $body = implode( "\n", $lines ); /** * Change the update email. * * @param array $email ['to','subject','body','headers'] * @param array $receipt */ $email = (array) apply_filters( 'actr_update_email', array( 'to' => $to, 'subject' => $subject, 'body' => $body, 'headers' => array( 'Content-Type: text/plain; charset=UTF-8' ), ), $receipt ); $sent = self::mail( $email ); if ( $sent ) { EventRepository::add( (int) $receipt['id'], EventRepository::EMAIL_SENT, array( 'to_status' => (string) $receipt['status_key'] ) ); } return (bool) $sent; } }