Skip to content

Instantly share code, notes, and snippets.

View stevegrunwell's full-sized avatar

Steve Grunwell stevegrunwell

View GitHub Profile
@stevegrunwell
stevegrunwell / .htaccess
Created June 12, 2012 14:49
Load production WordPress uploads in a local version of the site by putting this in a new Htaccess file in /wp-content/uploads/
# Attempt to load files from production if they're not in our local version (replace {SITE URL} with your production server)
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule (.*) http://{SITE URL}/wp-content/uploads/$1
</IfModule>
@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 / cdils.php
Created March 6, 2018 14:48
Modify the available block formats within WordPress' TinyMCE editor. A quick solution for https://twitter.com/cdils/status/970854979735977984
<?php
/**
* Change the block formats available in TinyMCE.
*
* @link http://codex.wordpress.org/TinyMCE_Custom_Styles
*
* @param array $init Default settings to be overridden.
*
* @return array The modified $init array.
@stevegrunwell
stevegrunwell / limit-orders-custom-daily-interval.php
Last active November 17, 2022 21:57
Set a custom start time for the "daily" interval when using Limit Orders for WooCommerce.
<?php
/**
* Plugin Name: Limit Orders for WooCommerce - Custom Daily Interval
* Description: Restart daily order limiting at a time other than midnight.
* Author: Nexcess
* Author URI: https://nexcess.net
*/
/**
* Get a DateTime object representing the start of the daily interval.
@stevegrunwell
stevegrunwell / limit-orders-shortcode.php
Created March 26, 2021 15:55
Limit Orders for WooCommerce - Custom Shortcodes
<?php
/**
* Plugin Name: Limit Orders for WooCommerce - Shortcode
* Description: Custom shortcode for displaying information from the Order Limiter.
* Author: Nexcess
* Author URI: https://nexcess.net
*/
use Nexcess\LimitOrders\OrderLimiter;
@stevegrunwell
stevegrunwell / one-time-hooks.php
Created February 14, 2017 20:06
Enables action and filter callbacks to be executed exactly once via the WordPress Plugin API. https://engineering.growella.com/one-time-callbacks-wordpress-plugin-api/
<?php
/**
* Registers the "One time hook" functionality.
*
* Note that this file is intentionally in the *global* namespace!
*
* @author Growella
* @license MIT
*/
@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 / README.md
Created May 10, 2021 01:15
Getting PHPUnit 8 working with the WordPress core test suite

This code comes from the Nexcess Managed Applications (MAPPS) Must-Use plugin and is used to let the test suite run on PHPUnit 8 and above.

We're able to do this because our test suite takes advantage of Symfony's PHPUnit Bridge component, so we're already able to run our suite across multiple versions of PHPUnit, as the library takes care of differences like return typehints and differences in PHPUnit class names.

The (abbreviated) bootstrap.php file in this gist shows how we load the core test suite and, if we're running PHP 8.0 or above, will duplicate the stock includes/bootstrap.php file from the test suite to includes/bootstrap-phpunit8.php.

The duplicated bootstrap file is the same as the version that ships with core, minus the "Looks like you're using PHPUnit $version" error.


@stevegrunwell
stevegrunwell / limit-orders-do-not-empty-cart.php
Created February 4, 2021 19:34
Prevent WooCommerce from emptying carts after the order limit has been reached — https://wordpress.org/support/topic/cart-empties-when-limit-is-hit/
<?php
/**
* Plugin Name: Limit Orders for WooCommerce - Prevent Empty Carts
* Description: Prevent WooCommerce from emptying carts after the order limit has been reached.
* Author: Nexcess
* Author URI: https://nexcess.net
*/
/**
* Prevent WooCommerce from removing non-purchasable items from the cart.
@stevegrunwell
stevegrunwell / limit-orders-forever.php
Created June 19, 2020 14:48
Add a "Forever" option to Limit Orders for WooCommerce - https://wordpress.org/support/topic/all-time-interval/
<?php
/**
* Plugin Name: Limit Orders for WooCommerce - Never-ending Interval
* Description: Add a "Forever" option to Limit Orders for WooCommerce.
* Author: Nexcess
* Author URI: https://nexcess.net
*/
/**
* Add "Forever" to the list of intervals.