Title: Comments for subscribers only
Last modified: August 20, 2016

---

# Comments for subscribers only

 *  [perezdi](https://wordpress.org/support/users/perezdi/)
 * (@perezdi)
 * [13 years, 10 months ago](https://wordpress.org/support/topic/comments-for-subscribers-only/)
 * Hi, there.
 * I have a website that is kind of a sports magazine and recently, we are added
   a subscribers session. So we are using the YourMembers plugin for it. I work 
   with WordPress for three years, not really a programmer over here, but I was 
   never afraid about messing with code. That’s what I want to do:
 * – Subscribers can comment on the subscribers categorie posts.
    – Non-subscribers
   can comment in all other categories without needing a free subsbriber account.
 * I thought a way of doing it would be creating a custom categorie but then I don’t
   know what else to do. Probably, two comments files? If so, how to properly do
   it? And how it would reflect on WordPress automatic updates? I think the updates
   will be just fine because it will not overwrite the files in the server (and 
   of course, a backup before upgrading ins’t a bad idea).
 * Thank you in advance

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

 *  Moderator [bcworkz](https://wordpress.org/support/users/bcworkz/)
 * (@bcworkz)
 * [13 years, 10 months ago](https://wordpress.org/support/topic/comments-for-subscribers-only/#post-2885236)
 * I’m not familiar with YourMembers, or how subscribers might be different than
   WP registered users. I’ll assume there is a way for your code to determine if
   a client is a subscriber or not.
 * My solution is theme based, so it’s protected from WP updates. You can protect
   your code from theme updates by creating a child theme. On any theme template
   for which comment forms are displayed, typically comments.php, there should be
   a call to `comment_form()` or code that outputs the comment form directly.
 * You just need to modify this code so that if the post is in your subscribers 
   category, only display the comment form if the client is a subscriber, otherwise
   display the comment form to everyone. No need for two files.
 *  Thread Starter [perezdi](https://wordpress.org/support/users/perezdi/)
 * (@perezdi)
 * [13 years, 10 months ago](https://wordpress.org/support/topic/comments-for-subscribers-only/#post-2885242)
 * I’ve been told to wrap the comments function on a funcionality the plugin has.
 * I search for the function on the plugin and it’s this one:
 *     ```
       //Private Tag with AND statement Account Type
       		case 'private_and':
       			if (ym_user_has_access() && strtolower($argument) == strtolower($ym_user->account_type)){
       				$return = $matches;
       			}
       ```
   
 * I need help recognizing where is the comment loop, I’m not really a php ninja.
 *     ```
       ﻿<?php
       /**
        * @package WordPress
        * @subpackage Default_Theme
        */
   
       // Do not delete these lines
       	if (!empty($_SERVER['SCRIPT_FILENAME']) && 'comments.php' == basename($_SERVER['SCRIPT_FILENAME']))
       		die ('Please do not load this page directly. Thanks!');
   
       	if ( post_password_required() ) { ?>	
   
       <p class="nocomments"><?php _e('Essa postagem é protegida por senha, se você errá-la, seu computador irá explodir.', 'framework') ?></p>
       <?php
       		return;
       	}
       ?>
       <!-- You can start editing here. -->
       <div id="comments">
         <?php if ( have_comments() ) : ?>
         <?php if ( ! empty($comments_by_type['comment']) ) : ?>
         <h3 id="comments-h3">
           <?php comments_number(__('Deixe na conta do Papa', 'framework'), __('1 na conta do Papa', 'framework'), __('% na conta do Papa', 'framework') );?>
         </h3>
         <ol class="commentlist">
           <?php wp_list_comments('type=comment&avatar_size=50&callback=custom_comment_fun'); ?>
         </ol>
         <?php endif; ?>
         <?php if ( ! empty($comments_by_type['pings']) ) : ?>
         <div class="trackbacks">
           <h3 id="pings">Trackbacks/Pings</h3>
           <ul>
             <?php wp_list_comments('type=pings&callback=list_pings'); ?>
           </ul>
         </div>
         <?php endif; ?>
         <div class="navigation">
           <div class="alignleft">
             <?php previous_comments_link() ?>
           </div>
           <div class="alignright">
             <?php next_comments_link() ?>
           </div>
         </div>
         <?php else : // this is displayed if there are no comments so far ?>
         <?php if ( comments_open() ) : ?>
         <!-- If comments are open, but there are no comments. -->
         <?php else : // comments are closed ?>
         <!-- If comments are closed. -->
   
         <?php endif; ?>
         <?php endif; ?>
         <?php if ( comments_open() ) : ?>
         <div id="respond">
           <h3>
             <?php comment_form_title( __('Deixar na conta do Papa', 'framework'), __('Deixe um comentário para %', 'framework') ); ?>
           </h3>
   
       <br/>
       Quer ver seu avatar nos comentários? Faça uma conta gratuita no <strong><a target="_blank" href="http://pt.gravatar.com"/><span style="color: #dd2221;">Gravatar</a></span></strong>.<br/> Os comentários são um espaço para conversarmos. Concordar ou discordar não faz diferença, mas educação, sim. Se você sabe dialogar, concordando ou discordando educadamente, seja bem-vindo.<br/><br/>
   
           <div class="cancel-comment-reply">
             <?php cancel_comment_reply_link(); ?>
           </div>
           <?php if ( get_option('comment_registration') && !is_user_logged_in() ) : ?>
           <p><?php _e('You must be', 'framework') ?> <a href="<?php echo wp_login_url( get_permalink() ); ?>"><?php _e('logged in', 'framework') ?></a> <?php _e('para deixar na conta do Papa.', 'framework') ?></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><?php _e('Logado como', 'framework') ?> <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="<?php _e('Deslogar dessa conta', 'framework') ?>"><?php _e('Deslogar &raquo;', 'framework') ?></a></p>
             <?php else : ?>
             <p>
               <label for="author"><small><?php _e('Nome', 'framework') ?>
                 <?php if ($req) _e('(required)', 'framework'); ?>
                 </small></label>
               <br />
               <input type="text" name="author" id="author" value="<?php echo esc_attr($comment_author); ?>" size="22" tabindex="1"/>
             </p>
             <p>
               <label for="email"><small><?php _e('e-mail (não será publicado)', 'framework') ?>
                 <?php if ($req) _e('(Obrigatório)', 'framework'); ?>
                 </small></label>
               <br />
               <input type="text" name="email" id="email" value="<?php echo esc_attr($comment_author_email); ?>" size="22" tabindex="2" />
             </p>
             <p>
               <label for="url"><small><?php _e('Website', 'framework') ?></small></label>
               <br />
               <input type="text" name="url" id="url" value="<?php echo esc_attr($comment_author_url); ?>" size="22" tabindex="3" />
             </p>
             <?php endif; ?>
             <!--<p><small><strong>XHTML:</strong> You can use these tags: <code><?php echo allowed_tags(); ?></code></small></p>-->
             <p>
               <label for="comment"><small><?php _e('Digite abaixo o seu comentário', 'framework') ?></small></label>
               <br />
               <textarea name="comment" id="comment" cols="58" rows="10" tabindex="4"></textarea>
             </p>
             <p>
               <input name="submit" type="submit" id="submit" tabindex="20" value="<?php _e('ENVIAR', 'framework') ?>" />
               <?php comment_id_fields(); ?>
             </p>
             <?php do_action('comment_form', $post->ID); ?>
           </form>
         </div>
         <?php endif; // If registration required and not logged in ?>
         <?php endif; // if you delete this the sky will fall on your head ?>
       </div>
       ```
   
 * I got a tip from a developer over there saying that I should do this:
 *     ```
       if (ym_user_has_access()) {
       // comment submit form
       }
       ```
   
 * But like I said, I’m no php programmer, I’m really new to it, I just need a bit
   of pointing “this is what you are looking for”. I hope it’s not to much to ask
   for. A problem when you don’t know what you are talking about is not knowing 
   the limits too from “too much” or “too little”. I guess.
 * Thank you
 *  Moderator [bcworkz](https://wordpress.org/support/users/bcworkz/)
 * (@bcworkz)
 * [13 years, 10 months ago](https://wordpress.org/support/topic/comments-for-subscribers-only/#post-2885304)
 * The actual comment form is all the html starting with and including the line 
   beginning:
    `<form action="<?php echo get_option('siteurl');...` including all
   lines between and ending with and including the line: `</form>` but the actual
   related code starts with the line: `<?php if ( comments_open() ) : ?>` and ends
   with a corresponding: `<?php endif; ?>` which is not included in the snippet 
   you provided. The code has some logic that may conflict with your desires, which
   will need sorting out. To result in cleaner modular code, it would be useful 
   to call a function that outputs the form, instead of it being part of the template.
   This would mean all the html would need to be echoed out in a php function.
 * Since you are new to this, doing so will take a bit of work, but if you don’t
   do it, you can easily get confused by simply copying code snippets here and there
   and end up with difficult to find errors. Also keep in mind that if you hack 
   this plugin, anytime the plugin is updated, your changes may be lost. You should
   consider keeping your code in a separate file outside of the plugin’s folder 
   structure, so your edit of the plugin code is limited to commenting out the section
   not needed and inserting a require_once statement referring to your separate 
   file. You will need to re-do this edit every time the plugin is updated.
 *  Thread Starter [perezdi](https://wordpress.org/support/users/perezdi/)
 * (@perezdi)
 * [13 years, 10 months ago](https://wordpress.org/support/topic/comments-for-subscribers-only/#post-2885307)
 * Well, this already tells me a lot and is very helpfull. Thank you so much, mate.
   Will have to see someone to mess with this for me, since I don`t think I`m ready
   to fight this dragon.
 * Cheers!

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

The topic ‘Comments for subscribers only’ is closed to new replies.

## Tags

 * [Comments](https://wordpress.org/support/topic-tag/comments/)
 * [subscribers](https://wordpress.org/support/topic-tag/subscribers/)

 * In: [Hacks](https://wordpress.org/support/forum/plugins-and-hacks/hacks/)
 * 4 replies
 * 2 participants
 * Last reply from: [perezdi](https://wordpress.org/support/users/perezdi/)
 * Last activity: [13 years, 10 months ago](https://wordpress.org/support/topic/comments-for-subscribers-only/#post-2885307)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
