$form_name ) ) ); $rows = array(); foreach ( $config['steps'] as $step ) { foreach ( $step['fields'] as $field ) { if ( ! isset( $labels[ $field['key'] ] ) ) { continue; } $q = '' !== $field['label'] ? wp_strip_all_tags( $field['label'] ) : $step['title']; $rows[] = array( $q, (string) $labels[ $field['key'] ] ); } } $page_id = isset( $context['page_id'] ) ? (int) $context['page_id'] : 0; $head = sprintf( /* translators: 1: form name, 2: page path, 3: date. */ __( 'Form: %1$s Page: %2$s Sent: %3$s', 'reactwoo-atomic' ), $form_name, $page_id ? wp_make_link_relative( get_permalink( $page_id ) ) : '-', wp_date( 'j M Y, H:i T' ) ); $text = $head . "\n" . str_repeat( '-', 14 ) . "\n"; $html = '
' . esc_html( $head ) . '
| ' . esc_html( $r[0] ) . ' | ' . nl2br( esc_html( $r[1] ) ) . ' |
' . esc_html__( 'Lead tags:', 'reactwoo-atomic' ) . ' ' . esc_html( $tag_list ) . '
'; } if ( ! empty( $context['tracking'] ) && is_array( $context['tracking'] ) ) { $src = implode( ' ยท ', array_map( 'strval', array_filter( $context['tracking'], 'is_scalar' ) ) ); $text .= str_repeat( '-', 14 ) . "\n" . __( 'Source:', 'reactwoo-atomic' ) . ' ' . $src . "\n"; $html .= '' . esc_html__( 'Source:', 'reactwoo-atomic' ) . ' ' . esc_html( $src ) . '
'; } if ( $entry_id ) { $link = admin_url( 'post.php?post=' . (int) $entry_id . '&action=edit' ); $text .= sprintf( 'Entry #%d โ %s', $entry_id, $link ) . "\n"; $html .= ''; } $headers = array( 'Content-Type: text/html; charset=UTF-8' ); $reply_to = isset( $config['reply_to_field'] ) ? (string) $config['reply_to_field'] : 'email'; if ( isset( $result['clean'][ $reply_to ] ) && is_email( $result['clean'][ $reply_to ] ) ) { $name = isset( $result['clean']['name'] ) ? str_replace( array( "\r", "\n", '"', '<', '>' ), '', (string) $result['clean']['name'] ) : ''; $headers[] = 'Reply-To: ' . ( '' !== $name ? '"' . $name . '" ' : '' ) . '<' . $result['clean'][ $reply_to ] . '>'; } $mail = apply_filters( 'reactwoo/atomic/forms/email', array( 'to' => $to, 'subject' => $subject, 'body' => $html, 'text' => $text, 'headers' => $headers ), $config, $result, $entry_id ); return (bool) wp_mail( $mail['to'], $mail['subject'], $mail['body'], $mail['headers'] ); } /** * @param string $list Comma list. * @return string[] */ public static function recipients( $list ) { $out = array(); foreach ( explode( ',', (string) $list ) as $e ) { $e = sanitize_email( trim( $e ) ); if ( is_email( $e ) ) { $out[] = $e; } } return $out ? $out : array( get_option( 'admin_email' ) ); } /** * Replace {key} tokens; strips line breaks (header-safe). * * @param string $s Template. * @param array $vars Values. */ public static function tokens( $s, array $vars ) { $s = preg_replace_callback( '/\{([a-z0-9_]+)\}/', static function ( $m ) use ( $vars ) { return isset( $vars[ $m[1] ] ) && is_scalar( $vars[ $m[1] ] ) ? (string) $vars[ $m[1] ] : ''; }, (string) $s ); return trim( preg_replace( '/[\r\n]+|\s+โ\s*$/u', ' ', $s ) ); } }