Skip to content

Instantly share code, notes, and snippets.

View thisislawatts's full-sized avatar

Luke Watts thisislawatts

View GitHub Profile
@thisislawatts
thisislawatts / functions.php
Last active December 28, 2015 07:39
WordPress Excerpt _with_ HTML tags. Based on some brilliant snippets elsewhere.
/**
* Close out any open tags
* via: http://milianw.de/code-snippets/close-html-tags
*/
function closetags( $html ) {
#put all opened tags into an array
preg_match_all('#<([a-z]+)(?: .*)?(?<![/|/ ])>#iU', $html, $result);
$openedtags = $result[1];
#put all closed tags into an array
@thisislawatts
thisislawatts / gist:7099166
Created October 22, 2013 11:43
Remove hardcoded dependency on 'Catalog'
<!-- Full navigation
============================================= -->
<nav class="full {{ settings.mobile-navigation-colour-scheme }}">
<!-- Main nav
++++++++++++++++++++++++++++ -->
<ul>
{% for link in linklists.main-menu.links %}<li class="nav-item {% include 'for-looper' %} {% if link.title == settings.catalog-label-override and settings.enable-mega-nav %}has-mega-nav{% endif %} {% capture link_handle %}{{ link.title | handle }}{% endcapture %} {% if linklists[link_handle] and linklists[link_handle].links.size > 0 %}dropdown{% endif %}">
@thisislawatts
thisislawatts / gist:6413556
Created September 2, 2013 14:38
Speedy Cache
<?php
/**
* Speedy cache
*
*/
$url = "http://thisis.la";
$file_path = getcwd() . '/cache';
@thisislawatts
thisislawatts / gist:6378995
Created August 29, 2013 14:42
Some funny little regexes I conjured up for an edge case project.
String.prototype.replaceAllButLast = function( search, replace ) {
var tmp = this.slice(0, this.lastIndexOf(search)),
end = this.slice(this.lastIndexOf(search)),
regex = new RegExp(search.replace(/[\-\[\]\/\{\}\(\)\*\+\?\.\\\^\$\|]/g, "\\$&"), 'g'); // Escaping chars
return tmp.replace(regex,replace) + end;
}
String.prototype.replaceAllButFirst = function( search, replace ) {
var tmp = this.slice( this.indexOf(search)),
@thisislawatts
thisislawatts / gist:6163831
Created August 6, 2013 11:49
WordPress Importer - When you've got a stack of users to import and there's a decent mix of one's that already exist, sorting them out is an unnecessary pain ->
jQuery('#authors li').each(function() {
var $self = jQuery(this);
var $strong = $self.find('strong');
var $select = $self.find('select');
var username = $strong.text().match(/\(([\w]*)\)/);
var matched = false;
console.log(username[1])
if (username) {
$select.find('option').each(function() {
if (jQuery(this).text() === username[1]) {
@thisislawatts
thisislawatts / Vine Wrapper
Created July 23, 2013 11:56
Vine Lazy Loader
/**
*
* Vine - Lazy Load Wrapper
*
*
* @requires jQuery
*/
jQuery(document).ready(function($) {
var $vine = [],
@thisislawatts
thisislawatts / functions.php
Last active December 19, 2015 09:39
WordPress Dashboard. Order by Page Template
<?php /**
*
* Adds a Column to WordPress pages admin so you can easily see
* which pages are using which page template.
*
* @since 1.0
*/
function la_modify_page_table ( $columns ) {
/* Add a Page Template Column */
@thisislawatts
thisislawatts / Fabric
Last active December 17, 2015 22:49
Big Cartel Shipping Tasked with transferring a spreadsheet into Product Shipping Costs, I whipped these up to run in the console to auto populate the field
/* Fabric Shipping Costs */
// Wallpaper - Shipping Defaults
var arr = [{
"country" : "Guernsey",
"shipping_alone": 0,
"with_others" : 0
},
{
"country" : "Isle of Man",
@thisislawatts
thisislawatts / script.js
Last active December 15, 2015 04:19
Calculate a page's base em
function calculate_base_em() {
var d = document.createElement('div');
var base_height;
d.style.opacity = 0;
d.innerHTML = 'E';
document.body.appendChild(d);
base_height = d.offsetHeight;
@thisislawatts
thisislawatts / post-creation.php
Created February 20, 2013 10:48
Simple way for inserting a number of posts. Originally set up for 280+ records imported from a XML file.
<?
/**
* WordPress Content Generation
*
*/
/**
* Loads the WordPress Environment and Template
*/