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

Merge branch 'add/embed-variation' into 'main'

Add `core/embed` variation in Block Editor

See merge request !2
parents 458dc748 11235e38
Branches
Tags
1 merge request!2Add `core/embed` variation in Block Editor
Pipeline #5151 passed
<?php return array('dependencies' => array('wp-components', 'wp-element', 'wp-hooks', 'wp-i18n'), 'version' => 'e397fb7700ad8600f5bd');
(()=>{"use strict";const e=window.wp.element,c=window.wp.components,o=window.wp.hooks,t=window.wp.i18n,r="blocks.registerBlockType",n="eth-embed-anchor-fm/register-block-core-embed",m="anchor-fm-inc";(0,o.addFilter)(r,n,((i,s)=>("core/embed"!==s||((0,o.removeFilter)(r,n),i.variations.push({name:m,title:(0,t.__)("Anchor.fm","eth-embed-anchor-fm"),icon:(0,e.createElement)(c.SVG,{viewBox:"0 0 24 24",xmlns:"http://www.w3.org/2000/svg"},(0,e.createElement)(c.Path,{d:"M19 3H5c-1.1 0-2 .9-2 2v14c0 1.1.9 2 2 2h14c1.1 0 2-.9 2-2V5c0-1.1-.9-2-2-2zm.5 16c0 .3-.2.5-.5.5H5c-.3 0-.5-.2-.5-.5V9.8l4.7-5.3H19c.3 0 .5.2.5.5v14zM13.2 7.7c-.4.4-.7 1.1-.7 1.9v3.7c-.4-.3-.8-.4-1.3-.4-1.2 0-2.2 1-2.2 2.2 0 1.2 1 2.2 2.2 2.2.5 0 1-.2 1.4-.5.9-.6 1.4-1.6 1.4-2.6V9.6c0-.4.1-.6.2-.8.3-.3 1-.3 1.6-.3h.2V7h-.2c-.7 0-1.8 0-2.6.7z"})),keywords:[(0,t.__)("podcast","eth-embed-anchor-fm"),(0,t.__)("embed","eth-embed-anchor-fm")],description:(0,t.__)("Embed an Anchor.fm podcast.","eth-embed-anchor-fm"),patterns:[/^https:\/\/anchor\.fm\/[^\/]+\/episodes\/.+/i],attributes:{providerNameSlug:m,responsive:!1}})),i)))})();
\ No newline at end of file
import { Path, SVG } from '@wordpress/components';
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 providerName = 'anchor-fm-inc';
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: (
<SVG viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg">
<Path d="M19 3H5c-1.1 0-2 .9-2 2v14c0 1.1.9 2 2 2h14c1.1 0 2-.9 2-2V5c0-1.1-.9-2-2-2zm.5 16c0 .3-.2.5-.5.5H5c-.3 0-.5-.2-.5-.5V9.8l4.7-5.3H19c.3 0 .5.2.5.5v14zM13.2 7.7c-.4.4-.7 1.1-.7 1.9v3.7c-.4-.3-.8-.4-1.3-.4-1.2 0-2.2 1-2.2 2.2 0 1.2 1 2.2 2.2 2.2.5 0 1-.2 1.4-.5.9-.6 1.4-1.6 1.4-2.6V9.6c0-.4.1-.6.2-.8.3-.3 1-.3 1.6-.3h.2V7h-.2c-.7 0-1.8 0-2.6.7z" />
</SVG>
),
keywords: [
__( 'podcast', 'eth-embed-anchor-fm' ),
__( 'embed', 'eth-embed-anchor-fm' ),
],
description: __( 'Embed an Anchor.fm podcast.', 'eth-embed-anchor-fm' ),
patterns: [ /^https:\/\/anchor\.fm\/[^\/]+\/episodes\/.+/i ],
attributes: { providerNameSlug: providerName, responsive: false },
} );
return settings;
} );
......@@ -45,5 +45,9 @@ add_action( 'plugins_loaded', __NAMESPACE__ . '\action_plugins_loaded' );
/**
* Load plugin classes.
*/
require_once __DIR__ . '/inc/trait-singleton.php';
require_once __DIR__ . '/inc/class-plugin.php';
require_once __DIR__ . '/inc/class-block-editor.php';
Plugin::get_instance();
Block_Editor::get_instance();
<?php
/**
* Block Editor integration.
*
* @package ETH_Embed_Anchor_FM
*/
namespace ETH_Embed_Anchor_FM;
/**
* Class Block_Editor.
*/
class Block_Editor {
use Singleton;
/**
* Register hooks.
*
* @return void
*/
protected function _setup(): void {
add_action(
'enqueue_block_editor_assets',
[ $this, 'action_enqueue_block_editor_assets' ]
);
}
/**
* Enqueue block editor assets.
*
* @return void
*/
public function action_enqueue_block_editor_assets(): void {
$asset_data = require dirname( __FILE__, 2 )
. '/assets/build/index.asset.php';
$asset_handle = 'eth-embed-anchor-fm-block-editor';
wp_enqueue_script(
$asset_handle,
plugins_url(
'assets/build/index.js',
dirname( __FILE__, 2 )
. '/eth-embed-anchor-fm.php'
),
$asset_data['dependencies'],
$asset_data['version'],
true
);
wp_set_script_translations(
$asset_handle,
'eth-embed-anchor-fm',
dirname( __FILE__, 2 ) . '/languages'
);
}
}
......@@ -11,6 +11,8 @@ namespace ETH_Embed_Anchor_FM;
* Class Plugin.
*/
class Plugin {
use Singleton;
/**
* Regex pattern to match URL to be oEmbedded.
*
......@@ -39,40 +41,12 @@ class Plugin {
*/
private const SHORTCODE_TAG = 'eth_anchor_fm';
/**
* Singleton.
*
* @var Plugin
*/
private static $_instance = null;
/**
* Implement singleton.
*
* @return Plugin
*/
public static function get_instance(): Plugin {
if ( ! is_a( self::$_instance, __CLASS__ ) ) {
self::$_instance = new self();
self::$_instance->_setup();
}
return self::$_instance;
}
/**
* Silence is golden!
*/
private function __construct() {
// Add nothing here.
}
/**
* Register hooks.
*
* @return void
*/
private function _setup(): void {
protected function _setup(): void {
add_action( 'init', [ $this, 'action_init' ] );
add_filter(
......
<?php
/**
* Singleton trait.
*
* @package ETH_Embed_Anchor_FM
*/
namespace ETH_Embed_Anchor_FM;
/**
* Trait Singleton.
*/
trait Singleton {
/**
* Singleton.
*
* @var self
*/
private static $_instance = null;
/**
* Implement singleton.
*
* @return self
*/
public static function get_instance(): self {
if ( ! is_a( self::$_instance, __CLASS__ ) ) {
self::$_instance = new self();
self::$_instance->_setup();
}
return self::$_instance;
}
/**
* Silence is golden!
*/
private function __construct() {
// Add nothing here.
}
/**
* Register hooks.
*
* @return void
*/
abstract protected function _setup(): void;
}
This diff is collapsed.
{
"name": "eth-embed-anchor-fm",
"version": "0.1.0",
"main": "Gruntfile.js",
"author": "Erick Hitter",
"devDependencies": {
"grunt": "^1.5.3",
"grunt-wp-i18n": "^1.0.3",
"grunt-wp-readme-to-markdown": "^2.1.0"
}
"name": "eth-embed-anchor-fm",
"version": "0.1.0",
"main": "Gruntfile.js",
"author": "Erick Hitter",
"scripts": {
"build": "wp-scripts build",
"check-engines": "wp-scripts check-engines",
"check-licenses": "wp-scripts check-licenses",
"format": "wp-scripts format",
"lint:css": "wp-scripts lint-style",
"lint:js": "wp-scripts lint-js",
"lint:md:docs": "wp-scripts lint-md-docs",
"lint:pkg-json": "wp-scripts lint-pkg-json",
"packages-update": "wp-scripts packages-update",
"plugin-zip": "wp-scripts plugin-zip",
"start": "wp-scripts start",
"test": "npm run test:e2e && npm run test:unit",
"test:e2e": "wp-scripts test-e2e --passWithNoTests",
"test:unit": "wp-scripts test-unit-js --passWithNoTests"
},
"devDependencies": {
"@wordpress/scripts": "^23.5.0",
"grunt": "^1.5.3",
"grunt-wp-i18n": "^1.0.3",
"grunt-wp-readme-to-markdown": "^2.1.0"
},
"dependencies": {
"@wordpress/components": "^19.15.0",
"@wordpress/hooks": "^3.13.0",
"@wordpress/i18n": "^4.13.0"
}
}
......@@ -4,6 +4,7 @@
<!-- What to scan -->
<file>.</file>
<exclude-pattern>/assets/build/</exclude-pattern>
<exclude-pattern>/vendor/</exclude-pattern>
<exclude-pattern>/node_modules/</exclude-pattern>
......
const config = require( './node_modules/@wordpress/scripts/config/webpack.config' );
const { resolve } = require( 'path' );
config.entry = {
index: './assets/src/index.js',
};
config.output.path = resolve( process.cwd(), 'assets/build' );
module.exports = config;
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment