【发布时间】:2019-04-30 14:51:15
【问题描述】:
我编写了一个简单的插件,通过使用 add_filter() 将一些文本附加到每个帖子内容,它工作正常。但现在我只想在单击按钮后运行 add_filter 。所以我在我的选项页面中添加了一个按钮,并添加了一个在单击后执行的功能。但问题是当我将 add_filter() 放在该按钮操作函数中时,它不会执行。 谁能帮我写代码?谢谢!
这是在 php 文件的根目录中工作的。
add_filter("the_content", "appendAction");
function appendAction($the_Post) {
$the_Post.=" Bye ! ";
return $the_Post;
}
但放入按钮操作功能时不起作用
function test_button_action(){
echo "button clicked "; //this runs after clicking button but not below code
add_filter("the_content", "appendAction");
function appendAction($the_Post) {
$the_Post.=" Bye ! ";
return $the_Post;
}
}
【问题讨论】: