mirror of
https://github.com/WordPress/WordPress.git
synced 2024-08-25 23:33:22 +02:00
This introduces the Block Bindings API for WordPress. The API allows developers to connects block attributes to different sources. In this PR, two such sources are included: "post meta" and "pattern". Attributes connected to sources can have their HTML replaced by values coming from the source in a way defined by the binding. Props czapla, lgladdy, gziolo, sc0ttkclark, swissspidy, artemiosans, kevin940726, fabiankaegy, santosguillamot, talldanwp, wildworks. Fixes #60282. Built from https://develop.svn.wordpress.org/trunk@57514 git-svn-id: http://core.svn.wordpress.org/trunk@57015 1a063a9b-81f0-0310-95a4-ce76da25c4cd
35 lines
990 B
PHP
35 lines
990 B
PHP
<?php
|
|
/**
|
|
* The "pattern" source for the Block Bindings API. This source is used by the
|
|
* Pattern Overrides.
|
|
*
|
|
* @since 6.5.0
|
|
* @package WordPress
|
|
*/
|
|
function pattern_source_callback( $source_attrs, $block_instance, $attribute_name ) {
|
|
if ( ! _wp_array_get( $block_instance->attributes, array( 'metadata', 'id' ), false ) ) {
|
|
return null;
|
|
}
|
|
$block_id = $block_instance->attributes['metadata']['id'];
|
|
return _wp_array_get( $block_instance->context, array( 'pattern/overrides', $block_id, $attribute_name ), null );
|
|
}
|
|
|
|
|
|
/**
|
|
* Registers the "pattern" source for the Block Bindings API.
|
|
*
|
|
* @access private
|
|
* @since 6.5.0
|
|
*/
|
|
function _register_block_bindings_pattern_overrides_source() {
|
|
register_block_bindings_source(
|
|
'core/pattern-overrides',
|
|
array(
|
|
'label' => _x( 'Pattern Overrides', 'block bindings source' ),
|
|
'get_value_callback' => 'pattern_source_callback',
|
|
)
|
|
);
|
|
}
|
|
|
|
add_action( 'init', '_register_block_bindings_pattern_overrides_source' );
|