Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update Pattern Registration flow in theme to use patterns directory #113

Merged
merged 2 commits into from
May 25, 2022
Merged
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
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 -->