Category: WordPress snippets

Create different color palettes with Gutenberg

Since Friday I am working on my first Gutenberg project and almost instantly had my first larger problem: the project has two different color palettes for text and background color. Gutenberg, by default, makes it possible to have one color palette. The colors can be modified relatively easy, but the project makes it necessary two have two different palettes. This post shows how to get this working. Continue reading Create different color palettes with Gutenberg

Creating background processes in WordPress

If a PHP script runs, the page loads typically as long as the script needs to finish (or throws an error). That is fine for many cases, but if the script needs to process complex and/or many tasks, that take a few minutes or even hours, it would be nice to put that tasks in the background. This post shows you how to create background processes in WordPress with a library. Continue reading Creating background processes in WordPress

Using the official PHP library for the WooCommerce REST API with basic auth

If a WordPress installation is protected via .htaccess basic auth, the requests against the WooCommerce REST API with the PHP library do not work. I did not find the GitHub issue where someone said that CURL could be used to set the login credentials, but with that information, I found a question and the answers on Stack Overflow, that helped me:

$ch = curl_init();
curl_setopt( $ch, CURLOPT_USERPWD, 'user:password' );

I inserted these two lines at the beginning of my script and replaced user and password with the actual login data. With that, the requests against the protected installation worked.

Change title of customize section

When creating a customize section, you define a title for it. Sometimes it can be useful to change this title during a customize session, for example, to reflect the value of a control, like the GIF shows:

A GIF showing the detail view of a section. When changing a select field, the section title is also updated.

I did not find a solution for that via the Customize JS API, so there was only the way via manipulating the DOM directly. Continue reading Change title of customize section