Skip to content

Commit c77072f

Browse files
committed
Added styling support for displaying images as a grid.
Removed support for displaying non-image file types and made links mandatory.
1 parent f43ab70 commit c77072f

File tree

1 file changed

+29
-40
lines changed

1 file changed

+29
-40
lines changed

gp-file-upload-pro/gpfup-display-images-in-entry-details.php

Lines changed: 29 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,8 @@
33
* Gravity Perks // File Upload Pro // Show Images in Entry Details
44
* https://gravitywiz.com/documentation/gravity-forms-file-upload-pro/
55
*
6-
* Instead of an unordered list with links to the files, display the images. Non-images will still
7-
* be displayed as a text link.
8-
*
9-
* By default, the images will be hyperlinks linking to the original image.
6+
* Instead of an unordered list with links to the files, display the images. Image previews will be hyperlinked to the
7+
* original image.
108
*
119
* Instructions: https://gravitywiz.com/documentation/how-do-i-install-a-snippet/
1210
*/
@@ -33,45 +31,36 @@
3331
$html = '';
3432

3533
foreach ( $file_urls as $file_index => $file_url ) {
36-
/* Skip file if the file is not an image supported by mPDF */
37-
$extension = pathinfo( $file_url, PATHINFO_EXTENSION );
38-
$file_name = pathinfo( $file_url, PATHINFO_FILENAME );
39-
40-
if ( ! in_array( strtolower( $extension ), array(
41-
'gif',
42-
'png',
43-
'jpg',
44-
'wmf',
45-
'svg',
46-
'bmp',
47-
), true ) ) {
48-
// Link directly to other file types (e.g. PDF) without further processing
49-
$html .= '<ul><li><a href="' . esc_url( $file_url ) . '">' . $file_name . '</a>' . "</li></ul>\n";
50-
continue;
51-
}
52-
53-
if ( $link_images ) {
54-
$html .= '<a href="' . esc_url( $file_url ) . '"><img src="' . $file_url . '" style="max-width: 100%" /></a>' . "\n";
55-
} else {
56-
$html .= '<img src="' . $file_url . '" style="max-width: 100%" />' . "\n";
57-
}
58-
59-
if ( count( $file_urls ) > 1 && $file_index + 1 < count( $file_urls ) ) {
60-
$html .= "<br />\n";
61-
}
34+
$html .= '<a href="' . esc_url( $file_url ) . '"><img src="' . $file_url . '" style="max-width: 100%" /></a>';
6235
}
6336

6437
/**
6538
* Strip all HTML except for img, a, ul, li, and br tags.
6639
*/
67-
return wp_kses( $html, array(
68-
'img' => array(
69-
'src' => array(),
70-
'style' => array(),
71-
),
72-
'a' => array( 'href' => array() ),
73-
'br' => array(),
74-
'ul' => array(),
75-
'li' => array(),
76-
) );
40+
return '<style>
41+
.gpfup-preview-container { display: flex; flex-wrap: wrap; }
42+
.gpfup-preview-container a {
43+
flex: 1;
44+
flex-basis: 25%;
45+
max-width: 25%;
46+
overflow: hidden;
47+
padding: 0.4rem;
48+
box-sizing: border-box;
49+
}
50+
.gpfup-preview-container img {
51+
display: block;
52+
object-fit: cover;
53+
aspect-ratio: 1/1;
54+
}
55+
</style>
56+
<div class="gpfup-preview-container">' . wp_kses( $html, array(
57+
'img' => array(
58+
'src' => array(),
59+
'style' => array(),
60+
),
61+
'a' => array( 'href' => array() ),
62+
'br' => array(),
63+
'ul' => array(),
64+
'li' => array(),
65+
) ) . '</div>';
7766
}, 10, 4 );

0 commit comments

Comments
 (0)