Uncategorized

  • wc_get_product exists so you stop using get_post

    A WooCommerce product is a post, so get_post() returns something usable and the price is right there in the meta. It is also wrong for variable products, where…

  • Moving a legacy PHP application onto Composer and PSR-4

    Two hundred and forty require_once calls where load order was load-bearing, moved onto an autoloader one namespace at a time without a big-bang rewrite.

  • srcset serves the right image without JavaScript

    Responsive images used to mean shipping the desktop file to everyone, or swapping src after load — which downloads both. srcset hands the browser the candidates and lets…

  • setUp runs per test; setUpBeforeClass runs once

    PHPUnit builds a fresh instance of the test class for every test method, so anything assigned in setUp() is rebuilt each time. That isolation is the point, and…

  • Flexbox is finally usable without a prefix stack

    Flexbox went through three incompatible syntaxes on its way to a recommendation, which is why so much production CSS still carries display: -webkit-box next to display: -ms-flexbox. As…

  • phpunit –filter is faster than commenting tests out

    Chasing one failure through a suite that takes four minutes usually ends with the other tests commented out — and one of them staying commented out, which nobody…

  • Array.from converts anything iterable

    Converting a NodeList or an arguments object into a real array has been Array.prototype.slice.call(x) for a decade — an incantation that works because of how slice was specified…

  • The leftmost prefix rule decides if your index is used

    A composite index on (a, b, c) is usable by a query filtering on a, on a and b, or on all three. It is not usable by…

  • wp_enqueue_script dependencies decide the load order for you

    Printing a <script> tag straight into a template puts it wherever the template happens to run, which is why so many themes have jQuery loaded twice and a…

  • OPcache settings that actually matter in production

    OPcache has shipped with PHP since 5.5 and is disabled in several distribution builds, which means a good number of production servers are compiling every file on every…