Skip to content

Instantly share code, notes, and snippets.

@thisislawatts
Created April 5, 2012 07:36
Show Gist options
  • Save thisislawatts/2308784 to your computer and use it in GitHub Desktop.
Save thisislawatts/2308784 to your computer and use it in GitHub Desktop.
Adding Custom Fields to Wordpress Comments
/* Setup our custom fields variable */
global $custom_comment_meta_LA;
$custom_comment_meta_LA = array(
'rating' => '<p class="comment-form-rating"><input id="rating" name="rating" size="30" type="hidden" value="0" /></p>',
'vote_count' => '<p class="comment-form-vote_count"><input id="vote_count" name="vote_count" size="30" type="hidden" value="0" /></p>'
// 'file' => '<label for="image">Booooosh</label><input type="file" name="image" size="31" />'
);
/* Add our custom fields into comment form */
function add_custom_meta_fields( $defaults ) {
global $custom_comment_meta_LA;
foreach( $custom_comment_meta_LA as $key => $value ) {
$defaults['fields'][ $key ] = $value;
}
// Remove website default comment field
unset( $defaults['fields']['url'] );
return $defaults;
}
add_action( 'comment_form_defaults', 'add_custom_meta_fields' );
function add_custom_meta_fields_logged_in ( ) {
global $custom_comment_meta_LA;
foreach ( $custom_comment_meta_LA as $field_html ) {
echo $field_html . "\n";
}
}
add_action( 'comment_form_logged_in_after', 'add_custom_meta_fields_logged_in' );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment