Skip to content
This repository has been archived by the owner on Nov 18, 2024. It is now read-only.

Commit

Permalink
Merge pull request #608 from WordPress/try/post-format-binding
Browse files Browse the repository at this point in the history
Try: Post format binding.

Co-authored-by: juanfra <[email protected]>
Co-authored-by: carolinan <[email protected]>
  • Loading branch information
3 people authored Oct 21, 2024
2 parents 279f71d + 9f18193 commit 345f756
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 0 deletions.
39 changes: 39 additions & 0 deletions functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -117,3 +117,42 @@ function twentytwentyfive_pattern_categories() {
}
endif;
add_action( 'init', 'twentytwentyfive_pattern_categories' );

// Registers block binding sources.
if ( ! function_exists( 'twentytwentyfive_register_block_bindings' ) ) :
/**
* Registers the post format block binding source.
*
* @since Twenty Twenty-Five 1.0
*
* @return void
*/
function twentytwentyfive_register_block_bindings() {
register_block_bindings_source(
'twentytwentyfive/format',
array(
'label' => _x( 'Post format name', 'Label for the block binding placeholder in the editor', 'twentytwentyfive' ),
'get_value_callback' => 'twentytwentyfive_format_binding',
)
);
}
endif;
add_action( 'init', 'twentytwentyfive_register_block_bindings' );

// Registers block binding callback function for the post format name.
if ( ! function_exists( 'twentytwentyfive_format_binding' ) ) :
/**
* Callback function for the post format name block binding source.
*
* @since Twenty Twenty-Five 1.0
*
* @return string|void Post format name, or nothing if the format is 'standard'.
*/
function twentytwentyfive_format_binding() {
$post_format_slug = get_post_format();

if ( $post_format_slug && 'standard' !== $post_format_slug ) {
return get_post_format_string( $post_format_slug );
}
}
endif;
16 changes: 16 additions & 0 deletions patterns/binding-format.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?php
/**
* Title: Post format name
* Slug: twentytwentyfive/binding-format
* Categories: twentytwentyfive_post-format
* Description: Prints the name of the post format with the help of the Block Bindings API.
*
* @package WordPress
* @subpackage Twenty_Twenty_Five
* @since Twenty Twenty-Five 1.0
*/

?>
<!-- wp:paragraph {"metadata":{"bindings":{"content":{"source":"twentytwentyfive/format"}}},"fontSize":"small"} -->
<p class="has-small-font-size"></p>
<!-- /wp:paragraph -->

0 comments on commit 345f756

Please sign in to comment.