Showing all posts (13)

Gutenberg: how to insert a reusable block in the editor with JavaScript

May 23, 2020

Accessing core blocks and custom made blocks, is pretty straight forward. For example, if you want to get the paragraph block, you could do so with: And if you want to insert a paragraph, you can easily do so with: There’s even a convenient way to get ALL registered blocks as an array with However, … Read More

Gutenberg: how to force sidebar to be always open on post edit screen

May 18, 2020

Add this to your functions.php … Read More

Gutenberg: custom validation / how to prevent post from being saved

May 17, 2020

This script will disable the Publish/Update button: To make the post publishable again, you can do: Very nice. But how is this useful? Here are a couple of use cases. Force users to enter a post title. Let’s say you want to force your users to at least enter a title before they can save … Read More

Gutenberg: Prevent specific block from being removable

May 14, 2020

Ideally, we should use template_lock as much as we possibly can. But with the problems it introduces currently, and because there might be special use cases that template locking cannot handle, I wanted to explore a way to prevent a specific block from being deletable. If you’re comming from a jQuery background (which is likely … Read More

Gutenberg: Problems with template_lock

May 11, 2020

In my previous post, I described a way for developers to create a custom user interface for a specific post type. This approach relies heavily on using template_lock=’all’ in combination with templateLock={false} on some of the child blocks. Problem 1: there’s a warning Each published Book that you try to edit, will show this warning … Read More

Gutenberg: creating an advanced custom admin user interface for your post types with the block editor using template lock.

May 9, 2020

As a freelance developer, I want my clients to have an easy to use interface when creating posts. Before WP 5.0 (and before Gutenberg) I used Advanced Custom Fields a lot for this purpose. An example interface for a Book post, could look something like this: As you can see, I want to add the … Read More

Gutenberg: set category with dispatch

May 6, 2020

Set the category with id termId and post ID currentPostId: Both termID and currentPostId need to be integers. use parseInt to enforce this if necessary. Custom taxonomy Same thing, just use your custom taxonomy slug instead of ‘category’: Set multiple categories If you want to set categories with term ID’s 24, 45 and 87: … Read More

WordPress core development with Xdebug and VS Code

April 19, 2020

I had a bit of a struggle to get Xdebug working with wordpress-develop, but the solution turned out to be very simple. So I’m sharing it here for future reference. … Read More

Dynamically populate a Contact Form 7 dropdown list (or any other input field)

April 16, 2020

With Contact Form 7 the normal way to create a drop down list, looks like this: That’s all very nice, but what if this information tends to change often? You probably have a data source already, be it a web API, an excel sheet, or a simple text file. Wouldn’t it be nice to write … Read More

Gutenberg: custom validation

March 29, 2020

This is a work in progress. The plan is to list all possible validation patterns for custom blocks. At the point of writing it seems like Gutenberg does not provide an out-of-the-box validation mechanism. https://bdwm.be/gutenberg-how-to-make-post-categories-required/ … Read More

Gutenberg: how to make post categories required?

March 28, 2020

This is how: So, what’s happening here? First we get all the currently selected categories with: Then we subscribe to any changes in the data store. If we detect a change in the selected catergories, we check the number of selected categories. If the number is zero, we show an error message with: and we … Read More

Use react in your wordpress plugins

November 6, 2019

Try this: https://github.com/pwkip/wp-simple-react-starter-plugin … Read More

setting up PHPUnit for plugin development on Local by Flywheel

July 16, 2019

Get local by flywheel Add a new local site Custom install PHP 7.3 nginx Mysql 5.6 WP user: admin WP password: admin Go to WP admin Install and activate the plugin you would like to test SSH into the site and run these commands: apt-get update apt-get install curl apt-get install subversion wget -O phpunit … Read More