Referring to the Previous Git Commit

On the command line shell, there is a magic symbol “-” (hyphen). When dealing with streams, it can refer to STDIN or STDOUT. When used in the context of the cd command, the – refers to the previous directory (it is the same as $OLDPWD). So you can switch between two directories by repeatedly entering … Continue reading Referring to the Previous Git Commit

The Definitive Guide To PHP’s isset() And empty()

Check out The Definitive Guide To PHP’s isset() And empty() for a deep dive on these faux-function language constructs.

TL;DR

  • always develop with error reporting turned to 11 (and fix all real errors)
  • always use empty or isset for variables that may legitimately not exist
  • never use empty or isset for variables that should exist

Note: To deal with PHP notices in 3rd-party code, if you can’t contribute fixes upstream you may want to consider using a plugin like Zack Tollman’s Ostrichcize.

it [is] impossible to distinguish between a variable that does not exist and a variable that has the value null. […] Specifically for arrays, there’s an alternative to isset($array['key']) called array_key_exists. This function specifically does what it says: it returns true if an array key exists, regardless of the value of that key. That makes it possible to detect null values in arrays

Note that array_key_exists() is used in WP_Customize_Manager::post_value() for this reason. Since the Customizer’s dirty setting values are encoded as JSON it is possible for a post value to be null (although wp.customize.Value doesn’t directly facilitate seting this value).

/via @Josh412

Sanity check pre-commit hook for SVN

When committing to SVN, “there is no reset button”. You cannot purge the memory of a commit once it has been made in an SVN repo (e.g. a theme on WordPress.com VIP, a plugin in the WordPress.org directory, or even especially WordPress core at develop.svn.wordpress.org). That is, in SVN there is no commit amending, hard … Continue reading Sanity check pre-commit hook for SVN

Git pre-commit hook for WordPress development

As seen previously on this blog, in Contributing to WordPress Core via GitHub and Streamlining Contributions to WordPress Core via GitHub, there are instructions for how to get a Git repo set up for committing patches for WordPress Core. These posts also include instructions for how to set up Travis CI to restrict reporting linting errors to just the scope of the changed lines … Continue reading Git pre-commit hook for WordPress development

Bridging the Customizer and the WP REST API

Update 2017-01-03: This post and associated plugins have been updated for WordPress 4.7. There’s a lot of excitement in the WordPress community about the WP REST API. We’ll be sending a couple representatives to the Day of REST conference coming up at the end of January, and I’ve been long-overdue to do a deep-dive in to the REST … Continue reading Bridging the Customizer and the WP REST API

The Impact of the Customizer at WCPDX

A couple months ago at WordCamp Portland, I gave a talk on “The Impact of the Customizer”: The Customizer is WordPress’s framework for live previewing changes to a site. Live preview gives confidence to those who would otherwise lack it when making a change: it gives freedom to experiment and explore, without a negative “save … Continue reading The Impact of the Customizer at WCPDX

Implementing Selective Refresh in the Customizer

To make the Customizer a great user experience, themes and plugins should implement settings that use the postMessage transport as much as possible. By default, settings get registered with a refresh transport meaning that every change to that setting will trigger a refresh in the preview so that PHP can re-render the preview with the … Continue reading Implementing Selective Refresh in the Customizer