Skip to content

Instantly share code, notes, and snippets.

View adamsilverstein's full-sized avatar
💭
Working remotely, as usual

Adam Silverstein adamsilverstein

💭
Working remotely, as usual
View GitHub Profile
@adamsilverstein
adamsilverstein / expanded_alowed_tags
Last active April 3, 2024 18:15
WordPress expanded allowed tags for wp_kses with iframe, forms, etc.
function expanded_alowed_tags() {
$my_allowed = wp_kses_allowed_html( 'post' );
// iframe
$my_allowed['iframe'] = array(
'src' => array(),
'height' => array(),
'width' => array(),
'frameborder' => array(),
'allowfullscreen' => array(),
);
<?php
/**
* Disable password reset
*
* @wordpress-plugin
* Plugin Name: Disable password reset.
* Description: Disable password reset.
* Plugin URI:
* Version: 1.0.0
* Author: Adam Silverstein, Google
@adamsilverstein
adamsilverstein / yield-to-main.js
Last active January 9, 2024 20:59
Yield to main thread
/*
* Yielding method using scheduler.yield, falling back to setTimeout:
*/
async function yieldToMain() {
if('scheduler' in window && 'yield' in scheduler) {
return await scheduler.yield();
}
return new Promise(resolve => {
setTimeout(resolve, 0);
%%bigquery oembeds
WITH
WPEmbeds AS (
SELECT
url,
JSON_EXTRACT(payload, '$._cms.wordpress.has_embed_block') AS has_embed_block,
CAST( JSON_EXTRACT(payload, '$._cms.wordpress.embed_block_count.total') AS FLOAT64 ) AS embed_block_count_total,
JSON_EXTRACT_ARRAY(payload, '$._cms.wordpress.embed_block_count.total_by_type') AS embed_block_count_total_by_type,
FROM `httparchive.pages.2023_10_01_*`
%%bigquery bytype
WITH
embed_data AS (
SELECT
url,
JSON_EXTRACT(payload, '$._cms.wordpress.has_embed_block') AS has_embed_block,
CAST(JSON_EXTRACT(payload, '$._cms.wordpress.embed_block_count.total') AS FLOAT64)
AS embed_block_count_total,
JSON_EXTRACT(payload, '$._cms.wordpress.embed_block_count.total_by_type') AS embeds,
FROM `httparchive.pages.2023_10_01_desktop`
SELECT
*
FROM(
SELECT
JSON_VALUE(third_party, '$.entity') as entity,
CAST(APPROX_QUANTILES(CAST(JSON_QUERY(third_party, '$.blockingTime') AS FLOAT64), 100)[offset(75)] as INT64) as p75_blockingTime,
COUNT(page) as usage
FROM
`httparchive.all.pages`,
UNNEST(technologies) as technologies,
@adamsilverstein
adamsilverstein / gist:542528726a67797e3cbf
Created July 21, 2014 17:20
Strict Error Reporting Off
<?php
/**
* Plugin Name: Force Strict OFF
* Description: Forces Strict errors off
* Author: John P. Bloch
* Version: 0.1
* License: GPLv2
*/
if ( WP_DEBUG ) {
@adamsilverstein
adamsilverstein / add-lazy-loading-to-oembeds.php
Last active November 22, 2023 22:16
Add lazy loading to oEmbed iframes (in WordPress)
<?php
/**
* Add lazy loading to oEmbed iframes.
*
* @wordpress-plugin
* Plugin Name: Lazy Load oEmbeds.
* Description: Add lazy loading to oEmbed iframes.
* Plugin URI:
* Version: 1.0.0
* Author: Adam Silverstein, Google
@adamsilverstein
adamsilverstein / defer_all_scripts.php
Last active November 22, 2023 22:04
Hook into `wp_enqueue_script` and defer all scripts using defer strategy from WordPress 6.3.
<?php
/**
* Recursively add the defer strategy to a script and all its dependencies.
*
* @param string $handle The script handle.
* @return void
*/
function recursively_add_defer_strategy( $handle ) {
wp_script_add_data( $handle, 'strategy', 'defer' );