Creating your�First Block
Brian Richards / @rzen
Who still needs help with their local setup?
Add Josh’s companion plugin:
Update my companion plugin:
$> cd /app/public/wp-content/plugins/gutendev
$> git pull
$> cd /app/public/wp-content/plugins
$> git clone https://github.com/caldera-learn/alert-block.git
Create required files
Step 1
What we’ll need
Admin-only styles
Front-end (and admin) styles
01-static
assets
block.js
editor.css
style.css
index.php
JS file for powering the block
Base file to register assets
Register the assets
Step 2
What we’re registering
Create the rest of the block
Step 3
What we’re going to do...
Code demo time.
And now for something you’ll really enjoy!
This seems like a lot of work for very little return...
“
— YOU, 30 SECONDS AGO
WP-CLI can accomplish this in 2 commands:
Plus one line of PHP:
$> wp scaffold plugin my-guten-block --skip-tests --activate
Success: Created plugin files.
$> wp scaffold block hello-block --title="Hello, Block!" --dashicon=smiley --category=common --plugin=my-guten-block
Success: Created block 'Hello, Block!'.
require_once plugin_dir_path( __FILE__ ) . '/blocks/hello-block.php';
More goodies
Suddenly things don’t look so bad!
“
— YOU, RIGHT NOW
Let’s make it editable
Step 4
What do we need to change?
Code demo time.
Questions?