Skip to content

Instantly share code, notes, and snippets.

View RadGH's full-sized avatar

Radley Sustaire RadGH

View GitHub Profile
@RadGH
RadGH / quick-user-creds.js
Created April 16, 2014 16:39
Quickly create the same user in multiple WordPress sites
// Bookmarklet:
// javascript:(function()%7Bif%20(%20jQuery('%23createuser').length%20)%20%7Bvar%20previous_creds%20%3D%20prompt('Enter%20previous%20setup%20code%20(or%20click%20enter%20to%20skip)'%2C%20'')%3Bvar%20username%20%3D%20false%3Bvar%20email%20%3D%20false%3Bvar%20password%20%3D%20false%3Bvar%20firstname%20%3D%20false%3Bvar%20lastname%20%3D%20false%3Bvar%20website%20%3D%20false%3Bvar%20role%20%3D%20false%3Bif%20(%20previous_creds%20)%20%7Bvar%20creds%20%3D%20jQuery.parseJSON(%20previous_creds%20)%3Bif%20(%20creds%20)%20%7Busername%20%3D%20creds.username%3Bemail%20%3D%20creds.email%3Bpassword%20%3D%20creds.password%3Bif%20(%20creds.firstname%20)%20firstname%20%3D%20creds.firstname%3Bif%20(%20creds.lastname%20)%20lastname%20%3D%20creds.lastname%3Bif%20(%20creds.website%20)%20website%20%3D%20creds.website%3Bif%20(%20creds.role%20)%20role%20%3D%20creds.role%3B%7D%7Dif%20(%20!previous_creds%20%7C%7C%20!username%20%7C%7C%20!email%20%7C%7C%20!password%20)%20%7Bvar%20username%20%3D%20prompt('(Step%201%2F8)%2
@RadGH
RadGH / ftpbackup.sh
Last active August 29, 2015 14:01
Upload a backup file to external FTP. Delete local copy if successful.
#!/bin/bash
# Upload a backup file to external FTP. Delete local copy if successful.
# CONFIGURATION ----------
LOCALPATH='/path/to/backup'
HOST=''
USER=''
PASS=''
REMOTEPATH='/remote/storage/path'
# RUN PROGRAM ------------
/*
This function allows you to press and drag your mouse over multiple checkboxes to change the state of them all.
It does not toggle, but instead causes any selected values to match the originating element.
Does not support radio buttons or dynamically loaded elements.
Example Usage -- Say you have five checkboxes, with the middle one checked:
[0]
[0]
@RadGH
RadGH / weather.php
Created May 12, 2014 18:31
Get the current temperature and weather summary from Forecast.io, cached results
<?php
$recent_weather = get_transient('recent_weather_widget');
if ( !$recent_weather ) {
$api_key = 'YOUR_API_KEY';
$lat = '44.052303';
$long = '-123.102148';
$cache_duration = 60*30; // seconds
// retrieve weather information from forecast.io
@RadGH
RadGH / cmm_quick_field_syntax.php
Last active August 29, 2015 14:01
Quick matadata group and field declaration for the Custom Metadata Manager plugin.
<?php
/*
Format:
array(
group_key => (
post_type = TYPES,
args = ARGS,
fields = FIELDS,
@RadGH
RadGH / wp-media-browse-button.js
Last active August 29, 2015 14:01
Easily create a media browse button, automatically insert URL, title, thumbnail, alt text, etc. into other inputs automatically.
/*
Rad's WordPress Media Upload Button API
Serves as an easy-to-use relay between your form fields and the media browser.
----------
Example Usage:
Retrieve the image URL and the attachment ID of an image with a single "Browse" button, and display a preview of the selected image.
@RadGH
RadGH / table-to-array.js
Last active August 29, 2015 14:05
Convert pasted Excel/Spreadsheet data to 2d array in JavaScript
// Converts a (user-pasted) string to a 2d array, utilizing line breaks and tabs.
function interpret_table( data ) {
var table = data.split("\n");
for (i in table) {
table[i] = table[i].split("\t");
}
return table;
@RadGH
RadGH / install.php
Last active August 29, 2015 14:16
default install settings for a wordpress install: "Private: Formatting Page"
<?php
/*
* Overwrites the default environment in /wp-admin/includes/upgrade.php.
*
* Originally this function will:
* 1: Create a category titled "Uncategorized"
* 2: Create a post titled "Test Post"
* 3: Create a comment by "Mr WordPress"
* 4: Create a page called "Sample Page"
* 5: Create some widgets for the sidebar
@RadGH
RadGH / friendly_dropdown_menu.js
Last active August 29, 2015 14:18
Keyboard-friendly and intent-friendly dropdown navigation menu using jQuery
/*
Usage:
friendly_dropdown_menu( "container", "item", "link", "submenu", (boolean) );
Demo:
http://codepen.io/RadGH/pen/xboxaw
*/
function friendly_dropdown_menu( container_selector, item_selector, link_selector, submenu_selector, close_toggle ) {
// Use WordPress default nav menu classes if parameters undefined
@RadGH
RadGH / earth-view-download.js
Last active August 29, 2015 14:19
Download images from "Earth View from Google Maps"
// Allows downloading the background image from the "Earth View from Google Maps" extension for Chrome:
// https://chrome.google.com/webstore/detail/earth-view-from-google-ma/bhloflhklmhfpedakmangadcdofhnnoh
//
// HOW TO USE:
// 1. Open a new tab to see your earth view, preferably something you want to download.
// 2. Open the javascript console (Ctrl+Shift+J). Note that the regular inspector may freeze due to the large data-uri, so you must go straight to the javascript console.
// 3. Paste the following code to the console, which will create a download link above the earth icon in the corner:
// 4. Image will open in a new tab when you click the link. You can then save it.
var link = document.createElement('a');