Skip to content

Instantly share code, notes, and snippets.

View benhuson's full-sized avatar

Ben Huson benhuson

View GitHub Profile
@benhuson
benhuson / manage-orphan-menu-items.php
Created September 2, 2015 13:10
Manage WordPress Orphan Menu Items (drop-in)
<?php
class Manage_Orphan_Menu_Items {
function Manage_Orphan_Menu_Items() {
add_action( 'admin_init', array( $this, 'process_menu_item_delete' ) );
add_action( 'admin_menu', array( $this, 'add_admin_page' ) );
}
function add_admin_page() {
@benhuson
benhuson / how-to-remain-detached.php
Created July 15, 2015 12:19
How to remain detached (when insert a WordPress image into a post)
<?php
/**
* Implement 'wp_ajax_send-attachment-to-editor' to not attach an unattached media item.
*
* In WordPress TRAC 22085 there was a change.
* that caused unattached media files (images) to be attached to posts if they are inserted into the post.
*
* If you don't like this strategy you can disable it using this simple, rather hacky, action hook.
*
@benhuson
benhuson / js-function-exists-test.js
Created July 13, 2015 16:22
Check if JS Function Exists Before Calling
if ( typeof yourFunctionName == 'function' ) {
yourFunctionName();
}
@benhuson
benhuson / wpsc-vargrp-name-desc.php
Created June 2, 2015 18:00
Use WP eCommerce Variation Group description as name
<?php
/**
* WPSC Variation Group Name Display
*
* @param string $name Group name.
* @param WP_Term $group Group term object.
* @return string Group name.
*/
function my_wpsc_vargrp_name( $name, $group ) {
@benhuson
benhuson / jquery-plugin.js
Created April 8, 2015 20:54
jQuery Plugin Starter Template
( function( $ ) {
$.fn.helloWorld = function( options ) {
// Establish our default settings
var settings = $.extend( {
text : 'Hello, World!',
color : null,
fontStyle : null,
complete : null
@benhuson
benhuson / set-100-percent-height.js
Created January 8, 2015 13:40
100% height div across multiple browsers including mobile Safari.
/**
* 100% height div across multiple browsers including mobile Safari.
* http://www.ethanhackett.com/?blog=window-height-100-on-mobile-safari-coding-solution
*/
( function( $, window, undefined ) {
// First check to see if the platform is an iPhone, iPod, iPad (mobile Safari)
if ( /iP/.test( navigator.platform ) && /Safari/i.test( navigator.userAgent ) ) {
var mobileSafari = "Safari";
}
@benhuson
benhuson / htaccess-not-ip-redirect.txt
Last active May 15, 2019 01:26
.htaccess rules for redirecting if IP address does not match.
# Redirect other IP addresses
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
# Single IP Address
RewriteCond %{REMOTE_HOST} !^00.00.00.00
# Multiple IP Addresses
RewriteCond %{REMOTE_HOST} !^(00.00.00.00|00.00.00.00)
RewriteRule .* http://www.example.com/ [R=301,L]
{
"url": "http://example.com/json",
"rates": [
{
"name": "Belgium",
"code": "BE",
"periods": [
{
"effective_from": "1996-01-01",
"rates": {
@benhuson
benhuson / cust-vimeo-oembed
Last active April 18, 2020 23:30
Customise WordPress Vimeo oEmbed
<?php
/**
* Customise WordPress Vimeo oEmbed
* https://developer.vimeo.com/apis/oembed
*/
function my_oembed_fetch_url( $provider, $url, $args ) {
if ( strpos( $provider, 'vimeo.com' ) !== false) {
@benhuson
benhuson / WordPress-jQuery
Created October 9, 2014 08:53
WordPress jQuery Tips
/**
* jQuery Wrapper
*/
( function( $ ) {
// Safe to use $
} )( jQuery );