Created
April 5, 2012 07:36
-
-
Save thisislawatts/2308784 to your computer and use it in GitHub Desktop.
Adding Custom Fields to Wordpress Comments
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* 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