Skip to content

Instantly share code, notes, and snippets.

View petertwise's full-sized avatar

Peter Wise petertwise

View GitHub Profile
@petertwise
petertwise / test-queue-race.php
Created September 5, 2026 02:25
Test script for Offload SES emails stuck in queue issue
<?php
/**
* Standalone reproduction script for the WP Offload SES stuck-queue race.
*
* =========================
* NOTE: Confirmed broken on v1.8.0 when running cron via WP CLI and cronjob
* with DISABLE_WP_CRON set to true. In 1.8.0 sending two+ emails within the
* same php script with wp_mail even micro seconds apart, the first one sends,
* the second+ ones are queued and the queued emails are stuck indefinitely and
* never send until something else calls wp_mail again in new php call.
@petertwise
petertwise / woocommerce-subscriptions-list-table-performance.php
Last active September 2, 2026 01:09
WooCommerce Subscriptions admin list table query fix
<?php
/**
* WooCommerce Subscriptions admin list table performance fix.
*
* WCS_Admin_Post_Types::orders_table_clauses_low_performance() builds a derived table of the
* most recent renewal order date per subscription, then joins it with
* `wc_orders.id = lp.meta_value`. `wc_orders_meta.meta_value` is a TEXT column, so:
*
* - the BIGINT = TEXT comparison can never use an index, and
* - MariaDB/MySQL cannot build an auto-key on a TEXT column of a derived table,
@petertwise
petertwise / admin-color-scheme-fix.php
Created May 26, 2026 18:50
WordPress 7.0 Admin Color Scheme Fix
<?php
/**
* Plugin Name: WP 7.0 Admin Color Scheme Fix
* Description: Restores Fresh as default admin color scheme; removes "Modern" option (new default); Restores contrast on notices.
*/
defined( 'ABSPATH' ) || exit;
add_filter( 'get_user_option_admin_color', function( $color, $option, $user ) {
if ( empty( $color ) || 'modern' === $color ) {
@petertwise
petertwise / squarecandy-noindex-staging.php
Created December 22, 2025 03:56
Square Candy noindex Staging
<?php
/*
Plugin Name: Square Candy noindex Staging
Description: A must-use plugin to add noindex to staging sites.
Author: squarecandy
Author URI: https://squarecandydesign.com
Version: 1.0
License: GPL2
SETUP INSTRUCTIONS:
@petertwise
petertwise / givewp-auto-connect-donors.php
Last active November 13, 2025 19:46
GiveWP Auto-connect existing WP users to GiveWP Donors
<?php
// Add this snippet to your theme code, or integrate it into a plugin.
// Exit if accessed directly
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
// Bail if GiveWP is not active
if ( ! class_exists( 'Give' ) ) {
@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 );