Skip to content
Snippets Groups Projects
Commit 1d6e7c6e authored by Erick Hitter's avatar Erick Hitter
Browse files

Add embed-block variation

parent 1f035e37
Branches
No related tags found
1 merge request!2Add `core/embed` variation in Block Editor
<?php return array('dependencies' => array(), 'version' => '31d6cfe0d16ae931b73c'); <?php return array('dependencies' => array('wp-hooks', 'wp-i18n'), 'version' => '6a0f88ce1d82184ce1ea');
(()=>{"use strict";const e=window.wp.hooks,r=window.wp.i18n,o="blocks.registerBlockType",t="eth-embed-anchor-fm/register-block-core-embed",{name:m,patterns:n}=ethEmbedAnchorFm;(0,e.addFilter)(o,t,((d,c)=>("core/embed"!==c||((0,e.removeFilter)(o,t),d.variations.push({name:m,title:(0,r.__)("Anchor.fm","eth-embed-anchor-fm"),keywords:[(0,r.__)("podcast","eth-embed-anchor-fm"),(0,r.__)("embed","eth-embed-anchor-fm")],description:(0,r.__)("Embed an Anchor.fm podcast.","eth-embed-anchor-fm"),patterns:n,attributes:{providerNameSlug:m,responsive:!1}})),d)))})();
\ No newline at end of file
/* global ethEmbedAnchorFm */
import { addFilter, removeFilter } from '@wordpress/hooks';
import { __ } from '@wordpress/i18n';
const blockName = 'core/embed';
const filterTag = 'blocks.registerBlockType';
const namespace = 'eth-embed-anchor-fm/register-block-core-embed';
const { name: providerName, patterns } = ethEmbedAnchorFm;
addFilter( filterTag, namespace, ( settings, name ) => {
if ( name !== blockName ) {
return settings;
}
removeFilter( filterTag, namespace );
settings.variations.push( {
name: providerName,
title: __( 'Anchor.fm', 'eth-embed-anchor-fm' ),
// icon: embedTwitterIcon,
keywords: [
__( 'podcast', 'eth-embed-anchor-fm' ),
__( 'embed', 'eth-embed-anchor-fm' ),
],
description: __( 'Embed an Anchor.fm podcast.', 'eth-embed-anchor-fm' ),
patterns,
attributes: { providerNameSlug: providerName, responsive: false },
} );
return settings;
} );
...@@ -31,11 +31,12 @@ class Block_Editor { ...@@ -31,11 +31,12 @@ class Block_Editor {
* @return void * @return void
*/ */
public function action_enqueue_block_editor_assets(): void { public function action_enqueue_block_editor_assets(): void {
$asset_data = require dirname( __FILE__, 2 ) $asset_data = require dirname( __FILE__, 2 )
. '/assets/build/index.asset.php'; . '/assets/build/index.asset.php';
$asset_handle = 'eth-embed-anchor-fm-block-editor';
wp_enqueue_script( wp_enqueue_script(
'eth-embed-anchor-fm-block-editor', $asset_handle,
plugins_url( plugins_url(
'assets/build/index.js', 'assets/build/index.js',
dirname( __FILE__, 2 ) dirname( __FILE__, 2 )
...@@ -45,5 +46,24 @@ class Block_Editor { ...@@ -45,5 +46,24 @@ class Block_Editor {
$asset_data['version'], $asset_data['version'],
true true
); );
// TODO: localize with necessary names.
// TODO: include `anchor-fm-inc` in localization.
wp_localize_script(
$asset_handle,
'ethEmbedAnchorFm',
[
'name' => 'anchor-fm-inc',
'patterns' => [
Plugin::get_instance()->url_regex,
],
]
);
wp_set_script_translations(
$asset_handle,
'eth-embed-anchor-fm',
dirname( __FILE__, 2 ) . '/languages'
);
} }
} }
...@@ -41,6 +41,22 @@ class Plugin { ...@@ -41,6 +41,22 @@ class Plugin {
*/ */
private const SHORTCODE_TAG = 'eth_anchor_fm'; private const SHORTCODE_TAG = 'eth_anchor_fm';
public function __get( $name ): ?string {
if ( 'url_regex' === $name ) {
return self::OEMBED_FORMAT;
}
return null;
}
public function __set( string $name, string $value ): bool {
return false;
}
public function __isset( $name ): bool {
return 'url_regex' === $name;
}
/** /**
* Register hooks. * Register hooks.
* *
......
This diff is collapsed.
{ {
"name": "eth-embed-anchor-fm", "name": "eth-embed-anchor-fm",
"version": "0.1.0", "version": "0.1.0",
"main": "Gruntfile.js", "main": "Gruntfile.js",
"author": "Erick Hitter", "author": "Erick Hitter",
"scripts": { "scripts": {
"build": "wp-scripts build", "build": "wp-scripts build",
"check-engines": "wp-scripts check-engines", "check-engines": "wp-scripts check-engines",
"check-licenses": "wp-scripts check-licenses", "check-licenses": "wp-scripts check-licenses",
"format": "wp-scripts format", "format": "wp-scripts format",
"lint:css": "wp-scripts lint-style", "lint:css": "wp-scripts lint-style",
"lint:js": "wp-scripts lint-js", "lint:js": "wp-scripts lint-js",
"lint:md:docs": "wp-scripts lint-md-docs", "lint:md:docs": "wp-scripts lint-md-docs",
"lint:pkg-json": "wp-scripts lint-pkg-json", "lint:pkg-json": "wp-scripts lint-pkg-json",
"packages-update": "wp-scripts packages-update", "packages-update": "wp-scripts packages-update",
"plugin-zip": "wp-scripts plugin-zip", "plugin-zip": "wp-scripts plugin-zip",
"start": "wp-scripts start", "start": "wp-scripts start",
"test": "npm run test:e2e && npm run test:unit", "test": "npm run test:e2e && npm run test:unit",
"test:e2e": "wp-scripts test-e2e --passWithNoTests", "test:e2e": "wp-scripts test-e2e --passWithNoTests",
"test:unit": "wp-scripts test-unit-js --passWithNoTests" "test:unit": "wp-scripts test-unit-js --passWithNoTests"
}, },
"devDependencies": { "devDependencies": {
"@wordpress/scripts": "^23.5.0", "@wordpress/scripts": "^23.5.0",
"grunt": "^1.5.3", "grunt": "^1.5.3",
"grunt-wp-i18n": "^1.0.3", "grunt-wp-i18n": "^1.0.3",
"grunt-wp-readme-to-markdown": "^2.1.0" "grunt-wp-readme-to-markdown": "^2.1.0"
} },
"dependencies": {
"@wordpress/hooks": "^3.13.0",
"@wordpress/i18n": "^4.13.0"
}
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment