php

  • 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…

  • 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…

  • A service layer is where the fat controller was going anyway

    Business logic in a controller is reachable from exactly one place: an HTTP request. The first time the same operation is needed from a console command, a queue…

  • array_walk_recursive for nested structures

    Applying a transformation to every scalar in a nested array — trimming decoded JSON, casting numeric strings — usually produces a small recursive function that gets copied between…

  • Hooking woocommerce_before_calculate_totals for dynamic pricing

    Changing a price by filtering woocommerce_get_price alters it everywhere at once, including the catalogue and the order confirmation email — and it fires often enough to be a…

  • A Redis cache layer that does not go stale

    The cache made it fast and made it wrong. Key design, invalidation on write rather than on a timer, and why KEYS is the command that takes the…

  • composer.lock belongs in version control for applications

    The rule is not “always commit the lock file” — it depends on what the package is. An application is deployed, so it wants the exact versions that…

  • the_content filter order decides who wins

    Everything that touches post output hangs off the same filter — autoembeds, wpautop, shortcode expansion, and every plugin. Priority decides the order, and getting it wrong is why…

  • iterator_to_array closes the generator gap

    A function returning a generator cannot be passed to anything expecting an array — count(), array_map(), json_encode() all fail or produce nonsense. iterator_to_array() is the escape hatch, and…

  • WooCommerce checkout field order is a filter, not a template edit

    Reordering the checkout form by copying form-billing.php into the theme works and then quietly rots: every WooCommerce release that touches that template leaves your copy behind, and the…