Skip to content

Instantly share code, notes, and snippets.

View RadGH's full-sized avatar

Radley Sustaire RadGH

View GitHub Profile
@RadGH
RadGH / phone-number.php
Last active May 31, 2023 08:00
Convert user-inputted phone number to consistently formatted HTML link, with extension support
<?php
// improved version: https://gist.github.com/RadGH/31f16cd4705a2d8076021a9ad528f34f
// ----------
// Example #1: HTML
$phone_number = '555.123.4567';
echo format_phone( $phone_number );
@RadGH
RadGH / wordpress-tinymce.js
Last active October 21, 2022 01:21
Get/Set content of a TinyMCE visual or text editor with JavaScript
/*
Based on: http://wordpress.stackexchange.com/questions/42652/#answer-42729
These functions provide a simple way to interact with TinyMCE (wp_editor) visual editor.
This is the same thing that WordPress does, but a tad more intuitive.
Additionally, this works for any editor - not just the "content" editor.
Usage:
@RadGH
RadGH / woocommerce-custom-cart-item-data.php
Last active April 27, 2024 17:25
Get and set custom cart item/product information prior to WooCommerce checkout, and carry those valus over to Order Item Metadata.
<?php
// UPDATE: Stefan from Stack Overflow has explained a better way to handle cart item data.
// See http://stackoverflow.com/a/32327810/470480
// ----------------------
/*
Instructions:
@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 / debug_log.js
Last active July 6, 2017 21:37
Cross-browser console.log, warnings, info, and errors supported
// EXAMPLE USAGE IN A COMMENT BELOW.
/*
Rad's Debug Console:
A safe-to-use JavaScript logging tool which can be disabled by setting window.error_log to false
@Thanks http://stackoverflow.com/questions/26554807
log( [mixed] )
log.__log( [mixed] )
Displays the value of one or more arguments in the developer's console.
@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');
@RadGH
RadGH / gtarating.js
Last active August 29, 2015 14:24
Add ratings to GTA5 Social Club map browser (List view only)
var ratingToInt = function( str ) {
// numstr = ' 18.6k '
str = str.trim(); // "18.6k"
var number = parseFloat(str); // 18.6
var letter = str.replace(/[^kmb]/g, '');//"k"
switch( letter ) {
case 'k':
number = number * 1000;
@RadGH
RadGH / gta5rating-bookmarklet.js
Last active August 29, 2015 14:24
GTA5 Social Club Rating Bookmarklet
javascript:(function(e,a,g,h,f,c,b,d){if(!(f=e.jQuery)||g>f.fn.jquery||h(f)){c=a.createElement("script");c.type="text/javascript";c.src="http://ajax.googleapis.com/ajax/libs/jquery/"+g+"/jquery.min.js";c.onload=c.onreadystatechange=function(){if(!b&&(!(d=this.readyState)||d=="loaded"||d=="complete")){h((f=e.jQuery).noConflict(1),b=1);f(c).remove()}};a.documentElement.childNodes[0].appendChild(c)}})(window,document,"1.3.2",function($,L){var ratingToInt=function(t){t=t.trim();var e=parseFloat(t),i=t.replace(/[^kmb]/g,"");switch(i){case"k":e=1e3*e;break;case"m":e=1e6*e}return parseInt(e)},ratingsGetValues=function(t){var e=t.children("li");if(e.length<3)return!1;var i={up:ratingToInt(e.eq(0).text()),down:ratingToInt(e.eq(1).text()),play:ratingToInt(e.eq(2).text())};return i.rating=(i.up-i.down)/i.up,i},updateList=function(){var t=jQuery("#search-results-list"),e=t.find("tr.mission-result-text");e.each(function(){var t=jQuery(this),i=t.find("ul.ratings");if(!(i.find("li.percent").length>0)){var a=ratingsGetValues