Skip to content

Instantly share code, notes, and snippets.

<?php
/*
Using WordPress as a REST API endpoint (vs AJAX Admin)
-- with caching using the Transient API --
forked from: Pete Nelson @GunGeekATX
1) Create a page called API in WordPres
2) Create a file called page-api.php in your theme directory
3) Build custom endpoints
@iainmcampbell
iainmcampbell / spinner.html
Created February 26, 2015 22:08
SVG Loading Spinner
<div class="loader"></div>
@iainmcampbell
iainmcampbell / visibility-change.js
Created February 2, 2015 21:55
Page Visibility API
var hidden
, visibilityChange
// browser prefixes
if (typeof document.hidden !== "undefined") { // Opera 12.10 and Firefox 18 and later support
hidden = "hidden"
visibilityChange = "visibilitychange"
} else if (typeof document.mozHidden !== "undefined") {
hidden = "mozHidden"
visibilityChange = "mozvisibilitychange"
@iainmcampbell
iainmcampbell / extend.js
Last active August 29, 2015 14:13
JS Object Merge
function extend(){
var output = {},
args = arguments,
l = args.length;
for ( var i = 0; i < l; i++ )
for ( var key in args[i] )
if ( args[i].hasOwnProperty(key) )
output[key] = args[i][key];
return output;
@iainmcampbell
iainmcampbell / share.html
Created January 14, 2015 19:39
Social Media Share Links
<a href="#" class="facebook" onclick="window.open(
'https://www.facebook.com/sharer/sharer.php?u='+encodeURIComponent(location.href),
'facebook-share-dialog','width=626,height=436');return false;">
Facebook
</a>
<a href="#" class="twitter" onclick="window.open(
'http://twitter.com/intent/tweet?url='+encodeURIComponent(location.href),
'twitter-share-dialog','width=626,height=300');return false;">
Twitter
/**************************************************************************
Perlin Noise
from https://gist.github.com/banksean/304522, in angular wrapper
**************************************************************************/
(function(window, angular, undefined){ 'use strict';
@iainmcampbell
iainmcampbell / wordpress-backup.sh
Last active August 29, 2015 14:13
Web Server Remote Backup
#!/bin/bash
# PRE SETUP: create bkpath dir, ie /user/backups. suggested: put this script there.
name="" # set this to the name of the project
bkpath="/var/backups/" # directory to store backups in locally
# Grab a DB dump from the MySQL server -> $bkpath/db/name_YYYY-MM-DD.sql
MYSQLDUMP="$(which mysqldump)"
@iainmcampbell
iainmcampbell / safari-ios.css
Created January 7, 2015 22:11
Responsive SVG
/* have to use intrinsic ratio: http://alistapart.com/article/creating-intrinsic-ratios-for-video */
.svg-container {
width: 100%;
display: block;
height: auto;
position: relative;
padding-top: 100%; // ratio: w/h*100
}
@iainmcampbell
iainmcampbell / acf-image.php
Last active August 29, 2015 14:13
Advanced Custom Fields
<?php
$imageID = get_field('image_field_name'); // set this field to return Image ID
$size = 'full'; // thumbnail, medium, large, full
$img = wp_get_attachment_image_src( $imageID, $size );
if( !empty($image) ):
$url = $img[0];
$width = $img[1];
@iainmcampbell
iainmcampbell / ajax-cached.php
Last active August 29, 2015 14:13
Wordpress Ajax
<?php
add_action('wp_ajax_myajaxfunctionname', 'ajax_myajaxfunctionname');
add_action('wp_ajax_nopriv_myajaxfunctionname', 'ajax_myajaxfunctionname');
function ajax_myajaxfunctionname(){
$var = $_POST['var'];
if( ! isset($var) ) die(1);