每当有人发表评论时,我都想在 php 中采取一些行动。我怎样才能为此设置一个钩子(Hook)?我假设它会进入 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);
}
最佳答案
参见:http://codex.wordpress.org/Function_Reference/wp_new_comment
Calls 'comment_post' action with comment ID and whether comment is approved by WordPress.
然后您应该能够从您的 functions.php 中调用 add_action('comment_post', 'my_func');
。
关于php - wordpress - 发表评论时调用函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5759882/