Skip to content

Instantly share code, notes, and snippets.

View webaware's full-sized avatar

Ross McKay webaware

View GitHub Profile
@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:2892517
Created June 8, 2012 00:05
When wp-e-commerce products are shown in an iframe, this will hopefully update the cart widget in the parent page
// example of JavaScript for somewhere on the page
<script>
function myReloadCart() {
form_values = "ajax=true&my_plugin_no_force_load=1"
jQuery.post( 'index.php?wpsc_ajax_action=get_cart', form_values, function(returned_data) {
eval(returned_data);
});
}
</script>
@webaware
webaware / gist:2999934
Created June 26, 2012 22:59
Using WordPress custom fields to drive WP Flexible Maps
<?php
/*
In reply to this request:
http://wordpress.org/support/topic/plugin-wp-flexible-map-updating-the-map-from-custom-field-data
add a simple [map] shortcode to WordPress that allows maps to be
created from custom fields:
"map zoom" = the zoom level (will default to 12 if not set)
@webaware
webaware / gist:3110728
Created July 14, 2012 11:25
basic example of populating a form from a database using AJAX and JSON
<?php
/*
-- the SQL database table
create table form_ajax (
ID varchar(5) not null,
Name varchar(100),
Address varchar(100),
Phone varchar(20),
Email varchar(255),
@webaware
webaware / gist:3368517
Created August 16, 2012 08:55
kludge to make WordPress' Google Sitemap Generator exclude Page Links To pages linking to PDF files
<?php
function filterSitemapOptions($opts) {
global $wpdb;
// tell it to exclude any pages that are just page-links-to links to PDF files
$exclude = $wpdb->get_col("select post_id from $wpdb->postmeta where meta_key = '_links_to' and meta_value like '%.pdf'");
if (!empty($exclude)) {
$opts['sm_b_exclude'] = array_merge($opts['sm_b_exclude'], $exclude);
}
@webaware
webaware / gist:3808642
Created September 30, 2012 22:41
filter the eWAY invoice description for a Gravity Form post
<?php
/**
* filter the eWAY invoice description for a Gravity Form post
* @param string $desc the description before filtering
* @param array $form the Gravity Form object
* @return string
*/
function my_gfeway_invoice_desc($desc, $form) {
// set by form ID
switch ($form['id']) {
@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:4048580
Created November 9, 2012 22:02
basic example of populating a form from a database using AJAX and JSON, jQuery version
<?php
// jQuery version of https://gist.github.com/3110728
/*
-- the SQL database table
create table form_ajax (
ID varchar(5) not null,
Name varchar(100),
Address varchar(100),
@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) {