Wednesday, January 11, 2023
HomeWordPress Developmentplugins - Buffered output in chunks and shortcode - how do I...

plugins – Buffered output in chunks and shortcode – how do I obtain that?


I ponder methods to obtain outputbuffering in chunks when utilizing a shortcode?

With out outbuffering:
(This works and will get at right location (beneath the precise header in template due to return $html;)

add_shortcode( 'showtable', array ( $this, 'source_to_table') );
perform source_to_table( $attrs ) 
{
    code...
    $html="";
    for($row_values as $r) {
        $html .= $r . '<br>';
    }
    return $html;
}

With outbuffering:
(This works however is positioned immediately at high (earlier than the precise header in template as a result of no return exists. but when I’ve a return then complete level of utilizing output buffering chunks are gone!?)

add_shortcode( 'showtable', array ( $this, 'buffered_source_to_table') );
perform buffered_source_to_table( $attrs ) 
{
    code...
    $chunk = 0;
    for($row_values as $r) {
        ob_start();
        echo $r.'<br>';
        $chunk++;
        if ($chunk % 100 == 0) ob_flush();
    }
    ob_flush();
    
}

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

- Advertisment -
Google search engine

Most Popular

Recent Comments