Support » Plugin: Insert PHP Code Snippet » Plugin breaks output buffers started in other plugins and themes

  • Resolved Nextendweb

    (@nextendweb)


    Hi @f1logic,
    In wp-content/plugins/insert-php-code-snippet/shortcode-handler.php, you close other output buffer with not reason. You should remove that code to allow other plugins to work properly.

    
    $tmp = ob_get_contents();
    if (strlen($tmp) > 0) ob_clean();
    

    Also you should remove at the end of the file:
    echo $tmp;

Viewing 7 replies - 1 through 7 (of 7 total)
  • For users: if you experience something strange on your content when you use this plugin, try to add the following file to your /wp-content/plugins/ folder and activate the plugin: https://gist.github.com/nextend/c7201df29919f5719cfed767584fc295

    This will permanently fix the output buffer related problems.

    • This reply was modified 11 months, 2 weeks ago by  Nextendweb.
    Plugin Author f1logic

    (@f1logic)

    hi @nextendweb

    We are not clearing the buffer without considering other output.
    We are doing the following
    >copy contents from buffer to a temporary variable
    >clear the buffer
    >generate output from our shortcode in the buffer
    >copy our shortcode output from bufffer
    >clear buffer again.
    >put back the temporary variable to buffer again

    Hope it shouldn’t disturb any other code

    @f1logic – I’m the ‘end user’ who discovered this problem. I use both Smart Slider 3 and Insert PHP Code Snippet. I updated Smart Slider yesterday and it broke. Their developers investigated and found it was your plugin causing a conflict.

    I don’t understand what the coding issue is here, and Nextendweb have provided a work around with their ‘fix’ plugin, but are you going to address the root cause in your plugin and issue an update to resolve it? It’s not clear from your reply above but I can no longer use Smart Slider 3 and Insert PHP Code Snippet together without the ‘fix’.

    @f1logic, I see what is the real problem. It is new for me too.

    We use output buffer with callback:

    
    ob_start('my_callback);
    function my_callback($buffer){
        // Here we modify the buffer
        return $buffer;
    }
    

    It seems like calling ob_clean on a buffer with callback, it fires the callback every ob_clean call. Stacktrace: https://i.imgur.com/OXFSsaI.png

    I think you use ob_clean and the $tmp variable for reason, could you tell me why?
    I think you use them, because the output buffer you open later stay opened and you have some bugs when your shortcode runs multiple times. Is that right?

    Things you do currently:

    
    $tmp=ob_get_contents();
    if(strlen($tmp)>0)
      ob_clean();
    ob_start();
    
    //some business logic
    
    eval($content_to_eval);
    $xyz_em_content = ob_get_contents();
    ob_clean();
    echo $tmp;
    return $xyz_em_content;
    

    You just need to open an output buffer which will store the result of the eval. Then use ob_get_clean which will returns the content of the output buffer and also it closes the output buffer.

    
    ob_start();
    
    //some business logic
    
    eval($content_to_eval);
    return ob_get_clean();
    Plugin Author f1logic

    (@f1logic)

    @nextendweb

    thanks for the solution. we can do as suggested.

    hope the ob_get_clean in the new code wont trigger your callback

    Thanks @f1logic,
    it won’t trigger that as it closes only your output buffer 🙂

    Plugin Author f1logic

    (@f1logic)

    plugin updated

Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘Plugin breaks output buffers started in other plugins and themes’ is closed to new replies.