Foobox modal issue with Minify snippet
-
I have been using this well known php snippet to Minify HTML, CSS and JS code on my site: https://mylybrary.wordpress.com/2019/09/12/minify-html-without-plugin/
But when I installed the Lightbox & Modal Popup WordPress Plugin I noticed that I need to disable the snippet for modal foobox to work (compression broke the plugin somehow).
Is there any workaround to make the plugin work with this snippet?
Thank you!
-
Hi @jrvcosta
I’d like to test the EXACT code snippet that you added, to ensure that we are on the same page when it comes to the code snippet used.
If you don’t mind, could you kindly paste the code from your theme’s files where you’ve added it to your next response so that I can test it out from my end and try to figure out what’s causing the conflict? Thanks in advance.
Kind regards,
Elvis.Absolutely, Elvis! And thanks so much for your quick reply!
Here’s the minify snippet I was using:class FLHM_HTML_Compression { protected $flhm_compress_css = true; protected $flhm_compress_js = true; protected $flhm_info_comment = true; protected $flhm_remove_comments = true; protected $html; public function __construct($html) { if (!empty($html)) { $this->flhm_parseHTML($html); } } public function __toString() { return $this->html; } protected function flhm_bottomComment($raw, $compressed) { $raw = strlen($raw); $compressed = strlen($compressed); $savings = (($raw - $compressed) / $raw) * 100; $savings = round($savings, 2); return '<!--Código compactado. Redução de ' . $savings . '%. De ' . $raw . ' bytes para ' . $compressed . ' bytes-->'; } protected function flhm_minifyHTML($html) { $pattern = '/<(?<script>script).*?<\/script\s*>|<(?<style>style).*?<\/style\s*>|<!(?<comment>--).*?-->|<(?<tag>[\/\w.:-]*)(?:".*?"|\'.*?\'|[^\'">]+)*>|(?<text>((<[^!\/\w.:-])?[^<]*)+)|/si'; preg_match_all($pattern, $html, $matches, PREG_SET_ORDER); $overriding = false; $raw_tag = false; $html = ''; foreach ($matches as $token) { $tag = isset($token['tag']) ? strtolower($token['tag']) : null; $content = $token[0]; if (is_null($tag)) { if (!empty($token['script'])) { $strip = $this->flhm_compress_js; } elseif (!empty($token['style'])) { $strip = $this->flhm_compress_css; } elseif ( $content == '<!-- Sem redução -->' ) { $overriding = !$overriding; continue; } elseif ($this->flhm_remove_comments) { if (!$overriding && $raw_tag != 'textarea') { $content = preg_replace( '/<!--(?!\s*(?:\[if [^\]]+]|<!|>))(?:(?!-->).)*-->/s', '', $content ); } } } else { if ($tag == 'pre' || $tag == 'textarea') { $raw_tag = $tag; } elseif ($tag == '/pre' || $tag == '/textarea') { $raw_tag = false; } else { if ($raw_tag || $overriding) { $strip = false; } else { $strip = true; $content = preg_replace( '/(\s+)(\w++(?<!\baction|\balt|\bcontent|\bsrc)="")/', '$1', $content ); $content = str_replace(' />', '/>', $content); } } } if ($strip) { $content = $this->flhm_removeWhiteSpace($content); } $html .= $content; } return $html; } public function flhm_parseHTML($html) { $this->html = $this->flhm_minifyHTML($html); if ($this->flhm_info_comment) { $this->html .= "\n" . $this->flhm_bottomComment($html, $this->html); } } protected function flhm_removeWhiteSpace($str) { $str = str_replace("\t", ' ', $str); $str = str_replace("\n", '', $str); $str = str_replace("\r", '', $str); while (stristr($str, ' ')) { $str = str_replace(' ', ' ', $str); } return $str; } } function flhm_wp_html_compression_finish($html) { return new FLHM_HTML_Compression($html); } function flhm_wp_html_compression_start() { ob_start('flhm_wp_html_compression_finish'); } add_action('get_header', 'flhm_wp_html_compression_start');Hi @jrvcosta
I’ve been looking into this issue and even went ahead and tested the code snippet on my local WordPress installation with the latest version of WordPress (Version 5.8).
However, once I added the exact code you shared with us, it actually made my site’s pages not to load and give out a 504 error message. This happened whether FooBox was enabled or disabled. When I deleted the code, the pages loaded perfectly as they did before the code was added.
I suspect that there might be some buggy lines on the code you’ve shared with us, and it may possibly be creating some conflict with the latest WordPress version. I’d like to kindly ask you to get in touch with a developer to have another look at the code.
Currently, becasue that is out of our scope of support so I am unable to assist you with it.
Thanks.
Kind regards,
Elvis.Thank you very much for the effort, Elvis.
There may have been a problem pasting here. I can only say that I copied it directly from the snippet on my website (Code Snippets plugin).
May I ask you to do just one last test with the original code, from Github?
It´s here: https://gist.github.com/MrJoshFisher/481251d1e89d1c5a25c8aa82482cd747Best wishes,
José.Hi @jrvcosta
I’ve tested out the original code that’s on the Github page you shared with me and I can confirm that it’s working perfectly on the latest version of WordPress (version 5.8) and with FooBox enabled.
Thanks.
Kind regards,
Elvis.Well, this is very strange!
See what happens to me: I have both plugins installed on my WordPress 5.8: FooBox Image Lightbox 2.7.16 and FooGallery 2.0.39.
They work fine without the minify snippet but when I activate this code the galleries keeps showing normally but without the image modal. The most curious thing is that if I go to the menu of the Foobox plugin (wp-admin/admin.php?page=foobox-image-lightbox) all demos works normally!
Only the front-end of site stops showing the modal images. When I click on an image that I know has the class=”foobox” the image itself is displayed instead (no dialog box/popup window over the CURRENT page).
I thought it might be some error because the minify compression of the Foobox JS, but apparently it isn’t.
The topic ‘Foobox modal issue with Minify snippet’ is closed to new replies.