Skip to content

Instantly share code, notes, and snippets.

View zacscott's full-sized avatar

Zac Scott zacscott

View GitHub Profile
@zacscott
zacscott / object-cache.php
Last active June 15, 2020 00:45
Custom object cache for WordPress with some logic for selectively disabling it for certain URLs.
<?php
/**
* Plugin Name: Object Cache
* Description: Object cache backend - uses APC for local development, Redis or Memcached for prod/staging.
* Version: 3.0
* Author: The Code Company
* Author URI: http://thecode.co
*
* @package thecodeco
*/
@zacscott
zacscott / precache.sh
Created June 15, 2020 00:10
Precache sitemaps automatically via a smart Bash script.
!/bin/bash
# Automatically hits all sitemaps on a site to pre-cache then at the edge.
# CONFIG
SITEMAP_URL=https://www.oursite.com.au/sitemap_index.xml
# Pull the index sitemap and get a list of all of the individual sitemaps.
echo "PULLING $SITEMAP_URL"
sitemaps=`curl $SITEMAP_URL | awk -F '[<>]' '/loc/{print $3}'`
@zacscott
zacscott / phpcs.py
Created June 25, 2018 00:05
PHPCS w/ Bitbucket Pipelines helper script
import os
import re
import subprocess
import sys
import tempfile
def log(message):
"""Print a log message to console, will be a darker colour than normal print()"""
@zacscott
zacscott / gist:0c67e0a75d23581609ecc1bf631570f4
Created June 23, 2018 01:37
PIP install mysqlclient on MacOSX
# Python's mysqlclient requires MySQL version 5.7, however brew installs MySQL v8 by default.
# This is how you can install MySQL 5.7 and have it work to build mysqlclient
brew install mysql@5.7
ln -s /usr/local/Cellar/mysql-client/5.7.22/bin/mysql_config /usr/local/bin/mysql_config
@zacscott
zacscott / fragment-cache.php
Last active April 27, 2020 16:01
Fragment caching utility class for WordPress. Based off; https://gist.github.com/markjaquith/2653957
<?php
/*
* Plugin Name: Fragment Cache
* Description: Provides the <code>FragmentCache</code> helper class
* Version: 1.2
* Author: Zachary Scott
*/
namespace zacscott;
@zacscott
zacscott / routes.php
Last active March 11, 2017 01:23
Simple one file router for WordPress (can be used as a mu-plugin)
<?php
/*
* Plugin Name: Routes for WordPress
* Description: Routes class provider plugin
* Version: 2.0
* Author: Zachary Scott
*/
namespace zacscott;
@zacscott
zacscott / wpcom-cdn.php
Last active January 30, 2024 10:12
Use the WP.com Photon image CDN without installing JetPack
<?php
/**
* Plugin Name: Photon CDN
* Version: 1.1
* Description: Use the WP.com Photon image CDN without installing JetPack
* Author: Zachary Scott
*/
namespace zacscott;
@zacscott
zacscott / purge-cache.php
Last active March 11, 2017 11:07
Allow admins to purge the WordPress cache
<?php
/**
* Plugin Name: Purge Cache
* Description: Allow admins to purge the WordPress cache
* Version: 1.1
* Author: Zachary Scott
*/
namespace zacscott;
@zacscott
zacscott / allow-https.php
Last active March 11, 2017 11:07
Fixes the canonical URL to always be HTTP (SEO)
<?php
/**
* Plugin Name: Allow HTTPS
* Description: Fixes the canonical URL to always be HTTP
* Version: 1.0
* Author: Zachary Scott
*/
namespace zacscott;
@zacscott
zacscott / relative-urls.php
Last active March 11, 2017 11:07
Converts all links in post content, attachments etc. to root relative. This is specifically designed to work well with RAMP
<?php
/**
* Plugin Name: Relative URLs
* Description: Converts all links in post content, attachments etc. to root
* relative. This is specifically designed to work well with
* <a href="https://crowdfavorite.com/ramp/">RAMP</a>.
* Version: 1.1
* Author: Zachary Scott
*/