ayesh / wordpress-oembed-plus Goto Github PK
View Code? Open in Web Editor NEWWordPress plugin to support Facebook and Instagram oEmbed embeds
Home Page: https://php.watch/articles/wordpress-facebook-instagram-oembed
WordPress plugin to support Facebook and Instagram oEmbed embeds
Home Page: https://php.watch/articles/wordpress-facebook-instagram-oembed
=== oEmbed Plus === Contributors: ayeshrajans Tags: embed, facebook, instagram, oembed Requires at least: 4.9 Tested up to: 5.6 Stable tag: 1.7 Requires PHP: 7.1 License: GPLv2 or later License URI: https://www.gnu.org/licenses/gpl-2.0.html Adds support for embedding Facebook and Instagram posts in Block Editor (Gutenberg) and Classic Editor. == Description == Adds support for embedding Facebook and Instagram posts in Block Editor (Gutenberg) and Classic Editor. This feature was removed in WordPress core due to deprecation of legacy APIs WordPress core used. Prior to WordPress 5.5.1, WordPress had support to embed Instagram and Facebook photos, videos, notes, quizes, etc in posts created with Block Editor and Classic Editor. However, Facebook removed this legacy API in October 2020, and this plugin implements the new APIs to bring back support for Facebook and Instagram content embedding. Note that you will need to register a Facebook developer account and create an app to get API credentials that this plugin uses. There is no coding necessary, but an API key needs to be created and set for the plugin. Detailed setup instructions are available in [oEmbed Plus guide at PHP.Watch](https://php.watch/articles/wordpress-facebook-instagram-oembed) == Frequently Asked Questions == = WordPress already supports this feature in core = Yes, but only in versions prior to 5.5.1, and it used a legacy API that stopped working after October 24, 2020. See [#50861](https://core.trac.wordpress.org/ticket/50861) for more information. = This version requires PHP 7.1 = Yes, this plugin requires PHP 7.1 or later. That is by design. = Can you add support for service X? = Probably not. This plugin is intended to bring back functionality the WordPress core eventually drops. = How do I set the API ID and secret? = Go to Settings -> Writing, and you will see a section to enter Facebook App ID and Secret. Alternately, you can set the Facebook App ID and secret in the `wp-config.php` file. If they are set in the `wp-config.php` file, the settings form in Settings -> Writing section will be disabled. To enter the Facebook App ID and secret, update the `wp-config.php` file in root of your WordPress installation, and append the following lines: ` define('OEMBED_PLUS_FACEBOOK_APP_ID', '<App ID Here>'); define('OEMBED_PLUS_FACEBOOK_SECRET', '<Secret Here>'); ` = Optionally hide the admin UI= It is possible to completely hide the administration form added by this plugin in Admin → Settings → Writing page. This can be helpful if you set the configuration values in the `wp-config.php` file, and keep the administration UI minimal. To hide the administration form, update the `wp-config.php` file with an extra line: ` define('OEMBED_PLUS_HIDE_ADMIN_UI', true); ` == Screenshots == 1. Plugin configuration (Admin → Settings → Writing) 2. Registering a new Facebook App 3. Example embedded content == Changelog == **1.0** - Initial release. **1.1** - Fixes a bug in Instagram oEmbed URL endpoint check. - Minor improvements in the Facebook App ID field validations. **1.2** - Add `https://www.facebook.com/watch/?v=<ID>` URL pattern to supported video URL patterns. - Allow setting Facebook App ID and secret with a [constant in `wp-config.php` file](https://php.watch/articles/wordpress-facebook-instagram-oembed#wp-config). **1.4** - Add an option to completely hide the admin UI by setting `OEMBED_PLUS_HIDE_ADMIN_UI` PHP constant in `wp-config.php` file. - Code styling clean-up. - The minimum required PHP version is changed to 7.1 from PHP 7.3. It's strongly suggested to use more recent and supported PHP versions nonetheless. **1.5** - Updates to the readme file to make it more clear that this plugin supports both Classic Editor and Block Editor. **1.6** - Updated the plugin minimum WordPress core requirement to 4.9, along with relevant compatibility changes. The plugin works on all WordPress versions from 4.9 through 5.6 and up. **1.7** - Maintenance of this plugin was on a hiatus, but with this version, it is back to active development. - Fixes a few bugs that caused failed embeds. - Updated instructions to match changes in Facebook Developer program.
I know the app key/secret need to be saved into wp_options, but it strikes me as less secure that they are visible in cleartext. Should/could those fields (at least the secret) be marked as a password in some way in settings so it's not visible from someone seeing the screen?
There are two instances of values from the Database needing to be escaped:
https://github.com/Ayesh/WordPress-oEmbed-Facebook-Instagram/blob/master/src/Settings.php#L64
https://github.com/Ayesh/WordPress-oEmbed-Facebook-Instagram/blob/master/src/Settings.php#L68
I would wrap esc_attr()
around the option.
Facebook alerted us that oEmbed Read is replacing oEmbed with a new app review need, amongst other changes.
Is the plugin ready for this or any updates needed?
Hi @Ayesh,
We're considering recommending this plugin for customers of WordPress VIP and in my review I found a problem with Instagram Embeds:
On this line:
https://github.com/Ayesh/WordPress-oEmbed-Facebook-Instagram/blob/master/oembed-plus.php#L22
There's a check for https://graph.facebook.com/v8.0/oembed_
and since Instagram is using the instagram_oembed
the check fails and so the Instagram Embeds never load.
I think adding a check for the Instagram embed would fix this:
if (strpos($provider_url, 'https://graph.facebook.com/v8.0/oembed_') === false
|| strpos($provider_url, 'https://graph.facebook.com/v8.0/instagram_oembed') === false) {
return $provider_url;
}
Hi,
I tried to set up the plugin/create a FB app to get the keys as instruced here, but I could not add the oEmbed Product. Has this changed on Facebook's side over the years?
Thanks,
Alex
Firstly thanks for your plugin!
Updated to wordpress 6.0 yesterday and since haven’t been able to embed any facebook videos.
Not sure if this plugin is still maintained but has really useful functionality.
Wasn't sure if it was best to post here or here, so have done both.
Thanks in advance,
Sometimes embeds from Instagram and Facebook fail without a clear reason.
When checking the postmeta, there is no html in the postmeta, just {{unknown}}
. When deleting all the _oembed_*
values from the postmeta and trying again, the embed sometimes works and valid html is showing in the postmeta.
I suspect the API is returning an unknown response, but this is not visible anywhere. Can you give some guidance on how to debug this? For example enable a 'debug' mode that shows the api response. Thanks!
Hey there!
My instagram oembed is working with your plugin + acf but facebook posts are not showing up.
e.g. '#https?://fb.watch/*#i'=> ['https://graph.facebook.com/v8.0/oembed_video', true],
Not a huge deal but wanted to make a note! :)
In this function:
https://github.com/Ayesh/WordPress-oEmbed-Facebook-Instagram/blob/master/src/Settings.php#L40-L45
The sanitization filter could be prone to human error.
For example, the value of AAA1938BBBB914979
would be sanitized as 1938914979
which is an integer, but maybe not what the user was expecting.
Even though most browsers are pretty good about validating the input first, it might be better to cast a type to the string like this:
return (int) $string;
Instead of:
return filter_var($string, FILTER_SANITIZE_NUMBER_INT);
That way the return value would be 0
, and the user would see that something they entered was not right.
.. so that each subsite can enter their own credentials.
Plugin does not work to embed a Facebook page in a Wordpress site. More importantly, the documentation at https://php.watch/articles/wordpress-facebook-instagram-oembed is not (now) correct. It claims "the new self-plug WordPress plugin oEmbed Plus brings back the support for Facebook and Instagram oEmbed using Facebook's new API endpoints" but if you go to Facebook, you learn that there is no longer an oembed option from Facebook "The oEmbed product has been replaced with the oEmbed Read feature. If you implemented the oEmbed product before June 8, 2021, you have until September 7, 2021 to complete App Review for the oEmbed Read feature. If you have not been approved for the oEmbed Read feature by September 7, 2021, your oEmbed implementations will fail to load."
The information on what to do to setup a Facebook App is incorrect - there is no option for "For Everything Else" and of course, no "Add Oembed" or even "Add OembedRead" option. No idea if there is any way to correct, anyone else have an idea?
Is there a way to set the App ID and App Secret network-wide on a Multisite installation? There seems to be no Settings > Writing network admin screen. I tried setting up in wp-config.php
, but upon testing, it's not working on individual sites on the network.
Thanks for the plugin.
If I attempt to embed a video with a url of the format https://www.facebook.com/watch/?v=xxx , it does not work. (It didn't work in the past either).
Can you please add this as a valid provider - it's valid on Facebook's side, just not matched in WordPress.
@Ayesh in @mikeyarce's code sample in issue #1 , the code is:
(strpos($provider_url, 'https://graph.facebook.com/v8.0/oembed_') === false || strpos($provider_url, 'https://graph.facebook.com/v8.0/instagram_oembed') === false)
with both being ===
but in the actual plugin (see 87fc123#diff-54825a668a335a7e9908af19652bb263R24 ), it is:
strpos($provider_url, 'https://graph.facebook.com/v8.0/oembed_') === false || strpos($provider_url, 'https://graph.facebook.com/v8.0/instagram_oembed') !== false
with the === for oembed, and !== for instagram.
Is this intentionally different? Just want to confirm which is correct.
If you try to embed an Instagram Reels URL (like https://www.instagram.com/reel/CTuakCmAhU5/) you get an error message "Sorry, this content could not be embedded." but if you do a traditional Instagram post it works fine.
The AJAX call specifically returns this value: "{"code":"oembed_invalid_url","message":"Not Found","data":{"status":404}}"
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.