Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save wpmudev-sls/e7960f08b4763c3c23fb4a7e212c0963 to your computer and use it in GitHub Desktop.
Save wpmudev-sls/e7960f08b4763c3c23fb4a7e212c0963 to your computer and use it in GitHub Desktop.
[Forminator] Display images on email notifications
<?php
/**
* Plugin Name: [Forminator] Display images on email notifications
* Plugin URI: https://wpmudev.com/
* Description: Display the images from e-sign, radio field and upload field in the email notifications.
* Author: Glauber Silva @ WPMUDEV
* Author URI: https://wpmudev.com/
* Task: SLS-3324
* License: GPLv2 or later
*
* @package Forminator_Display_Images_On_Email_Notifications
*/
defined( 'ABSPATH' ) || exit;
function wpmudev_display_images_on_email_notifications( $message, $custom_form, $data, $entry, $Forminator_CForm_Front_Mail ) {
foreach ( $custom_form->fields as $field ) {
$field_type = $field->raw['type'];
$field_name = $field->slug;
switch ( $field_type ) {
case 'radio':
foreach ( $field->raw['options'] as $radio_option ) {
if ( $radio_option['value'] == $data[ $field_name ] ) {
$image = $radio_option['image'];
$search = $radio_option['label'];
$replace = "<a href='" . $image . "' target='_blank' rel='noreferrer' title='View File'>" .
'<img src="' . $image . '" alt="' . $search . '"><br/>' . $search . '</a>';
$message = str_replace( $search, $replace, $message );
}
}
break;
case 'upload':
case 'signature':
$images = $entry->meta_data[ $field_name ]['value']['file']['file_url'];
foreach ( (array)$images as $image ) {
$search = "<a href='" . $image . "' target='_blank' rel='noreferrer' title='View File'>";
$replace = $search . '<img src="' . $image . '" alt="' . $field->raw['field_label'] . '"><br/>';
$message = str_replace( $search, $replace, $message );
}
break;
}
}
return $message;
}
add_filter( 'forminator_custom_form_mail_admin_message', 'wpmudev_display_images_on_email_notifications', 999, 5 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment