[wp-hackers] Modifying wp-comments-post.php to accept new custom
glenn at glennansley.com
Wed Sep 24 02:51:45 GMT 2008
It is possible to do this as DD32 outlines without modifying core
files but it takes a little bit of work so if you're not going to be
upgrading in the future (you should upgrade in the future), this
probably isn't worth it.
1. Copy wp_comments_post.php from your root directory and place it
into your theme's directory
2. Open up your theme's comments.php and change the FORM action from
<?php echo get_option('siteurl'); ?>/wp-comments-post.php to <?php
3. Copy the wp_new_comment() and wp_insert_comment() functions from
comment.php and paste them (with new names) into your theme's
functions.php file (or your own plugin if you want).
4. In your new version of wp_new_comment(), change the line that says
$comment_ID = wp_insert_comment($commentdata); to $comment_ID =
5. In your new version of wp_insert_comment(), make the necessary
changes needed in the code/sql.
6. Go back to you copy of wp_comments_post.php (the one you put in
your theme directory) and change line 71 to call your new version of
wp_insert_comment() that you created in step 3 and modified in step 5.
While this is not a "quick" solution to implement, it will allow you
to upgrade WP in the future without having to modify comments.php each
Again, it's a lot of work for what might be a little trade off
(creating the new file / functions v. updating comments.php every time
you upgrade). It would be worth it to me though just so I don't have
to change the WP core code.
Oh, and one disclaimer: the above code probably has syntax errors in
it (and possibly a logical one) as I did test the process tonight, but
recalled it from a similar procedure I did earlier this year.
On Tue, Sep 23, 2008 at 10:03 PM, DD32 <wordpress at dd32.id.au> wrote:
> Sorry, Seems that filter will be useless, as wp_insert_comment() completely
> ignores any extra fields which you pass it, So you -will- need to modify
> core files and add the item to the compact() in wp_insert_comment() too
> (line 700ish of wp-includes/comment.php)
> On Wed, 24 Sep 2008 12:01:04 +1000, DD32 <wordpress at dd32.id.au> wrote:
>> rather than modifying core files, you should probably use the
>> 'preprocess_comment' filter inside wp_new_comment() and check for a $_POST
>> variable that you've added
>> compact() takes a list of variables and compacts them into an array, As
>> well as adding to that line, you need to also add the actual variable, eg,
>> something similar to:
>> $comment_author_url = trim($_POST['url']);
>> $comment_content = trim($_POST['comment']);
>> So i miught use
>> $d_plugin = trim($_POST['d_plugin']);
>> compact('comment_post_ID', ...., 'd_plugin');
>> On Wed, 24 Sep 2008 11:53:47 +1000, MLR <mlrichard at gmail.com> wrote:
>>> I have created new columns in wp_comments and new input fields in a blog
>>> gather more data along with the comments (Gender, Age, etc.)
>>> I have modified wp-comments-post.php to gather these new POST variables
>>> added the column names to the $commentdata = compact() line
>>> Currently my mods are not causing an error but obviously the new fields
>>> empty on save.
>>> What else should I tweak beyond that? I have looked in the Codex and on
>>> Web for an answer but the search results are overwhelmed with generic
>>> unrelated info.
>>> Thanks for pointing me in the right direction,
>>> wp-hackers mailing list
>>> wp-hackers at lists.automattic.com
>> wp-hackers mailing list
>> wp-hackers at lists.automattic.com
> wp-hackers mailing list
> wp-hackers at lists.automattic.com
More information about the wp-hackers