Created
February 8, 2017 15:59
-
-
Save mwordpress/4119e0e89ea81e267dc3da829ec1cb9b to your computer and use it in GitHub Desktop.
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
/* | |
* Function Description : Facebook Scrape | |
* Author Name : Mouad Achemli | |
* Source : https://www.mwordpress.net/force-facebook-to-update-post-thumbnail-automatically/ | |
* Inspered from : https://stackoverflow.com/a/32916433/2535061 | |
* @website : https://www.mwordpress.net/ | |
* | |
*/ | |
function scrape_open_graph($post) { | |
global $pagenow; | |
global $post; | |
// Flush W3 Total Cache | |
if (function_exists('w3tc_pgcache_flush_post')) : | |
w3tc_pgcache_flush_post($post->ID); | |
endif; | |
// Flush WP Super Cache | |
if (function_exists('wp_cache_post_change')) : | |
wp_cache_post_change($post->ID); | |
endif; | |
// get key | |
$check_key = get_post_meta($post->ID, 'opengraph-is-update' , true); | |
if (!empty($check_key)) { | |
// Nothing to do | |
} else { | |
// add meta key value for next check | |
add_post_meta($post->ID, 'opengraph-is-update', 'yes', true ); | |
// Facebook scrape | |
$url = 'https://graph.facebook.com'; | |
$param = array( | |
'id' => get_permalink( $post->ID ), | |
'scrape' => 'true', | |
'method' => 'post' | |
); | |
wp_remote_get(add_query_arg( $param, $url )); | |
} | |
} | |
add_action('publish_post', 'scrape_open_graph'); | |
add_action('save_post', 'scrape_open_graph'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment