Skip to content

Instantly share code, notes, and snippets.

Avatar

Weston Ruter westonruter

View GitHub Profile
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-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 -
@westonruter
westonruter / amp-responsive-image-preload-link-srcset-opt-in.php
Last active Jan 31, 2021
Enable preload links for responsive hero images which have srcset and sizes attributes. This is disabled by default because only Chrome supports imagesrcset and imagesizes on preload links. This eliminates the Optimizer from raising this notice: CannotPreloadImage: Not preloading the hero image because of the presence of a srcset attribute…
View amp-responsive-image-preload-link-srcset-opt-in.php
View amp-mobile-server-side-redirection.php
<?php
/**
* AMP Mobile Server-Side Redirection plugin bootstrap.
*
* @package Google\AMP_Mobile_Server_Side_Redirection
* @author Weston Ruter, Google
* @license GPL-2.0-or-later
* @copyright 2021 Google Inc.
*
* @wordpress-plugin
View jetpack-amp-contact-form-submission-fix.php
<?php
/**
* Jetpack AMP Contact Form Submission Fix plugin bootstrap.
*
* @package Google\Jetpack_AMP_Contact_Form_Submission_Fix
* @author Weston Ruter, Google
* @license GPL-2.0-or-later
* @copyright 2021 Google Inc.
*
* @wordpress-plugin
View Sanitizer.php
<?php
/**
* Sanitizer file.
*
* @package Google\AMP_Auto_Lightbox_Disable
*/
namespace Google\AMP_Auto_Lightbox_Disable;
use AMP_Base_Sanitizer;
View amp-update-supported-post-types-cli-command.php
<?php
/**
* AMP Update Supported Post Types WP-CLI Command
*
* @package Google\AMP_Update_Supported_Post_Types_CLI_Command
* @author Weston Ruter, Google
* @license GPL-2.0-or-later
* @copyright 2021 Google Inc.
*
* @wordpress-plugin
View amp-collect-spec-names.php
<?php
$spec_names = [];
foreach ( AMP_Allowed_Tags_Generated::get_allowed_tags() as $tag => $tag_rules ) {
foreach ( $tag_rules as $tag_rule ) {
if ( isset( $tag_rule['tag_spec']['spec_name'] ) ) {
$spec_name = strtolower( $tag_rule['tag_spec']['spec_name'] );
} elseif ( isset( $tag_rule['tag_spec']['extension_spec']['name'] ) ) {
$spec_name = sprintf(
'script[%s=%s]',
View amp-suppress-eager-loading-images.php
<?php
/**
* AMP Suppress Eager Loading Images plugin bootstrap.
*
* @package Google\AMP_Suppress_Eager_Loading_Images
* @author Weston Ruter, Google
* @license GPL-2.0-or-later
* @copyright 2020 Google Inc.
*
* @wordpress-plugin
@westonruter
westonruter / class-amp-base-sanitizer.php.diff
Created Nov 25, 2020
Gathering all validation errors generated during AMP plugin unit tests
View class-amp-base-sanitizer.php.diff
diff --git a/includes/sanitizers/class-amp-base-sanitizer.php b/includes/sanitizers/class-amp-base-sanitizer.php
index 32badf460..312fc2431 100644
--- a/includes/sanitizers/class-amp-base-sanitizer.php
+++ b/includes/sanitizers/class-amp-base-sanitizer.php
@@ -542,10 +542,12 @@ abstract class AMP_Base_Sanitizer {
* @return bool Whether to sanitize.
*/
public function should_sanitize_validation_error( $validation_error, $data = [] ) {
+ $validation_error = $this->prepare_validation_error( $validation_error, $data );
+ file_put_contents( AMP__DIR__ . '/error-key-dump.txt', json_encode( $validation_error ) . PHP_EOL, FILE_APPEND );