我正在尝试覆盖wp_insert_comment() (wp包括/comment.php)。我在functions.php 文件,位于我的主题中:
add_filter(\'wp_insert_comment\', \'my_insert_comment\');
function my_insert_comment($commentdata)
{
/* Some stuff */
}
以下是原始wp\\u insert\\u comment()函数中的一行:
function wp_insert_comment($commentdata)
{
/* Some stuff */
do_action(\'wp_insert_comment\', $id, $comment);
return $id;
}
经过多次测试,我觉得
wp_insert_comment() 执行时
do_action() 行,我的过滤器被考虑在内,我的
my_insert_comment() 函数最终执行。
当然,我的目的是用我自己的函数替换原来的函数。my_insert_comment() 如果我直接在comments.php 文件,但我想保留它,以防更新。
我做错什么了吗?
最合适的回答,由SO网友:Eugene Manuilov 整理而成
您不能重写它,因为此函数是不可插入的,并且是WP核心的一部分。你所能做的就是加入你的钩子wp_insert_comment, 就像你实际做的那样。