Skip to content

Instantly share code, notes, and snippets.

View joshcanhelp's full-sized avatar
👋
Open to new connections!

Josh Cunningham joshcanhelp

👋
Open to new connections!
View GitHub Profile
@joshcanhelp
joshcanhelp / single-tweet
Created August 14, 2015 16:19
Create a widget at Settings > Widgets > Create New, add your Twitter name, check "Exclude replies, uncheck "Auto-expand photos", then Create Widget, find the data-widget-id attribute and paste in this Gist
<div class="home-tweet">
<h6>Latest Tweet</h6>
<a class="twitter-timeline" data-dnt="true" href="[[DIRECT TWITTER PROFILE URL]]" data-widget-id="[[TWITTER WIDGET ID]]"
data-link-color="#ce2029" data-chrome="nofooter noheader noscrollbar noborders transparent" data-tweet-limit="1">
<script>!function (d, s, id) {
var js, fjs = d.getElementsByTagName(s)[0], p = /^http:/.test(d.location) ? 'http' : 'https';
if (!d.getElementById(id)) {
js = d.createElement(s);
js.id = id;
js.src = p + "://platform.twitter.com/widgets.js";
<script>
( function() {
"use strict";
// Get headline link URLs
var wpdHeadlines = document.getElementsByClassName('headline-link');
// Combine and win
var wpdTrackThese = Array.prototype.slice.call(wpdHeadlines);
@joshcanhelp
joshcanhelp / WP attachment metas
Created July 10, 2013 17:42
Adding meta fields to attachments
/*
* Meta fields for media uploads
*/
/*
* @param array $form_fields
* @param object $post
*
* @return array
*/
@joshcanhelp
joshcanhelp / gist:6108952
Created July 29, 2013 23:55
Get and parse blocked IPs
$blocked = get_option('blacklist_keys');
$blocked = str_replace( "\r", "\n", $blocked );
$blocked_arr = explode( "\n", $blocked );
$blocked_arr = array_map('trim', $blocked_arr);
$final_blocked_arr = array();
foreach ($blocked_arr as $ip) {
$ip = trim($ip);
if ( filter_var( $ip, FILTER_VALIDATE_IP ) ) {
@joshcanhelp
joshcanhelp / gist:6196492
Created August 9, 2013 19:32
WordPress mobile UA redirection
/**
* Redirect on mobile UA
*/
function tenup_mobile_redirect() {
$useragent = $_SERVER['HTTP_USER_AGENT'];
// From http://detectmobilebrowsers.com, set 8/9/2013
// We're looking for user agents that are associated with mobile devices
if ( preg_match( '/(android|bb\d+|meego).+mobile|avantgo|bada\/|blackberry|blazer|compal|elaine|fennec|hiptop|iemobile|ip(hone|od)|iris|kindle|lge |maemo|midp|mmp|netfront|opera m(ob|in)i|palm( os)?|phone|p(ixi|re)\/|plucker|pocket|psp|series(4|6)0|symbian|treo|up\.(browser|link)|vodafone|wap|windows (ce|phone)|xda|xiino/i', $useragent ) || preg_match( '/1207|6310|6590|3gso|4thp|50[1-6]i|770s|802s|a wa|abac|ac(er|oo|s\-)|ai(ko|rn)|al(av|ca|co)|amoi|an(ex|ny|yw)|aptu|ar(ch|go)|as(te|us)|attw|au(di|\-m|r |s )|avan|be(ck|ll|nq)|bi(lb|rd)|bl(ac|az)|br(e|v)w|bumb|bw\-(n|u)|c55\/|capi|ccwa|cdm\-|cell|chtm|cldc|cmd\-|co(mp|nd)|craw|da(it|ll|ng)|dbte|dc\-s|devi|dica|dmob|do(c|p)o|ds(12|\-d)|el(49|ai)|em(l2|ul)|er(ic|k0)|esl8|ez([4-7]0|os|wa|ze)|fetc|fly(\-|_)|g1 u|g560|gene|gf\
@joshcanhelp
joshcanhelp / gist:6196972
Created August 9, 2013 20:36
Add and save media attachment custom fields in WordPress
/*
* @param array $form_fields
* @param object $post
*
* @return array
*/
function tenup_attachment_fields_to_edit ( $form_fields, $post )
{
$form_fields[ "use_as_header_img" ] = array(
@joshcanhelp
joshcanhelp / parseUrlParams.js
Last active February 5, 2017 03:39
Get the various parameters from a URL piece, hash or query
/**
* Get the various parameters from a URL piece, hash or query
*
* @param params
*
* @returns {{}}
*/
function parseUrlParams( params ) {
'use strict';
@joshcanhelp
joshcanhelp / WPRemoveComments.php
Created March 1, 2017 20:07
WordPress: remove comment support completely
<?php
/**
* Completely nuke comments support
* Need to also also turn off comments/pingbacks at wp-admin > Settings > Discussion
* Need to also turn off comments for posts individually (Bulk Edit or DB find/replace)
*
* Adapted from: https://www.dfactory.eu/wordpress-how-to/turn-off-disable-comments/
*
* @package WordPress
/**
* Find next available server number
*
* @param servers
*
* @return {int}
*/
function next_server_number( servers ) {
'use strict';
@joshcanhelp
joshcanhelp / auth0-styleguide.scss
Created April 10, 2018 23:24
Auth0 Styleguide SCSS include
// Primary colors
// http://styleguide.auth0.com/#/design/primary-colors
$color-red: #EB5424;
$color-blue-light: #44C7F4;
$color-blue: #16214D;
$color-yellow: #EACA2C;
// Secondary colors
// http://styleguide.auth0.com/#/design/secondary-colors