-
Notifications
You must be signed in to change notification settings - Fork 7
/
oembed-plus.php
47 lines (40 loc) · 1.46 KB
/
oembed-plus.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
<?php
/**
* Plugin Name: oEmbed Plus
* Plugin URI: https://php.watch/articles/wordpress-facebook-instagram-oembed
* Version: 1.7
* Description: Adds support for embedding Facebook and Instagram posts in Block Editor and Classic Editor.
* Licence: GPLv2 or later
* Author: Ayesh Karunaratne
* Author URI: https://aye.sh/open-source
* Requires PHP: 7.1
*/
use Ayesh\OembedPlus\Embed;
use Ayesh\OembedPlus\Settings;
add_filter('oembed_providers', static function (array $providers): array {
require_once __DIR__ . '/src/Embed.php';
return Embed::registerProviders($providers);
});
add_filter('oembed_fetch_url', static function ($provider_url): string {
if (strpos($provider_url, 'https://graph.facebook.com/v8.0/') !== 0) {
return $provider_url;
}
require_once __DIR__ . '/src/Embed.php';
if (defined('OEMBED_PLUS_FACEBOOK_APP_ID') && defined('OEMBED_PLUS_FACEBOOK_SECRET')) {
$embed = new Embed(OEMBED_PLUS_FACEBOOK_APP_ID, OEMBED_PLUS_FACEBOOK_SECRET);
} elseif (
($app_id = get_option('oembed_facebook_app_id', null))
&& ($app_secret = get_option('oembed_facebook_app_secret', null))) {
$embed = new Embed($app_id, $app_secret);
} else {
return $provider_url;
}
return $embed->processProviderUrls($provider_url);
});
add_action('admin_init', static function (): void {
if (defined('OEMBED_PLUS_HIDE_ADMIN_UI') && !empty(OEMBED_PLUS_HIDE_ADMIN_UI)) {
return;
}
require_once __DIR__ . '/src/Settings.php';
Settings::runHook();
});