Created
May 8, 2024 20:47
-
-
Save Qubadi/8cf03a5ae226415c20898bbc1a38b01f to your computer and use it in GitHub Desktop.
Jetformbuilder multi-image display for email submissions
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
Short Description: | |
This shortcode enhances JetFormBuilder by allowing it to format and display multiple images within email notifications. | |
Upon form submission, it automatically converts a comma-separated list of image URLs into | |
individually styled HTML <img> tags, complete with custom spacing for optimal presentation in emails. | |
1. Copy the following PHP code and create a snippet using your snippet plugins. Paste the code into the plugin and save it. | |
2. Create a media field in your form. | |
3. In the post submit actions, set it to send email. Open the email content section and insert the shortcode | |
below into the content area: | |
[process_gallery urls="%gallery%"], use the same field name gallery, or change it to your field name. | |
________________________________________ | |
// Function to process gallery URLs and format them into HTML image tags | |
function process_gallery_shortcode($atts) { | |
// Extract URLs attribute from shortcode attributes | |
$gallery_urls = shortcode_atts(array( | |
'urls' => '', | |
), $atts); | |
// Split the string of URLs into an array | |
$urls = explode(',', $gallery_urls['urls']); | |
$output = ''; | |
foreach ($urls as $url) { | |
// Generate an image tag for each URL, with added margin for spacing | |
$output .= '<img src="' . esc_url(trim($url)) . '" style="width: 200px; max-width: 200px; height: 150px; object-fit: cover; border-radius: 10px; box-shadow: rgba(0, 0, 0, 0.21) 0px 30px 30px -10px; margin-right: 10px;">'; | |
} | |
return rtrim($output, 'margin-right: 10px;'); // Remove the right margin from the last image if necessary | |
} | |
add_shortcode('process_gallery', 'process_gallery_shortcode'); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment