Skip to content

Instantly share code, notes, and snippets.

Tim Whitlock timwhitlock

Block or report user

Report or block timwhitlock

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@timwhitlock
timwhitlock / rotate-backups.sh
Last active May 16, 2019
Disk backup rotation script
View rotate-backups.sh
#!/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
@timwhitlock
timwhitlock / mongo-insert-bench.php
Created Mar 21, 2019
bulkWrite benchmarks for different write concerns
View mongo-insert-bench.php
<?php
function runTest( MongoDB\Driver\WriteConcern $writeConcern ){
$bulk = new MongoDB\Driver\BulkWrite(['ordered'=>false]);
for( $i = 0; $i < 10000; $i++ ){
$bulk->insert( [
'time' => new MongoDB\BSON\UTCDateTime,
] );
}
@timwhitlock
timwhitlock / loco-translate-webhook.php
Created Nov 15, 2018
Loco Translate Webhook example
View loco-translate-webhook.php
<?php
/*
Plugin Name: Loco Webhook
Description: Monitors changes to PO files during save operations
Author: Tim Whitlock
*/
class LocoWebhook {
private $path;
@timwhitlock
timwhitlock / valencian.php
Created Feb 28, 2018
Forces Loco Translate to display Catalan as Valencian without changing "ca" tag
View valencian.php
<?php
/*
Plugin Name: Valencia variant
Description: Makes "ca" locale appear like "ca-valencia" in Loco Translate
Author: Tim Whitlock
Version: 1.0.0
*/
// Only running for admin screens
@timwhitlock
timwhitlock / buddypress.pot
Last active Feb 10, 2018
POT template for BuddyPress 2.9.3
View buddypress.pot
#, fuzzy
msgid ""
msgstr ""
"Project-Id-Version: BuddyPress 2.9.3\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2018-02-10 15:18+0000\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: \n"
"Language: \n"
@timwhitlock
timwhitlock / preload-ssh2.php
Created May 6, 2017
Ensures custom SSH2 class is loaded before autoloader is triggered by class_exists
View preload-ssh2.php
<?php
/*
Plugin Name: Preload SSH class
Plugin URI: https://wordpress.org/support/topic/conflict-with-ssh-sftp-updater-support-ssh2-fs_method/
Description: Ensures custom SSH2 class is loaded before autoloader is triggered by class_exists
Author: Tim Whitlock
*/
function filter_filesystem_method( $method = '' ){
if( 'ssh2' === $method && ! class_exists('WP_Filesystem_SSH2',false) ){
@timwhitlock
timwhitlock / diable-auto-translation-updates.php
Created Mar 9, 2017
Prevents WordPress from automatically updating translation files in the global languages directory
View diable-auto-translation-updates.php
<?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 Feb 22, 2018
Standalone version of Loco_hooks_LoadHelper
View loco-loader.php
<?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 / get-only-wp-json.php
Created Feb 11, 2017
Disable non-GET requests to WordPress REST API
View get-only-wp-json.php
<?php
/**
* Plugin Name: Disable POSTing to REST API
* Version: 0
*/
add_filter( 'rest_authentication_errors', function( $access = null ){
if( 'GET' !== $_SERVER['REQUEST_METHOD'] ){
return new WP_Error( 'rest_cannot_access', 'Nope', array( 'status' => 405 ) );
}
@timwhitlock
timwhitlock / disable-wp-json.php
Created Feb 11, 2017
Disable WordPress REST API completely
View disable-wp-json.php
<?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 ) );
} );
You can’t perform that action at this time.