Rendering Dynamic Gutenberg Blocks in Theme Template Parts

Gutenberg is an ambitious project that aims to completely overhaul the experience of writing content in WordPress.

One of the problems you’ll soon run into when building a block for Gutenberg is that as a block becomes more complex, storing its complete output statically becomes undesirable. If a block contains several fields or its output contains HTML markup, you don’t want to find yourself in a situation where this output needs to be changed at some point in the future and you need to retrospectively apply changes to stored block output in every post.

Gutenberg supports dynamic block rendering so that you can perform more complex output rendering on the fly, without having to store the complete output when the block is saved. This is the same method that shortcodes in WordPress use and allows you to move away from static block output. If you’re building a block for Gutenberg that uses anything more than very simple output, you should consider using dynamic rendering.

You can take this one step further and build a dynamic block for Gutenberg which uses a theme template part for its output. This way, the theme on your site really is in control of its output, regardless of where the block is registered.

Continue reading “Rendering Dynamic Gutenberg Blocks in Theme Template Parts”

A Collection of My Talks

Last updated August 2017.

I’ve given a few talks (mostly about WordPress) in recent months and years, but I haven’t blogged about them in the past. Here’s a list of the talks I’ve given and links to the video recordings and slides when they’re available.

A Deep Dive into the Roles and Capabilities API

Video. Slides.

The user roles and capabilities API is one of the most powerful APIs in WordPress. With it you can giveth, and with it you can taketh away. In this presentation I talk through the basics of roles and capabilities, and go on to explain some of the more advanced and interesting use cases of working with the API.

Continue reading “A Collection of My Talks”

Misleading Code Coverage Reports for Switch Statements

I was recently investigating the code coverage of the map_meta_cap() function in WordPress’ core unit test suite — particularly the large switch statement contained within the function. I was surprised to see that the coverage was higher than I was expecting, because I know for a fact that several meta capabilities aren’t tested.

It turns out there is a subtle code coverage reporting issue for switch statements that allow multiple conditions to trigger one action.

Continue reading “Misleading Code Coverage Reports for Switch Statements”

Git changelog generator

When I’m preparing a new release of one of my plugins, its Git commit history is a great starting point to use when writing the changelog.

Rather than dealing with a bunch of parameters in git log, I use a simple Git alias which generates a plain list of the commit messages between the previous tag and the current HEAD. I can then copy and paste this into my changelog, and go from there.

Continue reading “Git changelog generator”

My Sublime Text 3 Packages

Last updated: September 2015

Blog posts like these (the latest of which is Dominik Schilling’s) have helped me find packages in the past, so I thought it was time I published my own.

I use Sublime Text 3 for the same reason as Dominik. It’s exceptionally fast. One day I will inevitably switch to the free and open source Atom editor, but it’s got a long way to go until it can match ST3’s performance.

Here are the packages I use:

Continue reading “My Sublime Text 3 Packages”