I'm attempting to extend the functionality from the comments inside a WordPress install. I just read allusion for an elusive 'custom comment type' functionality, but tend to not find any information. Rather, I had been convinced that I'd give a custom column ' towards the 'comments' database table. This is the easy part. Things I have no idea how you can do would be to personalize your comments ought to queries to save, upgrading and reading through your comments ought to to mirror the presence of the brand new table column. I figured there will be a filter to change the query, however i cannot find any that will get it done... Any ideas? thanks.

Hi @Regis Zaleman:

There is not a real custom comment type but it is simple to and effectively add posts using "comment meta" the industry table of title/value pairs connected where each title/value pair is connected having a given comment utilizing a 'meta_key' (do not give a column towards the SQL database that's frowned upon within the WordPress developer community.)

Let us assume you desired to allow the consumer add their Twitter account. This is actually the code that will save my Twitter account towards the comment recognized by $comment_ID (prefixing the meta key title by having an underscore may be beneficial for just about any meta that you simply maintain via custom code versus that you simply let customers choose the meta key):

update_comment_meta($comment_ID,'_twitter','mikeschinkel')

Then to load the worthiness to show inside your template you simply call get_comment_meta() (the 3rd parameter way to return just one value, not a range of values):

$twitter = get_comment_meta($comment_ID,'_twitter',true)

Obviously not understanding how you can hook WordPress to integrate this the above mentioned functions wouldn't be lots of help. You will find two hooks you will need to use, the very first being wordpress_place_comment that will get known as when WordPress saves a comment:

add_action('wp_place_comment','yoursite_wordpress_place_comment',10,2)

function yoursite_wordpress_place_comment($comment_ID,$commmentdata) 

The 2nd the first is a little more difficult the one which allows you add fields and modify other facets of the comment form. The 'comment_form_defaults' hook sets the defaults for that comment and let us you add the HTML for any Twitter area (I snagged the format for that HTML in the comment_form() function present in /wordpress-includes/comment-template.php online 1511 in Wordpress v3..1)

add_filter('comment_form_defaults','yoursite_comment_form_defaults')

function yoursite_comment_form_defaults($defaults) </label>

<input id="twitter" title="twitter" type="text" value="" size="30" />

</p>

HTML

  return $defaults



And some tips about what it appears as with action:

WordPress Comments form with a Twitter field

This comment form extensibility is totally new for WordPress 3. so by its character to be new within an open-source project it's most likely not likely to accommodate all use-cases yet (for example there is no good way to obtain a appreciated value for that Twitter screen title) but hopefully you'll have the ability to bend it enough for you will and obtain the thing you need as well as in future launched of WordPress the comment form API will likely improve.

Hope this can help.

-Mike

P.S. Later on consider posting your question on StackOverflow's sister site WordPress Solutions this is where the majority of the WordPress fanatics spend time, individuals who are able to rapidly respond to questions such as this.