Skip to content

Instantly share code, notes, and snippets.

@markhowellsmead
Last active February 18, 2022 14:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save markhowellsmead/f8a771c2f6198e127219697c316b9d71 to your computer and use it in GitHub Desktop.
Save markhowellsmead/f8a771c2f6198e127219697c316b9d71 to your computer and use it in GitHub Desktop.
Register a block pattern using PHP. Fits into the Theme structure of https://github.com/SayHelloGmbH/hello-roots/
<!-- wp:group {"backgroundColor":"secondary","textColor":"primary","layout":{"inherit":true}} -->
<div class="wp-block-group has-primary-color has-secondary-background-color has-text-color has-background">
<!-- wp:media-text -->
<div class="wp-block-media-text alignwide is-stacked-on-mobile">
<figure class="wp-block-media-text__media"></figure>
<div class="wp-block-media-text__content">
<!-- wp:paragraph -->
<p>Lorem ipsum dolor sit amet consectetur adipisicing elit. Officia magni, aut esse aliquam omnis voluptate placeat nemo dolorem totam beatae, ipsa atque veritatis impedit tempora quaerat, perferendis accusamus! Ab, ipsam.</p>
<!-- /wp:paragraph -->
</div>
</div>
<!-- /wp:media-text -->
</div>
<!-- /wp:group -->
<?php
namespace SayHello\Theme\Pattern;
/**
* Manage single block pattern
*
* @author Say Hello GmbH <hello@sayhello.ch>
*/
class GroupWithMediaText
{
public function run()
{
add_filter('init', [$this, 'register']);
}
public function register()
{
ob_start();
get_template_part('partials/patterns/group-with-media-text');
$content = ob_get_contents();
ob_end_clean();
register_block_pattern(
'sht/group-with-media-text',
[
'title' => __('Group with media and text', 'sha'),
'categories' => ['text'],
'content' => $content,
]
);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment