• Resolved zgall1

    (@zgall1)


    I have been experiencing some problems with the plugin after installing W3 Total Cache. I searched the forum and found this post but unfortunately, the linked article within the post is dead. Any ideas as to what that dead article says?

Viewing 4 replies - 1 through 4 (of 4 total)
  • I don’t use W3 so I don’t know if it works, but here’s the code that was on that webpage…

    /**
     * Get WP-PostRatings via ajax
     *
     * Useful when using cache plugins like WP Super Cache or W3 Total Cache
     * 
     */
    function ac_get_rating_ajax($postID) {
    
    	// Create nonce - security measure
    	$nonce = wp_create_nonce('display-rating');
    
    	// Placeholder HTML that will get replaced when the rating loads
    	$out .= '<div id="ac-ratings-wrap-' . $postID . '">';
    	$out .= '<p>Just a moment please...</p>';
    	$out .= '</div>';
    
    	// Script to get the rating
    	$out .= '<script type="text/javascript">';
    	$out .= 'jQuery(document).ready(function($) {';
    	$out .= '$.ajax({';
    	    $out .= 'url : "' . admin_url( 'admin-ajax.php' ) . '",';
    	    $out .= 'dataType: "jsonp", ';
    	    $out .= 'data : { "id" : "' . $postID . '", "_ajax_nonce" : "' . $nonce . '", action : "ajax_display_rating" }, ';
    	    $out .= 'success : function(response) { $("#ac-ratings-wrap-' . $postID . '").html(response.output); }';
    	  	$out .= '});';
    	$out .= '});';
    	$out .= '</script>';
    	
    	// Return it
    	return $out;
    
    }
    
    // Hook ajax function into admin-ajax.php
    add_action( 'wp_ajax_nopriv_ajax_display_rating', 'ac_ajax_display_rating' );
    add_action( 'wp_ajax_ajax_display_rating', 'ac_ajax_display_rating' );
    
    // Ajax function
    function ac_ajax_display_rating() {
    		
    	// Nonce
    	$nonce = $_GET['_ajax_nonce'];
    	if ( !wp_verify_nonce( $nonce, 'display-rating' ) ) die('Security check');
    	
    	// Check Ajax referer
    	if ( !check_ajax_referer( 'display-rating', '_ajax_nonce', false ) ) die('Security check');
    	
    	global $wpdb;
    		
    	// SQL injection protection
    	$postID = $wpdb->escape($_GET['id']);
    	if ( !is_numeric($postID) ) die('error');
    
    	// Return the rating display (not echo)
    	$out = the_ratings( 'div', $postID, false );
    	
    	// Encode and echo
    	$arr = array( 'output' => $out );
    	
    	$arr = json_encode($arr);
    	
    	echo $_GET['callback'] . '(' . $arr . ');'; // Callback is generated by jQuery
    	
    	exit();
    
    }
    Thread Starter zgall1

    (@zgall1)

    I added this code to the /plugins/wp-postratings/wp-postratings.php file and that seems to have fixed the problem. Thanks for the help.

    @zgall1 What version of WP postratings are you using? This has no effect for me.

    1. i added the code.
    2. cleared all caches.
    3. voted as guest (logged out)
    4. refreshed the page.
    5. it still shows i did not vote, but if i try to vote again it says i already voted.

    So, no effect.

    I’m surprised you say it works, maybe it did work on an older version?

    Thread Starter zgall1

    (@zgall1)

    It didn’t work long-term. I ended up having to make changes to the plugin file itself.

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘W3 Total Cache’ is closed to new replies.