【发布时间】:2015-01-03 02:24:39
【问题描述】:
我正在尝试找出 do_action 和 add_action 究竟是如何工作的。我已经用 add_action 进行了检查,但是对于 do_action 我现在正在尝试新的。这是我试过的。
function mainplugin_test() {
$regularprice = 50;
if(class_exists('rs_dynamic')) {
$regularprice = 100;
}
// and doing further
//like i echoing the regular price
echo $regularprice; //It print 100 from this code
}
现在我打算创建 do_action 以避免代码混乱问题,而不是在主文件中放置少量代码。
function mainplugin_test() {
$regularprice = 50;
do_action('testinghook');
// and doing further
//like i echoing the regular price
echo $regularprice; //It should print 100 but it print 50
}
所以我创建了另一个函数来指出该钩子类似于
function anothertest() {
if(class_exists('rs_dynamic')) {
$regularprice = 100;
}
}
add_action('testinghook','anothertest');
不确定如何将代码行添加到上述函数可能起作用的钩子中?根据我在测试环境中的尝试,没有任何帮助。如果我理解正确的 do_action 更像是包含一个文件???如果没有,请告诉我。
谢谢。
【问题讨论】: