Hi @oganianarman,
thank you for reporting this issue, we will investigate it. What I need is an installer to one of your theme and any special things to enable in your theme if needed. I will check how do you handle output buffering and based on that I will fix this issue in Smart Slider.
Few years ago I had a thorough research about output buffering in plugins and themes. There are a lot of misunderstanding about output buffers. Here you can read about my findings: https://github.com/nextend/wp-ob-plugins-themes
It turned out that the only failsafe way of using output buffers if you use ob_start
with callback function. If you start a new output buffer somewhere around template_redirect
action, you can not be sure that the same output buffer will be accessible at shutdown for example.
Hey @nextendweb,
Thanks for response. Did you see the pattern example I shared? I think you misunderstood the logic of buffering.
Let’s say you calling ob_start once,but you are removing others buffers https://prnt.sc/vfq0o2, which doesn’t belong to you(it’s the same if you will open 1 div tag but will close 3 div tag).
You should just use a $varible to calculate how many times you are opening ob_start instead of using count of ob_list_handlers in here https://prnt.sc/vfq0o2 .
@oganianarman, output buffer is a FIFO stack. Your idea about counting is wrong.
<?php
ob_start(); // #1
ob_start(); // #2
ob_start(); // #3
ob_get_clean(); // this will close #3
ob_get_clean(); // this will close #2
ob_get_clean(); // this will close #1
There are examples:
template_redirect
: Smart Slider opens #2, then Your theme opens #3.
wp_footer
: Smart Slider wants to close #2, but #3 is still open. It must call 2 ob_get_clean()
to close #2 buffer.
There is no standard in WordPress how to work with output buffers, so anything can happen with them. I have seen several conflicts with output buffers in the past 6 years. So I’m not telling you that it is your theme’s fault also not Smart Slider fault either. It is the way how output buffering works. This is why I told that in my experience the only fail safe method if you use output callback for your ob_start
call.
I wrote you in private asking for a theme installer to test. I’m willing to check the situation and we will do our best to make this conflict go away.
Hey Again,
Your example isn’t correct
1. ob_start – Our code (has priority is -99999999)
2. ob_start – Your code
and OUR ob_get_clean is working in the last(shutdown hook has 99999999 priority)
BUT your loop will remove it , here is screenshot of buffer handlers(#2 our ,which will be removed in your loop)
http://prntscr.com/vg6kbu
It means the problem in your side.
@oganianarman
https://prnt.sc/vfq0o2
in_array
checking if our callback is in the ob_list_handlers()
-> array
.
Also if we reach our callback, we break the loop so no other output buffer handlers gets closed.
If you check your last screenshot, you can see that Smart Slider’s output buffer was opened sooner than yours. Also it seems likes Smart Slider closes the buffer closes earlier than you. This is how it looks like:
<?php
ob_start(); // Smart Slider opens
ob_start(); // Themify opens
ob_get_clean(); // Smart Slider closes as its not our callback
ob_get_clean(); // Smart Slider closes as its our callback and breaks the loop
ob_get_clean(); // Themify tries, but there is no output buffer left. Smart Slider closed it.
I’m open for changes, but without sending you an installer of your theme where I could test I can not change anything. Proper testing is important for me.
Hey @nextendweb,
I really don’t have time for debats,I can only suggest you instead of writting hacks for plugins/themes or suggesting some plugins to change their code to work with your plugin(https://wordpress.org/support/topic/conflict-with-smart-slider-3-output-buffering/), fix your code logic. It’s good plugin and you are good developer,I am sure you can do it. We are using the buffer in a lot of places in our themes(for lazy loading,webp converter,audio,video,css concate and etc.) and we still haven’t had ANY issue with others plugins who are using the buffer.
@oganianarman as I told you I need an installer of your theme. You can send it privately, you know our email address, I sent you the request twice. Our shared interest to solve this issue and as you can see I do not demand the fix from you, I’m not even arguing with you. I just want to be able to reproduce the problem, that’s all.
What would you do if I tell you there is an issue somewhere in your code with another plugin which you do not have access? Would you change anything in your code without testing the issue yourself?
@oganianarman, I just bought one of your theme and checked your code. I will make a fix tomorrow in Smart Slider for Themify themes.
BTW.: class TFCache
:
I do understand that your implementation works, but it’s wrong! You open an output buffer in template_include
and you want to close the same output buffer at late shutdown. If there are multiple plugins installed, there is a chance that you are closing someone else’s output buffer. It might not result in bugs most of the times, but it might…
The fail-safe solution on your side would be the following. Only drawback is that you can not start new output buffer inside tf_cache_end
and you can not echo anything there:
private static function tf_cache_start() {
// ....
define('TF_CACHE',true);
ob_start(array(__CLASS__,'tf_cache_end'));
}
public static function tf_cache_end($html, $phase) {
if ($phase & PHP_OUTPUT_HANDLER_FINAL || $phase & PHP_OUTPUT_HANDLER_END) {
//.....
$html=preg_replace(..., ..., $html);
//.....
}
return $html;
}
I do not mind if you do not implement it. I just wanted to let you know.
Hi @oganianarman,
I have implemented the required changes to make Smart Slider to properly work with Themify theme’s cache system. Let me know if there’s any other area where you experience bugs related to output buffers.
You can download the fixed version for testing purpose from here:
https://www.dropbox.com/s/joa1m78uwp287kp/smart-slider3-wordpress-free.zip?dl=1
@oganianarman, the fix for this issue is out in version 3.4.1.12. Thank you for reporting it!