Skip to content

Instantly share code, notes, and snippets.

@k4zuki02h4t4
Last active August 29, 2015 14:19
Show Gist options
  • Save k4zuki02h4t4/2665be868ec05dc509f9 to your computer and use it in GitHub Desktop.
Save k4zuki02h4t4/2665be868ec05dc509f9 to your computer and use it in GitHub Desktop.
記事更新時に Facebook のサイト情報のキャッシュを削除する
/**
* 記事更新時に Facebook のサイト情報のキャッシュを削除する
*
* @link http://2inc.org/blog/2014/11/11/4485/
*/
class fb_ogp_cache_clear {
private $api = 'https://graph.facebook.com?id=%s&scrape=true';
static function init() {
static $instance = false;
if( ! $instance )
$instance = new fb_ogp_cache_clear;
return $instance;
}
public function __construct() {
add_action( 'transition_post_status', array( $this, 'clear' ), 10, 3 );
}
public function clear( $new_status, $old_status, $post ) {
if ( $new_status === 'publish' )
$t = wp_remote_post( sprintf( $this->api, get_permalink( $post->ID ) ) );
}
}
add_action( 'init', array( 'fb_ogp_cache_clear', 'init' ) );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment