Viewing 7 replies - 1 through 7 (of 7 total)
  • Plugin Author Ricard Torres

    (@quicoto)

    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!

    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

    (@quicoto)

    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

    (@antonhh)

    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

    (@quicoto)

    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 https://api.jquery.com/removeattr/

    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

    (@quicoto)

    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.