register_activation_hookを使用すると「予期しない出力」のエラーがでる
【問題】
register_activation_hookをクラス内で使用しプラグインを作成する際に、「予期しない出力」や「header already sent」のエラーが出る。
【解決】
class TestClass{
$property = '';
function __construct(){
if(function_exists('register_activation_hook')){
register_activation_hook(__FILE__, array($this,'testFunc'));
}
public function testFunc(){
$this->property = 'property';
}
}
}
①register_activation_hookで実行する関数はprivateではなくpublicにしましょう。
②register_activation_hookで実行する関数内ではechoなどの出力をしないようにしましょう。
【備考】
①フックして実行する関数がprivate関数だとエラーになります。
②関数を実行する際にechoをするとエラーになります。
役に立った
3人中3人がこの投稿は役に立ったと言っています。