Skip to content

Commit

Permalink
Merge pull request #113 from 10up/feature/pattern-registration
Browse files Browse the repository at this point in the history
Update Pattern Registration flow in theme to use `patterns` directory
  • Loading branch information
fabiankaegy authored May 25, 2022
2 parents 2d120d6 + a103ba3 commit bedbc20
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 25 deletions.
30 changes: 5 additions & 25 deletions themes/10up-theme/includes/blocks.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ function setup() {

add_action( 'init', $n( 'register_theme_blocks' ) );

add_action( 'init', $n( 'block_patterns_and_categories' ) );
add_action( 'init', $n( 'register_block_pattern_categories' ) );

/*
If you are using the block library, remove the blocks you don't need.
Expand Down Expand Up @@ -152,37 +152,17 @@ function blocks_categories( $categories ) {
}

/**
* Manage block patterns and block pattern categories
* Register block pattern categories
*
* @see https://developer.wordpress.org/block-editor/reference-guides/block-api/block-patterns/
*
* @return void
*/
function block_patterns_and_categories() {
/*
## Examples
// Register block pattern
register_block_pattern(
'tenup/block-pattern',
array(
'title' => __( 'Two buttons', 'tenup' ),
'description' => _x( 'Two horizontal buttons, the left button is filled in, and the right button is outlined.', 'Block pattern description', 'wpdocs-my-plugin' ),
'content' => "<!-- wp:buttons {\"align\":\"center\"} -->\n<div class=\"wp-block-buttons aligncenter\"><!-- wp:button {\"backgroundColor\":\"very-dark-gray\",\"borderRadius\":0} -->\n<div class=\"wp-block-button\"><a class=\"wp-block-button__link has-background has-very-dark-gray-background-color no-border-radius\">" . esc_html__( 'Button One', 'wpdocs-my-plugin' ) . "</a></div>\n<!-- /wp:button -->\n\n<!-- wp:button {\"textColor\":\"very-dark-gray\",\"borderRadius\":0,\"className\":\"is-style-outline\"} -->\n<div class=\"wp-block-button is-style-outline\"><a class=\"wp-block-button__link has-text-color has-very-dark-gray-color no-border-radius\">" . esc_html__( 'Button Two', 'wpdocs-my-plugin' ) . "</a></div>\n<!-- /wp:button --></div>\n<!-- /wp:buttons -->",
)
);
// Unregister a block pattern
unregister_block_pattern( 'tenup/block-pattern' );
function register_block_pattern_categories() {

// Register a block pattern category
register_block_pattern_category(
'client-name',
array( 'label' => __( 'Client Name', 'tenup' ) )
'10up-theme',
[ 'label' => __( '10up Theme', 'tenup' ) ]
);
// Unregister a block pattern category
unregister_block_pattern('client-name')
*/
}
13 changes: 13 additions & 0 deletions themes/10up-theme/patterns/example-pattern.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?php
/**
* Title: Example Pattern
* Slug: tenup-theme/example
* Categories: 10up-theme
*
* @package TenUpTheme
*/

?>
<!-- wp:heading -->
<h2>Example Pattern</h2>
<!-- /wp:heading -->

0 comments on commit bedbc20

Please sign in to comment.