Skip to content

Instantly share code, notes, and snippets.

View zacscott's full-sized avatar

Zac Scott zacscott

View GitHub Profile
@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 / disable-yoast-nags.php
Last active January 17, 2023 09:51
Hides all Yoast premium nags in the backend
<?php
/**
* Plugin Name: Disable Yoast Nags
* Description: Hides all Yoast premium nags in the backend.
* Version: 1.0
* Author: Zachary Scott
*/
namespace zacscott;
@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 / 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 / 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 / bbcode.php
Last active April 6, 2020 07:59
Simple BBcode rendering function (PHP).
<?php
/**
* Renders BBCode to html, suitable to be embedded in a document. Supports only
* a limited set of BBCode tags (can be extended), which are:
*
* @param $bbcode The bbcode to be rendered. Must not be `null` or empty
* string.
* @param $reps Optional additional replacements. Allows you to add custom tags
* etc. Should be an associative array, mapping a regex (preg) to replacement.
@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 / example.php
Last active March 11, 2017 11:09
Settings builder utility for WordPress (can be used as a mu-plugin)
<?php
add_action( 'plugins_loaded', function() {
$settings = new zacscott\SettingsBuilder();
$settings->page( array(
'title' => 'TEST ',
'menu' => 'Test Settings',
) );
@zacscott
zacscott / notes.php
Last active March 11, 2017 11:09
Notes - WordPress Plugin
<?php
/**
* Plugin Name: Notes
* Description: Keep private notes within WordPress
* Version: 1.0
* Author: Zachary Scott
* Author URI: https://www.zacscott.net
* Plugin URI: https://gist.github.com/zacscott/b4cbacf5a0825a270a28
* License: GPLv3+
*/