クロージャーが使えないときにフックへ引数を渡すメモです。
includes/class-sample.php
class Sample {
private $sample
public function set_sample_hook($args) {
$this->sample = $args;
add_action( 'sample_hook', array( $this, '_set_sample_hook') );
}
public function _set_sample_hook() {
// .... 処理
$foo = $this->sample['foo'];
$bar = $this->sample['bar'];
// ..... 処理
}
}
functions.php
require_once( get_template_directory() . '/includes/class-head.php' );
$sample = new Sample();
$args = array(
'foo' => 'foo',
'bar' => 'bar',
);
$sample->set_sample_hook($args);
No comments yet.
改行と段落タグは自動で挿入されます。
メールアドレスは表示されません。