$row['name'], '{reference}' => $row['reference'], '{date}' => Reservations::format_date( $row['start_at'] ), '{time}' => Reservations::format_time( $row['start_at'] ), /* translators: %d guests */ '{party}' => sprintf( _n( '%d guest', '%d guests', (int) $row['party_size'], 'tableengine' ), (int) $row['party_size'] ), '{table}' => $row['table_label'] ? $row['table_label'] : __( 'To be assigned', 'tableengine' ), '{room}' => $plan ? $plan['name'] : '', '{restaurant}' => Settings::get( 'restaurant_name' ), '{manage_url}' => Reservations::manage_url( $row ), '{amount}' => $row['amount'] ? Reservations::format_money( $row['amount'], $row['currency'] ) : '', '{notes}' => $row['notes'], '{phone}' => $row['phone'], '{email}' => $row['email'], ); return apply_filters( 'tableengine_email_placeholders', $vars, $row ); } private static function headers() { $name = Settings::get( 'from_name' ); $email = Settings::get( 'from_email' ); $h = array( 'Content-Type: text/html; charset=UTF-8' ); if ( $email && is_email( $email ) ) { $h[] = sprintf( 'From: %s <%s>', wp_specialchars_decode( $name, ENT_QUOTES ), $email ); } return $h; } /** * Template for a guest email: array( on, subject, body[, summary] ), or null when * no such email exists. Built from email_{type}_* settings; extensions supply * templates for their own types through `tableengine_email_template`. */ public static function template( $type, array $row, array $args = array() ) { $on = Settings::get( "email_{$type}_on" ); $tpl = null === $on ? null : array( 'on' => (bool) $on, 'subject' => (string) Settings::get( "email_{$type}_subject" ), 'body' => (string) Settings::get( "email_{$type}_body" ), ); return apply_filters( 'tableengine_email_template', $tpl, $type, $row, $args ); } /** * Send a guest-facing email: confirm | pending | cancel | reminder, or an extension's type. */ public static function send( $type, array $row, array $args = array() ) { $tpl = self::template( $type, $row, $args ); if ( ! $tpl || empty( $tpl['on'] ) || ! is_email( $row['email'] ) ) { return false; } $vars = self::placeholders( $row ); $subject = strtr( (string) $tpl['subject'], $vars ); $body = strtr( (string) $tpl['body'], array_map( 'esc_html', $vars ) ); $content = self::linkify( nl2br( $body ) ); // Placeholders that expand to markup (e.g. buttons), substituted after escaping. $content = strtr( $content, (array) apply_filters( 'tableengine_email_html_placeholders', array(), $row, $type, $args ) ); $summary = isset( $tpl['summary'] ) ? (bool) $tpl['summary'] : 'cancel' !== $type; $html = self::wrap( $subject, $content, $row, $summary, $type ); $attachments = array(); $mail = apply_filters( 'tableengine_email_args', compact( 'subject', 'html', 'attachments' ), $type, $row, $args ); return wp_mail( $row['email'], $mail['subject'], $mail['html'], self::headers(), $mail['attachments'] ); } /** * Restaurant alert: new | cancel, or any type an extension registers with an * `admin_{type}_notify` setting and a `tableengine_admin_email_subject` filter. */ public static function send_admin( $type, array $row ) { $keys = array( 'new' => 'admin_notify', 'cancel' => 'admin_cancel_notify', ); $key = isset( $keys[ $type ] ) ? $keys[ $type ] : "admin_{$type}_notify"; if ( ! Settings::get( $key ) ) { return false; } $to = array_filter( array_map( 'trim', explode( ',', (string) Settings::get( 'admin_emails' ) ) ), 'is_email' ); if ( ! $to ) { return false; } $v = self::placeholders( $row ); if ( 'new' === $type ) { /* translators: 1: party 2: date 3: time */ $subject = sprintf( __( 'New booking: %1$s · %2$s at %3$s', 'tableengine' ), $v['{party}'], $v['{date}'], $v['{time}'] ); } else { /* translators: %s reference */ $subject = sprintf( __( 'Booking cancelled: %s', 'tableengine' ), $v['{reference}'] ); } $subject = apply_filters( 'tableengine_admin_email_subject', $subject, $type, $row, $v ); $rows = apply_filters( 'tableengine_admin_email_rows', array( __( 'Guest', 'tableengine' ) => $row['name'], __( 'Email', 'tableengine' ) => $row['email'], __( 'Phone', 'tableengine' ) => $row['phone'], __( 'Occasion', 'tableengine' ) => $row['occasion'], __( 'Requests', 'tableengine' ) => $row['notes'], __( 'Status', 'tableengine' ) => Reservations::statuses()[ $row['status'] ] ?? $row['status'], ), $row, $type ); $body = '
| ' . esc_html( $label ) . ' | ' . nl2br( esc_html( $value ) ) . ' |
' . esc_html__( 'Open in dashboard →', 'tableengine' ) . '
'; return wp_mail( $to, $subject, self::wrap( $subject, $body, $row, true, 'admin_' . $type ), self::headers() ); } private static function linkify( $html ) { return preg_replace( '~(?$1', $html ); } /** * Responsive, inline-styled email shell with a booking summary card. */ public static function wrap( $title, $content, array $row, $show_summary = true, $type = '' ) { /** Return a full HTML document to replace the built-in layout (e.g. a designed template). */ $custom = apply_filters( 'tableengine_email_html', null, $title, $content, $row, $show_summary, $type ); if ( is_string( $custom ) && '' !== $custom ) { return $custom; } $primary = Settings::get( 'primary_color' ); $logo = Settings::get( 'email_logo' ); $name = Settings::get( 'restaurant_name' ); // Emails not about a booking (e.g. a digest) have no booking card. $v = ! empty( $row['reference'] ) ? self::placeholders( $row ) : array(); $footer = Settings::get( 'email_footer' ); ob_start(); ?>