Page Mapping... RIP (When Your Business Case Eliminates a Feature)

So, I had two use cases for this subdomain mapping, and I figured out that one of these use cases isn't relevant, or it is really not relevant in the long term.

As always, business needs determine technical needs, though that can get lost when you're focused on code.

Domain Mapping with Page Mapping

I had one of those mornings and a little bit of the afternoon when I had to dig pretty deep into the code... wrote a lot of code, then trashed most of it.

My goal was to be able to map a subdomain to a page's permalink. This way, I can have map to

Hacking Multisite WordPress' Domain Mapping

I had been using the old WordPress MU Domain Mapping plugin for multisite WordPress, and was pretty happy with it, but unknown to me (because I only started reading WP blogs and groups this past year) WordPress has rolled this feature into the core.

WordPress Customizer selective Refresh and Partials for Multiple Settings

There are several good references about how to set up the Customizer to avoid refreshing the entire page with each change. here, and there's some deeper explanation here. What's not described much is how to map several settings to a single area of the page (called a Partial).

This tutorial will go into updating Partials that use several settings. I assume you have already done the other tutorials.

WP's Backbone-like Templating Language

In yesterday's post, I talked about fixing up old PHP code to be safer.

There's another anti-pattern common in old PHP code, and that's mixing the display logic with the output logic. While some of this is inevitable, nowadays, the rule is to use a templating system like Twig to separate out even small bits of HTML code from the logic.

WordPress does this on the front end via Underscore templates, but configured to use Handlebars-like syntax.

This is a PHP class that does the same thing with PHP.

filter_var? filter_input? No, Use Filter Input Array.

I've been a real nut for filter_var() for years, and have come up with concise ways to use it, but totally missed this other function, which, at first look, seemed a little too specialized.


Well, I was so wrong. This is a great way to filter inputs. I figured this out when I had to fix up some code because it was throwing a zillion "Notice, index foobar not defined." in the error logs.

That's what happens when your legacy code looks like this:

$bar = $_GET['bar'];

all over the place, and it's not defined.


There are a lot of demos and tutorials about incorporating the image uploader and selector, but not much about the other parts of the library. is a blank modal view, which the media modal uses as its default container.

This view is demo'd in the Media Guide, but it's not really discussed elsewhere.

Modal displays the large white box that contains the media manager. Within, it's used only two times.

WordPress Study

I'm studying the library, and Backbone.js. I never really did anything with except toy programs with Backbone - and I didn't really grok it, so now I can learn it... post Angular and post-React. It's going backwards in time, but, still instructive because the Backbone.js idioms are different from the easier-to-use frameworks. Tutorials, and wp.Backbone. Subviews

I'm still working on reading through the WP media code, but found several references that have helped.

Developing admin-ajax.php Handlers with PHPUnit and Curl (WordPress WP)

The typical way I've made AJAX handlers that hook into admin-ajax.php is with Firebug and little bits of Javascript code to exercise the REST API. The problem with this is that you lose all the development code. This note shows how to use PHPUnit to write your code as tests, and develop the REST API using something like test driven development (TDD).

WordPress: How to use get_shortcode_regex()

get_shortcode_regex() (GSR() from now on) is used to parse shortcodes from a post's text.

I was writing a filter to take the post text, parse the shortcodes, and modify them by adding an "id" parameter.

After I spent some time writing a regex to parse the shortcodes, I discovered GSR(). GSR() was better and more complete.

Now I just had to learn to use it - and there weren't any docs.

Let's Review How to Use Shortcodes

You've basically got five ways to use shortcodes:

[[fe-escape] ...

Contemporary PHP Coding

Some of the notes here are really old, and use old practices. This is a rundown of contemporary practices circa 2016. I'm a few years behind, so, it's more like 2013 practices, but, there are still tutorials being written that don't use these better techniques. Get with the times.

Don't set up Apache. Instead use "php -S localhost:8000" to start a local server from the shell. The docroot will be in the current directory, and error logs go to the screen.

Vagrant with WordPress, Provisioned by Ansible

This is a small project that helps you set up a development environment for WordPress, and it's done with Vagrant and Ansible. Vagrant sets up the virtual machine, and Ansible provisions WordPress and its dependencies. It also brings in a theme, and a child theme that has a development environment.

It's based on

Compiling PHP... :(

It's been a few years since I compiled PHP from sources... and "ouch", it's a lot of work. It makes me want to give up, port all the sites to a new OS stack, and deploy that.

Syndicate content