Skip to content

Instantly share code, notes, and snippets.

Avatar

Weston Ruter westonruter

View GitHub Profile
View lando.sh
#!/bin/bash
cd $( dirname "$0" )/..
set -e
set -x
if [ -z "$1" ]; then
command="start"
else
View amp-enable-ssr.php
<?php
/**
* AMP Enable SSR
*
* @package AMP_Enable_SSR
* @author Weston Ruter, Google
* @link https://gist.github.com/westonruter/8d52c0b807e6dfbbdf2219622d0f4a7e
* @license GPL-2.0-or-later
* @copyright 2019 Google Inc.
*
@westonruter
westonruter / filter-post-thumbnail-id.php
Last active Apr 7, 2021
How to filter the response for get_post_thumbnail_id()
View filter-post-thumbnail-id.php
<?php
/**
* How to filter the value that would be returned by get_post_thumbnail_id()
*/
add_filter( 'get_post_metadata', function ( $value, $post_id, $meta_key, $single ) {
// We want to pass the actual _thumbnail_id into the filter, so requires recursion
static $is_recursing = false;
// Only filter if we're not recursing and if it is a post thumbnail ID
View amp-async-validation.php
<?php
/**
* AMP Async Validation
*
* Installation instructions:
* 1. Click the “Download ZIP” button.
* 2. Rename the downloaded ZIP file to “amp-async-validation.zip”
* 3. In the WordPress admin, go to Plugins > Add New
* 4. Click the Upload Plugin button.
* 5. Select the “amp-async-validation.zip” file and click “Install now”.
View amp-cover-block-fix.php
<?php
/**
* AMP Cover Block Fix plugin bootstrap.
*
* @package Google\AMP_Cover_Block_Fix
* @author Weston Ruter, Google
* @license GPL-2.0-or-later
* @copyright 2021 Google Inc.
*
* @wordpress-plugin
View amp-fx-blocks.php
<?php
/**
* AMP FX Blocks plugin bootstrap.
*
* @package Google\AMP_FX_Blocks
* @author Weston Ruter, Google
* @license GPL-2.0-or-later
* @copyright 2021 Google Inc.
*
* @wordpress-plugin
View background-image-svg-data-url.css
#try-stylesheet-containing-closing-style-tag {
background-color: red;
}
#try-stylesheet-containing-closing-style-tag {
background-image: url( "data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' version='1.1' viewBox='0 0 30 30' width='30' height='30'><title>AMP</title><defs><style>.circle{fill:white}.overlay{fill:blue;}</style></defs><g fill='none' fill-rule='evenodd'><path class='circle' d='M0 15c0 8.284 6.716 15 15 15 8.285 0 15-6.716 15-15 0-8.284-6.715-15-15-15C6.716 0 0 6.716 0 15z'/><path class='overlay' fill-rule='nonzero' d='M13.85 24.098h-1.14l1.128-6.823-3.49.005h-.05a.57.57 0 0 1-.568-.569c0-.135.125-.363.125-.363l6.272-10.46 1.16.005-1.156 6.834 3.508-.004h.056c.314 0 .569.254.569.568 0 .128-.05.24-.121.335L13.85 24.098zM15 0C6.716 0 0 6.716 0 15c0 8.284 6.716 15 15 15 8.285 0 15-6.716 15-15 0-8.284-6.715-15-15-15z'/></g></svg>" );
background-repeat: no-repeat;
background-color: lime;
background-position: bottom left;
background-size: 50px 50px;
View amp-domain-checker.php
<?php
/**
* Check domains for the status of AMP on the homepage.
*
* The input file needs to have one domain per line.
*
* USAGE:
*
* wp eval-file amp-domain-checker.php domains.txt
* cat domains.txt | wp eval-file amp-domain-checker.php -
View amp-wordfence-compat.php
<?php
/**
* AMP Wordfence Compat plugin bootstrap.
*
* @package Google\AMP_Wordfence_Compat
* @author Weston Ruter, Google
* @license GPL-2.0-or-later
* @copyright 2020 Google Inc.
*
* @wordpress-plugin
View amp-validation-error-logger.php
<?php
/**
* AMP Validation Error Logger plugin initialization file.
*
* @package AMP_Validation_Error_Logger
* @author Weston Ruter, Google
* @license GPL-2.0-or-later
* @copyright 2019 Google Inc.
*
* @wordpress-plugin