latest stable versions: v150827 (changelog)

Old Forums (READ-ONLY): The community now lives at WP Sharks™. If you have an s2Member® Pro question, please use our new Support System.

Additional conditional in comments section

Home Forums Community Forum Additional conditional in comments section

This topic contains 11 replies, has 2 voices. Last updated by  Eduardo Colmenares 3 years, 11 months ago.

Topic Author Topic
Posted: Friday Feb 1st, 2013 at 3:24 pm #40300

Hi-

I’m trying to restrict access to commenting on a site I’m working on. I want only paid members to be able to comment (non-paid users can still read comments). I changed the following

comment_status) : ?>

to

comment_status && current_user_can(“access_s2member_level1”) : ?>

The good news is, no errors. The bad news is, it doesn’t do anything. If I’m logged in as a level0 member, I can still comment. Any ideas?

thanks
-e

List Of Topic Replies

Viewing 11 replies - 1 through 11 (of 11 total)
Author Replies
Author Replies
Posted: Friday Feb 1st, 2013 at 3:26 pm #40301

Part of my code was stripped out. I changed

if (‘open’ == $post->comment_status) : ?>

to

if (‘open’ == $post->comment_status && current_user_can(“access_s2member_level1”) : ?>

Just pretend the opening php code is on those =)

Posted: Friday Feb 1st, 2013 at 3:40 pm #40303

Also tried

(‘open’ == $post->comment_status && current_user_is(“s2member_level1”) : ?>

to no avail.

-e

Posted: Saturday Feb 2nd, 2013 at 12:54 pm #40490
Eduan
Username: Eduan
Moderator

That is all very strange.

What happens if you try something like this?:

if ('open' == $post->comment_status):
	if (current_user_is("s2member_level1")): ?>

Of course you would add a closing endif at the bottom. :)

Also, I noticed, all of your examples are missing a ‘)’ for all the if statements. ;)

– Eduan

Posted: Saturday Feb 2nd, 2013 at 12:55 pm #40493

Thanks – that if statement already has the endif – I’m just adding the extra conditional.

I’ll check out the possible missing “)”, but I’m pretty sure that’s already there too.

Posted: Saturday Feb 2nd, 2013 at 2:41 pm #40510

Eduan-

Yep – I’m missing the first “)” . It still isn’t doing anything though :P

thanks
-e

Posted: Monday Feb 4th, 2013 at 1:16 pm #40749
Eduan
Username: Eduan
Moderator

Hmm…

Could you show me the entire post/page or file that contains this code? Or just the whole code from the start of the if till the endif, without cutting out anything.

– Eduan

Posted: Monday Feb 4th, 2013 at 1:23 pm #40752

Hi-

Sure. Here’s a post:

http://drumsetgallery.com/welcome-to-drum-set-gallery/

And let me try the code tag. Look at line 69:

<?php
/**
* @package WordPress
* @subpackage Default_Theme
*/

// Do not delete these lines
   if (!empty($_SERVER['SCRIPT_FILENAME']) && 'comments.php' == basename($_SERVER['SCRIPT_FILENAME']))
      die (esc_html__('Please do not load this page directly. Thanks!','TheStyle'));

   if ( post_password_required() ) { ?>

<p class="nocomments"><?php esc_html_e('This post is password protected. Enter the password to view comments.','TheStyle') ?></p>
<?php
      return;
   }
?>
<!-- You can start editing here. -->

<?php if ('open' == $post->comment_status) : ?>
<div id="comment-wrap">
   <div id="comment-bottom-bg">
<?php endif; ?>
      <?php if ( have_comments() ) : ?>
         
         <h3 id="comments"><?php comments_number(esc_html__('0 Comments','TheStyle'), esc_html__('1 Comment','TheStyle'), '% '.esc_html__('Comments','TheStyle') );?></h3>
            
        <?php if ( get_comment_pages_count() > 1 && get_option( 'page_comments' ) ) : // Are there comments to navigate through? ?>
			<div class="comment_navigation_top clearfix">
				<div class="nav-previous"><?php previous_comments_link( __( '<span class="meta-nav">&larr;</span> Older Comments', 'TheStyle' ) ); ?></div>
				<div class="nav-next"><?php next_comments_link( __( 'Newer Comments <span class="meta-nav">&rarr;</span>', 'TheStyle' ) ); ?></div>
			</div> <!-- .navigation -->
		<?php endif; // check for comment navigation ?>
		
		<?php if ( ! empty($comments_by_type['comment']) ) : ?>
			<ol class="commentlist clearfix">
				<?php wp_list_comments( array('type'=>'comment','callback'=>'et_custom_comments_display') ); ?>
			</ol>
		<?php endif; ?>
		
		<?php if ( get_comment_pages_count() > 1 && get_option( 'page_comments' ) ) : // Are there comments to navigate through? ?>
			<div class="comment_navigation_bottom clearfix">
				<div class="nav-previous"><?php previous_comments_link( __( '<span class="meta-nav">&larr;</span> Older Comments', 'TheStyle' ) ); ?></div>
				<div class="nav-next"><?php next_comments_link( __( 'Newer Comments <span class="meta-nav">&rarr;</span>', 'TheStyle' ) ); ?></div>
			</div> <!-- .navigation -->
		<?php endif; // check for comment navigation ?>
			
		<?php if ( ! empty($comments_by_type['pings']) ) : ?>
			<div id="trackbacks">
				<h3 id="trackbacks-title"><?php esc_html_e('Trackbacks/Pingbacks','TheStyle') ?></h3>
				<ol class="pinglist">
					<?php wp_list_comments('type=pings&callback=et_list_pings'); ?>
				</ol>
			</div>
		<?php endif; ?>	
      <?php else : // this is displayed if there are no comments so far ?>
         <div id="comment-section" class="nocomments">
           <?php if ('open' == $post->comment_status) : ?>
             <!-- If comments are open, but there are no comments. -->
             
           <?php else : // comments are closed ?>
             <!-- If comments are closed. -->
               <div id="respond">
                  
               </div> <!-- end respond div -->
           <?php endif; ?>
         </div>
      <?php endif; ?>
      <?php if ('open' == $post->comment_status) && current_user_is("s2member_level1") : ?>

        <?php comment_form( array('label_submit' => esc_attr__( 'Submit Comment', 'TheStyle' ), 'title_reply' => '<span>' . esc_attr__( 'Leave a Reply', 'TheStyle' ) . '</span>', 'title_reply_to' => esc_attr__( 'Leave a Reply to %s' )) ); ?>
      <?php else: ?>

      <?php endif; // if you delete this the sky will fall on your head ?>
<?php if ('open' == $post->comment_status) : ?>
   </div>
</div>
<?php endif; ?>
Posted: Wednesday Feb 6th, 2013 at 8:27 pm #40951
Eduan
Username: Eduan
Moderator

Line 69 is:

<?php if ('open' == $post->comment_status) && current_user_is("s2member_level1") : ?>

Try this instead:

<?php if ('open' == $post->comment_status && current_user_is("s2member_level1")) : ?>

The parentheses are messed up. :)

– Eduan

Posted: Thursday Feb 7th, 2013 at 2:55 pm #41043

Hi Eduan-

Still no go with the corrected code. Here’s what I finally did, in the Single template

<?php if (current_user_is("s2member_level0")){ ?>
<style type="text/css">
#sfw-respond {display: none;}
</style>
<?php } ?>

Not the greatest, but it works.

thanks
-e

Posted: Friday Feb 8th, 2013 at 10:06 pm #41241
Eduan
Username: Eduan
Moderator

Well if it works that’s great. :)

I’m not sure what could be wrong with the other code. Maybe I’m just blind. :)

– Eduan

Posted: Friday Feb 8th, 2013 at 10:11 pm #41242

Really, it should just work. It’s just being completely ignored for some reason. Thanks for the input though!

Viewing 11 replies - 1 through 11 (of 11 total)

This topic is closed to new replies. Topics with no replies for 2 weeks are closed automatically.

Old Forums (READ-ONLY): The community now lives at WP Sharks™. If you have an s2Member® Pro question, please use our new Support System.

Contacting s2Member: Please use our Support Center for bug reports, pre-sale questions & technical assistance.