Skip to content

Instantly share code, notes, and snippets.

View timwhitlock's full-sized avatar

Tim Whitlock timwhitlock

View GitHub Profile
@timwhitlock
timwhitlock / mongo-insert-bench.php
Created March 21, 2019 20:35
bulkWrite benchmarks for different write concerns
<?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 / mu-example.php
Created August 20, 2016 11:16
Example of adding an unregistered MU plugin to Loco Translate
<?php
/**
* MU plugins inside directories are not returned in `get_mu_plugins`.
* This filter modifies the array obtained from Wordpress when Loco grabs it.
*
* Note that this filter only runs once per script execution, because the value is cached.
* Define the function *before* Loco Translate plugin is even included by WP.
*/
function add_unregistered_plugins_to_loco( array $plugins ){
@timwhitlock
timwhitlock / loco-translate-webhook.php
Created November 15, 2018 16:34
Loco Translate Webhook example
<?php
/*
Plugin Name: Loco Webhook
Description: Monitors changes to PO files during save operations
Author: Tim Whitlock
*/
class LocoWebhook {
private $path;
@timwhitlock
timwhitlock / abc.mo
Last active June 17, 2018 22:46
Testing Gettext MO hash table compilation in PHP
@timwhitlock
timwhitlock / valencian.php
Created February 28, 2018 13:42
Forces Loco Translate to display Catalan as Valencian without changing "ca" tag
<?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 February 10, 2018 15:31
POT template for BuddyPress 2.9.3
#, 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 / wp-config.php
Last active November 15, 2017 06:09
Enable mysqi driver in Wordpress >= 3.9
<?php
/* wp-config.php */
/* use mysqli driver, WP>=3.9 */
define('WP_USE_EXT_MYSQL', false );
@timwhitlock
timwhitlock / preload-ssh2.php
Created May 6, 2017 10:35
Ensures custom SSH2 class is loaded before autoloader is triggered by class_exists
<?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 / get-only-wp-json.php
Created February 11, 2017 15:00
Disable non-GET requests to WordPress REST API
<?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 ) );
}

Keybase proof

I hereby claim:

  • I am timwhitlock on github.
  • I am timwhitlock (https://keybase.io/timwhitlock) on keybase.
  • I have a public key ASAqRSGF2gFgfMTquG-FBo71hJ229f0ZOlYS8-SbbTp-8Qo

To claim this, I am signing this object: