Skip to content

Instantly share code, notes, and snippets.

View westonruter's full-sized avatar

Weston Ruter westonruter

View GitHub Profile
<?php
/**
* Plugin Name: Always Print Script Modules in Head
* Plugin URI: https://gist.github.com/westonruter/f9e67442c674c3176b95cd1ed0e784c1
* Description: In classic themes script modules are forced to print in the footer since the HEAD is rendered before the rest of the page, so it is not yet known what script modules will be enqueued. This can be fixed with output buffering. This is a demonstration plugin for Core Trac ticket #43258 which adds output buffering for the rendered template.
* Requires at least: 6.8-beta1
* Version: 0.1.0
* Author: Weston Ruter
* Author URI: https://weston.ruter.net/
* License: GPLv2 or later
<?php
/**
* Plugin Name: Always Load Block Styles on Demand
* Plugin URI: https://gist.github.com/westonruter/99af37489334927aaf04a46eaf2a11eb
* Description: In classic themes a lot more CSS is added to a page than is needed because when the HEAD is rendered before the rest of the page, so it is not yet known what blocks will be used. This can be fixed with output buffering. This is a demonstration plugin for Core Trac ticket #43258 which adds output buffering for the rendered template.
* Requires at least: 6.8-beta1
* Version: 0.1.0
* Author: Weston Ruter
* Author URI: https://weston.ruter.net/
* License: GPLv2 or later
<?php
/**
* Constructs a CSS selector for the current tag.
*
* @param WP_HTML_Processor $processor Processor.
* @return string Selector.
*/
function get_css_selector( WP_HTML_Processor $processor ): string {
$selector = join( ' > ', $processor->get_breadcrumbs() );
@westonruter
westonruter / image-prioritizer-urls.sql
Last active December 10, 2024 21:40
Query list of URLs in HTTP Archive which use Image Prioritizer
CREATE TEMPORARY FUNCTION IS_CMS(technologies ARRAY<STRUCT<technology STRING, categories ARRAY<STRING>, info ARRAY<STRING>>>, cms STRING, version STRING) RETURNS BOOL AS (
EXISTS(
SELECT * FROM UNNEST(technologies) AS technology, UNNEST(technology.info) AS info
WHERE technology.technology = cms
AND (
version = ""
OR ENDS_WITH(version, ".x") AND (STARTS_WITH(info, RTRIM(version, "x")) OR info = RTRIM(version, ".x"))
OR info = version
)
)
/**
* Finalizes extension.
*
* @type {FinalizeCallback}
* @param {FinalizeArgs} args Args.
*/
export async function finalize( { extendRootData } ) {
const script = document.getElementById( 'od-normalized-query-vars' );
if ( script instanceof HTMLScriptElement ) {
extendRootData( { queryVars: JSON.parse( script.text ) } );
/**
* Finalizes extension.
*
* @type {FinalizeCallback}
* @param {FinalizeArgs} args Args.
*/
export async function finalize( { extendRootData } ) {
extendRootData( { userAgent: navigator.userAgent } );
}

auto-sizes

Warning

Stable tag is unchanged at 1.3.0, so no plugin release will occur.

svn status:

M       readme.txt
@westonruter
westonruter / od-admin-ui.php
Last active November 19, 2024 22:58
[OUTDATED] Gist moved to full repo: https://github.com/westonruter/od-admin-ui
<?php
/**
* Plugin Name: Optimization Detective Admin UI
* Plugin URI: https://gist.github.com/westonruter/004094f1d49b8b98492deb3dd20bc55e
* Description: Provides an admin UI to inspect URL Metrics from the Optimization Detective plugin.
* Requires at least: 6.5
* Requires PHP: 7.2
* Requires Plugins: optimization-detective
* Version: 0.3.3
* Author: Weston Ruter
<?php
/**
* This file is intended to be executed using WP-CLI's eval-file command.
*/
$bookmark_name = 'the-bookmark';
$html = <<<HTML
<html lang="en">
<head>
Warning: The next_token() method was called another time for +HTML. in /var/www/html/wp-content/plugins/html-processor-debug/html-processor-debug.php on line 80
<HTML xpath="/*[2][self::HTML]">
Warning: The next_token() method was called another time for +HEAD. in /var/www/html/wp-content/plugins/html-processor-debug/html-processor-debug.php on line 80
<HEAD xpath="/*[2][self::HTML]/*[2][self::HEAD]">
Warning: The next_token() method was called another time for +META. in /var/www/html/wp-content/plugins/html-processor-debug/html-processor-debug.php on line 80
<META xpath="/*[2][self::HTML]/*[2][self::HEAD]/*[3][self::META]">
Warning: The next_token() method was called another time for +TITLE. in /var/www/html/wp-content/plugins/html-processor-debug/html-processor-debug.php on line 80
<TITLE xpath="/*[2][self::HTML]/*[2][self::HEAD]/*[6][self::TITLE]">
Warning: The next_token() method was called another time for -HEAD. in /var/www/html/wp-content/plugins/html-processor-d