Forked from wpmudev-sls/wpmudev-forminator-display-images-email-notifications.php
Created
June 4, 2022 15:06
-
-
Save glaubersilva/ed3450965d8f3798af62471ff3551fc8 to your computer and use it in GitHub Desktop.
[Forminator] Display images on email notifications
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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