Skip to content

Instantly share code, notes, and snippets.

#!/bin/bash
# iterate-by-date.sh - A template script for looping through days/months/years and running a command that takes
# before and after arguments.
#
# Usage: ./iterate-by-date.sh [iterate_by] [start_date] [end_date]
#
# Options:
# - iterate_by: The granularity of the operation - day, month or year (default: day).
# - start_date: The start date for the operation in YYYY-MM-DD format (default: 30 days ago).
@philipjohn
philipjohn / .wp-env.json
Created June 6, 2025 08:31
RawHTML adds a wrapper div when it shouldn't
{
"plugins": [ "." ],
"themes": [ "WordPress/twentytwentyfive" ]
}
@philipjohn
philipjohn / core-post-template.js
Created May 19, 2025 09:47
Attempting to override the core/query and core/post-template WordPress blocks
/**
* WordPress dependencies
*/
import { unregisterBlockVariation, registerBlockVariation } from '@wordpress/blocks'
import { addFilter } from '@wordpress/hooks';
import { registerPlugin } from '@wordpress/plugins';
import { select, subscribe } from '@wordpress/data';
/**
* Internal dependencies
@philipjohn
philipjohn / watch_sync.sh
Last active May 6, 2025 09:57
Watch the current folder for changes and sync them to somewhere
# USAGE: watch_sync [destination_folder]
# Watch and sync a folder
watch_sync() {
# The first and only argument is the folder to sync to.
TO=$(echo "$1" | sed 's/\/$//')
# We assume the current folder is the one to sync from.
FROM=$(pwd)
# Delete all users with a role of "subscriber" from a WordPress database.
#
# Assumes the `wp_` table prefix
DELETE FROM wp_users WHERE ID IN ( SELECT user_id FROM wp_usermeta WHERE meta_key = 'wp_capabilities' AND meta_value LIKE '%subscriber%' );
DELETE FROM wp_usermeta WHERE user_id IN ( SELECT user_id FROM wp_usermeta WHERE meta_key = 'wp_capabilities' AND meta_value LIKE '%subscriber%' );
@philipjohn
philipjohn / scroll-snap.html
Created October 12, 2022 08:58
Testing scroll snap
<html>
<head>
<title>Scroll Snap</title>
<style type="text/css">
* {
box-sizing: border-box;
}
.scroll-container {
max-height: 100vh;
overflow-y: scroll;
<?php
/*
Migrate from WP User Avatar to Simple Local Avatars
Allows sites to easily move away from the WP User Avatar plugin and switch to Simple Local Avatars instead.
Run by invoking with WP CLI like so:
`wp eval-file migrate-wp-user-avatar.php`
Author: Philip John
@philipjohn
philipjohn / rename-comments.php
Created October 1, 2019 12:04
Rename Comments PoC
<?php
/**
* Plugin Name: Rename Comments
* Description: Provides themes with the ability to allow users to rename comments.
* Version: 0.1.0
* Author: Philip John, Automattic
* Author URI: https://automattic.com
* Text Domain: rename-comments
* Domain Path: /languages
@philipjohn
philipjohn / time-to-publish.php
Created September 25, 2018 13:05
A WordPress plugin for tracking the time to publish for posts.
<?php
/*
Plugin Name: Time to Publish
Plugin URI: https://vip.wordpress.com
Description: Track "Time to Publish" on your WordPress site.
Version: 0.1.0
Author: WordPress.com VIP
Author URI: http://vip.wordpress.com
Text Domain: time_to_publish
Domain Path: /languages
add_filter( 'pre_update_option', 'll_kill_frontend_rewrite_rules_update', 10, 3 );
function ll_kill_frontend_rewrite_rules_update( $value, $option, $old_value ) {
// We're only concerned with the rewrite rules option.
if ( 'rewrite_rules' !== $option ) {
return $value;
}
// We want to concentrate on frontend requests only.
if ( ! is_admin() && ! is_user_logged_in() ) {