Viewing 7 replies - 1 through 7 (of 7 total)
  • Hi needed this too! This requirement is not part of the plugin, but I’ve found an easy hack that does the job!

    1. Open the kk-star-ratings folder, and open up index.php

    2. Look for the line below. It’s the last line in the function js() (near the top). In the version of this plugin I am using (2.4), the line you want is 71:

    $this->enqueue_js('js', self::file_uri('js.min.js'), $this->ver, array('jquery'), $Params, false, true);

    3. Replace the above line with this:

    if (is_user_logged_in())
    {
       $this->enqueue_js('js', self::file_uri('js.min.js'), $this->ver, array('jquery'), $Params, false, true);
    }
    else {
          $this->enqueue_js('js', self::file_uri('js.js'), $this->ver, array('jquery'), $Params, false, true);
    };

    4. Within the kk-star-ratings folder, open up js.js

    5. Replace this function (line 129)

    $.fn.kkstarratings.click = function(obj, stars)
    {
    //////////////////.................
    }

    with this:

    $.fn.kkstarratings.click = function(obj, stars)
    	{
    
                    alert("You must be registered to vote");
    
    		return false;
    	};

    this is great. it works. thank u

    Hi,

    I tried this and it doesn’t work for me. After editing the code i still only can rate if im a subscriber or logged in as admin. Otherwise it shows me the gray stars…

    Can you give details on the “line 129” code that should be replaced, where does this “///////////////………” ends exactly?

    Is there any newer solution to this issue? Heaving all visitors to be able to rate should be a general feature, maby it will be included in the next update??

    Best Regards

    Pez

    Hey sorry just seen this…

    $.fn.kkstarratings.click = function(obj, stars)
    {
    //////////////////.................
    }

    This means to replace the entire function…so look for that line:
    $.fn.kkstarratings.click = function(obj, stars), then follow it’s opening curly brace, right the way down to its matching closing brace..

    so there’s a lot in between the two…I don’t know the line, I haven’t looked at this for a long time.

    Hi from here,

    Thx for your reply and the help.

    But i still can’t figure out till wich line i should go and replace the code. I am not that familiar with coding so i just tried to replace more an more down the “$.fn.kkstarratings.click = function(obj, stars)” line.

    The rating still dosent work when not logged in. Down below is the rest of the js.js code, many you can tell tip wich line to go?

    Thx

    $.fn.kkstarratings.click = function(obj, stars)
    	{
    
                    alert("You must be registered to vote");
    
    		return false;
    	};
    
    $.fn.kkstarratings.fetch = function(obj, stars, fallback_fuel, fallback_legend, is_fetch)
    {
    var postids = [];
    $.each(obj, function(){
    postids.push($(this).attr('data-id'));
    });
    $.ajax({
    url: $.fn.kkstarratings.options.ajaxurl,
    data: 'action='+$.fn.kkstarratings.options.func+'&id='+postids+'&stars='+stars+'&_wpnonce='+$.fn.kkstarratings.options.nonce,
    type: "post",
    dataType: "json",
    beforeSend: function(){
    $('.kksr-fuel', obj).animate({'width':'0%'}, $.fn.kkstarratings.options.fuelspeed);
    if(stars)
    {
    $('.kksr-legend', obj).fadeOut('fast', function(){
    $('.kksr-legend', obj).html('<span style="color: green">'+$.fn.kkstarratings.options.thankyou+'</span>');
    }).fadeIn('slow');
    }
    },
    success: function(response){
    $.each(obj, function(){
    var current = $(this),
    current_id = current.attr('data-id');
    if(response[current_id].success)
    {
    $.fn.kkstarratings.update(current, response[current_id].fuel+'%', response[current_id].legend, response[current_id].disable, is_fetch);
    }
    else
    {
    $.fn.kkstarratings.update(current, fallback_fuel, fallback_legend, false, is_fetch);
    }
    });
    },
    complete: function(){
    },
    error: function(e){
    $('.kksr-legend', obj).fadeOut('fast', function(){
    $('.kksr-legend', obj).html('<span style="color: red">'+$.fn.kkstarratings.options.error_msg+'</span>');
    }).fadeIn('slow', function(){
    $.fn.kkstarratings.update(obj, fallback_fuel, fallback_legend, false, is_fetch);
    });
    }
    });
    };
    
    $.fn.kkstarratings.options = {
    ajaxurl   : bhittani_plugin_kksr_js.ajaxurl,
    func      : bhittani_plugin_kksr_js.func,
    nonce     : bhittani_plugin_kksr_js.nonce,
    grs       : bhittani_plugin_kksr_js.grs,
    tooltip   : bhittani_plugin_kksr_js.tooltip,
    tooltips  : bhittani_plugin_kksr_js.tooltips,
    msg       : bhittani_plugin_kksr_js.msg,
    fuelspeed : bhittani_plugin_kksr_js.fuelspeed,
    thankyou  : bhittani_plugin_kksr_js.thankyou,
    error_msg : bhittani_plugin_kksr_js.error_msg
    };
    
    })(jQuery, window, document);
    
    jQuery(document).ready( function($){
    $('.kk-star-ratings').kkstarratings();
    });

    alert not working..

    This code will alert guests that they must be logged in in order to vote.

    $.fn.kkstarratings.click = function(obj, stars)
    	{
    
                    alert("Pentru a putea vota este necesar sa te autentifici!");
    
    		return false;
    	};

    The OP asked for a solution which will allow anyone, including guests, to vote. That js does not do that..

    The solution is to alter the first file only and leave the js file as it is.

Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘can only vote if logged in’ is closed to new replies.