Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

When the user clicks on the vote image, the image changes to the voted state. If the user clicks the image in the voted state again, a message pops up saying:

You Had Already Rated This Post. Post ID #X

I want it so that this message does not pop up and the 'voted' image stays as is.

Below is what I believe to be the relevant code needed to make this change. It is from lines 558-633 of wp-postratings.php. If someone can take a look and let me know what I need to change, I'd be very grateful.

### Function: Process Ratings
process_ratings();
function process_ratings() {
    global $wpdb, $user_identity, $user_ID;
    $rate = intval($_GET['rate']);
    $post_id = intval($_GET['pid']);
    if($rate > 0 && $post_id > 0 && check_allowtorate()) {      
        // Check For Bot
        $bots_useragent = array('googlebot', 'google', 'msnbot', 'ia_archiver', 'lycos', 'jeeves', 'scooter', 'fast-webcrawler', 'slurp@inktomi', 'turnitinbot', 'technorati', 'yahoo', 'findexa', 'findlinks', 'gaisbo', 'zyborg', 'surveybot', 'bloglines', 'blogsearch', 'ubsub', 'syndic8', 'userland', 'gigabot', 'become.com');
        $useragent = $_SERVER['HTTP_USER_AGENT'];
        foreach ($bots_useragent as $bot) { 
            if (stristr($useragent, $bot) !== false) {
                return;
            } 
        }
        header('Content-Type: text/html; charset='.get_option('blog_charset').'');
        postratings_textdomain();
        $rated = check_rated($post_id);
        // Check Whether Post Has Been Rated By User
        if(!$rated) {
            // Check Whether Is There A Valid Post
            $post = get_post($post_id);
            // If Valid Post Then We Rate It
            if($post && !wp_is_post_revision($post)) {
                $ratings_max = intval(get_option('postratings_max'));
                $ratings_custom = intval(get_option('postratings_customrating'));
                $ratings_value = get_option('postratings_ratingsvalue');
                $post_title = addslashes($post->post_title);
                $post_ratings = get_post_custom($post_id);
                $post_ratings_users = intval($post_ratings['ratings_users'][0]);
                $post_ratings_score = intval($post_ratings['ratings_score'][0]);    
                // Check For Ratings Lesser Than 1 And Greater Than $ratings_max
                if($rate < 1 || $rate > $ratings_max) {
                    $rate = 0;
                }
                $post_ratings_users = ($post_ratings_users+1);
                $post_ratings_score = ($post_ratings_score+intval($ratings_value[$rate-1]));
                $post_ratings_average = round($post_ratings_score/$post_ratings_users, 2);
                if (!update_post_meta($post_id, 'ratings_users', $post_ratings_users)) {
                    add_post_meta($post_id, 'ratings_users', $post_ratings_users, true);
                }
                if(!update_post_meta($post_id, 'ratings_score', $post_ratings_score)) {
                    add_post_meta($post_id, 'ratings_score', $post_ratings_score, true);
                }
                if(!update_post_meta($post_id, 'ratings_average', $post_ratings_average)) {
                    add_post_meta($post_id, 'ratings_average', $post_ratings_average, true);    
                }
                // Add Log
                if(!empty($user_identity)) {
                    $rate_user = addslashes($user_identity);
                } elseif(!empty($_COOKIE['comment_author_'.COOKIEHASH])) {
                    $rate_user = addslashes($_COOKIE['comment_author_'.COOKIEHASH]);
                } else {
                    $rate_user = __('Guest', 'wp-postratings');
                }
                $rate_userid = intval($user_ID);
                // Only Create Cookie If User Choose Logging Method 1 Or 3
                $postratings_logging_method = intval(get_option('postratings_logging_method'));
                if($postratings_logging_method == 1 || $postratings_logging_method == 3) {
                    $rate_cookie = setcookie("rated_".$post_id, $ratings_value[$rate-1], time() + 30000000, COOKIEPATH);
                }
                // Log Ratings No Matter What
                $rate_log = $wpdb->query("INSERT INTO $wpdb->ratings VALUES (0, $post_id, '$post_title', ".$ratings_value[$rate-1].",'".current_time('timestamp')."', '".get_ipaddress()."', '".@gethostbyaddr(get_ipaddress())."' ,'$rate_user', $rate_userid)");
                // Output AJAX Result
                echo the_ratings_results($post_id, $post_ratings_users, $post_ratings_score, $post_ratings_average);
                exit();
            } else {
                printf(__('Invalid Post ID. Post ID #%s.', 'wp-postratings'), $post_id);
                exit();
            } // End if($post)
        } else {
            printf(__('You Had Already Rated This Post. Post ID #%s.', 'wp-postratings'), $post_id);
            exit(); 
        }// End if(!$rated)
    } // End if($rate && $post_id && check_allowtorate())
}

EDIT: You can find the Plugin here

share|improve this question
add comment

1 Answer

up vote 0 down vote accepted

Just comment out (or change) the following line:

// printf(__('You Had Already Rated This Post. Post ID #%s.', 'wp-postratings'), $post_id);

If you just want to not have the $post_id, change the line to the following:

_e('You Had Already Rated This Post. Post ID #%s.', 'wp-postratings');

Btw: If you change a plugin and then make an update, all your changes are gone.

share|improve this answer
    
Strangely enough, I was sure this was working when I tested it yesterday (which was why I gave you the check mark) but now it's behaving strangely (ratings score isn't showing). I tried editing the line to look like this... printf (__("<img src='http://site.com/wp-content/plugins/wp-postratings/images/site/rating_1_on.p‌​ng' />", 'wp-postratings'), $post_ratings_score); to get the rating score to show up but it's not working. Any ideas? By the way, that img url is the 'voted' image. –  jwp Jul 6 '11 at 1:14
    
Take a look at printf via google. It fills placeholders like %1$s or %s. If you haven't got placeholders, you don't need it. –  kaiser Jul 6 '11 at 2:37
    
I took a look but it seems what I need to insert in there is $post_ratings_score to output the amount of votes? Is there any way to insert $post_ratings_score in that line two posts above? Or maybe just disable the voting function (make the image unclickable) after a user has voted? –  jwp Jul 6 '11 at 4:59
    
Please, read my comment extremly careful - again. It is the answer. Hint: "placeholders". Another hint: Compare the both lines in the answer after reading about printf in php.net. –  kaiser Jul 6 '11 at 13:30
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.