I would like to override the comment_save function. Is there a way to override it so I can add in my functionality?
Is creating a trigger such as http://drupal.org/node/375833 the best way? That doesn’t seem very reliable since it happens after the fact.
BTW, this is in D6.
It’s tricky. First off, I’d suggest instead going and seeing if you can manage what you need by using hook_comment ( http://api.drupal.org/api/drupal/developer–hooks–core.php/function/hook_comment/6). It’s really more of what this is needed for.
If you really need to override comment_save, then often a good choice is to look around at what things call it. For this situation, you’re lucky – comment_save only gets called in one place, on line 1542 of comment.module, inside of comment_form_submit.
Now, comment_form_submit is a form submit function – instead of replacing comment_save, we can instead make our own custom version of comment_form_submit (and for argument’s sake, we’ll assume we’re working in a ‘custom_module’ module) – so what I would do is create a new function called custom_module_comment_form_submit, which calls the variant of comment_save that I’m interested in using, and then use hook_form_alter() ( http://api.drupal.org/api/drupal/developer–hooks–core.php/function/hook_form_alter/6 ) to set the $form[‘#submit’] to replace the value ‘comment_form_submit’ with ‘custom_module_comment_form_submit’.
This isn’t perfect – if you install another module that uses comment_save, then you’ll need to find a similar workaround. And if a bug or security hole is found in Drupal that is fixed in the part you’re working around here, you won’t get that security hole fixed in your code. But if you absolutely must replace comment_save, this is pretty much the only way to do it.