Customize Posts v0.5 Released

We’re pleased to announce the v0.5 release of the Customize Posts plugin! Check out my rough release demo video: Key features in this release: Postmeta support A framework for registering postmeta types, adding controls, and previewing changes. Page template Changes to the page template can now be previewed, both in the Customizer and from the edit page admin screen. … Continue reading Customize Posts v0.5 Released

Running PHPUnit tests with VVV and PhpStorm

PhpStorm has excellent out of the box support for running unit tests using the PHPUnit testing framework. It also provides you with great code coverage statistics of your unit tests. The challenge however is getting it setup properly and actually running your WordPress unit tests. On my local development environment, I specifically use VVV and ideally I wanted … Continue reading Running PHPUnit tests with VVV and PhpStorm

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