wordpress

  • Object cache groups, and which ones are global

    On multisite the object cache prefixes keys with the current blog id, so the same key on two sites does not collide. Some groups must not be prefixed…

  • get_option returns false for missing and for false alike

    get_option() returns false when the option does not exist, and also when it exists and holds false. Any setting that can legitimately be off is therefore indistinguishable from…

  • permission_callback is not optional

    Omitting permission_callback registers a route that anyone can call. It works, there is no error, and this year there is not even a warning — the notice that…

  • wc_get_orders is the query you should be using

    Orders are posts, so WP_Query works and every example on the internet uses it — with a post_type of shop_order, a meta query for the customer, and a…

  • One large autoloaded option is on every single request

    The failure mode is not a slow query. It is one option holding a megabyte of serialised data, fetched and unserialised on every request, quietly adding both to…

  • wp_die is the wrong way to fail an AJAX request

    wp_die() in an AJAX handler sends an HTML error page with a 200 status, so the JavaScript sees a successful response containing markup and fails while parsing it.…

  • Order status transitions have hooks of their own

    Hooking save_post to react to an order being paid works occasionally and misses every transition made from a payment gateway callback, the REST API or WP-CLI. The status…

  • wp_cache_add refuses to overwrite; wp_cache_set does not

    The two look interchangeable and differ on whether the key already exists: set() overwrites unconditionally, add() fails and returns false. That failure is the useful part. With a…

  • Turning revisions off for one post type

    WP_POST_REVISIONS is a constant, so it applies to the whole site. A catalogue whose products are updated by a nightly import does not want a revision per product…

  • wp_insert_post fires every hook the editor fires

    An import loop calling wp_insert_post() is doing everything a human clicking Publish does: revisions, term counting, ping status, and every plugin listening on save_post. For ten posts that…