Skip to content

Instantly share code, notes, and snippets.

@colorful-tones
Created October 1, 2024 20:48
Show Gist options
  • Save colorful-tones/b6a2dd85e66dd4adb1d58c0ed1623a61 to your computer and use it in GitHub Desktop.
Save colorful-tones/b6a2dd85e66dd4adb1d58c0ed1623a61 to your computer and use it in GitHub Desktop.
Testing WP 6.7 Block Bindings stuff
<?php
/**
* Testing out WP 6.7 Block Bindings stuff.
*
* @see Block Bindings iteration for WordPress 6.7 #63018
* @link https://github.com/WordPress/gutenberg/issues/63018
*
* @package demo-plugin
*/
/**
* Testing out: Block bindings: UI for connecting bindings #62880
*
* @link https://github.com/WordPress/gutenberg/pull/62880
*/
function demo_register_meta() {
register_meta(
'post',
'demo_image',
array(
'label' => 'Demo Image', // #65099
'show_in_rest' => true,
'single' => true,
'type' => 'string',
'default' => 'https://www.pokemon.com/static-assets/content-assets/cms2/img/pokedex/full/006.png',
)
);
register_meta(
'post',
'demo_text',
array(
'label' => 'Demo text', // #65099
'show_in_rest' => true,
'single' => true,
'type' => 'string',
'default' => 'Demo text is wonderful.',
)
);
}
add_action( 'init', 'demo_register_meta' );
/**
* Testing: Adds a filter to customize the output of a block bindings source. #6839
* https://github.com/WordPress/wordpress-develop/pull/6839
*
* @param mixed $value The computed value for the source.
* @param string $source_name The name of the source.
* @param array $source_args Array containing source arguments used to look up the override value, i.e. { "key": "foo" }.
*
* @return mixed The value of the source.
*/
function filter_demo_text_meta_value( $value, $source_name, $source_args ) {
if ( 'core/post-meta' !== $source_name ) {
return $value;
}
if ( 'demo_text' !== $source_args['key'] ) {
return $value;
}
return 'Demo text is wonderful. 🚀';
}
add_filter( 'block_bindings_source_value', 'filter_demo_text_meta_value', 10, 3 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment