最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

Facebook embeds fixing with functions.php

programmeradmin1浏览0评论

I use this code to solve the new Instagram embeds problem on my old Wordpress site:

add_filter('oembed_providers', 'fr_replace_deprecated_instagram_api', 10, 1);
function fr_replace_deprecated_instagram_api($providers) {
  unset($providers['#https?://(www\.)?instagr(\.am|am\)/(p|tv)/.*#i']);
  $providers['#https?://(www\.)?instagr(\.am|am\)/(p|tv)/.*#i'] = array('.0/instagram_oembed', true);
  return $providers;
}

// You need to create a developer account for Facebook's API and grant permission for the "OEmbed" App.
define('FR_FACEBOOK_APP_ID', 'APP_ID');
define('FR_FACEBOOK_CLIENT_SECRET', 'CLIENT_SECRET');
define('FR_FACEBOOK_TOKEN_URI', '=' . FR_FACEBOOK_APP_ID . '&client_secret=' . FR_FACEBOOK_CLIENT_SECRET . '&grant_type=client_credentials');

add_filter('oembed_fetch_url', 'fr_add_facebook_access_token', 10, 3);
function fr_add_facebook_access_token($provider, $url, $args) {
  if (strpos($provider, 'instagram_oembed') !== -1) {
    $response = @file_get_contents(FR_FACEBOOK_TOKEN_URI);
    if (!$response) {
      trigger_error("Couldn't retrieve an access token for Instagram OEmbed API by Facebook. Check your App ID, Client Secret & the permissions in the Facebook Developer Dashboard.", E_USER_WARNING);
      return $provider;
    }
    $response = json_decode($response);
    $access_token = $response->access_token;
    $provider .= '&access_token=' . $access_token;
  }
  return $provider;
}

Anybody know something similar code to solve the Facebook embeds problem?

发布评论

评论列表(0)

  1. 暂无评论