WP-PostRatings compatibility fix
-
Since WP-PostRatings plugin is using PHP to display ratings data of the post, it is generally incompatible with any caching plugin.
But here is working code that solves this by simply cleaning the cache of post (and everything related) whenever the post is rated.
/** * Make WP-PostRatings compatible with the Gator Cache. */ function wp_postratings_clear_gator_cache( $rate_userid, $post_id ) { if ( $post_id && class_exists( 'WpGatorCache' ) ) { //$options = WpGatorCache::getOptions(); // NOTE: use standard WP function since the main class method getOptions() is protected $options = get_option( WpGatorCache::PREFIX . '_opts', array( 'refresh' => array('home' => true, 'archive' => true) ) ); $path_ref = ''; // purge cache of the rated post if ( null !== ($path = parse_url( get_permalink( $post_id ), PHP_URL_PATH )) ) { WpGatorCache::purgePath( $path ); } // purge cache also for the page on which the post was rated (other than single) if ( isset($_SERVER['HTTP_REFERER']) && '' !== ($path_ref = parse_url( $_SERVER['HTTP_REFERER'], PHP_URL_PATH )) && $path !== $path_ref ) { WpGatorCache::purgePath( $path_ref ); } // refresh home page if desired and not already cleared if ( $options['refresh']['home'] && $path_ref !== '/' ) { WpGatorCache::purgePath( '/' ); } // refresh taxonomy archive pages if desired and not already cleared if ( $options['refresh']['archive'] && false !== ($terms = WpGatorCache::getArchiveTerms( get_post( $post_id ) )) ) { foreach ( $terms as $term ) { if ( null !== ($path_tax = parse_url( get_term_link( $term, $term->taxonomy ), PHP_URL_PATH )) && $path_tax !== $path_ref ) { WpGatorCache::purgePath( $path_tax ); } } } // TODO: purge cache for other pages that might contain the rated post (e.g. post type archive) } } add_action( 'rate_post', 'wp_postratings_clear_gator_cache', 10, 2 );
Viewing 2 replies - 1 through 2 (of 2 total)
Viewing 2 replies - 1 through 2 (of 2 total)
- The topic ‘WP-PostRatings compatibility fix’ is closed to new replies.