First, this is what I want to achieve:
I want to add a comments hook on a CPT which is asking users to be registered and logged in to be able to post a comment. And after the user is logged in to display two custom fields before the comment field.
My discussion settings are not set to *Users must be registered and logged in to comment * because on my default blog posts I don't want to force users to register in order to comment.
Here is what I've did till now :
function debate_comment_fields( $fields ) {
if( is_singular( 'debate' ) ) {
// these are the custom fields which I want to display before the comment field
$fields['first'] = '<p class="comment-form-first"><label for="first">' .
__( 'HTML5' ) .
'</label>' .
'<input id="first" name="category" type="radio" value="'.get_post_meta($post->ID, 'agree', true).'" /></p>';
$fields['second'] = '<p class="comment-form-second"><label for="second">' .
__( 'FLASH' ) .
'</label>' .
'<input id="second" name="category" type="radio" value="'.get_post_meta($post->ID, 'disagree', true).'" /></p>';
return $fields;
}
else {
return $fields;
}
}
add_filter('comment_form_default_fields','debate_comment_fields');
I've looked through the CODEX, and I found this comment_form_must_log_in_after
but this is not helping me because I need first to add a hook which is asking user to log in.
I've looked also into mytheme/comments.php here is a snippet:
<div id="comments" class="comments-area">
<?php if ( have_comments() ) : ?>
<h3 class="comments-title">
<?php
printf( _n('%d comment', '%d comments', get_comments_number(), 'outbox' ),
number_format_i18n( get_comments_number() ) );
?>
</h3>
<ol class="commentlist">
<?php
wp_list_comments( array( 'callback' => 'outbox_comment' ) );
?>
</ol><!-- .commentlist -->
<?php if ( get_comment_pages_count() > 1 && get_option( 'page_comments' ) ) : // are there comments to navigate through? If so, show navigation ?>
<nav role="navigation" id="comment-nav-below" class="site-navigation comment-navigation clearfix">
<div class="nav-previous"><i class="icon-left-open-1"></i> <?php echo get_previous_comments_link( __( 'Older Comments', 'outbox' ) ); ?></div>
<div class="nav-next"><?php echo get_next_comments_link( __( 'Newer Comments', 'outbox' ) ); ?> <i class="icon-right-open-1"></i></div>
</nav><!-- #comment-nav-below .site-navigation .comment-navigation -->
<?php endif; ?>
<?php endif; // have_comments() ?>
<?php
// If comments are closed and there are comments, let's leave a little note, shall we?
if ( ! comments_open() && '0' != get_comments_number() && post_type_supports( get_post_type(), 'comments' ) ) :
?>
<p class="nocomments"><?php _e( 'Comments are closed.', 'outbox' ); ?></p>
<?php endif; ?>
<?php comment_form(); ?>
This is the 'must_log_in' :
'must_log_in' => '<p class="must-log-in">' . sprintf( __( 'You must be <a href="%s">logged in</a> to post a comment.' ), wp_login_url( apply_filters( 'the_permalink', get_permalink( $post_id ) ) ) ) . '</p>',
Any idea on how can I achieve this?
Thank you!