-
Notifications
You must be signed in to change notification settings - Fork 800
/
facebook.js
67 lines (61 loc) · 1.97 KB
/
facebook.js
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
/**
* External dependencies
*/
import { addFilter } from '@wordpress/hooks';
import { __, _x } from '@wordpress/i18n';
/**
* Internal dependencies
*/
import { getIconColor } from '../../shared/block-icons';
const facebookVariation = {
name: 'facebook',
title: 'Facebook',
icon: {
src: 'facebook',
foreground: getIconColor(),
},
keywords: [ _x( 'social', 'block search term', 'jetpack' ) ],
description: __( 'Embed a Facebook post.', 'jetpack' ),
patterns: [ /^https?:\/\/www\.facebook.com\/.+/i ],
attributes: {
providerNameSlug: 'facebook',
previewable: false,
responsive: true,
},
};
/**
* Re-enable the Facebook embed block variation by making it appear in the inserter
* and its URL pattern parseable again.
*
* Relevant for Gutenberg >= 9.0, where the aforementioned block was deprecated*[0] because
* they do not support the oEmbed changes that Facebook is going to implement on Oct. 24th, 2020,
* and Core has currently no plans to support it.
*
* However, we do plan on keeping support for these embeds in Jetpack and WordPress.com by sending an
* access token alongside the oEmbed API request.
*
* Our goal is for this go unnoticed by our end-users, as this is only an implementation detail.
*
* *[0] https://github.com/WordPress/gutenberg/pull/24472.
*
* @param {object} settings - Block settings object.
* @param {string} name - The block name
* @returns {object} The settings for the given block with the patched variations.
*/
function reactivateFacebookEmbedBlockVariation( settings, name ) {
if ( name !== 'core/embed' || ! settings.variations ) {
return settings;
}
// Remove potentially existing variation.
const variations = settings.variations.filter(
variation => variation.name !== facebookVariation.name
);
// Add 'our' variation.
settings.variations = [ ...variations, facebookVariation ];
return settings;
}
addFilter(
'blocks.registerBlockType',
'reactivateFacebookEmbedBlockVariation',
reactivateFacebookEmbedBlockVariation
);