Skip to content

Instantly share code, notes, and snippets.

Avatar

Zachary Scott zacscott

  • Queensland Australia
View GitHub Profile
@zacscott
zacscott / object-cache.php
Last active Jun 15, 2020
Custom object cache for WordPress with some logic for selectively disabling it for certain URLs.
View object-cache.php
<?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 Jun 15, 2020
Precache sitemaps automatically via a smart Bash script.
View precache.sh
!/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 Jun 25, 2018
PHPCS w/ Bitbucket Pipelines helper script
View phpcs.py
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 Jun 23, 2018
PIP install mysqlclient on MacOSX
View gist:0c67e0a75d23581609ecc1bf631570f4
# 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 Apr 27, 2020
Fragment caching utility class for WordPress. Based off; https://gist.github.com/markjaquith/2653957
View fragment-cache.php
<?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 Mar 11, 2017
Simple one file router for WordPress (can be used as a mu-plugin)
View routes.php
<?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 Jul 11, 2021
Use the WP.com Photon image CDN without installing JetPack
View wpcom-cdn.php
<?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 Mar 11, 2017
Allow admins to purge the WordPress cache
View purge-cache.php
<?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 Mar 11, 2017
Fixes the canonical URL to always be HTTP (SEO)
View allow-https.php
<?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 Mar 11, 2017
Converts all links in post content, attachments etc. to root relative. This is specifically designed to work well with RAMP
View relative-urls.php
<?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
*/