Skip to content

Instantly share code, notes, and snippets.

@wpsmith
wpsmith / webfont-localstorage.js
Last active May 10, 2016 15:36 — forked from mattboon/webfont-localstorage.js
webfont-localstorage.js
(function(window, document) {
"use strict";
function supportsWoff2() {
/*global FontFace*/
// Source: https://github.com/filamentgroup/woff2-feature-test
if (!window.FontFace) {
return false;
} else {
var f = new FontFace('t', 'url("data:application/font-woff2,") format("woff2")', {});
@wpsmith
wpsmith / sm-annotated.html
Created October 22, 2015 16:25 — forked from hdragomir/sm-annotated.html
The deferred font loading logic for Smashing Magazine. http://www.smashingmagazine.com/
<script type="text/javascript">
(function () {
"use strict";
// once cached, the css file is stored on the client forever unless
// the URL below is changed. Any change will invalidate the cache
var css_href = './index_files/web-fonts.css';
// a simple event handler wrapper
function on(el, ev, callback) {
if (el.addEventListener) {
el.addEventListener(ev, callback, false);
@wpsmith
wpsmith / high-dpi-media.css
Created October 20, 2015 02:01 — forked from marcedwards/high-dpi-media.css
A CSS media query that captures almost all high DPI aware devices.
/* ---------------------------------------------------------- */
/* */
/* A media query that captures: */
/* */
/* - Retina iOS devices */
/* - Retina Macs running Safari */
/* - High DPI Windows PCs running IE 8 and above */
/* - Low DPI Windows PCs running IE, zoomed in */
/* - Low DPI Windows PCs and Macs running Firefox, zoomed in */
/* - Android hdpi devices and above */
@wpsmith
wpsmith / cmb2-number-field.php
Created October 19, 2015 20:09 — forked from jtsternberg/cmb2-number-field.php
CMB2 Number Field
array(
'name' => __( 'My Number Field', 'theme-domain' ),
'desc' => __( 'Numbers only', 'msft-newscenter' ),
'id' => $prefix . 'number',
'type' => 'text',
'attributes' => array(
'type' => 'number',
'pattern' => '\d*',
),
),
@wpsmith
wpsmith / gsfw-targeted-instance.php
Last active October 13, 2015 16:40 — forked from electricbrick/gsfw-targeted-instance.php
Genesis Sandbox Featured Content Widget - Targeted Instance
<?php
//* Add "See All Videos" Link to Featured Videos
add_action( 'wp_head', 'target_gs_ftd' );
function target_gs_ftd() {
if ( is_active_widget( true, 'featured-content-3', 'featured-content', true ) ) {
add_filter( 'gsfc_after_loop', 'featured_content_3' );
function featured_content_3( $instance ) {
if ( 3 != $instance['custom_field'] ) {
@wpsmith
wpsmith / fbUrlCheck.php
Last active October 9, 2015 12:21 — forked from atomicpages/fbUrlCheck.php
A simple facebook URL checker RegEx for PHP or JavaScript
<?php
/**
* A simple regex to test whether or not a facebook url is valid. For basic usage, this will do the job.
* @see Test cases <http://ideone.com/ZMJp4f>
*/
function fbUrlCheck( $url ) {
if ( preg_match( '/^(https?:\/\/)?(www\.)?facebook.com\/[a-zA-Z0-9(\.\?)?]/', $url ) == 1 && preg_match( '/home((\/)?\.[a-zA-Z0-9])?/', $url ) == 0 ) {
return true;
}
(function($,sr){
// debouncing function from John Hann
// http://unscriptable.com/index.php/2009/03/20/debouncing-javascript-methods/
var debounce = function (func, threshold, execAsap) {
var timeout;
return function debounced () {
var obj = this, args = arguments;
function delayed () {
<?php
/*
* Resize images dynamically using wp built in functions
* @author Victor Teixeira
* @link http://core.trac.wordpress.org/ticket/15311
*
* php 5.2+
*
* Exemple use:
@wpsmith
wpsmith / gist:2d2074edd76fab7d5892
Created October 2, 2015 21:40 — forked from jakubp/gist:2881585
jQuery plugin to remove classes with given prefix
// Remove classes that have given prefix
// Example:
// You have an element with classes "apple juiceSmall juiceBig banana"
// You run:
// $elem.removeClassPrefix('juice');
// The resulting classes are "apple banana"
// NOTE: discussion of implementation techniques for this, including why simple RegExp with word boundaries isn't correct:
// http://stackoverflow.com/questions/57812/jquery-remove-all-classes-that-begin-with-a-certain-string#comment14232343_58533
@wpsmith
wpsmith / gw-gravity-forms-create-coupons.php
Created September 30, 2015 13:36 — forked from spivurno/gw-gravity-forms-create-coupons.php
Gravity Wiz // Gravity Forms // Create Coupons with Gravity Forms for Gravity Forms, WooCommerce, or Easy Digital Downloads
<?php
/**
* Gravity Wiz // Gravity Forms // Create Coupons with Gravity Forms for Gravity Forms, WooCommerce, or Easy Digital Downloads
*
* Create coupons via Gravity Forms submissions. Map the coupon code to a field on the GF form and voila!
*
* @version 1.0
* @author David Smith <david@gravitywiz.com>
* @license GPL-2.0+
* @link WooCommerce: http://gravitywiz.com/creating-coupons-woocommerce-gravity-forms/