wordpress

  • wp-cli commands are classes, and yours can be too

    A maintenance task run through wp eval-file has no arguments, no help, no progress and no exit code worth checking. Registering it as a command costs about ten…

  • The cron event that schedules itself twice

    wp_schedule_event() does not check whether the hook is already scheduled, so calling it on init — which is where it usually ends up — adds another entry on…

  • CRUD objects load lazily, which changes your query count

    A 2.6 product was hydrated from the post and its meta in one pass. A 3.0 product reads what it is asked for, which is usually fewer queries…

  • WooCommerce 3.0 turned products into objects

    Every plugin reading _price from post meta is now reading a private field. The mechanical half, the half that is not, and the compatibility layer for code you…

  • Content filters run in an order plugins fight over

    the_content is a queue every plugin joins, and priority decides the outcome. A shortcode that renders as text, a paragraph tag wrapped around a block element, and an…

  • 4.7 added a settings API for the REST API

    Options registered with register_setting() can now appear on /wp/v2/settings, which turns a plugin’s configuration into something an admin interface elsewhere can read and write without a bespoke endpoint.…

  • wp_json_encode over json_encode, for the charset

    json_encode() returns false on invalid UTF-8 and gives no indication why, which on a site with content pasted from Word is a JSON response that is silently empty.…

  • wp_add_inline_script instead of wp_localize_script

    wp_localize_script() exists to pass translated strings to JavaScript and has been used for everything else because it was the only way to get data across. 4.5 added the…

  • wp-cli –require to load a file before the command

    A one-off maintenance script usually gets written as a file and run with wp eval-file, which works until it needs to define a class or register a command…

  • wp_cache_get with the found flag

    A cached value of false and a cache miss both return false, so a lookup that legitimately caches “no result” re-queries on every request and the cache appears…