1

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 ?

  • Why do you want to override it? – Eugene Manuilov May 18 '12 at 7:27
  • To make some changes in the DB when a user posts a comment. That's related to specifics features I'm developing. – Pierre Espenan May 18 '12 at 8:18
  • your hook for wp_insert_comment action is the best place to do it. – Eugene Manuilov May 18 '12 at 8:29
0

You can't override it, because this function is not pluggable and is a part of WP core. All what you can do is to add your hook for action wp_insert_comment, as you've actually done.

  • Is there any list or something of Wordpress pluggable functions ? – Pierre Espenan May 18 '12 at 8:19
  • 1
    wp-includes/pluggable.php – Eugene Manuilov May 18 '12 at 8:27
  • Thanks. That's a pity I can't override that function... Will have to re-implement my code for each Wordpress update :/ – Pierre Espenan May 18 '12 at 8:46

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.