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 / junction-fix.php
Created June 22, 2012 10:15
WP Junction fix
<?php
/*
Plugin Name: Junction fixes for plugins
Plugin URI: http://interconnectit.com/
Description: Junctioning files into the WordPess plug-ins folder causes problems with php 5.3 for plugin_url, this tries to fix it. Place in the wp-content/mu-plugins folder so it loads before all other plugins.
Author: James R Whitehead
Version: 0.0.0.0.0.0.2
Author URI: http://interconnectit.com
*/
@tomjn
tomjn / gist:3425191
Created August 22, 2012 12:39
GDocs Spreadsheet Check WordPress Sites for Updates
function getWPVersion(url){
var newurl = url + "/readme.html";
var hdoc = null;
try{
hdoc = UrlFetchApp.fetch(newurl);
if(hdoc.getResponseCode() != 200){
return "Cannot retrieve version";
}
}catch(e){
return "Cannot retrieve version";
@tomjn
tomjn / typekit.editor.php
Created September 10, 2012 10:22
Typekit fonts for TinyMCE editor plugin
add_filter("mce_external_plugins", "tomjn_mce_external_plugins");
function tomjn_mce_external_plugins($plugin_array){
$plugin_array['typekit'] = get_template_directory_uri().'/typekit.tinymce.js';
return $plugin_array;
}
@tomjn
tomjn / gist:3871705
Created October 11, 2012 11:19
PHP Levenshtein distance methods
class Example {
public function length(){
return 5;
}
public function __call($name,$arguments){
$methods = get_class_methods($this);
$ldist = 9999;
$currmethod = $name;
foreach($methods as $m){
$distance = levenshtein($name,$m);
@tomjn
tomjn / notify-on-media.php
Created October 18, 2012 12:15
WP - Notify via Email on creation of Attachment
<?php
/*
Plugin Name: Notify on Attachment Creation
Plugin URI: http://www.tomjn.com
Description: Send a notification when an attachment is created
Version: 1.04
Author: Tom J Nowell
Author URI: http://www.tomjn.com
*/
@tomjn
tomjn / sellwirecsv.php
Last active October 13, 2015 04:07
Grab product orders from Sellwire in PHP
require 'PHP-Browser/browser.class.php';
function get_sellwire_csv( $username, $password, $project_id ) {
$browser = new Browser( 'SellWire Browser' );
$browser->navigate( 'http://app.sellwire.net/logout' );
$browser->navigate( 'http://app.sellwire.net/login' );
$form = $browser->getForm( '//form[@method]' );
$form->setAction( 'http://app.sellwire.net/login' );
$form->setAttributeByName( 'username', $username )->setAttributeByName( 'password', $password );
@tomjn
tomjn / gist:4148899
Created November 26, 2012 15:51 — forked from jmdodd/gist:4055427
Set Twitter language for WordPress oEmbeds
global $wp_version;
if ( version_compare( $wp_version, '3.5', 'ge' ) ) {
if ( !function_exists( 'ucc_oembed_twitter_lang' ) ) {
function ucc_oembed_twitter_lang( $provider, $url, $args ) {
if ( stripos( $url, 'twitter.com' ) ) {
if ( defined( 'WPLANG' ) )
$lang = strtolower( WPLANG );
if ( empty( $lang ) )
$lang = 'en';
@tomjn
tomjn / remove_jetpack_menu_order.php
Last active December 9, 2015 22:18
Disables Jetpacks menu reordering code
<?php
/*
Plugin Name: Jetpack Menu Weight
Plugin URI: http://tomjn.com
Description: Fixes the broken Jetpack menu reordering by removing it
Author: Tom J Nowell
Contributors: TJNowell
Version: 1.0
Author URI: http://tomjn.com
*/
@tomjn
tomjn / gist:4551786
Last active December 11, 2015 05:19
hmmm initialise in the loop start, loop_end shouldn't ever be called without loop_start
<?php
add_action( 'loop_start', 'qd_loop_start' );
add_action( 'loop_end', 'qd_loop_end' );
function qd_loop_start( $query ) {
global $query_depth;
if(!isset($query_depth)){
$query_depth = 0;
}
@tomjn
tomjn / gist:4593910
Created January 22, 2013 11:21
Displaying html5 audio controls in WordPress
<audio controls>
<source src="<?php echo wp_get_attachment_url(); ?>" type="<?php echo get_post_mime_type(); ?>">
Your browser does not support the audio tag.
</audio>