From 1855dec01101820fbf2068dc4e8219b25633404f Mon Sep 17 00:00:00 2001 From: Kerry Liu Date: Fri, 16 Apr 2021 13:56:26 -0700 Subject: [PATCH 01/12] Add home link block --- lib/blocks.php | 2 + packages/block-library/src/home/block.json | 31 ++++++++++ packages/block-library/src/home/edit.js | 54 ++++++++++++++++ packages/block-library/src/home/index.js | 36 +++++++++++ packages/block-library/src/home/index.php | 61 +++++++++++++++++++ packages/block-library/src/home/save.js | 8 +++ packages/block-library/src/home/style.scss | 3 + packages/block-library/src/index.js | 2 + packages/block-library/src/navigation/edit.js | 1 + 9 files changed, 198 insertions(+) create mode 100644 packages/block-library/src/home/block.json create mode 100644 packages/block-library/src/home/edit.js create mode 100644 packages/block-library/src/home/index.js create mode 100644 packages/block-library/src/home/index.php create mode 100644 packages/block-library/src/home/save.js create mode 100644 packages/block-library/src/home/style.scss diff --git a/lib/blocks.php b/lib/blocks.php index aff9e254edf1c..77e2e56e46096 100644 --- a/lib/blocks.php +++ b/lib/blocks.php @@ -26,6 +26,7 @@ function gutenberg_reregister_core_block_types() { 'group', 'heading', 'html', + 'home', 'image', 'list', 'media-text', @@ -59,6 +60,7 @@ function gutenberg_reregister_core_block_types() { 'loginout.php' => 'core/loginout', 'navigation.php' => 'core/navigation', 'navigation-link.php' => 'core/navigation-link', + 'home.php' => 'core/home', 'rss.php' => 'core/rss', 'search.php' => 'core/search', 'shortcode.php' => 'core/shortcode', diff --git a/packages/block-library/src/home/block.json b/packages/block-library/src/home/block.json new file mode 100644 index 0000000000000..73ac8945a24a3 --- /dev/null +++ b/packages/block-library/src/home/block.json @@ -0,0 +1,31 @@ +{ + "apiVersion": 2, + "name": "core/home", + "category": "design", + "parent": [ "core/navigation" ], + "attributes": { + "label": { + "type": "string" + }, + "opensInNewTab": { + "type": "boolean", + "default": false + } + }, + "usesContext": [ + "textColor", + "customTextColor", + "backgroundColor", + "customBackgroundColor", + "fontSize", + "customFontSize", + "showSubmenuIcon", + "style" + ], + "supports": { + "reusable": false, + "html": false + }, + "editorStyle": "wp-block-home-editor", + "style": "wp-block-home" +} diff --git a/packages/block-library/src/home/edit.js b/packages/block-library/src/home/edit.js new file mode 100644 index 0000000000000..1572a16a55481 --- /dev/null +++ b/packages/block-library/src/home/edit.js @@ -0,0 +1,54 @@ +/** + * WordPress dependencies + */ +import { RichText, useBlockProps } from '@wordpress/block-editor'; +import { __ } from '@wordpress/i18n'; +import { useSelect } from '@wordpress/data'; +import { store as coreStore } from '@wordpress/core-data'; + +const preventDefault = ( event ) => event.preventDefault(); + +export default function HomeEdit( { attributes, setAttributes, clientId } ) { + const blockProps = useBlockProps(); + const { homeUrl } = useSelect( + ( select ) => { + const { + getUnstableBase, //site index + } = select( coreStore ); + return { + homeUrl: getUnstableBase()?.home, + }; + }, + [ clientId ] + ); + + const { label } = attributes; + + return ( +
  • + + { + setAttributes( { label: labelValue } ); + } } + aria-label={ __( 'Home link text' ) } + placeholder={ __( 'Add home link' ) } + withoutInteractiveFormatting + allowedFormats={ [ + 'core/bold', + 'core/italic', + 'core/image', + 'core/strikethrough', + ] } + /> + +
  • + ); +} diff --git a/packages/block-library/src/home/index.js b/packages/block-library/src/home/index.js new file mode 100644 index 0000000000000..4349462e71f5f --- /dev/null +++ b/packages/block-library/src/home/index.js @@ -0,0 +1,36 @@ +/** + * WordPress dependencies + */ +import { __, _x } from '@wordpress/i18n'; +import { home } from '@wordpress/icons'; + +/** + * Internal dependencies + */ +import metadata from './block.json'; +import edit from './edit'; +import save from './save'; + +const { name } = metadata; + +export { metadata, name }; + +export const settings = { + title: _x( 'Home Link', 'block title' ), + + icon: home, + + description: __( 'Add a home link to your navigation.' ), + + keywords: [ __( 'home' ), __( 'menu' ), __( 'navigation' ) ], + + edit, + + save, + + example: { + attributes: { + label: _x( 'Home', 'Home preview example' ), + }, + }, +}; diff --git a/packages/block-library/src/home/index.php b/packages/block-library/src/home/index.php new file mode 100644 index 0000000000000..34bd64a55b8f9 --- /dev/null +++ b/packages/block-library/src/home/index.php @@ -0,0 +1,61 @@ + implode( ' ', $classnames ) ) ); + + $label = wp_kses( + $attributes['label'], + array( + 'code' => array(), + 'em' => array(), + 'img' => array( + 'scale' => array(), + 'class' => array(), + 'style' => array(), + 'src' => array(), + 'alt' => array(), + ), + 's' => array(), + 'span' => array( + 'style' => array(), + ), + 'strong' => array(), + ) + ); + + $html = sprintf( '
  • %s
  • ', $wrapper_attributes, home_url(), $label ); + + return $html; +} + +/** + * Register the home block + * + * @uses render_block_core_home() + * @throws WP_Error An WP_Error exception parsing the block definition. + */ +function register_block_core_home() { + register_block_type_from_metadata( + __DIR__ . '/home', + array( + 'render_callback' => 'render_block_core_home', + ) + ); +} +add_action( 'init', 'register_block_core_home' ); diff --git a/packages/block-library/src/home/save.js b/packages/block-library/src/home/save.js new file mode 100644 index 0000000000000..17571d8f30d2d --- /dev/null +++ b/packages/block-library/src/home/save.js @@ -0,0 +1,8 @@ +/** + * WordPress dependencies + */ +import { InnerBlocks } from '@wordpress/block-editor'; + +export default function save() { + return ; +} diff --git a/packages/block-library/src/home/style.scss b/packages/block-library/src/home/style.scss new file mode 100644 index 0000000000000..9bff7c1d58082 --- /dev/null +++ b/packages/block-library/src/home/style.scss @@ -0,0 +1,3 @@ +.wp-block-home .wp-block-home__content { + text-decoration: inherit; +} diff --git a/packages/block-library/src/index.js b/packages/block-library/src/index.js index 26e22c76af314..34da6300518f5 100644 --- a/packages/block-library/src/index.js +++ b/packages/block-library/src/index.js @@ -35,6 +35,7 @@ import * as html from './html'; import * as mediaText from './media-text'; import * as navigation from './navigation'; import * as navigationLink from './navigation-link'; +import * as home from './home'; import * as latestComments from './latest-comments'; import * as latestPosts from './latest-posts'; import * as legacyWidget from './legacy-widget'; @@ -233,6 +234,7 @@ export const __experimentalRegisterExperimentalCoreBlocks = [ navigation, navigationLink, + home, // Register Legacy Widget block. ...( enableLegacyWidgetBlock ? [ legacyWidget ] : [] ), diff --git a/packages/block-library/src/navigation/edit.js b/packages/block-library/src/navigation/edit.js index 18d9da732015c..f66015225de6c 100644 --- a/packages/block-library/src/navigation/edit.js +++ b/packages/block-library/src/navigation/edit.js @@ -35,6 +35,7 @@ const ALLOWED_BLOCKS = [ 'core/social-links', 'core/page-list', 'core/spacer', + 'core/home', ]; const LAYOUT = { From cc0b7a5c4791944cd07823e5488a26b0ef80381c Mon Sep 17 00:00:00 2001 From: Kerry Liu Date: Tue, 20 Apr 2021 11:36:19 -0700 Subject: [PATCH 02/12] rename home block to home-link --- lib/blocks.php | 4 +-- .../src/{home => home-link}/block.json | 6 ++-- .../src/{home => home-link}/edit.js | 11 +++++-- .../src/{home => home-link}/index.js | 2 +- .../src/{home => home-link}/index.php | 4 +-- .../src/{home => home-link}/save.js | 0 .../block-library/src/home-link/style.scss | 29 +++++++++++++++++++ packages/block-library/src/home/style.scss | 3 -- packages/block-library/src/index.js | 4 +-- packages/block-library/src/navigation/edit.js | 2 +- 10 files changed, 49 insertions(+), 16 deletions(-) rename packages/block-library/src/{home => home-link}/block.json (80%) rename packages/block-library/src/{home => home-link}/edit.js (81%) rename packages/block-library/src/{home => home-link}/index.js (91%) rename packages/block-library/src/{home => home-link}/index.php (95%) rename packages/block-library/src/{home => home-link}/save.js (100%) create mode 100644 packages/block-library/src/home-link/style.scss delete mode 100644 packages/block-library/src/home/style.scss diff --git a/lib/blocks.php b/lib/blocks.php index 77e2e56e46096..1ba9e37e1b84b 100644 --- a/lib/blocks.php +++ b/lib/blocks.php @@ -26,7 +26,7 @@ function gutenberg_reregister_core_block_types() { 'group', 'heading', 'html', - 'home', + 'home-link', 'image', 'list', 'media-text', @@ -60,7 +60,7 @@ function gutenberg_reregister_core_block_types() { 'loginout.php' => 'core/loginout', 'navigation.php' => 'core/navigation', 'navigation-link.php' => 'core/navigation-link', - 'home.php' => 'core/home', + 'home-link.php' => 'core/home-link', 'rss.php' => 'core/rss', 'search.php' => 'core/search', 'shortcode.php' => 'core/shortcode', diff --git a/packages/block-library/src/home/block.json b/packages/block-library/src/home-link/block.json similarity index 80% rename from packages/block-library/src/home/block.json rename to packages/block-library/src/home-link/block.json index 73ac8945a24a3..39d0e0f5539ee 100644 --- a/packages/block-library/src/home/block.json +++ b/packages/block-library/src/home-link/block.json @@ -1,6 +1,6 @@ { "apiVersion": 2, - "name": "core/home", + "name": "core/home-link", "category": "design", "parent": [ "core/navigation" ], "attributes": { @@ -26,6 +26,6 @@ "reusable": false, "html": false }, - "editorStyle": "wp-block-home-editor", - "style": "wp-block-home" + "editorStyle": "wp-block-home-link-editor", + "style": "wp-block-home-link" } diff --git a/packages/block-library/src/home/edit.js b/packages/block-library/src/home-link/edit.js similarity index 81% rename from packages/block-library/src/home/edit.js rename to packages/block-library/src/home-link/edit.js index 1572a16a55481..71f5fca8645f4 100644 --- a/packages/block-library/src/home/edit.js +++ b/packages/block-library/src/home-link/edit.js @@ -5,6 +5,7 @@ import { RichText, useBlockProps } from '@wordpress/block-editor'; import { __ } from '@wordpress/i18n'; import { useSelect } from '@wordpress/data'; import { store as coreStore } from '@wordpress/core-data'; +import { useEffect } from '@wordpress/element'; const preventDefault = ( event ) => event.preventDefault(); @@ -24,16 +25,22 @@ export default function HomeEdit( { attributes, setAttributes, clientId } ) { const { label } = attributes; + useEffect( () => { + if ( label === undefined ) { + setAttributes( { label: __( 'Home' ) } ); + } + }, [ clientId, label ] ); + return (
  • { setAttributes( { label: labelValue } ); diff --git a/packages/block-library/src/home/index.js b/packages/block-library/src/home-link/index.js similarity index 91% rename from packages/block-library/src/home/index.js rename to packages/block-library/src/home-link/index.js index 4349462e71f5f..026fc3269c1dc 100644 --- a/packages/block-library/src/home/index.js +++ b/packages/block-library/src/home-link/index.js @@ -30,7 +30,7 @@ export const settings = { example: { attributes: { - label: _x( 'Home', 'Home preview example' ), + label: _x( 'Home', 'Home Link preview example' ), }, }, }; diff --git a/packages/block-library/src/home/index.php b/packages/block-library/src/home-link/index.php similarity index 95% rename from packages/block-library/src/home/index.php rename to packages/block-library/src/home-link/index.php index 34bd64a55b8f9..0d93604975873 100644 --- a/packages/block-library/src/home/index.php +++ b/packages/block-library/src/home-link/index.php @@ -1,7 +1,7 @@ 'render_block_core_home', ) diff --git a/packages/block-library/src/home/save.js b/packages/block-library/src/home-link/save.js similarity index 100% rename from packages/block-library/src/home/save.js rename to packages/block-library/src/home-link/save.js diff --git a/packages/block-library/src/home-link/style.scss b/packages/block-library/src/home-link/style.scss new file mode 100644 index 0000000000000..22d530bce3abd --- /dev/null +++ b/packages/block-library/src/home-link/style.scss @@ -0,0 +1,29 @@ +.wp-block-navigation { + // Force links to inherit text decoration applied to navigation block. + // The extra selector adds specificity to ensure it works when user-set. + &[style*="text-decoration"] { + .wp-block-home-link { + text-decoration: inherit; + } + + .wp-block-home-link__content { + text-decoration: inherit; + + &:focus, + &:active { + text-decoration: inherit; + } + } + } + + &:not([style*="text-decoration"]) { + .wp-block-home-link__content { + text-decoration: none; + + &:focus, + &:active { + text-decoration: none; + } + } + } +} diff --git a/packages/block-library/src/home/style.scss b/packages/block-library/src/home/style.scss deleted file mode 100644 index 9bff7c1d58082..0000000000000 --- a/packages/block-library/src/home/style.scss +++ /dev/null @@ -1,3 +0,0 @@ -.wp-block-home .wp-block-home__content { - text-decoration: inherit; -} diff --git a/packages/block-library/src/index.js b/packages/block-library/src/index.js index 34da6300518f5..a4ec8243c4e74 100644 --- a/packages/block-library/src/index.js +++ b/packages/block-library/src/index.js @@ -35,7 +35,7 @@ import * as html from './html'; import * as mediaText from './media-text'; import * as navigation from './navigation'; import * as navigationLink from './navigation-link'; -import * as home from './home'; +import * as homeLink from './home-link'; import * as latestComments from './latest-comments'; import * as latestPosts from './latest-posts'; import * as legacyWidget from './legacy-widget'; @@ -234,7 +234,7 @@ export const __experimentalRegisterExperimentalCoreBlocks = [ navigation, navigationLink, - home, + homeLink, // Register Legacy Widget block. ...( enableLegacyWidgetBlock ? [ legacyWidget ] : [] ), diff --git a/packages/block-library/src/navigation/edit.js b/packages/block-library/src/navigation/edit.js index f66015225de6c..b086931cb8bec 100644 --- a/packages/block-library/src/navigation/edit.js +++ b/packages/block-library/src/navigation/edit.js @@ -35,7 +35,7 @@ const ALLOWED_BLOCKS = [ 'core/social-links', 'core/page-list', 'core/spacer', - 'core/home', + 'core/home-link', ]; const LAYOUT = { From 62d08218b9aa60500b5160a7fbdbc814a759f6cc Mon Sep 17 00:00:00 2001 From: Kerry Liu Date: Wed, 21 Apr 2021 14:29:28 -0700 Subject: [PATCH 03/12] add support for title rel and target --- .../block-library/src/home-link/block.json | 7 +- packages/block-library/src/home-link/edit.js | 89 +++++++++++++------ .../block-library/src/home-link/index.php | 61 ++++++++----- .../block-library/src/home-link/style.scss | 1 + 4 files changed, 110 insertions(+), 48 deletions(-) diff --git a/packages/block-library/src/home-link/block.json b/packages/block-library/src/home-link/block.json index 39d0e0f5539ee..c43a896852835 100644 --- a/packages/block-library/src/home-link/block.json +++ b/packages/block-library/src/home-link/block.json @@ -10,6 +10,12 @@ "opensInNewTab": { "type": "boolean", "default": false + }, + "rel": { + "type": "string" + }, + "title": { + "type": "string" } }, "usesContext": [ @@ -19,7 +25,6 @@ "customBackgroundColor", "fontSize", "customFontSize", - "showSubmenuIcon", "style" ], "supports": { diff --git a/packages/block-library/src/home-link/edit.js b/packages/block-library/src/home-link/edit.js index 71f5fca8645f4..5479d7f0a4778 100644 --- a/packages/block-library/src/home-link/edit.js +++ b/packages/block-library/src/home-link/edit.js @@ -1,11 +1,16 @@ /** * WordPress dependencies */ -import { RichText, useBlockProps } from '@wordpress/block-editor'; +import { + RichText, + useBlockProps, + InspectorControls, +} from '@wordpress/block-editor'; import { __ } from '@wordpress/i18n'; import { useSelect } from '@wordpress/data'; import { store as coreStore } from '@wordpress/core-data'; import { useEffect } from '@wordpress/element'; +import { PanelBody, TextControl, ToggleControl } from '@wordpress/components'; const preventDefault = ( event ) => event.preventDefault(); @@ -23,7 +28,7 @@ export default function HomeEdit( { attributes, setAttributes, clientId } ) { [ clientId ] ); - const { label } = attributes; + const { label, opensInNewTab, rel, title } = attributes; useEffect( () => { if ( label === undefined ) { @@ -32,30 +37,60 @@ export default function HomeEdit( { attributes, setAttributes, clientId } ) { }, [ clientId, label ] ); return ( -
  • - - { - setAttributes( { label: labelValue } ); - } } - aria-label={ __( 'Home link text' ) } - placeholder={ __( 'Add home link' ) } - withoutInteractiveFormatting - allowedFormats={ [ - 'core/bold', - 'core/italic', - 'core/image', - 'core/strikethrough', - ] } - /> - -
  • + <> + + + { + setAttributes( { opensInNewTab: ! opensInNewTab } ); + } } + help={ __( 'Opens the home link in a new tab' ) } + /> + { + setAttributes( { title: titleValue } ); + } } + label={ __( 'Link title' ) } + autoComplete="off" + /> + { + setAttributes( { rel: relValue } ); + } } + label={ __( 'Link rel' ) } + autoComplete="off" + /> + + +
  • + + { + setAttributes( { label: labelValue } ); + } } + aria-label={ __( 'Home link text' ) } + placeholder={ __( 'Add home link' ) } + withoutInteractiveFormatting + allowedFormats={ [ + 'core/bold', + 'core/italic', + 'core/image', + 'core/strikethrough', + ] } + /> + +
  • + ); } diff --git a/packages/block-library/src/home-link/index.php b/packages/block-library/src/home-link/index.php index 0d93604975873..f4d5b5145005c 100644 --- a/packages/block-library/src/home-link/index.php +++ b/packages/block-library/src/home-link/index.php @@ -19,28 +19,49 @@ function render_block_core_home( $attributes ) { $wrapper_attributes = get_block_wrapper_attributes( array( 'class' => implode( ' ', $classnames ) ) ); - $label = wp_kses( - $attributes['label'], - array( - 'code' => array(), - 'em' => array(), - 'img' => array( - 'scale' => array(), - 'class' => array(), - 'style' => array(), - 'src' => array(), - 'alt' => array(), - ), - 's' => array(), - 'span' => array( - 'style' => array(), - ), - 'strong' => array(), - ) - ); + $html = '
  • %s
  • ', $wrapper_attributes, home_url(), $label ); + if ( isset( $attributes['rel'] ) ) { + $html .= ' rel="' . esc_attr( $attributes['rel'] ) . '"'; + } + + if ( isset( $attributes['title'] ) ) { + $html .= ' title="' . esc_attr( $attributes['title'] ) . '"'; + } + + // End appending HTML attributes to anchor tag. + $html .= '>'; + + if ( isset( $attributes['label'] ) ) { + $html .= wp_kses( + $attributes['label'], + array( + 'code' => array(), + 'em' => array(), + 'img' => array( + 'scale' => array(), + 'class' => array(), + 'style' => array(), + 'src' => array(), + 'alt' => array(), + ), + 's' => array(), + 'span' => array( + 'style' => array(), + ), + 'strong' => array(), + ) + ); + } + $html .= ''; return $html; } diff --git a/packages/block-library/src/home-link/style.scss b/packages/block-library/src/home-link/style.scss index 22d530bce3abd..8e0275e0f8a2e 100644 --- a/packages/block-library/src/home-link/style.scss +++ b/packages/block-library/src/home-link/style.scss @@ -17,6 +17,7 @@ } &:not([style*="text-decoration"]) { + .wp-block-home-link, .wp-block-home-link__content { text-decoration: none; From 8cf6624164f5eef0fba1465b85869f6cde4a6793 Mon Sep 17 00:00:00 2001 From: Kerry Liu Date: Thu, 22 Apr 2021 15:12:20 -0700 Subject: [PATCH 04/12] Add color/font support --- packages/block-library/src/home-link/edit.js | 27 +++- .../block-library/src/home-link/index.php | 128 ++++++++++++++++-- .../block-library/src/home-link/style.scss | 24 +++- .../fixtures/blocks/core__home-link.html | 1 + .../fixtures/blocks/core__home-link.json | 15 ++ .../blocks/core__home-link.parsed.json | 14 ++ .../blocks/core__home-link.serialized.html | 1 + 7 files changed, 199 insertions(+), 11 deletions(-) create mode 100644 packages/e2e-tests/fixtures/blocks/core__home-link.html create mode 100644 packages/e2e-tests/fixtures/blocks/core__home-link.json create mode 100644 packages/e2e-tests/fixtures/blocks/core__home-link.parsed.json create mode 100644 packages/e2e-tests/fixtures/blocks/core__home-link.serialized.html diff --git a/packages/block-library/src/home-link/edit.js b/packages/block-library/src/home-link/edit.js index 5479d7f0a4778..c21c0d72710e0 100644 --- a/packages/block-library/src/home-link/edit.js +++ b/packages/block-library/src/home-link/edit.js @@ -1,3 +1,8 @@ +/** + * External dependencies + */ +import classnames from 'classnames'; + /** * WordPress dependencies */ @@ -14,8 +19,12 @@ import { PanelBody, TextControl, ToggleControl } from '@wordpress/components'; const preventDefault = ( event ) => event.preventDefault(); -export default function HomeEdit( { attributes, setAttributes, clientId } ) { - const blockProps = useBlockProps(); +export default function HomeEdit( { + attributes, + setAttributes, + context, + clientId, +} ) { const { homeUrl } = useSelect( ( select ) => { const { @@ -28,6 +37,20 @@ export default function HomeEdit( { attributes, setAttributes, clientId } ) { [ clientId ] ); + const { textColor, backgroundColor, style } = context; + const blockProps = useBlockProps( { + className: classnames( { + 'has-text-color': !! textColor || !! style?.color?.text, + [ `has-${ textColor }-color` ]: !! textColor, + 'has-background': !! backgroundColor || !! style?.color?.background, + [ `has-${ backgroundColor }-background-color` ]: !! backgroundColor, + } ), + style: { + color: style?.color?.text, + backgroundColor: style?.color?.background, + }, + } ); + const { label, opensInNewTab, rel, title } = attributes; useEffect( () => { diff --git a/packages/block-library/src/home-link/index.php b/packages/block-library/src/home-link/index.php index f4d5b5145005c..5e3734abe19f9 100644 --- a/packages/block-library/src/home-link/index.php +++ b/packages/block-library/src/home-link/index.php @@ -1,25 +1,137 @@ array(), + 'inline_styles' => '', + ); + + // Text color. + $has_named_text_color = array_key_exists( 'textColor', $context ); + $has_custom_text_color = isset( $context['style']['color']['text'] ); + + // If has text color. + if ( $has_custom_text_color || $has_named_text_color ) { + // Add has-text-color class. + $colors['css_classes'][] = 'has-text-color'; + } + + if ( $has_named_text_color ) { + // Add the color class. + $colors['css_classes'][] = sprintf( 'has-%s-color', $context['textColor'] ); + } elseif ( $has_custom_text_color ) { + // Add the custom color inline style. + $colors['inline_styles'] .= sprintf( 'color: %s;', $context['style']['color']['text'] ); + } + + // Background color. + $has_named_background_color = array_key_exists( 'backgroundColor', $context ); + $has_custom_background_color = isset( $context['style']['color']['background'] ); + + // If has background color. + if ( $has_custom_background_color || $has_named_background_color ) { + // Add has-background class. + $colors['css_classes'][] = 'has-background'; + } + + if ( $has_named_background_color ) { + // Add the background-color class. + $colors['css_classes'][] = sprintf( 'has-%s-background-color', $context['backgroundColor'] ); + } elseif ( $has_custom_background_color ) { + // Add the custom background-color inline style. + $colors['inline_styles'] .= sprintf( 'background-color: %s;', $context['style']['color']['background'] ); + } + + return $colors; +} + +/** + * Build an array with CSS classes and inline styles defining the font sizes + * which will be applied to the home link markup in the front-end. + * + * @param array $context Home link block context. + * @return array Font size CSS classes and inline styles. + */ +function block_core_home_link_build_css_font_sizes( $context ) { + // CSS classes. + $font_sizes = array( + 'css_classes' => array(), + 'inline_styles' => '', + ); + + $has_named_font_size = array_key_exists( 'fontSize', $context ); + $has_custom_font_size = isset( $context['style']['typography']['fontSize'] ); + + if ( $has_named_font_size ) { + // Add the font size class. + $font_sizes['css_classes'][] = sprintf( 'has-%s-font-size', $context['fontSize'] ); + } elseif ( $has_custom_font_size ) { + // Add the custom font size inline style. + $font_sizes['inline_styles'] = sprintf( 'font-size: %spx;', $context['style']['typography']['fontSize'] ); + } + + return $font_sizes; +} + +/** + * Builds an array with classes and style for the li wrapper + * + * @param array $context Home link block context. + * @param array $attributes Home link block attributes. + * @return array The li wrapper attributes. + */ +function block_core_home_link_build_li_wrapper_attributes( $context, $attributes ) { + $colors = block_core_home_link_build_css_colors( $context ); + $font_sizes = block_core_home_link_build_css_font_sizes( $context ); + $classes = array_merge( + $colors['css_classes'], + $font_sizes['css_classes'] + ); + $style_attribute = ( $colors['inline_styles'] . $font_sizes['inline_styles'] ); + $css_classes = trim( implode( ' ', $classes ) ); + $class_name = ! empty( $attributes['className'] ) ? implode( ' ', (array) $attributes['className'] ) : false; + if ( false !== $class_name ) { + $css_classes .= ' ' . $class_name; + } + + $wrapper_attributes = get_block_wrapper_attributes( + array( + 'class' => $css_classes, + 'style' => $style_attribute, + ) + ); + return $wrapper_attributes; +} /** * Renders the `core/home-link` block. * * @param array $attributes The block attributes. + * @param array $content The saved content. + * @param array $block The parsed block. * * @return string Returns the post content with the home url added. */ -function render_block_core_home( $attributes ) { +function render_block_core_home( $attributes, $content, $block ) { if ( empty( $attributes['label'] ) ) { return ''; } - $classnames = array(); - if ( ! empty( $attributes['className'] ) ) { - $classnames[] = $attributes['className']; - } - - $wrapper_attributes = get_block_wrapper_attributes( array( 'class' => implode( ' ', $classnames ) ) ); + $wrapper_attributes = block_core_home_link_build_li_wrapper_attributes( $block->context, $attributes ); - $html = '
  • diff --git a/packages/e2e-tests/fixtures/blocks/core__home-link.json b/packages/e2e-tests/fixtures/blocks/core__home-link.json new file mode 100644 index 0000000000000..f17ee4ad61313 --- /dev/null +++ b/packages/e2e-tests/fixtures/blocks/core__home-link.json @@ -0,0 +1,15 @@ +[ + { + "clientId": "_clientId_0", + "name": "core/home-link", + "isValid": true, + "attributes": { + "label": "Home", + "opensInNewTab": true, + "rel": "nofollow", + "title": "title" + }, + "innerBlocks": [], + "originalContent": "" + } +] diff --git a/packages/e2e-tests/fixtures/blocks/core__home-link.parsed.json b/packages/e2e-tests/fixtures/blocks/core__home-link.parsed.json new file mode 100644 index 0000000000000..9d26ee6aeb40f --- /dev/null +++ b/packages/e2e-tests/fixtures/blocks/core__home-link.parsed.json @@ -0,0 +1,14 @@ +[ + { + "blockName": "core/home-link", + "attrs": { + "label": "Home", + "opensInNewTab": true, + "rel": "nofollow", + "title": "title" + }, + "innerBlocks": [], + "innerHTML": "", + "innerContent": [] + } +] diff --git a/packages/e2e-tests/fixtures/blocks/core__home-link.serialized.html b/packages/e2e-tests/fixtures/blocks/core__home-link.serialized.html new file mode 100644 index 0000000000000..7a861ad5b6a88 --- /dev/null +++ b/packages/e2e-tests/fixtures/blocks/core__home-link.serialized.html @@ -0,0 +1 @@ + From 7855aee6c52fbd67354abb8bdcf8ae731ff83c34 Mon Sep 17 00:00:00 2001 From: jasmussen Date: Tue, 4 May 2021 11:49:35 +0200 Subject: [PATCH 05/12] A little polish. --- packages/block-library/src/home-link/edit.js | 3 +-- packages/block-library/src/home-link/index.js | 2 +- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/packages/block-library/src/home-link/edit.js b/packages/block-library/src/home-link/edit.js index c21c0d72710e0..6680a763b9613 100644 --- a/packages/block-library/src/home-link/edit.js +++ b/packages/block-library/src/home-link/edit.js @@ -62,14 +62,13 @@ export default function HomeEdit( { return ( <> - + { setAttributes( { opensInNewTab: ! opensInNewTab } ); } } - help={ __( 'Opens the home link in a new tab' ) } /> Date: Tue, 4 May 2021 11:32:08 -0700 Subject: [PATCH 06/12] Move home link translation strings to block.json add link to reading options --- packages/block-library/src/home-link/block.json | 3 +++ packages/block-library/src/home-link/index.js | 15 ++++++++------- 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/packages/block-library/src/home-link/block.json b/packages/block-library/src/home-link/block.json index c43a896852835..b8bd5146b530a 100644 --- a/packages/block-library/src/home-link/block.json +++ b/packages/block-library/src/home-link/block.json @@ -3,6 +3,9 @@ "name": "core/home-link", "category": "design", "parent": [ "core/navigation" ], + "title": "Home Link", + "keywords": [ "home", "menu", "navigation" ], + "textdomain": "default", "attributes": { "label": { "type": "string" diff --git a/packages/block-library/src/home-link/index.js b/packages/block-library/src/home-link/index.js index b178596f10b94..71e084b48d963 100644 --- a/packages/block-library/src/home-link/index.js +++ b/packages/block-library/src/home-link/index.js @@ -1,8 +1,10 @@ /** * WordPress dependencies */ -import { __, _x } from '@wordpress/i18n'; +import { _x } from '@wordpress/i18n'; import { home } from '@wordpress/icons'; +import { createInterpolateElement } from '@wordpress/element'; +import { ExternalLink } from '@wordpress/components'; /** * Internal dependencies @@ -16,13 +18,12 @@ const { name } = metadata; export { metadata, name }; export const settings = { - title: _x( 'Home Link', 'block title' ), - icon: home, - description: __( 'Link to your homepage.' ), - - keywords: [ __( 'home' ), __( 'menu' ), __( 'navigation' ) ], + description: createInterpolateElement( + _x( 'Link to your homepage.', 'block description' ), + { a: } + ), edit, @@ -30,7 +31,7 @@ export const settings = { example: { attributes: { - label: _x( 'Home', 'Home Link preview example' ), + label: _x( 'Home Link', 'block example' ), }, }, }; From c3b705467912fdef2538966c93114075e949cb5a Mon Sep 17 00:00:00 2001 From: Kerry Liu Date: Tue, 4 May 2021 11:33:20 -0700 Subject: [PATCH 07/12] remove period --- packages/block-library/src/home-link/index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/block-library/src/home-link/index.js b/packages/block-library/src/home-link/index.js index 71e084b48d963..2ee1bd70da3db 100644 --- a/packages/block-library/src/home-link/index.js +++ b/packages/block-library/src/home-link/index.js @@ -21,7 +21,7 @@ export const settings = { icon: home, description: createInterpolateElement( - _x( 'Link to your homepage.', 'block description' ), + _x( 'Link to your homepage', 'block description' ), { a: } ), From 179666306c603da513e14f91d1a52d4b5621817d Mon Sep 17 00:00:00 2001 From: Kerry Liu Date: Tue, 4 May 2021 12:25:10 -0700 Subject: [PATCH 08/12] add home link settings inline instead of in panel body --- packages/block-library/src/editor.scss | 1 + packages/block-library/src/home-link/edit.js | 11 +++++++---- packages/block-library/src/home-link/editor.scss | 9 +++++++++ packages/block-library/src/style.scss | 1 + 4 files changed, 18 insertions(+), 4 deletions(-) create mode 100644 packages/block-library/src/home-link/editor.scss diff --git a/packages/block-library/src/editor.scss b/packages/block-library/src/editor.scss index cef09dbb86549..31ee0ec856d8b 100644 --- a/packages/block-library/src/editor.scss +++ b/packages/block-library/src/editor.scss @@ -25,6 +25,7 @@ @import "./more/editor.scss"; @import "./navigation/editor.scss"; @import "./navigation-link/editor.scss"; +@import "./home-link/editor.scss"; @import "./nextpage/editor.scss"; @import "./page-list/editor.scss"; @import "./paragraph/editor.scss"; diff --git a/packages/block-library/src/home-link/edit.js b/packages/block-library/src/home-link/edit.js index 6680a763b9613..b0051bddb3e75 100644 --- a/packages/block-library/src/home-link/edit.js +++ b/packages/block-library/src/home-link/edit.js @@ -11,11 +11,11 @@ import { useBlockProps, InspectorControls, } from '@wordpress/block-editor'; -import { __ } from '@wordpress/i18n'; +import { __, _x } from '@wordpress/i18n'; import { useSelect } from '@wordpress/data'; import { store as coreStore } from '@wordpress/core-data'; import { useEffect } from '@wordpress/element'; -import { PanelBody, TextControl, ToggleControl } from '@wordpress/components'; +import { TextControl, ToggleControl } from '@wordpress/components'; const preventDefault = ( event ) => event.preventDefault(); @@ -62,7 +62,10 @@ export default function HomeEdit( { return ( <> - +
    +

    + { _x( 'Settings', 'Home link settings' ) } +

    - +
  • Date: Tue, 4 May 2021 12:53:00 -0700 Subject: [PATCH 09/12] do not add custom class twice --- packages/block-library/src/home-link/index.php | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/packages/block-library/src/home-link/index.php b/packages/block-library/src/home-link/index.php index 5e3734abe19f9..e0ef303504c09 100644 --- a/packages/block-library/src/home-link/index.php +++ b/packages/block-library/src/home-link/index.php @@ -89,10 +89,9 @@ function block_core_home_link_build_css_font_sizes( $context ) { * Builds an array with classes and style for the li wrapper * * @param array $context Home link block context. - * @param array $attributes Home link block attributes. * @return array The li wrapper attributes. */ -function block_core_home_link_build_li_wrapper_attributes( $context, $attributes ) { +function block_core_home_link_build_li_wrapper_attributes( $context ) { $colors = block_core_home_link_build_css_colors( $context ); $font_sizes = block_core_home_link_build_css_font_sizes( $context ); $classes = array_merge( @@ -101,10 +100,6 @@ function block_core_home_link_build_li_wrapper_attributes( $context, $attributes ); $style_attribute = ( $colors['inline_styles'] . $font_sizes['inline_styles'] ); $css_classes = trim( implode( ' ', $classes ) ); - $class_name = ! empty( $attributes['className'] ) ? implode( ' ', (array) $attributes['className'] ) : false; - if ( false !== $class_name ) { - $css_classes .= ' ' . $class_name; - } $wrapper_attributes = get_block_wrapper_attributes( array( @@ -112,6 +107,7 @@ function block_core_home_link_build_li_wrapper_attributes( $context, $attributes 'style' => $style_attribute, ) ); + return $wrapper_attributes; } @@ -129,7 +125,7 @@ function render_block_core_home( $attributes, $content, $block ) { return ''; } - $wrapper_attributes = block_core_home_link_build_li_wrapper_attributes( $block->context, $attributes ); + $wrapper_attributes = block_core_home_link_build_li_wrapper_attributes( $block->context ); $html = '
  • Date: Wed, 5 May 2021 11:01:04 -0700 Subject: [PATCH 10/12] remove title and rel fields --- .../block-library/src/home-link/block.json | 7 ------- packages/block-library/src/home-link/edit.js | 20 ++----------------- packages/block-library/src/home-link/index.js | 7 ++++--- .../fixtures/blocks/core__home-link.html | 2 +- .../fixtures/blocks/core__home-link.json | 4 +--- .../blocks/core__home-link.parsed.json | 4 +--- .../blocks/core__home-link.serialized.html | 2 +- 7 files changed, 10 insertions(+), 36 deletions(-) diff --git a/packages/block-library/src/home-link/block.json b/packages/block-library/src/home-link/block.json index b8bd5146b530a..544e209ab530c 100644 --- a/packages/block-library/src/home-link/block.json +++ b/packages/block-library/src/home-link/block.json @@ -4,7 +4,6 @@ "category": "design", "parent": [ "core/navigation" ], "title": "Home Link", - "keywords": [ "home", "menu", "navigation" ], "textdomain": "default", "attributes": { "label": { @@ -13,12 +12,6 @@ "opensInNewTab": { "type": "boolean", "default": false - }, - "rel": { - "type": "string" - }, - "title": { - "type": "string" } }, "usesContext": [ diff --git a/packages/block-library/src/home-link/edit.js b/packages/block-library/src/home-link/edit.js index b0051bddb3e75..9bdc9a3a390d1 100644 --- a/packages/block-library/src/home-link/edit.js +++ b/packages/block-library/src/home-link/edit.js @@ -15,7 +15,7 @@ import { __, _x } from '@wordpress/i18n'; import { useSelect } from '@wordpress/data'; import { store as coreStore } from '@wordpress/core-data'; import { useEffect } from '@wordpress/element'; -import { TextControl, ToggleControl } from '@wordpress/components'; +import { ToggleControl } from '@wordpress/components'; const preventDefault = ( event ) => event.preventDefault(); @@ -51,7 +51,7 @@ export default function HomeEdit( { }, } ); - const { label, opensInNewTab, rel, title } = attributes; + const { label, opensInNewTab } = attributes; useEffect( () => { if ( label === undefined ) { @@ -73,22 +73,6 @@ export default function HomeEdit( { setAttributes( { opensInNewTab: ! opensInNewTab } ); } } /> - { - setAttributes( { title: titleValue } ); - } } - label={ __( 'Link title' ) } - autoComplete="off" - /> - { - setAttributes( { rel: relValue } ); - } } - label={ __( 'Link rel' ) } - autoComplete="off" - />
  • diff --git a/packages/block-library/src/home-link/index.js b/packages/block-library/src/home-link/index.js index 2ee1bd70da3db..26c4228179c1c 100644 --- a/packages/block-library/src/home-link/index.js +++ b/packages/block-library/src/home-link/index.js @@ -4,7 +4,6 @@ import { _x } from '@wordpress/i18n'; import { home } from '@wordpress/icons'; import { createInterpolateElement } from '@wordpress/element'; -import { ExternalLink } from '@wordpress/components'; /** * Internal dependencies @@ -21,8 +20,10 @@ export const settings = { icon: home, description: createInterpolateElement( - _x( 'Link to your homepage', 'block description' ), - { a: } + _x( 'Link to your homepage.', 'block description' ), + //TODO: slot/fill to override link + // eslint-disable-next-line jsx-a11y/anchor-has-content + { a: } ), edit, diff --git a/packages/e2e-tests/fixtures/blocks/core__home-link.html b/packages/e2e-tests/fixtures/blocks/core__home-link.html index 7a861ad5b6a88..cba810356d4cb 100644 --- a/packages/e2e-tests/fixtures/blocks/core__home-link.html +++ b/packages/e2e-tests/fixtures/blocks/core__home-link.html @@ -1 +1 @@ - + diff --git a/packages/e2e-tests/fixtures/blocks/core__home-link.json b/packages/e2e-tests/fixtures/blocks/core__home-link.json index f17ee4ad61313..ff4835d9a1c5b 100644 --- a/packages/e2e-tests/fixtures/blocks/core__home-link.json +++ b/packages/e2e-tests/fixtures/blocks/core__home-link.json @@ -5,9 +5,7 @@ "isValid": true, "attributes": { "label": "Home", - "opensInNewTab": true, - "rel": "nofollow", - "title": "title" + "opensInNewTab": false }, "innerBlocks": [], "originalContent": "" diff --git a/packages/e2e-tests/fixtures/blocks/core__home-link.parsed.json b/packages/e2e-tests/fixtures/blocks/core__home-link.parsed.json index 9d26ee6aeb40f..c8e3e255ed2d8 100644 --- a/packages/e2e-tests/fixtures/blocks/core__home-link.parsed.json +++ b/packages/e2e-tests/fixtures/blocks/core__home-link.parsed.json @@ -3,9 +3,7 @@ "blockName": "core/home-link", "attrs": { "label": "Home", - "opensInNewTab": true, - "rel": "nofollow", - "title": "title" + "opensInNewTab": false }, "innerBlocks": [], "innerHTML": "", diff --git a/packages/e2e-tests/fixtures/blocks/core__home-link.serialized.html b/packages/e2e-tests/fixtures/blocks/core__home-link.serialized.html index 7a861ad5b6a88..cba810356d4cb 100644 --- a/packages/e2e-tests/fixtures/blocks/core__home-link.serialized.html +++ b/packages/e2e-tests/fixtures/blocks/core__home-link.serialized.html @@ -1 +1 @@ - + From f01992c8fd9323e00076ebf3581c48d3c63c1e57 Mon Sep 17 00:00:00 2001 From: Kerry Liu Date: Wed, 5 May 2021 13:52:36 -0700 Subject: [PATCH 11/12] remove open in new tab, back out link to settings --- packages/block-library/src/editor.scss | 1 - .../block-library/src/home-link/block.json | 5 +--- packages/block-library/src/home-link/edit.js | 25 +++---------------- .../block-library/src/home-link/editor.scss | 9 ------- packages/block-library/src/home-link/index.js | 8 ------ .../block-library/src/home-link/index.php | 12 --------- .../fixtures/blocks/core__home-link.html | 2 +- .../fixtures/blocks/core__home-link.json | 3 +-- .../blocks/core__home-link.parsed.json | 3 +-- .../blocks/core__home-link.serialized.html | 2 +- 10 files changed, 8 insertions(+), 62 deletions(-) delete mode 100644 packages/block-library/src/home-link/editor.scss diff --git a/packages/block-library/src/editor.scss b/packages/block-library/src/editor.scss index 31ee0ec856d8b..cef09dbb86549 100644 --- a/packages/block-library/src/editor.scss +++ b/packages/block-library/src/editor.scss @@ -25,7 +25,6 @@ @import "./more/editor.scss"; @import "./navigation/editor.scss"; @import "./navigation-link/editor.scss"; -@import "./home-link/editor.scss"; @import "./nextpage/editor.scss"; @import "./page-list/editor.scss"; @import "./paragraph/editor.scss"; diff --git a/packages/block-library/src/home-link/block.json b/packages/block-library/src/home-link/block.json index 544e209ab530c..42cea69c7aaf7 100644 --- a/packages/block-library/src/home-link/block.json +++ b/packages/block-library/src/home-link/block.json @@ -4,14 +4,11 @@ "category": "design", "parent": [ "core/navigation" ], "title": "Home Link", + "description": "Create a link that always points to the homepage of the site. Usually not necessary if there is already a site title link present in the header.", "textdomain": "default", "attributes": { "label": { "type": "string" - }, - "opensInNewTab": { - "type": "boolean", - "default": false } }, "usesContext": [ diff --git a/packages/block-library/src/home-link/edit.js b/packages/block-library/src/home-link/edit.js index 9bdc9a3a390d1..85571c518c862 100644 --- a/packages/block-library/src/home-link/edit.js +++ b/packages/block-library/src/home-link/edit.js @@ -6,16 +6,11 @@ import classnames from 'classnames'; /** * WordPress dependencies */ -import { - RichText, - useBlockProps, - InspectorControls, -} from '@wordpress/block-editor'; -import { __, _x } from '@wordpress/i18n'; +import { RichText, useBlockProps } from '@wordpress/block-editor'; +import { __ } from '@wordpress/i18n'; import { useSelect } from '@wordpress/data'; import { store as coreStore } from '@wordpress/core-data'; import { useEffect } from '@wordpress/element'; -import { ToggleControl } from '@wordpress/components'; const preventDefault = ( event ) => event.preventDefault(); @@ -51,7 +46,7 @@ export default function HomeEdit( { }, } ); - const { label, opensInNewTab } = attributes; + const { label } = attributes; useEffect( () => { if ( label === undefined ) { @@ -61,20 +56,6 @@ export default function HomeEdit( { return ( <> - -
    -

    - { _x( 'Settings', 'Home link settings' ) } -

    - { - setAttributes( { opensInNewTab: ! opensInNewTab } ); - } } - /> -
    -
  • your homepage.', 'block description' ), - //TODO: slot/fill to override link - // eslint-disable-next-line jsx-a11y/anchor-has-content - { a: } - ), - edit, save, diff --git a/packages/block-library/src/home-link/index.php b/packages/block-library/src/home-link/index.php index e0ef303504c09..9de6b5d59bf9c 100644 --- a/packages/block-library/src/home-link/index.php +++ b/packages/block-library/src/home-link/index.php @@ -132,18 +132,6 @@ function render_block_core_home( $attributes, $content, $block ) { // Start appending HTML attributes to anchor tag. $html .= ' href="' . esc_url( home_url() ) . '"'; - if ( isset( $attributes['opensInNewTab'] ) && true === $attributes['opensInNewTab'] ) { - $html .= ' target="_blank" '; - } - - if ( isset( $attributes['rel'] ) ) { - $html .= ' rel="' . esc_attr( $attributes['rel'] ) . '"'; - } - - if ( isset( $attributes['title'] ) ) { - $html .= ' title="' . esc_attr( $attributes['title'] ) . '"'; - } - // End appending HTML attributes to anchor tag. $html .= '>'; diff --git a/packages/e2e-tests/fixtures/blocks/core__home-link.html b/packages/e2e-tests/fixtures/blocks/core__home-link.html index cba810356d4cb..e1564a33298ae 100644 --- a/packages/e2e-tests/fixtures/blocks/core__home-link.html +++ b/packages/e2e-tests/fixtures/blocks/core__home-link.html @@ -1 +1 @@ - + diff --git a/packages/e2e-tests/fixtures/blocks/core__home-link.json b/packages/e2e-tests/fixtures/blocks/core__home-link.json index ff4835d9a1c5b..1a2c5fc0c6c5d 100644 --- a/packages/e2e-tests/fixtures/blocks/core__home-link.json +++ b/packages/e2e-tests/fixtures/blocks/core__home-link.json @@ -4,8 +4,7 @@ "name": "core/home-link", "isValid": true, "attributes": { - "label": "Home", - "opensInNewTab": false + "label": "Home" }, "innerBlocks": [], "originalContent": "" diff --git a/packages/e2e-tests/fixtures/blocks/core__home-link.parsed.json b/packages/e2e-tests/fixtures/blocks/core__home-link.parsed.json index c8e3e255ed2d8..7dee324f4fd40 100644 --- a/packages/e2e-tests/fixtures/blocks/core__home-link.parsed.json +++ b/packages/e2e-tests/fixtures/blocks/core__home-link.parsed.json @@ -2,8 +2,7 @@ { "blockName": "core/home-link", "attrs": { - "label": "Home", - "opensInNewTab": false + "label": "Home" }, "innerBlocks": [], "innerHTML": "", diff --git a/packages/e2e-tests/fixtures/blocks/core__home-link.serialized.html b/packages/e2e-tests/fixtures/blocks/core__home-link.serialized.html index cba810356d4cb..e1564a33298ae 100644 --- a/packages/e2e-tests/fixtures/blocks/core__home-link.serialized.html +++ b/packages/e2e-tests/fixtures/blocks/core__home-link.serialized.html @@ -1 +1 @@ - + From 10b9f65ab13fafad3794f30baefa5e147d6c3a9a Mon Sep 17 00:00:00 2001 From: Kerry Liu Date: Thu, 6 May 2021 09:01:38 -0700 Subject: [PATCH 12/12] update function names from _home to home_link --- packages/block-library/src/home-link/index.php | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/packages/block-library/src/home-link/index.php b/packages/block-library/src/home-link/index.php index 9de6b5d59bf9c..eafd27461c097 100644 --- a/packages/block-library/src/home-link/index.php +++ b/packages/block-library/src/home-link/index.php @@ -120,7 +120,7 @@ function block_core_home_link_build_li_wrapper_attributes( $context ) { * * @return string Returns the post content with the home url added. */ -function render_block_core_home( $attributes, $content, $block ) { +function render_block_core_home_link( $attributes, $content, $block ) { if ( empty( $attributes['label'] ) ) { return ''; } @@ -164,15 +164,15 @@ function render_block_core_home( $attributes, $content, $block ) { /** * Register the home block * - * @uses render_block_core_home() + * @uses render_block_core_home_link() * @throws WP_Error An WP_Error exception parsing the block definition. */ -function register_block_core_home() { +function register_block_core_home_link() { register_block_type_from_metadata( __DIR__ . '/home-link', array( - 'render_callback' => 'render_block_core_home', + 'render_callback' => 'render_block_core_home_link', ) ); } -add_action( 'init', 'register_block_core_home' ); +add_action( 'init', 'register_block_core_home_link' );