猿问

如何让ob_start()在Wordpress插件中的类中工作?

我试图将ob_start添加到我的Wordpress插件中的类中,如下所示:


class ObStart {

  public static function callback($buffer){

    return $buffer;

  }


  public static function add_ob_start(){

    ob_start("callback");

  }


  public static function flush_ob_end(){

    ob_end_flush();

  }

}


add_action('init', array( 'ObStart', 'add_ob_start' ) );

add_action('wp_footer', array( 'ObStart', 'flush_ob_end' ) );



这似乎不起作用,而是导致此错误:


Warning:  ob_start(): function 'callback' not found or invalid function name in <b>\wp-content\plugins\timeline-plugin\obstart.php on line 8


Notice:  ob_start(): failed to create buffer in \wp-content\plugins\timeline-plugin\obstart.php on line 8


Warning:  Cannot modify header information - headers already sent by (output started at \wp-includes\formatting.php:5520) in \wp-includes\pluggable.php on line 1251


Warning:  Cannot modify header information - headers already sent by (output started at \wp-includes\formatting.php:5520) in \wp-includes\pluggable.php</b> on line 1254

是否可以让ob_start在课堂上工作?如果是,我哪里出问题了?


元芳怎么了
浏览 172回答 1
1回答

ABOUTYOU

class Obstart&nbsp;{&nbsp;&nbsp; &nbsp; &nbsp; public static function callback($buffer)&nbsp; &nbsp; &nbsp; {&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;return $buffer;&nbsp;&nbsp; &nbsp; &nbsp; }&nbsp;&nbsp; &nbsp; &nbsp; public static function add_ob_start()&nbsp; &nbsp; &nbsp; {&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;global $buffer;&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;ob_start( self::callback($buffer) );&nbsp;&nbsp; &nbsp; &nbsp; }&nbsp; &nbsp; &nbsp; public static function flush_ob_end()&nbsp; &nbsp; &nbsp; {&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;ob_end_flush();&nbsp;&nbsp; &nbsp; &nbsp; }&nbsp;}&nbsp;add_action('init', array( 'Obstart', 'add_ob_start' ) );&nbsp;add_action('wp_footer', array( 'Obstart', 'flush_ob_end' ) );
随时随地看视频慕课网APP
我要回答