Skip to content

Instantly share code, notes, and snippets.

View jamesmorrison's full-sized avatar

James Morrison jamesmorrison

View GitHub Profile
@jamesmorrison
jamesmorrison / filter-wp-basic-http-authentication-environments.php
Last active January 5, 2018 19:54
Filter WP Basic HTTP Authentication Environments
<?php
/**
* Plugin Name: Filter WP Basic HTTP Authentication Environments
* Description: Filter WP Basic HTTP Authentication Environments to use environment variables
* Author: James Morrison
* Version: 1.0.0
* Author URI: https://www.jamesmorrison.me
**/
// Filter the environments
@jamesmorrison
jamesmorrison / display-git-branch.php
Created January 3, 2018 19:29
WordPress plugin to display your Git branch in the admin bar
<?php
/**
* Plugin Name: Display Git Branch
* Version: 1.0.0
* Description: Shows which Git branch you're working on. Highlights restricted branches in red.
* Author: James Morrison
* Author URI: https://www.jamesmorrison.me/
**/
// Namespace
@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 / 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 / 30_wpcli.config
Created November 9, 2017 22:02 — forked from Azrael808/30_wpcli.config
Elastic Beanstalk extension for installing WP CLI.
commands:
"01":
command: curl https://raw.githubusercontent.com/wp-cli/builds/gh-pages/phar/wp-cli.phar -o /usr/local/bin/wp
"02":
command: chmod +x /usr/local/bin/wp
@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 / 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/
*
**/