Skip to content

Commit 2c3d37a

Browse files
gpqr-decode-html-entities-in-url.php: Added new snippet to decode HTML entities in QR codes that only consist of a URL.
1 parent 4c582f9 commit 2c3d37a

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<?php
2+
/**
3+
* Gravity Perks // QR Code // Decode HTML entities in QR codes that only consist of a URL
4+
* https://gravitywiz.com/documentation/gravity-forms-qr-code/
5+
*
6+
* Instructions: https://gravitywiz.com/documentation/how-do-i-install-a-snippet/
7+
*/
8+
add_filter( 'gpqr_content_pre_generate', function ( $content ) {
9+
// Only modify QR codes that only consist of a URL.
10+
if ( ! preg_match( '/^https?:\/\//', $content ) ) {
11+
return $content;
12+
}
13+
14+
// Prevent infinite loop.
15+
if ( html_entity_decode( $content ) === $content ) {
16+
return $content;
17+
}
18+
19+
// Use while loop in case there are recursively encoded HTML entities (e.g. &amp;amp;).
20+
while ( html_entity_decode( $content ) !== $content ) {
21+
$content = html_entity_decode( $content );
22+
}
23+
24+
return $content;
25+
} );

0 commit comments

Comments
 (0)