Skip to content

Instantly share code, notes, and snippets.

View timwhitlock's full-sized avatar

Tim Whitlock timwhitlock

View GitHub Profile
@timwhitlock
timwhitlock / diable-auto-translation-updates.php
Last active April 11, 2024 10:44
Prevents WordPress from automatically updating translation files in the global languages directory
<?php
/*
Plugin Name: Disable auto translation updates
Description: Prevents WordPress from automatically updating translation files in the global languages directory.
Author: Tim Whitlock
Version: 1.0
*/
/**
@timwhitlock
timwhitlock / loco-loader.php
Last active October 17, 2023 17:28
Standalone version of Loco_hooks_LoadHelper
<?php
/*
Plugin Name: Loco Standalone Loader
Description: Mimics Loco_hooks_LoadHelper without dependency on the main plugin
Author: Tim Whitlock
Version: 1.0
*/
new LocoStandaloneLoadHelper;
@timwhitlock
timwhitlock / disable-wp-json.php
Created February 11, 2017 12:39
Disable WordPress REST API completely
<?php
/**
* Plugin Name: Disable REST API
* Version: 0
*/
// completely disable wp-json access
add_filter( 'rest_authentication_errors', function( $access ){
return new WP_Error( 'rest_cannot_access', 'Bye', array( 'status' => 403 ) );
} );
@timwhitlock
timwhitlock / dict.js
Last active January 6, 2021 19:01
Searchable JavaScript Dictionary
/**
* Searchable JavaScript dictionary.
*
* Usage:
* var dict = require('path/to/this').create();
* dict.add( 'somedata', 'Text to index' );
* var items = dict.find('text');
*/
exports.create = function(){
return new Dict;
@timwhitlock
timwhitlock / convert_array_access_braces.php
Last active September 30, 2020 10:55 — forked from theodorejb/convert_array_access_braces.php
Migrate deprecated curly brace array access syntax to bracket syntax. Requires PHP 7.4.
<?php
error_reporting(E_ALL);
$opts = getopt('f:d:rb:', ['ext:', 'php:', 'diff::']);
if ((int)isset($opts['d']) + (int)isset($opts['f']) !== 1) {
$self = basename(__FILE__);
echo <<<EOF
Usage:
php $self -f<php_script> [-b] [--php <path_to_php>] [ --diff [<file>]]
@timwhitlock
timwhitlock / no-widows.php
Created February 2, 2012 16:42
Simple wordpress plug to avoid typographical widows
<?php
/*
Plugin Name: No Widows
Plugin URI: http://timwhitlock.info/
Description: Prevents typographical widows in titles and post body content
Author: Tim Whitlock
Version: 1.0
Author URI: http://timwhitlock.info/
*/
@timwhitlock
timwhitlock / client.php
Last active November 7, 2019 15:09
Simple 0MQ client/server pattern
<?php
// Client: Pings server, gets reply. Exits.
$zmq = new ZMQContext;
$sock = new ZMQSocket( $zmq, ZMQ::SOCKET_REQ );
$sock->connect('tcp://localhost:5555');
echo "Pinging..\n";
$sock->send('Ping');
/* [twhitlock] define some configs before Wordpress can beat our plug-ins to it */
define('WP_CDN_ROOT','http://cdn.timwhitlock.info/wordpress');
define('WP_CONTENT_URL', WP_CDN_ROOT.'/wp-content');
/** Sets up WordPress vars and included files. */
require_once(ABSPATH . 'wp-settings.php');
@timwhitlock
timwhitlock / wp-cdn.php
Created August 21, 2010 11:18
Simple tools for deploying Wordpress assets on a CDN
<?php
/**
Plugin Name: CDN Tools
Plugin URI: http://web.2point1.com/tag/wp-cdn
Description: Simple tool for deploying Wordpress assets on a CDN
Version: 0
Author: Tim Whitlock
Author URI: http://twitter.com/timwhitlock
*/
@timwhitlock
timwhitlock / rotate-backups.sh
Last active May 16, 2019 15:43
Disk backup rotation script
#!/bin/bash
# Rotates disk image backups inside working directory
# Maintains a rolling window of 4 hourly snapshots (uncompressed)
# Plus 7xdays and 6xmonths of older compressed archives
# config
HOURS=4
DAYS=7
MONTHS=6