Uncategorized

  • use function and use const, not just use for classes

    Namespaced code can import classes with use, but until 5.6 functions and constants had no equivalent. Calling a namespaced function meant either fully qualifying it every time or…

  • SETEX is atomic where SET plus EXPIRE is not

    Writing a cache entry and then setting its TTL is two commands, and the process can die between them. The result is a key with no expiry that…

  • Nonces are not permissions — check both

    A nonce proves the request came from a form your site rendered, recently. It says nothing about whether the person submitting it is allowed to perform the action…

  • wpdb->prepare placeholders are typed, and unquoted

    $wpdb->prepare() looks like sprintf() and behaves differently in the one way that matters: %s adds the surrounding quotes itself. Writing them by hand produces a doubly-quoted value and…

  • utf8 in MySQL is not UTF-8; utf8mb4 is

    MySQL’s utf8 encodes at most three bytes per character. Real UTF-8 needs four for anything above the basic plane, which is where emoji and a good deal of…

  • box-sizing border-box, applied once, globally

    The default box model adds padding and borders outside the width you set, so a column declared at 25% with 10px of padding is not 25% wide. Every…

  • str_getcsv parses a single CSV line without a file handle

    CSV is not a format you should parse with explode() — quoted fields containing the delimiter, and escaped quotes inside those, break it immediately. fgetcsv() handles all of…

  • Transients expire; the object cache does not have to

    The two caching APIs in WordPress look interchangeable and are not. wp_cache_* is per-request by default and lives only for that request unless a persistent backend is installed.…

  • ON DUPLICATE KEY UPDATE is one round trip, not two

    The usual upsert is a SELECT to see whether the row exists and then an INSERT or an UPDATE. That is two round trips, and between them another…

  • nginx location matching is not top to bottom

    Configuration files are read top to bottom, so location blocks look like they are evaluated that way. They are not: nginx picks the longest matching prefix, then lets…