Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Add Name with Link markup binding
  • Loading branch information
mikachan committed Sep 16, 2025
commit 5551355cd52f50a2aacd6e556271c78d69b28f5e
10 changes: 9 additions & 1 deletion lib/compat/wordpress-6.9/term-data-block-bindings.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,10 @@
* @param array $source_args Array containing source arguments used to look up the override value.
* Example: array( "key" => "name" ).
* @param WP_Block $block_instance The block instance.
* @param string $attribute_name The name of the attribute being bound.
* @return mixed The value computed for the source.
*/
function gutenberg_block_bindings_term_data_get_value( array $source_args, $block_instance ) {
function gutenberg_block_bindings_term_data_get_value( array $source_args, $block_instance, $attribute_name = '' ) {
if ( empty( $source_args['key'] ) ) {
return null;
}
Expand Down Expand Up @@ -54,6 +55,13 @@ function gutenberg_block_bindings_term_data_get_value( array $source_args, $bloc
case 'link':
return esc_url( get_term_link( $term ) );

case 'nameWithLink':
if ( 'content' === $attribute_name ) {
return '<a href="' . esc_url( get_term_link( $term ) ) . '">' . esc_html( $term->name ) . '</a>';
}
// Return null for non-content attributes.
return null;

case 'slug':
return esc_html( $term->slug );

Expand Down
7 changes: 7 additions & 0 deletions packages/block-editor/src/hooks/block-bindings.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,13 @@ function BlockBindingsPanelMenuContent( { fieldsList, attribute, binding } ) {
.filter(
( [ , args ] ) => args?.type === attributeType
)
.filter( ( [ , args ] ) => {
// Filter out markup for non-content attributes.
if ( args?.markup && attribute !== 'content' ) {
return false;
}
return true;
} )
.map( ( [ key, args ] ) => (
<Menu.RadioItem
key={ key }
Expand Down
19 changes: 14 additions & 5 deletions packages/editor/src/bindings/term-data.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,25 @@ function createDataFields( termDataValues, idValue ) {
value: termDataValues?.name,
type: 'string',
},
slug: {
label: __( 'Slug' ),
value: termDataValues?.slug,
type: 'string',
},
link: {
label: __( 'Link' ),
value: termDataValues?.link,
type: 'string',
},
nameWithLink: {
label: __( 'Name with Link' ),
value:
termDataValues?.name && termDataValues?.link
? `<a href="${ termDataValues.link }">${ termDataValues.name }</a>`
: termDataValues?.nameWithLink,
type: 'string',
markup: true,
},
slug: {
label: __( 'Slug' ),
value: termDataValues?.slug,
type: 'string',
},
description: {
label: __( 'Description' ),
value: termDataValues?.description,
Expand Down
Loading