Skip to content

Instantly share code, notes, and snippets.

View webaware's full-sized avatar

Ross McKay webaware

View GitHub Profile
@webaware
webaware / htaccess-extras
Last active April 7, 2025 07:17
Here’s some basic recipe stuff to put into the top of .htaccess, above WP Super Cache and WordPress rules. Together, they reduce load on the server by compressing static files before sending them, making browsers cache static files, dying quickly on static files 404 errors, and blocking some common hacker / spammer attacks.
# v18 2025-04-07
# prevent listing files in folders
Options -Indexes
# some security rules
<IfModule mod_rewrite.c>
RewriteEngine On
# prevent php execution in uploads
RewriteRule /uploads/.*\.php - [F]
@webaware
webaware / force-ssl-url-scheme.php
Last active April 4, 2025 15:56
For WordPress, force the protocol scheme to be HTTPS when is_ssl() doesn't work, e.g. on a load-balanced server where _SERVER['HTTPS'] and _SERVER['SERVER_PORT'] don't indicate that SSL is being used. NB: may not be needed now, see SSL Insecure Content Fixer and HTTP Detection: https://ssl.webaware.net.au/https-detection/
<?php
/*
Plugin Name: Force SSL URL Scheme
Plugin URI: https://gist.github.com/webaware/4688802
Description: Force the protocol scheme to be HTTPS when is_ssl() doesn't work
Version: 1.0.0
Author: WebAware
Author URI: http://webaware.com.au/
@ref: http://wordpress.org/support/topic/ssl-insecure-needs-35-compatibility
@webaware
webaware / debug-log-not-strict.php
Last active December 23, 2024 02:31
Turn on WordPress' WP_DEBUG_LOG but without E_STRICT. Accompanying blog post: http://snippets.webaware.com.au/snippets/wordpress-wp_debug_log-without-e_strict/
<?php
/*
Plugin Name: Debug Log Not Strict
Plugin URI: https://gist.github.com/webaware/6520892
Description: Turn on WP_DEBUG_LOG but without E_STRICT
Version: 1.4.0
Author: WebAware
Author URI: https://shop.webaware.com.au/
*/
@webaware
webaware / gist:6260468
Last active October 28, 2024 06:19
WooCommerce purchase page add-to-cart with quantity and AJAX, without customising any templates. See blog post for details: http://snippets.webaware.com.au/snippets/woocommerce-add-to-cart-with-quantity-and-ajax/
<?php
/**
* start the customisation
*/
function custom_woo_before_shop_link() {
add_filter('woocommerce_loop_add_to_cart_link', 'custom_woo_loop_add_to_cart_link', 10, 2);
add_action('woocommerce_after_shop_loop', 'custom_woo_after_shop_loop');
}
add_action('woocommerce_before_shop_loop', 'custom_woo_before_shop_link');
@webaware
webaware / plugin-download.php
Last active October 24, 2024 03:45
Add download links to WordPress plugins with updates available
<?php
/*
Plugin Name: Plugin Download
Plugin URI: https://gist.github.com/webaware/4a4f2dca44b1c10fb9a8fe85a5f90f40
Update URI: plugin-download
Description: add download links to plugins with updates available
Version: 0.0.2
Author: WebAware
Author URI: https://shop.webaware.com.au/
*/
@webaware
webaware / add-to-cart.php
Last active October 9, 2024 00:33 — forked from mikejolley/functions.php
WooCommerce purchase page add-to-cart with quantity and AJAX, by customising the add-to-cart template in the WooCommerce loop. See blog post for details: http://snippets.webaware.com.au/snippets/woocommerce-add-to-cart-with-quantity-and-ajax/
<?php
/**
* Loop Add to Cart -- with quantity and AJAX
* requires associated JavaScript file qty-add-to-cart.js
*
* @link http://snippets.webaware.com.au/snippets/woocommerce-add-to-cart-with-quantity-and-ajax/
* @link https://gist.github.com/mikejolley/2793710/
*/
// add this file to folder "woocommerce/loop" inside theme
@webaware
webaware / contiguous-usa.php
Created January 19, 2024 21:41
GF Address Enhanced: Filter USA states to only have the Lower 48 + DC. Add this to a plugin, or functions.php in your theme.
<?php
/**
* Filter USA states to only have the Lower 48 + DC
*/
add_filter('gf_address_enhanced_smart_states_script_data', function(array $script_data) : array {
if (isset($script_data['states']['United States'])) {
// Alaska, Hawaii, and the Armed Forces codes
$remove = ['AK', 'HI', 'AA', 'AE', 'AP'];
@webaware
webaware / private-debug-log.php
Created February 17, 2013 02:17
Enable WordPress debug log to a private folder not accessible from the web. See http://wordpress.stackexchange.com/q/84132/24260 for details and motivations. NB: currently needs to be manually edited to specify the private folder path;
<?php
/*
Plugin Name: Private Debug Log
Description: Enable debug log to a private folder not accessible from the web
Version: 0.0.1
Author: WebAware
Author URI: http://www.webaware.com.au/
*/
/*
@webaware
webaware / gf-country-usa.php
Last active September 30, 2023 02:38
change United States to USA in Gravity Forms addresses, with support for Gravity Forms Address Enhanced
<?php
/*
Plugin Name: GF Country USA
Plugin URI: https://gist.github.com/webaware/edba921af11f06bdfd5147bab806f591
Description: change United States to USA in Gravity Forms addresses
Version: 2
Author: WebAware
Author URI: https://shop.webaware.com.au/
*/
@webaware
webaware / network-lister.php
Last active May 14, 2023 03:56
Simple dashboard widget for listing WordPress multisite sites, and accompanying shortcode for the front end.
<?php
/*
Plugin Name: Network Lister
Plugin URI: https://gist.github.com/webaware/b914967f0ce8110c775cd12ddc546283
Update URI: network-lister
Description: simple dashboard widget for listing network sites
Version: 0.0.5
Author: WebAware
Author URI: https://shop.webaware.com.au/
*/