Skip to content

Instantly share code, notes, and snippets.

View westonruter's full-sized avatar

Weston Ruter westonruter

View GitHub Profile
@westonruter
westonruter / wp_enqueue_non_blocking_script.php
Last active November 9, 2023 05:24 — forked from adamsilverstein/wp_enqueue_non_blocking_script.php
Use async/defer in a backwards compatible manner
<?php
/**
* Register scripts with a `defer` or `async` strategy in a backwards compatible manner.
*
* From WordPress 6.3 onwards, the `wp_register_script` function accepts an `$args` array that
* can include a `strategy` key with a value of either `async` or `defer`.
*
* This helper function handles the backwards compatibility for older versions of WordPress. When a
* `strategy` key is present in the `$args` array (and is either `defer` or `async`), the
@westonruter
westonruter / hook-count.php
Last active August 7, 2023 17:49
Install as mu-plugin to get dump of all hooks invoked more than once.
<?php
/**
* Plugin Name: Hook Counter
* Author: Weston Ruter
* Description: Drop in mu-plugins and see a markdown table at the end of a page's source code counting all hooks invoked more than once.
*/
$hook_counts = [];
add_filter( 'all', static function ( $hook_name ) use ( &$hook_counts ) {
<!-- wp:paragraph -->
<p>These are the emoji which are tested for in <code>emoji-loader.js</code>:</p>
<!-- /wp:paragraph -->
<!-- wp:columns {"align":"wide"} -->
<div class="wp-block-columns alignwide"><!-- wp:column -->
<div class="wp-block-column"><!-- wp:paragraph {"fontSize":"xx-large"} -->
<p class="has-xx-large-font-size">🏳️‍⚧️</p>
<!-- /wp:paragraph -->
<?php
/**
* Optimize Loading Separate Core Block Assets in Classic Themes Plugin.
*
* @package OptimizeLoadingSeparateCoreBlockAssetsInClassicThemes
* @author Weston Ruter
* @link https://gist.github.com/westonruter/25187db63a7666f08b151ca53497ffb5
* @license GPL-2.0-or-later
* @copyright 2023 Google Inc.
*
<?php
/**
* Make YouTube Accessible Embed Plugin
*
* @package TBK_YouTube_Embed_Mods
* @author Weston Ruter
* @link https://gist.github.com/westonruter/8199d0fcb417a909380b0aeff4247cf7
* @license GPL-2.0-or-later
* @copyright 2023 Google Inc.
*
<?php
require_once __DIR__ . '/functions.php';
require_once __DIR__ . '/_wp_normalize_relative_css_links.trunk.php';
require_once __DIR__ . '/_wp_normalize_relative_css_links.patch.php';
/**
* @BeforeMethods("setUp")
* @Revs(100)
* @Iterations(5)
<?php
/**
* PWA Cache Pre-Activation Resources
*
* @package PWA
* @author Weston Ruter
* @link https://gist.github.com/westonruter/3beda9d304c02712cbb0f01ba06aa5b2
* @license GPL-2.0-or-later
* @copyright 2019 Google Inc.
*
<?php
/**
* @package Syntax_Highlighting_Code_Block
* @author Weston Ruter
* @link https://gist.github.com/westonruter/d99067473ad799deb099334a70bdf336
* @license GPL-2.0-or-later
* @copyright 2023 Google Inc.
*
* @wordpress-plugin
* Plugin Name: Code Block Copy Button
@westonruter
westonruter / composer-install-php-56.sh
Created May 3, 2022 04:05
Running composer install to generate PHP 5.6-compatible autoload files
#!/bin/bash
if [ ! -e composer.json ]; then
echo "Run script from package root."
exit 1
fi
# "Composer 2.3.0 dropped support for PHP <7.2.5 and you are running 5.6.40, please upgrade PHP or use Composer 2.2 LTS…"
docker run -it --rm --name composer-install -v "$PWD":/app -w /app php:5.6-cli-alpine sh -c "
wget -O /tmp/composer.phar https://getcomposer.org/download/latest-2.2.x/composer.phar \