From f4e8852ff5a99d72c0895e08f9d97587232b2c7d Mon Sep 17 00:00:00 2001 From: StevenDufresne Date: Mon, 15 Jan 2024 13:13:42 +0900 Subject: [PATCH 1/6] Update code to match current format. --- .../blocks/article-meta-github/block.json | 30 ++++++++ .../blocks/article-meta-github/block.php | 70 +++++++++++++++++++ .../blocks/article-meta-github/index.js | 17 +++++ mu-plugins/loader.php | 1 + 4 files changed, 118 insertions(+) create mode 100644 mu-plugins/blocks/article-meta-github/block.json create mode 100644 mu-plugins/blocks/article-meta-github/block.php create mode 100644 mu-plugins/blocks/article-meta-github/index.js diff --git a/mu-plugins/blocks/article-meta-github/block.json b/mu-plugins/blocks/article-meta-github/block.json new file mode 100644 index 000000000..0b5ec6c49 --- /dev/null +++ b/mu-plugins/blocks/article-meta-github/block.json @@ -0,0 +1,30 @@ +{ + "$schema": "https://schemas.wp.org/trunk/block.json", + "apiVersion": 2, + "name": "wporg/article-meta-github", + "version": "0.1.0", + "title": "Article Meta GitHub", + "category": "widgets", + "icon": "smiley", + "description": "", + "usesContext": [ "postId", "postType" ], + "attributes": { + "heading": { + "type": "string", + "default": "" + }, + "linkText": { + "type": "string", + "default": "" + }, + "linkUrl": { + "type": "string", + "default": "" + } + }, + "supports": { + "inserter": false + }, + "textdomain": "wporg", + "editorScript": "file:./index.js" +} diff --git a/mu-plugins/blocks/article-meta-github/block.php b/mu-plugins/blocks/article-meta-github/block.php new file mode 100644 index 000000000..0e17c55cb --- /dev/null +++ b/mu-plugins/blocks/article-meta-github/block.php @@ -0,0 +1,70 @@ + __NAMESPACE__ . '\render', + ) + ); +} + +/** + * Render the block content. + * + * @param array $attributes Block attributes. + * @param string $content Block default content. + * @param WP_Block $block Block instance. + * + * @return string Returns the block markup. + */ +function render( $attributes, $content, $block ) { + $post_type = $block->context['postType']; + $post_id = $block->context['postId']; + + if ( + ! isset( $post_id ) || ! isset( $post_type ) + ) { + return ''; + } + + $title = get_the_title( $post_id ); + $link_url = $attributes['linkURL']; + + return sprintf( + do_blocks( + ' +
+ + +

%1$s

+ + + + + + +
+ ' + ), + esc_html( $attributes['heading'] ), + // Don't use esc_url for a shortcode. + preg_match( '/^\[.*\]$/', $link_url ) ? esc_html( $link_url ) : esc_url( $link_url ), + sprintf( + /* translators: %1$s: call to action, %2$s: article title */ + __( '%1$s: %2$s"', 'wporg' ), + esc_html( $attributes['linkText'] ), + esc_html( $title ) + ) + ); +} diff --git a/mu-plugins/blocks/article-meta-github/index.js b/mu-plugins/blocks/article-meta-github/index.js new file mode 100644 index 000000000..abba51c28 --- /dev/null +++ b/mu-plugins/blocks/article-meta-github/index.js @@ -0,0 +1,17 @@ +/** + * WordPress dependencies + */ +import { registerBlockType } from '@wordpress/blocks'; + +/** + * Internal dependencies + */ +import Edit from '../shared/dynamic-edit'; +import metadata from './block.json'; + +registerBlockType( metadata.name, { + /** + * @see ./edit.js + */ + edit: Edit, +} ); diff --git a/mu-plugins/loader.php b/mu-plugins/loader.php index cf0cdaafb..ffc4c9808 100644 --- a/mu-plugins/loader.php +++ b/mu-plugins/loader.php @@ -27,6 +27,7 @@ } require_once __DIR__ . '/helpers/helpers.php'; +require_once __DIR__ . '/blocks/article-meta-github/block.php'; require_once __DIR__ . '/blocks/global-header-footer/blocks.php'; require_once __DIR__ . '/blocks/google-map/index.php'; require_once __DIR__ . '/blocks/horizontal-slider/horizontal-slider.php'; From 65955e5b6ae336f2881c8e69307bb9265f6668ea Mon Sep 17 00:00:00 2001 From: StevenDufresne Date: Mon, 15 Jan 2024 13:14:44 +0900 Subject: [PATCH 2/6] Update namespace. --- mu-plugins/blocks/article-meta-github/block.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mu-plugins/blocks/article-meta-github/block.php b/mu-plugins/blocks/article-meta-github/block.php index 0e17c55cb..d8a6da4a2 100644 --- a/mu-plugins/blocks/article-meta-github/block.php +++ b/mu-plugins/blocks/article-meta-github/block.php @@ -1,5 +1,5 @@ Date: Mon, 15 Jan 2024 13:27:45 +0900 Subject: [PATCH 3/6] Fix file structure. --- .../article-meta-github/{ => src}/block.json | 0 .../blocks/article-meta-github/src/edit.js | 20 +++++++++++++++++++ .../article-meta-github/{ => src}/index.js | 2 +- 3 files changed, 21 insertions(+), 1 deletion(-) rename mu-plugins/blocks/article-meta-github/{ => src}/block.json (100%) create mode 100644 mu-plugins/blocks/article-meta-github/src/edit.js rename mu-plugins/blocks/article-meta-github/{ => src}/index.js (85%) diff --git a/mu-plugins/blocks/article-meta-github/block.json b/mu-plugins/blocks/article-meta-github/src/block.json similarity index 100% rename from mu-plugins/blocks/article-meta-github/block.json rename to mu-plugins/blocks/article-meta-github/src/block.json diff --git a/mu-plugins/blocks/article-meta-github/src/edit.js b/mu-plugins/blocks/article-meta-github/src/edit.js new file mode 100644 index 000000000..c2c830d75 --- /dev/null +++ b/mu-plugins/blocks/article-meta-github/src/edit.js @@ -0,0 +1,20 @@ +/** + * WordPress dependencies + */ +import { useBlockProps } from '@wordpress/block-editor'; +import ServerSideRender from '@wordpress/server-side-render'; + +export default function Edit( { name, attributes, context } ) { + const blockProps = useBlockProps(); + const { postId } = context; + return ( +
+ +
+ ); +} \ No newline at end of file diff --git a/mu-plugins/blocks/article-meta-github/index.js b/mu-plugins/blocks/article-meta-github/src/index.js similarity index 85% rename from mu-plugins/blocks/article-meta-github/index.js rename to mu-plugins/blocks/article-meta-github/src/index.js index abba51c28..56aa2185c 100644 --- a/mu-plugins/blocks/article-meta-github/index.js +++ b/mu-plugins/blocks/article-meta-github/src/index.js @@ -6,7 +6,7 @@ import { registerBlockType } from '@wordpress/blocks'; /** * Internal dependencies */ -import Edit from '../shared/dynamic-edit'; +import Edit from './edit'; import metadata from './block.json'; registerBlockType( metadata.name, { From 3d6f8fa25ae6a77f6a7eb7a356fb9af0220f524c Mon Sep 17 00:00:00 2001 From: StevenDufresne Date: Mon, 15 Jan 2024 13:33:16 +0900 Subject: [PATCH 4/6] Run linter. --- mu-plugins/blocks/article-meta-github/src/edit.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mu-plugins/blocks/article-meta-github/src/edit.js b/mu-plugins/blocks/article-meta-github/src/edit.js index c2c830d75..62679697b 100644 --- a/mu-plugins/blocks/article-meta-github/src/edit.js +++ b/mu-plugins/blocks/article-meta-github/src/edit.js @@ -17,4 +17,4 @@ export default function Edit( { name, attributes, context } ) { /> ); -} \ No newline at end of file +} From bd6443450c45b9a3d2ef3d801e5c553859b3f2b2 Mon Sep 17 00:00:00 2001 From: StevenDufresne Date: Mon, 15 Jan 2024 13:48:03 +0900 Subject: [PATCH 5/6] Remove duplicate register. --- mu-plugins/blocks/article-meta-github/block.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mu-plugins/blocks/article-meta-github/block.php b/mu-plugins/blocks/article-meta-github/block.php index d8a6da4a2..4ed319eea 100644 --- a/mu-plugins/blocks/article-meta-github/block.php +++ b/mu-plugins/blocks/article-meta-github/block.php @@ -12,7 +12,7 @@ */ function init() { register_block_type( - register_block_type( __DIR__ . '/build' ), + __DIR__ . '/build', array( 'render_callback' => __NAMESPACE__ . '\render', ) From 2592fa0157f922eb50033d9d6dfe62585723eaba Mon Sep 17 00:00:00 2001 From: StevenDufresne Date: Mon, 22 Jan 2024 13:30:58 +0900 Subject: [PATCH 6/6] Rename to Handbook meta link. --- .../{article-meta-github => handbook-meta-link}/block.php | 2 +- .../src/block.json | 4 ++-- .../{article-meta-github => handbook-meta-link}/src/edit.js | 0 .../{article-meta-github => handbook-meta-link}/src/index.js | 0 mu-plugins/loader.php | 2 +- 5 files changed, 4 insertions(+), 4 deletions(-) rename mu-plugins/blocks/{article-meta-github => handbook-meta-link}/block.php (97%) rename mu-plugins/blocks/{article-meta-github => handbook-meta-link}/src/block.json (87%) rename mu-plugins/blocks/{article-meta-github => handbook-meta-link}/src/edit.js (100%) rename mu-plugins/blocks/{article-meta-github => handbook-meta-link}/src/index.js (100%) diff --git a/mu-plugins/blocks/article-meta-github/block.php b/mu-plugins/blocks/handbook-meta-link/block.php similarity index 97% rename from mu-plugins/blocks/article-meta-github/block.php rename to mu-plugins/blocks/handbook-meta-link/block.php index 4ed319eea..14b2bf8e0 100644 --- a/mu-plugins/blocks/article-meta-github/block.php +++ b/mu-plugins/blocks/handbook-meta-link/block.php @@ -1,5 +1,5 @@