Skip to content

Instantly share code, notes, and snippets.

View dannyvankooten's full-sized avatar

Danny van Kooten dannyvankooten

View GitHub Profile
@dannyvankooten
dannyvankooten / compress-images-in-wp-uploads.bash
Created April 26, 2026 06:15
Run all images in wp-content/uploads through lossless compression.
# PNG files: optipng
find wp-content/uploads -name '*.png' -exec optipng {} +
# JPG files: jpegtran
find wp-content/uploads -name '*.jpg' -o -name '*.jpeg' | xargs -I{} jpegtran -copy none -optimize -outfile {} {}
# Webp: cwebp
find wp-content/uploads -name '*.webp' -exec cwebp -lossless {} -o {} \;
# GIF: gifiscle
@dannyvankooten
dannyvankooten / cache-headers.php
Last active April 18, 2026 11:11
WordPress plugin to set HTTP Cache-Control headers on all cache-able requests. Use this in combination with caching at the edge (Bunny CDN, Cloudflare, ...) to make your site fly. Use with caution if your site has dynamic content.
<?php
/*
Plugin Name: Cache Headers
Description: Sets Cache-Control headers on all GET requests for logged-out visitors
Author: Danny van Kooten
Author URI: https://dannyvankooten.com/
Private: True
*/
add_filter('wp_headers', function ($headers) {
@dannyvankooten
dannyvankooten / stop-comment-spam.php
Last active May 2, 2026 15:44
Simple WordPress comment spam block.
<?php
/*
Plugin Name: Stop Comment Spam
Author: Danny van Kooten
Author URI: https://www.dannyvankooten.com/
Private: True
Update URI: https://gist.github.com/dannyvankooten/c6b3e08e0bd4178eca6acd05df18a67a
*/
/**
window.fetch('https://api.wordpress.org/plugins/info/1.2/?action=query_plugins&per_page=500&search=forms').then(r => r.json()).then(d => {
let sortedPlugins = d.plugins.sort((a, b) => a.downloaded < b.downloaded);
console.log("plugins", sortedPlugins);
console.log(sortedPlugins.map(p => `${p.name} (${p.slug}): ${Math.round(p.downloaded/1000)}K downloads`).join("\n"));
});
@dannyvankooten
dannyvankooten / README.md
Last active December 9, 2022 18:58
Delete all of your GitHub gists w/ Python

Delete all of your GitHub gists

  1. Ensure Python3.x and the requests library is installed.
  2. Create a personal access token and give it the gists permission.
  3. Store the access token in the GITHUB_TOKEN environment value
  4. Run the script
python3 delete-gists.py