wordpress - 发布评论时调用函数
每当有人发表评论时,我想在 php 中采取一些操作。我怎样才能为此设置一个钩子?我假设它会进入functions.php...
编辑-这是我更新的代码:
add_action('comment_post', 'comment_posted');
function comment_posted() {
$MyClass = new MyClass(); //I do this in other functions and don't have any blank screen problems
$test = "";
$MyClass->doSomething($test);
}
I would like to take some action in php whenever someone posts a comment. How can I set up a hook for that? I assume it would go in functions.php...
EDIT - here is my udpated code:
add_action('comment_post', 'comment_posted');
function comment_posted() {
$MyClass = new MyClass(); //I do this in other functions and don't have any blank screen problems
$test = "";
$MyClass->doSomething($test);
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
请参阅:http://codex.wordpress.org/Function_Reference/wp_new_comment
然后您应该能够从functions.php 中调用
add_action('comment_post', 'my_func');
。See: http://codex.wordpress.org/Function_Reference/wp_new_comment
You should be able to then call
add_action('comment_post', 'my_func');
from within your functions.php.