|
3 | 3 | * Gravity Perks // File Upload Pro // Show Images in Entry Details |
4 | 4 | * https://gravitywiz.com/documentation/gravity-forms-file-upload-pro/ |
5 | 5 | * |
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. |
10 | 8 | * |
11 | 9 | * Instructions: https://gravitywiz.com/documentation/how-do-i-install-a-snippet/ |
12 | 10 | */ |
|
33 | 31 | $html = ''; |
34 | 32 |
|
35 | 33 | 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>'; |
62 | 35 | } |
63 | 36 |
|
64 | 37 | /** |
65 | 38 | * Strip all HTML except for img, a, ul, li, and br tags. |
66 | 39 | */ |
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>'; |
77 | 66 | }, 10, 4 ); |
0 commit comments