wordpress - 在发布评论时调用函数
我想在php中采取一些行动,每当有人发表评论。我如何设置一个钩子呢?我假设它会在functions.php ...
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);
}
http://codex.wordpress.org/Function_Reference/wp_new_comment =nofollow> http://codex.wordpress.org/Function_Reference/wp_new_comment
See: http://codex.wordpress.org/Function_Reference/wp_new_comment
使用评论ID和评论是否通过WordPress批准来调用comment_post操作。
Calls 'comment_post' action with comment ID and whether comment is approved by WordPress.
应该能够在functions.php中调用 add_action('comment_post','my_func');
。
You should be able to then call add_action('comment_post', 'my_func');
from within your functions.php.