Skip to content

Instantly share code, notes, and snippets.

@thomasmb
thomasmb / form.js
Created July 1, 2014 22:23
Replacement for the Akismet jQuery code
document.addEventListener("DOMContentLoaded", function(event) {
var ak_js = document.getElementById( 'ak_js' );
if( !ak_js ){
ak_js = document.createElement( 'input' );
ak_js.type = 'hidden';
ak_js.name = ak_js.id = 'ak_js';
}
else {
ak_js.parentNode.removeChild( ak_js );
@thomasmb
thomasmb / varnish-https-cache.vcl
Created August 15, 2014 09:34
Sperate varnish cache for HTTPS
sub vcl_hash {
# … Other vcl_hash stuff
# If this is a HTTPS request, keep it in a different cache
if (req.http.X-Forwarded-Proto) {
hash_data(req.http.X-Forwarded-Proto);
}
@thomasmb
thomasmb / gulpfile.js
Created August 26, 2014 12:43
Filtering empty files in gulp
var gulp = require('gulp'),
filter = require('gulp-filter'),
changed = require('gulp-changed'),
imagemin = require('gulp-imagemin')
var paths = {
images: './source/img/**/*'
};
// Process images
@thomasmb
thomasmb / add-stylesheet-once.js
Created October 24, 2013 07:19
A JS function used to add a stylesheet to the HTML head tag, but only once ( in this cases it uses jQuery )
function add_stylesheet_once( url ){
$head = $('head');
if( $head.find('link[rel="stylesheet"][href="'+url+'"]').length < 1 )
$head.append('<link rel="stylesheet" href="'+ url +'" type="text/css" />');
}
@thomasmb
thomasmb / gist:b67680a04ae75bc301b7
Created August 11, 2014 14:03
Google Webfonts
WebFontConfig = {
google: { families: [ 'PT+Sans:400,400italic:latin', 'Ubuntu:300,400,500:latin' ] }
};
var cb = function() {
var wf = document.createElement('script');
wf.src = '//ajax.googleapis.com/ajax/libs/webfont/1/webfont.js';
wf.type = 'text/javascript';
wf.async = 'true';
var s = document.getElementsByTagName('script')[0];
@thomasmb
thomasmb / ssl-support.php
Last active March 27, 2018 07:14
Simple filter for adding https support to wp_get_attachment_url in WordPress
<?php
add_filter( 'wp_get_attachment_url', function( $url, $id ){
if( is_ssl() )
$url = str_replace( 'http://', 'https://', $url );
return $url;
});
@thomasmb
thomasmb / statusboard-serverstats.php
Created April 10, 2013 14:05
A simple script for getting and displaying server stats in StatusBoard
<?php
//add your server aliases here
$servers = array(
"185.14.184.234" => "mcfly.bensmann.no",
"185.14.184.xxx" => "another.server.com",
);
//this script is triggered by this command from the terminal or cron:
//echo "time=`uptime`&df=`df -h`" | curl -s -d @- http://domain.com/path/to/script.php
@thomasmb
thomasmb / gform_tabindex.php
Created November 9, 2017 09:59
Remove tabindex from Gravity Forms
<?php
add_filter( 'gform_tabindex', '__return_false' );
@thomasmb
thomasmb / nginx-helper-purge.php
Created April 10, 2020 13:56
WP Nginx helper purge cache on multiple domains
<?php
/**
* When the site admin is hosted on a different domain, this filter can be used to
* purge the cache of the exposed site
*/
add_filter( 'rt_nginx_helper_purge_url', function( $url ){
$find = 'admin-domain.com';
$replace = 'live-domain.com';
@thomasmb
thomasmb / script.js
Created December 9, 2020 21:14
Contact Form 7 prevent duplicate submissions
// Once the form is submitted, disable the button
$(document).on( 'submit', '.wpcf7-form', function() {
var $submit = $(this).find('[type=submit]');
// Disable the button
$submit.attr('disabled', true)
// Create a backup of the button text
.data( 'original-text', $submit.text() )
// Change the button text to indicate sending
.text( 'Sending…' );