-
Notifications
You must be signed in to change notification settings - Fork 803
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Blocks: Add Facebook and Instagram Embed block variations (#17192)
Co-authored-by: Jeremy Herve <[email protected]>
- Loading branch information
Showing
7 changed files
with
157 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,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 | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
|
||
/** | ||
* Internal dependencies | ||
*/ | ||
import './variations'; | ||
import './facebook'; | ||
import './instagram'; | ||
import './loom'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
/** | ||
* External dependencies | ||
*/ | ||
import { addFilter } from '@wordpress/hooks'; | ||
import { __, _x } from '@wordpress/i18n'; | ||
|
||
/** | ||
* Internal dependencies | ||
*/ | ||
import { getIconColor } from '../../shared/block-icons'; | ||
import isActive from '../../shared/is-active'; | ||
|
||
const instagramVariation = { | ||
name: 'instagram', | ||
title: 'Instagram', | ||
icon: { | ||
src: 'instagram', | ||
foreground: getIconColor(), | ||
}, | ||
keywords: [ | ||
_x( 'image', 'block search term', 'jetpack' ), | ||
_x( 'social', 'block search term', 'jetpack' ), | ||
], | ||
description: __( 'Embed an Instagram post.', 'jetpack' ), | ||
patterns: [ /^https?:\/\/(www\.)?instagr(\.am|am\.com)\/.+/i ], | ||
attributes: { providerNameSlug: 'instagram', responsive: true }, | ||
}; | ||
|
||
/** | ||
* Re-enable the Instagram 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 reactivateInstagramEmbedBlockVariation( settings, name ) { | ||
if ( name !== 'core/embed' || ! settings.variations || ! isActive() ) { | ||
return settings; | ||
} | ||
|
||
// Remove potentially existing variation. | ||
const variations = settings.variations.filter( | ||
variation => variation.name !== instagramVariation.name | ||
); | ||
// Add 'our' variation. | ||
settings.variations = [ ...variations, instagramVariation ]; | ||
|
||
return settings; | ||
} | ||
|
||
addFilter( | ||
'blocks.registerBlockType', | ||
'reactivateInstagramEmbedBlockVariation', | ||
reactivateInstagramEmbedBlockVariation | ||
); |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
/** | ||
* External dependencies | ||
*/ | ||
import { get } from 'lodash'; | ||
|
||
/** | ||
* Internal dependencies | ||
*/ | ||
import getJetpackData from './get-jetpack-data'; | ||
|
||
/** | ||
* Return whether Jetpack is connected to WP.com. | ||
* | ||
* @returns {boolean} Whether Jetpack is connected to WP.com | ||
*/ | ||
export default function isActive() { | ||
return get( getJetpackData(), [ 'jetpack', 'is_active' ], false ); | ||
} |