Title: Logged-In Users Only
Last modified: August 21, 2016

---

# Logged-In Users Only

 *  Resolved [Dennis Wagner](https://wordpress.org/support/users/antonhh/)
 * (@antonhh)
 * [12 years, 7 months ago](https://wordpress.org/support/topic/logged-in-users-only/)
 * Hi Ricard,
 * great plugin and great support, too.
 * How can I achieve that only logged-in users can rate posts or comments.
 * Greetings,
    Dennis
 * [http://wordpress.org/plugins/thumbs-rating/](http://wordpress.org/plugins/thumbs-rating/)

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

 *  Plugin Author [Ricard Torres](https://wordpress.org/support/users/quicoto/)
 * (@quicoto)
 * [12 years, 7 months ago](https://wordpress.org/support/topic/logged-in-users-only/#post-4492318)
 * Hello!
 * You could print the buttons for logged-in users only.
 * The code inside your functions.php file would be like this:
 *     ```
       function thumbs_rating_print($content)
       {
           if ( is_user_logged_in() ){
   
                $content .= thumbs_rating_getlink();
           }
           return $content;
       }
       add_filter('the_content', 'thumbs_rating_print');
       ```
   
 * Let me know if this works for you!
 *  [Stefan Velev](https://wordpress.org/support/users/kozzmen/)
 * (@kozzmen)
 * [12 years, 6 months ago](https://wordpress.org/support/topic/logged-in-users-only/#post-4492487)
 * Thanks for your input Richard,
 * I was looking for more or less the same feature.
 * Is there any way to achieve this: when visitor tries to vote/rate a post, pop
   up is showing up with “log in or register” option?
 * Thanks in advance
 * Stefan
 *  Plugin Author [Ricard Torres](https://wordpress.org/support/users/quicoto/)
 * (@quicoto)
 * [12 years, 6 months ago](https://wordpress.org/support/topic/logged-in-users-only/#post-4492488)
 * Hi Stefan,
 * I guess you could. Here’s a brainstorming:
 * You could add an event listener (using jQuery) to listen the onclick event. The
   code should only run if the user is not logged in.
 * Try something like this:
 *     ```
       <?php
       	if ( !is_user_logged_in() ){ ?>
   
       	<script>
       	jQuery(document).ready(function() {
   
       	  jQuery(".thumbs-rating-container .thumbs-rating-up, .thumbs-rating-container .thumbs-rating-down").on("click", function(event){
   
       	  		alert('You need to be registered in order to vote!');
   
       	  });
       	});
       	</script>
   
       <?php } /* END if user is not logged in */ ?>
       ```
   
 *  Thread Starter [Dennis Wagner](https://wordpress.org/support/users/antonhh/)
 * (@antonhh)
 * [12 years, 6 months ago](https://wordpress.org/support/topic/logged-in-users-only/#post-4492493)
 * First of all, thanks for your quick response.
 * I definitely want people to see there is a voting possibilty, so the first option
   wouldn’t satisfy me. I think your second suggestion is what I was looking for,
   I’m just not sure what to do with that piece of code. I tried a couple times 
   to integrate jQuerys in my theme but they didn’t work. Can you give me a little
   tip to make this work. Or are you planing to make an update with that feature
   in the near future?
 * Greetings,
    Dennis
 *  Plugin Author [Ricard Torres](https://wordpress.org/support/users/quicoto/)
 * (@quicoto)
 * [12 years, 6 months ago](https://wordpress.org/support/topic/logged-in-users-only/#post-4492494)
 * No plans for now.
 * Your theme should work with jQuery, although it could be something wrong with
   it. If that were the case, I’d suggest choosing an other theme.
 * Regarding the code, you should paste it in your footer.php (or similar). However
   I think it needs more tweaking. Right now it will pop the alert but actually 
   let you vote.
    We should remove the “onclick” event from the buttons when the
   user is not logged in.
 * I think it’d have to look something like this:
 *     ```
       <?php
       	if ( !is_user_logged_in() ){ ?>
   
       	<script>
       	jQuery(document).ready(function() {
   
              // Remove the onclick event from the buttons
   
              jQuery(".thumbs-rating-container .thumbs-rating-up, .thumbs-rating-container .thumbs-rating-down"). removeAttr('onclick');
   
              // Pop an alert if the user clicks on it.
   
       	  jQuery(".thumbs-rating-container .thumbs-rating-up, .thumbs-rating-container .thumbs-rating-down").on("click", function(event){
   
       	  		alert('You need to be registered in order to vote!');
   
       	  });
       	});
       	</script>
   
       <?php } /* END if user is not logged in */ ?>
       ```
   
 * I haven’t tested this on a local environment. If I find sometime on Monday I’ll
   get back to you.
 * More on the removeAttr function here [http://api.jquery.com/removeattr/](http://api.jquery.com/removeattr/)
 *  [Stefan Velev](https://wordpress.org/support/users/kozzmen/)
 * (@kozzmen)
 * [12 years, 6 months ago](https://wordpress.org/support/topic/logged-in-users-only/#post-4492497)
 * Hi **Richard**!
 * Thanks a lot for the snippet! Should we use this code in the function.php or 
   in any other file?
 * Thanks!
    Stefan
 *  Plugin Author [Ricard Torres](https://wordpress.org/support/users/quicoto/)
 * (@quicoto)
 * [12 years, 6 months ago](https://wordpress.org/support/topic/logged-in-users-only/#post-4492498)
 * > Regarding the code, you should paste it in your footer.php (or similar).
 * 😉
 * PS: just tested it in my local environment, works great 🙂

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

The topic ‘Logged-In Users Only’ is closed to new replies.

 * ![](https://s.w.org/plugins/geopattern-icon/thumbs-rating_d1a77d.svg)
 * [Thumbs Rating](https://wordpress.org/plugins/thumbs-rating/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/thumbs-rating/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/thumbs-rating/)
 * [Active Topics](https://wordpress.org/support/plugin/thumbs-rating/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/thumbs-rating/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/thumbs-rating/reviews/)

 * 7 replies
 * 3 participants
 * Last reply from: [Ricard Torres](https://wordpress.org/support/users/quicoto/)
 * Last activity: [12 years, 6 months ago](https://wordpress.org/support/topic/logged-in-users-only/#post-4492498)
 * Status: resolved