Skip to content

Instantly share code, notes, and snippets.

View stevegrunwell's full-sized avatar

Steve Grunwell stevegrunwell

View GitHub Profile
@stevegrunwell
stevegrunwell / database-backup.sh
Last active December 14, 2017 21:07
Dump each MySQL database and send its backup to Amazon S3. https://engineering.growella.com/automatic-database-backups-amazon-s3/
#!/bin/bash
#
# Backup local databases to Amazon S3.
#
# This script takes a single argument: an S3 bucket name with optional path.
#
# Usage:
# database-backup.sh backup.example.com
# database-backup.sh backup.example.com/some/path
#
### Keybase proof
I hereby claim:
* I am stevegrunwell on github.
* I am stevegrunwell (https://keybase.io/stevegrunwell) on keybase.
* I have a public key whose fingerprint is 56A8 ED6A 4437 6DE0 0EE9 3D74 5435 2694 8DF1 91E1
To claim this, I am signing this object:
@stevegrunwell
stevegrunwell / functions.php
Created March 15, 2016 18:56
WP404: Send an email to Eric Mann every time there's a 404
<?php
/**
* Email the error log to Eric Mann every time a 404 error occurs.
*
* @param array $report The WP404 report.
* @return array The (untouched) WP404 report.
*/
function mytheme_spam_eric_with_404s( $report ) {
wp_mail(
@stevegrunwell
stevegrunwell / .bash_profile
Created September 9, 2015 19:25
Upgrade WordPress plugins via WP-CLI one at a time, committing the results to Git as you go
function wp-upgrade-plugins() {
UPDATES=`wp plugin list --update=available --fields=name,title,update_version --format=csv`
i=1
while IFS="," read -r slug name version
do
test $i -eq 1 && ((i=i+1)) && continue
echo "Upgrading $name to $version..."
@stevegrunwell
stevegrunwell / gist:11c3e9d370127fa97898
Last active May 13, 2021 22:44
Bulk-upgrade WordPress plugins using WP-CLI, committing each upgrade to Git as we go
#! /bin/bash
# Find available updates for WordPress plugins via WP-CLI, then upgrade theme one at a time.
# After each upgrade, commit the changed files to Git.
#
# Requires that WP-CLI be installed and in your path: http://wp-cli.org/
#
# Currently, it will only work when run from the root of the WordPress installation, and has
# a hard-coded path for wp-content/plugins.
#
@stevegrunwell
stevegrunwell / gist:10011122
Last active August 29, 2015 13:58
Example of restricting shipping to a single state for a single shipping class with WooCommerce, prepared for Evan Thorpe based on my blog post http://stevegrunwell.com/blog/woocommerce-restrict-shipping
public function is_available( $package ) {
// Determine if we have any items in the "In-state" shipping class
$restricted_shipping_class_slug = 'in-state';
$permitted_states_for_restricted_items = array( 'NY' );
$has_restricted_items = false;
foreach ( $package as $pkg ) {
if ( isset( $pkg['contents'] ) ) {
foreach ( $pkg['contents'] as $contents ) {
@stevegrunwell
stevegrunwell / gist:8578709
Created January 23, 2014 13:51
(Quick and dirty) modification of http://stevegrunwell.com/blog/woocommerce-restrict-shipping/ to help Katie from http://noizepro.com/ with limiting WooCommerce shipping for two shipping methods.
<?php
/**
* Return an array of restricted shipping locations for WooCommerce
*
* Restricted locations include Alaska, American Samoa, Guam, Hawaii, North Mariana Islands, Puerto Rico,
* US Minor Outlying Islands, and the US Virgin Islands
*
* @return array
*/
@stevegrunwell
stevegrunwell / gist:6286357
Created August 20, 2013 19:53
Easily add a new Bitbucket repo on a Redmine server. Add this to the Redmine user's .bash_profile, run `bitbucket-add-repository <slug>`, then add the repo to Redmine project configuration. Modifying this to use with Github is trivial, just update git@bitbucket.org to git@github.com (and update textual references, of course).
# Create a bare clone in ~/git_repositories/{slug}.git
# Before running this command ensure that the repo on Bitbucket has an appropriate deploy key.
# You'll also want to set a POST hook (e.g. http://{redmine}/github_hook?project_id={slug})
#
# Usage: bitbucket-add-repository <slug>
function bitbucket-add-repository {
base=/home/redmine/git_repositories/
if [ -n "$1" ]; then
path=$base$1.git
@stevegrunwell
stevegrunwell / get_current_git_commit.php
Created August 15, 2012 21:44
Get current git HEAD using PHP
<?php
/**
* Get the hash of the current git HEAD
* @param str $branch The git branch to check
* @return mixed Either the hash or a boolean false
*/
function get_current_git_commit( $branch='master' ) {
if ( $hash = file_get_contents( sprintf( '.git/refs/heads/%s', $branch ) ) ) {
return $hash;
} else {
@stevegrunwell
stevegrunwell / wordpress-multisite.md
Created July 15, 2012 15:00
WordPress Multisite - WordCamp Columbus 2012

WordPress Multisite

July 15, 2012

Instructor: Angie Meeker (@angiemeeker)

Slides: http://slidesha.re/LZT6T3

Angie's Multisite-mentor: @angela_r