wordpress - 在发布评论时调用函数 [英] wordpress - call a function when a comment is posted

查看:140
本文介绍了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.

这篇关于wordpress - 在发布评论时调用函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆