Last active
August 29, 2015 14:19
-
-
Save k4zuki02h4t4/2665be868ec05dc509f9 to your computer and use it in GitHub Desktop.
記事更新時に Facebook のサイト情報のキャッシュを削除する
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 記事更新時に 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