Skip to content

Instantly share code, notes, and snippets.

@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() ) {
@philipjohn
philipjohn / pj_error_log.function.php
Last active May 12, 2025 12:45
A useful error logging function intended for use with WordPress. Simply add to your wp-config.php, or other non-version controlled PHP file.
<?php
if ( ! defined( 'PJID' ) ) define( 'PJID', uniqid() );
if ( ! defined( 'PJLOG' ) ) define( 'PJLOG', ABSPATH . 'pj.log' );
function pj_error_log(){
// Get line numbers and such
$caller = array_shift( debug_backtrace() );
$prefix = implode( '::', [
PJID,
$caller['file'],
@philipjohn
philipjohn / ascii-for-the-people
Last active August 29, 2015 14:02
ASCII For The People
/* Copyright 2014 Code for the People Ltd
_____________
/ ____ \
_____/ \ \ \
/\ \ \___\ \
/ \ \ \
/ / / _______\
/ / / \ /
/ / / \ /
@philipjohn
philipjohn / post.md
Created May 25, 2014 18:34
Blog post about candidates collab thing wotsit

Collaborating on European Election data in GitHub

On Friday my friend and cracking coder Stuart Harrison, of the Open Data Institute, launched a collaborative project to collate European Parliament 2014 election results for the UK regions using GitHub. As I type I'm waiting for the start of results night so I can help with that project.

Inspired, I spent some of today building something similar to build a list of candidates for the UK General Election in 2015. Through a recent work project I've realised there isn't really a good data source for candidates, and the method Stuart devised for the European election results seemed like a great fit.

Contribute!

You can help build this with me, and all you really need to know is how to create and edit CSV files. I've split the following instructions into developer and non-developer guides to give each a more easy-to-follow set.