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.

Greasemonkey/Tampermoney Ebay Seller Script to Filter Active LIstings

I wrote another script at Greasyfork. Here's my profile.

This one adds a "filter" feature to the ebay selling list so you can quickly find specific items.

Greasyfork is a repository of scripts for Greasemoney and Tampermoney, web browser extensions that allow you to execute your own Javscript code on any web page.

This means you can create elements, insert them onto the page, and do automate some repetitive tasks.

Export eBay Active Listings as Text (csv)

Go to your active listings.

Set the listing length (at the bottom of the page) to a high number so all your items are listed.

Check off the box that selects all the rows.

Click "Edit" button, to go to the editor that alters multiple items.

Check off the box that selects all the rows.

Under the "Action" menu, select "Export to file". From there you can choose CSV or PDF.

WordPress wp.media Study

I'm studying the wp.media 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.

wp.media Tutorials, and wp.Backbone.Subviews

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

WP Media UI: States, StateMachine, and Frame

(It seems like I got the AJAX server working, at least somewhat. So I needed to implement the editors. This is really difficult because it's all in the wp.media hierarchy, and with keywords like "wp" and "media", it's hard to find the documentation. I have been digging around in the code trying to understand it, and came up with notes, which I'll post occasionally. These are mainly for myself, to review when I need to restart the exploration, but they're posted because someone else might find this useful.)

These are incomplete, and probably incorrect notes.

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).

Encrypting Your Thunderbird Mailbox

This is a two-part howto about encrypting data for Thunderbird. The first part is about Enigmail, a way to encrypt your email messages. The second is about encrypting your entire email storage on your computer.

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] ...

Re: Destructured Objects as Parameters

Re: https://css-tricks.com/new-favorite-es6-toy-destructured-objects-parameters/#more-244951

Since the comments were closed, I'm noting here, that Python figured this out a while back.

Function parameters start with required positional parameters, followed by optional positional parameters, followed by named parameters.

def fun(a, b, c=10, **kwargs):

In JS this would be:

function fun(a, b, c, obj) {
    c = (c === undefined ?

Learning About Kindle Publishing

I'm learning a lot from this excursion into Kindle publishing.

Technical books are higher-value products, so that's good. They don't have a big audience, which is bad.

Giving away the CSS book got 100 takes. I'm giving away a short WordPress book, and it only got 65 takes on the first day, probably due to stiffer competition.

Cookbooks are lower-value products, but take little time to write, and have a much larger audience.

Boost Your Click Through Traffic with Just One Tip (Headlines)

On a lark, I got a marketing ebook and was told to write catchy headlines. Then I got another ebook about writing headlines. So, I'm going to be changing all the headlines on this site, save a few, just to see if it boosts the traffic coming into the site.

What Many Other Books Don't Tell You about CSS


A lot of other books out there don't discuss selector specificity and the Cascade in enough detail. They don't talk about ways to organize your code, either. When you read this ebook, it'll make sense.

Python-Fu: Rename a file to match a caption

This script renames a directory full of XCF files so that the filename is derived from the first line of a layer named "caption".

I wrote this to enhance the file names for Koya Hand Crafts.

Syndicate content