Skip to content

Instantly share code, notes, and snippets.

View petertwise's full-sized avatar

Peter Wise petertwise

View GitHub Profile
@petertwise
petertwise / my-squarecandy-error-logging.README.md
Last active June 27, 2025 21:01
Square Candy Error Logging Overrides for WordPress

Square Candy Error Logging

FAQ

Why can't this be a regular plugin? Or why can't I just override these settings in php.ini instead?

This code needs to go in mu-plugins because of some quirks of how WP Core itself overrides the error logging settings.

  • If you make changes in php.ini or other server level settings, they will get overridden by WP Core
  • If you put ini_set and error_reporting changes in wp-config.php - same thing - they will load before the core files that modify error logging and get overridden.
@petertwise
petertwise / squarecandy-total-size-alert.php
Last active December 12, 2024 15:14
WP Total Disk Size Alert
<?php
/*
Plugin Name: WP Total Disk Size Alert
Description: Alerts when the total size of the WordPress installation exceeds a given size.
Version: 1.0.0
Author: Square Candy
* Defaults to a 10GB limit
* Defaults to sending the alert to the site admin email
* Sends the alert when the total size is within 1GB of the limit
@petertwise
petertwise / logged_in_active_subscribers_skip_oopspam_check.php
Last active September 15, 2024 19:21
OOPSpam Skip Certain User Roles
<?php
add_filter( 'oopspam_check_for_spam', 'logged_in_active_subscribers_skip_oopspam_check', 99 );
function logged_in_active_subscribers_skip_oopspam_check() {
// if the user has active-subscriber role, pass the check automatically
// https://wordpress.stackexchange.com/a/5048/41488
$user = wp_get_current_user();
if ( $user && isset( $user->roles ) && in_array( 'active-subscriber', (array) $user->roles ) ) {
return 0; // zero spam score means "never block due to being spam"
}
}
@petertwise
petertwise / squarecandy-checkout-donation-mod.js
Last active September 3, 2024 16:11
GiveWP WooCommerce Checkout Donations - UI Modifications
( function( $ ) {
$( document ).ready( function() {
// Checkout Donation Add On
function showHideAddDonationButton() {
if ( ! $( '.give-wc-form-selector' ).is( ':checked' ) ) {
$( '.give-wc-update-donations' ).hide();
} else {
$( '.give-wc-update-donations' ).show();
}
setTimeout( function() {
@petertwise
petertwise / squarecandy-wc-status-change-logger.php
Last active September 27, 2024 01:46
Log WooCommerce status changes with stack trace, even when WP_DEBUG is off.
<?php
/**
* Plugin Name: SquareCandy Status Change Logger for WooCommmerce
* Description: Log WooCommerce status changes with stack trace, even when WP_DEBUG is off.
* Author: squarecandy
* License: GNU General Public License v3 or later
* License URI: http://www.gnu.org/licenses/gpl-3.0.html
*/
add_action( 'woocommerce_order_status_changed', 'squarecandy_status_change_logger', 999, 4 );
@petertwise
petertwise / staging-images-main-context.conf
Last active January 23, 2024 06:45
nginx use production media for staging
if (!-f $request_filename){
set $rule_0 1$rule_0;
}
if ($rule_0 = "1"){
rewrite ^/wp-content/uploads/(.*)$ https://example.com/wp-content/uploads/$1 last;
}
@petertwise
petertwise / git-updater-ignore.php
Created January 11, 2024 03:17 — forked from afragen/git-updater-ignore.php
A plugin to ignore specific repositories from Git Updater
<?php
/**
* Plugin Name: Git Updater Ignore
* Plugin URI: https://gist.github.com/afragen/414612961ac500b652862096a54d62d7
* Description: This plugin is used to set Git Updater to ignore specific repository slugs.
* Version: 0.3
* Author: Andy Fragen
* License: MIT
* Requires at least: 5.2
* Requires PHP: 5.6
@petertwise
petertwise / squarecandy-hide-stream-activity-logger.php
Last active July 26, 2023 18:23
Hide Stream plugin from all users except one Admin
<?php
/*
Plugin Name: Square Candy Hide Stream (activity monitor plugin)
Plugin URI: https://gist.github.com/petertwise/5468e4d793c7ad89a32cb8e27de8ae3c
Version: 1.0
Author: Square Candy
Author URI: https://squarecandydesign.com
License: GPLv2
@petertwise
petertwise / plusminus.html
Last active July 14, 2023 03:56 — forked from Farmatique/gist:5c48d1d9b5744117a94901f6ed84f7b5
input[type="number"] plus/minus buttons
<div id="field1">
<button type="button" id="sub" class="sub">-</button>
<input type="text" id="1" value="0" class="field" />
<button type="button" id="add" class="add">+</button>
</div>
@petertwise
petertwise / widow-buster.php
Last active October 14, 2021 02:52
PHP widow buster function - eliminate a single word wrapping to a new line
<?php
function widow_buster( $text, $min_words = 3, $max_chars = 16 ) {
$words = explode( ' ', $text );
$word_count = count( $words );
$char_length = strlen( $words[ $word_count - 2 ] ) + strlen( $words[ $word_count - 1 ] );
// if our minimum word count and maximum character count are met,