Support » Fixing WordPress » Comment box shows when ‘login to comment’ is selected

  • In the Discussion Settings I’ve chosen Users must be registered and logged in to comment.

    However the comment box still appears on posts. If you fill it in, you get a screen with ‘Sorry, you must be logged in to comment’ and that’s all.

    The comment box should be hidden if this is chosen.

    Can someone please let me know how to do this?


Viewing 4 replies - 1 through 4 (of 4 total)
  • whooami



    youre asking for a lot of info without providing a lot. By that i mean that the theme file, comments.php, is rather complicated, and I cant just paste code for you to use out of the box. No-one can really, without knowing what theme you are using and being able to look at the files.

    That said, what your theme is missing is a variation of this bit though:

    <?php if ( get_option('comment_registration') && !is_user_logged_in() ) : ?>
    <p>You must be <a href="<?php echo wp_login_url( get_permalink() ); ?>">logged in</a> to post a comment.</p>
    <?php else : ?>
    <form action="<?php echo get_option('siteurl'); ?>/wp-comments-post.php" method="post" id="commentform">
    <?php if ( is_user_logged_in() ) : ?>
    <p>Logged in as <a href="<?php echo get_option('siteurl'); ?>/wp-admin/profile.php"><?php echo $user_identity; ?></a>. <a href="<?php echo wp_logout_url(get_permalink()); ?>" title="Log out of this account">Log out &raquo;</a></p>
    <?php else : ?>
    <p><input type="text" name="author" id="author" value="<?php echo esc_attr($comment_author); ?>" size="22" tabindex="1" <?php if ($req) echo "aria-required='true'"; ?> />
    <label for="author"><small>Name <?php if ($req) echo "(required)"; ?></small></label></p>
    <p><input type="text" name="email" id="email" value="<?php echo esc_attr($comment_author_email); ?>" size="22" tabindex="2" <?php if ($req) echo "aria-required='true'"; ?> />
    <label for="email"><small>Mail (will not be published) <?php if ($req) echo "(required)"; ?></small></label></p>
    <p><input type="text" name="url" id="url" value="<?php echo esc_attr($comment_author_url); ?>" size="22" tabindex="3" />
    <label for="url"><small>Website</small></label></p>
    <?php endif; ?>

    thats a straight copy and paste out of the default theme’s comment.php, so if you decide to edit your own theme’s comment.php and change things up, your mileage may vary.

    I’m using arras theme, which I put as a tag. I thought that would be enough information to see which theme I am using. I didn’t realise I had to put it in the text as well.

    Here is the comments.php:

    if ( !empty($_SERVER['SCRIPT_FILENAME']) && 'comments.php' == basename($_SERVER['SCRIPT_FILENAME']) )
    die( __('Please do not load this page directly. Thanks!', 'arras') );
    if ( post_password_required() ) {
    _e('<p class="nocomments">This post is password protected. Enter the password to view comments.</p>', 'arras');
    <?php if ( have_comments() ) : ?>
    <?php if ( !empty($comments_by_type['comment']) ) : ?>
    <h4 class="module-title"><?php comments_number( __('No Comments', 'arras'), __('1 Comment', 'arras'), __ngettext('% Comment', '% Comments', get_comments_number(), 'arras') ); ?></h4>
    <ol id="commentlist" class="clearfix">
    <?php wp_list_comments('type=comment&callback=arras_list_comments'); ?>

    <div class="comments-navigation clearfix">
    <div class="floatleft"><?php previous_comments_link() ?></div>
    <div class="floatright"><?php next_comments_link() ?></div>
    <?php endif; ?>

    <?php if ( !empty($comments_by_type['pings']) ) : ?>
    <h4 class="module-title"><?php _e('Trackbacks / Pings', 'arras') ?></h4>
    <ol class="pingbacks"><?php wp_list_comments('type=pings&callback=arras_list_trackbacks'); ?>
    <?php endif; ?>

    <?php else: ?>
    <?php if ('open' == $post->comment_status) : ?>
    <h4 class="module-title"><?php _e('No Comments', 'arras') ?></h4>
    <p class="nocomments"><?php _e('Start the ball rolling by posting a comment on this article!', 'arras') ?></p>
    <?php else : ?>
    <h4 class="module-title"><?php _e('Comments Closed', 'arras') ?></h4>
    <p class="nocomments"><?php _e('Comments are closed. You will not be able to post a comment in this post.', 'arras') ?></p>
    <?php endif ?>
    <?php endif; ?>

    <?php if ('open' == $post->comment_status) : ?>
    <div id="respond">
    <h4 class="module-title"><?php comment_form_title( __('Leave a Reply', 'arras'), __('Leave a Reply to %s', 'arras') ); ?></h4>
    <div id="commentsform">
    <form action="<?php echo get_option('siteurl'); ?>/wp-comments-post.php" method="post" id="commentform">
    <?php comment_id_fields(); ?>
    <?php if ( $user_ID ) : ?>
    <?php printf( __('Logged in as %3$s.', 'arras'), get_option('siteurl') . '/wp-admin/profile.php', $user_identity, $user_identity) ?>
    " title="<?php _e('Log out of this account', 'arras') ?>"> (<?php _e('Logout', 'arras') ?>)
    <?php else : ?>
    <p><label for="author"><?php _e('Name', 'arras') ?> <?php if ($req) _e('(required)', 'arras') ?></label>
    <input type="text" name="author" id="s1" value="<?php echo $comment_author; ?>" size="40" tabindex="1" minlength="2" <?php if (get_option('require_name_email')) : ?>class="required"<?php endif ?> />
    <p><label for="email"><?php _e('Mail (will not be published)', 'arras') ?> <?php if ($req) _e('(required)', 'arras') ?></label>
    <input type="text" name="email" id="s2" value="<?php echo $comment_author_email; ?>" size="40" tabindex="2" <?php if (get_option('require_name_email')) : ?>class="required email"<?php endif ?> />
    <p><label for="url"><?php _e('Website', 'arras') ?></label>
    <input type="text" name="url" id="s3" value="<?php echo $comment_author_url; ?>" size="40" tabindex="3" class="url" />
    <?php endif; ?>
    <p><?php printf( __('XHTML: You can use these tags: %s‘, ‘arras’), allowed_tags() ) ?></p>
    <textarea name=”comment” id=”s4″ cols=”50″ rows=”10″ tabindex=”4″ class=”required”></textarea>
    <?php if(function_exists(‘show_subscription_checkbox’)) : ?>
    <p><?php show_subscription_checkbox() ?></p>
    <?php endif; ?>
    <input name=”submit” type=”submit” id=”sbutt” tabindex=”5″ value=”<?php _e(‘Submit Comment’, ‘arras’) ?>” />
    <?php cancel_comment_reply_link( __(‘Cancel Reply’, ‘arras’) ) ?>
    <?php do_action(‘comment_form’, $post->ID); ?>
    <?php if(function_exists(‘show_manual_subscription_form’)) { show_manual_subscription_form(); } ?>
    </div><!– end #commentsform –></div>
    <?php endif ?>

    Thanks for any help – this is a showstopper!



    I had the same problem. I have found a solution for this problem. You need to update your arrastheme “comments.php” file:
    Just after <?php if ('open' == $post->comment_status) : ?>, you need add the following code at the line 34:
    <?php if ( get_option('comment_registration') && !$user_ID ) : ?>
    <p>You need to be <a href="<?php echo get_option('siteurl'); ?>/wp-login.php?redirect_to=<?php echo urlencode(get_permalink()); ?>">logged</a> to publish comments.</p>
    At the end of the file, you add <?php endif ?>.

    All works for me

    Comment: I’m french, and my english is bad. You can change easily the sentence to redirect the users.



    To preserve the design of the theme, you need to add “class”.
    replace the previous first point by :
    <?php if ( get_option('comment_registration') && !$user_ID ) : ?>
    <h4 class="module-title">Connection</h4>
    <p class="nocomments">You need to be <a href="<?php echo get_option('siteurl'); ?>/wp-login.php?redirect_to=<?php echo urlencode(get_permalink()); ?>">logged</a> to publish comments.</p>

    To change the title of this section, you need to replace Connection by your title.

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Comment box shows when ‘login to comment’ is selected’ is closed to new replies.