: str_replace(): Passing null to parameter #2 ($replace) of type array|string is deprecated in
* Convert text formatted HTML. This is primarily for turning line breaks
* into <p> and <br/> tags.
* @param string $message Text to convert.
public function text_to_html( $message ) {
if ( 'text/html' === $this->content_type || true === $this->html ) {
$message = wpautop( $message );
* Decodes entities and sanitized (keeping line breaks) by default.
* @uses wpforms_decode_string()
* @since 1.6.0 Deprecated 2 params: $sanitize, $linebreaks.
* @param string $string String that may contain tags.
public function process_tag( $string = '' ) {
return wpforms_process_smart_tags( $string, $this->form_data, $this->fields, $this->entry_id, 'email' );
* Process the all fields smart tag if present.
* @param bool $is_html_email Toggle to use HTML or plaintext.
public function wpforms_html_field_value( $is_html_email = true ) { // phpcs:ignore
if ( empty( $this->fields ) ) {
if ( empty( $this->form_data['fields'] ) ) {
// Hooks into the email field.
do_action( 'wpforms_email_field', $this );
$this->get_template_part( 'field', $this->get_template(), true );
$field_template = ob_get_clean();
// Check to see if user has added support for field type.
$other_fields = apply_filters( 'wpforms_email_display_other_fields', [], $this );
foreach ( $this->form_data['fields'] as $field_id => $field ) {
// If the field exists in the form_data but not in the final
// field data, then it's a non-input based field, "other fields".
if ( empty( $this->fields[ $field_id ] ) ) {
if ( empty( $other_fields ) || ! in_array( $field['type'], $other_fields, true ) ) {
if ( $field['type'] === 'divider' ) {
$field_name = ! empty( $field['label'] ) ? str_repeat( '—', 3 ) . ' ' . $field['label'] . ' ' . str_repeat( '—', 3 ) : null;
$field_val = ! empty( $field['description'] ) ? $field['description'] : '';
} elseif ( $field['type'] === 'pagebreak' ) {
if ( ! empty( $field['position'] ) && $field['position'] === 'bottom' ) {
$title = ! empty( $field['title'] ) ? $field['title'] : esc_html__( 'Page Break', 'wpforms-lite' );
$field_name = str_repeat( '—', 6 ) . ' ' . $title . ' ' . str_repeat( '—', 6 );
} elseif ( $field['type'] === 'html' ) {
if ( $this->is_field_conditionally_hidden( $field['id'] ) ) {
$field_name = ! empty( $field['name'] ) ? $field['name'] : esc_html__( 'HTML / Code Block', 'wpforms-lite' );
$field_val = $field['code'];
} elseif ( $field['type'] === 'content' ) {
if ( $this->is_field_conditionally_hidden( $field['id'] ) ) {
$field_name = esc_html__( 'Content', 'wpforms-lite' );
$field_val = $field['content'];
! apply_filters( 'wpforms_email_display_empty_fields', false ) &&
( ! isset( $this->fields[ $field_id ]['value'] ) || (string) $this->fields[ $field_id ]['value'] === '' )
if ( $field['type'] === 'payment-total' ) {
$field_name = isset( $this->fields[ $field_id ]['name'] ) ? $this->fields[ $field_id ]['name'] : '';
// Replace the payment total value if an order summary is enabled.
// Ideally, it could be done through the `wpforms_html_field_value` filter,
// but needed data is missed there, e.g. entry data ($this->fields).
if ( ! empty( $field['summary'] ) ) {
$field_val = $this->process_tag( '{order_summary}' );
$field_val = $this->fields[ $field_id ]['value'];
$field_name = isset( $this->fields[ $field_id ]['name'] ) ? $this->fields[ $field_id ]['name'] : '';
$field_val = empty( $this->fields[ $field_id ]['value'] ) && ! is_numeric( $this->fields[ $field_id ]['value'] ) ? '<em>' . esc_html__( '(empty)', 'wpforms-lite' ) . '</em>' : $this->fields[ $field_id ]['value'];
if ( empty( $field_name ) && null !== $field_name ) {
$field_name = sprintf( /* translators: %d - field ID. */
esc_html__( 'Field ID #%s', 'wpforms-lite' ),
wpforms_validate_field_id( $field['id'] )
$field_item = $field_template;
$field_item = str_replace( 'border-top:1px solid #dddddd;', '', $field_item );
$field_item = str_replace( '{field_name}', $field_name, $field_item );
$field_item = str_replace(
'wpforms_html_field_value',
isset( $this->fields[ $field_id ] ) ? $this->fields[ $field_id ] : $field,
$message .= wpautop( $field_item );
foreach ( $this->fields as $field ) {
! apply_filters( 'wpforms_email_display_empty_fields', false ) &&
( ! isset( $field['value'] ) || (string) $field['value'] === '' )
$field_val = empty( $field['value'] ) && ! is_numeric( $field['value'] ) ? esc_html__( '(empty)', 'wpforms-lite' ) : $field['value'];
$field_name = $field['name'];
if ( empty( $field_name ) ) {
$field_name = sprintf( /* translators: %d - field ID. */
esc_html__( 'Field ID #%s', 'wpforms-lite' ),
wpforms_validate_field_id( $field['id'] )
$message .= '--- ' . $field_name . " ---\r\n\r\n";
$field_value = $field_val . "\r\n\r\n";
$message .= apply_filters( 'wpforms_plaintext_field_value', $field_value, $field, $this->form_data );
if ( empty( $message ) ) {
$empty_message = esc_html__( 'An empty form was submitted.', 'wpforms-lite' );
$message = $is_html_email ? wpautop( $empty_message ) : $empty_message;
* Email kill switch if needed.
public function is_email_disabled() {
return (bool) apply_filters( 'wpforms_disable_all_emails', false, $this );
* Get the enabled email template.
* @return string When filtering return 'none' to switch to text/plain email.
public function get_template() {
if ( ! $this->template ) {
$this->template = wpforms_setting( 'email-template', 'default' );
return apply_filters( 'wpforms_email_template', $this->template );
* Retrieve a template part. Taken from bbPress.
* @param string $slug Template file slug.
* @param string $name Optional. Default null.
* @param bool $load Maybe load.
public function get_template_part( $slug, $name = null, $load = true ) {
$templates[] = $slug . '-' . $name . '.php';
$templates[] = $slug . '.php';
// Return the part that is found.
return $this->locate_template( $templates, $load, false );
* Retrieve the name of the highest priority template file that exists.
* Search in the STYLESHEETPATH before TEMPLATEPATH so that themes which
* inherit from a parent theme can just overload one file. If the template is
* not found in either of those, it looks in the theme-compat folder last.
* @param string|array $template_names Template file(s) to search for, in order.
* @param bool $load If true the template file will be loaded if it is found.
* @param bool $require_once Whether to require_once or require. Default true.
* Has no effect if $load is false.
* @return string The template filename if one is located.
public function locate_template( $template_names, $load = false, $require_once = true ) {
// Try to find a template file.
foreach ( (array) $template_names as $template_name ) {
// Continue if template is empty.
if ( empty( $template_name ) ) {
// Trim off any slashes from the template name.
$template_name = ltrim( $template_name, '/' );
// Try locating this template file by looping through the template paths.
foreach ( $this->get_theme_template_paths() as $template_path ) {
$validated_path = Templates::validate_safe_path(
$template_path . $template_name,
$located = $validated_path;
if ( ( true === $load ) && ! empty( $located ) ) {
load_template( $located, $require_once );
* Return a list of paths to check for template locations
public function get_theme_template_paths() {
$template_dir = 'wpforms-email';
1 => trailingslashit( get_stylesheet_directory() ) . $template_dir,
10 => trailingslashit( get_template_directory() ) . $template_dir,
100 => WPFORMS_PLUGIN_DIR . 'includes/emails/templates',
$file_paths = apply_filters( 'wpforms_email_template_paths', $file_paths );
// Sort the file paths based on priority.
ksort( $file_paths, SORT_NUMERIC );
return array_map( 'trailingslashit', $file_paths );
* Perform email subject preparation: process tags, remove new lines, etc.
* @param string $subject Email subject to post-process.
private function get_prepared_subject( $subject ) {
$subject = $this->process_tag( $subject );
$subject = trim( str_replace( [ "\r\n", "\r", "\n" ], ' ', $subject ) );
return wpforms_decode_string( $subject );
* If CL is enabled and the field is conditionally hidden, hide it from message.
* @param int $field_id Field ID.
private function is_field_conditionally_hidden( $field_id ) {
return ! empty( $this->form_data['fields'][ $field_id ]['conditionals'] ) && ! wpforms_conditional_logic_fields()->field_is_visible( $this->form_data, $field_id );