Skip to content

Instantly share code, notes, and snippets.

View webaware's full-sized avatar

Ross McKay webaware

View GitHub Profile
@webaware
webaware / gist:3830445
Created October 3, 2012 23:01
Example of simple widget for WP Flexible Map plugin
<?php
// drop this code into your theme's functions.php file and edit the array properties below
add_action('widgets_init', 'widgetsInitExampleMap');
function widgetsInitExampleMap() {
register_widget('ExampleMapWidget');
}
@webaware
webaware / gist:3990308
Created October 31, 2012 22:12
Make CSS drop-down menus work on touch devices
// code from blog post:
// http://snippets.webaware.com.au/snippets/make-css-drop-down-menus-work-on-touch-devices/
// this version: 27 November, 2012
// "an attempt to make it work on Windows 8 -- please try and tell me"
// see whether device supports touch events (a bit simplistic, but...)
var hasTouch = ("ontouchstart" in window || ("msMaxTouchPoints" in navigator && navigator.msMaxTouchPoints > 0));
var iOS5 = /iPad|iPod|iPhone/.test(navigator.platform) && "matchMedia" in window;
// hook touch events for drop-down menus
@webaware
webaware / gist:2409958
Created April 17, 2012 23:47
base64 encode email addresses in PHP, and replace with decoded addresses client-side in JavaScript
/*
* I don't like this sort of thing, but I have a client who needs it.
* What I did for them was to put the email address on the page encoded in base64,
* and use client-side script to decode it.
*/
// server-side...
/**
* return HTML for a base64-encoded email link
@webaware
webaware / gist:4333741
Created December 19, 2012 01:56
filter the eWAY invoice reference for a Gravity Form post
<?php
add_filter('gfeway_invoice_ref', 'my_gfeway_invoice_ref', 10, 2);
/**
* filter the eWAY invoice reference for a Gravity Form post
* @param string $ref the reference before filtering
* @param array $form the Gravity Form object
* @return string
*/
function my_gfeway_invoice_ref($ref, $form) {
@webaware
webaware / gist:4964078
Last active December 13, 2015 19:38
Extend WP e-Commerce customer emails to add shipping and billing details. Just drop this into a plugin, or add to your theme's functions.php. Some discussion over at my blog post about extending notification emails in wp-e-commerce -- http://snippets.webaware.com.au/snippets/extend-notification-emails-in-wp-e-commerce/
<?php
/**
* extend WP e-Commerce customer emails to add shipping and billing details
* drop this into a plugin, or add to your theme's functions.php
*/
class WpscExtendCustEmail {
/**
* add filter hooks
*/
public function __construct() {
@webaware
webaware / gist:5882259
Last active December 19, 2015 02:19
replace icons in Social Media Feather plugin with custom icons; see http://wordpress.org/plugins/social-media-feather/
<?php
/*
* replace icons in Social Media Feather with custom icons
* @ref: http://wordpress.org/plugins/social-media-feather/
*/
add_filter('synved_social_skin_image_list', 'custom_social_feather_icons');
function custom_social_feather_icons($image_list) {
@webaware
webaware / gist:7689334
Created November 28, 2013 09:27
quick WordPress snippet for showing what classes have been added to the HTML and BODY elements -- useful for seeing what a tablet or phone gets without messing around with debuggers.
<?php
add_action('wp_print_footer_scripts', function() {
?>
<script>
(function() {
var p = document.createElement("p");
@webaware
webaware / flxmap-valter-kml-map.php
Created December 28, 2013 09:13
Valter wants to centre a KML map in WP Flexible Map; this plugin will do that for a map with id=kml_centred on a post/page with custom field 'flxmap-centre' that has the centre coordinate. e.g. `[flexiblemap id="kml_centred" src="http://goo.gl/pDG8hl" width="100%" zoom="10" maptype="satellite"]`
<?php
/*
Plugin Name: Flxmap Valter KML map
Description: Valter wants to centre/zoom KML maps
Version: 1
Author: WebAware
Author URI: http://wordpress.org/support/topic/testing-sometimes-it-does-not-work?replies=5#post-5040741
*/
add_action('wp_enqueue_scripts', function() {
@webaware
webaware / gf-aussie-address.php
Last active January 4, 2016 05:47 — forked from thewebprincess/gravity-au.php
Australian address fields in Gravity Forms
<?php
/*
Plugin Name: Gravity Forms Aussie Addresses
Plugin URI: https://gist.github.com/webaware/f445808d0475ea0e02f2
Description: Australian address fields in Gravity Forms
Author: thewebprincess
Author URI: https://thewebprincess.com/
Version: 0.0.1
@link https://gist.github.com/thewebprincess/7855509
@webaware
webaware / ofw-referer-hash.php
Created January 4, 2016 23:15
Modify the wp_http_referer to include the hash for an accordian tab for a set of Order Form for WooCommerce forms.
<?php
/**
* append hash to referrer URI
* @param array $attrs
*/
add_action('orderform_woocommerce_form_before', function($attrs) {
// remove any existing hash
$_SERVER['REQUEST_URI'] = preg_replace('/#.*$/', '', $_SERVER['REQUEST_URI']);