admin管理员组文章数量:1405636
I'm new to WordPress, and currently developing my first plugin and currently having difficulties.
How I can insert the add_filter action inside my submit function? I want the add_filter
action to process after the user click the submit button.
I have try this but it didn't work.
if(isset($_POST['btn_submit'])) {
function addContent($content = '') {
$content .= "My content";
return $content;
}
add_filter('the_content', 'addContent');
}
Any help would be greatly appreciated. Thanks!
I'm new to WordPress, and currently developing my first plugin and currently having difficulties.
How I can insert the add_filter action inside my submit function? I want the add_filter
action to process after the user click the submit button.
I have try this but it didn't work.
if(isset($_POST['btn_submit'])) {
function addContent($content = '') {
$content .= "My content";
return $content;
}
add_filter('the_content', 'addContent');
}
Any help would be greatly appreciated. Thanks!
Share Improve this question edited Feb 8, 2012 at 23:37 EAMann 32.2k9 gold badges88 silver badges147 bronze badges asked Feb 7, 2012 at 13:38 ronnielronniel 211 gold badge1 silver badge3 bronze badges 1- 1 If you've solved this problem (as stated in comments blow), please post your solution as an answer for others. – EAMann Commented Feb 7, 2012 at 15:26
3 Answers
Reset to default 3I think what you're ACTUALLY looking to do is to apply_filters()
. add_filter()
registers a new filter, whereas apply_filters()
does the filters that have been registered.
If that's not what you're looking to do, then you need to be aware that add_filter()
needs to be run every time you want the filter applied. This allows plugins to be removed without having to unregister all their filters and generally keeps a wordpress install pretty clean...it also helps with security. A better question might encompass a broader scope, where you state what you're trying to do, rather than having us try and troubleshoot your implementation of it.
You can also write in the following way:
function addContent($content = '') {
$content .= "My content";
return $content;
}
if(isset($_POST['btn_submit'])) {
add_filter('the_content', 'addContent'); }
@Shaon, Thanks for your reply. I couldn't get that to work efefctively, but here is a very workable function I found: http://core.trac.wordpress/ticket/15311#comment:13
本文标签: filtersCan you use addfilter() inside other function
版权声明:本文标题:filters - Can you use add_filter() inside other function? 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744336777a2601235.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论