When developing code related to the WordPress heartbeat, it is frustrating to make your code changes and then wait for the next heartbeat to occur. You can trigger the WordPress heartbeat in the browser manually to eliminate this delay.
While PHP namespaces allow you to refer to a function in file without using the fully qualified name, there is a catch when adding a WordPress hook or filter. The PHP __NAMESPACE__ magic constant can be helpful in this situation.
Recently on a project I wanted to migrate WordPress users with a certain role to a different role. This is the command I used.
The WordPress block editor (a.k.a. Gutenberg) communicates with the database via the WordPress REST API. We can read and write post meta from within the Gutenberg editor after we enable the specific post meta field in the WordPress REST API.
Code to add a custom column to the WP Admin Posts listing page.
When using a WordPress translation function, e.g. __(), you need to use a hardcoded string (not a variable).
Recently I was talking to another developer about how to detect ‘WP_DEBUG’ being set on a WordPress installation. Here is the code I use.
When creating a block for the WordPress block editor (a.k.a. Gutenberg), I find that most of the documentation is for class components. However, with React hooks we can use functional components. When you need to import ‘useState’ from React, you can do it as follows in a WordPress block.