Skip to content

Instantly share code, notes, and snippets.

View westonruter's full-sized avatar

Weston Ruter westonruter

View GitHub Profile

This plugin was generated by Gemini 2.5 Pro with the following prompt:

Create a WordPress plugin which does the following:

Create a new postmeta field in WordPress which contains an array of colors names. This gets stored as serialized data in one postmeta value.

Expose this as postmeta field so it is publicly accessible and editable via the REST API for any user who has the ability to edit posts.

On the frontend, when a user is logged-in and is able to edit a post, print out a JavaScript function in an inline script which fetches that REST API field to log out to the console, and then create another function which calls the REST API to update that postmeta field.

@westonruter
westonruter / increase-styles-inline-size-limit.php
Last active September 15, 2025 20:27
Sample Page in stock WordPress Twenty Twenty-Five theme with all stylesheets inlined
<?php
/**
* Plugin Name: Increase Styles Inline Size Limit (styles_inline_size_limit)
* Author: Weston Ruter
* Update URI: false
*/
add_filter(
'styles_inline_size_limit',
static function (): int {
@westonruter
westonruter / wp-trac-ticket-user-counter.js
Created September 12, 2025 18:00
Helper script to run from bookmarklet to get list of users to potentially prop in order of potential impact in a ticket
const authorContribCount = {};
Array.from(document.querySelectorAll('.trac-author')).forEach(
(link) => {
if ( ! ( link.textContent in authorContribCount ) ) {
authorContribCount[ link.textContent ] = 0;
}
authorContribCount[ link.textContent ]++;
}
);
@westonruter
westonruter / bar.js
Last active September 5, 2025 21:58
import foo from 'foo';
console.log( 'Executed script module bar.' );
export default {};
<?php
/**
* Emoji Detection Script Deferred Plugin for WordPress
*
* @package EmojiDetectionScriptDeferred
* @author Weston Ruter
* @license GPL-2.0-or-later
*
* @wordpress-plugin
* Plugin Name: Emoji Detection Script Deferred
@westonruter
westonruter / facebook-pixel-strict-csp-compatible.php
Last active August 11, 2025 04:38
How to adapt the Base Code for Facebook Pixel to be compatible with Strict CSP: https://developers.facebook.com/docs/meta-pixel/get-started/#base-code
<?php
// This adaptation of the Base Code for Facebook Pixel is compatible with the Strict CSP plugin: https://wordpress.org/plugins/strict-csp/
add_action(
'wp_head',
static function () {
?>
<!-- Facebook Pixel Code -->
<?php
$js = <<<JS
!function(f,b,e,v,n,t,s)
<?php
/**
* Plugin Name: Sleepy Responses
* Plugin URI: https://gist.github.com/westonruter/b66cfc51397c75d6497b6ed0aeb68ce3
* Description: Slows down a response when a <code>sleep</code> query parameter is provided, with a value being an integer for the number of seconds passed into the PHP <code>sleep()</code> function. Only applies when <code>WP_DEBUG</code> is enabled or when <code>wp_get_environment_type()</code> returns <code>local</code> or <code>development</code>.
* Requires at least: 6.8
* Requires PHP: 7.4
* Version: 0.1.0
* Author: Weston Ruter
* Author URI: https://weston.ruter.net/

Status: Draft (The final form of this may move to a blog post or a full repo.)

This describes how to set up the repos for WordPress/wordpress-develop, WordPress/gutenberg, and WordPress/performance in one single place all using their own built-in environments (in Docker). Importantly, the latter two repos (for plugins) are configured to use the core files from the repos for both their development and tests environments.

Benefits:

  1. WordPress core files are shared across all environments, including when running unit tests. So if you run PHPUnit tests for Gutenberg or Performance Lab, any core changes you've made will be reflected. This resolves a big painpoint with trying out core patches in plugin unit tests.
  2. Plugins, mu-plugins, and themes and are shared across all environments, although you can add additional environment-specific extensions in your `.wp-e
--- before.prettier.html 2025-05-21 13:15:12
+++ after.prettier.html 2025-05-21 13:15:19
@@ -2150,28 +2150,34 @@
type="module"
src="http://localhost:10008/wp-includes/js/dist/script-modules/block-library/file/view.min.js?ver=fdc2f6842e015af83140"
id="@wordpress/block-library/file/view-js-module"
+ fetchpriority="low"
></script>
<script
type="module"