Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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 ?

share|improve this question
    
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

1 Answer 1

up vote 0 down vote accepted

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.

share|improve this answer
    
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

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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