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
12 changes: 7 additions & 5 deletions src/wp-includes/block-bindings.php
Original file line number Diff line number Diff line change
Expand Up @@ -140,11 +140,13 @@ function get_block_bindings_source( string $source_name ) {
*/
function get_block_bindings_supported_attributes( $block_type ) {
$block_bindings_supported_attributes = array(
'core/paragraph' => array( 'content' ),
'core/heading' => array( 'content' ),
'core/image' => array( 'id', 'url', 'title', 'alt', 'caption' ),
'core/button' => array( 'url', 'text', 'linkTarget', 'rel' ),
'core/post-date' => array( 'datetime' ),
'core/paragraph' => array( 'content' ),
'core/heading' => array( 'content' ),
'core/image' => array( 'id', 'url', 'title', 'alt', 'caption' ),
'core/button' => array( 'url', 'text', 'linkTarget', 'rel' ),
'core/post-date' => array( 'datetime' ),
'core/navigation-link' => array( 'url' ),
'core/navigation-submenu' => array( 'url' ),
);

$supported_block_attributes =
Expand Down
106 changes: 106 additions & 0 deletions src/wp-includes/block-bindings/entity.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
<?php
/**
* Entity source for the block bindings.
*
* @since 6.9.0
* @package WordPress
* @subpackage Block Bindings
*/

/**
* Gets value for Entity source.
*
* @since 6.9.0
* @access private
*
* @param array $source_args Array containing source arguments used to look up the override value.
* Example: array( "key" => "url" ).
* @param WP_Block $block_instance The block instance.
* @return mixed The value computed for the source.
*/
function _block_bindings_entity_get_value( array $source_args, $block_instance ) {
// Get the key from source args - no key means invalid binding
if ( empty( $source_args['key'] ) ) {
return null;
}

$key = $source_args['key'];

// For now, only support 'url' key
if ( 'url' !== $key ) {
return null;
}

// Read entity data from block attributes
$entity_id = $block_instance->attributes['id'] ?? null;
$type = $block_instance->attributes['type'] ?? '';
$kind = $block_instance->attributes['kind'] ?? '';

if ( empty( $entity_id ) ) {
return null;
}

try {
// Handle post types
if ( 'post-type' === $kind ) {
$post = get_post( $entity_id );
if ( ! $post ) {
return null;
}

$permalink = get_permalink( $entity_id );
if ( is_wp_error( $permalink ) ) {
return null;
}
Comment on lines +52 to +54
Copy link
Member

@mukeshpanchal27 mukeshpanchal27 Oct 4, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The get_permalink() return either string or bool false why we check is_wp_error here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's just an error on my part which we need to fix.


return esc_url( $permalink );
}

// Handle taxonomies
if ( 'taxonomy' === $kind ) {
// Convert 'tag' back to 'post_tag' for API calls
// See update-attributes.js line 166 for the reverse conversion
$taxonomy_slug = ( 'tag' === $type ) ? 'post_tag' : $type;
$term = get_term( $entity_id, $taxonomy_slug );

if ( is_wp_error( $term ) || ! $term ) {
return null;
}

$term_link = get_term_link( $term );
if ( is_wp_error( $term_link ) ) {
return null;
}

return esc_url( $term_link );
}

// Unknown entity kind
return null;
} catch ( Exception $e ) {
return null;
}
}

/**
* Registers Entity source in the block bindings registry.
*
* @since 6.9.0
* @access private
*/
function _register_block_bindings_entity_source() {
if ( get_block_bindings_source( 'core/entity' ) ) {
// The source is already registered.
return;
}

register_block_bindings_source(
'core/entity',
array(
'label' => _x( 'Entity', 'block bindings source' ),
'get_value_callback' => '_block_bindings_entity_get_value',
)
);
}

add_action( 'init', '_register_block_bindings_entity_source' );
Loading