2011-04-22 32 views
3

我想在某人发布评论时采取一些PHP操作。我怎样才能为此设置钩子?我相信它会去的functions.php ...wordpress - 在评论发布时调用函数

编辑 - 这是我的udpated代码:

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); 
    } 

回答

1

参见:http://codex.wordpress.org/Function_Reference/wp_new_comment

称之为 'comment_post' 行动注释ID以及是否评论由WordPress批准。

你应该可以在你的functions.php中调用add_action('comment_post', 'my_func');

+0

谢谢。它起作用,并且调用该函数。但是,当添加评论时,屏幕变为空白(白色)。我没有在屏幕上回应任何内容。你知道我怎么才能让用户回到他们评论的帖子而不是空白屏幕? – sol 2011-04-22 21:25:06

+0

你有一些示例代码吗?很难猜测你的功能发生了什么。你可以尝试设置'error_reporting(E_ALL);'来查看是否有错误被抛出。 – scurker 2011-04-22 21:45:43

+0

在上面添加了一些代码。错误报告不会显示任何错误。 – sol 2011-04-22 21:59:11