Skip to content

Instantly share code, notes, and snippets.

@wgkoro
Created April 21, 2014 16:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save wgkoro/11148589 to your computer and use it in GitHub Desktop.
Save wgkoro/11148589 to your computer and use it in GitHub Desktop.
WordPressのNginx Proxy Cache Purgeプラグイン改造版。
<?php
/*
Plugin Name: Nginx Proxy Cache Purge
Plugin URI: http://wpselect.com/
Description: Purges the nginx proxy cache when you publish or update a post or page.
Version: 0.9.6
Author: John Levandowski
Author URI: http://wpselect.com/
*/
function wpselect_cache($post_id) {
#post/page purge url
$link = get_permalink($post_id);
$parse = parse_url($link);
$page_urls = array(
$post_url = 'http://'.$parse[host].'/purge'.$parse[path],
$post_url_ssl = 'https://'.$parse[host].'/purge'.$parse[path],
$post_url_sp = 'http://'.$parse[host].'/pg_s'.$parse[path],
$post_url_sp_ssl = 'https://'.$parse[host].'/pg_s'.$parse[path],
$post_url_ft = 'http://'.$parse[host].'/pg_f'.$parse[path],
$post_url_ft_ssl = 'https://'.$parse[host].'/pg_f'.$parse[path],
);
$comment_urls = array();
foreach($page_urls as $url){
$comment_urls[] = $url ."/comment-page-1";
}
#home page purge url
$home_page = home_url();
$parse_home = parse_url($home_page);
$home_page_url = $parse[scheme].'://'.$parse[host].'/purge';
if ($parse_home[path] != '') {
$home_page_url = $home_page_url.$parse_home[path].'/';
} else $home_page_url = $home_page_url.'/';
#posts page purge url
if ( get_option('show_on_front') == 'page' ) {
$posts_page = get_option('page_for_posts');
$posts_page_link = get_permalink($posts_page);
$parse_posts = parse_url($posts_page_link);
$posts_url = $parse_posts[scheme].'://'.$parse_posts[host].'/purge'.$parse_posts[path];
} ;
#feed purge url
$feed_url = $home_page_url.'feed/';
#comments feed purge url
$comments_feed_url = $home_page_url.'comments/feed/';
#array of purge urls
$etc_urls = array(
$home_page_url,
$feed_url,
$comments_feed_url,
$posts_url
);
$urls = array_merge($page_urls, $comment_urls, $etc_urls);
#remove duplicate purge urls
$urls_unique = array_unique($urls);
foreach ($urls_unique as $uri) {
wp_remote_get($uri);
};
}
add_action('edit_post', 'wpselect_cache');
function wpselect_footer() {
$content = '<!-- Page created in ';
$content .= timer_stop($display = 0, $precision = 2);
$content .= ' seconds from ';
$content .= get_num_queries();
$content .= ' queries on ';
$content .= date('m.d.y \@ H:i:s T');
$content .= ' -->';
echo $content;
}
add_action('wp_footer', 'wpselect_footer');
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment