Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Changes to support Watch, Reels, and API v15 #20

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions oembed-plus.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
/**
* Plugin Name: oEmbed Plus
* Plugin URI: https://php.watch/articles/wordpress-facebook-instagram-oembed
* Version: 1.6
* Version: 1.8.0
* Description: Adds support for embedding Facebook and Instagram posts in Block Editor and Classic Editor.
* Licence: GPLv2 or later
* Author: Ayesh Karunaratne
Expand All @@ -19,7 +19,7 @@
});

add_filter('oembed_fetch_url', static function ($provider_url): string {
if (strpos($provider_url, 'https://graph.facebook.com/v8.0/') !== 0) {
if (strpos($provider_url, 'https://graph.facebook.com/v15.0/') !== 0) {
return $provider_url;
}

Expand Down
6 changes: 3 additions & 3 deletions readme.txt
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
=== oEmbed Plus ===
Contributors: ayeshrajans
Contributors: ayeshrajans, scorpionmit01
Tags: embed, facebook, instagram, oembed
Requires at least: 4.9
Tested up to: 5.6
Stable tag: 1.6
Tested up to: 6.1.1
Stable tag: 1.8
Requires PHP: 7.1
License: GPLv2 or later
License URI: https://www.gnu.org/licenses/gpl-2.0.html
Expand Down
31 changes: 16 additions & 15 deletions src/Embed.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,21 @@

class Embed {
private static $providerPatterns = [
'#https?://www\.facebook\.com/.*/posts/.*#i' => ['https://graph.facebook.com/v8.0/oembed_post', true],
'#https?://www\.facebook\.com/.*/activity/.*#i' => ['https://graph.facebook.com/v8.0/oembed_post', true],
'#https?://www\.facebook\.com/.*/photos/.*#i' => ['https://graph.facebook.com/v8.0/oembed_post', true],
'#https?://www\.facebook\.com/photo(s/|\.php).*#i' => ['https://graph.facebook.com/v8.0/oembed_post', true],
'#https?://www\.facebook\.com/permalink\.php.*#i' => ['https://graph.facebook.com/v8.0/oembed_post', true],
'#https?://www\.facebook\.com/media/.*#i' => ['https://graph.facebook.com/v8.0/oembed_post', true],
'#https?://www\.facebook\.com/questions/.*#i' => ['https://graph.facebook.com/v8.0/oembed_post', true],
'#https?://www\.facebook\.com/notes/.*#i' => ['https://graph.facebook.com/v8.0/oembed_post', true],
'#https?://www\.facebook\.com/.*/videos/.*#i' => ['https://graph.facebook.com/v8.0/oembed_video', true],
'#https?://www\.facebook\.com/video\.php.*#i' => ['https://graph.facebook.com/v8.0/oembed_video', true],
'#https?://www\.facebook\.com/watch/?\?v=\d+#i' => ['https://graph.facebook.com/v8.0/oembed_video', true],

'#https?://(www\.)?instagr(\.am|am\.com)/(p|tv)/.*#i' => ['https://graph.facebook.com/v8.0/instagram_oembed', true],
'#https?://(www\.)?instagr(\.am|am\.com)/p/.*#i' => ['https://graph.facebook.com/v8.0/instagram_oembed', true],
'#https?://www\.facebook\.com/.*/posts/.*#i' => ['https://graph.facebook.com/v15.0/oembed_post', true],
'#https?://www\.facebook\.com/.*/activity/.*#i' => ['https://graph.facebook.com/v15.0/oembed_post', true],
'#https?://www\.facebook\.com/.*/photos/.*#i' => ['https://graph.facebook.com/v15.0/oembed_post', true],
'#https?://www\.facebook\.com/photo(s/|\/|\.php).*#i' => ['https://graph.facebook.com/v15.0/oembed_post', true],
'#https?://www\.facebook\.com/permalink\.php.*#i' => ['https://graph.facebook.com/v15.0/oembed_post', true],
'#https?://www\.facebook\.com/media/.*#i' => ['https://graph.facebook.com/v15.0/oembed_post', true],
'#https?://www\.facebook\.com/questions/.*#i' => ['https://graph.facebook.com/v15.0/oembed_post', true],
'#https?://www\.facebook\.com/notes/.*#i' => ['https://graph.facebook.com/v15.0/oembed_post', true],
'#https?://www\.facebook\.com/.*/videos/.*#i' => ['https://graph.facebook.com/v15.0/oembed_video', true],
'#https?://www\.facebook\.com/video\.php.*#i' => ['https://graph.facebook.com/v15.0/oembed_video', true],
'#https?://www\.facebook\.com/watch/?\?v=\d+#i' => ['https://graph.facebook.com/v15.0/oembed_video', true],
'#https?://(www\.)?fb\.watch/*#i'=> ['https://graph.facebook.com/v15.0/oembed_video', true],

'#https?://(www\.)?instagr(\.am|am\.com)/(p|tv|reel)/.*#i' => ['https://graph.facebook.com/v15.0/instagram_oembed', true],
'#https?://(www\.)?instagr(\.am|am\.com)/p/.*#i' => ['https://graph.facebook.com/v15.0/instagram_oembed', true],
];

private $app_id;
Expand All @@ -43,4 +44,4 @@ public function processProviderUrls(string $provider_url): string {

return $provider_url . '&access_token=' . urlencode($this->app_id . '|' . $this->app_secret);
}
}
}