Discussion:
adding custom fields to a comment form
BenderisGreat
2013-10-06 09:15:00 UTC
Permalink
I would like to add custom fields to a comment form - but only for a custom
post type. I have searched online for the last hour for a tutorial
explaining how to just add basic custom fields to a comment form and haven't
had any luck. Most if not all of it is outdated.

Would someone point me to a good tutorial, or if someone has already coded
something like this and doesnt mind sharing? Just being able to look at how
to properly hook into comment functions would help a lot.



--
View this message in context: http://wordpress-hackers.1065353.n5.nabble.com/adding-custom-fields-to-a-comment-form-tp42446.html
Sent from the Wordpress Hackers mailing list archive at Nabble.com.
J.D. Grimes
2013-10-06 21:01:13 UTC
Permalink
I'm sure you've already seen this: http://wp.smashingmagazine.com/2012/05/08/adding-custom-fields-in-wordpress-comment-form/
Post by BenderisGreat
I would like to add custom fields to a comment form - but only for a custom
post type. I have searched online for the last hour for a tutorial
explaining how to just add basic custom fields to a comment form and haven't
had any luck. Most if not all of it is outdated.
Would someone point me to a good tutorial, or if someone has already coded
something like this and doesnt mind sharing? Just being able to look at how
to properly hook into comment functions would help a lot.
--
View this message in context: http://wordpress-hackers.1065353.n5.nabble.com/adding-custom-fields-to-a-comment-form-tp42446.html
Sent from the Wordpress Hackers mailing list archive at Nabble.com.
_______________________________________________
wp-hackers mailing list
http://lists.automattic.com/mailman/listinfo/wp-hackers
BenderisGreat
2013-10-07 18:45:04 UTC
Permalink
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-comment-form-tp42446p42453.html
Sent from the Wordpress Hackers mailing list archive at Nabble.com.
Chris McCoy
2013-10-07 18:50:33 UTC
Permalink
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.
Post by BenderisGreat
I did see that, but I need to add the custom comment fields only to the
custom post type
--
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
http://lists.automattic.com/mailman/listinfo/wp-hackers
Gregory Lancaster
2013-10-07 18:54:09 UTC
Permalink
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.
Post by Chris McCoy
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.
Post by BenderisGreat
I did see that, but I need to add the custom comment fields only to the
custom post type
--
http://wordpress-hackers.1065353.n5.nabble.com/adding-custom-fields-to-a-c
Post by BenderisGreat
omment-form-tp42446p42453.html
Sent from the Wordpress Hackers mailing list archive at Nabble.com.
_______________________________________________
wp-hackers mailing list
http://lists.automattic.com/mailman/listinfo/wp-hackers
_______________________________________________
wp-hackers mailing list
http://lists.automattic.com/mailman/listinfo/wp-hackers
J.D. Grimes
2013-10-07 18:57:49 UTC
Permalink
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.
Post by Gregory Lancaster
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.
Post by Chris McCoy
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.
Post by BenderisGreat
I did see that, but I need to add the custom comment fields only to the
custom post type
--
http://wordpress-hackers.1065353.n5.nabble.com/adding-custom-fields-to-a-c
Post by BenderisGreat
omment-form-tp42446p42453.html
Sent from the Wordpress Hackers mailing list archive at Nabble.com.
_______________________________________________
wp-hackers mailing list
http://lists.automattic.com/mailman/listinfo/wp-hackers
_______________________________________________
wp-hackers mailing list
http://lists.automattic.com/mailman/listinfo/wp-hackers
_______________________________________________
wp-hackers mailing list
http://lists.automattic.com/mailman/listinfo/wp-hackers
Gregory Lancaster
2013-10-07 19:01:11 UTC
Permalink
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);
Post by J.D. Grimes
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.
Post by Gregory Lancaster
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.
Post by Chris McCoy
I would check for the post type, if its the one you wish to add to do
the
Post by Gregory Lancaster
Post by Chris McCoy
process like in the tutorial, so it only shows on the comment form for
the
Post by Gregory Lancaster
Post by Chris McCoy
post type.
Post by BenderisGreat
I did see that, but I need to add the custom comment fields only to the
custom post type
--
http://wordpress-hackers.1065353.n5.nabble.com/adding-custom-fields-to-a-c
Post by Gregory Lancaster
Post by Chris McCoy
Post by BenderisGreat
omment-form-tp42446p42453.html
Sent from the Wordpress Hackers mailing list archive at Nabble.com.
_______________________________________________
wp-hackers mailing list
http://lists.automattic.com/mailman/listinfo/wp-hackers
_______________________________________________
wp-hackers mailing list
http://lists.automattic.com/mailman/listinfo/wp-hackers
_______________________________________________
wp-hackers mailing list
http://lists.automattic.com/mailman/listinfo/wp-hackers
_______________________________________________
wp-hackers mailing list
http://lists.automattic.com/mailman/listinfo/wp-hackers
J.D. Grimes
2013-10-07 19:13:06 UTC
Permalink
// 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...
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
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);
Post by J.D. Grimes
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.
Post by Gregory Lancaster
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.
Post by Chris McCoy
I would check for the post type, if its the one you wish to add to do
the
Post by Gregory Lancaster
Post by Chris McCoy
process like in the tutorial, so it only shows on the comment form for
the
Post by Gregory Lancaster
Post by Chris McCoy
post type.
Post by BenderisGreat
I did see that, but I need to add the custom comment fields only to the
custom post type
--
http://wordpress-hackers.1065353.n5.nabble.com/adding-custom-fields-to-a-c
Post by Gregory Lancaster
Post by Chris McCoy
Post by BenderisGreat
omment-form-tp42446p42453.html
Sent from the Wordpress Hackers mailing list archive at Nabble.com.
_______________________________________________
wp-hackers mailing list
http://lists.automattic.com/mailman/listinfo/wp-hackers
_______________________________________________
wp-hackers mailing list
http://lists.automattic.com/mailman/listinfo/wp-hackers
_______________________________________________
wp-hackers mailing list
http://lists.automattic.com/mailman/listinfo/wp-hackers
_______________________________________________
wp-hackers mailing list
http://lists.automattic.com/mailman/listinfo/wp-hackers
_______________________________________________
wp-hackers mailing list
http://lists.automattic.com/mailman/listinfo/wp-hackers
J.D. Grimes
2013-10-07 19:26:32 UTC
Permalink
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.
Post by J.D. Grimes
// 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...
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
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);
Post by J.D. Grimes
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.
Post by Gregory Lancaster
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.
Post by Chris McCoy
I would check for the post type, if its the one you wish to add to do
the
Post by Gregory Lancaster
Post by Chris McCoy
process like in the tutorial, so it only shows on the comment form for
the
Post by Gregory Lancaster
Post by Chris McCoy
post type.
Post by BenderisGreat
I did see that, but I need to add the custom comment fields only to the
custom post type
--
http://wordpress-hackers.1065353.n5.nabble.com/adding-custom-fields-to-a-c
Post by Gregory Lancaster
Post by Chris McCoy
Post by BenderisGreat
omment-form-tp42446p42453.html
Sent from the Wordpress Hackers mailing list archive at Nabble.com.
_______________________________________________
wp-hackers mailing list
http://lists.automattic.com/mailman/listinfo/wp-hackers
_______________________________________________
wp-hackers mailing list
http://lists.automattic.com/mailman/listinfo/wp-hackers
_______________________________________________
wp-hackers mailing list
http://lists.automattic.com/mailman/listinfo/wp-hackers
_______________________________________________
wp-hackers mailing list
http://lists.automattic.com/mailman/listinfo/wp-hackers
_______________________________________________
wp-hackers mailing list
http://lists.automattic.com/mailman/listinfo/wp-hackers
_______________________________________________
wp-hackers mailing list
http://lists.automattic.com/mailman/listinfo/wp-hackers
Gregory Lancaster
2013-10-07 19:53:25 UTC
Permalink
awesome! Thats exactly what I needed. Apparently with this framework the
comments.php isnt affected by the add_comment_fields, I have to add it
manually. Since thats the case, I can skip the function right?
Post by J.D. Grimes
comment_form_logged_in_after
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.
Post by J.D. Grimes
// 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...
Post by J.D. Grimes
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
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);
Post by J.D. Grimes
I tried to send a reply to that earlier, but I don't think it went
through
Post by J.D. Grimes
Post by J.D. Grimes
- I just resent it now, let me know if you get it.
On Oct 7, 2013, at 2:54 PM, Gregory Lancaster <
Post by Gregory Lancaster
I was going to (i am tryign to code the plugin I emailed you about
myself
Post by J.D. Grimes
Post by J.D. Grimes
Post by Gregory Lancaster
today, I have all day :) ) but the is_post_type was depreciated.
Not
Post by J.D. Grimes
Post by J.D. Grimes
Post by Gregory Lancaster
sure what to use now.
Post by Chris McCoy
I would check for the post type, if its the one you wish to add to do
the
Post by Gregory Lancaster
Post by Chris McCoy
process like in the tutorial, so it only shows on the comment form
for
Post by J.D. Grimes
Post by J.D. Grimes
the
Post by Gregory Lancaster
Post by Chris McCoy
post type.
Post by BenderisGreat
I did see that, but I need to add the custom comment fields only to
the
Post by J.D. Grimes
Post by J.D. Grimes
Post by Gregory Lancaster
Post by Chris McCoy
Post by BenderisGreat
custom post type
--
http://wordpress-hackers.1065353.n5.nabble.com/adding-custom-fields-to-a-c
Post by J.D. Grimes
Post by J.D. Grimes
Post by Gregory Lancaster
Post by Chris McCoy
Post by BenderisGreat
omment-form-tp42446p42453.html
Sent from the Wordpress Hackers mailing list archive at Nabble.com.
_______________________________________________
wp-hackers mailing list
http://lists.automattic.com/mailman/listinfo/wp-hackers
_______________________________________________
wp-hackers mailing list
http://lists.automattic.com/mailman/listinfo/wp-hackers
_______________________________________________
wp-hackers mailing list
http://lists.automattic.com/mailman/listinfo/wp-hackers
_______________________________________________
wp-hackers mailing list
http://lists.automattic.com/mailman/listinfo/wp-hackers
_______________________________________________
wp-hackers mailing list
http://lists.automattic.com/mailman/listinfo/wp-hackers
_______________________________________________
wp-hackers mailing list
http://lists.automattic.com/mailman/listinfo/wp-hackers
_______________________________________________
wp-hackers mailing list
http://lists.automattic.com/mailman/listinfo/wp-hackers
J.D. Grimes
2013-10-07 19:59:05 UTC
Permalink
Yes. That means it must be using its own version of the comment_form() function. Maybe it has similar hooks?
Post by Gregory Lancaster
awesome! Thats exactly what I needed. Apparently with this framework the
comments.php isnt affected by the add_comment_fields, I have to add it
manually. Since thats the case, I can skip the function right?
Post by J.D. Grimes
comment_form_logged_in_after
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.
Post by J.D. Grimes
// 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...
Post by J.D. Grimes
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
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);
Post by J.D. Grimes
I tried to send a reply to that earlier, but I don't think it went
through
Post by J.D. Grimes
Post by J.D. Grimes
- I just resent it now, let me know if you get it.
On Oct 7, 2013, at 2:54 PM, Gregory Lancaster <
Post by Gregory Lancaster
I was going to (i am tryign to code the plugin I emailed you about
myself
Post by J.D. Grimes
Post by J.D. Grimes
Post by Gregory Lancaster
today, I have all day :) ) but the is_post_type was depreciated.
Not
Post by J.D. Grimes
Post by J.D. Grimes
Post by Gregory Lancaster
sure what to use now.
Post by Chris McCoy
I would check for the post type, if its the one you wish to add to do
the
Post by Gregory Lancaster
Post by Chris McCoy
process like in the tutorial, so it only shows on the comment form
for
Post by J.D. Grimes
Post by J.D. Grimes
the
Post by Gregory Lancaster
Post by Chris McCoy
post type.
Post by BenderisGreat
I did see that, but I need to add the custom comment fields only to
the
Post by J.D. Grimes
Post by J.D. Grimes
Post by Gregory Lancaster
Post by Chris McCoy
Post by BenderisGreat
custom post type
--
http://wordpress-hackers.1065353.n5.nabble.com/adding-custom-fields-to-a-c
Post by J.D. Grimes
Post by J.D. Grimes
Post by Gregory Lancaster
Post by Chris McCoy
Post by BenderisGreat
omment-form-tp42446p42453.html
Sent from the Wordpress Hackers mailing list archive at Nabble.com.
_______________________________________________
wp-hackers mailing list
http://lists.automattic.com/mailman/listinfo/wp-hackers
_______________________________________________
wp-hackers mailing list
http://lists.automattic.com/mailman/listinfo/wp-hackers
_______________________________________________
wp-hackers mailing list
http://lists.automattic.com/mailman/listinfo/wp-hackers
_______________________________________________
wp-hackers mailing list
http://lists.automattic.com/mailman/listinfo/wp-hackers
_______________________________________________
wp-hackers mailing list
http://lists.automattic.com/mailman/listinfo/wp-hackers
_______________________________________________
wp-hackers mailing list
http://lists.automattic.com/mailman/listinfo/wp-hackers
_______________________________________________
wp-hackers mailing list
http://lists.automattic.com/mailman/listinfo/wp-hackers
_______________________________________________
wp-hackers mailing list
http://lists.automattic.com/mailman/listinfo/wp-hackers
Gregory Lancaster
2013-10-07 20:31:44 UTC
Permalink
I am not sure. I used the code you suggested in functions.php, and then I
edited the comments.php template so it checks the post type - see the
bolded portion. The field data was showing before, but now it is not.

<?php
/**
* Use Bootstrap's media object for listing comments
*
* @link http://twitter.github.com/bootstrap/components.html#media
*/
class Roots_Walker_Comment extends Walker_Comment {
function start_lvl(&$output, $depth = 0, $args = array()) {
$GLOBALS['comment_depth'] = $depth + 1; ?>
<ul <?php comment_class('media unstyled comment-' . get_comment_ID());
?>>
<?php
}

function end_lvl(&$output, $depth = 0, $args = array()) {
$GLOBALS['comment_depth'] = $depth + 1;
echo '</ul>';
}

function start_el(&$output, $comment, $depth = 0, $args = array(), $id =
0) {
$depth++;
$GLOBALS['comment_depth'] = $depth;
$GLOBALS['comment'] = $comment;

if (!empty($args['callback'])) {
call_user_func($args['callback'], $comment, $args, $depth);
return;
}

extract($args, EXTR_SKIP); ?>


<li id="comment-<?php comment_ID(); ?>" <?php comment_class('media
comment-' . get_comment_ID()); ?>>
* <?php if (get_post_type() == 'profile') { *
* include(locate_template('templates/comment-profile.php')); } else {*
* include(locate_template('templates/comment.php')); } ?>*
}
<?php
}

function end_el(&$output, $comment, $depth = 0, $args = array()) {
if (!empty($args['end-callback'])) {
call_user_func($args['end-callback'], $comment, $args, $depth);
return;
}
echo "</div></li>\n";
}
}

function roots_get_avatar($avatar) {
$avatar = str_replace("class='avatar", "class='avatar pull-left
media-object", $avatar);
return $avatar;
}
add_filter('get_avatar', 'roots_get_avatar');
Post by J.D. Grimes
Yes. That means it must be using its own version of the comment_form()
function. Maybe it has similar hooks?
Post by Gregory Lancaster
awesome! Thats exactly what I needed. Apparently with this framework the
comments.php isnt affected by the add_comment_fields, I have to add it
manually. Since thats the case, I can skip the function right?
Post by J.D. Grimes
comment_form_logged_in_after
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.
Post by J.D. Grimes
// 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...
Post by Gregory Lancaster
Post by J.D. Grimes
Post by J.D. Grimes
On Oct 7, 2013, at 3:01 PM, Gregory Lancaster <
I got it :)
I followed the smashing guide, and no fields showed up. So I tried
just
Post by Gregory Lancaster
Post by J.D. Grimes
Post by J.D. Grimes
copy pasting their example code and that didnt work either. Is there
function add_comment_fields($fields) {
$fields['age'] = '<p class="comment-form-age"><label for="age">' .
__(
Post by Gregory Lancaster
Post by J.D. Grimes
Post by J.D. Grimes
'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);
Post by J.D. Grimes
I tried to send a reply to that earlier, but I don't think it went
through
Post by J.D. Grimes
Post by J.D. Grimes
- I just resent it now, let me know if you get it.
On Oct 7, 2013, at 2:54 PM, Gregory Lancaster <
Post by Gregory Lancaster
I was going to (i am tryign to code the plugin I emailed you about
myself
Post by J.D. Grimes
Post by J.D. Grimes
Post by Gregory Lancaster
today, I have all day :) ) but the is_post_type was depreciated.
Not
Post by J.D. Grimes
Post by J.D. Grimes
Post by Gregory Lancaster
sure what to use now.
Post by Chris McCoy
I would check for the post type, if its the one you wish to add to
do
Post by Gregory Lancaster
Post by J.D. Grimes
Post by J.D. Grimes
Post by J.D. Grimes
the
Post by Gregory Lancaster
Post by Chris McCoy
process like in the tutorial, so it only shows on the comment form
for
Post by J.D. Grimes
Post by J.D. Grimes
the
Post by Gregory Lancaster
Post by Chris McCoy
post type.
Post by BenderisGreat
I did see that, but I need to add the custom comment fields only
to
Post by Gregory Lancaster
Post by J.D. Grimes
the
Post by J.D. Grimes
Post by J.D. Grimes
Post by Gregory Lancaster
Post by Chris McCoy
Post by BenderisGreat
custom post type
--
http://wordpress-hackers.1065353.n5.nabble.com/adding-custom-fields-to-a-c
Post by Gregory Lancaster
Post by J.D. Grimes
Post by J.D. Grimes
Post by J.D. Grimes
Post by Gregory Lancaster
Post by Chris McCoy
Post by BenderisGreat
omment-form-tp42446p42453.html
Sent from the Wordpress Hackers mailing list archive at
Nabble.com.
Post by Gregory Lancaster
Post by J.D. Grimes
Post by J.D. Grimes
Post by J.D. Grimes
Post by Gregory Lancaster
Post by Chris McCoy
Post by BenderisGreat
_______________________________________________
wp-hackers mailing list
http://lists.automattic.com/mailman/listinfo/wp-hackers
_______________________________________________
wp-hackers mailing list
http://lists.automattic.com/mailman/listinfo/wp-hackers
_______________________________________________
wp-hackers mailing list
http://lists.automattic.com/mailman/listinfo/wp-hackers
_______________________________________________
wp-hackers mailing list
http://lists.automattic.com/mailman/listinfo/wp-hackers
_______________________________________________
wp-hackers mailing list
http://lists.automattic.com/mailman/listinfo/wp-hackers
_______________________________________________
wp-hackers mailing list
http://lists.automattic.com/mailman/listinfo/wp-hackers
_______________________________________________
wp-hackers mailing list
http://lists.automattic.com/mailman/listinfo/wp-hackers
_______________________________________________
wp-hackers mailing list
http://lists.automattic.com/mailman/listinfo/wp-hackers
_______________________________________________
wp-hackers mailing list
http://lists.automattic.com/mailman/listinfo/wp-hackers
Gregory Lancaster
2013-10-07 21:30:29 UTC
Permalink
I dont think the comment meta can not save on custom post types by default.
Post by J.D. Grimes
Yes. That means it must be using its own version of the comment_form()
function. Maybe it has similar hooks?
Post by Gregory Lancaster
awesome! Thats exactly what I needed. Apparently with this framework the
comments.php isnt affected by the add_comment_fields, I have to add it
manually. Since thats the case, I can skip the function right?
Post by J.D. Grimes
comment_form_logged_in_after
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.
Post by J.D. Grimes
// 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...
Post by Gregory Lancaster
Post by J.D. Grimes
Post by J.D. Grimes
On Oct 7, 2013, at 3:01 PM, Gregory Lancaster <
I got it :)
I followed the smashing guide, and no fields showed up. So I tried
just
Post by Gregory Lancaster
Post by J.D. Grimes
Post by J.D. Grimes
copy pasting their example code and that didnt work either. Is there
function add_comment_fields($fields) {
$fields['age'] = '<p class="comment-form-age"><label for="age">' .
__(
Post by Gregory Lancaster
Post by J.D. Grimes
Post by J.D. Grimes
'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);
Post by J.D. Grimes
I tried to send a reply to that earlier, but I don't think it went
through
Post by J.D. Grimes
Post by J.D. Grimes
- I just resent it now, let me know if you get it.
On Oct 7, 2013, at 2:54 PM, Gregory Lancaster <
Post by Gregory Lancaster
I was going to (i am tryign to code the plugin I emailed you about
myself
Post by J.D. Grimes
Post by J.D. Grimes
Post by Gregory Lancaster
today, I have all day :) ) but the is_post_type was depreciated.
Not
Post by J.D. Grimes
Post by J.D. Grimes
Post by Gregory Lancaster
sure what to use now.
Post by Chris McCoy
I would check for the post type, if its the one you wish to add to
do
Post by Gregory Lancaster
Post by J.D. Grimes
Post by J.D. Grimes
Post by J.D. Grimes
the
Post by Gregory Lancaster
Post by Chris McCoy
process like in the tutorial, so it only shows on the comment form
for
Post by J.D. Grimes
Post by J.D. Grimes
the
Post by Gregory Lancaster
Post by Chris McCoy
post type.
Post by BenderisGreat
I did see that, but I need to add the custom comment fields only
to
Post by Gregory Lancaster
Post by J.D. Grimes
the
Post by J.D. Grimes
Post by J.D. Grimes
Post by Gregory Lancaster
Post by Chris McCoy
Post by BenderisGreat
custom post type
--
http://wordpress-hackers.1065353.n5.nabble.com/adding-custom-fields-to-a-c
Post by Gregory Lancaster
Post by J.D. Grimes
Post by J.D. Grimes
Post by J.D. Grimes
Post by Gregory Lancaster
Post by Chris McCoy
Post by BenderisGreat
omment-form-tp42446p42453.html
Sent from the Wordpress Hackers mailing list archive at
Nabble.com.
Post by Gregory Lancaster
Post by J.D. Grimes
Post by J.D. Grimes
Post by J.D. Grimes
Post by Gregory Lancaster
Post by Chris McCoy
Post by BenderisGreat
_______________________________________________
wp-hackers mailing list
http://lists.automattic.com/mailman/listinfo/wp-hackers
_______________________________________________
wp-hackers mailing list
http://lists.automattic.com/mailman/listinfo/wp-hackers
_______________________________________________
wp-hackers mailing list
http://lists.automattic.com/mailman/listinfo/wp-hackers
_______________________________________________
wp-hackers mailing list
http://lists.automattic.com/mailman/listinfo/wp-hackers
_______________________________________________
wp-hackers mailing list
http://lists.automattic.com/mailman/listinfo/wp-hackers
_______________________________________________
wp-hackers mailing list
http://lists.automattic.com/mailman/listinfo/wp-hackers
_______________________________________________
wp-hackers mailing list
http://lists.automattic.com/mailman/listinfo/wp-hackers
_______________________________________________
wp-hackers mailing list
http://lists.automattic.com/mailman/listinfo/wp-hackers
_______________________________________________
wp-hackers mailing list
http://lists.automattic.com/mailman/listinfo/wp-hackers
Gregory Lancaster
2013-10-07 22:33:44 UTC
Permalink
Got it thanks to your help JD. Thank you!
Post by Gregory Lancaster
I dont think the comment meta can not save on custom post types by default.
Post by J.D. Grimes
Yes. That means it must be using its own version of the comment_form()
function. Maybe it has similar hooks?
Post by Gregory Lancaster
awesome! Thats exactly what I needed. Apparently with this framework
the
Post by Gregory Lancaster
comments.php isnt affected by the add_comment_fields, I have to add it
manually. Since thats the case, I can skip the function right?
Post by J.D. Grimes
comment_form_logged_in_after
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.
Post by Gregory Lancaster
Post by J.D. Grimes
The saving should work the same as before, I think.
No, there's nothing wrong with that code. Actually, it works, but
// 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...
Post by Gregory Lancaster
Post by J.D. Grimes
On Oct 7, 2013, at 3:01 PM, Gregory Lancaster <
I got it :)
I followed the smashing guide, and no fields showed up. So I tried
just
Post by Gregory Lancaster
Post by J.D. Grimes
copy pasting their example code and that didnt work either. Is
there
Post by Gregory Lancaster
Post by J.D. Grimes
function add_comment_fields($fields) {
$fields['age'] = '<p class="comment-form-age"><label for="age">' .
__(
Post by Gregory Lancaster
Post by J.D. Grimes
'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);
Post by J.D. Grimes
I tried to send a reply to that earlier, but I don't think it went
through
Post by J.D. Grimes
- I just resent it now, let me know if you get it.
On Oct 7, 2013, at 2:54 PM, Gregory Lancaster <
Post by Gregory Lancaster
I was going to (i am tryign to code the plugin I emailed you about
myself
Post by J.D. Grimes
Post by Gregory Lancaster
today, I have all day :) ) but the is_post_type was depreciated.
Not
Post by J.D. Grimes
Post by Gregory Lancaster
sure what to use now.
Post by Chris McCoy
I would check for the post type, if its the one you wish to add
to do
Post by Gregory Lancaster
Post by J.D. Grimes
Post by J.D. Grimes
the
Post by Gregory Lancaster
Post by Chris McCoy
process like in the tutorial, so it only shows on the comment form
for
Post by J.D. Grimes
the
Post by Gregory Lancaster
Post by Chris McCoy
post type.
Post by BenderisGreat
I did see that, but I need to add the custom comment fields only
to
Post by Gregory Lancaster
Post by J.D. Grimes
the
Post by J.D. Grimes
Post by Gregory Lancaster
Post by Chris McCoy
Post by BenderisGreat
custom post type
--
http://wordpress-hackers.1065353.n5.nabble.com/adding-custom-fields-to-a-c
Post by Gregory Lancaster
Post by J.D. Grimes
Post by J.D. Grimes
Post by Gregory Lancaster
Post by Chris McCoy
Post by BenderisGreat
omment-form-tp42446p42453.html
Sent from the Wordpress Hackers mailing list archive at
Nabble.com.
Post by Gregory Lancaster
Post by J.D. Grimes
Post by J.D. Grimes
Post by Gregory Lancaster
Post by Chris McCoy
Post by BenderisGreat
_______________________________________________
wp-hackers mailing list
http://lists.automattic.com/mailman/listinfo/wp-hackers
_______________________________________________
wp-hackers mailing list
http://lists.automattic.com/mailman/listinfo/wp-hackers
_______________________________________________
wp-hackers mailing list
http://lists.automattic.com/mailman/listinfo/wp-hackers
_______________________________________________
wp-hackers mailing list
http://lists.automattic.com/mailman/listinfo/wp-hackers
_______________________________________________
wp-hackers mailing list
http://lists.automattic.com/mailman/listinfo/wp-hackers
_______________________________________________
wp-hackers mailing list
http://lists.automattic.com/mailman/listinfo/wp-hackers
_______________________________________________
wp-hackers mailing list
http://lists.automattic.com/mailman/listinfo/wp-hackers
_______________________________________________
wp-hackers mailing list
http://lists.automattic.com/mailman/listinfo/wp-hackers
_______________________________________________
wp-hackers mailing list
http://lists.automattic.com/mailman/listinfo/wp-hackers
Gregory Lancaster
2013-10-07 19:35:09 UTC
Permalink
No something isnt right here. Even if I drop that code in functions.php no
extra field is showing. Maybe its because I use roots framework theme. Not
sure gonna try the code on a different theme now.
Post by J.D. Grimes
// 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...
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
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);
Post by J.D. Grimes
I tried to send a reply to that earlier, but I don't think it went
through
Post by J.D. Grimes
- I just resent it now, let me know if you get it.
On Oct 7, 2013, at 2:54 PM, Gregory Lancaster <
Post by Gregory Lancaster
I was going to (i am tryign to code the plugin I emailed you about
myself
Post by J.D. Grimes
Post by Gregory Lancaster
today, I have all day :) ) but the is_post_type was depreciated. Not
sure what to use now.
Post by Chris McCoy
I would check for the post type, if its the one you wish to add to do
the
Post by Gregory Lancaster
Post by Chris McCoy
process like in the tutorial, so it only shows on the comment form for
the
Post by Gregory Lancaster
Post by Chris McCoy
post type.
Post by BenderisGreat
I did see that, but I need to add the custom comment fields only to
the
Post by J.D. Grimes
Post by Gregory Lancaster
Post by Chris McCoy
Post by BenderisGreat
custom post type
--
http://wordpress-hackers.1065353.n5.nabble.com/adding-custom-fields-to-a-c
Post by J.D. Grimes
Post by Gregory Lancaster
Post by Chris McCoy
Post by BenderisGreat
omment-form-tp42446p42453.html
Sent from the Wordpress Hackers mailing list archive at Nabble.com.
_______________________________________________
wp-hackers mailing list
http://lists.automattic.com/mailman/listinfo/wp-hackers
_______________________________________________
wp-hackers mailing list
http://lists.automattic.com/mailman/listinfo/wp-hackers
_______________________________________________
wp-hackers mailing list
http://lists.automattic.com/mailman/listinfo/wp-hackers
_______________________________________________
wp-hackers mailing list
http://lists.automattic.com/mailman/listinfo/wp-hackers
_______________________________________________
wp-hackers mailing list
http://lists.automattic.com/mailman/listinfo/wp-hackers
_______________________________________________
wp-hackers mailing list
http://lists.automattic.com/mailman/listinfo/wp-hackers
J.D. Grimes
2013-10-07 18:54:47 UTC
Permalink
Find the post type with get_post_type() - http://codex.wordpress.org/Function_Reference/get_post_type

If it's the wrong post type, don't display/save the fields.
Post by BenderisGreat
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-comment-form-tp42446p42453.html
Sent from the Wordpress Hackers mailing list archive at Nabble.com.
_______________________________________________
wp-hackers mailing list
http://lists.automattic.com/mailman/listinfo/wp-hackers
Loading...