From 88114420cb5b14204e68b0446c26673cc1e11562 Mon Sep 17 00:00:00 2001
From: Erick Hitter <ehitter@gmail.com>
Date: Tue, 25 Feb 2014 21:51:20 -0800
Subject: [PATCH] Consolidate plugin's settings and cache clearing functions
 into a single file and rename for clarity. Given how small the files are,
 there's no sense in splitting.

---
 wp-redis-cache/cache.php                      | 73 -------------------
 .../{options.php => wp-redis-cache.php}       | 70 +++++++++++++++++-
 2 files changed, 69 insertions(+), 74 deletions(-)
 delete mode 100644 wp-redis-cache/cache.php
 rename wp-redis-cache/{options.php => wp-redis-cache.php} (77%)

diff --git a/wp-redis-cache/cache.php b/wp-redis-cache/cache.php
deleted file mode 100644
index 31b70a1..0000000
--- a/wp-redis-cache/cache.php
+++ /dev/null
@@ -1,73 +0,0 @@
-<?php
-
-add_action('transition_post_status', 'refresh_wp_redis_cache',10,3);
-add_action('wp_ajax_clear_wp_redis_cache', 'clear_wp_redis_cache');
-add_action( 'admin_footer', 'clear_wp_redis_cache_javascript' );
-//clears the cache after you update a post
-function refresh_wp_redis_cache( $new, $old, $post )
-{
-
-	if($new == "publish")
-	{
-		$permalink = get_permalink( $post->ID );
-
-		// aaronstpierre: this needs to be include_once so as not to cauase a redeclaration error
-		include_once("predis5.2.php");  //we need this to use Redis inside of PHP
-		$redis = new Predis_Client();
-
-		$redis_key = md5($permalink);
-		$redis->del($redis_key);
-
-		//refresh the front page
-		$frontPage = get_home_url() . "/";
-		$redis_key = md5($frontPage);
-		$redis->del($redis_key);
-	}
-}
-
-// clears the whole cache
-function clear_wp_redis_cache()
-{
-	include_once("predis5.2.php"); //we need this to use Redis inside of PHP
-	$args = array( 'post_type' => 'any', 'posts_per_page' => -1);
-	$wp_query = new WP_Query( $args); // to get all Posts
-	$redis = new Predis_Client();
-	// Loop all posts and clear the cache
-	$i = 0;
-	while ( $wp_query->have_posts() ) : $wp_query->the_post();
-		$permalink = get_permalink();
-
-		$redis_key = md5($permalink);
-		if (($redis->exists($redis_key)) == true ) {
-			$redis->del($redis_key);
-			$i++;
-		}
-
-
-	endwhile;
-
-	echo $i++." of " . $wp_query  -> found_posts . " posts was cleared in cache";
-	die();
-}
-
-function clear_wp_redis_cache_javascript() {
-?>
-<script type="text/javascript" >
-jQuery(document).ready(function($) {
-
-	jQuery('#WPRedisClearCache').click(function(){
-		var data = {
-			action: 'clear_wp_redis_cache',
-		};
-
-		// since 2.8 ajaxurl is always defined in the admin header and points to admin-ajax.php
-		$.post(ajaxurl, data, function(response) {
-			alert(response);
-		});
-	});
-});
-</script>
-<?php
-}
-?>
-
diff --git a/wp-redis-cache/options.php b/wp-redis-cache/wp-redis-cache.php
similarity index 77%
rename from wp-redis-cache/options.php
rename to wp-redis-cache/wp-redis-cache.php
index 6bf7dc5..7a3d804 100644
--- a/wp-redis-cache/options.php
+++ b/wp-redis-cache/wp-redis-cache.php
@@ -152,4 +152,72 @@ function edit_redis_options() {
 	<?php
 }
 
-include('cache.php');
\ No newline at end of file
+add_action('transition_post_status', 'refresh_wp_redis_cache',10,3);
+add_action('wp_ajax_clear_wp_redis_cache', 'clear_wp_redis_cache');
+add_action( 'admin_footer', 'clear_wp_redis_cache_javascript' );
+//clears the cache after you update a post
+function refresh_wp_redis_cache( $new, $old, $post )
+{
+
+	if($new == "publish")
+	{
+		$permalink = get_permalink( $post->ID );
+
+		// aaronstpierre: this needs to be include_once so as not to cauase a redeclaration error
+		include_once("predis5.2.php");  //we need this to use Redis inside of PHP
+		$redis = new Predis_Client();
+
+		$redis_key = md5($permalink);
+		$redis->del($redis_key);
+
+		//refresh the front page
+		$frontPage = get_home_url() . "/";
+		$redis_key = md5($frontPage);
+		$redis->del($redis_key);
+	}
+}
+
+// clears the whole cache
+function clear_wp_redis_cache()
+{
+	include_once("predis5.2.php"); //we need this to use Redis inside of PHP
+	$args = array( 'post_type' => 'any', 'posts_per_page' => -1);
+	$wp_query = new WP_Query( $args); // to get all Posts
+	$redis = new Predis_Client();
+	// Loop all posts and clear the cache
+	$i = 0;
+	while ( $wp_query->have_posts() ) : $wp_query->the_post();
+		$permalink = get_permalink();
+
+		$redis_key = md5($permalink);
+		if (($redis->exists($redis_key)) == true ) {
+			$redis->del($redis_key);
+			$i++;
+		}
+
+
+	endwhile;
+
+	echo $i++." of " . $wp_query  -> found_posts . " posts was cleared in cache";
+	die();
+}
+
+function clear_wp_redis_cache_javascript() {
+?>
+<script type="text/javascript" >
+jQuery(document).ready(function($) {
+
+	jQuery('#WPRedisClearCache').click(function(){
+		var data = {
+			action: 'clear_wp_redis_cache',
+		};
+
+		// since 2.8 ajaxurl is always defined in the admin header and points to admin-ajax.php
+		$.post(ajaxurl, data, function(response) {
+			alert(response);
+		});
+	});
+});
+</script>
+<?php
+}
-- 
GitLab