Slide 1

Slide 1 text

Three Ways to Extend the WordPress Block Editor Speaker nme Daisy Olsen Developer Relations Wrangler, Automattic

Slide 2

Slide 2 text

Aside: Reusable Blocks

Slide 3

Slide 3 text

A reusable blocks is a block (or multiple blocks) that are saved to allow management from a central location. Changes made to a global block will apply to every instance of the global block across an entire website. What are Reusable Blocks?

Slide 4

Slide 4 text

Block Patterns

Slide 5

Slide 5 text

The Block Patterns feature provides access to a catalog of pre-made patterns (made of blocks) that allow users to easily create and modify engaging layouts for their content. What are Block Patterns?

Slide 6

Slide 6 text

Registering Block Patterns

Slide 7

Slide 7 text

Register Block Pattern Category register_block_pattern_category( 'my-block-patterns',My Block Patterns', 'my-plugin' ) ) );

Slide 8

Slide 8 text

Register Block Pattern register_block_pattern( 'my-plugin/awesome-paragraph-pattern', array( 'title' => __( 'Awesome Paragraph', 'my-plugin' ), 'description' => _x( 'Just a Paragraph Pattern', 'my-plugin' ), 'categories' => array('my-block-patterns'), 'content' => ‘

This is Awesome!

’, ) );

Slide 9

Slide 9 text

Let’s Register a Block Pattern

Slide 10

Slide 10 text

Register Block Pattern function my_register_block_patterns () { if ( class_exists( 'WP_Block_Patterns_Registry' ) ) { register_block_pattern_category( 'my-block-patterns', array('label' => __('Team Page', 'my-plugin')) ); register_block_pattern( 'my-patterns/team-listing', array( 'title' => __( 'Team Listing', 'my-plugin' ), 'description' => _x( 'Team Listing Block Pattern', 'my-plugin' ), 'categories' => array('my-block-patterns'), 'content' => \n
\n
\n

\n\n\n\n\"\"/\n
\n\n\n\n
\n

\n
\n
\n", ) ); } } add_action( 'init', 'my_register_block_patterns' );

Slide 11

Slide 11 text

Block Styles

Slide 12

Slide 12 text

Block Styles allow providing alternative styles to existing blocks. They work by adding a className to the block’s wrapper. This className can be used to provide an alternative styling for the block if the block style is selected in the block settings panel. What are Block Styles?

Slide 13

Slide 13 text

Register Block Style (Server Side Inline Style) function my_register_block_styles () { register_block_style( 'core/quote', array( 'name' => 'my-quote', 'label' => __( 'My Quote Style' ), 'inline_style' => '.wp-block-quote.is-style-my-quote { color: purple; }', ) ); } add_action( 'init', 'my_register_block_styles' );

Slide 14

Slide 14 text

Register Block Style (Server Side w/CSS File) function my_register_block_styles () { wp_register_style( 'myblockstyle', get_template_directory_uri() . '/block-styles.css' ); register_block_style( 'core/quote', array( 'name' => 'my-quote', 'label' => __( 'My Quote Style' ), 'style_handle' => 'myblockstyle', ) ); } add_action( 'init', 'my_register_block_styles' );

Slide 15

Slide 15 text

Register Block Style (CSS File - block-styles.css) .wp-block-quote.is-style-my-quote { color: purple; } .wp-block-quote.is-style-my-quote:before { font-size: 85px; line-height: 1em; font-style: italic; } .wp-block-quote.is-style-my-quote p, .wp-block-quote.is-style-my-quote cite, { padding-left: 45px; }

Slide 16

Slide 16 text

Block Variations

Slide 17

Slide 17 text

Block Variations allow a block to have different versions, all sharing common functionality. Each block variation is differentiated from the others by setting initial attributes or inner blocks. When a block is inserted, the defined attributes and/or inner blocks are applied. What are Block Variations?

Slide 18

Slide 18 text

Register Block Variations function my_editor_assets() { wp_enqueue_script( 'my-block-variations', get_template_directory_uri() . '/block-variations.js', array( 'wp-blocks' ) ); } add_action( 'enqueue_block_editor_assets', 'my_editor_assets' );

Slide 19

Slide 19 text

Register Block Variations (block-variations.js) wp.blocks.registerBlockVariation ( 'core/columns', { name: 'team-listing', title: 'Team Listing', innerBlocks: [ ['core/column', {}, [ ['core/heading', { level: 2, placeholder: 'Enter name' }], ['core/image', { }], ]], ['core/column', {}, [ ['core/paragraph', { placeholder: 'Enter bio’ }], ]], ], } );

Slide 20

Slide 20 text

20 Thank you Daisy Olsen Email: [email protected] Twitter: @daisyolsen WordPress: @daisyo Github: @daisyolsen LinkedIn: linkedin.com/in/daisyolsen/ @wordpressdotorg @wordpress @wordpress https://wordpress.org/