我在 wordpress 插件模型中添加 add_action 但它显示错误意外标识符
i am adding add_action inside a model of wordpress plugin but it is showing error unexpected identifier
this is my model file
class customactionsModel {
function getMessagekey(){
$key = 'customfunction'; if(is_admin()){$key = 'admin_'.$key;}return $key;
}
function __construct(){
add_action( 'wp_ajax_admission_form', 'admission_form');
add_action( 'wp_ajax_nopriv_admission_form', 'admission_form');
}
function admission_form() {
//call hook;
echo "ljdlf";
wp_die();
}
}
i am facing error that is:
error - unexpected identifier "add_action", expecting "function" or "const" in Standard input code
您的 class 定义不正确。您没有定义功能的范围,您需要在添加操作
中参考 class
class customactionsModel {
public function getMessagekey(){ //May needs to be a private function
$key = 'customfunction'; if(is_admin()){$key = 'admin_'.$key;}return $key;
}
public function __construct(){
add_action( 'wp_ajax_admission_form', [$this,'admission_form']);
add_action( 'wp_ajax_nopriv_admission_form', [$this,'admission_form']);
}
public function admission_form() {
//call hook;
echo "ljdlf";
wp_die();
}
}
this is my model file
class customactionsModel {
function getMessagekey(){
$key = 'customfunction'; if(is_admin()){$key = 'admin_'.$key;}return $key;
}
function __construct(){
add_action( 'wp_ajax_admission_form', 'admission_form');
add_action( 'wp_ajax_nopriv_admission_form', 'admission_form');
}
function admission_form() {
//call hook;
echo "ljdlf";
wp_die();
}
}
i am facing error that is:
error - unexpected identifier "add_action", expecting "function" or "const" in Standard input code
您的 class 定义不正确。您没有定义功能的范围,您需要在添加操作
中参考 classclass customactionsModel {
public function getMessagekey(){ //May needs to be a private function
$key = 'customfunction'; if(is_admin()){$key = 'admin_'.$key;}return $key;
}
public function __construct(){
add_action( 'wp_ajax_admission_form', [$this,'admission_form']);
add_action( 'wp_ajax_nopriv_admission_form', [$this,'admission_form']);
}
public function admission_form() {
//call hook;
echo "ljdlf";
wp_die();
}
}