How to override wp_insert_comment()
题
I am trying to override wp_insert_comment()
(wp-includes/comment.php). I added the following lines of code in my functions.php
file, located in my theme :
add_filter('wp_insert_comment', 'my_insert_comment');
function my_insert_comment($commentdata)
{
/* Some stuff */
}
Here is a line found in the original wp_insert_comment() function :
function wp_insert_comment($commentdata)
{
/* Some stuff */
do_action('wp_insert_comment', $id, $comment);
return $id;
}
After many tests, I have the feeling that the real wp_insert_comment()
is executed, and when it comes to the do_action()
line, my filter is taken into consideration and my my_insert_comment()
function is finally executed.
Of course, my purpose is to replace the original function by my own one. my_insert_comment()
is working fine if I write it directly in the comments.php
file, but I would like to keep it update-proof.
Am I doing something wrong ?
没有正确的解决方案