Skip to content

Commit

Permalink
Merge branch 'b-quick-cache-171' into 140520-RC
Browse files Browse the repository at this point in the history
  • Loading branch information
raamdev committed May 29, 2014
2 parents e62f052 + f22a291 commit 108d834
Showing 1 changed file with 27 additions and 13 deletions.
40 changes: 27 additions & 13 deletions quick-cache/quick-cache.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -916,7 +916,7 @@ public function auto_clear_cache()
* @param integer $id A WordPress post ID.
* @param bool $force Defaults to a `FALSE` value.
* Pass as TRUE if purge should be done for `draft`, `pending`,
* or `future` post statuses.
* `future`, or `trash` post statuses.
*
* @return integer Total files purged by this routine (if any).
*
Expand All @@ -940,6 +940,9 @@ public function auto_purge_post_cache($id, $force = FALSE)

$post_status = get_post_status($id); // Cache this.

if(!$post_status)
return $counter; // Nothing to do.

if($post_status === 'auto-draft')
return $counter; // Nothing to do.

Expand All @@ -952,12 +955,15 @@ public function auto_purge_post_cache($id, $force = FALSE)
if($post_status === 'future' && !$force)
return $counter; // Nothing to do.

if($post_status === 'trash' && !$force)
return $counter; // Nothing to do.

$cache_dir = $this->abspath_to($this->cache_sub_dir);
if(!is_dir($cache_dir)) return $counter; // Nothing to do.

$counter += $this->auto_purge_home_page_cache(); // If enabled and necessary.
$counter += $this->auto_purge_posts_page_cache(); // If enabled & applicable.
$counter += $this->auto_purge_post_terms_cache($id); // If enabled and applicable.
$counter += $this->auto_purge_post_terms_cache($id, $force); // If enabled and applicable.

if(!($permalink = get_permalink($id))) return $counter; // Nothing we can do.

Expand Down Expand Up @@ -996,7 +1002,7 @@ public function auto_purge_post_cache($id, $force = FALSE)

/**
* Automatically purge cache files for a particular post when transitioning
* from `publish` or `private` post status to `draft`, `future`, or `private`.
* from `publish` or `private` post status to `draft`, `future`, `private`, or `trash`.
*
* @attaches-to `transition_post_status` hook.
*
Expand All @@ -1023,9 +1029,9 @@ public function auto_purge_post_cache_transition($new_status, $old_status, $post
return $counter; // Nothing to do.

if($old_status !== 'publish' && $old_status !== 'private')
return $counter; // Nothing to do.
return $counter; // Nothing to do. We MUST be transitioning FROM one of these statuses.

if($new_status === 'draft' || $new_status === 'future' || $new_status === 'private')
if($new_status === 'draft' || $new_status === 'future' || $new_status === 'private' || $new_status === 'trash')
$counter = $this->auto_purge_post_cache($post->ID, TRUE);

return apply_filters(__METHOD__, $counter, get_defined_vars());
Expand Down Expand Up @@ -1265,6 +1271,9 @@ public function auto_purge_author_page_cache($post_ID, $post_after, $post_before
* @since 14XXXX First documented version.
*
* @param integer $id A WordPress post ID.
* @param bool $force Defaults to a `FALSE` value.
* Pass as TRUE if purge should be done for `draft`, `pending`,
* or `future` post statuses.
*
* @return integer Total files purged by this routine (if any).
*
Expand All @@ -1275,19 +1284,13 @@ public function auto_purge_author_page_cache($post_ID, $post_after, $post_before
*
* @see auto_purge_post_cache()
*/
public function auto_purge_post_terms_cache($id)
public function auto_purge_post_terms_cache($id, $force = FALSE)
{
$counter = 0; // Initialize

if(defined('DOING_AUTOSAVE') && DOING_AUTOSAVE)
return $counter; // Nothing to do.

// @TODO Add option to UI to disable clearing term cache when saving as Draft
// By default, clearing the tag cache when saving as Draft is enabled because
// the post might be going from Published -> Draft, in which case the Tag
// archive cache should be updated. Some site-owners might want to disable
// this behavior.

if(!$this->options['enable'])
return $counter; // Nothing to do.

Expand All @@ -1297,7 +1300,18 @@ public function auto_purge_post_terms_cache($id)
)
return $counter; // Nothing to do.

if(get_post_status($id) === 'auto-draft')
$post_status = get_post_status($id); // Cache this.

if($post_status === 'auto-draft')
return $counter; // Nothing to do.

if($post_status === 'draft' && !$force)
return $counter; // Nothing to do.

if($post_status === 'pending' && !$force)
return $counter; // Nothing to do.

if($post_status === 'future' && !$force)
return $counter; // Nothing to do.

$cache_dir = $this->abspath_to($this->cache_sub_dir);
Expand Down

0 comments on commit 108d834

Please sign in to comment.