Skip to content

Instantly share code, notes, and snippets.

@joemaller
joemaller / README.md
Last active February 16, 2024 15:00
Fix term counts so wp-admin Taxonomy listings show the correct number of items for the selected post_type.

Fixing post counts for WordPress taxonomies

The problem

For WordPress sites using Custom Post Types, Taxonomy admin listings show cumulative term-assignment totals for all post_types instead of counts specific to the selected post_type. Since Taxonomy listings are always attached to a single post_type, totals for shared taxonomies don't make sense.

The Goal

Fix term counts so wp-admin Taxonomy listings show the correct number of items for the selected post_type.

@joemaller
joemaller / wordpress-wp_rewrite-rule-dump.php
Last active February 12, 2024 12:46
A default dump of WordPress `$wp_rewrite->rules` from a fresh install of WordPress v5.2.3
<?php
array (
'^wp-json/?$' => 'index.php?rest_route=/',
'^wp-json/(.*)?' => 'index.php?rest_route=/$matches[1]',
'^index.php/wp-json/?$' => 'index.php?rest_route=/',
'^index.php/wp-json/(.*)?' => 'index.php?rest_route=/$matches[1]',
'robots\\.txt$' => 'index.php?robots=1',
'.*wp-(atom|rdf|rss|rss2|feed|commentsrss2)\\.php$' => 'index.php?feed=old',
'.*wp-app\\.php(/.*)?$' => 'index.php?error=403',
'.*wp-register.php$' => 'index.php?register=true',
@joemaller
joemaller / call-exec.js
Created January 26, 2024 23:34
Mock child_process.exec in module in Vitest
import { exec } from "node:child_process";
export function callExec() {
return new Promise((resolve, reject) => {
exec(`ls -la`, (error, stdout, stderr) => {
if (error) {
reject(error);
return;
}
if (stdout) {
@joemaller
joemaller / harrassment-training-bot.js
Created October 6, 2022 14:56
bot for helping test online training. Kind of garbage, but maybe useful in the future.
/**
* For ADP's 2022 sexual harrassment training
*/
cr = () => {
const next = $('button.next-button:not(.disabled)')
if (next.length) {
next.click();
}
@joemaller
joemaller / Verizon FiOS - DNS servers.md
Created May 9, 2018 14:49
Nameservers for Verizon FiOS - North East US specific

Boston, MA:

  • nsbost02.verizon.net - 71.243.0.14

New York, NY:

  • nsnyny02.verizon.net - 68.237.161.14

Newark, NJ:

nsnwrk02.verizon.net - 71.250.0.14

Philadelphia, PA:

News to Posts Migration

  1. Update the iop-theme to >2.28.0
  2. Update iop-data-model to >0.4.0
  3. Delete all existing Posts in wp-admin
  4. Change all News posts' post_type to Posts in phpMyAdmin:
    UPDATE `wp_posts` SET `post_type` = 'post' WHERE `post_type` = 'news';
  5. Update permalink Custom Structure to /news/%postname%/
@joemaller
joemaller / crontab
Last active November 2, 2023 13:38
Example cron task for auto-removing old downloads on macOS Big Sur and Catalina
# Cron on modern macOS systems (10.14+) requires Full Disk Access permissions
# in System Preferences->Privacy & Security. To enable this, drag the cron
# binary from /usr/sbin/cron into the Full Disk Access list.
# More here: https://apple.stackexchange.com/a/372810/42898
# https://gist.github.com/joemaller/c4c0a6000ac53c8b1a70ff66c547380a
# Removes downloads older than 14 days. Runs every 6 hours
45 */6 * * * echo "$(date)\nRemoving downloads older than 14 days (cron)" >> /tmp/cron.log
45 */6 * * * find ~/Downloads -maxdepth 1 -mtime +14 -exec du -sh {} \+ | sort -rh >> /tmp/cron.log
46 */6 * * * find ~/Downloads -maxdepth 1 -mtime +14 -exec rm -rf {} \; >> /tmp/cron.log 2>&1
@joemaller
joemaller / setup.sh
Last active October 21, 2023 16:40
Helper script for installing apps on a new Mac
#!/usr/bin/env bash
# Download this file then run:
# % chmod a+x setup.sh
# % ./setup.sh
# Or run directly from this Gist:
# % curl https://gist.githubusercontent.com/joemaller/55aca1bcffe44558cf93527153d6896a/raw/setup.sh | bash
# Install Homebrew first https://brew.sh
set -u

How to run phpcs on WordPress-Develop files without installing PHP

I've been running all my dev projects via Docker to avoid the pitfalls of installing server software on my computer. This also lets me jump between macheines very easily since everything I need is wrapped up in dockerfiles, docker-compose files or package.json scripts.

WordPress development doesn't work like that. The default development environment expects PHP to be installed and will try to run PHPCS validation checks from a local instance of PHP.

Use Composer's Docker image

The official Composer Docker image is extremely versatile. It can run arbitrary shell commands if the passed argument isn't a Composer keyword.

@joemaller
joemaller / wordpress-blocks-min-scripts.md
Last active September 29, 2023 02:41
How WordPress includes minimized script snippets for blocks in use.

WordPress v6.3.1 inlines styles for used blocks via the wp_head hook. However there is an additional wrinkle. If the SCRIPT_DEBUG constant is set and truthy, then a minimized copy of the styles will be inlined. The minimized copy is pre-generated and included with WordPress.

Code for choosing to use the min variant is in wp-includes/blocks.php:

// Check whether styles should have a ".min" suffix or not.
$suffix = SCRIPT_DEBUG ? '' : '.min';
if ( $is_core_block ) {
    $style_path = ( 'editorStyle' === $field_name ) ? "editor{$suffix}.css" : "style{$suffix}.css";
}