Skip to content

Instantly share code, notes, and snippets.

@sybrew
sybrew / tsf-admin-access.php
Created October 23, 2026 13:24
Mu-plugin that restricts TSF's admin interface to users with manage_options.
<?php
/**
* Plugin Name: TSF Admin Access
* Description: Restricts TSF's admin interface to users with manage_options.
*/
add_action(
'plugins_loaded',
/**
* Enables Headless mode for restricted admin requests before TSF loads.
@sybrew
sybrew / cpanel-php-upload-progress-mitigation.md
Last active October 27, 2026 16:20
Tested cPanel ModSecurity block for the known PHP session upload-progress field. Not a substitute for today's PHP security release.

This blocks the default PHP session upload-progress field on cPanel until every PHP on the server is on a fixed release. Ordinary uploads do not send this field, so they keep working. If session.upload_progress.name was changed in php.ini, put that name in the rule in place of PHP_SESSION_UPLOAD_PROGRESS.

First, go to: Security Center → ModSecurity™ Tools → Rules List → Add Rule. Paste the code below under Rule Text.

SecRule REQUEST_HEADERS:Content-Type "@rx multipart/form-data" \
    "id:2026102101,phase:2,chain,t:lowercase,deny,status:403,log,\
    msg:'Blocked PHP session upload-progress field'"
    SecRule ARGS_NAMES|FILES_NAMES "@streq PHP_SESSION_UPLOAD_PROGRESS" "t:none"
@sybrew
sybrew / strict-typing-php-benchmark.php
Created July 24, 2026 13:57
Benchmark: cost of strict parameter/return typing vs. loose typing + manual cast/sanitization. This should be run in an opcache-enabled and opcache-disabled run.
<?php
/**
* Benchmark: cost of strict parameter/return typing vs. loose typing + manual
* cast/sanitization. This should be run in an opcache-enabled and opcache-disabled run.
*
* Improvements over the original script:
* - Randomizes test order every round to cancel out positional/thermal bias
* (CPU frequency scaling, branch predictor & instruction-cache warm-up).
* - Runs many rounds and reports the median (robust against GC pauses/noise)
* instead of a single sample per "test" loop.
@sybrew
sybrew / wcs-diagnostics.sql
Last active April 22, 2026 17:54
WooCommerce Subscriptions: Diagnostic Queries - Detect subscriptions silently broken by the requires_manual_renewal bug
-- =============================================================================
-- WooCommerce Subscriptions: Diagnostic Queries
-- Detect subscriptions silently broken by the requires_manual_renewal bug
-- =============================================================================
--
-- WHO SHOULD RUN THIS:
-- Any store running WooCommerce Subscriptions that:
-- - Used HPOS (High-Performance Order Storage) before mid-2024
-- - Has subscriptions dating back to 2017 or later
-- - Uses Stripe, PayPal, or any non-WooCommerce-Payments gateway
@sybrew
sybrew / tsf-acf-description-snippet.php
Created February 16, 2026 07:50
This snippet shows how to pull an Advanced Custom Fields (ACF) field value into the auto-generated meta description.
<?php
// Do not include the PHP opening tag if PHP is already open.
/**
* ACF Description Snippet for The SEO Framework
*
* This snippet shows how to pull an Advanced Custom Fields (ACF) field value
* into the auto-generated meta description. Two approaches are demonstrated:
*
* 1. With HTML -- When your ACF field stores rich/HTML content, use
@sybrew
sybrew / woocommerce-structured-data-shippingdetails-hasmerchantreturnpolicy.php
Created January 14, 2026 18:05
Adds shippingDetails and hasMerchantReturnPolicy to WooCommerce product Schema.org structured data output
<?php
// Don't include the PHP opening tag if PHP is already open.
add_filter(
'woocommerce_structured_data_product_offer',
function ( $markup_offer, $product ) {
// Add shipping details.
$markup_offer['shippingDetails'] = [
<?php
/**
* Copyright (c) 2025 Sybre Waaijer, CyberWire B.V.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
@sybrew
sybrew / tsf-disable-page-12.php
Created June 29, 2025 05:11
Disable TSF on page ID 12
<?php
// Do not include the opening PHP tag if PHP is already opened.
\add_filter(
'the_seo_framework_query_supports_seo',
/**
* Disables SEO support for page ID 12.
*
@sybrew
sybrew / tsf-allow-empty-category-indexing.php
Created June 18, 2025 13:19
This code snippet modifies The SEO Framework plugin to let search engines index empty category archives by disabling the noindex directive. Note: WordPress may still emit a 404 response.
<?php
// Do not open PHP if PHP is already opened.
add_filter(
'the_seo_framework_enable_noindex_no_posts',
function ( $noindex ) {
if ( is_category() ) {
// To allow indexing, so set noindex to false.
@sybrew
sybrew / tsf-acf-html-excerpt-description.php
Last active May 21, 2025 19:34
Use ACF fields for meta descriptions via excerpt extraction in The SEO Framework plugin, supporting both admin and front-end contexts.
<?php
// Do not include the PHP opening tag if PHP is already open.
// Per email Wojciech.
add_filter( 'the_seo_framework_description_excerpt', 'my_tsf_acf_custom_excerpt', 10, 3 );
/**
* Use ACF HTML fields as meta description for specific CPTs.
*
* @param string $excerpt The auto‐generated excerpt.