Skip to content

Instantly share code, notes, and snippets.

View jamesmorrison's full-sized avatar

James Morrison jamesmorrison

View GitHub Profile
@jamesmorrison
jamesmorrison / disable-network-active-plugin.php
Last active January 2, 2018 10:21
Disable one or more network active plugins for one or more sites
<?php
add_filter( 'site_option_active_sitewide_plugins',
function( $value ) {
// Lookup the current site object global
$current_blog;
// This would disable the plugins on sites with ID's 2, 3 and 5
if ( in_array( $current_blog->blog_id, [ 2, 3, 5 ] ) ) {
@jamesmorrison
jamesmorrison / 000-default.conf
Created October 25, 2017 10:19
Nginx Config for Apollo with nocache headers for all content
server {
server_name apollo;
listen 80 default_server;
listen 443 ssl default_server;
ssl_certificate ssl/selfsigned.crt;
ssl_certificate_key ssl/selfsigned.key;
ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
@jamesmorrison
jamesmorrison / functions.php
Created October 5, 2017 11:07
When enqueueing a script or style, use `filemtime` to set the file version to the Unix timestamp for when the file was last modified
<?php
/* Obviously, add this to a function that hooks into wp_enqueue_scripts() (or admin_enqueue_scripts()) */
wp_enqueue_style( 'main', get_stylesheet_directory_uri() . '/style.css', false, filemtime( get_stylesheet_directory() . '/style.css' ) );
@jamesmorrison
jamesmorrison / improve-wp-signup-redirect.php
Created September 29, 2017 10:35
Improve WP Signup - redirect to the main network URL with referral parameters
<?php
/**
* @package Improve WP Signup - redirect to the main network URL with referral parameters
* @author James Morrison
*
* The WP core /wp-signup.php file calls "get_header( 'wp-signup' );" we can hook into this to force a redirect
* Add this as a MU Plugin, make sure NOBLOGREDIRECT is *not* defined as it'll override this
*
* Notes:
* Whilst you can set up a redirect from the NOBLOGREDIRECT constant, the advantage of using this
@jamesmorrison
jamesmorrison / header-wp-signup.php
Last active September 21, 2017 21:29
Adding this to your theme will redirect any requests for wp-signup.php (triggered upon visiting a multisite network address that doesn't exist) to the network home URL along with some GA parameters
<?php
/**
* @package Header for WP Signup
* @author James Morrison
* @link https://gist.github.com/jamesmorrison/5f8a3108b2a773cd07db430b73992e9d/edit
*
* This file is called by the WP core /wp-signup.php file; we can force a redirect from here
*
* Whilst you can do this from the NOBLOGREDIRECT constant, the advantage of using this header
* file is that you can capture the path that triggered the call to signup; as seen in the example
@jamesmorrison
jamesmorrison / admin-bar-site-id.php
Last active January 2, 2018 10:11
Add the current site ID to the Admin Bar
<?php
/**
* Plugin Name: Admin Bar Site ID
* Description: Add the current site ID to the Admin Bar
* Version: 1.0.3
* Author: James Morrison
* Author URI: https://www.jamesmorrison.me/
**/
@jamesmorrison
jamesmorrison / rewrite-search-urls.php
Created August 10, 2017 18:05
Rewrite search URL's to "pretty" permalinks. A custom permalink structure must be set.
<?php
/**
*
* Plugin Name: Rewrite Search URL's
* Description: Rewrite search URL's to "pretty" permalinks. A custom permalink structure must be set.
* Version: 1.0.1
* Author: James Morrison
* Author URI: https://www.jamesmorrison.me/
*
**/
if [ -f ~/.bashrc ]; then
source ~/.bashrc
fi
@jamesmorrison
jamesmorrison / wp-cache-controller.php
Created July 7, 2017 11:52
Set a max age for WP pages
<?php
/**
* Plugin Name: Cache Controller
* Plugin URI: #
* Description: HTTP Cache Control headers for WordPress.
* Version: 0.0.1
* Author: James Morrison
* Author URI: https://james.morrison.me/
**/
## CMD PROMPT
green=$(tput setaf 2)
blue=$(tput setaf 4)
white=$(tput setaf 7)
bold=$(tput bold)
reset=$(tput sgr0)
PS1='${debian_chroot:+($debian_chroot)}\[$green\]MAC\[$reset\]:\[$white\]\w\[$reset\]\[$green\]$(parse_git_branch)\[$reset\]\$ '