开发者

wordpress - call a function when a comment is posted

开发者 https://www.devze.com 2023-02-28 08:40 出处:网络
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...

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 othe开发者_StackOverflowr functions and don't have any blank screen problems
            $test = "";
            $MyClass->doSomething($test); 
    }


See: http://codex.wordpress.org/Function_Reference/wp_new_comment

Calls 'comment_post' action with comment ID and whether comment is approved by WordPress.

You should be able to then call add_action('comment_post', 'my_func'); from within your functions.php.

0

精彩评论

暂无评论...
验证码 换一张
取 消