All Good Things Must Come To An End

As you all know, I have been doing WordPress plugins and supporting it for the past 6 years. These 6 years of my life, I have been through my polytechnic education, my national service as well as my university education.

I just graduated from university in December 2009 and have been looking for full-time jobs. I am offered a full-time job and will be starting work on 1st February 2010.

I regret to say that I am NOT ABLE to provide support for my plugins anymore due to my full-time job commitment. I will leave this forum open and let the community help one another.

However, I WILL still update my plugins whenever I can and you still can report bugs to me via email and I will try to fix it.


Author Topic: Making WP-PostRatings 1.50 Work With SuperCache Properly  (Read 3263 times)

0 Members and 1 Guest are viewing this topic.

Offline lokos

  • Newbie
  • *
  • Posts: 2
    • View Profile
Hi, Here is how you can make wp-postrating to always show the updated rating with supercache installed

The problem you describe above happen because when you vote your rating refresh via AJAX so you see the updated view count immediately but once the page is refreshed supercache show the cache page with the old rating.
The solution: Load the rating with AJAX

1. Add the AJAX function to get the rating into your theme's function.php file
Code: [Select]
function get_rating_ajax($id) {
$nonce = wp_create_nonce('my_rating');
?>

<div id="ratings-wrap-<?php echo $id;?>">
<img src="/wp-content/uploads/images/loading_rating.gif" />
</div>

<script type="text/javascript">
jQuery(document).ready(function($){
  $.ajax({
    type : "GET",
    url : "<?php echo get_option('home'); ?>/wp-content/plugins/wp-postratings/wp-postratings.php",
    data : { wp_ajaxaction : "jquery", post_id : <?php echo $id?> , _ajax_check : "<?php echo $nonce;?>"},
    success : function(response){$("#ratings-wrap-<?php echo $id?>").html(response);}
  });
});
</script><?php
}
?>


2. Add the function to return the rating via ajax on the wp-postrating.php file
Look for the line:
Code: [Select]
$wpdb->ratings = $wpdb->prefix.'ratings';and copy this code below it:
Code: [Select]
if ( $_GET['wp_ajaxaction'] == 'jquery' ) {

$nonce =$_REQUEST['_ajax_check'];
if (! wp_verify_nonce($nonce, 'my_rating') ) die('Security check');

$id = $wpdb->escape($_GET['post_id']);
the_ratings('div',$id);
    exit();
}
3. Use it.

Replace your normal <?php the_rating() ?> function in your theme for  <?php get_rating_ajax ($post->ID) ?>

Make sure jquery is on the page where you are using this.
You can update this <img src="/wp-content/uploads/images/loading_rating.gif" /> for the path of the loading image you want to show while the rating is being updated.
« Last Edit: 06 October 2009, 07:32 by GaMerZ »

Offline GaMerZ

  • lesterchan.net
  • Administrator
  • *****
  • Posts: 11,536
    • View Profile
  • WordPress Version: WordPress 2.9.x
  • Theme Name: lesterchan.net v3.4
Re: Making WP-PostRatings 1.50 Work With SuperCache Properly
« Reply #1 on: 25 September 2009, 16:46 »
thanks, stickied.

++ lesterchan.net - Lester Chan's Website

I regret to say that I am not able to provide support for my plugins anymore due to my full-time job commitment. I will leave this forum open and let the community help one another.

Offline Need_Help

  • Newbie
  • *
  • Posts: 9
    • View Profile
Re: Making WP-PostRatings 1.50 Work With SuperCache Properly
« Reply #2 on: 06 October 2009, 06:42 »
In which file and where shall I put the codes into?

Thanks.

Offline GaMerZ

  • lesterchan.net
  • Administrator
  • *****
  • Posts: 11,536
    • View Profile
  • WordPress Version: WordPress 2.9.x
  • Theme Name: lesterchan.net v3.4
Re: Making WP-PostRatings 1.50 Work With SuperCache Properly
« Reply #3 on: 06 October 2009, 07:28 »
Read the first post carefully, it is all stated there.

Modified the post to make it more obvious

++ lesterchan.net - Lester Chan's Website

I regret to say that I am not able to provide support for my plugins anymore due to my full-time job commitment. I will leave this forum open and let the community help one another.

Offline Need_Help

  • Newbie
  • *
  • Posts: 9
    • View Profile
Re: Making WP-PostRatings 1.50 Work With SuperCache Properly
« Reply #4 on: 06 October 2009, 07:33 »
Thanks for making it clearer. At first, he just stated function.php (which I couldn't find in the plugin folder)

Thanks.

Offline Need_Help

  • Newbie
  • *
  • Posts: 9
    • View Profile
Re: Making WP-PostRatings 1.50 Work With SuperCache Properly
« Reply #5 on: 07 October 2009, 03:07 »
<div id="ratings-wrap-<?php echo $id;?>">
<img src="/wp-content/uploads/images/loading_rating.gif" />
</div>

If you want your site to be XHTML valid, the line in bold should include the alt="" tag, like :
<img src="/wp-content/uploads/images/loading_rating.gif" alt="Loading"/>

Thanks.

PS : Of course, you may put whatever you want between the " mark, or even leave it blank.

Offline japhy

  • Newbie
  • *
  • Posts: 1
    • View Profile
Re: Making WP-PostRatings 1.50 Work With SuperCache Properly
« Reply #6 on: 22 October 2009, 21:23 »
Hi!

I just tried your fix. But I got this error message:

arning: Cannot modify header information - headers already sent by (output started at .../functions.php:276) in .../wp-content/plugins/wp-postratings/wp-postratings.php on line 580

Warning: Cannot modify header information - headers already sent by (output started at .../functions.php:276) in .../wp-content/plugins/wp-postratings/wp-postratings.php on line 624

Any idea what I'm doing wrong?

Thank you!

regards,
Japhy

Offline GaMerZ

  • lesterchan.net
  • Administrator
  • *****
  • Posts: 11,536
    • View Profile
  • WordPress Version: WordPress 2.9.x
  • Theme Name: lesterchan.net v3.4
Re: Making WP-PostRatings 1.50 Work With SuperCache Properly
« Reply #7 on: 23 October 2009, 06:02 »
Ensure that you do not have any white spaces after the
Code: [Select]
?>

++ lesterchan.net - Lester Chan's Website

I regret to say that I am not able to provide support for my plugins anymore due to my full-time job commitment. I will leave this forum open and let the community help one another.

Offline eilrax

  • Newbie
  • *
  • Posts: 2
    • View Profile
Re: Making WP-PostRatings 1.50 Work With SuperCache Properly
« Reply #8 on: 27 October 2009, 10:47 »
not work for me :s

in post

"Fatal error: Call to undefined function get_ip_address()"

Offline GaMerZ

  • lesterchan.net
  • Administrator
  • *****
  • Posts: 11,536
    • View Profile
  • WordPress Version: WordPress 2.9.x
  • Theme Name: lesterchan.net v3.4
Re: Making WP-PostRatings 1.50 Work With SuperCache Properly
« Reply #9 on: 27 October 2009, 11:00 »
Your error pasted has nothing to do with this. get_ip_address is not used. It is get_ipaddress() and not get_ip_address();

++ lesterchan.net - Lester Chan's Website

I regret to say that I am not able to provide support for my plugins anymore due to my full-time job commitment. I will leave this forum open and let the community help one another.

Offline eilrax

  • Newbie
  • *
  • Posts: 2
    • View Profile
Re: Making WP-PostRatings 1.50 Work With SuperCache Properly
« Reply #10 on: 27 October 2009, 11:21 »
sorry xd

Fatal error: Call to undefined function get_ipaddress() in /home/admin/domains/.../public_html/wp-content/plugins/wp-postratings/wp-postratings.php on line 310


Offline GaMerZ

  • lesterchan.net
  • Administrator
  • *****
  • Posts: 11,536
    • View Profile
  • WordPress Version: WordPress 2.9.x
  • Theme Name: lesterchan.net v3.4
Re: Making WP-PostRatings 1.50 Work With SuperCache Properly
« Reply #11 on: 27 October 2009, 11:38 »
I am guessing you did not place the code properly. get_ipaddress() is defined on line 416. Re-download wp-postratings and try again or you can drop lokos an email or private message to send you the modified file.

++ lesterchan.net - Lester Chan's Website

I regret to say that I am not able to provide support for my plugins anymore due to my full-time job commitment. I will leave this forum open and let the community help one another.

Offline chuy ban

  • Newbie
  • *
  • Posts: 4
    • View Profile
Re: Making WP-PostRatings 1.50 Work With SuperCache Properly
« Reply #12 on: 14 November 2009, 17:36 »
Thanks for the code, it works great for me just like magic.

But there is a problem for rating that use embed other post ratings such as using [ratings id="1"] or [ratings id="1" results="true"].
The ratings still don't show real time result. It shows cached result instead.

It would be great and helpful, if you can make this work as well.

Offline chuy ban

  • Newbie
  • *
  • Posts: 4
    • View Profile
Re: Making WP-PostRatings 1.50 Work With SuperCache Properly
« Reply #13 on: 24 November 2009, 13:38 »
Hi GaMerZ and Everyone,

Any ideas about the problem for rating that use embed other post ratings such as using [ratings id="1"] or [ratings id="1" results="true"]. with SuperCache enable.
The ratings still don't show real time result. It shows cached result instead.

It would be great and helpful, if you can make this work as well.

Thanks!

Offline GaMerZ

  • lesterchan.net
  • Administrator
  • *****
  • Posts: 11,536
    • View Profile
  • WordPress Version: WordPress 2.9.x
  • Theme Name: lesterchan.net v3.4
Re: Making WP-PostRatings 1.50 Work With SuperCache Properly
« Reply #14 on: 24 November 2009, 14:11 »
I am not using SuperCache but I am guessing that the shortcode will not work with it. because the shortcode will be translated to normal ratings when the supercache parse it, it will be cache. And also by embedding other ratings ID into the post containing ratings will screw up the ID making it not work as well.

++ lesterchan.net - Lester Chan's Website

I regret to say that I am not able to provide support for my plugins anymore due to my full-time job commitment. I will leave this forum open and let the community help one another.