class sample{ public function __construct(){ add_action('init', array($this, 'samp') ); } public function samp(){ // 必须公开!! echo 'i did something'; } } new sample();