Skip to content

Instantly share code, notes, and snippets.

View tomjn's full-sized avatar
🎯
Focusing

Tom J Nowell tomjn

🎯
Focusing
View GitHub Profile
@tomjn
tomjn / behave.js
Last active April 17, 2018 19:45
Adds a shortcode to WordPress that lets you test escaping and sanitising functions on content
/*
* Behave.js
*
* Copyright 2013, Jacob Kelley - http://jakiestfu.com/
* Released under the MIT Licence
* http://opensource.org/licenses/MIT
*
* Github: http://github.com/jakiestfu/Behave.js/
* Version: 1.5
*/
@tomjn
tomjn / class.wp-filter-return.php
Last active November 1, 2017 14:45
Easy method of returning or echoing strings on filters and actions
<?php
class WP_Filter_Return {
private $val='';
public function __construct( $val ) {
$this->val = $val;
}
public function display() {
echo $this->val;
}
@tomjn
tomjn / hodor.php
Created April 28, 2015 14:49
Hodor! Hodor hodor hodor, hodor? Hodor!
<?php
/**
* Plugin Name: Hodor Translation Pack
* Description: Hodor hodor hodor. Hodor hodor?
* Version: 1.0
* Author: Tom J Nowell
* Author URI: http://tomjn.com/
* License: GPLv2+
* License URI: http://www.gnu.org/licenses/gpl-2.0.txt
*/
@tomjn
tomjn / loop.php
Created October 21, 2014 16:26
Thinking out loud on functional programming
<?php
global $wp_query;
array_walk( $wp_query->posts, function( $post, $key ) {
setup_postdata( $post );
the_title();
the_content();
});
@tomjn
tomjn / composer.json
Last active August 29, 2015 14:05
Checking if composer ran succesfully after the fact
{
"require": {
"justinrainsdasdfbow/json-schema": "~1.1"
},
"scripts": {
"post-update-cmd": "cftp\\composer_checker::post",
"post-install-cmd": "cftp\\composer_checker::post",
"pre-install-cmd": "cftp\\composer_checker::pre",
"pre-update-cmd": "cftp\\composer_checker::pre"
},
{
"name": "tomjn/composer-webtest",
"description": "tests for web based composer uis",
"license": "GPL-V2.0",
"authors": [
{
"name": "Tom J Nowell",
"email": "contact@tomjn.com"
}
],
#!/bin/bash
# Takes a composer controlled repo and pushes a
# composed PACKAGE into a branch called "PACKAGE".
(
# SANITY CHECKS
# Check for uncommitted changes, and refuse to proceed if there are any
if [ -n "$(git ls-files . --exclude-standard --others)" ]; then
@tomjn
tomjn / gist:8543481
Created January 21, 2014 16:43
Mark Jaquith has a snippet of code at http://markjaquith.wordpress.com/2009/12/14/excluding-your-plugin-or-theme-from-update-checks/ however there is an edge case it misses, causing notices and warnings when wordpress.org cannot be reached. Happens more on local developer and QA environments rather than production but should still be fixed
<?php
/**
* Exclude from official repo update check.
*
* @link http://markjaquith.wordpress.com/2009/12/14/excluding-your-plugin-or-theme-from-update-checks/
*
* @param array $r
* @param string $url
* @return array
@tomjn
tomjn / composer.json
Last active January 3, 2016 13:49
Fixes oEmbedding tweets after Twitter's changes in Jan 2014. To use, download by clicking the "Download Gist" button below, upload to your WordPress site and activate. You will then need to re-save any posts edited or published since the 17 January.
{
"name": "cftp/twitteroembed-hotfix",
"description": "Fixes oEmbedding tweets after Twitter's changes in Jan 2014",
"license": "GPL-2.0+",
"type": "wordpress-plugin",
"authors": [
{
"name": "Tom J Nowell",
"email": "contact@tomjn.com",
"homepage": "http://tomjn.com"
@tomjn
tomjn / jstest.php
Created January 17, 2014 00:36
Add this widget and save, and refresh the page. Once you have done this, look at the dropdown in the widget interface, notice how it responds when clicked. Now add a new JS Test Widget, and notice how the UI of the test widget does not respond. Until the page is refreshed or the save button is pressed, the selectize control is inactive. Also not…
<?php
/*
Plugin Name: JS Test Widget
Description: Tests a frustrating issue
Author: Tom J Nowell
Version: 1.0
License: GPLv2 or later
License URI: http://www.gnu.org/licenses/gpl-2.0.html
*/