Skip to content

Commit

Permalink
Merge branch '64383' into shakib-latest
Browse files Browse the repository at this point in the history
  • Loading branch information
shuvo7670 committed Jul 14, 2024
2 parents 2eade05 + 8f4824b commit d243a3d
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions includes/Social/Facebook.php
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,12 @@ public function remote_post($app_id, $app_secret, $app_access_token, $type, $ID,

$linkData = $this->get_share_content_args($post_id);

// Refresh Facebook cache before sharing
$post_url = get_permalink($post_id);

if( ( get_post_meta( $post_id, $count_meta_key, true ) ) > 0 ) {
$this->refresh_facebook_cache($app_id, $app_secret, $post_url);
}

// group api
if ($type === 'group') {
Expand Down Expand Up @@ -335,6 +341,19 @@ public function remote_post($app_id, $app_secret, $app_access_token, $type, $ID,
return;
}


public function refresh_facebook_cache($app_id, $app_secret, $url) {
$access_token = $app_id . '|' . $app_secret;
$api_url = 'https://graph.facebook.com/v20.0';
$endpoint = $api_url . '?id=' . urlencode($url) . '&scrape=true&access_token=' . $access_token;
$response = wp_remote_post($endpoint);
if (is_wp_error($response)) {
error_log('Error refreshing Facebook cache: ' . $response->get_error_message());
} else {
error_log('Facebook cache refreshed for URL: ' . $url);
}
}

/**
* Schedule Republish social share hook
* @since 2.5.0
Expand Down

0 comments on commit d243a3d

Please sign in to comment.