strtolower( $form['title'] ), '{site}' => wp_specialchars_decode( get_bloginfo( 'name' ), ENT_QUOTES ), ); foreach ( $fields as $key => $value ) { $map[ '{' . $key . '}' ] = is_scalar( $value ) ? (string) $value : ''; } $out = strtr( $template, $map ); return trim( preg_replace( '/\{[a-z0-9_]+\}/i', '', $out ) ); } /** * Display value for a field (select options show their label). * * @param array $field Field definition. * @param string $value Stored value. */ function stackmime_forms_display_value( $field, $value ) { if ( 'consent' === $field['type'] ) { return '1' === (string) $value ? __( 'Yes', 'stackmime-forms' ) : ''; } if ( in_array( $field['type'], array( 'select', 'radio' ), true ) && isset( $field['options'][ $value ] ) ) { return (string) $field['options'][ $value ]; } if ( 'choices' === $field['type'] && '' !== (string) $value ) { $labels = array(); foreach ( explode( ',', (string) $value ) as $k ) { $labels[] = isset( $field['options'][ $k ] ) ? (string) $field['options'][ $k ] : $k; } return implode( ', ', $labels ); } if ( 'date' === $field['type'] && $value ) { $ts = strtotime( $value ); return $ts ? wp_date( get_option( 'date_format' ), $ts ) : $value; } return (string) $value; } /** * Send the business notification for an entry. Records the result on the entry. * * @param int $entry_id Entry ID. * @return bool Sent. */ function stackmime_forms_send_notification( $entry_id ) { $entry = stackmime_forms_entry( $entry_id ); $form = $entry ? stackmime_forms_get( $entry->form_id ) : null; if ( ! $entry || ! $form ) { return false; } $settings = stackmime_forms_settings(); $to = array_filter( array_map( 'sanitize_email', array_map( 'trim', explode( ',', $form['notify_to'] ? $form['notify_to'] : $settings['notify_to'] ) ) ), 'is_email' ); if ( ! $to ) { stackmime_forms_update( $entry_id, array( 'email_status' => 'failed', 'email_error' => __( 'No notification address is set (StackMime Forms → Settings).', 'stackmime-forms' ), ) ); return false; } $fields = $entry->fields; $contact = stackmime_forms_entry_contact( $form, $fields ); if ( ! isset( $fields['name'] ) ) { $fields['name'] = $contact['name']; } // {entry} = the entry number, so each notification has its own subject. Gmail otherwise merges repeat // subjects (e.g. two "New message from Sam") into one thread, and a second inbox may seem to miss it. $subject = stackmime_forms_fill( $form['subject'], array_merge( $fields, array( 'entry' => (string) (int) $entry_id ) ), $form ); $rows = ''; foreach ( $form['fields'] as $key => $field ) { if ( stackmime_forms_is_display_type( $field['type'] ) ) { continue; } $value = stackmime_forms_display_value( $field, $fields[ $key ] ?? '' ); if ( '' === $value ) { continue; } if ( 'email' === $field['type'] ) { $value_html = '' . esc_html( $value ) . ''; } elseif ( 'tel' === $field['type'] ) { $value_html = '' . esc_html( $value ) . ''; } else { $value_html = nl2br( esc_html( $value ) ); } $rows .= '
' . esc_html( wp_date( get_option( 'date_format' ) . ' ' . get_option( 'time_format' ) ) . ( $reply_note ? ' · ' . $reply_note : '' ) ) . '
' . '' . esc_html( sprintf( __( 'Sent from: %s', 'stackmime-forms' ), $entry->page_url ) ) . '
' : '' ) . '' . esc_html__( 'View this entry on the website', 'stackmime-forms' ) . '
' . '