[wp-hackers] adding custom fields to a comment form
J.D. Grimes
jdg at codesymphony.co
Mon Oct 7 19:26:32 UTC 2013
Ah, found an action hook you can use to display the field: comment_form_logged_in_after
So:
function add_comment_fields( $fields ) {
?>
<p class="comment-form-age">
<label for="age"><?php _e( 'Age' ); ?></label>
<input id="age" name="age" type="text" size="30" />
</p>
<?php
}
add_filter( 'comment_form_logged_in_after', 'add_comment_fields' );
That will display to logged in users only. Just echo out the form input. The saving should work the same as before, I think.
On Oct 7, 2013, at 3:13 PM, "J.D. Grimes" <jdg at codesymphony.co> wrote:
> No, there's nothing wrong with that code. Actually, it works, but this:
>> // Default comment form elements are hidden when user is logged in
> So, if you want them to show even when the user is logged in, you will have to use a different hook. I don't know any off of the top of my head...
>
> On Oct 7, 2013, at 3:01 PM, Gregory Lancaster <greglancaster71 at gmail.com> wrote:
>
>> I got it :)
>>
>> I followed the smashing guide, and no fields showed up. So I tried just
>> copy pasting their example code and that didnt work either. Is there
>> something wrong with this code I used here:
>>
>> function add_comment_fields($fields) {
>>
>> $fields['age'] = '<p class="comment-form-age"><label for="age">' . __(
>> 'Age' ) . '</label>' .
>> '<input id="age" name="age" type="text" size="30" /></p>';
>> return $fields;
>>
>> }
>> add_filter('comment_form_default_fields','add_comment_fields');
>>
>> function add_comment_meta_values($comment_id) {
>>
>> if(isset($_POST['age'])) {
>> $age = wp_filter_nohtml_kses($_POST['age']);
>> add_comment_meta($comment_id, 'age', $age, false);
>> }
>>
>> }
>> add_action ('comment_post', 'add_comment_meta_values', 1);
>>
>>
>> On Mon, Oct 7, 2013 at 11:57 AM, J.D. Grimes <jdg at codesymphony.co> wrote:
>>
>>> I tried to send a reply to that earlier, but I don't think it went through
>>> - I just resent it now, let me know if you get it.
>>>
>>> On Oct 7, 2013, at 2:54 PM, Gregory Lancaster <greglancaster71 at gmail.com>
>>> wrote:
>>>
>>>> I was going to (i am tryign to code the plugin I emailed you about myself
>>>> today, I have all day :) ) but the is_post_type was depreciated. Not
>>>> sure what to use now.
>>>>
>>>>
>>>> On Mon, Oct 7, 2013 at 11:50 AM, Chris McCoy <chris at lod.com> wrote:
>>>>
>>>>> I would check for the post type, if its the one you wish to add to do
>>> the
>>>>> process like in the tutorial, so it only shows on the comment form for
>>> the
>>>>> post type.
>>>>>
>>>>>
>>>>>
>>>>> On 10/7/2013, 2:45 PM, "BenderisGreat" <greglancaster71 at gmail.com>
>>> wrote:
>>>>>
>>>>>> I did see that, but I need to add the custom comment fields only to the
>>>>>> custom post type
>>>>>>
>>>>>>
>>>>>>
>>>>>> --
>>>>>> View this message in context:
>>>>>>
>>>>>
>>> http://wordpress-hackers.1065353.n5.nabble.com/adding-custom-fields-to-a-c
>>>>>> omment-form-tp42446p42453.html
>>>>>> Sent from the Wordpress Hackers mailing list archive at Nabble.com.
>>>>>> _______________________________________________
>>>>>> wp-hackers mailing list
>>>>>> wp-hackers at lists.automattic.com
>>>>>> http://lists.automattic.com/mailman/listinfo/wp-hackers
>>>>>
>>>>>
>>>>> _______________________________________________
>>>>> wp-hackers mailing list
>>>>> wp-hackers at lists.automattic.com
>>>>> http://lists.automattic.com/mailman/listinfo/wp-hackers
>>>>>
>>>> _______________________________________________
>>>> wp-hackers mailing list
>>>> wp-hackers at lists.automattic.com
>>>> http://lists.automattic.com/mailman/listinfo/wp-hackers
>>>
>>> _______________________________________________
>>> wp-hackers mailing list
>>> wp-hackers at lists.automattic.com
>>> http://lists.automattic.com/mailman/listinfo/wp-hackers
>>>
>> _______________________________________________
>> wp-hackers mailing list
>> wp-hackers at lists.automattic.com
>> http://lists.automattic.com/mailman/listinfo/wp-hackers
>
> _______________________________________________
> wp-hackers mailing list
> wp-hackers at lists.automattic.com
> http://lists.automattic.com/mailman/listinfo/wp-hackers
More information about the wp-hackers
mailing list