$v ) { if ( '_' === substr( (string) $k, 0, 1 ) ) { continue; // Internal (e.g. _files). } if ( ! isset( $known[ $k ] ) ) { $rows[ $k ] = array( $k, self::text( $v ) ); // A field that was removed from the form later. } } return $rows; } /** Replace {form}, {all_fields}, {name} and {field_key} tags. */ public static function tags( $text, array $form, array $data, $html = false ) { $rows = self::rows( $form, $data ); $all = array(); foreach ( $rows as $r ) { $all[] = $r[0] . ': ' . $r[1]; } $name = ''; foreach ( array( 'name', 'full_name', 'your_name', 'first_name' ) as $k ) { if ( ! empty( $data[ $k ] ) ) { $name = self::text( $data[ $k ] ); break; } } $map = array( '{form}' => $form['name'], '{all_fields}' => implode( "\n", $all ), '{name}' => $name, '{site}' => wp_specialchars_decode( get_bloginfo( 'name' ), ENT_QUOTES ), ); foreach ( $data as $k => $v ) { if ( '_' !== substr( (string) $k, 0, 1 ) ) { $map[ '{' . $k . '}' ] = self::text( $v ); } } $out = strtr( $text, $map ); $out = preg_replace( '/\{[a-z0-9_]+\}/', '', $out ); return $html ? nl2br( esc_html( $out ) ) : $out; } private static function table( array $rows ) { $h = ''; foreach ( $rows as $r ) { $h .= ''; } return $h . '
' . esc_html( $r[0] ) . '' . nl2br( esc_html( $r[1] ) ) . '
'; } public function notify( array $form, array $data, $entry_id, $email, $product_id = 0, $page = '' ) { $s = $form['settings']; $headers = array( 'Content-Type: text/html; charset=UTF-8' ); if ( 'yes' === $s['notify'] ) { $to = $s['notify_to'] ? $s['notify_to'] : get_option( 'admin_email' ); $body = self::table( self::rows( $form, $data ) ); $meta = array(); if ( $product_id && function_exists( 'wc_get_product' ) ) { $p = wc_get_product( $product_id ); if ( $p ) { $meta[] = esc_html__( 'Product', 'byltcommerce-toolkit' ) . ': ' . esc_html( $p->get_name() ) . ''; } } if ( $page ) { $meta[] = esc_html__( 'Sent from', 'byltcommerce-toolkit' ) . ': ' . esc_html( $page ) . ''; } if ( $entry_id ) { $meta[] = '' . esc_html__( 'View entry', 'byltcommerce-toolkit' ) . ''; } if ( $meta ) { $body .= '

' . implode( '
', $meta ) . '

'; } $body = (string) apply_filters( 'bylt_form_notify_body', $body, $form, $data, $entry_id ); $h = $headers; if ( $email ) { $h[] = 'Reply-To: ' . $email; } wp_mail( $to, self::tags( $s['notify_subject'], $form, $data ), $body, apply_filters( 'bylt_form_notify_headers', $h, $form, $data ) ); } if ( 'yes' === $s['confirm'] && $email ) { $body = '
' . self::tags( $s['confirm_message'], $form, $data, true ) . '
'; wp_mail( $email, self::tags( $s['confirm_subject'], $form, $data ), $body, $headers ); } } }