KK Rating user can vote after login and also add in comment form

Posted: May 19, 2015 in Uncategorized

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;


if for subscribers you mean logged in users the task is quite simple:

1) in kk settings turn off visualization on any post, page, archive or category.

2) open your template files where you want to show the rating, example: single.php for single posts

3) find the place in template where you want the ratings to be and paste this snippet:

if ( is_user_logged_in() ) {
if(function_exists("kk_star_ratings")) : echo kk_star_ratings($pid);
} else {
// use the else to show a message to non logged users
echo '<p>To rate this post you Must Login</p>';

4) Done: publish your modified file 🙂


If you need to put ratings along with new comment form, and you are restricting comments to logged in users, you can put the kk_star_ratings($pid) call inside the comment_form args.

It’s quite simple:

1) restrict comments to logged in users in wp-admin->settings->discussion

2) open your comments.php file (or whatever file your theme uses as comments temmplate)

3) find this line:

<?php comment_form(); ?>

3) replace it with this code:

// put the kk_star_ratings call into a variable
$ratingstars = (function_exists("kk_star_ratings") ? kk_star_ratings($pid): '');
// declare custom comment_form args
$comments_args = array(
// here you replace the "Text or HTML to be displayed after the set of comment fields" and you show the ratings
  'comment_notes_after' =>  $ratingstars

This is to achieve something like this: http://goo.gl/b68yH
here you will see the kk rating stars in the comment form box, shown only to logged users.
Here I’ve changed also Form title and the send button title. If you want to change other stuff on your comment form just have a look at this page: http://codex.wordpress.org/Function_Reference/comment_form
and add other arguments along with the ‘comment_notes_after’ in the previous snippet

I hope it helps 🙂


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s